From 2af257a35fea2f01fce4b83c705f13ef9253bebb Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Tue, 24 May 2022 11:34:17 -0400 Subject: [PATCH] added patches required to block item swapping while holding a vision torch. this is the last change required to get vision torches baseline functional --- .../Builder/Props/ProjectionBuilder.cs | 2 +- NewHorizons/Patches/ToolModeSwapperPatches.cs | 36 +++++++++++++++++++ NewHorizons/Patches/VisionTorchPatches.cs | 3 ++ 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 NewHorizons/Patches/ToolModeSwapperPatches.cs diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index fe01b388..d0f7f67d 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -184,7 +184,7 @@ namespace NewHorizons.Builder.Props // TODO: do this part asynchronously so that you can load all the slides you want without stalling the game out for 5 days var texture = ImageUtilities.GetTexture(mod, slideInfo.imagePath); - slide.textureOverride = ImageUtilities.Invert(texture); + slide.textureOverride = texture; //ImageUtilities.Invert(texture); AddModules(slideInfo, ref slide); diff --git a/NewHorizons/Patches/ToolModeSwapperPatches.cs b/NewHorizons/Patches/ToolModeSwapperPatches.cs new file mode 100644 index 00000000..dc102864 --- /dev/null +++ b/NewHorizons/Patches/ToolModeSwapperPatches.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HarmonyLib; + +namespace NewHorizons.Patches +{ + [HarmonyPatch] + 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 + + // the correct way to do this is to patch ToolModeSwapper.Update to be exactly the same as it is now, but change the below line + // 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))] + public static bool ToolModeSwapper_EquipToolMode(ToolModeSwapper __instance, ToolMode mode) + { + bool isHoldingVisionTorch = __instance.GetItemCarryTool()?.GetHeldItemType() == ItemType.VisionTorch; + bool swappingToRestrictedTool = + mode == ToolMode.Probe || + mode == ToolMode.SignalScope || + mode == ToolMode.Translator; + + if (isHoldingVisionTorch && swappingToRestrictedTool) return false; + + return true; + } + } +} diff --git a/NewHorizons/Patches/VisionTorchPatches.cs b/NewHorizons/Patches/VisionTorchPatches.cs index 82d8fbf2..c51e6afe 100644 --- a/NewHorizons/Patches/VisionTorchPatches.cs +++ b/NewHorizons/Patches/VisionTorchPatches.cs @@ -68,5 +68,8 @@ namespace NewHorizons.Patches return true; } + + // ProbeLauncher.Disable()? + // public override void PickUpItem(Transform holdTranform) } }