No description
  • C 57.4%
  • Python 32%
  • Objective-C 7.4%
  • M 1%
  • C# 0.9%
  • Other 1.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-17 17:36:22 +09:00
.claude/skills Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
cmake Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
docs Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
games Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
hub Sync working tree: drop legacy runtime/runtime32/a32, add hub, ABI/manifest/shader pipeline, vendored hactool/stb/ghidra loader 2026-10-17 15:01:41 +09:00
pipeline Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
runtime64 Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
tests Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
third_party Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
tools Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
.DS_Store Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
.gitignore nxnative: AI-native Switch -> x86-64 recompiler, initial version 2026-10-16 22:43:57 +09:00
CLAUDE.md Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
CMakeLists.txt Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
CMakePresets.json nxnative: AI-native Switch -> x86-64 recompiler, initial version 2026-10-16 22:43:57 +09:00
LICENSE Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
nx.local.toml.example Sync working tree: drop legacy runtime/runtime32/a32, add hub, ABI/manifest/shader pipeline, vendored hactool/stb/ghidra loader 2026-10-17 15:01:41 +09:00
nx.py Rename copyright holder to forgotway; sync working tree 2026-10-17 17:36:22 +09:00
README.md Sync working tree: drop legacy runtime/runtime32/a32, add hub, ABI/manifest/shader pipeline, vendored hactool/stb/ghidra loader 2026-10-17 15:01:41 +09:00
requirements.txt nxnative: AI-native Switch -> x86-64 recompiler, initial version 2026-10-16 22:43:57 +09:00

nxnative

把 Switch 游戏静态重编译为 x86-64 原生程序的 AI 原生流水线:ARM64 → LLVM IR → x86,SDL3 运行时,目标是"尽可能原生",而不是用 C 和内存模拟 ARM CPU。一个仓库管理多款游戏。

个人项目,P0 阶段:FE3H 已经用 IR 生成的代码跑通开场动画。只处理你自己合法 dump 的游戏,仓库里不含任何游戏数据、密钥或泄露材料。

为什么是"AI 原生"

每款游戏都不一样:入口点、间接跳转、SDK 版本、中间件、GPU 用法、需要的 HLE 都不同。

  • 确定性的部分由脚本完成:解包、提升、编译、差分验证。
  • 每款游戏要做的判断交给 AI 代理:补 HLE、修画面、加补丁、二分定位。代理的改动收在 games/<title>/,每一步都要过自动验证门禁。

见 CLAUDE.md 和 .claude/skills。

使用

python nx.py new fe3h "D:/switch/.../BEN+1.2+6.xci" --name "Fire Emblem: Three Houses"
python nx.py build fe3h          # 生成 IR,CMake/Ninja 编译(共享运行时 nxrt 只编一次)
python nx.py run fe3h            # 运行;遗漏的间接跳转目标自动补入口、重建、再跑
python nx.py difftest fe3h       # 用这款游戏的代码做逐指令差分测试
python nx.py list                # 所有游戏的状态

其中 new 会完成解包,写入 data/fe3h,并生成 games/fe3h/game.toml。

一次性准备:

  1. py -3.13 -m venv .venv && .venv\Scripts\pip install -r requirements.txt
  2. 复制 nx.local.toml.example 为 nx.local.toml,填写 prod.keys 和 vcpkg 的路径。
  3. 分析工具(可选):python nx.py tools 编译 hactool 和 Ghidra 的 Switch 加载器,再用 python nx.py ghidra <title> 为一款游戏建 Ghidra 工程。详见 tools/README.md。

工具链:

  • clang/lld 18+ 是硬性要求。 游戏代码是 LLVM IR;运行时和回退代码用了 clang 的 GNU C 扩展,MSVC/clang-cl 和 GCC 都不行。
  • CMake 3.25+ 和 Ninja(CMakePresets.json)。
  • vcpkg:SDL3、Vulkan、VMA、libvpx、libvorbis,以及 shaderc 包里的 glslc(构建时编译运行时自带的着色器;运行时不带 GLSL 编译器)。
  • .NET 10 SDK:用于编译离线着色器翻译器 tools/ryuxlate(dotnet build tools/ryuxlate -c Release --artifacts-path build/ryu)。

原生化层级

层级 内容 状态
L1 逐指令翻成 C,状态全在内存 用作回退和参考语义(tools/lifter.py)
L2 LLVM IR:寄存器在 SSA/host 寄存器里,标志位是 i1,guest 内存直接 load/store,alias scope 隔离 P0:整数、访存、控制流已原生化(FE3H main 84%,其余模块 96–99%)
L3 恢复 AAPCS64 调用约定,栈帧提升 P2
L4 库替换:libc/libm/nn::/NVN/中间件改用 host 实现 P3
L5 AI 把热点函数改写成 C++,并做等价验证 P5

目录

nx.py                 命令行入口(多游戏)
pipeline/             a64ir.py(ARM64→LLVM IR)、nxgen.py(模块→IR 分块)、build.py(gen + CMake)
CMakeLists.txt, cmake/  共享运行时 nxrt(OBJECT 库)+ 每款游戏一个可执行文件(nx_game)
runtime64/                      运行时:内核、IPC、服务、HLE、NVN→Vulkan、SDL3 窗口
tools/                前端:NSO 加载、函数划分、跳转表、逐指令 C;hle/hlekit;unpack/nxunpack.py
tests/difftest.py     逐指令差分:IR 和参考 C 在随机状态下逐字节比对
games/<title>/        每款游戏的配置和 AI 交接记录(在 git 里)
data/<title>/         解包后的游戏文件(不进 git)
build/<title>/        gen/、<title>.exe、rundir/(存档、日志、截帧);build/cmake:CMake 树
third_party/          ryujinx(Ryujinx.Graphics.Shader、Ryujinx.Common、Spv.Generator 1.3.2,MIT,带几处 nxnative 补丁)、SMAA、字体
tools/ryuxlate/       NVN 着色器唯一的翻译器(Ryujinx → SPIR-V,离线);pipeline/shaders.py 打包成 rundir/shaders.pak
docs/                 ARCHITECTURE.md、QUICK_RESUME.md、PROVENANCE.md

来源与参考

  • 代码来源: runtime*/ 和 tools/ 来自作者的 lasrecomp 项目,现在是 nxnative 的一部分(见 docs/PROVENANCE.md)。
  • 思路参考:
    • d2r-mobile:离线着色器流水线(Ryujinx.Graphics.Shader → SPIR-V)、在 NVN 层录制与回放、hactool 的 BKTR 补丁。
    • Ryujinx(MIT):着色器翻译器、HLE 服务的行为。
    • libnx(ISC)、switchbrew:SVC、IPC 和服务的定义。
  • 只作为识别参考: OdysseyDecomp、open-ead/sead,用于辨认第一方库的名字和布局,不复制实现代码。
  • 不使用: ScarletNX(GPL-3.0)的代码,以及任何泄露材料。