From feb2bb9fdc27ce143169b13a1ef18a38b3663c26 Mon Sep 17 00:00:00 2001 From: jhaizhou <258432107+jhaizhou-ops@users.noreply.github.com> Date: Wed, 14 Oct 2026 05:22:34 +0800 Subject: [PATCH] Greater Rift minion life fix (#23); Mac click-to-walk and keyboard key names; older-API declaration de-duplication --- README.md | 2 +- README.zh-CN.md | 2 +- dm/.gitignore | 1 + dm/gfx/nvn/nvn_mtl.m | 21 ++++++++- dm/gfx/tests/Makefile | 27 ++++++++++- dm/host/Makefile | 59 +++++++++++++++++++++++- dm/host/dm_i18n_tab.h | 2 +- dm/host/dm_padmode.c | 59 +++++++++++++++++++++++- dm/host/dm_rift.c | 61 +++++++++++++++++++++---- dm/host/dm_world.c | 76 ++++++++++++++++++++++++++++++- dm/host/front_mac.m | 1 + dm/host/tests/Makefile | 35 +++++++++++++- dm/host/tests/t_touch_mac.c | 1 + dm/host/tests/t_touch_tick_stub.c | 1 + dm/host/touch_mac.c | 15 +++++- dm/i18n/literal_whitelist.tsv | 2 +- dm/i18n/ui_text.tsv | 2 +- dm/ios/Sources/dm_gamepad.m | 6 ++- dm/ios/tools/gen_romfs_overlay.py | 3 ++ dm/ios/tools/kbd_glyphs.py | 49 ++++++++++++++++++++ docs/MAC.md | 14 ++++-- docs/MAC.zh-CN.md | 14 ++++-- 22 files changed, 420 insertions(+), 33 deletions(-) create mode 100644 dm/ios/tools/kbd_glyphs.py diff --git a/README.md b/README.md index 2e582e7..11aa7eb 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,7 @@ dm/tools/mac_app.sh # macOS 26 or later: produces ~/dm-work/out DM_MAC_M3=1 dm/tools/mac_app.sh # macOS 15 – 25: produces D2R Mobile M3.app ``` -The interface is the original's gamepad interface. Keyboard: Space confirms, Esc goes back, Return, the `=` key opens the menu / a new character, W A S D moves, and every other gamepad button has a key. Mouse: clicking a monster, NPC or object walks over and interacts, and the skill slots, potion cells and key hints at the bottom, buttons and tabs in panels, the class figures when creating a character and the minimap can all be clicked; walking by clicking empty ground and dragging items are not there yet. Saves stay on this Mac (an App you build yourself has no iCloud sync) and can be imported by hand from an iPhone / iPad. The key table, how to create a character, what the mouse can do, the import steps and the known shortcomings are in [docs/MAC.md](docs/MAC.md). Keyboard and a physical gamepad have not been operated by a person yet — if you try it, please tell us how it went. +The interface is the original's gamepad interface. Keyboard: Space confirms, Esc goes back, Return, the `=` key opens the menu / a new character, W A S D moves, and every other gamepad button has a key. Mouse: clicking a monster, NPC or object walks over and interacts, and the skill slots, potion cells and key hints at the bottom, buttons and tabs in panels, the class figures when creating a character and the minimap can all be clicked; clicking empty ground walks there and holding keeps walking; attacking by clicking a monster and dragging items are not there yet. With a keyboard, the prompts on screen show keyboard keys. Saves stay on this Mac (an App you build yourself has no iCloud sync) and can be imported by hand from an iPhone / iPad. The key table, how to create a character, what the mouse can do, the import steps and the known shortcomings are in [docs/MAC.md](docs/MAC.md). Keyboard and a physical gamepad have not been operated by a person yet — if you try it, please tell us how it went. ### Without a Mac: the shell plus the packaging tool diff --git a/README.zh-CN.md b/README.zh-CN.md index b9e77c8..5cebeba 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -250,7 +250,7 @@ dm/tools/mac_app.sh # macOS 26 及以上:产出 ~/dm-work/out DM_MAC_M3=1 dm/tools/mac_app.sh # macOS 15 – 25:产出 D2R Mobile M3.app ``` -界面用原版的手柄版界面。键盘:空格确认、Esc 返回、回车、`=` 键开菜单 / 新角色,W A S D 移动,其余手柄键各有对应。鼠标:点怪、NPC、物件会走过去交互,底部的技能格、药水格、按键提示、面板里的按钮和页签、建角时的职业、小地图都能点;点空地走路和物品的拖放还没有。存档在这台 Mac 上(自己构建的 App 没有 iCloud 同步),可以从 iPhone / iPad 手工导入。键位表、建角怎么按、鼠标能做什么、导入步骤和已知不足,见 [docs/MAC.zh-CN.md](docs/MAC.zh-CN.md)。键盘、实体手柄这几项还未经真人操作,你试过的话,请告诉我们结果。 +界面用原版的手柄版界面。键盘:空格确认、Esc 返回、回车、`=` 键开菜单 / 新角色,W A S D 移动,其余手柄键各有对应。鼠标:点怪、NPC、物件会走过去交互,底部的技能格、药水格、按键提示、面板里的按钮和页签、建角时的职业、小地图都能点;点空地会走过去、按住一直走;点怪攻击和物品的拖放还没有。用键盘时屏上的按键提示直接显示键盘键名。存档在这台 Mac 上(自己构建的 App 没有 iCloud 同步),可以从 iPhone / iPad 手工导入。键位表、建角怎么按、鼠标能做什么、导入步骤和已知不足,见 [docs/MAC.zh-CN.md](docs/MAC.zh-CN.md)。键盘、实体手柄这几项还未经真人操作,你试过的话,请告诉我们结果。 ### 没有 Mac:壳 + 做包工具 diff --git a/dm/.gitignore b/dm/.gitignore index 10b3c4e..e79a995 100644 --- a/dm/.gitignore +++ b/dm/.gitignore @@ -1,4 +1,5 @@ host/dmhost +host/dmhost_m3 host/*.dSYM/ *.bin *.pkl diff --git a/dm/gfx/nvn/nvn_mtl.m b/dm/gfx/nvn/nvn_mtl.m index 857e4b7..78e37d0 100644 --- a/dm/gfx/nvn/nvn_mtl.m +++ b/dm/gfx/nvn/nvn_mtl.m @@ -2856,6 +2856,25 @@ static uint64_t ui_mat_patch(const p_bind_buf *u, void *mb, uint64_t mo) { la = u->addr; ls = u->size; lp = g_pass.serial; lo = g_ui_moff; lg = ring_gpu + at; at += n; return lg; } +#if DM_NVN_M3 +// 老接口的资源声明去重:同一渲染编码器内对同一资源重复 useResource 是幂等的,而每次新编参数块都会把它引用的资源全声明一遍—— +// 营地实测每次绘制声明 9.7 次、其中 9.2 次是本编码器里已经声明过的,每次约 227 条指令。这里记下本通道(g_pass.serial,与渲染编码器一一对应: +// 序号只在开渲染编码器前递增)已按哪些用法声明过哪些资源,已覆盖的跳过。表满(一个通道里超过表长个不同资源)时不记、照常声明。 +// 表项不持有资源:声明过的资源被编码器持有到提交完成,同一通道内它的地址不会被别的资源复用。只在提交线程上用 +// De-duplicating resource declarations on the older API: repeated useResource for the same resource within one render encoder is idempotent, yet every newly encoded argument block declares all the resources it references once more - +// measured in the camp at 9.7 declarations per draw, of which 9.2 were already declared in this encoder, about 227 instructions per draw. Here it is recorded which resources have been declared with which usages in this pass (g_pass.serial, one-to-one with render encoders: +// the serial only increments before a render encoder is opened), and those already covered are skipped. When the table is full (more distinct resources in one pass than the table holds) nothing is recorded and declarations proceed as usual. +// Table entries do not retain resources: a declared resource is held by the encoder until the submission completes, so within one pass its address is not reused by another resource. Used only on the submission thread +enum { M3_USE_N = 1024 }; +static struct { void *p; uint64_t pass; uint32_t u; } g_m3_use[M3_USE_N]; +static inline int m3_use_seen(void *p, uint32_t u) { + for (uint32_t h = (uint32_t)(((uintptr_t)p >> 4) * 0x9E3779B1u) >> 22, k = 0; k < M3_USE_N; k++, h = (h + 1) & (M3_USE_N - 1)) { + if (g_m3_use[h].pass != g_pass.serial) { g_m3_use[h].p = p; g_m3_use[h].pass = g_pass.serial; g_m3_use[h].u = u; return 0; } + if (g_m3_use[h].p == p) { if ((g_m3_use[h].u & u) == u) return 1; g_m3_use[h].u |= u; return 0; } + } + return 0; +} +#endif static int encode_args(id en, NvShader *sh, int nvn_stage, int metal_vertex) { if (!sh->ae) return 1; uint64_t slots[NVN_REFL_MAXB] = {0}; @@ -2870,7 +2889,7 @@ static int encode_args(id en, NvShader *sh, int nvn_stage, in // 不声明的话只读贴图会和写它的拷贝乱序(迁 Metal 4 前实测过)。同一编码器内重复声明是幂等的 // Older API: every resource a shader accesses indirectly through an argument block must have its usage declared on this encoder, so that the system knows its ordering dependency against other encoders (upload copies, other passes); // without the declaration a read-only texture gets out of order with the copy that writes it (measured before the move to Metal 4). Repeated declarations within one encoder are idempotent - #define USE(r, u) do { id r_ = (id)(r); if (r_) { if (nvn_stage == 5) [(id)en useResource:r_ usage:(u)]; else [(id)en useResource:r_ usage:(u) stages:MTLRenderStageVertex | MTLRenderStageFragment]; } \ + #define USE(r, u) do { id r_ = (id)(r); if (r_) { if (nvn_stage == 5) [(id)en useResource:r_ usage:(u)]; else if (!m3_use_seen((__bridge void *)r_, (uint32_t)(u))) [(id)en useResource:r_ usage:(u) stages:MTLRenderStageVertex | MTLRenderStageFragment]; } \ if (__builtin_expect(g_res_check_on, 0)) res_check((r), sh->key, reg); } while (0) #define USE_SAMP(r, u) do { (void)(u); if (__builtin_expect(g_res_check_on, 0)) res_check((r), sh->key, reg); } while (0) // 采样器不是资源,不用声明 | samplers are not resources and need no declaration #else diff --git a/dm/gfx/tests/Makefile b/dm/gfx/tests/Makefile index 4c3639a..175e135 100644 --- a/dm/gfx/tests/Makefile +++ b/dm/gfx/tests/Makefile @@ -54,7 +54,32 @@ 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_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 +# 依赖一行一个、按字母序(免得加一个测试就整行冲突);下面各条命令的先后不变 +# Dependencies one per line in alphabetical order (so that adding one test does not conflict on the whole line); the order of the commands below is unchanged +run: \ + t_builtin \ + t_cover \ + t_defer_chain \ + t_deswz_gpu \ + t_dirty_race \ + t_dirty_slots \ + t_fuse_check \ + t_hmap \ + t_mip_extent \ + t_nvn \ + t_pace \ + t_pfv \ + t_present_crop \ + t_pso_skey \ + t_refl \ + t_reorder_chain \ + t_rt_depth_ro \ + t_rt_range \ + t_rt_range_ro \ + t_rt_range_shape \ + t_ub \ + t_xv \ + t_zskip ./t_nvn ./t_dirty_slots ./t_dirty_race diff --git a/dm/host/Makefile b/dm/host/Makefile index 3a181fd..dd2bb96 100644 --- a/dm/host/Makefile +++ b/dm/host/Makefile @@ -6,8 +6,63 @@ DM_ROOT ?= $(HOME)/dm-work MACOS_MIN ?= 26.0 CFLAGS=-O1 -g -Wall -Wno-unused-function -mmacosx-version-min=$(MACOS_MIN) # 服务层接管 hle_*.c 按通配纳入:新增文件不改这一行(免合并冲突) -# Service-layer takeover hle_*.c files are included by wildcard: adding a file does not touch this line (avoids merge conflicts) -SRC=main.c loader.c hle.c crash.c diag.c thread.c memstat.m dm_cursor.c dm_cursor_item.c dm_world.c dm_textinput.c dm_update.c dm_actions.c dm_namegen.c dm_cloudsync.c dm_custom.c dm_elysium.c dm_bossrush.c dm_pages.c dm_vault.c dm_vault_ui.c dm_kills.c dm_textbox.c dm_turnsmooth.c dm_textbox_core.c dm_potpick.c dm_lootfilter.c dm_autobuff.c dm_beltauto.c dm_padmode.c dm_pouch.c dm_drophaptic.c dm_freetp.c dm_townwp.c dm_shoprefresh.c dm_runeword.c dm_rwlv_core.c dm_uiscreen.c dm_dropfilter.c dm_hud.c dm_rift.c dm_rift_ui.c dm_bright.c touch_mac.c romfs_validate.c ../ios/Sources/dm_touch_controls.c $(sort $(wildcard hle_*.c)) front_mac.m app_mac.m ../ios/Sources/dm_gamepad.m ../ios/Sources/cloud_ios.m entry.S dm_i18n.c +# 一行一个、按字母序(先本目录的,再 ../ 开头的,最后是通配那一项):加源文件时插到自己的位置,别的分支加的在别的行,变基不再整行冲突 +# The service-layer hle_*.c files are included by wildcard: adding a file does not change this line (no merge conflicts) +# One per line, in alphabetical order (first those in this directory, then those starting with ../, the wildcard entry last): insert a new source file at its own place; files added on other branches are on other lines, so rebasing no longer conflicts on the whole line +SRC=\ + app_mac.m \ + crash.c \ + diag.c \ + entry.S \ + front_mac.m \ + hle.c \ + loader.c \ + main.c \ + memstat.m \ + romfs_validate.c \ + dm_actions.c \ + dm_autobuff.c \ + dm_beltauto.c \ + dm_bossrush.c \ + dm_bright.c \ + dm_cloudsync.c \ + dm_cursor.c \ + dm_cursor_item.c \ + dm_custom.c \ + dm_dropfilter.c \ + dm_drophaptic.c \ + dm_elysium.c \ + dm_freetp.c \ + dm_hud.c \ + dm_i18n.c \ + dm_kills.c \ + dm_lootfilter.c \ + dm_namegen.c \ + dm_padmode.c \ + dm_pages.c \ + dm_potpick.c \ + dm_pouch.c \ + dm_rift.c \ + dm_rift_ui.c \ + dm_runeword.c \ + dm_rwlv_core.c \ + dm_shoprefresh.c \ + dm_textbox.c \ + dm_textbox_core.c \ + dm_textinput.c \ + dm_townwp.c \ + dm_turnsmooth.c \ + dm_uiscreen.c \ + dm_update.c \ + dm_vault.c \ + dm_vault_ui.c \ + dm_world.c \ + thread.c \ + touch_mac.c \ + ../ios/Sources/cloud_ios.m \ + ../ios/Sources/dm_gamepad.m \ + ../ios/Sources/dm_touch_controls.c \ + $(sort $(wildcard hle_*.c)) # NVN 空设备 + nn::vi(dm/gfx/) # 按通配纳入 dm/gfx 与 dm/gfx/nvn 下的源(tests/ metal/ 不进宿主):新增文件不改这一行 # NVN null device + nn::vi (dm/gfx/) diff --git a/dm/host/dm_i18n_tab.h b/dm/host/dm_i18n_tab.h index 66b6bc7..8d85c6c 100644 --- a/dm/host/dm_i18n_tab.h +++ b/dm/host/dm_i18n_tab.h @@ -317,5 +317,5 @@ static const struct { const char *k, *zh, *en; } k_dm_i18n[] = { { "dmAppFullscreen", "全屏", "Toggle Full Screen" }, { "dmAppMenuHelp", "帮助", "Help" }, { "dmAppKeysTitle", "键盘与手柄按键对照", "Keyboard and Controller Buttons" }, - { "dmAppKeysText", "界面上的按键提示是手柄字母,键盘这样对应:\n\n确认(A):空格 或 J  返回(B):Esc 或 K\n回车:确认;页面底部有「+」提示时是 +(如起名后的「接受」)\n+(菜单 / 新角色):= 键  −(地图):Tab\n移动:W A S D(左摇杆)  十字键:方向键\nX:U  Y:I  L:Q  R:E  ZL:Z  ZR:C\n按左摇杆:F  按右摇杆:G\n\n鼠标:左键点目标、界面、底部的按键提示和技能 / 药水格;右键 = 返回;滚轮滚列表。\n接上手柄可以直接用。这一页以后在「帮助」菜单里。", "On-screen button hints use controller letters. Keyboard mapping:\n\nConfirm (A): Space or J Back (B): Esc or K\nReturn: confirm; acts as + when the page shows a + hint (e.g. Accept after naming)\n+ (menu / new character): = key − (map): Tab\nMove: W A S D (left stick) D-pad: arrow keys\nX: U Y: I L: Q R: E ZL: Z ZR: C\nPress left stick: F Press right stick: G\n\nMouse: left click targets, the interface, the button hints at the bottom and skill / potion slots; right click = back; wheel scrolls lists.\nA connected controller works right away. This page stays in the Help menu." }, + { "dmAppKeysText", "用键盘时,界面上的按键提示显示的就是键盘上的键;接上手柄按一下,提示换成手柄字母。\n\n确认:J(空格也可以)  返回:K(Esc 也可以)\n回车也可以确认;页面底部有「=」提示时回车当 =(如起名后的「接受」)\n=:菜单 / 新角色  Tab:地图\n移动:W A S D  十字键:方向键\nU I Q E Z C:手柄的 X Y L R ZL ZR\nF:按左摇杆  G:按右摇杆\n\n鼠标:左键点空地走过去,按住不放一直朝光标走;点目标、界面、底部的按键提示和技能 / 药水格;右键 = 返回;滚轮滚列表。\n接上手柄可以直接用。这一页以后在「帮助」菜单里。", "With a keyboard, on-screen button hints show keyboard keys; press anything on a connected controller and they switch to controller letters.\n\nConfirm: J (Space also works) Back: K (Esc also works)\nReturn also confirms; acts as = when the page shows an = hint (e.g. Accept after naming)\n=: menu / new character Tab: map\nMove: W A S D D-pad: arrow keys\nU I Q E Z C: controller X Y L R ZL ZR\nF: press left stick G: press right stick\n\nMouse: left click the ground to walk there, hold to keep walking toward the cursor; click targets, the interface, the button hints at the bottom and skill / potion slots; right click = back; wheel scrolls lists.\nA connected controller works right away. This page stays in the Help menu." }, }; diff --git a/dm/host/dm_padmode.c b/dm/host/dm_padmode.c index 1e03273..c2f532e 100644 --- a/dm/host/dm_padmode.c +++ b/dm/host/dm_padmode.c @@ -44,6 +44,7 @@ #include #include #include +#include static const struct { uint32_t off; const char *pad, *touch; } k_pfx[] = { { 0x1d21db5, "Controller/Console/Switch/", "0touch_console_switch_lay/" }, @@ -65,10 +66,40 @@ static uint64_t g_tx_from; // 本次事务开始的帧 | Frame at which static _Atomic uint32_t g_rebuilds; // 布局重建完成的次数:前端据此重认 HUD(技能钮快照的 HUD 集合按控件地址认,重建后全换了) | Number of completed layout rebuilds: the front end uses it to re-identify the HUD (the HUD set of the skill-button snapshot is identified by widget address, and they all change after a rebuild) uint32_t dm_padmode_rebuilds(void) { return atomic_load(&g_rebuilds); } +// Mac App 的键盘键帽(只在 macOS 宿主里编;iOS 包没有这一套):手柄版布局不变,只把取键位图标的路径换到覆盖层里那套键盘键名的图 +// (ios/tools/kbd_glyphs.py,与触屏的透明键帽同目录、文件名「<平台>K<名字>」)。玩家按了键盘就用键盘键帽,实体手柄有输入就换回手柄键帽; +// 换图要让游戏重载布局,走的就是手柄 / 触屏那同一个切换事务(事务里的「模式」多带一位:第 0 位手柄版、第 1 位键盘键帽)。 +// Keyboard key caps of the Mac App (compiled only in the macOS host; the iOS package does not have them): the gamepad layout is unchanged, only the path the key icons are taken from is switched to the keyboard-key images in the overlay +// (ios/tools/kbd_glyphs.py, in the same directory as the touch layout's transparent key caps, file names "K"). When the player presses the keyboard, keyboard key caps are used; when a physical gamepad has input, it switches back to gamepad key caps; +// swapping images requires the game to reload the layout, which goes through the same switching transaction as gamepad / touch (the transaction's "mode" carries one more bit: bit 0 gamepad layout, bit 1 keyboard key caps). +#if TARGET_OS_OSX +#define KBD_GLYPH_OFF 0x1d0f5b8 +static const char k_kbd_glyph[] = "Ztouch_controller_buttons_ui/%sK%s"; +static int g_kbd_have, g_kbd, g_kbd_next, g_app; // 覆盖层带键盘键帽;当前路径指着键盘键帽;下一次写路径时要不要指键盘键帽;Mac App 形态 | the overlay carries keyboard key caps; the current path points at keyboard key caps; whether the next path write should point at keyboard key caps; Mac App form +static _Atomic int g_kbd_want; +void dm_padmode_request_kbd(int kbd) { kbd = kbd ? 1 : 0; if (!g_kbd_have) return; atomic_store(&g_kbd_want, kbd); } // 前端(任意线程):键盘有输入 1 / 实体手柄有输入 0。这里不立输入冻结:换键帽要等面板都关了才起(见 kbd_swap_ok),等的时候玩家照常操作;事务起的那一帧才冻结 | front end (any thread): keyboard had input 1 / physical gamepad had input 0. No input freeze is raised here: swapping key caps waits until all panels are closed (see kbd_swap_ok), and the player operates as usual while waiting; the freeze starts only on the frame the transaction starts +int dm_padmode_kbd(void) { return g_kbd; } +// 只换键帽的重载只在「没有面板开着」时起:重载布局会把开着的页重建一遍,设置页的勾选框会全显示成未勾、还多出「全部接受」(实测), +// 所以局内要 HUD 在屏、游戏没停(暂停菜单 / 设置页 / 借壳的页)、手势层认的面板一个没开;前端要删除 / 选项 / 起名 / 确认框都没开。等到条件满足的那一帧再换 +// The reload that only swaps key caps starts only when "no panel is open": reloading the layout rebuilds any open page, and the checkboxes of the settings page would all show as unchecked with an extra "Accept All" appearing (measured), +// so in game the HUD must be on screen, the game not stopped (pause menu / settings page / pages borrowing another shell) and none of the panels the gesture layer recognises open; in the front end none of delete / options / naming / confirmation boxes open. The swap happens on the first frame where the conditions hold +static int kbd_swap_ok(uint8_t *b) { + int dm_ingame_now(void), dm_ui_panel_state(void), dm_ui_fe_drag_ok(void); + if (!dm_ingame_now()) return dm_ui_fe_drag_ok(); + return !(*(volatile uint8_t *)(b + 0x2d5ff51) | *(volatile uint8_t *)(b + 0x2d5ff67)) && !dm_ui_panel_state(); +} +#endif static int pfx_write(uint8_t *b, int pad) { for (unsigned i = 0; i < sizeof k_pfx / sizeof *k_pfx; i++) { const char *p = (const char *)(b + k_pfx[i].off); +#if TARGET_OS_OSX + if (k_pfx[i].off == KBD_GLYPH_OFF && !strcmp(p, k_kbd_glyph)) continue; +#endif if (strcmp(p, k_pfx[i].pad) && strcmp(p, k_pfx[i].touch)) { LOG("【红】手柄 / 触屏布局:main+%#x 不是预期的「%s」(是「%.32s」),不改", k_pfx[i].off, k_pfx[i].pad, p); return 0; } } for (unsigned i = 0; i < sizeof k_pfx / sizeof *k_pfx; i++) memcpy(b + k_pfx[i].off, pad ? k_pfx[i].pad : k_pfx[i].touch, strlen(k_pfx[i].pad)); +#if TARGET_OS_OSX + _Static_assert(sizeof k_kbd_glyph == sizeof "Controller/ControllerButtons/%s/%s", "键盘键帽路径要与原版路径等长"); + if (pad && g_kbd_next) memcpy(b + KBD_GLYPH_OFF, k_kbd_glyph, sizeof k_kbd_glyph - 1); +#endif return 1; } enum { NSTR = 64 }; @@ -127,9 +158,17 @@ void dm_padmode_boot(void) { // 开机:游戏建面板之前(main.c,nnMa if (!m || !getenv("DM_ROMFS_OVERLAY")) return; if (!dm_overlay_file("ctrl_touch", mk, sizeof mk)) { LOG("手柄 / 触屏布局:覆盖层没有 ctrl_touch 标记,照原版布局"); return; } int pad = getenv("DM_APP") != NULL; // Mac App:没有触屏圆钮与底栏的绘制层,开机就用原版手柄版(我们的功能页在手柄版布局里同样有),之后也不切 | Mac App: there is no drawing layer for the touch buttons and bottom bar, so it starts in the original gamepad UI (our feature pages exist in the gamepad layout as well) and never switches afterwards +#if TARGET_OS_OSX + g_app = pad; g_kbd_have = pad && dm_overlay_file("kbd_glyphs", mk, sizeof mk); g_kbd = g_kbd_next = g_kbd_have; atomic_store(&g_kbd_want, g_kbd); // Mac App 开机先用键盘键帽(多数人没接手柄);实体手柄一有输入就换 | the Mac App starts with keyboard key caps (most people have no gamepad connected); it switches as soon as a physical gamepad has input + if (pad) LOG("手柄 / 触屏布局:键盘键帽 %d", g_kbd_have); +#endif if (pfx_write((uint8_t *)m->base, pad)) { g_have = 1; g_cur = pad; atomic_store(&g_want, pad); g_b = (uint8_t *)m->base; str_load(); LOG("手柄 / 触屏布局:开机用%s", pad ? "原版手柄版(Mac App)" : "触屏版(layouts/xtouch_lay 等三个目录)"); } } -void dm_padmode_request(int pad) { pad = pad ? 1 : 0; atomic_store(&g_want, pad); if (g_have && pad != g_cur) atomic_store(&g_freeze, 1); } // 前端(任意线程):从这一刻起输入就不再交给游戏 | Front end (any thread): from this moment on input is no longer handed to the game +void dm_padmode_request(int pad) { pad = pad ? 1 : 0; +#if TARGET_OS_OSX + if (g_app) pad = 1; // Mac App 没有触屏圆钮与底栏的绘制层:手柄断开也留在手柄版,不切触屏版 | the Mac App has no drawing layer for the touch round buttons and bottom bar: stay in the gamepad layout even when the gamepad disconnects, do not switch to the touch layout +#endif + atomic_store(&g_want, pad); if (g_have && pad != g_cur) atomic_store(&g_freeze, 1); } // 前端(任意线程):从这一刻起输入就不再交给游戏 | Front end (any thread): from this moment on input is no longer handed to the game int dm_padmode_current(void) { return g_cur; } int dm_padmode_busy(void) { return atomic_load(&g_freeze); } // 切换事务进行中(含请求已到、事务还没起的那一小段) | Switch transaction in progress (including the short span where the request has arrived but the transaction has not started yet) int dm_padmode_input_gate(uint64_t *buttons) { static dm_modegate g; return dm_modegate_apply(&g, atomic_load(&g_freeze), buttons); } // 取手柄处(hle_hid.c fill,游戏主线程) | Where the controller is read (hle_hid.c fill, game main thread) @@ -430,18 +469,36 @@ void dm_padmode_step(uint8_t *b, uint64_t frame) { // 游戏主线程每帧( for (int i = 0; i < g_nstr && i < 3; i++) { struct { const char *s; uint64_t n; } q = { g_str[i].key, g_str[i].klen }; const char *r = ((const char *(*)(void *))(b + 0x7f5630))(&q); L += (size_t)snprintf(o + L, L < sizeof o ? sizeof o - L : 0, "%s%s=「%s」", i ? "、" : "", g_str[i].key, r ? r : "(空)"); } LOG("DM_TEST_PADMODE:帧 %llu 模式 %s,原版取串 %s", (unsigned long long)frame, g_cur ? "手柄" : "触屏", o); } } +#if TARGET_OS_OSX + // 测试开关 DM_TEST_KBDCAPS=<帧>:<0|1>[,…]:到帧当作「实体手柄有输入(0)/ 键盘有输入(1)」(无人值守的局没有实体手柄) + // Test switch DM_TEST_KBDCAPS=:<0|1>[,...]: at that frame act as if "a physical gamepad had input (0) / the keyboard had input (1)" (unattended runs have no physical gamepad) + { static int n = -1, k; static struct { uint64_t f; int m; } ev[8]; + if (n < 0) { n = 0; const char *e = getenv("DM_TEST_KBDCAPS"); for (const char *q = e; q && *q && n < 8; ) { unsigned long long f; int m; if (sscanf(q, "%llu:%d", &f, &m) != 2) break; ev[n].f = f; ev[n].m = m; n++; q = strchr(q, ','); if (q) q++; } } + if (k < n && frame >= ev[k].f) { LOG("DM_TEST_KBDCAPS:帧 %llu 请求键盘键帽 %d", (unsigned long long)frame, ev[k].m); dm_padmode_request_kbd(ev[k].m); k++; } } +#endif if (g_have && frame % 30 == 0) str_apply(g_cur); // 串表开机后才装、切语言会重装:定期核 | The string table is loaded only after boot and reloaded on a language switch: check periodically if (!g_have) return; { uint32_t dm_oe_ui_opmode_reads(void); static uint64_t fp0; static uint32_t nfp; uint64_t root = rd8((uint64_t)(uintptr_t)(b + 0x2f05458)), ch = root ? rd8(root + 0x58) : 0, n = root ? rd8(root + 0x60) : 0, fp = n * 0x9e3779b97f4a7c15ull; for (uint64_t i = 0; ch && i < n && i < 256; i++) fp = (fp << 7 | fp >> 57) ^ rd8(ch + 8 * i); if (fp != fp0) { fp0 = fp; nfp++; } g_sig = dm_oe_ui_opmode_reads() + nfp; } +#if TARGET_OS_OSX + int w = atomic_load(&g_want), wx = w, cx = g_cur; + if (g_kbd_have) { int tp = w >= 0 ? w : g_cur, tk = tp ? atomic_load(&g_kbd_want) : 0; if (tk != g_kbd && tp == g_cur && !kbd_swap_ok(b)) tk = g_kbd; + wx = tp | tk << 1; cx = g_cur | g_kbd << 1; if (wx == cx && w < 0) wx = -1; } // 键帽那一位并进事务的「模式」里 | the key-cap bit is merged into the transaction's "mode" + int act = dm_modetx_step(&g_tx, frame, wx, cx, g_sig); + if (act == DM_TXA_BEGIN) { g_kbd_next = wx >> 1; w = wx & 1; } +#else int w = atomic_load(&g_want), act = dm_modetx_step(&g_tx, frame, w, g_cur, g_sig); +#endif if (act == DM_TXA_NONE) { if (g_tx.st == DM_TX_IDLE && atomic_load(&g_freeze)) { atomic_store(&g_freeze, 0); if (atomic_load(&g_want) != w) atomic_store(&g_freeze, 1); } return; } // 没在切:请求时立的冻结(想要的就是当前模式 / 又改回来了)撤掉;撤的同时又来了新请求的重新立上 | Not switching: the freeze set at request time (the wanted mode is the current one / it was changed back) is lifted; if a new request arrives at the same time as the lift, it is set again if (act == DM_TXA_BEGIN) { if (!pfx_write(b, w)) { g_tx.st = DM_TX_IDLE; atomic_store(&g_want, -1); atomic_store(&g_freeze, 0); return; } atomic_store(&g_freeze, 1); g_tx_from = frame; items_run(g_cur, 1); // 旧一侧各登记项收手(dm_mode_items.h):在途的替按键作废、挪过的控件写回、缓存的控件地址清掉 | Registered items of the old side stand down (dm_mode_items.h): in-flight key presses on the player's behalf are voided, moved widgets written back, cached widget addresses cleared g_cur = w; str_apply(w); dm_oe_ui_opmode(!dm_opmode()); +#if TARGET_OS_OSX + g_kbd = g_kbd_next; if (g_kbd_have) LOG("手柄 / 触屏布局:键盘键帽 → %d", g_kbd); +#endif LOG("手柄 / 触屏布局:切到%s版——开始(输入冻结,让游戏重载布局)", w ? "原版手柄" : "触屏"); return; } if (g_tx.timeouts) LOG("【红】手柄 / 触屏布局:%d 帧内没回读到界面重建(游戏没来读运行模式、界面根下的面板也没换),按超时往下走", DM_MODETX_TIMEOUT); if (act == DM_TXA_REPORT_BACK) { dm_oe_ui_opmode(-1); return; } diff --git a/dm/host/dm_rift.c b/dm/host/dm_rift.c index f9d5122..5e49fdb 100644 --- a/dm/host/dm_rift.c +++ b/dm/host/dm_rift.c @@ -69,6 +69,14 @@ static int ground_items(uint64_t G) { int n = 0; for (int b = 0; b < 128; b++) f static uint64_t find_unit(uint64_t G, int type, uint32_t id) { for (int b = 0; b < 128; b++) for (uint64_t u = rd(G + 0x2230 + type * 0x400 + 8 * b); u; u = rd(u + 0x158)) if (*(uint32_t *)(uintptr_t)(u + 8) == id) return u; return 0; } static int gs(uint64_t u, int st) { return ((int (*)(uint64_t, int, int))(B + 0x5b9290))(u, st, 0); } static void ss(uint64_t u, int st, int v) { ((void (*)(uint64_t, int, int, int))(B + 0x5bc1f0))(u, st, v, 0); } +// 属性的基础项。0x5b9290(gs)在带扩展标志的属性表上读的是合计数组(表 +0xe8:基础 + 各状态 / 光环 / 装备的加成,百分比加成已乘进去), +// 而 0x5bc1f0(ss)写的是基础数组(表 +0x30,经 0x5bbe20)、写完由 0x5bbcd0 重算合计。「读合计、乘一个数、写回」会把加成乘两遍;要改基础项就得读基础项。 +// 基础数组:{键 = 属性号 << 16 | 层号, 值} 各 4 字节,个数在 +0x38(同 0x5b9290 里的查法,这里层号取 0) +// The base entry of a stat. On a stat table with the extended flag, 0x5b9290 (gs) reads the totals array (table +0xe8: base plus the bonuses of states / auras / equipment, with percentage bonuses already multiplied in), +// while 0x5bc1f0 (ss) writes the base array (table +0x30, through 0x5bbe20), after which 0x5bbcd0 recomputes the total. "Read the total, multiply by a number, write back" multiplies the bonus in twice; to change the base entry the base entry must be read. +// Base array: {key = stat id << 16 | layer, value}, 4 bytes each, count at +0x38 (the same lookup as in 0x5b9290, with layer 0 here) +static int gsb(uint64_t u, int st) { uint64_t sl = rd(u + 0x88); const uint32_t *a = sl ? (const uint32_t *)(uintptr_t)rd(sl + 0x30) : NULL; uint64_t n = sl ? rd(sl + 0x38) : 0; + if (!a || n > 4096) return 0; for (uint64_t i = 0; i < n; i++) if (a[i * 2] == (uint32_t)st << 16) return (int)a[i * 2 + 1]; return 0; } static uint64_t free_spot(uint64_t G, uint64_t room, int32_t pos[2]) { uint64_t out = 0; ((void (*)(uint64_t, uint64_t, int32_t *, int, int, uint64_t *, int, int))(B + 0x7160d0))(G, room, pos, 3, 0x400, &out, 4, 100); return out; } static void level_origin(uint64_t lv, int *x0, int *y0) { *x0 = *y0 = 1 << 30; int n = 0; for (uint64_t r = dm_level_rooms(lv); r && n < 2000; r = rd(r + 0x48), n++) { int x = *(int32_t *)(uintptr_t)(r + 0x60) * 5, y = *(int32_t *)(uintptr_t)(r + 0x64) * 5; if (x < *x0) *x0 = x; if (y < *y0) *y0 = y; } } @@ -446,6 +454,18 @@ static void pet_file_save(void) { char p[1200], q[1220]; if (!pet_path(p, sizeof snprintf(q, sizeof q, "%s.tmp", p); FILE *f = fopen(q, "w"); if (!f) { LOG("【红】秘境:随从基数侧文件写不进 %s", q); return; } for (int i = 0; i < g_pfn; i++) fprintf(f, "%u %d %d\n", g_pf[i].cls, g_pf[i].base, g_pf[i].boosted); if (fclose(f) || rename(q, p)) LOG("【红】秘境:随从基数侧文件改名失败 %s", p); } +// 束缚恶魔生命上限的原版封顶,现算:随从表(monpet)那一行的 BoundStat1 须是生命上限(属性 7),用它的算式 BoundCalc1 让游戏自己再算一遍—— +// 就是转化那一刻原版的做法(main+0x7aaf78 起:0x51ea40 取行,行 +0x50 属性号、+0x5c 算式号,0x5285b0 求值,生命类属性左移 8 位)。 +// 算式是 min(现值, 该类封顶),人数档读恶魔自己身上记的那份(属性 100,转化时定下、随存档走),所以对没被动过的恶魔算出来就是它现在的值。返回原始定点值;取不到 = 0 +// The original's cap on a bound demon's maximum life, computed on the spot: BoundStat1 of its row in the pet table (monpet) must be maximum life (stat 7), and its formula BoundCalc1 is evaluated by the game itself once more - +// exactly what the original does at the moment of conversion (from main+0x7aaf78: 0x51ea40 fetches the row, row +0x50 stat id, +0x5c formula id, 0x5285b0 evaluates, life-type stats shifted left by 8). +// The formula is min(current value, cap of this class), and the player-count tier is read from what is recorded on the demon itself (stat 100, fixed at conversion and saved with the save), so for an untouched demon the result is just its current value. Returns the raw fixed-point value; 0 = unavailable +static int bound_cap(uint64_t u, uint64_t player) { + uint8_t ver = *(uint8_t *)(uintptr_t)(u + 0x1bd); if (ver < 1 || ver > 3) return 0; + uint64_t row = ((uint64_t (*)(uint64_t))(B + 0x51ea40))(u); if (!row || *(uint16_t *)(uintptr_t)(row + 0x50) != 7) return 0; + int v = ((int (*)(int, uint64_t, uint64_t, uint32_t))(B + 0x5285b0))(ver, u, player, *(uint32_t *)(uintptr_t)(row + 0x5c)); + return v > 0 && v <= 0x7fffff ? v << 8 : 0; +} static void pet_hp_pump(uint64_t G, uint64_t player, uint32_t t) { static int dump = -1; if (dump < 0) dump = getenv("DM_RIFT_TEST_PETDUMP") != NULL; if (!K.who[0]) return; @@ -459,21 +479,40 @@ static void pet_hp_pump(uint64_t G, uint64_t player, uint32_t t) { int mult = on ? 1000 + (int)((long long)(top - 100) * 10 * (tier - f) / (100 - f)) : 1000, act = top || g_pfn; uint64_t pd = rd(player + 0x10), lst = pd ? rd(pd + 0x98) : 0, arr = lst ? rd(lst) : 0, T = tables(G); uint32_t nt = T ? *(uint32_t *)(uintptr_t)(T + 0x1300) : 0; if (!arr || nt > 64) return; char line[700]; int lo = 0; line[0] = 0; - struct { uint32_t cls; int base, boosted; } now[16]; int nn = 0; + struct { uint32_t cls; int base, boosted; } now[16]; int nn = 0, pf_dirty = 0; for (uint32_t ty = 1; ty < nt; ty++) { if (ty == 7) continue; /* 7 = 佣兵,不算 | 7 = mercenary, not counted */ int guard = 0; for (uint64_t nd = rd(arr + (uint64_t)ty * 0x20); nd && guard < 64; nd = rd(nd + 0x18), guard++) { uint32_t id = *(uint32_t *)(uintptr_t)(nd + 4); uint64_t u = find_unit(G, 1, id); if (!u) continue; uint32_t md = *(uint32_t *)(uintptr_t)(u + 0xc); if (md == 0 || md == 12) continue; - int cur = gs(u, 7); uint32_t cls = *(uint32_t *)(uintptr_t)(u + 4); if (cur <= 0) continue; - if (dump && t % 125 == 0 && lo < (int)sizeof line - 80) lo += snprintf(line + lo, sizeof line - lo, " [类型 %u 类号 %u id %u 等级 %d 生命上限 %d]", ty, cls, id, gs(u, 12), cur >> 8); + // cur = 生命上限的基础项(不是 gs 读到的合计):我们写的是基础项,基数、比较、侧文件全按同一个量走;游戏给随从的百分比生命加成(技能 / 光环)由它自己乘在合计上。 + // 原先这里读合计:有 +N% 加成的随从,写进去的「合计 × 倍率」又被游戏乘一遍 (1 + N%),下一轮读回 ≠ 上次写入、被当成新基数再乘——每 10 拍涨 (1 + N%) 倍直到溢出 + // cur = the base entry of maximum life (not the total gs reads): what we write is the base entry, and base, comparison and sidecar file all use the same quantity; the percentage life bonus the game gives minions (skills / auras) is multiplied onto the total by the game itself. + // This used to read the total: for a minion with a +N% bonus, the written "total x multiplier" was multiplied by (1 + N%) again by the game, the next readback != the last write and was taken as a new base and multiplied again - growing by (1 + N%) every 10 ticks until overflow + int cur = gsb(u, 7), full = gs(u, 7); uint32_t cls = *(uint32_t *)(uintptr_t)(u + 4); if (cur <= 0 || full <= 0) continue; + // 测试开关 DM_RIFT_TEST_PETPCT=<百分数>(造现场用):给每只随从的基础项加一条「生命上限 +N%」(属性 76),模拟技能 / 光环给随从的常驻生命加成 + // Test switch DM_RIFT_TEST_PETPCT= (for staging a scene): add a "maximum life +N%" entry (stat 76) to the base of every minion, imitating a standing life bonus given to minions by a skill / aura + { static int pct = -1; static uint32_t done[16]; static unsigned dn; if (pct < 0) { const char *e = getenv("DM_RIFT_TEST_PETPCT"); pct = e ? atoi(e) : 0; } + if (pct > 0) { int seen = 0; for (int i = 0; i < 16; i++) seen |= done[i] == id; if (!seen) { done[dn++ % 16] = id; int b0 = gsb(u, 7), f0 = gs(u, 7); ss(u, 76, pct); + LOG("秘境:测试 DM_RIFT_TEST_PETPCT 给随从 id %u(类号 %u)加生命上限 +%d%%:基础 %d、合计 %d → 基础 %d、合计 %d", id, cls, pct, b0 >> 8, f0 >> 8, gsb(u, 7) >> 8, gs(u, 7) >> 8); full = gs(u, 7); } } } + if (dump && t % 125 == 0 && lo < (int)sizeof line - 110) lo += snprintf(line + lo, sizeof line - lo, " [类型 %u 类号 %u id %u 等级 %d 生命上限 %d(基础 %d)当前 %d]", ty, cls, id, gs(u, 12), full >> 8, cur >> 8, gs(u, 6) >> 8); if (!act) continue; - int k = -1; for (int i = 0; i < 64; i++) if (tb[i].id == id && tb[i].cls == cls) { k = i; break; } + int k = -1, fresh = 1; for (int i = 0; i < 64; i++) if (tb[i].id == id && tb[i].cls == cls) { k = i; break; } if (k < 0) { k = (int)(tw++ % 64); tb[k].id = id; tb[k].cls = cls; tb[k].base = cur; tb[k].last = cur; for (int i = 0; i < g_pfn; i++) if (g_pf[i].cls == cls && g_pf[i].boosted == cur) { tb[k].base = g_pf[i].base; LOG("秘境:随从 id %u(类号 %u)读档带着放大后的生命上限 %d,基数按侧文件取 %d", id, cls, cur >> 8, tb[k].base >> 8); break; } } else if (cur != tb[k].last) { tb[k].base = cur; tb[k].last = cur; } /* 游戏自己改过:新值当基数 | changed by the game itself: the new value becomes the base */ - long long want = (long long)tb[k].base * mult / 1000; if (want > 0x7fffff00LL) want = 0x7fffff00LL; - if ((int)want != cur) { int hp = gs(u, 6); long long nh = (long long)hp * want / cur; if (nh < 256) nh = 256; if (nh > want) nh = want; + else fresh = 0; + // 一次性修正(留在存档里的值):束缚恶魔的基数不可能高过原版封顶——高了就是修正前那个循环写进角色档的,设回封顶; + // 侧文件里同类号、基数也高过封顶的记录是那条链上的,一并去掉。低于封顶的污染值和正常值分不开,不碰。只在基数刚定下时判(头一次见到 / 游戏改过) + // One-time repair (values left in saves): a bound demon's base cannot be higher than the original's cap - if it is, it was written into the character save by the loop that existed before the fix, so set it back to the cap; + // records in the sidecar file with the same class id whose base is also above the cap belong to that chain and are removed as well. Polluted values below the cap cannot be told apart from normal ones and are left alone. Checked only when the base has just been established (first seen / changed by the game) + if (fresh && ty == 21) { int cap = bound_cap(u, player); if (cap > 0 && tb[k].base > cap) { + LOG("秘境:%s 的束缚恶魔(类号 %u)生命基础 %d 超过上限,已设回 %d", K.who, cls, tb[k].base >> 8, cap >> 8); tb[k].base = cap; + for (int i = 0; i < g_pfn; ) { if (g_pf[i].cls == cls && g_pf[i].base > cap) { g_pf[i] = g_pf[--g_pfn]; pf_dirty = 1; } else i++; } } } + // 封顶按合计算:合计 = 基础 × (合计 ÷ 基础),合计不能过属性的上限(0x7fffff00 = 8388607 点;再大就溢出成负数,游戏读成 1 点) + // The cap is computed on the total: total = base x (total / base), and the total must not exceed the stat's limit (0x7fffff00 = 8388607 points; any larger and it overflows to a negative number, which the game reads as 1 point) + long long want = (long long)tb[k].base * mult / 1000, lim = full > cur ? 0x7fffff00LL * cur / full : 0x7fffff00LL; if (want > lim) want = lim; + if ((int)want != cur) { int hp = gs(u, 6); long long nf = (long long)full * want / cur, nh = (long long)hp * want / cur; if (nh < 256) nh = 256; if (nh > nf) nh = nf; /* 当前生命同比例;nf = 写完后的合计 | current life in the same proportion; nf = the total after writing */ ss(u, 7, (int)want); ss(u, 6, (int)nh); - LOG("秘境:随从 id %u(宠物类型 %u,类号 %u)生命上限 %d → %lld(基数 %d,第 %d 层 ×%d.%02d)", id, ty, cls, cur >> 8, want >> 8, tb[k].base >> 8, K.tier, mult / 1000, mult % 1000 / 10); } + LOG("秘境:随从 id %u(宠物类型 %u,类号 %u)生命上限基础项 %d → %lld(基数 %d,第 %d 层 ×%d.%02d);合计 %d → %d", id, ty, cls, cur >> 8, want >> 8, tb[k].base >> 8, K.tier, mult / 1000, mult % 1000 / 10, full >> 8, gs(u, 7) >> 8); } tb[k].last = (int)want; if (tb[k].last != tb[k].base && nn < 16) { now[nn].cls = cls; now[nn].base = tb[k].base; now[nn].boosted = tb[k].last; nn++; } } } // 侧文件 = 现在放大着的 + 刚设回基数的。设回基数的记录不当场删,留到其后第 2 次存档提交:那一刻若正有一次存盘「已序列化、还没写盘」, @@ -486,7 +525,7 @@ static void pet_hp_pump(uint64_t G, uint64_t player, uint32_t t) { uint64_t gone = g_pf[i].gone ? g_pf[i].gone : cc + 1; if (cc >= gone + 1) continue; /* 设回之后已经提交过两次:记录可以没了 | two commits have happened since it was set back: the record can go */ nl[m].cls = g_pf[i].cls; nl[m].base = g_pf[i].base; nl[m].boosted = g_pf[i].boosted; nl[m].gone = gone; m++; } int same = m == g_pfn; for (int i = 0; same && i < m; i++) same = nl[i].cls == g_pf[i].cls && nl[i].base == g_pf[i].base && nl[i].boosted == g_pf[i].boosted && !nl[i].gone == !g_pf[i].gone; - if (!same) { g_pfn = m; for (int i = 0; i < m; i++) { g_pf[i].cls = nl[i].cls; g_pf[i].base = nl[i].base; g_pf[i].boosted = nl[i].boosted; g_pf[i].gone = nl[i].gone; } pet_file_save(); } } + if (!same || pf_dirty) { g_pfn = m; for (int i = 0; i < m; i++) { g_pf[i].cls = nl[i].cls; g_pf[i].base = nl[i].base; g_pf[i].boosted = nl[i].boosted; g_pf[i].gone = nl[i].gone; } pet_file_save(); } } if (dump && t % 125 == 0) LOG("秘境:随从读数 拍 %u(%s,第 %d 层,倍率 ×%d.%02d,侧文件 %d 条):%s", t, atomic_load(&K.st) == ST_RUN ? "秘境进行中" : "不在秘境", K.tier, mult / 1000, mult % 1000 / 10, g_pfn, lo ? line : " 没有随从"); } @@ -1044,9 +1083,13 @@ void dm_rift_tick(uint64_t G, uint64_t player, uint8_t *main_base) { { static int at = -1; if (at < 0) { const char *e = getenv("DM_RIFT_TEST_RESTART"); at = e ? atoi(e) : 0; } if (at > 0 && t >= (uint32_t)at) { at = 0; void dm_restart_request(void); LOG("秘境:测试 DM_RIFT_TEST_RESTART 拍 %u 请求一键重开", t); dm_restart_request(); } } // 测试:拍 N 替玩家一键重开 | Test: at tick N, do a one-tap restart on the player's behalf if (lv != LV_TOWN && atomic_load(&M.menu)) atomic_store(&M.menu, MENU_NONE); // 离城自动收起 | Closes automatically on leaving town { int tq = atomic_exchange(&M.req_start, 0); if (tq > 0 && lv == LV_TOWN && st != ST_RUN) { if (tq > R.unlock) tq = R.unlock; if (tq < 1) tq = 1; LOG("秘境:选层页开始第 %d 层", tq); L.next_door = L.town_door = 0; start_rift(G, player, t, tq); return; } } + { static int at = -1; if (at < 0) { const char *e = getenv("DM_RIFT_TEST_SAVE"); at = e ? atoi(e) : 0; } if (at > 0 && t >= (uint32_t)at) { at = 0; int dm_request_save(void); LOG("秘境:测试 DM_RIFT_TEST_SAVE 拍 %u 请游戏存盘 → %d", t, dm_request_save()); } } // 测试开关 DM_RIFT_TEST_SAVE=<拍>:到这一拍请游戏存一次盘(验放大着的随从生命进不进角色档) | test switch DM_RIFT_TEST_SAVE=: ask the game to save once at this tick (to check whether boosted minion life gets into the character save) + { static int at = -1; if (at < 0) { const char *e = getenv("DM_RIFT_TEST_ABANDON"); at = e ? atoi(e) : 0; } if (at > 0 && t >= (uint32_t)at && st == ST_RUN) { at = 0; LOG("秘境:测试 DM_RIFT_TEST_ABANDON 拍 %u 替玩家放弃本层", t); atomic_store(&M.req_abandon, 1); } } // 测试开关 DM_RIFT_TEST_ABANDON=<拍>:秘境进行中到这一拍替玩家放弃(裸宿主上点不了「放弃」) | test switch DM_RIFT_TEST_ABANDON=: during a rift run, abandon on the player's behalf at this tick ("Abandon" cannot be clicked on the bare host) if (atomic_exchange(&M.req_abandon, 0) && (st == ST_RUN || st == ST_DONE)) { // 放弃:本层作废(不涨层、不发奖),写回改过的表,回选层页 | Abandon: this level is void (no level increase, no rewards); write back the modified tables and return to the level selection page region_set(G, 0); if (K.players_old) dm_hud_request_players(K.players_old); K.guard = 0; L.next_door = L.town_door = 0; atomic_store(&K.st, ST_IDLE); st = ST_IDLE; - LOG("秘境:放弃第 %d 层", K.tier); atomic_store(&M.menu, MENU_SELECT); return; } + LOG("秘境:放弃第 %d 层", K.tier); atomic_store(&M.menu, MENU_SELECT); + pet_hp_pump(G, player, t); // 随从生命当拍设回基数,同结算处:放弃后回到选层页会走原版暂停,等下一拍的话要到玩家关掉面板才设回 | minion life is set back to base on this very tick, as at completion: after abandoning, returning to the level-selection page goes through the original's pause, and waiting for the next tick would delay it until the player closes the panel + return; } if (atomic_exchange(&M.req_cont, 0)) { // 继续:进行中 = 回到离开时的位置;本层已完成 = 回到守护者处(结算时人站的地方,两扇门就在旁边) | Continue: in progress = back to the position at the time of leaving; this level completed = back to the Guardian's spot (where the player stood at completion, with both portals right beside it) // 已完成后点「继续」就该回到战斗终止的地方(从那里捡东西、走红门去下一层);城门面板不提供「直接开下一层」 // After completion, tapping "Continue" should return to where the fight ended (pick things up there, take the red portal to the next level); the town diff --git a/dm/host/dm_world.c b/dm/host/dm_world.c index 6fa2df0..4ef143c 100644 --- a/dm/host/dm_world.c +++ b/dm/host/dm_world.c @@ -15,6 +15,7 @@ #include #include #include +#include static uint8_t *wb(void) { static uint8_t *b; if (!b) for (int i = 0; i < g_nmod; i++) if (!strcmp(g_mod[i].name, "main")) b = (uint8_t *)g_mod[i].base; return b; } static uint64_t w_player(void) { uint8_t *b = wb(); return b ? ((uint64_t (*)(uint32_t))(b + 0x45f9d0))(*(uint32_t *)(b + 0x2d20e4c)) : 0; } @@ -48,6 +49,14 @@ static int w_interact(uint64_t u) { // 就近交互:游戏的点击入口( // A waypoint (large footprint) appears at offset (3,4); an NPC at 4 cells comes and goes (he is walking, and it is gone again after the player stops). Stopped at 4 cells, tapping the target can interact (we call the click entry with the target), but after closing the dialog pressing the primary button does nothing // (Akara 4 cells 0/5, 2 cells 5/5). So always walk to within 2 cells before interacting; when 2 cells cannot be reached (the target itself occupies the cell, or it is blocked) and the player is already within W_FAR cells, interact in place #define W_FAR 4 +#if TARGET_OS_OSX +#define W_GROUND 99 // g_go.type 的特殊值:目标不是单位,是地面上的一格(Mac 鼠标点空地走过去;只有 macOS 宿主有) | special value of g_go.type: the target is not a unit but a tile on the ground (Mac mouse click-to-walk; macOS host only) +#define W_NEAREST_OK(t) ((t) == 2 || (t) == W_GROUND) +static int g_gnd_x, g_gnd_y; // 地面目标格 | ground target tile +static uint64_t g_gnd_stick_seen, g_gnd_stick_at; // 摇杆时间戳上次读到的值、它变化的时刻(本文件的时钟;那个时间戳是别的时钟记的,只能比变没变) | the last value read of the stick timestamp and the moment it changed (this file's clock; that timestamp is recorded by another clock, so only whether it changed can be compared) +#else +#define W_NEAREST_OK(t) ((t) == 2) +#endif static struct { uint32_t type, id; uint64_t until_ns, stick, next_fr, still_fr; int on, lx, ly; int n, i, tx, ty, replans, stop_at, empty, direct, alt, alt_on, ax, ay, nearest; uint16_t node[24][2]; } g_go; // stop_at > 0:只走到这么多格内就停、不交互(测试开关「走到怪旁」用) | stop_at > 0: only walk to within this many cells and stop, without interacting (used by the test switch "walk next to a monster") static uint64_t w_find(uint32_t type, uint32_t id) { uint8_t *b = wb(); return type <= 5 ? ((uint64_t (*)(uint64_t, uint32_t, uint32_t, uint32_t))(b + 0x45f5f0))((uint64_t)(uintptr_t)(b + 0x2d603a0 + type * 0x400), id & 0x7f, id, type) : 0; } static void w_go(uint64_t u) { uint64_t dm_stick_last_ns(void); g_go.type = *(uint32_t *)u; g_go.nearest = 0; g_go.id = *(uint32_t *)(u + 8); g_go.until_ns = w_now_ns() + 15000000000ull; g_go.stick = dm_stick_last_ns(); g_go.next_fr = 0; g_go.still_fr = 0; g_go.n = g_go.i = g_go.replans = g_go.empty = g_go.direct = g_go.alt = g_go.alt_on = 0; g_go.stop_at = 0; g_go.on = 1; } @@ -117,7 +126,7 @@ static int w_plan(uint8_t *b, uint64_t pl, int x, int y) { // 到了由 w_go_step 就地交互(只对物件)。原版手柄主钮在那个位置就能开这扇门(anc1–anc4:手指 8 下全是「找不到路,取消」,主钮 1 下开) // The target cell cannot be reached (the object itself and its surroundings are blocked: a closed gate, such as the one from Arreat Summit to the Worldstone Keep, where the nearest standable spot is 6 cells from it) and the reachable cells have all been searched: walk instead to "the reachable cell closest to it", // and on arrival w_go_step interacts in place (objects only). The original game's controller primary button opens this gate from that position (four regression cases: 8 finger taps were all 「找不到路,取消」(no route found, cancel), 1 press of the primary button opened it) - g_go.nearest = 0; if (goal < 0 && h >= t && best >= 0 && g_go.type == 2) { g_go.nearest = 1; if (best != syi * WP_W + sxi) goal = best; } + g_go.nearest = 0; if (goal < 0 && h >= t && best >= 0 && W_NEAREST_OK(g_go.type)) { g_go.nearest = 1; if (best != syi * WP_W + sxi) goal = best; } if (goal >= 0) { // 回溯成格子序列(复用 q 的尾部),再拉直成几段直线 | backtrack into a cell sequence (reusing the tail of q), then straighten it into a few straight segments int n = 0, c = goal; while (from[c] != 9 && n < WP_W * WP_W / 2) { q[WP_W * WP_W - 1 - n++] = (uint32_t)c; int d = from[c] - 1; c -= D[d][1] * WP_W + D[d][0]; } uint32_t *path = q + WP_W * WP_W - n; int ax = px, ay = py, k = 0; @@ -182,8 +191,51 @@ static int w_arrive(uint64_t pl, uint64_t u, int px, int py, int ox, int oy, con if (act != u) LOG("世界目标:出口砖 id %u 旁有把守它的物件 cls %u id %u(%d,%d,游戏自己选中的)→ 交互它", g_go.id, *(uint32_t *)(act + 4), *(uint32_t *)(act + 8), nx, ny); } g_go.on = 0; int r = w_interact(act); LOG("世界目标:类型 %u id %u %s(玩家 %d,%d 目标 %d,%d%s)→ 交互 %d", g_go.type, g_go.id, how, px, py, ox, oy, ok ? "" : ",四侧都进不了同一房间", r); return 1; } +#if TARGET_OS_OSX +// ---- Mac 鼠标:点空地走过去 ---- +// 触屏上「除摇杆外触点不触发点地移动」(见文件头)不变;这一段只给 Mac App 的鼠标用:键鼠玩家没有摇杆,点空地 = 走到那一点,按住 = 一直朝光标走(touch_mac.c 每隔几拍重发一次)。 +// 屏幕点 → 地面格:以玩家脚底的屏幕位置(游戏自己的投影)为原点,按等距投影反算——每「经典像素」合屏幕 k = 画面高 × 0.00206 像素(同上面物件占地菱形用的那个数), +// 一格沿 x 方向在屏幕上是右 16、下 8 经典像素,沿 y 方向是左 16、下 8:格差 dx = (横/16 + 纵/8) / 2、dy = (纵/8 − 横/16) / 2。画面有透视,离人越远偏得越多(验收时量)。 +// 走法复用上面的路线规划与逐段「跑到点」;到点 = 离目标格 1 格内;目标格站不了人(墙里、水里)= 走到能到的最近一格就停;原地 1 秒不动重算一次,再不动就停;15 秒没到停。 +// 摇杆(含键盘 W A S D)一动就让给摇杆:进行中的取消,0.3 秒内的新请求不受理。 +// ---- Mac mouse: click empty ground to walk there ---- +// On touch, "touches other than the stick do not trigger click-to-move" (see the file header) is unchanged; this section is only for the Mac App's mouse: keyboard-and-mouse players have no stick, so a click on empty ground = walk to that point, holding = keep walking towards the pointer (touch_mac.c re-sends every few ticks). +// Screen point -> ground tile: with the screen position of the player's feet (the game's own projection) as origin, back-compute through the isometric projection - each "classic pixel" is k = picture height x 0.00206 screen pixels (the same number used above for the footprint diamond of objects), +// one tile along x is 16 right and 8 down in classic pixels on screen, along y 16 left and 8 down: tile difference dx = (horizontal/16 + vertical/8) / 2, dy = (vertical/8 - horizontal/16) / 2. The picture has perspective, so the further from the character the larger the error (measured during acceptance). +// Walking reuses the route planning above and the segment-by-segment "run to point"; arrived = within 1 tile of the target tile; a target tile that cannot be stood on (inside a wall, in water) = walk to the nearest reachable tile and stop; no movement for 1 second: re-plan once, then stop if still not moving; stop after 15 seconds without arriving. +// As soon as the stick (including keyboard W A S D) moves, it yields to the stick: a walk in progress is cancelled and new requests within 0.3 s are not accepted. +static _Atomic uint64_t g_walk; +void dm_world_walk(float nx, float ny) { if (nx < 0) nx = 0; if (nx > 1) nx = 1; if (ny < 0) ny = 0; if (ny > 1) ny = 1; atomic_store(&g_walk, 1ull << 32 | (uint64_t)(uint32_t)(nx * 65535) << 16 | (uint32_t)(ny * 65535)); } // 任意线程:排一笔,主线程取手柄处执行;后一笔覆盖前一笔 | any thread: queue one request, executed where the main thread reads the gamepad; a later request overwrites an earlier one +int dm_world_walking(void) { return g_go.on && g_go.type == W_GROUND; } +static void w_ground_end(const char *how, int px, int py) { g_go.on = 0; static int lg; if (lg++ < 400) LOG("点地面走:%s(玩家 %d,%d 目标 %d,%d)", how, px, py, g_gnd_x, g_gnd_y); } +static void w_ground_step(uint8_t *b, uint64_t pl) { + uint64_t dm_stick_last_ns(void); uint32_t dm_cur_tick(void); int px = 0, py = 0; + if (!pl || !w_unit_xy(pl, &px, &py)) { g_go.on = 0; return; } + if (dm_stick_last_ns() != g_go.stick) { w_ground_end("取消(摇杆 / W A S D 动了)", px, py); return; } + if (w_now_ns() > g_go.until_ns) { w_ground_end("停下(15 秒没到)", px, py); return; } + int x = g_gnd_x, y = g_gnd_y, dx = abs(x - px), dy = abs(y - py); uint64_t f = dm_cur_tick(), fr = dm_guest_frame(); + if (dx <= 1 && dy <= 1) { w_ground_end("到点", px, py); return; } + if (px != g_go.lx || py != g_go.ly || !g_go.still_fr) { g_go.lx = px; g_go.ly = py; g_go.still_fr = f; } + else if (g_go.next_fr && f - g_go.still_fr > 25) { // 发过令而原地 1 秒没动 | an order was issued and it has not moved for 1 second + if (g_go.direct || g_go.replans++ >= 1) { w_ground_end(g_go.nearest ? "停在能到的最近处" : "停下(走不动了)", px, py); return; } + g_go.n = 0; g_go.next_fr = 0; g_go.still_fr = f; } + if (!g_go.direct && !g_go.n) { if (!w_plan(b, pl, x, y)) { w_ground_end("不走(找不到路)", px, py); return; } g_go.next_fr = 0; } + while (g_go.i < g_go.n && abs((int)g_go.node[g_go.i][0] - px) <= 1 && abs((int)g_go.node[g_go.i][1] - py) <= 1) { g_go.i++; g_go.next_fr = 0; } + int gx, gy; + if (g_go.i >= g_go.n) { // 路线走完:规划的终点在目标 2 格内,最后朝目标格直走一次;目标格本来就站不了人的到此为止 | route finished: the planned end point is within 2 tiles of the target, so walk straight to the target tile once at the end; if the target tile cannot be stood on, stop here + if (g_go.nearest || !wp_line(px, py, x, y)) { w_ground_end(g_go.nearest ? "停在能到的最近处" : "到点(目标格旁)", px, py); return; } + if (g_go.direct && fr < g_go.next_fr) return; g_go.direct = 1; gx = x; gy = y; } + else { gx = g_go.node[g_go.i][0]; gy = g_go.node[g_go.i][1]; } + if (fr < g_go.next_fr) return; g_go.next_fr = fr + 20; + atomic_store(&g_dm_move_allow_until_ns, w_now_ns() + 500000000ull); + ((void (*)(int, uint64_t, int, int))(b + 0x4ad870))(3, pl, gx, gy); +} +#endif static void w_go_step(void) { if (!g_go.on) return; uint64_t dm_stick_last_ns(void); uint8_t *b = wb(); uint64_t pl = w_player(), u = pl ? w_find(g_go.type, g_go.id) : 0; int px, py, x, y; +#if TARGET_OS_OSX + if (g_go.type == W_GROUND) { w_ground_step(b, pl); return; } +#endif const char *why = !u ? "目标没了" : w_now_ns() > g_go.until_ns ? "15 秒没到" : dm_stick_last_ns() != g_go.stick ? "摇杆动了" : !w_unit_xy(pl, &px, &py) || !w_unit_xy(u, &x, &y) ? "读不到坐标" : (g_go.type == 4 && *(uint32_t *)(u + 0xc) != 3) ? "物品已不在地上" : NULL; if (why) { g_go.on = 0; LOG("世界目标:类型 %u id %u 取消(%s)", g_go.type, g_go.id, why); return; } int ox = x, oy = y; if (g_go.alt_on) { x = g_go.ax; y = g_go.ay; } // 换侧时走向的是物件旁的那一点;ox / oy 仍是物件自己 | when switching sides the walk goes to the point beside the object; ox / oy are still the object itself @@ -313,6 +365,24 @@ unsigned dm_world_tap(float nx, float ny) { if (nx < 0) nx = 0; if (nx > 1) nx = unsigned seq = atomic_fetch_add(&g_tap_seq, 1) + 1; atomic_store(&g_tap, (uint64_t)seq << 32 | (uint64_t)(uint32_t)(nx * 65535) << 16 | (uint32_t)(ny * 65535)); return seq; } int dm_world_tap_result(unsigned seq) { return atomic_load(&g_tap_done) == seq ? atomic_load(&g_tap_res) : -1; } // -1 还没执行;0 没有目标(什么都没发);1 物品 2 NPC 3 物件 4 出口 | -1 not executed yet; 0 no target (nothing sent); 1 item 2 NPC 3 object 4 exit int dm_world_has_target(void) { return atomic_load(&g_has_target); } // 按主键会去交互的目标存在(游戏手柄版自己的选择,main+0x2f7a0c);任意线程读 | a target that the primary button would interact with exists (the game's own controller-version selection, main+0x2f7a0c); read from any thread +#if TARGET_OS_OSX +static void w_walk_step(uint8_t *b) { + uint64_t t = atomic_exchange(&g_walk, 0); if (!t) return; uint64_t dm_stick_last_ns(void); uint64_t pl = w_player(), scene = *(uint64_t *)(b + 0x2e2a698); int W = 0, H = 0, px = 0, py = 0; float f[2]; + dm_screen_real(&W, &H); if (!pl || !scene || W <= 0 || H <= 0 || !w_unit_xy(pl, &px, &py) || !w_project(b, scene, pl, f, 0)) return; + if (g_go.on && g_go.type != W_GROUND) return; // 正走向某个目标去交互:不打断 | walking towards some target to interact: do not interrupt + if (w_now_ns() - g_gnd_stick_at < 300000000ull) return; // 摇杆 / W A S D 0.3 秒内动过:让给它 | the stick / W A S D moved within 0.3 s: yield to it + float sx = ((t >> 16) & 0xffff) / 65535.0f * W, sy = (t & 0xffff) / 65535.0f * H, k = H * 0.00206f, a = (sx - f[0]) / k / 16, c = (sy - f[1]) / k / 8; + int x = px + (int)lroundf((a + c) / 2), y = py + (int)lroundf((c - a) / 2); + if (getenv("DM_TEST_WALK_CAL")) { static int n; if (n++ < 3) // 测试:把画面里各单位的脚底屏幕点按同一条公式反算成格,和它真实所在的格比(量换算误差) | test: back-compute the foot screen points of units on screen into tiles with the same formula and compare with the tiles they are really on (to measure the conversion error) + for (int ty = 1; ty <= 2; ty++) for (int kk = 0; kk < 128; kk++) for (uint64_t u = *(uint64_t *)(b + 0x2d603a0 + ty * 0x400 + kk * 8); u; u = *(uint64_t *)(u + 0x158)) { float g[2]; int ux, uy; + if (!w_unit_xy(u, &ux, &uy) || !w_project(b, scene, u, g, 0) || g[0] < 0 || g[1] < 0 || g[0] > W || g[1] > H) continue; float a2 = (g[0] - f[0]) / k / 16, c2 = (g[1] - f[1]) / k / 8; + LOG("点地面走:[校] 类型 %d cls %u 脚底 (%.0f,%.0f) 真格 %d,%d 反算 %d,%d 差 %d,%d(离人 %d,%d 格)", ty, *(uint32_t *)(u + 4), g[0], g[1], ux, uy, px + (int)lroundf((a2 + c2) / 2), py + (int)lroundf((c2 - a2) / 2), px + (int)lroundf((a2 + c2) / 2) - ux, py + (int)lroundf((c2 - a2) / 2) - uy, ux - px, uy - py); } } + if (g_go.on && abs(x - g_gnd_x) <= 1 && abs(y - g_gnd_y) <= 1) return; // 按住不动时重发的同一格:不重起 | the same tile re-sent while holding still: do not restart + static int lg; if (lg++ < 400) LOG("点地面走:点 (%.0f,%.0f),人脚底在 (%.0f,%.0f) → 格 %d,%d(玩家 %d,%d)", sx, sy, f[0], f[1], x, y, px, py); + g_go.type = W_GROUND; g_go.id = 0; g_go.nearest = 0; g_go.until_ns = w_now_ns() + 15000000000ull; g_go.stick = dm_stick_last_ns(); g_go.next_fr = 0; g_go.still_fr = 0; + g_go.n = g_go.i = g_go.replans = g_go.empty = g_go.direct = g_go.alt = g_go.alt_on = 0; g_go.stop_at = 0; g_gnd_x = x; g_gnd_y = y; g_go.on = 1; +} +#endif static void w_tap_step(uint8_t *b) { uint64_t t = atomic_exchange(&g_tap, 0); if (!t) return; unsigned seq = (unsigned)(t >> 32); int res = 0; int W = 0, H = 0; dm_screen_real(&W, &H); // 命中框按真实画面算,不能用游戏的「屏幕宽高」全局量(界面改成 16:9 后它的高是界面高,dm_uiscreen.c) | hit boxes are computed against the real picture, not the game's "screen width/height" globals (after the UI was changed to 16:9 its height is the UI height, dm_uiscreen.c) @@ -578,5 +648,9 @@ void dm_world_pump(void) { // 取手柄处每帧调 | Called every frame at th for (int k = 0; k < 128; k++) for (uint64_t c = *(uint64_t *)(b + 0x2d603a0 + gt * 0x400 + k * 8); c; c = *(uint64_t *)(c + 0x158)) if (*(uint32_t *)(c + 4) == (uint32_t)gi && w_unit_xy(c, &x, &y)) { long dd = (long)(x - px) * (x - px) + (long)(y - py) * (y - py); if (bd < 0 || dd < bd) { bd = dd; u = c; } } } if (u) { w_go(u); if (nearonly) g_go.stop_at = nearonly; } LOG("世界目标:DM_TEST_WORLD_GO %s → %s", e, u ? "已发" : "没找到"); if (u) LOG("世界目标:DM_TEST_WORLD_GO 目标 类型 %u 类号 %u id %u", *(uint32_t *)u, *(uint32_t *)(u + 4), *(uint32_t *)(u + 8)); } } w_tap_step(b); +#if TARGET_OS_OSX + { uint64_t dm_stick_last_ns(void); uint64_t v = dm_stick_last_ns(); if (v != g_gnd_stick_seen) { g_gnd_stick_seen = v; g_gnd_stick_at = w_now_ns(); } } + w_walk_step(b); +#endif { uint64_t pl = w_player(); atomic_store(&g_has_target, pl && ((uint64_t (*)(uint64_t, uint32_t))(b + 0x2f7a0c))(((uint64_t (*)(void))(b + 0x2acecc))(), *(uint32_t *)(b + 0x2d20e4c)) != 0); } } diff --git a/dm/host/front_mac.m b/dm/host/front_mac.m index 9638605..845ae92 100644 --- a/dm/host/front_mac.m +++ b/dm/host/front_mac.m @@ -98,6 +98,7 @@ static void on_key(NSEvent *e, int down) { unsigned short c = e.keyCode; switch (c) { case 13: g_w = down; break; case 0: g_a = down; break; case 1: g_s = down; break; case 2: g_d = down; break; } int b = key_bit(c); + if (down && (b >= 0 || c == 13 || c <= 2)) { void dm_padmode_request_kbd(int kbd); dm_padmode_request_kbd(1); } // 按了游戏用的键:键位图标换成键盘键帽(鼠标移动 / 点击不算) | a key used by the game was pressed: switch the key icons to keyboard key caps (mouse moves / clicks do not count) if (b >= 0) g_btn = down ? (g_btn | 1ull << b) : (g_btn & ~(1ull << b)); push(); } diff --git a/dm/host/tests/Makefile b/dm/host/tests/Makefile index da375cd..1d95137 100644 --- a/dm/host/tests/Makefile +++ b/dm/host/tests/Makefile @@ -4,7 +4,40 @@ DM_ROOT ?= $(HOME)/dm-work PY ?= $(DM_ROOT)/build/cache/dm/venv/bin/python EXEFS ?= $(DM_ROOT)/data/switch/3.3.94012/Update/ExeFS B = build -run: $(B)/t_thread_leak $(B)/t_rift_clock $(B)/t_textbox $(B)/t_rwlv $(B)/t_padmap $(B)/t_touch $(B)/t_hid_receipt $(B)/t_hid_script $(B)/t_touch_mac $(B)/t_oe $(B)/t_fs $(B)/t_fs_case $(B)/t_romfs_validate $(B)/t_audio $(B)/t_audio_spsc $(B)/t_swkbd $(B)/t_altstack $(B)/t_movie $(B)/t_condvar $(B)/t_condvar_old $(B)/t_target_rank $(B)/t_hud_dead $(B)/t_namegen $(B)/t_modetx $(B)/t_unit_level $(B)/t_widget $(B)/t_doorspot $(B)/t_cloudsync $(B)/t_i18n $(B)/main.orig.bin $(B)/subsdk0.orig.bin +# 依赖一行一个、按字母序(同 ../Makefile 的 SRC:免得加一个测试就整行冲突);下面各条命令的先后不变 +# Dependencies one per line in alphabetical order (same as SRC in ../Makefile: so that adding one test does not conflict on the whole line); the order of the commands below is unchanged +run: \ + $(B)/main.orig.bin \ + $(B)/subsdk0.orig.bin \ + $(B)/t_altstack \ + $(B)/t_audio \ + $(B)/t_audio_spsc \ + $(B)/t_cloudsync \ + $(B)/t_condvar \ + $(B)/t_condvar_old \ + $(B)/t_doorspot \ + $(B)/t_fs \ + $(B)/t_fs_case \ + $(B)/t_hid_receipt \ + $(B)/t_hid_script \ + $(B)/t_hud_dead \ + $(B)/t_i18n \ + $(B)/t_modetx \ + $(B)/t_movie \ + $(B)/t_namegen \ + $(B)/t_oe \ + $(B)/t_padmap \ + $(B)/t_rift_clock \ + $(B)/t_romfs_validate \ + $(B)/t_rwlv \ + $(B)/t_swkbd \ + $(B)/t_target_rank \ + $(B)/t_textbox \ + $(B)/t_thread_leak \ + $(B)/t_touch \ + $(B)/t_touch_mac \ + $(B)/t_unit_level \ + $(B)/t_widget python3 native_write_scan.py --selftest .. python3 mode_scan.py ../.. python3 ../../ios/tools/dm_i18n.py --check diff --git a/dm/host/tests/t_touch_mac.c b/dm/host/tests/t_touch_mac.c index 737fd29..d9fa316 100644 --- a/dm/host/tests/t_touch_mac.c +++ b/dm/host/tests/t_touch_mac.c @@ -10,6 +10,7 @@ uint64_t guest_ns(void) { return 0; } uint64_t dm_guest_frame(void) { return 0; } // 界面鼠标 / 前端路径按出图帧节拍走;本单测不测它们 | the UI mouse / front-end paths run on the presented-frame cadence; this unit test does not test them int dm_world_has_target(void) { return 1; } // 点世界(dm_world.c)的桩:有目标 = 主按钮照常发键 | stub for world tapping (dm_world.c): has a target = the primary button sends its key as usual unsigned dm_world_tap(float nx, float ny) { (void)nx; (void)ny; return 0; } +void dm_world_walk(float nx, float ny) { (void)nx; (void)ny; } int dm_world_tap_result(unsigned q) { (void)q; return -1; } uint64_t dm_padmode_legend_click(float nx, float ny) { (void)nx; (void)ny; return 0; } int dm_padmode_hud_click(float nx, float ny, uint64_t *b) { (void)nx; (void)ny; (void)b; return 0; } int dm_padmode_legend_has(uint32_t g) { (void)g; return 0; } int dm_game_paused(void) { return 0; } int dm_shop_open(void) { return 0; } // 商人页(dm_actions.c)的桩:没开 | stub for the vendor page (dm_actions.c): not open int dm_padmode_current(void) { return 0; } // 手柄 / 触屏模式(dm_padmode.c)的桩:触屏 | Stub for controller / touch mode (dm_padmode.c): touch diff --git a/dm/host/tests/t_touch_tick_stub.c b/dm/host/tests/t_touch_tick_stub.c index 07fe582..f4bfa84 100644 --- a/dm/host/tests/t_touch_tick_stub.c +++ b/dm/host/tests/t_touch_tick_stub.c @@ -7,6 +7,7 @@ int dm_loadscreen_down(void) { return 1; } // 读取画面判定在 diag.c; void dm_world_pump(void) {} int dm_world_has_target(void) { return 1; } unsigned dm_world_tap(float nx, float ny) { (void)nx; (void)ny; return 0; } +void dm_world_walk(float nx, float ny) { (void)nx; (void)ny; } int dm_world_tap_result(unsigned q) { (void)q; return -1; } void dm_textinput_pump(void) {} // 文本框接法(dm_textinput.c):同上,给空桩 | text box hookup (dm_textinput.c): same as above, an empty stub void dm_update_pump(void) {} // 选角页构建号与新版本提示(dm_update.c):同上,给空桩 | build number and new-version notice on the character select page (dm_update.c): same as above, an empty stub void dm_num_set(int n) { (void)n; } diff --git a/dm/host/touch_mac.c b/dm/host/touch_mac.c index 5427225..412a039 100644 --- a/dm/host/touch_mac.c +++ b/dm/host/touch_mac.c @@ -42,6 +42,7 @@ static struct { #include static uint32_t g_live_tick0; static int g_live_based; static uint64_t g_live_btn; static uint32_t g_live_btn_until; static struct { _Atomic unsigned head, tail; struct { int op; float nx, ny; } q[64]; } g_live; +static struct { int down; uint32_t t0, last; float x, y; unsigned tap_seq; float tap_x, tap_y; } g_lm; // 真鼠标左键在世界上的状态(点地面走用):按着没有、按下的拍、上次发「朝光标走」的拍、光标位置;等答案的那一笔点按 | state of the real mouse's left button on the world (for click-to-walk): whether it is down, the tick it went down, the tick "walk towards the pointer" was last sent, the pointer position; the click awaiting its answer void dm_touch_host_live(int op, float nx, float ny) { // 前端线程:op 0 按下 1 移动 2 抬起;坐标 = 游戏画面归一化 [0,1] | Front-end thread: op 0 down, 1 move, 2 up; coordinates = normalized to the game picture [0,1] if (!g_live_on) return; unsigned t = atomic_load(&g_live.tail); if (t - atomic_load(&g_live.head) >= 64) return; g_live.q[t % 64].op = op; g_live.q[t % 64].nx = nx; g_live.q[t % 64].ny = ny; atomic_store(&g_live.tail, t + 1); @@ -199,8 +200,19 @@ void dm_touch_host_step(uint64_t now, uint64_t *buttons, int32_t *lx, int32_t *l if (g_touch.next == g_touch.count) g_touch.next = g_touch.count = 0; // 表里的都处理完了:从头复用 | Everything in the table has been handled: reuse from the start if (g_touch.count >= 256) break; touch_event *e = &g_touch.event[g_touch.count++]; e->beat = 0; e->slot = 0; e->op = op == 0 ? TOUCH_DOWN : op == 1 ? TOUCH_MOVE : TOUCH_UP; e->x = px * 2868; e->y = py * 1320; + if (op == 0) { g_lm.down = 1; g_lm.t0 = touch_cur_tick(); g_lm.last = 0; } else if (op == 2) g_lm.down = 0; + g_lm.x = px; g_lm.y = py; atomic_store(&g_live.head, h + 1); } + // 点地面走(键鼠玩家没有摇杆)。点一下空地:世界点选答「没有目标」后改成走到那一点(下面等答案);按住不放:0.3 秒后起每 0.2 秒朝光标所在的地面点走一次, + // 光标挪到哪跟到哪,松手后走完最后那一段。只在局内、游戏没停、手势层没有面板开着、光标不在任何面板里时做。W A S D / 手柄摇杆在用时让给摇杆(dm_world.c) + // Click-to-walk (keyboard-and-mouse players have no stick). A click on empty ground: once the world pick answers "no target" it becomes walking to that point (the answer is awaited below); holding: after 0.3 s, walk towards the ground point under the pointer every 0.2 s, + // following the pointer wherever it moves, and finishing the last segment after release. Only in game, with the game not stopped, no panel open in the gesture layer and the pointer not inside any panel. While W A S D / the gamepad stick is in use it yields to the stick (dm_world.c) + { void dm_world_walk(float, float); int dm_world_tap_result(unsigned), dm_game_paused(void); uint32_t tk = touch_cur_tick(); + dm_tc_set_joy_block(&g_touch.state, 1); // 鼠标不起触屏那个浮动摇杆(左下那片按住拖动原先会变成推摇杆) | the mouse does not start the touch layout's floating stick (holding and dragging in the bottom-left area used to turn into pushing the stick) + if (g_lm.tap_seq) { int r = dm_world_tap_result(g_lm.tap_seq); if (r >= 0) { if (r == 0 && in && !dm_game_paused()) dm_world_walk(g_lm.tap_x, g_lm.tap_y); g_lm.tap_seq = 0; } } + if (g_lm.down && in && !g_touch.state.navigation_mode && !dm_game_paused() && (int32_t)(tk - g_lm.t0) >= 9 && (!g_lm.last || (int32_t)(tk - g_lm.last) >= 6) && dm_ui_item_at_now(g_lm.x, g_lm.y) != 0) { g_lm.last = tk; dm_world_walk(g_lm.x, g_lm.y); } + if (!in) g_lm.down = 0; } } if (g_live_btn) { if ((int32_t)(g_live_btn_until - touch_cur_tick()) > 0) *buttons |= g_live_btn; else g_live_btn = 0; } if (!g_touch.enabled || !g_touch.started) return; @@ -274,7 +286,8 @@ apply_input: if (g_touch.state.world_tap_seq != wt) { unsigned dm_world_tap(float, float); float wx = g_touch.state.world_tap_x / 2868, wy = g_touch.state.world_tap_y / 1320; // 真鼠标:手势层认为没有面板开着(它按名单认面板,大秘境选层页这类借壳的面板不在名单里),这一下却落在某个面板里 → 发界面点击,不当点世界 // Real mouse: the gesture layer believes no panel is open (it recognises panels by a list, and panels that borrow another shell, such as the Greater Rift level-selection page, are not on it), yet this click lands inside some panel -> send a UI click instead of a world click - if (g_live_on && dm_ui_item_at_now(wx, wy) == 0) { dm_ui_touch(0, wx, wy); dm_ui_touch(2, wx, wy); } else dm_world_tap(wx, wy); } + if (g_live_on && dm_ui_item_at_now(wx, wy) == 0) { dm_ui_touch(0, wx, wy); dm_ui_touch(2, wx, wy); } + else { unsigned q = dm_world_tap(wx, wy); if (g_live_on) { g_lm.tap_seq = q; g_lm.tap_x = wx; g_lm.tap_y = wy; } } } // 真鼠标:记下这一笔,答案是「没有目标」就改成走到那一点 | real mouse: remember this click, and if the answer is "no target" turn it into walking to that point if (g_touch.state.mouse_click_seq != mc) { float nx = g_touch.state.mouse_click_x / 2868, ny = g_touch.state.mouse_click_y / 1320; dm_ui_touch(0, nx, ny); dm_ui_touch(2, nx, ny); } } } diff --git a/dm/i18n/literal_whitelist.tsv b/dm/i18n/literal_whitelist.tsv index 3b468da..b9d1194 100644 --- a/dm/i18n/literal_whitelist.tsv +++ b/dm/i18n/literal_whitelist.tsv @@ -105,7 +105,7 @@ host/diag.c 容器 %u 页 %u 格 同上 host/dm_rift.c @merc_dump 佣兵装备位的测试读数(DM_TEST_MERC_DUMP),只进日志 host/dm_rift.c 部位 %u 模式 %u id %u 佣兵装备位的测试读数,只进日志 host/dm_rift.c [%.3s 部位 %u] 同上 -host/dm_rift.c [类型 %u 类号 %u id %u 等级 %d 生命上限 %d] 随从生命的测试读数(DM_RIFT_TEST_PETDUMP),只进日志 +host/dm_rift.c [类型 %u 类号 %u id %u 等级 %d 生命上限 %d(基础 %d)当前 %d] 随从生命的测试读数(DM_RIFT_TEST_PETDUMP),只进日志 host/dm_kills.c @DM_WIDGET_OK 控件类型核对的日志标签(dm_widget.h),不上屏 host/dm_custom.c @DM_WIDGET_OK 同上 host/dm_rift_ui.c @DM_WIDGET_OK 同上 diff --git a/dm/i18n/ui_text.tsv b/dm/i18n/ui_text.tsv index e5c2aa7..fd835b4 100644 --- a/dm/i18n/ui_text.tsv +++ b/dm/i18n/ui_text.tsv @@ -315,4 +315,4 @@ dmAppMenuView 显示 View Mac App 菜单栏(host/front_mac.m,下同) dmAppFullscreen 全屏 Toggle Full Screen 显示菜单的全屏项 dmAppMenuHelp 帮助 Help 帮助菜单 dmAppKeysTitle 键盘与手柄按键对照 Keyboard and Controller Buttons 帮助菜单的键位对照项,也是那一页的标题 -dmAppKeysText 界面上的按键提示是手柄字母,键盘这样对应:\n\n确认(A):空格 或 J  返回(B):Esc 或 K\n回车:确认;页面底部有「+」提示时是 +(如起名后的「接受」)\n+(菜单 / 新角色):= 键  −(地图):Tab\n移动:W A S D(左摇杆)  十字键:方向键\nX:U  Y:I  L:Q  R:E  ZL:Z  ZR:C\n按左摇杆:F  按右摇杆:G\n\n鼠标:左键点目标、界面、底部的按键提示和技能 / 药水格;右键 = 返回;滚轮滚列表。\n接上手柄可以直接用。这一页以后在「帮助」菜单里。 On-screen button hints use controller letters. Keyboard mapping:\n\nConfirm (A): Space or J Back (B): Esc or K\nReturn: confirm; acts as + when the page shows a + hint (e.g. Accept after naming)\n+ (menu / new character): = key − (map): Tab\nMove: W A S D (left stick) D-pad: arrow keys\nX: U Y: I L: Q R: E ZL: Z ZR: C\nPress left stick: F Press right stick: G\n\nMouse: left click targets, the interface, the button hints at the bottom and skill / potion slots; right click = back; wheel scrolls lists.\nA connected controller works right away. This page stays in the Help menu. 键位对照正文(首次启动弹一次) +dmAppKeysText 用键盘时,界面上的按键提示显示的就是键盘上的键;接上手柄按一下,提示换成手柄字母。\n\n确认:J(空格也可以)  返回:K(Esc 也可以)\n回车也可以确认;页面底部有「=」提示时回车当 =(如起名后的「接受」)\n=:菜单 / 新角色  Tab:地图\n移动:W A S D  十字键:方向键\nU I Q E Z C:手柄的 X Y L R ZL ZR\nF:按左摇杆  G:按右摇杆\n\n鼠标:左键点空地走过去,按住不放一直朝光标走;点目标、界面、底部的按键提示和技能 / 药水格;右键 = 返回;滚轮滚列表。\n接上手柄可以直接用。这一页以后在「帮助」菜单里。 With a keyboard, on-screen button hints show keyboard keys; press anything on a connected controller and they switch to controller letters.\n\nConfirm: J (Space also works) Back: K (Esc also works)\nReturn also confirms; acts as = when the page shows an = hint (e.g. Accept after naming)\n=: menu / new character Tab: map\nMove: W A S D D-pad: arrow keys\nU I Q E Z C: controller X Y L R ZL ZR\nF: press left stick G: press right stick\n\nMouse: left click the ground to walk there, hold to keep walking toward the cursor; click targets, the interface, the button hints at the bottom and skill / potion slots; right click = back; wheel scrolls lists.\nA connected controller works right away. This page stays in the Help menu. 键位对照正文(首次启动弹一次) diff --git a/dm/ios/Sources/dm_gamepad.m b/dm/ios/Sources/dm_gamepad.m index e16ac88..dfaa581 100644 --- a/dm/ios/Sources/dm_gamepad.m +++ b/dm/ios/Sources/dm_gamepad.m @@ -85,7 +85,11 @@ static void apply(void) { static int on[2]; static uint64_t prev_b; on[0] = stick_on(on[0], ax[0], ax[1]); on[1] = stick_on(on[1], ax[2], ax[3]); if (!on[0] && !on[1]) g_need_center = 0; // 碰过屏幕后摇杆回过中了:之后再推出来算数 | The stick has returned to center since the screen was touched: pushing it out again from now on counts - if ((b & ~prev_b) || ((on[0] || on[1]) && !g_need_center)) set_mode(1); + if ((b & ~prev_b) || ((on[0] || on[1]) && !g_need_center)) { set_mode(1); +#if TARGET_OS_OSX + { void dm_padmode_request_kbd(int kbd); dm_padmode_request_kbd(0); } // Mac App:实体手柄有输入,键位图标换回手柄键帽 | Mac App: a physical gamepad had input, switch the key icons back to gamepad key caps +#endif + } prev_b = b; if (!g_pad_mode || !on[0]) ax[0] = ax[1] = 0; if (!g_pad_mode || !on[1]) ax[2] = ax[3] = 0; // 触屏模式不交摇杆;手柄模式下没推出来的给 0 | Sticks are not delivered in touch mode; in controller mode a stick that is not pushed out gives 0 // ZR:原版六个技能格之一。这一格空着(没绑技能)时按它 = 免费回城(手柄玩家也免费回城,与触屏回城钮一致);绑了技能就整颗交还原版(不再整颗占用)。 diff --git a/dm/ios/tools/gen_romfs_overlay.py b/dm/ios/tools/gen_romfs_overlay.py index e94d489..a149308 100644 --- a/dm/ios/tools/gen_romfs_overlay.py +++ b/dm/ios/tools/gen_romfs_overlay.py @@ -47,6 +47,8 @@ with tempfile.TemporaryDirectory() as t: import merc_slots; REPL.update(merc_slots.build(romfs,t,REPL)) # 佣兵面板加六个装备位(底图 + 布局;要在 build_ingame 给它插关闭钮之后) | Add six equipment slots to the mercenary panel (base image + layout; must come after build_ingame has inserted the close button into it) REPL.update(touch_layout.build_cursor(romfs,t)) # 面板里的手柄光标圆环换成透明 | The controller cursor ring in panels replaced with a transparent one REPL.update(touch_layout.build_glyphs(romfs,t)) # 22 张手柄键图标换成透明 | 22 controller button icons replaced with transparent ones + if os.environ.get('DM_OVERLAY_MAC'): # Mac App:再出一套键盘键帽,放在触屏键帽同一个目录、文件名「<平台>k<名字>」(宿主 dm_padmode.c 的键盘键帽路径 Ztouch_controller_buttons_ui/%sK%s) | Mac App: additionally produce a set of keyboard key caps, placed in the same directory as the touch key caps with file names "k" (the keyboard key-cap path of the host's dm_padmode.c is Ztouch_controller_buttons_ui/%sK%s) + import kbd_glyphs; REPL.update({'data/hd/global/ui/ztouch_controller_buttons_ui/switchk'+os.path.basename(k):v for k,v in kbd_glyphs.build(romfs,t).items()}) REPL.update(touch_layout.build_profile(romfs,t)) # 大字号 | Large font size import touch_strings; ts,nts=touch_strings.build(romfs,t); REPL.update(ts) # 排版用的串(大字号);手柄说法 → 触摸说法改由宿主按模式换(旁路表 touch_strings.tsv,见 emit) | Strings used for typesetting (large font size); controller wording → touch wording is now switched by the host according to mode (sidecar table touch_strings.tsv, see emit) TS=touch_strings.build_sidecar(romfs) @@ -196,6 +198,7 @@ with tempfile.TemporaryDirectory() as t: for n in ('.build.config',new[0]): shutil.copyfile(os.path.join(src,n),os.path.join(dst,'data',n)) with open(os.path.join(dst,'touch_strings.tsv'),'w',encoding='utf-8') as f: # 键 \t 原文校验(SHA-1 前 8 位) \t 触摸说法(\\ \\n \\t 转义);宿主 dm_padmode.c 读 | key source checksum (first 8 hex digits of SHA-1) touch wording (backslash, newline and tab are escaped); read by the host's dm_padmode.c for k,o,v in TS: f.write('%s\t%s\t%s\n' % (k,o,v.replace('\\','\\\\').replace('\n','\\n').replace('\t','\\t'))) + if os.environ.get('DM_OVERLAY_MAC'): open(os.path.join(dst,'kbd_glyphs'),'w').write('ztouch_controller_buttons_ui/switchk*.sprite\n') # 标记文件:覆盖层带键盘键帽,宿主 dm_padmode.c 见到它才用 | marker file: the overlay carries keyboard key caps; the host's dm_padmode.c uses them only when it sees this open(os.path.join(dst,'ctrl_touch'),'w').write('触屏版布局在 layouts/xtouch_lay、ztouch_console_lay、0touch_console_switch_lay(dm_padmode.c 见到本文件才改写前缀)\n') return new[0], os.path.getsize(os.path.join(dst,'data',new[0])) n0,z0=emit(REPL,out,'') diff --git a/dm/ios/tools/kbd_glyphs.py b/dm/ios/tools/kbd_glyphs.py new file mode 100644 index 0000000..1287326 --- /dev/null +++ b/dm/ios/tools/kbd_glyphs.py @@ -0,0 +1,49 @@ +# Mac App 的键盘键帽:玩家用键盘时,按键提示条 / 技能格 / 页签两端画的手柄键图标换成对应的键盘键名(宿主 dm_padmode.c 把取图路径改到这一套)。 +# 22 张原版键帽(Controller/ControllerButtons/switch/,48×45)里有键盘对应键的那些各出一张同尺寸的:底板取原版肩键那块石板的配色(左缘一列 + 板面一列, +# 竖向拉到键盘键的高),键名用原版界面字体白字黑边;没有键盘对应键的(右摇杆、十字键、刷新小图标)原图不动。键位同 host/front_mac.m key_bit。 +# Keyboard key caps of the Mac App: when the player uses the keyboard, the gamepad button icons drawn on the key-hint bar / skill slots / ends of tab rows are replaced by the corresponding keyboard key names (the host's dm_padmode.c switches the image path to this set). +# Of the 22 original key caps (Controller/ControllerButtons/switch/, 48x45), each one with a keyboard counterpart gets an image of the same size: the plate takes the colours of the stone slab of the original shoulder button (one column from the left edge + one column of the face, +# stretched vertically to the height of a keyboard key), and the key name is in the original UI font, white with a black outline; those without a keyboard counterpart (right stick, D-pad, the small refresh icon) keep the original image. Key mapping as in host/front_mac.m key_bit. +import os, struct, sys +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +from PIL import Image, ImageDraw, ImageFont +import romfs_art, gen_widestash_art as GW + +DIR = 'data/hd/global/ui/Controller/ControllerButtons/switch/' +KEYS = {'ButtonRight': 'J', 'ButtonBottom': 'K', 'ButtonTop': 'U', 'ButtonLeft': 'I', 'BumperLeft': 'Q', 'BumperLeftRectangle': 'Q', 'BumperRight': 'E', 'BumperRightRectangle': 'E', + 'TriggerLeft': 'Z', 'TriggerRight': 'C', 'ButtonStart': '=', 'ButtonSelect': 'Tab', 'StickLeftButton': 'F', 'StickRightButton': 'G', 'StickLeft': 'WASD'} +ALL = 22 +S = 4 # 先按 4 倍画再缩回去:小图上的圆角与字边才平滑 | draw at 4x and scale back down: rounded corners and glyph edges are only smooth that way on a small image + +def _cap(plate, label, font): + """plate = 原版肩键图(取配色);返回 48×45 的键盘键帽。 | plate = the original shoulder-button image (for its colours); returns a 48x45 keyboard key cap.""" + w = 30 if len(label) == 1 else 44; x0 = (45 - w) // 2; y0, y1 = 9, 35; n = y1 - y0 + edge = [plate.getpixel((11, 16 + round(i * 13 / (n - 1)))) for i in range(n)]; face = [plate.getpixel((14, 16 + round(i * 13 / (n - 1)))) for i in range(n)] + im = Image.new('RGBA', (48, 45), (0, 0, 0, 0)) + for i in range(n): + for x in range(x0, x0 + w): im.putpixel((x, y0 + i), edge[i] if x in (x0, x0 + w - 1) else face[i]) + for x, y in ((x0, y0), (x0 + w - 1, y0), (x0, y1 - 1), (x0 + w - 1, y1 - 1)): im.putpixel((x, y), (0, 0, 0, 0)) # 四角各去一个像素 | remove one pixel at each of the four corners + big = Image.new('RGBA', (48 * S, 45 * S), (0, 0, 0, 0)); g = ImageDraw.Draw(big) + f = ImageFont.truetype(font, (19 if len(label) == 1 else 13 if len(label) == 3 else 10) * S); bb = g.textbbox((0, 0), label, font=f, stroke_width=S) + g.text(((x0 + w / 2) * S - (bb[0] + bb[2]) / 2, (y0 + n / 2 - .5) * S - (bb[1] + bb[3]) / 2), label, font=f, fill=(255, 255, 255, 255), stroke_width=S, stroke_fill=(16, 16, 18, 255)) + im.alpha_composite(big.resize((48, 45), Image.LANCZOS)) + return im + +def build(romfs, outdir): + """返回 {原版键帽逻辑路径(小写): 生成的贴图文件},22 张齐全(没有键盘对应键的是原图字节)。 | Returns {logical path of the original key cap (lower case): generated texture file}, all 22 present (those with no keyboard counterpart are the original image bytes).""" + L = GW.lib(); font = romfs_art.font(romfs, 'BlizzardGlobal-V5_81.ttf'); plate = romfs_art.sprite(romfs, DIR + 'BumperLeft.sprite'); repl = {} + for line in open(os.path.join(romfs, 'data', 'build_manifest.psv'), encoding='utf-8'): + f = line.rstrip('\n').split('|') + if len(f) < 11 or line.startswith('#') or '/ui/controller/controllerbuttons/switch/' not in f[9].lower(): continue + path = f[9].split(':', 1)[1]; name = os.path.basename(path)[:-len('.sprite')]; b = romfs_art.read(romfs, path); o = os.path.join(outdir, 'kbd_' + name + '.sprite') + if name in KEYS: + ver, fw, w, h = struct.unpack_from(' <输出目录>,另存一张放大的总览图 | preview: kbd_glyphs.py , which also saves an enlarged overview image + r = build(sys.argv[1], sys.argv[2]); L = GW.lib(); z = 6; sheet = Image.new('RGBA', (8 * 48 * z, 3 * 45 * z), (40, 40, 40, 255)) + for i, k in enumerate(sorted(r)): im = GW.decode(L, open(r[k], 'rb').read()); sheet.alpha_composite(im.resize((im.width * z, im.height * z), Image.NEAREST), ((i % 8) * 48 * z, (i // 8) * 45 * z)) + sheet.save(os.path.join(sys.argv[2], 'kbd_sheet.png')); print(len(r)) diff --git a/docs/MAC.md b/docs/MAC.md index 2da8d7b..6453d09 100644 --- a/docs/MAC.md +++ b/docs/MAC.md @@ -43,7 +43,7 @@ Language: the first launch follows the system language (Chinese systems start in ## Keyboard ↔ gamepad -Button prompts on screen show gamepad letters. Where the screen says "A", "B", "X" or "Y", the key to press is **not** the letter of the same name on the keyboard (the keyboard's A walks left) but the one in the right-hand column: +With a keyboard, the button prompts on screen (the hint bar at the bottom, skill slots, the ends of tab rows) show the keyboard keys directly: J K U I Q E Z C = Tab and so on; press a button on a connected gamepad and they switch back to gamepad letters. The full mapping: | What you want / gamepad button | Keyboard | |---|---| @@ -67,7 +67,9 @@ A gamepad works as soon as it is connected, alongside the keyboard. The menu bar What it can do now: -- **Click a target in the world** (monster, NPC, chest, waypoint, item on the ground): the character walks over and interacts. +- **Click empty ground to walk there**: a left click on empty ground walks the character to that point, finding its way around obstacles; a click inside a wall or water walks to the nearest reachable spot. +- **Hold to keep walking**: hold the left button and the character keeps walking towards the pointer, following it as it moves. W A S D / the gamepad stick take priority: press a direction key while walking and the keyboard takes over at once. +- **Click a target in the world** (NPC, chest, waypoint, item on the ground): the character walks over and interacts. With a panel open, a click outside it only closes the panel. - **Click the bottom row**: a skill icon = use that skill (the same as pressing the key shown under it), a potion cell = drink it, the middle button = open the inventory group of pages, the run / walk button = toggle. - **Click the interface**: buttons, checkboxes and tabs in panels (including the in-page tabs of the skill tree), the pause menu, the settings pages, "Start" on the rift level-selection page. - **Click a key hint at the bottom**: clicking an entry presses that key. @@ -77,8 +79,9 @@ What it can do now: What it cannot do yet: -- **Clicking empty ground does not walk.** Move with W A S D or a gamepad stick. -- **Key caps on screen are still gamepad letters**; translate them with the table above. +- **Clicking a monster does not attack**; attack with the skill keys (J K U I). +- Click-to-walk was verified only in the camp, on empty ground and the waypoint; complex terrain in the wild and clicking NPCs are unverified. +- Switching input device (keyboard ↔ gamepad) while the settings page or the stash is open: the prompts change only after the panel closes. - **Long press / double click / drag / buying on items do not take the mouse.** Use the keyboard or gamepad cursor: move the cursor onto the item with W A S D and press the key shown in the bottom bar. For example, buying from a vendor: cursor onto the goods (the bottom bar shows "A Buy") → press Space (or J) → press it again in the confirmation. - "Hold …" key hints need longer than a click, so hold the key on the keyboard; a hint with two key caps is not recognised. - The life orb, mana orb and experience bar do nothing when clicked. @@ -130,7 +133,8 @@ After a forced quit or a crash, the system's "reopen windows?" dialog no longer ## Known shortcomings - The five things from the top have not been operated by a person: keyboard keys, a physical gamepad, the resource-folder dialog, ⌘Q and menu clicks, how it feels in the hand. The key mapping was written from the key-code table. -- Clicking empty ground does not walk; key caps on screen are still gamepad letters; long press / double click / drag / buying on items do not take the mouse (see "Mouse" above). +- Clicking a monster does not attack; long press / double click / drag / buying on items do not take the mouse; click-to-walk was verified only in the camp (see "Mouse" above). +- "Prompts switch back to gamepad letters when a gamepad is used" was verified by simulation; no physical gamepad has been connected. - The free town portal on ZR + Space of a gamepad is not there. - The quest bar on the left in rifts is not there. - An App you build yourself has no iCloud save sync; there are no update checks and no sharing of the diagnostic log. diff --git a/docs/MAC.zh-CN.md b/docs/MAC.zh-CN.md index b33308e..e1b7fcc 100644 --- a/docs/MAC.zh-CN.md +++ b/docs/MAC.zh-CN.md @@ -43,7 +43,7 @@ DM_MAC_M3=1 dm/tools/mac_app.sh # macOS 15 – 25 ## 键盘 ↔ 手柄 -界面上的按键提示显示的是手柄字母。屏上写着「A」「B」「X」「Y」的地方,按的**不是**键盘上的同名字母(键盘的 A 是向左走),而是下表右边那一列: +用键盘时,屏上的按键提示(底部提示条、技能格、页签两端)直接显示键盘上的键:J K U I Q E Z C = Tab 等;接上手柄按一下,自动换回手柄字母。完整对应如下: | 要做的事 / 手柄键 | 键盘 | |---|---| @@ -67,7 +67,9 @@ DM_MAC_M3=1 dm/tools/mac_app.sh # macOS 15 – 25 现在能做的: -- **点世界里的目标**(怪、NPC、箱子、传送点、地上的物品):走过去交互。 +- **点空地走过去**:左键点一下空地,角色走到那一点,会自己绕开障碍;点在墙里、水里就走到能到的最近处。 +- **按住一直走**:左键按住不放,角色一直朝鼠标所在的地方走,鼠标挪到哪跟到哪。W A S D / 手柄摇杆优先:走着的时候按方向键,立刻听键盘的。 +- **点世界里的目标**(NPC、箱子、传送点、地上的物品):走过去交互。面板开着时点面板外只关面板。 - **点底部那一排**:技能图标 = 放那个技能(等于按它下面标的键),药水格 = 喝那格药,中间的钮 = 打开物品栏那组页面,跑 / 走钮 = 切换。 - **点界面**:面板里的按钮、勾选框、页签(含技能树页里的分页)、暂停菜单、设置页、秘境选层页的「开始」。 - **点底部的按键提示**:点哪一条,等于按那个键。 @@ -77,8 +79,9 @@ DM_MAC_M3=1 dm/tools/mac_app.sh # macOS 15 – 25 还不能的: -- **点空地不会走**。移动用 W A S D 或手柄摇杆。 -- **屏上的键帽仍是手柄字母**,照上面的表换成键盘键。 +- **点怪攻击没有**,攻击用技能键(J K U I)。 +- 点地走只在营地验过空地与小站;野外复杂地形、点 NPC 未经验证。 +- 设置页、储藏箱开着时换输入设备(键盘 ↔ 手柄),按键提示要等面板关掉才换。 - **物品的长按 / 双击 / 拖放 / 购买不认鼠标**,用键盘或手柄的光标操作:W A S D 把光标移到物品上,按底栏提示的键。例如在商人处买东西:光标移到货物上(底栏出现「A 购买」)→ 按空格(或 J)→ 确认框里再按一次。 - 「按住…」类的按键提示点一下不够长,用键盘按住;一条提示带两个键帽的不认。 - 血球、魔球、经验条点了没有反应。 @@ -130,7 +133,8 @@ DM_MAC_M3=1 dm/tools/mac_app.sh # macOS 15 – 25 ## 已知不足 - 开头说的五项未经真人操作:键盘按键、实体手柄、选资源文件夹的对话框、⌘Q 与菜单点击、真人手感。键位是照键码表写的。 -- 鼠标点空地不会走;屏上的键帽仍是手柄字母;物品的长按 / 双击 / 拖放 / 购买不认鼠标(见上面「鼠标」一节)。 +- 鼠标点怪攻击没有;物品的长按 / 双击 / 拖放 / 购买不认鼠标;点地走只在营地验过(见上面「鼠标」一节)。 +- 「接上手柄提示换回手柄字母」是模拟验的,实体手柄没接过。 - 手柄上 ZR 空格的免费回城没有。 - 秘境左侧的任务栏没有。 - 自己构建的 App 没有 iCloud 存档同步;没有更新检查和分享诊断日志。