存入同款暗金 / 套装时自动比较,新的更好就替换
背景
编年史(Chronicle)现在只收「同款还没有」的暗金和套装件:store_begin 里 !dm_vault_has(...) 一挡,有同款就跳过。玩家打到同款第二件时得自己把两件都看一遍、比数值,再决定留哪件——极品暗金往往是差在几条随机属性上,来回看很费事。
改动
- 存同款时先比较:把编年史里那件的位流取出来重建(
dm_item_make(..., room = 0, ...),不放进任何物品栏),和新件逐条 stat(1–358)求差值累加。- 差值 > 0(新的更好)→ 走原来的存入流程,原版已有的
withdraw(旧件)会把旧件退回背包。 - 差值 ≤ 0(旧的更好 / 平手)→ 不存,新件留在背包,日志一行说明。
- 差值 > 0(新的更好)→ 走原来的存入流程,原版已有的
- 新增
dm_vault_get_bits()(dm_vault.c):加锁拷出某件的位流(找不到 / 放不下返回 0),给主线程比较用。 - 同款两件的固定词条相同,差值天然为 0,所以实际只比随机属性的高低。
两个文件,+33/−2:
dm/host/dm_pouch.c | 29 +++++++++++++++++++++++++++--
dm/host/dm_vault.c | 6 ++++++测试
一加 Ace 5 Pro(Adreno 830 / Android 16),系统驱动,0 崩溃。
用背包里的同款暗金戒指验证两个方向:
| 场景 | 日志 | 结果 |
|---|---|---|
| 新的两条属性都更高(+5) | 编年史:新的比旧件好(5)→ 替换,旧件回背包 | 新件进编年史,旧件回到背包 ✅ |
| 新的更低(−N) | 编年史:新的不如旧件(−N)→ 不替换 | 编年史不动,新件留在背包 ✅ |
还在测试中
戒指验过;护身符、武器、防具的类型和词条组合多得多,可能还有没覆盖到的情况。欢迎大家帮忙测,判断错了贴两件装备的属性最好。
(如果觉得「比较后替换」应该是可选开关、而不是默认行为,请说一声,我改成 files/dm/env 里的开关。)
Activity
8两条都改了,推在 887b417。
-
比较搬到服务端拍:
store_begin/store_step只发请求、等结果(dm_vault_request_compare/dm_vault_take_compare),建临时物品、逐条读 stat、释放全部在dm_vault.c的vault_compare()里,由dm_vault_tick驱动——和vault_desc同一套请求/结果模式。主线程那条路不再碰dm_item_make/0x658be0。新件的服务端单位用dm_diag_srv_item(id)找,找不到就按「不替换」处理并打一行红字。- 存放流程变成:同款先进待存队列 → 请求比较 → 结果出来再决定存 / 不存(等不到结果有 4 秒超时,超时按不替换)。
-
算法收紧了(
item_score()):- 跳过 70–73:数量、当前耐久、最大耐久(使用状态,不是好坏);
- 生命 / 法力 / 耐力(6–11)按内部 1/256 折算,不再压过其它词条;
- 三层都读(带参数的词条,比如「+N 某技能」,记在 layer 上)。
-
开关缺省关:
DM_VAULT_COMPARE=1写进files/dm/env才启用;开关关着时行为和现在完全一样(同款不存、新件留背包)。
按 UniqueItems / SetItems 的随机范围来比确实更准,这块我还没做——两份表的行结构与 prop/par/min/max 列位要重新摸一遍,打算单独开一轮,不混在这个 PR 里。
构建:本机 Windows 全量重编(删 .cxx)BUILD SUCCESSFUL,只有仓库里原有的 unused 警告。
谢谢,线程问题改对了:建临时物品、比较、释放都在服务端拍里、持 g_vmu 做,和 vault_desc 同一个模式;主线程只发请求、读结果。开关缺省关也好。宿主闸门在这个 head 上通过(Linux 容器里编的):mode_scan.py、t_hid_receipt 5/5、t_hid_script 37/37、t_touch_mac 39/39。还有两点:
- 「三层都读」读的不是带参数的词条。
0x5b9290(物品, stat, layer)的第三个参数是这个 stat 的参数本身,不是 0–2 的层序号。物品的 stat 表里存的是statId<<16 | layer对(diag.c:642就是这么读的)。「+N 某个技能」(stat 107)的 layer 是技能号,所以读 layer 0、1、2 基本都漏掉了;按职业 +技能(stat 83,layer = 职业号 0–6)也只算到前三个职业。要算进带参数的词条,可以像diag.c:642那样遍历物品自己的 stat 表,按(statId, layer)逐对比较。提交说明里「带参数的词条也计入」这句目前不成立。 - 超时之后可能拿到上一件的结果。 A 超时(240 帧)后接着请求 B:
dm_vault_request_compare把g_cmp_ready置 0、g_cmp_newid改成 B。但如果服务端拍此前已经取走了 A 的请求、正在算,算完会把g_cmp_ready置 1,dm_vault_take_compare(B)就会读到 A 的差值。把结果和它对应的物品 id 一起存(例如g_cmp_doneid = nid,取结果时核对它),就不会串。只有服务端拍长时间不跑才会发生,概率低,但改起来便宜。
开关缺省关,这两点都不阻塞;打开之前最好先改第 1 点。
Thanks, the threading fix is right: the temporary item is built, compared and freed on the server tick under g_vmu, in the same pattern as vault_desc, and the main thread only posts the request and reads the result. Off by default is good too. The host gate passes on this head (built on Linux in a container): mode_scan.py, t_hid_receipt 5/5, t_hid_script 37/37, t_touch_mac 39/39. Two more points:
- Reading "three layers" doesn't reach parameterised affixes. The third argument of
0x5b9290(item, stat, layer)is the stat's parameter itself, not a layer index from 0 to 2. An item's stat list holdsstatId<<16 | layerpairs (that's howdiag.c:642reads it). For "+N to one skill" (stat 107) the layer is the skill id, so layers 0, 1 and 2 miss almost all of them. Class skill bonuses (stat 83, layer = class 0–6) only count for the first three classes. To include parameterised affixes, walk the item's own stat list asdiag.c:642does and compare per(statId, layer)pair. As it stands, the commit message's "parameterised affixes are counted" isn't true yet. - After a timeout, the next item can get the previous item's result. Say request A times out after 240 frames and request B follows.
dm_vault_request_comparesetsg_cmp_readyto 0 andg_cmp_newidto B. But if the server tick had already taken A's request and is still working on it, it then setsg_cmp_readyto 1, anddm_vault_take_compare(B)reads A's difference. Storing the result together with the item id it belongs to (e.g.g_cmp_doneid = nid, checked when taking the result) prevents the mix-up. It only happens if the server tick stalls for a long time, so it's unlikely, but cheap to fix.
With the switch off by default, neither point blocks the merge; point 1 is worth fixing before anyone turns it on.
两点都改了,在 7b7f459:
-
带参数的词条 ——
item_score不再按 0/1/2 去取0x5b9290,改成遍历物品自己的 stat 表(+0x88→+0x30缓冲、+0x38计数),每项是(statId<<16 | layer, 值)对,按对累加。+N 某技能(stat 107,layer = 技能号)和按职业 +技能(stat 83,layer = 职业号 0–6)现在都算进去了,提交说明里「带参数的词条也计入」这句从7b7f459起成立。数量 / 当前与最大耐久(70–73)照旧跳过,生命 / 法力 / 耐力照旧按 /256 归一。 -
超时后串结果 —— 加了
g_cmp_doneid:服务端拍算完把结果和它对应的新物品 id 一起存,dm_vault_take_compare核对doneid == new_item_id才取走。A 超时后接着请求 B 时,A 的结果回来也会被丢掉(B 等不到就按超时走「不替换」),不会读到 B 身上。
Windows 上编过(gradle :app:assembleDebug,-PdmAppId=com.xiaoboluo.d2r.own),BUILD SUCCESSFUL。宿主闸门那几个测试我这边没有 Linux 环境复跑,麻烦你那边再跑一遍。
开关仍然缺省关。
Both points are fixed in 7b7f459:
-
Parameterised affixes —
item_scoreno longer reads0x5b9290per layer 0/1/2. It walks the item's own stat list (+0x88→+0x30buffer,+0x38count), where each entry is a(statId<<16 | layer, value)pair, and sums per pair.+N to a skill(stat 107, layer = skill id) and class skill bonuses (stat 83, layer = class 0-6) are now counted, so the commit message's "parameterised affixes are counted" is true from this commit on. Quantity / current and max durability (70-73) are still skipped, and life / mana / stamina are still divided by 256. -
Mixing up results after a timeout — added
g_cmp_doneid: the server tick stores the result together with the new item id it belongs to, anddm_vault_take_compareonly takes it whendoneid == new_item_id. If A times out and B is requested, A's late result is discarded (B waits, times out and falls back to "not replaced") instead of being read as B's.
Built on Windows (gradle :app:assembleDebug, -PdmAppId=com.xiaoboluo.d2r.own), BUILD SUCCESSFUL. I don't have a Linux environment here to re-run the host gate tests — could you run those again on your side?
The switch is still off by default.
谢谢,7b7f459 两点都对了:
item_score现在按物品自己的 stat 表逐对读(+0x88→+0x30/+0x38,statId<<16 | layer),和diag.c的stat_read、dm_rift.c的读法一致,带参数的词条(107 / 83 等)都算进去了。这些读都在服务端拍里、对本拍自己拿到的物品做,直接读没问题。- 结果带上了
g_cmp_doneid,超时后换件不会串。
宿主闸门我在 Linux 容器里替你跑了这个 head:mode_scan.py 通过,t_hid_receipt 5/5,t_hid_script 37/37,t_touch_mac 39/39,dm_vault.c / dm_pouch.c 语法检查(-Wall)没有报错也没有警告。我这边没有其他意见了;没在手机上跑过。
Thanks, both points are right in 7b7f459:
item_scorenow walks the item's own stat list pair by pair (+0x88→+0x30/+0x38,statId<<16 | layer), the same reading asdiag.c'sstat_readanddm_rift.c, so parameterised affixes (107, 83 and so on) count. These reads happen on the server tick, on items that tick itself obtained, so reading directly is fine.- The result now carries
g_cmp_doneid, so a timeout followed by another item can't mix them up.
I ran the host gate on this head for you, in a Linux container: mode_scan.py passes, t_hid_receipt 5/5, t_hid_script 37/37, t_touch_mac 39/39. A syntax check of dm_vault.c / dm_pouch.c with -Wall gives no errors or warnings. No further comments from me. I haven't run it on a phone.
想法很好,但有一处线程问题需要先改:
在客户端线程上建 / 删服务端物品。
store_begin由dm_pouch_step调,跑在游戏主(客户端)线程上。vault_better却用服务端拍里记下的G调dm_item_make(b, G, ...)和0x658be0(G, ...),也就是在主线程上动服务端的物品分配和单位表,而服务端线程同时在跑。dm_vault.c特意把所有建物品的操作放在服务端拍里(存取、vault_desc的临时物品都是),就是为了避开这个竞争,偶发崩溃或数据损坏都可能。建议把比较挪进服务端拍:像vault_desc那样发一个请求,服务端拍里建临时物品、比较、释放,再把结果交回主线程。「更好」的算法还很粗:
比较只看这件暗金 / 套装在 UniqueItems / SetItems 里有随机范围的那几条,会准得多。在那之前,你提的「做成开关、缺省关」更稳妥。
Nice idea, but there's a threading problem to fix first:
Server items are created and freed on the client thread.
store_beginis called fromdm_pouch_stepon the game's main (client) thread.vault_betteruses theGcaptured on the server tick to calldm_item_make(b, G, ...)and0x658be0(G, ...), so it touches the server's item allocator and unit lists from the main thread while the server thread runs.dm_vault.cdeliberately does all item creation on the server tick (store, withdraw, and the temporary item invault_desc) to avoid exactly this race, which can crash or corrupt state now and then. Moving the comparison onto the server tick would fix it: post a request asvault_descdoes, create, compare and free the temporary item there, and hand the result back to the main thread.The "better" score is still rough:
Comparing only the properties that have a range for that unique / set item in UniqueItems / SetItems would be much more reliable. Until then, your own suggestion of an opt-in switch, off by default, seems the safer default.