summary refs log tree commit diff stats
path: root/Plugin.cs
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2025-02-20 21:39:04 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2025-02-20 21:39:04 -0500
commitd1baf62bea385c75ad4e7612e5caa285400ffaa7 (patch)
tree79cc011c17eb3d6d19c1750834d95e4446744a12 /Plugin.cs
parent6ffa77c6a55f181577d1c5dca88c96f9863cca08 (diff)
downloadmanifold-garden-archipelago-d1baf62bea385c75ad4e7612e5caa285400ffaa7.tar.gz
manifold-garden-archipelago-d1baf62bea385c75ad4e7612e5caa285400ffaa7.tar.bz2
manifold-garden-archipelago-d1baf62bea385c75ad4e7612e5caa285400ffaa7.zip
Opening a door via an item!
Diffstat (limited to 'Plugin.cs')
-rw-r--r--Plugin.cs74
1 files changed, 74 insertions, 0 deletions
diff --git a/Plugin.cs b/Plugin.cs index 5f49f5f..50e6e2b 100644 --- a/Plugin.cs +++ b/Plugin.cs
@@ -1,5 +1,8 @@
1using BepInEx; 1using BepInEx;
2using BepInEx.Logging; 2using BepInEx.Logging;
3using HarmonyLib;
4using System.Linq;
5using System.Reflection;
3 6
4namespace ManifoldGardenArchipelago 7namespace ManifoldGardenArchipelago
5{ 8{
@@ -8,11 +11,82 @@ namespace ManifoldGardenArchipelago
8 { 11 {
9 internal static new ManualLogSource Logger; 12 internal static new ManualLogSource Logger;
10 13
14 public static ArchipelagoManager archipelagoManager = new();
15
11 private void Awake() 16 private void Awake()
12 { 17 {
13 // Plugin startup logic 18 // Plugin startup logic
14 Logger = base.Logger; 19 Logger = base.Logger;
15 Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!"); 20 Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
21
22 Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
23
24 archipelagoManager.Connect("localhost:38281", "Manifold", "").RunSynchronously();
25 }
26 }
27
28 [HarmonyPatch(typeof(GameManager), "Update")]
29 static class GameManagerUpdatePatch
30 {
31 static void Postfix()
32 {
33 Plugin.archipelagoManager.Update();
16 } 34 }
17 } 35 }
36
37 [HarmonyPatch(typeof(LineDoorController), "SetDoorOpenCloseStateAnimated")]
38 static class LineDoorControllerSetDoorOpenCloseStateAnimatedPatch
39 {
40 static bool Prefix(LineDoorController __instance, bool open)
41 {
42 if (Plugin.archipelagoManager.chainListenersByScene.TryGetValue(__instance.gameObject.scene.name, out var activatedChainListeners))
43 {
44 LevelSystems levelSystem = __instance.gameObject.scene.GetRootGameObjects().Single((obj) => obj.name == "Level Systems").GetComponent<LevelSystems>();
45
46 foreach (var listener in activatedChainListeners)
47 {
48 if (levelSystem.chainListeners[listener.Key] == __instance)
49 {
50 if (open != listener.Value)
51 {
52 return false;
53 }
54 }
55 }
56 }
57
58 return true;
59 }
60 }
61
62 [HarmonyPatch(typeof(LineDoorController), nameof(LineDoorController.OnLevelEnable))]
63 static class LineDoorControllerOnLevelEnablePatch
64 {
65 static void Prefix(LineDoorController __instance)
66 {
67 if (Plugin.archipelagoManager.chainListenersByScene.TryGetValue(__instance.gameObject.scene.name, out var activatedChainListeners))
68 {
69 LevelSystems levelSystem = __instance.gameObject.scene.GetRootGameObjects().Single((obj) => obj.name == "Level Systems").GetComponent<LevelSystems>();
70
71 foreach (var listener in activatedChainListeners)
72 {
73 if (levelSystem.chainListeners[listener.Key] == __instance)
74 {
75 FieldInfo fieldInfo = typeof(LineDoorController).GetField("doorShouldOpenImmediatelyOnEnable", BindingFlags.Instance | BindingFlags.NonPublic);
76 fieldInfo.SetValue(__instance, listener.Value);
77 }
78 }
79 }
80 }
81 }
82
83 [HarmonyPatch(typeof(ButtonLineActivator), nameof(ButtonLineActivator.OnInteract))]
84 static class ButtonLineActivatorOnInteractPatch
85 {
86 public static void Postfix(ButtonLineActivator __instance)
87 {
88 Plugin.Logger.LogInfo($"Interacted with {__instance.name} in {__instance.gameObject.scene.name}: {__instance.isButtonPressed}");
89 }
90 }
91
18} 92}