diff options
Diffstat (limited to 'GameplayPatches.cs')
-rw-r--r-- | GameplayPatches.cs | 237 |
1 files changed, 237 insertions, 0 deletions
diff --git a/GameplayPatches.cs b/GameplayPatches.cs new file mode 100644 index 0000000..e0767c4 --- /dev/null +++ b/GameplayPatches.cs | |||
@@ -0,0 +1,237 @@ | |||
1 | using HarmonyLib; | ||
2 | using System.Reflection; | ||
3 | |||
4 | namespace ManifoldGardenArchipelago | ||
5 | { | ||
6 | [HarmonyPatch(typeof(LineDoorController), "SetDoorOpenCloseStateAnimated")] | ||
7 | static class LineDoorControllerSetDoorOpenCloseStateAnimatedPatch | ||
8 | { | ||
9 | static bool Prefix(LineDoorController __instance, bool open) | ||
10 | { | ||
11 | SceneItemReference sir = GameState.GetChainListenerSceneReference(__instance); | ||
12 | |||
13 | if (GameData.scenes.TryGetValue(sir.scene, out var sceneDescription)) | ||
14 | { | ||
15 | if (sceneDescription.doors.TryGetValue(sir.index, out var requirement)) | ||
16 | { | ||
17 | if (open != requirement.Check()) | ||
18 | { | ||
19 | return false; | ||
20 | } | ||
21 | } | ||
22 | } | ||
23 | |||
24 | return true; | ||
25 | } | ||
26 | } | ||
27 | |||
28 | [HarmonyPatch(typeof(ButtonLineActivator), "ToggleButtonPress")] | ||
29 | static class ButtonLineActivatorToggleButtonPressPatch | ||
30 | { | ||
31 | static void Prefix(ButtonLineActivator __instance, bool setPressed) | ||
32 | { | ||
33 | SceneItemReference sir = GameState.GetButtonSceneReference(__instance); | ||
34 | Plugin.Logger.LogInfo($"Button {sir} state {setPressed}"); | ||
35 | |||
36 | if (!GameData.listenersByButton.TryGetValue(sir, out GameStateListeners listeners)) | ||
37 | { | ||
38 | return; | ||
39 | } | ||
40 | |||
41 | if (setPressed) | ||
42 | { | ||
43 | Plugin.slotSave.ActivatedButtons.Add(sir); | ||
44 | } | ||
45 | else | ||
46 | { | ||
47 | Plugin.slotSave.ActivatedButtons.Remove(sir); | ||
48 | } | ||
49 | |||
50 | GameState.EvaluateGameStateListeners(listeners); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | [HarmonyPatch(typeof(CubeReceiverController), "SetActivatorActive")] | ||
55 | static class CubeReceiverControllerSetActivatorActivePatch | ||
56 | { | ||
57 | static void Prefix(CubeReceiverController __instance, bool active) | ||
58 | { | ||
59 | SceneItemReference sir = GameState.GetSocketSceneReference(__instance); | ||
60 | Plugin.Logger.LogInfo($"Socket {sir} state {active}"); | ||
61 | |||
62 | if (!GameData.listenersBySocket.TryGetValue(sir, out GameStateListeners listeners)) | ||
63 | { | ||
64 | return; | ||
65 | } | ||
66 | |||
67 | if (active) | ||
68 | { | ||
69 | Plugin.slotSave.ActivatedSockets.Add(sir); | ||
70 | } | ||
71 | else | ||
72 | { | ||
73 | Plugin.slotSave.ActivatedSockets.Remove(sir); | ||
74 | } | ||
75 | |||
76 | GameState.EvaluateGameStateListeners(listeners); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | [HarmonyPatch(typeof(CubeLineActivator), "SetActivatorActive")] | ||
81 | static class CubeLineActivatorSetActivatorActivePatch | ||
82 | { | ||
83 | static void Prefix(CubeLineActivator __instance, bool setActive) | ||
84 | { | ||
85 | SceneItemReference sir = GameState.GetPadSceneReference(__instance); | ||
86 | Plugin.Logger.LogInfo($"Pad {sir} state {setActive}"); | ||
87 | |||
88 | if (!GameData.listenersByPad.TryGetValue(sir, out GameStateListeners listeners)) | ||
89 | { | ||
90 | return; | ||
91 | } | ||
92 | |||
93 | if (setActive) | ||
94 | { | ||
95 | Plugin.slotSave.ActivatedPads.Add(sir); | ||
96 | } | ||
97 | else | ||
98 | { | ||
99 | Plugin.slotSave.ActivatedPads.Remove(sir); | ||
100 | } | ||
101 | |||
102 | GameState.EvaluateGameStateListeners(listeners); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | [HarmonyPatch(typeof(WaterDetector), "SetActivatorActive")] | ||
107 | static class WaterDetectorSetActivatorActivePatch | ||
108 | { | ||
109 | static void Prefix(WaterDetector __instance, bool setActive) | ||
110 | { | ||
111 | SceneItemReference sir = GameState.GetWaterwheelSceneReference(__instance); | ||
112 | Plugin.Logger.LogInfo($"Waterwheel {sir} state {setActive}"); | ||
113 | |||
114 | if (!GameData.listenersByWaterwheel.TryGetValue(sir, out GameStateListeners listeners)) | ||
115 | { | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | if (setActive) | ||
120 | { | ||
121 | Plugin.slotSave.ActivatedWaterwheels.Add(sir); | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | Plugin.slotSave.ActivatedWaterwheels.Remove(sir); | ||
126 | } | ||
127 | |||
128 | GameState.EvaluateGameStateListeners(listeners); | ||
129 | } | ||
130 | } | ||
131 | |||
132 | [HarmonyPatch(typeof(SphereController), nameof(SphereController.SetState))] | ||
133 | static class SphereControllerSetStatePatch | ||
134 | { | ||
135 | static void Prefix(SphereController __instance, SphereController.State newState) | ||
136 | { | ||
137 | SceneItemReference sir = GameState.GetSphereSceneReference(__instance); | ||
138 | Plugin.Logger.LogInfo($"Sphere {sir} state {newState}"); | ||
139 | |||
140 | if (!GameData.listenersBySphere.TryGetValue(sir, out GameStateListeners listeners)) | ||
141 | { | ||
142 | return; | ||
143 | } | ||
144 | |||
145 | if (newState == SphereController.State.AtDestination) | ||
146 | { | ||
147 | Plugin.slotSave.ActivatedSpheres.Add(sir); | ||
148 | } | ||
149 | else | ||
150 | { | ||
151 | Plugin.slotSave.ActivatedSpheres.Remove(sir); | ||
152 | } | ||
153 | |||
154 | GameState.EvaluateGameStateListeners(listeners); | ||
155 | } | ||
156 | } | ||
157 | |||
158 | [HarmonyPatch(typeof(LineDoorController), nameof(LineDoorController.OnLevelEnable))] | ||
159 | static class LineDoorControllerOnLevelEnablePatch | ||
160 | { | ||
161 | static void Prefix(LineDoorController __instance) | ||
162 | { | ||
163 | SceneItemReference sir = GameState.GetChainListenerSceneReference(__instance); | ||
164 | |||
165 | if (GameData.scenes.TryGetValue(sir.scene, out var sceneDescription)) | ||
166 | { | ||
167 | if (sceneDescription.doors.TryGetValue(sir.index, out var requirement)) | ||
168 | { | ||
169 | FieldInfo fieldInfo = typeof(LineDoorController).GetField("doorShouldOpenImmediatelyOnEnable", BindingFlags.Instance | BindingFlags.NonPublic); | ||
170 | fieldInfo.SetValue(__instance, requirement.Check()); | ||
171 | |||
172 | __instance.chains.Clear(); | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | |||
178 | [HarmonyPatch(typeof(LineDoorController), nameof(LineDoorController.OnLoad))] | ||
179 | static class LineDoorControllerOnLoadPatch | ||
180 | { | ||
181 | static void Prefix(LineDoorController __instance) | ||
182 | { | ||
183 | SceneItemReference sir = GameState.GetChainListenerSceneReference(__instance); | ||
184 | |||
185 | if (GameData.scenes.TryGetValue(sir.scene, out var sceneDescription)) | ||
186 | { | ||
187 | if (sceneDescription.doors.TryGetValue(sir.index, out var requirement)) | ||
188 | { | ||
189 | FieldInfo fieldInfo = typeof(LineDoorController).GetField("doorShouldOpenImmediatelyOnEnable", BindingFlags.Instance | BindingFlags.NonPublic); | ||
190 | fieldInfo.SetValue(__instance, requirement.Check()); | ||
191 | |||
192 | __instance.chains.Clear(); | ||
193 | } | ||
194 | } | ||
195 | } | ||
196 | } | ||
197 | |||
198 | [HarmonyPatch(typeof(LevelLoader), nameof(LevelLoader.MovePlayerIntoNewScene))] | ||
199 | static class LevelLoaderMovePlayerIntoNewScenePatch | ||
200 | { | ||
201 | static void Postfix(LevelSystems newLevel) | ||
202 | { | ||
203 | Plugin.slotSave.VisitedScenes.Add(newLevel.levelName); | ||
204 | |||
205 | if (GameData.listenersByScene.TryGetValue(newLevel.levelName, out var listeners)) | ||
206 | { | ||
207 | GameState.EvaluateGameStateListeners(listeners); | ||
208 | } | ||
209 | } | ||
210 | } | ||
211 | |||
212 | [HarmonyPatch(typeof(DarkModeCollapsedCubeWorldGrow), nameof(DarkModeCollapsedCubeWorldGrow.OnChainFillComplete))] | ||
213 | static class DarkModeCollapsedCubeWorldGrowOnChainFillCompletePatch | ||
214 | { | ||
215 | static bool Prefix() | ||
216 | { | ||
217 | return false; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | [HarmonyPatch(typeof(DarkModeCollapsedCubeWorldGrow), nameof(DarkModeCollapsedCubeWorldGrow.OnLevelEnable))] | ||
222 | static class DarkModeCollapsedCubeWorldGrowOnLevelEnablePatch | ||
223 | { | ||
224 | static void Prefix(DarkModeCollapsedCubeWorldGrow __instance) | ||
225 | { | ||
226 | SceneItemReference sir = GameState.GetChainListenerSceneReference(__instance); | ||
227 | |||
228 | if (GameData.scenes.TryGetValue(sir.scene, out var sceneDescription) && | ||
229 | sceneDescription.worldGrows.TryGetValue(sir.index, out var requirement) && | ||
230 | requirement.Check()) | ||
231 | { | ||
232 | FieldInfo fieldInfo = typeof(DarkModeCollapsedCubeWorldGrow).GetField("m_grown", BindingFlags.Instance | BindingFlags.NonPublic); | ||
233 | fieldInfo.SetValue(__instance, true); | ||
234 | } | ||
235 | } | ||
236 | } | ||
237 | } | ||