Compile patches.c per install instead of into the prebuilt runtime library

The release built libtotkrt.a against generated/v121, so patches.c baked in 1.2.1's patch page (0x700472b000, the page
after 1.2.1's main). A 1.4.3 install lifts its code with the 1.4.3 patch table, whose patched sites read the page after
1.4.3's main (0x7003adf000): the runtime never committed it and the game faulted there soon after mounting the save, while
frame_rate.c wrote its frame step into sdk memory at the 1.2.1 address. patches.c now joins romfs.c in INSTALL_SIDE and
the release ships its source, so it compiles against the player's patches.h.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-10-27 09:12:15 +03:00
1 parent e1476494d5
commit 7fefa86fe3
4 files changed
+13 -9

No files matched your search

+3 -2
View File
@@ -45,7 +45,8 @@ keeps `profile/`. Saves carry over both ways: 1.4.3 converts a 1.2.1 save on loa
2. **Extract** ExeFS and RomFS into the install folder and verify the hashes.
3. **Lift** the ExeFS to C (`recomp/gen.py`, `recomp/patches-v121.txt` or `patches-v143.txt`) into a temp folder next
to the installer.
4. **Compile** the generated C, `modules.c` and `romfs.c` (they bake per-install layout and RomFS hashes) and link
4. **Compile** the generated C, `modules.c`, `romfs.c` and `patches.c` (they bake the per-install layout, RomFS
hashes and the game version's patch page) and link
them with the prebuilt runtime library into `totk.exe` (`build_game.py --runtime-lib`; about 3 min on 24 cores).
5. **Prepare** the RomFS patches and the shaders (`tools/make_romfs_patches.py`, `tools/prepare_shaders.py`,
`totk.exe --prepare-shaders`) in the install folder.
@@ -91,7 +92,7 @@ installer/ the installer: steps, CLI, window, en/ru text catalog
python/ Python 3.14.9 embeddable + numpy, lz4, cryptography, cffi, pycparser (+ tkinter for the window)
recomp/, tools/ the lifter and the build, extraction and shader scripts the steps run (copied from the repo)
llvm/ llvm-mingw, x86_64-only subset (Apache-2.0 with LLVM exception; mingw-w64 parts permissive)
runtime/ libtotkrt.a and the headers the generated code and modules.c/romfs.c include
runtime/ libtotkrt.a and the headers the generated code and modules.c/romfs.c/patches.c include
bin/ totk_xlate.exe, hactool.exe, SDL3.dll, libopus-0.dll, ninja.exe
data/ shader_list.tsv (MacNativeGames, MIT)
THIRD_PARTY_NOTICES.md
+1 -1
View File
@@ -7,7 +7,7 @@ Release (docs/installer.md "Release layout"), root = the unpacked folder:
recomp/, tools/ the lifter and the scripts; recomp/patches-<v>.txt, tools/data/expected-v<version>.json for
each supported update (SUPPORTED)
llvm/ llvm-mingw (bin/clang.exe)
runtime/ libtotkrt.a, the headers, install-side sources (romfs.c) and totk.ico; runtime/deps/ holds
runtime/ libtotkrt.a, the headers, install-side sources (romfs.c, patches.c) and totk.ico; runtime/deps/ holds
include/ + lib/ of Vulkan, SDL3, Opus, libvpx and VMA (build_game.py --deps)
bin/ totk_xlate.exe (+ totk_xlate.id), hactool.exe, ninja.exe, SDL3.dll, libopus-0.dll
data/shader_list.tsv the MacNativeGames shader list
+4 -2
View File
@@ -44,7 +44,7 @@ runtime is libc++ from llvm-mingw. Such a build never reuses another build's gen
Split build. --make-runtime-lib compiles only runtime/ into <out>/libtotkrt.a (what CI prebuilds). --runtime-lib PATH
then compiles only the generated C and the install-time files (modules.c and INSTALL_SIDE, which bake the player's
game hashes in) and links them with that library. The library holds no game-derived data.
game hashes and version in) and links them with that library. The library holds no game-derived data.
Standard library only.
"""
@@ -84,7 +84,9 @@ VMA_INCLUDE = UCRT.parent / 'include' / 'vma' # vk_mem_alloc.h; MSYS2 package
LLVM_LINK_LIBS = ['-lpsapi', '-lbcrypt', '-luser32', '-lgdi32', '-ldwmapi', '-lwinmm', '-lvulkan-1', '-lSDL3', '-lopus',
'-l:libvpx.a', '-l:libc++.a', '-l:libc++abi.a', '-l:libunwind.a', '-l:libwinpthread.a']
DEFAULT_DEPS = ROOT / 'toolchain' / 'deps-mingw'
INSTALL_SIDE = {'romfs.c'} # runtime sources that include romfs_config.h: compiled per install, not in the library
# Runtime sources compiled per install, not in the library: romfs.c includes romfs_config.h, patches.c the patches.h
# of the player's game version (its patch page is the page after that version's main).
INSTALL_SIDE = {'romfs.c', 'patches.c'}
LIB_NAME = 'libtotkrt.a'
AR = UCRT / 'llvm-ar.exe'
WINDRES = UCRT / 'windres.exe' # runtime/totk.rc: the manifest of totk.exe
+5 -4
View File
@@ -10,8 +10,8 @@ cached in toolchain/release-dl/ and checked against the sha256 in PINS; a mismat
files come out of the python.org installer's own component MSI, unpacked with msiexec /a and expand.exe;
the installer is never run)
llvm/ llvm-mingw, x86_64 only, the files clang and lld need to compile and link totk.exe
runtime/ libtotkrt.a (build_game.py --make-runtime-lib with llvm/), the runtime headers, romfs.c (compiled per
install), deps/ (headers and import libraries of SDL3, Opus, libvpx, Vulkan and VMA)
runtime/ libtotkrt.a (build_game.py --make-runtime-lib with llvm/), the runtime headers, romfs.c and patches.c
(compiled per install), deps/ (headers and import libraries of SDL3, Opus, libvpx, Vulkan and VMA)
bin/ totk_xlate.exe (+ .id), hactool.exe, SDL3.dll (upstream), libopus-0.dll, ninja.exe
recomp/, tools/, data/, installer/, licenses/, THIRD_PARTY_NOTICES.md, totk.ini.example
VERSION git describe of the checkout (else the short hash); the installer's release string
@@ -321,7 +321,7 @@ def collect_licenses(out):
# ---- runtime/, recomp/, tools/, data/ ---------------------------------------------------------------------------------
def runtime_lib(out, llvm):
"""Build libtotkrt.a with the folder's llvm/ and copy it, the headers and romfs.c into runtime/."""
"""Build libtotkrt.a with the folder's llvm/ and copy it, the headers and the install-side sources into runtime/."""
build = MAIN_ROOT / 'build' / 'release-check' / 'rtlib'
gen = MAIN_ROOT / 'generated' / 'v121'
run([sys.executable, ROOT / 'tools' / 'build_game.py', '--make-runtime-lib', '--toolchain', llvm,
@@ -333,7 +333,8 @@ def runtime_lib(out, llvm):
if p.suffix in RUNTIME_SUFFIXES and p.is_file():
(rt / p.relative_to(ROOT / 'runtime')).parent.mkdir(parents=True, exist_ok=True)
shutil.copy2(p, rt / p.relative_to(ROOT / 'runtime'))
shutil.copy2(ROOT / 'runtime' / 'romfs.c', rt / 'romfs.c') # build_game.py INSTALL_SIDE
for name in ('romfs.c', 'patches.c'): # build_game.py INSTALL_SIDE
shutil.copy2(ROOT / 'runtime' / name, rt / name)
def build_sources(out):