Hacknet-Pathfinder 的 .NET 9 移植版。
让 Pathfinder(Hacknet 的 modding API 与 loader)在 Hacknet 的 .NET 9 移植版上完整运行——
包括全部 32 个 [HarmonyILManipulator] IL patch 和所有依赖它的第三方 mod。
- Arkhist — Hacknet-Pathfinder 原作者
- 原始版权(MIT):Benjamin Peyrille, George L. Albany, Aaron Robinson
本仓库基于 Hacknet-Pathfinder 的 MIT 许可源码修改。原许可证见 LICENSE。
Pathfinder 原版面向 .NET Framework(net472),依赖 BepInEx 的 Harmony fork(2.5.5)。
其独有的 [HarmonyILManipulator] 特性在 .NET Core / .NET 5+ 上会触发 CLR 级崩溃:
PrepareMethod → MonoMod detour → 0x80131506
因此 net472 编译的 Pathfinder 在现代 .NET 上要么无法加载,要么 patch 全部失效。
- 运行时改用官方 Harmony 2.4.2(net9 下稳定,Detour/transpiler 管道经大量插件验证不炸)。
- 新增
ILModBridge桥接层(ILModBridge/,本移植的核心创新):- 用 MonoMod.Cil 在纯内存跑 ILManipulator(不触碰 JIT / RuntimeDetour)
- 结果经 2.4.2 已验证安全的 transpiler 管道写回目标方法
- 自动识别
[HarmonyILManipulator]方法并分组注册,兼容运行时注册(MiscPatches.cs路径) - 内置 ReversePatch 支持(
CreateReversePatcher+ 保活,避免 detour 悬垂)
- 修复 Roslyn 重编译差异:net9 移植版的 Hacknet.dll 是 Roslyn 重编译,局部变量编号 / 分支形式 / 比较指令与原 Mono 编译不同(
MatchLdloc(1)实为V_27、stloc 9实为V_30、brtrue↔brfalse、cgt↔cgt.un等),全部 patch 逐一适配。 - transpiler 对已 JIT 方法不生效的问题:标题 patch 从 ILManipulator 改写为
[HarmonyPrefix]。
| 模块 | 修复 |
|---|---|
Executable/ExecutableManager |
onOSUpdate / programsKillFix 局部变量 out 捕获、leave 标签锚点 |
Port/ComputerExtensions |
FixCommandProbe / FixDisplayProbe / FixPortCrackers 指令序差异 |
Event/Gameplay/ExecutableExecuteEvent |
6 参注入去 ref、exeData 变量编号适配 |
Event/Menu/DrawMainMenuTitlesEvent |
ILManipulator → HarmonyPrefix(transpiler 对已 JIT 方法不应用) |
BaseGameFixes/Performance/NodeLookup |
DrawIPEntryScreen / DrawLoadingScreen / RebuildBeforePostLoadDLC / connect 循环锚点 |
BaseGameFixes/FlickeringTextReportNull |
private 字段 BindingFlags |
BaseGameFixes/FixTutorialStartup |
栈泄漏修复、AdvancedTutorial.Killed 目标序列 |
BaseGameFixes/Performance/ThemeCaching |
cgt.un、ref float 去 ref(EmitDelegate 对 ref 值类型 NRE) |
Replacements/ActionsLoader / ContentLoader |
流 / 读取器局部变量 out 捕获 |
BaseGameFixes/KillExeCheckIdentifierName |
只匹配前三项、Ldc_I4_0; Ceq; And→Or |
BaseGameFixes/DontLosePlayerCompAdmin / KeepBranchesOnMailMissionCompletion |
局部变量 out 捕获 |
BaseGameFixes/FixExtensionTests |
brfalse 取反、File.Exists 内联取反 |
| 用途 | 版本 | 位置 |
|---|---|---|
| 编译期:Pathfinder 源码引用的 API | 2.5.5 | libs/0Harmony.dll |
| 编译期:ILModBridge 引用 | 2.4.2(net35) | libs/0Harmony.net35.dll |
| 运行期:游戏进程加载 | 2.4.2(net9 core) | 由 Hacknet 的 .NET 9 版运行环境提供,ILModBridge 负责桥接 |
Pathfinder.net9/
├─ PathfinderAPI/ # Pathfinder 插件本体(net9 修复后的源码)
├─ BepInEx.Hacknet/ # Pathfinder 的 BepInEx 宿主
├─ ILModBridge/ # ILManipulator 桥接层(移植核心)
├─ libs/ # 构建依赖(0Harmony 2.5.5 / 2.4.2 net35、MonoMod.Utils、Mono.Cecil、BepInEx.Core 等)
├─ Configurations.props # 构建配置
└─ LICENSE / README.md
- .NET SDK(需要支持 net472 与 net8.0-windows 目标)
- Hacknet 游戏文件:
HacknetPathfinder.exe、FNA.dll—— 版权原因不随仓库分发,请放入libs/ - Hacknet 的 .NET 9 版(运行时验证)
cd ILModBridge
dotnet build -c Debugcd PathfinderAPI
dotnet build PathfinderAPI.csproj -c Debug -p:DisableBepInExHacknetPrepareForBuild=trueILModBridge.dll→bin/Debug/net9.0/BepInEx/core/PathfinderAPI.dll→bin/Debug/net9.0/BepInEx/plugins/- 运行游戏,BepInExLoader 输出每方法的 patch 成功/失败日志
- ReversePatch 依赖 MonoMod.Core detour,个别方法(
CachedCustomTheme.GetLayoutForTheme)在 net9 x64 下 trampoline 崩溃——已通过禁用 ThemeCaching 的两个 switchTheme prefix 止血(主题切换走原版,仅丢缓存优化)。 - 少量 IL patch(
Emit(ILLabel)前向分支场景)在 2.4.2 + MonoMod 21.9.19.1 组合下暂不可用,需要 MonoMod 版本升级。
MIT,保留原作者版权。见 LICENSE。