Turn snap-back smoothing and gamepad turning feel (r42); close several slow memory accumulations; Mac App mouse, language switch and warm-up list
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
3.3.94012-r41
|
||||
3.3.94012-r42
|
||||
|
||||
+47
-3
@@ -358,10 +358,12 @@ void mtl_pool_add(const void *mem, uint64_t size) {
|
||||
|
||||
void mtl_pool_del(const void *mem) {
|
||||
g_reg_gen++;
|
||||
id<MTLBuffer> gone = nil;
|
||||
pthread_mutex_lock(&g_mu);
|
||||
for (int i = 0; i < g_npool; i++)
|
||||
if (g_pools[i].key == mem) { [g_keep removeObject:g_pools[i].buf]; g_pools[i] = g_pools[--g_npool]; break; }
|
||||
if (g_pools[i].key == mem) { gone = g_pools[i].buf; [g_keep removeObject:gone]; g_pools[i] = g_pools[--g_npool]; break; }
|
||||
pthread_mutex_unlock(&g_mu);
|
||||
defer_obj_release(gone); // 退役:等用过它的提交完成后放掉,并移出驻留集(原先只从 g_keep 摘掉——驻留集强持有它,零拷贝缓冲对象永远不销毁) | retire: release after the submissions that used it complete, and remove from the residency set (it used to be only removed from g_keep - the residency set holds it strongly, so the zero-copy buffer object was never destroyed)
|
||||
}
|
||||
|
||||
int mtl_addr(uint64_t addr, uint64_t len, void **buf, uint64_t *off) {
|
||||
@@ -405,6 +407,7 @@ typedef struct { int n; vis_slot s[]; } vis_list;
|
||||
typedef struct { __strong id<MTLBuffer> buf; uint64_t fence; } vis_buf;
|
||||
static vis_buf g_vis_ring[4]; static int g_vis_ring_n, g_vis_ring_i = -1;
|
||||
static id<MTLBuffer> g_vis; static uint32_t g_vis_n; // 本次提交的可见性缓冲与已用槽数 | This submission's visibility buffer and number of slots used
|
||||
static int vis_in_ring(id<MTLBuffer> b) { for (int i = 0; i < g_vis_ring_n; i++) if (g_vis_ring[i].buf == b) return 1; return 0; }
|
||||
static int g_vis_on, g_vis_counting, g_vis_cur = -1; static uint64_t g_vis_cur_pass;
|
||||
static vis_slot *g_vs; static int g_nvs, g_vscap; // 自上次清零以来的槽 | Slots since the last reset
|
||||
static uint64_t g_cnt_report[32], g_cnt_reset[32]; // 各计数器类型的报告 / 清零次数(诊断) | Report / reset counts per counter type (diagnostics)
|
||||
@@ -496,6 +499,7 @@ void mtl_sub_begin(void) {
|
||||
if (pick < 0) { uint64_t oldest = UINT64_MAX; for (int i = 0; i < 4; i++) if (g_vis_ring[i].fence < oldest) { oldest = g_vis_ring[i].fence; pick = i; } if (oldest > g_done) mtl_wait(oldest, UINT64_MAX); }
|
||||
g_vis_ring_i = pick; g_vis_ring[pick].fence = UINT64_MAX;
|
||||
if (!g_vis_ring[pick].buf) { g_vis_ring[pick].buf = [g_dev newBufferWithLength:VIS_SLOTS * 8 options:MTLResourceStorageModeShared]; res_add(g_vis_ring[pick].buf); }
|
||||
if (g_vis && !vis_in_ring(g_vis)) defer_obj_release(g_vis); // 上次提交留下的溢出缓冲(见 g_vis_n >= VIS_SLOTS 那一处):退役,否则它一直留在驻留集里 | the overflow buffer left by the previous submission (see the place with g_vis_n >= VIS_SLOTS): retire it, otherwise it stays in the residency set forever
|
||||
g_vis = g_vis_ring[pick].buf;
|
||||
void pg_sub_begin_ext(uint64_t fence); pg_sub_begin_ext(g_fence + 1);
|
||||
void arena_begin(void); arena_begin();
|
||||
@@ -1243,6 +1247,7 @@ static void res_census(unsigned long long frame, unsigned long long rss_mb) {
|
||||
nl[0], bl[0] >> 20, nl[1], bl[1] >> 20, nr[0], br[0] >> 20, nr[1], br[1] >> 20);
|
||||
}
|
||||
}
|
||||
unsigned long long mtl_gpu_allocated_mb(void) { id<MTLDevice> d = g_dev; return d ? (unsigned long long)(d.currentAllocatedSize >> 20) : 0; } // 显卡已分配(图形层还没起时 0);任何线程可调 | GPU allocated (0 before the graphics layer starts); callable from any thread
|
||||
void mtl_mem_stat(unsigned long long frame, unsigned long long rss_mb, int heap_ok, unsigned long long heap_mb, unsigned long long heap_free_mb, unsigned long long heap_maxblk_kb) {
|
||||
if (g_res_census > 0) res_census(frame, rss_mb);
|
||||
static unsigned long long last_rss, last_gpu, last_frame, last_hfree, last_hmax; static int lines; unsigned long long gpu = (unsigned long long)(g_dev.currentAllocatedSize >> 20);
|
||||
@@ -1799,7 +1804,11 @@ static id<MTL4RenderCommandEncoder> rp_begin_ex(int clear_only) {
|
||||
g_enc_pso = nil; g_enc_dss = nil;
|
||||
}
|
||||
if (g_vis_on) {
|
||||
if (!g_vis || g_vis_n >= VIS_SLOTS) { if (g_vis) defer_obj_release(g_vis); g_vis = [g_dev newBufferWithLength:VIS_SLOTS * 8 options:MTLResourceStorageModeShared]; res_add(g_vis); g_vis_n = 0; }
|
||||
// 槽用满(单次提交超过 VIS_SLOTS 个计数通道):另建一块溢出缓冲接着用。环里的缓冲不许交去退役(它还要轮着用,退役会把它移出驻留集);
|
||||
// 退役的只能是上一块溢出缓冲。溢出缓冲本身在下次提交换回环里的缓冲时退役(mtl_sub_begin)
|
||||
// Slots used up (one submission exceeds VIS_SLOTS counting passes): create an overflow buffer and continue with it. Buffers in the ring must not be handed to retirement (they are still used in rotation, and retiring would remove them from the residency set);
|
||||
// only the previous overflow buffer may be retired. The overflow buffer itself is retired when the next submission switches back to a ring buffer (mtl_sub_begin)
|
||||
if (!g_vis || g_vis_n >= VIS_SLOTS) { if (g_vis && !vis_in_ring(g_vis)) defer_obj_release(g_vis); g_vis = [g_dev newBufferWithLength:VIS_SLOTS * 8 options:MTLResourceStorageModeShared]; res_add(g_vis); g_vis_n = 0; }
|
||||
pd.visibilityResultBuffer = g_vis;
|
||||
}
|
||||
g_enc_vis = 0; g_enc_has_vis = g_vis_on;
|
||||
@@ -4142,7 +4151,7 @@ static int bloomq_make_pipeline(MTLPixelFormat fmt) {
|
||||
static int bloomq_capture(void) {
|
||||
uint64_t ser; int lv, sl; if (!bloomq_target(&ser, &lv, &sl) || !g_bloomq.s_tex) return 0;
|
||||
id<MTLTexture> base = tex_mtl(R.rt.color[0]), src = tex_mtl(g_bloomq.s_tex); if (!base || !src) return 0;
|
||||
id<MTLTexture> dst = base; if (lv || sl) { static id<MTLTexture> vb; static int vl, vs; if (vb != base || vl != lv || vs != sl) { g_bloomq_view = [base newTextureViewWithPixelFormat:base.pixelFormat textureType:base.textureType levels:NSMakeRange(lv, 1) slices:NSMakeRange(sl, 1)]; if (g_bloomq_view) res_add(g_bloomq_view); vb = base; vl = lv; vs = sl; } dst = g_bloomq_view; }
|
||||
id<MTLTexture> dst = base; if (lv || sl) { static id<MTLTexture> vb; static int vl, vs; if (vb != base || vl != lv || vs != sl) { defer_obj_release(g_bloomq_view); /* 旧视图退役(原先直接被覆盖:留在驻留集里,连带钉住旧底图) | retire the old view (it used to be overwritten directly: it stayed in the residency set and pinned the old base texture with it) */ g_bloomq_view = [base newTextureViewWithPixelFormat:base.pixelFormat textureType:base.textureType levels:NSMakeRange(lv, 1) slices:NSMakeRange(sl, 1)]; if (g_bloomq_view) res_add(g_bloomq_view); vb = base; vl = lv; vs = sl; } dst = g_bloomq_view; }
|
||||
if (!dst || !bloomq_make_pipeline(dst.pixelFormat)) return 0;
|
||||
rp_end();
|
||||
MTL4RenderPassDescriptor *rp = [MTL4RenderPassDescriptor new]; rp.colorAttachments[0].texture = dst; rp.colorAttachments[0].loadAction = MTLLoadActionDontCare; rp.colorAttachments[0].storeAction = MTLStoreActionStore;
|
||||
@@ -5200,6 +5209,40 @@ static void grab_present(id<MTLTexture> src, const int crop[4], CGSize sz) {
|
||||
CGImageRelease(img); CGContextRelease(ctx); CGColorSpaceRelease(cs); }];
|
||||
[cb2 commit];
|
||||
}
|
||||
// ---------- 测试:连拍(量画面连续性用,缺省不动;触点脚本步骤「<时刻> burst <帧数> <目录名>」触发,目录建在 Documents 下)----------
|
||||
// 连续 N 帧(上限 BURST_MAX)各拷一块上屏前的游戏画面(屏幕中心、边长 = 画面高 × 0.6 的方块,原始像素):抓的那一帧只多一次显存拷贝、不等显卡,
|
||||
// 帧间隔不受影响(Mac 实测 16.5–16.9 ms);全部抓完后台线程写盘:f000.raw…(宽 × 高 × 4 字节)+ meta.txt(每帧的出图帧号、墙钟、客体时钟、本地玩家逻辑位置)。
|
||||
// 分析:dm/ios/tools/burst_sad.py <目录>(逐帧画面位移与逻辑位移对照)
|
||||
// ---------- Test: burst capture (for measuring picture continuity, inactive by default; triggered by the touch-script step "<time> burst <frames> <directory name>", directory created under Documents) ----------
|
||||
// For N consecutive frames (limit BURST_MAX) copy a block of the game picture before presentation (a square at the screen centre with side = picture height x 0.6, raw pixels): a captured frame costs only one more GPU memory copy and does not wait for the GPU,
|
||||
// so the frame interval is unaffected (16.5–16.9 ms measured on a Mac); after all frames are captured a background thread writes to disk: f000.raw... (width x height x 4 bytes) + meta.txt (presented frame number, wall clock, guest clock and logical position of the local player for each frame).
|
||||
// Analysis: dm/ios/tools/burst_sad.py <directory> (per-frame picture displacement compared with logical displacement)
|
||||
__attribute__((weak)) int dm_diag_player_fixed(uint32_t *x, uint32_t *y) { (void)x; (void)y; return 0; } // 宿主 diag.c 提供强定义 | the strong definition is provided by the host's diag.c
|
||||
#define BURST_MAX 512 /* 512 帧约 415 MB(450×450×4 一帧),只在 Mac 上给这么大;真机别超过 128 | 512 frames is about 415 MB (450x450x4 per frame), this much only on a Mac; do not exceed 128 on a device */
|
||||
static int g_burst_left, g_burst_n; static char g_burst_dir[700];
|
||||
static id<MTLBuffer> g_burst_buf[BURST_MAX]; static id<MTLCommandBuffer> g_burst_cb[BURST_MAX]; static uint64_t g_burst_fr[BURST_MAX], g_burst_ns[BURST_MAX], g_burst_gns[BURST_MAX]; static uint32_t g_burst_px[BURST_MAX], g_burst_py[BURST_MAX];
|
||||
static size_t g_burst_w, g_burst_h; static unsigned long g_burst_fmt;
|
||||
void dm_gfx_burst(int n, const char *dir) { if (g_burst_left > 0 || n <= 0) return; if (n > BURST_MAX) n = BURST_MAX; strlcpy(g_burst_dir, dir, sizeof g_burst_dir); g_burst_n = n; g_burst_left = n; }
|
||||
static void burst_grab(id<MTLTexture> src) {
|
||||
uint64_t guest_ns(void);
|
||||
int i = g_burst_n - g_burst_left; size_t dm_ = src.width, sh_ = src.height, c = sh_ * 6 / 10; if (c > dm_) c = dm_;
|
||||
g_burst_w = c; g_burst_h = c; g_burst_fmt = (unsigned long)src.pixelFormat;
|
||||
id<MTLBuffer> buf = [g_dev newBufferWithLength:c * c * 4 options:MTLResourceStorageModeShared]; id<MTLCommandBuffer> cb = q_cb(); id<MTLBlitCommandEncoder> b = [cb blitCommandEncoder];
|
||||
[b copyFromTexture:src sourceSlice:0 sourceLevel:0 sourceOrigin:MTLOriginMake((dm_ - c) / 2, (sh_ - c) / 2, 0) sourceSize:MTLSizeMake(c, c, 1) toBuffer:buf destinationOffset:0 destinationBytesPerRow:c * 4 destinationBytesPerImage:c * c * 4];
|
||||
[b endEncoding]; [cb commit];
|
||||
g_burst_buf[i] = buf; g_burst_cb[i] = cb; g_burst_fr[i] = g_present_n; g_burst_ns[i] = now_ns(); g_burst_gns[i] = guest_ns(); g_burst_px[i] = g_burst_py[i] = 0; dm_diag_player_fixed(&g_burst_px[i], &g_burst_py[i]);
|
||||
if (--g_burst_left == 0) { int n = g_burst_n; size_t w = g_burst_w, h = g_burst_h; unsigned long fmt = g_burst_fmt; NSString *dir = [NSString stringWithUTF8String:g_burst_dir];
|
||||
dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
|
||||
[[NSFileManager defaultManager] createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
NSMutableString *meta = [NSMutableString stringWithFormat:@"w %zu h %zu fmt %lu n %d\n", w, h, fmt, n];
|
||||
for (int k = 0; k < n; k++) { [g_burst_cb[k] waitUntilCompleted];
|
||||
[[NSData dataWithBytes:g_burst_buf[k].contents length:w * h * 4] writeToFile:[dir stringByAppendingPathComponent:[NSString stringWithFormat:@"f%03d.raw", k]] atomically:NO];
|
||||
[meta appendFormat:@"%d frame %llu ns %llu guest_ns %llu px %.4f py %.4f\n", k, (unsigned long long)g_burst_fr[k], (unsigned long long)g_burst_ns[k], (unsigned long long)g_burst_gns[k], g_burst_px[k] / 65536.0, g_burst_py[k] / 65536.0];
|
||||
g_burst_buf[k] = nil; g_burst_cb[k] = nil; }
|
||||
[meta writeToFile:[dir stringByAppendingPathComponent:@"meta.txt"] atomically:YES encoding:NSUTF8StringEncoding error:nil];
|
||||
MLOG("测试:连拍 %d 帧写完 %s(%zux%zu 格式 %lu)", n, dir.UTF8String, w, h, fmt); });
|
||||
}
|
||||
}
|
||||
void dm_gfx_shot_at(long k, const char *path) {
|
||||
pthread_mutex_lock(&g_shotq_mu);
|
||||
if (g_nshotq < SHOTQ_MAX) { g_shotq[g_nshotq].frame = g_present_n + (uint64_t)(k > 0 ? k : 0); strlcpy(g_shotq[g_nshotq].path, path, sizeof g_shotq[0].path); g_nshotq++; }
|
||||
@@ -5550,6 +5593,7 @@ static int present_now(const tex_t *t, double period, uint64_t frame, uint64_t t
|
||||
for (int i = 0; i < g_nshotq;) if (g_present_n >= g_shotq[i].frame) { mtl_finish_gpu(); shot(src, g_shotq[i].path, 1, crop); g_shotq[i] = g_shotq[--g_nshotq]; } else i++;
|
||||
pthread_mutex_unlock(&g_shotq_mu);
|
||||
|
||||
if (g_burst_left > 0) burst_grab(src); // 测试:连拍 | test: burst capture
|
||||
CAMetalLayer *layer = (__bridge CAMetalLayer *)front_metal_layer();
|
||||
if (!layer) return 0;
|
||||
if (g_present_layer_resident != layer) { [g_q4 addResidencySet:layer.residencySet]; g_present_layer_resident = layer; }
|
||||
|
||||
+9
-2
@@ -1,8 +1,13 @@
|
||||
DM_ROOT ?= $(HOME)/dm-work
|
||||
CFLAGS=-O1 -g -Wall -Wno-unused-function
|
||||
# 最低系统版本:图形后端(gfx/nvn/nvn_mtl.m)整个建在 Metal 4 上,macOS 26 才有;不显式写的话编译器取本机系统的版本。
|
||||
# 打包脚本(tools/mac_app.sh)用 print-macos-min 取同一个数写进 Info.plist,并核程序本体里的数与它相等
|
||||
# Minimum system version: the graphics backend (gfx/nvn/nvn_mtl.m) is built entirely on Metal 4, which exists from macOS 26; without stating it explicitly the compiler takes the version of the local system.
|
||||
# The packaging script (tools/mac_app.sh) takes the same number through print-macos-min, writes it into Info.plist, and checks that the number in the executable equals it
|
||||
MACOS_MIN ?= 26.0
|
||||
CFLAGS=-O1 -g -Wall -Wno-unused-function -mmacosx-version-min=$(MACOS_MIN)
|
||||
# 服务层接管 hle_*.c 按通配纳入:新增文件不改这一行(免合并冲突)
|
||||
# Service-layer takeover hle_*.c files are included by wildcard: adding a file does not touch this line (avoids merge conflicts)
|
||||
SRC=main.c loader.c hle.c crash.c diag.c thread.c memstat.m dm_cursor.c dm_cursor_item.c dm_world.c dm_textinput.c dm_update.c dm_actions.c dm_namegen.c dm_cloudsync.c dm_custom.c dm_elysium.c dm_bossrush.c dm_pages.c dm_vault.c dm_vault_ui.c dm_kills.c dm_textbox.c dm_textbox_core.c dm_potpick.c dm_lootfilter.c dm_autobuff.c dm_beltauto.c dm_padmode.c dm_pouch.c dm_drophaptic.c dm_freetp.c dm_townwp.c dm_shoprefresh.c dm_runeword.c dm_uiscreen.c dm_dropfilter.c dm_hud.c dm_rift.c dm_rift_ui.c dm_bright.c touch_mac.c romfs_validate.c ../ios/Sources/dm_touch_controls.c $(sort $(wildcard hle_*.c)) front_mac.m app_mac.m ../ios/Sources/dm_gamepad.m entry.S dm_i18n.c
|
||||
SRC=main.c loader.c hle.c crash.c diag.c thread.c memstat.m dm_cursor.c dm_cursor_item.c dm_world.c dm_textinput.c dm_update.c dm_actions.c dm_namegen.c dm_cloudsync.c dm_custom.c dm_elysium.c dm_bossrush.c dm_pages.c dm_vault.c dm_vault_ui.c dm_kills.c dm_textbox.c dm_turnsmooth.c dm_textbox_core.c dm_potpick.c dm_lootfilter.c dm_autobuff.c dm_beltauto.c dm_padmode.c dm_pouch.c dm_drophaptic.c dm_freetp.c dm_townwp.c dm_shoprefresh.c dm_runeword.c dm_uiscreen.c dm_dropfilter.c dm_hud.c dm_rift.c dm_rift_ui.c dm_bright.c touch_mac.c romfs_validate.c ../ios/Sources/dm_touch_controls.c $(sort $(wildcard hle_*.c)) front_mac.m app_mac.m ../ios/Sources/dm_gamepad.m entry.S dm_i18n.c
|
||||
# NVN 空设备 + nn::vi(dm/gfx/)
|
||||
# 按通配纳入 dm/gfx 与 dm/gfx/nvn 下的源(tests/ metal/ 不进宿主):新增文件不改这一行
|
||||
# NVN null device + nn::vi (dm/gfx/)
|
||||
@@ -13,6 +18,8 @@ GFX_H=$(sort $(wildcard ../gfx/nvn/*.h ../gfx/nvn/include/*.h ../gfx/tex/*.h))
|
||||
# Third party: only the decompression-related sources of libdeflate are built (TACT BLTE zlib blocks, hle_tact.c)
|
||||
LIBDEFLATE=../third_party/libdeflate/lib/deflate_decompress.c ../third_party/libdeflate/lib/zlib_decompress.c ../third_party/libdeflate/lib/adler32.c ../third_party/libdeflate/lib/utils.c ../third_party/libdeflate/lib/arm/cpu_features.c
|
||||
.DEFAULT_GOAL := dmhost # 下面先写了表头生成规则,缺省目标要明说(否则 make 只生成表头、不编宿主) | The header generation rules are written first below, so the default goal must be stated explicitly (otherwise make only generates the headers and does not build the host)
|
||||
print-macos-min:
|
||||
@echo $(MACOS_MIN)
|
||||
# 由原版表生成的头文件:不进仓库,构建时从玩家自己的游戏文件(Switch 版 3.3.94012 的 Update/RomFS)生成;路径用环境变量 DM_ROMFS_SRC 指定
|
||||
# Headers generated from the original game's tables: not checked into the repository, generated at build time from the player's own game files (Update/RomFS of Switch version 3.3.94012); the path is given by the environment variable DM_ROMFS_SRC
|
||||
ROMFS?=$(or $(DM_ROMFS_SRC),$(DM_ROOT)/data/switch/3.3.94012/Update/RomFS)
|
||||
|
||||
@@ -94,6 +94,7 @@ int dm_app_bootstrap(int *argc, char ***argv) {
|
||||
if (!rom) { LOG("App:没有选资源文件夹,退出"); exit(0); }
|
||||
[ud setObject:rom forKey:kRomfsKey];
|
||||
}
|
||||
{ void dm_custom_init(const char *dir); dm_custom_init(sup.fileSystemRepresentation); } // 自定义设置文件的目录现在就给(同 iOS 壳):不给的话要等存档挂上才知道在哪,而语言开关正是在挂存档那一刻读它改游戏语言的——晚了开关就不生效 | the directory of the custom settings file is given right now (same as the iOS shell): otherwise it is only known once the save is mounted, and the language switch is read to change the game language at exactly that moment - too late and the switch has no effect
|
||||
setenv("DM_WINDOW", "1", 1); setenv("DM_APP", "1", 1);
|
||||
setenv("DM_SAVE", save.fileSystemRepresentation, 1); setenv("DM_TEMP", temp.fileSystemRepresentation, 1);
|
||||
setenv("DM_ROMFS", rom.fileSystemRepresentation, 1); setenv("DM_ROOT", sup.fileSystemRepresentation, 1);
|
||||
|
||||
@@ -585,6 +585,10 @@ void inflate_bench_maybe(void) {
|
||||
// 5 unit tables (128 buckets, next=+0x158) + global seed G+0x1a8, merged in stable ascending (type, id) order into each cell's FNV-1a 64. Unreadable pointers follow the ground-truth Reader semantics (failed read = None).
|
||||
// One JSON line per tick (fields in the same order and with the same separators as swtick.py's json.dumps); each tick number is taken only once, a gap reports a failure; exits normally once DM_TICKS_N ticks are recorded. When off, no callback is attached to the observation gate.
|
||||
static int tk_rd(uint64_t a, void *buf, size_t n);
|
||||
static _Atomic uint64_t g_player_path; // 本地玩家的路径头(状态泵每拍更新) | path head of the local player (updated by the state pump every tick)
|
||||
// 本地玩家的逻辑位置(16.16 定点,格):给图形层的连拍逐帧记一份,好和画面位移对照。读不到返回 0
|
||||
// Logical position of the local player (16.16 fixed point, tiles): the graphics layer's burst capture records one per frame so it can be compared with on-screen displacement. Returns 0 when it cannot be read
|
||||
int dm_diag_player_fixed(uint32_t *x, uint32_t *y) { uint64_t pp = atomic_load(&g_player_path); uint32_t c[2]; if (!pp || !tk_rd(pp, c, 8)) return 0; *x = c[0]; *y = c[1]; return 1; }
|
||||
static FILE *g_tkfp; static int g_tkfull; static long g_tkleft = -1; static int64_t g_tklast = -1; static uint64_t g_tkt0; static unsigned g_tkreads;
|
||||
static FILE *g_spfp;
|
||||
// ---- 难度档位与 HUD 数字(dm_hud.h):都在拍入口(游戏线程)读写客体,前端经 dm_hud_get / dm_hud_request_players 交互 ----
|
||||
@@ -808,6 +812,7 @@ static void hud_tick(uint64_t G) { // 每拍:受控玩家等级 / 本
|
||||
h.level = (int)lv;
|
||||
{ uint64_t pp = 0, r1 = 0, r2 = 0, lvl = 0; uint16_t c[4] = {0}; uint32_t no = 0; // 坐标:单位 +0x38 → 路径头 4 个 16 位(x 小数 / x / y 小数 / y) | Coordinates: unit +0x38 → 4 16-bit values at the head of the path (x fraction / x / y fraction / y)
|
||||
if (tk_rd(player + 0x38, &pp, 8) && tk_rd(pp, c, 8)) { h.x = c[1]; h.y = c[3]; }
|
||||
atomic_store(&g_player_path, pp); // 连拍(dm_gfx_burst)逐帧读位置用 | used by burst capture (dm_gfx_burst) to read the position per frame
|
||||
// 区域号(levels.txt 的 Id:1 = 罗格营地,2 = 鲜血荒地…):路径 +0x20 → 所在房间 +0x18 → 区域房间 +0x90 → 区域 +0x1f8
|
||||
// Area number (Id in levels.txt: 1 = Rogue Encampment, 2 = Blood Moor...): path +0x20 → current room +0x18 → area room +0x90 → area +0x1f8
|
||||
if (pp && tk_rd(pp + 0x20, &r1, 8) && tk_rd(r1 + 0x18, &r2, 8) && tk_rd(r2 + 0x90, &lvl, 8) && tk_rd(lvl + 0x1f8, &no, 4) && no < 200) h.area = (int)no; }
|
||||
@@ -1890,6 +1895,7 @@ void ticks_install(void) {
|
||||
if (gate_obs_present(OBS_TICK)) gate_obs_set(OBS_TICK, tick_gate_product);
|
||||
else LOG("【红】产物没有拍入口观测门 OBS_TICK:底栏数字 / 难度条 / 动态 3D 比例(dm_ingame_now)都不工作");
|
||||
{ module_t *tm = main_mod(); void dm_textbox_install(uint8_t *); if (tm) dm_textbox_install((uint8_t *)tm->base); } // 普通文字框里的注释颜色码(dm_textbox.c,观测门 14) | Annotation color codes in ordinary text boxes (dm_textbox.c, observation gate 14)
|
||||
{ module_t *tm = main_mod(); void dm_turnsmooth_install(uint8_t *); if (tm) dm_turnsmooth_install((uint8_t *)tm->base); } // 转向回跳平滑 / 模型转身参数读取(dm_turnsmooth.c,观测门 19 / 20) | turn snap-back smoothing / reading the model turning parameters (dm_turnsmooth.c, observation gates 19 / 20)
|
||||
if (e || rp || lg || sp) { // DM_C2S_LOG 也挂拍入口:系统类消息的拍号要从 G 读 | DM_C2S_LOG also hooks the tick entry: the tick number of system-class messages has to be read from G
|
||||
if (!gate_obs_present(OBS_TICK)) die("DM_TICKS / DM_STATE / DM_C2S_REPLAY / DM_C2S_LOG:产物没有拍入口观测门 OBS_TICK(需 r8 起的产物)");
|
||||
gate_obs_set(OBS_TICK, tick_gate);
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ module_t *module_of(const void *p);
|
||||
uint64_t gate_dispatch(uint64_t ret_addr, uint64_t *regs);
|
||||
// 观测门(改写器 OBS 表;编号与 patch_nso.py 一致):只读回调,挂上即在门命中时调用
|
||||
// Observation gates (rewriter OBS table; numbering matches patch_nso.py): read-only callbacks, called on a gate hit once attached
|
||||
enum { OBS_UIMSG = 1, OBS_TICK = 2, OBS_C2S = 3, OBS_C2S_SYS = 4, OBS_SETLANG = 5, OBS_TARGET_RANK = 7, OBS_UI_PROJECT = 8, OBS_FREEZE_WORLD = 10, OBS_FREEZE_CLIENT = 11, OBS_FREEZE_ANIM = 12, OBS_FREEZE_RENDER = 13, OBS_TEXTBOX = 14, OBS_EVENT_MSG = 15, OBS_LEVEL_WARP = 16, OBS_QUEST_KILL = 17, OBS_NOTICE_INPUT = 18, OBS_MAX = 19 }; // 6 = iOS 绑定读取(dm_touch_game_bridge.c) | 6 = iOS binding read (dm_touch_game_bridge.c)
|
||||
enum { OBS_UIMSG = 1, OBS_TICK = 2, OBS_C2S = 3, OBS_C2S_SYS = 4, OBS_SETLANG = 5, OBS_TARGET_RANK = 7, OBS_UI_PROJECT = 8, OBS_FREEZE_WORLD = 10, OBS_FREEZE_CLIENT = 11, OBS_FREEZE_ANIM = 12, OBS_FREEZE_RENDER = 13, OBS_TEXTBOX = 14, OBS_EVENT_MSG = 15, OBS_LEVEL_WARP = 16, OBS_QUEST_KILL = 17, OBS_NOTICE_INPUT = 18, OBS_ERR_SMOOTH = 19, OBS_MODEL_YAW = 20, OBS_MAX = 21 }; // 6 = iOS 绑定读取(dm_touch_game_bridge.c) | 6 = iOS binding read (dm_touch_game_bridge.c)
|
||||
void gate_obs_set(int id, void (*fn)(const uint64_t *regs));
|
||||
int gate_obs_present(int id);
|
||||
void dm_quiet_difficulty_msg(int on); // 秘境局里拦原版「游戏难度设为 N」提示(观测门 15,diag.c) | In a rift run, block the original game's 「游戏难度设为 N」(Game difficulty set to N) message (observation gate 15, diag.c)
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
// verified one by one, and nothing is written on a mismatch (wrong game version).
|
||||
#include "hle.h"
|
||||
#include "dm_hud.h"
|
||||
#include "dm_input.h"
|
||||
#include "dm_i18n.h"
|
||||
#include "dm_modetx.h"
|
||||
#include "dm_mode_items.h"
|
||||
@@ -294,6 +295,40 @@ static uint64_t legend_find(uint8_t *b, uint64_t lg, int act) { // 提示条
|
||||
return 0;
|
||||
}
|
||||
static int legend_ours(uint64_t e, const char *text) { size_t n = strlen(text); return rd8(e + 0x18) == n && !memcmp((const void *)(uintptr_t)rd8(e + 0x10), text, n); }
|
||||
// 鼠标点在按键提示条的某一条上 = 按它那个键(Mac App:手柄版布局里底部的「ⓧ 默认 ⓑ 关闭菜单」是提示、不是按钮,鼠标点它没有任何响应)。
|
||||
// 提示条控件(局内底部那条虚表 main+0x20b7960,前端各页的 main+0x20b7a30)自己画、没有子控件,读不到每一条的矩形:点落在控件里时按它的排法估——整排居中,每条 = 键帽 + 字,
|
||||
// 字宽按字数算(全角 1 个字宽、半角约半个),条与条之间留空。量自 1600×900 截图:字宽约屏高的 2.8%,键帽连间隔约 1.3 个字宽,条间约 0.4–0.95 个字宽(取 0.67)。
|
||||
// 返回要按的手柄键(DM_BTN_*,0 = 没点在提示条的条目上)。只许游戏主线程调
|
||||
// A mouse click on one entry of the key-hint bar = pressing that key (Mac App: in the gamepad layout the bottom "X Default B Close Menu" is a hint, not a button, and clicking it does nothing).
|
||||
// The hint-bar widget (vtable main+0x20b7960 for the in-game bottom bar, main+0x20b7a30 for the front-end pages) draws itself and has no child widgets, so the rectangle of each entry cannot be read: when the click lands inside the widget, estimate by its layout - the whole row is centred, each entry = key cap + text,
|
||||
// text width counted by characters (one glyph width for full-width, about half for half-width), with a gap between entries. Measured on 1600x900 screenshots: glyph width about 2.8% of screen height, key cap plus spacing about 1.3 glyph widths, gap between entries about 0.4–0.95 glyph widths (0.67 used).
|
||||
// Returns the gamepad key to press (DM_BTN_*, 0 = the click is not on an entry of the hint bar). Call only from the game main thread
|
||||
static uint64_t legend_at(uint8_t *b, uint64_t w, uint64_t xy, int dep) {
|
||||
if (!w || dep > 8 || !*(uint8_t *)(uintptr_t)(w + 0x50) || !*(uint8_t *)(uintptr_t)(w + 0x51)) return 0;
|
||||
uint64_t vt = rd8(w) - (uint64_t)(uintptr_t)b; if (vt == 0x20b7960 || vt == 0x20b7a30) return /* 局内底部那条(会滚的)/ 前端各页自己的那条,条目数组同一个位置 | the in-game bottom bar (the scrolling one) / each front-end page's own bar: the entry array is at the same position */ rd8(w + 0x90) && (((int (*)(uint64_t, uint64_t))rd8(rd8(w) + 0x48))(w, xy) & 1) ? w : 0;
|
||||
uint64_t ch = rd8(w + 0x58), n = rd8(w + 0x60); for (uint64_t i = n < 256 ? n : 0; ch && i-- > 0; ) { uint64_t r = legend_at(b, rd8(ch + 8 * i), xy, dep + 1); if (r) return r; }
|
||||
return 0;
|
||||
}
|
||||
uint64_t dm_padmode_legend_click(float nx, float ny) {
|
||||
extern module_t g_mod[]; extern int g_nmod; uint8_t *b = NULL; for (int i = 0; i < g_nmod; i++) if (!strcmp(g_mod[i].name, "main")) b = (uint8_t *)g_mod[i].base;
|
||||
if (!b || !g_cur) return 0; int W = *(int32_t *)(b + 0x211da38), H = *(int32_t *)(b + 0x211da3c); uint64_t root = rd8((uint64_t)(uintptr_t)(b + 0x2f05458)); if (!root || W <= 0 || H <= 0) return 0;
|
||||
int x = (int)(nx * W), y = (int)(ny * H); uint64_t lg = legend_at(b, root, (uint64_t)(uint32_t)x | ((uint64_t)(uint32_t)y << 32), 0); if (!lg) return 0;
|
||||
uint64_t arr = rd8(lg + 0x88), n = rd8(lg + 0x90); if (!arr || n > 12) return 0;
|
||||
float em = H * 0.0281f, gap = 0.67f * em, wd[12], tot = 0;
|
||||
for (uint64_t i = 0; i < n; i++) { const uint8_t *t = (const uint8_t *)(uintptr_t)rd8(arr + 0x40 * i + 0x10); uint64_t tn = rd8(arr + 0x40 * i + 0x18); float tw = 0;
|
||||
for (uint64_t k = 0; t && k < tn && k < 96; k++) { if ((t[k] & 0xc0) == 0x80) continue; tw += t[k] < 0x80 ? (t[k] == ' ' ? 0.3f : 0.55f) : 1.0f; }
|
||||
wd[i] = (1.3f + tw) * em; tot += wd[i] + (i ? gap : 0); }
|
||||
float x0 = W / 2.0f - tot / 2; int hit = -1; for (uint64_t i = 0; i < n; i++) { if (x >= x0 - gap / 2 && x < x0 + wd[i] + gap / 2) hit = (int)i; x0 += wd[i] + gap; }
|
||||
if (hit < 0) return 0;
|
||||
uint64_t e = arr + 0x40 * (uint64_t)hit; uint32_t gl = *(uint32_t *)(uintptr_t)e; uint64_t btn = 0;
|
||||
static const struct { int act; uint64_t btn; } km[] = { { 0, DM_BTN_A }, { 1, DM_BTN_Y }, { 2, DM_BTN_X }, { 4, DM_BTN_RS }, { 7, DM_BTN_ZL }, { 8, DM_BTN_ZR }, { 10, DM_BTN_MINUS }, { 11, DM_BTN_LEFT }, { 14, DM_BTN_RIGHT }, { 12, DM_BTN_UP }, { 13, DM_BTN_DOWN }, { 19, DM_BTN_L }, { 20, DM_BTN_R }, { 23, DM_BTN_B } };
|
||||
if (*(int32_t *)(uintptr_t)(e + 8) == 1) for (unsigned k = 0; k < sizeof km / sizeof *km && !btn; k++) { // 键帽 → 键:照 legend_find 的比法,拿动作号建一个空字条目取它的键帽来比 | key cap -> key: the same comparison as legend_find, build an entry with empty text from the action number and take its key cap to compare
|
||||
uint64_t ent[8] = { 0 }; struct { const char *p; uint64_t n; } sv = { "", 0 }; ((void (*)(void *, int, int, void *))(b + 0xaa9358))(ent, km[k].act, 0, &sv); legend_free(b, ent);
|
||||
if ((int32_t)ent[1] == 1 && (uint32_t)ent[0] == gl) btn = km[k].btn; }
|
||||
if (!btn && gl == 0xe005) btn = DM_BTN_PLUS; // + 键没有对应的动作号可比(主菜单「+ 新角色」):直接认它的键帽码(实测 e005) | the + key has no action number to compare with (main menu "+ New Character"): recognise its key-cap code directly (measured e005)
|
||||
LOG("手柄提示条:鼠标点在第 %d 条(共 %llu 条,键帽 %x)→ %s", hit + 1, (unsigned long long)n, gl, btn ? "按它那个键" : "认不出是哪个键,不按");
|
||||
return btn;
|
||||
}
|
||||
static void legend_pump(uint8_t *b, uint64_t frame) { // 游戏主线程每帧 | Game main thread, every frame
|
||||
static int miss, tot; static uint64_t logged; int test = getenv("DM_TEST_LEGEND") != NULL;
|
||||
// 测试开关 DM_TEST_LEGEND=<动作号>:<字>[,…]:手柄模式下一直声明这些条目;DM_TEST_LEGEND_OFF=<帧>:到这一帧起不再声明。DM_TEST_LEGEND_LOG=1:每 120 帧记一行提示条现状(不声明条目)
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
// 转向回跳平滑(本地玩家)+ 模型转身参数读取。
|
||||
//
|
||||
// 原版客户端每个渲染帧把全部单位的路径坐标按「距上一逻辑拍的时间」原地向前外推(主循环 main+0x2c28e8 → 0x461f10),画完帧尾恢复。
|
||||
// 跑动中急转向时,逻辑在那一拍直接按新方向走,之前沿旧方向多推出去的那段被一帧收回:60 帧下转 90° 那一帧画面倒退约 6 像素、
|
||||
// 掉头那一帧走平时 2.5 帧的量(镜头直接读这份坐标,所以是整个画面跳一下)。原版自带一套「位置误差平滑」(路径 +0x2a8 / +0x2ac 的浮点误差
|
||||
// 每帧加回坐标、在走的单位每拍线性收 0.16 格,0x463f40 → 0x5a1810),但只在起步 / 停步时算误差(0x4639c0,排在逻辑拍循环之前),转向接不住。
|
||||
// 这里在误差平滑函数入口(观测门 OBS_ERR_SMOOTH,main+0x463f40:外推刚做完、误差还没加)给本地玩家补上转向那一帧的误差:
|
||||
// 误差 +=(旧方向 − 新方向)× 每拍位移 × 上一帧外推的拍比例(正是被收回的那段),每轴夹 ±0.4 格(原版同一个上限),之后由原版逐帧衰减。
|
||||
// 只在「上一帧与这一帧都在走、方向转过了 TURN_COS 对应的角度」那一帧写一次;转向同时停下的帧不写(原版只在单位在走时衰减,停着写会冻成静止偏移)。
|
||||
// 逻辑位置、发包、存档都不受影响:改的是外推后的显示坐标上的误差量,帧尾原版照常恢复真值。
|
||||
// 缺省开;测试开关 DM_TURN_SMOOTH=0 关(改前改后对照用)、=2 挂门只看不写,DM_TEST_TURN_LOG=1 每次补误差 / 停步各记一行,DM_TEST_TURN_TRACE=1 每帧记一行外推坐标与误差(dm/ios/tools/turn_trace.py 出逐帧位移表)。产物没有这个门(r42 之前)就不处理。
|
||||
//
|
||||
// 手柄转身手感(本地玩家,看 Mac 上的对比片定的:「去掉并配 360」,真机未看):
|
||||
// 3D 模型的朝向由模型朝向组件每帧更新(main+0x9da5b0,观测门 OBS_MODEL_YAW),参数是组件实例里的浮点。原版手柄跑动中掉头(朝向差超过 +0x38 = 100°)
|
||||
// 会切到一段「原地转身」动画:身体先压低蹬地再转过来,画面约 12 帧(60 帧),这期间逻辑位置已经在往回走——看着像倒着滑一下;
|
||||
// 转 90° 走限速跟随,转速 = 下限 + 剩余角度 ÷ 180 ×(上限 − 下限),手柄下限 +0x10 / +0x18 = 180 度 / 秒,约 14 帧。
|
||||
// 这里对本地玩家:手柄门限抬到 YAW_TURN_OFF(不再播那段动画,掉头也走限速跟随、朝向单调转过去),手柄两组下限取 max(原值, YAW_PAD_MIN)。
|
||||
// 鼠标点地那组(下限 +0x20 / +0x28、门限 +0x3c)不动;别的玩家 / 怪物 / 佣兵不动(只认本地玩家的单位)。纯画面层:这个函数不写路径、不发包。
|
||||
// 测试开关:DM_TURN_YAW=0 照原版(门限与下限都不改);DM_TEST_YAW_DUMP=1 打一次原版值并每 5 秒记门的触发频率;
|
||||
// DM_TEST_YAW_MIN=<度每秒> / DM_TEST_YAW_SET="<偏移十六进制>=<值>[,…]" 试别的值;DM_TEST_YAW_TRACE=1 每帧记一行偏航角。
|
||||
// Turn snap-back smoothing (local player) + reading the model turning parameters.
|
||||
// On every rendered frame the original client extrapolates the path coordinates of all units forward in place by "the time since the last logic tick" (main loop main+0x2c28e8 -> 0x461f10) and restores them at the end of the frame.
|
||||
// On a sharp turn while running, the logic moves along the new direction on that tick, and the part pushed out along the old direction is taken back within one frame: at 60 fps the picture steps back about 6 pixels on the frame of a 90-degree turn,
|
||||
// and on the frame of a U-turn it moves as much as 2.5 normal frames (the camera reads these coordinates directly, so the whole picture jumps). The original has its own "position error smoothing" (float errors at path +0x2a8 / +0x2ac,
|
||||
// added back to the coordinates every frame and reduced linearly by 0.16 tiles per tick while the unit is walking, 0x463f40 -> 0x5a1810), but it computes the error only when starting / stopping (0x4639c0, placed before the logic tick loop), so turns are not covered.
|
||||
// Here, at the entry of the error-smoothing function (observation gate OBS_ERR_SMOOTH, main+0x463f40: extrapolation just done, error not yet added), the error of the turning frame is supplied for the local player:
|
||||
// error += (old direction - new direction) x displacement per tick x the tick fraction extrapolated in the previous frame (exactly the part taken back), clamped to +-0.4 tiles per axis (the same limit as the original), and then decayed frame by frame by the original.
|
||||
// Written once, only on the frame where "the previous frame and this frame are both walking and the direction has turned past the angle of TURN_COS"; frames that turn and stop at the same time are not written (the original decays only while the unit walks, so writing while stopped would freeze into a static offset).
|
||||
// Logical position, packets and saves are unaffected: what changes is the error on the displayed coordinates after extrapolation, and the original restores the true values at the end of the frame as usual.
|
||||
// On by default; test switch DM_TURN_SMOOTH=0 turns it off (for before / after comparison), =2 hooks the gate but only observes, DM_TEST_TURN_LOG=1 logs one line per supplied error / per stop, DM_TEST_TURN_TRACE=1 logs one line per frame with the extrapolated coordinates and the error (dm/ios/tools/turn_trace.py prints a per-frame displacement table). Build outputs without this gate (before r42) are left alone.
|
||||
// Gamepad turning feel (local player; decided from a side-by-side clip on a Mac, not looked at on a device):
|
||||
// The facing of the 3D model is updated every frame by the model facing component (main+0x9da5b0, observation gate OBS_MODEL_YAW); the parameters are floats in the component instance. In the original, a U-turn while running with a gamepad (facing difference above +0x38 = 100 degrees)
|
||||
// switches to a "turn in place" animation: the body crouches, pushes off and then turns around, about 12 frames on screen (at 60 fps), while the logical position is already heading back - it looks like sliding backwards for a moment;
|
||||
// a 90-degree turn uses rate-limited following, turning speed = minimum + remaining angle / 180 x (maximum - minimum), with the gamepad minimum +0x10 / +0x18 = 180 degrees / second, about 14 frames.
|
||||
// Here, for the local player: the gamepad threshold is raised to YAW_TURN_OFF (that animation no longer plays; a U-turn also uses rate-limited following and the facing turns monotonically), and the two gamepad minimums become max(original, YAW_PAD_MIN).
|
||||
// The click-to-move group (minimums +0x20 / +0x28, threshold +0x3c) is untouched; other players / monsters / mercenaries are untouched (only the local player's unit is recognised). Purely visual: this function writes no path and sends no packet.
|
||||
// Test switches: DM_TURN_YAW=0 behaves as the original (neither threshold nor minimum changed); DM_TEST_YAW_DUMP=1 prints the original values once and logs the gate's firing rate every 5 seconds;
|
||||
// DM_TEST_YAW_MIN=<degrees per second> / DM_TEST_YAW_SET="<offset in hex>=<value>[,...]" try other values; DM_TEST_YAW_TRACE=1 logs one line of yaw per frame.
|
||||
#include "dm.h"
|
||||
#include "hle.h"
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define TURN_COS 0.94 /* 方向夹角余弦低于它(约 20° 以上)才算急转;每拍转 10° 左右的缓转原本就平滑,不动 | only when the cosine of the angle between directions is below this (about 20 degrees and up) does it count as a sharp turn; gentle turns of about 10 degrees per tick are already smooth and are left alone */
|
||||
#define YAW_PAD_MIN 360.0f /* 手柄转速下限(度 / 秒),原版 180 | gamepad minimum turning speed (degrees / second), 180 in the original */
|
||||
#define YAW_TURN_OFF 999.0f /* 手柄「原地转身」门限(度),原版 100;大于 180 = 永不触发 | gamepad "turn in place" threshold (degrees), 100 in the original; above 180 = never triggers */
|
||||
#define ERR_MAX 26214.4f /* ±0.4 格(16.16 定点单位),与原版 0x5a1710 的夹值相同 | +-0.4 tiles (16.16 fixed-point units), the same clamp as the original at 0x5a1710 */
|
||||
|
||||
static uint8_t *g_b; static int g_log, g_dry, g_trace; static float g_yaw_min; static int g_yaw_trace, g_yaw_stat, g_yaw_native; static struct { unsigned off; float v; } g_set[8]; static int g_nset;
|
||||
static struct { uint64_t path; int ok, moving; int32_t x, y, dx, dy; float tau; double per_tick; } g_p;
|
||||
|
||||
static uint64_t local_player(void) { return ((uint64_t (*)(uint32_t))(g_b + 0x45f9d0))(*(uint32_t *)(uintptr_t)(g_b + 0x2d20e4c)); }
|
||||
|
||||
static void ts_obs(const uint64_t *regs) {
|
||||
float frame = *(const float *)(const void *)®s[32]; /* s0 = 本帧帧长折成的拍数(不出拍的帧是 0) | s0 = this frame's length expressed in ticks (0 on frames that produce no tick) */
|
||||
uint64_t G = *(uint64_t *)(uintptr_t)(g_b + 0x2d20b80); float tau = G ? (float)(*(uint32_t *)(uintptr_t)(G + 8) - *(uint32_t *)(uintptr_t)(G + 0xc)) / 40.0f : 0; /* 这一帧外推用的拍比例 | the tick fraction used for extrapolation in this frame */
|
||||
uint64_t pl = local_player(), pp = pl ? *(uint64_t *)(uintptr_t)(pl + 0x38) : 0;
|
||||
if (!G || !pp || !*(uint8_t *)(uintptr_t)(pp + 0x260)) { g_p.ok = 0; return; }
|
||||
int32_t x = *(int32_t *)(uintptr_t)pp, y = *(int32_t *)(uintptr_t)(pp + 4), dx, dy; memcpy(&dx, (void *)(uintptr_t)(pp + 0x8e), 4); memcpy(&dy, (void *)(uintptr_t)(pp + 0x92), 4);
|
||||
int moving = (*(uint8_t *)(uintptr_t)(pp + 0x48) >> 5) & 1; float *ex = (float *)(uintptr_t)(pp + 0x2a8), *ey = (float *)(uintptr_t)(pp + 0x2ac);
|
||||
int same_dir = g_p.ok && g_p.path == pp && dx == g_p.dx && dy == g_p.dy;
|
||||
if (g_p.ok && g_p.path == pp && moving && g_p.moving) {
|
||||
double n0 = hypot(g_p.dx, g_p.dy), n1 = hypot(dx, dy);
|
||||
/* 方向没变的帧:外推坐标这一帧走了「每拍位移 × 帧长」,由此记下每拍位移(速度变了下一帧就跟上) | frames where the direction did not change: the extrapolated coordinates moved "displacement per tick x frame length" this frame, which gives the displacement per tick (a speed change is picked up on the next frame) */
|
||||
if (same_dir && frame > 0) g_p.per_tick = hypot((double)x - g_p.x, (double)y - g_p.y) / frame;
|
||||
else if (!same_dir && n0 > 0 && n1 > 0 && g_p.per_tick > 0 && ((double)g_p.dx * dx + (double)g_p.dy * dy) / (n0 * n1) < TURN_COS) {
|
||||
/* 急转:上一帧沿旧方向外推了 tau 拍,逻辑这一拍改按新方向走——画面上被收回的那段 =(旧方向 − 新方向)× 每拍位移 × 上一帧的 tau | sharp turn: the previous frame extrapolated tau ticks along the old direction, and this tick the logic moves along the new one - the part taken back on screen = (old direction - new direction) x displacement per tick x the previous frame's tau */
|
||||
double k = g_p.per_tick * g_p.tau; float ox = *ex, oy = *ey;
|
||||
float tx = (float)(ox + (g_p.dx / n0 - dx / n1) * k), ty = (float)(oy + (g_p.dy / n0 - dy / n1) * k);
|
||||
tx = fminf(ERR_MAX, fmaxf(-ERR_MAX, tx)); ty = fminf(ERR_MAX, fmaxf(-ERR_MAX, ty)); if (!g_dry) { *ex = tx; *ey = ty; }
|
||||
if (g_log) LOG("转向平滑:方向 (%d,%d) → (%d,%d),误差 (%.0f,%.0f) → (%.0f,%.0f)(单位 1/65536 格),每拍位移 %.0f,上一帧外推 %.2f 拍%s", g_p.dx, g_p.dy, dx, dy, ox, oy, tx, ty, g_p.per_tick, g_p.tau, g_dry ? "(只看不写)" : "");
|
||||
}
|
||||
}
|
||||
if (g_log) { static int cnt = -1; /* 停步后误差有没有留下静止偏移:停步那一帧与其后第 30 帧各记一行 | whether the error leaves a static offset after stopping: one line at the stopping frame and one at the 30th frame after it */
|
||||
if (g_p.ok && g_p.moving && !moving) { cnt = 30; LOG("转向平滑:停步这一帧误差 (%.0f,%.0f)", *ex, *ey); }
|
||||
else if (cnt > 0 && --cnt == 0) LOG("转向平滑:停步后第 30 帧误差 (%.0f,%.0f),在走 %d", *ex, *ey, moving); }
|
||||
if (g_trace) LOG("转向帧迹 %d %d %.0f %.0f %d %.3f %.3f", x, y, *ex, *ey, moving, tau, frame); /* 外推坐标、将加回的误差:画出来的位置 = 两者之和 | extrapolated coordinates and the error about to be added back: the drawn position = the sum of the two */
|
||||
g_p.path = pp; g_p.ok = 1; g_p.moving = moving; g_p.x = x; g_p.y = y; g_p.dx = dx; g_p.dy = dy; g_p.tau = tau;
|
||||
}
|
||||
|
||||
static void yaw_obs(const uint64_t *regs) { /* x1 = 参数块:+8 组件,+0x20 → +8 单位。每帧对每个带朝向组件的单位触发一次 | x1 = parameter block: +8 component, +0x20 -> +8 unit. Fires once per frame for every unit that has a facing component */
|
||||
uint64_t a = regs[1], comp = a ? *(uint64_t *)(uintptr_t)(a + 8) : 0, h = a ? *(uint64_t *)(uintptr_t)(a + 0x20) : 0, unit = h ? *(uint64_t *)(uintptr_t)(h + 8) : 0;
|
||||
static uint64_t lp_comp; static uint64_t n, t0, shared;
|
||||
if (g_yaw_stat) { uint64_t t = guest_ns(); n++; if (!t0) t0 = t; if (comp && comp == lp_comp && unit != local_player()) shared++; /* 触发频率、别的单位是不是和本地玩家共用同一个组件 | how often it fires, and whether other units share the same component with the local player */
|
||||
if (t - t0 >= 5000000000ull) { LOG("模型转身参数:观测门 %d 在 %.1f 秒内触发 %llu 次(%.0f 次 / 秒),别的单位用到本地玩家那个组件 %llu 次", OBS_MODEL_YAW, (t - t0) / 1e9, (unsigned long long)n, n * 1e9 / (double)(t - t0), (unsigned long long)shared); n = 0; shared = 0; t0 = t; } }
|
||||
if (!comp || !unit || unit != local_player()) return;
|
||||
lp_comp = comp; float *w = (float *)(uintptr_t)comp; static uint64_t dumped;
|
||||
if (g_yaw_stat && dumped != comp) { dumped = comp; uint64_t pp = *(uint64_t *)(uintptr_t)(unit + 0x38); /* 改值之前的原版值,换了组件(换角色 / 重进)再打一次 | the original values before the change; printed again when the component changes (another character / re-entering) */
|
||||
LOG("模型转身参数(本地玩家,职业 %u,路径模式 0x%x):手柄转速(度/秒)+10 %.1f +14 %.1f | +18 %.1f +1c %.1f | 鼠标转速 +20 %.1f +24 %.1f | +28 %.1f +2c %.1f | 弹簧直接到位门限 +30 %.1f | 弹簧参数 +34 %.4f | 原地转身门限 手柄 +38 %.1f 其余 +3c %.1f | +40 %.3f +44 %.3f +48 %.3f +4c %.3f +50 %.3f",
|
||||
*(uint32_t *)(uintptr_t)(unit + 4), pp ? *(uint32_t *)(uintptr_t)(pp + 0x50) : 0, w[4], w[5], w[6], w[7], w[8], w[9], w[10], w[11], w[12], w[13], w[14], w[15], w[16], w[17], w[18], w[19], w[20]); }
|
||||
if (!g_yaw_native) { /* 手感(见文件头):只动手柄那一组,原值更快的不压低 | feel (see the file header): only the gamepad group is touched, and original values that are already faster are not lowered */
|
||||
if (w[14] < 181.0f) w[14] = YAW_TURN_OFF;
|
||||
if (w[4] < YAW_PAD_MIN) w[4] = YAW_PAD_MIN;
|
||||
if (w[6] < YAW_PAD_MIN) w[6] = YAW_PAD_MIN; }
|
||||
if (g_yaw_min > 0) w[4] = w[6] = g_yaw_min;
|
||||
for (int i = 0; i < g_nset; i++) *(float *)(uintptr_t)(comp + g_set[i].off) = g_set[i].v;
|
||||
if (g_yaw_trace) LOG("转身帧迹 %.1f %.4f %.4f", guest_ns() / 1e6, w[1], w[2]); /* 客体时钟毫秒、身体偏航、平滑偏航(弧度) | guest clock in milliseconds, body yaw, smoothed yaw (radians) */
|
||||
}
|
||||
|
||||
void dm_turnsmooth_install(uint8_t *main_base) {
|
||||
g_b = main_base; const char *e = getenv("DM_TURN_SMOOTH"); g_log = getenv("DM_TEST_TURN_LOG") != NULL; g_trace = getenv("DM_TEST_TURN_TRACE") != NULL;
|
||||
if (!gate_obs_present(OBS_ERR_SMOOTH)) LOG("转向平滑:产物没有观测门 %d(r42 起),不处理", OBS_ERR_SMOOTH);
|
||||
else if (e && atoi(e) == 0) LOG("转向平滑:测试开关 DM_TURN_SMOOTH=0,不挂门(改前改后对照用)");
|
||||
else { g_dry = e && atoi(e) == 2; gate_obs_set(OBS_ERR_SMOOTH, ts_obs); }
|
||||
{ const char *m = getenv("DM_TEST_YAW_MIN"); g_yaw_min = m ? (float)atof(m) : 0; g_yaw_trace = getenv("DM_TEST_YAW_TRACE") != NULL; g_yaw_stat = getenv("DM_TEST_YAW_DUMP") != NULL;
|
||||
const char *nv = getenv("DM_TURN_YAW"); g_yaw_native = nv && atoi(nv) == 0;
|
||||
if (g_yaw_native) LOG("模型转身参数:测试开关 DM_TURN_YAW=0,本地玩家的手柄转身照原版(门限 100°、下限 180 度 / 秒)");
|
||||
if (g_yaw_min > 0) LOG("模型转身参数:测试开关 DM_TEST_YAW_MIN=%.0f,本地玩家手柄转速下限改成这个值", g_yaw_min); }
|
||||
{ const char *q = getenv("DM_TEST_YAW_SET"); unsigned off; float v; int k; /* "38=999,48=0.1":偏移十六进制(4 的倍数、0x10..0x50)= 浮点值 | "38=999,48=0.1": offset in hex (a multiple of 4, 0x10..0x50) = float value */
|
||||
while (q && g_nset < 8 && sscanf(q, "%x=%f%n", &off, &v, &k) == 2) { if (off >= 0x10 && off <= 0x50 && !(off & 3)) { g_set[g_nset].off = off; g_set[g_nset++].v = v; LOG("模型转身参数:测试开关 DM_TEST_YAW_SET,本地玩家组件 +0x%x 逐帧写成 %g", off, v); } q += k; if (*q == ',') q++; else break; } }
|
||||
if (!gate_obs_present(OBS_MODEL_YAW)) LOG("模型转身参数:产物没有观测门 %d(r42 起),手柄转身照原版", OBS_MODEL_YAW);
|
||||
else if (!g_yaw_native || g_yaw_min > 0 || g_yaw_trace || g_yaw_stat || g_nset) gate_obs_set(OBS_MODEL_YAW, yaw_obs);
|
||||
}
|
||||
@@ -82,6 +82,9 @@ int dm_guest_heap_stat(unsigned long long *total_mb, unsigned long long *free_mb
|
||||
*total_mb = g_heap_cur >> 20; *free_mb = fr >> 20; *maxblk_kb = mx >> 10;
|
||||
g_gheap_last[0] = *total_mb; g_gheap_last[1] = *free_mb; g_gheap_last[2] = *maxblk_kb; return 1;
|
||||
}
|
||||
// 上次读到的主堆读数(总量 MB、余量 MB、最大可分配块 KB;没读过全 0)。任何线程可调——不进分配器(iOS 壳在主线程上记内存告警那一行用)
|
||||
// The last main-heap readout (total MB, free MB, largest allocatable block KB; all 0 if never read). Callable from any thread - does not enter the allocator (the iOS shell uses it on the main thread for the memory-warning log line)
|
||||
void dm_guest_heap_last(unsigned long long v[3]) { for (int i = 0; i < 3; i++) v[i] = atomic_load(&g_gheap_last[i]); }
|
||||
HLE_FORCE("_ZN2nn3mem17StandardAllocator8AllocateEmm", "照原版分配,只在返回空时报红(原版调用方多处不判空)", void *, hle_stdalloc_allocate, void *self, size_t size, size_t align) {
|
||||
static void *(*orig)(void *, size_t, size_t); if (!orig) { module_t *ms = mod_named("sdk"); orig = (void *(*)(void *, size_t, size_t))(ms->base + 0x2f9974); }
|
||||
void *p = orig(self, size, align);
|
||||
|
||||
+11
-1
@@ -54,6 +54,16 @@ static void chk_log(const uint8_t *in, uint32_t n, const uint8_t *out, size_t go
|
||||
}
|
||||
|
||||
static __thread struct libdeflate_decompressor *t_dec; // 每线程一个(解压器不可跨线程并用) | One per thread (a decompressor must not be shared across threads)
|
||||
// 随线程退出释放(键析构,同 crash.c 备用栈):原先不放,做过解码又退出的线程每条漏一个解压器(约 11.5 KB)
|
||||
// Freed when the thread exits (key destructor, same as the alternate stack in crash.c): it used not to be freed, so every thread that decoded something and then exited leaked one decompressor (about 11.5 KB)
|
||||
static pthread_key_t g_dec_key; static pthread_once_t g_dec_once = PTHREAD_ONCE_INIT;
|
||||
static void dec_free(void *p) { libdeflate_free_decompressor(p); }
|
||||
static void dec_key_init(void) { if (pthread_key_create(&g_dec_key, dec_free)) die("libdeflate 解压器键创建失败"); }
|
||||
static struct libdeflate_decompressor *thread_dec(void) {
|
||||
if (t_dec) return t_dec;
|
||||
if (!(t_dec = libdeflate_alloc_decompressor())) die("libdeflate 分配解压器失败");
|
||||
pthread_once(&g_dec_once, dec_key_init); pthread_setspecific(g_dec_key, t_dec); return t_dec;
|
||||
}
|
||||
|
||||
// ---------- DM_TACT_PREFETCH=<启动块清单>:后台预解码(性能提示,正确性不依赖它)----------
|
||||
// 清单(dm/tools/tact_bootlist.py 由一局 DM_TACTCHK 生成):选角前会请求的块,每行「数据文件 偏移 压缩长 解码长 开头16字节 发起线程」,
|
||||
@@ -243,7 +253,7 @@ static uint32_t tact_decode_zlib(uint64_t *r) {
|
||||
if (n < 2 || in[0] != 'Z') { LOG("tact:zlib 块编码字节不是 'Z'(%#x)", n ? in[0] : 0); return 8; }
|
||||
in++; n--;
|
||||
}
|
||||
if (!t_dec && !(t_dec = libdeflate_alloc_decompressor())) die("libdeflate 分配解压器失败");
|
||||
thread_dec();
|
||||
size_t got = 0; uint64_t t0 = now_ns();
|
||||
if (pf_take(in, n, out, cap, &got)) { dm_prof_add(PROF_TACT, now_ns() - t0, got); chk_log(in, n, out, got); return 0; }
|
||||
enum libdeflate_result rc = libdeflate_zlib_decompress(t_dec, in, n, out, cap, &got);
|
||||
|
||||
@@ -4,11 +4,12 @@ DM_ROOT ?= $(HOME)/dm-work
|
||||
PY ?= $(DM_ROOT)/build/cache/dm/venv/bin/python
|
||||
EXEFS ?= $(DM_ROOT)/data/switch/3.3.94012/Update/ExeFS
|
||||
B = build
|
||||
run: $(B)/t_rift_clock $(B)/t_textbox $(B)/t_padmap $(B)/t_touch $(B)/t_hid_receipt $(B)/t_hid_script $(B)/t_touch_mac $(B)/t_oe $(B)/t_fs $(B)/t_fs_case $(B)/t_romfs_validate $(B)/t_audio $(B)/t_audio_spsc $(B)/t_swkbd $(B)/t_altstack $(B)/t_movie $(B)/t_condvar $(B)/t_condvar_old $(B)/t_target_rank $(B)/t_hud_dead $(B)/t_namegen $(B)/t_modetx $(B)/t_unit_level $(B)/t_widget $(B)/t_doorspot $(B)/t_cloudsync $(B)/t_i18n $(B)/main.orig.bin $(B)/subsdk0.orig.bin
|
||||
run: $(B)/t_thread_leak $(B)/t_rift_clock $(B)/t_textbox $(B)/t_padmap $(B)/t_touch $(B)/t_hid_receipt $(B)/t_hid_script $(B)/t_touch_mac $(B)/t_oe $(B)/t_fs $(B)/t_fs_case $(B)/t_romfs_validate $(B)/t_audio $(B)/t_audio_spsc $(B)/t_swkbd $(B)/t_altstack $(B)/t_movie $(B)/t_condvar $(B)/t_condvar_old $(B)/t_target_rank $(B)/t_hud_dead $(B)/t_namegen $(B)/t_modetx $(B)/t_unit_level $(B)/t_widget $(B)/t_doorspot $(B)/t_cloudsync $(B)/t_i18n $(B)/main.orig.bin $(B)/subsdk0.orig.bin
|
||||
python3 native_write_scan.py --selftest ..
|
||||
python3 mode_scan.py ../..
|
||||
python3 ../../ios/tools/dm_i18n.py --check
|
||||
python3 ../../i18n/scan_literals.py
|
||||
$(B)/t_thread_leak
|
||||
$(B)/t_rift_clock
|
||||
$(B)/t_textbox
|
||||
$(B)/t_touch
|
||||
@@ -105,3 +106,5 @@ $(B)/t_target_rank: t_target_rank.c ../hle_target.c ../dm.h | $(B)
|
||||
clang -O1 -Wno-unused-function -I.. -o $@ t_target_rank.c ../hle_target.c
|
||||
$(B)/t_rift_clock: t_rift_clock.c ../dm_rift.c ../dm_rift.h ../hle_os.c ../hle.h ../dm.h | $(B)
|
||||
clang -O1 -Wall -Wno-unused-function -ffunction-sections -fdata-sections -Wl,-dead_strip -I.. -o $@ t_rift_clock.c ../hle_os.c
|
||||
$(B)/t_thread_leak: t_thread_leak.c ../thread.c ../dm.h | $(B)
|
||||
clang -O1 -Wall -Wno-unused-function -I.. -I../../ios/Sources -o $@ t_thread_leak.c
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
// 客体线程每建销一条不许漏宿主堆(内存泄漏专题第 1 条):guest_thread_init 给每条线程申请 TLS 块与线程本地区,
|
||||
// 原先建键时析构传空、线程退出时不放,每条漏 8192 + 0x200 + 0x400 = 9728 字节。
|
||||
// 做法:直接包含真的 thread.c,把其中的 calloc / free 换成这里计数的版本;TLS / 线程本地区两把键照装载器的建法(析构为空),释放靠 thread.c 自己另建的那把键。
|
||||
// 期望值写死:建销 200 条线程,申请过的字节 = 200 ×(9728 + 记指针的 16)= 1948800,全部线程退出后仍没释放的块数 = 0。
|
||||
// 每条线程在退出前把两把键的槽改写成别的指针(客体就是这么干的:它自己设线程指针)——析构按槽里的值 free 会崩(第一版修法在真宿主上就崩在这里)。
|
||||
// Creating and destroying a guest thread must not leak host heap (item 1 of the memory-leak work): guest_thread_init allocates a TLS block and a thread-local region for each thread,
|
||||
// and previously the keys were created with a null destructor and nothing was freed at thread exit, leaking 8192 + 0x200 + 0x400 = 9728 bytes per thread.
|
||||
// Method: include the real thread.c directly and replace its calloc / free with the counting versions here; the TLS / thread-local-region keys are created the way the loader does (null destructor), and freeing relies on the extra key thread.c creates itself.
|
||||
// Expected values are hard-coded: create and destroy 200 threads, bytes allocated = 200 x (9728 + 16 for recording the pointers) = 1948800, blocks still not freed after all threads exit = 0.
|
||||
// Before exiting, each thread overwrites the slots of both keys with other pointers (which is what the guest does: it sets its own thread pointer) - a destructor that frees the value in the slot would crash (the first version of the fix crashed right here on the real host).
|
||||
#include <stdatomic.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
#include <malloc/malloc.h>
|
||||
static _Atomic long g_live_blocks, g_live_bytes, g_total_bytes;
|
||||
static void *t_calloc(size_t n, size_t sz) { void *p = calloc(n, sz); atomic_fetch_add(&g_live_blocks, 1); atomic_fetch_add(&g_live_bytes, (long)(n * sz)); atomic_fetch_add(&g_total_bytes, (long)(n * sz)); return p; }
|
||||
static _Atomic long g_freed_req; // 释放次数 | number of frees
|
||||
static void t_free(void *p) { if (!p) return; atomic_fetch_sub(&g_live_blocks, 1); atomic_fetch_add(&g_freed_req, 1); free(p); }
|
||||
#define calloc t_calloc
|
||||
#define free t_free
|
||||
#include "../thread.c"
|
||||
#undef calloc
|
||||
#undef free
|
||||
|
||||
pthread_key_t g_key18, g_keytls, g_keytlr, g_keygate, g_keyres[2], g_keyaspect, g_keyaspectui;
|
||||
void dm_gate(void) {}
|
||||
uint64_t dm_game_res(int i) { (void)i; return 0; }
|
||||
uint64_t front_game_res(int i) { (void)i; return 0; }
|
||||
|
||||
static int fails, checks;
|
||||
#define EXPECT(name, want, got) do { long w_ = (long)(want), g_ = (long)(got); checks++; printf("%-46s 期望 %-8ld → 真结果 %-8ld %s\n", name, w_, g_, w_ == g_ ? "✓" : "✗"); if (w_ != g_) fails++; } while (0)
|
||||
static char g_not_heap[64];
|
||||
static void *one(void *a) { (void)a; guest_thread_init(); pthread_setspecific(g_keytls, g_not_heap); pthread_setspecific(g_keytlr, g_not_heap + 32); return NULL; }
|
||||
int main(void) {
|
||||
enum { N = 200 };
|
||||
if (pthread_key_create(&g_key18, NULL) || pthread_key_create(&g_keytls, NULL) || pthread_key_create(&g_keytlr, NULL) || pthread_key_create(&g_keygate, NULL)) { printf("建键失败\n"); return 2; }
|
||||
for (int i = 0; i < N; i++) { pthread_t t; if (pthread_create(&t, NULL, one, NULL)) { printf("建线程失败\n"); return 2; } pthread_join(t, NULL); }
|
||||
EXPECT("200 条线程申请过的字节(200 × 9744)", 1948800, atomic_load(&g_total_bytes));
|
||||
EXPECT("全部退出后还没释放的块数", 0, atomic_load(&g_live_blocks));
|
||||
EXPECT("释放次数(每条线程 3 块)", 600, atomic_load(&g_freed_req));
|
||||
printf("t_thread_leak:%d 项,%d 项不通\n", checks, fails); return fails != 0;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ uint64_t guest_ns(void) { return 0; }
|
||||
uint64_t dm_guest_frame(void) { return 0; } // 界面鼠标 / 前端路径按出图帧节拍走;本单测不测它们 | the UI mouse / front-end paths run on the presented-frame cadence; this unit test does not test them
|
||||
int dm_world_has_target(void) { return 1; } // 点世界(dm_world.c)的桩:有目标 = 主按钮照常发键 | stub for world tapping (dm_world.c): has a target = the primary button sends its key as usual
|
||||
unsigned dm_world_tap(float nx, float ny) { (void)nx; (void)ny; return 0; }
|
||||
uint64_t dm_padmode_legend_click(float nx, float ny) { (void)nx; (void)ny; return 0; }
|
||||
int dm_shop_open(void) { return 0; } // 商人页(dm_actions.c)的桩:没开 | stub for the vendor page (dm_actions.c): not open
|
||||
int dm_padmode_current(void) { return 0; } // 手柄 / 触屏模式(dm_padmode.c)的桩:触屏 | Stub for controller / touch mode (dm_padmode.c): touch
|
||||
uint64_t dm_padmode_page_keys(uint64_t m) { (void)m; return 0; } void dm_padmode_legend_hide(const char *l, int a) { (void)l; (void)a; } int dm_padmode_busy(void) { return 0; } uint64_t dm_padmode_page_held(void) { return 0; } void dm_padmode_page_pulse(uint64_t m) { (void)m; } void dm_padmode_ident_hint(int on) { (void)on; } void dm_padmode_legend(int a, const char *t) { (void)a; (void)t; } const char *dm_str(uint8_t *b, const char *k) { (void)b; return k; } // 手柄页键 / 提示条 / 取串的桩(个人仓库手柄翻页用,触屏下不走) | Stubs for controller page keys / button legend / string fetch (used by controller paging of the personal stash, not reached under touch)
|
||||
|
||||
@@ -90,3 +90,4 @@ int dm_runeword_long_press(const void *ci) { (void)ci; return 0; } // 符文
|
||||
int dm_runeword_list_open(void) { return 0; }
|
||||
void dm_runeword_button(const char *name) { (void)name; }
|
||||
void dm_runeword_list_close(void) {}
|
||||
uint64_t dm_padmode_legend_click(float nx, float ny) { (void)nx; (void)ny; return 0; } // 鼠标点按键提示条(dm_padmode.c):这些单测不带游戏映像,给空桩 | mouse click on the key-hint bar (dm_padmode.c): these unit tests carry no game image, so an empty stub is given
|
||||
|
||||
+16
-4
@@ -9,6 +9,10 @@
|
||||
extern void dm_gate(void); // entry.S:门公共入口 | entry.S: common gate entry
|
||||
#include "front.h"
|
||||
#include "dm_uiscreen.h"
|
||||
static pthread_key_t g_keyown; // 本线程申请到的 TLS 块 / 线程本地区的原始指针(见函数末尾) | raw pointers of the TLS block / thread-local region allocated by this thread (see the end of the function)
|
||||
static pthread_once_t g_keyown_once = PTHREAD_ONCE_INIT;
|
||||
static void own_free(void *p) { void **own = p; free(own[0]); free(own[1]); free(own); }
|
||||
static void own_key_init(void) { if (pthread_key_create(&g_keyown, own_free)) die("创建线程本地块的释放键失败"); }
|
||||
void guest_thread_init(void) {
|
||||
pthread_setspecific(g_keygate, (void *)dm_gate);
|
||||
for (int i = 0; i < 2; i++) if (g_keyres[i]) pthread_setspecific(g_keyres[i], (void *)dm_game_res(i)); // 分辨率参数位:{u32 宽, u32 高} 打包 | resolution parameter slot: {u32 width, u32 height} packed
|
||||
@@ -29,8 +33,16 @@ void guest_thread_init(void) {
|
||||
if (g_keyaspectui) { memcpy(&bits, &ui, 4); pthread_setspecific(g_keyaspectui, (void *)(uintptr_t)bits); }
|
||||
}
|
||||
pthread_setspecific(g_key18, 0);
|
||||
pthread_setspecific(g_keytls, calloc(1, TLS_SIZE));
|
||||
uint8_t *tlr = calloc(1, TLR_SIZE);
|
||||
*(void **)(tlr + 0x1f8) = calloc(1, THREAD_OBJ_SIZE); // 当前线程对象 | current thread object
|
||||
pthread_setspecific(g_keytlr, tlr);
|
||||
// 这两块随线程退出释放。客体会改写 TLS / 线程本地区这两把键的槽(它自己设线程指针),所以不能按键里的当前值去 free:
|
||||
// 申请到的原始指针另记在本文件自己的键 g_keyown 上,由它的析构放(键析构在 pthread_exit 时调用,同信号备用栈 crash.c altstack_free;
|
||||
// 析构里只有 free,客体线程的小栈上也安全)。原先不放:游戏频繁起短命线程,每条漏 8192 + 0x200 + 0x400 = 9728 字节。
|
||||
// 线程本地区与当前线程对象并成一块(TLR[0x1f8] 那一格 SDK 也可能改写)
|
||||
// These two blocks are freed when the thread exits. The guest overwrites the slots of the TLS / thread-local-region keys (it sets its own thread pointer), so they cannot be freed by the current value in the key:
|
||||
// the raw pointers that were allocated are recorded separately on this file's own key g_keyown and freed by its destructor (key destructors are called at pthread_exit, same as the signal alternate stack, crash.c altstack_free;
|
||||
// the destructor only calls free, which is safe on the small stack of a guest thread as well). They used not to be freed: the game starts short-lived threads frequently, and each leaked 8192 + 0x200 + 0x400 = 9728 bytes.
|
||||
// The thread-local region and the current thread object are merged into one block (the slot TLR[0x1f8] may also be overwritten by the SDK)
|
||||
void **own = calloc(2, sizeof *own); uint8_t *tlr = calloc(1, TLR_SIZE + THREAD_OBJ_SIZE);
|
||||
own[0] = calloc(1, TLS_SIZE); own[1] = tlr;
|
||||
*(void **)(tlr + 0x1f8) = tlr + TLR_SIZE; // 当前线程对象 | current thread object
|
||||
pthread_once(&g_keyown_once, own_key_init); pthread_setspecific(g_keytls, own[0]); pthread_setspecific(g_keytlr, tlr); pthread_setspecific(g_keyown, own);
|
||||
}
|
||||
|
||||
+20
-4
@@ -12,7 +12,12 @@ uint64_t now_ns(void);
|
||||
uint64_t guest_ns(void);
|
||||
uint32_t dm_cur_tick(void);
|
||||
int dm_loadscreen_down(void);
|
||||
static uint32_t touch_cur_tick(void) { return dm_cur_tick(); }
|
||||
// 拍号:脚本回放按服务端拍(确定性);真鼠标(App 形态)按墙钟折成每秒 30 拍——暂停菜单 / 设置页 / 大秘境面板开着时游戏停拍,
|
||||
// 按服务端拍的话鼠标事件排在队里不处理,这些页一下都点不进去
|
||||
// Tick number: script playback goes by server ticks (deterministic); a real mouse (App form) converts wall clock into 30 ticks per second - the game stops ticking while the pause menu / settings page / Greater Rift panel is open,
|
||||
// and with server ticks the mouse events would sit in the queue unprocessed, so nothing on those pages could be clicked
|
||||
static int g_live_on;
|
||||
static uint32_t touch_cur_tick(void) { return g_live_on ? (uint32_t)(now_ns() / 33333333ull) : dm_cur_tick(); }
|
||||
|
||||
typedef struct { uint64_t beat; int op, slot; float x, y; } touch_event;
|
||||
enum { TOUCH_DOWN, TOUCH_MOVE, TOUCH_UP };
|
||||
@@ -35,7 +40,7 @@ static struct {
|
||||
// outside panels no button target is opened and no stick is raised at the bottom left (a click anywhere is just "click the world": clicking a target walks over and interacts, clicking empty ground does nothing); in panels it works as before (clicking controls, tabs, item cells).
|
||||
// Front-end pages (main menu / character select / character creation, not in a game) bypass the state machine and the touch point is taken directly as a UI click (same as frontendMode in the iOS front end).
|
||||
#include <stdatomic.h>
|
||||
static int g_live_on; static uint32_t g_live_tick0; static int g_live_based;
|
||||
static uint32_t g_live_tick0; static int g_live_based; static uint64_t g_live_btn; static uint32_t g_live_btn_until;
|
||||
static struct { _Atomic unsigned head, tail; struct { int op; float nx, ny; } q[64]; } g_live;
|
||||
void dm_touch_host_live(int op, float nx, float ny) { // 前端线程:op 0 按下 1 移动 2 抬起;坐标 = 游戏画面归一化 [0,1] | Front-end thread: op 0 down, 1 move, 2 up; coordinates = normalized to the game picture [0,1]
|
||||
if (!g_live_on) return; unsigned t = atomic_load(&g_live.tail); if (t - atomic_load(&g_live.head) >= 64) return;
|
||||
@@ -162,13 +167,21 @@ void dm_touch_host_step(uint64_t now, uint64_t *buttons, int32_t *lx, int32_t *l
|
||||
if (!in) g_live_based = 0;
|
||||
while ((h = atomic_load(&g_live.head)) != atomic_load(&g_live.tail)) {
|
||||
int op = g_live.q[h % 64].op; float nx = g_live.q[h % 64].nx, ny = g_live.q[h % 64].ny; if (op != 2) { px = nx; py = ny; }
|
||||
if (!in) { dm_ui_touch(op, px, py); atomic_store(&g_live.head, h + 1); continue; }
|
||||
// 按在按键提示条的某一条上:这一下不当点击,改成按那个键 4 拍(dm_padmode.c);吞到抬起为止
|
||||
// Pressed on an entry of the key-hint bar: this is not treated as a click but as pressing that key for 4 ticks (dm_padmode.c); swallowed until release
|
||||
{ uint64_t dm_padmode_legend_click(float, float); static int eat; uint64_t lb = op == 0 ? dm_padmode_legend_click(px, py) : 0;
|
||||
if (lb) { eat = 1; g_live_btn = lb; g_live_btn_until = touch_cur_tick() + 4; }
|
||||
if (eat) { if (op == 2) eat = 0; atomic_store(&g_live.head, h + 1); continue; } }
|
||||
if (!in) { // 前端页:抬起时先问一次命中——落在页签上就走「点页签 = 按对应的手柄键」(页签不认鼠标点击;局内由手势层做同一件事),其余照旧发鼠标点击 | front-end pages: on release, hit-test once first - landing on a tab goes through "clicking a tab = pressing the corresponding gamepad key" (tabs do not take mouse clicks; in game the gesture layer does the same), everything else sends a mouse click as before
|
||||
if (op == 2 && dm_ui_item_at_now(px, py) == 2) { dm_ui_touch(3, px, py); dm_ui_tab_go(); } else dm_ui_touch(op, px, py);
|
||||
atomic_store(&g_live.head, h + 1); continue; }
|
||||
if (g_touch.next == g_touch.count) g_touch.next = g_touch.count = 0; // 表里的都处理完了:从头复用 | Everything in the table has been handled: reuse from the start
|
||||
if (g_touch.count >= 256) break;
|
||||
touch_event *e = &g_touch.event[g_touch.count++]; e->beat = 0; e->slot = 0; e->op = op == 0 ? TOUCH_DOWN : op == 1 ? TOUCH_MOVE : TOUCH_UP; e->x = px * 2868; e->y = py * 1320;
|
||||
atomic_store(&g_live.head, h + 1);
|
||||
}
|
||||
}
|
||||
if (g_live_btn) { if ((int32_t)(g_live_btn_until - touch_cur_tick()) > 0) *buttons |= g_live_btn; else g_live_btn = 0; }
|
||||
if (!g_touch.enabled || !g_touch.started) return;
|
||||
uint32_t tick = touch_cur_tick();
|
||||
if (!g_touch.prefix && !g_touch.tick_set) { g_touch.to_game_tick = tick; g_touch.tick_set = 1; }
|
||||
@@ -237,7 +250,10 @@ apply_input:
|
||||
if (g_touch.state.item_tap_seq != its) dm_ui_item_tap();
|
||||
if (g_touch.state.ident_seq != ids) dm_ui_identify_hovered();
|
||||
if (g_touch.state.use_seq != us) dm_ui_use_item();
|
||||
if (g_touch.state.world_tap_seq != wt) { unsigned dm_world_tap(float, float); dm_world_tap(g_touch.state.world_tap_x / 2868, g_touch.state.world_tap_y / 1320); }
|
||||
if (g_touch.state.world_tap_seq != wt) { unsigned dm_world_tap(float, float); float wx = g_touch.state.world_tap_x / 2868, wy = g_touch.state.world_tap_y / 1320;
|
||||
// 真鼠标:手势层认为没有面板开着(它按名单认面板,大秘境选层页这类借壳的面板不在名单里),这一下却落在某个面板里 → 发界面点击,不当点世界
|
||||
// Real mouse: the gesture layer believes no panel is open (it recognises panels by a list, and panels that borrow another shell, such as the Greater Rift level-selection page, are not on it), yet this click lands inside some panel -> send a UI click instead of a world click
|
||||
if (g_live_on && dm_ui_item_at_now(wx, wy) == 0) { dm_ui_touch(0, wx, wy); dm_ui_touch(2, wx, wy); } else dm_world_tap(wx, wy); }
|
||||
if (g_touch.state.mouse_click_seq != mc) { float nx = g_touch.state.mouse_click_x / 2868, ny = g_touch.state.mouse_click_y / 1320; dm_ui_touch(0, nx, ny); dm_ui_touch(2, nx, ny); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,8 @@ static NSDate *g_t0; // 本次启动时刻(dm_sharelog_boot) | Time of thi
|
||||
static NSURL *build_file(void) {
|
||||
NSFileManager *fm = NSFileManager.defaultManager;
|
||||
NSString *doc = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
||||
NSData *cur = [NSData dataWithContentsOfFile:[doc stringByAppendingPathComponent:@"boot.txt"]], *prev = [NSData dataWithContentsOfFile:[doc stringByAppendingPathComponent:@"boot.previous.txt"]];
|
||||
NSData *(^rd)(NSString *) = ^NSData *(NSString *n) { return [NSData dataWithContentsOfFile:[doc stringByAppendingPathComponent:n] options:NSDataReadingMappedIfSafe error:nil]; }; // 映射着读:日志没有字节封顶,整读进内存再拼、再洗各拷一遍,峰值是日志的四倍 | read through a mapping: the log has no byte cap, and reading it whole into memory, then joining and scrubbing with one copy each, peaks at four times the log size
|
||||
NSData *cur = rd(@"boot.txt"), *prev = rd(@"boot.previous.txt");
|
||||
NSDictionary *inf = NSBundle.mainBundle.infoDictionary; NSString *build = [inf[@"CFBundleVersion"] description] ?: @"未知";
|
||||
NSDateFormatter *df = [NSDateFormatter new]; df.dateFormat = @"yyyy-MM-dd HH:mm:ss ZZZ";
|
||||
char hw[64] = "未知"; size_t hn = sizeof hw; sysctlbyname("hw.machine", hw, &hn, NULL, 0);
|
||||
@@ -73,11 +74,11 @@ static NSURL *build_file(void) {
|
||||
[fm removeItemAtPath:dir error:nil]; [fm createDirectoryAtPath:dir withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
df.dateFormat = @"yyyyMMdd_HHmmss";
|
||||
NSString *p = [dir stringByAppendingPathComponent:[NSString stringWithFormat:@(dm_ui("dmShareLogFile")), build, [df stringFromDate:NSDate.date]]];
|
||||
out = [scrub_home(out) mutableCopy];
|
||||
if (![out writeToFile:p atomically:YES]) { plog("诊断日志:【红】导出文件写不进 %s", p.UTF8String); return nil; }
|
||||
plog("诊断日志:已打包 %s(%lu 字节:本局 %lu、上一局 %s)", p.lastPathComponent.UTF8String, (unsigned long)out.length, (unsigned long)cur.length,
|
||||
NSData *fin = scrub_home(out);
|
||||
if (![fin writeToFile:p atomically:YES]) { plog("诊断日志:【红】导出文件写不进 %s", p.UTF8String); return nil; }
|
||||
plog("诊断日志:已打包 %s(%lu 字节:本局 %lu、上一局 %s)", p.lastPathComponent.UTF8String, (unsigned long)fin.length, (unsigned long)cur.length,
|
||||
prev ? [NSString stringWithFormat:@"%lu", (unsigned long)prev.length].UTF8String : "没有");
|
||||
if (getenv("DM_TEST_SHARELOG_CLOSE")) [out writeToFile:[doc stringByAppendingPathComponent:@"sharelog_test.txt"] atomically:YES];
|
||||
if (getenv("DM_TEST_SHARELOG_CLOSE")) [fin writeToFile:[doc stringByAppendingPathComponent:@"sharelog_test.txt"] atomically:YES];
|
||||
return [NSURL fileURLWithPath:p];
|
||||
}
|
||||
static UIViewController *top_vc(void) { // 同 front_ios.m 系统输入框找宿主的顺序:主窗口 → 前台活跃场景的窗口 → 任一窗口,再顺着已弹出的往上找 | Same order as front_ios.m's system input box uses to find its host: main window → a window of the foreground active scene → any window, then walk up through what is already presented
|
||||
|
||||
@@ -1055,7 +1055,7 @@ int front_text_input(const char *title, const char *sub, const char *guide, cons
|
||||
tf.text = [tf.text substringWithRange:keep];
|
||||
}] forControlEvents:UIControlEventEditingChanged];
|
||||
}];
|
||||
void (^finish)(int) = ^(int ok) { g_text_alert = nil; g_text_alert_finish = nil; if (ok) text = a.textFields.firstObject.text;
|
||||
void (^finish)(int) = ^(int ok) { UIAlertController *sa = wa; g_text_alert = nil; g_text_alert_finish = nil; if (ok) text = sa.textFields.firstObject.text; // 弱引用对话框:按钮回调 → finish → 对话框 → 按钮 是个环,对话框每弹一次留一个 | weak reference to the dialog: button callback -> finish -> dialog -> button is a cycle, leaving one dialog behind every time it is shown
|
||||
// 名字留空点确定 = 随机取名:我们自己抽一个(dm_namegen.c,约 1.8 万种、与已有角色重名就再抽),当作玩家输入的名字返回,走游戏原本的起名校验;只填进名字框不自动接受(同原版「随机名字」键,玩家看到再点创建)。
|
||||
// 原先发原版「随机名字」键,那是按职业在 12 个名字里依次轮,容易撞
|
||||
// Leaving the name empty and tapping OK = random naming: we draw one ourselves (dm_namegen.c, about 18,000 variants; redraw if it collides with an existing character), return it as the name the player typed, and go through the game's original name validation; it is only filled into the name field and not auto-accepted (same as the original game's 「随机名字」(Random Name) key: the player sees it and then taps create).
|
||||
@@ -1353,6 +1353,7 @@ static void touch_script_start(void) {
|
||||
while(next<steps.count && [steps[next][0] doubleValue]<=now) {
|
||||
NSArray *f=steps[next++]; NSString *op=f.count>1?f[1]:@""; aw_on=0;
|
||||
if([op isEqualToString:@"shot"]) window_shot(f[2]);
|
||||
else if([op isEqualToString:@"burst"] && f.count>=4) { void dm_gfx_burst(int, const char *); dm_gfx_burst([f[2] intValue], [doc stringByAppendingPathComponent:f[3]].UTF8String); LOG("[script] burst %d 帧 → %s", [f[2] intValue], [f[3] UTF8String]); }
|
||||
else if([op isEqualToString:@"tshot"]) [g_touch_view captureTouchLayer:[doc stringByAppendingPathComponent:f[2]]]; // 操作层 PNG + 控件/当前技能元数据 JSON | Control layer PNG + JSON metadata of widgets / current skills
|
||||
// type <文字>:往弹着的输入对话框里敲字——走 UITextField 的 insertText:(系统键盘上屏走的同一个入口,照样触发输入规则的拦截);
|
||||
// alert ok|cancel:点对话框的「确定」/「取消」。两者都只在对话框弹着时有效,没弹着就记一行日志
|
||||
|
||||
@@ -17,6 +17,8 @@ static int g_nofile_was, g_nofile_now; // 启动时的文件描述符软上限
|
||||
#include <dirent.h>
|
||||
#include <libkern/OSCacheControl.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <os/proc.h>
|
||||
#include <mach/mach.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
@@ -689,6 +691,8 @@ static void host_start(void) {
|
||||
{ extern int dm_shader_prep_begin(void (^)(void)); static int asked; if (!asked) { asked = 1; if (dm_shader_prep_begin(^{ host_start(); })) return; } }
|
||||
#endif
|
||||
g_host_up = 1; plog("boot: 场景到前台,起宿主(进程已活 %.1f ms)", since_start());
|
||||
{ const char *mw = getenv("DM_TEST_MEMWARN"); // 测试开关 DM_TEST_MEMWARN=<秒>:起宿主后这么多秒,照系统的调法调一次内存告警回调(验那一行日志;系统真发告警的时机造不出来) | test switch DM_TEST_MEMWARN=<seconds>: this many seconds after the host starts, call the memory-warning callback once the way the system does (to check that log line; the moment the system really sends a warning cannot be staged)
|
||||
if (mw && atof(mw) > 0) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(atof(mw) * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ UIApplication *app = UIApplication.sharedApplication; [app.delegate applicationDidReceiveMemoryWarning:app]; }); }
|
||||
boot_begin(); // 覆盖层、宿主装载与预取:也等到这里才做(在后台线程,和后面的界面收尾并行) | overlay, host loading and prefetch: also deferred until here (on a background thread, in parallel with the UI wrap-up that follows)
|
||||
front_ios_lifecycle_install(); // 过热 / 不自动锁屏 / 亮度(窗口与焦点在 SceneDelegate) | overheating / no auto-lock / brightness (window and focus are in SceneDelegate)
|
||||
run_boot(); // 宿主线程自己写 DONE | The host thread writes DONE itself
|
||||
@@ -948,6 +952,19 @@ static void bg_relaunch_test(void) {
|
||||
|
||||
@implementation App
|
||||
- (void)applicationWillTerminate:(UIApplication *)a { if (g_host_up) dm_host_shutdown("iOS App 终止"); }
|
||||
// 系统内存告警:只记一行,不放任何缓存。用途:玩家被系统按内存终止前不会有任何通知,上一局日志里至少留下前兆与当时的几项读数
|
||||
// (常驻、显卡已分配、游戏主堆余量是上次每 300 帧读到的值、离系统内存上限还有多少)。一局最多记 50 行
|
||||
// System memory warning: log one line only, release no cache. Purpose: a player gets no notice before the system terminates the app for memory, so the previous session's log at least keeps the precursor and a few readouts at that moment
|
||||
// (resident size, GPU allocated, main-heap free space as last read every 300 frames, and how far from the system memory limit). At most 50 lines per session
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)a {
|
||||
static int n; if (++n > 50) return;
|
||||
task_vm_info_data_t vi; mach_msg_type_number_t cnt = TASK_VM_INFO_COUNT; unsigned long long fp = 0;
|
||||
if (task_info(mach_task_self(), TASK_VM_INFO, (task_info_t)&vi, &cnt) == KERN_SUCCESS) fp = vi.phys_footprint >> 20;
|
||||
unsigned long long h[3] = {0, 0, 0}, gpu = 0; void dm_guest_heap_last(unsigned long long *); unsigned long long mtl_gpu_allocated_mb(void);
|
||||
if (g_host_up) { dm_guest_heap_last(h); gpu = mtl_gpu_allocated_mb(); }
|
||||
plog("【内存告警】系统发来内存告警(本局第 %d 次,进程已活 %.0f 秒,applicationState=%ld):常驻 %llu MB,显卡已分配 %llu MB,游戏堆 %llu MB 余量 %llu MB 最大可分配块 %llu KB,离系统内存上限还有 %llu MB",
|
||||
n, since_start() / 1000.0, (long)a.applicationState, fp, gpu, h[0], h[1], h[2], (unsigned long long)(os_proc_available_memory() >> 20));
|
||||
}
|
||||
- (void)application:(UIApplication *)a handleEventsForBackgroundURLSession:(NSString *)ident completionHandler:(void (^)(void))done {
|
||||
plog("boot: 系统交来后台下载会话 %s 的事件(applicationState=%ld,宿主%s)", ident.UTF8String, (long)a.applicationState, g_host_up ? "在跑" : "没起");
|
||||
if ([ident hasSuffix:@".bgtest"]) { plog("后台测试会话:接回"); (void)bg_test_session(); done(); return; }
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
# 连拍分析:burst_sad.py <连拍目录>。连拍由触点脚本步骤「burst <帧数> <目录名>」产出(nvn_mtl.m burst_grab),目录在 App 的 Documents 下。
|
||||
# 每对相邻帧:高通后去掉屏幕中心人物那块,在 ±R 像素内找绝对差最小的整像素位移(环境变量 R,缺省 14;30 帧档每帧位移大,给 26);
|
||||
# 同时打印 meta.txt 里记的本地玩家逻辑位移(格)。相位相关在草地这类弱纹理上会读成 0,所以用块匹配
|
||||
# Burst analysis: burst_sad.py <burst directory>. A burst is produced by the touch-script step "burst <frames> <directory name>" (nvn_mtl.m burst_grab); the directory is under the App's Documents.
|
||||
# For each pair of adjacent frames: after a high-pass, with the character block at the screen centre removed, find the whole-pixel displacement with the smallest absolute difference within +-R pixels (environment variable R, default 14; at 30 fps the per-frame displacement is larger, use 26);
|
||||
# the logical displacement of the local player (tiles) recorded in meta.txt is printed alongside. Phase correlation reads 0 on weak textures such as grass, hence block matching
|
||||
import os,sys,numpy as np
|
||||
from PIL import Image, ImageFilter
|
||||
d=sys.argv[1]; L=open(d+'/meta.txt').read().split('\n'); n=int(L[0].split()[-1]); W=int(L[0].split()[1]); L=L[1:n+1]
|
||||
P=[(float(l.split()[8]),float(l.split()[10])) for l in L] if len(L[0].split())>8 else None
|
||||
def hp(k):
|
||||
a=np.frombuffer(open(f'{d}/f{k:03d}.raw','rb').read(),dtype=np.uint8).reshape(W,W,4)[:,:,:3].mean(2)
|
||||
im=Image.fromarray(a.astype(np.uint8)); b=np.asarray(im.filter(ImageFilter.GaussianBlur(6)),dtype=float); return a-b
|
||||
H=[hp(k) for k in range(n)]; c=W//2; R=14
|
||||
R=int(os.environ.get("R","14")); mask=np.ones((W,W),bool); mask[c-160:c+120,c-120:c+120]=False; mask[:R+1]=mask[-R-1:]=False; mask[:,:R+1]=mask[:,-R-1:]=False
|
||||
ys,xs=np.nonzero(mask)
|
||||
out=[]
|
||||
for k in range(n-1):
|
||||
a=H[k][ys,xs]; best=None
|
||||
for dy in range(-R,R+1):
|
||||
for dx in range(-R,R+1):
|
||||
v=np.abs(a-H[k+1][ys+dy,xs+dx]).mean()
|
||||
if best is None or v<best[0]: best=(v,dx,dy)
|
||||
out.append((best[1],best[2]))
|
||||
for k,(dx,dy) in enumerate(out):
|
||||
lp='' if not P else ' 逻辑位移 %+.2f,%+.2f'%(P[k+1][0]-P[k][0],P[k+1][1]-P[k][1])
|
||||
print(f'{k:3d}→{k+1:3d} 画面位移 {dx:+d},{dy:+d}{lp}')
|
||||
@@ -0,0 +1,13 @@
|
||||
# 转向平滑逐帧位移表:turn_trace.py <boot.txt> [起始行号 [行数]]。读宿主日志里的「转向帧迹」行(DM_TEST_TURN_TRACE=1,dm_turnsmooth.c),
|
||||
# 画出来的位置 = 外推坐标 + 误差(1/65536 格);换成屏幕方向的位移(格):横 = (dx − dy),纵 = (dx + dy) / 2(等距投影,纵向压一半)。
|
||||
# 输出每帧:序号 横位移 纵位移 位移模 | 外推坐标自身的位移模(= 不做平滑时画面的走法)| 误差模 在走 外推拍比例
|
||||
# Per-frame displacement table for turn smoothing: turn_trace.py <boot.txt> [start line [line count]]. Reads the turn-trace lines in the host log (DM_TEST_TURN_TRACE=1, dm_turnsmooth.c);
|
||||
# the drawn position = extrapolated coordinates + error (1/65536 tile); converted to displacement in screen directions (tiles): horizontal = (dx - dy), vertical = (dx + dy) / 2 (isometric projection, vertical halved).
|
||||
# Output per frame: index, horizontal displacement, vertical displacement, displacement magnitude | displacement magnitude of the extrapolated coordinates alone (= how the picture would move without smoothing) | error magnitude, walking, extrapolated tick fraction
|
||||
import sys,re
|
||||
rows=[tuple(float(v) for v in m.groups()) for m in (re.search(r'转向帧迹 (-?\d+) (-?\d+) (-?\d+) (-?\d+) (\d) ([\d.]+) ([\d.]+)',l) for l in open(sys.argv[1],encoding='utf-8',errors='replace')) if m]
|
||||
a=int(sys.argv[2]) if len(sys.argv)>2 else 0; n=int(sys.argv[3]) if len(sys.argv)>3 else len(rows)
|
||||
def scr(dx,dy): return (dx-dy)/65536,(dx+dy)/131072
|
||||
for i in range(max(1,a),min(len(rows),a+n)):
|
||||
p,q=rows[i-1],rows[i]; sx,sy=scr(q[0]+q[2]-p[0]-p[2],q[1]+q[3]-p[1]-p[3]); rx,ry=scr(q[0]-p[0],q[1]-p[1])
|
||||
print('%4d 画面 %+.3f %+.3f 模 %.3f | 不平滑 %+.3f %+.3f 模 %.3f | 误差 %.3f 在走 %d 外推 %.2f'%(i,sx,sy,(sx*sx+sy*sy)**.5,rx,ry,(rx*rx+ry*ry)**.5,((q[2]/65536)**2+(q[3]/65536)**2)**.5,int(q[4]),q[5]))
|
||||
@@ -61,6 +61,7 @@ dm/host/dm_cursor* a c f g h j m n p q s t u sb cb sl1 sl2 me1 me2 pg2 vt1 rw1 b
|
||||
dm/host/hle_touch* a c f g h j m n p q s t u sb cb sl1 sl2 me1 me2 pg2 vt1 rw1 bd
|
||||
dm/host/touch_mac.c a c j s sb pg2 vt1 rw1
|
||||
dm/ios/tools/touch_layout.py a c f g h j k m n p q s t u sb cb sl1 me1 me2 pg2 vt1 vf1 vf2 rw1 rw2 kba bd pk pvb
|
||||
dm/ios/Sources/dm_sharelog.m shl
|
||||
dm/ios/Sources/front_ios.m a c f g h j m n p q s t u sb cb sl1 sl2 me1 me2 pg2 vt1 rw1 bd pk
|
||||
dm/ios/Sources/* a e pk rf2
|
||||
dm/ios/NativeHUD/* a f pk bd g q
|
||||
|
||||
|
@@ -668,6 +668,13 @@ def groups():
|
||||
g.item("「综合技能」页长按另一个技能","开绑定框",r"OpenPanel ButtonBindingModal"); g.hold(301,114,1.3); g.shot()
|
||||
g.tap(P(120,200),1.5); g.tap(P(615,17),1.2)
|
||||
gs.append(g)
|
||||
# shl 局:暂停菜单「分享诊断日志」。测试开关让分享面板弹出 3 秒后自己收起(真机截不到系统弹层,只读日志);导出的文件另拷一份到容器 Documents/sharelog_test.txt
|
||||
# shl run: pause menu "Share diagnostic log". A test switch lets the share sheet dismiss itself 3 seconds after it appears (system overlays cannot be captured on a device, only the log is read); the exported file is also copied to Documents/sharelog_test.txt in the container
|
||||
g=G("shl","DM_TEST_SHARELOG_CLOSE=3"); g.sect("sharelog",0); g.enter(); g.tap("@menu",1.4); g.tap(P(551,17))
|
||||
g.item("暂停菜单点「分享诊断日志」","两份日志打成一个文件(本局那份非空)、分享面板弹出",r"诊断日志:已打包 \S+(\d+ 字节:本局 [1-9]\d*、[^\n]*\n(?:[^\n]*\n){0,40}?[^\n]*诊断日志:分享面板已弹出"); g.at("tap_ui MessageLog@PauseLayoutGarden 3",2.5); g.shot()
|
||||
g.item("等 3 秒","分享面板到点自己收起",r"到点收起分享面板"); g.wait(3.0); g.shot()
|
||||
g.item("再点一次「分享诊断日志」","又能打包(上一次收起后没卡在忙状态)",r"诊断日志:已打包"); g.at("tap_ui MessageLog@PauseLayoutGarden 3",5.5); g.shot()
|
||||
gs.append(g)
|
||||
# i 局:雇佣兵(第一幕卡夏;第二幕格雷兹是同一个雇佣面板)。最小步骤来自一条真问题:雇佣名单里同一行连点几下、雇成之后面板栈的计数没清,摇杆和技能钮回不来
|
||||
# i run: hiring a mercenary (Act 1 Kashya; Act 2 Greiz is the same hire panel). The minimal steps come from a real problem: tapping the same row of the hire list several times, the panel stack count was not cleared after the hire succeeded, and the stick and skill buttons did not come back
|
||||
g=G("i","DM_TEST_GOLD=200000 DM_TEST_WORLD_GO=near2:1:c150@200"); g.sect("hire",0); g.enter(1)
|
||||
|
||||
+22
-9
@@ -3,22 +3,26 @@
|
||||
# 包里有:宿主程序、改写后的游戏程序(产物目录,种类 DM_MAC_PRODUCT,缺省 touch)、有界面覆盖层就带上(DM_MAC_OVERLAY=<目录>)。
|
||||
# DM_MAC_LINK=1:不带派生物的出法——改写后的游戏程序、着色器库、界面覆盖层都是从游戏内容派生的,公开发布的包不能带;
|
||||
# 这样出的包里只有宿主程序和 Resources/paths.txt(三项各指向本机构建产物的路径),只在构建它的这台机器上能跑。
|
||||
# 版本:给人看的版本号 DM_MAC_VERSION(缺省 1.0,与 iOS 包同叫法);构建号 DM_MAC_BUILD(缺省取当前月日时分,同 iOS 包格式)。产物代号与提交号写在包里的 Resources/build.txt。
|
||||
# 游戏资源不进包:第一次启动请玩家选资源文件夹(host/app_mac.m)。签名用本地临时签名,本机直接能跑。
|
||||
# Package the Mac host as a macOS App that starts on double-click: mac_app.sh [output dir] produces <output dir>/D2R Mobile.app (default $DM_ROOT/out/macapp)
|
||||
# The package holds: the host program, the rewritten game program (build output directory, kind DM_MAC_PRODUCT, default touch), and the UI overlay when there is one (DM_MAC_OVERLAY=<dir>).
|
||||
# DM_MAC_LINK=1: the build without derived content -- the rewritten game program, the shader library and the UI overlay are all derived from game content and must not be in a publicly released package;
|
||||
# a package built this way holds only the host program and Resources/paths.txt (three entries, each pointing at a build output on this machine) and runs only on the machine that built it.
|
||||
# Game resources never go into the package: on first launch the player is asked to choose the resource folder (host/app_mac.m). Signing is local ad-hoc signing, which runs on this machine directly.
|
||||
# Wrap the Mac host into a macOS App that starts on double-click: mac_app.sh [output directory] produces <output directory>/D2R Mobile.app (default $DM_ROOT/out/macapp)
|
||||
# The package holds: the host program, the rewritten game program (build output directory, kind DM_MAC_PRODUCT, default touch), and the UI overlay when there is one (DM_MAC_OVERLAY=<directory>).
|
||||
# DM_MAC_LINK=1: build without derived content - the rewritten game program, the shader libraries and the UI overlay are all derived from game content and must not be in a publicly released package;
|
||||
# a package built this way holds only the host program and Resources/paths.txt (three entries, each pointing at a build output on this machine), and runs only on the machine that built it.
|
||||
# Version: the human-readable version DM_MAC_VERSION (default 1.0, named the same way as the iOS package); the build number DM_MAC_BUILD (default: current month-day-hour-minute, same format as the iOS package). The build output generation and the commit are written to Resources/build.txt in the package.
|
||||
# Game resources do not go into the package: on first launch the player is asked to choose the resource folder (host/app_mac.m). Signing is local ad-hoc signing, which runs directly on this machine.
|
||||
set -eu
|
||||
HERE=$(cd "$(dirname "$0")" && pwd); DM=$HERE/..; ROOT=${DM_ROOT:-$HOME/dm-work}
|
||||
OUT=${1:-$ROOT/out/macapp}; KIND=${DM_MAC_PRODUCT:-touch}; BID=${DM_MAC_BUNDLE_ID:-org.d2rmobile.mac}
|
||||
P=$(bash "$HERE/product.sh" path "$KIND"); [ -f "$P/main.patched.bin" ] || { echo "🔴 没有产物 ${P}(先跑 product.sh build)"; exit 2; }
|
||||
make -C "$DM/host" > /dev/null
|
||||
MIN=$(make -s -C "$DM/host" print-macos-min) # 最低系统版本:与编译宿主用的是同一个数(host/Makefile 的 MACOS_MIN) | minimum system version: the same number the host is compiled with (MACOS_MIN in host/Makefile)
|
||||
APP="$OUT/D2R Mobile.app"; rm -rf "$APP"; mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources"
|
||||
cp "$DM/host/dmhost" "$APP/Contents/MacOS/D2RMobile"
|
||||
LINK=${DM_MAC_LINK-1}; [ "$LINK" != 0 ] || LINK=; RES="$APP/Contents/Resources"; : > "$RES/paths.txt"
|
||||
if [ -n "$LINK" ]; then echo "product=$P" >> "$RES/paths.txt"; else cp -R "$P" "$RES/product"; fi
|
||||
cp "$DM/gfx/nvn/shader_map.tsv" "$APP/Contents/Resources/shader_map.tsv"
|
||||
cp "$DM/gfx/nvn/pso_manifest.tsv" "$APP/Contents/Resources/pso_manifest.tsv" # 管线预热的种子清单:图形后端按「与映射表同目录」找它(两种出法都带;漏带的包开局边画边现编管线——的日志里现编了 102 条) | seed list for pipeline warm-up: the graphics backend looks for it "in the same directory as the mapping table" (both ways of building carry it; a package without it compiles pipelines on the fly while drawing at the start of a game - 102 of them in one log)
|
||||
[ ! -f "$DM/gfx/nvn/c1_full.tsv" ] || cp "$DM/gfx/nvn/c1_full.tsv" "$APP/Contents/Resources/c1_full.tsv" # 图形后端按「与映射表同目录」找它 | The graphics backend looks for it "in the same directory as the mapping table"
|
||||
# 编好的着色器库(Mac 版,dmsh_build.py 出的):只带运行要用的 .metallib 与反射 .json,源码 .metal 不带
|
||||
# The compiled shader library (Mac variant, produced by dmsh_build.py): only the .metallib and reflection .json needed at run time are included, not the .metal sources
|
||||
@@ -34,7 +38,8 @@ if [ "${DM_MAC_OVERLAY:-}" != none ]; then
|
||||
else DM_OVERLAY_MAC=1 python3 "$DM/ios/tools/gen_romfs_overlay.py" "${DM_ROMFS_SRC:-$ROOT/data/switch/3.3.94012/Update/RomFS}" "$OVD" > /dev/null || { echo "🔴 界面覆盖层生成失败"; exit 2; }; fi
|
||||
fi
|
||||
[ -s "$RES/paths.txt" ] || rm -f "$RES/paths.txt"
|
||||
VER=$(cat "$DM/PRODUCT")
|
||||
VER=${DM_MAC_VERSION:-1.0}; BUILD=${DM_MAC_BUILD:-$(date +%m%d%H%M)}
|
||||
echo "版本 ${VER} 构建 ${BUILD} 产物 $(basename "$P") 提交 $(git -C "$DM" rev-parse --short HEAD 2>/dev/null || echo 未知)" > "$RES/build.txt"
|
||||
cat > "$APP/Contents/Info.plist" <<PL
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
@@ -45,12 +50,20 @@ cat > "$APP/Contents/Info.plist" <<PL
|
||||
<key>CFBundleExecutable</key><string>D2RMobile</string>
|
||||
<key>CFBundlePackageType</key><string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key><string>$VER</string>
|
||||
<key>CFBundleVersion</key><string>$(git -C "$DM" rev-parse --short HEAD 2>/dev/null || echo 0)</string>
|
||||
<key>LSMinimumSystemVersion</key><string>13.0</string>
|
||||
<key>CFBundleVersion</key><string>$BUILD</string>
|
||||
<key>LSMinimumSystemVersion</key><string>$MIN</string>
|
||||
<key>NSHighResolutionCapable</key><true/>
|
||||
<key>LSApplicationCategoryType</key><string>public.app-category.role-playing-games</string>
|
||||
<key>GCSupportsControllerUserInteraction</key><true/>
|
||||
</dict></plist>
|
||||
PL
|
||||
# 自检:管线预热的种子清单在包里、与映射表同目录、不是空的
|
||||
# Self-check: the seed list for pipeline warm-up is in the package, in the same directory as the mapping table, and not empty
|
||||
[ -s "$RES/pso_manifest.tsv" ] && [ -s "$RES/shader_map.tsv" ] || { echo "🔴 包里缺管线预热种子清单或着色器映射表(Resources/pso_manifest.tsv、shader_map.tsv)"; exit 3; }
|
||||
# 自检:程序本体里记的最低系统版本要与 Info.plist 写的相等(不等时老系统上双击只会得到一句「不能与此版本的 macOS 配合使用」);只许有 arm64 一个架构
|
||||
# Self-check: the minimum system version recorded in the executable must equal the one written in Info.plist (if they differ, double-clicking on an older system only yields "cannot be used with this version of macOS"); only the single arm64 architecture is allowed
|
||||
BIN_MIN=$(otool -l "$APP/Contents/MacOS/D2RMobile" | awk '$1=="minos"{print $2; exit}'); PL_MIN=$(/usr/libexec/PlistBuddy -c "Print :LSMinimumSystemVersion" "$APP/Contents/Info.plist")
|
||||
[ -n "$BIN_MIN" ] && [ "$BIN_MIN" = "$PL_MIN" ] || { echo "🔴 最低系统版本对不上:程序本体 ${BIN_MIN:-读不到},Info.plist ${PL_MIN}"; exit 3; }
|
||||
ARCHS=$(lipo -archs "$APP/Contents/MacOS/D2RMobile"); [ "$ARCHS" = arm64 ] || { echo "🔴 程序本体的架构不是只有 arm64:${ARCHS}"; exit 3; }
|
||||
codesign --force -s - "$APP" > /dev/null 2>&1 || { echo "🔴 本地签名失败"; exit 3; }
|
||||
echo "MACAPP ${APP}(产物 $(basename "$P"),$(du -sh "$APP" | cut -f1)${LINK:+,不带派生物:只能在本机跑})"
|
||||
echo "MACAPP ${APP}(版本 ${VER} 构建 ${BUILD},最低系统 macOS ${MIN},产物 $(basename "$P"),$(du -sh "$APP" | cut -f1)${LINK:+,不带派生物:只能在本机跑})"
|
||||
|
||||
@@ -638,6 +638,8 @@ if RULE_RUN and PRIVATE_GATES:
|
||||
obs.append((0x634000, 16, "d10143ff", "server level change by level number (game, player, level, kind), used by waypoints / portals / quest moves: in a rift game, when the player leaves a rift map for a level that is neither town nor a rift map, the host swaps w2 to the rift's next map so the destination is replaced inside the single native transition"))
|
||||
obs.append((0x711040, 17, "d101c3ff", "server quest event 'monster killed' entry (game, monster, attacker), the only entry (callers 0x7d8550 kill, 0x7ab8dc); in a rift game, for a monster that died on a rift map, the host swaps x1 to a stand-in whose +0xc0 is null so the function takes its own early return (0x711064): bosses in the rift are combat only, no quest state / quest notifications"))
|
||||
obs.append((0x3d84a0, 18, "d10143ff", "NotificationPanel message handler entry (panel, message): on InputMessage / ControllerActionBegin with action id 9 (the menu key) the native handler re-sends the notice callback and marks the message bus consumed, so the first menu press only dismisses the notice. In touch mode the host swaps x1 to a copy of the message whose action id is not 9: the notice stays until it times out and the menu key opens the menu; controller mode keeps the native behaviour"))
|
||||
obs.append((0x463f40, 19, "f81c0ff7", "client per-frame position-error smoothing entry (s0 = frame length in ticks), called by the main loop right after all units were extrapolated in place and before the per-unit error is added back: the native error is only computed on start / stop (0x4639c0, which runs before the tick loop), so a sharp turn inside a tick snaps the extrapolated position back in one frame; the host adds that frame's jump to the local player's error fields (path +0x2a8 / +0x2ac, same clamp as native) and the native code decays it"))
|
||||
obs.append((0x9da5b0, 20, "d104c3ff", "model yaw component per-frame update entry (x1 = argument block: +8 component, +0x20 -> +8 unit): the body turn speed is instance data on the component (+0x10..+0x2c min / max degrees per second for controller / mouse, +0x34 spring parameter); the host only reads them for the local player when a test switch is set"))
|
||||
obs.append((0x2f7664, 7, "6dbb23e9", "touch target rank: candidate compare entry (closure, unit, kind, s0=score); host raises Boss/elite score, native eligibility unchanged"))
|
||||
for off, oid, ow, why in obs:
|
||||
w = struct.unpack_from('<I', IMG, off)[0]
|
||||
|
||||
Reference in New Issue
Block a user