aaaaaa
This commit is contained in:
@@ -89,6 +89,7 @@
|
|||||||
<Compile Include="Data\Structs.cs" />
|
<Compile Include="Data\Structs.cs" />
|
||||||
<Compile Include="Networking\Messages\DiscardSyncableMessage.cs" />
|
<Compile Include="Networking\Messages\DiscardSyncableMessage.cs" />
|
||||||
<Compile Include="Networking\Messages\GunSyncMessage.cs" />
|
<Compile Include="Networking\Messages\GunSyncMessage.cs" />
|
||||||
|
<Compile Include="Patching\HolsterSlotPatches.cs" />
|
||||||
<Compile Include="Networking\Messages\MagazineSyncMessage.cs" />
|
<Compile Include="Networking\Messages\MagazineSyncMessage.cs" />
|
||||||
<Compile Include="Networking\Messages\ObjectDamageMessage.cs" />
|
<Compile Include="Networking\Messages\ObjectDamageMessage.cs" />
|
||||||
<Compile Include="Networking\Messages\ObjectSyncMessage.cs" />
|
<Compile Include="Networking\Messages\ObjectSyncMessage.cs" />
|
||||||
|
|||||||
48
BoneSync/Patching/HolsterSlotPatches.cs
Normal file
48
BoneSync/Patching/HolsterSlotPatches.cs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
using BoneSync.Sync;
|
||||||
|
using BoneSync.Sync.Components;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MelonLoader;
|
||||||
|
using StressLevelZero.Interaction;
|
||||||
|
using StressLevelZero.Props.Weapons;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
namespace BoneSync.Patching
|
||||||
|
{
|
||||||
|
internal class HolsterSlotPatches
|
||||||
|
{
|
||||||
|
[HarmonyPatch(typeof(HandWeaponSlotReciever), nameof(HandWeaponSlotReciever.MakeStatic))]
|
||||||
|
public static void StaticPatch(HandWeaponSlotReciever __instance)
|
||||||
|
{
|
||||||
|
MelonLogger.Msg("HandWeaponSlotReciever.MakeStatic: " + __instance.name);
|
||||||
|
InteractableHost interactableHost = __instance.m_WeaponHost;
|
||||||
|
if (interactableHost == null)
|
||||||
|
{
|
||||||
|
MelonLogger.Error("InteractableHost is null for " + __instance.transform.GetPath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Syncable syncable = ObjectSync.MakeOrGetSyncable(interactableHost);
|
||||||
|
syncable?.SetInHolster(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(HandWeaponSlotReciever), nameof(HandWeaponSlotReciever.MakeDynamic))]
|
||||||
|
public static void DynamicPatch(HandWeaponSlotReciever __instance)
|
||||||
|
{
|
||||||
|
MelonLogger.Msg("HandWeaponSlotReciever.MakeDynamic: " + __instance.name);
|
||||||
|
InteractableHost interactableHost = __instance.m_WeaponHost;
|
||||||
|
if (interactableHost == null)
|
||||||
|
{
|
||||||
|
MelonLogger.Error("InteractableHost is null for " + __instance.transform.GetPath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Syncable syncable = ObjectSync.MakeOrGetSyncable(interactableHost);
|
||||||
|
syncable?.SetInHolster(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -134,10 +134,15 @@ namespace BoneSync.Patching
|
|||||||
|
|
||||||
bool spawnNormally = BoneSync.lobby.IsHost || PoolBlacklist.IsClientSpawnPool(__instance.pool);
|
bool spawnNormally = BoneSync.lobby.IsHost || PoolBlacklist.IsClientSpawnPool(__instance.pool);
|
||||||
|
|
||||||
if (spawnNormally) return;
|
if (!spawnNormally) {
|
||||||
|
|
||||||
|
|
||||||
MelonCoroutines.Start(OnSpawnClient(__instance)); // block object from spawning
|
MelonCoroutines.Start(OnSpawnClient(__instance)); // block object from spawning
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (syncable == null) return;
|
||||||
|
|
||||||
|
MelonLogger.Msg("Poolee.OnSpawn: " + __instance.gameObject.transform.GetPath() + " " + syncable.GetSyncId());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,12 +75,20 @@ namespace BoneSync.Sync.Components
|
|||||||
private ushort _syncId;
|
private ushort _syncId;
|
||||||
private float _lastSyncTime;
|
private float _lastSyncTime;
|
||||||
|
|
||||||
|
private bool _isInHolster;
|
||||||
private bool _attemptedRegister;
|
private bool _attemptedRegister;
|
||||||
|
|
||||||
public bool Registered => _syncId != 0;
|
public bool Registered => _syncId != 0;
|
||||||
public bool isStale => Time.time - _lastSyncTime > 5f;
|
public bool isStale => Time.time - _lastSyncTime > 5f;
|
||||||
public bool isOwner => _ownerId == BoneSync.lobby.GetLocalId();
|
public bool isOwner => _ownerId == BoneSync.lobby.GetLocalId();
|
||||||
|
|
||||||
|
public void SetInHolster(bool val)
|
||||||
|
{
|
||||||
|
MelonLogger.Msg(transform.GetPath() + " hosterState:" + val);
|
||||||
|
_isInHolster = val;
|
||||||
|
FindAndUpdateComponents();
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsHolding()
|
public bool IsHolding()
|
||||||
{
|
{
|
||||||
if (interactableManager)
|
if (interactableManager)
|
||||||
@@ -119,7 +127,7 @@ namespace BoneSync.Sync.Components
|
|||||||
|
|
||||||
private void CheckAutoSync()
|
private void CheckAutoSync()
|
||||||
{
|
{
|
||||||
bool shouldAutoSync = CheckIfShouldAutoSync();
|
bool shouldAutoSync = ShouldAutoSync();
|
||||||
if (shouldAutoSync && (BoneSync.lobby.IsHost || ClientSpawningAllowed()))
|
if (shouldAutoSync && (BoneSync.lobby.IsHost || ClientSpawningAllowed()))
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("AutoSyncing: " + transform.GetPath());
|
MelonLogger.Msg("AutoSyncing: " + transform.GetPath());
|
||||||
@@ -128,7 +136,10 @@ namespace BoneSync.Sync.Components
|
|||||||
}
|
}
|
||||||
private IEnumerator _OnEnableCo()
|
private IEnumerator _OnEnableCo()
|
||||||
{
|
{
|
||||||
yield return null; // wait a frame to make sure all components are initialized, I hate this but it works
|
// wait for a couple frames to make sure all components are initialized, I hate this but it works
|
||||||
|
yield return null;
|
||||||
|
yield return null;
|
||||||
|
yield return null;
|
||||||
FindAndUpdateComponents();
|
FindAndUpdateComponents();
|
||||||
CheckAutoSync();
|
CheckAutoSync();
|
||||||
yield break;
|
yield break;
|
||||||
@@ -143,7 +154,7 @@ namespace BoneSync.Sync.Components
|
|||||||
MelonCoroutines.Start(_OnEnableCo());
|
MelonCoroutines.Start(_OnEnableCo());
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CheckIfShouldAutoSync()
|
public bool ShouldAutoSync()
|
||||||
{
|
{
|
||||||
if (InPoolManagerTransform()) return false;
|
if (InPoolManagerTransform()) return false;
|
||||||
if (!gameObject.activeInHierarchy) return false;
|
if (!gameObject.activeInHierarchy) return false;
|
||||||
@@ -225,6 +236,7 @@ namespace BoneSync.Sync.Components
|
|||||||
|
|
||||||
public bool IsPlugged()
|
public bool IsPlugged()
|
||||||
{
|
{
|
||||||
|
if (plugs.Length == 0) return false;
|
||||||
for (int i = 0; i < plugs.Length; i++)
|
for (int i = 0; i < plugs.Length; i++)
|
||||||
{
|
{
|
||||||
AlignPlug alignPlug = plugs[i];
|
AlignPlug alignPlug = plugs[i];
|
||||||
@@ -245,7 +257,7 @@ namespace BoneSync.Sync.Components
|
|||||||
bool isPlugged = IsPlugged();
|
bool isPlugged = IsPlugged();
|
||||||
|
|
||||||
bool canDiscard = isOwner && (!isPlugged || force); // only owner can discard
|
bool canDiscard = isOwner && (!isPlugged || force); // only owner can discard
|
||||||
MelonLogger.Msg("Discarding syncable: " + transform.GetPath() + " force:" + force + " registered:" + isRegistered + " despawn:" + despawn + " isPlugged:" + isPlugged + " canDiscard:" + canDiscard);
|
//MelonLogger.Msg("Discarding syncable: " + transform.GetPath() + " force:" + force + " registered:" + isRegistered + " despawn:" + despawn + " isPlugged:" + isPlugged + " canDiscard:" + canDiscard);
|
||||||
//MelonLogger.Warning("Discarding registered syncable: " + transform.GetPath() + " force: " + force);
|
//MelonLogger.Warning("Discarding registered syncable: " + transform.GetPath() + " force: " + force);
|
||||||
|
|
||||||
if (canDiscard)
|
if (canDiscard)
|
||||||
@@ -256,6 +268,8 @@ namespace BoneSync.Sync.Components
|
|||||||
if (!canDiscard && !force) return;
|
if (!canDiscard && !force) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//MelonLogger.Msg("Discarding syncable: " + transform.GetPath() + " force:" + force + " registered:" + isRegistered + " despawn:" + despawn + " isPlugged:" + IsPlugged());
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
EjectAllPlugs(true);
|
EjectAllPlugs(true);
|
||||||
@@ -317,6 +331,7 @@ namespace BoneSync.Sync.Components
|
|||||||
public void RegisterSyncable()
|
public void RegisterSyncable()
|
||||||
{
|
{
|
||||||
if (!BoneSync.lobby.IsConnected()) return;
|
if (!BoneSync.lobby.IsConnected()) return;
|
||||||
|
FindAndUpdateComponents();
|
||||||
if (Registered)
|
if (Registered)
|
||||||
{
|
{
|
||||||
TryBecomeOwner();
|
TryBecomeOwner();
|
||||||
|
|||||||
@@ -119,6 +119,7 @@ namespace BoneSync.Sync.Components
|
|||||||
if (!Registered) return false;
|
if (!Registered) return false;
|
||||||
if (!isOwner) return false;
|
if (!isOwner) return false;
|
||||||
if (isStale) return true;
|
if (isStale) return true;
|
||||||
|
if (_isInHolster) return true;
|
||||||
if (AllRigidbodiesSleeping()) return false;
|
if (AllRigidbodiesSleeping()) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ namespace BoneSync.Sync.Components
|
|||||||
|
|
||||||
public void ApplyObjectSyncTransforms(ObjectSyncTransform[] objectSyncTransforms)
|
public void ApplyObjectSyncTransforms(ObjectSyncTransform[] objectSyncTransforms)
|
||||||
{
|
{
|
||||||
|
if (IsPlugged()) { return; }
|
||||||
if (objectSyncTransforms.Length != rigidbodies.Length)
|
if (objectSyncTransforms.Length != rigidbodies.Length)
|
||||||
{
|
{
|
||||||
MelonLogger.Warning("ObjectSyncTransforms length mismatch: " + objectSyncTransforms.Length + " != " + _transforms.Length);
|
MelonLogger.Warning("ObjectSyncTransforms length mismatch: " + objectSyncTransforms.Length + " != " + _transforms.Length);
|
||||||
@@ -142,7 +143,7 @@ namespace BoneSync.Sync.Components
|
|||||||
private void UpdateTransformList()
|
private void UpdateTransformList()
|
||||||
{
|
{
|
||||||
// get non-null rigidbodies
|
// get non-null rigidbodies
|
||||||
Rigidbody[] rbs = GetRigidbodies().Where(rb => rb != null && RigidbodyBelongsToSyncable(rb)).ToArray();
|
Rigidbody[] rbs = GetRigidbodies().Where(rb => rb != null).ToArray();
|
||||||
rigidbodies = rbs;
|
rigidbodies = rbs;
|
||||||
_transforms = rbs.Select(rb => rb.transform).ToArray();
|
_transforms = rbs.Select(rb => rb.transform).ToArray();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ namespace BoneSync.Sync
|
|||||||
private static Syncable _MakeOrGetSyncable(GameObject gameObject, bool deleteSubSyncabled = true)
|
private static Syncable _MakeOrGetSyncable(GameObject gameObject, bool deleteSubSyncabled = true)
|
||||||
{
|
{
|
||||||
//Scene scene = gameObject.scene;
|
//Scene scene = gameObject.scene;
|
||||||
//MelonLogger.Msg("Making or getting syncable for: " + gameObject.name + " in scene: " + scene.name);
|
//MelonLogger.Msg("Making or getting syncable for: " + gameObject.name);
|
||||||
if (gameObject == null)
|
if (gameObject == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -121,24 +121,33 @@ namespace BoneSync.Sync
|
|||||||
|
|
||||||
// delete all sub syncables
|
// delete all sub syncables
|
||||||
if (deleteSubSyncabled)
|
if (deleteSubSyncabled)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
Syncable[] subSyncables = gameObject.GetComponentsInChildren<Syncable>(true);
|
Syncable[] subSyncables = gameObject.GetComponentsInChildren<Syncable>(true);
|
||||||
for (int i = 0; i < subSyncables.Length; i++)
|
for (int i = 0; i < subSyncables.Length; i++)
|
||||||
{
|
{
|
||||||
Syncable subSyncable = subSyncables[i];
|
Syncable subSyncable = subSyncables[i];
|
||||||
if (subSyncable == syncable) continue;
|
if (subSyncable == syncable) continue;
|
||||||
|
if (subSyncable == null) continue;
|
||||||
bool isRegistered = subSyncable.Registered;
|
bool isRegistered = subSyncable.Registered;
|
||||||
bool isPlugged = subSyncable.IsPlugged();
|
bool isPlugged = subSyncable.IsPlugged();
|
||||||
|
|
||||||
MelonLogger.Msg("Discarding subSyncable: " + subSyncable.transform.GetPath() + " registered:" + isRegistered + " plugged:" + isPlugged);
|
MelonLogger.Msg("Discarding subSyncable: " + subSyncable.transform.GetPath() + " registered:" + isRegistered + " plugged:" + isPlugged);
|
||||||
if (isRegistered || isPlugged) continue;
|
if (isRegistered || isPlugged) continue;
|
||||||
subSyncable.DiscardSyncableImmediate(true, false);
|
subSyncable.DiscardSyncable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
MelonLogger.Warning("Failed to delete sub syncables: " + e.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (syncable == null)
|
if (syncable == null)
|
||||||
{
|
{
|
||||||
syncable = gameObject.AddComponent<Syncable>();
|
syncable = gameObject.AddComponent<Syncable>();
|
||||||
|
// MelonLogger.Msg("Created syncable for: " + gameObject.name);
|
||||||
}
|
}
|
||||||
return syncable;
|
return syncable;
|
||||||
}
|
}
|
||||||
@@ -175,7 +184,7 @@ namespace BoneSync.Sync
|
|||||||
|
|
||||||
public static Syncable MakeOrGetSyncable(InteractableHostManager interactableHostManager)
|
public static Syncable MakeOrGetSyncable(InteractableHostManager interactableHostManager)
|
||||||
{
|
{
|
||||||
return _MakeOrGetSyncable(interactableHostManager.gameObject);
|
return _MakeOrGetSyncable(interactableHostManager.gameObject, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Syncable SpawnPooleeAndMakeSyncable(SpawnPoolableInfo spawnInfo)
|
public static Syncable SpawnPooleeAndMakeSyncable(SpawnPoolableInfo spawnInfo)
|
||||||
|
|||||||
Reference in New Issue
Block a user