!BROKEN!!!

This commit is contained in:
Aaro Varis
2025-03-23 19:59:59 +02:00
parent 143505f762
commit 3d879a605d
4 changed files with 21 additions and 12 deletions

View File

@@ -39,7 +39,7 @@ namespace BoneSync.Data
} }
} }
internal static class SyncDebugUI /*internal static class SyncDebugUI
{ {
public static Dictionary<string, string> keyValuePairs = new Dictionary<string, string>(); public static Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
public static Text debugText; public static Text debugText;
@@ -93,5 +93,5 @@ namespace BoneSync.Data
} }
debugText.text = sb.ToString(); debugText.text = sb.ToString();
} }
} }*/
} }

View File

@@ -54,27 +54,33 @@ namespace BoneSync.Patching
} }
// SceneZone and PlayerTrigger patches are based on the ones from entanglement mod // SceneZone and PlayerTrigger patches are based on the ones from entanglement mod
[HarmonyPatch(typeof(SceneZone))] [HarmonyPatch(typeof(SceneZone))]
public static class SceneZonePatch 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] /*[HarmonyPatch(nameof(SceneZone.OnTriggerEnter)), HarmonyPrefix]
public static bool EnterPrefix(SceneZone __instance, Collider other) public static bool EnterPrefix(SceneZone __instance, Collider other)
{ {
if (other.CompareTag("Player")) if (other.CompareTag("Player"))
{ {
return other.transform.IsChildOf(PlayerRig.localRigRoot); return IsChildOfLocalRigRoot(other.transform);
} }
return true; return true;
}*/ }*/
[HarmonyPatch(nameof(SceneZone.OnTriggerExit)), HarmonyPrefix] [HarmonyPatch(nameof(SceneZone.OnTriggerExit)), HarmonyPrefix]
public static bool ExitPrefix(SceneZone __instance, Collider other) public static bool ExitPrefix(SceneZone __instance, Collider other)
{ {
if (other.CompareTag("Player")) if (other.CompareTag("Player"))
{ {
return other.transform.IsChildOf(PlayerRig.localRigRoot); return IsChildOfLocalRigRoot(other.transform);
} }
return true; return true;
@@ -104,8 +110,7 @@ namespace BoneSync.Patching
{ {
if (other.CompareTag("Player")) if (other.CompareTag("Player"))
{ {
return SceneZonePatch.IsChildOfLocalRigRoot(other.transform);
return other.transform.IsChildOf(PlayerRig.localRigRoot);
} }
return true; return true;

View File

@@ -83,6 +83,8 @@ namespace BoneSync.Sync.Components
public bool isStale => Time.realtimeSinceStartup - _lastSyncTime > 5f; public bool isStale => Time.realtimeSinceStartup - _lastSyncTime > 5f;
public bool isOwner => _ownerId == BoneSync.lobby.GetLocalId(); public bool isOwner => _ownerId == BoneSync.lobby.GetLocalId();
public bool isValid => this != null && gameObject != null;
public void SetInHolster(bool val) public void SetInHolster(bool val)
{ {
SyncLogger.Msg(transform.GetPath() + " hosterState:" + val); SyncLogger.Msg(transform.GetPath() + " hosterState:" + val);
@@ -171,6 +173,7 @@ namespace BoneSync.Sync.Components
public string GetSyncableWorldPath() public string GetSyncableWorldPath()
{ {
if (!isValid) return "";
if (transform == null) return ""; if (transform == null) return "";
if (poolee && poolee.pool) if (poolee && poolee.pool)
{ {
@@ -187,6 +190,7 @@ namespace BoneSync.Sync.Components
public void FindAndUpdateComponents() public void FindAndUpdateComponents()
{ {
if (!isValid) return;
ObjectSyncCache.RemoveSyncable(this); ObjectSyncCache.RemoveSyncable(this);
pullDevice = GetComponent<PullDevice>(); pullDevice = GetComponent<PullDevice>();
@@ -266,17 +270,17 @@ namespace BoneSync.Sync.Components
private void _DiscardSyncable(bool force, bool despawn) 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; 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) if (isRegistered)
{ {
bool isPlugged = IsPlugged(); bool isPlugged = IsPlugged();
bool canDiscard = isOwner && (!isPlugged || force); // only owner can discard 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); //SyncLogger.Warning("Discarding registered syncable: " + transform.GetPath() + " force: " + force);
if (canDiscard) if (canDiscard)

View File

@@ -125,7 +125,7 @@ namespace BoneSync.Sync.Components
} }
private void SetKinematic(bool kinematic) private void SetKinematic(bool kinematic)
{ {
if (!this) return; if (!isValid) return;
try try
{ {
_SetKinematic(kinematic); _SetKinematic(kinematic);