From 79a0b4e47881cc7f37abe20e25edab36e06d9d6d Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:01:32 +0100 Subject: [PATCH 01/24] update OWML --- QSB/QSB.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 519e684f..80923879 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -69,7 +69,7 @@ - + From 2ad07641f1dc1e35f829d5effda38e08feaf5102 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:01:40 +0100 Subject: [PATCH 02/24] make ShipManager public --- QSB/ShipSync/ShipManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/ShipSync/ShipManager.cs b/QSB/ShipSync/ShipManager.cs index 6d7017a2..8bf13d8c 100644 --- a/QSB/ShipSync/ShipManager.cs +++ b/QSB/ShipSync/ShipManager.cs @@ -16,7 +16,7 @@ using UnityEngine; namespace QSB.ShipSync; -internal class ShipManager : WorldObjectManager +public class ShipManager : WorldObjectManager { public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem; From 7dfbba52c98685d3571c59b4dcef92727d5d6c30 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:05:49 +0100 Subject: [PATCH 03/24] make OnModStart addon patches work --- QSB/QSBCore.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index 1e54438c..cf8ef47c 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -167,6 +167,7 @@ public class QSBCore : ModBehaviour // init again to get addon patches QSBPatchManager.Init(); + QSBPatchManager.DoPatchType(QSBPatchTypes.OnModStart); MenuApi = ModHelper.Interaction.TryGetModApi(ModHelper.Manifest.Dependencies[0]); From fb2eda7b133942be1e53a91f0ef4b2e386162f5b Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:24:00 +0100 Subject: [PATCH 04/24] redo addon patch initialization --- QSB/Patches/QSBPatchManager.cs | 39 ++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 5c678ab8..2ee89973 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -23,16 +23,43 @@ public static class QSBPatchManager { if (_inited) { - var count = _patchList.Count; + var newPatches = new List(); + foreach (var type in typeof(QSBPatch).GetDerivedTypes()) { - if (!_patchList.Any(x => x.GetType() == type)) + if (!newPatches.Any(x => x.GetType() == type)) { - _patchList.Add((QSBPatch)Activator.CreateInstance(type)); + newPatches.Add((QSBPatch)Activator.CreateInstance(type)); } } - DebugLog.DebugWrite($"Registered {_patchList.Count - count} addon patches.", MessageType.Success); + _patchList.AddRange(newPatches); + + // could do lots of code to make sure all addon patches are done here, + // but the only patche type that will have been used by this point in the + // mod execution is OnModStart + + DebugLog.DebugWrite($"Re-patching block OnModStart for addons", MessageType.Info); + var harmonyInstance = TypeToInstance[QSBPatchTypes.OnModStart]; + foreach (var patch in newPatches) + { + if (patch.Type != QSBPatchTypes.OnModStart) + { + continue; + } + + DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info); + try + { + patch.DoPatches(harmonyInstance); + } + catch (Exception ex) + { + DebugLog.ToConsole($"Error while patching {patch.GetType().Name} :\r\n{ex}", MessageType.Error); + } + } + + DebugLog.DebugWrite($"Registered {newPatches.Count()} addon patches.", MessageType.Success); return; } @@ -59,10 +86,10 @@ public static class QSBPatchManager } OnPatchType?.SafeInvoke(type); - //DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); + DebugLog.DebugWrite($"Patch block {Enum.GetName(typeof(QSBPatchTypes), type)}", MessageType.Info); foreach (var patch in _patchList.Where(x => x.Type == type && x.PatchVendor.HasFlag(QSBCore.GameVendor))) { - //DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info); + DebugLog.DebugWrite($" - Patching in {patch.GetType().Name}", MessageType.Info); try { patch.DoPatches(TypeToInstance[type]); From c6255fbb1531d3f9a287d66ea9786ac1f13e918e Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:24:07 +0100 Subject: [PATCH 05/24] Revert "make OnModStart addon patches work" This reverts commit 7dfbba52c98685d3571c59b4dcef92727d5d6c30. --- QSB/QSBCore.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/QSB/QSBCore.cs b/QSB/QSBCore.cs index cf8ef47c..1e54438c 100644 --- a/QSB/QSBCore.cs +++ b/QSB/QSBCore.cs @@ -167,7 +167,6 @@ public class QSBCore : ModBehaviour // init again to get addon patches QSBPatchManager.Init(); - QSBPatchManager.DoPatchType(QSBPatchTypes.OnModStart); MenuApi = ModHelper.Interaction.TryGetModApi(ModHelper.Manifest.Dependencies[0]); From b6894e5b364624c0dfdee9002b0b06895a7422b8 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:29:10 +0100 Subject: [PATCH 06/24] fix it --- QSB/Patches/QSBPatchManager.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/QSB/Patches/QSBPatchManager.cs b/QSB/Patches/QSBPatchManager.cs index 2ee89973..969876bd 100644 --- a/QSB/Patches/QSBPatchManager.cs +++ b/QSB/Patches/QSBPatchManager.cs @@ -27,7 +27,8 @@ public static class QSBPatchManager foreach (var type in typeof(QSBPatch).GetDerivedTypes()) { - if (!newPatches.Any(x => x.GetType() == type)) + if (!newPatches.Any(x => x.GetType() == type) + && !_patchList.Any(x => x.GetType() == type)) { newPatches.Add((QSBPatch)Activator.CreateInstance(type)); } @@ -36,7 +37,7 @@ public static class QSBPatchManager _patchList.AddRange(newPatches); // could do lots of code to make sure all addon patches are done here, - // but the only patche type that will have been used by this point in the + // but the only patch type that will have been used by this point in the // mod execution is OnModStart DebugLog.DebugWrite($"Re-patching block OnModStart for addons", MessageType.Info); From 5402bfa3e20bc20f2bf71ee45997fc55c258929a Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:39:08 +0100 Subject: [PATCH 07/24] add null check to SetCurrentFlyer --- QSB/ShipSync/Messages/FlyShipMessage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/ShipSync/Messages/FlyShipMessage.cs b/QSB/ShipSync/Messages/FlyShipMessage.cs index 3b3adf11..1f55dd3e 100644 --- a/QSB/ShipSync/Messages/FlyShipMessage.cs +++ b/QSB/ShipSync/Messages/FlyShipMessage.cs @@ -57,7 +57,7 @@ internal class FlyShipMessage : QSBMessage if (QSBCore.IsHost) { - ShipTransformSync.LocalInstance.netIdentity.SetOwner(isFlying + ShipTransformSync.LocalInstance?.netIdentity.SetOwner(isFlying ? id : QSBPlayerManager.LocalPlayerId); } From 88d3babe52009b64a069e36f80a20e7a9ec008e6 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:56:59 +0100 Subject: [PATCH 08/24] make ShipAudioPatches and ShipPatches public --- QSB/ShipSync/Patches/ShipAudioPatches.cs | 2 +- QSB/ShipSync/Patches/ShipPatches.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/QSB/ShipSync/Patches/ShipAudioPatches.cs b/QSB/ShipSync/Patches/ShipAudioPatches.cs index 1e76d57a..51f68517 100644 --- a/QSB/ShipSync/Patches/ShipAudioPatches.cs +++ b/QSB/ShipSync/Patches/ShipAudioPatches.cs @@ -6,7 +6,7 @@ using UnityEngine; namespace QSB.ShipSync.Patches; -internal class ShipAudioPatches : QSBPatch +public class ShipAudioPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; diff --git a/QSB/ShipSync/Patches/ShipPatches.cs b/QSB/ShipSync/Patches/ShipPatches.cs index 5780d389..8eca58c2 100644 --- a/QSB/ShipSync/Patches/ShipPatches.cs +++ b/QSB/ShipSync/Patches/ShipPatches.cs @@ -13,7 +13,7 @@ using UnityEngine; namespace QSB.ShipSync.Patches; [HarmonyPatch] -internal class ShipPatches : QSBPatch +public class ShipPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; From fe97e0f5699e6edad6f703d15418456575112ed4 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 20:59:21 +0100 Subject: [PATCH 09/24] add null checks to FlyShipMessage.OnRecieveRemote --- QSB/ShipSync/Messages/FlyShipMessage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QSB/ShipSync/Messages/FlyShipMessage.cs b/QSB/ShipSync/Messages/FlyShipMessage.cs index 1f55dd3e..4722b424 100644 --- a/QSB/ShipSync/Messages/FlyShipMessage.cs +++ b/QSB/ShipSync/Messages/FlyShipMessage.cs @@ -40,12 +40,12 @@ internal class FlyShipMessage : QSBMessage if (Data) { QSBPlayerManager.GetPlayer(From)?.AudioController?.PlayOneShot(AudioType.ShipCockpitBuckleUp); - shipCockpitController._interactVolume.DisableInteraction(); + shipCockpitController._interactVolume?.DisableInteraction(); } else { QSBPlayerManager.GetPlayer(From)?.AudioController?.PlayOneShot(AudioType.ShipCockpitUnbuckle); - shipCockpitController._interactVolume.EnableInteraction(); + shipCockpitController._interactVolume?.EnableInteraction(); } } From 6099fa5fd12386f1074cc85361e92969c9027d52 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 21:34:29 +0100 Subject: [PATCH 10/24] add another null check --- QSB/ShipSync/Messages/FlyShipMessage.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/QSB/ShipSync/Messages/FlyShipMessage.cs b/QSB/ShipSync/Messages/FlyShipMessage.cs index 4722b424..f73c8a7e 100644 --- a/QSB/ShipSync/Messages/FlyShipMessage.cs +++ b/QSB/ShipSync/Messages/FlyShipMessage.cs @@ -37,6 +37,12 @@ internal class FlyShipMessage : QSBMessage { SetCurrentFlyer(From, Data); var shipCockpitController = ShipManager.Instance.CockpitController; + + if (shipCockpitController == null) + { + return; + } + if (Data) { QSBPlayerManager.GetPlayer(From)?.AudioController?.PlayOneShot(AudioType.ShipCockpitBuckleUp); From 2889bffb1655817bb1f1fe77414f408205a5e01a Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Tue, 4 Jul 2023 21:56:40 +0100 Subject: [PATCH 11/24] add more null checks --- QSB/Audio/Messages/ShipThrusterAudioOneShotMessage.cs | 8 +++++++- QSB/ShipSync/Patches/ShipDetachableModulePatches.cs | 2 +- QSB/ShipSync/Patches/ShipFlameWashPatches.cs | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/QSB/Audio/Messages/ShipThrusterAudioOneShotMessage.cs b/QSB/Audio/Messages/ShipThrusterAudioOneShotMessage.cs index 156e51b2..7b5f45a7 100644 --- a/QSB/Audio/Messages/ShipThrusterAudioOneShotMessage.cs +++ b/QSB/Audio/Messages/ShipThrusterAudioOneShotMessage.cs @@ -13,7 +13,13 @@ public class ShipThrusterAudioOneShotMessage : QSBMessage<(AudioType audioType, public override void OnReceiveRemote() { - var source = ShipManager.Instance.ShipThrusterAudio._rotationalSource; + var source = ShipManager.Instance?.ShipThrusterAudio?._rotationalSource; + + if (source == null) + { + return; + } + source.pitch = Data.pitch; source.PlayOneShot(Data.audioType, Data.volume); } diff --git a/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs b/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs index da1a6231..c11d473e 100644 --- a/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs +++ b/QSB/ShipSync/Patches/ShipDetachableModulePatches.cs @@ -8,7 +8,7 @@ using QSB.WorldSync; namespace QSB.ShipSync.Patches; [HarmonyPatch(typeof(ShipDetachableModule))] -internal class ShipDetachableModulePatches : QSBPatch +public class ShipDetachableModulePatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; diff --git a/QSB/ShipSync/Patches/ShipFlameWashPatches.cs b/QSB/ShipSync/Patches/ShipFlameWashPatches.cs index 525c2c38..c988f692 100644 --- a/QSB/ShipSync/Patches/ShipFlameWashPatches.cs +++ b/QSB/ShipSync/Patches/ShipFlameWashPatches.cs @@ -8,7 +8,7 @@ using UnityEngine; namespace QSB.ShipSync.Patches; -internal class ShipFlameWashPatches : QSBPatch +public class ShipFlameWashPatches : QSBPatch { public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect; From fa8f5045e2207caaed54defc747c97de8bff270d Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 5 Jul 2023 12:44:47 +0100 Subject: [PATCH 12/24] make assetId incrementation automatic --- QSB/QSBNetworkManager.cs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 735c08b7..8431533b 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -106,52 +106,52 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart playerPrefab = QSBCore.NetworkAssetBundle.LoadAsset("Assets/Prefabs/NETWORK_Player_Body.prefab"); playerPrefab.GetRequiredComponent().SetValue("_assetId", (uint)1); - ShipPrefab = MakeNewNetworkObject(2, "NetworkShip", typeof(ShipTransformSync)); + ShipPrefab = MakeNewNetworkObject("NetworkShip", typeof(ShipTransformSync)); var shipVector3Sync = ShipPrefab.AddComponent(); var shipThrustSync = ShipPrefab.AddComponent(); shipThrustSync.AccelerationSyncer = shipVector3Sync; spawnPrefabs.Add(ShipPrefab); - _probePrefab = MakeNewNetworkObject(3, "NetworkProbe", typeof(PlayerProbeSync)); + _probePrefab = MakeNewNetworkObject("NetworkProbe", typeof(PlayerProbeSync)); spawnPrefabs.Add(_probePrefab); - OrbPrefab = MakeNewNetworkObject(4, "NetworkOrb", typeof(NomaiOrbTransformSync)); + OrbPrefab = MakeNewNetworkObject("NetworkOrb", typeof(NomaiOrbTransformSync)); spawnPrefabs.Add(OrbPrefab); - AnglerPrefab = MakeNewNetworkObject(5, "NetworkAngler", typeof(AnglerTransformSync)); + AnglerPrefab = MakeNewNetworkObject("NetworkAngler", typeof(AnglerTransformSync)); spawnPrefabs.Add(AnglerPrefab); - JellyfishPrefab = MakeNewNetworkObject(6, "NetworkJellyfish", typeof(JellyfishTransformSync)); + JellyfishPrefab = MakeNewNetworkObject("NetworkJellyfish", typeof(JellyfishTransformSync)); spawnPrefabs.Add(JellyfishPrefab); - OccasionalPrefab = MakeNewNetworkObject(7, "NetworkOccasional", typeof(OccasionalTransformSync)); + OccasionalPrefab = MakeNewNetworkObject("NetworkOccasional", typeof(OccasionalTransformSync)); spawnPrefabs.Add(OccasionalPrefab); - RaftPrefab = MakeNewNetworkObject(8, "NetworkRaft", typeof(RaftTransformSync)); + RaftPrefab = MakeNewNetworkObject("NetworkRaft", typeof(RaftTransformSync)); spawnPrefabs.Add(RaftPrefab); - DoorPrefab = MakeNewNetworkObject(9, "NetworkEclipseDoor", typeof(EclipseDoorVariableSyncer)); + DoorPrefab = MakeNewNetworkObject("NetworkEclipseDoor", typeof(EclipseDoorVariableSyncer)); spawnPrefabs.Add(DoorPrefab); - ElevatorPrefab = MakeNewNetworkObject(10, "NetworkEclipseElevator", typeof(EclipseElevatorVariableSyncer)); + ElevatorPrefab = MakeNewNetworkObject("NetworkEclipseElevator", typeof(EclipseElevatorVariableSyncer)); spawnPrefabs.Add(ElevatorPrefab); - AirlockPrefab = MakeNewNetworkObject(11, "NetworkGhostAirlock", typeof(AirlockVariableSyncer)); + AirlockPrefab = MakeNewNetworkObject("NetworkGhostAirlock", typeof(AirlockVariableSyncer)); spawnPrefabs.Add(AirlockPrefab); - ShipModulePrefab = MakeNewNetworkObject(12, "NetworkShipModule", typeof(ShipModuleTransformSync)); + ShipModulePrefab = MakeNewNetworkObject("NetworkShipModule", typeof(ShipModuleTransformSync)); spawnPrefabs.Add(ShipModulePrefab); - ShipLegPrefab = MakeNewNetworkObject(13, "NetworkShipLeg", typeof(ShipLegTransformSync)); + ShipLegPrefab = MakeNewNetworkObject("NetworkShipLeg", typeof(ShipLegTransformSync)); spawnPrefabs.Add(ShipLegPrefab); - ModelShipPrefab = MakeNewNetworkObject(14, "NetworkModelShip", typeof(ModelShipTransformSync)); + ModelShipPrefab = MakeNewNetworkObject("NetworkModelShip", typeof(ModelShipTransformSync)); var modelShipVector3Syncer = ModelShipPrefab.AddComponent(); var modelShipThrusterVariableSyncer = ModelShipPrefab.AddComponent(); modelShipThrusterVariableSyncer.AccelerationSyncer = modelShipVector3Syncer; spawnPrefabs.Add(ModelShipPrefab); - StationaryProbeLauncherPrefab = MakeNewNetworkObject(15, "NetworkStationaryProbeLauncher", typeof(StationaryProbeLauncherVariableSyncer)); + StationaryProbeLauncherPrefab = MakeNewNetworkObject("NetworkStationaryProbeLauncher", typeof(StationaryProbeLauncherVariableSyncer)); spawnPrefabs.Add(StationaryProbeLauncherPrefab); ConfigureNetworkManager(); @@ -207,11 +207,13 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart } }); + private static int _assetId = 2; + /// create a new network prefab from the network object prefab template. /// this works by calling Unload(false) and then reloading the AssetBundle, /// which makes LoadAsset give you a new resource. /// see https://docs.unity3d.com/Manual/AssetBundles-Native.html. - private static GameObject MakeNewNetworkObject(uint assetId, string name, Type networkBehaviourType) + public static GameObject MakeNewNetworkObject(string name, Type networkBehaviourType) { var bundle = QSBCore.Helper.Assets.LoadBundle("AssetBundles/qsb_empty"); @@ -225,8 +227,11 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart bundle.Unload(false); template.name = name; - template.AddComponent().SetValue("_assetId", assetId); + template.AddComponent().SetValue("_assetId", _assetId); template.AddComponent(networkBehaviourType); + + _assetId++; + return template; } From 37cb95f740546bf09adacd4d637277ddfcfcf388 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 5 Jul 2023 12:46:03 +0100 Subject: [PATCH 13/24] add comment --- QSB/QSBNetworkManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index 8431533b..eb17df72 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -207,7 +207,7 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart } }); - private static int _assetId = 2; + private static int _assetId = 2; // 1 is the player /// create a new network prefab from the network object prefab template. /// this works by calling Unload(false) and then reloading the AssetBundle, From 6e86ce8dda35d20391c1b16ac85e308df548eb62 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Wed, 5 Jul 2023 23:08:50 +0100 Subject: [PATCH 14/24] im dumb --- QSB/QSBNetworkManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/QSBNetworkManager.cs b/QSB/QSBNetworkManager.cs index eb17df72..6cb7504b 100644 --- a/QSB/QSBNetworkManager.cs +++ b/QSB/QSBNetworkManager.cs @@ -207,7 +207,7 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart } }); - private static int _assetId = 2; // 1 is the player + private static uint _assetId = 2; // 1 is the player /// create a new network prefab from the network object prefab template. /// this works by calling Unload(false) and then reloading the AssetBundle, From cef539d1787d62cf31bb378204a0ae61ec1ca5e5 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Thu, 6 Jul 2023 11:59:39 -0700 Subject: [PATCH 15/24] revert transport error translations cuz they were dumb and also incorrect --- QSB/Localization/Translation.cs | 4 +--- QSB/Menus/MenuManager.cs | 2 +- QSB/Translations/en.json | 12 +----------- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/QSB/Localization/Translation.cs b/QSB/Localization/Translation.cs index b47014a8..4ed59efe 100644 --- a/QSB/Localization/Translation.cs +++ b/QSB/Localization/Translation.cs @@ -1,5 +1,4 @@ -using Mirror; -using System.Collections.Generic; +using System.Collections.Generic; namespace QSB.Localization; @@ -29,7 +28,6 @@ public class Translation public string OK; public string ServerRefusedConnection; public string ClientDisconnectWithError; - public Dictionary TransportErrors; public string QSBVersionMismatch; public string OWVersionMismatch; public string DLCMismatch; diff --git a/QSB/Menus/MenuManager.cs b/QSB/Menus/MenuManager.cs index 0bb1bd42..55166f55 100644 --- a/QSB/Menus/MenuManager.cs +++ b/QSB/Menus/MenuManager.cs @@ -736,7 +736,7 @@ internal class MenuManager : MonoBehaviour, IAddComponentOnStart } }; - OpenInfoPopup(string.Format(QSBLocalization.Current.ClientDisconnectWithError, QSBLocalization.Current.TransportErrors[error], reason), QSBLocalization.Current.OK); + OpenInfoPopup(string.Format(QSBLocalization.Current.ClientDisconnectWithError, reason), QSBLocalization.Current.OK); } SetButtonActive(DisconnectButton, false); diff --git a/QSB/Translations/en.json b/QSB/Translations/en.json index f3ad1b60..a0430021 100644 --- a/QSB/Translations/en.json +++ b/QSB/Translations/en.json @@ -22,17 +22,7 @@ "Connecting": "CONNECTING...", "OK": "OK", "ServerRefusedConnection": "Server refused connection.\n{0}", - "ClientDisconnectWithError": "Client disconnected with error!\n{0}\nMore info: {1}", - "TransportErrors": { - "DnsResolve": "Failed to resolve host name.", - "Refused": "Connection refused.", - "Timeout": "Connection timed out.", - "Congestion": "Congestion on transport.", - "InvalidReceive": "Error receiving message.", - "InvalidSend": "Error sending message.", - "ConnectionClosed": "Connection closed.", - "Unexpected": "Unexpected error." - }, + "ClientDisconnectWithError": "Client disconnected with error!\n{0}", "QSBVersionMismatch": "QSB version does not match. (Client:{0}, Server:{1})", "OWVersionMismatch": "Outer Wilds version does not match. (Client:{0}, Server:{1})", "DLCMismatch": "DLC installation state does not match. (Client:{0}, Server:{1})", From e8e37632037eb523d85bfba8c5653829a274b221 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 7 Jul 2023 13:42:05 +0100 Subject: [PATCH 16/24] Update QSB.csproj --- QSB/QSB.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 80923879..4116a8ac 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -68,7 +68,7 @@ - + From c74d36d714fdc852b1b35ba1652b898796327e0f Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 7 Jul 2023 19:23:19 +0100 Subject: [PATCH 17/24] improve ListStack --- QSB/HUD/MultiplayerHUDManager.cs | 2 +- QSB/HUD/PlanetTrigger.cs | 4 +-- QSB/Utility/ListStack.cs | 52 ++++++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/QSB/HUD/MultiplayerHUDManager.cs b/QSB/HUD/MultiplayerHUDManager.cs index d3886162..2970b741 100644 --- a/QSB/HUD/MultiplayerHUDManager.cs +++ b/QSB/HUD/MultiplayerHUDManager.cs @@ -94,7 +94,7 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart if (_messages.Count > LINE_COUNT) { - _messages.RemoveFirstElementAndShift(); + _messages.PopFromBack(); } var currentLineIndex = 10; diff --git a/QSB/HUD/PlanetTrigger.cs b/QSB/HUD/PlanetTrigger.cs index 339e32a1..a97b12ce 100644 --- a/QSB/HUD/PlanetTrigger.cs +++ b/QSB/HUD/PlanetTrigger.cs @@ -16,7 +16,7 @@ public class PlanetTrigger : SectoredMonoBehaviour } MultiplayerHUDManager.HUDIconStack.Push(Icon); - var top = MultiplayerHUDManager.HUDIconStack.Peek(); + var top = MultiplayerHUDManager.HUDIconStack.PeekFront(); new PlanetMessage(top).Send(); } @@ -28,7 +28,7 @@ public class PlanetTrigger : SectoredMonoBehaviour } MultiplayerHUDManager.HUDIconStack.Remove(Icon); - var top = MultiplayerHUDManager.HUDIconStack.Peek(); + var top = MultiplayerHUDManager.HUDIconStack.PeekFront(); new PlanetMessage(top).Send(); } } diff --git a/QSB/Utility/ListStack.cs b/QSB/Utility/ListStack.cs index 98cd65c9..8a960bca 100644 --- a/QSB/Utility/ListStack.cs +++ b/QSB/Utility/ListStack.cs @@ -4,6 +4,9 @@ using System.Collections.Generic; namespace QSB.Utility; +/// +/// A LIFO collection with List<> functionality. +/// public class ListStack : IEnumerable { private List _items = new(); @@ -12,14 +15,21 @@ public class ListStack : IEnumerable private readonly bool _removeDuplicates; + /// If true, all elements equal to the added item will be removed prior to adding the new element. public ListStack(bool removeDuplicates) { _removeDuplicates = removeDuplicates; } + /// + /// Removes all items from the stack. + /// public void Clear() => _items.Clear(); + /// + /// Pushes an element onto the front of the stack. + /// public void Push(T item) { if (_removeDuplicates && _items.Contains(item)) @@ -30,7 +40,10 @@ public class ListStack : IEnumerable _items.Add(item); } - public T Pop() + /// + /// Pops an element off the front of the stack. + /// + public T PopFromFront() { if (_items.Count > 0) { @@ -42,7 +55,10 @@ public class ListStack : IEnumerable return default; } - public T RemoveFirstElementAndShift() + /// + /// Pops an element off the back of the stack and shifts the entire stack backwards. + /// + public T PopFromBack() { if (_items.Count == 0) { @@ -50,29 +66,39 @@ public class ListStack : IEnumerable } var firstElement = _items[0]; - - if (_items.Count == 0) - { - return firstElement; - } - - // shift list left - // allocates blehhh who cares - _items = _items.GetRange(1, _items.Count - 1); - + _items.RemoveAt(0); return firstElement; } - public T Peek() => _items.Count > 0 + /// + /// Returns the element at the front of the stack. + /// + public T PeekFront() => _items.Count > 0 ? _items[_items.Count - 1] : default; + /// + /// Returns the element at the back of the stack. + /// + public T PeekBack() => _items.Count > 0 + ? _items[0] + : default; + + /// + /// Removes the element at the given index, where 0 is the back of the stack. The stack will shift backwards to fill empty space. + /// public void RemoveAt(int index) => _items.RemoveAt(index); + /// + /// Removes the first occurence (back to front) of an item. + /// public bool Remove(T item) => _items.Remove(item); + /// + /// Removes all elements that match the given predicate. + /// public int RemoveAll(Predicate match) => _items.RemoveAll(match); From 3675ba28fbad3a5dc7640c442d94c344a592daf5 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Fri, 7 Jul 2023 23:36:08 +0100 Subject: [PATCH 18/24] add custom data per playerinfo --- QSB/Player/PlayerInfo.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index 5774880d..e90e0cdd 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -11,6 +11,7 @@ using QSB.QuantumSync.WorldObjects; using QSB.ShipSync; using QSB.Tools; using QSB.Utility; +using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -178,5 +179,21 @@ public partial class PlayerInfo HUDBox.OnRespawn(); } + private Dictionary _customData = new(); + + public void SetCustomData(string key, T data) + => _customData[key] = data; + + public T GetCustomData(string key) + { + if (!_customData.ContainsKey(key)) + { + DebugLog.ToConsole($"Custom data for {ToString()} does not contain entry with key {key}!", MessageType.Error); + return default; + } + + return (T)_customData[key]; + } + public override string ToString() => $"{PlayerId}:{GetType().Name} ({Name})"; } From 96f3840b9217e09506de8815151f9b7cd323e150 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 8 Jul 2023 00:13:54 +0100 Subject: [PATCH 19/24] Update QSBMessage.cs --- QSB/Messaging/QSBMessage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/Messaging/QSBMessage.cs b/QSB/Messaging/QSBMessage.cs index 764bc9b2..f52f55b6 100644 --- a/QSB/Messaging/QSBMessage.cs +++ b/QSB/Messaging/QSBMessage.cs @@ -7,7 +7,7 @@ public abstract class QSBMessage /// /// set automatically by Send /// - internal uint From; + protected internal uint From; /// /// (default) uint.MaxValue = send to everyone
/// 0 = send to host From 98354e9a37cbdd3786e5548a4b38af43284e5ce9 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 8 Jul 2023 00:21:25 +0100 Subject: [PATCH 20/24] Update DebugLog.cs --- QSB/Utility/DebugLog.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/QSB/Utility/DebugLog.cs b/QSB/Utility/DebugLog.cs index 8c17293a..020f436f 100644 --- a/QSB/Utility/DebugLog.cs +++ b/QSB/Utility/DebugLog.cs @@ -1,8 +1,8 @@ using OWML.Common; using OWML.Logging; +using OWML.Utils; using System.Diagnostics; using System.Linq; -using System.Reflection; using System.Runtime.CompilerServices; #pragma warning disable CS0618 @@ -28,7 +28,20 @@ public static class DebugLog } else { - QSBCore.Helper.Console.WriteLine(message, type, GetCallingType()); + var socket = QSBCore.Helper.Console.GetValue("_socket"); + socket.WriteToSocket(new ModSocketMessage + { + SenderName = "QSB", + SenderType = GetCallingType(), + Type = type, + Message = message + }); + + if (type == MessageType.Fatal) + { + socket.Close(); + Process.GetCurrentProcess().Kill(); + } } } From 756fb161d0d6820ef7b66c6dd2bc6d493bff90cc Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 8 Jul 2023 10:42:39 +0100 Subject: [PATCH 21/24] remove log message when there is no existing key --- QSB/Player/PlayerInfo.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/QSB/Player/PlayerInfo.cs b/QSB/Player/PlayerInfo.cs index e90e0cdd..d8ef861d 100644 --- a/QSB/Player/PlayerInfo.cs +++ b/QSB/Player/PlayerInfo.cs @@ -188,7 +188,6 @@ public partial class PlayerInfo { if (!_customData.ContainsKey(key)) { - DebugLog.ToConsole($"Custom data for {ToString()} does not contain entry with key {key}!", MessageType.Error); return default; } From b1e38b69095b3f2dc94f9c514dc7f3a337ba6ce8 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sat, 8 Jul 2023 14:15:48 +0100 Subject: [PATCH 22/24] more improvements to ListStack --- QSB/Utility/ListStack.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/QSB/Utility/ListStack.cs b/QSB/Utility/ListStack.cs index 8a960bca..58ecd2f3 100644 --- a/QSB/Utility/ListStack.cs +++ b/QSB/Utility/ListStack.cs @@ -102,6 +102,18 @@ public class ListStack : IEnumerable public int RemoveAll(Predicate match) => _items.RemoveAll(match); + /// + /// Returns the index of the given item, where 0 is the back of the stack. + /// + public int IndexOf(T item) + => _items.IndexOf(item); + + public T this[int index] + { + get => _items[index]; + set => _items[index] = value; + } + IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_items).GetEnumerator(); public IEnumerator GetEnumerator() => ((IEnumerable)_items).GetEnumerator(); } From 4ab15e74e6c3fc71c5d53799ddb36e781aea4f74 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 9 Jul 2023 21:19:52 +0100 Subject: [PATCH 23/24] add command intepreter and message scrolling --- QSB/HUD/MultiplayerHUDManager.cs | 40 ++++++++++++++++- QSB/Utility/CommandInterpreter.cs | 74 +++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 QSB/Utility/CommandInterpreter.cs diff --git a/QSB/HUD/MultiplayerHUDManager.cs b/QSB/HUD/MultiplayerHUDManager.cs index 2970b741..fe698ba1 100644 --- a/QSB/HUD/MultiplayerHUDManager.cs +++ b/QSB/HUD/MultiplayerHUDManager.cs @@ -9,6 +9,7 @@ using QSB.WorldSync; using System; using System.Linq; using UnityEngine; +using UnityEngine.InputSystem; using UnityEngine.SceneManagement; using UnityEngine.UI; @@ -157,6 +158,8 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart _textChat.GetComponent().alpha = 1; } + ListStack previousMessages = new(true); + private void Update() { if (!QSBWorldSync.AllObjectsReady || _playerList == null) @@ -168,12 +171,39 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart var inSuit = Locator.GetPlayerSuit().IsWearingHelmet(); - if (OWInput.IsNewlyPressed(InputLibrary.enter, InputMode.Character) && !_writingMessage && inSuit && QSBCore.TextChatInput) + if ((OWInput.IsNewlyPressed(InputLibrary.enter, InputMode.Character) || (Keyboard.current[Key.Slash].wasPressedThisFrame && OWInput.IsInputMode(InputMode.Character))) + && !_writingMessage && inSuit && QSBCore.TextChatInput) { OWInput.ChangeInputMode(InputMode.KeyboardInput); _writingMessage = true; _inputField.ActivateInputField(); _textChat.GetComponent().alpha = 1; + + if (Keyboard.current[Key.Slash].wasPressedThisFrame) + { + Delay.RunNextFrame(() => _inputField.text = "/"); + } + } + + if (Keyboard.current[Key.UpArrow].wasPressedThisFrame && _writingMessage) + { + var currentText = _inputField.text; + + if (previousMessages.Contains(currentText)) + { + var index = previousMessages.IndexOf(currentText); + + if (index == 0) + { + return; + } + + _inputField.text = previousMessages[index - 1]; + } + else + { + _inputField.text = previousMessages.Last(); + } } if (OWInput.IsNewlyPressed(InputLibrary.enter, InputMode.KeyboardInput) && _writingMessage) @@ -185,6 +215,14 @@ internal class MultiplayerHUDManager : MonoBehaviour, IAddComponentOnStart var message = _inputField.text; _inputField.text = ""; message = message.Replace("\n", "").Replace("\r", ""); + + previousMessages.Push(message); + + if (QSBCore.DebugSettings.DebugMode && CommandInterpreter.InterpretCommand(message)) + { + return; + } + message = $"{QSBPlayerManager.LocalPlayer.Name}: {message}"; new ChatMessage(message, Color.white).Send(); } diff --git a/QSB/Utility/CommandInterpreter.cs b/QSB/Utility/CommandInterpreter.cs new file mode 100644 index 00000000..f402d559 --- /dev/null +++ b/QSB/Utility/CommandInterpreter.cs @@ -0,0 +1,74 @@ +using QSB.HUD; +using QSB.Messaging; +using QSB.ShipSync; +using QSB.ShipSync.Messages; +using QSB.WorldSync; +using System.Linq; +using UnityEngine; + +namespace QSB.Utility; + +public class CommandInterpreter : MonoBehaviour, IAddComponentOnStart +{ + public static bool InterpretCommand(string message) + { + if (message[0] != '/') + { + return false; + } + + var commandParts = message.ToLower().Substring(1).Split(' '); + var command = commandParts[0]; + + switch (command) + { + case "ship": + ShipCommand(commandParts.Skip(1).ToArray()); + break; + default: + MultiplayerHUDManager.Instance.WriteMessage($"Unknown command \"{command}\".", Color.red); + break; + } + + return true; + } + + public static void ShipCommand(string[] arguments) + { + var command = arguments[0]; + + switch (command) + { + case "explode": + MultiplayerHUDManager.Instance.WriteMessage($"Blowing up the ship.", Color.green); + var shipDamageController = Locator.GetShipTransform().GetComponentInChildren(); + shipDamageController.Explode(); + break; + case "repair": + case "damage": + var damage = command == "damage"; + switch (arguments[1]) + { + case "headlight": + var headlight = QSBWorldSync.GetUnityObject(); + headlight.SetDamaged(damage); + break; + default: + break; + } + MultiplayerHUDManager.Instance.WriteMessage($"{(damage ? "Damaging" : "Repairing")} the {arguments[1]}.", Color.green); + break; + case "open-hatch": + QSBWorldSync.GetUnityObject().OpenHatch(); + new HatchMessage(true).Send(); + break; + case "close-hatch": + QSBWorldSync.GetUnityObject().CloseHatch(); + new HatchMessage(false).Send(); + break; + default: + MultiplayerHUDManager.Instance.WriteMessage($"Unknown ship command \"{command}\".", Color.red); + break; + } + } +} From 9ff28dc891b344aa70ef3a241bede7a7f240e419 Mon Sep 17 00:00:00 2001 From: _nebula <41904486+misternebula@users.noreply.github.com> Date: Sun, 9 Jul 2023 21:21:13 +0100 Subject: [PATCH 24/24] Update manifest.json --- QSB/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QSB/manifest.json b/QSB/manifest.json index 55aa0efd..6a4ea52e 100644 --- a/QSB/manifest.json +++ b/QSB/manifest.json @@ -7,7 +7,7 @@ "body": "- Disable *all* other mods. (Can heavily affect performance)\n- Make sure you are not running any other network-intensive applications." }, "uniqueName": "Raicuparta.QuantumSpaceBuddies", - "version": "0.28.3", + "version": "0.29.0", "owmlVersion": "2.9.0", "dependencies": [ "_nebula.MenuFramework", "JohnCorby.VanillaFix" ], "pathsToPreserve": [ "debugsettings.json" ],