Merge pull request #1087 into task/pr1087

This commit is contained in:
Valiantsin Dzerakh committed 2026-11-11 13:20:43 +03:00
commit 873fc64b41
11 files changed
+113 -8

No files matched your search

+11
View File
@@ -10,6 +10,7 @@ set bounce TOTK_HIGHFPS_FIX 1
set output TOTK_PATCH_OUTPUT 0
set scene TOTK_PATCH_SCENE 0
set shadow TOTK_PATCH_SHADOW 0
set grass TOTK_PATCH_GRASS 0
# 60 fps: the adaptive present-interval controller (main+0x8f26c8, 1.0.0 0x8f6bec) gets the minimum interval 1.
site fps60 main 8f273c 6b08015f 7100055f # clamp: cmp w10, #1 (was cmp w10, w8 = minimum)
@@ -1115,3 +1116,13 @@ spin sdk 3d3250 3d3270 # 9 instructions; loads
# goes in just before the rounding, as the community's shadow resolution mods do (1.1.0: mov w11, #1024 over the
# computation). Found by a write watch on the size field (the writer was this function, and no other).
site shadow main cec22c 11001d6b @page:x11 b9405d6b 11001d6b # add w11, w11, #7 -> adrp x11, page; ldr w11, [x11, #92]; add w11, w11, #7
# Grass range (runtime/resolution.c res_grass_range; patches-v143.txt describes the set and the page). The near grass
# map's constructor loads its extent, step and texture sizes at main+0xfe58b4..0xfe5950, and main+0x1a30a28 sets the
# extent to 62.5 or 31.25 m, as on 1.4.3.
site grass main fe58b4 52a84f48 @page:x8 b9408108 # mov w8, #62.5 -> ldr w8, [page+128]
site grass main fe58c0 52a80f48 @page:x8 b9408508 # mov w8, #3.90625 -> ldr w8, [page+132]
site grass main fe58ec 52802002 @page:x2 b9408842 # mov w2, #0x100 -> ldr w2, [page+136]
site grass main fe5950 52801002 @page:x2 b9408c42 # mov w2, #0x80 -> ldr w2, [page+140]
site grass main 1a30a8c 52a84f48 @page:x8 b9408108 # mov w8, #62.5 -> ldr w8, [page+128]
site grass main 1a30a98 52a83f48 @page:x8 b9409108 # mov w8, #31.25 -> ldr w8, [page+144]
+14
View File
@@ -12,6 +12,7 @@ set output TOTK_PATCH_OUTPUT 0
set scene TOTK_PATCH_SCENE 0
set shadow TOTK_PATCH_SHADOW 0
set cascade TOTK_PATCH_CASCADE 0
set grass TOTK_PATCH_GRASS 0
# 60 fps: the adaptive present-interval controller (main+0x2db174, 1.2.1 0x8f26c8) gets the minimum interval 1.
site fps60 main 2db204 6b08015f 7100055f # clamp: cmp w10, #1 (was cmp w10, w8 = minimum)
@@ -1102,3 +1103,16 @@ site cascade main 6fad4c 52a86408 @page:x8 b9404d08 # mov w8, #160.0 -> ldr w8
# switches the set off without the real-time step, where the page is not written.
set climb TOTK_CLIMB_FIX 1
site climb main 1f497f4 1e201001 @page:x8 bd400104 1e286884 52946dc8 72a7e528 1e270102 1e241842 52828248 72a7dfe8 1e270103 1e232842 529573e8 72a7b5a8 1e270103 1f040862 1e2a3883 2f00e404 1e246863 1e261004 1f048862 1e241004 1e247842 1e226800 1e201001 1e226821 # fmov s1, #2.0 -> s2 = g(u); s0 = max(s0, s2); s1 = max(2.0, s2)
# Grass range (runtime/resolution.c res_grass_range switches the set on). Grass blades grow from the near grass map, a
# square texture the game draws around the camera (GrassShader.sharcb). Its constructor (main+0xa38e58) gives it a
# 62.5 m extent, a 3.90625 m step (1/16 of it) and 256x256 and 128x128 textures; main+0x206340c later sets the extent
# to 62.5 or 31.25 m. With the set on all of them come from page +128..+144, scaled together so the map keeps its
# texels per metre; resolution.c grows the grass heap of the HeapDef for the larger textures.
site grass main a38e58 52a84f48 @page:x8 b9408108 # mov w8, #62.5 -> ldr w8, [page+128]
site grass main a38e64 52a80f48 @page:x8 b9408508 # mov w8, #3.90625 -> ldr w8, [page+132]
site grass main a38e94 52802002 @page:x2 b9408842 # mov w2, #0x100 -> ldr w2, [page+136]
site grass main a38ef4 52801002 @page:x2 b9408c42 # mov w2, #0x80 -> ldr w2, [page+140]
site grass main 2063454 52a84f48 @page:x8 b9408108 # mov w8, #62.5 -> ldr w8, [page+128]
site grass main 2063460 52a83f48 @page:x8 b9409108 # mov w8, #31.25 -> ldr w8, [page+144]
+3 -3
View File
@@ -44,7 +44,7 @@ static const char *const known[] = {
"DUMP_LOG", "DYNAMIC_RES", "DYN_DELTA", "EXEFS", "FEEDBACK", "FIXED_RES_PATCH", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES",
"FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_QUEUE",
"FREEZE_IDLE", "FREE_CORES",
"FULLSCREEN", "FXAA", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "HDR", "HDR_GAME_NITS", "HDR_HUE",
"FULLSCREEN", "FXAA", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "GRASS_RANGE", "HDR", "HDR_GAME_NITS", "HDR_HUE",
"HDR_PEAK_NITS", "HDR_UI_NITS", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "KSPIN_US", "LANG", "LIB_PREBUILD",
"LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MAP_CLICK", "MEMORY", "MENU_LANG", "MENU_TEST",
"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",
@@ -80,7 +80,7 @@ static const struct { const char *key, *section; } sections[] = {
{"DLAA", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_CHAR_MASK", "display"}, {"REFLEX", "display"}, {"FXAA", "display"},
{"DEVICE_PROFILE", "display"}, {"ASSUME_FOCUS", "display"},
{"DISCORD_RPC", "discord"}, {"DISCORD_APP_ID", "discord"}, {"DISCORD_IMAGE", "discord"},
{"SHADOW_SCALE", "display"}, {"SHADOW_RANGE", "display"}, {"CONTACT_SHADOWS", "display"},
{"SHADOW_SCALE", "display"}, {"SHADOW_RANGE", "display"}, {"GRASS_RANGE", "display"}, {"CONTACT_SHADOWS", "display"},
{"PCSS", "display"},
{"MODS_DIR", "mods"}, {"MODS_ORDER", "mods"}, {"MODS_DISABLED", "mods"}, {"MODS_REBUILD", "mods"},
{"TEX_HEAP_EXTRA_MB", "mods"},
@@ -137,7 +137,7 @@ static const CfgMeta metas[] = {
{"DEVICE_PROFILE", "auto", "auto|desktop|deck", RESTART},
{"SHADOW_RES", "game", "game|256|512|768|1024|1536|2048", RESTART},
{"SHADOW_SCALE", "1", "1..4", RESTART},
{"SHADOW_RANGE", "100", "50..400", RESTART}, {"CONTACT_SHADOWS", "0", "0..100", RESTART},
{"SHADOW_RANGE", "100", "50..400", RESTART}, {"GRASS_RANGE", "100", "50..400", RESTART}, {"CONTACT_SHADOWS", "0", "0..100", RESTART},
{"PCSS", "0", "0..200", RESTART},
// Game
{"FPS_LIMIT", "60", "30|40|45|60|90|120|144|display", LIVE}, {"FPS60", "1", "0|1", LIVE}, {"FRAME_QUEUE", "0", "0|1", LIVE},
+2
View File
@@ -279,6 +279,8 @@ int cam_pack_build(const void *in, size_t n, const void *zsdic, size_t zsdic_n,
// multiplied, malloc'd; 0 = factor 1 or cannot (logged)
void cam_pack_served(void); // romfs.c serves the multiplied pack
// ---- game resolution (resolution.c): TOTK_OUTPUT_RES, TOTK_RENDER_SCALE
uint64_t res_grass_heap_extra_kib(void); // TOTK_GRASS_RANGE: added to the HeapDef grass heap; 0 = none
uint64_t res_grass_heap_extra_bytes(void); // the same, added to the application pool, 2 MiB steps
uint64_t res_heap_extra_bytes(void); // added to the application pool (mem_init), 2 MiB steps
uint64_t res_heap_extra_kib(void); // added to the HeapDef texture heap and its parent; 0 = none
uint64_t res_tex_heap_extra_bytes(void); // TOTK_TEX_HEAP_EXTRA_MB: added to the application pool and
+3 -2
View File
@@ -263,11 +263,12 @@ void mem_init(void) {
L = (RtGuestLayout){
.aslr = {low, RT_ADDRESS_LIMIT - low},
.stack = {low + STACK_OFF, STACK_SIZE},
.heap = {low + HEAP_OFF, HEAP_CAP + res_tex_heap_extra_bytes()},
.heap = {low + HEAP_OFF, HEAP_CAP + res_tex_heap_extra_bytes() + res_grass_heap_extra_bytes()},
.alias = {alias, ALIAS_SIZE},
.kernel = {RT_KERNEL_BASE, RT_KERNEL_SIZE},
.hostfn = {RT_HOSTFN_BASE, RT_HOSTFN_SIZE},
.pool = pool ? strtoull(pool, NULL, 0) : DEFAULT_POOL + res_heap_extra_bytes() + res_tex_heap_extra_bytes(),
.pool = pool ? strtoull(pool, NULL, 0)
: DEFAULT_POOL + res_heap_extra_bytes() + res_tex_heap_extra_bytes() + res_grass_heap_extra_bytes(),
};
if (!L.pool) rt_fatal("memory: TOTK_APP_POOL is 0");
}
+51 -2
View File
@@ -243,6 +243,23 @@ static double scene_scale(void) {
uint64_t res_heap_extra_bytes(void) { return ((res_heap_extra_kib() << 10) + 0x1fffff) & ~0x1fffffull; }
// TOTK_GRASS_RANGE (percent, 50 to 400; 100 = the game's): how far around the camera grass blades grow. The near grass
// map (the grass patch set, recomp/patches-v121.txt and patches-v143.txt) covers 62.5 m and draws into 256x256 and
// 128x128 textures; other values scale the extent, its step and both textures together, so the grass keeps its detail
// per metre. The larger textures come from the grass heap "草" of the HeapDef, which has no room for them (at 200 %
// without growth the game stops at start on a failed allocation), so it grows by 9318 KiB, its size in 1.4.3, times
// the textures' growth in area (k^2 - 1).
#define GRASS_HEAP_KIB 9318
static int grass_pct(void) {
int pct = cfg_int("TOTK_GRASS_RANGE");
return pct < 50 ? 50 : pct > 400 ? 400 : pct;
}
uint64_t res_grass_heap_extra_kib(void) {
int pct = grass_pct();
return pct > 100 ? (uint64_t)GRASS_HEAP_KIB * (uint64_t)(pct * pct - 10000) / 10000 : 0;
}
uint64_t res_grass_heap_extra_bytes(void) { return ((res_grass_heap_extra_kib() << 10) + 0x1fffff) & ~0x1fffffull; }
// TOTK_TEX_HEAP_EXTRA_MB (0 to 4096): more room in "TextureHeap" and its parent "ゲームグラフィックス", the heap the
// world's textures stream into. HD texture packs made for emulators with 8 GB of DRAM grow it by about 3.3 GiB in their
// own HeapDef; without the room the game runs out and starts its panic Blood Moon over and over. The pool and the heap
@@ -397,9 +414,9 @@ int res_heapdef_plain(const void *in, size_t n) {
}
int res_heapdef_build(const void *in, size_t n, void **out, size_t *out_n) {
uint64_t extra = res_heap_extra_kib(), tex = tex_heap_extra_kib();
uint64_t extra = res_heap_extra_kib(), tex = tex_heap_extra_kib(), grass = res_grass_heap_extra_kib();
*out = NULL;
if (!extra && !tex) return 0;
if (!extra && !tex && !grass) return 0;
Byml b;
uint32_t heaps = 0;
size_t dta_at = 0, gfx_at = 0;
@@ -439,6 +456,17 @@ int res_heapdef_build(const void *in, size_t n, void **out, size_t *out_n) {
}
}
}
if (grass) {
size_t at = heap_size_field(&b, heaps, "\xe8\x8d\x89"); // 草, the grass heap
if (at) {
int32_t g, g2;
memcpy(&g, b.p + at, 4);
g2 = g + (int32_t)grass;
memcpy(b.p + at, &g2, 4);
rt_log("resolution: HeapDef grass heap %d -> %d KiB (TOTK_GRASS_RANGE)", g, g2);
} else
rt_log("resolution: the HeapDef table has no grass heap; grass_range may run out of grass memory");
}
size_t cap = ZSTD_compressBound(b.n);
void *z = malloc(cap);
size_t zn = z ? ZSTD_compress(z, cap, b.p, b.n, 9) : 0;
@@ -499,8 +527,29 @@ static void res_shadow_range(void) {
rt_log("resolution: shadow cascades end at %g, %g, %g and %g m", d[0], d[1], d[2], d[3]);
}
// The grass map's values on page +128..+144 (the grass patch set): extent, step, the two texture sizes, and the
// half extent main+0x206340c picks instead of the extent. Texture sizes stay multiples of 32.
static void res_grass_range(void) {
int pct = grass_pct(), set = rt_patch_set("grass");
if (pct == 100) return;
if (set < 0) {
rt_log("resolution: this game version has no grass patch set; grass_range stays 100");
return;
}
float k = pct / 100.0f, f[2] = {62.5f * k, 3.90625f * k}, half = 31.25f * k;
uint32_t t[2] = {(uint32_t)(256 * pct / 100 + 16) / 32 * 32, (uint32_t)(128 * pct / 100 + 16) / 32 * 32};
uint8_t *page = rt_patch_page();
memcpy(page + 128, f, sizeof f);
memcpy(page + 136, t, sizeof t);
memcpy(page + 144, &half, sizeof half);
rt_patch_switch(set, 1);
rt_log("resolution: grass map %g m, textures %ux%u and %ux%u (TOTK_GRASS_RANGE=%d)", f[0], t[0], t[0], t[1], t[1],
pct);
}
void res_init(void) {
res_shadow_range();
res_grass_range();
if (!bigger()) {
rt_log("resolution: the game's own (output 1920x1080, scene 1600x900)");
shadow_init(rt_patch_page());
+1 -1
View File
@@ -888,7 +888,7 @@ static void *plain_mod_heapdef(size_t *n, const char **who) {
return NULL;
}
static void heapdef_overlay(void) {
if (!res_heap_extra_kib() && !res_tex_heap_extra_bytes()) return;
if (!res_heap_extra_kib() && !res_tex_heap_extra_bytes() && !res_grass_heap_extra_kib()) return;
static const char keeps[] = "the game keeps its own resolution";
Overlay *base;
size_t n;
+8
View File
@@ -552,6 +552,13 @@ static void row_shadow_range(void) {
opt_choice_list("TOTK_SHADOW_RANGE", UI_MENU_SHADOW_RANGE, vals, names, 4, UI_MENU_SHADOW_RANGE_DESC);
}
static void row_grass_range(void) {
static const char *const vals[] = {"50", "100", "150", "200", "300", "400"};
static const char *const names[] = {"31 m (0.5x)", "62 m (1x)", "94 m (1.5x)",
"125 m (2x)", "188 m (3x)", "250 m (4x)"};
opt_choice_list("TOTK_GRASS_RANGE", UI_MENU_GRASS_RANGE, vals, names, 6, UI_MENU_GRASS_RANGE_DESC);
}
static void row_gpu(void) {
const char *vals[MAX_GPUS + 1], *names[MAX_GPUS + 1];
char idx[MAX_GPUS][4];
@@ -683,6 +690,7 @@ static void tab_screen(float scale) {
opt_choice_list("TOTK_ANISO", UI_MENU_ANISO, aniso, aniso_names, 5, UI_MENU_ANISO_DESC);
row_shadow_scale();
row_shadow_range();
row_grass_range();
opt_slider("TOTK_PCSS", UI_MENU_PCSS, 0, 200, UI_MENU_PCSS_DESC, 10, "%.0f %%");
opt_slider("TOTK_CONTACT_SHADOWS", UI_MENU_CONTACT_SHADOWS, 0, 100, UI_MENU_CONTACT_SHADOWS_DESC, 10, "%.0f %%");
opt_toggle("TOTK_DLAA", UI_MENU_DLAA, UI_MENU_DLAA_DESC);
+14
View File
@@ -141,6 +141,10 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_SHADOW_RANGE_DESC] = "Moves the steps where shadows turn softer (the game's 20, 40, 80 and 160 m) further "
"away. Spreads the shadow map over more ground: raise Shadow resolution with it. "
"Takes effect at the next start.",
[UI_MENU_GRASS_RANGE] = "Grass range",
[UI_MENU_GRASS_RANGE_DESC] = "How far around the camera grass grows (the game's: 62.5 m). Higher keeps the "
"grass in meadows further out instead of growing it in just in front of you; lower "
"draws less of it. Takes effect at the next start.",
[UI_MENU_DLAA] = "NVIDIA DLSS / DLAA",
[UI_MENU_DLAA_DESC] = "NVIDIA DLSS for the 3D scene (NVIDIA RTX GPUs; " DLSS_FILE " next to " EXE_FILE "): smoother "
"edges and less shimmer. The HUD is not touched. The mode below sets the resolution it works "
@@ -634,6 +638,10 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_SHADOW_RANGE_DESC] = "Отодвигает границы, за которыми тени становятся мягче (в игре 20, 40, 80 и 160 м). "
"Карта теней растягивается на большую площадь, поэтому вместе с этим поднимайте "
"разрешение теней. Действует после перезапуска.",
[UI_MENU_GRASS_RANGE] = "Дальность травы",
[UI_MENU_GRASS_RANGE_DESC] = "Как далеко вокруг камеры растёт трава (в игре 62,5 м). Выше: трава на лугах видна "
"дальше и не вырастает прямо перед вами; ниже: травы меньше. Действует после "
"перезапуска.",
[UI_MENU_DLAA] = "NVIDIA DLSS / DLAA",
[UI_MENU_DLAA_DESC] = "NVIDIA DLSS для 3D-сцены (видеокарты NVIDIA RTX; " DLSS_FILE " рядом с " EXE_FILE "): ровнее "
"края и меньше мерцания. Интерфейс не затрагивается. Режим ниже задаёт разрешение, с которым он "
@@ -1476,6 +1484,10 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_MENU_SHADOW_RANGE_DESC] = "Afasta os degraus em que as sombras ficam mais suaves (20, 40, 80 e 160 m no "
"jogo). Espalha o mapa de sombras por mais terreno: aumente a Resolução das sombras "
"junto. Vale no próximo início.",
[UI_MENU_GRASS_RANGE] = "Alcance da grama",
[UI_MENU_GRASS_RANGE_DESC] = "Até onde a grama cresce ao redor da câmera (62,5 m no jogo). Mais alto mantém a "
"grama dos campos mais longe em vez de ela surgir logo à sua frente; mais baixo "
"desenha menos grama. Vale no próximo início.",
[UI_MENU_CONTACT_SHADOWS] = "Sombras de contato",
[UI_MENU_CONTACT_SHADOWS_DESC] = "Pequenas sombras do sol que os mapas de sombra não pegam: nos pés, sob pedras, "
"na grama e em dobras. Traçadas na tela depois da iluminação. Vale no próximo "
@@ -2105,6 +2117,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_SHADOW_SCALE_DESC] = "将太阳阴影贴图的每条边绘制为游戏 960x960 的若干倍:阴影边缘和树叶阴影更清晰。下次启动时生效。",
[UI_MENU_SHADOW_RANGE] = "阴影级联范围",
[UI_MENU_SHADOW_RANGE_DESC] = "把阴影变柔和的分界(游戏中为 20、40、80 和 160 米)推得更远。阴影贴图会覆盖更大的地面,请同时提高阴影分辨率。下次启动时生效。",
[UI_MENU_GRASS_RANGE] = "草地范围",
[UI_MENU_GRASS_RANGE_DESC] = "镜头周围长草的距离(游戏中为 62.5 米)。调高后草地延伸得更远,不会在你面前才长出来;调低则少画一些草。下次启动时生效。",
[UI_MENU_CONTACT_SHADOWS] = "接触阴影",
[UI_MENU_CONTACT_SHADOWS_DESC] = "阴影贴图遗漏的细小太阳阴影:脚下、石头下、草丛和褶皱中。在光照之后于屏幕空间追踪。下次启动时生效。",
[UI_MENU_PCSS] = "柔和阴影",
+1
View File
@@ -53,6 +53,7 @@ typedef enum {
UI_MENU_HDR_UI, UI_MENU_HDR_UI_DESC, UI_MENU_HDR_HUE, UI_MENU_HDR_HUE_DESC,
UI_MENU_SHADOW_SCALE, UI_MENU_SHADOW_SCALE_DESC,
UI_MENU_SHADOW_RANGE, UI_MENU_SHADOW_RANGE_DESC,
UI_MENU_GRASS_RANGE, UI_MENU_GRASS_RANGE_DESC,
UI_MENU_CONTACT_SHADOWS, UI_MENU_CONTACT_SHADOWS_DESC,
UI_MENU_PCSS, UI_MENU_PCSS_DESC,
UI_MENU_DLAA, UI_MENU_DLAA_DESC, UI_MENU_DLSS, UI_MENU_DLSS_DESC, UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY,
+5
View File
@@ -228,6 +228,11 @@
# Sun shadow cascade range in percent of the game's (its cascades end at 20, 40, 80 and 160 m), 50 to 400: higher moves
# the steps where shadows turn softer further away, and spreads the shadow map over more ground. Read at start.
# shadow_range = 100
# How far around the camera grass grows, in percent of the game's (its near grass map covers 62.5 m), 50 to 400.
# Higher keeps the grass in meadows further out instead of growing it in a short way in front of you, and draws more of
# it; the grass map's textures grow with it, so its detail per metre stays the game's, and the grass heap grows by about
# 9 MiB times (percent / 100)^2 - 1. Lower draws less grass. Read at start.
# grass_range = 100
# Screen-space contact shadows, strength in percent (0 = off): after the game lights its scene, each pixel traces a
# short way toward the sun through the depth buffer and darkens where something close blocks it, adding the small
# shadows at feet, under stones and in grass that the shadow maps miss. Read at start.