This commit is contained in:
Aaro Varis
2025-03-14 21:30:03 +02:00
parent 95cd554eb0
commit 104c52c183
5 changed files with 26 additions and 7 deletions

View File

@@ -21,6 +21,7 @@ namespace BoneSync.Networking.Messages
public sceneChangeType sceneChangeType;
public string sceneName;
public byte sceneIndex;
public bool reloadScene;
}
[PacketType(PacketType.SceneChange), PacketReliability(PacketReliability.Reliable), AlwaysExecute]
internal class SceneChangeMessage : NetworkMessage
@@ -32,6 +33,7 @@ namespace BoneSync.Networking.Messages
{
_sceneChangeInfo = sceneChangeInfo;
byteEncoder.WriteByte((byte)_sceneChangeInfo.sceneChangeType);
byteEncoder.WriteBool(_sceneChangeInfo.reloadScene);
switch (_sceneChangeInfo.sceneChangeType)
{
case sceneChangeType.FromIndex:
@@ -51,6 +53,7 @@ namespace BoneSync.Networking.Messages
byteEncoder.SetBytes(packet.Data);
_sceneChangeInfo = new SceneChangeInfo();
_sceneChangeInfo.sceneChangeType = (sceneChangeType)byteEncoder.ReadByte();
_sceneChangeInfo.reloadScene = byteEncoder.ReadBool();
switch (_sceneChangeInfo.sceneChangeType)
{
case sceneChangeType.FromIndex:
@@ -69,7 +72,20 @@ namespace BoneSync.Networking.Messages
public override void Execute()
{
SyncLogger.Msg("SceneChangeMessage: " + _sceneChangeInfo.sceneName + " " + _sceneChangeInfo.sceneIndex);
BoneworksSceneManager.LoadScene(_sceneChangeInfo.sceneIndex);
switch (_sceneChangeInfo.sceneChangeType)
{
case sceneChangeType.FromIndex:
if (!_sceneChangeInfo.reloadScene && _sceneChangeInfo.sceneIndex == BoneworksSceneManager.currentSceneIndex) return; // don't reload the scene if it's already loaded
BoneworksSceneManager.LoadScene(_sceneChangeInfo.sceneIndex);
break;
case sceneChangeType.FromName:
BoneworksSceneManager.LoadScene(_sceneChangeInfo.sceneName);
break;
case sceneChangeType.CustomMap:
BoneworksSceneManager.LoadScene(_sceneChangeInfo.sceneName);
break;
}
}
}
}

View File

@@ -88,7 +88,7 @@ namespace BoneSync.Patching
[HarmonyPatch(nameof(UnityEvent.Invoke)), HarmonyPrefix]
private static bool InvokePrefix(UnityEvent __instance)
{
int hash = __instance.GetHashCode();
//int hash = __instance.GetHashCode();
UnityEventPatch<ButtonToggle> patch = UnityEventPatch<ButtonToggle>.TryGetPatch(__instance);
if (patch != null)
{

View File

@@ -14,7 +14,7 @@ namespace BoneSync.Patching
[HarmonyPatch(typeof(BoneworksSceneManager))]
internal class SceneManagerPatches
{
[HarmonyPatch(nameof(BoneworksSceneManager.LoadScene), new Type[] { typeof(int) }), HarmonyPrefix]
/*[HarmonyPatch(nameof(BoneworksSceneManager.LoadScene), new Type[] { typeof(int) }), HarmonyPrefix]
private static void LoadSceneIndexPrefix(int sceneBuildIndex)
{
SyncLogger.Msg("LoadScenePrefix: " + sceneBuildIndex);
@@ -36,6 +36,6 @@ namespace BoneSync.Patching
//SyncLogger.Msg("Host is loading scene, sending message to clients...");
//SceneSync.SendSceneSyncMessage(sceneName);
}
}
}*/
}
}

View File

@@ -62,7 +62,7 @@ namespace BoneSync.Patching
[HarmonyPatch(typeof(SceneZone))]
public static class SceneZonePatch
{
[HarmonyPatch(nameof(SceneZone.OnTriggerEnter)), HarmonyPrefix]
/*[HarmonyPatch(nameof(SceneZone.OnTriggerEnter)), HarmonyPrefix]
public static bool EnterPrefix(SceneZone __instance, Collider other)
{
if (other.CompareTag("Player"))
@@ -71,7 +71,7 @@ namespace BoneSync.Patching
}
return true;
}
}*/
[HarmonyPatch(nameof(SceneZone.OnTriggerExit)), HarmonyPrefix]
public static bool ExitPrefix(SceneZone __instance, Collider other)
@@ -88,6 +88,7 @@ namespace BoneSync.Patching
[HarmonyPatch(typeof(PlayerTrigger))]
public static class PlayerTriggerPatch
{
/*
[HarmonyPatch(nameof(PlayerTrigger.OnTriggerEnter)), HarmonyPrefix]
public static bool EnterPrefix(PlayerTrigger __instance, Collider other)
{
@@ -98,7 +99,8 @@ namespace BoneSync.Patching
}
return true;
}
}*/
// only patch exit, as we want to allow activating a trigger always
[HarmonyPatch(nameof(PlayerTrigger.OnTriggerExit)), HarmonyPrefix]

View File

@@ -76,6 +76,7 @@ namespace BoneSync.Sync
SyncLogger.Msg("Scene initialized: " + SceneName);
RenameDuplicateSceneTransforms(scene);
SpawnableManager.AddUnregisteredSpawnables();
SendSceneSyncMessage(buildIndex);
}
public static void Initialize()