diff options
Diffstat (limited to 'GameplayPatches.cs')
-rw-r--r-- | GameplayPatches.cs | 195 |
1 files changed, 151 insertions, 44 deletions
diff --git a/GameplayPatches.cs b/GameplayPatches.cs index c21bf97..3090a98 100644 --- a/GameplayPatches.cs +++ b/GameplayPatches.cs | |||
@@ -1,5 +1,6 @@ | |||
1 | using HarmonyLib; | 1 | using HarmonyLib; |
2 | using System.Reflection; | 2 | using System.Reflection; |
3 | using UnityEngine; | ||
3 | 4 | ||
4 | namespace ManifoldGardenArchipelago | 5 | namespace ManifoldGardenArchipelago |
5 | { | 6 | { |
@@ -14,9 +15,16 @@ namespace ManifoldGardenArchipelago | |||
14 | { | 15 | { |
15 | if (sceneDescription.doors.TryGetValue(sir.index, out var requirement)) | 16 | if (sceneDescription.doors.TryGetValue(sir.index, out var requirement)) |
16 | { | 17 | { |
17 | if (open != requirement.Check()) | 18 | Requirement.Decision decision = requirement.Check(); |
19 | |||
20 | if (decision != Requirement.Decision.Maybe) | ||
18 | { | 21 | { |
19 | return false; | 22 | bool shouldOpen = (decision == Requirement.Decision.Yes); |
23 | |||
24 | if (open != shouldOpen) | ||
25 | { | ||
26 | return false; | ||
27 | } | ||
20 | } | 28 | } |
21 | } | 29 | } |
22 | } | 30 | } |
@@ -38,15 +46,27 @@ namespace ManifoldGardenArchipelago | |||
38 | return; | 46 | return; |
39 | } | 47 | } |
40 | 48 | ||
41 | if (setPressed) | 49 | Plugin.slotSave.ActivatedButtons[sir] = setPressed; |
42 | { | 50 | |
43 | Plugin.slotSave.ActivatedButtons.Add(sir); | 51 | GameState.EvaluateGameStateListeners(listeners); |
44 | } | 52 | } |
45 | else | 53 | } |
54 | |||
55 | [HarmonyPatch(typeof(ButtonLineActivator), "ForceButtonPressedImmediately")] | ||
56 | static class ButtonLineActivatorForceButtonPressedImmediatelyPatch | ||
57 | { | ||
58 | static void Prefix(ButtonLineActivator __instance, bool _pressed) | ||
59 | { | ||
60 | SceneItemReference sir = GameState.GetButtonSceneReference(__instance); | ||
61 | Plugin.Logger.LogInfo($"Button {sir} forced state {_pressed}"); | ||
62 | |||
63 | if (!GameData.listenersByButton.TryGetValue(sir, out GameStateListeners listeners)) | ||
46 | { | 64 | { |
47 | Plugin.slotSave.ActivatedButtons.Remove(sir); | 65 | return; |
48 | } | 66 | } |
49 | 67 | ||
68 | Plugin.slotSave.ActivatedButtons[sir] = _pressed; | ||
69 | |||
50 | GameState.EvaluateGameStateListeners(listeners); | 70 | GameState.EvaluateGameStateListeners(listeners); |
51 | } | 71 | } |
52 | } | 72 | } |
@@ -64,14 +84,7 @@ namespace ManifoldGardenArchipelago | |||
64 | return; | 84 | return; |
65 | } | 85 | } |
66 | 86 | ||
67 | if (active) | 87 | Plugin.slotSave.ActivatedSockets[sir] = active; |
68 | { | ||
69 | Plugin.slotSave.ActivatedSockets.Add(sir); | ||
70 | } | ||
71 | else | ||
72 | { | ||
73 | Plugin.slotSave.ActivatedSockets.Remove(sir); | ||
74 | } | ||
75 | 88 | ||
76 | GameState.EvaluateGameStateListeners(listeners); | 89 | GameState.EvaluateGameStateListeners(listeners); |
77 | } | 90 | } |
@@ -90,15 +103,46 @@ namespace ManifoldGardenArchipelago | |||
90 | return; | 103 | return; |
91 | } | 104 | } |
92 | 105 | ||
93 | if (setActive) | 106 | Plugin.slotSave.ActivatedPads[sir] = setActive; |
107 | |||
108 | GameState.EvaluateGameStateListeners(listeners); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | [HarmonyPatch(typeof(CubeLineActivator), "ForceActivatorToTurnOnAsCorrectCubeOnSwitch")] | ||
113 | static class CubeLineActivatorForceActivatorToTurnOnAsCorrectCubeOnSwitchPatch | ||
114 | { | ||
115 | static void Prefix(CubeLineActivator __instance) | ||
116 | { | ||
117 | SceneItemReference sir = GameState.GetPadSceneReference(__instance); | ||
118 | Plugin.Logger.LogInfo($"Pad {sir} forced on"); | ||
119 | |||
120 | if (!GameData.listenersByPad.TryGetValue(sir, out GameStateListeners listeners)) | ||
94 | { | 121 | { |
95 | Plugin.slotSave.ActivatedPads.Add(sir); | 122 | return; |
96 | } | 123 | } |
97 | else | 124 | |
125 | Plugin.slotSave.ActivatedPads[sir] = true; | ||
126 | |||
127 | GameState.EvaluateGameStateListeners(listeners); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | [HarmonyPatch(typeof(CubeLineActivator), "ForceActivatorToTurnOffAsCorrectCubeNotOnSwitch")] | ||
132 | static class CubeLineActivatorForceActivatorToTurnOffAsCorrectCubeNotOnSwitchPatch | ||
133 | { | ||
134 | static void Prefix(CubeLineActivator __instance) | ||
135 | { | ||
136 | SceneItemReference sir = GameState.GetPadSceneReference(__instance); | ||
137 | Plugin.Logger.LogInfo($"Pad {sir} forced off"); | ||
138 | |||
139 | if (!GameData.listenersByPad.TryGetValue(sir, out GameStateListeners listeners)) | ||
98 | { | 140 | { |
99 | Plugin.slotSave.ActivatedPads.Remove(sir); | 141 | return; |
100 | } | 142 | } |
101 | 143 | ||
144 | Plugin.slotSave.ActivatedPads[sir] = false; | ||
145 | |||
102 | GameState.EvaluateGameStateListeners(listeners); | 146 | GameState.EvaluateGameStateListeners(listeners); |
103 | } | 147 | } |
104 | } | 148 | } |
@@ -109,21 +153,14 @@ namespace ManifoldGardenArchipelago | |||
109 | static void Prefix(WaterDetector __instance, bool setActive) | 153 | static void Prefix(WaterDetector __instance, bool setActive) |
110 | { | 154 | { |
111 | SceneItemReference sir = GameState.GetWaterwheelSceneReference(__instance); | 155 | SceneItemReference sir = GameState.GetWaterwheelSceneReference(__instance); |
112 | Plugin.Logger.LogInfo($"Waterwheel {sir} state {setActive}"); | 156 | //Plugin.Logger.LogInfo($"Waterwheel {sir} state {setActive}"); |
113 | 157 | ||
114 | if (!GameData.listenersByWaterwheel.TryGetValue(sir, out GameStateListeners listeners)) | 158 | if (!GameData.listenersByWaterwheel.TryGetValue(sir, out GameStateListeners listeners)) |
115 | { | 159 | { |
116 | return; | 160 | return; |
117 | } | 161 | } |
118 | 162 | ||
119 | if (setActive) | 163 | Plugin.slotSave.ActivatedWaterwheels[sir] = setActive; |
120 | { | ||
121 | Plugin.slotSave.ActivatedWaterwheels.Add(sir); | ||
122 | } | ||
123 | else | ||
124 | { | ||
125 | Plugin.slotSave.ActivatedWaterwheels.Remove(sir); | ||
126 | } | ||
127 | 164 | ||
128 | GameState.EvaluateGameStateListeners(listeners); | 165 | GameState.EvaluateGameStateListeners(listeners); |
129 | } | 166 | } |
@@ -142,14 +179,7 @@ namespace ManifoldGardenArchipelago | |||
142 | return; | 179 | return; |
143 | } | 180 | } |
144 | 181 | ||
145 | if (newState == SphereController.State.AtDestination) | 182 | Plugin.slotSave.ActivatedSpheres[sir] = (newState == SphereController.State.AtDestination); |
146 | { | ||
147 | Plugin.slotSave.ActivatedSpheres.Add(sir); | ||
148 | } | ||
149 | else | ||
150 | { | ||
151 | Plugin.slotSave.ActivatedSpheres.Remove(sir); | ||
152 | } | ||
153 | 183 | ||
154 | GameState.EvaluateGameStateListeners(listeners); | 184 | GameState.EvaluateGameStateListeners(listeners); |
155 | } | 185 | } |
@@ -166,10 +196,22 @@ namespace ManifoldGardenArchipelago | |||
166 | { | 196 | { |
167 | if (sceneDescription.doors.TryGetValue(sir.index, out var requirement)) | 197 | if (sceneDescription.doors.TryGetValue(sir.index, out var requirement)) |
168 | { | 198 | { |
169 | FieldInfo fieldInfo = typeof(LineDoorController).GetField("doorShouldOpenImmediatelyOnEnable", BindingFlags.Instance | BindingFlags.NonPublic); | 199 | Requirement.Decision decision = requirement.Check(); |
170 | fieldInfo.SetValue(__instance, requirement.Check()); | 200 | |
201 | if (decision != Requirement.Decision.Maybe) | ||
202 | { | ||
203 | bool shouldOpen = (decision == Requirement.Decision.Yes); | ||
204 | |||
205 | FieldInfo fieldInfo = typeof(LineDoorController).GetField("doorShouldOpenImmediatelyOnEnable", BindingFlags.Instance | BindingFlags.NonPublic); | ||
206 | fieldInfo.SetValue(__instance, shouldOpen); | ||
207 | |||
208 | FieldInfo animatorInfo = typeof(LineDoorController).GetField("m_animator", BindingFlags.Instance | BindingFlags.NonPublic); | ||
209 | Animator animator = (Animator)animatorInfo.GetValue(__instance); | ||
210 | |||
211 | AnimatorExt.PlayDoorStateThenDisable(animator, __instance.DoorOpenAnimationString, shouldOpen ? 1f : -1f, true); | ||
171 | 212 | ||
172 | __instance.chains.Clear(); | 213 | __instance.chains.Clear(); |
214 | } | ||
173 | } | 215 | } |
174 | } | 216 | } |
175 | } | 217 | } |
@@ -180,16 +222,32 @@ namespace ManifoldGardenArchipelago | |||
180 | { | 222 | { |
181 | static void Prefix(LineDoorController __instance) | 223 | static void Prefix(LineDoorController __instance) |
182 | { | 224 | { |
225 | //Plugin.Logger.LogInfo("LineDoorControllerOnLoadPatch entered"); | ||
183 | SceneItemReference sir = GameState.GetChainListenerSceneReference(__instance); | 226 | SceneItemReference sir = GameState.GetChainListenerSceneReference(__instance); |
227 | //Plugin.Logger.LogInfo($"Got sir {sir}"); | ||
184 | 228 | ||
185 | if (GameData.scenes.TryGetValue(sir.scene, out var sceneDescription)) | 229 | if (GameData.scenes.TryGetValue(sir.scene, out var sceneDescription)) |
186 | { | 230 | { |
231 | //Plugin.Logger.LogInfo($"{sceneDescription.doors.Count} doors in scene"); | ||
187 | if (sceneDescription.doors.TryGetValue(sir.index, out var requirement)) | 232 | if (sceneDescription.doors.TryGetValue(sir.index, out var requirement)) |
188 | { | 233 | { |
189 | FieldInfo fieldInfo = typeof(LineDoorController).GetField("doorShouldOpenImmediatelyOnEnable", BindingFlags.Instance | BindingFlags.NonPublic); | 234 | //Plugin.Logger.LogInfo($"Found req {requirement}"); |
190 | fieldInfo.SetValue(__instance, requirement.Check()); | 235 | Requirement.Decision decision = requirement.Check(); |
236 | |||
237 | if (decision != Requirement.Decision.Maybe) | ||
238 | { | ||
239 | bool shouldOpen = (decision == Requirement.Decision.Yes); | ||
240 | |||
241 | FieldInfo fieldInfo = typeof(LineDoorController).GetField("doorShouldOpenImmediatelyOnEnable", BindingFlags.Instance | BindingFlags.NonPublic); | ||
242 | fieldInfo.SetValue(__instance, shouldOpen); | ||
243 | |||
244 | FieldInfo animatorInfo = typeof(LineDoorController).GetField("m_animator", BindingFlags.Instance | BindingFlags.NonPublic); | ||
245 | Animator animator = (Animator)animatorInfo.GetValue(__instance); | ||
246 | |||
247 | AnimatorExt.PlayDoorStateThenDisable(animator, __instance.DoorOpenAnimationString, shouldOpen ? 1f : -1f, true); | ||
191 | 248 | ||
192 | __instance.chains.Clear(); | 249 | __instance.chains.Clear(); |
250 | } | ||
193 | } | 251 | } |
194 | } | 252 | } |
195 | } | 253 | } |
@@ -204,6 +262,7 @@ namespace ManifoldGardenArchipelago | |||
204 | 262 | ||
205 | if (GameData.listenersByScene.TryGetValue(newLevel.levelName, out var listeners)) | 263 | if (GameData.listenersByScene.TryGetValue(newLevel.levelName, out var listeners)) |
206 | { | 264 | { |
265 | Plugin.Logger.LogInfo($"Evaluating for scene {newLevel.levelName}"); | ||
207 | GameState.EvaluateGameStateListeners(listeners); | 266 | GameState.EvaluateGameStateListeners(listeners); |
208 | } | 267 | } |
209 | } | 268 | } |
@@ -227,7 +286,7 @@ namespace ManifoldGardenArchipelago | |||
227 | 286 | ||
228 | if (GameData.scenes.TryGetValue(sir.scene, out var sceneDescription) && | 287 | if (GameData.scenes.TryGetValue(sir.scene, out var sceneDescription) && |
229 | sceneDescription.worldGrows.TryGetValue(sir.index, out var requirement) && | 288 | sceneDescription.worldGrows.TryGetValue(sir.index, out var requirement) && |
230 | requirement.Check()) | 289 | requirement.Check() == Requirement.Decision.Yes) |
231 | { | 290 | { |
232 | FieldInfo fieldInfo = typeof(DarkModeCollapsedCubeWorldGrow).GetField("m_grown", BindingFlags.Instance | BindingFlags.NonPublic); | 291 | FieldInfo fieldInfo = typeof(DarkModeCollapsedCubeWorldGrow).GetField("m_grown", BindingFlags.Instance | BindingFlags.NonPublic); |
233 | fieldInfo.SetValue(__instance, true); | 292 | fieldInfo.SetValue(__instance, true); |
@@ -235,6 +294,54 @@ namespace ManifoldGardenArchipelago | |||
235 | } | 294 | } |
236 | } | 295 | } |
237 | 296 | ||
297 | [HarmonyPatch(typeof(SolidStateController), nameof(SolidStateController.OnChainFillComplete))] | ||
298 | static class SolidStateControllerOnChainFillCompletePatch | ||
299 | { | ||
300 | static bool Prefix(SolidStateController __instance) | ||
301 | { | ||
302 | SceneItemReference sir = GameState.GetChainListenerSceneReference(__instance); | ||
303 | |||
304 | if (GameData.scenes.TryGetValue(sir.scene, out var sceneDescription)) | ||
305 | { | ||
306 | if (sceneDescription.smokeWalls.TryGetValue(sir.index, out var requirement)) | ||
307 | { | ||
308 | Requirement.Decision decision = requirement.Check(); | ||
309 | |||
310 | if (decision == Requirement.Decision.No) | ||
311 | { | ||
312 | return false; | ||
313 | } | ||
314 | } | ||
315 | } | ||
316 | |||
317 | return true; | ||
318 | } | ||
319 | } | ||
320 | |||
321 | [HarmonyPatch(typeof(SolidStateController), nameof(SolidStateController.OnUnfilled))] | ||
322 | static class SolidStateControllerOnUnfilledPatch | ||
323 | { | ||
324 | static bool Prefix(SolidStateController __instance) | ||
325 | { | ||
326 | SceneItemReference sir = GameState.GetChainListenerSceneReference(__instance); | ||
327 | |||
328 | if (GameData.scenes.TryGetValue(sir.scene, out var sceneDescription)) | ||
329 | { | ||
330 | if (sceneDescription.smokeWalls.TryGetValue(sir.index, out var requirement)) | ||
331 | { | ||
332 | Requirement.Decision decision = requirement.Check(); | ||
333 | |||
334 | if (decision == Requirement.Decision.Yes) | ||
335 | { | ||
336 | return false; | ||
337 | } | ||
338 | } | ||
339 | } | ||
340 | |||
341 | return true; | ||
342 | } | ||
343 | } | ||
344 | |||
238 | [HarmonyPatch(typeof(DarkModeCollider), nameof(DarkModeCollider.OnLevelUpdate))] | 345 | [HarmonyPatch(typeof(DarkModeCollider), nameof(DarkModeCollider.OnLevelUpdate))] |
239 | static class DarkModeColliderOnLevelUpdatePatch | 346 | static class DarkModeColliderOnLevelUpdatePatch |
240 | { | 347 | { |