From 14bd2480ce6d4f9be6ad52d35bbaa1d839f69bf4 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Wed, 7 Feb 2024 05:15:18 -0500 Subject: [PATCH 1/3] [+] Fix character selection crash --- AquaMai/Fix/FixCharaCrash.cs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 AquaMai/Fix/FixCharaCrash.cs diff --git a/AquaMai/Fix/FixCharaCrash.cs b/AquaMai/Fix/FixCharaCrash.cs new file mode 100644 index 00000000..02407fe8 --- /dev/null +++ b/AquaMai/Fix/FixCharaCrash.cs @@ -0,0 +1,28 @@ +using HarmonyLib; +using Process; +using Util; + +namespace AquaMai.Fix +{ + /** + * Fix character selection crashing because get map color returns null + */ + public class FixCharaCrash + { + // Check if the return is null. If it is, make up a color + [HarmonyPostfix] + [HarmonyPatch(typeof(CharacterSelectProces), "GetMapColorData")] + public static void GetMapColorData(ref CharacterSelectProces __instance, ref CharacterMapColorData __result) + { + if (__result != null) return; + + // 1 is a color that definitely exists + if (MapMaster.GetSlotData(1) == null) + { + MapMaster.GetSlotData(1).Load(); + } + __result = MapMaster.GetSlotData(1); + } + + } +} \ No newline at end of file From de12ec6548209f605a2321a5c39ee7a72120a816 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Wed, 7 Feb 2024 05:15:48 -0500 Subject: [PATCH 2/3] [+] Ticket unlock patch --- AquaMai/Cheat/TicketUnlock.cs | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 AquaMai/Cheat/TicketUnlock.cs diff --git a/AquaMai/Cheat/TicketUnlock.cs b/AquaMai/Cheat/TicketUnlock.cs new file mode 100644 index 00000000..697a516c --- /dev/null +++ b/AquaMai/Cheat/TicketUnlock.cs @@ -0,0 +1,40 @@ +using Manager.MaiStudio; +using HarmonyLib; + +namespace AquaMai.Cheat +{ + /** + * Unlock tickets that are typically locked unless a specific event is open. + */ + public class TicketUnlock + { + // For any ticket, return the event ID 1 to unlock it + [HarmonyPrefix] + [HarmonyPatch(typeof(TicketData), "get_ticketEvent")] + public static bool get_ticketEvent(ref StringID __result) + { + var id = new Manager.MaiStudio.Serialize.StringID + { + id = 1, + str = "無期限常時解放" + }; + + var sid = new StringID(); + sid.Init(id); + + __result = sid; + return false; + } + + // Modify the maxTicketNum to 0 + // this is because TicketManager.GetTicketData adds the ticket to the list if either + // the player owns at least one ticket or the maxTicketNum = 0 + [HarmonyPrefix] + [HarmonyPatch(typeof(TicketData), "get_maxCount")] + public static bool get_maxCount(ref int __result) + { + __result = 0; + return false; + } + } +} \ No newline at end of file From ccb3f7ef34002533e4de8b48f4883cef8f929c4d Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Wed, 7 Feb 2024 05:16:07 -0500 Subject: [PATCH 3/3] [+] Add cheat config --- AquaMai/AquaMai.csproj | 2 ++ AquaMai/AquaMai.toml | 6 ++++++ AquaMai/Config.cs | 6 ++++++ AquaMai/Main.cs | 28 +++++++++++++++++++--------- AquaMai/UX/SinglePlayer.cs | 6 ++++-- 5 files changed, 37 insertions(+), 11 deletions(-) diff --git a/AquaMai/AquaMai.csproj b/AquaMai/AquaMai.csproj index 70752762..4c891cf5 100644 --- a/AquaMai/AquaMai.csproj +++ b/AquaMai/AquaMai.csproj @@ -263,7 +263,9 @@ + + diff --git a/AquaMai/AquaMai.toml b/AquaMai/AquaMai.toml index 294a9cea..8fcedd98 100644 --- a/AquaMai/AquaMai.toml +++ b/AquaMai/AquaMai.toml @@ -1,4 +1,10 @@ +# =================================== +# Cheat: You control the buttons you press +[Cheat] +# Unlock normally event-only tickets +TicketUnlock=true + # =================================== # UX: User Experience Improvements [UX] diff --git a/AquaMai/Config.cs b/AquaMai/Config.cs index 8f20891e..0a1e0c98 100644 --- a/AquaMai/Config.cs +++ b/AquaMai/Config.cs @@ -6,6 +6,12 @@ namespace AquaMai public class Config { public UXConfig UX { get; set; } + public CheatConfig Cheat { get; set; } + + public class CheatConfig + { + public bool TicketUnlock { get; set; } + } public class UXConfig { diff --git a/AquaMai/Main.cs b/AquaMai/Main.cs index e7e62e9a..c613eb4f 100644 --- a/AquaMai/Main.cs +++ b/AquaMai/Main.cs @@ -1,4 +1,7 @@ -using AquaMai.UX; +using System; +using AquaMai.Cheat; +using AquaMai.Fix; +using AquaMai.UX; using MelonLoader; using Tomlet; @@ -18,6 +21,12 @@ namespace AquaMai { public static Config AppConfig { get; private set; } + private void Patch(Type type) + { + MelonLogger.Msg($"> Patching {type}"); + HarmonyLib.Harmony.CreateAndPatchAll(type); + } + public override void OnInitializeMelon() { MelonLogger.Msg("Loading mod settings..."); @@ -33,16 +42,17 @@ namespace AquaMai AppConfig = TomletMain.To(System.IO.File.ReadAllText("AquaMai.toml")); if (AppConfig.UX.SkipWarningScreen) - { - MelonLogger.Msg("> Patching SkipWarningScreen"); - HarmonyLib.Harmony.CreateAndPatchAll(typeof(SkipWarningScreen)); - } + Patch(typeof(SkipWarningScreen)); if (AppConfig.UX.SinglePlayer) - { - MelonLogger.Msg("> Patching SinglePlayer"); - HarmonyLib.Harmony.CreateAndPatchAll(typeof(SinglePlayer)); - } + Patch(typeof(SinglePlayer)); + + if (AppConfig.Cheat.TicketUnlock) + Patch(typeof(TicketUnlock)); + + // Fixes that does not have side effects + // These don't need to be configurable + Patch(typeof(FixCharaCrash)); MelonLogger.Msg("Loaded!"); } diff --git a/AquaMai/UX/SinglePlayer.cs b/AquaMai/UX/SinglePlayer.cs index e62018cc..eb9c2c1e 100644 --- a/AquaMai/UX/SinglePlayer.cs +++ b/AquaMai/UX/SinglePlayer.cs @@ -2,10 +2,12 @@ using System; using HarmonyLib; using UnityEngine; -namespace AquaMai { +namespace AquaMai.UX +{ // Hides the 2p (right hand side) UI. // Note: this is not my original work. I simply interpreted the code and rewrote it as a mod. - public class SinglePlayer { + public class SinglePlayer + { [HarmonyPrefix] [HarmonyPatch(typeof(Main.GameMain), "LateInitialize", new Type[] { typeof(MonoBehaviour), typeof(Transform), typeof(Transform) })] public static bool LateInitialize(MonoBehaviour gameMainObject, ref Transform left, ref Transform right)