From 4e30b16bf5f47d2f4158470510d84cdb1dffcf26 Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Sat, 7 Nov 2026 15:47:57 -0800 Subject: [PATCH] WebPanel fix round 1: close reply by code, loader PE check, no-open scan, drop Core.xml - RynthCoreChatCommands: each method keeps its own summary; /rc webpanel close answers by the Close code (closing / already closed / could not close); verb added to the class header list. - Build-Installer.ps1: Assert-PeMachine throws unless Runtime\WebView2Loader.dll is x86 (0x14C). - ChatCommandReplyTests: HandleWebPanelCommand has no Open(, Navigate( or ShellExecute. - Engine csproj: Microsoft.Web.WebView2.Core.xml is not copied (with the other dropped WebView2 copies). Co-Authored-By: Claude Opus 5.5 --- installer/Build-Installer.ps1 | 15 +++++++++++++- .../Compatibility/RynthCoreChatCommands.cs | 20 ++++++++++++------- src/RynthCore.Engine/RynthCore.Engine.csproj | 2 ++ tools/ChatCommandReplyTests/Program.cs | 14 ++++++++++++- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/installer/Build-Installer.ps1 b/installer/Build-Installer.ps1 index 79f9625..b982d4d 100644 --- a/installer/Build-Installer.ps1 +++ b/installer/Build-Installer.ps1 @@ -339,6 +339,17 @@ if ($SkipDecalBridge) { # release.txt — which core release this install is ($release, from -Version at the top). Set-Content -Path "$StagingDir\release.txt" -Value @($release, $Version) -Encoding ASCII +# The PE machine field of a DLL (e_lfanew at 0x3C, then the COFF Machine at PE offset + 4). The game is +# 32-bit, so the web panel's native loader must be the x86 one (0x14C): the NuGet package also carries +# win-x64 and win-arm64 copies that would load nowhere. +function Assert-PeMachine([string]$Path, [int]$Expected) { + $bytes = [System.IO.File]::ReadAllBytes($Path) + if ($bytes.Length -lt 0x40) { throw "$Path is not a PE file (too short)" } + $pe = [System.BitConverter]::ToInt32($bytes, 0x3C) + if ($pe -lt 0 -or $pe + 6 -gt $bytes.Length) { throw "$Path is not a PE file (bad e_lfanew)" } + $machine = [System.BitConverter]::ToUInt16($bytes, $pe + 4) + if ($machine -ne $Expected) { throw ("{0}: PE machine 0x{1:X}, expected 0x{2:X}" -f $Path, $machine, $Expected) } +} # Everything a working install needs. The 2026-09-25 public installer went out # without the Loader and the SEH trampoline because nothing checked. $required = @( @@ -369,7 +380,9 @@ if (-not $SkipDecalBridge) { } $missing = @($required | Where-Object { -not (Test-Path $_) }) if ($missing.Count -gt 0) { throw "Staging is missing required files:`n $($missing -join "`n ")" } - +if (-not $NativeAot) { + Assert-PeMachine "$StagingDir\Runtime\WebView2Loader.dll" 0x14C +} # Report staged sizes $engineDll = "$StagingDir\Runtime\RynthCore.Engine.dll" if (Test-Path $engineDll) { diff --git a/src/RynthCore.Engine/Compatibility/RynthCoreChatCommands.cs b/src/RynthCore.Engine/Compatibility/RynthCoreChatCommands.cs index f174872..b627033 100644 --- a/src/RynthCore.Engine/Compatibility/RynthCoreChatCommands.cs +++ b/src/RynthCore.Engine/Compatibility/RynthCoreChatCommands.cs @@ -108,6 +108,9 @@ namespace RynthCore.Engine.Compatibility; /// /rc uicost [on|off|<ms>|now|status] - the UI frame cost breakdown /// (): timing on or off, the slow-frame threshold, and (now, or /// alone) which parts of the UI frame took the time over the last seconds. Also Settings > Diagnostics. +/// /rc webpanel [status|close] - the in-game web panel (): +/// status is one redacted line (state, handle, visible/focused, browser pid, free address space); +/// close closes the panel. It never opens a URL. /// /// internal static class RynthCoreChatCommands @@ -1723,12 +1726,6 @@ internal static class RynthCoreChatCommands ReplyLines(UI.Data.Discord.ChatDiscord.HandleCommand(verb)); } - /// - /// /rc layout: which panel layout this client uses and its files (UI/PanelLayout: the character's own, - /// or the PC-wide default and why); default makes this character's the default for new characters; - /// reset asks, reset confirm copies the default over this character's. Those two answer when their - /// files are written (from the UI writer), or at once with why they can't run. - /// /// /// /rc webpanel [status|close]. Status: one redacted line (WebPanelApi.Describe plus the address /// space). Close: closes the live panel (WebPanelApi.Close does not block). Nothing here opens a URL. @@ -1741,12 +1738,21 @@ internal static class RynthCoreChatCommands int handle = WebPanel.WebPanelApi.LiveHandle; if (handle <= 0) { Reply("web panel: nothing to close."); return; } int rc = WebPanel.WebPanelApi.Close(handle); - Reply($"web panel: close requested (handle {handle}, code {rc})."); + // 1 = closing, 0 = already closed (the WebPanelCode values); anything else is a refusal or error. + if (rc == 1) Reply("web panel: closing."); + else if (rc == 0) Reply("web panel: already closed."); + else Fail($"web panel: could not close (code {rc})."); return; } Reply(WebPanel.WebPanelApi.Describe() + "; address space " + AddressSpace.Describe()); } + /// + /// /rc layout: which panel layout this client uses and its files (UI/PanelLayout: the character's own, + /// or the PC-wide default and why); default makes this character's the default for new characters; + /// reset asks, reset confirm copies the default over this character's. Those two answer when their + /// files are written (from the UI writer), or at once with why they can't run. + /// private static void HandleLayoutCommand(string args) { UI.LayoutCommand cmd = UI.PanelLayoutPolicy.ParseCommand(args); diff --git a/src/RynthCore.Engine/RynthCore.Engine.csproj b/src/RynthCore.Engine/RynthCore.Engine.csproj index 20ff4a7..a9dfca5 100644 --- a/src/RynthCore.Engine/RynthCore.Engine.csproj +++ b/src/RynthCore.Engine/RynthCore.Engine.csproj @@ -69,6 +69,8 @@ + + diff --git a/tools/ChatCommandReplyTests/Program.cs b/tools/ChatCommandReplyTests/Program.cs index e82fc1f..6b43a73 100644 --- a/tools/ChatCommandReplyTests/Program.cs +++ b/tools/ChatCommandReplyTests/Program.cs @@ -344,7 +344,19 @@ internal static class Program Check(!Regex.IsMatch(src, @"\bReply\(\$?""[Uu]sage"), "no usage line is written as a success (they go through Fail)"); Check(!Regex.IsMatch(src, @"\bReply\((usage|ServerUsage)\)"), "nor the usage constants"); Check(!Regex.IsMatch(src, @"catch \(Exception ex\) \{ RynthLog\.Compat"), "no command's exception is only logged"); - } + + Case("RynthCoreChatCommands.cs: /rc webpanel never opens or navigates (an arbitrary-URL command would be a phishing vector)"); + int wpStart = src.IndexOf("private static void HandleWebPanelCommand", StringComparison.Ordinal); + int wpEnd = src.IndexOf("private static void HandleLayoutCommand", StringComparison.Ordinal); + Check(wpStart > 0 && wpEnd > wpStart, "found HandleWebPanelCommand"); + if (wpStart > 0 && wpEnd > wpStart) + { + string wp = src.Substring(wpStart, wpEnd - wpStart); + Check(!Regex.IsMatch(wp, @"\bOpen\("), "HandleWebPanelCommand has no Open("); + Check(!Regex.IsMatch(wp, @"\bNavigate\("), "HandleWebPanelCommand has no Navigate("); + Check(!wp.Contains("ShellExecute", StringComparison.Ordinal), "HandleWebPanelCommand has no ShellExecute"); + Check(wp.Contains("WebPanelApi.Close(", StringComparison.Ordinal), "the scan reads the real body (it calls WebPanelApi.Close)"); + } } private static string? FindRepoFile(string relative) {