From dde624e603065b236e69b4d587405488b8a09213 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Wed, 11 Nov 2026 16:41:29 +0300 Subject: [PATCH 1/4] Skip a stale Recall / Ultrahand target and an unbounded model scene report row instead of crashing (#1005) Set ability (1.4.3 main+0x1bd01c4, 1.2.1 main+0x1622bf0): the target actor load becomes a host call that reads the holder safely and drops an actor failing the live-actor test (link record points back and carries its id), as UltraTears found; the game's own cbz skips it for that frame. The answer comes back in x9, since the lifted code keeps x21 in a C local across calls. Set report (1.4.3 only): the model scene report loop sends a negative handle or a row index from 0x8000 to the game's handle reset, the class Weeping of the Empire met (#52, #73). Both on by default, TOTK_ABILITY_GUARD=0 / TOTK_REPORT_GUARD=0 turn them off. Co-Authored-By: Claude Opus 5.5 --- docs/agents/symptoms.md | 3 +- recomp/patches-v121.txt | 7 ++++ recomp/patches-v143.txt | 27 +++++++++++++ runtime/ov_ability.c | 85 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 runtime/ov_ability.c diff --git a/docs/agents/symptoms.md b/docs/agents/symptoms.md index c654c712..7325c8a4 100644 --- a/docs/agents/symptoms.md +++ b/docs/agents/symptoms.md @@ -49,7 +49,8 @@ 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` in a game function | an invalid value (-1, `0xffff0000ffffffff`) in an optional reference the game checks only for null; set `optref` in `recomp/patches-v143.txt` guards main+0x1bd0138 | 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` in a game function (Windows reports any non-canonical address so) | 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: stale target skipped` 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 diff --git a/recomp/patches-v121.txt b/recomp/patches-v121.txt index 725aad6e..738d605d 100644 --- a/recomp/patches-v121.txt +++ b/recomp/patches-v121.txt @@ -1133,3 +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 + +# 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) diff --git a/recomp/patches-v143.txt b/recomp/patches-v143.txt index c67f95ae..3932d65b 100644 --- a/recomp/patches-v143.txt +++ b/recomp/patches-v143.txt @@ -1128,3 +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 + +# 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 when the holder is readable and the actor passes the live-actor test (its link record [actor+0x1a8] +# points back to it at +0x40 with its id at +0x48), else 0, which the game's cbz x21 skips for this frame. 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 diff --git a/runtime/ov_ability.c b/runtime/ov_ability.c new file mode 100644 index 00000000..16f9eabe --- /dev/null +++ b/runtime/ov_ability.c @@ -0,0 +1,85 @@ +// 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 [[x21+0x228]+0xb0] +// (main+0x9a89d4) and takes a reference on that (main+0x2b8464, an atomic write at +0x90). +// The holder can be reused memory by then: the actor pointer lands in .rodata, past the address space or on heap +// memory that holds other data, 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 and +// the test below; this code is ours. +// +// 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 when the holder is readable, and 0 when the holder is unreadable or the actor fails the live-actor test: the +// actor's link record [actor+0x1a8] points back to it (+0x40) and carries its id (+0x48 == [actor+0x10]), and every +// pointer the game then follows is readable. The cbz skips a 0 target 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 + +#include "host.h" + +#if __has_include("patches.h") +#include "patches.h" +#endif + +#ifdef RT_PATCH_PAGE + +#define HOST_ABILITY_TARGET (RT_PATCH_PAGE + 0xf60) + +// 0 when [a, a+8) cannot be read. +static int rd64(uint64_t a, uint64_t *v) { + *v = 0; + if (!a || (a & 7) || !mem_guest_readable(a, 8)) return 0; + *v = *(volatile uint64_t *)(uintptr_t)a; + return 1; +} + +static int rd32(uint64_t a, uint32_t *v) { + *v = 0; + if (!a || (a & 3) || !mem_guest_readable(a, 4)) return 0; + *v = *(volatile uint32_t *)(uintptr_t)a; + return 1; +} + +// NULL when the actor passes, else why it does not. +static const char *stale(uint64_t actor) { + uint64_t link, back, comp, sub, ref; + uint32_t link_id, actor_id; + if (!rd64(actor + 0x1a8, &link) || !rd32(actor + 0x10, &actor_id)) return "actor not readable"; + if (!rd64(link + 0x40, &back)) return "link record not readable"; + if (back != actor) return "link record points elsewhere"; + if (!rd32(link + 0x48, &link_id) || link_id != actor_id) return "link record has another id"; + if (!rd64(actor + 0x228, &comp)) return "actor not readable"; + if (!comp) return NULL; // main+0x9a89d4 returns 0 for it and the game stops there + if (!rd64(comp + 0xb0, &sub)) return "component not readable"; + if (sub && !rd64(sub + 0x90, &ref)) return "component target not readable"; + return NULL; +} + +static void host_ability_target(Cpu *c) { + static uint64_t checked, skipped; + uint64_t holder = c->x[8], actor = 0; + const char *why = NULL; + if (!rd64(holder, &actor)) why = "holder not readable"; + else if (actor && !(actor & 1)) why = stale(actor); + if (!why) { + c->x[9] = actor; + if (actor && !(actor & 1) && __atomic_add_fetch(&checked, 1, __ATOMIC_RELAXED) == 1) + rt_log("ability: first target checked, live (TOTK_ABILITY_GUARD=0: no check)"); + return; + } + c->x[9] = 0; + uint64_t n = __atomic_add_fetch(&skipped, 1, __ATOMIC_RELAXED); + if (n <= 20 || !(n & (n - 1))) + rt_log("ability: stale target skipped (%s): holder %#llx actor %#llx; %llu skipped", why, + (unsigned long long)holder, (unsigned long long)actor, (unsigned long long)n); +} + +__attribute__((constructor)) static void ability_register(void) { + rt_register_host(HOST_ABILITY_TARGET, host_ability_target); +} + +#endif From 5d8c2ceb301833e8d413e08cf853fa4626403f1f Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Wed, 11 Nov 2026 16:59:35 +0300 Subject: [PATCH 2/4] Drop an ability target only where the game would fault on it, and keep the live-actor test as a log line (#1005) The game links an actor whose link record is null without complaint, so UltraTears' live-actor test could drop targets the game handles. A target is now dropped only when the holder, the actor or its component is unreadable, or the word the game's reference takes (+0x90, an atomic read-modify-write) is unreadable or in a module's code or read-only data. The live-actor test logs the targets it would reject and changes nothing. Co-Authored-By: Claude Opus 5.5 --- docs/agents/symptoms.md | 2 +- recomp/patches-v143.txt | 8 +-- runtime/ov_ability.c | 109 +++++++++++++++++++++++----------------- 3 files changed, 69 insertions(+), 50 deletions(-) diff --git a/docs/agents/symptoms.md b/docs/agents/symptoms.md index 7325c8a4..f9d17df4 100644 --- a/docs/agents/symptoms.md +++ b/docs/agents/symptoms.md @@ -49,7 +49,7 @@ 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` in a game function (Windows reports any non-canonical address so) | 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: stale target skipped` lines in the log | +| random crash after minutes to hours, access violation reading `0xffffffffffffffff` in a game function (Windows reports any non-canonical address so) | 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 diff --git a/recomp/patches-v143.txt b/recomp/patches-v143.txt index 3932d65b..b1d61295 100644 --- a/recomp/patches-v143.txt +++ b/recomp/patches-v143.txt @@ -1134,10 +1134,10 @@ site optref main 1bd01c0 b4000188 937ffd09 8a290108 b4000188 # cbz x8 -> asr x # 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 when the holder is readable and the actor passes the live-actor test (its link record [actor+0x1a8] -# points back to it at +0x40 with its id at +0x48), else 0, which the game's cbz x21 skips for this frame. 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 +# 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 diff --git a/runtime/ov_ability.c b/runtime/ov_ability.c index 16f9eabe..19bd892c 100644 --- a/runtime/ov_ability.c +++ b/runtime/ov_ability.c @@ -2,20 +2,24 @@ // // 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 [[x21+0x228]+0xb0] -// (main+0x9a89d4) and takes a reference on that (main+0x2b8464, an atomic write at +0x90). -// The holder can be reused memory by then: the actor pointer lands in .rodata, past the address space or on heap -// memory that holds other data, 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 and -// the test below; this code is ours. +// 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 when the holder is readable, and 0 when the holder is unreadable or the actor fails the live-actor test: the -// actor's link record [actor+0x1a8] points back to it (+0x40) and carries its id (+0x48 == [actor+0x10]), and every -// pointer the game then follows is readable. The cbz skips a 0 target 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. +// 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 @@ -28,54 +32,69 @@ #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 -// 0 when [a, a+8) cannot be read. -static int rd64(uint64_t a, uint64_t *v) { - *v = 0; - if (!a || (a & 7) || !mem_guest_readable(a, 8)) return 0; - *v = *(volatile uint64_t *)(uintptr_t)a; - return 1; +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; } -static int rd32(uint64_t a, uint32_t *v) { - *v = 0; - if (!a || (a & 3) || !mem_guest_readable(a, 4)) return 0; - *v = *(volatile uint32_t *)(uintptr_t)a; - return 1; -} - -// NULL when the actor passes, else why it does not. -static const char *stale(uint64_t actor) { - uint64_t link, back, comp, sub, ref; - uint32_t link_id, actor_id; - if (!rd64(actor + 0x1a8, &link) || !rd32(actor + 0x10, &actor_id)) return "actor not readable"; - if (!rd64(link + 0x40, &back)) return "link record not readable"; - if (back != actor) return "link record points elsewhere"; - if (!rd32(link + 0x48, &link_id) || link_id != actor_id) return "link record has another id"; - if (!rd64(actor + 0x228, &comp)) return "actor not readable"; +// 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 (!rd64(comp + 0xb0, &sub)) return "component not readable"; - if (sub && !rd64(sub + 0x90, &ref)) return "component target not readable"; + 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, skipped; + static uint64_t checked, dropped, mismatched; uint64_t holder = c->x[8], actor = 0; const char *why = NULL; - if (!rd64(holder, &actor)) why = "holder not readable"; - else if (actor && !(actor & 1)) why = stale(actor); - if (!why) { - c->x[9] = actor; - if (actor && !(actor & 1) && __atomic_add_fetch(&checked, 1, __ATOMIC_RELAXED) == 1) - rt_log("ability: first target checked, live (TOTK_ABILITY_GUARD=0: no check)"); + 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] = 0; - uint64_t n = __atomic_add_fetch(&skipped, 1, __ATOMIC_RELAXED); + 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: stale target skipped (%s): holder %#llx actor %#llx; %llu skipped", why, - (unsigned long long)holder, (unsigned long long)actor, (unsigned long long)n); + 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) { From 42c458712d73fea47239cc2477b1268c7d60da23 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Wed, 11 Nov 2026 17:16:10 +0300 Subject: [PATCH 3/4] Crash guards switchable from totk.ini: optref_guard, ability_guard, report_guard (#1005) The three patch sets read their switch through cfg, so the keys already worked from totk.ini but logged as unknown and were undocumented. They are now known keys with defaults (on), in [performance] of totk.ini.example; the settings menu does not show them. The settings table reached 128 rows, the size of the menu's reset list, so that list grows to 256 and logs if the table ever outgrows it. Co-Authored-By: Claude Opus 5.5 --- runtime/cfg.c | 9 ++++++--- runtime/ui/menu.cpp | 5 +++-- totk.ini.example | 10 +++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/runtime/cfg.c b/runtime/cfg.c index abe4d5fe..3521bc27 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -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", @@ -50,11 +50,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", + "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", "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", @@ -104,6 +104,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"}, @@ -180,6 +181,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}, diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 3759552d..350537ec 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -962,9 +962,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); diff --git a/totk.ini.example b/totk.ini.example index 3aa468f6..421585ae 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -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. From 0ded6164a0cd204250fac8c73c81d92311fa42ef Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Wed, 11 Nov 2026 17:19:05 +0300 Subject: [PATCH 4/4] Describe optref_guard, ability_guard and report_guard in docs/settings.md (#1005) Co-Authored-By: Claude Opus 5.5 --- docs/settings.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/settings.md b/docs/settings.md index da5ca279..dd5c0ed5 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -208,9 +208,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 |