From 07ba77d448cc54d4f2b149b31652fff156efdb40 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 22 May 2024 10:35:42 -0400 Subject: It can connect! --- AnodyneArchipelago/ArchipelagoManager.cs | 43 ++++++++++++++++++++++++++++++++ AnodyneArchipelago/Plugin.cs | 24 ++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 AnodyneArchipelago/ArchipelagoManager.cs diff --git a/AnodyneArchipelago/ArchipelagoManager.cs b/AnodyneArchipelago/ArchipelagoManager.cs new file mode 100644 index 0000000..8c107a3 --- /dev/null +++ b/AnodyneArchipelago/ArchipelagoManager.cs @@ -0,0 +1,43 @@ +using Archipelago.MultiClient.Net; +using Archipelago.MultiClient.Net.Enums; +using System; + +namespace AnodyneArchipelago +{ + internal class ArchipelagoManager + { + private static ArchipelagoSession _session; + + public static void Connect(string url, string slotName, string password) + { + LoginResult result; + try + { + _session = ArchipelagoSessionFactory.CreateSession(url); + result = _session.TryConnectAndLogin("Anodyne", slotName, ItemsHandlingFlags.AllItems, null, null, null, password == "" ? null : password); + } + catch (Exception e) + { + result = new LoginFailure(e.GetBaseException().Message); + } + + if (!result.Successful) + { + LoginFailure failure = result as LoginFailure; + string errorMessage = $"Failed to connect to {url} as {slotName}:"; + foreach (string error in failure.Errors) + { + errorMessage += $"\n {error}"; + } + foreach (ConnectionRefusedError error in failure.ErrorCodes) + { + errorMessage += $"\n {error}"; + } + + Plugin.Instance.Log.LogError(errorMessage); + + return; + } + } + } +} diff --git a/AnodyneArchipelago/Plugin.cs b/AnodyneArchipelago/Plugin.cs index 411a2a4..7375503 100644 --- a/AnodyneArchipelago/Plugin.cs +++ b/AnodyneArchipelago/Plugin.cs @@ -1,15 +1,39 @@ using BepInEx; using BepInEx.NET.Common; +using HarmonyLib; +using HarmonyLib.Tools; +using System.Reflection; namespace AnodyneArchipelago { [BepInPlugin("com.fourisland.plugins.anodyne.archipelago", "Anodyne Archipelago", "1.0.0.0")] public class Plugin : BasePlugin { + public static Plugin Instance = null; + public override void Load() { + Instance = this; + // Plugin startup logic Log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); + + // Make patches + HarmonyFileLog.Enabled = true; + HarmonyFileLog.FileWriterPath = "HarmonyLog.txt"; + + Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly()); + } + } + + [HarmonyPatch(typeof(AnodyneSharp.States.PlayState), nameof(AnodyneSharp.States.PlayState.Create))] + class PlayStateCreatePatch + { + static void Prefix() + { + Plugin.Instance.Log.LogInfo("Connecting to Archipelago!"); + + ArchipelagoManager.Connect("localhost:38281", "Anodyne", ""); } } } -- cgit 1.4.1