Greater Rift minion life fix (#23); Mac click-to-walk and keyboard key names; older-API declaration de-duplication

This commit is contained in:
jhaizhou
2026-10-14 05:22:34 +08:00
parent d9e95c3381
commit feb2bb9fdc
22 changed files with 420 additions and 33 deletions
+57 -2
View File
@@ -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/)
+1 -1
View File
@@ -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." },
};
+58 -1
View File
@@ -44,6 +44,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <CommonCrypto/CommonDigest.h>
#include <TargetConditionals.h>
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 "<platform>K<name>"). 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=<frame>:<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; }
+52 -9
View File
@@ -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=<percent> (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=<tick>: 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=<tick>: 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
+75 -1
View File
@@ -15,6 +15,7 @@
#include <stdatomic.h>
#include <math.h>
#include <time.h>
#include <TargetConditionals.h>
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); }
}
+1
View File
@@ -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();
}
+34 -1
View File
@@ -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
+1
View File
@@ -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
+1
View File
@@ -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; }
+14 -1
View File
@@ -42,6 +42,7 @@ static struct {
#include <stdatomic.h>
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); }
}
}