From ea86e79688f9339319de3e2c52c69b8b13e30e9e Mon Sep 17 00:00:00 2001 From: jhaizhou <258432107+jhaizhou-ops@users.noreply.github.com> Date: Mon, 12 Oct 2026 21:09:04 +0800 Subject: [PATCH] Fix shell packaging (issue #1): drop stale prefetch list, clearer pack error; sync with trunk --- dm/host/dm_pouch.c | 23 +++++++++++++++++++++++ dm/ios/tools/uireg/affected.tsv | 2 +- dm/ios/tools/uireg/uireg.py | 15 ++++++++++++++- dm/tools/d2rm_pack.py | 2 +- dm/tools/patch_nso.py | 2 ++ docs/DEPENDENCIES.md | 1 + docs/DEPENDENCIES.zh-CN.md | 1 + docs/DERIVED.md | 2 +- docs/DERIVED.zh-CN.md | 2 +- 9 files changed, 45 insertions(+), 5 deletions(-) diff --git a/dm/host/dm_pouch.c b/dm/host/dm_pouch.c index b30d62b..b849f6d 100644 --- a/dm/host/dm_pouch.c +++ b/dm/host/dm_pouch.c @@ -248,6 +248,17 @@ static int adv_stack_full(uint64_t G, uint64_t player, uint32_t code) { // 高 void dm_pouch_c2s(uint64_t *regs) { // regs:x0 游戏、x1 玩家、x2 包、x3 长度(可改) | regs: x0 game, x1 player, x2 packet, x3 length (writable) uint64_t G = regs[0], player = regs[1]; const uint8_t *pk = (const uint8_t *)(uintptr_t)regs[2]; uint32_t len = (uint32_t)regs[3]; if (!B || !G || !player || !pk) return; if (len == 17 && pk[0] == 0x19) { uint32_t pg; memcpy(&g_pick_id, pk + 1, 4); memcpy(&g_pick_x, pk + 5, 4); memcpy(&g_pick_y, pk + 9, 4); memcpy(&pg, pk + 13, 4); if (pg) g_pick_id = 0; return; } // 只记从背包(页 0)拿起的 | only record pickups from the inventory (page 0) + // 手柄「按住确认键移到当前页」(触屏双击不可成叠物品也是它):物品还在背包里、不经手上——个人页 0x54 [物品 id]…(21 字节)、共享页 0x55 [物品 id][共享页单位]…(29 字节),实录。 + // 三类物品走这条时直接把整条包换成原版「移到仓库」0x63(背包来源);叠满就不换,照原样落到玩家选的那一页(共享页的在这里提示,个人页的由 stash_sweep 发一次没进去后提示) + // Gamepad "hold the confirm button to move to the current page" (a touch double-tap on a non-stackable item is the same thing): the item stays in the backpack and never goes onto the cursor -- personal page 0x54 [item id]... (21 bytes), shared page 0x55 [item id][shared page unit]... (29 bytes), as recorded. + // When one of the three item kinds takes this path, the whole packet is replaced with the original "move to stash" 0x63 (backpack source); when the stack is full it is not replaced and lands on the page the player chose as usual (the shared page case shows a hint here, the personal page case is hinted after stash_sweep sends once and it does not go in) + if ((len == 21 && pk[0] == 0x54) || (len == 29 && pk[0] == 0x55)) { uint32_t id; memcpy(&id, pk + 1, 4); + uint64_t dm_diag_srv_item(uint32_t); uint64_t it = dm_diag_srv_item(id); if (!it || !bag_item(player, id) || !(is_rune_gem(it) || is_mat(it))) return; + uint32_t unit = adv_stash_unit(player); int near = ((int (*)(uint64_t, uint64_t, int, int))(B + 0x650d10))(G, player, 0x10b, 0x32) & 1; if (!unit || !near) return; + uint32_t code = item_code(it); + if (adv_stack_full(G, player, code)) { if (pk[0] == 0x55) g_c2s_full = 1; LOG("珍宝匣:%.3s(id %u)按住确认键移到%s页,高级仓库那一格已叠满 → 照原样移过去", (const char *)&code, id, pk[0] == 0x55 ? "共享" : "个人"); return; } + static uint8_t st[25]; memset(st, 0, sizeof st); st[0] = 0x63; memcpy(st + 5, &id, 4); memcpy(st + 9, &unit, 4); regs[2] = (uint64_t)(uintptr_t)st; regs[3] = 25; + LOG("珍宝匣:%.3s(id %u)按住确认键移到%s页 → 改成原版移到仓库(高级仓库单位 %u)", (const char *)&code, id, pk[0] == 0x55 ? "共享" : "个人", unit); return; } if (len != 13 || pk[0] != 0x45) return; uint32_t id; memcpy(&id, pk + 1, 4); if (!id || id != g_pick_id) return; // 不是刚从背包拿起的那件(比如从别的页拖过来的):不管 | not the item just picked up from the inventory (e.g. dragged from another page): ignore uint64_t dm_diag_srv_item(uint32_t); uint64_t it = dm_diag_srv_item(id); if (!it || !(is_rune_gem(it) || is_mat(it))) return; @@ -449,6 +460,18 @@ void dm_pouch_srv_tick(uint8_t *b, uint64_t G, uint64_t player) { // 服务端 if (go63) { move_to_stash(b, G, player, id, unit); if (nw < 64) wl[nw++] = (watch){ id, tq }; LOG("百宝囊:物品 id %u 在储藏箱旁 → 原版移到仓库(高级仓库单位 %u)", id, unit); } else if (!unit) LOG("百宝囊:物品 id %u —— 这个角色没有高级仓库,不收", id); else if (pouch_put(b, G, player, id) > 0) saved = 1; } + // 测试开关 DM_TEST_HOLDY=<拍>:<物品码>:<54|55>(手柄光标不好用脚本摆位,用它造「按住确认键移到当前页」):到拍对背包里第一件这种物品代发那条包(字段照实录的填:个人页 0x54、共享页 0x55),走收包分发、会经过上面的改道 + // Test switch DM_TEST_HOLDY=::<54|55> (the gamepad cursor is hard to position from a script, so this creates "hold the confirm button to move to the current page"): at that tick, send that packet on behalf of the first such item in the backpack (fields filled as recorded: personal page 0x54, shared page 0x55), going through packet dispatch and therefore through the rerouting above + { static int at = -1, kind; static char code[5]; if (at < 0) { const char *e = getenv("DM_TEST_HOLDY"); if (!e || sscanf(e, "%d:%4[^:]:%x", &at, code, &kind) != 3) at = 0; } + if (at > 0 && tq >= (uint32_t)at) { at = 0; uint64_t inv = *(uint64_t *)(player + 0x90), it = inv && *(uint32_t *)inv == 0x01020304 ? *(uint64_t *)(inv + 0x10) : 0, f = 0; + for (int k = 0; it && k < 2048 && !f; k++) { uint64_t d = *(uint64_t *)(it + 0x10); if (!d) break; uint32_t c = item_code(it); if (*(uint32_t *)(it + 0xc) == 0 && *(uint8_t *)(d + 0x55) == 0 && !memcmp(&c, code, strlen(code))) f = it; else it = *(uint64_t *)(d + 0xb0); } + if (f) { uint64_t pp = *(uint64_t *)(f + 0x38); uint32_t id = *(uint32_t *)(f + 8), sh = 0; uint16_t x = pp ? (uint16_t)*(int32_t *)(pp + 0x10) : 0, y = pp ? (uint16_t)*(int32_t *)(pp + 0x14) : 0; uint8_t pk[29]; memset(pk, 0, sizeof pk); + for (uint64_t en = inv ? *(uint64_t *)(inv + 0x68) : 0, n = 0; en && n < 16 && !sh; en = *(uint64_t *)(en + 0x10), n++) if (*(uint8_t *)(en + 9) && !*(uint8_t *)(en + 0xa)) sh = *(uint32_t *)en; + int ln; pk[0] = (uint8_t)kind; memcpy(pk + 1, &id, 4); + if (kind == 0x55) { memcpy(pk + 5, &sh, 4); memcpy(pk + 13, &x, 2); memcpy(pk + 15, &y, 2); pk[17] = 4; pk[21] = 0x0d; pk[23] = 9; ln = 29; } + else { memcpy(pk + 9, &x, 2); memcpy(pk + 11, &y, 2); pk[13] = 4; pk[17] = 0x0d; pk[19] = 9; ln = 21; } + LOG("测试 DM_TEST_HOLDY:拍 %u 对背包里的 %s(id %u,格 %u,%u)代发 0x%02x", tq, code, id, x, y, kind); + *(uint32_t *)(G + 0x19050) = 1; ((void (*)(uint64_t, uint64_t, uint8_t *, uint32_t))(b + 0x6e5b40))(G, player, pk, (uint32_t)ln); *(uint32_t *)(G + 0x19050) = 0; } } } for (int i = 0; i < g_c2s_nq; i++) { uint32_t id = g_c2s_q[i]; // 拖进共享页被改道放回背包的(dm_pouch_c2s):人还在箱子旁就发原版移到仓库 | items dragged into the shared tab and rerouted back to the inventory (dm_pouch_c2s): if still at the stash, send the game's move-to-stash if (go63 && bag_item(player, id)) { move_to_stash(b, G, player, id, unit); if (nw < 64) wl[nw++] = (watch){ id, tq }; LOG("珍宝匣:物品 id %u 已回到背包 → 原版移到仓库(高级仓库单位 %u)", id, unit); } else LOG("珍宝匣:物品 id %u 改道后%s,留在背包", id, go63 ? "不在背包里" : "人已离开储藏箱"); } diff --git a/dm/ios/tools/uireg/affected.tsv b/dm/ios/tools/uireg/affected.tsv index 7381c24..ba4672e 100644 --- a/dm/ios/tools/uireg/affected.tsv +++ b/dm/ios/tools/uireg/affected.tsv @@ -31,7 +31,7 @@ dm/host/dm_bossrush* kbb bd dm/host/dm_townwp* * dm/host/dm_rift* kba kbb dc wp tp dm/host/dm_unit.h kbb dc wp tp -dm/host/dm_pouch* t u s sb vt1 c +dm/host/dm_pouch* t u s sb vt1 c sa dm/host/dm_padmode* a f rf2 pk od pvb psel0 psel1 psel2 psel3 dm/host/hle_fs.c rf1 rf2 rf3 e pg2 vt1 v od dm/host/hle_tact* a e od diff --git a/dm/ios/tools/uireg/uireg.py b/dm/ios/tools/uireg/uireg.py index 030cd50..befa4aa 100644 --- a/dm/ios/tools/uireg/uireg.py +++ b/dm/ios/tools/uireg/uireg.py @@ -274,7 +274,7 @@ def stay(s,before): # 人不离开原地:本段第一条与最后一条 pos # 物品栏一侧 +38.5(背包第 0 列 424.5)、关闭钮 654.5、取金币钮 187.5;宝石 / 材料 / 符文 / 魔盒四页回到原版位置。这几局(与 top / v 局开箱那几步)的点位都按这个量过 # After the stash widening (10 → 14 columns, the panel shift multiplied by the panel scale), with the stash open: the stash side is x −39 from the original game (personal tab 62.5, shared 106.5, personal page column 0 at 60), # the inventory panel side is +38.5 (inventory column 0 at 424.5), close button 654.5, withdraw gold button 187.5; the four pages gems / materials / runes / cube are back at the original game's positions. The tap positions of these runs (and of the stash-opening steps of the top / v runs) were all measured this way -WIDE=("c","d","t","u","s") +WIDE=("c","d","t","u","s","sa") def run(g): global INV_X0; INV_X0=424.5 if g.run in WIDE else 386.0 # 背包占格的读法跟着物品栏右移 | the inventory occupancy reading follows the inventory panel's shift to the right script="\n".join(g.L)+f"\n{g.t+1.0:.2f} note 结束\n"; cap=int(g.t)+6; tag=f"{os.environ.get('UIREG_TAG') or 'ur'}_{MODE}_{g.run}" # 起局脚本见到「note 结束」就收,cap 只是上限 | the run launcher script stops as soon as it sees 「note 结束」(note end); cap is only an upper limit @@ -586,6 +586,19 @@ def groups(): g.item("从成叠格拖到背包","取 1 件",r"取多件:.*取 1:"); g.dragp((201,81),(488.5,297)); g.shot() g.item("从成叠格拖到面板下方松手","不取",r"拖放落点|界面命中",r"取多件"); g.dragp((201,81),(333,372)); g.shot() gs.append(g) + # sa 局:往个人页 / 共享页里存符文自动进高级仓库(珍宝匣存入,dm_pouch.c)。同 d 局的存档与开头:珍宝匣页符文那一叠 12 个,每次双击取 1 个到背包(落在背包右上角那格), + # 再把它拖进个人页 / 共享页的格子,或开着箱子双击它。判据读宿主日志:个人页 = 落下后服务端代发原版「移到仓库」;共享页 = 收包处改道(放回背包原格再发);双击 = 原版「移动到堆叠栏」 + # Run sa: runes stored into the personal page / shared page go into the advanced stash automatically (trove deposit, dm_pouch.c). Same save and opening as run d: the stack of 12 runes on the trove page, each double-tap takes 1 into the backpack (it lands in the top-right backpack cell), + # then drag it into a cell of the personal page / shared page, or double-tap it with the stash open. The criteria read the host log: personal page = after the drop the server sends the original "move to stash" on its behalf; shared page = rerouted at packet receive (put back into its backpack cell and sent again); double-tap = the original "move to stacking tab" + g=G("sa","DM_TEST_WORLD_GO=near2:2:c267@200 DM_C2S_LOG=pwc2s.jsonl",save=os.environ.get("UIREG_STACK_SAVE") or "save.pw_rune_stack"); g.sect("stashauto",0); g.t=3.5; g.tap(P(333,336),1.6); g.at("await pos"); g.t=max(g.t,13.0); g.at("note 进局",1.5) + g.item("点箱子","开储藏箱",r"OpenPanel BankExpansionLayout"); g.arrive(5808,4443,3,24.0); g.at("tap_unit 2 267 3",3.0); g.shot() + g.item("珍宝匣页双击符文那一叠","取 1 件到背包",r"取多件:.*取 1:"); g.tap(P(148,53)); g.dbl(201,81); g.shot() + g.item("切到个人页,把背包里那颗符文拖进个人页格子","落下后自动转进珍宝匣,个人页不留",r"珍宝匣:仓库页里新落下的物品[\s\S]*珍宝匣:物品 id \d+ 已从仓库页转进高级仓库",r"2 秒还在仓库页"); g.tap(P(62,53)); g.dragp((600.5,227),(81,237)); g.wait(2.5); g.shot() + g.item("珍宝匣页再取 1 件","到背包(那一叠还是 12 个:上一步拖进个人页的那颗回来了)",r"叠数 12 取 1:"); g.tap(P(148,53)); g.dbl(201,81); g.shot() + g.item("切到共享页,把它拖进共享页格子","收包处改道:放回背包原格、下一拍进珍宝匣;共享页不留",r"珍宝匣:r01[^\n]*拖进共享页 → 改成放回背包格[\s\S]*珍宝匣:物品 id \d+ 已回到背包 → 原版移到仓库",r"留在背包"); g.tap(P(106,53)); g.dragp((600.5,227),(81,237)); g.wait(2.5); g.shot() + g.item("珍宝匣页再取 1 件","到背包(那一叠还是 12 个:上一步拖进共享页的那颗也回来了)",r"叠数 12 取 1:"); g.tap(P(148,53)); g.dbl(201,81); g.shot() + g.item("开着箱子双击背包里的那颗符文","原版「移动到堆叠栏」:背包少 1 格(回到珍宝匣那一叠)",("inv",-1)); g.dbl(600.5,246.5); g.wait(2.0); g.shot() + gs.append(g) # t 局:背包里带着魔盒时从符文页那一叠取件——双击 / 长按 / 拖三种手法。判据读截图的背包占格(魔盒本身占 4 格,取出的符文要多占格;占格增量 = 叠数减量,就没有东西进了魔盒),叠数认取件时读到的游戏值 # t run: with the cube in the inventory, take items from that stack on the rune page - three gestures: double-tap / long-press / drag. The criterion reads the inventory cell occupancy from the screenshot (the cube itself takes 4 cells, and runes taken out must take additional cells; cell increase = stack count decrease means nothing went into the cube), and the stack count trusts the game value read at take time SV=os.environ.get("UIREG_STACK_SAVE") or "save.pw_rune_stack" diff --git a/dm/tools/d2rm_pack.py b/dm/tools/d2rm_pack.py index 38315d0..3a9dc30 100755 --- a/dm/tools/d2rm_pack.py +++ b/dm/tools/d2rm_pack.py @@ -205,7 +205,7 @@ def main(): # 六、照壳的清单核对一项不缺,再放进去 # 6. Check against the shell's manifest that nothing is missing, then put it in miss = [m for m in manifest if not (os.path.isdir(os.path.join(stage, m)) if m.endswith('/') else os.path.isfile(os.path.join(stage, m)))] - if miss: die('有 %d 项没做出来:%s' % (len(miss), '、'.join(miss))) + if miss: die('有 %d 项没做出来:%s。壳的清单里要、而这份工具没有生成——壳与工具不是同一版。请用与这份仓库同一版本的壳(发布页最新的 D2RMobile-shell.ipa),或把仓库更新到与壳对应的版本' % (len(miss), '、'.join(miss))) tmp = out_ipa + '.part'; added = 0 with zipfile.ZipFile(tmp, 'w', zipfile.ZIP_DEFLATED, compresslevel=6) as o: for i in z.infolist(): o.writestr(i, z.read(i.filename)) diff --git a/dm/tools/patch_nso.py b/dm/tools/patch_nso.py index 7326a1a..ef8fb80 100644 --- a/dm/tools/patch_nso.py +++ b/dm/tools/patch_nso.py @@ -869,6 +869,8 @@ if NAME == 'main': BL = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'data', f'bootlist_{BUILD_ID}.tsv') if not os.path.isfile(BL): # 公开仓库不带这份清单(它每行带原版资源块的开头字节):没有就不预取,启动时少一步提前解码,别的不受影响 | the public repository does not ship this list (each line carries the first bytes of an original resource block): without it there is no prefetch, so launch skips one ahead-of-time decode step and nothing else is affected print('bootlist 没有启动块清单,跳过(不预取)。要用的话自己录一份:dm/tools/tact_bootlist.py') + for n in ('bootlist.tsv', 'bootlist.sha256'): # 产物目录里以前留下的也去掉:留着会被当成这一次的产物带进安装包和壳的清单 | Leftovers from earlier runs in the build output directory are removed too: if kept they would be taken as outputs of this run and carried into the install package and the shell manifest + if os.path.exists(os.path.join(outdir, n)): os.remove(os.path.join(outdir, n)) else: hd = open(BL, encoding='utf-8').readline().split() if hd[-1:] != [BUILD_ID]: sys.exit(f'【红】{BL} 头行构建号 {hd[-1:]} 与 main {BUILD_ID} 不符') diff --git a/docs/DEPENDENCIES.md b/docs/DEPENDENCIES.md index 94f77ee..90b3a2a 100644 --- a/docs/DEPENDENCIES.md +++ b/docs/DEPENDENCIES.md @@ -40,6 +40,7 @@ All at once: `python3 -m pip install pillow numpy lz4 capstone unicorn` (`./setu | Tool | Used for | Official site | |---|---|---| | astcenc | Converting textures for older devices without BC texture support | | +| hactool | Needed by `dm/tools/extract_game.sh` to extract files from your game package; not needed if your game files are already prepared some other way. We tested with upstream commit `1d64a83` | | ## Extra tools for on-device and verification scripts diff --git a/docs/DEPENDENCIES.zh-CN.md b/docs/DEPENDENCIES.zh-CN.md index 3143f01..4928585 100644 --- a/docs/DEPENDENCIES.zh-CN.md +++ b/docs/DEPENDENCIES.zh-CN.md @@ -40,6 +40,7 @@ English: [DEPENDENCIES.md](DEPENDENCIES.md) | 工具 | 用来做什么 | 官方地址 | |---|---|---| | astcenc | 给不支持 BC 贴图格式的旧机型转换贴图 | | +| hactool | 用 `dm/tools/extract_game.sh` 从你的游戏包取文件时要用;游戏文件已经用别的办法备好时不用装。我们实测用的是上游提交 `1d64a83` | | ## 真机与验证脚本额外需要 diff --git a/docs/DERIVED.md b/docs/DERIVED.md index 3e67235..15f5ebb 100644 --- a/docs/DERIVED.md +++ b/docs/DERIVED.md @@ -14,7 +14,7 @@ The front page says the project "contains none and distributes none" of the game All of these are generated on your own machine from your own game files. Every time the public repository is exported, a tool takes the real game files and searches the whole tree for them byte by byte; a hit blocks the export. -A few things derived from the game files are used internally but are not shipped here: the startup prefetch list (each line carries the first bytes of an original resource block — without it, launch skips one ahead-of-time decode step), the seed save for the shared stash (without it, the game creates an empty one itself as the original does), and two fixtures for the interface-binding tests (captured from the memory of the running game — without them, the three tests that read them are skipped automatically). +A few things derived from the game files are used internally but are not shipped here: the startup prefetch list (each line carries the first bytes of an original resource block — without it, launch skips one ahead-of-time decode step: measured with the iOS package running on a Mac, the character select screen is reached in 3.3–4.0 s versus 2.8 s with the list, two runs each; not measured on a phone), the seed save for the shared stash (without it, the game creates an empty one itself as the original does), and two fixtures for the interface-binding tests (captured from the memory of the running game — without them, the three tests that read them are skipped automatically). ## In the repository diff --git a/docs/DERIVED.zh-CN.md b/docs/DERIVED.zh-CN.md index 5ffa51b..f778329 100644 --- a/docs/DERIVED.zh-CN.md +++ b/docs/DERIVED.zh-CN.md @@ -14,7 +14,7 @@ English: [DERIVED.md](DERIVED.md) 这些都在你自己的机器上、用你自己的游戏文件现做出来。每次导出公开仓库时,有一道工具拿真实的游戏文件到整棵树里逐字节搜一遍,搜到就不放行。 -另有几样由游戏文件派生的东西我们自己在用,但公开仓库不带:启动预取清单(每行带原版资源块的开头字节——不带的后果是启动时少一步提前解码)、共享仓库的预置存档(不带的后果是游戏照原版自己生成一份空的)、界面绑定测试的两份夹具(从运行中的游戏内存抓的——不带的后果是读它们的三个测试自动跳过)。 +另有几样由游戏文件派生的东西我们自己在用,但公开仓库不带:启动预取清单(每行带原版资源块的开头字节——不带的后果是启动时少一步提前解码:Mac 上起 iOS 包实测,到选角页 3.3–4.0 秒,带清单时 2.8 秒,各两局;手机上没量)、共享仓库的预置存档(不带的后果是游戏照原版自己生成一份空的)、界面绑定测试的两份夹具(从运行中的游戏内存抓的——不带的后果是读它们的三个测试自动跳过)。 ## 仓库里带着的