Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of NetworkingRefreshed v1.9.6
NetworkingRefreshed.dll
Decompiled a day ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using ExitGames.Client.Photon; using HarmonyLib; using Photon.Pun; using Photon.Realtime; using Platforms; using RevivalSync.Patches; using TMPro; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("Revival")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Revival")] [assembly: AssemblyFileVersion("1.9.6.0")] [assembly: AssemblyInformationalVersion("1.9.6+0da67e8fc189c687383d184c438ea91614303621")] [assembly: AssemblyProduct("NetworkingRefreshed")] [assembly: AssemblyTitle("NetworkingRefreshed")] [assembly: AssemblyVersion("1.9.6.0")] namespace RevivalSync { internal static class Compat { private static bool done; private static ConfigEntry<bool> selfHostEnabled; private static FieldRef<MenuPageRegions, bool> regionsConnected; private static FieldRef<MenuElementRegion, string> regionCode; internal static void Apply() { if (done) { return; } done = true; try { DisableCartSpeedSync(); } catch (Exception arg) { Plugin.Log.LogError((object)$"[compat] CartSpeedSync handling failed: {arg}"); } try { FixRepoFidelity(); } catch (Exception arg2) { Plugin.Log.LogError((object)$"[compat] REPO Fidelity handling failed: {arg2}"); } try { FixSelfHostedPhoton(); } catch (Exception arg3) { Plugin.Log.LogError((object)$"[compat] Self_Hosted_Photon handling failed: {arg3}"); } } private static void FixSelfHostedPhoton() { //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Expected O, but got Unknown Type type = AccessTools.TypeByName("Self_Hosted_Photon.Patches.MenuPageRegionsPatch"); MethodInfo methodInfo = ((type != null) ? AccessTools.Method(type, "StartPrefix", (Type[])null, (Type[])null) : null); if (!(methodInfo == null) && !(AccessTools.Method(typeof(SteamManager), "SendSteamAuthTicket", (Type[])null, (Type[])null) != null)) { Type type2 = AccessTools.TypeByName("Self_Hosted_Photon.ConfigManager"); selfHostEnabled = ((type2 != null) ? (AccessTools.Property(type2, "Enabled")?.GetValue(null) as ConfigEntry<bool>) : null); regionsConnected = AccessTools.FieldRefAccess<MenuPageRegions, bool>("connectedToMaster"); regionCode = AccessTools.FieldRefAccess<MenuElementRegion, string>("regionCode"); new Harmony("com.Revival.revivalsync").Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Compat), "SelfHostStartPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Plugin.Log.LogInfo((object)"[compat] Self_Hosted_Photon: region page updated for game v0.5.0 (new Steam auth call)."); } } private static bool SelfHostStartPrefix(MenuPageRegions __0, ref bool __result) { if (selfHostEnabled != null && !selfHostEnabled.Value) { return true; } if ((Object)(object)__0 == (Object)null) { return true; } ((MonoBehaviour)__0).StartCoroutine(CustomHostRegionPage(__0)); __result = false; return false; } private static IEnumerator CustomHostRegionPage(MenuPageRegions page) { PhotonNetwork.Disconnect(); while ((int)PhotonNetwork.NetworkingClient.State != 14 && (int)PhotonNetwork.NetworkingClient.State != 0) { yield return null; } DataDirector.instance.PhotonSetVersion(); DataDirector.instance.PhotonSetAppId(); PlatformManager.instance.SetPhotonAuthTicket(); PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = ""; ServerSettings.ResetBestRegionCodeInPreferences(); PhotonNetwork.ConnectUsingSettings(); while (!regionsConnected.Invoke(page)) { yield return null; } page.loadingGraphics.SetDone(); yield return (object)new WaitForSecondsRealtime(0.3f); MenuElementRegion component = Object.Instantiate<GameObject>(page.regionPrefab, page.transformStartPosition.position, Quaternion.identity, page.transformStartPosition.parent).GetComponent<MenuElementRegion>(); ((TMP_Text)component.textName).text = "Custom Host"; ((TMP_Text)component.textName).color = Color.white; ((TMP_Text)component.textPing).text = ""; component.parentPage = page; regionCode.Invoke(component) = "custom"; PhotonNetwork.Disconnect(); ((Behaviour)page.menuScrollBox).enabled = true; while (page.scrollCanvasGroup.alpha < 0.99f) { CanvasGroup scrollCanvasGroup = page.scrollCanvasGroup; scrollCanvasGroup.alpha += Time.deltaTime * 5f; yield return null; } page.scrollCanvasGroup.alpha = 1f; } private static void DisableCartSpeedSync() { if (Chainloader.PluginInfos.ContainsKey("discjenny.CartSpeedSync")) { Harmony.UnpatchID("discjenny.CartSpeedSync"); Plugin.Log.LogWarning((object)"[compat] CartSpeedSync is not supported and has been switched off: it speeds up your copy of a cart past the host's, which makes held carts drift and fling loot. NetworkingRefreshed already makes carts instant. You can uninstall CartSpeedSync."); } } private static void FixRepoFidelity() { //IL_007f: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.InstantCartHandle.Value) { return; } MethodInfo methodInfo = AccessTools.Method(typeof(PhysGrabObjectGrabArea), "Update", (Type[])null, (Type[])null); Patches val = ((methodInfo != null) ? Harmony.GetPatchInfo((MethodBase)methodInfo) : null); if (val == null) { return; } foreach (Patch prefix in val.Prefixes) { if (!(prefix.PatchMethod?.DeclaringType?.Name != "GrabAreaIdleSkipPatch")) { new Harmony("com.Revival.revivalsync").Unpatch((MethodBase)methodInfo, prefix.PatchMethod); Plugin.Log.LogInfo((object)("[compat] REPO Fidelity: removed its cart-handle skip (" + prefix.owner + ") so Instant Cart Handle works. Everything else in REPO Fidelity is unchanged.")); } } } } internal static class GunShots { private sealed class Pred { public float time; public int shootLeft; public int bulletsLeft; public float cooldownUntil; } private sealed class Result { public int actor; public float time; public Vector3 origin; public Vector3 fwd; public int n; public int[] flags; public int[] anchor; public Vector3[] end; public Vector3[] local; } internal const byte EventCode = 189; private const float ResultMaxAge = 1f; private const float MaxOriginError = 4f; private const float RangeSlack = 1f; private const float SpreadSlackDeg = 3f; private const float MaxAnchorShift = 3f; private const float PredMaxAge = 1.5f; private const int MaxBullets = 32; private static readonly Dictionary<int, Pred> preds = new Dictionary<int, Pred>(); private static readonly Dictionary<int, Result> results = new Dictionary<int, Result>(); private static readonly RaiseEventOptions toHost = new RaiseEventOptions { Receivers = (ReceiverGroup)2 }; private static bool predicting; private static Result active; private static int activeIndex; private static FieldRef<ItemGun, State> gunState; private static FieldRef<ItemBattery, int> batteryBars; private static FieldRef<ItemToggle, int> togglePlayer; private static bool refsTried; private static bool refsOk; private static bool Refs() { if (refsTried) { return refsOk; } refsTried = true; try { gunState = AccessTools.FieldRefAccess<ItemGun, State>("stateCurrent"); batteryBars = AccessTools.FieldRefAccess<ItemBattery, int>("batteryLifeInt"); togglePlayer = AccessTools.FieldRefAccess<ItemToggle, int>("playerTogglePhotonID"); refsOk = true; } catch (Exception ex) { Plugin.Log.LogWarning((object)("[shot] gun internals changed — shooter-side shots stay off: " + ex.Message)); } return refsOk; } private static bool Fin(Vector3 v) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) if (!float.IsNaN(v.x) && !float.IsNaN(v.y) && !float.IsNaN(v.z) && !float.IsInfinity(v.x) && !float.IsInfinity(v.y)) { return !float.IsInfinity(v.z); } return false; } internal static void OnLocalToggle(ItemToggle toggle, int player) { //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_037e: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Unknown result type (might be due to invalid IL or missing references) //IL_022a: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_0237: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_024c: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_02ff: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_030c: Unknown result type (might be due to invalid IL or missing references) //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0283: Unknown result type (might be due to invalid IL or missing references) //IL_033b: Unknown result type (might be due to invalid IL or missing references) //IL_034e: Unknown result type (might be due to invalid IL or missing references) //IL_041f: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_043d: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_02ef: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)toggle == (Object)null || !GameManager.Multiplayer() || PhotonNetwork.IsMasterClient || !HostAssist.ShotsActive || (Object)(object)PlayerAvatar.instance == (Object)null || player != SemiFunc.PhotonViewIDPlayerAvatarLocal()) { return; } ItemGun component = ((Component)toggle).GetComponent<ItemGun>(); if ((Object)(object)component == (Object)null || !component.hasOneShot || (Object)(object)((Component)component).GetComponent<ItemGunRevolver>() != (Object)null) { return; } PhotonView component2 = ((Component)component).GetComponent<PhotonView>(); if ((Object)(object)component.gunMuzzle == (Object)null || (Object)(object)component.bulletPrefab == (Object)null || (Object)(object)component2 == (Object)null || !Refs()) { return; } PhysGrabObject component3 = ((Component)component).GetComponent<PhysGrabObject>(); SimManager.SimState simState = SimManager.StateOf(component3); if (simState == null || !simState.weapon || !simState.localGrab || simState.viewId == 0 || !HostAssist.For(simState) || gunState.Invoke(component)) { return; } ItemBattery component4 = ((Component)component).GetComponent<ItemBattery>(); if ((Object)(object)component4 == (Object)null || batteryBars.Invoke(component4) <= 0) { return; } float unscaledTime = Time.unscaledTime; if (preds.TryGetValue(simState.viewId, out var value) && unscaledTime < value.cooldownUntil) { return; } int num = Mathf.Clamp(component.numberOfBullets, 1, 32); Vector3 position = component.gunMuzzle.position; Vector3 forward = component.gunMuzzle.forward; int num2 = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) + LayerMask.GetMask(new string[1] { "Enemy" }); Vector3[] array = (Vector3[])(object)new Vector3[num]; bool[] array2 = new bool[num]; int[] array3 = new int[2 + 2 * num]; float[] array4 = new float[6 + 6 * num]; array3[0] = simState.viewId; array3[1] = num; Put(array4, 0, position); Put(array4, 3, forward); RaycastHit val3 = default(RaycastHit); for (int i = 0; i < num; i++) { Vector3 val = forward; if (component.gunRandomSpread > 0f) { float num3 = Random.Range(0f, component.gunRandomSpread / 2f); float num4 = Random.Range(0f, 360f); Vector3 val2 = Vector3.Cross(val, Random.onUnitSphere); Vector3 normalized = ((Vector3)(ref val2)).normalized; val2 = Quaternion.AngleAxis(num4, val) * Quaternion.AngleAxis(num3, normalized) * val; val = ((Vector3)(ref val2)).normalized; } int num5 = 0; int num6 = 0; Vector3 v = Vector3.zero; if (Physics.Raycast(position, val, ref val3, component.gunRange, num2)) { array[i] = ((RaycastHit)(ref val3)).point; array2[i] = true; num5 = 3; PhotonView val4 = (((Object)(object)((RaycastHit)(ref val3)).collider != (Object)null) ? ((Component)((RaycastHit)(ref val3)).collider).GetComponentInParent<PhotonView>() : null); if ((Object)(object)val4 != (Object)null && val4.ViewID != 0 && val4.ViewID != simState.viewId) { num6 = val4.ViewID; v = ((Component)val4).transform.InverseTransformPoint(((RaycastHit)(ref val3)).point); num5 |= 4; } } else { array[i] = position + forward * component.gunRange; num5 = 1; } array3[2 + 2 * i] = num5; array3[3 + 2 * i] = num6; Put(array4, 6 + 6 * i, array[i]); Put(array4, 9 + 6 * i, v); } PhotonNetwork.RaiseEvent((byte)189, (object)new object[2] { array3, array4 }, toHost, SendOptions.SendReliable); if (value == null) { value = new Pred(); preds[simState.viewId] = value; } value.time = unscaledTime; value.shootLeft = 1; value.bulletsLeft = num; value.cooldownUntil = unscaledTime + Mathf.Max(0.15f, component.shootCooldown) + 0.1f; PhotonMessageInfo val5 = default(PhotonMessageInfo); ((PhotonMessageInfo)(ref val5))..ctor(PhotonNetwork.MasterClient, PhotonNetwork.ServerTimestamp, component2); int num7 = (((Object)(object)PlayerAvatar.instance.photonView != (Object)null) ? PlayerAvatar.instance.photonView.ViewID : (-1)); predicting = true; try { component.ShootRPC(val5); for (int j = 0; j < num; j++) { component.ShootBulletRPC(array[j], true, num7, array2[j], val5); } } finally { predicting = false; } if (Plugin.VerboseLogging.Value) { Plugin.Log.LogInfo((object)string.Format("[shot] {0}: fired on our side ({1} bullet{2}), sent to the host", ((Object)component3).name, num, (num == 1) ? "" : "s")); } } catch (Exception ex) { predicting = false; if (Plugin.VerboseLogging.Value) { Plugin.Log.LogWarning((object)("[shot] local shot failed: " + ex.Message)); } } } private static Pred PredOf(ItemGun gun) { int num = ViewIdOf(gun); if (preds.Count == 0 || num == 0) { return null; } if (!preds.TryGetValue(num, out var value)) { return null; } if (Time.unscaledTime - value.time > 1.5f) { value.shootLeft = 0; value.bulletsLeft = 0; } return value; } internal static bool ConsumeShootEcho(ItemGun gun) { if (predicting) { return false; } Pred pred = PredOf(gun); if (pred == null || pred.shootLeft <= 0) { return false; } pred.shootLeft--; return true; } internal static bool ConsumeBulletEcho(ItemGun gun) { if (predicting) { return false; } Pred pred = PredOf(gun); if (pred == null || pred.shootLeft > 0 || pred.bulletsLeft <= 0) { return false; } pred.bulletsLeft--; return true; } internal static void OnHostDryFire(ItemGun gun) { Pred pred = PredOf(gun); if (pred != null) { if (pred.shootLeft > 0 && Plugin.VerboseLogging.Value) { Plugin.Log.LogInfo((object)("[shot] " + ((Object)gun).name + ": the host dry-fired instead of shooting (our shot was shown but did not happen)")); } pred.shootLeft = 0; pred.bulletsLeft = 0; } } private static int ViewIdOf(ItemGun gun) { PhotonView val = (((Object)(object)gun != (Object)null) ? ((Component)gun).GetComponent<PhotonView>() : null); if (!((Object)(object)val != (Object)null)) { return 0; } return val.ViewID; } private static void Put(float[] a, int i, Vector3 v) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) a[i] = v.x; a[i + 1] = v.y; a[i + 2] = v.z; } private static Vector3 Get(float[] a, int i) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) return new Vector3(a[i], a[i + 1], a[i + 2]); } internal static void OnShotEvent(EventData ev) { //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_017f: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) if (!PhotonNetwork.IsMasterClient || !HostAssist.HostServes || !(ev.CustomData is object[] array) || array.Length < 2 || !(array[0] is int[] array2) || !(array[1] is float[] array3) || array2.Length < 2) { return; } int key = array2[0]; int num = array2[1]; if (num < 1 || num > 32 || array2.Length != 2 + 2 * num || array3.Length != 6 + 6 * num) { return; } for (int i = 0; i < array3.Length; i++) { if (float.IsNaN(array3[i]) || float.IsInfinity(array3[i])) { return; } } Result result = new Result { actor = ev.Sender, time = Time.unscaledTime, origin = Get(array3, 0), fwd = Get(array3, 3), n = num, flags = new int[num], anchor = new int[num], end = (Vector3[])(object)new Vector3[num], local = (Vector3[])(object)new Vector3[num] }; float magnitude = ((Vector3)(ref result.fwd)).magnitude; if (!(magnitude < 0.5f) && !(magnitude > 1.5f)) { result.fwd /= magnitude; for (int j = 0; j < num; j++) { result.flags[j] = array2[2 + 2 * j]; result.anchor[j] = array2[3 + 2 * j]; result.end[j] = Get(array3, 6 + 6 * j); result.local[j] = Get(array3, 9 + 6 * j); } results[key] = result; } } internal static void HostShootBegin(ItemGun gun) { active = null; activeIndex = 0; int num = ((results.Count != 0) ? ViewIdOf(gun) : 0); if (num == 0 || !results.TryGetValue(num, out var value)) { return; } results.Remove(num); string text = Check(gun, value); if (text != null) { if (Plugin.VerboseLogging.Value) { Plugin.Log.LogInfo((object)("[shot] hosting: " + ((Object)gun).name + ": shooter's result refused (" + text + ") — using our own raycast")); } } else { active = value; } } internal static void HostShootEnd() { if (active != null && Plugin.VerboseLogging.Value) { Plugin.Log.LogInfo((object)$"[shot] hosting: {active.n} bullet(s) placed where the shooter (actor {active.actor}) aimed"); } active = null; activeIndex = 0; } private static string Check(ItemGun gun, Result r) { //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) if (!HostAssist.HostServes) { return "Host Assist off"; } if (!Refs()) { return "internals"; } if (Time.unscaledTime - r.time > 1f) { return "too old"; } PhysGrabObject component = ((Component)gun).GetComponent<PhysGrabObject>(); if ((Object)(object)component == (Object)null || !HostAssist.ActorHolds(component, r.actor)) { return "the sender does not hold it"; } ItemToggle component2 = ((Component)gun).GetComponent<ItemToggle>(); PlayerAvatar val = (((Object)(object)component2 != (Object)null) ? SemiFunc.PlayerAvatarGetFromPhotonID(togglePlayer.Invoke(component2)) : null); if ((Object)(object)val == (Object)null || (Object)(object)val.photonView == (Object)null || val.photonView.OwnerActorNr != r.actor) { return "someone else pulled the trigger"; } if (r.n > Mathf.Max(1, gun.numberOfBullets)) { return "too many bullets"; } if (!((Object)(object)gun.gunMuzzle == (Object)null)) { Vector3 val2 = gun.gunMuzzle.position - r.origin; if (!(((Vector3)(ref val2)).sqrMagnitude > 16f)) { float num = gun.gunRange + 1f; float num2 = gun.gunRandomSpread * 0.5f + 3f; for (int i = 0; i < r.n; i++) { Vector3 val3 = r.end[i] - r.origin; if (((Vector3)(ref val3)).sqrMagnitude > num * num) { return "hit out of range"; } if (((Vector3)(ref val3)).sqrMagnitude > 0.25f && Vector3.Angle(val3, r.fwd) > num2) { return "hit outside the spread"; } } return null; } } return "muzzle too far from our copy"; } internal static void HostBullet(ItemGun gun, ref Vector3 end, ref bool hit, ref bool surfaceHit) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) Result result = active; if (result == null || (Object)(object)gun == (Object)null || activeIndex >= result.n) { return; } int num = activeIndex++; Vector3 val = result.end[num]; if ((result.flags[num] & 4) != 0 && result.anchor[num] != 0) { PhotonView val2 = PhotonView.Find(result.anchor[num]); if ((Object)(object)val2 != (Object)null) { Vector3 val3 = ((Component)val2).transform.TransformPoint(result.local[num]); if (Fin(val3)) { Vector3 val4 = val3 - val; if (((Vector3)(ref val4)).sqrMagnitude <= 9f) { val = val3; } } } } if (Fin(val)) { end = val; hit = true; surfaceHit = (result.flags[num] & 2) != 0; } } } internal static class HostAssist { private struct Sample { public int t; public Vector3 pos; public Vector3 vel; public Vector3 angVel; public Quaternion rot; } private class Entry { public PhysGrabObject pgo; public int actor; public bool hostDriven; public readonly Sample[] buf = new Sample[32]; public int count; public float lastHeard; public float transit = float.NaN; public float jitter; public float interval = 40f; public int lastStamp; public bool hasStamp; public bool released; public float releasedAt; public bool hasFinal; public Sample final; public bool finalSleeping; public float finalArrived; public bool announced; public Collider[] objCols; public Collider[] bodyCols; public Collider[] pusherCols; public PhysGrabObjectImpactDetector det; public bool isCart; public float doneAt = -1f; public bool hasCmd; public Vector3 intendedVel; public Vector3 intendedAng; public float blockedUntil; public Vector3 postStepVel; public float postStepAt = -1f; } private const byte EventCode = 188; private const string Prop = "rsync"; private const int Protocol = 6; private const int StreamProtocol = 4; private const int ShotProtocol = 5; private const int MirrorProtocol = 6; internal const byte Held = 0; internal const byte Released = 1; internal const byte Final = 2; internal const byte Sleeping = 4; internal const byte Abort = 8; private const float MaxGap = 4f; private const float MaxSpeed = 30f; private const float Follow = 20f; private const float Stale = 0.35f; private const float Forget = 1.5f; private const int BufferSize = 32; private const float BlockedDv = 1f; private const float BlockedPush = 0.5f; private const float BlockedHold = 0.15f; private static FieldRef<PhysGrabObjectImpactDetector, Vector3> detPrevVel; private static FieldRef<PhysGrabObjectImpactDetector, Vector3> detPrevAng; private static FieldRef<PhysGrabObjectImpactDetector, Vector3> detPrevRaw; private static bool detFieldsTried; internal const float Tail = 4f; private static readonly HashSet<string> plainTypes = new HashSet<string> { "ValuableObject", "NotValuableObject", "ValuablePropSwitch", "ValuableExtracting", "ValuableDiscover", "ValuableDiscoverCustom", "ValuableDiscoverGraphic", "ValuableVolume", "ValuableVolumeDebugDisplay", "ValuablePills", "ValuableRattleSnake", "ValuableSprings", "ValuableSawBlade", "ValuableForeverCandle", "ValuableLevitationPotion", "ValuableSmallPotion", "ValuableDesertPopcornStand", "MoneyValuable", "MapValuable", "EnemyValuable", "EnemyValuableExplosion", "SurplusValuable", "PowerCrystalValuable", "ValuableCamera", "ValuableTeethBot", "ValuableDesertSnowGlobe", "ValuableEyeOfOrpigox", "CrystalBallValuable", "MusicalValuableLogic", "ValuableSpiderPotion", "FireExtinguisherValuable", "FlamethrowerValuable", "JackhammerValuable", "SnakeInACanValuable", "ValuableDesertBirdCage", "ValuableDesertZeroGravCrystal", "ValuableLovePotion", "ValuableDesertExplosiveTowerDynamite", "ValuableScale", "ValuableWizardCrystal", "ValuableDesertEnergyCrystalChunk" }; private static readonly HashSet<string> streamableTraps = new HashSet<string> { "FanTrap", "ClownTrap", "GrandfatherClockTrap", "TrapRadio", "TrapTV", "TrapGramophone", "MonkeyBox" }; private static readonly HashSet<string> plainItemTypes = new HashSet<string> { "ItemAttributes", "ItemEquippable", "ItemToggle", "ItemBattery", "ItemInfoUI", "ItemInfoExtraUI", "ItemDeactivatedUntilLevel", "ItemLight", "ItemDrone", "ItemDroneSounds", "ItemDroneTargetingCondition", "ItemDroneBattery", "ItemDroneFeather", "ItemDroneHeal", "ItemDroneIndestructible", "ItemDroneTorque", "ItemDroneZeroGravity", "ItemOrb", "ItemOrbZeroGravity", "ItemOrbFeather", "ItemOrbMagnet", "ItemOrbTorque", "ItemOrbIndestructible", "ItemOrbHeal", "ItemOrbBattery", "ItemGrenade", "ItemGrenadeExplosive", "ItemGrenadeStun", "ItemGrenadeShockwave", "ItemGrenadeDuctTaped", "ItemGrenadeHuman", "ItemVolume", "ItemHealthPack", "ItemWalkieBox", "ItemMine", "ItemMineExplosive", "ItemMineStun", "ItemMineTrigger", "ItemShockwave" }; private static readonly HashSet<string> selfMovingTypes = new HashSet<string> { "Larva", "MineCart", "RockSlideRock", "CosmeticWorldObject", "BotPhysicsController" }; private static readonly Dictionary<int, Entry> entries = new Dictionary<int, Entry>(); private static readonly List<int> dead = new List<int>(); private static readonly RaiseEventOptions toHost = new RaiseEventOptions { Receivers = (ReceiverGroup)2 }; private static bool hooked; private static float nextPropCheck; private static bool hostSupports; private static bool hostShots; private static bool hostMirror; private static bool announcedHost; private static bool announcedClient; internal static bool Active { get { if (On) { return hostSupports; } return false; } } internal static bool HostMirrors => hostMirror; internal static bool On { get { if (Plugin.HostAssistEnabled != null) { return Plugin.HostAssistEnabled.Value; } return false; } } internal static bool ShotsActive { get { if (On) { return hostShots; } return false; } } internal static bool HostServes { get { if (On) { return PhotonNetwork.IsMasterClient; } return false; } } private static int ProtocolOf(Player p) { if (p != null && ((Dictionary<object, object>)(object)p.CustomProperties).TryGetValue((object)"rsync", out object value) && value is int) { return (int)value; } return 0; } private static bool DetFields() { if (!detFieldsTried) { detFieldsTried = true; try { detPrevVel = AccessTools.FieldRefAccess<PhysGrabObjectImpactDetector, Vector3>("previousVelocity"); detPrevAng = AccessTools.FieldRefAccess<PhysGrabObjectImpactDetector, Vector3>("previousAngularVelocity"); detPrevRaw = AccessTools.FieldRefAccess<PhysGrabObjectImpactDetector, Vector3>("previousVelocityRaw"); } catch (Exception ex) { detPrevVel = null; Plugin.Log.LogWarning((object)("[assist] impact detector fields not found (" + ex.Message + ") — followed objects keep vanilla impact scoring")); } } return detPrevVel != null; } private static void TellDetector(Entry e) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) if (e.hasCmd && !((Object)(object)e.det == (Object)null) && DetFields()) { float fixedDeltaTime = Time.fixedDeltaTime; detPrevVel.Invoke(e.det) = e.intendedVel / fixedDeltaTime; detPrevAng.Invoke(e.det) = e.intendedAng / fixedDeltaTime; detPrevRaw.Invoke(e.det) = e.intendedVel; } } internal static void AfterImpactDetector(PhysGrabObjectImpactDetector det) { if (entries.Count == 0 || (Object)(object)det == (Object)null || !On || !PhotonNetwork.IsMasterClient) { return; } foreach (KeyValuePair<int, Entry> entry in entries) { Entry value = entry.Value; if ((Object)(object)value.det != (Object)(object)det || value.isCart) { continue; } if (value.doneAt != Time.fixedTime) { value.doneAt = Time.fixedTime; if (!Follow1(value)) { RemoveEntry(entry.Key); break; } } TellDetector(value); break; } } private static void IgnoreHolder(Entry e, PhysGrabber grabber) { if (!((Object)(object)grabber == (Object)null) && !((Object)(object)grabber.playerAvatar == (Object)null)) { if (e.objCols == null) { e.objCols = Solid(((Component)e.pgo).GetComponentsInChildren<Collider>(true)); e.bodyCols = Solid(((Component)grabber.playerAvatar).GetComponentsInChildren<Collider>(true)); PlayerPhysPusher playerPhysPusher = grabber.playerAvatar.playerPhysPusher; e.pusherCols = (Collider[])(((Object)(object)playerPhysPusher != (Object)null) ? ((Array)Solid(((Component)playerPhysPusher).GetComponentsInChildren<Collider>(true))) : ((Array)new Collider[0])); Pairs(e.objCols, e.bodyCols, ignore: true); } Pairs(e.objCols, e.pusherCols, ignore: true); } } private static Collider[] Solid(Collider[] all) { List<Collider> list = new List<Collider>(); foreach (Collider val in all) { if ((Object)(object)val != (Object)null && !val.isTrigger) { list.Add(val); } } return list.ToArray(); } private static void Pairs(Collider[] a, Collider[] b, bool ignore) { if (a == null || b == null) { return; } foreach (Collider val in a) { if ((Object)(object)val == (Object)null) { continue; } foreach (Collider val2 in b) { if (!((Object)(object)val2 == (Object)null)) { Physics.IgnoreCollision(val, val2, ignore); } } } } private static void SetIgnore(Entry e, bool ignore) { Pairs(e.objCols, e.bodyCols, ignore); Pairs(e.objCols, e.pusherCols, ignore); } private static void EndEntry(Entry e) { if (e != null && e.objCols != null) { SetIgnore(e, ignore: false); e.objCols = null; e.bodyCols = null; e.pusherCols = null; } } private static void RemoveEntry(int viewId) { if (entries.TryGetValue(viewId, out var value)) { EndEntry(value); } entries.Remove(viewId); } internal static bool For(SimManager.SimState st) { if (Active && st != null) { return !st.hostDriven; } return false; } internal static string HostDrivenReason(PhysGrabObject pgo, bool isCart) { if ((Object)(object)pgo == (Object)null || isCart) { return null; } if ((Object)(object)((Component)pgo).GetComponentInChildren<ItemGun>(true) != (Object)null || (Object)(object)((Component)pgo).GetComponentInChildren<ItemMelee>(true) != (Object)null) { return null; } MonoBehaviour[] componentsInChildren; if ((Object)(object)((Component)pgo).GetComponentInParent<ItemAttributes>() != (Object)null) { componentsInChildren = ((Component)pgo).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val in componentsInChildren) { if (!((Object)(object)val == (Object)null)) { string name = ((object)val).GetType().Name; if (name.StartsWith("Item") && !plainItemTypes.Contains(name) && (!name.StartsWith("ItemUpgrade") || name.EndsWith("Logic"))) { return name; } } } return null; } componentsInChildren = ((Component)pgo).GetComponentsInChildren<MonoBehaviour>(true); foreach (MonoBehaviour val2 in componentsInChildren) { if ((Object)(object)val2 == (Object)null) { continue; } string name2 = ((object)val2).GetType().Name; if (val2 is Trap && !streamableTraps.Contains(name2)) { return name2; } if (!plainTypes.Contains(name2) && !streamableTraps.Contains(name2)) { if (selfMovingTypes.Contains(name2)) { return name2; } if (name2.Contains("Valuable") || name2.StartsWith("Museum")) { return name2; } } } return null; } private static bool HeldByOtherThan(PhysGrabObject pgo, int actor) { List<PhysGrabber> playerGrabbing = pgo.playerGrabbing; for (int i = 0; i < playerGrabbing.Count; i++) { PhysGrabber val = playerGrabbing[i]; if ((Object)(object)val != (Object)null && (Object)(object)val.photonView != (Object)null && val.photonView.OwnerActorNr != actor) { return true; } } return false; } internal static bool ActorHolds(PhysGrabObject pgo, int actor) { if ((Object)(object)pgo != (Object)null) { return (Object)(object)GrabberOf(pgo, actor) != (Object)null; } return false; } internal static void FrameUpdate() { //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Expected O, but got Unknown //IL_00b3: Expected O, but got Unknown if (!Plugin.PhotonReady) { return; } if (!hooked) { hooked = true; PhotonNetwork.NetworkingClient.EventReceived += OnEvent; } if (Time.unscaledTime < nextPropCheck) { return; } nextPropCheck = Time.unscaledTime + 2f; hostSupports = false; hostShots = false; hostMirror = false; if (!PhotonNetwork.InRoom) { return; } Player localPlayer = PhotonNetwork.LocalPlayer; int num = (On ? 6 : 0); if (localPlayer != null && ProtocolOf(localPlayer) != num && (num != 0 || ((Dictionary<object, object>)(object)localPlayer.CustomProperties).ContainsKey((object)"rsync"))) { Hashtable val = new Hashtable(); ((Dictionary<object, object>)val).Add((object)"rsync", (object)num); localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null); } if (On) { Player masterClient = PhotonNetwork.MasterClient; hostSupports = masterClient != null && !masterClient.IsLocal && ProtocolOf(masterClient) >= 4; hostShots = hostSupports && ProtocolOf(masterClient) >= 5; hostMirror = hostSupports && ProtocolOf(masterClient) >= 6; if (hostSupports && !announcedClient) { announcedClient = true; Plugin.Log.LogInfo((object)"[assist] the host has NetworkingRefreshed — Host Assist is on: what you hold is streamed to it."); } } } internal static void ClientSend(SimManager.SimState st, byte flags, bool forceReliable = false) { //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Unknown result type (might be due to invalid IL or missing references) if (On && hostSupports && st != null && !((Object)(object)st.rb == (Object)null) && st.viewId != 0 && !st.isHinge && !st.hostDriven) { Rigidbody rb = st.rb; bool isKinematic = rb.isKinematic; object[] array = new object[7] { st.viewId, PhotonNetwork.ServerTimestamp, rb.position, rb.rotation, isKinematic ? Vector3.zero : rb.velocity, isKinematic ? Vector3.zero : rb.angularVelocity, flags }; bool flag = forceReliable || (flags != 0 && flags != 1); PhotonNetwork.RaiseEvent((byte)188, (object)array, toHost, flag ? SendOptions.SendReliable : SendOptions.SendUnreliable); } } private static void OnEvent(EventData ev) { //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_019c: Unknown result type (might be due to invalid IL or missing references) //IL_01a3: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Unknown result type (might be due to invalid IL or missing references) //IL_01c3: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_037d: Unknown result type (might be due to invalid IL or missing references) //IL_037f: Unknown result type (might be due to invalid IL or missing references) //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_0388: Unknown result type (might be due to invalid IL or missing references) //IL_038f: Unknown result type (might be due to invalid IL or missing references) //IL_0396: Unknown result type (might be due to invalid IL or missing references) //IL_039b: Unknown result type (might be due to invalid IL or missing references) //IL_03a2: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03ae: Unknown result type (might be due to invalid IL or missing references) if (ev.Code == 190) { try { PhysMirror.OnEvent(ev); return; } catch (Exception ex) { if (Plugin.VerboseLogging.Value) { Plugin.Log.LogWarning((object)("[physmirror] bad event: " + ex.Message)); } return; } } if (ev.Code == 189) { try { GunShots.OnShotEvent(ev); return; } catch (Exception ex2) { if (Plugin.VerboseLogging.Value) { Plugin.Log.LogWarning((object)("[shot] bad event: " + ex2.Message)); } return; } } if (ev.Code != 188 || !On || !PhotonNetwork.IsMasterClient) { return; } try { if (!(ev.CustomData is object[] array) || array.Length < 7 || !(array[0] is int num) || !(array[1] is int num2) || !(array[2] is Vector3 val) || !(array[3] is Quaternion val2) || !(array[4] is Vector3 val3) || !(array[5] is Vector3 val4) || !(array[6] is byte b) || !Finite(val) || !Finite(val3) || !Finite(val4) || float.IsNaN(val2.w)) { return; } float num3 = val2.x * val2.x + val2.y * val2.y + val2.z * val2.z + val2.w * val2.w; if (num3 < 0.8f || num3 > 1.2f) { return; } Quaternion rot = Quaternion.Normalize(val2); if ((b & 8) != 0) { if (entries.TryGetValue(num, out var value) && value.actor == ev.Sender) { RemoveEntry(num); } return; } if (!entries.TryGetValue(num, out var value2) || value2.actor != ev.Sender) { EndEntry(value2); PhotonView val5 = PhotonView.Find(num); PhysGrabObject val6 = (((Object)(object)val5 != (Object)null) ? ((Component)val5).GetComponent<PhysGrabObject>() : null); if ((Object)(object)val6 == (Object)null || (Object)(object)val6.rb == (Object)null) { return; } bool isCart = (Object)(object)((Component)val6).GetComponent<PhysGrabCart>() != (Object)null; value2 = new Entry { pgo = val6, actor = ev.Sender, hostDriven = (HostDrivenReason(val6, isCart) != null), isCart = isCart, det = ((Component)val6).GetComponent<PhysGrabObjectImpactDetector>() }; entries[num] = value2; if (!announcedHost) { announcedHost = true; Plugin.Log.LogInfo((object)"[assist] hosting: a client is streaming held objects — following them."); } } if (b == 0 && (value2.released || value2.hasFinal) && (!value2.hasStamp || num2 - value2.lastStamp > 0)) { value2.released = false; value2.hasFinal = false; value2.count = 0; value2.hasStamp = false; } if ((b & 1) != 0 && !value2.released) { value2.released = true; value2.releasedAt = Time.unscaledTime; } Sample sample = new Sample { t = num2, pos = val, rot = rot, vel = Vector3.ClampMagnitude(val3, 30f), angVel = Vector3.ClampMagnitude(val4, 30f) }; NoteTiming(value2, num2); Insert(value2, sample); value2.lastHeard = Time.unscaledTime; if ((b & 2) != 0) { value2.hasFinal = true; value2.final = sample; value2.finalSleeping = (b & 4) != 0; value2.finalArrived = Time.unscaledTime; value2.released = true; } } catch (Exception ex3) { if (Plugin.VerboseLogging.Value) { Plugin.Log.LogWarning((object)("[assist] bad event: " + ex3.Message)); } } } private static bool Finite(Vector3 v) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) if (!float.IsNaN(v.x) && !float.IsNaN(v.y) && !float.IsNaN(v.z) && !float.IsInfinity(v.x) && !float.IsInfinity(v.y)) { return !float.IsInfinity(v.z); } return false; } private static void NoteTiming(Entry e, int stamp) { float num = PhotonNetwork.ServerTimestamp - stamp; if (num > -200f && num < 2000f) { if (float.IsNaN(e.transit) || num < e.transit) { e.transit = num; } else { e.transit += (num - e.transit) * 0.01f; } e.jitter += (Mathf.Abs(num - e.transit) - e.jitter) * 0.1f; } if (e.hasStamp) { float num2 = stamp - e.lastStamp; if (num2 > 0f && num2 < 500f) { e.interval += (num2 - e.interval) * 0.1f; } } if (!e.hasStamp || stamp - e.lastStamp > 0) { e.lastStamp = stamp; e.hasStamp = true; } } private static void Insert(Entry e, Sample s) { int num = e.count; while (num > 0 && e.buf[num - 1].t - s.t > 0) { num--; } if (num > 0 && e.buf[num - 1].t == s.t) { e.buf[num - 1] = s; return; } if (e.count == 32) { if (num == 0) { return; } Array.Copy(e.buf, 1, e.buf, 0, 31); e.count--; num--; } Array.Copy(e.buf, num, e.buf, num + 1, e.count - num); e.buf[num] = s; e.count++; } private static int RenderStamp(Entry e) { float num = Mathf.Clamp(e.interval + 2f * e.jitter, 30f, 150f); float num2 = (float.IsNaN(e.transit) ? 0f : e.transit) + num; return PhotonNetwork.ServerTimestamp - Mathf.RoundToInt(num2); } private static bool StateAt(Entry e, int t, out Vector3 pos, out Quaternion rot, out Vector3 vel, out Vector3 angVel) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_022c: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_0242: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0266: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0270: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_028a: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_0299: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) //IL_02ab: Unknown result type (might be due to invalid IL or missing references) //IL_02b0: Unknown result type (might be due to invalid IL or missing references) //IL_02b5: Unknown result type (might be due to invalid IL or missing references) //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_02ed: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: Unknown result type (might be due to invalid IL or missing references) //IL_02fb: Unknown result type (might be due to invalid IL or missing references) //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_0310: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) pos = Vector3.zero; rot = Quaternion.identity; vel = Vector3.zero; angVel = Vector3.zero; if (e.count == 0) { return false; } Sample sample = e.buf[0]; if (e.count == 1 || t - sample.t <= 0) { pos = sample.pos; rot = sample.rot; vel = sample.vel; angVel = sample.angVel; return true; } Sample sample2 = e.buf[e.count - 1]; int num = t - sample2.t; if (num >= 0) { float num2 = (float)Mathf.Min(num, 100) / 1000f; pos = sample2.pos + sample2.vel * num2; float num3 = ((Vector3)(ref sample2.angVel)).magnitude * num2 * 57.29578f; rot = ((num3 > 0.01f) ? (Quaternion.AngleAxis(num3, ((Vector3)(ref sample2.angVel)).normalized) * sample2.rot) : sample2.rot); vel = sample2.vel; angVel = sample2.angVel; return true; } int i; for (i = 1; i < e.count - 1 && e.buf[i].t - t < 0; i++) { } Sample sample3 = e.buf[i - 1]; Sample sample4 = e.buf[i]; float num4 = (float)(sample4.t - sample3.t) / 1000f; float num5 = ((num4 > 0.0001f) ? Mathf.Clamp01((float)(t - sample3.t) / 1000f / num4) : 1f); float num6 = num5 * num5; float num7 = num6 * num5; float num8 = 2f * num7 - 3f * num6 + 1f; float num9 = num7 - 2f * num6 + num5; float num10 = -2f * num7 + 3f * num6; float num11 = num7 - num6; pos = num8 * sample3.pos + num9 * num4 * sample3.vel + num10 * sample4.pos + num11 * num4 * sample4.vel; Vector3 val = Vector3.Lerp(sample3.pos, sample4.pos, num5); Vector3 val2 = pos - val; float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude; val2 = sample4.pos - sample3.pos; if (sqrMagnitude > ((Vector3)(ref val2)).sqrMagnitude + 0.04f) { pos = val; } rot = Quaternion.Slerp(sample3.rot, sample4.rot, num5); vel = Vector3.Lerp(sample3.vel, sample4.vel, num5); angVel = Vector3.Lerp(sample3.angVel, sample4.angVel, num5); return true; } private static PhysGrabber GrabberOf(PhysGrabObject pgo, int actor) { List<PhysGrabber> playerGrabbing = pgo.playerGrabbing; for (int i = 0; i < playerGrabbing.Count; i++) { PhysGrabber val = playerGrabbing[i]; if ((Object)(object)val != (Object)null && (Object)(object)val.photonView != (Object)null && val.photonView.OwnerActorNr == actor) { return val; } } return null; } internal static void HostTick() { PhysMirror.HostTick(); if (entries.Count == 0) { return; } if (!On || !PhotonNetwork.IsMasterClient) { foreach (Entry value2 in entries.Values) { EndEntry(value2); } entries.Clear(); return; } dead.Clear(); float fixedTime = Time.fixedTime; foreach (KeyValuePair<int, Entry> entry in entries) { Entry value = entry.Value; if (value.doneAt != fixedTime && (value.isCart || !((Object)(object)value.det != (Object)null) || !((Behaviour)value.det).isActiveAndEnabled || !(fixedTime - value.doneAt <= Time.fixedDeltaTime * 1.5f))) { value.doneAt = fixedTime; if (!Follow1(value)) { dead.Add(entry.Key); } } } foreach (int item in dead) { RemoveEntry(item); } } internal static void AfterCartSteer(PhysGrabCart cart) { if (entries.Count == 0 || (Object)(object)cart == (Object)null || !On || !PhotonNetwork.IsMasterClient) { return; } foreach (KeyValuePair<int, Entry> entry in entries) { Entry value = entry.Value; if ((Object)(object)value.pgo != (Object)null && (Object)(object)((Component)value.pgo).gameObject == (Object)(object)((Component)cart).gameObject) { value.doneAt = Time.fixedTime; if (!Follow1(value)) { RemoveEntry(entry.Key); } break; } } } internal static void BeforeCartSteer(PhysGrabCart cart) { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) if (entries.Count == 0 || (Object)(object)cart == (Object)null || !On || !PhotonNetwork.IsMasterClient) { return; } foreach (Entry value in entries.Values) { if ((Object)(object)value.pgo != (Object)null && (Object)(object)value.pgo.rb != (Object)null && (Object)(object)((Component)value.pgo).gameObject == (Object)(object)((Component)cart).gameObject) { value.postStepVel = value.pgo.rb.velocity; value.postStepAt = Time.fixedTime; break; } } } private static bool Follow1(Entry e) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Unknown result type (might be due to invalid IL or missing references) //IL_0196: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01cf: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0221: Unknown result type (might be due to invalid IL or missing references) //IL_0202: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) //IL_0206: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_0247: Unknown result type (might be due to invalid IL or missing references) //IL_024e: Unknown result type (might be due to invalid IL or missing references) //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_0256: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Unknown result type (might be due to invalid IL or missing references) //IL_023a: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02cb: Unknown result type (might be due to invalid IL or missing references) //IL_02cd: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Unknown result type (might be due to invalid IL or missing references) //IL_02e8: Unknown result type (might be due to invalid IL or missing references) //IL_0295: Unknown result type (might be due to invalid IL or missing references) //IL_02a3: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) float unscaledTime = Time.unscaledTime; bool hasCmd = e.hasCmd; Vector3 intendedVel = e.intendedVel; e.hasCmd = false; if ((Object)(object)e.pgo == (Object)null || (Object)(object)e.pgo.rb == (Object)null || e.hostDriven) { return false; } Rigidbody rb = e.pgo.rb; if (e.hasFinal && (RenderStamp(e) - e.final.t >= 0 || unscaledTime - e.finalArrived > 1f)) { Land(e, rb); return false; } if (unscaledTime - e.lastHeard > 1.5f) { return false; } if (unscaledTime - e.lastHeard > 0.35f && !e.hasFinal) { return true; } if (rb.isKinematic) { return !e.released; } PhysGrabber val = GrabberOf(e.pgo, e.actor); if ((Object)(object)val == (Object)null) { if (!e.released) { return true; } if (e.pgo.playerGrabbing.Count > 0 || unscaledTime - e.releasedAt > 5f) { return false; } } if (HeldByOtherThan(e.pgo, e.actor)) { return true; } int t = RenderStamp(e) + Mathf.RoundToInt(Time.fixedDeltaTime * 1000f); if (!StateAt(e, t, out var pos, out var rot, out var vel, out var angVel)) { return true; } Vector3 val2 = pos - rb.position; if (((Vector3)(ref val2)).sqrMagnitude > 16f) { return true; } if ((Object)(object)val != (Object)null) { val.OverridePhysGrabForcesDisable(0.1f); IgnoreHolder(e, val); } Vector3 val3 = Vector3.ClampMagnitude(vel + val2 * 20f, 30f); Vector3 val4 = ((e.isCart && e.postStepAt == Time.fixedTime) ? e.postStepVel : rb.velocity); if (hasCmd) { Vector3 val5 = val4 - intendedVel; if (((Vector3)(ref val5)).magnitude > 1f) { e.blockedUntil = unscaledTime + 0.15f; } } if (unscaledTime < e.blockedUntil) { val3 = val4 + Vector3.ClampMagnitude(val3 - val4, 0.5f); } e.intendedVel = val3; if (rb.useGravity) { val3 -= Physics.gravity * Time.fixedDeltaTime; } rb.velocity = val3; Quaternion val6 = rot * Quaternion.Inverse(rb.rotation); float num = default(float); Vector3 val7 = default(Vector3); ((Quaternion)(ref val6)).ToAngleAxis(ref num, ref val7); if (num > 180f) { num -= 360f; } Vector3 val8 = Vector3.zero; if (Mathf.Abs(num) > 0.01f && !float.IsNaN(val7.x) && !float.IsInfinity(val7.x)) { val8 = val7 * (num * ((float)Math.PI / 180f) * 20f); } rb.angularVelocity = Vector3.ClampMagnitude(angVel + val8, 30f); e.intendedAng = rb.angularVelocity; e.hasCmd = true; if (!e.announced && Plugin.VerboseLogging.Value) { e.announced = true; Plugin.Log.LogInfo((object)($"[assist] hosting: following {((Object)e.pgo).name} (actor {e.actor}) " + $"{(float.IsNaN(e.transit) ? 0f : e.transit):F0}ms transit + {Mathf.Clamp(e.interval + 2f * e.jitter, 30f, 150f):F0}ms cushion")); } return true; } private static void Land(Entry e, Rigidbody rb) { //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) if (rb.isKinematic || (e.pgo.playerGrabbing.Count > 0 && (Object)(object)GrabberOf(e.pgo, e.actor) == (Object)null)) { return; } float num = Vector3.Distance(rb.position, e.final.pos); float num2 = Quaternion.Angle(rb.rotation, e.final.rot); if (!(num > 4f)) { rb.position = e.final.pos; rb.rotation = e.final.rot; ((Component)e.pgo).transform.SetPositionAndRotation(e.final.pos, e.final.rot); rb.velocity = e.final.vel; rb.angularVelocity = e.final.angVel; if (e.finalSleeping) { rb.Sleep(); } e.intendedVel = e.final.vel; e.intendedAng = e.final.angVel; e.hasCmd = true; TellDetector(e); if (Plugin.VerboseLogging.Value) { Plugin.Log.LogInfo((object)("[assist] hosting: " + ((Object)e.pgo).name + " landed on the holder's final pose " + $"({num * 100f:F0}cm / {num2:F0} deg from the replay)")); } } } } internal static class PhysMirror { private struct Sent { public byte f; public float m; public float d; public float a; } internal const byte EventCode = 190; internal const byte FMass = 1; internal const byte FDrag = 2; internal const byte FAngDrag = 4; internal const byte FNoGravity = 8; private static FieldRef<PhysGrabObject, float> tMass; private static FieldRef<PhysGrabObject, float> tDrag; private static FieldRef<PhysGrabObject, float> tAng; private static FieldRef<PhysGrabObject, float> tZeroG; private static FieldRef<RoundDirector, List<PhysGrabObject>> rdObjects; private static bool tried; private static bool ok; private static readonly Dictionary<int, Sent> sent = new Dictionary<int, Sent>(); private static readonly HashSet<int> seen = new HashSet<int>(); private static readonly List<int> stale = new List<int>(); private static readonly List<int> outIds = new List<int>(); private static readonly List<byte> outFlags = new List<byte>(); private static readonly List<float> outVals = new List<float>(); private static float nextScan; private static float nextFull; private static bool announced; private static readonly Dictionary<PhysGrabObject, int> viewIds = new Dictionary<PhysGrabObject, int>(); private static bool Init() { if (tried) { return ok; } tried = true; try { tMass = AccessTools.FieldRefAccess<PhysGrabObject, float>("timerAlterMass"); tDrag = AccessTools.FieldRefAccess<PhysGrabObject, float>("timerAlterDrag"); tAng = AccessTools.FieldRefAccess<PhysGrabObject, float>("timerAlterAngularDrag"); tZeroG = AccessTools.FieldRefAccess<PhysGrabObject, float>("timerZeroGravity"); rdObjects = AccessTools.FieldRefAccess<RoundDirector, List<PhysGrabObject>>("physGrabObjects"); ok = true; } catch (Exception ex) { ok = false; Plugin.Log.LogWarning((object)("[physmirror] disabled (game internals changed): " + ex.Message)); } return ok; } internal static void HostTick() { //IL_03a8: Unknown result type (might be due to invalid IL or missing references) //IL_03ad: Unknown result type (might be due to invalid IL or missing references) //IL_03af: Unknown result type (might be due to invalid IL or missing references) //IL_03b4: Unknown result type (might be due to invalid IL or missing references) //IL_03be: Expected O, but got Unknown if (!HostAssist.On || !PhotonNetwork.IsMasterClient || !PhotonNetwork.InRoom || PhotonNetwork.CurrentRoom == null || PhotonNetwork.CurrentRoom.PlayerCount < 2) { if (sent.Count > 0) { sent.Clear(); } return; } float unscaledTime = Time.unscaledTime; if (unscaledTime < nextScan) { return; } nextScan = unscaledTime + 0.1f; if (!Init()) { return; } RoundDirector instance = RoundDirector.instance; List<PhysGrabObject> list = (((Object)(object)instance != (Object)null) ? rdObjects.Invoke(instance) : null); if (list == null) { return; } bool flag = unscaledTime >= nextFull; if (flag) { nextFull = unscaledTime + 2f; } outIds.Clear(); outFlags.Clear(); outVals.Clear(); seen.Clear(); for (int i = 0; i < list.Count; i++) { PhysGrabObject val = list[i]; if ((Object)(object)val == (Object)null || (Object)(object)val.rb == (Object)null) { continue; } int num = ViewIdOf(val); if (num == 0) { continue; } byte b = 0; if (tMass.Invoke(val) > 0f) { b |= 1; } if (tDrag.Invoke(val) > 0f) { b |= 2; } if (tAng.Invoke(val) > 0f) { b |= 4; } if (tZeroG.Invoke(val) > 0f) { b |= 8; } Sent value; bool flag2 = sent.TryGetValue(num, out value); if (b == 0) { if (flag2) { Add(num, 0, 0f, 0f, 0f); sent.Remove(num); } continue; } seen.Add(num); Rigidbody rb = val.rb; float mass = rb.mass; float linearDamping = rb.linearDamping; float angularDamping = rb.angularDamping; if (!flag2 || value.f != b || Mathf.Abs(value.m - mass) > 0.01f || Mathf.Abs(value.d - linearDamping) > 0.01f || Mathf.Abs(value.a - angularDamping) > 0.01f || flag) { Add(num, b, mass, linearDamping, angularDamping); sent[num] = new Sent { f = b, m = mass, d = linearDamping, a = angularDamping }; } } if (flag && sent.Count > seen.Count) { stale.Clear(); foreach (int key in sent.Keys) { if (!seen.Contains(key)) { stale.Add(key); } } foreach (int item in stale) { Add(item, 0, 0f, 0f, 0f); sent.Remove(item); } } if (outIds.Count != 0) { PhotonNetwork.RaiseEvent((byte)190, (object)new object[3] { outIds.ToArray(), outFlags.ToArray(), outVals.ToArray() }, new RaiseEventOptions { Receivers = (ReceiverGroup)0 }, SendOptions.SendReliable); if (!announced && Plugin.VerboseLogging.Value) { announced = true; Plugin.Log.LogInfo((object)$"[physmirror] hosting: sharing physics overrides with clients (first batch: {outIds.Count} object(s))"); } } } private static int ViewIdOf(PhysGrabObject pgo) { if (viewIds.TryGetValue(pgo, out var value)) { return value; } if (viewIds.Count > 2048) { viewIds.Clear(); } PhotonView component = ((Component)pgo).GetComponent<PhotonView>(); value = (((Object)(object)component != (Object)null && (Object)(object)((Component)pgo).GetComponent<PhysGrabHinge>() == (Object)null) ? component.ViewID : 0); viewIds[pgo] = value; return value; } private static void Add(int id, byte f, float m, float d, float a) { outIds.Add(id); outFlags.Add(f); outVals.Add(m); outVals.Add(d); outVals.Add(a); } internal static void OnEvent(EventData ev) { if (PhotonNetwork.IsMasterClient) { return; } Player masterClient = PhotonNetwork.MasterClient; if (masterClient == null || ev.Sender != masterClient.ActorNumber || !(ev.CustomData is object[] array) || array.Length < 3 || !(array[0] is int[] array2) || !(array[1] is byte[] array3) || !(array[2] is float[] array4) || array3.Length != array2.Length || array4.Length != array2.Length * 3) { return; } for (int i = 0; i < array2.Length; i++) { float num = array4[i * 3]; float num2 = array4[i * 3 + 1]; float num3 = array4[i * 3 + 2]; if (!float.IsNaN(num) && !float.IsInfinity(num) && !float.IsNaN(num2) && !float.IsInfinity(num2) && !float.IsNaN(num3) && !float.IsInfinity(num3)) { PhotonView val = PhotonView.Find(array2[i]); PhysGrabObject val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<PhysGrabObject>() : null); if (!((Object)(object)val2 == (Object)null)) { SimManager.SetHostParams(val2, array3[i], Mathf.Max(num, 0.01f), Mathf.Max(num2, 0f), Mathf.Max(num3, 0f)); } } } } } [BepInPlugin("com.Revival.revivalsync", "NetworkingRefreshed", "1.9.6")] public class Plugin : BaseUnityPlugin { public const string PluginGuid = "com.Revival.revivalsync"; public const string PluginName = "NetworkingRefreshed"; public const string PluginVersion = "1.9.6"; internal static ManualLogSource Log; internal static ConfigEntry<bool> SimulateCarts; internal static ConfigEntry<bool> SimulateHinges; internal static ConfigEntry<bool> SimulateItems; internal static ConfigEntry<bool> InstantWeapons; internal static ConfigEntry<bool> InstantCartHandle; internal static ConfigEntry<float> PassiveSyncStrength; internal static ConfigEntry<float> PostThrowGrace; internal static ConfigEntry<float> SnapDistance; internal static ConfigEntry<float> HeldDriftHandbackAt; internal static ConfigEntry<bool> DisableTimeout; internal static ConfigEntry<bool> PhotonLateUpdate; internal static ConfigEntry<bool> SmoothSync; internal static ConfigEntry<bool> TrajectoryMatching; internal static ConfigEntry<bool> ResetToDefaults; internal static ConfigEntry<bool> HostAssistEnabled; private static bool resetting; internal static ConfigEntry<bool> Extrapolate; internal static ConfigEntry<float> Future; internal static ConfigEntry<float> RateSmoothing; internal static ConfigEntry<float> TimingThreshold; internal static ConfigEntry<bool> VerboseLogging; internal static ConfigEntry<string> ResyncKey; internal static ConfigEntry<float> AutoResyncSeconds; private static string resyncKeyRaw; private static KeyCode resyncKeyCode = (KeyCode)289; internal static bool PhotonReady; private static Harmony harmony; private static bool capturePatched; private static string sessionLogPath; private static float nextLogArchive; internal static KeyCode ResyncKeyCode { get { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) string text = ResyncKey?.Value; if (text != resyncKeyRaw) { resyncKeyRaw = text; resyncKeyCode = ParseKey(text); Log.LogInfo((object)$"Resync key set to {resyncKeyCode} (from \"{text}\")."); } return resyncKeyCode; } } private static KeyCode ParseKey(string raw) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_044e: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrWhiteSpace(raw)) { return (KeyCode)0; } string text = raw.Trim(); if (Enum.TryParse<KeyCode>(text, ignoreCase: true, out KeyCode result) && Enum.IsDefined(typeof(KeyCode), result)) { return result; } switch (text.ToLowerInvariant().Replace(" ", "")) { case "none": case "off": case "disabled": return (KeyCode)0; case "spacebar": case "space": return (KeyCode)32; case "esc": return (KeyCode)27; case "enter": case "return": return (KeyCode)13; case "del": return (KeyCode)127; case "ins": return (KeyCode)277; case "ctrl": case "leftctrl": case "lctrl": case "control": return (KeyCode)306; case "rctrl": case "rightctrl": return (KeyCode)305; case "lalt": case "alt": case "leftalt": return (KeyCode)308; case "shift": case "lshift": case "leftshift": return (KeyCode)304; case "middlemouse": case "mousemiddle": return (KeyCode)325; case "rightmouse": return (KeyCode)324; case "leftmouse": return (KeyCode)323; default: { if (text.Length == 1 && text[0] >= '0' && text[0] <= '9' && Enum.TryParse<KeyCode>("Alpha" + text, out KeyCode result2)) { return result2; } Log.LogWarning((object)("Resync key \"" + raw + "\" is not a recognized key name — resync key disabled. Try a name like F8, K, Mouse3 or None.")); return (KeyCode)0; } } } internal static void EnsureCapturePatch() { if (capturePatched || !PhotonReady || harmony == null) { return; } capturePatched = true; try { harmony.PatchAll(typeof(SerializeReadCapturePatch)); Log.LogInfo((object)"Host-state capture hooked (deferred until Photon start)."); } catch (Exception arg) { Log.LogError((object)$"Failed to hook host-state capture: {arg}"); } } private void Awake() { //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Expected O, but got Unknown //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Expected O, but got Unknown //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01e1: Expected O, but got Unknown //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Expected O, but got Unknown //IL_0251: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Expected O, but got Unknown //IL_02ee: Unknown result type (might be due to invalid IL or missing references) //IL_02f8: Expected O, but got Unknown //IL_032b: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Expected O, but got Unknown //IL_0368: Unknown result type (might be due to invalid IL or missing references) //IL_0372: Expected O, but got Unknown //IL_03f6: Unknown result type (might be due to invalid IL or missing references) //IL_0400: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; SimulateCarts = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Main", "Instant Carts", true, "Carts respond the moment you grab and push them, no waiting on the host. Only turn this off if carts misbehave for you. Changes apply from the next level."); SimulateHinges = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Main", "Instant Doors", true, "Doors and cabinets swing the moment you touch them, no waiting on the host. Only turn this off if doors misbehave for you. Takes full effect on the next game launch."); SimulateItems = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Main", "Instant Items", true, "Grenades, tools and gadgets follow your hand instantly and fly the way you throw them. Damage and explosions are still decided by the host, like normal. Vehicles, switched-on drones and the duck always use the game's normal sync (they move themselves). Only turn this off if an item misbehaves for you. Changes apply from the next level."); InstantWeapons = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Main", "Instant Weapons", true, "Guns and melee weapons follow your hand instantly: the game's own aiming, turning and swinging runs on your side for the weapon you hold. With a host that also has NetworkingRefreshed (or RevivalSync 1.8+) with Host Assist on, pistol, shotgun and tranq gun shots fire the moment you press and hit what you aimed at; the host still checks every shot and applies the damage. OFF = weapons use the game's normal sync (always correct, but with the usual delay in your hand). Needs Instant Items on. Changes apply from the next level."); DisableTimeout = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Main", "No Timeout Kicks", true, "Stops the game from kicking you out of the lobby during short lag spikes."); ResyncKey = ((BaseUnityPlugin)this).Config.Bind<string>("1. Main", "Resync Loot Key", "F8", "Emergency desync fix: press this key to instantly teleport every synced object to exactly where the host sees it. Type any key name here, for example: F8, K, Mouse3, Keypad5, LeftAlt, Backspace. Set it to None to turn the key off."); AutoResyncSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("1. Main", "Auto Resync Seconds", 0f, new ConfigDescription("0 = off. If set, automatically performs the Resync Loot teleport every this many seconds, so you never have to press the key yourself.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 120f), Array.Empty<object>())); TrajectoryMatching = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Main", "Trajectory Matching (experimental)", false, "Thrown items and carts you push follow the host's path while they move, instead of flying on your screen alone and then settling where the host has them. Turn it on and off in the same session to compare. Takes effect on your next throw."); HostAssistEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Main", "Host Assist", true, "Automatic: switches itself on whenever the host also has NetworkingRefreshed (or RevivalSync). What you hold is sent straight to the host, so the host's copy follows yours instead of trailing behind, and throws fly the same on every screen. With a host that does not have the mod nothing changes. When you host, it lets your friends' carts and loot do the same. Turn this OFF to force it off."); SmoothSync = ((BaseUnityPlugin)this).Config.Bind<bool>("1. Main", "Smooth Enemies", true, "Enemies and other host-controlled things move smoothly instead of stuttering. Takes effect on the next game launch."); PassiveSyncStrength = ((BaseUnityPlugin)this).Config.Bind<float>("2. Fine-Tuning (defaults are good)", "World Sync Strength", 0.075f, new ConfigDescription("How firmly the world is pulled toward what the host sees. Higher = tighter sync but harsher corrections, lower = gentler but objects drift longer.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.01f, 0.5f), Array.Empty<object>())); PostThrowGrace = ((BaseUnityPlugin)this).Config.Bind<float>("2. Fine-Tuning (defaults are good)", "Throw Freedom Seconds", 0.6f, new ConfigDescription("How long a thrown object flies purely on your screen before syncing takes over again.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>())); SnapDistance = ((BaseUnityPlugin)this).Config.Bind<float>("2. Fine-Tuning (defaults are good)", "Teleport Distance", 6f, new ConfigDescription("If an object ends up further than this many meters from where the host has it, it teleports there instead of gliding. Do NOT set this low: a cart you are steering naturally rides up to ~3m from the host's copy, so a low value makes it teleport constantly — through you and scattering its loot. 6 is the sweet spot.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(4f, 30f), Array.Empty<object>())); HeldDriftHandbackAt = ((BaseUnityPlugin)this).Config.Bind<float>("2. Fine-Tuning (defaults are good)", "Held Object Give Up At", 4f, new ConfigDescription("While you hold something: if it stays further off than this many meters (e.g. the host's copy got stuck), control returns to the host until you grab it again.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 20f), Array.Empty<object>())); InstantCartHandle = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Fine-Tuning (defaults are good)", "Instant Cart Handle", true, "Cart handle grabs register on your machine right away instead of waiting for the host."); PhotonLateUpdate = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Fine-Tuning (defaults are good)", "Process Packets Every Frame", true, "Handles network data every rendered frame instead of every physics tick. Lower felt latency."); Extrapolate = ((BaseUnityPlugin)this).Config.Bind<bool>("2. Fine-Tuning (defaults are good)", "Smooth Enemies - Extrapolate", true, "Keep enemies moving on a predicted path for a moment when an update arrives late."); Future = ((BaseUnityPlugin)this).Config.Bind<float>("2. Fine-Tuning (defaults are good)", "Smooth Enemies - Look Ahead", 1f, new ConfigDescription("How far ahead of the received data enemies are projected, in update intervals.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>())); RateSmoothing = ((BaseUnityPlugin)this).Config.Bind<float>("2. Fine-Tuning (defaults are good)", "Smooth Enemies - Rate Adapt", 0.1f, new ConfigDescription("How quickly the measured update rate adapts. Leave at 0.1 — high values make enemies jitter with every network wobble.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); TimingThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("2. Fine-Tuning (defaults are good)", "Smooth Enemies - Gap Seconds", 1f, new ConfigDescription("A silence longer than this many seconds counts as a gap instead of movement to smooth over.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 5f), Array.Empty<object>())); VerboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Debug", "Verbose Logging", false, "Records everything the mod does into BepInEx/LogOutput.log. Turn this ON before reporting a bug and include that file with the report."); ResetToDefaults = ((BaseUnityPlugin)this).Config.Bind<bool>("3. Debug", "Reset All Settings To Default", false, "Turn this ON to put every NetworkingRefreshed setting back to its default. It switches itself back OFF once done. (REPOConfig's own \"Reset To Default\" button does the same; its \"Revert\" button only undoes changes you have not saved yet.)"); ResetToDefaults.SettingChanged += delegate { ResetAllSettings(); }; ResetAllSettings(); if (!SimManager.InitAccessors()) { Log.LogError((object)"NetworkingRefreshed could not find expected game internals (the game probably updated). The mod has disabled itself to avoid breaking your game."); ((Behaviour)this).enabled = false; return; } harmony = new Harmony("com.Revival.revivalsync"); int num = 0; int num2 = 0; Type[] array = new Type[25] { typeof(DriverHooksPatch), typeof(PhotonHandlerAwakePatch), typeof(HingeJointKeeperPatch), typeof(HingePushPatch), typeof(HingeImpulsePredictPatch), typeof(HostAssistCartPatch), typeof(PhysGrabObjectStartPatch), typeof(GrabStartedPatch), typeof(GrabEndedPatch), typeof(GrabPlayerAddDedupePatch), typeof(TransformViewUpdatePatch), typeof(TransformViewSerializePatch), typeof(CartAuthorityPatch), typeof(WeaponAuthorityPatch), typeof(MeleeScrollSwingPatch), typeof(MeleeScrollSwingReceivePatch), typeof(GunShotPatch), typeof(ToggleClaimLogPatch), typeof(UpgradeCreditLogPatch), typeof(DestroyLogPatch), typeof(HostAssistImpactPatch), typeof(DeadObjectGrabPrunePatch), typeof(DeadHingeDiagPatch), typeof(SemiAffectTrackPatch), typeof(DroneCarryPatch) }; foreach (Type type in array) { try { harmony.PatchAll(type); num++; } catch (Exception arg) { num2++; Log.LogError((object)$"Failed to apply patch {type.Name}: {arg}"); } } if (SmoothSync.Value && Smoothing.InitAccessors()) { try { harmony.PatchAll(typeof(Smoothing.SerializePatch)); harmony.PatchAll(typeof(Smoothing.UpdatePatch)); harmony.PatchAll(typeof(Smoothing.TeleportPatch)); harmony.PatchAll(typeof(Smoothing.EnablePatch)); Smoothing.Active = true; } catch (Exception arg2) { Log.LogError((object)$"Failed to apply SmoothSync patches, interpolation disabled: {arg2}"); } } if (num == 0) { Log.LogError((object)"No patches could be applied — NetworkingRefreshed is inactive."); ((Behaviour)this).enabled = false; return; } Log.LogInfo((object)(string.Format("{0} {1} loaded. Patches: {2} ok, {3} failed. ", "NetworkingRefreshed", "1.9.6", num, num2) + $"SmoothSync: {Smoothing.Active}. Prediction activates when you join someone else's lobby; " + "while hosting, only Host Assist runs.")); } private void ResetAllSettings() { if (resetting || ResetToDefaults == null || !ResetToDefaults.Value) { return; } resetting = true; bool saveOnConfigSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet; try { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = false; foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in (IEnumerable<KeyValuePair<ConfigDefinition, ConfigEntryBase>>)((BaseUnityPlugin)this).Config) { item.Value.BoxedValue = item.Value.DefaultValue; } Log.LogInfo((object)"All NetworkingRefreshed settings were reset to their defaults."); } finally { ((BaseUnityPlugin)this).Config.SaveOnConfigSet = saveOnConfigSet; ((BaseUnityPlugin)this).Config.Save(); resetting = false; } } private void Update() { SimDriver.FrameUpdate(); } private void FixedUpdate() { SimManager.Tick(); } private void OnDestroy() { SimManager.RestoreAll(); ArchiveSessionLog(force: true); } internal static void ArchiveSessionLog(bool force = false) { try { if (!force && Time.unscaledTime < nextLogArchive) { return; } nextLogArchive = Time.unscaledTime + 60f; string text = Path.Combine(Paths.BepInExRootPath, "LogOutput.log"); if (!File.Exists(text)) { return; } if (sessionLogPath == null) { string text2 = Path.Combine(Paths.BepInExRootPath, "NetworkingRefreshed-logs"); Directory.CreateDirectory(text2); sessionLogPath = Path.Combine(text2, $"session-{DateTime.Now:yyyyMMdd-HHmmss}.log"); FileInfo[] files = new DirectoryInfo(text2).GetFiles("session-*.log"); Array.Sort(files, (FileInfo a, FileInfo b) => string.CompareOrdinal(b.Name, a.Name)); for (int num = 9; num < files.Length; num++) { files[num].Delete(); } } File.Copy(text, sessionLogPath, overwrite: true); } catch { } } internal static void ApplyPhotonSettings() { if (!PhotonReady) { return; } try { if (PhotonLateUpdate.Value) { PhotonNetwork.MinimalTimeScaleToDispatchInFixedUpdate = float.PositiveInfinity; } if (DisableTimeout.Value) { LoadBalancingClient networkingClient = PhotonNetwork.NetworkingClient; LoadBalancingPeer val = ((networkingClient != null) ? networkingClient.LoadBalancingPeer : null); if (val != null) { ((PhotonPeer)val).DisconnectTimeout = 3600000; ((PhotonPeer)val).SentCountAllowance = 10000; } } } catch (Exception ex) { Log.LogWarning((object)("Could not apply Photon settings: " + ex.Message)); } } } internal static class SimManager { internal class SimState { public PhysGrabObject pgo; public PhotonTransformView ptv; public Rigidbody rb; public PhysGrabCart cart; public bool isHinge; public PhysGrabHinge hinge; public HingeJoint joint; public int viewId; public bool localGrab; public float localPushTimer; public float postThrowTimer; public float postThrowRamp; public float noSnapTimer; public float hingeSyncPause; public float hingeOpenedAt = -999f; public float assistTail; public float assistTailAge; public int assistStill; public float awaitHostUntil; public float finalSentAt; public bool hostDriven; public string hostDrivenWhy; public bool droneExempt; public byte hpF; public float hpMass; public float hpDrag; public float hpAng; public byte hpApplied; public float origMass; public float origDrag; public float origAng; public bool origGravity; public float farTimer; public ItemDrone droneSelf; public ItemToggle droneToggle; public ItemMine mine; public ItemToggle itemToggle; public float desyncTimer; public float debugTimer; public int ridingTick; public bool wasRiding; public Trajectory traj; public float rideHoldTimer; public bool mirrorHeldRot; public bool weapon; public float releasedAt = -999f; public bool hasHostState; public float lastPacketTime = -999f; public Vector3 hostPos; public Quaternion hostRot = Quaternion.identity; public Vector3 hostVel; public Vector3 hostAngVel; public bool hostKinematic; public bool hostSleeping; public bool hostTeleport; } internal struct HostRead { public SimState st; public int stamp; public bool firstTake; public ushort teleportRev; public int sentStamp; } internal sealed class Trajectory { internal struct Sample { public int t; public Vector3 pos; public Vector3 vel; public Vector3 corr; public Vector3 corrV; } internal const int Capacity = 64; internal readonly Sample[] buf = new Sample[64]; internal int head; internal int count; internal bool flying; internal float flightAge; internal int ticksSinceRelease; internal int stillTicks; internal int contacts; internal Vector3 corr; internal Vector3 corrV; internal Vector3 remaining; internal Vector3 remainingV; internal Vector3 lastVel; internal bool hasLastVel; internal bool packetFresh; internal int packetStamp; internal int packets; internal float errSum; internal float errMax; internal void Reset() { //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) head = (count = 0); flying = false; flightAge = 0f; ticksSinceRelease = 0; stillTicks = 0; contacts = 0; corr = (corrV = (remaining = (remainingV = Vector3.zero))); hasLastVel = false; packetFresh = false; packets = 0; errSum = (errMax = 0f); } internal void Record(Rigidbody rb) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references)