From 4a4a469ed523e57b658d8696c80a8e1e51fd644e Mon Sep 17 00:00:00 2001 From: gwisp2 <60121533+gwisp2@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:56:41 +0300 Subject: [PATCH] Initial commit --- .gitignore | 4 ++++ Plugin.cs | 22 +++++++++++++++++++ Puzzleskip.csproj | 39 +++++++++++++++++++++++++++++++++ Puzzleskip.sln | 25 +++++++++++++++++++++ PuzzleskipPatcher.cs | 51 +++++++++++++++++++++++++++++++++++++++++++ SkipPuzzleButton.cs | 52 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 193 insertions(+) create mode 100644 .gitignore create mode 100644 Plugin.cs create mode 100644 Puzzleskip.csproj create mode 100644 Puzzleskip.sln create mode 100644 PuzzleskipPatcher.cs create mode 100644 SkipPuzzleButton.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94c0a3c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +lib/Assembly-CSharp.dll +.vs +bin +obj diff --git a/Plugin.cs b/Plugin.cs new file mode 100644 index 0000000..7c9ef6a --- /dev/null +++ b/Plugin.cs @@ -0,0 +1,22 @@ +using BepInEx; +using BepInEx.Logging; +using HarmonyLib; + +namespace Puzzleskip +{ + [BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] + public class Plugin : BaseUnityPlugin + { + internal static new ManualLogSource Logger; + + private void Awake() + { + // Plugin startup logic + Logger = base.Logger; + Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!"); + // Patch game code + var harmony = new Harmony("Puzzleskip"); + harmony.PatchAll(); + } + } +} diff --git a/Puzzleskip.csproj b/Puzzleskip.csproj new file mode 100644 index 0000000..010ba69 --- /dev/null +++ b/Puzzleskip.csproj @@ -0,0 +1,39 @@ + + + + netstandard2.0 + Puzzleskip + Skip puzzles in Mansions of Madness + 1.0.0 + true + latest + + https://api.nuget.org/v3/index.json; + https://nuget.bepinex.dev/v3/index.json; + https://nuget.samboy.dev/v3/index.json + + Puzzleskip + + + + + + + + + + + + + lib\Assembly-CSharp.dll + + + + + + + + + + + diff --git a/Puzzleskip.sln b/Puzzleskip.sln new file mode 100644 index 0000000..94a4585 --- /dev/null +++ b/Puzzleskip.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.35013.160 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Puzzleskip", "Puzzleskip.csproj", "{3EC53305-2A9E-41FB-A124-0DBD2BDC7FCB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3EC53305-2A9E-41FB-A124-0DBD2BDC7FCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3EC53305-2A9E-41FB-A124-0DBD2BDC7FCB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3EC53305-2A9E-41FB-A124-0DBD2BDC7FCB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3EC53305-2A9E-41FB-A124-0DBD2BDC7FCB}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {287AA528-E116-497E-BE5D-2CA1094F224D} + EndGlobalSection +EndGlobal diff --git a/PuzzleskipPatcher.cs b/PuzzleskipPatcher.cs new file mode 100644 index 0000000..4561c6a --- /dev/null +++ b/PuzzleskipPatcher.cs @@ -0,0 +1,51 @@ +using FFG.MoM; +using HarmonyLib; + +namespace Puzzleskip +{ + [HarmonyPatch(typeof(PuzzleViewBase))] + internal class PuzzleskipPatcher + { + [HarmonyPrefix] + [HarmonyPatch("PuzzleClosedEvent")] + static bool PrePuzzleClosedEvent(PuzzleViewBase __instance, ref bool completed) + { + SkipPuzzleButton skipPuzzleButton = __instance.gameObject.GetComponentInChildren(); + if (skipPuzzleButton.SkipEnabled) + { + completed = true; + } + return true; + } + + + [HarmonyPrefix] + [HarmonyPatch("Show")] + static void PreShow(PuzzleViewBase __instance) + { + UIButton button = FindCloseButton(__instance); + if (button != null) + { + if (button.gameObject.GetComponent() == null) + { + button.gameObject.AddComponent(); + } + SkipPuzzleButton skipButton = button.gameObject.GetComponent(); + skipButton.SkipEnabled = false; + } + } + + private static UIButton FindCloseButton(PuzzleViewBase puzzleViewBase) + { + var buttons = puzzleViewBase.GetComponentsInChildren(); + foreach (var button in buttons) + { + if (button.name.Contains("Close")) + { + return button; + } + } + return null; + } + } +} diff --git a/SkipPuzzleButton.cs b/SkipPuzzleButton.cs new file mode 100644 index 0000000..c1d04ca --- /dev/null +++ b/SkipPuzzleButton.cs @@ -0,0 +1,52 @@ +using UnityEngine; + +namespace Puzzleskip +{ + internal class SkipPuzzleButton : MonoBehaviour + { + private UILabel _label; + private bool _skipEnabled; + private string _originalText; + private float _buttonDownSeconds = 0; + + public void Awake() + { + _label = this.gameObject.GetComponentInChildren(); + _originalText = _label.text; + } + + public void Update() + { + if (Input.GetMouseButton(1)) + { + _buttonDownSeconds += Time.deltaTime; + } + else + { + _buttonDownSeconds = 0; + } + if (_buttonDownSeconds > 3) + { + SkipEnabled = !SkipEnabled; + _buttonDownSeconds = 0; + } + } + + public bool SkipEnabled + { + get { return _skipEnabled; } + set + { + _skipEnabled = value; + if (_skipEnabled) + { + _label.text = "Skip"; + } + else + { + _label.text = _originalText; + } + } + } + } +}