diff --git a/BoneSync/Patching/AIHealthPatches.cs b/BoneSync/Patching/AIHealthPatches.cs index a03424f..8184ee6 100644 --- a/BoneSync/Patching/AIHealthPatches.cs +++ b/BoneSync/Patching/AIHealthPatches.cs @@ -12,7 +12,7 @@ namespace BoneSync.Patching [HarmonyPatch(typeof(SubBehaviourHealth))] internal class AIHealthPatches { - [HarmonyPatch(nameof(SubBehaviourHealth.TakeDamage)), HarmonyPrefix] + /*[HarmonyPatch(nameof(SubBehaviourHealth.TakeDamage)), HarmonyPrefix] private static bool DamagePrefix(SubBehaviourHealth __instance) { if (!BoneSync.IsConnected) return true; @@ -20,6 +20,6 @@ namespace BoneSync.Patching Syncable syncable = __instance.behaviour.GetComponentInParent(); if (syncable != null && syncable.Registered && !syncable.isOwner) return false; return true; - } + }*/ } } diff --git a/BoneSync/Patching/ButtonTogglePatches.cs b/BoneSync/Patching/ButtonTogglePatches.cs index 8c18b5e..c4543bb 100644 --- a/BoneSync/Patching/ButtonTogglePatches.cs +++ b/BoneSync/Patching/ButtonTogglePatches.cs @@ -82,7 +82,7 @@ namespace BoneSync.Patching } } - [HarmonyPatch(typeof(UnityEvent))] + /*[HarmonyPatch(typeof(UnityEvent))] internal class UnityEventPatches { [HarmonyPatch(nameof(UnityEvent.Invoke)), HarmonyPrefix] @@ -96,5 +96,5 @@ namespace BoneSync.Patching } return true; } - } + }*/ } diff --git a/BoneSync/Patching/SkeletonHandPatches.cs b/BoneSync/Patching/SkeletonHandPatches.cs index 5d635f2..cfc24fb 100644 --- a/BoneSync/Patching/SkeletonHandPatches.cs +++ b/BoneSync/Patching/SkeletonHandPatches.cs @@ -28,12 +28,7 @@ namespace BoneSync.Patching if (handPoses.ContainsKey(handPoseName)) return handPoses[handPoseName]; - if (PlayerScripts.playerHandPoses == null) - { - SyncLogger.Error("PlayerScripts.playerHandPoses is null!"); - return 0; - } - if (PlayerScripts.playerHandPoses.Count == 0) + if (PlayerScripts.playerHandPoses == null || PlayerScripts.playerHandPoses.Count == 0) { SyncLogger.Msg("PlayerScripts.playerHandPoses is empty, getting hand poses..."); PlayerScripts.GetHandPoses(); diff --git a/BoneSync/Patching/ZonePatches.cs b/BoneSync/Patching/ZonePatches.cs index 88d18bc..ceb2180 100644 --- a/BoneSync/Patching/ZonePatches.cs +++ b/BoneSync/Patching/ZonePatches.cs @@ -61,10 +61,10 @@ namespace BoneSync.Patching { public static bool IsChildOfLocalRigRoot(Transform transform) { - if (PlayerRig.localRigRoot == null) return false; - return transform.IsChildOf(PlayerRig.localRigRoot); + if (PlayerRig.localRigWorldRoot == null) return false; + return transform.root == PlayerRig.localRigWorldRoot; } - /*[HarmonyPatch(nameof(SceneZone.OnTriggerEnter)), HarmonyPrefix] + [HarmonyPatch(nameof(SceneZone.OnTriggerEnter)), HarmonyPrefix] public static bool EnterPrefix(SceneZone __instance, Collider other) { if (other.CompareTag("Player")) @@ -73,7 +73,7 @@ namespace BoneSync.Patching } return true; - }*/ + } [HarmonyPatch(nameof(SceneZone.OnTriggerExit)), HarmonyPrefix] public static bool ExitPrefix(SceneZone __instance, Collider other) @@ -90,18 +90,18 @@ namespace BoneSync.Patching [HarmonyPatch(typeof(PlayerTrigger))] public static class PlayerTriggerPatch { - /* + [HarmonyPatch(nameof(PlayerTrigger.OnTriggerEnter)), HarmonyPrefix] public static bool EnterPrefix(PlayerTrigger __instance, Collider other) { if (other.CompareTag("Player")) { - return other.transform.IsChildOf(PlayerRig.localRigRoot); + return SceneZonePatch.IsChildOfLocalRigRoot(other.transform); } return true; - }*/ + } // only patch exit, as we want to allow activating a trigger always diff --git a/BoneSync/Player/PlayerRig.cs b/BoneSync/Player/PlayerRig.cs index 7fea216..99ef383 100644 --- a/BoneSync/Player/PlayerRig.cs +++ b/BoneSync/Player/PlayerRig.cs @@ -110,7 +110,8 @@ namespace BoneSync.Player public static GameObject localPlayerRig; - public static Transform localRigRoot; + public static Transform localRigSkeletonRoot; + public static Transform localRigWorldRoot; private static Transform localRigHeadTransform; private static Transform localRigLeftHandTransform; @@ -119,11 +120,12 @@ namespace BoneSync.Player { if (localPlayerRig != null) return; localPlayerRig = GameObject.Find("[RigManager (Default Brett)]/[SkeletonRig (GameWorld Brett)]"); - localRigRoot = localPlayerRig.transform; + localRigSkeletonRoot = localPlayerRig.transform; + localRigWorldRoot = localRigSkeletonRoot.root; - localRigHeadTransform = localRigRoot.Find("Head"); - localRigLeftHandTransform = localRigRoot.Find("Hand (left)"); - localRigRightHandTransform = localRigRoot.Find("Hand (right)"); + localRigHeadTransform = localRigSkeletonRoot.Find("Head"); + localRigLeftHandTransform = localRigSkeletonRoot.Find("Hand (left)"); + localRigRightHandTransform = localRigSkeletonRoot.Find("Hand (right)"); } public static PlayerSyncInfo? GetLocalSyncInfo() @@ -145,7 +147,7 @@ namespace BoneSync.Player PlayerSyncInfo playerSyncInfo = new PlayerSyncInfo() { - rootPos = localRigRoot.position, + rootPos = localRigSkeletonRoot.position, headPos = new SimpleSyncTransform(localRigHeadTransform), leftHandPos = new SimpleSyncTransform(localRigLeftHandTransform), rightHandPos = new SimpleSyncTransform(localRigRightHandTransform), diff --git a/BoneSync/Sync/Components/SyncableNetworking.cs b/BoneSync/Sync/Components/SyncableNetworking.cs index 89b97bc..8dbdfa7 100644 --- a/BoneSync/Sync/Components/SyncableNetworking.cs +++ b/BoneSync/Sync/Components/SyncableNetworking.cs @@ -176,7 +176,7 @@ namespace BoneSync.Sync.Components /*ZoneTracker[] zoneTrackers = GetComponentsInChildren(true); foreach (ZoneTracker zoneTracker in zoneTrackers) { - //Destroy(zoneTracker); + Destroy(zoneTracker); }*/ } diff --git a/BoneSync/Sync/ObjectSyncCache.cs b/BoneSync/Sync/ObjectSyncCache.cs index 3f2380c..c60b9e3 100644 --- a/BoneSync/Sync/ObjectSyncCache.cs +++ b/BoneSync/Sync/ObjectSyncCache.cs @@ -17,8 +17,8 @@ namespace BoneSync.Sync private static Dictionary _pathToSyncable = new Dictionary(); private static Dictionary _idToSyncable = new Dictionary(); - private static Dictionary _componentToSyncable = new Dictionary(); - private static Dictionary _syncableToComponent = new Dictionary(); + private static Dictionary _componentToSyncable = new Dictionary(); + private static Dictionary _syncableToComponent = new Dictionary(); public static Dictionary CallbackIdToSyncable = new Dictionary(); @@ -27,24 +27,18 @@ namespace BoneSync.Sync return component.GetType().Namespace; } - private static bool IsCachableComponent(MonoBehaviour component) + private static bool IsCachableComponent(Component component) { - if (component is InteractableHost) return true; - if (component is Poolee) return true; - if (component is Plug) return true; - if (component is Socket) return true; - if (component is AlignPlug) return true; - if (component is Gun) return true; - if (component is Magazine) return true; + if (component is MonoBehaviour) return true; return false; //string ns = GetComponentNamespace(component); //return ns.StartsWith("StressLevelZero") || ns.StartsWith("BoneSync"); } - private static MonoBehaviour[] GetComponentsToCache(Syncable syncable) + private static Component[] GetComponentsToCache(Syncable syncable) { - MonoBehaviour[] components = syncable.GetComponentsInChildren(true); - List slzComponents = new List(); + Component[] components = syncable.GetComponentsInChildren(true); + List slzComponents = new List(); for (int i = 0; i < components.Length; i++) { if (IsCachableComponent(components[i])) @@ -56,21 +50,21 @@ namespace BoneSync.Sync } private static void _AddSyncableComponents(Syncable syncable) { - MonoBehaviour[] components = GetComponentsToCache(syncable); + Component[] components = GetComponentsToCache(syncable); _syncableToComponent[syncable] = components; - foreach (MonoBehaviour component in components) + foreach (Component component in components) { - _componentToSyncable[component] = syncable; + _componentToSyncable[component.GetHashCode()] = syncable; } } private static void _RemoveSyncableComponents(Syncable syncable) { if (_syncableToComponent.ContainsKey(syncable)) { - MonoBehaviour[] components = _syncableToComponent[syncable]; - foreach (MonoBehaviour component in components) + Component[] components = _syncableToComponent[syncable]; + foreach (Component component in components) { - _componentToSyncable.Remove(component); + _componentToSyncable.Remove(component.GetHashCode()); } _syncableToComponent.Remove(syncable); } @@ -147,11 +141,11 @@ namespace BoneSync.Sync return null; } - public static Syncable GetSyncable(MonoBehaviour component) + public static Syncable GetSyncable(Component component) { - if (_componentToSyncable.ContainsKey(component)) + if (_componentToSyncable.ContainsKey(component.GetHashCode())) { - return _componentToSyncable[component]; + return _componentToSyncable[component.GetHashCode()]; } return null; } @@ -160,7 +154,7 @@ namespace BoneSync.Sync { foreach (Syncable syncable in Syncable.syncablesCache.Values) { - syncable.DiscardSyncable(); + syncable.DiscardSyncableImmediate(true, false); } } }