From 88adb52b58f997746f36a5fd1ab51622998ce1f4 Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Wed, 9 Aug 2023 08:25:07 -0500 Subject: [PATCH 01/63] re-enable instant transmission --- Archipelago/ArchipelagoClient.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Archipelago/ArchipelagoClient.cs b/Archipelago/ArchipelagoClient.cs index 1c2d9a6..9e9f2ee 100644 --- a/Archipelago/ArchipelagoClient.cs +++ b/Archipelago/ArchipelagoClient.cs @@ -87,7 +87,7 @@ private static ArchipelagoSession CreateSession() { var session = ArchipelagoSessionFactory.CreateSession(ServerData.Uri, ServerData.Port); session.MessageLog.OnMessageReceived += OnMessageReceived; - // session.Items.ItemReceived += ItemReceived; + session.Items.ItemReceived += ItemReceived; session.Socket.ErrorReceived += SessionErrorReceived; session.Socket.SocketClosed += SessionSocketClosed; return session; @@ -188,10 +188,18 @@ public static void SyncLocations() private static void ItemReceived(ReceivedItemsHelper helper) { - if (RandomizerStateManager.Instance.CurrentFileSlot == 0 || - ServerData.Index >= Session.Items.AllItemsReceived.Count) return; + if (RandomizerStateManager.Instance.CurrentFileSlot == 0) return; Console.WriteLine("ItemReceived called"); - ItemsAndLocationsHandler.Unlock(helper.DequeueItem().Item); + if (ServerData.Index > helper.Index) + { + helper.DequeueItem(); + return; + } + + var currentItem = helper.DequeueItem(); + ItemsAndLocationsHandler.Unlock(currentItem.Item); + if (!currentItem.Player.Equals(Session.ConnectionInfo.Slot)) + DialogChanger.CreateDialogBox($"Received {currentItem.ColorizeItem()}!"); ServerData.Index++; } From 5fad02cb43c71f16028db39c6680fadb18fbe96f Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Wed, 9 Aug 2023 08:35:02 -0500 Subject: [PATCH 02/63] update lib --- MessengerRando.csproj | 8 ++++---- Utils/RandomizerSaveMethod.cs | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/MessengerRando.csproj b/MessengerRando.csproj index f5076ae..c57168d 100644 --- a/MessengerRando.csproj +++ b/MessengerRando.csproj @@ -35,8 +35,8 @@ false - - packages\Archipelago.MultiClient.Net.5.0.3\lib\net35\Archipelago.MultiClient.Net.dll + + packages\Archipelago.MultiClient.Net.5.0.6\lib\net35\Archipelago.MultiClient.Net.dll C:\Program Files (x86)\Steam\steamapps\common\The Messenger\TheMessenger_Data\Managed\Assembly-CSharp.dll @@ -59,7 +59,7 @@ False - packages\Archipelago.MultiClient.Net.5.0.3\lib\net35\Newtonsoft.Json.dll + packages\Archipelago.MultiClient.Net.5.0.6\lib\net35\Newtonsoft.Json.dll C:\Program Files (x86)\Steam\steamapps\common\The Messenger\TheMessenger_Data\Managed\UnityEngine.dll @@ -82,7 +82,7 @@ False - packages\Archipelago.MultiClient.Net.5.0.3\lib\net35\websocket-sharp.dll + packages\Archipelago.MultiClient.Net.5.0.6\lib\net35\websocket-sharp.dll diff --git a/Utils/RandomizerSaveMethod.cs b/Utils/RandomizerSaveMethod.cs index aebda33..bfec3a4 100644 --- a/Utils/RandomizerSaveMethod.cs +++ b/Utils/RandomizerSaveMethod.cs @@ -1,11 +1,10 @@ using System; using MessengerRando.Archipelago; -using MessengerRando.Utils; using Newtonsoft.Json; -namespace MessengerRando +namespace MessengerRando.Utils { - public class RandomizerSaveMethod + public static class RandomizerSaveMethod { private const char SplitConst = '|'; From 53c03e11a2c22f9790a371b6c15fae72d76b27dd Mon Sep 17 00:00:00 2001 From: alwaysintreble Date: Sun, 3 Sep 2023 17:15:44 -0500 Subject: [PATCH 03/63] prelim work on new menus --- APRandomizerMain.cs | 27 +- MessengerRando.csproj | 1 + Utils/Constants/RoomConstants.cs | 2 +- Utils/RandoMenu.cs | 464 +++++++++++++++++++++++++++++++ 4 files changed, 490 insertions(+), 4 deletions(-) create mode 100644 Utils/RandoMenu.cs diff --git a/APRandomizerMain.cs b/APRandomizerMain.cs index 112d62c..e03316a 100644 --- a/APRandomizerMain.cs +++ b/APRandomizerMain.cs @@ -125,6 +125,20 @@ public override void Load() //Add Archipelago collect button archipelagoCollectButton = Courier.UI.RegisterSubMenuModOptionButton(() => "Collect remaining items", OnSelectArchipelagoCollect); + RandoMenu.ArchipelagoMenuButton = Courier.UI.RegisterSubMenuOptionButton(() => "Randomizer", RandoMenu.DisplayRandoMenu); + + PopulateRandoButtons(); + + void PopulateRandoButtons() + { + RandoMenu.versionButton = + RandoMenu.RegisterSubRandoButton( + () => "Messenger AP Randomizer: v" + ItemRandomizerUtil.GetModVersion(), null); + RandoMenu.connectMenuButton = RandoMenu.RegisterSubRandoButton(() => "Connect to Archipelago", null); + RandoMenu.resetSaveButton = RandoMenu.RegisterMultipleRandoButton(() => "Reset Randomizer File Slot", null, + ResetSaves, null, RandoMenu.GetTextForResetIndex); + } + //Plug in my code :3 On.InventoryManager.AddItem += InventoryManager_AddItem; On.ProgressionManager.SetChallengeRoomAsCompleted += ProgressionManager_SetChallengeRoomAsCompleted; @@ -631,6 +645,12 @@ bool OnRandoFileResetConfirmation(string answer) return true; } + ConfirmFileReset(); + return true; + } + + void ConfirmFileReset() + { ArchipelagoData.ClearData(); randoStateManager = new RandomizerStateManager(); clearedData = true; @@ -640,15 +660,16 @@ bool OnRandoFileResetConfirmation(string answer) { sw.WriteLine(RandomizerConstants.SAVE_FILE_STRING); } - + Manager.Instance.LoadSaveGame(); //Delete the existing save file selection ui since it really wants to hold on to the previous saves data. GameObject.Destroy(Manager.Instance.GetView().gameObject); //Reinit the save file selection ui. - SaveGameSelectionScreen selectionScreen = Manager.Instance.ShowView(EScreenLayers.MAIN, null, false, AnimatorUpdateMode.Normal); + SaveGameSelectionScreen selectionScreen = + Manager.Instance.ShowView(EScreenLayers.MAIN, null, false, + AnimatorUpdateMode.Normal); selectionScreen.GoOffscreenInstant(); - return true; } public static void OnToggleWindmillShuriken() diff --git a/MessengerRando.csproj b/MessengerRando.csproj index c57168d..73081df 100644 --- a/MessengerRando.csproj +++ b/MessengerRando.csproj @@ -103,6 +103,7 @@ + diff --git a/Utils/Constants/RoomConstants.cs b/Utils/Constants/RoomConstants.cs index 4ac44bc..6ca789f 100644 --- a/Utils/Constants/RoomConstants.cs +++ b/Utils/Constants/RoomConstants.cs @@ -6,7 +6,7 @@ namespace MessengerRando.Utils.Constants { - public class RoomConstants + public static class RoomConstants { public struct RoomTransition: IEquatable { diff --git a/Utils/RandoMenu.cs b/Utils/RandoMenu.cs new file mode 100644 index 0000000..b8fe3e0 --- /dev/null +++ b/Utils/RandoMenu.cs @@ -0,0 +1,464 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using MessengerRando.Archipelago; +using Mod.Courier; +using Mod.Courier.UI; +using TMPro; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace MessengerRando.Utils +{ + public class RandoMenu + { + public static OptionsButtonInfo ArchipelagoMenuButton; + private static RandoScreen randoScreen; + + public static SubMenuButtonInfo versionButton; + public static SubMenuButtonInfo connectMenuButton; + public static MultipleOptionButtonInfo resetSaveButton; + + + public static void DisplayRandoMenu() + { + Manager.Instance.GetView().gameObject.SetActive(false); + if (!RandoScreen.RandoScreenLoaded) + randoScreen = RandoScreen.BuildModOptionScreen(Manager.Instance.GetView()); + + Courier.UI.ShowView(randoScreen, EScreenLayers.PROMPT, null, false); + } + + public class RandoScreen : ModOptionScreen + { + public static bool RandoScreenLoaded; + public static readonly List OptionButtons = new List(); + + private static int OptionsCount() + { + return OptionButtons.Count(modOptionButton => modOptionButton.gameObject.activeInHierarchy); + } + + private static int EnabledModOptionsBeforeButton(OptionsButtonInfo button) + { + int num = 0; + foreach (OptionsButtonInfo modOptionButton in OptionButtons) + { + if (modOptionButton.Equals(button)) + return num; + if (modOptionButton.gameObject.activeInHierarchy) + ++num; + } + + return -1; + } + + public void InitOptionsViewWithModButtons() + { + var view = this; + OptionScreen optionScreen = Manager.Instance.GetView(); + Transform parent = view.transform.Find("Container").Find("BackgroundFrame").Find("OptionsFrame") + .Find("OptionMenuButtons"); + foreach (OptionsButtonInfo button in OptionButtons) + { + switch (button) + { + case ToggleButtonInfo _: + button.gameObject = Instantiate(optionScreen.fullscreenOption, parent); + break; + case SubMenuButtonInfo _: + button.gameObject = Instantiate(optionScreen.controlsButton.transform.parent.gameObject, + parent); + break; + case MultipleOptionButtonInfo _: + button.gameObject = Instantiate(optionScreen.languageOption, parent); + break; + default: + CourierLogger.Log(LogType.Warning, "OptionsMenu", + button.GetType()?.ToString() + " not a known type of OptionsButtonInfo!"); + break; + } + + button.gameObject.transform.SetAsLastSibling(); + GameObject gameObject = button.gameObject; + Func getText = button.GetText; + string str = getText?.Invoke() ?? "Nameless Modded Options Button"; + gameObject.name = str; + button.addedTo = view; + foreach (TextMeshProUGUI componentsInChild in button.gameObject + .GetComponentsInChildren()) + { + if (componentsInChild.name.Equals("OptionState") || componentsInChild.name.Equals("Text")) + button.stateTextMesh = componentsInChild; + if (componentsInChild.name.Equals("OptionName")) + { + button.nameTextMesh = componentsInChild; + TextLocalizer component = componentsInChild.GetComponent(); + if (component != null) + component.locID = ""; + } + } + + Button component1 = button.gameObject.transform.Find("Button").GetComponent