loottable patches

This commit is contained in:
Aaro Varis
2025-03-02 17:55:18 +02:00
parent 7f266321db
commit b7bd646520
2 changed files with 25 additions and 5 deletions

View File

@@ -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;
}
}
}

View File

@@ -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<Magazine>();
plugs = GetComponentsInChildren<Plug>();
spawnFragment = GetComponent<SpawnFragment>();
//rigidbodies = GetComponentsInChildren<Rigidbody>();
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()
{
}