diff options
| author | Star Rauchenberger <fefferburbia@gmail.com> | 2024-05-22 12:45:43 -0400 |
|---|---|---|
| committer | Star Rauchenberger <fefferburbia@gmail.com> | 2024-05-22 12:45:43 -0400 |
| commit | f717a556a909b831cb6965bcd2f8e057053e5161 (patch) | |
| tree | 3c4b963dfa517bd79c0a0f5bfa2fb325144217d8 /AnodyneArchipelago/Plugin.cs | |
| parent | 07ba77d448cc54d4f2b149b31652fff156efdb40 (diff) | |
| download | anodyne-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.cs | 51 |
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 @@ | |||
| 1 | using BepInEx; | 1 | using AnodyneSharp; |
| 2 | using AnodyneSharp.Entities; | ||
| 3 | using AnodyneSharp.Entities.Gadget; | ||
| 4 | using AnodyneSharp.Entities.Gadget.Treasures; | ||
| 5 | using BepInEx; | ||
| 2 | using BepInEx.NET.Common; | 6 | using BepInEx.NET.Common; |
| 3 | using HarmonyLib; | 7 | using HarmonyLib; |
| 4 | using HarmonyLib.Tools; | 8 | using HarmonyLib.Tools; |
| 9 | using System; | ||
| 5 | using System.Reflection; | 10 | using System.Reflection; |
| 6 | 11 | ||
| 7 | namespace AnodyneArchipelago | 12 | namespace 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 | } |
