From c074de5876a98c8f0f8d2e7b3bf36fbc5a2022b2 Mon Sep 17 00:00:00 2001 From: Clansty Date: Fri, 25 Oct 2024 00:45:12 +0800 Subject: [PATCH] [+] SinglePlayer support legacy game versions --- AquaMai/Helpers/GuiSizes.cs | 1 + AquaMai/UX/SinglePlayer.cs | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/AquaMai/Helpers/GuiSizes.cs b/AquaMai/Helpers/GuiSizes.cs index e5db2347..b3012724 100644 --- a/AquaMai/Helpers/GuiSizes.cs +++ b/AquaMai/Helpers/GuiSizes.cs @@ -36,6 +36,7 @@ public static class GuiSizes GUI.backgroundColor = backgroundColor; } + [HarmonyPatch] public class BoxBackground { public static IEnumerable TargetMethods() diff --git a/AquaMai/UX/SinglePlayer.cs b/AquaMai/UX/SinglePlayer.cs index 476f3ecf..13ceb465 100644 --- a/AquaMai/UX/SinglePlayer.cs +++ b/AquaMai/UX/SinglePlayer.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; +using System.Reflection; using HarmonyLib; using MAI2.Util; using Manager; @@ -14,13 +16,22 @@ namespace AquaMai.UX // Note: this is not my original work. I simply interpreted the code and rewrote it as a mod. public class SinglePlayer { - [HarmonyPrefix] - [HarmonyPatch(typeof(Main.GameMain), "LateInitialize", new Type[] { typeof(MonoBehaviour), typeof(Transform), typeof(Transform) })] - public static void LateInitialize(MonoBehaviour gameMainObject, ref Transform left, ref Transform right) + [HarmonyPatch] + public class WhateverInitialize { - left.transform.position = Vector3.zero; - right.localScale = Vector3.zero; - GameObject.Find("Mask").transform.position = new Vector3(540f, 0f, 0f); + public static IEnumerable TargetMethods() + { + var lateInitialize = AccessTools.Method(typeof(Main.GameMain), "LateInitialize", [typeof(MonoBehaviour), typeof(Transform), typeof(Transform)]); + if (lateInitialize is not null) return [lateInitialize]; + return [AccessTools.Method(typeof(Main.GameMain), "Initialize", [typeof(MonoBehaviour), typeof(Transform), typeof(Transform)])]; + } + + public static void Prefix(MonoBehaviour gameMainObject, ref Transform left, ref Transform right) + { + left.transform.position = Vector3.zero; + right.localScale = Vector3.zero; + GameObject.Find("Mask").transform.position = new Vector3(540f, 0f, 0f); + } } [HarmonyPrefix]