diff options
Diffstat (limited to 'AnodyneArchipelago/Plugin.cs')
-rw-r--r-- | AnodyneArchipelago/Plugin.cs | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/AnodyneArchipelago/Plugin.cs b/AnodyneArchipelago/Plugin.cs index 0bc372b..0fb7b60 100644 --- a/AnodyneArchipelago/Plugin.cs +++ b/AnodyneArchipelago/Plugin.cs | |||
@@ -1,4 +1,5 @@ | |||
1 | using AnodyneSharp; | 1 | using AnodyneArchipelago.Patches; |
2 | using AnodyneSharp; | ||
2 | using AnodyneSharp.Entities; | 3 | using AnodyneSharp.Entities; |
3 | using AnodyneSharp.Entities.Events; | 4 | using AnodyneSharp.Entities.Events; |
4 | using AnodyneSharp.Entities.Gadget; | 5 | using AnodyneSharp.Entities.Gadget; |
@@ -69,10 +70,8 @@ namespace AnodyneArchipelago | |||
69 | { | 70 | { |
70 | static void Prefix(TreasureChest __instance) | 71 | static void Prefix(TreasureChest __instance) |
71 | { | 72 | { |
72 | Type chestType = typeof(TreasureChest); | 73 | string entityId = PatchHelper.GetEntityPreset(typeof(TreasureChest), __instance).EntityID.ToString(); |
73 | FieldInfo presetField = chestType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance); | 74 | Plugin.Instance.Log.LogInfo($"Touched chest: {entityId}"); |
74 | EntityPreset preset = presetField.GetValue(__instance) as EntityPreset; | ||
75 | Plugin.Instance.Log.LogInfo($"Touched chest: {preset.EntityID.ToString()}"); | ||
76 | } | 75 | } |
77 | } | 76 | } |
78 | 77 | ||
@@ -81,15 +80,12 @@ namespace AnodyneArchipelago | |||
81 | { | 80 | { |
82 | static bool Prefix(TreasureChest __instance) | 81 | static bool Prefix(TreasureChest __instance) |
83 | { | 82 | { |
84 | Type chestType = typeof(TreasureChest); | 83 | Guid entityId = PatchHelper.GetEntityPreset(typeof(TreasureChest), __instance).EntityID; |
85 | FieldInfo presetField = chestType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance); | 84 | if (Locations.LocationsByGuid.ContainsKey(entityId)) |
86 | EntityPreset preset = presetField.GetValue(__instance) as EntityPreset; | ||
87 | |||
88 | if (Locations.LocationsByGuid.ContainsKey(preset.EntityID)) | ||
89 | { | 85 | { |
90 | BaseTreasure treasure = new ArchipelagoTreasure(Locations.LocationsByGuid[preset.EntityID], __instance.Position); | 86 | BaseTreasure treasure = new ArchipelagoTreasure(Locations.LocationsByGuid[entityId], __instance.Position); |
91 | 87 | ||
92 | FieldInfo treasureField = chestType.GetField("_treasure", BindingFlags.NonPublic | BindingFlags.Instance); | 88 | FieldInfo treasureField = typeof(TreasureChest).GetField("_treasure", BindingFlags.NonPublic | BindingFlags.Instance); |
93 | treasureField.SetValue(__instance, treasure); | 89 | treasureField.SetValue(__instance, treasure); |
94 | 90 | ||
95 | return false; | 91 | return false; |
@@ -105,15 +101,12 @@ namespace AnodyneArchipelago | |||
105 | // We basically just rewrite this method, because we need to get rid of the part that adds the key to the inventory. | 101 | // We basically just rewrite this method, because we need to get rid of the part that adds the key to the inventory. |
106 | static bool Prefix(Big_Key __instance, ref bool __result) | 102 | static bool Prefix(Big_Key __instance, ref bool __result) |
107 | { | 103 | { |
108 | Type keyType = typeof(Big_Key); | 104 | MethodInfo statesMethod = typeof(Big_Key).GetMethod("States", BindingFlags.NonPublic | BindingFlags.Instance); |
109 | FieldInfo presetField = keyType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance); | ||
110 | EntityPreset preset = presetField.GetValue(__instance) as EntityPreset; | ||
111 | |||
112 | MethodInfo statesMethod = keyType.GetMethod("States", BindingFlags.NonPublic | BindingFlags.Instance); | ||
113 | 105 | ||
106 | EntityPreset preset = PatchHelper.GetEntityPreset(typeof(Big_Key), __instance); | ||
114 | preset.Alive = false; | 107 | preset.Alive = false; |
115 | __instance.Solid = false; | 108 | __instance.Solid = false; |
116 | GlobalState.StartCutscene = (System.Collections.Generic.IEnumerator<AnodyneSharp.States.CutsceneState.CutsceneEvent>)statesMethod.Invoke(__instance, new object[] { }); | 109 | GlobalState.StartCutscene = (IEnumerator<AnodyneSharp.States.CutsceneState.CutsceneEvent>)statesMethod.Invoke(__instance, new object[] { }); |
117 | __result = true; | 110 | __result = true; |
118 | return false; | 111 | return false; |
119 | } | 112 | } |
@@ -124,9 +117,7 @@ namespace AnodyneArchipelago | |||
124 | { | 117 | { |
125 | static void Postfix(Big_Key __instance) | 118 | static void Postfix(Big_Key __instance) |
126 | { | 119 | { |
127 | Type keyType = typeof(Big_Key); | 120 | EntityPreset preset = PatchHelper.GetEntityPreset(typeof(Big_Key), __instance); |
128 | FieldInfo presetField = keyType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance); | ||
129 | EntityPreset preset = presetField.GetValue(__instance) as EntityPreset; | ||
130 | 121 | ||
131 | if (preset.Frame == 0) | 122 | if (preset.Frame == 0) |
132 | { | 123 | { |
@@ -152,9 +143,7 @@ namespace AnodyneArchipelago | |||
152 | FieldInfo childField = hcsType.GetField("_child", BindingFlags.NonPublic | BindingFlags.Instance); | 143 | FieldInfo childField = hcsType.GetField("_child", BindingFlags.NonPublic | BindingFlags.Instance); |
153 | HealthCicada healthCicada = (HealthCicada)childField.GetValue(__instance); | 144 | HealthCicada healthCicada = (HealthCicada)childField.GetValue(__instance); |
154 | 145 | ||
155 | Type cicadaType = typeof(HealthCicada); | 146 | EntityPreset preset = PatchHelper.GetEntityPreset(typeof(HealthCicada), healthCicada); |
156 | FieldInfo presetField = cicadaType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance); | ||
157 | EntityPreset preset = presetField.GetValue(healthCicada) as EntityPreset; | ||
158 | Plugin.Instance.Log.LogInfo($"Touched cicada: {preset.EntityID.ToString()}"); | 147 | Plugin.Instance.Log.LogInfo($"Touched cicada: {preset.EntityID.ToString()}"); |
159 | } | 148 | } |
160 | } | 149 | } |
@@ -184,15 +173,13 @@ namespace AnodyneArchipelago | |||
184 | 173 | ||
185 | static IEnumerator<string> StateLogic(HealthCicada healthCicada) | 174 | static IEnumerator<string> StateLogic(HealthCicada healthCicada) |
186 | { | 175 | { |
187 | Type cicadaType = typeof(HealthCicada); | 176 | EntityPreset preset = PatchHelper.GetEntityPreset(typeof(HealthCicada), healthCicada); |
188 | FieldInfo presetField = cicadaType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance); | ||
189 | EntityPreset preset = presetField.GetValue(healthCicada) as EntityPreset; | ||
190 | 177 | ||
191 | while (!MathUtilities.MoveTo(ref healthCicada.opacity, 0.0f, 0.6f)) | 178 | while (!MathUtilities.MoveTo(ref healthCicada.opacity, 0.0f, 0.6f)) |
192 | yield return "FadingOut"; | 179 | yield return "FadingOut"; |
193 | preset.Alive = false; | 180 | preset.Alive = false; |
194 | 181 | ||
195 | FieldInfo sentinelField = cicadaType.GetField("_sentinel", BindingFlags.NonPublic | BindingFlags.Instance); | 182 | FieldInfo sentinelField = typeof(HealthCicada).GetField("_sentinel", BindingFlags.NonPublic | BindingFlags.Instance); |
196 | HealthCicadaSentinel sentinel = (HealthCicadaSentinel)sentinelField.GetValue(healthCicada); | 183 | HealthCicadaSentinel sentinel = (HealthCicadaSentinel)sentinelField.GetValue(healthCicada); |
197 | 184 | ||
198 | sentinel.exists = false; | 185 | sentinel.exists = false; |
@@ -261,4 +248,29 @@ namespace AnodyneArchipelago | |||
261 | } | 248 | } |
262 | } | 249 | } |
263 | } | 250 | } |
251 | |||
252 | [HarmonyPatch] | ||
253 | class BreakChainPatch | ||
254 | { | ||
255 | static MethodInfo TargetMethod() | ||
256 | { | ||
257 | return typeof(Red_Pillar).GetNestedType("Chain", BindingFlags.NonPublic).GetMethod("Collided"); | ||
258 | } | ||
259 | |||
260 | static void Postfix(object __instance) | ||
261 | { | ||
262 | Type chainType = typeof(Red_Pillar).GetNestedType("Chain", BindingFlags.NonPublic); | ||
263 | FieldInfo parentField = chainType.GetField("_parent", BindingFlags.NonPublic | BindingFlags.Instance); | ||
264 | |||
265 | Red_Pillar redPillar = (Red_Pillar)parentField.GetValue(__instance); | ||
266 | EntityPreset preset = PatchHelper.GetEntityPreset(typeof(Red_Pillar), redPillar); | ||
267 | |||
268 | Plugin.Instance.Log.LogInfo($"Broke red chain: {preset.EntityID.ToString()}"); | ||
269 | |||
270 | if (Locations.LocationsByGuid.ContainsKey(preset.EntityID)) | ||
271 | { | ||
272 | ArchipelagoManager.SendLocation(Locations.LocationsByGuid[preset.EntityID]); | ||
273 | } | ||
274 | } | ||
275 | } | ||
264 | } | 276 | } |