aaaaaa
This commit is contained in:
@@ -18,6 +18,7 @@ namespace BoneSync.Networking.Messages
|
||||
{
|
||||
public ushort syncId;
|
||||
public SimpleEventType eventType;
|
||||
public byte index;
|
||||
//public object[] args;
|
||||
}
|
||||
[PacketType(PacketType.SimpleObjectEventSync)]
|
||||
@@ -29,6 +30,7 @@ namespace BoneSync.Networking.Messages
|
||||
eventData = simpleSyncableEvent;
|
||||
byteEncoder.WriteUShort(simpleSyncableEvent.syncId);
|
||||
byteEncoder.WriteByte((byte)simpleSyncableEvent.eventType);
|
||||
byteEncoder.WriteByte(simpleSyncableEvent.index);
|
||||
}
|
||||
|
||||
public SimpleSyncableEventMessage(Packet packet)
|
||||
@@ -36,6 +38,7 @@ namespace BoneSync.Networking.Messages
|
||||
byteEncoder.WriteBytes(packet.Data);
|
||||
eventData.syncId = byteEncoder.ReadUShort();
|
||||
eventData.eventType = (SimpleEventType)byteEncoder.ReadByte();
|
||||
eventData.index = byteEncoder.ReadByte();
|
||||
}
|
||||
|
||||
public override void Execute()
|
||||
@@ -44,7 +47,5 @@ namespace BoneSync.Networking.Messages
|
||||
if (syncable == null) return;
|
||||
syncable.OnSimpleSyncableEvent(eventData);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,12 @@ namespace BoneSync.Patching
|
||||
|
||||
MelonLogger.Msg("ForcePullGrip.OnFarHandHoverUpdate: " + __instance.name + " Hand: " + hand.name);
|
||||
|
||||
InteractableHost interactableHost = __instance.GetComponentInParent<InteractableHost>();
|
||||
if (interactableHost == null) return;
|
||||
InteractableHost interactableHost = __instance?.grip?.host;
|
||||
if (interactableHost == null)
|
||||
{
|
||||
MelonLogger.Error("InteractableHost is null for " + __instance.name);
|
||||
return;
|
||||
}
|
||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(interactableHost);
|
||||
|
||||
syncable?.RegisterSyncable();
|
||||
|
||||
@@ -17,15 +17,15 @@ namespace BoneSync.Patching
|
||||
public class GunPatches
|
||||
{
|
||||
[HarmonyPatch(nameof(Gun.Fire)), HarmonyPrefix]
|
||||
public static void FirePatch(Gun __instance)
|
||||
public static bool FirePatch(Gun __instance)
|
||||
{
|
||||
if (CallPatchedMethods.allowPatchedMethodCall) return;
|
||||
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
||||
MelonLoader.MelonLogger.Msg("Gun fired: " + __instance.name);
|
||||
if (!BoneSync.lobby.IsConnected()) return;
|
||||
if (!BoneSync.lobby.IsConnected()) return true;
|
||||
|
||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
|
||||
if (syncable == null) return;
|
||||
if (!syncable.Registered) return;
|
||||
if (syncable == null) return true;
|
||||
if (!syncable.Registered) return true;
|
||||
|
||||
if (syncable.isOwner)
|
||||
{
|
||||
@@ -42,7 +42,7 @@ namespace BoneSync.Patching
|
||||
gunSyncMessage.Broadcast();
|
||||
}
|
||||
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace BoneSync.Patching
|
||||
return;
|
||||
}
|
||||
|
||||
plugSyncable.FindAndUpdateComponents();
|
||||
|
||||
if (!plugSyncable.Registered)
|
||||
{
|
||||
MelonLogger.Warning("PlugSyncable not registered");
|
||||
@@ -40,6 +42,8 @@ namespace BoneSync.Patching
|
||||
MelonLogger.Warning("SocketSyncable not found");
|
||||
}
|
||||
|
||||
plugSyncable.FindAndUpdateComponents();
|
||||
|
||||
if (socketSyncable && socketSyncable.isOwner && !plugSyncable.isOwner)
|
||||
{
|
||||
plugSyncable.TryBecomeOwner(true); // forcefully take ownership of the plug
|
||||
|
||||
@@ -145,10 +145,7 @@ namespace BoneSync.Sync.Components
|
||||
|
||||
public bool CheckIfShouldAutoSync()
|
||||
{
|
||||
if (transform.GetPath().StartsWith("/Pool Manager/"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (InPoolManagerTransform()) return false;
|
||||
if (poolee && poolee.pool) {
|
||||
return true;
|
||||
}
|
||||
@@ -197,10 +194,21 @@ namespace BoneSync.Sync.Components
|
||||
_attemptedRegister = false;
|
||||
SetKinematic(false);
|
||||
}
|
||||
|
||||
private bool InPoolManagerTransform()
|
||||
{
|
||||
if (transform.GetPath().StartsWith("/Pool Manager/"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public bool CanBeSynced()
|
||||
{
|
||||
|
||||
if (spawnFragment) return false; // if has spawn fragment, don't sync
|
||||
FindAndUpdateComponents();
|
||||
if (InPoolManagerTransform()) return false;
|
||||
if (rigidbodies.Length > 0) return true;
|
||||
|
||||
return false;
|
||||
@@ -241,12 +249,6 @@ namespace BoneSync.Sync.Components
|
||||
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);
|
||||
|
||||
if (isPlugged)
|
||||
{
|
||||
MelonLogger.Warning("Trying to discard plugged syncable: " + transform.GetPath());
|
||||
}
|
||||
|
||||
|
||||
if (canDiscard)
|
||||
{
|
||||
_SendDiscard(true); // owner sends discard message
|
||||
@@ -255,7 +257,14 @@ namespace BoneSync.Sync.Components
|
||||
if (!canDiscard && !force) return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
EjectAllPlugs(true);
|
||||
}
|
||||
catch {
|
||||
MelonLogger.Warning("Failed to eject plugs (should be fine)");
|
||||
}
|
||||
|
||||
|
||||
if (gameObject) syncablesCache.Remove(gameObject);
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ namespace BoneSync.Sync.Components
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void SetKinematic(bool kinematic)
|
||||
|
||||
private void _SetKinematic(bool kinematic)
|
||||
{
|
||||
if (!this) return;
|
||||
if (rigidbodies.Length == 0) return;
|
||||
foreach (Rigidbody rb in rigidbodies)
|
||||
{
|
||||
@@ -65,6 +65,17 @@ namespace BoneSync.Sync.Components
|
||||
catch { } // ignore null rigidbodies
|
||||
}
|
||||
}
|
||||
private void SetKinematic(bool kinematic)
|
||||
{
|
||||
if (!this) return;
|
||||
try
|
||||
{
|
||||
_SetKinematic(kinematic);
|
||||
}
|
||||
catch {
|
||||
MelonLogger.Warning("Failed to set kinematic");
|
||||
}
|
||||
}
|
||||
|
||||
public ObjectSyncTransform[] GetObjectSyncTransforms()
|
||||
{
|
||||
@@ -99,7 +110,18 @@ namespace BoneSync.Sync.Components
|
||||
}
|
||||
}
|
||||
|
||||
private Rigidbody[] UpdateRigidbodyList()
|
||||
private Syncable GetRigidbodySyncable(Rigidbody rigidbody)
|
||||
{
|
||||
if (rigidbody == null) return null;
|
||||
return rigidbody.GetComponentInParent<Syncable>();
|
||||
}
|
||||
|
||||
private bool RigidbodyBelongsToSyncable(Rigidbody rigidbody)
|
||||
{
|
||||
return GetRigidbodySyncable(rigidbody) == this;
|
||||
}
|
||||
|
||||
private Rigidbody[] GetRigidbodies()
|
||||
{
|
||||
if (interactableManager)
|
||||
{
|
||||
@@ -120,7 +142,7 @@ namespace BoneSync.Sync.Components
|
||||
private void UpdateTransformList()
|
||||
{
|
||||
// get non-null rigidbodies
|
||||
Rigidbody[] rbs = UpdateRigidbodyList().Where(rb => rb != null).ToArray();
|
||||
Rigidbody[] rbs = GetRigidbodies().Where(rb => rb != null && RigidbodyBelongsToSyncable(rb)).ToArray();
|
||||
rigidbodies = rbs;
|
||||
_transforms = rbs.Select(rb => rb.transform).ToArray();
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ namespace BoneSync.Sync.Components
|
||||
{
|
||||
foreach (AlignPlug plug in plugs)
|
||||
{
|
||||
if (plug == null) continue;
|
||||
if (plug.GetSocket())
|
||||
{
|
||||
if (force)
|
||||
|
||||
@@ -122,13 +122,15 @@ namespace BoneSync.Sync
|
||||
// delete all sub syncables
|
||||
if (deleteSubSyncabled)
|
||||
{
|
||||
Syncable[] subSyncables = gameObject.GetComponentsInChildren<Syncable>();
|
||||
Syncable[] subSyncables = gameObject.GetComponentsInChildren<Syncable>(true);
|
||||
for (int i = 0; i < subSyncables.Length; i++)
|
||||
{
|
||||
if (subSyncables[i] != syncable)
|
||||
{
|
||||
subSyncables[i].DiscardSyncable();
|
||||
}
|
||||
Syncable subSyncable = subSyncables[i];
|
||||
if (subSyncable == syncable) continue;
|
||||
bool isRegistered = subSyncable.Registered;
|
||||
MelonLogger.Msg("Discarding subSyncable: " + subSyncable.transform.GetPath() + " registered:" + isRegistered);
|
||||
if (isRegistered) continue;
|
||||
subSyncable.DiscardSyncableImmediate(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user