From 6ecdc3d7a15d6df60ac22123b84b8eacad4fd18f Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 18 Mar 2023 13:30:22 -0400 Subject: [PATCH] Rearrange and clean up patches --- .../CameraPatches/NomaiRemoteCameraPatches.cs | 4 +- .../NomaiRemoteCameraPlatformPatches.cs | 32 +++ .../{OWCameraPatch.cs => OWCameraPatches.cs} | 6 +- .../CameraPatches/ProbeCameraPatches.cs | 16 ++ .../Patches/CharacterDialogueTreePatches.cs | 26 -- .../CreditsEntryPatches.cs | 4 +- .../CreditsPatches.cs | 4 +- .../AlignToSurfaceFluidDetectorPatches.cs | 41 +++ .../PlayerFogWarpDetectorPatches.cs | 6 +- .../ProbeDestructionDetectorPatches.cs} | 24 +- .../CharacterDialogueTreePatches.cs | 41 +++ .../RemoteDialogueTriggerPatches.cs | 17 +- .../AutoSlideProjectorPatches.cs | 10 +- .../CloakFieldControllerPatches.cs} | 14 +- .../MindProjectorTriggerPatches.cs | 47 ++++ .../MindSlideProjectionPatches.cs | 35 +++ .../RaftControllerPatches.cs} | 54 +--- .../VisionTorchItemPatches.cs | 33 +++ .../Patches/EyeOfTheUniversePatches.cs | 53 ---- .../EyeVortexTriggerPatches.cs | 17 ++ .../EyeScenePatches/LoadManagerPatches.cs | 29 ++ .../SubmitActionLoadScenePatches.cs | 21 ++ NewHorizons/Patches/HUDPatches.cs | 124 --------- .../Patches/HUDPatches/HUDMarkerPatches.cs | 28 ++ .../HUDPatches/ProbeHUDMarkerPatches.cs | 44 +++ .../HUDPatches/ShipHUDMarkerPatches.cs | 43 +++ .../ShipLogEntryHUDMarkerPatches.cs | 26 ++ NewHorizons/Patches/LocatorPatches.cs | 10 +- .../MapPatches/CanvasMapMarkerPatches.cs | 19 ++ .../{ => MapPatches}/MapControllerPatches.cs | 18 +- .../ReferenceFramePatches.cs} | 25 +- .../ReferenceFrameTrackerPatches.cs | 15 ++ ...rPatches.cs => MeteorControllerPatches.cs} | 6 +- .../{ => PlayerPatches}/PlayerDataPatches.cs | 32 +-- .../PlayerSpawnerPatches.cs | 7 +- .../{ => PlayerPatches}/PlayerStatePatches.cs | 8 +- NewHorizons/Patches/ProbeLauncherPatches.cs | 14 - .../Patches/ProxyPatches/ProxyBodyPatches.cs | 15 ++ .../ProxyPlanetPatches.cs} | 14 +- .../SunProxyEffectControllerPatches.cs | 22 ++ NewHorizons/Patches/RemotePatches.cs | 153 ----------- ...ShapePatches.cs => ShapeManagerPatches.cs} | 6 +- NewHorizons/Patches/ShipLogPatches.cs | 254 ------------------ .../ShipLogAstroObjectPatches.cs | 52 ++++ .../ShipLogPatches/ShipLogFactPatches.cs | 24 ++ .../ShipLogPatches/ShipLogManagerPatches.cs | 135 ++++++++++ .../ShipLogPatches/ShipLogMapModePatches.cs | 47 ++++ .../ShipLogSandFunnelPatches.cs | 22 ++ .../ShipLogPatches/UIStyleManagerPatches.cs | 25 ++ .../{ => SignalPatches}/AudioSignalPatches.cs | 107 +++----- .../SignalscopePatches.cs} | 19 +- .../TravelerAudioManagerPatches.cs | 15 ++ NewHorizons/Patches/SingularityPatches.cs | 51 ---- NewHorizons/Patches/StreamingPatches.cs | 26 -- .../NomaiRemoteCameraStreamingPatches.cs | 47 ++++ .../StreamingManagerPatches.cs | 18 ++ .../StreamingPatches/UnityLoggerPatches.cs | 17 ++ NewHorizons/Patches/SunPatches.cs | 65 ----- .../SunPatches/SunControllerPatches.cs | 18 ++ .../SunPatches/SunLightParamUpdaterPatches.cs | 31 +++ .../SunSurfaceAudioControllerPatches.cs | 22 ++ NewHorizons/Patches/TimeLoopPatches.cs | 43 +-- .../ToolPatches/ProbeLauncherPatches.cs | 15 ++ .../ToolPatches/SurveyorProbePatches.cs | 18 ++ .../ToolModeSwapperPatches.cs | 20 +- NewHorizons/Patches/VisionTorchPatches.cs | 108 -------- .../VolumePatches/BlackHoleVolumePatches.cs | 15 ++ .../DestructionVolumePatches.cs | 2 +- .../VolumePatches/FluidVolumePatches.cs | 20 ++ .../FogWarpVolumePatches.cs} | 12 +- .../VolumePatches/VanishVolumePatches.cs | 15 ++ .../VolumePatches/WhiteHoleVolumePatches.cs | 28 ++ .../EyeCoordinatePromptTriggerPatches.cs | 2 +- .../NomaiCoordinateInterfacePatches.cs | 18 ++ .../ShipCockpitControllerPatches.cs} | 11 +- .../VesselWarpControllerPatches.cs} | 28 +- 76 files changed, 1288 insertions(+), 1225 deletions(-) create mode 100644 NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPlatformPatches.cs rename NewHorizons/Patches/CameraPatches/{OWCameraPatch.cs => OWCameraPatches.cs} (83%) create mode 100644 NewHorizons/Patches/CameraPatches/ProbeCameraPatches.cs delete mode 100644 NewHorizons/Patches/CharacterDialogueTreePatches.cs rename NewHorizons/Patches/{CreditsScene => CreditsScenePatches}/CreditsEntryPatches.cs (90%) rename NewHorizons/Patches/{CreditsScene => CreditsScenePatches}/CreditsPatches.cs (78%) create mode 100644 NewHorizons/Patches/DetectorPatches/AlignToSurfaceFluidDetectorPatches.cs rename NewHorizons/Patches/{ => DetectorPatches}/PlayerFogWarpDetectorPatches.cs (86%) rename NewHorizons/Patches/{AchievementPatches.cs => DetectorPatches/ProbeDestructionDetectorPatches.cs} (61%) create mode 100644 NewHorizons/Patches/DialoguePatches/CharacterDialogueTreePatches.cs rename NewHorizons/Patches/{ => DialoguePatches}/RemoteDialogueTriggerPatches.cs (72%) rename NewHorizons/Patches/{ => EchoesOfTheEyePatches}/AutoSlideProjectorPatches.cs (51%) rename NewHorizons/Patches/{CloakPatches.cs => EchoesOfTheEyePatches/CloakFieldControllerPatches.cs} (62%) create mode 100644 NewHorizons/Patches/EchoesOfTheEyePatches/MindProjectorTriggerPatches.cs create mode 100644 NewHorizons/Patches/EchoesOfTheEyePatches/MindSlideProjectionPatches.cs rename NewHorizons/Patches/{RaftPatches.cs => EchoesOfTheEyePatches/RaftControllerPatches.cs} (55%) create mode 100644 NewHorizons/Patches/EchoesOfTheEyePatches/VisionTorchItemPatches.cs delete mode 100644 NewHorizons/Patches/EyeOfTheUniversePatches.cs create mode 100644 NewHorizons/Patches/EyeScenePatches/EyeVortexTriggerPatches.cs create mode 100644 NewHorizons/Patches/EyeScenePatches/LoadManagerPatches.cs create mode 100644 NewHorizons/Patches/EyeScenePatches/SubmitActionLoadScenePatches.cs delete mode 100644 NewHorizons/Patches/HUDPatches.cs create mode 100644 NewHorizons/Patches/HUDPatches/HUDMarkerPatches.cs create mode 100644 NewHorizons/Patches/HUDPatches/ProbeHUDMarkerPatches.cs create mode 100644 NewHorizons/Patches/HUDPatches/ShipHUDMarkerPatches.cs create mode 100644 NewHorizons/Patches/HUDPatches/ShipLogEntryHUDMarkerPatches.cs create mode 100644 NewHorizons/Patches/MapPatches/CanvasMapMarkerPatches.cs rename NewHorizons/Patches/{ => MapPatches}/MapControllerPatches.cs (66%) rename NewHorizons/Patches/{TranslationPatches.cs => MapPatches/ReferenceFramePatches.cs} (50%) create mode 100644 NewHorizons/Patches/MapPatches/ReferenceFrameTrackerPatches.cs rename NewHorizons/Patches/{MeteorPatches.cs => MeteorControllerPatches.cs} (65%) rename NewHorizons/Patches/{ => PlayerPatches}/PlayerDataPatches.cs (82%) rename NewHorizons/Patches/{ => PlayerPatches}/PlayerSpawnerPatches.cs (83%) rename NewHorizons/Patches/{ => PlayerPatches}/PlayerStatePatches.cs (81%) delete mode 100644 NewHorizons/Patches/ProbeLauncherPatches.cs create mode 100644 NewHorizons/Patches/ProxyPatches/ProxyBodyPatches.cs rename NewHorizons/Patches/{ProxyBodyPatches.cs => ProxyPatches/ProxyPlanetPatches.cs} (89%) create mode 100644 NewHorizons/Patches/ProxyPatches/SunProxyEffectControllerPatches.cs delete mode 100644 NewHorizons/Patches/RemotePatches.cs rename NewHorizons/Patches/{ShapePatches.cs => ShapeManagerPatches.cs} (85%) delete mode 100644 NewHorizons/Patches/ShipLogPatches.cs create mode 100644 NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs create mode 100644 NewHorizons/Patches/ShipLogPatches/ShipLogFactPatches.cs create mode 100644 NewHorizons/Patches/ShipLogPatches/ShipLogManagerPatches.cs create mode 100644 NewHorizons/Patches/ShipLogPatches/ShipLogMapModePatches.cs create mode 100644 NewHorizons/Patches/ShipLogPatches/ShipLogSandFunnelPatches.cs create mode 100644 NewHorizons/Patches/ShipLogPatches/UIStyleManagerPatches.cs rename NewHorizons/Patches/{ => SignalPatches}/AudioSignalPatches.cs (66%) rename NewHorizons/Patches/{SignalScopePatches.cs => SignalPatches/SignalscopePatches.cs} (59%) create mode 100644 NewHorizons/Patches/SignalPatches/TravelerAudioManagerPatches.cs delete mode 100644 NewHorizons/Patches/SingularityPatches.cs delete mode 100644 NewHorizons/Patches/StreamingPatches.cs create mode 100644 NewHorizons/Patches/StreamingPatches/NomaiRemoteCameraStreamingPatches.cs create mode 100644 NewHorizons/Patches/StreamingPatches/StreamingManagerPatches.cs create mode 100644 NewHorizons/Patches/StreamingPatches/UnityLoggerPatches.cs delete mode 100644 NewHorizons/Patches/SunPatches.cs create mode 100644 NewHorizons/Patches/SunPatches/SunControllerPatches.cs create mode 100644 NewHorizons/Patches/SunPatches/SunLightParamUpdaterPatches.cs create mode 100644 NewHorizons/Patches/SunPatches/SunSurfaceAudioControllerPatches.cs create mode 100644 NewHorizons/Patches/ToolPatches/ProbeLauncherPatches.cs create mode 100644 NewHorizons/Patches/ToolPatches/SurveyorProbePatches.cs rename NewHorizons/Patches/{ => ToolPatches}/ToolModeSwapperPatches.cs (73%) delete mode 100644 NewHorizons/Patches/VisionTorchPatches.cs create mode 100644 NewHorizons/Patches/VolumePatches/BlackHoleVolumePatches.cs rename NewHorizons/Patches/{ => VolumePatches}/DestructionVolumePatches.cs (95%) create mode 100644 NewHorizons/Patches/VolumePatches/FluidVolumePatches.cs rename NewHorizons/Patches/{BramblePatches.cs => VolumePatches/FogWarpVolumePatches.cs} (80%) create mode 100644 NewHorizons/Patches/VolumePatches/VanishVolumePatches.cs create mode 100644 NewHorizons/Patches/VolumePatches/WhiteHoleVolumePatches.cs rename NewHorizons/Patches/{ => WarpPatches}/EyeCoordinatePromptTriggerPatches.cs (96%) create mode 100644 NewHorizons/Patches/WarpPatches/NomaiCoordinateInterfacePatches.cs rename NewHorizons/Patches/{WarpDrivePatches.cs => WarpPatches/ShipCockpitControllerPatches.cs} (77%) rename NewHorizons/Patches/{NomaiCoordinatePatches.cs => WarpPatches/VesselWarpControllerPatches.cs} (69%) diff --git a/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs index 29719c0e..02e3a8be 100644 --- a/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs +++ b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs @@ -4,11 +4,11 @@ using UnityEngine; namespace NewHorizons.Patches.CameraPatches { - [HarmonyPatch] + [HarmonyPatch(typeof(NomaiRemoteCamera))] public static class NomaiRemoteCameraPatches { [HarmonyPostfix] - [HarmonyPatch(typeof(NomaiRemoteCamera), nameof(NomaiRemoteCamera.Awake))] + [HarmonyPatch(nameof(NomaiRemoteCamera.Awake))] public static void NomaiRemoteCamera_Awake(NomaiRemoteCamera __instance) { // Ensures that if the player is visible from the remote camera they look normal diff --git a/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPlatformPatches.cs b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPlatformPatches.cs new file mode 100644 index 00000000..a2c7a532 --- /dev/null +++ b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPlatformPatches.cs @@ -0,0 +1,32 @@ +using HarmonyLib; +using NewHorizons.Handlers; + +namespace NewHorizons.Patches.CameraPatches +{ + [HarmonyPatch(typeof(NomaiRemoteCameraPlatform))] + public static class NomaiRemoteCameraPlatformPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(NomaiRemoteCameraPlatform.IDToPlanetString))] + public static bool NomaiRemoteCameraPlatform_IDToPlanetString(NomaiRemoteCameraPlatform.ID id, out string __result) + { + __result = id switch + { + NomaiRemoteCameraPlatform.ID.None => "None", + NomaiRemoteCameraPlatform.ID.SunStation => UITextLibrary.GetString(UITextType.LocationSS), + NomaiRemoteCameraPlatform.ID.HGT_TimeLoop => UITextLibrary.GetString(UITextType.LocationTT), + NomaiRemoteCameraPlatform.ID.TH_Mine => UITextLibrary.GetString(UITextType.LocationTH), + NomaiRemoteCameraPlatform.ID.THM_EyeLocator => UITextLibrary.GetString(UITextType.LocationTHMoon), + NomaiRemoteCameraPlatform.ID.BH_Observatory or NomaiRemoteCameraPlatform.ID.BH_GravityCannon or NomaiRemoteCameraPlatform.ID.BH_QuantumFragment or NomaiRemoteCameraPlatform.ID.BH_BlackHoleForge or NomaiRemoteCameraPlatform.ID.BH_NorthPole => UITextLibrary.GetString(UITextType.LocationBH), + NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland1 or NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland2 or NomaiRemoteCameraPlatform.ID.GD_StatueIsland => UITextLibrary.GetString(UITextType.LocationGD), + NomaiRemoteCameraPlatform.ID.GD_ProbeCannonSunkenModule => UITextLibrary.GetString(UITextType.LocationOPC_Module3), + NomaiRemoteCameraPlatform.ID.GD_ProbeCannonDamagedModule => UITextLibrary.GetString(UITextType.LocationOPC_Module2), + NomaiRemoteCameraPlatform.ID.GD_ProbeCannonIntactModule => UITextLibrary.GetString(UITextType.LocationOPC_Module1), + NomaiRemoteCameraPlatform.ID.VM_Interior => UITextLibrary.GetString(UITextType.LocationBHMoon), + NomaiRemoteCameraPlatform.ID.HGT_TLE => UITextLibrary.GetString(UITextType.LocationCT), + _ => RemoteHandler.GetPlatformIDName(id), + }; + return false; + } + } +} diff --git a/NewHorizons/Patches/CameraPatches/OWCameraPatch.cs b/NewHorizons/Patches/CameraPatches/OWCameraPatches.cs similarity index 83% rename from NewHorizons/Patches/CameraPatches/OWCameraPatch.cs rename to NewHorizons/Patches/CameraPatches/OWCameraPatches.cs index db9251c1..efa9aba6 100644 --- a/NewHorizons/Patches/CameraPatches/OWCameraPatch.cs +++ b/NewHorizons/Patches/CameraPatches/OWCameraPatches.cs @@ -2,11 +2,11 @@ using HarmonyLib; namespace NewHorizons.Patches.CameraPatches { - [HarmonyPatch] - public static class OWCameraPatch + [HarmonyPatch(typeof(OWCamera))] + public static class OWCameraPatches { [HarmonyPostfix] - [HarmonyPatch(typeof(OWCamera), nameof(OWCamera.Awake))] + [HarmonyPatch(nameof(OWCamera.Awake))] public static void OnOWCameraAwake(OWCamera __instance) { if (Main.SystemDict.TryGetValue(Main.Instance.CurrentStarSystem, out var system) && system?.Config?.farClipPlaneOverride != 0f) diff --git a/NewHorizons/Patches/CameraPatches/ProbeCameraPatches.cs b/NewHorizons/Patches/CameraPatches/ProbeCameraPatches.cs new file mode 100644 index 00000000..481c0f30 --- /dev/null +++ b/NewHorizons/Patches/CameraPatches/ProbeCameraPatches.cs @@ -0,0 +1,16 @@ +using HarmonyLib; +using NewHorizons.Handlers; + +namespace NewHorizons.Patches.CameraPatches +{ + [HarmonyPatch(typeof(ProbeCamera))] + public static class ProbeCameraPatches + { + [HarmonyPostfix] + [HarmonyPatch(nameof(ProbeCamera.HasInterference))] + public static void ProbeCamera_HasInterference(ProbeCamera __instance, ref bool __result) + { + __result = __result || (__instance._id != ProbeCamera.ID.PreLaunch && (Components.CloakSectorController.isPlayerInside != Components.CloakSectorController.isProbeInside || !InterferenceHandler.IsPlayerSameAsProbe())); + } + } +} diff --git a/NewHorizons/Patches/CharacterDialogueTreePatches.cs b/NewHorizons/Patches/CharacterDialogueTreePatches.cs deleted file mode 100644 index 2d4a8831..00000000 --- a/NewHorizons/Patches/CharacterDialogueTreePatches.cs +++ /dev/null @@ -1,26 +0,0 @@ -using HarmonyLib; - -namespace NewHorizons.Patches; - -[HarmonyPatch] -internal static class CharacterDialogueTreePatches -{ - [HarmonyPrefix] - [HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.Awake))] - private static void CharacterDialogueTree_Awake(CharacterDialogueTree __instance) - { - GlobalMessenger.AddListener("AttachPlayerToPoint", __instance.OnAttachPlayerToPoint); - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.OnDestroy))] - private static void CharacterDialogueTree_OnDestroy(CharacterDialogueTree __instance) - { - GlobalMessenger.RemoveListener("AttachPlayerToPoint", __instance.OnAttachPlayerToPoint); - } - - private static void OnAttachPlayerToPoint(this CharacterDialogueTree characterDialogueTree, OWRigidbody rigidbody) - { - characterDialogueTree.EndConversation(); - } -} diff --git a/NewHorizons/Patches/CreditsScene/CreditsEntryPatches.cs b/NewHorizons/Patches/CreditsScenePatches/CreditsEntryPatches.cs similarity index 90% rename from NewHorizons/Patches/CreditsScene/CreditsEntryPatches.cs rename to NewHorizons/Patches/CreditsScenePatches/CreditsEntryPatches.cs index fe255ed6..a5e10707 100644 --- a/NewHorizons/Patches/CreditsScene/CreditsEntryPatches.cs +++ b/NewHorizons/Patches/CreditsScenePatches/CreditsEntryPatches.cs @@ -4,11 +4,11 @@ using System; namespace NewHorizons.Patches.CreditsScene { - [HarmonyPatch] + [HarmonyPatch(typeof(CreditsEntry))] public static class CreditsEntryPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(CreditsEntry), nameof(CreditsEntry.SetContents))] + [HarmonyPatch(nameof(CreditsEntry.SetContents))] public static bool CreditsEntry_SetContents(CreditsEntry __instance, string[] __0) { var columnTexts = __0; diff --git a/NewHorizons/Patches/CreditsScene/CreditsPatches.cs b/NewHorizons/Patches/CreditsScenePatches/CreditsPatches.cs similarity index 78% rename from NewHorizons/Patches/CreditsScene/CreditsPatches.cs rename to NewHorizons/Patches/CreditsScenePatches/CreditsPatches.cs index 724ef696..787d2ead 100644 --- a/NewHorizons/Patches/CreditsScene/CreditsPatches.cs +++ b/NewHorizons/Patches/CreditsScenePatches/CreditsPatches.cs @@ -3,11 +3,11 @@ using NewHorizons.Handlers; namespace NewHorizons.Patches.CreditsScene { - [HarmonyPatch] + [HarmonyPatch(typeof(Credits))] public static class CreditsPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(Credits), nameof(Credits.Start))] + [HarmonyPatch(nameof(Credits.Start))] public static void Credits_Start(Credits __instance) { CreditsHandler.AddCredits(__instance); diff --git a/NewHorizons/Patches/DetectorPatches/AlignToSurfaceFluidDetectorPatches.cs b/NewHorizons/Patches/DetectorPatches/AlignToSurfaceFluidDetectorPatches.cs new file mode 100644 index 00000000..7634cbd5 --- /dev/null +++ b/NewHorizons/Patches/DetectorPatches/AlignToSurfaceFluidDetectorPatches.cs @@ -0,0 +1,41 @@ +using HarmonyLib; +using UnityEngine; + +namespace NewHorizons.Patches.DetectorPatches +{ + [HarmonyPatch] + public static class AlignToSurfaceFluidDetectorPatches + { + [HarmonyReversePatch] + [HarmonyPatch(typeof(AsymmetricFluidDetector), nameof(AsymmetricFluidDetector.ManagedFixedUpdate))] + public static void AsymmetricFluidDetector_ManagedFixedUpdate(AsymmetricFluidDetector __instance) + { + // This is like doing base.FixedUpdate + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(AlignToSurfaceFluidDetector), nameof(AlignToSurfaceFluidDetector.ManagedFixedUpdate))] + public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance) + { + if (__instance._alignmentFluid is not RadialFluidVolume) return true; + + // Mostly copy pasting from the AlignWithDirection class + AsymmetricFluidDetector_ManagedFixedUpdate(__instance); + + if (__instance._inAlignmentFluid) + { + // Both in world space + var currentDirection = __instance._owRigidbody.transform.up; + var alignmentDirection = (__instance.transform.position - __instance._alignmentFluid.transform.position).normalized; + var degreesToTarget = Vector3.Angle(currentDirection, alignmentDirection); + + var adjustedSlerpRate = Mathf.Clamp01(0.01f * degreesToTarget * Time.fixedDeltaTime); + + Vector3 a = OWPhysics.FromToAngularVelocity(currentDirection, alignmentDirection); + __instance._owRigidbody.AddAngularVelocityChange(a * adjustedSlerpRate); + } + + return false; + } + } +} diff --git a/NewHorizons/Patches/PlayerFogWarpDetectorPatches.cs b/NewHorizons/Patches/DetectorPatches/PlayerFogWarpDetectorPatches.cs similarity index 86% rename from NewHorizons/Patches/PlayerFogWarpDetectorPatches.cs rename to NewHorizons/Patches/DetectorPatches/PlayerFogWarpDetectorPatches.cs index 00348490..e9b894c1 100644 --- a/NewHorizons/Patches/PlayerFogWarpDetectorPatches.cs +++ b/NewHorizons/Patches/DetectorPatches/PlayerFogWarpDetectorPatches.cs @@ -1,15 +1,15 @@ using HarmonyLib; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.DetectorPatches { - [HarmonyPatch] + [HarmonyPatch(typeof(PlayerFogWarpDetector))] public static class PlayerFogWarpDetectorPatches { // Morbius moment: they only let fog go away if there is a fog controller on the planet near you // However you can leave these volumes with fog on your screen, or have fog applied by a bramble node on a fogless planet [HarmonyPostfix] - [HarmonyPatch(typeof(PlayerFogWarpDetector), nameof(PlayerFogWarpDetector.LateUpdate))] + [HarmonyPatch(nameof(PlayerFogWarpDetector.LateUpdate))] public static void PlayerFogWarpDetector_LateUpdate(PlayerFogWarpDetector __instance) { if (PlanetaryFogController.GetActiveFogSphere() == null) diff --git a/NewHorizons/Patches/AchievementPatches.cs b/NewHorizons/Patches/DetectorPatches/ProbeDestructionDetectorPatches.cs similarity index 61% rename from NewHorizons/Patches/AchievementPatches.cs rename to NewHorizons/Patches/DetectorPatches/ProbeDestructionDetectorPatches.cs index 1c75e7d8..b73be669 100644 --- a/NewHorizons/Patches/AchievementPatches.cs +++ b/NewHorizons/Patches/DetectorPatches/ProbeDestructionDetectorPatches.cs @@ -1,17 +1,15 @@ using HarmonyLib; -using NewHorizons.Components; -using NewHorizons.OtherMods.AchievementsPlus; using NewHorizons.OtherMods.AchievementsPlus.NH; -using System.Linq; +using NewHorizons.OtherMods.AchievementsPlus; using UnityEngine; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.DetectorPatches { - [HarmonyPatch] - public static class AchievementPatches + [HarmonyPatch(typeof(ProbeDestructionDetector))] + internal static class ProbeDestructionDetectorPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(ProbeDestructionDetector), nameof(ProbeDestructionDetector.FixedUpdate))] + [HarmonyPatch(nameof(ProbeDestructionDetector.FixedUpdate))] public static bool ProbeDestructionDetector_FixedUpdate(ProbeDestructionDetector __instance) { if (__instance._activeVolumes.Count > 0 && __instance._safetyVolumes.Count == 0) @@ -32,17 +30,5 @@ namespace NewHorizons.Patches __instance.enabled = false; return false; } - - [HarmonyPostfix] - [HarmonyPatch(typeof(CharacterDialogueTree), nameof(CharacterDialogueTree.StartConversation))] - public static void CharacterDialogueTree_StartConversation(CharacterDialogueTree __instance) - { - if (!AchievementHandler.Enabled) return; - - if (__instance is NHCharacterDialogueTree) - { - TalkToFiveCharactersAchievement.OnTalkedToCharacter(__instance._characterName); - } - } } } diff --git a/NewHorizons/Patches/DialoguePatches/CharacterDialogueTreePatches.cs b/NewHorizons/Patches/DialoguePatches/CharacterDialogueTreePatches.cs new file mode 100644 index 00000000..32cab4ad --- /dev/null +++ b/NewHorizons/Patches/DialoguePatches/CharacterDialogueTreePatches.cs @@ -0,0 +1,41 @@ +using HarmonyLib; +using NewHorizons.Components; +using NewHorizons.OtherMods.AchievementsPlus.NH; +using NewHorizons.OtherMods.AchievementsPlus; + +namespace NewHorizons.Patches.DialoguePatches; + +[HarmonyPatch(typeof(CharacterDialogueTree))] +public static class CharacterDialogueTreePatches +{ + [HarmonyPrefix] + [HarmonyPatch(nameof(CharacterDialogueTree.Awake))] + private static void CharacterDialogueTree_Awake(CharacterDialogueTree __instance) + { + GlobalMessenger.AddListener("AttachPlayerToPoint", __instance.OnAttachPlayerToPoint); + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(CharacterDialogueTree.OnDestroy))] + private static void CharacterDialogueTree_OnDestroy(CharacterDialogueTree __instance) + { + GlobalMessenger.RemoveListener("AttachPlayerToPoint", __instance.OnAttachPlayerToPoint); + } + + private static void OnAttachPlayerToPoint(this CharacterDialogueTree characterDialogueTree, OWRigidbody rigidbody) + { + characterDialogueTree.EndConversation(); + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(CharacterDialogueTree.StartConversation))] + public static void CharacterDialogueTree_StartConversation(CharacterDialogueTree __instance) + { + if (!AchievementHandler.Enabled) return; + + if (__instance is NHCharacterDialogueTree) + { + TalkToFiveCharactersAchievement.OnTalkedToCharacter(__instance._characterName); + } + } +} diff --git a/NewHorizons/Patches/RemoteDialogueTriggerPatches.cs b/NewHorizons/Patches/DialoguePatches/RemoteDialogueTriggerPatches.cs similarity index 72% rename from NewHorizons/Patches/RemoteDialogueTriggerPatches.cs rename to NewHorizons/Patches/DialoguePatches/RemoteDialogueTriggerPatches.cs index f6002b05..330e578e 100644 --- a/NewHorizons/Patches/RemoteDialogueTriggerPatches.cs +++ b/NewHorizons/Patches/DialoguePatches/RemoteDialogueTriggerPatches.cs @@ -1,19 +1,18 @@ using HarmonyLib; -using NewHorizons.Utility; -using System; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.DialoguePatches { - /// - /// Should fix a bug where disabled a CharacterDialogueTree makes its related RemoteDialogueTriggers softlock your game - /// - [HarmonyPatch] + [HarmonyPatch(typeof(RemoteDialogueTrigger))] public static class RemoteDialogueTriggerPatches { private static bool _wasLastDialogueInactive = false; + /// + /// Should fix a bug where disabled a CharacterDialogueTree makes its related RemoteDialogueTriggers softlock your game + /// + [HarmonyPostfix] - [HarmonyPatch(typeof(RemoteDialogueTrigger), nameof(RemoteDialogueTrigger.OnTriggerEnter))] + [HarmonyPatch(nameof(RemoteDialogueTrigger.OnTriggerEnter))] public static void RemoteDialogueTrigger_OnTriggerEnter(RemoteDialogueTrigger __instance) { if (__instance._inRemoteDialogue && __instance._activeRemoteDialogue?.gameObject != null) @@ -27,7 +26,7 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(RemoteDialogueTrigger), nameof(RemoteDialogueTrigger.OnEndConversation))] + [HarmonyPatch(nameof(RemoteDialogueTrigger.OnEndConversation))] public static void RemoteDialogueTrigger_OnEndConversation(RemoteDialogueTrigger __instance) { if (__instance._inRemoteDialogue && __instance._activeRemoteDialogue != null) diff --git a/NewHorizons/Patches/AutoSlideProjectorPatches.cs b/NewHorizons/Patches/EchoesOfTheEyePatches/AutoSlideProjectorPatches.cs similarity index 51% rename from NewHorizons/Patches/AutoSlideProjectorPatches.cs rename to NewHorizons/Patches/EchoesOfTheEyePatches/AutoSlideProjectorPatches.cs index 9c5d5e2d..accd6ee6 100644 --- a/NewHorizons/Patches/AutoSlideProjectorPatches.cs +++ b/NewHorizons/Patches/EchoesOfTheEyePatches/AutoSlideProjectorPatches.cs @@ -1,12 +1,12 @@ using HarmonyLib; -namespace NewHorizons.Patches -{ - [HarmonyPatch] - public class AutoSlideProjectorPatches +namespace NewHorizons.Patches.EchoesOfTheEyePatches +{ + [HarmonyPatch(typeof(AutoSlideProjector))] + public static class AutoSlideProjectorPatches { [HarmonyPostfix] - [HarmonyPatch(typeof(AutoSlideProjector), nameof(AutoSlideProjector.Play))] + [HarmonyPatch(nameof(AutoSlideProjector.Play))] public static void AutoSlideProjector_Play(AutoSlideProjector __instance) { __instance._slideCollectionItem.enabled = true; diff --git a/NewHorizons/Patches/CloakPatches.cs b/NewHorizons/Patches/EchoesOfTheEyePatches/CloakFieldControllerPatches.cs similarity index 62% rename from NewHorizons/Patches/CloakPatches.cs rename to NewHorizons/Patches/EchoesOfTheEyePatches/CloakFieldControllerPatches.cs index 2129a198..cdb8736c 100644 --- a/NewHorizons/Patches/CloakPatches.cs +++ b/NewHorizons/Patches/EchoesOfTheEyePatches/CloakFieldControllerPatches.cs @@ -1,33 +1,33 @@ using HarmonyLib; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.EchoesOfTheEyePatches { - [HarmonyPatch] - public static class CloakPatches + [HarmonyPatch(typeof(CloakFieldController))] + public static class CloakFieldControllerPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(CloakFieldController), nameof(CloakFieldController.FixedUpdate))] + [HarmonyPatch(nameof(CloakFieldController.FixedUpdate))] public static bool CloakFieldController_FixedUpdate(CloakFieldController __instance) { return __instance != null && __instance._cloakSphereShape != null; } [HarmonyPostfix] - [HarmonyPatch(typeof(CloakFieldController), nameof(CloakFieldController.isPlayerInsideCloak), MethodType.Getter)] + [HarmonyPatch(nameof(CloakFieldController.isPlayerInsideCloak), MethodType.Getter)] public static void CloakFieldController_isPlayerInsideCloak(ref bool __result) { __result = __result || Components.CloakSectorController.isPlayerInside; } [HarmonyPostfix] - [HarmonyPatch(typeof(CloakFieldController), nameof(CloakFieldController.isProbeInsideCloak), MethodType.Getter)] + [HarmonyPatch(nameof(CloakFieldController.isProbeInsideCloak), MethodType.Getter)] public static void CloakFieldController_isProbeInsideCloak(ref bool __result) { __result = __result || Components.CloakSectorController.isProbeInside; } [HarmonyPostfix] - [HarmonyPatch(typeof(CloakFieldController), nameof(CloakFieldController.isShipInsideCloak), MethodType.Getter)] + [HarmonyPatch(nameof(CloakFieldController.isShipInsideCloak), MethodType.Getter)] public static void CloakFieldController_isShipInsideCloak(ref bool __result) { __result = __result || Components.CloakSectorController.isShipInside; diff --git a/NewHorizons/Patches/EchoesOfTheEyePatches/MindProjectorTriggerPatches.cs b/NewHorizons/Patches/EchoesOfTheEyePatches/MindProjectorTriggerPatches.cs new file mode 100644 index 00000000..eefb309b --- /dev/null +++ b/NewHorizons/Patches/EchoesOfTheEyePatches/MindProjectorTriggerPatches.cs @@ -0,0 +1,47 @@ +using HarmonyLib; +using NewHorizons.Builder.Props; +using UnityEngine; + +namespace NewHorizons.Patches.EchoesOfTheEyePatches +{ + [HarmonyPatch(typeof(MindProjectorTrigger))] + public static class MindProjectorTriggerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(MindProjectorTrigger.OnTriggerVolumeEntry))] + public static bool MindProjectorTrigger_OnTriggerVolumeEntry(MindProjectorTrigger __instance, GameObject hitObj) + { + var t = hitObj.GetComponent(); + if (t != null) //(hitObj.CompareTag("PrisonerDetector")) + { + __instance._mindProjector.OnProjectionStart += t.onSlidesStart; + __instance._mindProjector.OnProjectionComplete += t.onSlidesComplete; + __instance._mindProjector.SetMindSlideCollection(t.slideCollection); + + __instance.OnBeamStartHitPrisoner.Invoke(); + __instance._mindProjector.Play(reset: true); + __instance._mindProjector.OnProjectionStart += __instance.OnProjectionStart; + __instance._mindProjector.OnProjectionComplete += __instance.OnProjectionComplete; + + Locator.GetPlayerTransform().GetComponent().LockOn(hitObj.transform, Vector3.zero); + __instance._playerLockedOn = true; + return false; + } + + return true; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(MindProjectorTrigger.OnTriggerVolumeExit))] + private static bool MindProjectorTrigger_OnTriggerVolumeExit(MindProjectorTrigger __instance, GameObject hitObj) + { + var t = hitObj.GetComponent(); + if (t != null) //(hitObj.CompareTag("PrisonerDetector")) + { + __instance._mindProjector.OnProjectionStart -= t.onSlidesStart; + __instance._mindProjector.OnProjectionComplete -= t.onSlidesComplete; + } + return true; + } + } +} diff --git a/NewHorizons/Patches/EchoesOfTheEyePatches/MindSlideProjectionPatches.cs b/NewHorizons/Patches/EchoesOfTheEyePatches/MindSlideProjectionPatches.cs new file mode 100644 index 00000000..b40493ab --- /dev/null +++ b/NewHorizons/Patches/EchoesOfTheEyePatches/MindSlideProjectionPatches.cs @@ -0,0 +1,35 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.EchoesOfTheEyePatches +{ + [HarmonyPatch(typeof(MindSlideProjector))] + public static class MindSlideProjectionPatches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(MindSlideProjector), nameof(MindSlideProjector.SetMindSlideCollection))] + private static bool MindSlideProjector_SetMindSlideCollection(MindSlideProjector __instance, MindSlideCollection mindSlideCollection) + { + if (mindSlideCollection == null) return false; + + if (__instance._mindSlideCollection == mindSlideCollection) return false; + + // Original method didn't check if old _slideCollectionItem was null. + if (__instance._slideCollectionItem != null) + { + __instance._slideCollectionItem.onSlideTextureUpdated -= __instance.OnSlideTextureUpdated; + __instance._slideCollectionItem.onPlayBeatAudio -= __instance.OnPlayBeatAudio; + } + + __instance._mindSlideCollection = mindSlideCollection; + __instance._defaultSlideDuration = mindSlideCollection.defaultSlideDuration; + + __instance._slideCollectionItem = mindSlideCollection.slideCollectionContainer; + __instance._slideCollectionItem.onSlideTextureUpdated += __instance.OnSlideTextureUpdated; + __instance._slideCollectionItem.onPlayBeatAudio += __instance.OnPlayBeatAudio; + __instance._slideCollectionItem.Initialize(); + __instance._slideCollectionItem.enabled = false; + + return false; + } + } +} diff --git a/NewHorizons/Patches/RaftPatches.cs b/NewHorizons/Patches/EchoesOfTheEyePatches/RaftControllerPatches.cs similarity index 55% rename from NewHorizons/Patches/RaftPatches.cs rename to NewHorizons/Patches/EchoesOfTheEyePatches/RaftControllerPatches.cs index 196885c0..a0b40a99 100644 --- a/NewHorizons/Patches/RaftPatches.cs +++ b/NewHorizons/Patches/EchoesOfTheEyePatches/RaftControllerPatches.cs @@ -1,12 +1,13 @@ using HarmonyLib; using UnityEngine; -namespace NewHorizons.Patches + +namespace NewHorizons.Patches.EchoesOfTheEyePatches { - [HarmonyPatch] - public static class RaftPatches + [HarmonyPatch(typeof(RaftController))] + public static class RaftControllerPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(RaftController), nameof(RaftController.FixedUpdate))] + [HarmonyPatch(nameof(RaftController.FixedUpdate))] public static bool RaftController_FixedUpdate(RaftController __instance) { // If it has a river fluid its a normal one and we don't do anything @@ -18,7 +19,7 @@ namespace NewHorizons.Patches return false; } bool playerInEffectsRange = __instance._playerInEffectsRange; - __instance._playerInEffectsRange = ((Locator.GetPlayerBody().GetPosition() - __instance._raftBody.GetPosition()).sqrMagnitude < 2500f); + __instance._playerInEffectsRange = (Locator.GetPlayerBody().GetPosition() - __instance._raftBody.GetPosition()).sqrMagnitude < 2500f; if (playerInEffectsRange && !__instance._playerInEffectsRange) { __instance._effectsController.StopAllEffects(); @@ -71,48 +72,5 @@ namespace NewHorizons.Patches return false; } - - [HarmonyReversePatch] - [HarmonyPatch(typeof(AsymmetricFluidDetector), nameof(AsymmetricFluidDetector.ManagedFixedUpdate))] - public static void AsymmetricFluidDetector_ManagedFixedUpdate(AsymmetricFluidDetector __instance) - { - // This is like doing base.FixedUpdate - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(AlignToSurfaceFluidDetector), nameof(AlignToSurfaceFluidDetector.ManagedFixedUpdate))] - public static bool AlignToSurfaceFluidDetector_ManagedFixedUpdate(AlignToSurfaceFluidDetector __instance) - { - if (__instance._alignmentFluid is not RadialFluidVolume) return true; - - // Mostly copy pasting from the AlignWithDirection class - AsymmetricFluidDetector_ManagedFixedUpdate(__instance); - - if (__instance._inAlignmentFluid) - { - // Both in world space - var currentDirection = __instance._owRigidbody.transform.up; - var alignmentDirection = (__instance.transform.position - __instance._alignmentFluid.transform.position).normalized; - var degreesToTarget = Vector3.Angle(currentDirection, alignmentDirection); - - var adjustedSlerpRate = Mathf.Clamp01(0.01f * degreesToTarget * Time.fixedDeltaTime); - - Vector3 a = OWPhysics.FromToAngularVelocity(currentDirection, alignmentDirection); - __instance._owRigidbody.AddAngularVelocityChange(a * adjustedSlerpRate); - } - - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(FluidVolume), nameof(FluidVolume.GetDepthAtPosition))] - public static bool FluidVolume_GetDepthAtPosition(FluidVolume __instance, ref float __result, Vector3 worldPosition) - { - if (__instance is not RadialFluidVolume radialFluidVolume) return true; - - Vector3 vector = radialFluidVolume.transform.InverseTransformPoint(worldPosition); - __result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - radialFluidVolume._radius; - return false; - } } } diff --git a/NewHorizons/Patches/EchoesOfTheEyePatches/VisionTorchItemPatches.cs b/NewHorizons/Patches/EchoesOfTheEyePatches/VisionTorchItemPatches.cs new file mode 100644 index 00000000..8565c244 --- /dev/null +++ b/NewHorizons/Patches/EchoesOfTheEyePatches/VisionTorchItemPatches.cs @@ -0,0 +1,33 @@ +using HarmonyLib; +using UnityEngine; + +namespace NewHorizons.Patches.EchoesOfTheEyePatches +{ + [HarmonyPatch] + public static class VisionTorchItemPatches + { + // This is some dark magic + // this creates a method called base_DropItem that basically just calls OWItem.PickUpItem whenever it (VisionTorchItemPatches.base_PickUpItem) is called + [HarmonyReversePatch] + [HarmonyPatch(typeof(OWItem), nameof(OWItem.DropItem))] + private static void base_DropItem(OWItem instance, Vector3 position, Vector3 normal, Transform parent, Sector sector, IItemDropTarget customDropTarget) { } + + + // Make the vision torch droppable. In the base game you can only drop it if you're in the dream world. + [HarmonyPrefix] + [HarmonyPatch(typeof(VisionTorchItem), nameof(VisionTorchItem.DropItem))] + public static bool VisionTorchItem_DropItem(VisionTorchItem __instance, Vector3 position, Vector3 normal, Transform parent, Sector sector, IItemDropTarget customDropTarget) + { + if (!Locator.GetDreamWorldController().IsInDream()) + { + base_DropItem(__instance, position, normal, parent, sector, customDropTarget); + } + + if (__instance._wasProjecting) __instance._mindProjectorTrigger.SetProjectorActive(false); + + __instance.gameObject.GetComponent().enabled = true; + + return true; + } + } +} diff --git a/NewHorizons/Patches/EyeOfTheUniversePatches.cs b/NewHorizons/Patches/EyeOfTheUniversePatches.cs deleted file mode 100644 index df4ba1e7..00000000 --- a/NewHorizons/Patches/EyeOfTheUniversePatches.cs +++ /dev/null @@ -1,53 +0,0 @@ -using HarmonyLib; -using UnityEngine; -namespace NewHorizons.Patches -{ - [HarmonyPatch] - public static class EyeOfTheUniversePatches - { - // Funny eye of the universe stuff - - private static void OnLoadScene(OWScene scene) - { - if (scene == OWScene.SolarSystem && !Main.Instance.IsWarpingBackToEye) - { - PlayerData.SaveEyeCompletion(); - - // Switch to default just in case another mod warps back. - if (Main.Instance.CurrentStarSystem == "EyeOfTheUniverse") Main.Instance._currentStarSystem = Main.Instance.DefaultStarSystem; - } - // Switch to eye just in case another mod warps there. - else if (scene == OWScene.EyeOfTheUniverse) Main.Instance._currentStarSystem = "EyeOfTheUniverse"; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(LoadManager), nameof(LoadManager.LoadSceneImmediate))] - public static void LoadManager_LoadSceneImmediate(OWScene scene) => OnLoadScene(scene); - - [HarmonyPrefix] - [HarmonyPatch(typeof(LoadManager), nameof(LoadManager.StartAsyncSceneLoad))] - public static void LoadManager_StartAsyncSceneLoad(OWScene scene) => OnLoadScene(scene); - - [HarmonyPrefix] - [HarmonyPatch(typeof(SubmitActionLoadScene), nameof(SubmitActionLoadScene.ConfirmSubmit))] - public static void SubmitActionLoadScene_ConfirmSubmit(SubmitActionLoadScene __instance) - { - // Title screen can warp you to eye and cause problems. - if (__instance._sceneToLoad == SubmitActionLoadScene.LoadableScenes.EYE) - { - Utility.Logger.LogWarning("Warping to solar system and then back to eye"); - Main.Instance.IsWarpingBackToEye = true; - __instance._sceneToLoad = SubmitActionLoadScene.LoadableScenes.GAME; - } - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(EyeVortexTrigger), nameof(EyeVortexTrigger.OnEnterVortex))] - public static void EyeVortexTrigger_OnEnterVortex(EyeVortexTrigger __instance, GameObject hitObj) - { - if (!hitObj.CompareTag("PlayerDetector")) return; - __instance._tunnelObject.SetActive(true); - } - - } -} diff --git a/NewHorizons/Patches/EyeScenePatches/EyeVortexTriggerPatches.cs b/NewHorizons/Patches/EyeScenePatches/EyeVortexTriggerPatches.cs new file mode 100644 index 00000000..d99e33f0 --- /dev/null +++ b/NewHorizons/Patches/EyeScenePatches/EyeVortexTriggerPatches.cs @@ -0,0 +1,17 @@ +using HarmonyLib; +using UnityEngine; + +namespace NewHorizons.Patches.EyeScenePatches +{ + [HarmonyPatch(typeof(EyeVortexTrigger))] + public static class EyeVortexTriggerPatches + { + [HarmonyPostfix] + [HarmonyPatch(nameof(EyeVortexTrigger.OnEnterVortex))] + public static void EyeVortexTrigger_OnEnterVortex(EyeVortexTrigger __instance, GameObject hitObj) + { + if (!hitObj.CompareTag("PlayerDetector")) return; + __instance._tunnelObject.SetActive(true); + } + } +} diff --git a/NewHorizons/Patches/EyeScenePatches/LoadManagerPatches.cs b/NewHorizons/Patches/EyeScenePatches/LoadManagerPatches.cs new file mode 100644 index 00000000..2bf53abf --- /dev/null +++ b/NewHorizons/Patches/EyeScenePatches/LoadManagerPatches.cs @@ -0,0 +1,29 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.EyeScenePatches +{ + [HarmonyPatch(typeof(LoadManager))] + public static class LoadManagerPatches + { + private static void OnLoadScene(OWScene scene) + { + if (scene == OWScene.SolarSystem && !Main.Instance.IsWarpingBackToEye) + { + PlayerData.SaveEyeCompletion(); + + // Switch to default just in case another mod warps back. + if (Main.Instance.CurrentStarSystem == "EyeOfTheUniverse") Main.Instance._currentStarSystem = Main.Instance.DefaultStarSystem; + } + // Switch to eye just in case another mod warps there. + else if (scene == OWScene.EyeOfTheUniverse) Main.Instance._currentStarSystem = "EyeOfTheUniverse"; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(LoadManager.LoadSceneImmediate))] + public static void LoadManager_LoadSceneImmediate(OWScene scene) => OnLoadScene(scene); + + [HarmonyPrefix] + [HarmonyPatch(nameof(LoadManager.StartAsyncSceneLoad))] + public static void LoadManager_StartAsyncSceneLoad(OWScene scene) => OnLoadScene(scene); + } +} diff --git a/NewHorizons/Patches/EyeScenePatches/SubmitActionLoadScenePatches.cs b/NewHorizons/Patches/EyeScenePatches/SubmitActionLoadScenePatches.cs new file mode 100644 index 00000000..33bdb236 --- /dev/null +++ b/NewHorizons/Patches/EyeScenePatches/SubmitActionLoadScenePatches.cs @@ -0,0 +1,21 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.EyeScenePatches +{ + [HarmonyPatch(typeof(SubmitActionLoadScene))] + public static class SubmitActionLoadScenePatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(SubmitActionLoadScene.ConfirmSubmit))] + public static void SubmitActionLoadScene_ConfirmSubmit(SubmitActionLoadScene __instance) + { + // Title screen can warp you to eye and cause problems. + if (__instance._sceneToLoad == SubmitActionLoadScene.LoadableScenes.EYE) + { + Utility.Logger.LogWarning("Warping to solar system and then back to eye"); + Main.Instance.IsWarpingBackToEye = true; + __instance._sceneToLoad = SubmitActionLoadScene.LoadableScenes.GAME; + } + } + } +} diff --git a/NewHorizons/Patches/HUDPatches.cs b/NewHorizons/Patches/HUDPatches.cs deleted file mode 100644 index bb9a1c4f..00000000 --- a/NewHorizons/Patches/HUDPatches.cs +++ /dev/null @@ -1,124 +0,0 @@ -using HarmonyLib; -using NewHorizons.Handlers; - -namespace NewHorizons.Patches -{ - [HarmonyPatch] - public static class HUDPatches - { - [HarmonyPostfix] - [HarmonyPatch(typeof(HUDMarker), nameof(HUDMarker.Awake))] - public static void HUDMarker_Awake(HUDMarker __instance) - { - GlobalMessenger.AddListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); - GlobalMessenger.AddListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); - GlobalMessenger.AddListener("PlayerEnterCloakField", __instance.OnPlayerEnterCloakField); - GlobalMessenger.AddListener("PlayerExitCloakField", __instance.OnPlayerExitCloakField); - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(HUDMarker), nameof(HUDMarker.OnDestroy))] - public static void HUDMarker_OnDestroy(HUDMarker __instance) - { - GlobalMessenger.RemoveListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); - GlobalMessenger.RemoveListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); - GlobalMessenger.RemoveListener("PlayerEnterCloakField", __instance.OnPlayerEnterCloakField); - GlobalMessenger.RemoveListener("PlayerExitCloakField", __instance.OnPlayerExitCloakField); - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(ProbeHUDMarker), nameof(ProbeHUDMarker.Awake))] - public static void ProbeHUDMarker_Awake(ProbeHUDMarker __instance) - { - GlobalMessenger.AddListener("ProbeEnterCloakField", __instance.RefreshOwnVisibility); - GlobalMessenger.AddListener("ProbeExitCloakField", __instance.RefreshOwnVisibility); - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(ProbeHUDMarker), nameof(ProbeHUDMarker.OnDestroy))] - public static void ProbeHUDMarker_OnDestroy(ProbeHUDMarker __instance) - { - GlobalMessenger.RemoveListener("ProbeEnterCloakField", __instance.RefreshOwnVisibility); - GlobalMessenger.RemoveListener("ProbeExitCloakField", __instance.RefreshOwnVisibility); - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(ShipHUDMarker), nameof(ShipHUDMarker.Awake))] - public static void ShipHUDMarker_Awake(ShipHUDMarker __instance) - { - GlobalMessenger.AddListener("ShipEnterCloakField", __instance.RefreshOwnVisibility); - GlobalMessenger.AddListener("ShipExitCloakField", __instance.RefreshOwnVisibility); - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(ShipHUDMarker), nameof(ShipHUDMarker.OnDestroy))] - public static void ShipHUDMarker_OnDestroy(ShipHUDMarker __instance) - { - GlobalMessenger.RemoveListener("ShipEnterCloakField", __instance.RefreshOwnVisibility); - GlobalMessenger.RemoveListener("ShipExitCloakField", __instance.RefreshOwnVisibility); - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ProbeHUDMarker), nameof(ProbeHUDMarker.RefreshOwnVisibility))] - public static bool ProbeHUDMarker_RefreshOwnVisibility(ProbeHUDMarker __instance) - { - bool insideEYE = Locator.GetEyeStateManager() != null && Locator.GetEyeStateManager().IsInsideTheEye(); - bool insideQM = __instance._quantumMoon != null && (__instance._quantumMoon.IsPlayerInside() || __instance._quantumMoon.IsProbeInside()); - bool insideRW = Locator.GetRingWorldController() != null && Locator.GetRingWorldController().isPlayerInside == Locator.GetRingWorldController().isProbeInside; - bool insideIP = Locator.GetCloakFieldController() != null && Locator.GetCloakFieldController().isPlayerInsideCloak == Locator.GetCloakFieldController().isProbeInsideCloak; - bool insideCloak = Components.CloakSectorController.isPlayerInside == Components.CloakSectorController.isProbeInside; - bool sameInterference = InterferenceHandler.IsPlayerSameAsProbe(); - bool isActive = __instance.gameObject.activeInHierarchy || __instance._isTLCDuplicate; - - __instance._isVisible = isActive && !insideEYE && !insideQM && !__instance._translatorEquipped && !__instance._inConversation && __instance._launched && (__instance._isWearingHelmet || __instance._atFlightConsole) && insideRW && insideIP && insideCloak && sameInterference; - - if (__instance._canvasMarker != null) __instance._canvasMarker.SetVisibility(__instance._isVisible); - - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipHUDMarker), nameof(ShipHUDMarker.RefreshOwnVisibility))] - public static bool ShipHUDMarker_RefreshOwnVisibility(ShipHUDMarker __instance) - { - bool insideEYE = Locator.GetEyeStateManager() != null && Locator.GetEyeStateManager().IsInsideTheEye(); - bool insideQM = __instance._quantumMoon != null && (__instance._quantumMoon.IsPlayerInside() || __instance._quantumMoon.IsShipInside()); - bool insideRW = Locator.GetRingWorldController() != null && Locator.GetRingWorldController().isPlayerInside; - bool insideIP = Locator.GetCloakFieldController() != null && Locator.GetCloakFieldController().isPlayerInsideCloak == Locator.GetCloakFieldController().isShipInsideCloak; - bool insideCloak = Components.CloakSectorController.isPlayerInside == Components.CloakSectorController.isShipInside; - bool sameInterference = InterferenceHandler.IsPlayerSameAsShip(); - - __instance._isVisible = !insideEYE && !insideQM && !insideRW && !__instance._translatorEquipped && !__instance._inConversation && !__instance._shipDestroyed && !__instance._playerInShip && PlayerState.HasPlayerEnteredShip() && __instance._isWearingHelmet && insideIP && insideCloak && sameInterference; - - if (__instance._canvasMarker != null) __instance._canvasMarker.SetVisibility(__instance._isVisible); - - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipLogEntryHUDMarker), nameof(ShipLogEntryHUDMarker.RefreshOwnVisibility))] - public static bool ShipLogEntryHUDMarker_RefreshOwnVisibility(ShipLogEntryHUDMarker __instance) - { - bool hasEntryLocation = ShipLogEntryHUDMarker.s_entryLocation != null; - bool insideEYE = Locator.GetEyeStateManager() != null && Locator.GetEyeStateManager().IsInsideTheEye(); - bool insideQM = __instance._quantumMoon != null && __instance._quantumMoon.IsPlayerInside(); - bool insideRW = Locator.GetRingWorldController() != null && Locator.GetRingWorldController().isPlayerInside && ShipLogEntryHUDMarker.s_entryLocationID == "IP_RING_WORLD"; - bool insideIP = (hasEntryLocation && ShipLogEntryHUDMarker.s_entryLocation.IsWithinCloakField()) || !(Locator.GetCloakFieldController() != null && Locator.GetCloakFieldController().isPlayerInsideCloak); - bool insideCloak = (hasEntryLocation && ShipLogEntryHUDMarker.s_entryLocation.IsWithinCloakField()) || !Components.CloakSectorController.isPlayerInside; - - __instance._isVisible = (!insideEYE && !insideQM && !insideRW && !__instance._translatorEquipped && !__instance._inConversation && hasEntryLocation && (__instance._isWearingHelmet || __instance._atFlightConsole) && insideIP && insideCloak); - - if (__instance._canvasMarker != null) __instance._canvasMarker.SetVisibility(__instance._isVisible); - - return false; - } - - - [HarmonyPostfix] - [HarmonyPatch(typeof(ProbeCamera), nameof(ProbeCamera.HasInterference))] - public static void ProbeCamera_HasInterference(ProbeCamera __instance, ref bool __result) - { - __result = __result || (__instance._id != ProbeCamera.ID.PreLaunch && (Components.CloakSectorController.isPlayerInside != Components.CloakSectorController.isProbeInside || !InterferenceHandler.IsPlayerSameAsProbe())); - } - } -} diff --git a/NewHorizons/Patches/HUDPatches/HUDMarkerPatches.cs b/NewHorizons/Patches/HUDPatches/HUDMarkerPatches.cs new file mode 100644 index 00000000..f82459ac --- /dev/null +++ b/NewHorizons/Patches/HUDPatches/HUDMarkerPatches.cs @@ -0,0 +1,28 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.HUDPatches +{ + [HarmonyPatch(typeof(HUDMarker))] + public static class HUDMarkerPatches + { + [HarmonyPostfix] + [HarmonyPatch(nameof(HUDMarker.Awake))] + public static void HUDMarker_Awake(HUDMarker __instance) + { + GlobalMessenger.AddListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); + GlobalMessenger.AddListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); + GlobalMessenger.AddListener("PlayerEnterCloakField", __instance.OnPlayerEnterCloakField); + GlobalMessenger.AddListener("PlayerExitCloakField", __instance.OnPlayerExitCloakField); + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(HUDMarker.OnDestroy))] + public static void HUDMarker_OnDestroy(HUDMarker __instance) + { + GlobalMessenger.RemoveListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); + GlobalMessenger.RemoveListener("RefreshHUDVisibility", __instance.RefreshOwnVisibility); + GlobalMessenger.RemoveListener("PlayerEnterCloakField", __instance.OnPlayerEnterCloakField); + GlobalMessenger.RemoveListener("PlayerExitCloakField", __instance.OnPlayerExitCloakField); + } + } +} diff --git a/NewHorizons/Patches/HUDPatches/ProbeHUDMarkerPatches.cs b/NewHorizons/Patches/HUDPatches/ProbeHUDMarkerPatches.cs new file mode 100644 index 00000000..dc464f3c --- /dev/null +++ b/NewHorizons/Patches/HUDPatches/ProbeHUDMarkerPatches.cs @@ -0,0 +1,44 @@ +using HarmonyLib; +using NewHorizons.Handlers; + +namespace NewHorizons.Patches.HUDPatches +{ + [HarmonyPatch(typeof(ProbeHUDMarker))] + public static class ProbeHUDMarkerPatches + { + [HarmonyPostfix] + [HarmonyPatch(nameof(ProbeHUDMarker.Awake))] + public static void ProbeHUDMarker_Awake(ProbeHUDMarker __instance) + { + GlobalMessenger.AddListener("ProbeEnterCloakField", __instance.RefreshOwnVisibility); + GlobalMessenger.AddListener("ProbeExitCloakField", __instance.RefreshOwnVisibility); + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(ProbeHUDMarker.OnDestroy))] + public static void ProbeHUDMarker_OnDestroy(ProbeHUDMarker __instance) + { + GlobalMessenger.RemoveListener("ProbeEnterCloakField", __instance.RefreshOwnVisibility); + GlobalMessenger.RemoveListener("ProbeExitCloakField", __instance.RefreshOwnVisibility); + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ProbeHUDMarker.RefreshOwnVisibility))] + public static bool ProbeHUDMarker_RefreshOwnVisibility(ProbeHUDMarker __instance) + { + bool insideEYE = Locator.GetEyeStateManager() != null && Locator.GetEyeStateManager().IsInsideTheEye(); + bool insideQM = __instance._quantumMoon != null && (__instance._quantumMoon.IsPlayerInside() || __instance._quantumMoon.IsProbeInside()); + bool insideRW = Locator.GetRingWorldController() != null && Locator.GetRingWorldController().isPlayerInside == Locator.GetRingWorldController().isProbeInside; + bool insideIP = Locator.GetCloakFieldController() != null && Locator.GetCloakFieldController().isPlayerInsideCloak == Locator.GetCloakFieldController().isProbeInsideCloak; + bool insideCloak = Components.CloakSectorController.isPlayerInside == Components.CloakSectorController.isProbeInside; + bool sameInterference = InterferenceHandler.IsPlayerSameAsProbe(); + bool isActive = __instance.gameObject.activeInHierarchy || __instance._isTLCDuplicate; + + __instance._isVisible = isActive && !insideEYE && !insideQM && !__instance._translatorEquipped && !__instance._inConversation && __instance._launched && (__instance._isWearingHelmet || __instance._atFlightConsole) && insideRW && insideIP && insideCloak && sameInterference; + + if (__instance._canvasMarker != null) __instance._canvasMarker.SetVisibility(__instance._isVisible); + + return false; + } + } +} diff --git a/NewHorizons/Patches/HUDPatches/ShipHUDMarkerPatches.cs b/NewHorizons/Patches/HUDPatches/ShipHUDMarkerPatches.cs new file mode 100644 index 00000000..c44f46dc --- /dev/null +++ b/NewHorizons/Patches/HUDPatches/ShipHUDMarkerPatches.cs @@ -0,0 +1,43 @@ +using HarmonyLib; +using NewHorizons.Handlers; + +namespace NewHorizons.Patches.HUDPatches +{ + [HarmonyPatch(typeof(ShipHUDMarker))] + public static class ShipHUDMarkerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipHUDMarker.RefreshOwnVisibility))] + public static bool ShipHUDMarker_RefreshOwnVisibility(ShipHUDMarker __instance) + { + bool insideEYE = Locator.GetEyeStateManager() != null && Locator.GetEyeStateManager().IsInsideTheEye(); + bool insideQM = __instance._quantumMoon != null && (__instance._quantumMoon.IsPlayerInside() || __instance._quantumMoon.IsShipInside()); + bool insideRW = Locator.GetRingWorldController() != null && Locator.GetRingWorldController().isPlayerInside; + bool insideIP = Locator.GetCloakFieldController() != null && Locator.GetCloakFieldController().isPlayerInsideCloak == Locator.GetCloakFieldController().isShipInsideCloak; + bool insideCloak = Components.CloakSectorController.isPlayerInside == Components.CloakSectorController.isShipInside; + bool sameInterference = InterferenceHandler.IsPlayerSameAsShip(); + + __instance._isVisible = !insideEYE && !insideQM && !insideRW && !__instance._translatorEquipped && !__instance._inConversation && !__instance._shipDestroyed && !__instance._playerInShip && PlayerState.HasPlayerEnteredShip() && __instance._isWearingHelmet && insideIP && insideCloak && sameInterference; + + if (__instance._canvasMarker != null) __instance._canvasMarker.SetVisibility(__instance._isVisible); + + return false; + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(ShipHUDMarker.OnDestroy))] + public static void ShipHUDMarker_OnDestroy(ShipHUDMarker __instance) + { + GlobalMessenger.RemoveListener("ShipEnterCloakField", __instance.RefreshOwnVisibility); + GlobalMessenger.RemoveListener("ShipExitCloakField", __instance.RefreshOwnVisibility); + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(ShipHUDMarker.Awake))] + public static void ShipHUDMarker_Awake(ShipHUDMarker __instance) + { + GlobalMessenger.AddListener("ShipEnterCloakField", __instance.RefreshOwnVisibility); + GlobalMessenger.AddListener("ShipExitCloakField", __instance.RefreshOwnVisibility); + } + } +} diff --git a/NewHorizons/Patches/HUDPatches/ShipLogEntryHUDMarkerPatches.cs b/NewHorizons/Patches/HUDPatches/ShipLogEntryHUDMarkerPatches.cs new file mode 100644 index 00000000..75800339 --- /dev/null +++ b/NewHorizons/Patches/HUDPatches/ShipLogEntryHUDMarkerPatches.cs @@ -0,0 +1,26 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.HUDPatches +{ + [HarmonyPatch(typeof(ShipLogEntryHUDMarker))] + public static class ShipLogEntryHUDMarkerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogEntryHUDMarker.RefreshOwnVisibility))] + public static bool ShipLogEntryHUDMarker_RefreshOwnVisibility(ShipLogEntryHUDMarker __instance) + { + bool hasEntryLocation = ShipLogEntryHUDMarker.s_entryLocation != null; + bool insideEYE = Locator.GetEyeStateManager() != null && Locator.GetEyeStateManager().IsInsideTheEye(); + bool insideQM = __instance._quantumMoon != null && __instance._quantumMoon.IsPlayerInside(); + bool insideRW = Locator.GetRingWorldController() != null && Locator.GetRingWorldController().isPlayerInside && ShipLogEntryHUDMarker.s_entryLocationID == "IP_RING_WORLD"; + bool insideIP = hasEntryLocation && ShipLogEntryHUDMarker.s_entryLocation.IsWithinCloakField() || !(Locator.GetCloakFieldController() != null && Locator.GetCloakFieldController().isPlayerInsideCloak); + bool insideCloak = hasEntryLocation && ShipLogEntryHUDMarker.s_entryLocation.IsWithinCloakField() || !Components.CloakSectorController.isPlayerInside; + + __instance._isVisible = !insideEYE && !insideQM && !insideRW && !__instance._translatorEquipped && !__instance._inConversation && hasEntryLocation && (__instance._isWearingHelmet || __instance._atFlightConsole) && insideIP && insideCloak; + + if (__instance._canvasMarker != null) __instance._canvasMarker.SetVisibility(__instance._isVisible); + + return false; + } + } +} diff --git a/NewHorizons/Patches/LocatorPatches.cs b/NewHorizons/Patches/LocatorPatches.cs index a9a901e0..b1d32bd8 100644 --- a/NewHorizons/Patches/LocatorPatches.cs +++ b/NewHorizons/Patches/LocatorPatches.cs @@ -2,7 +2,7 @@ using HarmonyLib; namespace NewHorizons.Patches { - [HarmonyPatch] + [HarmonyPatch(typeof(Locator))] public static class LocatorPatches { public static AstroObject _attlerock; @@ -13,7 +13,7 @@ namespace NewHorizons.Patches public static AstroObject _sunStation; [HarmonyPrefix] - [HarmonyPatch(typeof(Locator), nameof(Locator.RegisterCloakFieldController))] + [HarmonyPatch(nameof(Locator.RegisterCloakFieldController))] public static bool Locator_RegisterCloakFieldController() { return Locator._cloakFieldController == null; @@ -22,7 +22,7 @@ namespace NewHorizons.Patches // Locator Fixes // Vanilla doesn't register these AstroObjects for some reason. So here is a fix. [HarmonyPrefix] - [HarmonyPatch(typeof(Locator), nameof(Locator.GetAstroObject))] + [HarmonyPatch(nameof(Locator.GetAstroObject))] public static bool Locator_GetAstroObject(AstroObject.Name astroObjectName, ref AstroObject __result) { switch (astroObjectName) @@ -52,7 +52,7 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(Locator), nameof(Locator.RegisterAstroObject))] + [HarmonyPatch(nameof(Locator.RegisterAstroObject))] public static bool Locator_RegisterAstroObject(AstroObject astroObject) { if (astroObject.GetAstroObjectName() == AstroObject.Name.None) return false; @@ -98,7 +98,7 @@ namespace NewHorizons.Patches } [HarmonyPostfix] - [HarmonyPatch(typeof(Locator), nameof(Locator.ClearReferences))] + [HarmonyPatch(nameof(Locator.ClearReferences))] public static void Locator_ClearReferences() { _attlerock = null; diff --git a/NewHorizons/Patches/MapPatches/CanvasMapMarkerPatches.cs b/NewHorizons/Patches/MapPatches/CanvasMapMarkerPatches.cs new file mode 100644 index 00000000..8339d26e --- /dev/null +++ b/NewHorizons/Patches/MapPatches/CanvasMapMarkerPatches.cs @@ -0,0 +1,19 @@ +using HarmonyLib; +using NewHorizons.Handlers; +using System; +using UnityEngine; + +namespace NewHorizons.Patches.MapPatches +{ + [HarmonyPatch(typeof(CanvasMapMarker))] + public static class CanvasMapMarkerPatches + { + [HarmonyPostfix] + [HarmonyPatch(nameof(CanvasMapMarker.Init), new Type[] { typeof(Canvas), typeof(Transform), typeof(string) })] + [HarmonyPatch(nameof(CanvasMapMarker.SetLabel))] + public static void CanvasMapMarker_LocalizeLabel(CanvasMapMarker __instance) + { + __instance._label = TranslationHandler.GetTranslation(__instance._label, TranslationHandler.TextType.UI); + } + } +} diff --git a/NewHorizons/Patches/MapControllerPatches.cs b/NewHorizons/Patches/MapPatches/MapControllerPatches.cs similarity index 66% rename from NewHorizons/Patches/MapControllerPatches.cs rename to NewHorizons/Patches/MapPatches/MapControllerPatches.cs index 3c13673e..65306918 100644 --- a/NewHorizons/Patches/MapControllerPatches.cs +++ b/NewHorizons/Patches/MapPatches/MapControllerPatches.cs @@ -2,13 +2,13 @@ using HarmonyLib; using UnityEngine; using UnityEngine.SceneManagement; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.MapPatches { - [HarmonyPatch] + [HarmonyPatch(typeof(MapController))] public static class MapControllerPatches { [HarmonyPostfix] - [HarmonyPatch(typeof(MapController), nameof(MapController.Awake))] + [HarmonyPatch(nameof(MapController.Awake))] public static void MapController_Awake(MapController __instance) { __instance._maxPanDistance = Mathf.Max(__instance._maxPanDistance, Main.FurthestOrbit * 1.5f); @@ -19,14 +19,15 @@ namespace NewHorizons.Patches } [HarmonyPostfix] - [HarmonyPatch(typeof(MapController), nameof(MapController.OnTargetReferenceFrame))] + [HarmonyPatch(nameof(MapController.OnTargetReferenceFrame))] public static void MapController_OnTargetReferenceFrame(MapController __instance, ReferenceFrame __0) { + // Locked onto map satellite just means it will move vertically up from the plane of the solar system __instance._isLockedOntoMapSatellite = true; } [HarmonyPrefix] - [HarmonyPatch(typeof(MapController), nameof(MapController.MapInoperable))] + [HarmonyPatch(nameof(MapController.MapInoperable))] public static bool MapController_MapInoperable(MapController __instance, ref bool __result) { if (SceneManager.GetActiveScene().name != "SolarSystem") return true; @@ -44,12 +45,5 @@ namespace NewHorizons.Patches return true; } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ReferenceFrameTracker), nameof(ReferenceFrameTracker.UntargetReferenceFrame), new System.Type[] { typeof(bool) })] - public static bool ReferenceFrameTracker_UntargetReferenceFrame(ReferenceFrameTracker __instance, bool playAudio) - { - return __instance != null && __instance._hasTarget && __instance._currentReferenceFrame != null; - } } } diff --git a/NewHorizons/Patches/TranslationPatches.cs b/NewHorizons/Patches/MapPatches/ReferenceFramePatches.cs similarity index 50% rename from NewHorizons/Patches/TranslationPatches.cs rename to NewHorizons/Patches/MapPatches/ReferenceFramePatches.cs index c6ea4fc5..a9efb8b1 100644 --- a/NewHorizons/Patches/TranslationPatches.cs +++ b/NewHorizons/Patches/MapPatches/ReferenceFramePatches.cs @@ -1,15 +1,14 @@ using HarmonyLib; using NewHorizons.Components.Orbital; using NewHorizons.Handlers; -using System; -using UnityEngine; -namespace NewHorizons.Patches + +namespace NewHorizons.Patches.MapPatches { - [HarmonyPatch] - public static class TranslationPatches + [HarmonyPatch(typeof(ReferenceFrame))] + public static class ReferenceFramePatches { [HarmonyPrefix] - [HarmonyPatch(typeof(ReferenceFrame), nameof(ReferenceFrame.GetHUDDisplayName))] + [HarmonyPatch(nameof(ReferenceFrame.GetHUDDisplayName))] public static bool ReferenceFrame_GetHUDDisplayName(ReferenceFrame __instance, ref string __result) { var ao = __instance.GetAstroObject(); @@ -35,19 +34,5 @@ namespace NewHorizons.Patches return false; } - - [HarmonyPostfix] - [HarmonyPatch(typeof(CanvasMapMarker), nameof(CanvasMapMarker.Init), new Type[] { typeof(Canvas), typeof(Transform), typeof(string) })] - public static void CanvasMapMarker_Init(CanvasMapMarker __instance) - { - __instance._label = TranslationHandler.GetTranslation(__instance._label, TranslationHandler.TextType.UI); - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(CanvasMapMarker), nameof(CanvasMapMarker.SetLabel))] - public static void CanvasMapMarker_SetLabel(CanvasMapMarker __instance) - { - __instance._label = TranslationHandler.GetTranslation(__instance._label, TranslationHandler.TextType.UI); - } } } diff --git a/NewHorizons/Patches/MapPatches/ReferenceFrameTrackerPatches.cs b/NewHorizons/Patches/MapPatches/ReferenceFrameTrackerPatches.cs new file mode 100644 index 00000000..8184ef78 --- /dev/null +++ b/NewHorizons/Patches/MapPatches/ReferenceFrameTrackerPatches.cs @@ -0,0 +1,15 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.MapPatches +{ + [HarmonyPatch(typeof(ReferenceFrameTracker))] + public static class ReferenceFrameTrackerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(ReferenceFrameTracker.UntargetReferenceFrame), new System.Type[] { typeof(bool) })] + public static bool ReferenceFrameTracker_UntargetReferenceFrame(ReferenceFrameTracker __instance, bool playAudio) + { + return __instance != null && __instance._hasTarget && __instance._currentReferenceFrame != null; + } + } +} diff --git a/NewHorizons/Patches/MeteorPatches.cs b/NewHorizons/Patches/MeteorControllerPatches.cs similarity index 65% rename from NewHorizons/Patches/MeteorPatches.cs rename to NewHorizons/Patches/MeteorControllerPatches.cs index 31eb73fa..ba1603eb 100644 --- a/NewHorizons/Patches/MeteorPatches.cs +++ b/NewHorizons/Patches/MeteorControllerPatches.cs @@ -2,11 +2,11 @@ using HarmonyLib; namespace NewHorizons.Patches { - [HarmonyPatch] - public static class MeteorPatches + [HarmonyPatch(typeof(MeteorController))] + public static class MeteorControllerPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(MeteorController), nameof(MeteorController.Suspend), new System.Type[0])] + [HarmonyPatch(nameof(MeteorController.Suspend), new System.Type[0])] public static void MeteorController_Suspend(MeteorController __instance) { // Meteors launch inactive because of prefab. So let's fix that. diff --git a/NewHorizons/Patches/PlayerDataPatches.cs b/NewHorizons/Patches/PlayerPatches/PlayerDataPatches.cs similarity index 82% rename from NewHorizons/Patches/PlayerDataPatches.cs rename to NewHorizons/Patches/PlayerPatches/PlayerDataPatches.cs index 7c4b3fc6..38f3f1e7 100644 --- a/NewHorizons/Patches/PlayerDataPatches.cs +++ b/NewHorizons/Patches/PlayerPatches/PlayerDataPatches.cs @@ -1,20 +1,20 @@ using HarmonyLib; -using NewHorizons.OtherMods.AchievementsPlus; -using NewHorizons.OtherMods.AchievementsPlus.NH; using NewHorizons.Builder.Props; using NewHorizons.External; using NewHorizons.Handlers; +using NewHorizons.OtherMods.AchievementsPlus; +using NewHorizons.OtherMods.AchievementsPlus.NH; +using NewHorizons.Utility; using System.Collections.Generic; using System.Linq; -using NewHorizons.Utility; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.PlayerPatches { - [HarmonyPatch] + [HarmonyPatch(typeof(PlayerData))] public static class PlayerDataPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.KnowsFrequency))] + [HarmonyPatch(nameof(PlayerData.KnowsFrequency))] public static bool OnPlayerDataKnowsFrequency(SignalFrequency __0, ref bool __result) { var freqString = SignalBuilder.GetCustomFrequencyName(__0); @@ -28,7 +28,7 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.LearnFrequency))] + [HarmonyPatch(nameof(PlayerData.LearnFrequency))] public static bool OnPlayerDataLearnFrequency(SignalFrequency __0) { var freqString = SignalBuilder.GetCustomFrequencyName(__0); @@ -42,7 +42,7 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.KnowsSignal))] + [HarmonyPatch(nameof(PlayerData.KnowsSignal))] public static bool OnPlayerDataKnowsSignal(SignalName __0, ref bool __result) { var customSignalName = SignalBuilder.GetCustomSignalName(__0); @@ -55,13 +55,13 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.LearnSignal))] + [HarmonyPatch(nameof(PlayerData.LearnSignal))] public static bool OnPlayerDataLearnSignal(SignalName __0) { var customSignalName = SignalBuilder.GetCustomSignalName(__0); if (customSignalName != null) { - if (!NewHorizonsData.KnowsSignal(customSignalName)) + if (!NewHorizonsData.KnowsSignal(customSignalName)) { NewHorizonsData.LearnSignal(customSignalName); } @@ -74,7 +74,7 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.KnowsMultipleFrequencies))] + [HarmonyPatch(nameof(PlayerData.KnowsMultipleFrequencies))] public static bool OnPlayerDataKnowsMultipleFrequencies(ref bool __result) { if (NewHorizonsData.KnowsMultipleFrequencies()) @@ -86,7 +86,7 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.AddNewlyRevealedFactID))] + [HarmonyPatch(nameof(PlayerData.AddNewlyRevealedFactID))] public static bool OnPlayerDataAddNewlyRevealedFactID(string __0) { if (ShipLogHandler.IsModdedFact(__0)) @@ -101,7 +101,7 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.GetNewlyRevealedFactIDs))] + [HarmonyPatch(nameof(PlayerData.GetNewlyRevealedFactIDs))] public static bool OnPlayerDataGetNewlyRevealedFactIDs(ref List __result) { var newHorizonsNewlyRevealedFactIDs = NewHorizonsData.GetNewlyRevealedFactIDs(); @@ -118,7 +118,7 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.ClearNewlyRevealedFactIDs))] + [HarmonyPatch(nameof(PlayerData.ClearNewlyRevealedFactIDs))] public static bool OnPlayerDataClearNewlyRevealedFactIDs() { PlayerData._currentGameSave.newlyRevealedFactIDs.Clear(); @@ -127,14 +127,14 @@ namespace NewHorizons.Patches } [HarmonyPostfix] - [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.ResetGame))] + [HarmonyPatch(nameof(PlayerData.ResetGame))] public static void OnPlayerDataResetGame() { NewHorizonsData.Reset(); } [HarmonyPostfix] - [HarmonyPatch(typeof(PlayerData), nameof(PlayerData.GetNewlyRevealedFactIDs))] + [HarmonyPatch(nameof(PlayerData.GetNewlyRevealedFactIDs))] public static void PlayerData_GetNewlyRevealedFactIDs(ref List __result) { ShipLogManager manager = Locator.GetShipLogManager(); diff --git a/NewHorizons/Patches/PlayerSpawnerPatches.cs b/NewHorizons/Patches/PlayerPatches/PlayerSpawnerPatches.cs similarity index 83% rename from NewHorizons/Patches/PlayerSpawnerPatches.cs rename to NewHorizons/Patches/PlayerPatches/PlayerSpawnerPatches.cs index 3eef005c..80f814fb 100644 --- a/NewHorizons/Patches/PlayerSpawnerPatches.cs +++ b/NewHorizons/Patches/PlayerPatches/PlayerSpawnerPatches.cs @@ -1,12 +1,13 @@ using HarmonyLib; using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Patches + +namespace NewHorizons.Patches.PlayerPatches { - [HarmonyPatch] + [HarmonyPatch(typeof(PlayerSpawner))] public static class PlayerSpawnerPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerSpawner), nameof(PlayerSpawner.SpawnPlayer))] + [HarmonyPatch(nameof(PlayerSpawner.SpawnPlayer))] public static bool PlayerSpawner_SpawnPlayer(PlayerSpawner __instance) { if (Main.Instance.IsWarpingFromVessel || Main.Instance.DidWarpFromVessel) diff --git a/NewHorizons/Patches/PlayerStatePatches.cs b/NewHorizons/Patches/PlayerPatches/PlayerStatePatches.cs similarity index 81% rename from NewHorizons/Patches/PlayerStatePatches.cs rename to NewHorizons/Patches/PlayerPatches/PlayerStatePatches.cs index 0fe13918..adc39008 100644 --- a/NewHorizons/Patches/PlayerStatePatches.cs +++ b/NewHorizons/Patches/PlayerPatches/PlayerStatePatches.cs @@ -1,12 +1,12 @@ -using HarmonyLib; +using HarmonyLib; using UnityEngine; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.PlayerPatches { - [HarmonyPatch] + [HarmonyPatch(typeof(PlayerState))] public static class PlayerStatePatches { [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerState), nameof(PlayerState.CheckShipOutsideSolarSystem))] + [HarmonyPatch(nameof(PlayerState.CheckShipOutsideSolarSystem))] public static bool PlayerState_CheckShipOutsideSolarSystem(PlayerState __instance, ref bool __result) { if (PlayerState._inBrambleDimension) return false; diff --git a/NewHorizons/Patches/ProbeLauncherPatches.cs b/NewHorizons/Patches/ProbeLauncherPatches.cs deleted file mode 100644 index 0f1ef17e..00000000 --- a/NewHorizons/Patches/ProbeLauncherPatches.cs +++ /dev/null @@ -1,14 +0,0 @@ -using HarmonyLib; -namespace NewHorizons.Patches -{ - [HarmonyPatch] - public static class ProbeLauncherPatches - { - [HarmonyPrefix] - [HarmonyPatch(typeof(ProbeLauncher), nameof(ProbeLauncher.UpdateOrbitalLaunchValues))] - public static bool ProbeLauncher_UpdateOrbitalLaunchValues(ProbeLauncher __instance) - { - return (Locator.GetPlayerRulesetDetector()?.GetPlanetoidRuleset()?.GetGravityVolume() != null); - } - } -} diff --git a/NewHorizons/Patches/ProxyPatches/ProxyBodyPatches.cs b/NewHorizons/Patches/ProxyPatches/ProxyBodyPatches.cs new file mode 100644 index 00000000..5ff71810 --- /dev/null +++ b/NewHorizons/Patches/ProxyPatches/ProxyBodyPatches.cs @@ -0,0 +1,15 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.ProxyPatches +{ + [HarmonyPatch(typeof(ProxyBody))] + public static class ProxyBodyPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(ProxyBody.IsObjectInSupernova))] + public static bool ProxyBody_IsObjectInSupernova(ProxyBody __instance) + { + return Locator.GetSunController() != null; + } + } +} diff --git a/NewHorizons/Patches/ProxyBodyPatches.cs b/NewHorizons/Patches/ProxyPatches/ProxyPlanetPatches.cs similarity index 89% rename from NewHorizons/Patches/ProxyBodyPatches.cs rename to NewHorizons/Patches/ProxyPatches/ProxyPlanetPatches.cs index 8040d805..b59bdfcf 100644 --- a/NewHorizons/Patches/ProxyBodyPatches.cs +++ b/NewHorizons/Patches/ProxyPatches/ProxyPlanetPatches.cs @@ -1,23 +1,15 @@ using HarmonyLib; -using NewHorizons.Components; -using NewHorizons.Handlers; using NewHorizons.Utility; using System; using System.Runtime.CompilerServices; using UnityEngine; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.ProxyPatches { [HarmonyPatch] - public static class ProxyBodyPatches + public static class ProxyPlanetPatches { - [HarmonyPrefix] - [HarmonyPatch(typeof(ProxyBody), nameof(ProxyBody.IsObjectInSupernova))] - public static bool ProxyBody_IsObjectInSupernova(ProxyBody __instance) - { - return Locator.GetSunController() != null; - } - + // To call the base method [HarmonyReversePatch] [HarmonyPatch(typeof(ProxyPlanet), nameof(ProxyPlanet.Initialize))] [MethodImpl(MethodImplOptions.NoInlining)] diff --git a/NewHorizons/Patches/ProxyPatches/SunProxyEffectControllerPatches.cs b/NewHorizons/Patches/ProxyPatches/SunProxyEffectControllerPatches.cs new file mode 100644 index 00000000..24e22d07 --- /dev/null +++ b/NewHorizons/Patches/ProxyPatches/SunProxyEffectControllerPatches.cs @@ -0,0 +1,22 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.ProxyPatches +{ + [HarmonyPatch(typeof(SunProxyEffectController))] + public static class SunProxyEffectControllerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(SunProxyEffectController.UpdateScales))] + public static bool SunProxyEffectController_UpdateScales(SunProxyEffectController __instance) + { + return __instance != null && __instance._surface != null && __instance._fog != null && __instance._fogMaterial != null && __instance._solarFlareEmitter != null && __instance._atmosphere != null; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(SunProxyEffectController.UpdateAtmosphereRadii))] + public static bool SunProxyEffectController_UpdateAtmosphereRadii(SunProxyEffectController __instance) + { + return __instance != null && __instance.transform != null && __instance.transform.parent != null && __instance._atmosphereMaterial != null; + } + } +} diff --git a/NewHorizons/Patches/RemotePatches.cs b/NewHorizons/Patches/RemotePatches.cs deleted file mode 100644 index 40c6a5c2..00000000 --- a/NewHorizons/Patches/RemotePatches.cs +++ /dev/null @@ -1,153 +0,0 @@ -using HarmonyLib; -using NewHorizons.Components; -using NewHorizons.Handlers; -using UnityEngine; - -namespace NewHorizons.Patches -{ - [HarmonyPatch] - public class RemotePatches - { - [HarmonyPrefix] - [HarmonyPatch(typeof(NomaiRemoteCameraPlatform), nameof(NomaiRemoteCameraPlatform.IDToPlanetString))] - public static bool NomaiRemoteCameraPlatform_IDToPlanetString(NomaiRemoteCameraPlatform.ID id, out string __result) - { - switch (id) - { - case NomaiRemoteCameraPlatform.ID.None: - __result = "None"; - break; - case NomaiRemoteCameraPlatform.ID.SunStation: - __result = UITextLibrary.GetString(UITextType.LocationSS); - break; - case NomaiRemoteCameraPlatform.ID.HGT_TimeLoop: - __result = UITextLibrary.GetString(UITextType.LocationTT); - break; - case NomaiRemoteCameraPlatform.ID.TH_Mine: - __result = UITextLibrary.GetString(UITextType.LocationTH); - break; - case NomaiRemoteCameraPlatform.ID.THM_EyeLocator: - __result = UITextLibrary.GetString(UITextType.LocationTHMoon); - break; - case NomaiRemoteCameraPlatform.ID.BH_Observatory: - case NomaiRemoteCameraPlatform.ID.BH_GravityCannon: - case NomaiRemoteCameraPlatform.ID.BH_QuantumFragment: - case NomaiRemoteCameraPlatform.ID.BH_BlackHoleForge: - case NomaiRemoteCameraPlatform.ID.BH_NorthPole: - __result = UITextLibrary.GetString(UITextType.LocationBH); - break; - case NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland1: - case NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland2: - case NomaiRemoteCameraPlatform.ID.GD_StatueIsland: - __result = UITextLibrary.GetString(UITextType.LocationGD); - break; - case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonSunkenModule: - __result = UITextLibrary.GetString(UITextType.LocationOPC_Module3); - break; - case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonDamagedModule: - __result = UITextLibrary.GetString(UITextType.LocationOPC_Module2); - break; - case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonIntactModule: - __result = UITextLibrary.GetString(UITextType.LocationOPC_Module1); - break; - case NomaiRemoteCameraPlatform.ID.VM_Interior: - __result = UITextLibrary.GetString(UITextType.LocationBHMoon); - break; - case NomaiRemoteCameraPlatform.ID.HGT_TLE: - __result = UITextLibrary.GetString(UITextType.LocationCT); - break; - default: - __result = RemoteHandler.GetPlatformIDName(id); - break; - } - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(NomaiRemoteCameraStreaming), nameof(NomaiRemoteCameraStreaming.NomaiRemoteCameraPlatformIDToSceneName))] - public static bool NomaiRemoteCameraStreaming_NomaiRemoteCameraPlatformIDToSceneName(NomaiRemoteCameraPlatform.ID id, out string __result) - { - switch (id) - { - case NomaiRemoteCameraPlatform.ID.SunStation: - __result = "SolarSystem"; - break; - case NomaiRemoteCameraPlatform.ID.HGT_TimeLoop: - case NomaiRemoteCameraPlatform.ID.HGT_TLE: - __result = "HourglassTwins"; - break; - case NomaiRemoteCameraPlatform.ID.TH_Mine: - case NomaiRemoteCameraPlatform.ID.THM_EyeLocator: - __result = "TimberHearth"; - break; - case NomaiRemoteCameraPlatform.ID.BH_Observatory: - case NomaiRemoteCameraPlatform.ID.BH_GravityCannon: - case NomaiRemoteCameraPlatform.ID.BH_QuantumFragment: - case NomaiRemoteCameraPlatform.ID.BH_BlackHoleForge: - case NomaiRemoteCameraPlatform.ID.BH_NorthPole: - case NomaiRemoteCameraPlatform.ID.VM_Interior: - __result = "BrittleHollow"; - break; - case NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland1: - case NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland2: - case NomaiRemoteCameraPlatform.ID.GD_StatueIsland: - case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonSunkenModule: - case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonDamagedModule: - case NomaiRemoteCameraPlatform.ID.GD_ProbeCannonIntactModule: - __result = "GiantsDeep"; - break; - case NomaiRemoteCameraPlatform.ID.None: - __result = ""; - break; - default: - var key = RemoteHandler.GetPlatformIDKey(id); - var _ = key.IndexOf("_"); - switch ((_ == -1) ? key : key.Substring(0, _)) - { - case "SS": - __result = "SolarSystem"; - break; - case "HGT": - case "CT": - case "TT": - __result = "HourglassTwins"; - break; - case "CO": - __result = "Comet"; - break; - case "QM": - __result = "QuantumMoon"; - break; - case "GD": - __result = "GiantsDeep"; - break; - case "BH": - case "VM": - __result = "BrittleHollow"; - break; - case "TH": - case "THM": - __result = "TimberHearth"; - break; - case "DB": - __result = "DarkBramble"; - break; - case "WH": - __result = "WhiteHole"; - break; - case "RW": - __result = "RingWorld"; - break; - case "DW": - __result = "DreamWorld"; - break; - default: - __result = key; - break; - } - break; - } - return false; - } - } -} diff --git a/NewHorizons/Patches/ShapePatches.cs b/NewHorizons/Patches/ShapeManagerPatches.cs similarity index 85% rename from NewHorizons/Patches/ShapePatches.cs rename to NewHorizons/Patches/ShapeManagerPatches.cs index cf4d19d0..ea6a6190 100644 --- a/NewHorizons/Patches/ShapePatches.cs +++ b/NewHorizons/Patches/ShapeManagerPatches.cs @@ -3,11 +3,11 @@ using System.Collections.Generic; namespace NewHorizons.Patches { - [HarmonyPatch] - public class ShapePatches + [HarmonyPatch(typeof(ShapeManager))] + public class ShapeManagerPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(ShapeManager), nameof(ShapeManager.Initialize))] + [HarmonyPatch(nameof(ShapeManager.Initialize))] public static bool ShapeManager_Initialize() { ShapeManager._exists = true; diff --git a/NewHorizons/Patches/ShipLogPatches.cs b/NewHorizons/Patches/ShipLogPatches.cs deleted file mode 100644 index 8fe329c1..00000000 --- a/NewHorizons/Patches/ShipLogPatches.cs +++ /dev/null @@ -1,254 +0,0 @@ -using HarmonyLib; -using NewHorizons.OtherMods.AchievementsPlus; -using NewHorizons.Builder.ShipLog; -using NewHorizons.Handlers; -using NewHorizons.Utility; -using System; -using System.Collections.Generic; -using System.Linq; -using UnityEngine; -using Logger = NewHorizons.Utility.Logger; -using Object = UnityEngine.Object; -using NewHorizons.Components.ShipLog; - -namespace NewHorizons.Patches -{ - [HarmonyPatch] - public static class ShipLogPatches - { - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.Awake))] - public static void ShipLogManager_Awake_Prefix(ShipLogManager __instance) - { - if (Main.Instance.IsWarpingBackToEye) return; - - RumorModeBuilder.Init(); - ShipLogHandler.Init(); - - var currentStarSystem = Main.Instance.CurrentStarSystem; - - if (!Main.SystemDict.ContainsKey(currentStarSystem) || !Main.BodyDict.ContainsKey(currentStarSystem)) - { - currentStarSystem = Main.Instance.DefaultStarSystem; - } - - Logger.Log($"Beginning Ship Log Generation For: {currentStarSystem}"); - - if (currentStarSystem != "SolarSystem") - { - __instance._shipLogXmlAssets = new TextAsset[] { }; - foreach (ShipLogEntryLocation logEntryLocation in GameObject.FindObjectsOfType()) - { - logEntryLocation._initialized = true; - } - } - - var curiosities = Main.SystemDict[currentStarSystem].Config.curiosities; - if (curiosities != null) - { - RumorModeBuilder.AddCuriosityColors(curiosities); - } - - foreach (NewHorizonsBody body in Main.BodyDict[currentStarSystem]) - { - if (body.Config.ShipLog?.xmlFile != null) - { - RumorModeBuilder.AddBodyToShipLog(__instance, body); - } - } - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.Awake))] - public static void ShipLogManager_Awake_Postfix(ShipLogManager __instance) - { - if (Main.Instance.IsWarpingBackToEye) return; - - ShipLogHandler.CheckForModdedFacts(__instance); - RumorModeBuilder.GenerateEntryData(__instance); - for (var i = 0; i < __instance._entryList.Count; i++) - { - ShipLogEntry logEntry = __instance._entryList[i]; - RumorModeBuilder.UpdateEntryCuriosity(ref logEntry); - } - - Logger.Log($"Ship Log Generation Complete For: {Main.Instance.CurrentStarSystem}"); - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.IsFactRevealed))] - public static bool ShipLogManager_IsFactRevealed(ShipLogManager __instance, ref bool __result, string __0) - { - if (__instance._factDict != null && __instance._factDict.ContainsKey(__0)) - { - __result = __instance._factDict[__0].IsRevealed(); - } - else - { - __result = false; - } - - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.CheckForCompletionAchievement))] - public static bool ShipLogManager_CheckForCompletionAchievement(ShipLogManager __instance) - { - foreach (KeyValuePair keyValuePair in __instance._factDict) - { - if (!ShipLogHandler.IsModdedFact(keyValuePair.Key) && !keyValuePair.Value.IsRumor() && !keyValuePair.Value.IsRevealed() && !keyValuePair.Key.Equals("TH_VILLAGE_X3") && !keyValuePair.Key.Equals("GD_GABBRO_ISLAND_X1") && __instance.GetEntry(keyValuePair.Value.GetEntryID()).GetCuriosityName() != CuriosityName.InvisiblePlanet) - { - return false; - } - } - Achievements.Earn(Achievements.Type.STUDIOUS); - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.Start))] - public static bool ShipLogManager_Start(ShipLogManager __instance) - { - var initialReveal = Main.SystemDict[Main.Instance.CurrentStarSystem].Config.initialReveal ?? Array.Empty(); - foreach (string fact in initialReveal) - { - __instance.RevealFact(fact, false, false); - } - - if (Main.Instance.CurrentStarSystem == "SolarSystem") - { - return true; - } - else - { - EntryLocationBuilder.InitializeLocations(); - return false; - } - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(UIStyleManager), nameof(UIStyleManager.GetCuriosityColor))] - public static bool UIStyleManager_GetCuriosityColor(UIStyleManager __instance, CuriosityName __0, bool __1, ref Color __result) - { - if ((int)__0 < 7) - { - return true; - } - else - { - __result = RumorModeBuilder.GetCuriosityColor(__0, __1, __instance._neutralColor, __instance._neutralHighlight); - return false; - } - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(ShipLogMapMode), nameof(ShipLogMapMode.Initialize))] - public static void ShipLogMapMode_Initialize(ShipLogMapMode __instance) - { - GameObject panRoot = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH); - GameObject sunObject = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/Sun"); - ShipLogAstroObject[][] navMatrix = MapModeBuilder.ConstructMapMode(Main.Instance.CurrentStarSystem, panRoot, __instance._astroObjects, sunObject.layer); - if (navMatrix == null || navMatrix.Length <= 1) - { - Logger.LogWarning("Skipping Map Mode Generation."); - } - else - { - __instance._astroObjects = navMatrix; - __instance._startingAstroObjectID = navMatrix[1][0].GetID(); - if (Main.Instance.CurrentStarSystem != "SolarSystem") - { - List delete = panRoot.GetAllChildren().Where(g => g.name.Contains("_ShipLog") == false).ToList(); - foreach (GameObject gameObject in delete) - { - Object.Destroy(SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + gameObject.name)); - } - if (SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel") == null) - { - __instance._sandFunnel = __instance.gameObject.AddComponent(); - } - } - } - - Logger.Log("Map Mode Construction Complete"); - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipLogAstroObject), nameof(ShipLogAstroObject.GetName))] - public static bool ShipLogAstroObject_GetName(ShipLogAstroObject __instance, ref string __result) - { - if (ShipLogHandler.IsVanillaAstroID(__instance.GetID())) - { - return true; - } - else - { - __result = MapModeBuilder.GetAstroBodyShipLogName(__instance.GetID()); - return false; - } - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(ShipLogAstroObject), nameof(ShipLogAstroObject.UpdateState))] - public static void ShipLogAstroObject_UpdateState(ShipLogAstroObject __instance) - { - Transform detailsParent = __instance.transform.Find("Details"); - if (detailsParent != null) - { - foreach (GameObject child in detailsParent.gameObject.GetAllChildren()) - { - if (child.TryGetComponent(typeof(ShipLogDetail), out Component detail)) - { - (detail as ShipLogDetail)?.UpdateState(__instance._state); - } - } - } - - Transform lineObject = __instance.transform.Find("Line_ShipLog"); - if (lineObject != null) - { - ShipLogDetail lineDetail = lineObject.gameObject.GetComponent(); - lineDetail.UpdateState(__instance._state); - } - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipLogSandFunnel), nameof(ShipLogSandFunnel.UpdateState))] - public static bool ShipLogSandFunnel_UpdateState() - { - return Main.Instance.CurrentStarSystem == "SolarSystem"; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipLogSandFunnel), nameof(ShipLogSandFunnel.Awake))] - public static bool ShipLogSandFunnel_Awake() - { - return Main.Instance.CurrentStarSystem == "SolarSystem"; - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(ShipLogManager), nameof(ShipLogManager.RevealFact))] - public static void ShipLogManager_RevealFact(string __0) - { - StarChartHandler.OnRevealFact(__0); - - AchievementHandler.OnRevealFact(); - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipLogFact), nameof(ShipLogFact.GetText))] - public static bool ShipLogFact_GetText(ShipLogFact __instance, ref string __result) - { - if (ShipLogHandler.IsModdedFact(__instance.GetID())) - { - __result = TranslationHandler.GetTranslation(__instance._text, TranslationHandler.TextType.SHIPLOG); - return false; - } - else - { - return true; - } - } - } -} \ No newline at end of file diff --git a/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs b/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs new file mode 100644 index 00000000..ba3c0e33 --- /dev/null +++ b/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs @@ -0,0 +1,52 @@ +using HarmonyLib; +using NewHorizons.Builder.ShipLog; +using NewHorizons.Components.ShipLog; +using NewHorizons.Handlers; +using NewHorizons.Utility; +using UnityEngine; + +namespace NewHorizons.Patches.ShipLogPatches +{ + [HarmonyPatch(typeof(ShipLogAstroObject))] + public static class ShipLogAstroObjectPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogAstroObject.GetName))] + public static bool ShipLogAstroObject_GetName(ShipLogAstroObject __instance, ref string __result) + { + if (ShipLogHandler.IsVanillaAstroID(__instance.GetID())) + { + return true; + } + else + { + __result = MapModeBuilder.GetAstroBodyShipLogName(__instance.GetID()); + return false; + } + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(ShipLogAstroObject.UpdateState))] + public static void ShipLogAstroObject_UpdateState(ShipLogAstroObject __instance) + { + Transform detailsParent = __instance.transform.Find("Details"); + if (detailsParent != null) + { + foreach (GameObject child in detailsParent.gameObject.GetAllChildren()) + { + if (child.TryGetComponent(typeof(ShipLogDetail), out Component detail)) + { + (detail as ShipLogDetail)?.UpdateState(__instance._state); + } + } + } + + Transform lineObject = __instance.transform.Find("Line_ShipLog"); + if (lineObject != null) + { + ShipLogDetail lineDetail = lineObject.gameObject.GetComponent(); + lineDetail.UpdateState(__instance._state); + } + } + } +} diff --git a/NewHorizons/Patches/ShipLogPatches/ShipLogFactPatches.cs b/NewHorizons/Patches/ShipLogPatches/ShipLogFactPatches.cs new file mode 100644 index 00000000..39f7647c --- /dev/null +++ b/NewHorizons/Patches/ShipLogPatches/ShipLogFactPatches.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using NewHorizons.Handlers; + +namespace NewHorizons.Patches.ShipLogPatches +{ + [HarmonyPatch(typeof(ShipLogFact))] + public static class ShipLogFactPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogFact.GetText))] + public static bool ShipLogFact_GetText(ShipLogFact __instance, ref string __result) + { + if (ShipLogHandler.IsModdedFact(__instance.GetID())) + { + __result = TranslationHandler.GetTranslation(__instance._text, TranslationHandler.TextType.SHIPLOG); + return false; + } + else + { + return true; + } + } + } +} diff --git a/NewHorizons/Patches/ShipLogPatches/ShipLogManagerPatches.cs b/NewHorizons/Patches/ShipLogPatches/ShipLogManagerPatches.cs new file mode 100644 index 00000000..8276ccc7 --- /dev/null +++ b/NewHorizons/Patches/ShipLogPatches/ShipLogManagerPatches.cs @@ -0,0 +1,135 @@ +using HarmonyLib; +using NewHorizons.Builder.ShipLog; +using NewHorizons.Handlers; +using NewHorizons.OtherMods.AchievementsPlus; +using NewHorizons.Utility; +using System.Collections.Generic; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.Patches.ShipLogPatches +{ + [HarmonyPatch(typeof(ShipLogManager))] + public static class ShipLogManagerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogManager.Awake))] + public static void ShipLogManager_Awake_Prefix(ShipLogManager __instance) + { + if (Main.Instance.IsWarpingBackToEye) return; + + RumorModeBuilder.Init(); + ShipLogHandler.Init(); + + var currentStarSystem = Main.Instance.CurrentStarSystem; + + if (!Main.SystemDict.ContainsKey(currentStarSystem) || !Main.BodyDict.ContainsKey(currentStarSystem)) + { + currentStarSystem = Main.Instance.DefaultStarSystem; + } + + Logger.Log($"Beginning Ship Log Generation For: {currentStarSystem}"); + + if (currentStarSystem != "SolarSystem") + { + __instance._shipLogXmlAssets = new TextAsset[] { }; + foreach (ShipLogEntryLocation logEntryLocation in Object.FindObjectsOfType()) + { + logEntryLocation._initialized = true; + } + } + + var curiosities = Main.SystemDict[currentStarSystem].Config.curiosities; + if (curiosities != null) + { + RumorModeBuilder.AddCuriosityColors(curiosities); + } + + foreach (NewHorizonsBody body in Main.BodyDict[currentStarSystem]) + { + if (body.Config.ShipLog?.xmlFile != null) + { + RumorModeBuilder.AddBodyToShipLog(__instance, body); + } + } + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(ShipLogManager.Awake))] + public static void ShipLogManager_Awake_Postfix(ShipLogManager __instance) + { + if (Main.Instance.IsWarpingBackToEye) return; + + ShipLogHandler.CheckForModdedFacts(__instance); + RumorModeBuilder.GenerateEntryData(__instance); + for (var i = 0; i < __instance._entryList.Count; i++) + { + ShipLogEntry logEntry = __instance._entryList[i]; + RumorModeBuilder.UpdateEntryCuriosity(ref logEntry); + } + + Logger.Log($"Ship Log Generation Complete For: {Main.Instance.CurrentStarSystem}"); + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogManager.IsFactRevealed))] + public static bool ShipLogManager_IsFactRevealed(ShipLogManager __instance, ref bool __result, string __0) + { + if (__instance._factDict != null && __instance._factDict.ContainsKey(__0)) + { + __result = __instance._factDict[__0].IsRevealed(); + } + else + { + __result = false; + } + + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogManager.CheckForCompletionAchievement))] + public static bool ShipLogManager_CheckForCompletionAchievement(ShipLogManager __instance) + { + foreach (KeyValuePair keyValuePair in __instance._factDict) + { + if (!ShipLogHandler.IsModdedFact(keyValuePair.Key) && !keyValuePair.Value.IsRumor() && !keyValuePair.Value.IsRevealed() && !keyValuePair.Key.Equals("TH_VILLAGE_X3") && !keyValuePair.Key.Equals("GD_GABBRO_ISLAND_X1") && __instance.GetEntry(keyValuePair.Value.GetEntryID()).GetCuriosityName() != CuriosityName.InvisiblePlanet) + { + return false; + } + } + Achievements.Earn(Achievements.Type.STUDIOUS); + return false; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogManager.Start))] + public static bool ShipLogManager_Start(ShipLogManager __instance) + { + var initialReveal = Main.SystemDict[Main.Instance.CurrentStarSystem].Config.initialReveal ?? System.Array.Empty(); + foreach (string fact in initialReveal) + { + __instance.RevealFact(fact, false, false); + } + + if (Main.Instance.CurrentStarSystem == "SolarSystem") + { + return true; + } + else + { + EntryLocationBuilder.InitializeLocations(); + return false; + } + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(ShipLogManager.RevealFact))] + public static void ShipLogManager_RevealFact(string __0) + { + StarChartHandler.OnRevealFact(__0); + + AchievementHandler.OnRevealFact(); + } + } +} \ No newline at end of file diff --git a/NewHorizons/Patches/ShipLogPatches/ShipLogMapModePatches.cs b/NewHorizons/Patches/ShipLogPatches/ShipLogMapModePatches.cs new file mode 100644 index 00000000..b946c3c6 --- /dev/null +++ b/NewHorizons/Patches/ShipLogPatches/ShipLogMapModePatches.cs @@ -0,0 +1,47 @@ +using HarmonyLib; +using NewHorizons.Builder.ShipLog; +using NewHorizons.Handlers; +using NewHorizons.Utility; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + +namespace NewHorizons.Patches.ShipLogPatches +{ + [HarmonyPatch(typeof(ShipLogMapMode))] + public static class ShipLogMapModePatches + { + [HarmonyPostfix] + [HarmonyPatch(nameof(ShipLogMapMode.Initialize))] + public static void ShipLogMapMode_Initialize(ShipLogMapMode __instance) + { + GameObject panRoot = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH); + GameObject sunObject = SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/Sun"); + ShipLogAstroObject[][] navMatrix = MapModeBuilder.ConstructMapMode(Main.Instance.CurrentStarSystem, panRoot, __instance._astroObjects, sunObject.layer); + if (navMatrix == null || navMatrix.Length <= 1) + { + Logger.LogWarning("Skipping Map Mode Generation."); + } + else + { + __instance._astroObjects = navMatrix; + __instance._startingAstroObjectID = navMatrix[1][0].GetID(); + if (Main.Instance.CurrentStarSystem != "SolarSystem") + { + List delete = panRoot.GetAllChildren().Where(g => g.name.Contains("_ShipLog") == false).ToList(); + foreach (GameObject gameObject in delete) + { + Object.Destroy(SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + gameObject.name)); + } + if (SearchUtilities.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel") == null) + { + __instance._sandFunnel = __instance.gameObject.AddComponent(); + } + } + } + + Logger.Log("Map Mode Construction Complete"); + } + } +} diff --git a/NewHorizons/Patches/ShipLogPatches/ShipLogSandFunnelPatches.cs b/NewHorizons/Patches/ShipLogPatches/ShipLogSandFunnelPatches.cs new file mode 100644 index 00000000..1f56a152 --- /dev/null +++ b/NewHorizons/Patches/ShipLogPatches/ShipLogSandFunnelPatches.cs @@ -0,0 +1,22 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.ShipLogPatches +{ + [HarmonyPatch(typeof(ShipLogSandFunnel))] + public static class ShipLogSandFunnelPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogSandFunnel.UpdateState))] + public static bool ShipLogSandFunnel_UpdateState() + { + return Main.Instance.CurrentStarSystem == "SolarSystem"; + } + + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogSandFunnel.Awake))] + public static bool ShipLogSandFunnel_Awake() + { + return Main.Instance.CurrentStarSystem == "SolarSystem"; + } + } +} diff --git a/NewHorizons/Patches/ShipLogPatches/UIStyleManagerPatches.cs b/NewHorizons/Patches/ShipLogPatches/UIStyleManagerPatches.cs new file mode 100644 index 00000000..be44f036 --- /dev/null +++ b/NewHorizons/Patches/ShipLogPatches/UIStyleManagerPatches.cs @@ -0,0 +1,25 @@ +using HarmonyLib; +using NewHorizons.Builder.ShipLog; +using UnityEngine; + +namespace NewHorizons.Patches.ShipLogPatches +{ + [HarmonyPatch(typeof(UIStyleManager))] + public static class UIStyleManagerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(UIStyleManager.GetCuriosityColor))] + public static bool UIStyleManager_GetCuriosityColor(UIStyleManager __instance, CuriosityName __0, bool __1, ref Color __result) + { + if ((int)__0 < 7) + { + return true; + } + else + { + __result = RumorModeBuilder.GetCuriosityColor(__0, __1, __instance._neutralColor, __instance._neutralHighlight); + return false; + } + } + } +} diff --git a/NewHorizons/Patches/AudioSignalPatches.cs b/NewHorizons/Patches/SignalPatches/AudioSignalPatches.cs similarity index 66% rename from NewHorizons/Patches/AudioSignalPatches.cs rename to NewHorizons/Patches/SignalPatches/AudioSignalPatches.cs index 9811bc77..5470d5f2 100644 --- a/NewHorizons/Patches/AudioSignalPatches.cs +++ b/NewHorizons/Patches/SignalPatches/AudioSignalPatches.cs @@ -5,13 +5,13 @@ using NewHorizons.Handlers; using System; using UnityEngine; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.SignalPatches { - [HarmonyPatch] + [HarmonyPatch(typeof(AudioSignal))] public static class AudioSignalPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.SignalNameToString))] + [HarmonyPatch(nameof(AudioSignal.SignalNameToString))] public static bool AudioSignal_SignalNameToString(SignalName __0, ref string __result) { var customSignalName = SignalBuilder.GetCustomSignalName(__0); @@ -24,83 +24,45 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.FrequencyToIndex))] + [HarmonyPatch(nameof(AudioSignal.FrequencyToIndex))] public static bool AudioSignal_FrequencyToIndex(SignalFrequency __0, ref int __result) { - switch (__0) + __result = __0 switch { - case (SignalFrequency.Default): - __result = 0; - break; - case (SignalFrequency.Traveler): - __result = 1; - break; - case (SignalFrequency.Quantum): - __result = 2; - break; - case (SignalFrequency.EscapePod): - __result = 3; - break; - case (SignalFrequency.WarpCore): - __result = 4; - break; - case (SignalFrequency.HideAndSeek): - __result = 5; - break; - case (SignalFrequency.Radio): - __result = 6; - break; - case (SignalFrequency.Statue): - __result = 7; - break; - default: - // Frequencies are in powers of 2 - __result = (int)(Mathf.Log((float)__0) / Mathf.Log(2f)); - break; - } - + SignalFrequency.Default => 0, + SignalFrequency.Traveler => 1, + SignalFrequency.Quantum => 2, + SignalFrequency.EscapePod => 3, + SignalFrequency.WarpCore => 4, + SignalFrequency.HideAndSeek => 5, + SignalFrequency.Radio => 6, + SignalFrequency.Statue => 7, + _ => (int)(Mathf.Log((float)__0) / Mathf.Log(2f)),// Frequencies are in powers of 2 + }; return false; } [HarmonyPrefix] - [HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.IndexToFrequency))] + [HarmonyPatch(nameof(AudioSignal.IndexToFrequency))] public static bool AudioSignal_IndexToFrequency(int __0, ref SignalFrequency __result) { - switch (__0) + __result = __0 switch { - case 0: - __result = SignalFrequency.Default; - break; - case 1: - __result = SignalFrequency.Traveler; - break; - case 2: - __result = SignalFrequency.Quantum; - break; - case 3: - __result = SignalFrequency.EscapePod; - break; - case 4: - __result = SignalFrequency.WarpCore; - break; - case 5: - __result = SignalFrequency.HideAndSeek; - break; - case 6: - __result = SignalFrequency.Radio; - break; - case 7: - __result = SignalFrequency.Statue; - break; - default: - __result = (SignalFrequency)(Math.Pow(2, __0)); - break; - } + 0 => SignalFrequency.Default, + 1 => SignalFrequency.Traveler, + 2 => SignalFrequency.Quantum, + 3 => SignalFrequency.EscapePod, + 4 => SignalFrequency.WarpCore, + 5 => SignalFrequency.HideAndSeek, + 6 => SignalFrequency.Radio, + 7 => SignalFrequency.Statue, + _ => (SignalFrequency)Math.Pow(2, __0), + }; return false; } [HarmonyPrefix] - [HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.FrequencyToString))] + [HarmonyPatch(nameof(AudioSignal.FrequencyToString))] public static bool AudioSignal_FrequencyToString(SignalFrequency __0, ref string __result) { var customName = SignalBuilder.GetCustomFrequencyName(__0); @@ -114,13 +76,13 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(AudioSignal), nameof(AudioSignal.UpdateSignalStrength))] + [HarmonyPatch(nameof(AudioSignal.UpdateSignalStrength))] public static bool AudioSignal_UpdateSignalStrength(AudioSignal __instance, Signalscope scope, float distToClosestScopeObstruction) { if (!SignalBuilder.Initialized) return true; - var isCloaked = SignalBuilder.IsCloaked(__instance._name); - var isOnQuantumMoon = SignalBuilder.IsOnQuantumMoon(__instance._name); + var isCloaked = __instance._name.IsCloaked(); + var isOnQuantumMoon = __instance._name.IsOnQuantumMoon(); if (!isCloaked && !isOnQuantumMoon) return true; @@ -213,12 +175,5 @@ namespace NewHorizons.Patches return false; } - - [HarmonyPrefix] - [HarmonyPatch(typeof(TravelerAudioManager), nameof(TravelerAudioManager.Update))] - public static void TravelerAudioManager_Update(TravelerAudioManager __instance) - { - __instance._signals.RemoveAll(signal => signal == null || signal.gameObject == null || signal._owAudioSource == null || signal._owAudioSource._audioSource == null); - } } } diff --git a/NewHorizons/Patches/SignalScopePatches.cs b/NewHorizons/Patches/SignalPatches/SignalscopePatches.cs similarity index 59% rename from NewHorizons/Patches/SignalScopePatches.cs rename to NewHorizons/Patches/SignalPatches/SignalscopePatches.cs index 6f1cdb2d..b6e241a4 100644 --- a/NewHorizons/Patches/SignalScopePatches.cs +++ b/NewHorizons/Patches/SignalPatches/SignalscopePatches.cs @@ -1,33 +1,34 @@ -using HarmonyLib; +using HarmonyLib; using NewHorizons.Builder.Props; -namespace NewHorizons.Patches + +namespace NewHorizons.Patches.SignalPatches { - [HarmonyPatch] + [HarmonyPatch(typeof(Signalscope))] public static class SignalScopePatches { [HarmonyPrefix] - [HarmonyPatch(typeof(Signalscope), nameof(Signalscope.Awake))] - public static bool Signalscope_Awake(Signalscope __instance) + [HarmonyPatch(nameof(Signalscope.Awake))] + public static void Signalscope_Awake(Signalscope __instance) { __instance._strongestSignals = new AudioSignal[8]; - return true; } [HarmonyPrefix] - [HarmonyPatch(typeof(Signalscope), nameof(Signalscope.SwitchFrequencyFilter))] + [HarmonyPatch(nameof(Signalscope.SwitchFrequencyFilter))] public static bool Signalscope_SwitchFrequencyFilter(Signalscope __instance, int __0) { var increment = __0; var count = SignalBuilder.NumberOfFrequencies; __instance._frequencyFilterIndex += increment; - __instance._frequencyFilterIndex = ((__instance._frequencyFilterIndex >= count) ? 0 : __instance._frequencyFilterIndex); - __instance._frequencyFilterIndex = ((__instance._frequencyFilterIndex < 0) ? count - 1 : __instance._frequencyFilterIndex); + __instance._frequencyFilterIndex = __instance._frequencyFilterIndex >= count ? 0 : __instance._frequencyFilterIndex; + __instance._frequencyFilterIndex = __instance._frequencyFilterIndex < 0 ? count - 1 : __instance._frequencyFilterIndex; SignalFrequency signalFrequency = AudioSignal.IndexToFrequency(__instance._frequencyFilterIndex); if (!PlayerData.KnowsFrequency(signalFrequency) && (!__instance._isUnknownFreqNearby || __instance._unknownFrequency != signalFrequency)) { __instance.SwitchFrequencyFilter(increment); } + return false; } } diff --git a/NewHorizons/Patches/SignalPatches/TravelerAudioManagerPatches.cs b/NewHorizons/Patches/SignalPatches/TravelerAudioManagerPatches.cs new file mode 100644 index 00000000..af33b3f5 --- /dev/null +++ b/NewHorizons/Patches/SignalPatches/TravelerAudioManagerPatches.cs @@ -0,0 +1,15 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.SignalPatches +{ + [HarmonyPatch(typeof(TravelerAudioManager))] + public static class TravelerAudioManagerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(TravelerAudioManager.Update))] + public static void TravelerAudioManager_Update(TravelerAudioManager __instance) + { + __instance._signals.RemoveAll(signal => signal == null || signal.gameObject == null || signal._owAudioSource == null || signal._owAudioSource._audioSource == null); + } + } +} diff --git a/NewHorizons/Patches/SingularityPatches.cs b/NewHorizons/Patches/SingularityPatches.cs deleted file mode 100644 index e172c9e1..00000000 --- a/NewHorizons/Patches/SingularityPatches.cs +++ /dev/null @@ -1,51 +0,0 @@ -using HarmonyLib; -using System; -using System.Collections.Generic; -namespace NewHorizons.Patches -{ - [HarmonyPatch] - public static class SingularityPatches - { - // For our custom black holes that don't link to anything - [HarmonyPrefix] - [HarmonyPatch(typeof(BlackHoleVolume), nameof(BlackHoleVolume.Start))] - public static bool BlackHoleVolume_Start(BlackHoleVolume __instance) - { - return __instance._whiteHole == null; - } - - // To fix custom white holes - [HarmonyPrefix] - [HarmonyPatch(typeof(WhiteHoleVolume), nameof(WhiteHoleVolume.Awake))] - public static bool WhiteHoleVolume_Awake(WhiteHoleVolume __instance) - { - __instance._growQueue = new List(8); - __instance._growQueueLocationData = new List(8); - __instance._ejectedBodyList = new List(64); - try - { - __instance._whiteHoleBody = __instance.gameObject.GetAttachedOWRigidbody(false); - __instance._whiteHoleProxyShadowSuperGroup = __instance._whiteHoleBody.GetComponentInChildren(); - __instance._fluidVolume = __instance.gameObject.GetRequiredComponent(); - } - catch (Exception) { } - return false; - } - - // This is to stop the game throwing too many errors if the probe is destroyed by a blackhole - [HarmonyPrefix] - [HarmonyPatch(typeof(SurveyorProbe), nameof(SurveyorProbe.IsLaunched))] - public static bool SurveyorProbe_IsLaunched(SurveyorProbe __instance, ref bool __result) - { - try - { - __result = __instance.gameObject.activeSelf; - } - catch (Exception) - { - __result = true; - } - return false; - } - } -} diff --git a/NewHorizons/Patches/StreamingPatches.cs b/NewHorizons/Patches/StreamingPatches.cs deleted file mode 100644 index 85acd0ab..00000000 --- a/NewHorizons/Patches/StreamingPatches.cs +++ /dev/null @@ -1,26 +0,0 @@ -using HarmonyLib; -using NewHorizons.Handlers; -using OWML.Logging; - -namespace NewHorizons.Patches -{ - [HarmonyPatch] - public static class StreamingPatches - { - [HarmonyPrefix] - [HarmonyPatch(typeof(StreamingManager), nameof(StreamingManager.UnloadStreamingAssets))] - public static bool StreamingManager_UnloadStreamingAssets(string assetBundleName) - { - // Only let it unload stuff that isn't being used - return !StreamingHandler.IsBundleInUse(assetBundleName); - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(UnityLogger), "OnLogMessageReceived")] - public static bool UnityLogger_OnLogMessageReceived(string message) - { - // Filter out goofy error that doesn't actually break anything - return !message.EndsWith(") is out of bounds (size=0)"); - } - } -} diff --git a/NewHorizons/Patches/StreamingPatches/NomaiRemoteCameraStreamingPatches.cs b/NewHorizons/Patches/StreamingPatches/NomaiRemoteCameraStreamingPatches.cs new file mode 100644 index 00000000..e520a99f --- /dev/null +++ b/NewHorizons/Patches/StreamingPatches/NomaiRemoteCameraStreamingPatches.cs @@ -0,0 +1,47 @@ +using HarmonyLib; +using NewHorizons.Handlers; + +namespace NewHorizons.Patches.StreamingPatches +{ + [HarmonyPatch(typeof(NomaiRemoteCameraStreaming))] + public class NomaiRemoteCameraStreamingPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(NomaiRemoteCameraStreaming.NomaiRemoteCameraPlatformIDToSceneName))] + public static bool NomaiRemoteCameraStreaming_NomaiRemoteCameraPlatformIDToSceneName(NomaiRemoteCameraPlatform.ID id, out string __result) + { + __result = id switch + { + NomaiRemoteCameraPlatform.ID.SunStation => "SolarSystem", + NomaiRemoteCameraPlatform.ID.HGT_TimeLoop or NomaiRemoteCameraPlatform.ID.HGT_TLE => "HourglassTwins", + NomaiRemoteCameraPlatform.ID.TH_Mine or NomaiRemoteCameraPlatform.ID.THM_EyeLocator => "TimberHearth", + NomaiRemoteCameraPlatform.ID.BH_Observatory or NomaiRemoteCameraPlatform.ID.BH_GravityCannon or NomaiRemoteCameraPlatform.ID.BH_QuantumFragment or NomaiRemoteCameraPlatform.ID.BH_BlackHoleForge or NomaiRemoteCameraPlatform.ID.BH_NorthPole or NomaiRemoteCameraPlatform.ID.VM_Interior => "BrittleHollow", + NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland1 or NomaiRemoteCameraPlatform.ID.GD_ConstructionYardIsland2 or NomaiRemoteCameraPlatform.ID.GD_StatueIsland or NomaiRemoteCameraPlatform.ID.GD_ProbeCannonSunkenModule or NomaiRemoteCameraPlatform.ID.GD_ProbeCannonDamagedModule or NomaiRemoteCameraPlatform.ID.GD_ProbeCannonIntactModule => "GiantsDeep", + NomaiRemoteCameraPlatform.ID.None => "", + _ => PlatformKeyToSceneName(id), + }; + return false; + } + + private static string PlatformKeyToSceneName(NomaiRemoteCameraPlatform.ID id) + { + var key = RemoteHandler.GetPlatformIDKey(id); + var _ = key.IndexOf("_"); + return (_ == -1 ? key : key.Substring(0, _)) switch + { + "SS" => "SolarSystem", + "HGT" or "CT" or "TT" => "HourglassTwins", + "CO" => "Comet", + "QM" => "QuantumMoon", + "GD" => "GiantsDeep", + "BH" or "VM" => "BrittleHollow", + "TH" or "THM" => "TimberHearth", + "DB" => "DarkBramble", + "WH" => "WhiteHole", + "RW" => "RingWorld", + "DW" => "DreamWorld", + _ => key, + }; + } + } +} diff --git a/NewHorizons/Patches/StreamingPatches/StreamingManagerPatches.cs b/NewHorizons/Patches/StreamingPatches/StreamingManagerPatches.cs new file mode 100644 index 00000000..db34067c --- /dev/null +++ b/NewHorizons/Patches/StreamingPatches/StreamingManagerPatches.cs @@ -0,0 +1,18 @@ +using HarmonyLib; +using NewHorizons.Handlers; +using OWML.Logging; + +namespace NewHorizons.Patches.StreamingPatches +{ + [HarmonyPatch(typeof(StreamingManager))] + public static class StreamingManagerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(StreamingManager.UnloadStreamingAssets))] + public static bool StreamingManager_UnloadStreamingAssets(string assetBundleName) + { + // Only let it unload stuff that isn't being used + return !StreamingHandler.IsBundleInUse(assetBundleName); + } + } +} diff --git a/NewHorizons/Patches/StreamingPatches/UnityLoggerPatches.cs b/NewHorizons/Patches/StreamingPatches/UnityLoggerPatches.cs new file mode 100644 index 00000000..ac772441 --- /dev/null +++ b/NewHorizons/Patches/StreamingPatches/UnityLoggerPatches.cs @@ -0,0 +1,17 @@ +using HarmonyLib; +using OWML.Logging; + +namespace NewHorizons.Patches.StreamingPatches +{ + [HarmonyPatch(typeof(UnityLogger))] + public static class UnityLoggerPatches + { + [HarmonyPrefix] + [HarmonyPatch("OnLogMessageReceived")] + public static bool UnityLogger_OnLogMessageReceived(string message) + { + // Filter out goofy error that doesn't actually break anything + return !message.EndsWith(") is out of bounds (size=0)"); + } + } +} diff --git a/NewHorizons/Patches/SunPatches.cs b/NewHorizons/Patches/SunPatches.cs deleted file mode 100644 index 447028bd..00000000 --- a/NewHorizons/Patches/SunPatches.cs +++ /dev/null @@ -1,65 +0,0 @@ -using HarmonyLib; -using UnityEngine; -namespace NewHorizons.Patches -{ - [HarmonyPatch] - public static class SunPatches - { - [HarmonyPrefix] - [HarmonyPatch(typeof(SunLightParamUpdater), nameof(SunLightParamUpdater.LateUpdate))] - public static bool SunLightParamUpdater_LateUpdate(SunLightParamUpdater __instance) - { - if (__instance.sunLight) - { - Vector3 position = __instance.transform.position; - float w = 2000f; - if (__instance._sunController != null) - { - w = (__instance._sunController.HasSupernovaStarted() ? __instance._sunController.GetSupernovaRadius() : __instance._sunController.GetSurfaceRadius()); - } - float range = __instance.sunLight.range; - Color color = (__instance._sunLightController != null) ? __instance._sunLightController.sunColor : __instance.sunLight.color; - float w2 = (__instance._sunLightController != null) ? __instance._sunLightController.sunIntensity : __instance.sunLight.intensity; - Shader.SetGlobalVector(__instance._propID_SunPosition, new Vector4(position.x, position.y, position.z, w)); - Shader.SetGlobalVector(__instance._propID_OWSunPositionRange, new Vector4(position.x, position.y, position.z, 1f / (range * range))); - Shader.SetGlobalVector(__instance._propID_OWSunColorIntensity, new Vector4(color.r, color.g, color.b, w2)); - } - - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(SunSurfaceAudioController), nameof(SunSurfaceAudioController.Update))] - public static bool SunSurfaceAudioController_Update(SunSurfaceAudioController __instance) - { - if (__instance._sunController != null) return true; - - var surfaceRadius = __instance.transform.parent.parent.localScale.magnitude; - float value = Mathf.Max(0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, __instance.transform.position) - surfaceRadius); - float num = Mathf.InverseLerp(1600f, 100f, value); - __instance._audioSource.SetLocalVolume(num * num * __instance._fade); - return false; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(SunProxyEffectController), nameof(SunProxyEffectController.UpdateScales))] - public static bool SunProxyEffectController_UpdateScales(SunProxyEffectController __instance) - { - return __instance != null && __instance._surface != null && __instance._fog != null && __instance._fogMaterial != null && __instance._solarFlareEmitter != null && __instance._atmosphere != null; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(SunProxyEffectController), nameof(SunProxyEffectController.UpdateAtmosphereRadii))] - public static bool SunProxyEffectController_UpdateAtmosphereRadii(SunProxyEffectController __instance) - { - return __instance != null && __instance.transform != null && __instance.transform.parent != null && __instance._atmosphereMaterial != null; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(VanishVolume), nameof(VanishVolume.Shrink))] - public static bool VanishVolume_Shrink(VanishVolume __instance, OWRigidbody bodyToShrink) - { - return __instance != null && __instance.transform != null && __instance._shrinkingBodies != null && __instance._shrinkingBodyLocationData != null && bodyToShrink != null; - } - } -} diff --git a/NewHorizons/Patches/SunPatches/SunControllerPatches.cs b/NewHorizons/Patches/SunPatches/SunControllerPatches.cs new file mode 100644 index 00000000..222b87f0 --- /dev/null +++ b/NewHorizons/Patches/SunPatches/SunControllerPatches.cs @@ -0,0 +1,18 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.SunPatches +{ + [HarmonyPatch(typeof(SunController))] + public static class SunControllerPatches + { + /// + /// Disables sun logic if no time loop + /// + [HarmonyPrefix] + [HarmonyPatch(nameof(SunController.Update))] + [HarmonyPatch(nameof(SunController.UpdateScale))] + [HarmonyPatch(nameof(SunController.OnTriggerSupernova))] + public static bool SunController_DisableWithoutTimeLoop(SunController __instance) => Main.Instance.TimeLoopEnabled && __instance.isActiveAndEnabled; + + } +} diff --git a/NewHorizons/Patches/SunPatches/SunLightParamUpdaterPatches.cs b/NewHorizons/Patches/SunPatches/SunLightParamUpdaterPatches.cs new file mode 100644 index 00000000..45d68e3e --- /dev/null +++ b/NewHorizons/Patches/SunPatches/SunLightParamUpdaterPatches.cs @@ -0,0 +1,31 @@ +using HarmonyLib; +using UnityEngine; +namespace NewHorizons.Patches.SunPatches +{ + [HarmonyPatch(typeof(SunLightParamUpdater))] + public static class SunLightParamUpdaterPatches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(SunLightParamUpdater), nameof(SunLightParamUpdater.LateUpdate))] + public static bool SunLightParamUpdater_LateUpdate(SunLightParamUpdater __instance) + { + if (__instance.sunLight) + { + Vector3 position = __instance.transform.position; + float w = 2000f; + if (__instance._sunController != null) + { + w = __instance._sunController.HasSupernovaStarted() ? __instance._sunController.GetSupernovaRadius() : __instance._sunController.GetSurfaceRadius(); + } + float range = __instance.sunLight.range; + Color color = __instance._sunLightController != null ? __instance._sunLightController.sunColor : __instance.sunLight.color; + float w2 = __instance._sunLightController != null ? __instance._sunLightController.sunIntensity : __instance.sunLight.intensity; + Shader.SetGlobalVector(__instance._propID_SunPosition, new Vector4(position.x, position.y, position.z, w)); + Shader.SetGlobalVector(__instance._propID_OWSunPositionRange, new Vector4(position.x, position.y, position.z, 1f / (range * range))); + Shader.SetGlobalVector(__instance._propID_OWSunColorIntensity, new Vector4(color.r, color.g, color.b, w2)); + } + + return false; + } + } +} diff --git a/NewHorizons/Patches/SunPatches/SunSurfaceAudioControllerPatches.cs b/NewHorizons/Patches/SunPatches/SunSurfaceAudioControllerPatches.cs new file mode 100644 index 00000000..d4040f3f --- /dev/null +++ b/NewHorizons/Patches/SunPatches/SunSurfaceAudioControllerPatches.cs @@ -0,0 +1,22 @@ +using HarmonyLib; +using UnityEngine; + +namespace NewHorizons.Patches.SunPatches +{ + [HarmonyPatch(typeof(SunSurfaceAudioController))] + public static class SunSurfaceAudioControllerPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(SunSurfaceAudioController.Update))] + public static bool SunSurfaceAudioController_Update(SunSurfaceAudioController __instance) + { + if (__instance._sunController != null) return true; + + var surfaceRadius = __instance.transform.parent.parent.localScale.magnitude; + float value = Mathf.Max(0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, __instance.transform.position) - surfaceRadius); + float num = Mathf.InverseLerp(1600f, 100f, value); + __instance._audioSource.SetLocalVolume(num * num * __instance._fade); + return false; + } + } +} diff --git a/NewHorizons/Patches/TimeLoopPatches.cs b/NewHorizons/Patches/TimeLoopPatches.cs index d627d2b4..5628fa15 100644 --- a/NewHorizons/Patches/TimeLoopPatches.cs +++ b/NewHorizons/Patches/TimeLoopPatches.cs @@ -6,52 +6,13 @@ namespace NewHorizons.Patches public static class TimeLoopPatches { /// - /// Disables starfield updates + /// Disable certain behaviours without timeloop /// [HarmonyPrefix] [HarmonyPatch(typeof(StarfieldController), nameof(StarfieldController.Update))] - public static bool StarfieldController_Update() => Main.Instance.TimeLoopEnabled; - - /// - /// Disables interloper destruction - /// - [HarmonyPrefix] [HarmonyPatch(typeof(TempCometCollisionFix), nameof(TempCometCollisionFix.Update))] - public static bool TempCometCollisionFix_Update() => Main.Instance.TimeLoopEnabled; - - /// - /// Disables sun logic - /// - [HarmonyPrefix] - [HarmonyPatch(typeof(SunController), nameof(SunController.Update))] - public static bool SunController_Update(SunController __instance) => Main.Instance.TimeLoopEnabled && __instance.isActiveAndEnabled; - - /// - /// Disables sun expansion - /// - [HarmonyPrefix] - [HarmonyPatch(typeof(SunController), nameof(SunController.UpdateScale))] - public static bool SunController_UpdateScale(SunController __instance) => Main.Instance.TimeLoopEnabled && __instance.isActiveAndEnabled; - - /// - /// Disables sun collapse SFX - /// - [HarmonyPrefix] - [HarmonyPatch(typeof(SunController), nameof(SunController.OnTriggerSupernova))] - public static bool SunController_OnTriggerSupernova(SunController __instance) => Main.Instance.TimeLoopEnabled && __instance.isActiveAndEnabled; - - /// - /// Disables end times music - /// - [HarmonyPrefix] [HarmonyPatch(typeof(GlobalMusicController), nameof(GlobalMusicController.UpdateEndTimesMusic))] - public static bool GlobalMusicController_UpdateEndTimesMusic() => Main.Instance.TimeLoopEnabled; - - /// - /// Disables supernova trigger - /// - [HarmonyPrefix] [HarmonyPatch(typeof(TimeLoop), nameof(TimeLoop.Update))] - public static bool TimeLoop_Update() => Main.Instance.TimeLoopEnabled; + public static bool DisableWithoutTimeLoop() => Main.Instance.TimeLoopEnabled; } } diff --git a/NewHorizons/Patches/ToolPatches/ProbeLauncherPatches.cs b/NewHorizons/Patches/ToolPatches/ProbeLauncherPatches.cs new file mode 100644 index 00000000..a2e38c28 --- /dev/null +++ b/NewHorizons/Patches/ToolPatches/ProbeLauncherPatches.cs @@ -0,0 +1,15 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.ToolPatches +{ + [HarmonyPatch(typeof(ProbeLauncher))] + public static class ProbeLauncherPatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(ProbeLauncher.UpdateOrbitalLaunchValues))] + public static bool ProbeLauncher_UpdateOrbitalLaunchValues(ProbeLauncher __instance) + { + return Locator.GetPlayerRulesetDetector()?.GetPlanetoidRuleset()?.GetGravityVolume() != null; + } + } +} diff --git a/NewHorizons/Patches/ToolPatches/SurveyorProbePatches.cs b/NewHorizons/Patches/ToolPatches/SurveyorProbePatches.cs new file mode 100644 index 00000000..08cd5d15 --- /dev/null +++ b/NewHorizons/Patches/ToolPatches/SurveyorProbePatches.cs @@ -0,0 +1,18 @@ +using HarmonyLib; +using System; + +namespace NewHorizons.Patches.ToolPatches +{ + [HarmonyPatch(typeof(SurveyorProbe))] + public static class SurveyorProbePatches + { + // This is to stop the game throwing too many errors if the probe is destroyed by a blackhole + [HarmonyPrefix] + [HarmonyPatch(nameof(SurveyorProbe.IsLaunched))] + public static bool SurveyorProbe_IsLaunched(SurveyorProbe __instance, ref bool __result) + { + __result = __instance?.gameObject?.activeSelf ?? false; + return false; + } + } +} diff --git a/NewHorizons/Patches/ToolModeSwapperPatches.cs b/NewHorizons/Patches/ToolPatches/ToolModeSwapperPatches.cs similarity index 73% rename from NewHorizons/Patches/ToolModeSwapperPatches.cs rename to NewHorizons/Patches/ToolPatches/ToolModeSwapperPatches.cs index ec5e4a93..63986a2a 100644 --- a/NewHorizons/Patches/ToolModeSwapperPatches.cs +++ b/NewHorizons/Patches/ToolPatches/ToolModeSwapperPatches.cs @@ -1,16 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using HarmonyLib; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.ToolPatches { - [HarmonyPatch] + [HarmonyPatch(typeof(ToolModeSwapper))] public static class ToolModeSwapperPatches { - // Patches ToolModeSwapper.EquipToolMode(ToolMode mode) to deny swaps if you're holding a vision torch. // This is critical for preventing swapping to the scout launcher (causes memory slides to fail) but it // just doesn't look right when you switch to other stuff (eg the signalscope), so I'm disabling swapping tools entirely @@ -19,15 +13,15 @@ namespace NewHorizons.Patches // to include a check for "is holding vision torch", but I'm not copy/pasting an entire function, no sir // if (((_currentToolMode == ToolMode.None || _currentToolMode == ToolMode.Item) && Locator.GetPlayerSuit().IsWearingSuit(includeTrainingSuit: false)) || ((_currentToolMode == ToolMode.None || _currentToolMode == ToolMode.SignalScope) && OWInput.IsInputMode(InputMode.ShipCockpit))) [HarmonyPrefix] - [HarmonyPatch(typeof(ToolModeSwapper), nameof(ToolModeSwapper.EquipToolMode))] + [HarmonyPatch(nameof(ToolModeSwapper.EquipToolMode))] public static bool ToolModeSwapper_EquipToolMode(ToolModeSwapper __instance, ToolMode mode) { var isHoldingVisionTorch = __instance.GetItemCarryTool()?.GetHeldItemType() == ItemType.VisionTorch; - var swappingToRestrictedTool = - mode == ToolMode.Probe || - mode == ToolMode.SignalScope || + var swappingToRestrictedTool = + mode == ToolMode.Probe || + mode == ToolMode.SignalScope || mode == ToolMode.Translator; - var isInShip = UnityEngine.GameObject.FindObjectOfType()?._playerAtFlightConsole ?? false; + var isInShip = UnityEngine.Object.FindObjectOfType()?._playerAtFlightConsole ?? false; if (!isInShip && isHoldingVisionTorch && swappingToRestrictedTool) return false; diff --git a/NewHorizons/Patches/VisionTorchPatches.cs b/NewHorizons/Patches/VisionTorchPatches.cs deleted file mode 100644 index 9a0b7b56..00000000 --- a/NewHorizons/Patches/VisionTorchPatches.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using HarmonyLib; -using NewHorizons.Builder.Props; -using UnityEngine; - -namespace NewHorizons.Patches -{ - - [HarmonyPatch] - public static class MindProjectorTriggerPatches - { - [HarmonyPrefix] - [HarmonyPatch(typeof(MindProjectorTrigger), nameof(MindProjectorTrigger.OnTriggerVolumeEntry))] - public static bool MindProjectorTrigger_OnTriggerVolumeEntry(MindProjectorTrigger __instance, GameObject hitObj) - { - var t = hitObj.GetComponent(); - if (t != null) //(hitObj.CompareTag("PrisonerDetector")) - { - __instance._mindProjector.OnProjectionStart += t.onSlidesStart; - __instance._mindProjector.OnProjectionComplete += t.onSlidesComplete; - __instance._mindProjector.SetMindSlideCollection(t.slideCollection); - - __instance.OnBeamStartHitPrisoner.Invoke(); - __instance._mindProjector.Play(reset: true); - __instance._mindProjector.OnProjectionStart += __instance.OnProjectionStart; - __instance._mindProjector.OnProjectionComplete += __instance.OnProjectionComplete; - - Locator.GetPlayerTransform().GetComponent().LockOn(hitObj.transform, Vector3.zero); - __instance._playerLockedOn = true; - return false; - } - - return true; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(MindProjectorTrigger), nameof(MindProjectorTrigger.OnTriggerVolumeExit))] - private static bool MindProjectorTrigger_OnTriggerVolumeExit(MindProjectorTrigger __instance, GameObject hitObj) - { - var t = hitObj.GetComponent(); - if (t != null) //(hitObj.CompareTag("PrisonerDetector")) - { - __instance._mindProjector.OnProjectionStart -= t.onSlidesStart; - __instance._mindProjector.OnProjectionComplete -= t.onSlidesComplete; - } - return true; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(MindSlideProjector), nameof(MindSlideProjector.SetMindSlideCollection))] - private static bool MindSlideProjector_SetMindSlideCollection(MindSlideProjector __instance, MindSlideCollection mindSlideCollection) - { - if (mindSlideCollection == null) return false; - - if (__instance._mindSlideCollection == mindSlideCollection) return false; - - // Original method didn't check if old _slideCollectionItem was null. - if (__instance._slideCollectionItem != null) - { - __instance._slideCollectionItem.onSlideTextureUpdated -= __instance.OnSlideTextureUpdated; - __instance._slideCollectionItem.onPlayBeatAudio -= __instance.OnPlayBeatAudio; - } - - __instance._mindSlideCollection = mindSlideCollection; - __instance._defaultSlideDuration = mindSlideCollection.defaultSlideDuration; - - __instance._slideCollectionItem = mindSlideCollection.slideCollectionContainer; - __instance._slideCollectionItem.onSlideTextureUpdated += __instance.OnSlideTextureUpdated; - __instance._slideCollectionItem.onPlayBeatAudio += __instance.OnPlayBeatAudio; - __instance._slideCollectionItem.Initialize(); - __instance._slideCollectionItem.enabled = false; - - return false; - } - } - - [HarmonyPatch] - public static class VisionTorchItemPatches - { - // This is some dark magic - // this creates a method called base_DropItem that basically just calls OWItem.PickUpItem whenever it (VisionTorchItemPatches.base_PickUpItem) is called - [HarmonyReversePatch] - [HarmonyPatch(typeof(OWItem), nameof(OWItem.DropItem))] - private static void base_DropItem(OWItem instance, Vector3 position, Vector3 normal, Transform parent, Sector sector, IItemDropTarget customDropTarget) { } - - - // Make the vision torch droppable. In the base game you can only drop it if you're in the dream world. - [HarmonyPrefix] - [HarmonyPatch(typeof(VisionTorchItem), nameof(VisionTorchItem.DropItem))] - public static bool VisionTorchItem_DropItem(VisionTorchItem __instance, Vector3 position, Vector3 normal, Transform parent, Sector sector, IItemDropTarget customDropTarget) - { - if (!Locator.GetDreamWorldController().IsInDream()) - { - base_DropItem(__instance, position, normal, parent, sector, customDropTarget); - } - - if (__instance._wasProjecting) __instance._mindProjectorTrigger.SetProjectorActive(false); - - __instance.gameObject.GetComponent().enabled = true; - - return true; - } - } -} diff --git a/NewHorizons/Patches/VolumePatches/BlackHoleVolumePatches.cs b/NewHorizons/Patches/VolumePatches/BlackHoleVolumePatches.cs new file mode 100644 index 00000000..65cd95b7 --- /dev/null +++ b/NewHorizons/Patches/VolumePatches/BlackHoleVolumePatches.cs @@ -0,0 +1,15 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.VolumePatches +{ + [HarmonyPatch(typeof(BlackHoleVolume))] + public static class BlackHoleVolumePatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(BlackHoleVolume.Start))] + public static bool BlackHoleVolume_Start(BlackHoleVolume __instance) + { + return __instance._whiteHole == null; + } + } +} diff --git a/NewHorizons/Patches/DestructionVolumePatches.cs b/NewHorizons/Patches/VolumePatches/DestructionVolumePatches.cs similarity index 95% rename from NewHorizons/Patches/DestructionVolumePatches.cs rename to NewHorizons/Patches/VolumePatches/DestructionVolumePatches.cs index e29e3d02..45564b50 100644 --- a/NewHorizons/Patches/DestructionVolumePatches.cs +++ b/NewHorizons/Patches/VolumePatches/DestructionVolumePatches.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.VolumePatches { [HarmonyPatch] public static class DestructionVolumePatches diff --git a/NewHorizons/Patches/VolumePatches/FluidVolumePatches.cs b/NewHorizons/Patches/VolumePatches/FluidVolumePatches.cs new file mode 100644 index 00000000..a85acc0f --- /dev/null +++ b/NewHorizons/Patches/VolumePatches/FluidVolumePatches.cs @@ -0,0 +1,20 @@ +using HarmonyLib; +using UnityEngine; + +namespace NewHorizons.Patches.VolumePatches +{ + [HarmonyPatch(typeof(FluidVolume))] + public static class FluidVolumePatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(FluidVolume.GetDepthAtPosition))] + public static bool FluidVolume_GetDepthAtPosition(FluidVolume __instance, ref float __result, Vector3 worldPosition) + { + if (__instance is not RadialFluidVolume radialFluidVolume) return true; + + Vector3 vector = radialFluidVolume.transform.InverseTransformPoint(worldPosition); + __result = Mathf.Sqrt(vector.x * vector.x + vector.z * vector.z + vector.y * vector.y) - radialFluidVolume._radius; + return false; + } + } +} diff --git a/NewHorizons/Patches/BramblePatches.cs b/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs similarity index 80% rename from NewHorizons/Patches/BramblePatches.cs rename to NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs index fcec7f30..21283d6e 100644 --- a/NewHorizons/Patches/BramblePatches.cs +++ b/NewHorizons/Patches/VolumePatches/FogWarpVolumePatches.cs @@ -1,17 +1,11 @@ using HarmonyLib; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using UnityEngine; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.VolumePatches { [HarmonyPatch] - public static class BramblePatches + public static class FogWarpVolumePatches { - [HarmonyPrefix] [HarmonyPatch(typeof(SphericalFogWarpVolume), nameof(SphericalFogWarpVolume.IsProbeOnly))] public static bool SphericalFogWarpVolume_IsProbeOnly(SphericalFogWarpVolume __instance, ref bool __result) @@ -22,7 +16,7 @@ namespace NewHorizons.Patches [HarmonyPrefix] [HarmonyPatch(typeof(FogWarpVolume), nameof(FogWarpVolume.GetFogThickness))] - public static bool FogWarpVolume_GetFogThickness(FogWarpVolume __instance, ref float __result) + public static bool FogWarpVolume_GetFogThickness(FogWarpVolume __instance, ref float __result) { if (__instance is InnerFogWarpVolume sph) __result = sph._exitRadius; else __result = 50; // 50f is hardcoded as the return value in the base game diff --git a/NewHorizons/Patches/VolumePatches/VanishVolumePatches.cs b/NewHorizons/Patches/VolumePatches/VanishVolumePatches.cs new file mode 100644 index 00000000..9b1b8ab2 --- /dev/null +++ b/NewHorizons/Patches/VolumePatches/VanishVolumePatches.cs @@ -0,0 +1,15 @@ +using HarmonyLib; + +namespace NewHorizons.Patches.VolumePatches +{ + [HarmonyPatch(typeof(VanishVolume))] + public static class VanishVolumePatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(VanishVolume.Shrink))] + public static bool VanishVolume_Shrink(VanishVolume __instance, OWRigidbody bodyToShrink) + { + return __instance != null && __instance.transform != null && __instance._shrinkingBodies != null && __instance._shrinkingBodyLocationData != null && bodyToShrink != null; + } + } +} diff --git a/NewHorizons/Patches/VolumePatches/WhiteHoleVolumePatches.cs b/NewHorizons/Patches/VolumePatches/WhiteHoleVolumePatches.cs new file mode 100644 index 00000000..0abf582f --- /dev/null +++ b/NewHorizons/Patches/VolumePatches/WhiteHoleVolumePatches.cs @@ -0,0 +1,28 @@ +using HarmonyLib; +using System; +using System.Collections.Generic; + +namespace NewHorizons.Patches.VolumePatches +{ + [HarmonyPatch(typeof(WhiteHoleVolume))] + public static class WhiteHoleVolumePatches + { + // To fix custom white holes + [HarmonyPrefix] + [HarmonyPatch(nameof(WhiteHoleVolume.Awake))] + public static bool WhiteHoleVolume_Awake(WhiteHoleVolume __instance) + { + __instance._growQueue = new List(8); + __instance._growQueueLocationData = new List(8); + __instance._ejectedBodyList = new List(64); + try + { + __instance._whiteHoleBody = __instance.gameObject.GetAttachedOWRigidbody(false); + __instance._whiteHoleProxyShadowSuperGroup = __instance._whiteHoleBody.GetComponentInChildren(); + __instance._fluidVolume = __instance.gameObject.GetRequiredComponent(); + } + catch (Exception) { } + return false; + } + } +} diff --git a/NewHorizons/Patches/EyeCoordinatePromptTriggerPatches.cs b/NewHorizons/Patches/WarpPatches/EyeCoordinatePromptTriggerPatches.cs similarity index 96% rename from NewHorizons/Patches/EyeCoordinatePromptTriggerPatches.cs rename to NewHorizons/Patches/WarpPatches/EyeCoordinatePromptTriggerPatches.cs index ed827a6f..9afd44e9 100644 --- a/NewHorizons/Patches/EyeCoordinatePromptTriggerPatches.cs +++ b/NewHorizons/Patches/WarpPatches/EyeCoordinatePromptTriggerPatches.cs @@ -2,7 +2,7 @@ using HarmonyLib; using NewHorizons.Handlers; using UnityEngine; -namespace NewHorizons.Patches +namespace NewHorizons.Patches.WarpPatches { [HarmonyPatch] public static class EyeCoordinatePromptTriggerPatches diff --git a/NewHorizons/Patches/WarpPatches/NomaiCoordinateInterfacePatches.cs b/NewHorizons/Patches/WarpPatches/NomaiCoordinateInterfacePatches.cs new file mode 100644 index 00000000..f34b9785 --- /dev/null +++ b/NewHorizons/Patches/WarpPatches/NomaiCoordinateInterfacePatches.cs @@ -0,0 +1,18 @@ +using HarmonyLib; +using NewHorizons.Utility; + +namespace NewHorizons.Patches.WarpPatches +{ + [HarmonyPatch(typeof(NomaiCoordinateInterface))] + public static class NomaiCoordinateInterfacePatches + { + [HarmonyPrefix] + [HarmonyPatch(nameof(NomaiCoordinateInterface.SetPillarRaised), new System.Type[] { typeof(bool) })] + public static bool NomaiCoordinateInterface_SetPillarRaised(NomaiCoordinateInterface __instance, bool raised) + { + if (raised) + return !(!__instance._powered || __instance.CheckEyeCoordinates() && Main.Instance.CurrentStarSystem != "EyeOfTheUniverse" || __instance.CheckAllCoordinates(out string targetSystem) && Main.Instance.CurrentStarSystem != targetSystem); + return true; + } + } +} diff --git a/NewHorizons/Patches/WarpDrivePatches.cs b/NewHorizons/Patches/WarpPatches/ShipCockpitControllerPatches.cs similarity index 77% rename from NewHorizons/Patches/WarpDrivePatches.cs rename to NewHorizons/Patches/WarpPatches/ShipCockpitControllerPatches.cs index 4520fa97..b17b0248 100644 --- a/NewHorizons/Patches/WarpDrivePatches.cs +++ b/NewHorizons/Patches/WarpPatches/ShipCockpitControllerPatches.cs @@ -1,14 +1,13 @@ using HarmonyLib; using NewHorizons.Handlers; -using NewHorizons.Utility; -using UnityEngine; -namespace NewHorizons.Patches + +namespace NewHorizons.Patches.WarpPatches { - [HarmonyPatch] - public static class WarpDrivePatches + [HarmonyPatch(typeof(ShipCockpitController))] + public static class ShipCockpitControllerPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(ShipCockpitController), nameof(ShipCockpitController.Update))] + [HarmonyPatch(nameof(ShipCockpitController.Update))] public static bool ShipCockpitController_Update(ShipCockpitController __instance) { if (!Main.HasWarpDrive) return true; diff --git a/NewHorizons/Patches/NomaiCoordinatePatches.cs b/NewHorizons/Patches/WarpPatches/VesselWarpControllerPatches.cs similarity index 69% rename from NewHorizons/Patches/NomaiCoordinatePatches.cs rename to NewHorizons/Patches/WarpPatches/VesselWarpControllerPatches.cs index 5191ceca..1a6df743 100644 --- a/NewHorizons/Patches/NomaiCoordinatePatches.cs +++ b/NewHorizons/Patches/WarpPatches/VesselWarpControllerPatches.cs @@ -1,22 +1,13 @@ using HarmonyLib; using NewHorizons.Utility; -using UnityEngine; -namespace NewHorizons.Patches + +namespace NewHorizons.Patches.WarpPatches { - [HarmonyPatch] - public static class NomaiCoordinatePatches + [HarmonyPatch(typeof(VesselWarpController))] + public static class VesselWarpControllerPatches { [HarmonyPrefix] - [HarmonyPatch(typeof(NomaiCoordinateInterface), nameof(NomaiCoordinateInterface.SetPillarRaised), new System.Type[] { typeof(bool) })] - public static bool NomaiCoordinateInterface_SetPillarRaised(NomaiCoordinateInterface __instance, bool raised) - { - if (raised) - return !(!__instance._powered || (__instance.CheckEyeCoordinates() && Main.Instance.CurrentStarSystem != "EyeOfTheUniverse") || (__instance.CheckAllCoordinates(out string targetSystem) && Main.Instance.CurrentStarSystem != targetSystem)); - return true; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(VesselWarpController), nameof(VesselWarpController.WarpVessel))] + [HarmonyPatch(nameof(VesselWarpController.WarpVessel))] public static bool VesselWarpController_WarpVessel(VesselWarpController __instance, bool debugWarp) { if (!Main.Instance.IsWarpingFromVessel && TimeLoop.GetLoopCount() < 2) @@ -29,11 +20,12 @@ namespace NewHorizons.Patches PlayerData.SaveWarpedToTheEye(TimeLoopUtilities.GetVanillaSecondsRemaining()); LoadManager.EnableAsyncLoadTransition(); + return false; } [HarmonyPrefix] - [HarmonyPatch(typeof(VesselWarpController), nameof(VesselWarpController.CheckSystemActivation))] + [HarmonyPatch(nameof(VesselWarpController.CheckSystemActivation))] public static void VesselWarpController_CheckSystemActivation(VesselWarpController __instance) { if (Locator.GetEyeStateManager() == null && Main.Instance.CurrentStarSystem != "EyeOfTheUniverse") @@ -46,19 +38,19 @@ namespace NewHorizons.Patches } [HarmonyPrefix] - [HarmonyPatch(typeof(VesselWarpController), nameof(VesselWarpController.OnSlotActivated))] + [HarmonyPatch(nameof(VesselWarpController.OnSlotActivated))] public static bool VesselWarpController_OnSlotActivated(VesselWarpController __instance, NomaiInterfaceSlot slot) { bool canWarpToEye = __instance._coordinateInterface.CheckEyeCoordinates(); bool canWarpToStarSystem = __instance._coordinateInterface.CheckAllCoordinates(out string targetSystem); - if (slot == __instance._warpVesselSlot && __instance._hasPower && ((canWarpToEye && Main.Instance.CurrentStarSystem != "EyeOfTheUniverse") || (canWarpToStarSystem && targetSystem != Main.Instance.CurrentStarSystem)) && __instance._blackHole.GetState() == SingularityController.State.Collapsed) + if (slot == __instance._warpVesselSlot && __instance._hasPower && (canWarpToEye && Main.Instance.CurrentStarSystem != "EyeOfTheUniverse" || canWarpToStarSystem && targetSystem != Main.Instance.CurrentStarSystem) && __instance._blackHole.GetState() == SingularityController.State.Collapsed) { __instance._blackHole.Create(); RumbleManager.StartVesselWarp(); __instance._openingBlackHole = true; __instance.enabled = true; Locator.GetPauseCommandListener().AddPauseCommandLock(); - if (canWarpToEye || (canWarpToStarSystem && targetSystem == "EyeOfTheUniverse")) + if (canWarpToEye || canWarpToStarSystem && targetSystem == "EyeOfTheUniverse") { Main.Instance._currentStarSystem = "EyeOfTheUniverse"; LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, false, LoadManager.FadeType.ToWhite);