From cac24fcc343569b73a57953ef35936df877f4906 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 28 Mar 2021 17:53:05 +0100 Subject: [PATCH 1/3] split pool code into seperate namespace --- QSB/ItemSync/ItemManager.cs | 12 ------ QSB/ItemSync/Patches/ItemPatches.cs | 20 ---------- QSB/Patches/QSBPatchManager.cs | 4 +- QSB/Player/Events/EnterLeaveEvent.cs | 1 + .../CustomNomaiRemoteCamera.cs | 2 +- .../CustomNomaiRemoteCameraPlatform.cs | 2 +- .../CustomNomaiRemoteCameraStreaming.cs | 2 +- QSB/PoolSync/Patches/PoolPatches.cs | 37 +++++++++++++++++++ QSB/PoolSync/PoolManager.cs | 24 ++++++++++++ QSB/QSB.csproj | 8 ++-- QSB/QSBNetworkManager.cs | 1 + QSB/manifest.json | 2 +- 12 files changed, 75 insertions(+), 40 deletions(-) rename QSB/{ItemSync => PoolSync}/CustomNomaiRemoteCamera.cs (98%) rename QSB/{ItemSync => PoolSync}/CustomNomaiRemoteCameraPlatform.cs (99%) rename QSB/{ItemSync => PoolSync}/CustomNomaiRemoteCameraStreaming.cs (98%) create mode 100644 QSB/PoolSync/Patches/PoolPatches.cs create mode 100644 QSB/PoolSync/PoolManager.cs diff --git a/QSB/ItemSync/ItemManager.cs b/QSB/ItemSync/ItemManager.cs index d4a04af4..f80543e4 100644 --- a/QSB/ItemSync/ItemManager.cs +++ b/QSB/ItemSync/ItemManager.cs @@ -19,18 +19,6 @@ namespace QSB.ItemSync QSBWorldSync.Init(); QSBWorldSync.Init(); QSBWorldSync.Init(); - foreach (var streaming in Resources.FindObjectsOfTypeAll()) - { - streaming.gameObject.AddComponent(); - } - foreach (var camera in Resources.FindObjectsOfTypeAll()) - { - camera.gameObject.AddComponent(); - } - foreach (var platform in Resources.FindObjectsOfTypeAll()) - { - platform.gameObject.AddComponent(); - } } public static IQSBOWItem GetObject(OWItem unityObject) diff --git a/QSB/ItemSync/Patches/ItemPatches.cs b/QSB/ItemSync/Patches/ItemPatches.cs index 6f390649..8a06c754 100644 --- a/QSB/ItemSync/Patches/ItemPatches.cs +++ b/QSB/ItemSync/Patches/ItemPatches.cs @@ -18,15 +18,6 @@ namespace QSB.ItemSync.Patches QSBCore.HarmonyHelper.AddPrefix("StartUnsocketItem", typeof(ItemPatches), nameof(ItemTool_StartUnsocketItem)); QSBCore.HarmonyHelper.AddPrefix("CompleteUnsocketItem", typeof(ItemPatches), nameof(ItemTool_CompleteUnsocketItem)); QSBCore.HarmonyHelper.AddPrefix("DropItem", typeof(ItemPatches), nameof(ItemTool_DropItem)); - QSBCore.HarmonyHelper.AddPrefix("Update", typeof(ItemPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnSocketableRemoved", typeof(ItemPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnSocketableDonePlacing", typeof(ItemPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnPedestalContact", typeof(ItemPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("FixedUpdate", typeof(ItemPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnSectorOccupantAdded", typeof(ItemPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnSectorOccupantRemoved", typeof(ItemPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnEntry", typeof(ItemPatches), nameof(ReturnFalse)); - QSBCore.HarmonyHelper.AddPrefix("OnExit", typeof(ItemPatches), nameof(ReturnFalse)); } public override void DoUnpatches() @@ -36,19 +27,8 @@ namespace QSB.ItemSync.Patches QSBCore.HarmonyHelper.Unpatch("StartUnsocketItem"); QSBCore.HarmonyHelper.Unpatch("CompleteUnsocketItem"); QSBCore.HarmonyHelper.Unpatch("DropItem"); - QSBCore.HarmonyHelper.Unpatch("Update"); - QSBCore.HarmonyHelper.Unpatch("OnSocketableRemoved"); - QSBCore.HarmonyHelper.Unpatch("OnSocketableDonePlacing"); - QSBCore.HarmonyHelper.Unpatch("OnPedestalContact"); - QSBCore.HarmonyHelper.Unpatch("FixedUpdate"); - QSBCore.HarmonyHelper.Unpatch("OnSectorOccupantAdded"); - QSBCore.HarmonyHelper.Unpatch("OnSectorOccupantRemoved"); - QSBCore.HarmonyHelper.Unpatch("OnEntry"); - QSBCore.HarmonyHelper.Unpatch("OnExit"); } - public static bool ReturnFalse() => false; - public static bool ItemTool_MoveItemToCarrySocket(OWItem item) { var itemId = QSBWorldSync.GetIdFromTypeSubset(ItemManager.GetObject(item)); diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 6a98a2fd..96192fee 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -7,6 +7,7 @@ using QSB.GeyserSync.Patches; using QSB.ItemSync.Patches; using QSB.LogSync.Patches; using QSB.OrbSync.Patches; +using QSB.PoolSync.Patches; using QSB.QuantumSync.Patches; using QSB.StatueSync.Patches; using QSB.TimeSync.Patches; @@ -43,7 +44,8 @@ namespace QSB.Patches new QuantumPatches(), new ItemPatches(), new StatuePatches(), - new GeyserPatches() + new GeyserPatches(), + new PoolPatches() }; DebugLog.DebugWrite("Patch Manager ready.", MessageType.Success); diff --git a/QSB/Player/Events/EnterLeaveEvent.cs b/QSB/Player/Events/EnterLeaveEvent.cs index d87c7071..e57f801c 100644 --- a/QSB/Player/Events/EnterLeaveEvent.cs +++ b/QSB/Player/Events/EnterLeaveEvent.cs @@ -1,5 +1,6 @@ using QSB.Events; using QSB.ItemSync; +using QSB.PoolSync; using QSB.Utility; namespace QSB.Player.Events diff --git a/QSB/ItemSync/CustomNomaiRemoteCamera.cs b/QSB/PoolSync/CustomNomaiRemoteCamera.cs similarity index 98% rename from QSB/ItemSync/CustomNomaiRemoteCamera.cs rename to QSB/PoolSync/CustomNomaiRemoteCamera.cs index 15b6df13..3c7c8b26 100644 --- a/QSB/ItemSync/CustomNomaiRemoteCamera.cs +++ b/QSB/PoolSync/CustomNomaiRemoteCamera.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace QSB.ItemSync +namespace QSB.PoolSync { internal class CustomNomaiRemoteCamera : MonoBehaviour { diff --git a/QSB/ItemSync/CustomNomaiRemoteCameraPlatform.cs b/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs similarity index 99% rename from QSB/ItemSync/CustomNomaiRemoteCameraPlatform.cs rename to QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs index c6893efc..7ebf6bfe 100644 --- a/QSB/ItemSync/CustomNomaiRemoteCameraPlatform.cs +++ b/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs @@ -8,7 +8,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -namespace QSB.ItemSync +namespace QSB.PoolSync { internal class CustomNomaiRemoteCameraPlatform : NomaiShared { diff --git a/QSB/ItemSync/CustomNomaiRemoteCameraStreaming.cs b/QSB/PoolSync/CustomNomaiRemoteCameraStreaming.cs similarity index 98% rename from QSB/ItemSync/CustomNomaiRemoteCameraStreaming.cs rename to QSB/PoolSync/CustomNomaiRemoteCameraStreaming.cs index ec4a4636..d98f6b80 100644 --- a/QSB/ItemSync/CustomNomaiRemoteCameraStreaming.cs +++ b/QSB/PoolSync/CustomNomaiRemoteCameraStreaming.cs @@ -1,6 +1,6 @@ using OWML.Utils; -namespace QSB.ItemSync +namespace QSB.PoolSync { internal class CustomNomaiRemoteCameraStreaming : SectoredMonoBehaviour { diff --git a/QSB/PoolSync/Patches/PoolPatches.cs b/QSB/PoolSync/Patches/PoolPatches.cs new file mode 100644 index 00000000..24d2bcf6 --- /dev/null +++ b/QSB/PoolSync/Patches/PoolPatches.cs @@ -0,0 +1,37 @@ +using QSB.Patches; + +namespace QSB.PoolSync.Patches +{ + internal class PoolPatches : QSBPatch + { + public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; + + public override void DoPatches() + { + QSBCore.HarmonyHelper.AddPrefix("Update", typeof(PoolPatches), nameof(ReturnFalse)); + QSBCore.HarmonyHelper.AddPrefix("OnSocketableRemoved", typeof(PoolPatches), nameof(ReturnFalse)); + QSBCore.HarmonyHelper.AddPrefix("OnSocketableDonePlacing", typeof(PoolPatches), nameof(ReturnFalse)); + QSBCore.HarmonyHelper.AddPrefix("OnPedestalContact", typeof(PoolPatches), nameof(ReturnFalse)); + QSBCore.HarmonyHelper.AddPrefix("FixedUpdate", typeof(PoolPatches), nameof(ReturnFalse)); + QSBCore.HarmonyHelper.AddPrefix("OnSectorOccupantAdded", typeof(PoolPatches), nameof(ReturnFalse)); + QSBCore.HarmonyHelper.AddPrefix("OnSectorOccupantRemoved", typeof(PoolPatches), nameof(ReturnFalse)); + QSBCore.HarmonyHelper.AddPrefix("OnEntry", typeof(PoolPatches), nameof(ReturnFalse)); + QSBCore.HarmonyHelper.AddPrefix("OnExit", typeof(PoolPatches), nameof(ReturnFalse)); + } + + public override void DoUnpatches() + { + QSBCore.HarmonyHelper.Unpatch("Update"); + QSBCore.HarmonyHelper.Unpatch("OnSocketableRemoved"); + QSBCore.HarmonyHelper.Unpatch("OnSocketableDonePlacing"); + QSBCore.HarmonyHelper.Unpatch("OnPedestalContact"); + QSBCore.HarmonyHelper.Unpatch("FixedUpdate"); + QSBCore.HarmonyHelper.Unpatch("OnSectorOccupantAdded"); + QSBCore.HarmonyHelper.Unpatch("OnSectorOccupantRemoved"); + QSBCore.HarmonyHelper.Unpatch("OnEntry"); + QSBCore.HarmonyHelper.Unpatch("OnExit"); + } + + public static bool ReturnFalse() => false; + } +} diff --git a/QSB/PoolSync/PoolManager.cs b/QSB/PoolSync/PoolManager.cs new file mode 100644 index 00000000..2ea1b52c --- /dev/null +++ b/QSB/PoolSync/PoolManager.cs @@ -0,0 +1,24 @@ +using QSB.WorldSync; +using UnityEngine; + +namespace QSB.PoolSync +{ + class PoolManager : WorldObjectManager + { + protected override void RebuildWorldObjects(OWScene scene) + { + foreach (var streaming in Resources.FindObjectsOfTypeAll()) + { + streaming.gameObject.AddComponent(); + } + foreach (var camera in Resources.FindObjectsOfTypeAll()) + { + camera.gameObject.AddComponent(); + } + foreach (var platform in Resources.FindObjectsOfTypeAll()) + { + platform.gameObject.AddComponent(); + } + } + } +} diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 6a2065eb..41d0668b 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -134,8 +134,8 @@ - - + + @@ -144,7 +144,7 @@ - + @@ -177,6 +177,8 @@ + + diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 486de516..4de1e1e0 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -7,6 +7,7 @@ using QSB.Instruments; using QSB.ItemSync; using QSB.Patches; using QSB.Player; +using QSB.PoolSync; using QSB.TimeSync; using QSB.TransformSync; using QSB.Utility; diff --git a/QSB/manifest.json b/QSB/manifest.json index addb0571..112fda3d 100644 --- a/QSB/manifest.json +++ b/QSB/manifest.json @@ -4,6 +4,6 @@ "name": "Quantum Space Buddies", "description": "Adds online multiplayer to the game.", "uniqueName": "Raicuparta.QuantumSpaceBuddies", - "version": "0.9.0", + "version": "0.9.1", "owmlVersion": "1.1.8" } \ No newline at end of file From 86fa334020dc356f7edad354dc8895ae8ab66962 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 28 Mar 2021 19:08:18 +0100 Subject: [PATCH 2/3] fix _poolT on slave not updating smoothly and fix holograms not appearing --- QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs | 17 +++++++++-------- QSB/QSBCore.cs | 2 ++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs b/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs index 7ebf6bfe..0e2cad5d 100644 --- a/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs +++ b/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs @@ -92,6 +92,7 @@ namespace QSB.PoolSync _hologramGroup.SetActive(false); UpdateRendererFade(); _transitionStone.SetActive(false); + _hologramGroup.transform.SetParent(null); } private void Start() @@ -258,7 +259,7 @@ namespace QSB.PoolSync return; } UpdatePoolRenderer(); - _slavePlatform._poolT = target; + _slavePlatform._poolT = _poolT; _slavePlatform.UpdatePoolRenderer(); } @@ -338,11 +339,6 @@ namespace QSB.PoolSync DebugLog.ToConsole($"Error - Gameobject for {item.Key.PlayerId} in _playerToHologram is null!", MessageType.Error); continue; } - if (!item.Value.activeInHierarchy) - { - DebugLog.ToConsole($"Error - Gameobject for {item.Key.PlayerId} is inactive!", MessageType.Error); - continue; - } var hologram = item.Value.transform.GetChild(0); hologram.position = TransformPoint(item.Key.Body.transform.position, this, _slavePlatform); hologram.rotation = TransformRotation(item.Key.Body.transform.rotation, this, _slavePlatform); @@ -400,7 +396,7 @@ namespace QSB.PoolSync { Debug.LogError("Shared stone with Remote Camera ID: " + _sharedStone.GetRemoteCameraID() + " has no registered camera platform!"); } - if (_slavePlatform == this || !_slavePlatform.gameObject.activeInHierarchy) + if (_slavePlatform == this || !_slavePlatform.gameObject.activeSelf) { _sharedStone = null; _slavePlatform = null; @@ -633,7 +629,7 @@ namespace QSB.PoolSync return; } var hologram = _playerToHologram.First(x => x.Key == player).Value; - if (hologram.activeInHierarchy) + if (hologram.activeSelf) { OnRemotePlayerExit(id); } @@ -690,6 +686,11 @@ namespace QSB.PoolSync return; } _playerToHologram[player].SetActive(false); + + if (!_anyoneStillOnPlatform) + { + _hologramGroup.SetActive(false); + } } public enum CameraState diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index b1169b3a..749f9b6f 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -8,6 +8,7 @@ using QSB.ItemSync; using QSB.OrbSync; using QSB.Patches; using QSB.Player; +using QSB.PoolSync; using QSB.QuantumSync; using QSB.QuantumSync.WorldObjects; using QSB.SectorSync; @@ -104,6 +105,7 @@ namespace QSB gameObject.AddComponent(); gameObject.AddComponent(); gameObject.AddComponent(); + gameObject.AddComponent(); DebugBoxManager.Init(); From 285163f5f6fb2e31630d9d7835b3379d5f632d93 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Mon, 29 Mar 2021 00:01:26 +0100 Subject: [PATCH 3/3] fix it yeah --- QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs | 12 +++++++++--- QSB/PoolSync/Patches/PoolPatches.cs | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs b/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs index 0e2cad5d..d8001c4e 100644 --- a/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs +++ b/QSB/PoolSync/CustomNomaiRemoteCameraPlatform.cs @@ -358,6 +358,10 @@ namespace QSB.PoolSync private void OnSocketableRemoved(OWItem socketable) { + if (_wasLocalInBounds) + { + QSBEventManager.FireEvent(EventNames.QSBExitPlatform, CustomPlatformList.IndexOf(this)); + } if (_slavePlatform == null) { return; @@ -560,6 +564,7 @@ namespace QSB.PoolSync private void OnLeaveBounds() { DisconnectCamera(); + QSBEventManager.FireEvent(EventNames.QSBExitPlatform, CustomPlatformList.IndexOf(this)); if (_anyoneStillOnPlatform) { return; @@ -642,6 +647,9 @@ namespace QSB.PoolSync { return; } + + _hologramGroup.SetActive(true); + var player = QSBPlayerManager.GetPlayer(playerId); if (_playerToHologram.ContainsKey(player)) { @@ -669,7 +677,6 @@ namespace QSB.PoolSync _playerToHologram.Add(player, hologramCopy.gameObject); - _hologramGroup.SetActive(true); hologramCopy.gameObject.SetActive(true); } @@ -682,12 +689,11 @@ namespace QSB.PoolSync var player = QSBPlayerManager.GetPlayer(playerId); if (!_playerToHologram.ContainsKey(player)) { - DebugLog.ToConsole($"Error - Trying to remove remote player {playerId} that isn't in _playerToHologram!", MessageType.Error); return; } _playerToHologram[player].SetActive(false); - if (!_anyoneStillOnPlatform) + if (!_platformActive) { _hologramGroup.SetActive(false); } diff --git a/QSB/PoolSync/Patches/PoolPatches.cs b/QSB/PoolSync/Patches/PoolPatches.cs index 24d2bcf6..f717ebfe 100644 --- a/QSB/PoolSync/Patches/PoolPatches.cs +++ b/QSB/PoolSync/Patches/PoolPatches.cs @@ -8,6 +8,7 @@ namespace QSB.PoolSync.Patches public override void DoPatches() { + QSBCore.HarmonyHelper.AddPrefix("Awake", typeof(PoolPatches), nameof(ReturnFalse)); QSBCore.HarmonyHelper.AddPrefix("Update", typeof(PoolPatches), nameof(ReturnFalse)); QSBCore.HarmonyHelper.AddPrefix("OnSocketableRemoved", typeof(PoolPatches), nameof(ReturnFalse)); QSBCore.HarmonyHelper.AddPrefix("OnSocketableDonePlacing", typeof(PoolPatches), nameof(ReturnFalse)); @@ -21,6 +22,7 @@ namespace QSB.PoolSync.Patches public override void DoUnpatches() { + QSBCore.HarmonyHelper.Unpatch("Awake"); QSBCore.HarmonyHelper.Unpatch("Update"); QSBCore.HarmonyHelper.Unpatch("OnSocketableRemoved"); QSBCore.HarmonyHelper.Unpatch("OnSocketableDonePlacing");