diff options
-rw-r--r-- | AnodyneArchipelago/ArchipelagoManager.cs | 43 | ||||
-rw-r--r-- | AnodyneArchipelago/Plugin.cs | 24 |
2 files changed, 67 insertions, 0 deletions
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 @@ | |||
1 | using Archipelago.MultiClient.Net; | ||
2 | using Archipelago.MultiClient.Net.Enums; | ||
3 | using System; | ||
4 | |||
5 | namespace AnodyneArchipelago | ||
6 | { | ||
7 | internal class ArchipelagoManager | ||
8 | { | ||
9 | private static ArchipelagoSession _session; | ||
10 | |||
11 | public static void Connect(string url, string slotName, string password) | ||
12 | { | ||
13 | LoginResult result; | ||
14 | try | ||
15 | { | ||
16 | _session = ArchipelagoSessionFactory.CreateSession(url); | ||
17 | result = _session.TryConnectAndLogin("Anodyne", slotName, ItemsHandlingFlags.AllItems, null, null, null, password == "" ? null : password); | ||
18 | } | ||
19 | catch (Exception e) | ||
20 | { | ||
21 | result = new LoginFailure(e.GetBaseException().Message); | ||
22 | } | ||
23 | |||
24 | if (!result.Successful) | ||
25 | { | ||
26 | LoginFailure failure = result as LoginFailure; | ||
27 | string errorMessage = $"Failed to connect to {url} as {slotName}:"; | ||
28 | foreach (string error in failure.Errors) | ||
29 | { | ||
30 | errorMessage += $"\n {error}"; | ||
31 | } | ||
32 | foreach (ConnectionRefusedError error in failure.ErrorCodes) | ||
33 | { | ||
34 | errorMessage += $"\n {error}"; | ||
35 | } | ||
36 | |||
37 | Plugin.Instance.Log.LogError(errorMessage); | ||
38 | |||
39 | return; | ||
40 | } | ||
41 | } | ||
42 | } | ||
43 | } | ||
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 @@ | |||
1 | using BepInEx; | 1 | using BepInEx; |
2 | using BepInEx.NET.Common; | 2 | using BepInEx.NET.Common; |
3 | using HarmonyLib; | ||
4 | using HarmonyLib.Tools; | ||
5 | using System.Reflection; | ||
3 | 6 | ||
4 | namespace AnodyneArchipelago | 7 | namespace AnodyneArchipelago |
5 | { | 8 | { |
6 | [BepInPlugin("com.fourisland.plugins.anodyne.archipelago", "Anodyne Archipelago", "1.0.0.0")] | 9 | [BepInPlugin("com.fourisland.plugins.anodyne.archipelago", "Anodyne Archipelago", "1.0.0.0")] |
7 | public class Plugin : BasePlugin | 10 | public class Plugin : BasePlugin |
8 | { | 11 | { |
12 | public static Plugin Instance = null; | ||
13 | |||
9 | public override void Load() | 14 | public override void Load() |
10 | { | 15 | { |
16 | Instance = this; | ||
17 | |||
11 | // Plugin startup logic | 18 | // Plugin startup logic |
12 | Log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); | 19 | Log.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!"); |
20 | |||
21 | // Make patches | ||
22 | HarmonyFileLog.Enabled = true; | ||
23 | HarmonyFileLog.FileWriterPath = "HarmonyLog.txt"; | ||
24 | |||
25 | Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly()); | ||
26 | } | ||
27 | } | ||
28 | |||
29 | [HarmonyPatch(typeof(AnodyneSharp.States.PlayState), nameof(AnodyneSharp.States.PlayState.Create))] | ||
30 | class PlayStateCreatePatch | ||
31 | { | ||
32 | static void Prefix() | ||
33 | { | ||
34 | Plugin.Instance.Log.LogInfo("Connecting to Archipelago!"); | ||
35 | |||
36 | ArchipelagoManager.Connect("localhost:38281", "Anodyne", ""); | ||
13 | } | 37 | } |
14 | } | 38 | } |
15 | } | 39 | } |