From 09d93c8b30e1008c5b4d5d1e1900918570cd804b Mon Sep 17 00:00:00 2001 From: thislooksfun Date: Sat, 27 Apr 2024 23:00:28 -0500 Subject: [PATCH 1/5] Add silent status to debug logs --- Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs b/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs index e7951da..0edb8dc 100644 --- a/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs +++ b/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs @@ -106,7 +106,7 @@ public void MarkLocationAsChecked(long locationId, bool silentGive) bool hadNewlyObtainedItems = false; bool hadUnobtainedItems = false; - Archipelago.Instance.LogDebug($"Marking location {locationId} as checked."); + Archipelago.Instance.LogDebug($"Marking location {locationId} as checked{(silentGive ? " silently" : "")}."); if (!ArchipelagoPlacementTag.PlacementsByLocationId.TryGetValue(locationId, out pmt)) { Archipelago.Instance.LogDebug($"Could not find a placement for location {locationId}"); @@ -229,7 +229,7 @@ private void ReceiveItem(NetworkItem netItem, bool silentGive) { string name = session.Items.GetItemName(netItem.Item); Archipelago.Instance.LogDebug($"Receiving item ID {netItem.Item}. Name is {name}. " + - $"Slot is {netItem.Player}. Location is {netItem.Location}."); + $"Slot is {netItem.Player}. Location is {netItem.Location}. Silent is {silentGive}"); if (netItem.Player == Archipelago.Instance.Slot && netItem.Location > 0) { From d2b14ee379dbe0c5def6662312e88e1222d7ff96 Mon Sep 17 00:00:00 2001 From: thislooksfun Date: Sat, 27 Apr 2024 23:17:16 -0500 Subject: [PATCH 2/5] Add an option for whether or not items are shown when received offline --- Archipelago.HollowKnight/Archipelago.cs | 3 ++- Archipelago.HollowKnight/ConnectionDetails.cs | 2 ++ Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs | 5 +++-- .../MC/ArchipelagoModeMenuConstructor.cs | 4 +++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Archipelago.HollowKnight/Archipelago.cs b/Archipelago.HollowKnight/Archipelago.cs index 4c55065..015d9af 100644 --- a/Archipelago.HollowKnight/Archipelago.cs +++ b/Archipelago.HollowKnight/Archipelago.cs @@ -297,7 +297,8 @@ public ConnectionDetails OnSaveGlobal() { ServerUrl = MenuSettings.ServerUrl, ServerPort = MenuSettings.ServerPort, - SlotName = MenuSettings.SlotName + SlotName = MenuSettings.SlotName, + AlwaysShowItems = MenuSettings.AlwaysShowItems, }; } } diff --git a/Archipelago.HollowKnight/ConnectionDetails.cs b/Archipelago.HollowKnight/ConnectionDetails.cs index a8cdbd1..ff45afd 100644 --- a/Archipelago.HollowKnight/ConnectionDetails.cs +++ b/Archipelago.HollowKnight/ConnectionDetails.cs @@ -10,5 +10,7 @@ public record ConnectionDetails public string RoomSeed { get; set; } public long Seed { get; set; } + + public bool AlwaysShowItems { get; set; } } } diff --git a/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs b/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs index 0edb8dc..e178aa9 100644 --- a/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs +++ b/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs @@ -180,12 +180,13 @@ private async Task Synchronize() NetworkItem seen = session.Items.DequeueItem(); Archipelago.Instance.LogDebug($"Fast-forwarding past already-obtained {session.Items.GetItemName(seen.Item)} at index {i}"); } + bool silentGive = !Archipelago.Instance.MenuSettings.AlwaysShowItems; // receive from the server any items that are pending - while (ReceiveNextItem(true)) { } + while (ReceiveNextItem(silentGive)) { } // ensure any already-checked locations (co-op, restarting save) are marked cleared foreach (long location in session.Locations.AllLocationsChecked) { - MarkLocationAsChecked(location, true); + MarkLocationAsChecked(location, silentGive); } // send out any pending items that didn't get to the network from the previous session long[] pendingLocations = deferredLocationChecks.ToArray(); diff --git a/Archipelago.HollowKnight/MC/ArchipelagoModeMenuConstructor.cs b/Archipelago.HollowKnight/MC/ArchipelagoModeMenuConstructor.cs index 1956a15..9a9bceb 100644 --- a/Archipelago.HollowKnight/MC/ArchipelagoModeMenuConstructor.cs +++ b/Archipelago.HollowKnight/MC/ArchipelagoModeMenuConstructor.cs @@ -153,7 +153,9 @@ private static void StartOrResumeGame(bool newGame, MenuLabel errorLabel) } else { - Archipelago.Instance.MenuSettings = Archipelago.Instance.ApSettings with { }; + Archipelago.Instance.MenuSettings = Archipelago.Instance.ApSettings with { + AlwaysShowItems = Archipelago.Instance.MenuSettings.AlwaysShowItems + }; } try { From 70245c83e2d6e7121d5ac66e0df916ed3a91824c Mon Sep 17 00:00:00 2001 From: thislooksfun Date: Sat, 27 Apr 2024 23:17:54 -0500 Subject: [PATCH 3/5] Add a mod menu entry for toggling if offline items show on connection --- Archipelago.HollowKnight/Archipelago.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Archipelago.HollowKnight/Archipelago.cs b/Archipelago.HollowKnight/Archipelago.cs index 015d9af..6d61446 100644 --- a/Archipelago.HollowKnight/Archipelago.cs +++ b/Archipelago.HollowKnight/Archipelago.cs @@ -18,7 +18,7 @@ namespace Archipelago.HollowKnight { - public class Archipelago : Mod, IGlobalSettings, ILocalSettings + public class Archipelago : Mod, IGlobalSettings, ILocalSettings, IMenuMod { // Events support public static event Action OnArchipelagoGameStarted; @@ -301,5 +301,19 @@ public ConnectionDetails OnSaveGlobal() AlwaysShowItems = MenuSettings.AlwaysShowItems, }; } + + public bool ToggleButtonInsideMenu => false; + public List GetMenuData(IMenuMod.MenuEntry? toggleButtonEntry) + { + return [ + new IMenuMod.MenuEntry { + Name = "Show offline items", + Description = "Show items received while you were disconnected.", + Values = ["No", "Yes"], + Saver = opt => { MenuSettings.AlwaysShowItems = opt == 1; }, + Loader = () => MenuSettings.AlwaysShowItems ? 1 : 0, + }, + ]; + } } } From f171f5cec860a6736755a54110b6e9f4832c7257 Mon Sep 17 00:00:00 2001 From: thislooksfun Date: Sat, 11 May 2024 22:42:00 -0500 Subject: [PATCH 4/5] Allow marking locations without adding to recent items display --- .../IC/Modules/ItemNetworkingModule.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs b/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs index e178aa9..493c438 100644 --- a/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs +++ b/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs @@ -98,7 +98,7 @@ public async Task SendLocationsAsync(params long[] locationIds) } } - public void MarkLocationAsChecked(long locationId, bool silentGive) + public void MarkLocationAsChecked(long locationId, bool silentGive, bool silenceRecentItems = false) { // Called when marking a location as checked remotely (i.e. through ReceiveItem, etc.) // This also grants items at said locations. @@ -136,6 +136,14 @@ public void MarkLocationAsChecked(long locationId, bool silentGive) pmt.AddVisitFlag(VisitState.ObtainedAnyItem); GiveInfo giveInfo = silentGive ? SilentGiveInfo : RemoteGiveInfo; + + if (silenceRecentItems) + { + InteropTag recentItemsTag = item.AddTag(); + recentItemsTag.Message = "RecentItems"; + recentItemsTag.Properties["IgnoreItem"] = true; + } + item.Give(pmt, giveInfo.Clone()); } From 8be6fa77c8c2ee2f4bcfe75c86b7f2a77b47973e Mon Sep 17 00:00:00 2001 From: thislooksfun Date: Sat, 11 May 2024 22:43:27 -0500 Subject: [PATCH 5/5] fixup! Add an option for whether or not items are shown when received offline --- .../IC/Modules/ItemNetworkingModule.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs b/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs index 493c438..f5b768d 100644 --- a/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs +++ b/Archipelago.HollowKnight/IC/Modules/ItemNetworkingModule.cs @@ -191,10 +191,15 @@ private async Task Synchronize() bool silentGive = !Archipelago.Instance.MenuSettings.AlwaysShowItems; // receive from the server any items that are pending while (ReceiveNextItem(silentGive)) { } - // ensure any already-checked locations (co-op, restarting save) are marked cleared + // ensure any already-checked locations (co-op, restarting save, other players collecting) are marked cleared foreach (long location in session.Locations.AllLocationsChecked) { - MarkLocationAsChecked(location, silentGive); + // NOTE: this is intentionally always set to silently give during initial sync even when + // AlwaysShowItems is true because this shows the items that OTHER players have gotten + // FROM this world, which can SERIOUSLY lock up the item display if someone collects a + // lot of their items at once (usually via the !collect command). It also prevents these + // items from displaying in RecentItemsDisplay (if installed) for the same reason. + MarkLocationAsChecked(location, true, true); } // send out any pending items that didn't get to the network from the previous session long[] pendingLocations = deferredLocationChecks.ToArray();