From 3df389e9beb6b73d0f1a68475a112fb9c3e65b72 Mon Sep 17 00:00:00 2001
From: Star Rauchenberger <fefferburbia@gmail.com>
Date: Sun, 26 May 2024 11:17:52 -0400
Subject: Honor endgame_card_requirement value

---
 AnodyneArchipelago/ArchipelagoManager.cs      |  9 +++++++++
 AnodyneArchipelago/Menu/ConnectionState.cs    | 10 ++++++++++
 AnodyneArchipelago/Menu/MenuState.cs          |  6 +++++-
 AnodyneArchipelago/Patches/GameplayPatches.cs |  9 +++++++++
 4 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/AnodyneArchipelago/ArchipelagoManager.cs b/AnodyneArchipelago/ArchipelagoManager.cs
index 34ca75a..e4ccf36 100644
--- a/AnodyneArchipelago/ArchipelagoManager.cs
+++ b/AnodyneArchipelago/ArchipelagoManager.cs
@@ -20,10 +20,13 @@ namespace AnodyneArchipelago
         private ArchipelagoSession _session;
         private int _itemIndex = 0;
         private string _seedName;
+        private long _endgameCardRequirement = 36;
 
         private readonly Queue<NetworkItem> _itemsToCollect = new();
         private readonly Queue<string> _messages = new();
 
+        public long EndgameCardRequirement => _endgameCardRequirement;
+
         public async Task<LoginResult> Connect(string url, string slotName, string password)
         {
             LoginResult result;
@@ -45,6 +48,12 @@ namespace AnodyneArchipelago
             _itemIndex = 0;
             _itemsToCollect.Clear();
 
+            LoginSuccessful login = result as LoginSuccessful;
+            if (login.SlotData.ContainsKey("endgame_card_requirement"))
+            {
+                _endgameCardRequirement = (long)login.SlotData["endgame_card_requirement"];
+            }
+
             return result;
         }
 
diff --git a/AnodyneArchipelago/Menu/ConnectionState.cs b/AnodyneArchipelago/Menu/ConnectionState.cs
index 877213f..3eac618 100644
--- a/AnodyneArchipelago/Menu/ConnectionState.cs
+++ b/AnodyneArchipelago/Menu/ConnectionState.cs
@@ -50,6 +50,16 @@ namespace AnodyneArchipelago.Menu
         {
             if (_connectionTask != null && _connectionTask.IsCompleted)
             {
+                if (_connectionTask.IsFaulted)
+                {
+                    _text = _connectionTask.Exception.ToString();
+                    _connectionTask = null;
+
+                    UpdateDisplay();
+
+                    return;
+                }
+
                 LoginResult result = _connectionTask.Result;
 
                 if (result.Successful)
diff --git a/AnodyneArchipelago/Menu/MenuState.cs b/AnodyneArchipelago/Menu/MenuState.cs
index c7be02a..7e8020e 100644
--- a/AnodyneArchipelago/Menu/MenuState.cs
+++ b/AnodyneArchipelago/Menu/MenuState.cs
@@ -135,7 +135,11 @@ namespace AnodyneArchipelago.Menu
         {
             if (!_hide)
             {
-                _selector.Draw();
+                if (_substate == null)
+                {
+                    _selector.Draw();
+                }
+                
                 _versionLabel1.Draw();
                 _versionLabel2.Draw();
                 _serverLabel.Draw();
diff --git a/AnodyneArchipelago/Patches/GameplayPatches.cs b/AnodyneArchipelago/Patches/GameplayPatches.cs
index ec04451..056a855 100644
--- a/AnodyneArchipelago/Patches/GameplayPatches.cs
+++ b/AnodyneArchipelago/Patches/GameplayPatches.cs
@@ -148,6 +148,15 @@ namespace AnodyneArchipelago.Patches
     [HarmonyPatch(typeof(EntityPreset), nameof(EntityPreset.Create))]
     class EntityPresetCreatePatch
     {
+        static void Prefix(EntityPreset __instance)
+        {
+            if (__instance.EntityID == new Guid("C8CE6E18-CF07-180B-A550-9DC808A2F7E3"))
+            {
+                PropertyInfo frameProperty = typeof(EntityPreset).GetProperty("Frame");
+                frameProperty.SetValue(__instance, (int)Plugin.ArchipelagoManager.EndgameCardRequirement);
+            }
+        }
+
         static void Postfix(EntityPreset __instance, Entity __result)
         {
             if (__instance.Type.FullName == "AnodyneSharp.Entities.Interactive.DungeonStatue")
-- 
cgit 1.4.1