From 104c52c1835d8fba8991ce49a3e7e48184e8a6d7 Mon Sep 17 00:00:00 2001 From: Aaro Varis Date: Fri, 14 Mar 2025 21:30:03 +0200 Subject: [PATCH] Aaa --- .../Networking/Messages/SceneChangeMessage.cs | 18 +++++++++++++++++- BoneSync/Patching/ButtonTogglePatches.cs | 2 +- BoneSync/Patching/SceneManagerPatches.cs | 4 ++-- BoneSync/Patching/ZonePatches.cs | 8 +++++--- BoneSync/Sync/SceneSync.cs | 1 + 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/BoneSync/Networking/Messages/SceneChangeMessage.cs b/BoneSync/Networking/Messages/SceneChangeMessage.cs index dccc997..5476707 100644 --- a/BoneSync/Networking/Messages/SceneChangeMessage.cs +++ b/BoneSync/Networking/Messages/SceneChangeMessage.cs @@ -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; + } + } } } diff --git a/BoneSync/Patching/ButtonTogglePatches.cs b/BoneSync/Patching/ButtonTogglePatches.cs index 6302e42..e254857 100644 --- a/BoneSync/Patching/ButtonTogglePatches.cs +++ b/BoneSync/Patching/ButtonTogglePatches.cs @@ -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 patch = UnityEventPatch.TryGetPatch(__instance); if (patch != null) { diff --git a/BoneSync/Patching/SceneManagerPatches.cs b/BoneSync/Patching/SceneManagerPatches.cs index 3d92bdc..9a30765 100644 --- a/BoneSync/Patching/SceneManagerPatches.cs +++ b/BoneSync/Patching/SceneManagerPatches.cs @@ -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); } - } + }*/ } } diff --git a/BoneSync/Patching/ZonePatches.cs b/BoneSync/Patching/ZonePatches.cs index cdcd4e7..9dedf44 100644 --- a/BoneSync/Patching/ZonePatches.cs +++ b/BoneSync/Patching/ZonePatches.cs @@ -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,8 +99,9 @@ namespace BoneSync.Patching } return true; - } + }*/ + // only patch exit, as we want to allow activating a trigger always [HarmonyPatch(nameof(PlayerTrigger.OnTriggerExit)), HarmonyPrefix] public static bool ExitPrefix(PlayerTrigger __instance, Collider other) diff --git a/BoneSync/Sync/SceneSync.cs b/BoneSync/Sync/SceneSync.cs index 1350d5e..9f6d14e 100644 --- a/BoneSync/Sync/SceneSync.cs +++ b/BoneSync/Sync/SceneSync.cs @@ -76,6 +76,7 @@ namespace BoneSync.Sync SyncLogger.Msg("Scene initialized: " + SceneName); RenameDuplicateSceneTransforms(scene); SpawnableManager.AddUnregisteredSpawnables(); + SendSceneSyncMessage(buildIndex); } public static void Initialize()