XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEToolBox

【WPF】XFE工具箱

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFEToolBox

修复自研 SE 加载器高 DPI 画面模糊并验证原生分辨率

99897ce
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

6 个文件 +37 -4
Modified tests/SpaceEngineersPluginManager.Validation/Fixtures/FakeGame.cs +6 -0
@@ -2,6 +2,7 @@ using System;
2 2 using System.IO;
3 3 using System.Linq;
4 4 using System.Reflection;
5 using System.Runtime.InteropServices;
5 6 using VRage.Plugins;
6 7
7 8 public sealed class FixtureGame
@@ -11,6 +12,8 @@ public sealed class FixtureGame
11 12
12 13 internal static class Program
13 14 {
15 [DllImport("shcore.dll")]
16 private static extern int GetProcessDpiAwareness(IntPtr process, out int awareness);
14 17 private static void Journal(string message)
15 18 {
16 19 File.AppendAllText(Environment.GetEnvironmentVariable("XFE_FIXTURE_JOURNAL"), message + Environment.NewLine);
@@ -21,6 +24,9 @@ internal static class Program
21 24 try
22 25 {
23 26 Journal("game:start");
27 int dpiAwareness;
28 if (GetProcessDpiAwareness(IntPtr.Zero, out dpiAwareness) != 0) throw new InvalidOperationException("Cannot read process DPI awareness.");
29 Journal("game:dpi-awareness:" + dpiAwareness);
24 30 foreach (string argument in args) Journal("game:arg:" + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(argument)));
25 31 Journal("game:bin64:" + VRage.FileSystem.MyFileSystem.ExePath);
26 32 Journal("game:root:" + VRage.FileSystem.MyFileSystem.RootPath);
Modified tests/SpaceEngineersPluginManager.Validation/LoaderFixtureTests.cs +1 -0
@@ -25,6 +25,7 @@ internal static partial class Program
25 25 new PluginProfileStore().Save(new PluginProfileStore().Load(profile), fixture.Plugins.Select((path, index) => new StoredPlugin("fixture-" + index, Path.GetFileNameWithoutExtension(path), path, path, index != fixture.Plugins.Count - 1)));
26 26 var settings = new ManagerSettings { Bin64Path = fixture.Bin64, LauncherPath = built.LauncherPath, BridgePath = built.BridgePath, ProfilePath = profile, Arguments = ["中文 参数", "", "a\"b", @"C:\path with spaces\"] };
27 27 string[] journal = await RunOwnedLoaderAsync(GameRuntime.BuildStartInfo(settings, false), fixture);
28 Check(journal.Contains("game:dpi-awareness:2"), "native Windows loader enables per-monitor DPI before entering the game");
28 29 foreach (string healthy in new[] { "healthy-first", "healthy-second" })
29 30 Check(journal.Count(line => line == healthy + ":init:FixtureGame") == 1 && journal.Count(line => line == healthy + ":update") == 3 && journal.Count(line => line == healthy + ":input") == 3 && journal.Count(line => line == healthy + ":dispose") == 1, "actual bridge complete lifecycle isolated for " + healthy);
30 31 Check(journal.Count(line => line.EndsWith(":private-dependency-loaded")) == 6, "each enabled plugin resolves private dependencies outside game directory");
Modified tools/SpaceEngineersPluginManager/Code/Services/XfeLoaderBuilder.cs +5 -2
@@ -43,16 +43,18 @@ public sealed class XfeLoaderBuilder
43 43 cancellationToken.ThrowIfCancellationRequested();
44 44 progress?.Invoke("正在使用本机游戏程序集构建 XFE 自研加载器…");
45 45 string bootstrapSource = Path.Combine(staging, "XfeBootstrap.cs");
46 string bootstrapManifest = Path.Combine(staging, "XfeBootstrap.manifest");
46 47 string bridgeSource = Path.Combine(staging, "XfePluginBridge.cs");
47 48 string launcher = Path.Combine(staging, "XFE.SpaceEngineers.exe");
48 49 string bridge = Path.Combine(staging, "XFE.SpaceEngineers.Bridge.dll");
49 50 await File.WriteAllTextAsync(bootstrapSource, XfeLoaderSources.Bootstrap, cancellationToken);
51 await File.WriteAllTextAsync(bootstrapManifest, XfeLoaderSources.LauncherManifest, cancellationToken);
50 52 await File.WriteAllTextAsync(bridgeSource, XfeLoaderSources.Bridge, cancellationToken);
51 53 // Current VRage exposes IPlugin through the game's netstandard facade; older builds may not use it.
52 54 string[] bridgeReferences = new[] { Path.Combine(bin64, "VRage.dll"), Path.Combine(framework, "System.Runtime.Serialization.dll"),
53 55 Path.Combine(bin64, "netstandard.dll") }.Where(File.Exists).ToArray();
54 56 await CompileAsync(compiler, framework, bridgeSource, bridge, "library", bridgeReferences, cancellationToken);
55 await CompileAsync(compiler, framework, bootstrapSource, launcher, "winexe", Array.Empty<string>(), cancellationToken);
57 await CompileAsync(compiler, framework, bootstrapSource, launcher, "winexe", Array.Empty<string>(), cancellationToken, bootstrapManifest);
56 58 // CLR binding redirects and runtime settings must match the locally installed game.
57 59 File.Copy(Path.Combine(bin64, "SpaceEngineers.exe.config"), launcher + ".config", overwrite: false);
58 60 if (!SameHashes(gameHashes, HashGameFiles(bin64)))
@@ -122,7 +124,7 @@ public sealed class XfeLoaderBuilder
122 124 path.StartsWith(Path.TrimEndingDirectorySeparator(root) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase);
123 125
124 126 private static async Task CompileAsync(string compiler, string framework, string source, string output, string target,
125 string[] references, CancellationToken token)
127 string[] references, CancellationToken token, string? manifest = null)
126 128 {
127 129 var info = new ProcessStartInfo(compiler)
128 130 {
@@ -133,6 +135,7 @@ public sealed class XfeLoaderBuilder
133 135 "/reference:" + Path.Combine(framework, "System.dll"), "/reference:" + Path.Combine(framework, "System.Core.dll") })
134 136 info.ArgumentList.Add(argument);
135 137 foreach (string reference in references) info.ArgumentList.Add("/reference:" + reference);
138 if (manifest != null) info.ArgumentList.Add("/win32manifest:" + manifest);
136 139 info.ArgumentList.Add(source);
137 140 using var process = Process.Start(info) ?? throw new IOException("无法启动 .NET Framework 编译器。");
138 141 Task<string> standard = process.StandardOutput.ReadToEndAsync(token);
Modified tools/SpaceEngineersPluginManager/Code/Services/XfeLoaderSources.cs +19 -0
@@ -4,6 +4,25 @@ namespace XFEToolBox.Tools.SpaceEngineers;
4 4 // No game assemblies or third-party loader are distributed with this tool.
5 5 internal static class XfeLoaderSources
6 6 {
7 // Match the game's per-monitor DPI mode before CLR/game windows are created.
8 // A reflected entry point does not inherit the original executable's manifest.
9 public const string LauncherManifest = """
10 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
11 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
12 <assemblyIdentity version="1.0.0.0" name="XFE.SpaceEngineers.app" />
13 <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"><security><requestedPrivileges>
14 <requestedExecutionLevel level="asInvoker" uiAccess="false" />
15 </requestedPrivileges></security></trustInfo>
16 <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"><application>
17 <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
18 <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
19 </application></compatibility>
20 <application xmlns="urn:schemas-microsoft-com:asm.v3"><windowsSettings>
21 <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
22 </windowsSettings></application>
23 </assembly>
24 """;
25
7 26 public const string Bootstrap = """
8 27 using System;
9 28 using System.Collections.Generic;
Modified tools/SpaceEngineersPluginManager/README.md +4 -0
@@ -40,8 +40,12 @@ XFE ToolBox 的独立源码工具,包含自行实现的 **XFE Loader**。启
40 40
41 41 构建记录游戏关键程序集、原配置和 XFE 产物的 SHA-256。游戏更新或加载器产物变化后,启动检查会要求重新构建。工具包只分发源码,不包含游戏程序集或预编译的加载器二进制。
42 42
43 1.0.1 的启动引导包含与原版游戏一致的按显示器 DPI 感知声明。旧引导在 Windows 150% 等缩放下会被系统按位图放大,即使设置中显示 3840×2160,画面仍可能模糊。更新工具后需重新构建加载器并重启游戏;不需要降低分辨率或更改全局 Windows 缩放。
44
43 45 ## 验证
44 46
45 47 验证项目位于仓库的 `tests/SpaceEngineersPluginManager.Validation`,覆盖配置冲突与恢复、参数传递、正常退出与取消、文件同步、WPF 绑定和窗口布局,并调用 ToolBox 实际宿主编译和包校验流程。
46 48
47 49 集成夹具会使用真实生成的 XFE 启动引导和插件桥启动独立的模拟游戏进程,验证七个 .NET Framework 插件的生命周期、异常隔离、依赖解析、禁用状态和退出码。另已针对本机 Space Engineers **1.210.014** 的实际程序集编译通过。自动验证没有启动、关闭或修改用户的真实游戏;实际进游戏运行效果仍需首次使用时验证。
50
51 DPI 回归夹具在假游戏入口读取进程 DPI 感知级别,确保它在游戏创建窗口前已为 per-monitor(2)。2026-11-17 在真实游戏 1.210.014、150% Windows 缩放上验证:窗口 DPI 144,渲染、视口与后缓冲均为 3840×2160,动态分辨率关闭。
Modified tools/SpaceEngineersPluginManager/manifest.json +2 -2
@@ -3,14 +3,14 @@
3 3 "id": "xfestudio.space-engineers-plugin-manager",
4 4 "name": "太空工程师插件管理器",
5 5 "subtitle": "XFE 自研加载器 · 插件管理与自动重启",
6 "version": "1.0.0",
6 "version": "1.0.1",
7 7 "description": "为 Space Engineers 构建独立的 XFE 插件加载器,管理本地插件及依赖、启用清单和启动参数,支持正常启动、退出、重启、源文件变化后同步以及配置备份恢复。",
8 8 "author": "XFEstudio",
9 9 "icon": "Assets/icon.png",
10 10 "category": "游戏工具",
11 11 "tags": ["Space Engineers", "太空工程师", "插件", "XFE Loader", "开发"],
12 12 "minimumHostVersion": "1.2.1",
13 "releaseNotes": "首个版本:自研 XFE 加载器、本地插件与依赖管理、游戏启停、源文件监视、自动重启与配置备份。",
13 "releaseNotes": "修复自研加载器缺少 DPI 声明导致高分屏画面模糊的问题;重新构建加载器并重启游戏后生效。",
14 14 "nugetPackages": [],
15 15 "requiresAdministrator": false,
16 16 "entry": {