Work on mag sync, broken af atm
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using BoneSync.Sync;
|
using BoneSync.Sync;
|
||||||
using BoneSync.Sync.Components;
|
using BoneSync.Sync.Components;
|
||||||
|
using MelonLoader;
|
||||||
using StressLevelZero.Interaction;
|
using StressLevelZero.Interaction;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -41,14 +42,28 @@ namespace BoneSync.Networking.Messages
|
|||||||
|
|
||||||
public override void Execute()
|
public override void Execute()
|
||||||
{
|
{
|
||||||
|
MelonLogger.Msg("Got PlugSyncMessage " + messageData.plugSyncId + ":" + messageData.plugIndex + " " + messageData.socketSyncId + ":" + messageData.socketIndex);
|
||||||
Syncable plugSyncable = ObjectSyncCache.GetSyncable(messageData.plugSyncId);
|
Syncable plugSyncable = ObjectSyncCache.GetSyncable(messageData.plugSyncId);
|
||||||
Syncable socketSyncable = ObjectSyncCache.GetSyncable(messageData.socketSyncId);
|
Syncable socketSyncable = ObjectSyncCache.GetSyncable(messageData.socketSyncId);
|
||||||
|
|
||||||
if (!plugSyncable || messageData.plugIndex == byte.MaxValue) { return; }
|
if (!plugSyncable || messageData.plugIndex == byte.MaxValue)
|
||||||
AlignPlug plug = (AlignPlug)plugSyncable.GetPlugFromId(messageData.plugIndex);
|
{
|
||||||
if (plug == null) { return; }
|
MelonLogger.Warning("PlugSyncable not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AlignPlug plug = plugSyncable.GetPlugFromId(messageData.plugIndex);
|
||||||
|
|
||||||
|
if (plug == null) {
|
||||||
|
MelonLogger.Warning("Plug not found, " + plugSyncable.transform.GetPath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (plug == null) {
|
||||||
|
MelonLogger.Warning("Plug is not an AlignPlug");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!socketSyncable || messageData.socketIndex == byte.MaxValue) {
|
if (!socketSyncable || messageData.socketIndex == byte.MaxValue) {
|
||||||
|
MelonLogger.Warning("SocketSyncable not found");
|
||||||
plug.SafeEject();
|
plug.SafeEject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -56,10 +71,13 @@ namespace BoneSync.Networking.Messages
|
|||||||
Socket socket = socketSyncable.GetSocketFromId(messageData.socketIndex);
|
Socket socket = socketSyncable.GetSocketFromId(messageData.socketIndex);
|
||||||
if (socket == null)
|
if (socket == null)
|
||||||
{
|
{
|
||||||
|
MelonLogger.Warning("Unable to find socket from ID");
|
||||||
plug.SafeEject();
|
plug.SafeEject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MelonLogger.Msg("Inserting networked plug");
|
||||||
|
|
||||||
plug.SafeInsert(socket);
|
plug.SafeInsert(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace BoneSync.Networking.Messages
|
|||||||
public SimpleSyncableEventMessage(SimpleSyncableEvent simpleSyncableEvent)
|
public SimpleSyncableEventMessage(SimpleSyncableEvent simpleSyncableEvent)
|
||||||
{
|
{
|
||||||
eventData = simpleSyncableEvent;
|
eventData = simpleSyncableEvent;
|
||||||
byteEncoder.WriteULong(simpleSyncableEvent.syncId);
|
byteEncoder.WriteUShort(simpleSyncableEvent.syncId);
|
||||||
byteEncoder.WriteByte((byte)simpleSyncableEvent.eventType);
|
byteEncoder.WriteByte((byte)simpleSyncableEvent.eventType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace BoneSync.Patching
|
|||||||
|
|
||||||
MelonLogger.Msg("ForcePullGrip.OnFarHandHoverUpdate: " + __instance.name + " Hand: " + hand.name);
|
MelonLogger.Msg("ForcePullGrip.OnFarHandHoverUpdate: " + __instance.name + " Hand: " + hand.name);
|
||||||
|
|
||||||
InteractableHost interactableHost = __instance.GetComponent<InteractableHost>();
|
InteractableHost interactableHost = __instance.GetComponentInParent<InteractableHost>();
|
||||||
if (interactableHost == null) return;
|
if (interactableHost == null) return;
|
||||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(interactableHost);
|
Syncable syncable = ObjectSync.MakeOrGetSyncable(interactableHost);
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using BoneSync.Networking.Messages;
|
|||||||
using BoneSync.Sync;
|
using BoneSync.Sync;
|
||||||
using BoneSync.Sync.Components;
|
using BoneSync.Sync.Components;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
|
using MelonLoader;
|
||||||
using StressLevelZero.Props.Weapons;
|
using StressLevelZero.Props.Weapons;
|
||||||
|
|
||||||
namespace BoneSync.Patching
|
namespace BoneSync.Patching
|
||||||
@@ -16,18 +17,19 @@ namespace BoneSync.Patching
|
|||||||
public class GunPatches
|
public class GunPatches
|
||||||
{
|
{
|
||||||
[HarmonyPatch(nameof(Gun.Fire)), HarmonyPrefix]
|
[HarmonyPatch(nameof(Gun.Fire)), HarmonyPrefix]
|
||||||
public static bool FirePatch(Gun __instance)
|
public static void FirePatch(Gun __instance)
|
||||||
{
|
{
|
||||||
if (CallPatchedMethods.allowPatchedMethodCall) return true;
|
if (CallPatchedMethods.allowPatchedMethodCall) return;
|
||||||
MelonLoader.MelonLogger.Msg("Gun fired: " + __instance.name);
|
MelonLoader.MelonLogger.Msg("Gun fired: " + __instance.name);
|
||||||
if (!BoneSync.lobby.IsConnected()) return true;
|
if (!BoneSync.lobby.IsConnected()) return;
|
||||||
|
|
||||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
|
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance.gameObject);
|
||||||
if (syncable == null) return true;
|
if (syncable == null) return;
|
||||||
if (!syncable.Registered) return true;
|
if (!syncable.Registered) return;
|
||||||
|
|
||||||
if (syncable.isOwner)
|
if (syncable.isOwner)
|
||||||
{
|
{
|
||||||
|
MelonLogger.Msg("Sending gun fire message: " + __instance.name);
|
||||||
GunSyncInfo gunSyncInfo = new GunSyncInfo()
|
GunSyncInfo gunSyncInfo = new GunSyncInfo()
|
||||||
{
|
{
|
||||||
cartridgeState = __instance.cartridgeState,
|
cartridgeState = __instance.cartridgeState,
|
||||||
@@ -40,7 +42,7 @@ namespace BoneSync.Patching
|
|||||||
gunSyncMessage.Broadcast();
|
gunSyncMessage.Broadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,70 +13,15 @@ using static MelonLoader.MelonLogger;
|
|||||||
|
|
||||||
namespace BoneSync.Patching
|
namespace BoneSync.Patching
|
||||||
{
|
{
|
||||||
/*[HarmonyPatch(typeof(Socket))]
|
|
||||||
public static class SocketPatches
|
|
||||||
{
|
|
||||||
public static void GenericSocketEnterPatch(Socket __instance, Plug plug)
|
|
||||||
{
|
|
||||||
if (!plug) return;
|
|
||||||
MelonLogger.Msg("Plug entered: " + __instance.name + " Plug: " + plug.name);
|
|
||||||
Syncable syncable = ObjectSyncCache.GetSyncable(plug);
|
|
||||||
if (!syncable) return;
|
|
||||||
byte plugId = syncable.GetPlugId(plug);
|
|
||||||
byte socketId = syncable.GetSocketId(__instance);
|
|
||||||
MelonLogger.Msg("Plug entered: " + __instance.transform.GetPath() + " Plug: " + plug.transform.GetPath() + " ID: " + plugId + " Socket ID: " + socketId);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void GenericSocketExitPatch(Socket __instance, Plug plug)
|
|
||||||
{
|
|
||||||
if (!plug) return;
|
|
||||||
MelonLogger.Msg("Plug exited: " + __instance.name + " Plug: " + plug.name);
|
|
||||||
Syncable syncable = ObjectSyncCache.GetSyncable(plug);
|
|
||||||
if (!syncable) return;
|
|
||||||
byte plugId = syncable.GetPlugId(plug);
|
|
||||||
byte socketId = syncable.GetSocketId(__instance);
|
|
||||||
MelonLogger.Msg("Plug exited: " + __instance.transform.GetPath() + " Plug: " + plug.transform.GetPath() + " ID: " + plugId + " Socket ID: " + socketId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
[HarmonyPatch(nameof(Socket.OnPlugEnter)), HarmonyPostfix]
|
|
||||||
public static void SocketEnterPatch(Socket __instance, Plug plug)
|
|
||||||
{
|
|
||||||
GenericSocketEnterPatch(__instance, plug);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(nameof(Socket.OnPlugExit)), HarmonyPostfix]
|
|
||||||
public static void SocketExitPatch(Socket __instance, Plug plug)
|
|
||||||
{
|
|
||||||
GenericSocketExitPatch(__instance, plug);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(MagazineSocket))]
|
|
||||||
public static class MagazineSocketPatches
|
|
||||||
{
|
|
||||||
[HarmonyPatch(nameof(MagazineSocket.OnPlugEnter)), HarmonyPostfix]
|
|
||||||
public static void MagazineSocketEnterPatch(MagazineSocket __instance, Plug plug)
|
|
||||||
{
|
|
||||||
SocketPatches.GenericSocketEnterPatch(__instance, plug);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(nameof(MagazineSocket.OnPlugExit)), HarmonyPostfix]
|
|
||||||
public static void SocketExitPatch(MagazineSocket __instance, Plug plug)
|
|
||||||
{
|
|
||||||
SocketPatches.GenericSocketExitPatch(__instance, plug);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
[HarmonyPatch(typeof(AlignPlug))]
|
[HarmonyPatch(typeof(AlignPlug))]
|
||||||
public static class AlignPlugPatches
|
public static class AlignPlugPatches
|
||||||
{
|
{
|
||||||
public static void OnPlugSocketChange(AlignPlug plug, Socket socket)
|
public static void OnPlugSocketChange(AlignPlug plug, Socket socket)
|
||||||
{
|
{
|
||||||
|
|
||||||
Syncable plugSyncable = plug.GetComponentInParent<Syncable>();
|
Syncable plugSyncable = plug.GetComponentInParent<Syncable>();
|
||||||
Syncable socketSyncable = socket.GetComponentInParent<Syncable>();
|
Syncable socketSyncable = socket?.GetComponentInParent<Syncable>();
|
||||||
|
|
||||||
if (!plugSyncable)
|
if (!plugSyncable)
|
||||||
{
|
{
|
||||||
@@ -119,31 +64,32 @@ namespace BoneSync.Patching
|
|||||||
plugSyncMessage.Broadcast();
|
plugSyncMessage.Broadcast();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPatch(nameof(AlignPlug.InsertPlug)), HarmonyPostfix]
|
// for some reason AlignPlug.OnPlugInsertComplete can't be patched directly
|
||||||
public static void AlignPlugInsertPatch(AlignPlug __instance, Socket socket)
|
/*
|
||||||
{
|
[HarmonyPatch(nameof(AlignPlug.OnPlugExitComplete)), HarmonyPostfix]
|
||||||
MelonLogger.Msg("AlignPlug inserted: " + __instance.transform.GetPath() + " Socket: " + socket.transform.GetPath());
|
|
||||||
OnPlugSocketChange(__instance, socket);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
[HarmonyPatch(nameof(AlignPlug.EjectPlug)), HarmonyPostfix]
|
|
||||||
public static void AlignPlugEjectPatch(AlignPlug __instance)
|
public static void AlignPlugEjectPatch(AlignPlug __instance)
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("AlignPlug ejected: " + __instance.transform.GetPath());
|
MelonLogger.Msg("AlignPlug ejected: " + __instance.transform.GetPath());
|
||||||
OnPlugSocketChange(__instance, null);
|
OnPlugSocketChange(__instance, null);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(MagazinePlug))]
|
||||||
|
public static class MagazinePlugPatches
|
||||||
|
{
|
||||||
|
[HarmonyPatch(nameof(MagazinePlug.OnPlugInsertComplete)), HarmonyPostfix]
|
||||||
|
public static void MagazinePlugInsertPatch(MagazinePlug __instance)
|
||||||
|
{
|
||||||
|
MelonLogger.Msg("MagazinePlug inserted: " + __instance.transform.GetPath());
|
||||||
|
AlignPlugPatches.OnPlugSocketChange(__instance, __instance.GetSocket());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
[HarmonyPatch(nameof(MagazinePlug.OnPlugExitComplete)), HarmonyPostfix]
|
||||||
|
public static void MagazinePlugEjectPatch(MagazinePlug __instance)
|
||||||
|
|
||||||
|
|
||||||
public class PlugPatches
|
|
||||||
{
|
|
||||||
/*[HarmonyPatch(typeof(Plug))]
|
|
||||||
public class PlugPatches
|
|
||||||
{
|
{
|
||||||
[HarmonyPatch(nameof(Plug.)), HarmonyPostfix]
|
MelonLogger.Msg("MagazinePlug ejected: " + __instance.transform.GetPath());
|
||||||
}*/
|
AlignPlugPatches.OnPlugSocketChange(__instance, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ namespace BoneSync.Sync.Components
|
|||||||
private Gun gun;
|
private Gun gun;
|
||||||
private Magazine magazine;
|
private Magazine magazine;
|
||||||
|
|
||||||
private Plug[] plugs;
|
private AlignPlug[] plugs;
|
||||||
private Socket[] sockets;
|
private Socket[] sockets;
|
||||||
|
|
||||||
private AIBrain aiBrain;
|
private AIBrain aiBrain;
|
||||||
@@ -180,7 +180,7 @@ namespace BoneSync.Sync.Components
|
|||||||
objectDestructable = GetComponent<ObjectDestructable>();
|
objectDestructable = GetComponent<ObjectDestructable>();
|
||||||
gun = GetComponent<Gun>();
|
gun = GetComponent<Gun>();
|
||||||
magazine = GetComponent<Magazine>();
|
magazine = GetComponent<Magazine>();
|
||||||
plugs = GetComponentsInChildren<Plug>();
|
plugs = GetComponentsInChildren<AlignPlug>();
|
||||||
sockets = GetComponentsInChildren<Socket>();
|
sockets = GetComponentsInChildren<Socket>();
|
||||||
spawnFragment = GetComponent<SpawnFragment>();
|
spawnFragment = GetComponent<SpawnFragment>();
|
||||||
|
|
||||||
@@ -215,7 +215,19 @@ namespace BoneSync.Sync.Components
|
|||||||
}
|
}
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsPlugged()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < plugs.Length; i++)
|
||||||
|
{
|
||||||
|
AlignPlug alignPlug = plugs[i];
|
||||||
|
if (alignPlug.GetSocket()) return true;
|
||||||
|
if (alignPlug._isEnterTransition) return true;
|
||||||
|
if (alignPlug._isExitTransition) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
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 (!this) return; // if object is destroyed, don't do anything
|
||||||
@@ -223,19 +235,28 @@ namespace BoneSync.Sync.Components
|
|||||||
|
|
||||||
if (isRegistered)
|
if (isRegistered)
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("Discarding syncable: " + transform.GetPath() + " force: " + force + " isRegistered: " + isRegistered + " despawn: " + despawn);
|
bool isPlugged = IsPlugged();
|
||||||
|
|
||||||
|
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.Warning("Discarding registered syncable: " + transform.GetPath() + " force: " + force);
|
//MelonLogger.Warning("Discarding registered syncable: " + transform.GetPath() + " force: " + force);
|
||||||
|
|
||||||
bool isowner = isOwner;
|
if (isPlugged)
|
||||||
|
{
|
||||||
|
MelonLogger.Warning("Trying to discard plugged syncable: " + transform.GetPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isowner)
|
if (canDiscard)
|
||||||
{
|
{
|
||||||
_SendDiscard(true); // owner sends discard message
|
_SendDiscard(true); // owner sends discard message
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isowner && !force) return; // only owner can discard
|
if (!canDiscard && !force) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EjectAllPlugs(true);
|
||||||
|
|
||||||
if (gameObject) syncablesCache.Remove(gameObject);
|
if (gameObject) syncablesCache.Remove(gameObject);
|
||||||
|
|
||||||
ObjectSyncCache.RemoveSyncable(this);
|
ObjectSyncCache.RemoveSyncable(this);
|
||||||
@@ -271,7 +292,7 @@ namespace BoneSync.Sync.Components
|
|||||||
|
|
||||||
public void DiscardSyncableImmediate(bool force = false, bool despawn = false)
|
public void DiscardSyncableImmediate(bool force = false, bool despawn = false)
|
||||||
{
|
{
|
||||||
_DiscardSyncable(true, despawn);
|
_DiscardSyncable(force, despawn);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnDisable()
|
public void OnDisable()
|
||||||
|
|||||||
@@ -50,11 +50,18 @@ namespace BoneSync.Sync.Components
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerator __SendRegisterSyncCo()
|
||||||
|
{
|
||||||
|
yield return null; // wait a frame
|
||||||
|
SetOwner(BoneSync.lobby.GetLocalId());
|
||||||
|
SetSyncId(ObjectSync.SendRegisterSyncableMessage(this));
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
|
||||||
private void _SendRegisterSync()
|
private void _SendRegisterSync()
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("Registering syncable object: " + gameObject.name);
|
MelonLogger.Msg("Registering syncable object: " + gameObject.name);
|
||||||
SetOwner(BoneSync.lobby.GetLocalId());
|
MelonCoroutines.Start(__SendRegisterSyncCo());
|
||||||
SetSyncId(ObjectSync.SendRegisterSyncableMessage(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _SendDiscard(bool despawn = false)
|
private void _SendDiscard(bool despawn = false)
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ namespace BoneSync.Sync.Components
|
|||||||
}
|
}
|
||||||
if (poolee)
|
if (poolee)
|
||||||
{
|
{
|
||||||
return new Rigidbody[] { poolee.GetComponentInChildren<Rigidbody>() };
|
return new Rigidbody[] { poolee.GetComponentInChildren<Rigidbody>(true) };
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Rigidbody[0];
|
return new Rigidbody[0];
|
||||||
@@ -127,7 +127,8 @@ namespace BoneSync.Sync.Components
|
|||||||
|
|
||||||
private void UpdateKinematic()
|
private void UpdateKinematic()
|
||||||
{
|
{
|
||||||
SetKinematic(_ownerId != BoneSync.lobby.GetLocalId() && Registered);
|
//SetKinematic(false);
|
||||||
|
SetKinematic(_ownerId != BoneSync.lobby.GetLocalId() && Registered && !IsPlugged());
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void OnSimpleSyncableEvent(SimpleSyncableEvent eventData)
|
internal void OnSimpleSyncableEvent(SimpleSyncableEvent eventData)
|
||||||
|
|||||||
@@ -15,10 +15,9 @@ namespace BoneSync.Sync.Components
|
|||||||
{
|
{
|
||||||
Socket socket = plug._lastSocket;
|
Socket socket = plug._lastSocket;
|
||||||
if (!socket) return null;
|
if (!socket) return null;
|
||||||
if (socket.LockedPlug == plug)
|
if (socket.LockedPlug == plug) return socket;
|
||||||
{
|
if (plug._isExitTransition) return socket;
|
||||||
return socket;
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,14 +28,23 @@ namespace BoneSync.Sync.Components
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ForceEject(this AlignPlug plug)
|
||||||
|
{
|
||||||
|
if (!plug.GetSocket()) return;
|
||||||
|
plug.EjectPlug();
|
||||||
|
plug.ClearFromSocket();
|
||||||
|
plug._isEnterTransition = false;
|
||||||
|
plug._isExitTransition = false;
|
||||||
|
plug._isExitComplete = true;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool SafeInsert(this AlignPlug plug, Socket socket)
|
public static bool SafeInsert(this AlignPlug plug, Socket socket)
|
||||||
{
|
{
|
||||||
if (!socket) return false;
|
if (!socket) return false;
|
||||||
if (socket.LockedPlug) return false;
|
if (socket.LockedPlug) return false;
|
||||||
if (plug.GetSocket() && plug._lastSocket != socket)
|
if (plug.GetSocket() && plug._lastSocket != socket)
|
||||||
{
|
{
|
||||||
plug.EjectPlug();
|
plug.ForceEject();
|
||||||
plug.ClearFromSocket();
|
|
||||||
}
|
}
|
||||||
plug.InsertPlug(socket);
|
plug.InsertPlug(socket);
|
||||||
return true;
|
return true;
|
||||||
@@ -44,7 +52,25 @@ namespace BoneSync.Sync.Components
|
|||||||
}
|
}
|
||||||
public partial class Syncable : MonoBehaviour
|
public partial class Syncable : MonoBehaviour
|
||||||
{
|
{
|
||||||
public Plug GetPlugFromId(byte id)
|
|
||||||
|
public void EjectAllPlugs(bool force = false)
|
||||||
|
{
|
||||||
|
foreach (AlignPlug plug in plugs)
|
||||||
|
{
|
||||||
|
if (plug.GetSocket())
|
||||||
|
{
|
||||||
|
if (force)
|
||||||
|
{
|
||||||
|
plug.ForceEject();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
plug.SafeEject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public AlignPlug GetPlugFromId(byte id)
|
||||||
{
|
{
|
||||||
if (plugs.Length <= id)
|
if (plugs.Length <= id)
|
||||||
{
|
{
|
||||||
@@ -77,7 +103,7 @@ namespace BoneSync.Sync.Components
|
|||||||
return 255;
|
return 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte GetPlugId(Plug plug)
|
public byte GetPlugId(AlignPlug plug)
|
||||||
{
|
{
|
||||||
for (byte i = 0; i < plugs.Length; i++)
|
for (byte i = 0; i < plugs.Length; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,13 +43,19 @@ namespace BoneSync.Sync
|
|||||||
}
|
}
|
||||||
else if (syncable.poolee && syncable.poolee.pool && (BoneSync.lobby.IsHost || allowClientRegister))
|
else if (syncable.poolee && syncable.poolee.pool && (BoneSync.lobby.IsHost || allowClientRegister))
|
||||||
{
|
{
|
||||||
|
string spawnableRealTitle = syncable?.poolee?.spawnObject?.title;
|
||||||
|
string spawnableAlternateTitle = syncable?.poolee?.pool?.name.Replace("pool - ", ""); // hacky, but use when real title is unknown
|
||||||
|
|
||||||
|
string spawnableTitle = spawnableRealTitle ?? spawnableAlternateTitle;
|
||||||
|
|
||||||
|
MelonLogger.Msg("Spawnable title: " + spawnableTitle);
|
||||||
info = new RegisterSyncableInfo()
|
info = new RegisterSyncableInfo()
|
||||||
{
|
{
|
||||||
ownerId = ownerId,
|
ownerId = ownerId,
|
||||||
type = RegisterSyncType.RegisterAndSpawn,
|
type = RegisterSyncType.RegisterAndSpawn,
|
||||||
spawnInfo = new SpawnPoolableInfo()
|
spawnInfo = new SpawnPoolableInfo()
|
||||||
{
|
{
|
||||||
spawnableTitle = syncable.poolee.spawnObject.title,
|
spawnableTitle = spawnableTitle,
|
||||||
spawnLocation = new SimpleSyncTransform(syncable.poolee.transform),
|
spawnLocation = new SimpleSyncTransform(syncable.poolee.transform),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -59,11 +65,12 @@ namespace BoneSync.Sync
|
|||||||
|
|
||||||
public static ushort SendRegisterSyncableMessage(Syncable syncable)
|
public static ushort SendRegisterSyncableMessage(Syncable syncable)
|
||||||
{
|
{
|
||||||
|
MelonLogger.Msg("Sending register syncable message for: " + syncable.transform.name);
|
||||||
RegisterSyncableInfo? infoNullable = GetRegisterInfo(syncable, syncable.ClientSpawningAllowed());
|
RegisterSyncableInfo? infoNullable = GetRegisterInfo(syncable, syncable.ClientSpawningAllowed());
|
||||||
|
|
||||||
if (infoNullable == null)
|
if (infoNullable == null)
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("No valid registeration method for syncable");
|
MelonLogger.Warning("No valid registeration method for syncable");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +200,7 @@ namespace BoneSync.Sync
|
|||||||
}
|
}
|
||||||
public static void OnRegisterSyncMessage(RegisterSyncableMessage registerSyncableMessage)
|
public static void OnRegisterSyncMessage(RegisterSyncableMessage registerSyncableMessage)
|
||||||
{
|
{
|
||||||
|
MelonLogger.Msg("Received register sync message");
|
||||||
Syncable syncable = null;
|
Syncable syncable = null;
|
||||||
RegisterSyncableInfo info = registerSyncableMessage.info;
|
RegisterSyncableInfo info = registerSyncableMessage.info;
|
||||||
if (BoneSync.lobby.IsHost)
|
if (BoneSync.lobby.IsHost)
|
||||||
|
|||||||
Reference in New Issue
Block a user