mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-24 13:45:57 +00:00
Mod plugins that hook the middle of game functions, swap pointers in the game's data, use the SD card or switch their hooks during play build in, and may call what the game itself calls; Zonai Fieldworks starts (#1388)
Zonai Fieldworks was refused at several steps; each is now handled: 1. The start-up asked GetInfo 6, 7, 16 and 17 and SetHeapSize; runtime/plugin_init.c serves them. 2. Its start-up calls main where the lift has no function start. The tool names those addresses (--entries-out) and the installer lifts again with them as `entry` lines, up to four rounds (installer/steps.py PLUGIN_ENTRY_ROUNDS). 3. Branch hooks into the middle of game functions (far-jump veneers) and pointer swaps in main's data are accepted hook kinds; the veneer targets seed the plugin's lift, and an Orig trampoline counts as a seed. 4. Code the start-up writes into the plugin's own .text (hook pads it switches to during play) is found by comparing the image before and after the init, and seeds the lift (init_code). Without it the game stopped with "no function at guest pc" when a feature switched on. 5. recomp/gen.py: a branch-out alternative on a flag-writing site leaves with the flags from before the site; an inline hook may sit on a blr. 6. nn::fs::MountSdCard mounts <profile>/sdcard (runtime/fs_host.c), and nn::settings language codes are answered (runtime/ov_system.c). The import check now also allows what the game's main imports (--exefs, game_imports): the game runs on those paths, so the runtime serves them. Left out: nn::ro, the C runtime start, the thread-local allocator hook and the shader compiler. Break in code the hooks reach is allowed (an abort ends the game with the reason, as on the Switch), and RenameFile, DeleteDirectoryRecursively, Commit and Unmount join the SD card calls. Checked: Zonai Fieldworks, The Second Quest, Challenge Mode and Material Columns on 1.4.3, Full Inventory Expansion, Quick Weapon Durability and Magic of the Kingdom on 1.2.1 accepted; UltraCam's init still crashes its service run. Plain lift unchanged; probes 4/4 on both versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
942b6b7b2b
commit
3fe8d7a1d9
9 files changed
+552
-136
No files matched your search
+34
-14
@@ -64,6 +64,7 @@ TEMP_NEED = 3 * GiB # generated C (about 0.9 GB) and objects
|
||||
KIT_NEED = 1 * GiB # the build kit (Kit), about 0.65 GB
|
||||
HOSTCHECK = Path(__file__).resolve().parent / 'hostcheck.c'
|
||||
STAMP = '.install-key'
|
||||
PLUGIN_ENTRY_ROUNDS = 4 # plugin lifts at most: each finds where an init called into main past a function start
|
||||
|
||||
|
||||
# ---- helpers
|
||||
@@ -1246,20 +1247,39 @@ class Lift(Step):
|
||||
lift_plugins = []
|
||||
if plugins:
|
||||
listed = ['--plugins', ','.join(str(f) for f in plugins)]
|
||||
code, log = run_tool(ctx, 'lift', layout.recomp / 'gen.py', args + ['--patches', patches] + listed, parse)
|
||||
if not code:
|
||||
code, log = run_tool(ctx, 'lift', layout.tools / 'build_game.py', build_args(ctx, gen))
|
||||
if not code:
|
||||
# the service run's totk.exe loads its DLLs from its own folder, as the installed one does
|
||||
for dll in layout.dlls:
|
||||
replace_file(dll, ctx.temp / 'build' / dll.name)
|
||||
code, log = run_tool(ctx, 'lift', layout.tools / 'exefs_plugins.py', [
|
||||
'--exe', ctx.temp / 'build' / ('totk' + EXE), '--out', ctx.temp / 'plugins', '--mods',
|
||||
ctx.dest / 'mods', '--patches', patches, '--patches-out', ctx.temp / 'patches-plugins.txt',
|
||||
'--status', plugins_status(ctx)])
|
||||
# exit 1 with a status file: refused plugins, their reasons in it; the rest goes on
|
||||
if plugins_status(ctx).is_file() and (ctx.temp / 'patches-plugins.txt').is_file():
|
||||
code = 0
|
||||
# An init that calls into main where the lift has no function start crashes its service run; the tool
|
||||
# names those addresses (--entries-out), and one more lift with them as `entry` lines lets the init go on
|
||||
# (Zonai Fieldworks calls the second word of a 1.4.3 function). Each round adds what the last one found.
|
||||
lift_patches, found = patches, []
|
||||
for _ in range(PLUGIN_ENTRY_ROUNDS):
|
||||
code, log = run_tool(ctx, 'lift', layout.recomp / 'gen.py', args + ['--patches', lift_patches] + listed,
|
||||
parse)
|
||||
if not code:
|
||||
code, log = run_tool(ctx, 'lift', layout.tools / 'build_game.py', build_args(ctx, gen))
|
||||
if not code:
|
||||
# the service run's totk.exe loads its DLLs from its own folder, as the installed one does
|
||||
for dll in layout.dlls:
|
||||
replace_file(dll, ctx.temp / 'build' / dll.name)
|
||||
entries_file = ctx.temp / 'plugin-entries.txt'
|
||||
entries_file.unlink(missing_ok=True)
|
||||
code, log = run_tool(ctx, 'lift', layout.tools / 'exefs_plugins.py', [
|
||||
'--exe', ctx.temp / 'build' / ('totk' + EXE), '--out', ctx.temp / 'plugins', '--mods',
|
||||
ctx.dest / 'mods', '--exefs', ctx.dest / 'exefs', '--patches', lift_patches,
|
||||
'--patches-out', ctx.temp / 'patches-plugins.txt', '--status', plugins_status(ctx),
|
||||
'--entries-out', entries_file])
|
||||
# exit 1 with a status file: refused plugins, their reasons in it; the rest goes on
|
||||
if plugins_status(ctx).is_file() and (ctx.temp / 'patches-plugins.txt').is_file():
|
||||
code = 0
|
||||
if code:
|
||||
break
|
||||
new = [line for line in (entries_file.read_text(encoding='utf-8').splitlines()
|
||||
if entries_file.is_file() else []) if line and line not in found]
|
||||
if not new:
|
||||
break
|
||||
found += new
|
||||
lift_patches = ctx.temp / 'patches-entries.txt'
|
||||
lift_patches.write_text(Path(patches).read_text(encoding='utf-8') + '\n' + '\n'.join(found) + '\n',
|
||||
encoding='utf-8')
|
||||
if code:
|
||||
drop([plugins_status(ctx)])
|
||||
skipped['warn.plugins_skipped'] = log
|
||||
|
||||
Reference in new issue
Block a user