diff options
Diffstat (limited to 'AnodyneArchipelago/Patches')
-rw-r--r-- | AnodyneArchipelago/Patches/StatePatches.cs | 47 |
1 files changed, 47 insertions, 0 deletions
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; | |||
4 | using AnodyneSharp; | 4 | using AnodyneSharp; |
5 | using HarmonyLib; | 5 | using HarmonyLib; |
6 | using System.Reflection; | 6 | using System.Reflection; |
7 | using AnodyneSharp.Drawing.Effects; | ||
8 | using AnodyneSharp.States.MainMenu; | ||
9 | using static AnodyneSharp.AnodyneGame; | ||
10 | using AnodyneSharp.Drawing; | ||
7 | 11 | ||
8 | namespace AnodyneArchipelago.Patches | 12 | namespace AnodyneArchipelago.Patches |
9 | { | 13 | { |
@@ -16,6 +20,49 @@ namespace AnodyneArchipelago.Patches | |||
16 | } | 20 | } |
17 | } | 21 | } |
18 | 22 | ||
23 | [HarmonyPatch(typeof(AnodyneGame), "SetState")] | ||
24 | class SetStatePatch | ||
25 | { | ||
26 | // Pretty much rewrite this whole method, so that we can swap out some states. | ||
27 | static bool Prefix(AnodyneGame __instance, GameState state) | ||
28 | { | ||
29 | foreach (IFullScreenEffect effect in GlobalState.AllEffects) | ||
30 | { | ||
31 | effect.Deactivate(); | ||
32 | } | ||
33 | |||
34 | State new_state = CreateState(__instance, state); | ||
35 | |||
36 | if (new_state != null) | ||
37 | { | ||
38 | new_state.Create(); | ||
39 | |||
40 | MethodInfo setStateMethod = typeof(AnodyneGame).GetMethod("SetState", BindingFlags.NonPublic | BindingFlags.Instance); | ||
41 | new_state.ChangeStateEvent = (ChangeState)setStateMethod.CreateDelegate(typeof(ChangeState), __instance); | ||
42 | } | ||
43 | |||
44 | FieldInfo stateField = typeof(AnodyneGame).GetField("_currentState", BindingFlags.NonPublic | BindingFlags.Instance); | ||
45 | stateField.SetValue(__instance, new_state); | ||
46 | |||
47 | return false; | ||
48 | } | ||
49 | |||
50 | static State CreateState(AnodyneGame __instance, GameState state) | ||
51 | { | ||
52 | switch (state) | ||
53 | { | ||
54 | case GameState.TitleScreen: return new TitleState(); | ||
55 | case GameState.MainMenu: return new Menu.MenuState(); | ||
56 | case GameState.Intro: return new IntroState(); | ||
57 | case GameState.Game: | ||
58 | FieldInfo cameraField = typeof(AnodyneGame).GetField("_camera", BindingFlags.NonPublic | BindingFlags.Instance); | ||
59 | return new PlayState((Camera)cameraField.GetValue(__instance)); | ||
60 | case GameState.Credits: return new CreditsState(); | ||
61 | default: return null; | ||
62 | } | ||
63 | } | ||
64 | } | ||
65 | |||
19 | [HarmonyPatch(typeof(PlayState), nameof(PlayState.Create))] | 66 | [HarmonyPatch(typeof(PlayState), nameof(PlayState.Create))] |
20 | class PlayStateCreatePatch | 67 | class PlayStateCreatePatch |
21 | { | 68 | { |