Update Patches/OnDataReceived.cs
This commit is contained in:
1 parent
498eeb45bb
commit
a2c670d4bb
1 file changed
+55
-55
@@ -0,0 +1,56 @@
|
||||
using GorillaNetworking;
|
||||
using HarmonyLib;
|
||||
using Photon.Pun;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using TooMuchInfo.Tools;
|
||||
|
||||
namespace TooMuchInfo.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(VRRig))]
|
||||
[HarmonyPatch("SerializeReadShared", MethodType.Normal)]
|
||||
public static class OnDataReceived
|
||||
{
|
||||
private static void Postfix(VRRig __instance)
|
||||
{
|
||||
UpdatePlayerPing(__instance);
|
||||
UpdatePlayerCosmetXState(__instance);
|
||||
__instance.UpdateName();
|
||||
}
|
||||
|
||||
private static void UpdatePlayerPing(VRRig rig)
|
||||
{
|
||||
double estimatedPing = Math.Abs((rig.velocityHistoryList[0].time - PhotonNetwork.Time) * 1000);
|
||||
int clampedPing = (int)Math.Clamp(Math.Round(estimatedPing), 0, int.MaxValue);
|
||||
|
||||
Extensions.PlayerPing[rig] = clampedPing;
|
||||
}
|
||||
|
||||
private static void UpdatePlayerCosmetXState(VRRig rig)
|
||||
{
|
||||
if (!Extensions.PlayerMods.ContainsKey(rig))
|
||||
Extensions.PlayerMods[rig] = [];
|
||||
|
||||
if (!rig.HasCosmetics())
|
||||
return;
|
||||
|
||||
CosmeticsController.CosmeticSet cosmeticSet = rig.cosmeticSet;
|
||||
bool hasCosmetx =
|
||||
cosmeticSet.items.Any(cosmetic => !cosmetic.isNullItem &&
|
||||
!rig._playerOwnedCosmetics.Contains(
|
||||
cosmetic.itemName)) && !rig.inTryOnRoom;
|
||||
|
||||
switch (hasCosmetx)
|
||||
{
|
||||
case true when !Extensions.PlayerMods[rig].Contains("[<color=red>COSMETX</color>]"):
|
||||
Extensions.PlayerMods[rig].Add("[<color=red>COSMETX</color>]");
|
||||
|
||||
break;
|
||||
|
||||
case false when Extensions.PlayerMods[rig].Contains("[<color=red>COSMETX</color>]"):
|
||||
Extensions.PlayerMods[rig].Remove("[<color=red>COSMETX</color>]");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user