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 12:45:43 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2024-05-22 12:45:43 -0400
commitf717a556a909b831cb6965bcd2f8e057053e5161 (patch)
tree3c4b963dfa517bd79c0a0f5bfa2fb325144217d8 /AnodyneArchipelago/Plugin.cs
parent07ba77d448cc54d4f2b149b31652fff156efdb40 (diff)
downloadanodyne-archipelago-f717a556a909b831cb6965bcd2f8e057053e5161.tar.gz
anodyne-archipelago-f717a556a909b831cb6965bcd2f8e057053e5161.tar.bz2
anodyne-archipelago-f717a556a909b831cb6965bcd2f8e057053e5161.zip
Start sending and receiving items
Diffstat (limited to 'AnodyneArchipelago/Plugin.cs')
-rw-r--r--AnodyneArchipelago/Plugin.cs51
1 files changed, 50 insertions, 1 deletions
diff --git a/AnodyneArchipelago/Plugin.cs b/AnodyneArchipelago/Plugin.cs index 7375503..f49ba35 100644 --- a/AnodyneArchipelago/Plugin.cs +++ b/AnodyneArchipelago/Plugin.cs
@@ -1,7 +1,12 @@
1using BepInEx; 1using AnodyneSharp;
2using AnodyneSharp.Entities;
3using AnodyneSharp.Entities.Gadget;
4using AnodyneSharp.Entities.Gadget.Treasures;
5using BepInEx;
2using BepInEx.NET.Common; 6using BepInEx.NET.Common;
3using HarmonyLib; 7using HarmonyLib;
4using HarmonyLib.Tools; 8using HarmonyLib.Tools;
9using System;
5using System.Reflection; 10using System.Reflection;
6 11
7namespace AnodyneArchipelago 12namespace AnodyneArchipelago
@@ -26,6 +31,15 @@ namespace AnodyneArchipelago
26 } 31 }
27 } 32 }
28 33
34 [HarmonyPatch(typeof(AnodyneGame), "Update")]
35 class GameUpdatePatch
36 {
37 static void Postfix()
38 {
39 ArchipelagoManager.Update();
40 }
41 }
42
29 [HarmonyPatch(typeof(AnodyneSharp.States.PlayState), nameof(AnodyneSharp.States.PlayState.Create))] 43 [HarmonyPatch(typeof(AnodyneSharp.States.PlayState), nameof(AnodyneSharp.States.PlayState.Create))]
30 class PlayStateCreatePatch 44 class PlayStateCreatePatch
31 { 45 {
@@ -36,4 +50,39 @@ namespace AnodyneArchipelago
36 ArchipelagoManager.Connect("localhost:38281", "Anodyne", ""); 50 ArchipelagoManager.Connect("localhost:38281", "Anodyne", "");
37 } 51 }
38 } 52 }
53
54 [HarmonyPatch(typeof(TreasureChest), nameof(TreasureChest.PlayerInteraction))]
55 class ChestInteractPatch
56 {
57 static void Prefix(TreasureChest __instance)
58 {
59 Type chestType = typeof(TreasureChest);
60 FieldInfo presetField = chestType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance);
61 EntityPreset preset = presetField.GetValue(__instance) as EntityPreset;
62 Plugin.Instance.Log.LogInfo($"Touched chest: {preset.EntityID.ToString()}");
63 }
64 }
65
66 [HarmonyPatch(typeof(TreasureChest), "SetTreasure")]
67 class ChestSetTreasurePatch
68 {
69 static bool Prefix(TreasureChest __instance)
70 {
71 Type chestType = typeof(TreasureChest);
72 FieldInfo presetField = chestType.GetField("_preset", BindingFlags.NonPublic | BindingFlags.Instance);
73 EntityPreset preset = presetField.GetValue(__instance) as EntityPreset;
74
75 if (Locations.LocationsByGuid.ContainsKey(preset.EntityID))
76 {
77 BaseTreasure treasure = new ArchipelagoTreasure(Locations.LocationsByGuid[preset.EntityID], __instance.Position);
78
79 FieldInfo treasureField = chestType.GetField("_treasure", BindingFlags.NonPublic | BindingFlags.Instance);
80 treasureField.SetValue(__instance, treasure);
81
82 return false;
83 }
84
85 return true;
86 }
87 }
39} 88}