diff --git a/AquaMai/AquaMai.csproj b/AquaMai/AquaMai.csproj index 2314b799..86d93700 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/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 diff --git a/AquaMai/Config.cs b/AquaMai/Config.cs index 88dd5702..1102c7a2 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/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 diff --git a/AquaMai/Main.cs b/AquaMai/Main.cs index ebf5c336..0f0abeea 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,23 +42,24 @@ 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)); + if (AppConfig.UX.SkipToMusicSelection) { - MelonLogger.Msg($"> Patching {nameof(SkipToMusicSelection)}"); - HarmonyLib.Harmony.CreateAndPatchAll(typeof(SkipToMusicSelection)); + Patch(typeof(SkipToMusicSelection)); } + // 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 17e222a8..d9a5e026 100644 --- a/AquaMai/UX/SinglePlayer.cs +++ b/AquaMai/UX/SinglePlayer.cs @@ -2,15 +2,15 @@ using System; using HarmonyLib; using UnityEngine; -namespace AquaMai.UX +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) + public static bool LateInitialize(MonoBehaviour gameMainObject, ref Transform left, ref Transform right) { left.transform.position = Vector3.zero; right.localScale = Vector3.zero;