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