#297

Android: mark unopened chests / baskets / hidden stashes on the minimap

OpenDiablo-chia619wants to merge intofrom

给刷箱子的人

刷图最烦的不是怪,是漏箱子。

一个角落里的篮子、一棵树后面的隐藏储物点、贴着墙的箱子 —— 小地图上什么都没有,你只能凭记忆回头找,或者在每张图上顺着墙溜一遍。漏掉的那个可能正好是 30 号符文,也可能是一件暗金。

这个 PR 把还没开的箱子、篮子、隐藏储物点直接点到小地图上:一个金色小方块,开了就消失。开过的不会亮,火把、雾、灯这些装饰也不会亮(不然满屏都是点,等于没有)。

覆盖 76 类容器:各种箱子(普通 / 上锁 / 隐藏 / 大箱子)、篮子、瓮、桶、木箱、石棺、储物点…… 门和尸体不算。

怎么用

原版地图,不用改任何设置。角上的小地图和全屏地图都会标。

For reviewers

  • Host side — dm_chest_marks() walks the client unit table bucket 2 (main+0x2d603a0 + 2*0x400), keeping object units (+0 == 2) whose mode (+0xc) is 0 and whose class (+4) is in is_container_cls(). That list is 76 entries built from objects.txt (chest / stash / casket / urn / barrel / jug / basket / crate), minus doors and corpses.
  • Projection — reuses dm_ui_map_geom() for the per-cell pixel size and dm_ui_minimap_rect() / dm_cam_map_heading() for the centre; mx = (dx-dy)*1.6*cell, my = (dx+dy)*0.8*cell. Same overlay path as the existing map marks, no new renderer.
  • Why the unit table and not the room records — the randomised containers are not in the static room record chain (level+0x10 → room+0x98); a scan of 84 room records in Flayer Jungle found zero containers while the unit table had the Baskets, chest and hidden stash right next to the player.
  • Three things worth reviewing — (1) objects within 2 tiles of the player are skipped: a picked-up container's unit is recycled but still reads as "mode 0", which otherwise leaves a marker that follows you around; (2) two seconds of silence after a level change, since the unit table still holds the old level during the load animation; (3) CamThreats now invalidates every frame — the old condition missed the 1 → 0 transition and left the previous frame's square on screen.

Verified on OnePlus Ace 5 Pro (Adreno 830), Android 14: markers appear on unopened Baskets / chests, vanish on open, no ghost markers, nothing left behind after a level change.

Activity

8
yyan1607d ago

想法很实用,投影和朝向箭头同一套几何,容器类表也整理得很全。有一处需要先改,另外三处小的:

  1. (需要改)在界面线程上遍历游戏的单位表。 dm_chest_marks 由 CamThreats.doFrame(Choreographer,安卓界面线程)经 JNI 每帧调用,它直接走客户端单位哈希表 main+0x2d603a0,沿 +0x158 链表、再读 +0x38 路径。游戏线程同时在加、删单位(走动、换区、开箱)。读到刚释放的单位会读野指针(崩溃),链表正被改写时还可能绕圈(界面线程卡死 → ANR)。现有的小地图数据都不这么做:

    • dm_cam_threats 的怪物方位是游戏线程算好、持 g_mu 发布,界面只拷一份;
    • dm_map_goals 用序号锁发布 g_mg_pub(w_map_goal_step 在游戏线程)。

    建议照这个模式:在 dm_world.c 每帧的游戏线程步骤里收集「没开的容器格坐标」(连同所在关卡),发布成一个小数组;dm_chest_marks 只读这份数组,再按当前小地图几何投影。遍历时每个桶也最好加个次数上限。

  2. map_mark 开关没生效。 说明里写「复用 map_mark 叠加」,但代码没有查 dm_custom_get("map_mark")。自定义页里关了小地图标注的玩家照样会看到金点。建议按它(或加一个自己的开关)门控。

  3. 有三行中文注释是乱码(UTF-8 被当成 Latin-1 再编了一次):dm_world.c 第 732、734 行,CamThreats.java 第 119 行。请按 UTF-8 重存这几行。

  4. 小处:注释「贴玩家 8 格内不画」,代码是 ddx²+ddy² < 4,即 2 格以内;函数后面多了 7 个空行。

dm_world.c 是共享代码,iOS / 鸿蒙也会编到这个函数(不会调用)。


A useful idea. The projection uses the same geometry as the heading arrow, and the container class list is thorough. One thing needs fixing first, plus three small ones:

  1. (needs a change) The game's unit table is walked on the UI thread. dm_chest_marks is called every frame from CamThreats.doFrame (Choreographer, the Android UI thread) via JNI. It walks the client unit hash main+0x2d603a0 directly, follows the +0x158 list and reads the +0x38 path, while the game thread adds and frees units (walking, changing areas, opening chests). A unit freed in between means reading a dangling pointer (crash), and a list being relinked can loop (UI thread stuck → ANR). The existing minimap data never does this:

    • dm_cam_threats gets monster positions computed on the game thread and published under g_mu; the UI only copies them;
    • dm_map_goals publishes g_mg_pub with a sequence lock, and w_map_goal_step runs on the game thread.

    Following that pattern: collect the unopened containers' cells (and their level) in dm_world.c's per-frame game-thread step, publish them as a small array, and have dm_chest_marks only read that array and project it with the current minimap geometry. A per-bucket iteration cap would also help.

  2. The map_mark switch isn't honoured. The description says it reuses map_mark, but the code never checks dm_custom_get("map_mark"), so players who turned minimap markers off on the Custom page still see the dots. Gate it on that switch, or add one of its own.

  3. Three Chinese comment lines are garbled (UTF-8 read as Latin-1 and encoded again): dm_world.c lines 732 and 734, and CamThreats.java line 119. Please re-save them as UTF-8.

  4. Small: the comment says "not drawn within 8 cells of the player", but the code is ddx²+ddy² < 4, i.e. within 2 cells. There are also 7 blank lines after the function.

dm_world.c is shared, so iOS and HarmonyOS compile this function too (they never call it).

Diablo-chia6197d ago

四点都改了,在 0e6907a(chest-marks 分支):

  1. 界面线程遍历单位表 —— 按 dm_map_goals 的模式改了:收集挪到游戏线程的 w_chest_step()(在 dm_world_step 里跟 w_map_goal_step 并排),用序号锁(g_chest_seq / g_chest_pub,跟 g_mg_seq 同一套写法)发布「相对玩家的格差」数组(上限 64 个);dm_chest_marks 现在只读这份数组再按小地图几何投影,完全不碰游戏内存。遍历另外加了 512 个节点的上限。
  2. map_mark 开关 —— 现在查 dm_custom_get("map_mark"),跟小地图标注同一个开关(另留 DM_CHEST_MARK 环境变量给调试用)。自定义页里关了标注的玩家不会看到金点。
  3. 乱码注释 —— dm_world.c 那两行是我整段重写时带进来的(UTF-8 被当 Latin-1 又编了一次),已按 UTF-8 重存;CamThreats.java 第 119 行同样修了。现在整个改动里没有乱码。
  4. 注释与代码不符 / 多余空行 —— 注释改成「贴玩家 2 格内不标」,函数后面多出来的空行删掉了。

真机验证过(一加 Ace 5 Pro / Android 14):未开的篮子、箱子照样标,开掉立刻消失,过图后不残留,没有再出现贴着人走的方块。


All four are fixed in 0e6907a (chest-marks):

  1. Walking the unit table on the UI thread — changed to the dm_map_goals pattern: collection moved to a game-thread step, w_chest_step(), sitting next to w_map_goal_step() in dm_world_step. It publishes an array of offsets from the player (capped at 64) through a seqlock (g_chest_seq / g_chest_pub, same shape as g_mg_seq), and dm_chest_marks now only reads that array and projects it — no game memory is touched on the UI thread. The walk also has a 512-node cap now.
  2. The map_mark switch — it now checks dm_custom_get("map_mark"), the same switch as the minimap marks (with DM_CHEST_MARK left as a debugging override). Players who turned minimap marking off won't see the dots.
  3. Garbled comments — those two lines in dm_world.c came in when I rewrote the block (UTF-8 read as Latin-1 and re-encoded); re-saved as UTF-8. Same for CamThreats.java line 119. There is no garbled text left in the change.
  4. Comment vs. code / stray blank lines — the comment now says "not drawn within 2 cells of the player", and the blank lines after the function are gone.

Verified on OnePlus Ace 5 Pro / Android 14: unopened baskets and chests still get marked, vanish the moment they are opened, nothing is left behind after a level change, and no marker follows the player any more.

yyan1607d ago

谢谢,0e6907a 四点都对了:

  • 收集在游戏线程(w_chest_step,dm_world_step 里),按 g_mg_seq 的写法用序号锁发布格差。dm_chest_marks 只拷这份数组再投影,界面线程不再碰游戏内存。遍历有 512 节点上限。
  • 由 map_mark 门控,DM_CHEST_MARK 留作调试覆盖。
  • 改动里没有乱码了(新增行里没有 Latin-1 范围的字符)。
  • 注释与代码一致,多余的空行也没了。

宿主闸门在这个 head 上通过(Linux 容器):mode_scan.py、t_hid_receipt 5/5、t_hid_script 37/37、t_touch_mac 39/39;dm_world.c 语法检查(-Wall)没有报错也没有警告。我这边没有其他意见了;没在手机上跑过(你在一加 Ace 5 Pro 上验证过)。


Thanks, all four are right in 0e6907a:

  • Collection runs on the game thread (w_chest_step, in dm_world_step) and publishes the offsets through a seqlock the same way as g_mg_seq. dm_chest_marks only copies that array and projects it, so the UI thread no longer touches game memory. The walk has a 512-node cap.
  • It's gated on map_mark, with DM_CHEST_MARK as a debugging override.
  • No garbled text is left in the change (no Latin-1-range characters in the added lines).
  • The comments match the code, and the stray blank lines are gone.

The host gate passes on this head (Linux container): mode_scan.py, t_hid_receipt 5/5, t_hid_script 37/37, t_touch_mac 39/39. A -Wall syntax check of dm_world.c gives no errors or warnings. No further comments from me. I haven't run it on a phone myself (you verified it on a OnePlus Ace 5 Pro).