From c25c65e1accde8470eca37212a9aa02cd7c19a73 Mon Sep 17 00:00:00 2001 From: evrydayjunglist Date: Thu, 12 Nov 2026 19:19:42 -0800 Subject: [PATCH 1/2] fix: Give item works when Waypoint is started while the game runs Started while the servers and the game already ran, Waypoint's Give item answered "no running game has it loaded" for the Waypoint Tools mod, though the game's Gateway had it loaded. The Console asks the Gateway for its commands when Waypoint starts. That short-lived Gateway loads the mods too, for their commands, and the mod (up to 1.0.2) wrote data/waypoint-tools/loaded.json on every load: the file then named the asked process, which had ended, and Waypoint reads that as left by a Gateway that stopped. The mod is where this belongs, and its 1.0.3 leaves the file to the Gateway that runs the game. For the versions installed now, AskGateway keeps what the file said before its question and puts it back when the asked process wrote itself over a Gateway that still runs (WaypointToolsMod.KeepLoaded). With 1.0.3 the file does not change and nothing is put back. docs/launcher.md also said the mods' commands are not in the Console's list; they are, which is why the asked Gateway loads the mods. Checked in the running app on a 0.5.1-beta release folder with the 3.29.3d client and the released mod 1.0.2, Waypoint started while the character was in game: before, the refusal above; after, "Added Iron Ring" and the file naming the game's Gateway again. One unit test. --- docs/launcher.md | 9 +++- src/Launcher.Core/WaypointToolsMod.cs | 47 +++++++++++++++++++ src/Waypoint/CommandCatalog.cs | 11 ++++- tests/Waypoint.Tests/WaypointToolsModTests.cs | 31 ++++++++++++ 4 files changed, 95 insertions(+), 3 deletions(-) diff --git a/docs/launcher.md b/docs/launcher.md index dfe1e5c..38f9d9a 100644 --- a/docs/launcher.md +++ b/docs/launcher.md @@ -1405,7 +1405,8 @@ Advanced mode), the **Diagnostic report** button on an operation's failure dialo - The lists come from the Gateway the servers run (`src\GameServer.Gateway\bin\Debug`). When that build changes (Play, Restart Gateway or a hot reload after a pull), the next `/` reads the commands and their values again; **Reload commands** does it at once. The Gateway's catalogs write their own log lines beside the values ("[gateway] atlas: …"), - which the launcher skips. The loaded mods' commands are not in the list. + which the launcher skips. The Gateway that is asked loads the mods as well, so the commands of the mods that are + turned on are in the list. ### Tools: the item crafter @@ -1445,7 +1446,11 @@ write and gives it to the character in game. - **Give item** gives the item to the character in game, into the main inventory, through the Waypoint Tools mod (LocalExile-Mods' `waypoint-tools`, `WaypointToolsMod.cs`), the same on a source copy and a release; it needs no other mod and no Frida. The mod counts as loaded when its `data/waypoint-tools/loaded.json` names a Gateway process that still - runs and lists `item_give`. Waypoint writes `data/waypoint-tools/requests/.json` (as `.tmp`, then renamed) with the + runs and lists `item_give`. A Gateway Waypoint asks a question (its commands, when Waypoint starts) loads the mods + too, and the mod up to 1.0.2 then wrote that short-lived process into the file, over the Gateway that runs the game: + a Waypoint started while the game ran found the mod "not loaded". Waypoint now puts the file back after its question + when that happened (`WaypointToolsMod.KeepLoaded`, from `CommandCatalog.AskGateway`); the mod from 1.0.3 leaves the + file alone itself. Waypoint writes `data/waypoint-tools/requests/.json` (as `.tmp`, then renamed) with the item and no character, and the mod gives it to the one character in game on that connection's next tick, then answers in `replies/.json`, which Waypoint reads and deletes; the answer shows in the status line. Nothing goes over the network and nothing limits the item's length. An answer not there in 35 seconds (the mod waits 30 for a character in diff --git a/src/Launcher.Core/WaypointToolsMod.cs b/src/Launcher.Core/WaypointToolsMod.cs index 9dc1b51..1d89daf 100644 --- a/src/Launcher.Core/WaypointToolsMod.cs +++ b/src/Launcher.Core/WaypointToolsMod.cs @@ -45,6 +45,53 @@ public static bool Loaded(string root, string action, Func? running = } } + /// What loaded.json says now, to keep across a question to a Gateway (); null + /// without the file. + public static string? Announced(string root) + { + try + { + string file = Path.Combine(Root(root), "loaded.json"); + return File.Exists(file) ? File.ReadAllText(file) : null; + } + catch (Exception e) when (e is IOException or UnauthorizedAccessException) + { + return null; + } + } + + /// + /// After a Gateway was asked a question: puts loaded.json back as it was , when the + /// asked process wrote itself into it over a Gateway that still runs. A Gateway's commands and values + /// modes load the mods too, for their commands, and the mod up to 1.0.2 then named that process, which ends with the + /// question: the Gateway that runs the game still had the mod loaded, but Give item took it for not loaded (Waypoint's + /// Console asks when Waypoint starts, so a Waypoint started while the game ran always did). True when it put it back. + /// + public static bool KeepLoaded(string root, string? before, int asked, Func? running = null) + { + try + { + if (before is null || Pid(before) is not int owner || owner == asked) return false; + string file = Path.Combine(Root(root), "loaded.json"); + if (!File.Exists(file) || Pid(File.ReadAllText(file)) != asked || !(running ?? Running)(owner)) return false; + // Beside, then moved into place: the mod and Waypoint never read half of it. + File.WriteAllText(file + ".tmp", before); + File.Move(file + ".tmp", file, overwrite: true); + return true; + } + catch (Exception e) when (e is IOException or UnauthorizedAccessException) + { + return false; + } + } + + /// The process a loaded.json names, or null when it names none. + static int? Pid(string json) + { + try { return JsonNode.Parse(json) is JsonObject o ? (int?)o["pid"] : null; } + catch (Exception e) when (e is JsonException or FormatException or InvalidOperationException) { return null; } + } + static bool Running(int pid) { try diff --git a/src/Waypoint/CommandCatalog.cs b/src/Waypoint/CommandCatalog.cs index 77893f8..cc89c7c 100644 --- a/src/Waypoint/CommandCatalog.cs +++ b/src/Waypoint/CommandCatalog.cs @@ -55,6 +55,10 @@ internal static async Task AskGateway(TimeSpan timeout, params string[] Directory.CreateDirectory(temp); info.Environment["TMPDIR"] = temp; #endif + // A Gateway asked for its commands or values loads the mods too, and the Waypoint Tools mod up to 1.0.2 then names + // this process as the one that has it loaded: what the file said is kept, for the Gateway that runs the game. + string root = Environment.CurrentDirectory; + string? announced = WaypointToolsMod.Announced(root); using var process = Process.Start(info)!; try { @@ -65,7 +69,12 @@ internal static async Task AskGateway(TimeSpan timeout, params string[] } finally { - if (!process.HasExited) process.Kill(entireProcessTree: true); + if (!process.HasExited) + { + process.Kill(entireProcessTree: true); + try { await process.WaitForExitAsync().WaitAsync(TimeSpan.FromSeconds(5)); } catch (TimeoutException) { } + } + WaypointToolsMod.KeepLoaded(root, announced, process.Id); } } diff --git a/tests/Waypoint.Tests/WaypointToolsModTests.cs b/tests/Waypoint.Tests/WaypointToolsModTests.cs index c15fc9d..f794edf 100644 --- a/tests/Waypoint.Tests/WaypointToolsModTests.cs +++ b/tests/Waypoint.Tests/WaypointToolsModTests.cs @@ -31,6 +31,37 @@ public void The_mod_counts_as_loaded_only_in_a_running_Gateway_with_the_action() Assert.False(WaypointToolsMod.Loaded(_root, "item_give", _ => true)); } + [Fact] + public void A_question_to_a_Gateway_leaves_the_running_Gateways_announcement() + { + // The Gateway that runs the game (42) has the mod loaded. One asked for its commands (77) loads the mods too, and + // the mod up to 1.0.2 names it in loaded.json; it ends with the question. + const string game = """{"protocol":1,"version":"1.0.2","pid":42,"actions":["item_give"]}"""; + const string asked = """{"protocol":1,"version":"1.0.2","pid":77,"actions":["item_give"]}"""; + WriteLoaded(game); + string? before = WaypointToolsMod.Announced(_root); + WriteLoaded(asked); + Assert.False(WaypointToolsMod.Loaded(_root, "item_give", pid => pid == 42)); + Assert.True(WaypointToolsMod.KeepLoaded(_root, before, asked: 77, pid => pid == 42)); + Assert.Equal(game, File.ReadAllText(Data("loaded.json"))); + Assert.True(WaypointToolsMod.Loaded(_root, "item_give", pid => pid == 42)); + Assert.False(File.Exists(Data("loaded.json.tmp"))); + + // Left alone: a mod that did not write (1.0.3), a Gateway that stopped meanwhile, no file before, one written by + // another process than the asked one, and a file that is gone. + Assert.False(WaypointToolsMod.KeepLoaded(_root, before, asked: 77, pid => pid == 42)); + WriteLoaded(asked); + Assert.False(WaypointToolsMod.KeepLoaded(_root, before, asked: 77, _ => false)); + Assert.False(WaypointToolsMod.KeepLoaded(_root, null, asked: 77, _ => true)); + Assert.False(WaypointToolsMod.KeepLoaded(_root, "not json", asked: 77, _ => true)); + Assert.False(WaypointToolsMod.KeepLoaded(_root, before, asked: 78, _ => true)); + Assert.Equal(asked, File.ReadAllText(Data("loaded.json"))); + File.Delete(Data("loaded.json")); + Assert.Null(WaypointToolsMod.Announced(_root)); + Assert.False(WaypointToolsMod.KeepLoaded(_root, before, asked: 77, _ => true)); + Assert.False(File.Exists(Data("loaded.json"))); + } + [Fact] public void Installed_means_its_folder_has_a_manifest() { From 4e45402dc18d0b90cd0277974a220e1078f6f3f4 Mon Sep 17 00:00:00 2001 From: evrydayjunglist Date: Thu, 12 Nov 2026 20:36:10 -0800 Subject: [PATCH 2/2] docs: Give item and the mods' commands, without the guard in Waypoint Takes the guard of the commit before out again: Waypoint no longer puts the Waypoint Tools mod's loaded.json back after asking a Gateway a question. That file is the mod's and Waypoint only reads it; the fault was the mod's, which wrote it from a Gateway that was only asked a question, and the mod's 1.0.3 fixes it there. The guard also had two holes: two questions asked at once left the file wrong, and it wrote through the temporary file name the mod uses. What stays is docs/launcher.md: - The Console's list holds the commands of the mods that are turned on: the Gateway that is asked loads the mods. It said they are not listed. - Why Give item can find the mod "not loaded" with the mod up to 1.0.2, and what clears it. Against main the branch now changes docs/launcher.md only. --- docs/launcher.md | 8 ++-- src/Launcher.Core/WaypointToolsMod.cs | 47 ------------------- src/Waypoint/CommandCatalog.cs | 11 +---- tests/Waypoint.Tests/WaypointToolsModTests.cs | 31 ------------ 4 files changed, 5 insertions(+), 92 deletions(-) diff --git a/docs/launcher.md b/docs/launcher.md index 38f9d9a..c1f55fb 100644 --- a/docs/launcher.md +++ b/docs/launcher.md @@ -1447,10 +1447,10 @@ write and gives it to the character in game. (LocalExile-Mods' `waypoint-tools`, `WaypointToolsMod.cs`), the same on a source copy and a release; it needs no other mod and no Frida. The mod counts as loaded when its `data/waypoint-tools/loaded.json` names a Gateway process that still runs and lists `item_give`. A Gateway Waypoint asks a question (its commands, when Waypoint starts) loads the mods - too, and the mod up to 1.0.2 then wrote that short-lived process into the file, over the Gateway that runs the game: - a Waypoint started while the game ran found the mod "not loaded". Waypoint now puts the file back after its question - when that happened (`WaypointToolsMod.KeepLoaded`, from `CommandCatalog.AskGateway`); the mod from 1.0.3 leaves the - file alone itself. Waypoint writes `data/waypoint-tools/requests/.json` (as `.tmp`, then renamed) with the + too, and the mod up to 1.0.2 then writes that short-lived process into the file, over the Gateway that runs the game: + a Waypoint started while the game runs finds the mod "not loaded" until that Gateway loads the mod again (the game + started again, or the mod reloaded). The mod from 1.0.3 leaves the file to the Gateway that runs the game; + the file is the mod's, and Waypoint only reads it. Waypoint writes `data/waypoint-tools/requests/.json` (as `.tmp`, then renamed) with the item and no character, and the mod gives it to the one character in game on that connection's next tick, then answers in `replies/.json`, which Waypoint reads and deletes; the answer shows in the status line. Nothing goes over the network and nothing limits the item's length. An answer not there in 35 seconds (the mod waits 30 for a character in diff --git a/src/Launcher.Core/WaypointToolsMod.cs b/src/Launcher.Core/WaypointToolsMod.cs index 1d89daf..9dc1b51 100644 --- a/src/Launcher.Core/WaypointToolsMod.cs +++ b/src/Launcher.Core/WaypointToolsMod.cs @@ -45,53 +45,6 @@ public static bool Loaded(string root, string action, Func? running = } } - /// What loaded.json says now, to keep across a question to a Gateway (); null - /// without the file. - public static string? Announced(string root) - { - try - { - string file = Path.Combine(Root(root), "loaded.json"); - return File.Exists(file) ? File.ReadAllText(file) : null; - } - catch (Exception e) when (e is IOException or UnauthorizedAccessException) - { - return null; - } - } - - /// - /// After a Gateway was asked a question: puts loaded.json back as it was , when the - /// asked process wrote itself into it over a Gateway that still runs. A Gateway's commands and values - /// modes load the mods too, for their commands, and the mod up to 1.0.2 then named that process, which ends with the - /// question: the Gateway that runs the game still had the mod loaded, but Give item took it for not loaded (Waypoint's - /// Console asks when Waypoint starts, so a Waypoint started while the game ran always did). True when it put it back. - /// - public static bool KeepLoaded(string root, string? before, int asked, Func? running = null) - { - try - { - if (before is null || Pid(before) is not int owner || owner == asked) return false; - string file = Path.Combine(Root(root), "loaded.json"); - if (!File.Exists(file) || Pid(File.ReadAllText(file)) != asked || !(running ?? Running)(owner)) return false; - // Beside, then moved into place: the mod and Waypoint never read half of it. - File.WriteAllText(file + ".tmp", before); - File.Move(file + ".tmp", file, overwrite: true); - return true; - } - catch (Exception e) when (e is IOException or UnauthorizedAccessException) - { - return false; - } - } - - /// The process a loaded.json names, or null when it names none. - static int? Pid(string json) - { - try { return JsonNode.Parse(json) is JsonObject o ? (int?)o["pid"] : null; } - catch (Exception e) when (e is JsonException or FormatException or InvalidOperationException) { return null; } - } - static bool Running(int pid) { try diff --git a/src/Waypoint/CommandCatalog.cs b/src/Waypoint/CommandCatalog.cs index cc89c7c..77893f8 100644 --- a/src/Waypoint/CommandCatalog.cs +++ b/src/Waypoint/CommandCatalog.cs @@ -55,10 +55,6 @@ internal static async Task AskGateway(TimeSpan timeout, params string[] Directory.CreateDirectory(temp); info.Environment["TMPDIR"] = temp; #endif - // A Gateway asked for its commands or values loads the mods too, and the Waypoint Tools mod up to 1.0.2 then names - // this process as the one that has it loaded: what the file said is kept, for the Gateway that runs the game. - string root = Environment.CurrentDirectory; - string? announced = WaypointToolsMod.Announced(root); using var process = Process.Start(info)!; try { @@ -69,12 +65,7 @@ internal static async Task AskGateway(TimeSpan timeout, params string[] } finally { - if (!process.HasExited) - { - process.Kill(entireProcessTree: true); - try { await process.WaitForExitAsync().WaitAsync(TimeSpan.FromSeconds(5)); } catch (TimeoutException) { } - } - WaypointToolsMod.KeepLoaded(root, announced, process.Id); + if (!process.HasExited) process.Kill(entireProcessTree: true); } } diff --git a/tests/Waypoint.Tests/WaypointToolsModTests.cs b/tests/Waypoint.Tests/WaypointToolsModTests.cs index f794edf..c15fc9d 100644 --- a/tests/Waypoint.Tests/WaypointToolsModTests.cs +++ b/tests/Waypoint.Tests/WaypointToolsModTests.cs @@ -31,37 +31,6 @@ public void The_mod_counts_as_loaded_only_in_a_running_Gateway_with_the_action() Assert.False(WaypointToolsMod.Loaded(_root, "item_give", _ => true)); } - [Fact] - public void A_question_to_a_Gateway_leaves_the_running_Gateways_announcement() - { - // The Gateway that runs the game (42) has the mod loaded. One asked for its commands (77) loads the mods too, and - // the mod up to 1.0.2 names it in loaded.json; it ends with the question. - const string game = """{"protocol":1,"version":"1.0.2","pid":42,"actions":["item_give"]}"""; - const string asked = """{"protocol":1,"version":"1.0.2","pid":77,"actions":["item_give"]}"""; - WriteLoaded(game); - string? before = WaypointToolsMod.Announced(_root); - WriteLoaded(asked); - Assert.False(WaypointToolsMod.Loaded(_root, "item_give", pid => pid == 42)); - Assert.True(WaypointToolsMod.KeepLoaded(_root, before, asked: 77, pid => pid == 42)); - Assert.Equal(game, File.ReadAllText(Data("loaded.json"))); - Assert.True(WaypointToolsMod.Loaded(_root, "item_give", pid => pid == 42)); - Assert.False(File.Exists(Data("loaded.json.tmp"))); - - // Left alone: a mod that did not write (1.0.3), a Gateway that stopped meanwhile, no file before, one written by - // another process than the asked one, and a file that is gone. - Assert.False(WaypointToolsMod.KeepLoaded(_root, before, asked: 77, pid => pid == 42)); - WriteLoaded(asked); - Assert.False(WaypointToolsMod.KeepLoaded(_root, before, asked: 77, _ => false)); - Assert.False(WaypointToolsMod.KeepLoaded(_root, null, asked: 77, _ => true)); - Assert.False(WaypointToolsMod.KeepLoaded(_root, "not json", asked: 77, _ => true)); - Assert.False(WaypointToolsMod.KeepLoaded(_root, before, asked: 78, _ => true)); - Assert.Equal(asked, File.ReadAllText(Data("loaded.json"))); - File.Delete(Data("loaded.json")); - Assert.Null(WaypointToolsMod.Announced(_root)); - Assert.False(WaypointToolsMod.KeepLoaded(_root, before, asked: 77, _ => true)); - Assert.False(File.Exists(Data("loaded.json"))); - } - [Fact] public void Installed_means_its_folder_has_a_manifest() {