diff --git a/dm/gfx/nvn/nvn_dirty.c b/dm/gfx/nvn/nvn_dirty.c index 9e00974..2d44f70 100644 --- a/dm/gfx/nvn/nvn_dirty.c +++ b/dm/gfx/nvn/nvn_dirty.c @@ -13,8 +13,24 @@ #include #include #include +#include -enum { PG_NONE = 0, PG_PROT = 1, PG_BUSY = 2 }; // BUSY:正在解除保护(另一线程同时缺页时自旋等它) | BUSY: being unprotected (another thread faulting at the same time spins waiting for it) +// 页状态与 mprotect 的次序(改保护的一方先把状态改成 BUSY,mprotect 落地后才改成终态;别的线程见 BUSY 就等): +// 设只读:NONE → BUSY → mprotect(只读) → PROT;解保护:PROT → BUSY → mprotect(可写) → NONE。 +// 不变式:状态是 NONE 的页一定可写、是 PROT 的页一定只读。原先设只读是「先记 PROT、攒一段再 mprotect」,这段时间里另一线程的写前解保护 +// 会把状态改回 NONE,随后攒批的 mprotect 落地 ⇒ 页只读而状态 NONE:游戏线程写它时缺页处理只回「重执行」永远空转; +// 宿主用系统调用往里读文件时 prep_write 看状态 NONE 跳过,系统调用不走缺页处理,直接 EFAULT、数据读不全。 +// BUSY 最长持续 = 一次 mprotect 的时间(设只读时再加上给这一段逐页改状态的几次原子写)。等待有上限 BUSY_WAIT_MS,超限报红: +// 缺页处理里超限按「不是我们的页」返回,交给崩溃处理如实报崩,不静默空转。等待只读原子量、不拿任何锁。 +// Order of page state and mprotect (the side changing protection first sets the state to BUSY and sets the final state only after mprotect has landed; other threads wait when they see BUSY): +// set read-only: NONE -> BUSY -> mprotect(read-only) -> PROT; unprotect: PROT -> BUSY -> mprotect(writable) -> NONE. +// Invariant: a page whose state is NONE is always writable, and one whose state is PROT is always read-only. Setting read-only used to be "record PROT first, batch up a run, then mprotect"; during that time another thread's unprotect-before-write +// could set the state back to NONE, and then the batched mprotect landed => the page read-only with state NONE: when the game thread wrote to it the page-fault handler only returned "re-execute" and spun forever; +// when the host read a file into it with a system call, prep_write saw state NONE and skipped, the system call did not go through the page-fault handler and failed with EFAULT, leaving the data incomplete. +// BUSY lasts at most one mprotect (plus, when setting read-only, the few atomic writes that change the state of the pages in the run). The wait has an upper limit BUSY_WAIT_MS and reports red beyond it: +// in the page-fault handler, exceeding it returns "not our page" and lets the crash handler report the crash truthfully instead of spinning silently. The wait only reads atomics and takes no lock. +enum { PG_NONE = 0, PG_PROT = 1, PG_BUSY = 2 }; +enum { BUSY_WAIT_MS = 2000 }; // 跟踪区间 = 各内存池(MemoryPoolInitialize 登记)。池销毁后复用 live=0 的槽,信号处理里无锁扫描。 // Tracked ranges = the memory pools (registered by MemoryPoolInitialize). After a pool is destroyed its live=0 slot is reused; the signal handler scans without locks. #define MAX_RANGE 4096 // 原为 256:内存池多于它时超出的池不跟踪,里面的贴图每次取用都当成脏的重传(暗黑实测峰值见内存读数行的「内存池」;塞尔达约 300 个,踩过)。扫描只到已用的槽数,容量大不增加开销 | was 256: with more memory pools than that the excess pools are untracked and their textures are treated as dirty and re-uploaded on every use (for Diablo's measured peak see "memory pools" in the memory readout line; Zelda has about 300 and hit this). The scan only covers slots in use, so a larger capacity costs nothing @@ -35,6 +51,22 @@ static void mp(uintptr_t a, size_t len, int prot) { atomic_fetch_add(&g_mp_ticks, mach_absolute_time() - t); atomic_fetch_add(&g_mp_calls, 1); atomic_fetch_add(&g_mp_pages, len >> g_shift); } +static mach_timebase_info_data_t g_tb; // 首次登记池时取好(缺页路径里只做乘除) | Obtained when a pool is first registered (the fault path only multiplies and divides) +static _Atomic int g_busy_red; +// 等这一页离开 BUSY。返回 1 = 已离开;0 = 等过了上限(报红一次)。信号处理里可用:只有原子读、mach_absolute_time、sched_yield +// Wait for this page to leave BUSY. Returns 1 = it has left; 0 = waited past the limit (reported red once). Usable in a signal handler: only atomic reads, mach_absolute_time and sched_yield +static int busy_wait(range_t *r, uintptr_t p) { + uint64_t t0 = 0; + for (unsigned n = 1; atomic_load(&r->state[p]) == PG_BUSY; n++) { + if (n & 0x3ff) continue; + uint64_t now = mach_absolute_time(); if (!t0) t0 = now; + if ((now - t0) * g_tb.numer / g_tb.denom > (uint64_t)BUSY_WAIT_MS * 1000000ull) { + if (!atomic_exchange(&g_busy_red, 1)) LOG("【红】脏页跟踪:页 %p 停在「忙」超过 %d 毫秒(改保护的线程没走完),不再等", (void *)(r->base + (p << g_shift)), BUSY_WAIT_MS); + return 0; } + sched_yield(); + } + return 1; +} static range_t *find(uintptr_t a) { int n = atomic_load(&g_nr); for (int i = 0; i < n; i++) if (atomic_load_explicit(&g_r[i].live, memory_order_acquire) && a >= g_r[i].base && a < g_r[i].end) return &g_r[i]; @@ -52,7 +84,7 @@ static int on_fault(void *addr, int is_write, void *uc) { uintptr_t p = ((uintptr_t)addr - r->base) >> g_shift; uint8_t st = PG_PROT; if (atomic_compare_exchange_strong(&r->state[p], &st, PG_BUSY)) { unprotect_page(r, p); atomic_fetch_add(&g_faults, 1); return 1; } - if (st == PG_BUSY) { while (atomic_load(&r->state[p]) == PG_BUSY) {} return 1; } // 别的线程正在解:等它解完重执行 | Another thread is unprotecting it: wait for it to finish and re-execute + if (st == PG_BUSY) return busy_wait(r, p); // 别的线程正在改这页的保护:等它改完重执行(改成了只读就再缺页一次、走上面那一支) | Another thread is changing this page's protection: wait for it to finish and re-execute (if it became read-only, it faults once more and takes the branch above) return atomic_load(&r->gen[p]) != 0; // 刚被别的线程解掉(本次缺页发生在解之前):重执行;从未保护过的页不是我们的 | Just unprotected by another thread (this fault happened before the unprotect): re-execute; pages that were never protected are not ours } static void prep_write(void *addr, size_t len) { @@ -62,9 +94,9 @@ static void prep_write(void *addr, size_t len) { if (!r) { a = (a + g_pg) & ~(g_pg - 1); continue; } uintptr_t stop = e < r->end ? e : r->end; for (uintptr_t p = (a - r->base) >> g_shift, q = (stop - 1 - r->base) >> g_shift; p <= q; p++) { - uint8_t st = PG_PROT; - if (atomic_compare_exchange_strong(&r->state[p], &st, PG_BUSY)) { unprotect_page(r, p); atomic_fetch_add(&g_preps, 1); } - else while (atomic_load(&r->state[p]) == PG_BUSY) {} + for (;;) { uint8_t st = PG_PROT; // 见 BUSY 等完要重看:对方可能是在设只读,等完这页是 PROT,照样得解 | After waiting out BUSY, look again: the other side may have been setting read-only, in which case the page is PROT after the wait and still has to be unprotected + if (atomic_compare_exchange_strong(&r->state[p], &st, PG_BUSY)) { unprotect_page(r, p); atomic_fetch_add(&g_preps, 1); break; } + if (st != PG_BUSY || !busy_wait(r, p)) break; } } a = stop; } @@ -72,7 +104,7 @@ static void prep_write(void *addr, size_t len) { void nvn_dirty_add_range(const void *mem, size_t size) { static int inited; - if (!inited) { inited = 1; g_pg = (uintptr_t)getpagesize(); g_shift = __builtin_ctzl(g_pg); dm_fault_hook_register(on_fault); dm_guest_write_prep_register(prep_write); } + if (!inited) { inited = 1; g_pg = (uintptr_t)getpagesize(); g_shift = __builtin_ctzl(g_pg); mach_timebase_info(&g_tb); dm_fault_hook_register(on_fault); dm_guest_write_prep_register(prep_write); } atomic_fetch_add(&g_adds_total, 1); pthread_mutex_lock(&g_slot_mu); int n = atomic_load(&g_nr); @@ -117,22 +149,22 @@ void nvn_dirty_remove_range(const void *mem) { int nvn_dirty_tracked(const void *addr, size_t len) { range_t *r = find((uintptr_t)addr); return r && (uintptr_t)addr + len <= r->end; } -// 设只读:先置状态再 mprotect(反过来会有「页已只读、状态仍为 0」的窗口,那时的合法写入会被当成崩溃) -// Set read-only: set the state first, then mprotect (the reverse leaves a window of "page already read-only, state still 0", during which a legitimate write would be treated as a crash) +// 设只读:先把页标成 BUSY,mprotect 落地后才标 PROT(次序与不变式见文件头的状态说明) +// Set read-only: mark the page BUSY first, and mark it PROT only after mprotect has landed (for the order and the invariant see the state notes at the top of the file) void nvn_dirty_protect(const void *addr, size_t len) { if (!len || !nvn_dirty_tracked(addr, len)) return; range_t *r = find((uintptr_t)addr); uintptr_t a = (uintptr_t)addr, p = (a - r->base) >> g_shift, q = (a + len - 1 - r->base) >> g_shift; // 连续置成 PROT 的页合成一次 mprotect(逐页调用在首传大贴图时一帧上千次;选角页启动帧 5:4888 次)。 - // 已是 PROT / BUSY 的页断开连续段:不重复保护,也不碰别的线程正在解的页 - // Consecutive pages set to PROT are merged into one mprotect (per-page calls reach thousands per frame on the first upload of large textures; character select page startup frame 5: 4888 calls). - // Pages already PROT / BUSY break the consecutive run: do not protect again, and do not touch pages another thread is unprotecting + // 已是 PROT / BUSY 的页断开连续段:不重复保护,也不碰别的线程正在改的页 + // Consecutive pages set to PROT are merged into one mprotect (per-page calls ran to over a thousand per frame when large textures were first uploaded; character select, startup frame 5: 4888 calls). + // Pages already PROT / BUSY break a run: they are not protected again, and pages another thread is changing are left alone uintptr_t run = 0; int open = 0; for (uintptr_t i = p; i <= q + 1; i++) { uint8_t st = PG_NONE; - int took = i <= q && atomic_compare_exchange_strong(&r->state[i], &st, PG_PROT); + int took = i <= q && atomic_compare_exchange_strong(&r->state[i], &st, PG_BUSY); if (took && !open) { run = i; open = 1; } - if (!took && open) { mp(r->base + (run << g_shift), (i - run) << g_shift, PROT_READ); open = 0; } + if (!took && open) { mp(r->base + (run << g_shift), (i - run) << g_shift, PROT_READ); for (uintptr_t k = run; k < i; k++) atomic_store(&r->state[k], PG_PROT); open = 0; } } } uint64_t nvn_dirty_now(void) { return atomic_load(&g_now); } diff --git a/dm/gfx/tests/.gitignore b/dm/gfx/tests/.gitignore index 4fde36a..4502c8f 100644 --- a/dm/gfx/tests/.gitignore +++ b/dm/gfx/tests/.gitignore @@ -30,6 +30,8 @@ t_rt_depth_ro.dSYM/ t_pso_skey t_pso_skey.dSYM/ t_dirty_slots +t_dirty_race +t_dirty_race.dSYM/ t_dirty_slots.dSYM/ t_pfv t_pfv.dSYM/ diff --git a/dm/gfx/tests/Makefile b/dm/gfx/tests/Makefile index 4f7eb37..bc2995a 100644 --- a/dm/gfx/tests/Makefile +++ b/dm/gfx/tests/Makefile @@ -12,6 +12,8 @@ t_nvn: t_nvn.c ../nvn/hle_nvn.c ../../host/crash.c $(GFX) $(GFX_H) clang $(CFLAGS) -fobjc-arc -o $@ t_nvn.c ../../host/crash.c $(GFX) $(FW) t_dirty_slots: t_dirty_slots.c ../nvn/nvn_dirty.c ../../host/crash.c ../nvn/nvn_dirty.h clang $(CFLAGS) -o $@ t_dirty_slots.c ../../host/crash.c ../nvn/nvn_dirty.c +t_dirty_race: t_dirty_race.c ../nvn/nvn_dirty.c ../../host/crash.c ../nvn/nvn_dirty.h + clang $(CFLAGS) -o $@ t_dirty_race.c ../../host/crash.c t_builtin: t_builtin.m ../nvn/nvn_builtin.h clang -O1 -g -Wall -fobjc-arc -o $@ t_builtin.m -framework Metal -framework Foundation t_deswz_gpu: t_deswz_gpu.m ../tex/nvn_deswizzle.c ../tex/nvn_deswizzle_gpu.m ../tex/nvn_deswizzle.h ../tex/nvn_deswizzle_gpu.h ../nvn/nvn_tex.c ../nvn/nvn_tex.h @@ -52,9 +54,10 @@ t_pso_skey: t_pso_skey.m ../nvn/nvn_pso_skey.h ../nvn/nvn_obj.h clang $(CFLAGS) -fobjc-arc -o $@ t_pso_skey.m -framework Foundation t_pfv: t_pfv.m ../../host/crash.c $(GFX) $(GFX_H) clang $(CFLAGS) -fobjc-arc -o $@ t_pfv.m ../../host/crash.c $(filter-out ../nvn/nvn_mtl.m ../nvn/nvn_entry.S ../nvn/nvn_thunks.S,$(GFX)) $(FW) -run: t_nvn t_dirty_slots t_builtin t_deswz_gpu t_pace t_refl t_hmap t_cover t_fuse_check t_present_crop t_reorder_chain t_defer_chain t_zskip t_xv t_ub t_mip_extent t_rt_range_shape t_rt_range_ro t_rt_range t_rt_depth_ro t_pso_skey t_pfv +run: t_nvn t_dirty_slots t_dirty_race t_builtin t_deswz_gpu t_pace t_refl t_hmap t_cover t_fuse_check t_present_crop t_reorder_chain t_defer_chain t_zskip t_xv t_ub t_mip_extent t_rt_range_shape t_rt_range_ro t_rt_range t_rt_depth_ro t_pso_skey t_pfv ./t_nvn ./t_dirty_slots + ./t_dirty_race ./t_builtin ./t_deswz_gpu ./t_pace diff --git a/dm/gfx/tests/t_dirty_race.c b/dm/gfx/tests/t_dirty_race.c new file mode 100644 index 0000000..3553547 --- /dev/null +++ b/dm/gfx/tests/t_dirty_race.c @@ -0,0 +1,63 @@ +// 脏页跟踪「设只读」与「写前解保护」的次序竞态。 +// 现场:线程甲 nvn_dirty_protect 已把页的状态记成「受保护」、攒批的 mprotect 还没落地;线程乙这时来 prep_write(宿主往客体内存写之前的解保护, +// 例如读盘把文件读进贴图存储)。旧实现:乙把状态改回「无」,随后甲的 mprotect 落地 ⇒ 页只读而状态「无」—— +// 宿主再往里读文件:prep_write 看状态「无」跳过,系统调用不走缺页处理,直接 EFAULT;游戏线程直接写:缺页处理只回「重执行」,永远空转。 +// 造法:把 nvn_dirty.c 里的 mprotect 换成这里的 t_mprotect——甲设只读的那一次调用落地之前,先放乙进来并等 100 毫秒,次序是确定的。 +// 期望值不靠被测实现:乙的 prep_write 返回之后,这一页必须真的可写(往里 read 16 字节得 16;直接写一个字节不卡、读回是写进去的值), +// 且这次写要被记成脏(nvn_dirty_since 对设只读之前取的戳返回 1)。 +// Ordering race between "set read-only" and "unprotect before write" in dirty-page tracking. +// Scene: thread A, in nvn_dirty_protect, has already recorded the page state as "protected" while the batched mprotect has not landed yet; thread B now arrives with prep_write (the unprotect done before the host writes into guest memory, +// for example a disk read putting a file into texture storage). Old implementation: B sets the state back to "none", then A's mprotect lands => the page is read-only while its state is "none" -- +// when the host reads a file into it again: prep_write sees state "none" and skips, the system call does not go through the page-fault handler and fails with EFAULT; when the game thread writes directly: the page-fault handler only returns "re-execute" and spins forever. +// How it is staged: the mprotect in nvn_dirty.c is replaced by t_mprotect here -- before the call with which A sets read-only lands, B is let in and given 100 ms, so the order is deterministic. +// Expected values do not depend on the implementation under test: after B's prep_write returns, this page must really be writable (reading 16 bytes into it gives 16; writing one byte directly does not hang and reads back as written), +// and this write must be recorded as dirty (nvn_dirty_since returns 1 for a stamp taken before the page was set read-only). +#define mprotect t_mprotect +#include "../nvn/nvn_dirty.c" +#undef mprotect +int mprotect(void *, size_t, int); +#include +#include + +module_t g_mod[MAX_MOD]; +int g_nmod; +module_t *module_of(const void *p) { (void)p; return NULL; } +void crash_install(void); + +static int g_fail; +#define EXPECT(name, want, got) do { \ + long long want_ = (long long)(want), got_ = (long long)(got); \ + printf("%-58s 期望 %-4lld → 真结果 %-4lld %s\n", name, want_, got_, want_ == got_ ? "✓" : "✗"); \ + if (want_ != got_) g_fail++; \ +} while (0) + +static uint8_t *g_page; static _Atomic int g_armed, g_go, g_b_done; +static void *thread_b(void *arg) { (void)arg; while (!atomic_load(&g_go)) usleep(200); prep_write(g_page, 16); atomic_store(&g_b_done, 1); return NULL; } +int t_mprotect(void *a, size_t n, int prot) { + if (prot == PROT_READ && atomic_exchange(&g_armed, 0)) { atomic_store(&g_go, 1); usleep(100000); } // 甲的 mprotect 落地前:放乙进来,等它跑到头或卡在等待上 | Before A's mprotect lands: let B in and wait until it runs to the end or gets stuck waiting + return mprotect(a, n, prot); +} + +int main(void) { + crash_install(); + size_t pg = (size_t)getpagesize(); + g_page = mmap(NULL, 2 * pg, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); + if (g_page == MAP_FAILED) { perror("mmap"); return 2; } + nvn_dirty_add_range(g_page, 2 * pg); + uint64_t stamp = nvn_dirty_now(); + pthread_t tb; pthread_create(&tb, NULL, thread_b, NULL); + atomic_store(&g_armed, 1); + nvn_dirty_protect(g_page, 2 * pg); // 甲:置状态 → (乙插进来)→ mprotect 落地 | A: set the state -> (B cuts in) -> mprotect lands + for (int i = 0; i < 2000 && !atomic_load(&g_b_done); i++) usleep(1000); + EXPECT("乙的写前解保护在 2 秒内返回", 1, atomic_load(&g_b_done)); + if (!atomic_load(&g_b_done)) { printf("t_dirty_race:乙没返回,后面的项不测\n"); return 1; } + pthread_join(tb, NULL); + int fd = open("/dev/zero", O_RDONLY); g_page[pg] = 0; // 第二页没人解过保护,这一写走缺页处理(对照:正常路径是通的) | Nobody has unprotected the second page, so this write goes through the page-fault handler (control: the normal path works) + ssize_t r = read(fd, g_page, 16); // 乙接下来要做的那次宿主写:系统调用直接写进页里 | The host write that B is about to make: a system call writing straight into the page + EXPECT("乙解完保护后往这页读文件:读到的字节数 = 请求的 16", 16, r); + if (r == 16) { ((volatile uint8_t *)g_page)[1] = 0x5a; EXPECT("直接写这页不卡、读回是写进去的值", 0x5a, g_page[1]); } + else { printf(" (read 失败 errno=%d;页只读而状态为「无」,直接写会在缺页处理里空转,这一项不执行)\n", errno); g_fail++; } + EXPECT("这次写被记成脏(对设只读前的戳)", 1, nvn_dirty_since(g_page, 16, stamp)); + close(fd); + printf("t_dirty_race:%s\n", g_fail ? "不通" : "全通"); return g_fail != 0; +} diff --git a/dm/ios/tools/touch_layout.py b/dm/ios/tools/touch_layout.py index b30751f..e14b66e 100644 --- a/dm/ios/tools/touch_layout.py +++ b/dm/ios/tools/touch_layout.py @@ -614,25 +614,21 @@ def _pause_no_help(ys, hide=('Help',), restart_y=None, extra=()): return s, n return fn # 手柄版暂停菜单(「难度、百宝囊存放挂暂停菜单」):原版布局 + 我们的功能行,放原版路径(gen_romfs_overlay.py 手柄版布局);触屏插回的关闭钮不带。 -# 行 = 选项 / 保存并退出 / 一键重开 / 切换难度 / 存放 / 编年史(经典版没有)/ 分享诊断日志;帮助、战利品过滤器、消息记录照的裁定不留。 +# 行 = 游戏难度 / 保存并退出 / 一键重开 / 选项 / 存放 / 编年史(经典版没有)/ 分享诊断日志;帮助、战利品过滤器、消息记录照的裁定不留。 +# 「选项」固定在第四行(y 653):原版手柄版开暂停菜单时自由光标在屏幕正中、压着哪行哪行高亮,直接按确认就点它——正中那行只许是按了没后果的。 # 「游戏难度:N」= 按一下人数档 +1(8 之后回 1),当前档位写在这一行上;「存放」= 物品栏「存放」钮同一件事(手柄焦点到不了那颗钮),字用原版串 @strGoldDeposit。 -# 按钮图高 120 单位:带编年史那版七行在原版首末两行之间(278–1028)等距 125;经典版原底图只放得下四行,换用带编年史那版的底图(同尺寸),六行等距 150 -# Controller pause menu ("difficulty and pouch Deposit live in the pause menu"): original layout + our feature rows, placed at the original path -# (gen_romfs_overlay.py controller layouts); the close button re-inserted for touch is not included. -# Rows = Options / Save and Exit / one-tap restart / change difficulty / Deposit / Chronicle (absent in the classic version) / Share Diagnostics; Help, -# Loot Filter and Message Log are left out per an earlier decision. -# "Game Difficulty: N" = each press raises the /players setting by 1 (wrapping to 1 after 8), with the current setting written on this row; -# "Deposit" = the same thing as the inventory "Deposit" button (controller focus cannot reach that button), with its text taken from the original string -# @strGoldDeposit. -# Button image height is 120 units: the seven rows of the version with Chronicle are spaced evenly at 125 between the original first and last rows -# (278–1028); the classic version's original background only fits four rows, so the background of the version with Chronicle is used instead (same -# size), six rows spaced evenly at 150 +# 按钮图高 120 单位:带编年史那版七行在原版首末两行之间(278–1028)等距 125;经典版原底图只放得下四行,换用带编年史那版的底图(同尺寸),同一套行距排前六行(少编年史那行,后一行上移) +# Gamepad pause menu ("difficulty and trove deposit hang on the pause menu"): the original layout + our feature rows, placed at the original path (gamepad layout in gen_romfs_overlay.py); the close button inserted for touch is not included. +# Rows = Game Difficulty / Save and Exit / Quick Restart / Options / Deposit / Chronicle (absent in the classic version) / Share Diagnostics; Help, Loot Filter and Message Log are not kept, as ruled. +# "Options" is fixed on the fourth row (y 653): when the original gamepad UI opens the pause menu the free cursor is at the centre of the screen and highlights whichever row it rests on, and pressing confirm straight away activates it -- the centre row may only be one whose press has no consequence. +# "Game Difficulty: N" = one press raises the player-count setting by 1 (back to 1 after 8), with the current setting shown on this row; "Deposit" = the same thing as the "Deposit" button of the inventory (the gamepad focus cannot reach that button), using the original string @strGoldDeposit. +# Button image height is 120 units: in the version with the Chronicle, seven rows are spaced evenly by 125 between the original first and last rows (278–1028); the classic version's own background only fits four rows, so the background of the Chronicle version (same size) is used and the first six rows are laid out with the same spacing (without the Chronicle row, the following row moves up) def pad_pause(s, garden): - ex = lambda y0, dy: (('TouchPadDiff', '', y0), ('TouchPadStore', '@strGoldDeposit', y0 + dy)) - if garden: s, y = _pause_no_help({'Settings': (428, 278), 'Exit': (728, 403), 'Chronicle': (1028, 903), 'MessageLog': (278, 1028)}, hide=('Help', 'LootFilter'), restart_y=528, extra=ex(653, 125))(s)[0], 653 + ex = (('TouchPadDiff', '', 278), ('TouchPadStore', '@strGoldDeposit', 778)); y = 278 + if garden: s = _pause_no_help({'Settings': (428, 653), 'Exit': (728, 403), 'Chronicle': (1028, 903), 'MessageLog': (278, 1028)}, hide=('Help', 'LootFilter'), restart_y=528, extra=ex)(s)[0] else: s = _sub1(s, '"filename": "Controller/Panel/EscapeMenu/EscapeOptionsBGClassic"', '"filename": "Controller/Panel/EscapeMenu/EscapeOptionsBG"') - s, y = _pause_no_help({'Settings': (578, 278), 'Exit': (878, 428), 'MessageLog': (428, 1028)}, hide=('Help',), restart_y=578, extra=ex(728, 150))(s)[0], 728 + s = _pause_no_help({'Settings': (578, 653), 'Exit': (878, 403), 'MessageLog': (428, 903)}, hide=('Help',), restart_y=528, extra=ex)(s)[0] # 「游戏难度:N」的字:菜单开着时游戏停拍、原版系统通知要关了菜单才出,所以当前档位直接写在这一行上——按钮自己不带字,上面叠一个同字体的文字控件,宿主写(dm_padmode.c) # Text of "Game Difficulty: N": while the menu is open the game stops ticking and the original system notification only appears once the menu is closed, # so the current setting is written directly on this row. The button itself carries no text; a text widget with the same font is stacked on top and