From bc10f6b1b7d4930d5d62d2a6429808a3e7e6b485 Mon Sep 17 00:00:00 2001 From: Aaro Varis Date: Mon, 3 Mar 2025 20:57:12 +0200 Subject: [PATCH] aaaaaaaa --- BoneSync/Data/SpawnableManager.cs | 4 ++-- BoneSync/Patching/PlugPatches.cs | 10 ++++++---- BoneSync/Sync/Components/SyncableBase.cs | 3 ++- BoneSync/Sync/ObjectSyncCache.cs | 20 ++++++++++---------- BoneSync/Sync/SceneSync.cs | 4 +++- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/BoneSync/Data/SpawnableManager.cs b/BoneSync/Data/SpawnableManager.cs index 1fb4bd6..27a147c 100644 --- a/BoneSync/Data/SpawnableManager.cs +++ b/BoneSync/Data/SpawnableManager.cs @@ -16,7 +16,7 @@ namespace BoneSync.Data { private static Dictionary _spawnableCache = new Dictionary(); - private static void _UpdateSpawnableCache() + public static void AddUnregisteredSpawnables() { Il2CppReferenceArray foundSpawnables = UnityObject.FindObjectsOfTypeIncludingAssets(Il2CppType.Of()); foreach (UnityObject obj in foundSpawnables) @@ -50,7 +50,7 @@ namespace BoneSync.Data public static void Initialize() { _ClearCache(); - _UpdateSpawnableCache(); + AddUnregisteredSpawnables(); } } } diff --git a/BoneSync/Patching/PlugPatches.cs b/BoneSync/Patching/PlugPatches.cs index e154ac2..552f38e 100644 --- a/BoneSync/Patching/PlugPatches.cs +++ b/BoneSync/Patching/PlugPatches.cs @@ -21,8 +21,9 @@ namespace BoneSync.Patching MelonLogger.Msg("Plug entered: " + __instance.name + " Plug: " + plug.name); Syncable syncable = ObjectSyncCache.GetSyncable(plug); if (!syncable) return; - byte id = syncable.GetPlugId(plug); - MelonLogger.Msg("Plug entered: " + __instance.name + " Plug: " + plug.name + " ID: " + id); + byte plugId = syncable.GetPlugId(plug); + byte socketId = syncable.GetSocketId(__instance); + MelonLogger.Msg("Plug entered: " + __instance.transform.GetPath() + " Plug: " + plug.transform.GetPath() + " ID: " + plugId + " Socket ID: " + socketId); } @@ -33,8 +34,9 @@ namespace BoneSync.Patching MelonLogger.Msg("Plug exited: " + __instance.name + " Plug: " + plug.name); Syncable syncable = ObjectSyncCache.GetSyncable(plug); if (!syncable) return; - byte id = syncable.GetPlugId(plug); - MelonLogger.Msg("Plug exited: " + __instance.name + " Plug: " + plug.name + " ID: " + id); + byte plugId = syncable.GetPlugId(plug); + byte socketId = syncable.GetSocketId(__instance); + MelonLogger.Msg("Plug exited: " + __instance.transform.GetPath() + " Plug: " + plug.transform.GetPath() + " ID: " + plugId + " Socket ID: " + socketId); } } } diff --git a/BoneSync/Sync/Components/SyncableBase.cs b/BoneSync/Sync/Components/SyncableBase.cs index 1da68f7..c60424b 100644 --- a/BoneSync/Sync/Components/SyncableBase.cs +++ b/BoneSync/Sync/Components/SyncableBase.cs @@ -214,6 +214,7 @@ namespace BoneSync.Sync.Components private void _DiscardSyncable(bool force, bool despawn) { + if (!this) return; // if object is destroyed, don't do anything bool isRegistered = Registered; MelonLogger.Msg("Discarding syncable: " + transform.GetPath() + " force: " + force + " isRegistered: " + isRegistered + " despawn: " + despawn); if (isRegistered) @@ -236,7 +237,7 @@ namespace BoneSync.Sync.Components ResetSyncStatus(); - DestroyImmediate(this); // delete the component + Destroy(this); // delete the component if (despawn) MelonCoroutines.Start(DespawnSyncable()); } diff --git a/BoneSync/Sync/ObjectSyncCache.cs b/BoneSync/Sync/ObjectSyncCache.cs index 8516d94..ce9d00e 100644 --- a/BoneSync/Sync/ObjectSyncCache.cs +++ b/BoneSync/Sync/ObjectSyncCache.cs @@ -15,8 +15,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(); @@ -30,10 +30,10 @@ namespace BoneSync.Sync string ns = GetComponentNamespace(component); return ns.StartsWith("StressLevelZero") || ns.StartsWith("BoneSync"); } - private static Component[] GetSLZComponents(Syncable syncable) + private static MonoBehaviour[] GetSLZComponents(Syncable syncable) { - Component[] components = syncable.GetComponentsInChildren(true); - List slzComponents = new List(); + MonoBehaviour[] components = syncable.GetComponentsInChildren(true); + List slzComponents = new List(); for (int i = 0; i < components.Length; i++) { if (IsSlzComponent(components[i])) @@ -45,9 +45,9 @@ namespace BoneSync.Sync } private static void _AddSyncableComponents(Syncable syncable) { - Component[] components = GetSLZComponents(syncable); + MonoBehaviour[] components = GetSLZComponents(syncable); _syncableToComponent[syncable] = components; - foreach (Component component in components) + foreach (MonoBehaviour component in components) { _componentToSyncable[component] = syncable; } @@ -56,8 +56,8 @@ namespace BoneSync.Sync { if (_syncableToComponent.ContainsKey(syncable)) { - Component[] components = _syncableToComponent[syncable]; - foreach (Component component in components) + MonoBehaviour[] components = _syncableToComponent[syncable]; + foreach (MonoBehaviour component in components) { _componentToSyncable.Remove(component); } @@ -136,7 +136,7 @@ namespace BoneSync.Sync return null; } - public static Syncable GetSyncable(Component component) + public static Syncable GetSyncable(MonoBehaviour component) { if (_componentToSyncable.ContainsKey(component)) { diff --git a/BoneSync/Sync/SceneSync.cs b/BoneSync/Sync/SceneSync.cs index b302c8e..6f2b379 100644 --- a/BoneSync/Sync/SceneSync.cs +++ b/BoneSync/Sync/SceneSync.cs @@ -1,4 +1,5 @@ -using BoneSync.Sync.Components; +using BoneSync.Data; +using BoneSync.Sync.Components; using MelonLoader; using StressLevelZero.Interaction; using System; @@ -69,6 +70,7 @@ namespace BoneSync.Sync _currentSceneName = SceneName; MelonLogger.Msg("Scene initialized: " + SceneName); RenameDuplicateSceneTransforms(scene); + SpawnableManager.AddUnregisteredSpawnables(); } public static void Initialize()