diff --git a/docs/settings.md b/docs/settings.md index 36c67289..857cfee7 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -217,6 +217,7 @@ These names are code patch sets built into the generated game code (`recomp/patc | --- | --- | --- | --- | | `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 | +| `audio_drain_fix` (default `1`) | Patch set that sends the game's audio thread back to its command ring after each list (1.2.1 main+0x883780, 1.4.3 main+0x149244), so it takes every queued list per 5 ms audio frame instead of one (#337). Game 1.1.0 has no site and keeps the game's code. | `0` runs the game's code as shipped: above about 200 game updates a second the ring stays full and the game's guard (1.2.1 main+0x9bcdc4) switches the sound commands off until the game is restarted. The set acts only when more than one list is queued, so below that rate it seldom changes anything. Measured at `fps_limit = 240`, seconds with sound: on 1.2.1 5 of 118 with `0` and 108 of 118 with `1`; on 1.4.3 2 of 118 with `0` and 110 of 119 with `1`. | Safe | | `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 | diff --git a/recomp/patches-v121.txt b/recomp/patches-v121.txt index f1749df4..2fef5caa 100644 --- a/recomp/patches-v121.txt +++ b/recomp/patches-v121.txt @@ -1151,3 +1151,20 @@ site optref main 1622bec b4000188 937ffd09 8a290108 b4000188 # cbz x8 -> asr x 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) + +# Sound command lists above 200 fps (issue #337). The game thread hands its sound commands to the audio thread in +# lists: 16 of them, of which 4 are always held (one being filled by the game thread, the others on the audio thread's +# side), so at most 12 wait in the command ring. The game thread submits at most one list per update (main+0x9bd144, +# when a free list is there), and the audio thread takes one per pass of its loop, one 5 ms audio frame: after a list +# main+0x883780 goes on past the ring's check (b 0x883318). Above about 200 updates a second the ring stays full. A +# guard in the game (main+0x9bcdc4, at the end of each update) counts the updates that find the ring of free lists +# empty and exactly 12 lists in the command ring (0x9bce1c cmp w9, #0xc); the count goes back to 0 only when a free +# list is there. At every multiple of 300 (10 s at 30 fps, 1.25 s at 240) it clears the sound command switch, the byte +# at [[engine + 0x1a0] + 8] (main+0x2268bfc), and stops every active voice (main+0x226f29c). The switch is set to 1 only +# by its constructor (main+0xf31ce8, from the engine's init main+0xf31530), so the game stays silent until it is +# restarted. The site sends the audio thread back to the ring's check (0x8832e8, where the game's own 0x883c18 also +# branches; x21, the engine, is not written between the check and the site), so it takes every queued list in the pass +# and the ring does not stay full. Measured on 1.2.1 at fps_limit 240, same save and input script: sound in 5 of 118 s +# with the set off, in 108 of 118 s with it on. +set audiodrain TOTK_AUDIO_DRAIN_FIX 1 +site audiodrain main 883780 17fffee6 17fffeda # b 0x883318 -> b 0x8832e8 diff --git a/recomp/patches-v143.txt b/recomp/patches-v143.txt index 0b05ab02..e77eb0f4 100644 --- a/recomp/patches-v143.txt +++ b/recomp/patches-v143.txt @@ -1177,3 +1177,10 @@ site report main a2310 531f7821 530f7c24 531f7821 35000184 # lsr w4, w1, #15; # hook. main+0x585bd0 sets the render size (runtime/resolution.c SET_RENDER_SIZE): res_fn_hit takes the renderer from # the game's own call at start, so a DLSS mode can change while the game runs. hook main 585bd0 + +# Sound command lists above 200 fps (issue #337): as in patches-v121.txt. The audio thread's check of the command ring +# is main+0x148aec, which wants x8 = the engine (as 0x148ae0 loads it from [x19]); after a list the site goes back to +# it instead of on to 0x148b14, with the two instructions the game itself has at 0x149700. Measured on 1.4.3 at +# fps_limit 240, same save and input script: sound in 2 of 118 s with the set off, in 110 of 119 s with it on. +set audiodrain TOTK_AUDIO_DRAIN_FIX 1 +site audiodrain main 149244 17fffe34 f9400268 17fffe2a # b 0x148b14 -> ldr x8, [x19]; b 0x148aec diff --git a/runtime/cfg.c b/runtime/cfg.c index b21a1a1d..872d9dd4 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", "ABILITY_GUARD", "ADDR_REPORT", "AMIIBO_DIR", "ANISO", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_CHANNELS", "AUDIO_DEVICE", "AUDIO_OFF", "AUDIO_PREFILL_MS", + "AB", "ABILITY_GUARD", "ADDR_REPORT", "AMIIBO_DIR", "ANISO", "APP_POOL", "ASPECT", "ASPECT_PATCH", "ASSUME_FOCUS", "ASTC", "ASTC_BC", "ASTC_TIME", "ASYNC_PREEMPT", "AUDIO", "AUDIO_CHANNELS", "AUDIO_DEVICE", "AUDIO_DRAIN_FIX", "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", @@ -75,7 +75,7 @@ static const char *const known[] = { static const struct { const char *key, *section; } sections[] = { {"FPS_LIMIT", "frame rate"}, {"FPS60", "frame rate"}, {"FRAME_QUEUE", "frame rate"}, {"REALTIME", "frame rate"}, {"CLOTH_REALTIME", "frame rate"}, {"HIGHFPS_FIX", "frame rate"}, - {"CLIMB_FIX", "frame rate"}, + {"CLIMB_FIX", "frame rate"}, {"AUDIO_DRAIN_FIX", "frame rate"}, {"FULLSCREEN", "display"}, {"WINDOW_SIZE", "display"}, {"PERF_OVERLAY", "display"}, {"VK_PRESENT", "display"}, {"GPU_INDEX", "display"}, {"OUTPUT_RES", "display"}, {"RENDER_SCALE", "display"}, {"UPSCALER", "display"}, {"SHARPNESS", "display"}, {"DYNAMIC_RES", "display"}, {"ASPECT", "display"}, {"MOVIE_ASPECT", "display"}, {"FOV", "display"}, {"ANISO", "display"}, @@ -161,7 +161,7 @@ static const CfgMeta metas[] = { {"REALTIME", "1", "0|1", RESTART}, {"CLOTH_REALTIME", "1", "0|1", RESTART}, {"MODS_REBUILD", "auto", "auto|off", RESTART}, {"MODS_WITHOUT_CODE", "0", "0|1", RESTART}, // 1: a mod is used without the code module it cannot run (mods.c) - {"HIGHFPS_FIX", "1", "0|1", RESTART}, {"CLIMB_FIX", "1", "0|1", RESTART}, + {"HIGHFPS_FIX", "1", "0|1", RESTART}, {"CLIMB_FIX", "1", "0|1", RESTART}, {"AUDIO_DRAIN_FIX", "1", "0|1", RESTART}, {"LANG", "", "ja|en-US|fr|de|it|es|zh-CN|ko|nl|pt|ru|zh-TW|en-GB|fr-CA|es-419|zh-Hans|zh-Hant|pt-BR", RESTART}, {"OPERATION_MODE", "docked", "docked|handheld", RESTART}, {"ASSUME_FOCUS", "1", "0|1", LIVE}, // read on every focus change (ov_system.c) diff --git a/totk.ini.example b/totk.ini.example index 4f7bfa61..5ba53ab5 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -28,6 +28,9 @@ # highfps_fix = 1 # Climbing walls and ladders at full speed above 60 fps; 30 and 60 fps are unchanged. Needs realtime = 1. # climb_fix = 1 +# The game's audio thread takes every queued sound command list each 5 ms instead of one, so the queue does not fill +# above 200 fps, where the game would switch its sound off for good. 0 = the game's own code. +# audio_drain_fix = 1 [performance] # The keys of this section and of [diagnostics] are for testing and troubleshooting, and take effect at the next start.