about summary refs log tree commit diff stats
path: root/AnodyneArchipelago/Plugin.cs
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2024-05-22 13:57:28 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-05-22 13:57:28 -0400
commitf6bf7b8576a6c2a7d89d463b4998c44324d6d370 (patch)
treead8a8aab9c659ade37bdf5cb6e686d7e2fc6efd6 /AnodyneArchipelago/Plugin.cs
parentf717a556a909b831cb6965bcd2f8e057053e5161 (diff)
downloadanodyne-archipelago-f6bf7b8576a6c2a7d89d463b4998c44324d6d370.tar.gz
anodyne-archipelago-f6bf7b8576a6c2a7d89d463b4998c44324d6d370.tar.bz2
anodyne-archipelago-f6bf7b8576a6c2a7d89d463b4998c44324d6d370.zip
More stuff!
Big keys are now locations. Health cicadas work now, both as locations and items. The two checks in the Street now also give their vanilla items.
Diffstat (limited to 'AnodyneArchipelago/Plugin.cs')
-rw-r--r--AnodyneArchipelago/Plugin.cs108
1 files changed, 108 insertions, 0 deletions
diff --git a/AnodyneArchipelago/Plugin.cs b/AnodyneArchipelago/Plugin.cs index f49ba35..d40da7c 100644 --- a/AnodyneArchipelago/Plugin.cs +++ b/AnodyneArchipelago/Plugin.cs
@@ -2,11 +2,16 @@
2using AnodyneSharp.Entities; 2using AnodyneSharp.Entities;
3using AnodyneSharp.Entities.Gadget; 3using AnodyneSharp.Entities.Gadget;
4using AnodyneSharp.Entities.Gadget.Treasures; 4using AnodyneSharp.Entities.Gadget.Treasures;
5using AnodyneSharp.Entities.Interactive;
6using AnodyneSharp.Registry;
7using AnodyneSharp.Utilities;
5using BepInEx; 8using BepInEx;
6using BepInEx.NET.Common; 9using BepInEx.NET.Common;
7using HarmonyLib; 10using HarmonyLib;
8using HarmonyLib.Tools; 11using HarmonyLib.Tools;
9using System; 12using System;
13using System.Collections;
14using System.Collections.Generic;
10using System.Reflection; 15using System.Reflection;
11 16
12namespace AnodyneArchipelago 17namespace AnodyneArchipelago
@@ -85,4 +90,107 @@ namespace AnodyneArchipelago
85 return true; 90 return true;
86 } 91 }
87 } 92 }
93
94 [HarmonyPatch(typeof(Big_Key), nameof(Big_Key.PlayerInteraction))]
95 class BigKeyTouchPatch
96 {
97 // We basically just rewrite this method, because we need to get rid of the part that adds the key to the inventory.
98 static bool Prefix(Big_Key __instance, ref bool __result)
99 {
100 Type keyType = typeof(Big_Key);
101 FieldInfo presetField = keyType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance);
102 EntityPreset preset = presetField.GetValue(__instance) as EntityPreset;
103
104 MethodInfo statesMethod = keyType.GetMethod("States", BindingFlags.NonPublic | BindingFlags.Instance);
105
106 preset.Alive = false;
107 __instance.Solid = false;
108 GlobalState.StartCutscene = (System.Collections.Generic.IEnumerator<AnodyneSharp.States.CutsceneState.CutsceneEvent>)statesMethod.Invoke(__instance, new object[] { });
109 __result = true;
110 return false;
111 }
112 }
113
114 [HarmonyPatch(typeof(Big_Key), "States")]
115 class BigKeyStatesPatch
116 {
117 static void Postfix(Big_Key __instance)
118 {
119 Type keyType = typeof(Big_Key);
120 FieldInfo presetField = keyType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance);
121 EntityPreset preset = presetField.GetValue(__instance) as EntityPreset;
122
123 if (preset.Frame == 0)
124 {
125 ArchipelagoManager.SendLocation("Temple of the Seeing One - Green Key");
126 } else if (preset.Frame == 1)
127 {
128 ArchipelagoManager.SendLocation("Red Grotto - Red Key");
129 } else if (preset.Frame == 2)
130 {
131 ArchipelagoManager.SendLocation("Mountain Cavern - Blue Key");
132 }
133 }
134 }
135
136 [HarmonyPatch(typeof(HealthCicadaSentinel), nameof(HealthCicadaSentinel.Collided))]
137 class HealthCicadaInteractPatch
138 {
139 static void Prefix(TreasureChest __instance)
140 {
141 Type hcsType = typeof(HealthCicadaSentinel);
142 FieldInfo childField = hcsType.GetField("_child", BindingFlags.NonPublic | BindingFlags.Instance);
143 HealthCicada healthCicada = (HealthCicada)childField.GetValue(__instance);
144
145 Type cicadaType = typeof(HealthCicada);
146 FieldInfo presetField = cicadaType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance);
147 EntityPreset preset = presetField.GetValue(healthCicada) as EntityPreset;
148 Plugin.Instance.Log.LogInfo($"Touched cicada: {preset.EntityID.ToString()}");
149 }
150 }
151
152 [HarmonyPatch(typeof(HealthCicada), nameof(HealthCicada.Update))]
153 class HealthCicadaUpdatePatch
154 {
155 static void Postfix(HealthCicada __instance)
156 {
157 Type cicadaType = typeof(HealthCicada);
158 FieldInfo chirpField = cicadaType.GetField("_chirp", BindingFlags.NonPublic | BindingFlags.Instance);
159 FieldInfo sentinelField = cicadaType.GetField("_sentinel", BindingFlags.NonPublic | BindingFlags.Instance);
160
161 HealthCicadaSentinel sentinel = (HealthCicadaSentinel)sentinelField.GetValue(__instance);
162 Type hcsType = typeof(HealthCicadaSentinel);
163 FieldInfo flyDistanceField = hcsType.GetField("_flyDistance", BindingFlags.NonPublic | BindingFlags.Instance);
164 float flyDistance = (float)flyDistanceField.GetValue(sentinel);
165
166 if (__instance.visible && !(bool)chirpField.GetValue(__instance) && flyDistance > 0)
167 {
168 flyDistanceField.SetValue(sentinel, 0f);
169
170 FieldInfo stateField = cicadaType.GetField("_state", BindingFlags.NonPublic | BindingFlags.Instance);
171 stateField.SetValue(__instance, StateLogic(__instance));
172 }
173 }
174
175 static IEnumerator<string> StateLogic(HealthCicada healthCicada)
176 {
177 Type cicadaType = typeof(HealthCicada);
178 FieldInfo presetField = cicadaType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance);
179 EntityPreset preset = presetField.GetValue(healthCicada) as EntityPreset;
180
181 while (!MathUtilities.MoveTo(ref healthCicada.opacity, 0.0f, 0.6f))
182 yield return "FadingOut";
183 preset.Alive = false;
184
185 FieldInfo sentinelField = cicadaType.GetField("_sentinel", BindingFlags.NonPublic | BindingFlags.Instance);
186 HealthCicadaSentinel sentinel = (HealthCicadaSentinel)sentinelField.GetValue(healthCicada);
187
188 sentinel.exists = false;
189
190 if (Locations.LocationsByGuid.ContainsKey(preset.EntityID))
191 {
192 ArchipelagoManager.SendLocation(Locations.LocationsByGuid[preset.EntityID]);
193 }
194 }
195 }
88} 196}