Android port (Adreno): Vulkan backend, GameActivity app, touch HUD, lifecycle, minimap quest goals

- host/android: Vulkan replay backend (nvn_vk.c) with pipeline/descriptor caching, ADPF,
  AChoreographer present link; Linux compat layer; Makefile.android (headless dmhost + APK lib)
- android/app: GameActivity shell without Gradle (build_apk.sh), AAudio output, touch HUD port
  (touch_app.c + TouchOverlay.java, three layers: body / joystick / minimap goals),
  lifecycle save-on-background like iOS, art_from_ipa.py for touch / HUD / mapgoal art
- touch: shared touch controls moved from ios/Sources to dm/touch
- patch_nso.py Android ruleset, dmsh_vk.py shader pack, DM_TOUCH_PRODUCT defaults
- hle_audio: AAudio resume waits through STARTING and reopens once on failure
- .gitignore: local resources/ (original game data) never committed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-14 14:55:05 +09:00
co-authored by Claude Opus 5.5
parent 5bc5a01087
commit 4d91f80bae
106 changed files with 7009 additions and 181 deletions
-709
View File
@@ -1,709 +0,0 @@
#include "dm_touch_controls.h"
#include "../../host/dm_input.h"
#include <math.h>
#include <string.h>
#include <stdatomic.h>
#define DM_TC_POINTER_MOVE_PT 10.0f
#define DM_TC_POINTER_HOLD_S 0.5
#define DM_TC_POINTER_TAP_S 0.35
/* 控件缩放。手机(画面高 ≤ 440 点,最大的 iPhone 横屏就是 440):min(1, 宽/667, 高/375),与原来一字不差。
比手机高的画面(iPad 上居中的 16:9 那块,13 寸是 1366×768 点):按画面高度等比放大(高/440),否则摇杆与技能钮还是手机的点数大小,
在大画面里只剩一小簇(Mac 上按 iPad 尺寸出图所见),而底栏与游戏界面都是按画面高度缩放的。
这条放大只在前端显式打开时生效(dm_tc_set_tall_scale,front_ios.m 建视图时开):Mac 宿主的触屏用例通路(dm/host/touch_mac.c)是把像素数
(2868×1320)当点数传进来的,13 个用例的坐标按「缩放 = 1」写;不加这道开关,1320 > 440 会把它们的控件放大 3 倍、主钮挪位(skill_main 红)。
Widget scale. Phone (picture height ≤ 440 points; the largest iPhone in landscape is exactly 440): min(1, width/667, height/375), identical to before to the letter.
Pictures taller than the phone's (the centered 16:9 block on iPad; 13-inch is 1366×768 points): scale up proportionally by picture height (height/440), otherwise the stick and skill buttons keep the phone's point size
and are just a small cluster in the large picture (as seen when rendering at iPad size on Mac), while the bottom bar and the game UI both scale by picture height.
This enlargement takes effect only when the front end turns it on explicitly (dm_tc_set_tall_scale, turned on when front_ios.m creates the view): the Mac host's touch test-case path (dm/host/touch_mac.c) passes pixel counts
(2868×1320) in as points, and the coordinates of the 13 test cases are written for "scale = 1"; without this switch, 1320 > 440 would enlarge their widgets 3x and move the main button (skill_main red). */
static int g_tall_scale;
void dm_tc_set_tall_scale(int on) { g_tall_scale = !!on; }
float dm_tc_scale_for_size(float width, float height) { float k = fminf(1.0f, fminf(width / 667.0f, height / 375.0f)); return g_tall_scale && k >= 1.0f && height > 440.0f ? height / 440.0f : k; }
static float scale_for(const dm_tc_layout *l) { return dm_tc_scale_for_size(l->width, l->height); }
/* 安全区(iPhone 横屏左右各有一条让给灵动岛 / 圆角的区域,17 Pro Max 实读各 62 点):右侧技能键整组、左侧摇杆按最小位移平移到全部落在安全区内,
组内相对排布不变。岛在哪一侧取决于玩家怎么拿,两侧都内缩。缺省 0(Mac 宿主、单测不设 = 原布局)。
Safe area (in iPhone landscape there is a strip on each of the left and right yielded to the Dynamic Island / rounded corners; read as 62 points each on a 17 Pro Max): the whole right-side skill key group and the left stick are translated by the minimum displacement so that they lie entirely inside the safe area,
with the relative arrangement within the group unchanged. Which side the island is on depends on how the player holds the device, so both sides are inset. Default 0 (Mac host and unit tests do not set it = original layout). */
static float g_safe_l, g_safe_r;
/* 屏幕底边归系统的那一条(点):从这里起手往上划会被系统当成底边手势(iPad 上连着两次就拉出程序坞),而移动恰好是同一处反复起手往上推。
这一条里起手不当摇杆、松手也不当点地;从上面起手的摇杆拖进来照常持有。只有 iPad 的前端会给非零值,手机恒为 0。
The strip along the bottom edge of the screen that belongs to the system (points): a swipe up starting here is taken by the system as a bottom-edge gesture (on iPad two in a row pull out the Dock), and movement is exactly a repeated push upward starting from the same place.
A touch starting in this strip is not treated as the stick, and its release is not treated as a ground tap; a stick drag that started above and moves in keeps its hold as usual. Only the iPad front end passes a non-zero value; on phones it is always 0. */
static float g_edge_b;
void dm_tc_set_edge_bottom(float bottom) { g_edge_b = isfinite(bottom) && bottom > 0 ? bottom : 0; }
void dm_tc_set_safe_insets(float left, float right) { g_safe_l = isfinite(left) && left > 0 ? left : 0; g_safe_r = isfinite(right) && right > 0 ? right : 0; }
void dm_tc_layout_make(dm_tc_layout *l, float width, float height) {
memset(l, 0, sizeof(*l));
l->width = isfinite(width) && width > 0 ? width : 0;
l->height = isfinite(height) && height > 0 ? height : 0;
float k = scale_for(l);
float main_x = l->width - 56 * k, main_y = l->height - 82 * k;
{ float over = main_x + 40*k - (l->width - g_safe_r); if (over > 0) main_x -= over; } /* 右侧一组里最靠右的是主技能键(半径 40) | The rightmost one in the right-side group is the main skill key (radius 40) */
l->target[DM_TC_MAIN] = (dm_tc_target){ main_x, main_y, 40*k, DM_BTN_A };
/* 四分之一弧的单位向量:180°、150°、120°、90°。 | Unit vectors of the quarter arc: 180°, 150°, 120°, 90°. */
const float dx[4] = {-1, -0.8660254038f, -0.5f, 0};
const float dy[4] = {0, -0.5f, -0.8660254038f, -1};
const uint64_t skill[4] = {DM_BTN_B, DM_BTN_X, DM_BTN_Y, DM_BTN_R};
for (int i = 0; i < 4; ++i)
l->target[DM_TC_SKILL1+i] = (dm_tc_target){main_x+112*k*dx[i], main_y+112*k*dy[i], 26*k, skill[i]};
/* 底栏 = 底部 UI v4 六格(NativeHUD/v4,游戏 HUD 按屏高缩放、以屏幕中线居中,所以按屏高换算):
效果图 2868×1320 里格心 x = 1090 + 120×格号、y = 1241.5、格宽 114;第 0 格难度,1–4 腰带四列,5 功能入口(PLUS)。
回城不在底栏(离药水太近易误触):改为技能弧最上面那颗(技能四)正上方的圆钮,同半径、间距 12,点下由宿主施放原版回城技能(dm_freetp.c),不出按键。
Bottom bar = the six cells of bottom UI v4 (NativeHUD/v4; the game HUD scales by screen height and is centered on the screen centerline, so convert by screen height):
in the 2868×1320 mock, cell center x = 1090 + 120×cell index, y = 1241.5, cell width 114; cell 0 difficulty, 1–4 the four belt columns, 5 the function entry (PLUS).
Town portal is not in the bottom bar (too close to the potions, easy to hit by mistake): it is instead a round button directly above the topmost one on the skill arc (skill four), same radius, gap 12; on tap the host casts the original game's town portal skill (dm_freetp.c), with no key press. */
/* 腰带四列对十字键:左 = 第 1 列、上 = 第 2 列、下 = 第 3 列、右 = 第 4 列(原版实测:按「右」第 4 列减、按「下」第 3 列减;首版把后两个写反了,真机才撞到) | The four belt columns map to the D-pad: left = column 1, up = column 2, down = column 3, right = column 4 (measured in the original game: pressing "right" decrements column 4, pressing "down" decrements column 3; the first version had the last two swapped, which was only hit on a real device) */
const uint64_t bottom[5] = {DM_BTN_LEFT, DM_BTN_UP, DM_BTN_DOWN, DM_BTN_RIGHT, DM_BTN_PLUS};
const int cell[5] = {1, 2, 3, 4, 5};
float u = l->height / 1320.0f;
for (int i = 0; i < 5; ++i)
l->target[DM_TC_BELT1+i] = (dm_tc_target){l->width/2+(1090+120*cell[i]-1434)*u, 1241.5f*u, 57*u, bottom[i]};
{ const dm_tc_target *s4 = &l->target[DM_TC_SKILL4]; l->target[DM_TC_PORTAL] = (dm_tc_target){s4->x, s4->y-s4->r-12*k-26*k, 26*k, 0}; }
/* 第 0 格难度与选择条:选择条 8 格同格宽、格距 120,中线对齐两球中线(效果图 1390),格心 y = 1051.5(七格之上、避开数值文字) | Cell 0 difficulty and the selector bar: the selector bar has 8 cells of the same cell width, cell pitch 120, centerline aligned with the centerline between the two orbs (mock 1390), cell center y = 1051.5 (above the seven cells, clear of the value text) */
l->diff = (dm_tc_target){l->width/2+(1090-1434)*u, 1241.5f*u, 57*u, 0};
for (int i = 0; i < 8; ++i) l->pick[i] = (dm_tc_target){l->width/2+(1390+(i-3.5f)*120-1434)*u, 1051.5f*u, 57*u, 0};
l->target[DM_TC_MAP] = (dm_tc_target){l->width-30*k, 30*k, 22*k, DM_BTN_MINUS};
/* 技能组切换:主技能左下、技能一下方,避开主技能与弧上四键 | Skill set switch: lower-left of the main skill, below skill one, clear of the main skill and the four keys on the arc */
/* 位置与大小:技能一正下方,半径 22(直径 44 点 ≈ 7.3 毫米);上沿离技能一下沿 4 点、下沿离屏幕底 10 点(956×440) | Position and size: directly below skill one, radius 22 (diameter 44 points ≈ 7.3 mm); top edge 4 points from the bottom edge of skill one, bottom edge 10 points from the bottom of the screen (956×440) */
/* 比手机窄的画面(16:9:iPad 留边 / 真全屏的游戏视图、667×375)底栏按屏高缩放、右端雕像翼尖(效果图 x 2075)会伸到换组键底下:
键向右让到离翼尖 8 点以外,大小不变(量:1366×768 下原位重叠 21 点;956×440 下本来就隔着 28 点,不动)
On pictures narrower than the phone's (16:9: iPad letterboxed / true full-screen game view, 667×375) the bottom bar scales by screen height and the right-end statue wing tip (mock x 2075) would extend under the set-switch key:
the key moves right to at least 8 points away from the wing tip, size unchanged (measured: at 1366×768 the original position overlaps by 21 points; at 956×440 it is already 28 points apart and is not moved) */
{ float sx = main_x-112*k, bar_r = l->width/2+(2015-1434)*u+8*k+22*k; /* 右雕像翼尖:七格时 2075,六格石条右端收进 60 | Right statue wing tip: 2075 with seven cells; with six cells the right end of the stone bar is pulled in by 60 */ if (sx < bar_r) sx = bar_r;
l->swap = (dm_tc_target){sx, main_y+52*k, 22*k, 0}; }
/* 底栏外侧是血 / 蓝球;球不是输入目标。 | Outside the bottom bar are the life / mana orbs; the orbs are not input targets. */
/* 左摇杆是浮动底盘:左下「起摇杆区」里手指落在哪,底盘圆心就落在哪,松手回静止位。
静止位:圆心离安全区左界 90(底盘半径 60 + 30)、不小于 120,离屏幕底 115——只是没按时画在哪。
起摇杆区:屏宽的左 40% × 屏高的下 55%(左与下到屏幕边:拇指压在刘海那一条上也算);区里我们的圆钮 / 腰带格、原版界面上可点的东西各自优先。
夹回:落点贴边时圆心挪回来,整个底盘留在安全区左界以右、底盘下沿离屏幕底不少于 25(不撞系统横条)
The left stick is a floating base: wherever the finger lands inside the bottom-left "stick-start zone", the base centre goes there, and it returns to the rest position on release.
Rest position: centre 90 from the left edge of the safe area (base radius 60 + 30), not less than 120, and 115 from the bottom of the screen - only where it is drawn while not pressed.
Stick-start zone: the left 40% of the screen width x the lower 55% of the screen height (reaching the screen edges on the left and bottom: a thumb on the notch strip counts too); inside the zone our round buttons / belt cells and the clickable things of the original UI each take priority.
Clamping: when the touch point is near an edge the centre is moved back so that the whole base stays to the right of the safe area's left edge and its lower rim is at least 25 from the bottom of the screen (clear of the system bar) */
l->joy_radius = 60*k;
l->joy_x = fmaxf(90*k, g_safe_l + 60*k) + 30*k;
l->joy_y = l->height - 115*k;
l->joy_zone_r = l->width*0.40f; l->joy_zone_t = l->height*0.45f;
l->joy_min_x = g_safe_l + l->joy_radius; l->joy_max_y = l->height - 25*k - l->joy_radius;
}
int dm_tc_hit(const dm_tc_layout *l, float x, float y) {
if (!isfinite(x) || !isfinite(y) || x < 0 || y < 0 || x > l->width || y > l->height)
return DM_TC_NONE;
for (int i = 0; i < DM_TC_COUNT; ++i) {
const dm_tc_target *t = &l->target[i];
float dx = x-t->x, dy = y-t->y;
if (t->r > 0 && dx*dx+dy*dy <= t->r*t->r) return i;
}
float sx = x-l->swap.x, sy = y-l->swap.y;
if (l->swap.r > 0 && sx*sx+sy*sy <= l->swap.r*l->swap.r) return DM_TC_SWAP;
return DM_TC_NONE;
}
static int skill_target(int target) {
return target >= DM_TC_MAIN && target <= DM_TC_SKILL4;
}
/* 拖动方向(单位向量,屏幕坐标):拖动不过 10 点死区 = 没有方向 | Drag direction (unit vector, screen coordinates): a drag that does not pass the 10-point dead zone = no direction */
static int aim_dir(const dm_tc_state *s, const dm_tc_finger *f, float *ux, float *uy) {
float dx = f->x-f->aim_origin_x, dy = f->y-f->aim_origin_y, d = hypotf(dx, dy);
if (!(d > 10 * scale_for(&s->layout))) return 0;
*ux = dx/d; *uy = dy/d; return 1;
}
static int inside_map_cancel(const dm_tc_state *s, const dm_tc_finger *f) {
const dm_tc_target *map = &s->layout.target[DM_TC_MAP];
return map->r > 0 && fabsf(f->x-map->x) <= map->r && fabsf(f->y-map->y) <= map->r;
}
static int g_iso_fix = 1;
void dm_tc_set_iso_fix(int on) { g_iso_fix = !!on; }
static void update_aim(dm_tc_state *s) {
s->rx = s->ry = 0;
s->aim_slot = DM_TC_NONE;
s->map_cancel_active = 0;
if (s->navigation_mode) return;
uint64_t latest = 0;
for (int i = 0; i < DM_TC_MAX_TOUCH; ++i) {
const dm_tc_finger *f = &s->finger[i];
if (!f->active || !skill_target(f->target)) continue;
if (inside_map_cancel(s, f)) s->map_cancel_active = 1;
if (!f->aim_cancelled && f->aim_move_sequence > latest) {
latest = f->aim_move_sequence;
s->aim_slot = i;
}
}
if (s->pulse_button) { s->rx = s->pulse_rx; s->ry = s->pulse_ry; return; }
float radius = 60 * scale_for(&s->layout);
if (s->aim_slot == DM_TC_NONE || radius <= 0) return;
const dm_tc_finger *f = &s->finger[s->aim_slot];
if (f->target != DM_TC_MAIN && hypotf(f->x-f->aim_origin_x, f->y-f->aim_origin_y) <= 10 * scale_for(&s->layout)) return; /* 技能钮:拖动不过 10 点 = 点按,不给方向,原版自动选目标 | Skill button: a drag of no more than 10 points = tap, no direction given, the original game auto-targets */
float dx = (f->x-f->aim_origin_x)/radius;
float dy = (f->aim_origin_y-f->y)/radius;
s->rx = (int32_t)lroundf(fmaxf(-1, fminf(1, dx))*DM_STICK_MAX);
s->ry = (int32_t)lroundf(fmaxf(-1, fminf(1, dy))*DM_STICK_MAX);
}
static void update(dm_tc_state *s) {
s->buttons = 0;
for (int i = 0; i < DM_TC_MAX_TOUCH; ++i) {
dm_tc_finger *f = &s->finger[i];
if (f->active && !f->aim_cancelled && f->target >= 0 && f->target < DM_TC_COUNT) {
uint64_t b = f->target==DM_TC_PORTAL && s->portal_pending ? DM_BTN_ZL : s->layout.target[f->target].button;
/* 拖动定方向(核心手势)。技能钮:按下后先等 DM_TC_AIM_SETTLE_S 看是点按还是拖动——拖过死区就带着右轴方向立刻键下,
没拖到点也键下(点按 = 原版自动选目标 / 朝向);否则键先下、右轴后偏,按下那一发朝的是旧朝向。
主钮:按下即键下,不等(它是最高频的键,点按不该多等;按下就拖的第一发是原生朝向,第二发起跟手)。
按住期间方向再变由宿主的瞄准适配每拍重取,这里不做「松—按」;判定时间不为「按下稍停再拖」加长。
Drag to set direction (the core gesture). Skill button: after press, first wait DM_TC_AIM_SETTLE_S to see whether it is a tap or a drag -- once dragged past the dead zone, key down immediately with the right-axis direction,
and key down too if the time is reached without dragging (tap = the original game's auto target / facing); otherwise the key would go down first and the right axis deflect later, and the shot at press would aim at the old facing.
Main button: key down on press, no wait (it is the most frequent key and a tap should not wait longer; with press-then-drag the first shot uses the native facing, and from the second shot on it follows the finger).
Direction changes while held are re-read every tick by the host's aim adapter, so no "release-press" is done here; the decision time is not lengthened for "press, pause, then drag". */
if (!s->navigation_mode && f->target >= DM_TC_SKILL1 && f->target <= DM_TC_SKILL4) {
float ux, uy;
if (!f->key_down && !aim_dir(s, f, &ux, &uy) && s->last_time_s - f->start_time_s < DM_TC_AIM_SETTLE_S) b = 0;
else if (!f->key_down) { f->key_down = 1; f->key_down_s = s->last_time_s; }
}
/* 多排腰带:腰带格上滑 = 展开、下滑 = 收起,所以键不在按下时发;一律等松手那一刻按位移判(dm_tc_end_at)。不设「按住到点就喝」的计时:
手慢一点的上滑 / 下滑会先被它判成喝药(真机与 mini 各撞一次)。只有 1 排时照旧按下即喝
Multi-row belt: swiping up on a belt cell = expand, swiping down = collapse, so the key is not sent on press; always wait for the moment of release and decide by displacement (dm_tc_end_at). No "drink once held long enough" timer:
a slightly slow swipe up / down would first be judged by it as drinking a potion (hit once each on a real device and on the second Mac). With only 1 row, still drink on press as before */
/* 只有 1 排时也一律松手那一刻喝(和多排同一条路) | with only 1 row, also always drink at the moment of release (same path as multiple rows) */
if (!s->navigation_mode && f->target >= DM_TC_BELT1 && f->target <= DM_TC_BELT4) b = 0;
s->buttons |= b;
}
}
s->buttons |= s->pulse_button;
/* 第二套技能:ZL 是原版的换组修饰键。只在用技能的那一刻带上——手指按着主钮 / 技能钮、或技能脉冲在发(含等着发)时;
其余时候不按:一直按着会让十字(+)、腰带、回城都变成「ZL + 键」的组合(Ⅱ 态下十字开不了面板)。
ZL 先下、主钮的键晚 DM_TC_ZL_LEAD_S 再下(同一帧按下游戏只认主键 = 放成第一组的技能)。
Second skill set: ZL is the original game's set-switch modifier. It is added only at the moment a skill is used -- while a finger is on the main button / a skill button, or a skill pulse is being sent (including waiting to be sent);
it is not pressed the rest of the time: holding it all the time would turn the cross (+), the belt and town portal all into "ZL + key" combos (in state Ⅱ the cross could not open the panel).
ZL goes down first, and the main button's key goes down DM_TC_ZL_LEAD_S later (pressed in the same frame, the game only recognizes the main key = casts the first set's skill). */
if (s->skill_set && !s->navigation_mode) {
/* 在发的脉冲只有是技能键(主钮 / 技能钮补的那一下)才带 ZL:多排腰带松手补的喝药脉冲带上 ZL 就成了原版「ZL + 腰带键 = 喂佣兵」
(本机 实跑:第二组下点腰带,0x26 包目标字节 = 1、佣兵生命 642 → 762 涨、玩家不变)
The pulse being sent carries ZL only if it is a skill button (the make-up press of the main button / a skill button): a drink pulse made up on release of a multi-row belt, if it carried ZL, would become the original game's "ZL + belt key = feed the mercenary"
(actual run on the local machine: tapping the belt under the second set, 0x26 packet target byte = 1, mercenary life rose 642 → 762, player unchanged) */
/* 等着补发的技能也要 ZL 领先——但只在没有别的脉冲在发时:腰带脉冲在发时带上 ZL 同样成了「喂佣兵」(单测探针读到 0x1100) | A skill waiting for a make-up send also needs ZL to lead -- but only when no other pulse is being sent: adding ZL while a belt pulse is being sent likewise becomes "feed the mercenary" (the unit-test probe read 0x1100) */
int use = s->defer_button != 0 && !s->pulse_button;
for (int t = DM_TC_MAIN; t <= DM_TC_SKILL4 && !use; ++t) if (s->pulse_button && s->pulse_button == s->layout.target[t].button) use = 1;
/* 手指按着第二组技能时发「给玩家喝」的腰带脉冲:ZL 还按着就成了原版「ZL + 腰带键 = 喂佣兵」。ZL 和按着的技能键要一起让开
(只松 ZL 不松技能键 = 放成第一组的技能),而且要先让开、隔一段再按腰带键:同一拍里「松 ZL + 按腰带键」游戏仍按 ZL 还在算
(真局实测:发出的还是喂佣兵包——宿主取手柄处对按下沿做锁存,这一拍采到的是 ZL 与腰带键都在)。所以分三段:
等着发(belt_gap_cell)→ 脉冲在发 → 收回后 ZL 先回来、领先满 DM_TC_ZL_LEAD_S 技能键再回来(同一帧按下游戏只认主键)
The "drink for the player" belt pulse sent while a finger holds a skill of the second skill set: with ZL still held it becomes the original game's "ZL + belt key = feed the mercenary". ZL and the held skill key have to get out of the way together
(releasing only ZL and not the skill key = casting the first set's skill), and they have to get out of the way first, with the belt key pressed after a gap: with "release ZL + press belt key" in the same tick the game still counts ZL as held
(measured in a real run: what went out was still the feed-the-mercenary packet -- where the host fetches the controller it latches the press edge, and what was sampled this tick was both ZL and the belt key down). So there are three stages:
waiting to send (belt_gap_cell) → the pulse is being sent → after it is withdrawn ZL comes back first, and the skill key comes back once ZL has led by a full DM_TC_ZL_LEAD_S (pressed in the same frame, the game only recognizes the main key) */
int belt_pulse = s->belt_gap_cell != 0;
for (int t = DM_TC_BELT1; t <= DM_TC_BELT4; ++t) if (s->pulse_button && s->pulse_button == s->layout.target[t].button) belt_pulse = 1;
if (belt_pulse) s->belt_pulse_s = s->last_time_s;
for (int i = 0; i < DM_TC_MAX_TOUCH; ++i) {
const dm_tc_finger *f = &s->finger[i];
if (!f->active || f->aim_cancelled || f->target < DM_TC_MAIN || f->target > DM_TC_SKILL4) continue;
if (!belt_pulse) use = 1;
if (belt_pulse || s->last_time_s - f->start_time_s < DM_TC_ZL_LEAD_S || (s->belt_pulse_s > 0 && s->last_time_s - s->belt_pulse_s < DM_TC_ZL_LEAD_S)) s->buttons &= ~s->layout.target[f->target].button;
}
if (use) s->buttons |= DM_BTN_ZL;
}
update_aim(s);
s->lx = s->ly = 0;
if (s->joy_slot < 0) return;
dm_tc_finger *f = &s->finger[s->joy_slot];
float dx = f->x-s->joy_origin_x, dy = s->joy_origin_y-f->y;
/* 输入行程不跟大屏的视觉放大走:拇指不随屏幕变大。满偏 60 点、死区 6 点,手机与 iPad 一致
(原先乘视觉倍数,12.9 寸 iPad 要推 105 点 ≈ 20 mm 才满偏,是手机的两倍)。底盘和摇杆头的大小仍按视觉倍数画。
Input travel does not follow the visual enlargement on large screens: the thumb does not grow with the screen. Full deflection 60 points, dead zone 6 points, same on phone and iPad
(it used to be multiplied by the visual factor, so a 12.9-inch iPad needed a 105-point ≈ 20 mm push for full deflection, twice the phone's). The size of the base and the stick head is still drawn by the visual factor. */
float in_k = fminf(1.0f, scale_for(&s->layout));
float distance = hypotf(dx, dy), radius = 60 * in_k;
float dead = 6 * in_k;
if (distance <= dead || radius <= dead) return;
float strength = fminf(1, (distance-dead)/(radius-dead));
/* 斜向预修正:原版把摇杆做纯 45° 旋转成世界方向、不补偿等距画面的 2:1,人实际走的屏幕角 = atan(tan(摇杆角) / 2)(推 45° 走 26.6°)。
手柄玩家看不见摇杆和画面的对应,触屏上手指画的就是屏幕方向,所以送值前把纵向放大 2 倍再缩回原幅度:屏幕角 = 手指角,推多深不变。
只动游戏态的移动摇杆(导航态没有摇杆值;技能方向走右轴,不经这里)
Diagonal pre-correction: the original game turns the stick into a world direction by a pure 45° rotation and does not compensate for the 2:1 of the isometric view, so the screen angle the character actually walks = atan(tan(stick angle) / 2) (push 45°, walk 26.6°).
Controller players do not see the mapping between stick and picture, but on a touchscreen what the finger draws is the screen direction, so before sending the value the vertical component is doubled and then scaled back to the original magnitude: screen angle = finger angle, push depth unchanged.
Only the movement stick in game state is affected (navigation state has no stick value; skill direction goes through the right axis and does not pass here) */
float ex = dx/distance, ey = dy/distance;
if (g_iso_fix) { float n = hypotf(ex, 2*ey); ex /= n; ey = 2*ey/n; }
s->lx = (int32_t)lroundf(ex * strength * DM_STICK_MAX);
s->ly = (int32_t)lroundf(ey * strength * DM_STICK_MAX);
}
static int pointer_finger(const dm_tc_state *s, const dm_tc_finger *f) {
return s->navigation_mode && f->active && s->pointer_slot >= 0 &&
&s->finger[s->pointer_slot] == f;
}
static void update_pointer(dm_tc_state *s) {
if (!s->pointer_valid || s->pointer_slot < 0 || s->pointer_slot >= DM_TC_MAX_TOUCH) return;
dm_tc_finger *f = &s->finger[s->pointer_slot];
if (f->pointer_dragged && s->pointer_pickup_done && !f->shop_drag && !f->locked_drag) {
s->pointer_x = f->x;
s->pointer_y = f->y - DM_TC_POINTER_LIFT_PT * scale_for(&s->layout);
}
}
/* 指针脉冲(kind 1 = 拖放的拿起,2 = 放下 / 点按):指针先落到 (x,y) 再按 A。上一个脉冲还没收(游戏还没取走)时不动指针、只记下,
等前端在上一个收回且游戏已看到一次「A 松开」之后调 dm_tc_pulse_resume 才开始——否则两下 A 连成一下、或拿起落在放下的位置
Pointer pulse (kind 1 = pick-up of a drag-and-drop, 2 = put-down / tap): the pointer first lands at (x,y), then A is pressed. While the previous pulse has not been released (the game has not consumed it yet) the pointer is not moved and the request is only recorded,
and it starts only when the front end calls dm_tc_pulse_resume, after the previous one is released and the game has seen "A released" once -- otherwise two A presses merge into one, or the pick-up lands at the put-down position */
static void pointer_pulse_btn(dm_tc_state *s, float x, float y, int kind, uint64_t button, double hold_s) {
if (!s->pulse_button) {
s->pointer_x = x; s->pointer_y = y;
s->pulse_button = button;
s->pulse_hold_s = hold_s;
s->pulse_rx = s->pulse_ry = 0;
s->pointer_pulse_active = kind;
++s->pulse_epoch;
} else {
s->pointer_pulse_pending = kind;
s->pointer_pending_x = x;
s->pointer_pending_y = y;
s->pointer_pending_button = button; s->pointer_pending_hold = hold_s;
}
}
static void pointer_pulse_start(dm_tc_state *s, float x, float y, int kind) { pointer_pulse_btn(s, x, y, kind, DM_BTN_A, 0); }
void dm_tc_pointer_release(dm_tc_state *s, int kind) { s->pointer_release_item = kind == 1 || kind == 3 || kind == 4 || kind == 8 ? kind : 0; }
void dm_tc_pointer_release_at(dm_tc_state *s, float x, float y) { s->pointer_release_item = 5; s->release_x = x; s->release_y = y; }
void dm_tc_set_holding(dm_tc_state *s, int holding) { s->holding = !!holding; }
void dm_tc_pointer_item(dm_tc_state *s, int kind) {
if (kind == 7) { s->pointer_shop = 1; kind = 1; }
s->pointer_lock = kind == 10; if (kind == 10) kind = 1;
s->pointer_stack = kind == 8; if (kind == 8) kind = 1; /* 8 = 高级仓库的成叠格:照物品区,只有双击不同 | 8 = stacked cell of the advanced stash: follows the item area, only double tap differs */ /* 7 = 商人货架上的货:别的都照物品区,只有起拖不同 | 7 = goods on the vendor shelf: everything else follows the item area, only drag start differs */
s->pointer_item = (kind >= 1 && kind <= 3) || kind == 6 || kind == 11 ? kind : 0; /* 11 = 这一下不点(底下是被盖住的按钮),但可以起滚动手势(设置页列表里的文字 / 空处) | 11 = this tap does not click (a covered button is underneath), but it may start a scroll gesture (text / empty space in the settings page list) */
if (s->mouse_click_mode && s->pointer_slot >= 0 && s->pointer_slot < DM_TC_MAX_TOUCH && s->finger[s->pointer_slot].active && !s->finger[s->pointer_slot].pointer_dragged) {
if (kind == 1) { if (!s->pulse_button) { s->pointer_valid = 1; s->pointer_x = s->finger[s->pointer_slot].aim_origin_x; s->pointer_y = s->finger[s->pointer_slot].aim_origin_y; } }
else s->pointer_valid = 0; /* 不在物品区:放开手柄光标(前端据此清掉光标请求,不再推摇杆) | Not in the item area: release the controller cursor (based on this the front end clears the cursor request and stops pushing the stick) */
}
} /* 1 物品区 2 页签(点按不发键也不发鼠标,前端另调宿主切页) | 1 item area, 2 tab (a tap sends neither a key nor a mouse click; the front end separately calls the host to switch pages) */
static _Atomic int g_dead_modal;
static _Atomic int g_vendor_open; /* 商人交易页开着:ZL 是切货架页签,「再点同一处 = 比较」不发 | Vendor trade page open: ZL switches shelf tabs, so "tap the same spot again = compare" is not sent */
static _Atomic int g_close_stop; /* 「面板外点按 = 按返回到面板关掉」途中弹出了确认框(名字以 Modal 结尾的面板打开):后面的返回键不再按 | A confirmation box popped up (a panel whose name ends in Modal opened) in the middle of "tap outside the panel = press back until the panel closes": stop pressing the remaining back presses */
static _Atomic int g_tap_box; /* 最近一次单击的物品是魔盒(前端每拍从宿主同步) | The most recently single-tapped item is the cube (synced by the front end from the host every tick) */
void dm_tc_set_tap_box(int on) { atomic_store(&g_tap_box, on != 0); }
static _Atomic unsigned g_cur_stack;
void dm_tc_set_cur_stack(unsigned id) { atomic_store(&g_cur_stack, id); }
static _Atomic unsigned g_hover_unid;
void dm_tc_set_hover_unid(unsigned id) { atomic_store(&g_hover_unid, id); }
static _Atomic int g_imbue_open; /* 单件任务槽面板开着(灌魔 / 打孔 / 个性化 / 古墓底座,同一个 ImbueItemsPanel) | Single-item quest slot panel open (imbue / socket / personalize / tomb pedestal, all the same ImbueItemsPanel) */
static _Atomic int g_cube_open; /* 赫拉迪克方块页开着:双击 = 按住 Y(原版「移到另一侧」:背包 → 方块 / 方块 → 背包),不是「使用 / 装备」 | Horadric Cube page open: double tap = hold Y (the original game's "move to the other side": inventory → cube / cube → inventory), not "use / equip" */
static _Atomic int g_vault_open; /* 储藏箱开在第六页「编年史」:双击背包物品 = 存进编年史仓库(走 use_seq,宿主 ui_use_pump 判页),不发原版「按住 Y」——那一页游戏当魔盒页 | Stash open on page six 「编年史」(Chronicle): double-tapping an inventory item = store it in the Chronicle vault (goes through use_seq; the host's ui_use_pump determines the page); do not send the original game's "hold Y" -- the game treats that page as the cube page */
static _Atomic int g_bank_open; /* 储藏箱开着(前端从宿主读游戏面板树的结果设进来,不靠开关消息):双击 = 按住 Y(移到另一侧) | Stash open (set by the front end from the host's reading of the game panel tree, not from open/close messages): double tap = hold Y (move to the other side) */
void dm_tc_set_panel_state(int bits) { atomic_store(&g_bank_open, (bits & 1) != 0); atomic_store(&g_vendor_open, (bits & 2) != 0); atomic_store(&g_dead_modal, (bits & 4) != 0); atomic_store(&g_imbue_open, (bits & 16) != 0); atomic_store(&g_cube_open, (bits & 32) != 0); atomic_store(&g_vault_open, (bits & 64) != 0); } /* 位同 dm_cursor.h 的 DM_PS_*;宿主读游戏状态得来 | Bits are the same as DM_PS_* in dm_cursor.h; obtained by the host reading the game state */
static void pointer_drag_begin(dm_tc_state *s, dm_tc_finger *f) {
f->pointer_dragged = 1;
if (s->pointer_lock) { f->locked_drag = 1; return; } /* 单件槽占用时从别的物品上起拖:不拿起,这次拖动什么都不做 | Drag starting from another item while the single-item slot is occupied: do not pick up; this drag does nothing */
if (s->pointer_shop || s->pointer_stack) { f->shop_drag = 1; s->pointer_x = 2; s->pointer_y = 2; update(s); return; } /* 从货架上的货起拖:不拿起;光标挪到屏幕角上,让货上的说明框收掉(买的时候宿主再把光标放回这件货上) | Drag starting from goods on the shelf: do not pick up; move the cursor to a screen corner so the tooltip on the goods closes (at purchase time the host puts the cursor back on that item) */
s->pointer_pickup_done = 0;
pointer_pulse_start(s, f->aim_origin_x, f->aim_origin_y, 1);
}
void dm_tc_cancel_all(dm_tc_state *s) {
++s->gesture_epoch; s->portal_pending=s->portal_phase=0; s->diff_open=0;
memset(s->finger, 0, sizeof(s->finger));
for (int i = 0; i < DM_TC_MAX_TOUCH; ++i) s->finger[i].target = DM_TC_NONE;
s->joy_slot = DM_TC_NONE;
s->joy_origin_x = s->joy_origin_y = 0;
s->buttons = 0;
s->lx = s->ly = s->rx = s->ry = 0;
s->aim_slot = DM_TC_NONE;
s->aim_move_sequence = 0;
s->map_cancel_active = 0;
s->pulse_button = 0; s->pulse_rx = s->pulse_ry = 0;
s->belt_q = 0; s->belt_gap_cell = 0; /* 排着的、等着发的喝药一起作废 | queued and pending drinks are voided as well */ /* 等着判单双击的腰带格、等着发的喂雇佣兵一起作废 | The belt cell waiting for single/double tap decision and the pending mercenary feed are voided together */
s->defer_button = 0; /* 等着补发的那下技能也作废:原先取消后 0.2 秒照样放出来 | The skill press waiting for a make-up send is voided as well: previously it was still cast 0.2 seconds after the cancel */
s->pointer_slot = DM_TC_NONE;
s->pointer_valid = 0; s->pointer_x = s->pointer_y = 0;
s->pointer_pickup_done = 0;
s->pointer_pulse_active = s->pointer_pulse_pending = 0;
s->pointer_pending_x = s->pointer_pending_y = 0;
}
int dm_tc_pulse_end(dm_tc_state *s, uint64_t epoch) {
if (!s->pulse_button || s->pulse_epoch != epoch) return 0;
int ended_pointer = s->pointer_pulse_active;
if (s->defer_button && s->defer_at_s < s->last_time_s + DM_TC_ZL_LEAD_S) s->defer_at_s = s->last_time_s + DM_TC_ZL_LEAD_S; /* 等着补发的技能:从这一刻起 ZL 才能领先(见 dm_tc_tick) | Skill waiting for a make-up send: ZL can start leading only from this moment (see dm_tc_tick) */
s->pulse_button = 0; s->pulse_rx = s->pulse_ry = 0; s->pulse_hold_s = 0;
s->pointer_pulse_active = 0;
if (ended_pointer == 1) {
s->pointer_pickup_done = 1;
update_pointer(s);
}
update(s);
return 1;
}
int dm_tc_pulse_pending(const dm_tc_state *s) { return !s->pulse_button && s->pointer_pulse_pending; }
int dm_tc_pulse_resume(dm_tc_state *s) {
if (s->pulse_button || !s->pointer_pulse_pending) return 0;
int kind = s->pointer_pulse_pending;
s->pointer_pulse_pending = 0;
pointer_pulse_btn(s, s->pointer_pending_x, s->pointer_pending_y, kind, s->pointer_pending_button ? s->pointer_pending_button : DM_BTN_A, s->pointer_pending_hold);
s->pointer_pending_button = 0; s->pointer_pending_hold = 0;
update(s);
return 1;
}
void dm_tc_init(dm_tc_state *s, float width, float height) {
memset(s, 0, sizeof(*s));
s->pointer_release_item = 1;
dm_tc_layout_make(&s->layout, width, height);
s->enabled_targets = (1u << DM_TC_COUNT) - 1;
dm_tc_cancel_all(s);
}
void dm_tc_resize(dm_tc_state *s, float width, float height) {
uint64_t portal = s->layout.target[DM_TC_PORTAL].button;
dm_tc_cancel_all(s);
dm_tc_layout_make(&s->layout, width, height);
s->layout.target[DM_TC_PORTAL].button = portal;
}
void dm_tc_enable_targets(dm_tc_state *s, uint32_t mask) {
mask &= (1u << DM_TC_COUNT) - 1;
if (mask == s->enabled_targets) return;
dm_tc_cancel_all(s);
s->enabled_targets = mask;
}
void dm_tc_set_joy_block(dm_tc_state *s, int block) { s->joy_block = block != 0; }
void dm_tc_set_navigation_mode(dm_tc_state *s, int navigation_mode) {
navigation_mode = !!navigation_mode;
if (navigation_mode == s->navigation_mode) return;
dm_tc_cancel_all(s);
s->navigation_mode = navigation_mode;
}
/* 系统取消了这根手指(通知横幅、系统手势):不当松手——不补脉冲、不点世界、不点界面;只把它按着的键、摇杆、光标放掉 | The system cancelled this finger (notification banner, system gesture): do not treat it as a release -- no make-up pulse, no world tap, no UI click; only let go of the keys, stick and cursor it was holding */
void dm_tc_cancel_finger(dm_tc_state *s, int slot) {
if (slot < 0 || slot >= DM_TC_MAX_TOUCH) return;
++s->gesture_epoch;
if (s->finger[slot].active && s->finger[slot].target == DM_TC_PORTAL) { dm_tc_cancel_portal(s); }
if (slot == s->joy_slot && s->finger[slot].active) { s->joy_lost_s = s->last_time_s; s->joy_lost_x = s->finger[slot].x; s->joy_lost_y = s->finger[slot].y; s->joy_lost_ox = s->joy_origin_x; s->joy_lost_oy = s->joy_origin_y; } /* 系统取消了摇杆那根手指:记下,紧接着在附近重新落下的接着当摇杆 | the system cancelled the joystick finger: record it, and a finger landing again nearby right afterwards continues as the joystick */
s->finger[slot] = (dm_tc_finger){.target=DM_TC_NONE};
if (slot == s->joy_slot) { s->joy_slot = DM_TC_NONE; s->joy_origin_x = s->joy_origin_y = 0; }
if (slot == s->aim_slot) s->aim_slot = DM_TC_NONE;
if (slot == s->pointer_slot) { s->pointer_item = 0; s->pointer_shop = 0; s->pointer_stack = 0; s->pointer_lock = 0; s->pointer_slot = DM_TC_NONE; s->pointer_valid = 0; }
update(s);
}
void dm_tc_cancel_portal(dm_tc_state *s) {
++s->gesture_epoch; s->portal_pending=s->portal_phase=0;
for (int i=0;i<DM_TC_MAX_TOUCH;++i)
if(s->finger[i].active && s->finger[i].target==DM_TC_PORTAL)
s->finger[i]=(dm_tc_finger){.target=DM_TC_NONE};
update(s);
}
void dm_tc_set_portal_binding(dm_tc_state *s,uint64_t mask,uint64_t identity,uint64_t scene) {
if(s->layout.target[DM_TC_PORTAL].button==mask && s->portal_binding_identity==identity && s->portal_scene_epoch==scene)return;
dm_tc_cancel_portal(s);
s->portal_binding_identity=identity;s->portal_scene_epoch=scene;
s->layout.target[DM_TC_PORTAL].button=mask;update(s);
}
void dm_tc_set_portal_button(dm_tc_state *s,uint64_t mask) {
dm_tc_set_portal_binding(s,mask,s->portal_binding_identity,s->portal_scene_epoch);
}
int dm_tc_portal_ack(dm_tc_state *s,uint64_t epoch,uint64_t identity,uint64_t scene) {
if(!s->portal_pending || s->gesture_epoch!=epoch || s->portal_binding_identity!=identity || s->portal_scene_epoch!=scene)return 0;
int active=0;for(int i=0;i<DM_TC_MAX_TOUCH;i++)active|=s->finger[i].active && s->finger[i].target==DM_TC_PORTAL;
if(!active)return 0;
s->portal_pending=0;s->portal_phase=2;update(s);return 1;
}
/* 腰带展开着、这一点不在腰带上(底排四格与展开的几排之外):前端据此在自己的手势(小地图块、空位十字)之前先收腰带并吃掉这一下 | Belt expanded and this point is not on the belt (outside the four bottom-row cells and the expanded rows): based on this the front end collapses the belt and consumes this tap before its own gestures (minimap block, empty-slot cross) */
int dm_tc_belt_outside(const dm_tc_state *s, float x, float y) {
if (s->navigation_mode || !s->belt_open || s->belt_rows <= 1) return 0;
int hit = dm_tc_hit(&s->layout, x, y); if (hit >= DM_TC_BELT1 && hit <= DM_TC_BELT4) return 0;
float u = s->layout.height / 1320.0f;
for (int r = 1; r < s->belt_rows && r < 4; ++r) for (int c = 0; c < 4; ++c) {
const dm_tc_target *t = &s->layout.target[DM_TC_BELT1+c];
if (fabsf(x - t->x) <= 60*u && fabsf(y - (t->y - (165.0f + 162.0f*(r-1))*u)) <= 53.75f*u) return 0;
}
return 1;
}
/* 腰带点一下 = 自己喝,点几下喝几瓶(原版手感,不判双击)。底排 = 补一个腰带键脉冲(不带 ZL,第二组下也不带);上面几排手柄没有键 = belt_request 交宿主喝那一格。
喂雇佣兵不在腰带上做手势:佣兵面板里的原版入口和「自动给佣兵喝药」设置照旧
One tap on the belt = the player drinks, several taps drink several (original feel, no double-tap detection). Bottom row = one belt key pulse (without ZL, also under the second set); upper rows have no controller key = belt_request asks the host to drink that cell.
Feeding the mercenary has no gesture on the belt: the game's own entry in the mercenary panel and the "auto-feed mercenary" setting are unchanged */
static void belt_fire(dm_tc_state *s, int cell) {
if (cell >= 0x100) { s->belt_request = cell; return; }
uint64_t btn = s->layout.target[DM_TC_BELT1 + (cell & 0xf)].button; if (!btn) return;
if (s->pulse_button || s->defer_button || s->belt_gap_cell) { s->belt_q = cell; return; } /* 有脉冲在发 / 有补发在等:排着(dm_tc_tick 空了再发) | A pulse is being sent / a make-up send is waiting: queue it (dm_tc_tick sends it when free) */
if (s->skill_set && !s->navigation_mode) for (int i = 0; i < DM_TC_MAX_TOUCH; ++i) { /* 按着第二组技能:先松 ZL 和技能键,隔 DM_TC_ZL_LEAD_S 再按腰带键(见 update) | a skill of the second skill set is held: first release ZL and the skill key, and press the belt key after DM_TC_ZL_LEAD_S (see update) */
const dm_tc_finger *f = &s->finger[i]; if (!f->active || f->aim_cancelled || f->target < DM_TC_MAIN || f->target > DM_TC_SKILL4) continue;
s->belt_gap_cell = 0x1000 | cell; s->belt_gap_at = s->last_time_s + DM_TC_ZL_LEAD_S; update(s); return; }
s->pulse_rx = s->pulse_ry = 0; s->pulse_button = btn; ++s->pulse_epoch;
update(s);
}
void dm_tc_begin_at(dm_tc_state *s, int slot, float x, float y, double now_s) {
if (slot < 0 || slot >= DM_TC_MAX_TOUCH || s->finger[slot].active || !isfinite(x) || !isfinite(y)) return;
s->last_time_s = now_s;
dm_tc_finger *f = &s->finger[slot];
if (!s->navigation_mode) { /* 难度:点第 0 格开 / 收选择条;展开时点某格 = 选档并收起,点别处只收起、照常处理 | Difficulty: tapping cell 0 opens / collapses the selector bar; when expanded, tapping a cell = select that level and collapse; tapping elsewhere only collapses and is then handled as usual */
const dm_tc_target *d = &s->layout.diff;
int on_diff = d->r > 0 && hypotf(x-d->x, y-d->y) <= d->r, pick = -1;
for (int i = 0; s->diff_open && i < 8; ++i) if (hypotf(x-s->layout.pick[i].x, y-s->layout.pick[i].y) <= s->layout.pick[i].r) pick = i;
if (on_diff || pick >= 0) {
if (pick >= 0) s->diff_request = pick + 1;
s->diff_open = on_diff ? !s->diff_open : 0;
*f = (dm_tc_finger){.active=1, .target=DM_TC_DIFF, .x=x, .y=y}; update(s); return;
}
s->diff_open = 0;
}
int hit = dm_tc_hit(&s->layout, x, y);
if (!s->navigation_mode && s->belt_open && s->belt_rows > 1) { /* 腰带展开着:点上面几排 = 喝那一格;点腰带以外 = 只收起 | Belt expanded: tapping the upper rows = drink that cell; tapping outside the belt = only collapse */
float u = s->layout.height / 1320.0f; /* 展开的几排是游戏自己画的:列与底排对齐,排距 162、第一排比底排高 165(效果图单位;真机 2868×1320 实量,行距由 gen_hud_v4.py 的 bpy 定,改那边要一起改) | The expanded rows are drawn by the game itself: columns align with the bottom row, row pitch 162, the first row is 165 above the bottom row (mock units; measured on a real device at 2868×1320; the row spacing is set by bpy in gen_hud_v4.py, and changing it there requires changing it here too) */
for (int r = 1; r < s->belt_rows && r < 4; ++r) for (int c = 0; c < 4; ++c) {
const dm_tc_target *t = &s->layout.target[DM_TC_BELT1+c];
if (fabsf(x - t->x) <= 60*u && fabsf(y - (t->y - (165.0f + 162.0f*(r-1))*u)) <= 53.75f*u) {
belt_fire(s, 0x100 | r << 4 | c); /* 按下就喝那一格 | drink that cell on press */
*f = (dm_tc_finger){.active=1, .target=DM_TC_DIFF, .x=x, .y=y}; update(s); return;
}
}
if (hit < DM_TC_BELT1 || hit > DM_TC_BELT4) { /* 点别处:只收腰带,这一下不再做别的(不走路、不点世界、不按键) | Tap elsewhere: only collapse the belt; this tap does nothing else (no walking, no world tap, no key press) */
s->belt_request = 2; *f = (dm_tc_finger){.active=1, .target=DM_TC_DIFF, .x=x, .y=y}; update(s); return;
}
}
if (hit == DM_TC_SWAP) {
if (s->navigation_mode) hit = DM_TC_NONE;
else { s->skill_set = !s->skill_set; *f = (dm_tc_finger){.active=1, .target=DM_TC_SWAP, .x=x, .y=y}; update(s); return; }
}
int enabled = hit >= 0 && (s->enabled_targets & (1u << hit));
/* 面板态:被禁用的目标(底栏腰带 / 功能键 / 回城、圆钮收起后的技能钮位置)不占手指——它们压着的地方可能正是面板的按钮
(设置页「应用」在屏幕底部,落在禁用的底栏目标上,既不判类也不点击)。游戏态仍占着(防隐藏的回城触点变成摇杆)
Panel state: disabled targets (bottom-bar belt / function key / town portal, and the skill button positions after the round buttons are hidden) do not capture fingers -- the place they cover may be exactly a panel button
(「应用」(Apply) on the settings page is at the bottom of the screen and landed on a disabled bottom-bar target, getting neither classified nor clicked). In game state they still capture (preventing a hidden town-portal touch point from turning into the stick) */
if (s->navigation_mode && hit >= 0 && !enabled) hit = DM_TC_NONE;
if(enabled && hit==DM_TC_PORTAL && s->layout.target[hit].button && s->portal_phase==0) {
++s->gesture_epoch;
uint64_t mask=s->layout.target[hit].button;
s->portal_pending=(mask&DM_BTN_ZL) && (mask&~DM_BTN_ZL);
s->portal_phase=s->portal_pending?1:2;
}
*f = (dm_tc_finger){.active=1, .target=enabled ? hit : DM_TC_NONE, .x=x, .y=y,
.aim_origin_x=x, .aim_origin_y=y,
.start_time_s=now_s};
/* 禁用圆仍阻止落入左摇杆区,防止隐藏回城触点变成移动。 | A disabled circle still blocks falling through into the left stick area, preventing a hidden town-portal touch point from turning into movement. */
if (s->navigation_mode && hit == DM_TC_NONE && s->pointer_slot == DM_TC_NONE) {
s->pointer_slot = slot;
s->pointer_item = 0;
/* 鼠标点击模式下,手柄光标只跟「落在物品区的手指」走(前端答出命中后调 dm_tc_pointer_item):
光标是靠推摇杆走的,在没有自由光标的页面(选项、暂停菜单、小站)推摇杆 = 改当前选项 / 挪焦点(点页签顺带改了「显示物品」)
In mouse click mode the controller cursor follows only "a finger that landed in the item area" (the front end calls dm_tc_pointer_item once it has the hit answer):
the cursor moves by pushing the stick, and on pages without a free cursor (options, pause menu, waypoint) pushing the stick = changing the current option / moving the focus (tapping a tab changed 「显示物品」(Show Items) as a side effect) */
if (!s->mouse_click_mode) { s->pointer_valid = 1; s->pointer_x = x; s->pointer_y = y; }
} else if (!s->navigation_mode && hit == DM_TC_NONE && g_edge_b > 0 && x >= 0 && x < s->layout.width*0.43f && y > s->layout.height - g_edge_b) {
f->target = DM_TC_EDGE;
} else if (!s->navigation_mode && !s->joy_block && hit == DM_TC_NONE && s->joy_slot == DM_TC_NONE && x >= 0 && y <= s->layout.height &&
((x < s->layout.joy_zone_r && y > s->layout.joy_zone_t) ||
(x < s->layout.width*0.43f && y > s->layout.height*0.25f && s->joy_lost_s > 0 && now_s - s->joy_lost_s <= DM_TC_JOY_RESUME_S && hypotf(x - s->joy_lost_x, y - s->joy_lost_y) <= DM_TC_JOY_GRAB_K * s->layout.joy_radius))) {
/* 浮动底盘:落在起摇杆区里就起摇杆,底盘圆心 = 落点(贴边时夹回,见布局处),方向与幅度按「手指相对底盘圆心」算,按住后拖到多远都照样识别,
底盘不跟手走;落在区外照旧是点地。这一下若很快原地松开,仍兼作一次点击(dm_tc_end_at):区里的怪、掉落物、NPC 要点得到。
摇杆那根手指刚被系统取消(通知横幅、系统手势;dm_tc_cancel_finger 记下时刻与位置),DM_TC_JOY_RESUME_S 内在原处附近重新落下的手指接着当摇杆,
哪怕落点已拖出起摇杆区。只开着讲话文字框 / 对话菜单时不起摇杆(joy_block):夹回会让落点 ≠ 圆心、一落下就有方向,那一下只该关框
Floating base: a touch inside the stick-start zone starts the stick with the base centre = the touch point (clamped back near the edges, see the layout), direction and magnitude are computed from "finger relative to base centre", and once held, dragging any distance is still recognised;
the base does not follow the finger; a touch outside the zone is a ground tap as before. If this touch is released quickly in place it still doubles as a tap (dm_tc_end_at): monsters, dropped items and NPCs inside the zone must remain tappable.
When the stick finger has just been cancelled by the system (notification banner, system gesture; dm_tc_cancel_finger records the time and position), a finger touching down again near the same place within DM_TC_JOY_RESUME_S continues as the stick,
even if the touch point has been dragged out of the stick-start zone. The stick does not start while only a speech text box / dialogue menu is open (joy_block): clamping would make touch point != centre and give a direction the moment it lands, when that touch should only close the box */
int resume = s->joy_lost_s > 0 && now_s - s->joy_lost_s <= DM_TC_JOY_RESUME_S && hypotf(x - s->joy_lost_x, y - s->joy_lost_y) <= DM_TC_JOY_GRAB_K * s->layout.joy_radius;
s->joy_lost_s = 0;
f->target = DM_TC_JOYSTICK;
s->joy_slot = slot;
/* 接续的沿用取消前的圆心,不按新落点重定:触摸被系统反复打断又重来的机器上,每重来一次底盘就跳到手指当前位置,看着像底盘追着手指跑 | a continuation keeps the centre from before the cancel instead of re-centring on the new touch point: on devices where touches are repeatedly interrupted by the system and restarted, the base would jump to the finger's current position on every restart and look as if it were chasing the finger */
s->joy_origin_x = resume ? s->joy_lost_ox : fmaxf(x, s->layout.joy_min_x);
s->joy_origin_y = resume ? s->joy_lost_oy : fminf(y, s->layout.joy_max_y);
}
update(s);
}
void dm_tc_move_at(dm_tc_state *s, int slot, float x, float y, double now_s) {
if (slot < 0 || slot >= DM_TC_MAX_TOUCH || !s->finger[slot].active || !isfinite(x) || !isfinite(y)) return;
s->last_time_s = now_s;
dm_tc_finger *f = &s->finger[slot];
f->x = x;
f->y = y;
if (pointer_finger(s, f)) {
float distance = hypotf(f->x-f->aim_origin_x, f->y-f->aim_origin_y);
if (!f->pointer_dragged && distance > DM_TC_POINTER_MOVE_PT * scale_for(&s->layout) && (!s->mouse_click_mode || s->pointer_item == 1))
pointer_drag_begin(s, f); /* 鼠标点击模式:只有从物品区起手才是拖放;别处的滑动不发键。按住不动超过长按时长再拖也算拖放(真人「按住停一下再拖」,z4:0.5 秒后才动的拖放拿不起来) | Mouse click mode: only a gesture starting in the item area is a drag-and-drop; swipes elsewhere send no key. Holding still longer than the long-press duration and then dragging also counts as drag-and-drop (a real person "holds for a moment and then drags"; z4: a drag that started moving only after 0.5 seconds could not pick the item up) */
/* 起手在模态框外 / 被上层盖住(类 6 = 这一下不点)也不起滚动 / 滑块手势:原先模态框开着时框外上下滑照样给底下发滚轮 | A gesture starting outside the modal box / covered by an upper layer (class 6 = this tap does not click) does not start a scroll / slider gesture either: previously, with a modal box open, swiping up and down outside it still sent wheel events to what was underneath */
else if (s->mouse_click_mode && s->pointer_item != 1 && s->pointer_item != 3 && s->pointer_item != 6 && !f->ui_drag && !f->pointer_dragged && distance > DM_TC_POINTER_MOVE_PT * scale_for(&s->layout))
f->ui_drag = fabsf(f->x - f->aim_origin_x) > fabsf(f->y - f->aim_origin_y) ? 2 : 1; /* 界面连续手势:过阈值那一刻按方向定型(纵 = 滚动,横 = 滑块) | Continuous UI gesture: the type is fixed by direction at the moment the threshold is crossed (vertical = scroll, horizontal = slider) */
update_pointer(s);
} else if (!s->navigation_mode && skill_target(f->target)) {
if (inside_map_cancel(s, f)) f->aim_cancelled = 1;
if (!f->aim_cancelled) f->aim_move_sequence = ++s->aim_move_sequence;
}
update(s);
}
void dm_tc_end_at(dm_tc_state *s, int slot, double now_s) {
if (slot < 0 || slot >= DM_TC_MAX_TOUCH) return;
s->last_time_s = now_s;
if(s->finger[slot].active && s->finger[slot].target==DM_TC_PORTAL) {
s->finger[slot]=(dm_tc_finger){.target=DM_TC_NONE};
for(int i=0;i<DM_TC_MAX_TOUCH;i++)if(s->finger[i].active && s->finger[i].target==DM_TC_PORTAL) {update(s);return;}
dm_tc_cancel_portal(s);return;
}
dm_tc_finger done = s->finger[slot];
if (s->navigation_mode && slot == s->pointer_slot) {
float distance = hypotf(done.x-done.aim_origin_x, done.y-done.aim_origin_y);
double elapsed = now_s - done.start_time_s;
/* 商人货架上的货长按 = 原版的「按住 Y 大量购买」(提示条原文;宿主读数:约 1.3 秒):背包里有没满的卷轴书 / 同类叠时买满,没有就和买 1 份一样;买多少、钱够不够都由游戏定,这里只替玩家按键 | Long press on goods on the vendor shelf = the original game's 「按住 Y 大量购买」(Hold Y to buy in bulk) (button legend text; host reading: about 1.3 seconds): when the inventory has a non-full scroll tome / stack of the same kind it buys until full, otherwise it is the same as buying 1; how many to buy and whether there is enough gold are decided by the game, and here we only press the key for the player */
if (done.pointer_long && !done.pointer_dragged && !done.shop_drag && s->pointer_item == 1 && s->pointer_shop) pointer_pulse_btn(s, done.aim_origin_x, done.aim_origin_y, 2, DM_BTN_Y, 1.3);
else if (done.pointer_long && !done.pointer_dragged && !done.shop_drag && s->pointer_item == 1 && !s->pointer_lock) ++s->long_press_seq; /* 长按在松手时才算(按住没动):按住到点就算的话,「按住停一下再拖」的药水会先被放进腰带(mini 药拖腰带脚本里多出 2 次) | Long press counts only at release (held without moving): if it counted as soon as the hold time was reached, a potion that is "held for a moment and then dragged" would first be put into the belt (2 extra occurrences in the potion-drag-to-belt script on the second Mac) */
if (done.locked_drag) { } /* 单件槽占用时拖别的物品:不发任何键 | Dragging another item while the single-item slot is occupied: send no key */
else if (done.shop_drag) { ++s->shop_drop_seq; } /* 买不买由前端按落点定;这里不发任何键 | Whether to buy is decided by the front end from the drop point; no key is sent here */
else if (done.pointer_dragged) {
if (s->pointer_release_item == 1) pointer_pulse_start(s, done.x, done.y - DM_TC_POINTER_LIFT_PT * scale_for(&s->layout), 2); /* 放在抬起点(物品显示的位置) | Place at the lifted point (where the item is displayed) */
else if (s->pointer_release_item == 5) pointer_pulse_start(s, s->release_x, s->release_y, 2); /* 宿主给的放下位置(装备槽 = 槽心) | Drop position given by the host (equipment slot = slot center) */
else if (s->pointer_release_item == 4) pointer_pulse_start(s, done.x, done.y, 2); /* 放在手指点(玩家对着手指放) | Place at the finger point (the player aims with the finger) */
else if (s->pointer_release_item == 3) pointer_pulse_btn(s, done.aim_origin_x, done.aim_origin_y, 2, DM_BTN_Y, 0.15); /* 手指在面板外 = 丢弃:指针回原处、到位后按 Y | Finger outside the panel = discard: pointer returns to the original spot and presses Y once in place */
else if (s->pointer_release_item == 8) { /* 松在单件任务槽上:按原版走法重做——先放回原格,再对它按住 Y(原版的「放进槽」)。只把物品拿在手上停在槽上方不算进槽:槽会显示它,但点确认不成交(本机 实测没有成交包) | Released on the single-item quest slot: redo it the original game's way -- first put it back in its original cell, then hold Y on it (the original game's "put into slot"). Merely holding the item and hovering over the slot does not count as entering the slot: the slot shows it, but tapping confirm does not complete the transaction (measured on the local machine: no transaction packet) */
pointer_pulse_start(s, done.aim_origin_x, done.aim_origin_y, 2); pointer_pulse_btn(s, done.aim_origin_x, done.aim_origin_y, 2, DM_BTN_Y, 1.3); }
else pointer_pulse_start(s, done.aim_origin_x, done.aim_origin_y, 2); /* 面板里的空白处:放回原处 | Blank area inside the panel: put it back where it was */
} else if (!done.ui_drag && !done.pointer_long && elapsed < DM_TC_POINTER_TAP_S && distance <= DM_TC_POINTER_MOVE_PT * scale_for(&s->layout)) { /* 拖出去又拖回原处不算点按 | Dragging out and back to the original spot does not count as a tap */
/* 单件任务槽面板开着时,手上那件就是「槽里那件」:点背包格仍是放回去,点别处按没拿着处理——确认 / 关闭按钮要能点,点面板外 = 关面板(不是把槽里那件丢到地上) | While the single-item quest slot panel is open, the held item is "the one in the slot": tapping an inventory cell still puts it back, tapping elsewhere is handled as if nothing were held -- the confirm / close buttons must be tappable, and tapping outside the panel = close the panel (not drop the slot's item on the ground) */
if (s->pointer_lock) { s->pointer_x = done.aim_origin_x; s->pointer_y = done.aim_origin_y; } /* 单件槽占用时点别的物品:只移光标出说明,单击 / 双击都不动它 | Tapping another item while the single-item slot is occupied: only move the cursor to show the tooltip; neither single nor double tap moves it */
else if (s->holding && s->pointer_item != 0 && !(atomic_load(&g_imbue_open) && s->pointer_item != 1)) { if (s->pointer_item == 1) pointer_pulse_start(s, done.aim_origin_x, done.aim_origin_y, 2);
else if (s->pointer_item == 3) pointer_pulse_btn(s, s->pointer_x, s->pointer_y, 2, DM_BTN_Y, 0.15); } /* 手上还拿着物品(上次没放成):点物品区 = 放下;点面板外 / 两侧黑网格 = 丢(Y);点页签等别处不动。
点按钮(类 0)不在这里吞掉、照常发鼠标点击:原先连合成钮也吞,手上有东西时点合成什么都不发;合成钮由宿主先收手上那件再按,见 dm_cursor.c
Still holding an item (the last drop did not succeed): tap the item area = put down; tap outside the panel / the black grid on either side = drop (Y); tapping tabs or elsewhere does nothing.
Tapping a button (class 0) is not swallowed here and sends a mouse click as usual: previously even the transmute button was swallowed, and tapping transmute with something in hand sent nothing; for the transmute button the host first stows the held item and then presses, see dm_cursor.c */
else if (s->pointer_item == 2) { ++s->tab_tap_seq; }
else if (s->pointer_item == 6 || s->pointer_item == 11) { } /* 压着被上层面板盖住的按钮:不点、不发键 | Pressing on a button covered by an upper panel: no click, no key */
else if (s->pointer_item == 3) { if (!atomic_load(&g_dead_modal)) { s->close_left = 3; s->close_next_s = now_s; atomic_store(&g_close_stop, 0); } } /* 面板外:不发鼠标点击(会落到游戏世界 = 点地走路),按 B 关面板——子菜单里一下 B 只退一级,所以按到面板关掉为止(至多 3 下,见 dm_tc_tick);死亡弹窗开着时不动 | Outside the panel: do not send a mouse click (it would land in the game world = tap ground to walk); press B to close the panel -- in a submenu one B only goes back one level, so press until the panel is closed (at most 3 presses, see dm_tc_tick); do nothing while the death popup is open */
else if (s->pointer_item) { /* 物品区:单击只移光标(游戏自己出说明);紧接着在同一处再点一下 = 按住 A / Y | Item area: a single tap only moves the cursor (the game shows the tooltip itself); another tap at the same spot right after = hold A / Y */
float ox = done.aim_origin_x, oy = done.aim_origin_y;
int dbl = now_s - s->last_tap_s < DM_TC_DOUBLE_TAP_S && hypotf(ox - s->last_tap_x, oy - s->last_tap_y) <= 2 * DM_TC_POINTER_MOVE_PT * scale_for(&s->layout);
if (dbl) { if (atomic_load(&g_hover_unid) && !s->pointer_stack && !s->pointer_shop) ++s->ident_seq; /* 未鉴定物品:双击 = 免费鉴定(各页都先判;商人货架上的货不算我方物品,宿主也不发布) | Unidentified item: double tap = free identify (checked first on every page; goods on the vendor shelf are not our items, and the host does not publish them either) */
else if (s->pointer_stack) ++s->stack_take_seq; /* 成叠格:取 1 件(原版短按 Y;这里不按键,按住 0.6 秒会变成「移动 3 个」) | Stacked cell: take 1 (short press Y in the original game; no key is pressed here, since holding for 0.6 seconds would become "move 3") */
else if (atomic_load(&g_imbue_open)) pointer_pulse_btn(s, ox, oy, 2, DM_BTN_Y, 1.3); /* 单件任务槽面板:原版对背包物品按住 Y = 放进槽(宿主读数:约 1.3 秒);不能当「使用」——否则在古墓底座前双击法杖会被装到手上 | Single-item quest slot panel: in the original game holding Y on an inventory item = put it into the slot (host reading: about 1.3 seconds); it must not be treated as "use" -- otherwise double-tapping the staff in front of the tomb pedestal would equip it in hand */
else if (atomic_load(&g_bank_open) && !atomic_load(&g_tap_box) && !atomic_load(&g_vault_open)) {
/* 背包里的物品:先发原版的 X(移动到堆叠栏)。能堆叠的(符文 / 宝石 / 材料)游戏收下、进堆叠格;不能堆叠的游戏对 X 不做任何事,0.4 秒后它还在光标下就退回按住 Y。
不直接按住 Y:那是「到仓库当前这一页」,在符文 / 宝石页且背包带着魔盒时会进页里嵌的魔盒格。仓库一侧的物品不走这里,仍是按住 Y 取回
Item in the inventory: first send the original game's X (move to the stacking tab). Stackable ones (runes / gems / materials) are accepted by the game and go into a stack cell; for non-stackable ones the game does nothing on X, and if it is still under the cursor after 0.4 seconds, fall back to hold Y.
Do not hold Y directly: that means "to the stash's current page", and on the rune / gem page with a cube in the inventory it would go into the cube cell embedded in the page. Items on the stash side do not go through here; they are still retrieved by holding Y */
if (atomic_load(&g_cur_stack)) { pointer_pulse_btn(s, ox, oy, 2, DM_BTN_X, 0.15); s->stash_x_check_s = now_s + 0.4; s->stash_x_x = ox; s->stash_x_y = oy; s->stash_x_id = atomic_load(&g_cur_stack); }
else pointer_pulse_btn(s, ox, oy, 2, DM_BTN_Y, DM_TC_HOLD_USE_S); }
else if (atomic_load(&g_cube_open) && !atomic_load(&g_bank_open)) pointer_pulse_btn(s, ox, oy, 2, DM_BTN_Y, DM_TC_HOLD_USE_S); /* 方块页(不是箱子里嵌的那格):原版按住 Y 一步送进 / 送出方块;与箱子页双击同一条规则 | Cube page (not the cell embedded in the stash): in the original game holding Y sends the item into / out of the cube in one step; same rule as double tap on the stash page */
else ++s->use_seq; /* 开着箱子:按住 Y = 移到另一侧(魔盒除外:原版开箱时按住 A 仍是打开魔盒,读码);否则交给宿主当场使用(原先按住 A 0.6 秒,约 0.4 秒后才生效) | Stash open: hold Y = move to the other side (except the cube: in the original game holding A with the stash open still opens the cube, per the code); otherwise hand it to the host to use on the spot (it used to hold A for 0.6 seconds and took effect only after about 0.4 seconds) */
s->last_tap_s = -1e9; }
else { /* 单击:移光标。隔了一会儿(不算双击)又点同一处 = 与另一件已装备的比较(原版按 ZL 循环;说明框文案「再点一次与另一件比较」) | Single tap: move the cursor. Tapping the same spot again after a while (not a double tap) = compare with the other equipped item (the original game cycles with ZL; tooltip text 「再点一次与另一件比较」(Tap again to compare with the other one)) */
int again = now_s - s->last_tap_s < 8.0 && hypotf(ox - s->last_tap_x, oy - s->last_tap_y) <= 2 * DM_TC_POINTER_MOVE_PT * scale_for(&s->layout);
if (again && !atomic_load(&g_bank_open) && !atomic_load(&g_vendor_open)) pointer_pulse_btn(s, ox, oy, 2, DM_BTN_ZL, 0); /* 开着箱子 / 商人页时 ZL 是切页签,不发(货上点第二下把货架翻到了下一页) | With the stash / vendor page open ZL switches tabs, so do not send it (a second tap on goods flipped the shelf to the next page) */
else if (!s->pulse_button) { s->pointer_x = ox; s->pointer_y = oy; }
++s->item_tap_seq; s->last_tap_s = now_s; s->last_tap_x = ox; s->last_tap_y = oy; }
} else if (s->tap_button) {
s->pointer_valid = 1; pointer_pulse_btn(s, s->tap_x, s->tap_y, 2, s->tap_button, 0); /* 前端改写:光标到点 + 按键(技能绑定里点技能) | Front-end rewrite: cursor to the point + key press (tapping a skill in skill binding) */
} else if (s->tap_move) {
s->pointer_valid = 1; s->pointer_x = s->tap_x; s->pointer_y = s->tap_y; ++s->tap_move_seq;
} else if (s->mouse_click_mode) {
s->mouse_click_x = done.aim_origin_x; s->mouse_click_y = done.aim_origin_y; ++s->mouse_click_seq;
} else pointer_pulse_start(s, done.aim_origin_x, done.aim_origin_y, 2);
}
s->pointer_item = 0; s->pointer_release_item = 1; s->pointer_shop = 0; s->pointer_stack = 0; s->pointer_lock = 0;
s->pointer_slot = DM_TC_NONE;
s->finger[slot] = (dm_tc_finger){.target=DM_TC_NONE};
update(s);
return;
}
/* 技能钮:按住 = 持续施放、拖动定方向、松手键起,不再是「按住瞄准、松手放一下」。
唯一要补的:点得太短,键还没来得及按下手就松了(不到点按 / 拖动的判定时间,或第二组里 ZL 还没领先够)——补成一个带方向的脉冲;
第二组里 ZL 还没领先够时,这个脉冲延到够了再发(dm_tc_tick)。
Skill button: hold = continuous cast, drag sets the direction, release lifts the key; no longer "hold to aim, release to cast once".
The only thing to make up: the tap was too short and the finger lifted before the key could go down (shorter than the tap / drag decision time, or in the second set ZL has not led long enough) -- make it up as one pulse with direction;
in the second set, when ZL has not led long enough, this pulse is delayed until it has (dm_tc_tick). */
if (done.active && done.target >= DM_TC_SKILL1 && done.target <= DM_TC_SKILL4 && !done.aim_cancelled && !s->navigation_mode
&& (!done.key_down || now_s - done.key_down_s < DM_TC_KEY_MIN_S || (s->skill_set && now_s - done.start_time_s < DM_TC_ZL_LEAD_S))) { /* 键没按下过,或按下不到 2 帧(游戏可能漏读):补成脉冲 | The key was never pressed, or was pressed for less than 2 frames (the game may miss it): make it up as a pulse */
float ux = 0, uy = 0; int has = aim_dir(s, &done, &ux, &uy);
s->pulse_rx = has ? (int32_t)lroundf(ux*DM_STICK_MAX) : 0; s->pulse_ry = has ? (int32_t)lroundf(-uy*DM_STICK_MAX) : 0;
if (s->skill_set && now_s - done.start_time_s < DM_TC_ZL_LEAD_S) { s->defer_button = s->layout.target[done.target].button; s->defer_at_s = done.start_time_s + DM_TC_ZL_LEAD_S; }
else { s->pulse_button = s->layout.target[done.target].button; ++s->pulse_epoch; }
}
if (done.active && !s->navigation_mode && done.target >= DM_TC_BELT1 && done.target <= DM_TC_BELT4) {
/* 腰带格松手这一刻判:多排时上移过阈值 = 展开,下移过阈值 = 收起;几乎没动 = 点了一下,这一刻就喝;横着滑走了什么都不做 | decided when a belt cell is released: with multiple rows, moved up past the threshold = expand, down past the threshold = collapse; barely moved = a tap, drink right then; slid away sideways = do nothing */
float th = DM_TC_BELT_SWIPE_PT * scale_for(&s->layout), up = done.aim_origin_y - done.y, dx = done.x - done.aim_origin_x;
if (s->belt_rows > 1 && up > th) s->belt_request = 1;
else if (s->belt_rows > 1 && up < -th) s->belt_request = 2;
else if (fabsf(dx) <= th && fabsf(up) <= th) belt_fire(s, 0x10 | (done.target - DM_TC_BELT1));
}
if (done.active && !s->navigation_mode && (done.target == DM_TC_NONE || done.target == DM_TC_JOYSTICK) && now_s - done.start_time_s < DM_TC_POINTER_TAP_S && /* 起摇杆区里很快原地松开的那一下兼作点击 | a quick release in place inside the stick-start zone doubles as a tap */
hypotf(done.x - done.aim_origin_x, done.y - done.aim_origin_y) <= DM_TC_POINTER_MOVE_PT * scale_for(&s->layout)) {
s->world_tap_x = done.aim_origin_x; s->world_tap_y = done.aim_origin_y; ++s->world_tap_seq; /* 点游戏世界 | Tap the game world */
}
s->finger[slot] = (dm_tc_finger){.target=DM_TC_NONE};
if (slot == s->joy_slot) {
s->joy_slot = DM_TC_NONE;
s->joy_origin_x = s->joy_origin_y = 0;
}
update(s);
}
void dm_tc_begin(dm_tc_state *s, int slot, float x, float y) { dm_tc_begin_at(s, slot, x, y, s->last_time_s); }
void dm_tc_move(dm_tc_state *s, int slot, float x, float y) { dm_tc_move_at(s, slot, x, y, s->last_time_s); }
void dm_tc_end(dm_tc_state *s, int slot) { dm_tc_end_at(s, slot, s->last_time_s); }
void dm_tc_pointer_press(dm_tc_state *s, float x, float y, uint64_t button) {
if (s->pointer_slot >= 0 && s->pointer_slot < DM_TC_MAX_TOUCH) s->finger[s->pointer_slot].pointer_long = 1;
s->pointer_valid = 1; pointer_pulse_btn(s, x, y, 2, button, 0); update(s);
}
void dm_tc_tick(dm_tc_state *s, double now_s) {
s->last_time_s = now_s;
/* 补发不许盖掉在发的脉冲(腰带喝药等):在发就等;那个脉冲收回时(dm_tc_pulse_end)把补发时刻推到 ZL 再领先满 DM_TC_ZL_LEAD_S 之后(原先到点直接覆盖,腰带那下没了) | The make-up send must not overwrite a pulse being sent (belt potion, etc.): wait while one is being sent; when that pulse is released (dm_tc_pulse_end), push the make-up time to after ZL has again led for a full DM_TC_ZL_LEAD_S (it used to overwrite directly when due, and the belt press was lost) */
if (s->belt_gap_cell && now_s >= s->belt_gap_at && !s->pulse_button) { uint64_t btn = s->layout.target[DM_TC_BELT1 + (s->belt_gap_cell & 0xf)].button; s->belt_gap_cell = 0;
if (btn && !s->navigation_mode) { s->pulse_rx = s->pulse_ry = 0; s->pulse_button = btn; ++s->pulse_epoch; } update(s); }
if (s->belt_q && !s->pulse_button && !s->defer_button && !s->belt_gap_cell) { int q = s->belt_q; s->belt_q = 0; if (!s->navigation_mode) belt_fire(s, q); }
if (s->defer_button && !s->pulse_button && now_s >= s->defer_at_s) { s->pulse_button = s->defer_button; s->defer_button = 0; ++s->pulse_epoch; update(s); }
else if (!s->navigation_mode) { /* 主钮 / 技能钮上有手指:判定时间、ZL 领先这两个时刻要按时刷新键值 | A finger is on the main button / a skill button: the key values must be refreshed on time at two moments, the decision time and the ZL lead */
for (int i = 0; i < DM_TC_MAX_TOUCH; ++i) if (s->finger[i].active && (s->finger[i].target >= DM_TC_MAIN && s->finger[i].target <= DM_TC_SKILL4)) { update(s); break; }
}
if (s->stash_x_check_s > 0 && now_s >= s->stash_x_check_s) { /* 发过 X 的那件还在光标下(不能堆叠 / 这个存档没有堆叠栏 / 那一叠满了):退回按住 Y,移到仓库当前页。核的是同一个物品 id,X 已经把它移走就什么都不做 | The item that X was sent for is still under the cursor (not stackable / this save has no stacking tab / that stack is full): fall back to hold Y, moving it to the stash's current page. The check is on the same item id; if X has already moved it away, do nothing */
s->stash_x_check_s = 0;
if (atomic_load(&g_bank_open) && atomic_load(&g_cur_stack) == s->stash_x_id && !s->holding && !s->pulse_button) { pointer_pulse_btn(s, s->stash_x_x, s->stash_x_y, 2, DM_BTN_Y, DM_TC_HOLD_USE_S); update(s); }
}
if (s->close_left > 0 && atomic_exchange(&g_close_stop, 0)) s->close_left = 0; /* 返回键引出了确认框(设置页有未应用的改动):停手,让玩家自己答——再按一下就成了替他选「放弃」(改动丢失) | The back button brought up a confirmation box (the settings page has unapplied changes): stop and let the player answer -- one more press would choose 「放弃」(Discard) on their behalf (changes lost) */
if (s->close_left > 0) { /* 面板外点按 = 关到底:面板还开着、上一下 B 已收回,就隔 0.3 秒再按一下 | Tap outside the panel = close all the way: if the panel is still open and the previous B has been released, press once more after 0.3 seconds */
if (!s->navigation_mode) s->close_left = 0;
else if (!s->pulse_button && now_s >= s->close_next_s) { s->pulse_button = DM_BTN_B; s->pulse_hold_s = 0; s->pulse_rx = s->pulse_ry = 0; s->pointer_pulse_active = 2; ++s->pulse_epoch; --s->close_left; s->close_next_s = now_s + 0.3; update(s); }
}
if (s->pointer_slot < 0 || s->pointer_slot >= DM_TC_MAX_TOUCH) return;
dm_tc_finger *f = &s->finger[s->pointer_slot];
if (!f->active || f->pointer_dragged || f->pointer_long) return;
if (s->mouse_click_mode && s->pointer_item != 1) return;
if (now_s - f->start_time_s >= DM_TC_POINTER_HOLD_S &&
hypotf(f->x-f->aim_origin_x, f->y-f->aim_origin_y) <= DM_TC_POINTER_MOVE_PT * scale_for(&s->layout)) {
f->pointer_long = 1;
s->pointer_x = f->aim_origin_x;
s->pointer_y = f->aim_origin_y;
update(s);
}
}
int dm_tc_navigation(dm_tc_scene *s, const char *cat, const char *act, const char *arg) {
static const char *names[]={"PlayerInventoryExpansionLayout","SkillsTreePanel","PauseLayout","PauseLayoutGarden","CharacterStatsPanel","QuestLogPanelExpansion","BankExpansionLayout","HoradricCubeLayout","WaypointsPanelExpansion","NpcDialogPanel","NpcTradePanel","ButtonBindingModal","SkillSelect","YouDiedModal"};
if(!strcmp(cat,"FrontEndNavigation")&&!strcmp(act,"ToFrontEnd")) { s->game=0;s->panels=0; }
if(!strcmp(cat,"PanelManager")) {
if(!strcmp(arg,"LoadScreenPanel")&&!strcmp(act,"OpenPanel"))s->game=0;
if(!strcmp(arg,"LoadScreenPanel")&&!strcmp(act,"UnloadPanel"))s->game=1;
if(!strcmp(act,"UnloadAll"))s->panels=0;
{ size_t al=strlen(arg); if((!strcmp(act,"OpenPanel")||!strcmp(act,"OpenExclusivePanel"))&&al>5&&!strcmp(arg+al-5,"Modal"))atomic_store(&g_close_stop,1); }
for(unsigned i=0;i<sizeof(names)/sizeof(*names);i++)if(!strcmp(arg,names[i])) {
if(!strcmp(act,"OpenPanel")||!strcmp(act,"OpenExclusivePanel"))s->panels|=1ull<<i;
if(!strcmp(act,"ClosePanel")||!strcmp(act,"UnloadPanel"))s->panels&=~(1ull<<i);
}
}
return !s->game||s->panels!=0;
}
/* 死亡弹窗开着:也算导航态(触点走界面点击,能点到「继续」),但五个手柄圆钮不给——死后点技能钮位置会触发复活,容易误触 | Death popup open: also counts as navigation state (touch points go through UI clicks, so 「继续」(Continue) can be tapped), but the five controller round buttons are not offered -- after death a tap at a skill button position triggers resurrection, which is easy to hit by mistake */
int dm_tc_scene_dead(void) { return atomic_load(&g_dead_modal); }
int dm_tc_scene_dialog_only(const dm_tc_scene *s) { return s->game && s->panels == (1ull << 9); } /* 面板表第 9 项 = NpcDialogPanel(见 dm_tc_navigation 的 names) | Entry 9 of the panel table = NpcDialogPanel (see names in dm_tc_navigation) */
-205
View File
@@ -1,205 +0,0 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
enum { DM_TC_MAX_TOUCH = 16, DM_TC_COUNT = 12 };
enum {
DM_TC_NONE = -1, DM_TC_JOYSTICK = -2, DM_TC_SWAP = -3, DM_TC_DIFF = -4, /* DIFF:难度格 / 选择条占用的手指,不发按键 | DIFF: a finger captured by the difficulty cell / selector bar; sends no key */
DM_TC_EDGE = -5, /* 屏幕底边归系统的那一条里起手的手指:不当摇杆,松手也不当点地 | A finger that started in the strip along the bottom edge of the screen that belongs to the system: not treated as the stick, and its release is not treated as a ground tap */
DM_TC_MAIN = 0,
DM_TC_SKILL1, DM_TC_SKILL2, DM_TC_SKILL3, DM_TC_SKILL4,
DM_TC_PORTAL, DM_TC_BELT1, DM_TC_BELT2, DM_TC_BELT3, DM_TC_BELT4,
DM_TC_MENU, DM_TC_MAP
};
typedef struct { float x, y, r; uint64_t button; } dm_tc_target;
typedef struct {
float width, height;
dm_tc_target target[DM_TC_COUNT];
float joy_x, joy_y, joy_radius; /* 没按时底盘的显示位置(静止位)与底盘半径 | where the base is shown while not pressed (rest position), and the base radius */
float joy_zone_r, joy_zone_t, joy_min_x, joy_max_y; /* 起摇杆区的右界与上界(左与下到屏幕边);按下后底盘圆心的夹回界:x 不小于、y 不大于 | right and upper bounds of the stick-start zone (left and bottom reach the screen edges); clamp bounds for the base centre once pressed: x not less than, y not greater than */
dm_tc_target swap; /* 技能组切换键:本地开关,不直接发按键 | Skill set switch key: a local toggle; does not send a key directly */
dm_tc_target diff; /* 底部 UI v4 第 0 格难度:点开 / 收起 1–8 选择条,不发按键 | Bottom UI v4 cell 0 difficulty: tap to open / collapse the 1–8 selector bar; sends no key */
dm_tc_target pick[8]; /* 选择条 8 格(第 i 格 = 人数档 i+1),在七格上方 | The selector bar's 8 cells (cell i = player-count level i+1), above the seven cells */
} dm_tc_layout;
typedef struct {
int active, target;
float x, y;
float aim_origin_x, aim_origin_y;
uint64_t aim_move_sequence;
int aim_cancelled;
int key_down; double key_down_s; /* 技能钮:键是否已按下过、几时按下的(按下后先等判定时间,见 update) | Skill button: whether the key has gone down and when (after press, first wait the decision time, see update) */
double start_time_s;
int pointer_dragged, pointer_long;
/* 界面连续手势(鼠标点击模式、起手不在物品区也不在面板外、位移过阈值时按起始方向定型,定型后不变):1 = 纵向拖(滚动),2 = 横向拖(滑块)。
手势层只定型,前端看到后把起手点与当前点转给宿主(dm_ui_drag_*),滚动 / 滑块由宿主按游戏自己的命中去做
Continuous UI gesture (mouse click mode, started neither in the item area nor outside the panel; when displacement crosses the threshold the type is fixed by the initial direction and does not change afterwards): 1 = vertical drag (scroll), 2 = horizontal drag (slider).
The gesture layer only fixes the type; on seeing it the front end forwards the start point and current point to the host (dm_ui_drag_*), and the scroll / slider is done by the host according to the game's own hit testing */
int ui_drag;
int shop_drag; /* 从商人货架的货上起拖(不拿起):松手按落点买 / 不买 | Drag starting from goods on the vendor shelf (not picked up): on release, buy / do not buy by the drop point */
int locked_drag; /* 单件任务槽占用时从别的物品上起拖:不拿起,松手不发任何键 | Drag starting from another item while the single-item quest slot is occupied: do not pick up, and send no key on release */
} dm_tc_finger;
typedef struct {
dm_tc_layout layout;
dm_tc_finger finger[DM_TC_MAX_TOUCH];
int joy_slot;
float joy_origin_x, joy_origin_y;
uint32_t enabled_targets;
uint64_t buttons;
int32_t lx, ly, rx, ry;
int aim_slot, navigation_mode, map_cancel_active;
uint64_t aim_move_sequence;
int portal_pending, portal_phase; // 0idle / 1modifier-pending / 2armed
uint64_t gesture_epoch, portal_binding_identity, portal_scene_epoch;
/* 松手施放的短按脉冲:按键与右轴方向同时发布,前端到时调 dm_tc_pulse_end 收回 | Short-press pulse for release-to-cast: the key and the right-axis direction are published together, and the front end calls dm_tc_pulse_end to release it when due */
uint64_t pulse_button, pulse_epoch;
int32_t pulse_rx, pulse_ry;
uint64_t defer_button; double defer_at_s; /* 第二组里点得太短的那一下:等 ZL 领先够了再补发 | The too-short tap in the second set: make it up once ZL has led long enough */
/* 技能组:0 = 第一套;1 = 第二套(原版 Switch 按住 ZL 用 alt 槽)。是模式,不随取消/尺寸变化清零 | Skill set: 0 = first set; 1 = second set (on the original Switch game, holding ZL uses the alt slots). It is a mode and is not cleared on cancel/size change */
int skill_set;
/* 第二组技能(ZL 修饰):ZL 只在手指按着主钮 / 技能钮、或技能脉冲在发时按着,且先于技能键 DM_TC_ZL_LEAD_S 按下。
松手施放按得太短时,这一下脉冲延到 ZL 领先够了再发(dm_tc_tick 到点起)。
Second skill set (ZL modifier): ZL is held only while a finger is on the main button / a skill button or a skill pulse is being sent, and goes down DM_TC_ZL_LEAD_S before the skill button.
When a release-to-cast press is too short, that pulse is delayed until ZL has led long enough (dm_tc_tick starts it when due). */
int pointer_slot;
double last_time_s;
int pointer_pickup_done;
int pointer_pulse_active, pointer_pulse_pending;
float pointer_pending_x, pointer_pending_y;
int pointer_valid;
float pointer_x, pointer_y;
/* 物品手势:pointer_item = 当前指针手指落在物品区(前端在松手前按宿主命中结果置位)。物品区单击只移光标(出说明)、
双击 = 按住 A(游戏提示:按住 = 打开 / 使用 / 装备;开着箱子时按住 Y = 移到另一侧);非物品区单击照旧 = 移光标 + 按 A。
pulse_hold_s > 0 = 这个脉冲要按住这么久,前端在「游戏已取走」之外再等满它才收
Item gestures: pointer_item = the current pointer finger landed in the item area (set by the front end before release from the host's hit result). A single tap in the item area only moves the cursor (shows the tooltip),
double tap = hold A (game hint: hold = open / use / equip; with the stash open, hold Y = move to the other side); a single tap outside the item area is as before = move the cursor + press A.
pulse_hold_s > 0 = this pulse must be held this long, and the front end waits it out in full in addition to "the game has consumed it" before releasing */
int pointer_item;
/* 非物品区的点按走鼠标点击(暂停菜单按钮、布局里插回的关闭 / 修理等按钮只认鼠标):mouse_click_mode 由前端打开;
每次这样的点按 mouse_click_seq 加一,前端看到变化就在 (mouse_click_x, mouse_click_y) 发一次界面鼠标点击,不再按 A
Taps outside the item area go through mouse clicks (pause menu buttons and the close / repair buttons inserted back into the layout only respond to the mouse): mouse_click_mode is turned on by the front end;
each such tap increments mouse_click_seq, and on seeing a change the front end sends one UI mouse click at (mouse_click_x, mouse_click_y) and no longer presses A */
/* 拖放松手处(物品抬在手指上方的那个落点)是不是物品区:前端松手前置位。不是 = 拖到面板外 = 丢弃(指针回原处、到位后按 Y)。
holding = 光标上还拿着物品(上一次没放成):这时点物品区 = 放下(A),点别处不动
Whether the drag-and-drop release spot (the drop point where the item is lifted above the finger) is the item area: set by the front end before release. If not = dragged outside the panel = discard (pointer returns to the original spot and presses Y once in place).
holding = the cursor is still holding an item (the last drop did not succeed): then tapping the item area = put down (A), tapping elsewhere does nothing */
int pointer_release_item, holding; float release_x, release_y;
/* 游戏态(没开面板)的点按 = 点游戏世界:手指没落在任何控件目标上(含落在摇杆区但没拖动)、按下到抬起不到 0.35 秒、位移不超过点按阈值
→ world_tap_seq 加一,前端看到变化调宿主 dm_world_tap(点物品名拾取 / 点 NPC 对话 / 点箱子,点空地什么都不发)。
A tap in game state (no panel open) = tap the game world: the finger did not land on any widget target (including landing in the stick area without dragging), less than 0.35 seconds from press to lift, displacement within the tap threshold
→ world_tap_seq is incremented, and on seeing a change the front end calls the host's dm_world_tap (tap an item name to pick up / tap an NPC to talk / tap a chest; tapping empty ground sends nothing). */
unsigned world_tap_seq; float world_tap_x, world_tap_y;
int close_left; double close_next_s; /* 面板外点按后还要按几下 B、下一下最早什么时候(按到面板关掉为止) | After a tap outside the panel, how many more B presses remain and the earliest time of the next one (press until the panel is closed) */
/* 商人页:这次按下落在货架的货上(前端按宿主命中结果 7 置位)。从货上起拖 = 想买:不发「拿起」、光标留在那件货上(宿主买的是光标选中的那件);
松手时 shop_drop_seq 加一,前端按落点决定——落在背包类物品区 = 买,拖回货架 / 面板外 / 别处 = 不买
Vendor page: this press landed on goods on the shelf (set by the front end on host hit result 7). A drag starting from goods = intent to buy: do not send "pick up", and the cursor stays on that item (the host buys the item the cursor has selected);
on release shop_drop_seq is incremented and the front end decides by the drop point -- landing in an inventory-type item area = buy; dragged back to the shelf / outside the panel / elsewhere = do not buy */
int pointer_shop; unsigned shop_drop_seq;
int pointer_lock; /* 单件任务槽里有东西时按在别的物品上(宿主命中结果 10):照物品区移光标出说明,但不拿起、双击 / 长按 / 单击都不动它,也不把槽里那件放过来 | Pressing on another item while the single-item quest slot holds something (host hit result 10): move the cursor and show the tooltip as in the item area, but do not pick it up; double tap / long press / single tap do not move it, and the item in the slot is not placed here either */
/* 高级仓库的成叠格(前端按宿主命中结果 8 置位):别的都照物品区,只有双击不同——stack_take_seq 加一,前端调宿主 dm_stash_take(1) 取 1 件到背包 | Stacked cell of the advanced stash (set by the front end on host hit result 8): everything else follows the item area, only double tap differs -- stack_take_seq is incremented and the front end calls the host's dm_stash_take(1) to take 1 into the inventory */
int pointer_stack; unsigned stack_take_seq;
unsigned ident_seq; /* 物品区双击了一件未鉴定物品的次数(只有未鉴定时双击 = 免费鉴定,各页都先判这一条):前端看到变化调宿主 dm_ui_identify_hovered | Number of double taps on an unidentified item in the item area (only when unidentified does double tap = free identify, and this rule is checked first on every page): on seeing a change the front end calls the host's dm_ui_identify_hovered */
unsigned use_seq; /* 物品区双击的次数(没开箱子时):前端看到变化调宿主 dm_ui_use_item——按光标下物品走原生的使用 / 购买 / 装备,不等「按住 A」的门槛 | Number of double taps in the item area (when no stash is open): on seeing a change the front end calls the host's dm_ui_use_item -- performs the native use / buy / equip on the item under the cursor without waiting for the "hold A" threshold */
unsigned item_tap_seq; /* 物品区单击的次数(前端看到变化调宿主 dm_ui_item_tap:鉴定态下单击物品 = 鉴定它) | Number of single taps in the item area (on seeing a change the front end calls the host's dm_ui_item_tap: in identify state, single-tapping an item = identify it) */
unsigned long_press_seq; /* 物品区按住不动满长按时长的次数(前端看到变化调宿主 dm_ui_long_press:背包药水 → 腰带) | Number of times the item area was held still for the full long-press duration (on seeing a change the front end calls the host's dm_ui_long_press: inventory potion → belt) */
unsigned tab_tap_seq; /* 点按落在页签上的次数(前端看到变化调宿主 dm_ui_tab_go) | Number of taps that landed on a tab (on seeing a change the front end calls the host's dm_ui_tab_go) */
int mouse_click_mode; unsigned mouse_click_seq; float mouse_click_x, mouse_click_y;
/* 前端临时改写「面板内非物品区的点按」:非 0 = 不发鼠标点击,改成手柄光标走到触点、到位后按这个键(技能绑定流程里点技能 = 光标到它身上按 Y)。页签 / 面板外照旧 | Temporary front-end rewrite of "taps inside a panel outside the item area": non-zero = send no mouse click; instead the controller cursor walks to the touch point and presses this key on arrival (tapping a skill in the skill binding flow = cursor onto it and press Y). Tabs / outside the panel behave as before */
uint64_t tap_button; float tap_x, tap_y; int tap_move; unsigned tap_move_seq; /* tap_move:本次点按只把光标移到 tap_x / tap_y,不发点击(技能图标 / 属性「+」:先选中、再确认) | tap_move: this tap only moves the cursor to tap_x / tap_y and sends no click (skill icon / attribute "+": select first, then confirm) */
double pulse_hold_s;
double last_tap_s; float last_tap_x, last_tap_y;
double stash_x_check_s; float stash_x_x, stash_x_y; unsigned stash_x_id; /* 开着箱子双击背包物品先发了 X:到这个时刻那件还在光标下(游戏没收这下 X)就退回按住 Y | With the stash open, double-tapping an inventory item sent X first: if at this time the item is still under the cursor (the game did not accept that X), fall back to hold Y */
uint64_t pointer_pending_button; double pointer_pending_hold;
/* 难度:diff_open = 选择条展开;diff_request = 刚选中的人数档(1–8),前端交给宿主 dm_hud_request_players 后清零 | Difficulty: diff_open = selector bar expanded; diff_request = the player-count level just selected (1–8), cleared after the front end hands it to the host's dm_hud_request_players */
int diff_open, diff_request;
/* 腰带展开(原版键鼠「显示腰带」的那几排,手柄版没有入口):身上的腰带多于 1 排时,在腰带格上向上滑 = 展开、向下滑 / 点别处 = 收起,
展开后点上面几排的药 = 喝。belt_rows / belt_open 由前端每次触摸前按宿主读数写入;belt_request 前端取走后清零:
1 展开,2 收起,0x100 | 排 << 4 | 列 = 喝那一格(排 1–3 = 底排之上第几排)
Belt expansion (the rows of the original game's keyboard-and-mouse "show belt"; the controller version has no entry for it): when the worn belt has more than 1 row, swiping up on a belt cell = expand, swiping down / tapping elsewhere = collapse,
and after expansion tapping a potion in the upper rows = drink. belt_rows / belt_open are written by the front end from host readings before each touch; belt_request is cleared after the front end takes it:
1 expand, 2 collapse, 0x100 | row << 4 | column = drink that cell (row 1–3 = which row above the bottom row) */
int belt_rows, belt_open, belt_request;
/* 腰带点一下 = 自己喝,松手那一刻就喝,点几下喝几瓶;不判双击、腰带上不做喂雇佣兵的手势 | one tap on the belt = the player drinks, at the moment of release, several taps drink several; no double-tap detection, no mercenary feeding gesture on the belt */
int belt_gap_cell; double belt_gap_at; /* 按着第二组技能时要喝药:先把 ZL 和技能键松开、空出 DM_TC_ZL_LEAD_S,到 belt_gap_at 才按腰带键(belt_gap_cell = 等着的那一格,0 = 没有) | to drink a potion while a skill of the second skill set is held: first release ZL and the skill key and leave a gap of DM_TC_ZL_LEAD_S, and only at belt_gap_at press the belt key (belt_gap_cell = the cell that is waiting, 0 = none) */
double joy_lost_s; float joy_lost_x, joy_lost_y, joy_lost_ox, joy_lost_oy; /* 摇杆手指被系统取消的时刻与当时的位置(0 = 没有):紧接着在附近重新落下的手指接着当摇杆 | time and position at which the joystick finger was cancelled by the system (0 = none): a finger landing again nearby right afterwards continues as the joystick */
int joy_block; /* 讲话文字框单独开着(前端不进面板态):这时落在底座上的手指不起摇杆,照旧只当一次点击(关讲话框)。前端按面板栈写 | speech text box open on its own (the front end does not enter panel state): a finger on the base starts no stick and is still just one click (closes the speech box). Written by the front end from the panel stack */
double belt_pulse_s; /* 最近一次「给玩家喝」的腰带脉冲还在发的时刻:其间按着的第二组技能连同 ZL 一起让开,收回后 ZL 重新领先 DM_TC_ZL_LEAD_S 技能键才回来 | Time until which the most recent "player drinks" belt pulse is still being sent: during it the held second-set skill gives way together with ZL, and after the release ZL again leads by DM_TC_ZL_LEAD_S before the skill key comes back */
int belt_q; /* 此刻有别的脉冲在发 / 别的补发在等:排着,空了再落地(不互相盖掉)。值 = 格 | another pulse is being sent / another resend is pending: queue and fire when free (they never overwrite each other). Value = cell */
} dm_tc_state;
/* 原版UI消息驱动,不根据输入键猜面板。AutoMap是战斗叠加,不切导航。 | Driven by the original game's UI messages; panels are not guessed from input keys. AutoMap is a combat overlay and does not switch to navigation. */
typedef struct { int game; uint64_t panels; } dm_tc_scene;
int dm_tc_navigation(dm_tc_scene *scene, const char *cat, const char *act, const char *arg);
int dm_tc_scene_dialog_only(const dm_tc_scene *scene); /* 只开着 NPC 对话菜单 | Only the NPC dialog menu is open */
int dm_tc_scene_dead(void); /* 死亡弹窗开着(导航态,但不给手柄圆钮) | Death popup open (navigation state, but no controller round buttons) */
/* 坐标使用 UIKit 点;布局本身不画球、不声称游戏已绑定回城/腰带。 | Coordinates use UIKit points; the layout itself does not draw the orbs and does not claim the game has bound town portal/belt. */
/* 安全区左右内缩(点);在 init / resize 之前设,之后的布局按它把右侧技能键组与左摇杆移进安全区。缺省 0。 | Left/right safe-area insets (points); set before init / resize, and the layout afterwards uses them to move the right-side skill key group and the left stick into the safe area. Default 0. */
void dm_tc_set_safe_insets(float left, float right);
void dm_tc_set_edge_bottom(float bottom); /* 屏幕底边归系统的那一条的高度(点);0 = 没有。只约束移动摇杆的起手 | Height (points) of the strip along the bottom edge of the screen that belongs to the system; 0 = none. Constrains only where the movement stick may start */
void dm_tc_layout_make(dm_tc_layout *layout, float width, float height);
int dm_tc_hit(const dm_tc_layout *layout, float x, float y);
#define DM_TC_POINTER_LIFT_PT 40.0f // 功能页拖动时物品抬在手指上方的点数(× 控件缩放) | Number of points the item is lifted above the finger while dragging on function pages (× widget scale)
void dm_tc_set_tall_scale(int on); // 画面高 > 440 点时按 高/440 放大的开关;缺省关(Mac 宿主触屏用例传的是像素数,不能放大),iOS 前端建视图时开 | Switch for scaling up by height/440 when picture height > 440 points; default off (the Mac host touch test cases pass pixel counts and must not be scaled up); the iOS front end turns it on when creating the view
float dm_tc_scale_for_size(float width, float height); // 控件缩放:手机 min(1, 宽/667, 高/375);画面高 > 440 点(iPad)时按 高/440 等比放大 | Widget scale: phone min(1, width/667, height/375); when picture height > 440 points (iPad), scale up proportionally by height/440
void dm_tc_init(dm_tc_state *state, float width, float height);
/* 尺寸变更会取消全部触点,调用者随后推送归零状态。 | A size change cancels all touch points, and the caller then pushes the zeroed state. */
void dm_tc_resize(dm_tc_state *state, float width, float height);
/* 控件开关不改变布局;切换有效位时取消已有触点。 | Widget switches do not change the layout; existing touch points are cancelled when the valid bits are toggled. */
void dm_tc_enable_targets(dm_tc_state *state, uint32_t mask);
/* 导航模式(面板 / 对话 / 前端页开着)下可用的控件:右侧五个虚拟手柄圆钮(确认 / 返回 / 操作 / 绑定 / 下一页 = A B X Y R)。
底栏十字位置的「关闭」不再给:面板的关闭入口只留一个(外框右上角的关闭按钮;圆钮还在时另有「返回」)。
pad = 0:五个圆钮也不给(局内手指直接点界面接上之后用,开关 DM_TOUCH_NAV_PAD=0,缺省 1)。两个前端共用这一处,不各写各的。
Widgets available in navigation mode (a panel / dialog / front-end page is open): the five virtual controller round buttons on the right (confirm / back / action / bind / next page = A B X Y R).
The "close" at the bottom bar's cross position is no longer offered: only one close entry for panels remains (the close button at the top-right corner of the frame; while the round buttons are present there is also "back").
pad = 0: the five round buttons are not offered either (used once in-run fingers tapping the UI directly is hooked up; switch DM_TOUCH_NAV_PAD=0, default 1). Both front ends share this one place and do not each write their own. */
static inline uint32_t dm_tc_nav_mask(int pad) { return pad ? ((1u<<DM_TC_MAIN)|(1u<<DM_TC_SKILL1)|(1u<<DM_TC_SKILL2)|(1u<<DM_TC_SKILL3)|(1u<<DM_TC_SKILL4)) : 0; }
/* 模式变化释放全部手势;导航模式只按键,不启用技能拖拽和地图取消区。 | A mode change releases all gestures; navigation mode only presses keys and does not enable skill dragging or the map cancel area. */
void dm_tc_set_navigation_mode(dm_tc_state *state, int navigation_mode);
void dm_tc_set_joy_block(dm_tc_state *state, int block); /* 讲话文字框 / 对话菜单单独开着:落在底座上的手指不起摇杆、只当一次点击 | speech text box / dialogue menu open on its own: a finger on the base starts no stick and is just one click */
/* 只取消回城控件拥有的core触点;物理触点由前端保留。 | Cancel only the core touch point owned by the town-portal widget; the physical touch point is kept by the front end. */
void dm_tc_set_portal_button(dm_tc_state *state, uint64_t mask);
void dm_tc_set_portal_binding(dm_tc_state *state, uint64_t mask, uint64_t binding_identity, uint64_t scene_epoch);
/* 反馈确认仅作用于仍持有且身份/场景/请求一致的pending手势;返回是否首次armed。 | Feedback confirmation applies only to a pending gesture that is still held and whose identity/scene/request match; returns whether it was armed for the first time. */
int dm_tc_portal_ack(dm_tc_state *state, uint64_t gesture_epoch, uint64_t binding_identity, uint64_t scene_epoch);
void dm_tc_cancel_portal(dm_tc_state *state);
void dm_tc_begin(dm_tc_state *state, int slot, float x, float y);
void dm_tc_move(dm_tc_state *state, int slot, float x, float y);
void dm_tc_end(dm_tc_state *state, int slot);
void dm_tc_begin_at(dm_tc_state *state, int slot, float x, float y, double now_s);
void dm_tc_move_at(dm_tc_state *state, int slot, float x, float y, double now_s);
void dm_tc_end_at(dm_tc_state *state, int slot, double now_s);
void dm_tc_tick(dm_tc_state *state, double now_s);
void dm_tc_cancel_all(dm_tc_state *state);
void dm_tc_cancel_finger(dm_tc_state *state, int slot); /* 系统取消这根手指:不当松手,只放掉它按着的东西 | The system cancels this finger: do not treat it as a release, only let go of what it was holding */
/* 结束 epoch 对应的施放脉冲;返回是否有变化(调用者随后推送) | End the cast pulse corresponding to epoch; returns whether anything changed (the caller then pushes) */
int dm_tc_pulse_end(dm_tc_state *state, uint64_t pulse_epoch);
// 收回后还有排着的指针脉冲(拖放的「放下」在「拿起」没收时就到了):前端等游戏看到一次松开后调 resume 开始它
// After release there is still a queued pointer pulse (the "put-down" of a drag-and-drop arrived before the "pick-up" was released): the front end waits until the game has seen a release once, then calls resume to start it
int dm_tc_pulse_pending(const dm_tc_state *state);
void dm_tc_pointer_press(dm_tc_state *state, float x, float y, uint64_t button); /* 光标到 (x, y) 再按一下 button;当前指针手指记为「长按已处理」,松手不再算点按 | Cursor to (x, y), then press button once; the current pointer finger is marked "long press handled" and its release no longer counts as a tap */
void dm_tc_pointer_item(dm_tc_state *state, int kind); /* 指针手指的命中结果一出来就调(最晚松手前):1 = 物品区,2 = 页签,3 = 面板外(点按 = 关面板),其余 = 面板内别处(点按 = 鼠标点击) | Called as soon as the pointer finger's hit result is available (before release at the latest): 1 = item area, 2 = tab, 3 = outside the panel (tap = close the panel), anything else = elsewhere inside the panel (tap = mouse click) */
void dm_tc_pointer_release(dm_tc_state *state, int kind); /* 拖放松手前调:宿主的落点判定(1 放在抬起点 / 4 放在手指点 / 3 丢弃 / 0 放回原处) | Called before a drag-and-drop release: the host's drop decision (1 place at the lifted point / 4 place at the finger point / 3 discard / 0 put back where it was) */
void dm_tc_pointer_release_at(dm_tc_state *state, float x, float y); /* 拖放松手前调:放在这个位置(宿主算的,装备槽 = 槽心) | Called before a drag-and-drop release: place at this position (computed by the host; equipment slot = slot center) */
void dm_tc_set_holding(dm_tc_state *state, int holding);
void dm_tc_set_cur_stack(unsigned id); /* 仓库开着时光标此刻指着的背包物品的 id(指着仓库一侧 / 没指着 = 0) | id of the inventory item the cursor is pointing at right now while the stash is open (pointing at the stash side / pointing at nothing = 0) */
void dm_tc_set_hover_unid(unsigned id); /* 光标此刻指着的我方未鉴定物品 id(宿主 dm_ui_hover_unid):物品区双击先判它——非 0 = 鉴定(ident_seq 加一),不走各页原来的双击 | id of our unidentified item the cursor is pointing at right now (host dm_ui_hover_unid): an item-area double tap checks it first -- non-zero = identify (ident_seq incremented), skipping each page's original double tap */
void dm_tc_set_tap_box(int on); /* 最近一次单击的物品是不是魔盒(开着箱子时双击魔盒 = 打开) | Whether the most recently single-tapped item is the cube (with the stash open, double-tapping the cube = open) */
void dm_tc_set_panel_state(int bits); /* 宿主读游戏面板树得到的状态位(1 储藏箱开着 / 2 商人页 / 4 死亡弹窗);界面消息 DM:PanelState 到来时前端调 | State bits the host obtains by reading the game panel tree (1 stash open / 2 vendor page / 4 death popup); the front end calls this when the UI message DM:PanelState arrives */
void dm_tc_set_iso_fix(int on); /* 移动摇杆斜向预修正开关(缺省开;测量改前改后用) | Switch for the movement stick's diagonal pre-correction (default on; used to measure before and after the change) */
int dm_tc_belt_outside(const dm_tc_state *state, float x, float y);
#define DM_TC_AIM_SETTLE_S 0.08 /* 技能钮按下后等这么久判定是点按还是拖动(拖过死区就提前键下) | After a skill button is pressed, wait this long to decide tap versus drag (dragging past the dead zone puts the key down early) */
#define DM_TC_BELT_SWIPE_PT 24 /* 腰带格上松手时纵向位移过这么多点 = 展开 / 收起;不到 = 点按(喝) | On release over a belt cell, vertical displacement beyond this many points = expand / collapse; less = tap (drink) */
#define DM_TC_KEY_MIN_S 0.035 /* 技能键至少按住这么久(约 2 帧);不够的松手时补成脉冲,保证游戏读到 | A skill button is held at least this long (about 2 frames); a shorter one is made up as a pulse on release to guarantee the game reads it */
#define DM_TC_JOY_RESUME_S 0.35 /* 摇杆那根手指被系统取消后,这么久之内在原处附近重新落下的手指接着当摇杆(不要求落在底座附近) | after the joystick finger is cancelled by the system, a finger landing again near the same spot within this long continues as the joystick (landing near the base is not required) */
#define DM_TC_JOY_GRAB_K 1.5f /* 摇杆那根手指被系统取消后重新落下:离原处这么多倍底盘半径之内才接着当摇杆 | after the stick finger is cancelled by the system and touches down again: it continues as the stick only within this many base radii of the original place */
#define DM_TC_ZL_LEAD_S 0.17 /* 修饰键领先主键的时间(约 10 帧;同一帧按下游戏只认主键) | Time the modifier key leads the main key (about 10 frames; pressed in the same frame, the game only recognizes the main key) */
#define DM_TC_DOUBLE_TAP_S 0.40 /* 两次单击间隔上限 | Upper limit of the interval between two single taps */
#define DM_TC_HOLD_USE_S 0.60 /* 「按住」动作的按住时长:Mac 宿主实测 0.25 s 只捡起、0.45 s 打开魔盒 | Hold duration of the "hold" action: measured on the Mac host, 0.25 s only picks up, 0.45 s opens the cube */
int dm_tc_pulse_resume(dm_tc_state *state);
#ifdef __cplusplus
}
#endif
-125
View File
@@ -1,125 +0,0 @@
#include "dm_touch_game_state.h"
#include "dm_touch_game_identity.h"
#include "../../host/dm.h"
enum { OBS_BINDING_GETTER=6, MAPPING_OFFSET=0x2d13cbc, BINDING_OFFSET=0x2d5f0c0 };
static pthread_mutex_t lock=PTHREAD_MUTEX_INITIALIZER;
static dm_tg_snapshot latest;
static dm_tg_group group;
static dm_tg_hud_cohort hud_cohort;
static int scene_game;
static uint64_t scene_epoch,world_epoch;
static const module_t *main_module;
void dm_touch_game_set_scene(int game,uint64_t scene,uint64_t world) {
pthread_mutex_lock(&lock);
if(world_epoch!=world)dm_tg_hud_reset(&hud_cohort,world);
if(scene_game!=game || scene_epoch!=scene || world_epoch!=world) {
scene_game=game;scene_epoch=scene;world_epoch=world;memset(&group,0,sizeof group);
int supported=latest.supported;memset(&latest,0,sizeof latest);latest.supported=supported;
latest.scene_epoch=scene;latest.world_epoch=world;latest.portal.slot=-1;
}
pthread_mutex_unlock(&lock);
}
int dm_touch_game_snapshot(dm_tg_snapshot *out) {
if(!out)return 0;
pthread_mutex_lock(&lock);*out=latest;pthread_mutex_unlock(&lock);return out->valid;
}
/* 只读render实例门;不学习cohort,不续反馈TTL,不写客体。未知一律原render。 | Read-only render instance gate; does not learn the cohort, does not extend the feedback TTL, does not write to the guest. Anything unknown gets the original render. */
int dm_touch_game_hide_own_glyph(uint64_t widget) {
int match=0;pthread_mutex_lock(&lock);
const module_t *m=main_module;uint64_t t=now_ns();
if(m && scene_game && scene_epoch && world_epoch && hud_cohort.confirmed && hud_cohort.seen==63 &&
hud_cohort.world_epoch==world_epoch && latest.supported && latest.valid && latest.ready &&
latest.identity_scope==DM_TG_IDENTITY_NATIVE && latest.source==DM_TG_SOURCE_NATIVE_GETTER &&
latest.scene_epoch==scene_epoch && latest.world_epoch==world_epoch &&
latest.hud_identity==hud_cohort.hud_identity && latest.group_seen==63 &&
latest.captured_ns && t>=latest.captured_ns && t-latest.captured_ns<=DM_TG_MAX_AGE_NS) {
for(unsigned i=0;i<6;i++)if(widget && widget==hud_cohort.widget[i]) {
/* 一次读完[widget,widget+c91):VT、enum(+b18)、alwaysGetAlt(+c90)。读失败=原render。object是静态的(在lock内),不占客体线程的栈。 | Read [widget,widget+c91) in one go: VT, enum (+b18), alwaysGetAlt (+c90). Read failure = original render. object is static (inside the lock) and does not use the guest thread's stack. */
static unsigned char object[0xc91];uint64_t vt=0;uint32_t slot=UINT32_MAX;
if(widget<=UINT64_MAX-0xc90 && dm_tg_vm_read(widget,object,sizeof object)) {
memcpy(&vt,object,8);memcpy(&slot,object+0xb18,4);
if(vt==(uint64_t)m->base+0x208a5f8 && slot==i && !object[0xc90])match=1;
}
break;
}
}
pthread_mutex_unlock(&lock);return match;
}
/* 诊断(DM_BINDING_DIAG=1):各返回点计数,每 3 秒一行;身份确认失败再按原因码细分(identity.c) | Diagnostic (DM_BINDING_DIAG=1): counts per return point, one line every 3 seconds; identity confirmation failures are further broken down by reason code (identity.c) */
static unsigned dg[8], dg_id[8]; static uint64_t dg_last;
static void diag_tick(void) {
static int on=-1; if(on<0) on=getenv("DM_BINDING_DIAG")!=NULL; if(!on) return;
uint64_t t=now_ns(); if(t-dg_last<3000000000ull) return; dg_last=t;
LOG("绑定诊断:调用 %u|寄存器不符 %u|槽越界 %u|组不符 %u|不在局内 %u|身份未确认 %u(原因 3:%u 4:%u 5:%u 6:%u 7:%u,LR 偏移 %#llx 槽 %u)|成功 %u|scene_game %d world %llu",
dg[0],dg[1],dg[2],dg[3],dg[4],dg[5],dg_id[3],dg_id[4],dg_id[5],dg_id[6],dg_id[7],(unsigned long long)dm_tg_identity_lr,dm_tg_identity_slot,dg[6],scene_game,(unsigned long long)world_epoch);
}
static int live_check; /* 真游戏里才开(要调游戏函数);单测的假模块上不开 | Turned on only in the real game (it calls game functions); not turned on for the unit tests' fake module */
void dm_touch_game_live_check(int on) { live_check=on; }
/* 槽里绑的技能玩家现在还有没有(摘掉给技能的装备后,那颗钮回到空位;装备穿回来原版把绑定接回、钮自己回来——所以不清原版绑定表,只在快照里按空位报)。
判法照原版选用技能时那段 main+0x43f1ac–0x43f23c:技能链表 [玩家+0x100] 里找「技能号、物品号(槽 +4;-1 = 自己学的)都相同」的节点,
等级 = 节点 +0x38(自己学的再加装备加成 0x5b1710),夹到版本上限后 > 0 才算有。读不到玩家 / 版本不认 = 不改判。只在游戏线程调(观测门里)
Whether the player still has the skill bound in the slot (after taking off the gear that grants the skill, that button goes back to an empty slot; when the gear is put back on, the original game reconnects the binding and the button comes back by itself -- so the original binding table is not cleared, and the slot is only reported as empty in the snapshot).
The check follows the original game's code for selecting a skill at main+0x43f1ac–0x43f23c: in the skill linked list [player+0x100], find the node whose "skill number and item number (slot +4; -1 = self-learned) are both the same",
level = node +0x38 (for a self-learned one, plus the gear bonus 0x5b1710), and it counts as owned only if > 0 after clamping to the version cap. Player unreadable / version not recognized = verdict unchanged. Called only on the game thread (inside the observation gate) */
static int skill_live(const unsigned char *b,uint32_t id,int32_t item) {
if(id==UINT32_MAX || id==359 || id==219 || id==220)return 1; /* 空位、回城卷轴 / 书(原版取槽时自己换号,按数量判)不归这里 | Empty slots and town portal scrolls / tomes (the original game swaps the number itself when fetching the slot, judged by quantity) are not handled here */
uint64_t pl=((uint64_t(*)(uint32_t))(b+0x45f9d0))(*(const uint32_t*)(b+0x2d20e4c)); if(!pl)return 1;
uint8_t ver=*(uint8_t*)(pl+0x1bd); if(ver<1 || ver>3)return 1;
uint64_t l=*(uint64_t*)(pl+0x100),n=l?*(uint64_t*)l:0;
for(int k=0;n && k<1024;k++,n=*(uint64_t*)(n+8)) { uint64_t r=*(uint64_t*)n;
if(!r || *(int16_t*)r!=(int16_t)id || *(int32_t*)(n+0x44)!=item)continue;
int lv=*(int32_t*)(n+0x38); if(item==-1)lv+=((int(*)(uint64_t,uint64_t,int))(b+0x5b1710))(pl,n,0);
int cap=**(int32_t**)(*(uint64_t*)(b+0x2d64a18+(uint64_t)ver*16)+0x1500); if(lv<0)lv=0; if(lv>cap)lv=cap;
return lv>0; }
{ int dm_swapskill_equipped(int32_t); return item!=-1 && dm_swapskill_equipped(item); } /* 副手组技能:物品还穿在换手那组上 = 按下会先换武器再放(dm_actions.c),照常显示、角标「II」 | Off-hand set skill: the item is still worn on the weapon-swap set = pressing will swap weapons first and then cast (dm_actions.c); shown as usual, with corner badge "II" */
}
static void binding_getter(const uint64_t *regs) {
const module_t *m=main_module;
dg[0]++; diag_tick();
if(!m || !regs || regs[10]!=(uint64_t)(m->base+BINDING_OFFSET) || regs[8]%DM_TG_STRIDE){dg[1]++;return;}
uint64_t effective=regs[8]/DM_TG_STRIDE;
uint32_t input_slot=(uint32_t)regs[19]; // PRE-ldr原getter arg,不是ID。 | PRE-ldr arg of the original getter, not an ID.
if(input_slot>=DM_TG_SLOTS || effective>=28 || effective<input_slot){dg[2]++;return;}
uint64_t selected_bank=effective-input_slot;
if(selected_bank!=0 && selected_bank!=16){dg[3]++;return;}
unsigned dead=0; /* 绑着但玩家现在没有的技能(位 = 槽)。要调游戏函数,放在取锁之前 | Skills that are bound but the player does not currently have (bit = slot). This calls a game function, so it is placed before taking the lock */
for(int i=0;live_check && i<DM_TG_SLOTS;i++) { uint32_t id;int32_t item;const unsigned char *e=(const unsigned char*)m->base+BINDING_OFFSET+(selected_bank+i)*DM_TG_STRIDE;memcpy(&id,e,4);memcpy(&item,e+4,4);
static uint32_t gone[32]; int live=skill_live((const unsigned char*)m->base,id,item); if(!live)dead|=1u<<i;
if(gone[selected_bank+i]!=(live?UINT32_MAX:id)) { gone[selected_bank+i]=live?UINT32_MAX:id; if(!live)LOG("技能钮:槽 %d 绑的技能 %u(物品 %d)玩家现在没有,按空位显示",(int)selected_bank+i,id,item); else LOG("技能钮:槽 %d 的技能回来了,照常显示",(int)selected_bank+i); } }
pthread_mutex_lock(&lock);
if(!scene_game || !world_epoch) {dg[4]++;pthread_mutex_unlock(&lock);return;} // menu/nav不学cohort。 | menu/nav do not learn the cohort.
uint64_t caller=0,hud=0;
#ifndef DM_TG_TEST_SYNTHETIC_IDENTITY
/* 不读内存的前置筛:HUD updater在main3e2f68把arg放进w23、3e2f6c再mov w0,w23后BL原Get;原Get只动x19-x21,
被调函数按AAPCS保x23,所以HUD这条调用到门时必有x23==x19(arg)。不等=不是HUD updater,同「savedLR不符」一样IGNORE,省掉读栈。
Pre-filter that reads no memory: at main3e2f68 the HUD updater puts arg into w23, at 3e2f6c it does mov w0,w23 and then BL to the original Get; the original Get only touches x19-x21,
and the callee preserves x23 per AAPCS, so when this HUD call reaches the gate x23==x19 (arg) must hold. Not equal = not the HUD updater; IGNORE just like "savedLR mismatch", saving the stack read. */
if(regs[23]!=regs[19]) {dg[5]++;dg_id[4]++;pthread_mutex_unlock(&lock);return;}
#endif
#ifdef DM_TG_TEST_SYNTHETIC_IDENTITY
int scope=dm_touch_game_test_identity(regs,&caller,&hud); // 仅独立SDK_STUB构建;不与生产符号碰撞。 | Only for the standalone SDK_STUB build; does not collide with production symbols.
#else
int scope=dm_tg_hud_identity(&hud_cohort,regs,(uint64_t)m->base,scene_game,world_epoch,dm_tg_vm_read,&caller,&hud);
#endif
if(scope==DM_TG_IDENTITY_UNCONFIRMED) {dg[5]++;if(dm_tg_identity_reason>=0&&dm_tg_identity_reason<8)dg_id[dm_tg_identity_reason]++;pthread_mutex_unlock(&lock);return;} // cache/unknown/readFail全IGNORE,不清HUD快照/不续时。 | cache/unknown/readFail are all IGNORE; do not clear the HUD snapshot / do not extend the time.
unsigned char mapping[72],bindings[DM_TG_SLOTS*DM_TG_STRIDE]={0};
memcpy(mapping,m->base+MAPPING_OFFSET,sizeof mapping);
for(int i=0;i<DM_TG_SLOTS;i++)memcpy(bindings+i*DM_TG_STRIDE,m->base+BINDING_OFFSET+(selected_bank+i)*DM_TG_STRIDE,4);
uint32_t observed_id;memcpy(&observed_id,m->base+BINDING_OFFSET+regs[8],4);
dm_tg_snapshot s;
dm_tg_parse(&s,mapping,sizeof mapping,bindings,sizeof bindings,(int)selected_bank,(int)input_slot,(int)effective,observed_id,now_ns());
for(int i=0;i<DM_TG_SLOTS;i++)if(s.valid && (dead>>i&1) && !(s.portal.valid && s.portal.slot==i))s.raw_skill_id[i]=UINT32_MAX;
s.scene_epoch=scene_epoch;s.world_epoch=world_epoch;
dm_tg_group_observe(&group,&s,scene_game,scene_epoch,caller,hud,scope);latest=group.completed;dg[6]++;
pthread_mutex_unlock(&lock);
}
int dm_touch_game_attach(void) {
main_module=NULL;
pthread_mutex_lock(&lock);int supported=gate_obs_present(OBS_BINDING_GETTER);memset(&latest,0,sizeof latest);
latest.supported=supported;latest.scene_epoch=scene_epoch;latest.world_epoch=world_epoch;latest.portal.slot=-1;memset(&group,0,sizeof group);
pthread_mutex_unlock(&lock);
if(!supported)return 0;
if(g_nmod<1 || strcmp(g_mod[0].name,"main") || !g_mod[0].base ||
g_mod[0].size<BINDING_OFFSET+32*DM_TG_STRIDE || g_mod[0].size<MAPPING_OFFSET+72)return 0;
main_module=&g_mod[0];gate_obs_set(OBS_BINDING_GETTER,binding_getter);return 1;
}
-56
View File
@@ -1,56 +0,0 @@
#include "dm_touch_game_identity.h"
#include <string.h>
#ifdef __APPLE__
#include <mach/mach.h>
#include <mach/vm_map.h>
#endif
int dm_tg_vm_read(uint64_t address,void *out,size_t bytes) {
if(!out || !bytes || !address || address>UINT64_MAX-bytes)return 0;
#ifdef __APPLE__
vm_size_t copied=0;
kern_return_t rc=vm_read_overwrite(mach_task_self(),(vm_address_t)address,(vm_size_t)bytes,(vm_address_t)out,&copied);
return rc==KERN_SUCCESS && copied==bytes;
#else
(void)address;return 0;
#endif
}
/* 诊断(DM_BINDING_DIAG):最近一次的返回原因码与读到的 LR / 槽号,供 bridge 计数(v4 后快照全空,查卡在哪个返回点) | Diagnostic (DM_BINDING_DIAG): the most recent return reason code and the LR / slot number read, for bridge to count (after v4 the snapshot is entirely empty; find which return point it is stuck at) */
int dm_tg_identity_reason; uint64_t dm_tg_identity_lr; uint32_t dm_tg_identity_slot;
void dm_tg_hud_reset(dm_tg_hud_cohort *c,uint64_t world) {memset(c,0,sizeof(*c));c->world_epoch=world;}
static uint64_t add(uint64_t h,uint64_t v) {
for(int i=0;i<8;i++){h^=(unsigned char)(v>>(i*8));h*=1099511628211ull;}return h;
}
int dm_tg_hud_identity(dm_tg_hud_cohort *c,const uint64_t *regs,uint64_t base,int game,uint64_t world,
dm_tg_read_fn read_fn,uint64_t *caller,uint64_t *hud) {
dm_tg_identity_reason=1;
if(!caller || !hud)return DM_TG_IDENTITY_UNCONFIRMED;
*caller=*hud=0;
if(!c || !regs || !read_fn)return DM_TG_IDENTITY_UNCONFIRMED;
if(c->world_epoch!=world)dm_tg_hud_reset(c,world);
uint32_t arg=(uint32_t)regs[19];
dm_tg_identity_reason=3;
if(!game || !world || arg>=12 || base>UINT64_MAX-0x3e2f74)return DM_TG_IDENTITY_UNCONFIRMED;
dm_tg_identity_reason=4;
/* 原Get栈帧一次读完:fp-8=调用者x19(widget)、fp=上一帧fp、fp+8=savedLR;三者同在原Get序言刚写下的0x30字节帧里。 | Read the original Get's stack frame in one go: fp-8 = caller's x19 (widget), fp = previous frame's fp, fp+8 = savedLR; all three are in the 0x30-byte frame the original Get's prologue has just written. */
uint64_t fp=regs[29],frame[3]={0},lr=0,widget=0;
if(fp<8 || fp>UINT64_MAX-16 || !read_fn(fp-8,frame,sizeof frame))return DM_TG_IDENTITY_UNCONFIRMED;
widget=frame[0];lr=frame[2];dm_tg_identity_lr=lr-base;
if(lr!=base+0x3e2f74 || !widget || widget>UINT64_MAX-0xc90)return DM_TG_IDENTITY_UNCONFIRMED;
/* widget的enum(+b18)与alwaysGetAlt(+c90)同一对象内,一次读[+b18,+c91)。 | The widget's enum (+b18) and alwaysGetAlt (+c90) are inside the same object; read [+b18,+c91) in one go. */
uint32_t slot=UINT32_MAX;unsigned char always_alt=255;static unsigned char span[0xc91-0xb18]; /* 调用方(bridge 的门回调)持锁;不占客体线程的栈 | The caller (bridge's gate callback) holds the lock; does not use the guest thread's stack */ dm_tg_identity_reason=5;
if(read_fn(widget+0xb18,span,sizeof span)){memcpy(&slot,span,4);always_alt=span[0xc90-0xb18];}
if(slot>=6 || always_alt ||
(arg!=slot && arg!=slot+6)) { dm_tg_identity_slot=slot; return DM_TG_IDENTITY_UNCONFIRMED; }
dm_tg_identity_reason=6; dm_tg_identity_slot=slot;
if(c->widget[slot] && c->widget[slot]!=widget)return DM_TG_IDENTITY_UNCONFIRMED;
for(unsigned i=0;i<6;i++)if(i!=slot && c->widget[i]==widget)return DM_TG_IDENTITY_UNCONFIRMED;
if(c->confirmed){*caller=lr;*hud=c->hud_identity;dm_tg_identity_reason=0;return DM_TG_IDENTITY_NATIVE;}
dm_tg_identity_reason=7; /* 学习中:六槽未齐 | Learning: the six slots are not all filled yet */
c->widget[slot]=widget;c->seen|=1u<<slot;
if(c->seen==63) {
uint64_t h=add(1469598103934665603ull,world);for(int i=0;i<6;i++)h=add(h,c->widget[i]);
c->hud_identity=h?h:1;c->confirmed=1;
}
/* 首组六体只确认cohort,不把第六体借给反馈组;下一个原frame完整六组才ready。 | The first group of six only confirms the cohort and does not lend the sixth one to the feedback group; ready only once the next original frame has the complete six groups. */
return DM_TG_IDENTITY_UNCONFIRMED;
}
-18
View File
@@ -1,18 +0,0 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include "dm_touch_game_state.h"
typedef struct {
uint64_t world_epoch, widget[6], hud_identity;
uint32_t seen;
int confirmed;
} dm_tg_hud_cohort;
typedef int (*dm_tg_read_fn)(uint64_t address, void *out, size_t bytes);
/* 同进程Mach只读,不直接解引用未知FramePointer或widget堆地址。 | Same-process Mach read-only; never dereference an unknown FramePointer or widget heap address directly. */
int dm_tg_vm_read(uint64_t address, void *out, size_t bytes);
void dm_tg_hud_reset(dm_tg_hud_cohort *cohort, uint64_t world_epoch);
/* 首组六指针只确认cohort;返回身份从下一帧六组开始,不追认替换指针。 | The first group of six pointers only confirms the cohort; identity is returned starting from the next frame's six groups, and replaced pointers are not recognized retroactively. */
extern int dm_tg_identity_reason; extern uint64_t dm_tg_identity_lr; extern uint32_t dm_tg_identity_slot; /* 诊断用 | For diagnostics */
int dm_tg_hud_identity(dm_tg_hud_cohort *cohort, const uint64_t *regs,
uint64_t main_base, int game_no_panel, uint64_t world_epoch,
dm_tg_read_fn read_fn, uint64_t *caller, uint64_t *hud);
-83
View File
@@ -1,83 +0,0 @@
#include "dm_touch_game_state.h"
#include "../../host/dm_input.h"
#include <string.h>
static uint32_t u32(const unsigned char *p) {
return (uint32_t)p[0]|(uint32_t)p[1]<<8|(uint32_t)p[2]<<16|(uint32_t)p[3]<<24;
}
static uint64_t sdk(uint32_t logical) {
switch(logical) {
case 0x1000:return DM_BTN_B; case 0x2000:return DM_BTN_A;
case 0x4000:return DM_BTN_Y; case 0x8000:return DM_BTN_X;
case 0x200:return DM_BTN_R; case 0x800:return DM_BTN_ZR;
default:return 0;
}
}
static int portal(uint32_t id) { return id==359 || id==219 || id==220; }
int dm_tg_parse(dm_tg_snapshot *out,const void *mapping,size_t mapping_bytes,
const void *bank,size_t bank_bytes,int selected_bank,int getter_input_slot,
int observed_index,uint32_t observed_id,uint64_t captured_ns) {
if(!out)return 0;
memset(out,0,sizeof(*out)); out->supported=1;out->portal.slot=-1;
if(!mapping || !bank || mapping_bytes<DM_TG_FACETS*12 || bank_bytes<DM_TG_SLOTS*DM_TG_STRIDE ||
(selected_bank!=0 && selected_bank!=16) || getter_input_slot<0 || getter_input_slot>=DM_TG_SLOTS ||
observed_index!=selected_bank+getter_input_slot) return 0;
dm_tg_snapshot s=*out; unsigned normals=0,alts=0; uint64_t logicals=0;
const unsigned char *m=mapping,*b=bank;
for(int i=0;i<DM_TG_FACETS;i++) {
dm_tg_mapping *t=&s.mapping[i]; t->logical=u32(m+i*12);t->normal=u32(m+i*12+4);t->alt=u32(m+i*12+8);
uint64_t bit=sdk(t->logical);
if(!bit || (logicals&bit) || t->normal>=6 || t->alt<6 || t->alt>=12 ||
(normals&(1u<<t->normal)) || (alts&(1u<<(t->alt-6))))return 0;
logicals|=bit;normals|=1u<<t->normal;alts|=1u<<(t->alt-6);
}
for(int i=0;i<DM_TG_SLOTS;i++)s.raw_skill_id[i]=u32(b+i*DM_TG_STRIDE);
if(s.raw_skill_id[observed_index-selected_bank]!=observed_id)return 0;
/* 先替代栏,再普通栏;每栏按原slot顺序确定唯一入口。 | Alternate bar first, then the normal bar; within each bar the unique entry is determined in the original slot order. */
for(int pass=0;pass<2 && !s.portal.valid;pass++)for(int slot=pass?0:6;slot<(pass?6:12);slot++) {
if(!portal(s.raw_skill_id[slot]))continue;
for(int i=0;i<DM_TG_FACETS;i++)if((pass?s.mapping[i].normal:s.mapping[i].alt)==(uint32_t)slot) {
s.portal=(dm_tg_portal){sdk(s.mapping[i].logical)|(pass?0:DM_BTN_ZL),s.raw_skill_id[slot],slot,1};break;
}
if(s.portal.valid)break;
}
s.valid=1;s.source=DM_TG_SOURCE_NATIVE_GETTER;s.selected_bank=selected_bank;s.getter_input_slot=getter_input_slot;
s.observed_index=observed_index;s.captured_ns=captured_ns;*out=s;return 1;
}
uint64_t dm_tg_portal_mask(const dm_tg_snapshot *s,uint64_t host_now_ns) {
if(!s || !s->supported || !s->valid || !s->ready || !s->portal.valid || !s->captured_ns ||
host_now_ns<s->captured_ns || host_now_ns-s->captured_ns>DM_TG_MAX_AGE_NS)return 0;
return s->portal.buttons;
}
static uint64_t identity_add(uint64_t h,uint64_t value) {
for(int i=0;i<8;i++) { h^=(unsigned char)(value>>(i*8)); h*=1099511628211ull; }
return h;
}
static uint64_t binding_identity(const dm_tg_snapshot *s,uint64_t caller,uint64_t hud,int scope) {
uint64_t h=identity_add(1469598103934665603ull,(uint64_t)s->selected_bank);
h=identity_add(h,s->world_epoch);h=identity_add(h,caller);h=identity_add(h,hud);h=identity_add(h,(uint64_t)scope);
for(int i=0;i<DM_TG_FACETS;i++) {h=identity_add(h,s->mapping[i].logical);h=identity_add(h,s->mapping[i].normal);h=identity_add(h,s->mapping[i].alt);}
for(int i=0;i<DM_TG_SLOTS;i++)h=identity_add(h,s->raw_skill_id[i]);
return h?h:1;
}
int dm_tg_group_observe(dm_tg_group *g,const dm_tg_snapshot *table,int game,uint64_t scene,
uint64_t caller,uint64_t hud,int scope) {
if(!g || !table)return 0;
dm_tg_snapshot s=*table;s.ready=0;s.scene_epoch=scene;s.caller_identity=caller;s.hud_identity=hud;s.identity_scope=scope;
if(!s.valid || !game || !scene || !caller || !hud ||
(scope!=DM_TG_IDENTITY_NATIVE && scope!=DM_TG_IDENTITY_SYNTHETIC) ||
s.getter_input_slot<0 || s.getter_input_slot>=DM_TG_SLOTS) {
memset(g,0,sizeof(*g));g->completed=s;return 0;
}
s.binding_identity=binding_identity(&s,caller,hud,scope);s.secondary_group=s.getter_input_slot>=6;
int same=g->pending.binding_identity==s.binding_identity && g->pending.scene_epoch==scene &&
g->pending.world_epoch==s.world_epoch && g->pending.selected_bank==s.selected_bank && g->pending.caller_identity==caller && g->pending.hud_identity==hud && g->pending.identity_scope==scope &&
!memcmp(g->pending.mapping,s.mapping,sizeof s.mapping) && !memcmp(g->pending.raw_skill_id,s.raw_skill_id,sizeof s.raw_skill_id);
if(!same) { memset(g,0,sizeof(*g));g->completed=s; }
uint32_t bit=1u<<(s.getter_input_slot%6);
if(!same || g->pending.secondary_group!=s.secondary_group || (g->seen&bit)) {g->seen=0;g->started_ns=s.captured_ns;}
g->seen|=bit;s.group_seen=g->seen;s.group_started_ns=g->started_ns;g->pending=s;
if(g->seen!=63)return 0;
s.ready=1;g->completed=s;return 1;
}
-49
View File
@@ -1,49 +0,0 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
enum { DM_TG_FACETS=6, DM_TG_SLOTS=12, DM_TG_STRIDE=28,
DM_TG_MAX_AGE_NS=250000000,
DM_TG_IDENTITY_UNCONFIRMED=0, DM_TG_IDENTITY_NATIVE=1, DM_TG_IDENTITY_SYNTHETIC=2,
DM_TG_SOURCE_NONE=0, DM_TG_SOURCE_NATIVE_GETTER=1 };
typedef struct { uint32_t logical, normal, alt; } dm_tg_mapping;
typedef struct {
uint64_t buttons;
uint32_t raw_skill_id;
int slot, valid;
} dm_tg_portal;
typedef struct {
uint64_t captured_ns, group_started_ns, scene_epoch, world_epoch, binding_identity, caller_identity, hud_identity;
int ready, secondary_group, identity_scope;
uint32_t group_seen;
/* valid只证明捕获表解析完整,不证明当前武器bank、ammo或游戏施法状态。 | valid only proves the captured table parsed completely; it does not prove the current weapon bank, ammo or the game's casting state. */
int supported, valid, source, selected_bank, getter_input_slot, observed_index;
dm_tg_mapping mapping[DM_TG_FACETS];
uint32_t raw_skill_id[DM_TG_SLOTS];
dm_tg_portal portal;
} dm_tg_snapshot;
/* 只解析已复制的32位小端原表;不读取客体内存、不调用客体getter。 | Parses only the already-copied 32-bit little-endian original table; does not read guest memory and does not call guest getters. */
int dm_tg_parse(dm_tg_snapshot *out, const void *mapping, size_t mapping_bytes,
const void *bank, size_t bank_bytes, int selected_bank, int getter_input_slot,
int observed_index, uint32_t observed_id, uint64_t captured_ns);
typedef struct { dm_tg_snapshot pending, completed; uint32_t seen; uint64_t started_ns; } dm_tg_group;
/* 单normal/alt组的六facet完整且身份/scene一致才ready。身份未知则不ready。 | ready only when the six facets of a single normal/alt group are complete and identity/scene match. If identity is unknown, not ready. */
int dm_tg_group_observe(dm_tg_group *group, const dm_tg_snapshot *table, int game,
uint64_t scene_epoch, uint64_t caller_identity, uint64_t hud_identity, int identity_scope);
/* host now_ns时间域;未来/零时间戳及年龄>250ms时Portal输入归零。 | host now_ns time domain; for future/zero timestamps and age >250ms the Portal input is zeroed. */
uint64_t dm_tg_portal_mask(const dm_tg_snapshot *snapshot, uint64_t host_now_ns);
/* 生产桥:load_modules完成后的客体线程attach;UI只取锁内快照副本。 | Production bridge: attach on the guest thread after load_modules completes; the UI only takes a copy of the snapshot inside the lock. */
int dm_touch_game_attach(void);
/* 开:快照里把「绑着但玩家现在没有的技能」(如摘掉给技能的装备)按空位报;要调游戏函数,只在真游戏里开。 | On: in the snapshot, report "skills that are bound but the player does not currently have" (e.g. after taking off the gear that grants the skill) as empty slots; this calls game functions, so turn it on only in the real game. */
void dm_touch_game_live_check(int on);
int dm_touch_game_snapshot(dm_tg_snapshot *out);
void dm_touch_game_set_scene(int game_no_panel, uint64_t scene_epoch, uint64_t world_epoch);
#ifdef DM_TG_TEST_SYNTHETIC_IDENTITY
/* 仅SDK_STUB显式条件构建可提供此opaque seam;生产走strong Mach原HUD cohort。 | Only an explicitly conditional SDK_STUB build may provide this opaque seam; production uses the strong Mach original HUD cohort. */
int dm_touch_game_test_identity(const uint64_t *regs, uint64_t *caller_identity, uint64_t *hud_identity);
#endif
#ifdef __cplusplus
}
#endif
-13
View File
@@ -1,13 +0,0 @@
#pragma once
#include "dm_touch_game_state.h"
enum { DM_TA_UNKNOWN=0, DM_TA_EMPTY=1, DM_TA_GLYPH=2, DM_TA_ATLASES=9 };
typedef struct { const char *asset; int width,height,frame_width,pitch,count; } dm_ta_atlas;
typedef struct { int x,y,width,height; } dm_ta_frame;
typedef struct { int status,atlas,normal_frame,pressed_frame,slot,effective_slot; uint32_t raw_skill_id; const char *reason; } dm_ta_glyph;
extern const dm_ta_atlas dm_ta_atlases[DM_TA_ATLASES];
extern const char dm_ta_manifest_sha[],dm_ta_geometry_sha[],dm_ta_binding_sha[];
dm_ta_glyph dm_ta_skill(uint32_t raw_skill_id);
dm_ta_glyph dm_ta_current(const dm_tg_snapshot *s,uint64_t sdk_button,uint64_t host_now_ns);
/* 同上,skill_set=1 取第二套(alt 槽,原版按住 ZL) | Same as above; skill_set=1 takes the second set (alt slots, hold ZL in the original game) */
dm_ta_glyph dm_ta_current_set(const dm_tg_snapshot *s,uint64_t sdk_button,uint64_t host_now_ns,int skill_set);
int dm_ta_frame_at(int atlas,int frame,dm_ta_frame *out);