using BepInEx; using BepInEx.Logging; using HarmonyLib; using System.Linq; using System.Reflection; namespace ManifoldGardenArchipelago { [BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)] public class Plugin : BaseUnityPlugin { internal static new ManualLogSource Logger; public static ArchipelagoManager archipelagoManager = new(); private void Awake() { // Plugin startup logic Logger = base.Logger; Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!"); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly()); archipelagoManager.Connect("localhost:38281", "Manifold", "").RunSynchronously(); } } [HarmonyPatch(typeof(GameManager), "Update")] static class GameManagerUpdatePatch { static void Postfix() { Plugin.archipelagoManager.Update(); } } [HarmonyPatch(typeof(LineDoorController), "SetDoorOpenCloseStateAnimated")] static class LineDoorControllerSetDoorOpenCloseStateAnimatedPatch { static bool Prefix(LineDoorController __instance, bool open) { if (Plugin.archipelagoManager.chainListenersByScene.TryGetValue(__instance.gameObject.scene.name, out var activatedChainListeners)) { LevelSystems levelSystem = __instance.gameObject.scene.GetRootGameObjects().Single((obj) => obj.name == "Level Systems").GetComponent(); foreach (var listener in activatedChainListeners) { if (levelSystem.chainListeners[listener.Key] == __instance) { if (open != listener.Value) { return false; } } } } return true; } } [HarmonyPatch(typeof(LineDoorController), nameof(LineDoorController.OnLevelEnable))] static class LineDoorControllerOnLevelEnablePatch { static void Prefix(LineDoorController __instance) { if (Plugin.archipelagoManager.chainListenersByScene.TryGetValue(__instance.gameObject.scene.name, out var activatedChainListeners)) { LevelSystems levelSystem = __instance.gameObject.scene.GetRootGameObjects().Single((obj) => obj.name == "Level Systems").GetComponent(); foreach (var listener in activatedChainListeners) { if (levelSystem.chainListeners[listener.Key] == __instance) { FieldInfo fieldInfo = typeof(LineDoorController).GetField("doorShouldOpenImmediatelyOnEnable", BindingFlags.Instance | BindingFlags.NonPublic); fieldInfo.SetValue(__instance, listener.Value); } } } } } [HarmonyPatch(typeof(ButtonLineActivator), nameof(ButtonLineActivator.OnInteract))] static class ButtonLineActivatorOnInteractPatch { public static void Postfix(ButtonLineActivator __instance) { Plugin.Logger.LogInfo($"Interacted with {__instance.name} in {__instance.gameObject.scene.name}: {__instance.isButtonPressed}"); } } }