patch changes

This commit is contained in:
2025-03-28 22:30:09 +02:00
parent f5ad619ed5
commit b9390bbf03
7 changed files with 38 additions and 47 deletions

View File

@@ -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<Syncable>();
if (syncable != null && syncable.Registered && !syncable.isOwner) return false;
return true;
}
}*/
}
}

View File

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

View File

@@ -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();

View File

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

View File

@@ -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),

View File

@@ -176,7 +176,7 @@ namespace BoneSync.Sync.Components
/*ZoneTracker[] zoneTrackers = GetComponentsInChildren<ZoneTracker>(true);
foreach (ZoneTracker zoneTracker in zoneTrackers)
{
//Destroy(zoneTracker);
Destroy(zoneTracker);
}*/
}

View File

@@ -17,8 +17,8 @@ namespace BoneSync.Sync
private static Dictionary<string, Syncable> _pathToSyncable = new Dictionary<string, Syncable>();
private static Dictionary<ushort, Syncable> _idToSyncable = new Dictionary<ushort, Syncable>();
private static Dictionary<MonoBehaviour, Syncable> _componentToSyncable = new Dictionary<MonoBehaviour, Syncable>();
private static Dictionary<Syncable, MonoBehaviour[]> _syncableToComponent = new Dictionary<Syncable, MonoBehaviour[]>();
private static Dictionary<int, Syncable> _componentToSyncable = new Dictionary<int, Syncable>();
private static Dictionary<Syncable, Component[]> _syncableToComponent = new Dictionary<Syncable, Component[]>();
public static Dictionary<ushort, Syncable> CallbackIdToSyncable = new Dictionary<ushort, Syncable>();
@@ -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<MonoBehaviour>(true);
List<MonoBehaviour> slzComponents = new List<MonoBehaviour>();
Component[] components = syncable.GetComponentsInChildren<Component>(true);
List<Component> slzComponents = new List<Component>();
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);
}
}
}