public static void PatchRandoCornifer ( Action <RandomizerAction, string, object> orig, RandomizerAction self, string scene, object changeObj ) { orig(self, scene, changeObj); // This is a call to the originally hooked method to make it run. If you don't do this the original method will never run, which is something BingoUI does not want (but you might) // Below this it's mostly things not related to hooking but to BingoUI execution so I won't bother adding comments. if (!CorniferPositions.Keys.Contains(scene)) { return; } Type createNewShiny = Type.GetType("RandomizerMod.Actions.CreateNewShiny, RandomizerMod3.0"); if (createNewShiny == null) { return; } // ReSharper disable PossibleNullReferenceException float x = (float)createNewShiny.GetField("_x", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(self); float y = (float)createNewShiny.GetField("_y", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(self); // ReSharper enable PossibleNullReferenceException if ((CorniferPositions[scene] - new Vector2(x, y)).magnitude > 3.0f) { return; } BingoUI.Log("Patching rando cornifer"); GameObject cornifer = GameObject.Find ( (string)createNewShiny .GetField("_newShinyName", BindingFlags.NonPublic | BindingFlags.Instance)? .GetValue(self) ); PlayMakerFSM shinyControl = cornifer.LocateMyFSM("Shiny Control"); shinyControl.InsertMethod("Hero Down", 0, () => OnCorniferLocation.Invoke(scene)); }
public static void PatchPlandoCornifer ( Action <ItemChanger.Actions.RandomizerAction, string, object> orig, ItemChanger.Actions.RandomizerAction self, string scene, object changeObj ) { orig(self, scene, changeObj); if (!CorniferPositions.Keys.Contains(scene)) { return; } Type createNewShiny = Type.GetType("ItemChanger.Actions.CreateNewShiny, ItemChanger"); if (createNewShiny == null) { return; } // ReSharper disable once PossibleNullReferenceException float x = (float)createNewShiny.GetField("_x", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(self); // ReSharper disable once PossibleNullReferenceException float y = (float)createNewShiny.GetField("_y", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(self); if ((CorniferPositions[scene] - new Vector2(x, y)).magnitude > 3.0f) { return; } BingoUI.Log("Patching plando cornifer"); GameObject cornifer = GameObject.Find ( (string)createNewShiny .GetField("_newShinyName", BindingFlags.NonPublic | BindingFlags.Instance) ?.GetValue(self) ); PlayMakerFSM shinyControl = cornifer.LocateMyFSM("Shiny Control"); shinyControl.InsertMethod("Hero Down", 0, () => OnCorniferLocation?.Invoke(scene)); }