From 1ec73259768c9d8ecdf89a9968188d28c9e52808 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 25 May 2024 00:10:57 -0400 Subject: Started new main menu --- AnodyneArchipelago/Patches/StatePatches.cs | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'AnodyneArchipelago/Patches/StatePatches.cs') diff --git a/AnodyneArchipelago/Patches/StatePatches.cs b/AnodyneArchipelago/Patches/StatePatches.cs index f6acc62..4b29295 100644 --- a/AnodyneArchipelago/Patches/StatePatches.cs +++ b/AnodyneArchipelago/Patches/StatePatches.cs @@ -4,6 +4,10 @@ using AnodyneSharp.States; using AnodyneSharp; using HarmonyLib; using System.Reflection; +using AnodyneSharp.Drawing.Effects; +using AnodyneSharp.States.MainMenu; +using static AnodyneSharp.AnodyneGame; +using AnodyneSharp.Drawing; namespace AnodyneArchipelago.Patches { @@ -16,6 +20,49 @@ namespace AnodyneArchipelago.Patches } } + [HarmonyPatch(typeof(AnodyneGame), "SetState")] + class SetStatePatch + { + // Pretty much rewrite this whole method, so that we can swap out some states. + static bool Prefix(AnodyneGame __instance, GameState state) + { + foreach (IFullScreenEffect effect in GlobalState.AllEffects) + { + effect.Deactivate(); + } + + State new_state = CreateState(__instance, state); + + if (new_state != null) + { + new_state.Create(); + + MethodInfo setStateMethod = typeof(AnodyneGame).GetMethod("SetState", BindingFlags.NonPublic | BindingFlags.Instance); + new_state.ChangeStateEvent = (ChangeState)setStateMethod.CreateDelegate(typeof(ChangeState), __instance); + } + + FieldInfo stateField = typeof(AnodyneGame).GetField("_currentState", BindingFlags.NonPublic | BindingFlags.Instance); + stateField.SetValue(__instance, new_state); + + return false; + } + + static State CreateState(AnodyneGame __instance, GameState state) + { + switch (state) + { + case GameState.TitleScreen: return new TitleState(); + case GameState.MainMenu: return new Menu.MenuState(); + case GameState.Intro: return new IntroState(); + case GameState.Game: + FieldInfo cameraField = typeof(AnodyneGame).GetField("_camera", BindingFlags.NonPublic | BindingFlags.Instance); + return new PlayState((Camera)cameraField.GetValue(__instance)); + case GameState.Credits: return new CreditsState(); + default: return null; + } + } + } + [HarmonyPatch(typeof(PlayState), nameof(PlayState.Create))] class PlayStateCreatePatch { -- cgit 1.4.1