mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-19 04:15:57 +00:00
Merge task/abilityguard: a stale Recall / Ultrahand target is dropped only where the game would fault on it, replacing the 4 GiB target check, and the model scene report loop gets a bound (#1005, #1137, #1145)
The ability guard (runtime/ov_ability.c) checks the holder, the actor, its component and the reference word the game writes, so it catches every bad target seen in the reports: -1, 0x80, an empty bounding box (FLT_MAX) and a vtable in main's data. The optref site at main+0x1bd01c8 (1.2.1: 0x1622bf4) is dropped: set ability patches the same address and must win there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
e6839387fc
8 files changed
+161
-19
No files matched your search
@@ -49,13 +49,13 @@ GPU semantics behind the graphics rows: [maxwell.md](../maxwell.md). The method
|
||||
| a host core at 100% while the game waits | game spin loops without system calls | profile: which guest function spins |
|
||||
| crash on world load | sizes the game reads from the driver (command memory used) differ from the console's | the sizes the game asks for against the console's |
|
||||
| crash with one save only | the save itself; some crash on a real Switch | the same save on another build and, if possible, on hardware |
|
||||
| random crash after minutes to hours, access violation reading `0xffffffffffffffff` or a small address such as `0x90` in a game function | an invalid value (-1, `0xffff0000ffffffff`) in an optional reference the game checks only for null, or a freed holder whose first word reads as a small number; set `optref` in `recomp/patches-v143.txt` guards main+0x1bd0138 for both | the crash dump's faulting host instruction, the register it loads through and the field that register came from |
|
||||
| random crash after minutes to hours, access violation reading `0xffffffffffffffff` or a small address such as `0x90` in a game function (Windows reports any non-canonical address as `0xffffffffffffffff`) | an invalid value (-1, `0xffff0000ffffffff`) in an optional reference the game checks only for null; in main+0x1bd0138 (Recall / Ultrahand picking a target) also a reused holder whose actor points into other memory. Sets `optref` and `ability` in `recomp/patches-v143.txt` guard both there | the crash dump's faulting host instruction, the register it loads through and the field that register came from; `ability: target dropped` lines in the log |
|
||||
| crash while using Ultrahand or aiming, in the model scene's report loop (1.4.3 main+0xa22bc..0xa234c) | a report row index read from the report buffer with no bound (Weeping of the Empire #52, #73); set `report` sends a negative handle or an index from 0x8000 to the game's own reset | the faulting address against the report rows base (x12) |
|
||||
|
||||
## Device lost, hangs, black window
|
||||
|
||||
| Symptom | Usual causes | First check |
|
||||
|---|---|---|
|
||||
| with `replay_workers` above 0: the picture freezes for good mid-play while the window still closes, or a crash in `chunk_record` reading address 0x8 | the chunked replay's state (`RP` in vk_exec.c) overwritten: the submitting thread waits in `chunks_submit` for a chunk no `vk replay` thread takes (fixed: `tfr_note` walked its oldest-way search past the set, and from the last set into `RP`) | `replay_workers = 0`; `--probe-vkexec`'s target history part |
|
||||
| device lost a few frames in, GPU writes to address 0 (older NVIDIA) | present from another thread or queue | every submit and present on one queue under one lock |
|
||||
| device lost or garbage on one AMD generation | views the driver branch mishandles (BC block views of 3D textures) | `vk: pass marks`, validation; the formats in the pass |
|
||||
| device lost on one scene, every run, one vendor | a shader or pass that driver cannot run | pass marks name the pass; skip shaders by hash to bisect |
|
||||
|
||||
@@ -209,9 +209,12 @@ These names are code patch sets built into the generated game code (`recomp/patc
|
||||
|
||||
| Setting | What it does | Effect of changing it | Safety |
|
||||
| --- | --- | --- | --- |
|
||||
| `ability_guard` (default `1`) | Patch set that checks the target a Recall or Ultrahand pick hands to the game (1.4.3 main+0x1bd01c4, 1.2.1 main+0x1622bf0) and drops it for that frame where the game's own code would fault on it: the holder, the actor or its component unreadable, or the word the game's reference writes not writable (`runtime/ov_ability.c`). Every other target goes on unchanged; a target that fails UltraTears' live-actor test is only logged (`ability: target kept although ...`). | `0` runs the game's code as shipped: the random crash reading `0xffffffffffffffff` during an ability pick can return. | Risky |
|
||||
| `aspect_patch` (default `0`) | Patch set that feeds the camera the output's aspect ratio when it is not 16:9. | The resolution code switches this set on or off itself at start, so a value here is replaced; the code does not settle what a manual value does. | Unknown |
|
||||
| `fixed_res_patch` (default `0`) | Patch set that holds the game's dynamic resolution at 100 percent (the scene tier). | The resolution code switches this set from `dynamic_res` (on at `0`); a manual value is replaced. | Unknown |
|
||||
| `fov_patch` (default `0`) | Patch set that scales the camera's vertical view angle by the field-of-view setting. | The resolution code switches this set itself whenever the field of view is not 100 percent; a manual value is replaced. | Unknown |
|
||||
| `mouse_direct_patch` (default `1`) | Patch set of the hooks in the game's camera code behind `mouse_mode = direct` on game 1.4.3. | `0` stops `mouse_mode = direct` from taking effect; other mouse modes are unaffected. | Safe |
|
||||
| `optref_guard` (default `1`) | Patch set that treats a negative value in the optional reference at object +0x6b0 (1.4.3 main+0x1bd01c0, 1.2.1 main+0x1622bec) as absent instead of loading through it (#1005). | `0` runs the game's code as shipped: the random crash reading `0xffffffffffffffff` after minutes to hours of play can return. | Risky |
|
||||
| `patch_output` (default `0`) | Patch set that makes the game use the configured output size for its swapchain and display configuration. | The resolution code switches this set whenever the output differs from the base size; a manual value is replaced. | Unknown |
|
||||
| `patch_scene` (default `0`) | Patch set that makes the game use the configured scene render size. | The resolution code switches this set from the render size setting; a manual value is replaced. | Unknown |
|
||||
| `report_guard` (default `1`) | Patch set on 1.4.3 only: in the model scene's report loop (main+0xa22d8, main+0xa2310) an object whose report handle is negative or whose row index is 0x8000 or more gets coverage 0 for that frame and its handle reset, the path the game takes after every read, instead of reading past the report rows. On valid rows the game's code runs unchanged. | `0` runs the game's code as shipped: a bad row index reads far past the rows and crashes, the class Weeping of the Empire met while using Ultrahand and aiming. | Risky |
|
||||
@@ -1133,6 +1133,10 @@ site grass main 1a30a98 52a83f48 @page:x8 b9409108 # mov w8, #31.25 -> ldr
|
||||
# x8 and x9 are dead at the branch target 0x1622c1c, which loads x8 again.
|
||||
set optref TOTK_OPTREF_GUARD 1
|
||||
site optref main 1622bec b4000188 937ffd09 8a290108 b4000188 # cbz x8 -> asr x9, x8, #63; bic x8, x8, x9; cbz x8
|
||||
# The freed-holder case of patches-v143.txt (main+0x1bd01c8): a target below 2^32 is never a live guest object and
|
||||
# takes the game's own branch for a null target.
|
||||
site optref main 1622bf4 b4000155 d360fea9 b4000149 # cbz x21 -> lsr x9, x21, #32; cbz x9
|
||||
|
||||
# Recall and Ultrahand target that is stale memory: set ability in patches-v143.txt, here for 1.2.1's main+0x1622bf0
|
||||
# (function main+0x1622b60; the callees main+0x809ecc, 0x842aa4 and 0x842d10 read the same actor offsets). The model
|
||||
# scene report-row guard (set report there) has no 1.2.1 site: this version does not have that loop's code shape.
|
||||
set ability TOTK_ABILITY_GUARD 1
|
||||
site ability main 1622bf0 f9400115 94c424dc # ldr x21, [x8] -> bl page+0xf60
|
||||
site ability main 1622bf4 b4000155 aa0903f5 b4000155 # cbz x21 -> mov x21, x9; cbz x21 (x9 dead after it)
|
||||
+27
-8
@@ -1128,11 +1128,30 @@ site grass main 2063460 52a83f48 @page:x8 b9409108 # mov w8, #31.25 -> ldr
|
||||
# any read; on the fall-through path x8 is unchanged.
|
||||
set optref TOTK_OPTREF_GUARD 1
|
||||
site optref main 1bd01c0 b4000188 937ffd09 8a290108 b4000188 # cbz x8 -> asr x9, x8, #63; bic x8, x8, x9; cbz x8
|
||||
# The reference at +0x6b0 is the holder of the PlayerVirtualKey request embedded at object +0x678 (vtable 0x7003678900,
|
||||
# setHolder main+0x1bd1f78); the holder's first word is the target actor. A later report (LuizDavid48, 0.4.0) shows the
|
||||
# holder itself freed: its first word read 0x80, an allocator header, and f_70000155ec faulted reading [0x80 + 0x10].
|
||||
# The game already treats a target of 0 as absent (cbz x21 to 0x1bd01f0). Every guest object lies at or above 4 GiB:
|
||||
# runtime/memory.c mem_init places the stack, heap, ASLR and alias regions from LOW_SEARCH_FROM (2^32) up and the
|
||||
# modules and kernel region near 0x7000000000. So a target below 2^32 is never a live actor and takes the same branch:
|
||||
# x9 = x21 >> 32, cbz x9. x9 is already overwritten by the site above on this path.
|
||||
site optref main 1bd01c8 b4000155 d360fea9 b4000149 # cbz x21 -> lsr x9, x21, #32; cbz x9
|
||||
|
||||
# Recall and Ultrahand target that is stale memory. The same function reads the target actor from the holder
|
||||
# (ldr x21, [x8]) and follows it into main+0x155ec, main+0x9a89d4 and main+0x2b8464 (an atomic write at +0x90). The
|
||||
# holder can be reused memory by then, so the actor points into .rodata, outside the address space or at other heap
|
||||
# data, and the game crashes reading 0xffffffffffffffff. UltraTears (kuraeow/ultratears, ability target guard) found
|
||||
# the class. The load becomes a call to runtime/ov_ability.c host_ability_target (page+0xf60): x21 is the holder's
|
||||
# first word, or 0 where the game's own code would fault on the target (holder, actor or component unreadable, the
|
||||
# reference word not writable), which the game's cbz x21 skips for this frame. Every other target goes on unchanged.
|
||||
# The answer comes back in x9 and the cbz site moves it to x21: the lifted code keeps x21 (callee-saved) in a C local
|
||||
# across the call. x9 is dead after 0x1bd01c8 on every path (written or clobbered by a bl before any read); x30 is saved by the
|
||||
# prologue and clobbered by the next bl anyway.
|
||||
set ability TOTK_ABILITY_GUARD 1
|
||||
site ability main 1bd01c4 f9400115 947c3f67 # ldr x21, [x8] -> bl page+0xf60
|
||||
site ability main 1bd01c8 b4000155 aa0903f5 b4000155 # cbz x21 -> mov x21, x9; cbz x21
|
||||
|
||||
# Model scene report rows (WoE, daniel-madrid-07/weeping-of-the-empire, MIT, games/totk/patches/sites_v143.py
|
||||
# reportguard; their #52 and #73: crashes while using Ultrahand and aiming). gsys::ModelScene::calcGPU_ is inlined in
|
||||
# main+0xa1f84; its per-object loop (0xa22bc..0xa234c) takes the object's report handle h (int16 at obj+0x98 + 2 * side),
|
||||
# exits for -1 only, reads row 2h+1 and then u32 n from row 2h, and follows n to row 2n with no bound (WoE's crash had
|
||||
# n = the float 0.05, a read 32 GB past the rows). n indexes a row pair as h does, so a valid one is below 0x8000.
|
||||
# A negative h (other than -1) or n >= 0x8000 goes to 0xa2340, where the game resets the handle to -1 after every use:
|
||||
# the object has coverage 0 this frame (stored at 0xa22cc) and the game asks for a new report, as after a normal read.
|
||||
# WoE's veneers exit at 0xa2344 instead, which keeps the bad handle for the next frames. No flags change; w4 is never
|
||||
# used in main+0xa1f84; x1, x16, x15 and w13, which 0xa2340 reads, hold what they hold on the game's own path there.
|
||||
set report TOTK_REPORT_GUARD 1
|
||||
site report main a22d8 2a010571 2a010571 37f80341 # orr w17, w11, w1, lsl #1; tbnz w1, #31, 0xa2340
|
||||
site report main a2310 531f7821 530f7c24 531f7821 35000184 # lsr w4, w1, #15; lsl w1, w1, #1; cbnz w4, 0xa2340
|
||||
+6
-3
@@ -32,7 +32,7 @@ static int save_ok = 1; // the last cfg_save_to wrote (o
|
||||
// logged as unknown. A new variable goes here too, or its ini key logs a harmless "unknown key" line, and gets a
|
||||
// description in totk.ini.example or docs/settings.md (tests/settings_doc_check.py checks both).
|
||||
static const char *const known[] = {
|
||||
"AB", "AMIIBO_DIR", "ANISO", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_CHANNELS", "AUDIO_OFF", "AUDIO_PREFILL_MS",
|
||||
"AB", "ABILITY_GUARD", "AMIIBO_DIR", "ANISO", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_CHANNELS", "AUDIO_OFF", "AUDIO_PREFILL_MS",
|
||||
"BACKGROUND_WINDOW", "BIND_A", "BIND_B", "BIND_DOWN", "BIND_L", "BIND_LCLICK", "BIND_LEFT", "BIND_LSTICK_DOWN", "BIND_LSTICK_LEFT",
|
||||
"BIND_LSTICK_RIGHT", "BIND_LSTICK_UP", "BIND_MINUS",
|
||||
"BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_RSTICK_DOWN", "BIND_RSTICK_LEFT", "BIND_RSTICK_RIGHT", "BIND_RSTICK_UP",
|
||||
@@ -55,11 +55,11 @@ static const char *const known[] = {
|
||||
"MEM_RESERVE_MIB", "MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MOTION", "MOUSE_AIM_SCALE", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_ASPECT", "MOVIE_HOST", "MOVIE_PACE",
|
||||
"MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK",
|
||||
"MV_SURVEY",
|
||||
"ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "POINTER_IMAGE",
|
||||
"ONE_PER_CORE", "OPERATION_MODE", "OPTREF_GUARD", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "POINTER_IMAGE",
|
||||
"PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_BENCH", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES",
|
||||
"PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_ASYNC", "REC_END", "REC_SPIN_US", "REEXEC", "REFLEX",
|
||||
"RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS",
|
||||
"REPLAY_CHECK", "RESOLVE_CHECK", "RESTART_WAIT", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES",
|
||||
"REPLAY_CHECK", "REPORT_GUARD", "RESOLVE_CHECK", "RESTART_WAIT", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES",
|
||||
"ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RSTICK_DEADZONE", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE",
|
||||
"SHADER_MEMO", "SHADOW_DEFER", "SHADOW_RANGE", "SHADOW_RES", "SHADOW_SCALE", "SHADOW_SNAP", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR",
|
||||
"SHOTS_FULL", "SPEED_PROBE", "SPIN", "SPIN_HANDOFF_US", "SPLIT_DRAWS", "SPLIT_US", "STICK_DEADZONE", "STICK_SENS",
|
||||
@@ -109,6 +109,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"BIND_SKIP", "performance"}, {"SHADER_MEMO", "performance"}, {"PIPE_MEMO", "performance"}, {"TEX_MEMO", "performance"}, {"VB_USED", "performance"}, {"DESC_TEMPLATE", "performance"},
|
||||
{"SYNC_AHEAD", "performance"}, {"SHADOW_DEFER", "performance"}, {"PUSH_SKIP", "performance"}, {"SPLIT_DRAWS", "performance"}, {"SPLIT_US", "performance"}, {"VK_VALIDATION", "performance"},
|
||||
{"VK_DYN_VERTEX", "performance"}, {"VK_DYN_A2C", "performance"}, {"VK_SUBGROUP_PIN", "performance"},
|
||||
{"OPTREF_GUARD", "performance"}, {"ABILITY_GUARD", "performance"}, {"REPORT_GUARD", "performance"},
|
||||
{"TRACE", "diagnostics"}, {"FLIGHT", "diagnostics"}, {"PASS_CRUMBS", "diagnostics"}, {"FLIGHT_SPIKE_MS", "diagnostics"},
|
||||
{"WB_FENCE_LIMIT", "diagnostics"}, {"WB_MERGE", "diagnostics"}, {"WB_EXACT", "diagnostics"},
|
||||
{"MV_SURVEY", "diagnostics"},
|
||||
@@ -204,6 +205,8 @@ static const CfgMeta metas[] = {
|
||||
{"ASTC", "auto", "auto|gpu|native|cpu", RESTART}, {"MEMORY", "auto", "auto|import|mirror|verify", RESTART},
|
||||
{"TEX_ALIAS", "1", "0|1", RESTART}, {"TEX_VRAM_PRESSURE", "90", "0..100", RESTART},
|
||||
{"TEX_RELEASED_MIB", "256", "0..65536", RESTART}, {"TEX_BLOCK_MIB", "64", "0..1024", RESTART}, {"VMA_BLOCK_MIB", "64", "0..1024", RESTART}, {"ASTC_BC", "", "0|1", RESTART}, {"ZSTD_NATIVE", "1", "0|1", RESTART}, {"ZSTD_CHECK", "0", "0|1", RESTART},
|
||||
// crash guards: code patch sets (recomp/patches-v*.txt) over game reads that crash on stale data
|
||||
{"OPTREF_GUARD", "1", "0|1", RESTART}, {"ABILITY_GUARD", "1", "0|1", RESTART}, {"REPORT_GUARD", "1", "0|1", RESTART},
|
||||
// render fixes
|
||||
{"LOD_GUARD", "1", "0|1", RESTART}, {"FIX_C0", "1", "0|1", RESTART}, {"FIX_ZERO", "1", "0|1", RESTART},
|
||||
{"BIND_SKIP", "1", "0|1", RESTART}, {"SHADER_MEMO", "1", "0|1", RESTART}, {"PIPE_MEMO", "1", "0|1", RESTART}, {"TEX_MEMO", "1", "0|1", RESTART},
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
// Recall and Ultrahand target check (patch set "ability", recomp/patches-v143.txt and patches-v121.txt).
|
||||
//
|
||||
// main+0x1bd0138 on 1.4.3 (main+0x1622b60 on 1.2.1, the same code and actor offsets) runs while an ability picks its
|
||||
// target. Once the owner's request says ready, it loads the result holder from the owner (x8 = [x19+0x6b0]), the
|
||||
// target actor from the holder (x21 = [x8]), links the actor (main+0x155ec: reads the actor's +0x10, +0x24 and
|
||||
// +0x1a8), reads [[x21+0x228]+0xb0] (main+0x9a89d4) and takes a reference on that (main+0x2b8464: an atomic
|
||||
// read-modify-write of the word at +0x90). The holder can be reused memory by then, and the game crashes reading
|
||||
// 0xffffffffffffffff (Windows' report of a non-canonical address) minutes to hours into play. UltraTears
|
||||
// (kuraeow/ultratears, "ability target guard") found the class; this code is ours.
|
||||
//
|
||||
// A target is dropped only where the game's own code would fault on it: the holder or the actor unreadable, the
|
||||
// component pointer unreadable, or the reference word unreadable or in a module's code or read-only data. Every
|
||||
// other target goes on exactly as the game reads it, so no target the game can handle is ever lost. UltraTears' test
|
||||
// of a live actor (its link record [actor+0x1a8] points back to it at +0x40 and carries its id at +0x48) is not in the
|
||||
// game's code: the game links an actor whose link record is null without complaint. It runs here as a log line only,
|
||||
// to show in players' logs whether it would ever reject a live target.
|
||||
//
|
||||
// The first site replaces `ldr x21, [x8]` with a call here; the second, at the game's `cbz x21` right after it, becomes
|
||||
// `mov x21, x9; cbz x21`. The answer travels in x9 because the lifted caller keeps x21 (callee-saved) in a C local
|
||||
// across the call and reloads only caller-saved registers; x9 is dead there on every path. x9 gets the holder's first
|
||||
// word, or 0 for a dropped target, which the cbz skips for this frame as it skips an empty one. A null or tagged
|
||||
// (bit 0) word goes back unchanged: the game skips those itself. No other register changes.
|
||||
// Only an ability's target pick reaches this (hundreds of calls an hour), so the memory queries cost nothing.
|
||||
#include <stdint.h>
|
||||
|
||||
#include "host.h"
|
||||
|
||||
#if __has_include("patches.h")
|
||||
#include "patches.h"
|
||||
#endif
|
||||
|
||||
#ifdef RT_PATCH_PAGE
|
||||
|
||||
#define HOST_ABILITY_TARGET (RT_PATCH_PAGE + 0xf60)
|
||||
#define ACTOR_SPAN 0x230 // the actor fields the function and its callees read: +0x10 .. +0x22f
|
||||
|
||||
static int readable(uint64_t a, uint64_t n) { return a && !(a & 3) && mem_guest_readable(a, n); }
|
||||
|
||||
static uint64_t u64_at(uint64_t a) { return *(volatile uint64_t *)(uintptr_t)a; }
|
||||
static uint32_t u32_at(uint64_t a) { return *(volatile uint32_t *)(uintptr_t)a; }
|
||||
|
||||
// [a, a+4) inside a module's code or read-only data: a write there faults.
|
||||
static int read_only_module(uint64_t a) {
|
||||
for (int i = 0; i < ldr_count(); i++) {
|
||||
const RtLoaded *m = ldr_module(i);
|
||||
if (a - m->base < m->size) return a - m->base < m->data_off;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// NULL when the game's code can follow the actor without a fault, else what would fault.
|
||||
static const char *faults(uint64_t actor) {
|
||||
if (!readable(actor, ACTOR_SPAN)) return "actor not readable";
|
||||
uint64_t comp = u64_at(actor + 0x228);
|
||||
if (!comp) return NULL; // main+0x9a89d4 returns 0 for it and the game stops there
|
||||
if (!readable(comp + 0xb0, 8)) return "component not readable";
|
||||
uint64_t ref = u64_at(comp + 0xb0);
|
||||
if (!ref) return NULL; // the game's cbz x0 skips the reference
|
||||
if (!readable(ref + 0x90, 4) || read_only_module(ref + 0x90)) return "reference word not writable";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// UltraTears' live-actor test, for the log: NULL when it passes.
|
||||
static const char *not_live(uint64_t actor) {
|
||||
uint64_t link = u64_at(actor + 0x1a8);
|
||||
if (!readable(link + 0x40, 0x10)) return "link record not readable";
|
||||
if (u64_at(link + 0x40) != actor) return "link record points elsewhere";
|
||||
if (u32_at(link + 0x48) != u32_at(actor + 0x10)) return "link record has another id";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void host_ability_target(Cpu *c) {
|
||||
static uint64_t checked, dropped, mismatched;
|
||||
uint64_t holder = c->x[8], actor = 0;
|
||||
const char *why = NULL;
|
||||
if (!readable(holder, 8)) why = "holder not readable";
|
||||
else if ((actor = u64_at(holder)) && !(actor & 1)) why = faults(actor);
|
||||
if (why) {
|
||||
c->x[9] = 0;
|
||||
uint64_t n = __atomic_add_fetch(&dropped, 1, __ATOMIC_RELAXED);
|
||||
if (n <= 20 || !(n & (n - 1)))
|
||||
rt_log("ability: target dropped, the game would fault on it (%s): holder %#llx actor %#llx; %llu dropped",
|
||||
why, (unsigned long long)holder, (unsigned long long)actor, (unsigned long long)n);
|
||||
return;
|
||||
}
|
||||
c->x[9] = actor;
|
||||
if (!actor || (actor & 1)) return;
|
||||
uint64_t k = __atomic_add_fetch(&checked, 1, __ATOMIC_RELAXED);
|
||||
const char *odd = not_live(actor);
|
||||
if (!odd) {
|
||||
if (k == 1) rt_log("ability: first target checked (TOTK_ABILITY_GUARD=0: no check)");
|
||||
return;
|
||||
}
|
||||
uint64_t n = __atomic_add_fetch(&mismatched, 1, __ATOMIC_RELAXED);
|
||||
if (n <= 20 || !(n & (n - 1)))
|
||||
rt_log("ability: target kept although the live-actor test fails (%s): actor %#llx; %llu of %llu targets", odd,
|
||||
(unsigned long long)actor, (unsigned long long)n, (unsigned long long)k);
|
||||
}
|
||||
|
||||
__attribute__((constructor)) static void ability_register(void) {
|
||||
rt_register_host(HOST_ABILITY_TARGET, host_ability_target);
|
||||
}
|
||||
|
||||
#endif
|
||||
+3
-2
@@ -1019,9 +1019,10 @@ static bool validation_layer_present(void) {
|
||||
|
||||
// Every setting the menu shows back to its default (the environment's keys stay), written to totk.ini.
|
||||
static void reset_all(void) {
|
||||
const char *keys[128];
|
||||
const char *keys[256]; // above the number of rows in cfg.c metas (128 on 2026-11-11)
|
||||
int n = 0;
|
||||
for (const CfgMeta *m; n < 128 && (m = cfg_meta_at(n)); n++) keys[n] = m->key;
|
||||
for (const CfgMeta *m; n < 256 && (m = cfg_meta_at(n)); n++) keys[n] = m->key;
|
||||
if (cfg_meta_at(n)) rt_log("menu: reset covers the first %d settings only; raise keys[] in reset_all", n);
|
||||
int done = cfg_reset(keys, n);
|
||||
opt_save_soon();
|
||||
rt_log("menu: reset %d settings to their defaults", done);
|
||||
|
||||
+9
-1
@@ -31,7 +31,7 @@
|
||||
|
||||
[performance]
|
||||
# The keys of this section and of [diagnostics] are for testing and troubleshooting, and take effect at the next start.
|
||||
# The Advanced tab of the settings menu (F1) shows all of them except zstd_native and zstd_check.
|
||||
# The Advanced tab of the settings menu (F1) shows all of them except zstd_native, zstd_check and the crash guards.
|
||||
|
||||
# Scheduling.
|
||||
# A thread waiting for a virtual core interrupts the owner when it runs game code: 1 = on, 2 = priority inheritance
|
||||
@@ -103,6 +103,14 @@
|
||||
# zstd_native = 1
|
||||
# zstd_check = 0
|
||||
|
||||
# Crash guards: game code that crashes on stale data skips it instead (0 = the game's own code).
|
||||
# An optional reference holding an invalid value is treated as absent.
|
||||
# optref_guard = 1
|
||||
# A Recall or Ultrahand target the game would crash on is skipped for that frame.
|
||||
# ability_guard = 1
|
||||
# A model scene report row with an out-of-range index is skipped for that frame (1.4.3 only).
|
||||
# report_guard = 1
|
||||
|
||||
# Render fixes.
|
||||
# Wait for the game to finish rewriting level-of-detail data before the GPU reads it: stops objects flashing in the
|
||||
# wrong place and a flat far field for a frame.
|
||||
|
||||
Reference in new issue
Block a user