Client spawning fix
This commit is contained in:
@@ -14,7 +14,7 @@ namespace BoneSync.Networking.Messages
|
||||
public ulong NewOwnerId;
|
||||
}
|
||||
|
||||
[PacketType(PacketType.ObjectOwnership)]
|
||||
[PacketType(PacketType.ObjectOwnership), PacketReliability(PacketReliability.ReliableFast)]
|
||||
internal class OnwershipTransferMessage : NetworkMessage
|
||||
{
|
||||
private OnwershipTransferMessageData Data;
|
||||
|
||||
@@ -74,6 +74,7 @@ namespace BoneSync.Patching
|
||||
[HarmonyPostfix]
|
||||
private static void InstantiatePooleePatchPost(Pool __instance, Poolee __result, Vector3 position, Quaternion rotation)
|
||||
{
|
||||
if (CallPatchedMethods.allowPatchedMethodCall) return;
|
||||
if (__instance == null) return;
|
||||
if (PoolBlacklist.isBlacklistedPool(__instance)) return;
|
||||
MelonLogger.Msg("Patched Instantiating object in pool: " + __instance.name);
|
||||
@@ -128,7 +129,7 @@ namespace BoneSync.Patching
|
||||
|
||||
MelonLogger.Msg("Poolee.OnSpawn: " + __instance.gameObject.transform.GetPath());
|
||||
|
||||
ObjectSync.MakeOrGetSyncable(__instance);
|
||||
Syncable syncable = ObjectSync.MakeOrGetSyncable(__instance);
|
||||
|
||||
bool spawnNormally = BoneSync.lobby.IsHost || PoolBlacklist.IsClientSpawnPool(__instance.pool);
|
||||
|
||||
|
||||
@@ -92,6 +92,17 @@ namespace BoneSync.Sync.Components
|
||||
|
||||
private SpawnFragment spawnFragment;
|
||||
|
||||
private IEnumerator _CheckAutoSyncCo()
|
||||
{
|
||||
yield return null;
|
||||
bool shouldAutoSync = CheckIfShouldAutoSync();
|
||||
if (shouldAutoSync && (BoneSync.lobby.IsHost || ClientSpawningAllowed()))
|
||||
{
|
||||
MelonLogger.Msg("AutoSyncing: " + transform.GetPath());
|
||||
RegisterSyncable();
|
||||
}
|
||||
yield break;
|
||||
}
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
@@ -99,12 +110,7 @@ namespace BoneSync.Sync.Components
|
||||
|
||||
FindComponents();
|
||||
|
||||
bool shouldAutoSync = CheckIfShouldAutoSync();
|
||||
if (shouldAutoSync && (BoneSync.lobby.IsHost || ClientSpawningAllowed()))
|
||||
{
|
||||
MelonLogger.Msg("AutoSyncing: " + transform.GetPath());
|
||||
RegisterSyncable();
|
||||
}
|
||||
MelonCoroutines.Start(_CheckAutoSyncCo());
|
||||
}
|
||||
|
||||
public bool CheckIfShouldAutoSync()
|
||||
@@ -156,27 +162,50 @@ namespace BoneSync.Sync.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
DiscardSyncable();
|
||||
//MelonLogger.Msg("Syncable destroyed: " + transform.GetPath());
|
||||
}
|
||||
|
||||
public void DiscardSyncable()
|
||||
private void _DiscardSyncable(bool force)
|
||||
{
|
||||
if (Registered)
|
||||
{
|
||||
MelonLogger.Warning("Discarding registered syncable: " + transform.GetPath());
|
||||
MelonLogger.Warning("Discarding registered syncable: " + transform.GetPath() + " force: " + force);
|
||||
if (!force) return;
|
||||
}
|
||||
syncablesCache.Remove(gameObject);
|
||||
ObjectSyncCache.RemoveSyncable(this);
|
||||
Destroy(this);
|
||||
Destroy(this); // delete the component
|
||||
}
|
||||
|
||||
public void OnDestroy()
|
||||
{
|
||||
if (Registered)
|
||||
{
|
||||
MelonLogger.Warning("Destroying registered syncable: " + transform.GetPath());
|
||||
}
|
||||
_DiscardSyncable(true);
|
||||
//MelonLogger.Msg("Syncable destroyed: " + transform.GetPath());
|
||||
}
|
||||
|
||||
private IEnumerator _FlagForDiscardCo(bool force)
|
||||
{
|
||||
yield return null;
|
||||
_DiscardSyncable(force);
|
||||
}
|
||||
|
||||
public void DiscardSyncable(bool force = false)
|
||||
{
|
||||
MelonCoroutines.Start(_FlagForDiscardCo(force));
|
||||
}
|
||||
|
||||
public void OnDisable()
|
||||
{
|
||||
if (Registered && !isOwner)
|
||||
{
|
||||
MelonLogger.Warning("tried to disable non-owner syncable: " + transform.GetPath());
|
||||
gameObject.SetActive(true);
|
||||
} else
|
||||
{
|
||||
DiscardSyncable();
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterSyncable()
|
||||
{
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace BoneSync.Sync
|
||||
// delete all sub syncables
|
||||
if (deleteSubSyncabled)
|
||||
{
|
||||
Syncable[] subSyncables = gameObject.GetComponentsInChildren<Syncable>(true);
|
||||
Syncable[] subSyncables = gameObject.GetComponentsInChildren<Syncable>();
|
||||
for (int i = 0; i < subSyncables.Length; i++)
|
||||
{
|
||||
if (subSyncables[i] != syncable)
|
||||
@@ -244,10 +244,15 @@ namespace BoneSync.Sync
|
||||
public static void OnObjectSyncMessage(ObjectSyncMessage objectSyncMessage)
|
||||
{
|
||||
ObjectSyncMessageData data = objectSyncMessage.objectSyncMessageData;
|
||||
Syncable syncable = ObjectSyncCache.GetSyncable(data.objectId);
|
||||
ushort objectId = data.objectId;
|
||||
if (objectId >= _nextSyncableId && !BoneSync.lobby.IsHost)
|
||||
{
|
||||
_nextSyncableId = (ushort)(objectId + 1);
|
||||
}
|
||||
Syncable syncable = ObjectSyncCache.GetSyncable(objectId);
|
||||
if (syncable == null)
|
||||
{
|
||||
MelonLogger.Msg("SyncEvent: Syncable not found for id: " + data.objectId);
|
||||
MelonLogger.Msg("SyncEvent: Syncable not found for id: " + objectId);
|
||||
return;
|
||||
}
|
||||
syncable.ApplyObjectSyncTransforms(data.objectSyncTransforms);
|
||||
|
||||
Reference in New Issue
Block a user