From 3d879a605dd4efef9aa702ab934d5d2d5a0be157 Mon Sep 17 00:00:00 2001 From: Aaro Varis Date: Sun, 23 Mar 2025 19:59:59 +0200 Subject: [PATCH] !BROKEN!!! --- BoneSync/Data/Debugger.cs | 4 ++-- BoneSync/Patching/ZonePatches.cs | 17 +++++++++++------ BoneSync/Sync/Components/SyncableBase.cs | 10 +++++++--- BoneSync/Sync/Components/SyncablePhysics.cs | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/BoneSync/Data/Debugger.cs b/BoneSync/Data/Debugger.cs index 0f318ed..2ae046f 100644 --- a/BoneSync/Data/Debugger.cs +++ b/BoneSync/Data/Debugger.cs @@ -39,7 +39,7 @@ namespace BoneSync.Data } } - internal static class SyncDebugUI + /*internal static class SyncDebugUI { public static Dictionary keyValuePairs = new Dictionary(); public static Text debugText; @@ -93,5 +93,5 @@ namespace BoneSync.Data } debugText.text = sb.ToString(); } - } + }*/ } diff --git a/BoneSync/Patching/ZonePatches.cs b/BoneSync/Patching/ZonePatches.cs index 77f562a..88d18bc 100644 --- a/BoneSync/Patching/ZonePatches.cs +++ b/BoneSync/Patching/ZonePatches.cs @@ -54,27 +54,33 @@ namespace BoneSync.Patching } // SceneZone and PlayerTrigger patches are based on the ones from entanglement mod - + + [HarmonyPatch(typeof(SceneZone))] public static class SceneZonePatch { + public static bool IsChildOfLocalRigRoot(Transform transform) + { + if (PlayerRig.localRigRoot == null) return false; + return transform.IsChildOf(PlayerRig.localRigRoot); + } /*[HarmonyPatch(nameof(SceneZone.OnTriggerEnter)), HarmonyPrefix] public static bool EnterPrefix(SceneZone __instance, Collider other) { if (other.CompareTag("Player")) { - return other.transform.IsChildOf(PlayerRig.localRigRoot); + return IsChildOfLocalRigRoot(other.transform); } return true; }*/ - + [HarmonyPatch(nameof(SceneZone.OnTriggerExit)), HarmonyPrefix] public static bool ExitPrefix(SceneZone __instance, Collider other) { if (other.CompareTag("Player")) { - return other.transform.IsChildOf(PlayerRig.localRigRoot); + return IsChildOfLocalRigRoot(other.transform); } return true; @@ -104,8 +110,7 @@ namespace BoneSync.Patching { if (other.CompareTag("Player")) { - - return other.transform.IsChildOf(PlayerRig.localRigRoot); + return SceneZonePatch.IsChildOfLocalRigRoot(other.transform); } return true; diff --git a/BoneSync/Sync/Components/SyncableBase.cs b/BoneSync/Sync/Components/SyncableBase.cs index 986361e..92dc1f8 100644 --- a/BoneSync/Sync/Components/SyncableBase.cs +++ b/BoneSync/Sync/Components/SyncableBase.cs @@ -83,6 +83,8 @@ namespace BoneSync.Sync.Components public bool isStale => Time.realtimeSinceStartup - _lastSyncTime > 5f; public bool isOwner => _ownerId == BoneSync.lobby.GetLocalId(); + public bool isValid => this != null && gameObject != null; + public void SetInHolster(bool val) { SyncLogger.Msg(transform.GetPath() + " hosterState:" + val); @@ -171,6 +173,7 @@ namespace BoneSync.Sync.Components public string GetSyncableWorldPath() { + if (!isValid) return ""; if (transform == null) return ""; if (poolee && poolee.pool) { @@ -187,6 +190,7 @@ namespace BoneSync.Sync.Components public void FindAndUpdateComponents() { + if (!isValid) return; ObjectSyncCache.RemoveSyncable(this); pullDevice = GetComponent(); @@ -266,17 +270,17 @@ namespace BoneSync.Sync.Components private void _DiscardSyncable(bool force, bool despawn) { - if (!this) return; // if object is destroyed, don't do anything + if (!isValid) return; // if object is destroyed, don't do anything bool isRegistered = Registered; - SyncLogger.Debug("Discarding syncable: " + transform.GetPath() + " force:" + force + " registered:" + isRegistered + " despawn:" + despawn + " isPlugged:" + IsPlugged()); + //SyncLogger.Debug("Discarding syncable: " + transform.GetPath() + " force:" + force + " registered:" + isRegistered + " despawn:" + despawn + " isPlugged:" + IsPlugged()); if (isRegistered) { bool isPlugged = IsPlugged(); bool canDiscard = isOwner && (!isPlugged || force); // only owner can discard - //SyncLogger.Msg("Discarding syncable: " + transform.GetPath() + " force:" + force + " registered:" + isRegistered + " despawn:" + despawn + " isPlugged:" + isPlugged + " canDiscard:" + canDiscard); + SyncLogger.Debug("Discarding syncable: " + transform.GetPath() + " force:" + force + " registered:" + isRegistered + " despawn:" + despawn + " isPlugged:" + isPlugged + " canDiscard:" + canDiscard); //SyncLogger.Warning("Discarding registered syncable: " + transform.GetPath() + " force: " + force); if (canDiscard) diff --git a/BoneSync/Sync/Components/SyncablePhysics.cs b/BoneSync/Sync/Components/SyncablePhysics.cs index 1951d2a..1355c35 100644 --- a/BoneSync/Sync/Components/SyncablePhysics.cs +++ b/BoneSync/Sync/Components/SyncablePhysics.cs @@ -125,7 +125,7 @@ namespace BoneSync.Sync.Components } private void SetKinematic(bool kinematic) { - if (!this) return; + if (!isValid) return; try { _SetKinematic(kinematic);