PS2Recomp README

项目的 README,来自 github.com/ran-j/PS2Recomp。合并为一个 markdown 文件:README.md。

PS2Recomp: PlayStation 2 Static Recompiler (Experimental)

Discord

Also check our WIKI

This project statically recompiles PS2 ELF binaries into C++ and provides a runtime to execute the generated code.

Modules

Features

How It Works

PS2Recomp works by:

The translated code is very literal, with each MIPS instruction mapping to a C++ operation. For example, addiu $r4, $r4, 0x20 becomes ctx->r4 = ADD32(ctx->r4, 0X20);.

Current Behavior

Requirements

Build

git clone --recurse-submodules https://github.com/ran-j/PS2Recomp.git
cd PS2Recomp

cmake -S . -B out/build
cmake --build out/build --config Debug

Usage

Preferred workflow for retail or stripped games:

  1. Open the ELF in Ghidra.
  2. Run ps2xRecomp/tools/ghidra/ExportPS2Functions.java.
  3. Use the exported TOML and CSV map.
  4. Recompile with the exported TOML:
./ps2_recomp config.toml

Fallback workflow for quick local experiments or ELFs with debug symbol :

./ps2_analyzer your_game.elf config.toml

See the Ghidra Workflow for ghdira instructions.

Then build generated output and link with ps2xRuntime.

Configuration

Main fields in config.toml:

Address binding for stripped ELFs:

Example:

# stripped function binding by address:
stubs = ["sceCdRead@0x00123456", "SifLoadModule@0x00127890"]
# temporary return handlers:
stubs = ["ret0@0x001D9410", "ret1@0x001D5BC8", "reta0@0x0024B7C0"]
# mixed example:
stubs = ["printf", "sceCdRead@0x00123456", "SifLoadModule@0x00127890"] 

Runtime

To execute the recompiled code.

ps2xRuntime currently provides:

See IOP emulation for module execution and the service boundary.

Game Override Hooks

Game overrides are runtime-side, build-scoped patch modules.

A game override is C++ code that runs during loadELF and can replace EE function bindings by address for one specific game build. IOP RPC/DMA behavior is handled by the ps2xIOP emulator and its runtime transport. This is separate from recompilation output and separate from global runtime stubs/syscalls.

API:

Use Game Override modules when:

  1. Run with minimal config and no aggressive skipping.
  2. Fix hard blockers first (function not found, syscall TODO, critical IO stubs).
  3. Use temporary return stubs only to classify call importance.
  4. Promote temporary fixes to real implementations.
  5. Move per-game hacks into game overrides keyed by ELF metadata.
  6. Re-test from cold boot after each batch.

Describing Your Game Project

A game project built with PS2Recomp can describe itself in a .recomp.json file at the root of its repository. Lists of recomp and decomp projects, such as recomp.board, read that file instead of guessing the game, system and status from the README.

[!NOTE] This file is optional: PS2Recomp does not read it and works the same without it. .recomp.json and recomp.board are third-party projects; the PS2Recomp developers have no ties to them.

Starter file:

{
  "$schema": "https://recomp.fyi/schema/v1.json",
  "game": "<title as it shipped>",
  "system": "PS2",
  "type": "recomp",
  "toolchain": "PS2Recomp",
  "status": "in-progress",
  "original": { "region": "USA", "serial": "SLUS-20312" }
}

Other fields (Wikidata item, target platforms, maintainers, links, what help is wanted) and the JSON Schema are in the specification.

Limitations

Acknowledgments

PS2Recomp (ran-j/PS2Recomp)

正在搜索数据库…

这是什么?PS2Recomp 会将 PlayStation 2 的 ELF 二进制文件静态重编译为 C++ 源代码,并提供一个运行时来执行生成的代码,让你能够构建 PS2 游戏的原生 PC 移植版本。
这是模拟器还是编译工具链?它是一套工具链,而不是像 PCSX2 那样的模拟器:ps2xRecomp 会把 MIPS R5900 指令逐条翻译成直译的 C++ 代码,ps2xRuntime 在真实硬件上执行生成的代码,ps2xIOP 则运行原始的 IOP 模块,并在必要时使用 HLE 回退方案。
我该如何用它把 PS2 游戏的 ELF 转换成 C++ 代码?对于正式发行版或去除了符号信息的游戏,先在 Ghidra 中打开 ELF 文件,运行随附的 ExportPS2Functions.java 脚本,生成 TOML/CSV 函数映射表,然后使用导出的 TOML 进行重编译,并将生成的输出与 ps2xRuntime 链接。
构建前需要安装哪些东西?你需要 CMake 3.20 或更高版本、C++20 编译器(目前主要在 MSVC 上测试),以及支持 SSE4/AVX 的主机 CPU(部分向量翻译路径需要);如果是正式发行版游戏,还需要 Ghidra。
生成的代码能全速运行吗?不能。目前 VU 和 GS 代码路径的性能非常差,硬件模拟也只是部分实现,许多函数仍是存根,需要针对每款游戏逐一实现。
这个项目能在哪些操作系统上构建和运行?构建基于 CMake,目前主要在 Windows 上使用 MSVC 测试;其他编译器或平台尚未确认支持。
配置文件中的 stub 条目和 skip 条目有什么区别?stub 条目会生成对已知运行时系统调用/存根处理程序的包装调用(包括按地址绑定的形式,例如针对去除了符号信息的游戏使用的 sceCdRead@0xADDRESS),而 skip 条目不会被重编译,只会生成明确的 TODO 包装调用。
游戏覆盖钩子(Game Override hooks)是用来做什么的?它们是构建范围内的 C++ 模块,在 loadELF 期间运行,允许你针对某个确切的游戏构建版本,按地址替换特定的 EE 函数绑定,从而把每款游戏的专属修改与全局运行时存根和系统调用分开。
为什么不直接在 PCSX2 中运行游戏,而要用这个?PS2Recomp 的目标是把游戏的 MIPS 代码转换为编译后的 C++,从而得到原生的独立 PC 移植版(思路上类似 N64Recomp),而不是像 PCSX2 那样在运行时模拟原始 PS2 指令;PCSX2 仅被用作运行时行为的参考。
`.recomp.json` 文件是做什么用的?它是一个可选的元数据文件,移植游戏的项目可以包含它,用来描述原始发行版本、序列号、地区和移植状态;PS2Recomp 本身从不读取它,但 recomp.board 等第三方目录会使用它,而不是去猜测项目细节。
作者
ran-j
大小
5.6 MB
星标
3.9K
更新
提交Oct 23
时长
1年
提交 · 90 天