From b7bd64652046b395aef89e3896770c2144200fed Mon Sep 17 00:00:00 2001 From: Aaro Varis Date: Sun, 2 Mar 2025 17:55:18 +0200 Subject: [PATCH] loottable patches --- BoneSync/Patching/ObjectHealthPatches.cs | 17 +++++++++++++++++ BoneSync/Sync/Components/SyncableBase.cs | 13 ++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/BoneSync/Patching/ObjectHealthPatches.cs b/BoneSync/Patching/ObjectHealthPatches.cs index c1f9b98..f424508 100644 --- a/BoneSync/Patching/ObjectHealthPatches.cs +++ b/BoneSync/Patching/ObjectHealthPatches.cs @@ -3,6 +3,7 @@ using BoneSync.Sync; using BoneSync.Sync.Components; using HarmonyLib; using StressLevelZero.Combat; +using StressLevelZero.Data; using StressLevelZero.Props; using System; using System.Collections.Generic; @@ -39,6 +40,21 @@ namespace BoneSync.Patching } return true; } + + // patch the getter for lootTable to return null if the object is networked + [HarmonyPatch(nameof(ObjectDestructable.lootTable), MethodType.Getter)] + [HarmonyPrefix] + private static bool LootTablePatch(ObjectDestructable __instance, ref LootTableData __result) + { + if (!BoneSync.lobby.IsConnected()) return true; + Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject); + if (syncable != null && !BoneSync.lobby.IsHost) + { + __result = null; + return false; + } + return true; + } } [HarmonyPatch(typeof(Prop_Health))] @@ -64,5 +80,6 @@ namespace BoneSync.Patching } return true; } + } } diff --git a/BoneSync/Sync/Components/SyncableBase.cs b/BoneSync/Sync/Components/SyncableBase.cs index 1e15e39..6bb5145 100644 --- a/BoneSync/Sync/Components/SyncableBase.cs +++ b/BoneSync/Sync/Components/SyncableBase.cs @@ -126,7 +126,7 @@ namespace BoneSync.Sync.Components private IEnumerator _OnEnableCo() { yield return null; // wait a frame to make sure all components are initialized, I hate this but it works - FindComponents(); + FindAndUpdateComponents(); CheckAutoSync(); yield break; } @@ -135,7 +135,7 @@ namespace BoneSync.Sync.Components { syncablesCache[gameObject] = this; - FindComponents(); + FindAndUpdateComponents(); MelonCoroutines.Start(_OnEnableCo()); } @@ -165,7 +165,7 @@ namespace BoneSync.Sync.Components return ""; } - public void FindComponents() + public void FindAndUpdateComponents() { ObjectSyncCache.RemoveSyncable(this); @@ -178,7 +178,7 @@ namespace BoneSync.Sync.Components magazine = GetComponent(); plugs = GetComponentsInChildren(); spawnFragment = GetComponent(); - //rigidbodies = GetComponentsInChildren(); + UpdateTransformList(); ObjectSyncCache.AddSyncable(this); @@ -194,7 +194,7 @@ namespace BoneSync.Sync.Components public bool CanBeSynced() { if (spawnFragment) return false; // if has spawn fragment, don't sync - FindComponents(); + FindAndUpdateComponents(); if (rigidbodies.Length > 0) return true; return false; @@ -230,7 +230,10 @@ namespace BoneSync.Sync.Components { gameObject?.SetActive(false); } + } + private void OnRegister() + { }