Merge upstream v1.0.15 into android-port

Conflicts resolved: hle_audio.c keeps the AAudio downmix on Android and takes
upstream's 5.1 downmix on Apple; hle_nvn.c keeps mtl_queue_flush / ADPF pacing
on Android. Android translates synchronously on the submit thread for now (the
Vulkan backend's fence also counts readback commits); Vulkan gets no-op
mtl_host_latch / mtl_host_apply; compat adds pthread_attr_set_qos_class_np.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-15 10:07:20 +09:00
co-authored by Claude Opus 5.5
57 changed files with 2003 additions and 396 deletions
+3 -3
View File
@@ -104,11 +104,11 @@ $(B)/t_touch: t_touch.c ../hle_touch.c ../front.h ../dm.h | $(B)
$(B)/t_fs: t_fs.c t_fs_stub.c ../hle_fs.c ../hle.h ../dm.h ../dm_i18n.c | $(B)
clang -O1 -Wno-unused-function -I.. -o $@ t_fs.c t_fs_stub.c ../dm_i18n.c
$(B)/t_audio: t_audio.c ../hle_audio.c ../hle.h ../dm.h | $(B)
clang -O1 -Wno-unused-function -I.. -o $@ t_audio.c -framework AudioToolbox
clang -O1 -Wno-unused-function -I.. -o $@ t_audio.c -framework AudioToolbox -framework CoreAudio -framework CoreFoundation
$(B)/t_audio_spsc: t_audio_spsc.c ../hle_audio.c ../hle.h ../dm.h | $(B)
clang -O1 -Wno-unused-function -I.. -o $@ t_audio_spsc.c -framework AudioToolbox
clang -O1 -Wno-unused-function -I.. -o $@ t_audio_spsc.c -framework AudioToolbox -framework CoreAudio -framework CoreFoundation
$(B)/t_audio_spsc_tsan: t_audio_spsc.c ../hle_audio.c ../hle.h ../dm.h | $(B)
clang -O1 -g -O1 -fsanitize=thread -Wno-unused-function -I.. -o $@ t_audio_spsc.c -framework AudioToolbox
clang -O1 -g -O1 -fsanitize=thread -Wno-unused-function -I.. -o $@ t_audio_spsc.c -framework AudioToolbox -framework CoreAudio -framework CoreFoundation
$(B)/t_swkbd: t_swkbd.c ../hle_swkbd.c ../hle.h ../dm.h | $(B)
clang -O1 -Wno-unused-function -I.. -o $@ t_swkbd.c ../hle_swkbd.c
$(B)/t_movie: t_movie.c ../hle_movie.c ../hle.h ../dm.h | $(B)
+24 -7
View File
@@ -41,18 +41,32 @@ def vis_scan(text, where): # 直接写可见位的行;在带守卫的函数
# Third check (position guard): in dm_cursor.c, writing a widget rectangle (+0x70 x, +0x74 y, +0x78 width, +0x7c height) is allowed only in mv_offset (original-game widgets, allow list + record original value + must write back)
# and in ui_move_ours (only names starting with Touch). Two forms are recognized: a direct *(int32_t *)(... + 0x7?) = ...; or, within the same function, first taking int32_t *name = (int32_t *)(... + 0x7?) and then writing name[k] = / *name =
RECT_OK = ('mv_offset', 'ui_move_ours')
RECT_PTR = re.compile(r'int32_t\s*\*\s*(\w+)\s*=\s*\(int32_t\s*\*\)\s*\([^;]*\+\s*0x7[0-9a-c]\b')
RECT_DIRECT = re.compile(r'\*\s*\(int32_t\s*\*\)\s*\([^)]*\+\s*0x7[0-9a-c]\)\s*=(?!=)')
def rect_scan(text, where):
RECT_OFFS = ['0x7%x' % i for i in range(13)] # 0x70–0x7c
# 原版控件字段写入的登记例外(一项一行:文件、字段、只许在哪些函数里写、理由)。名单外的函数写这些字段一律报红
# Registered exceptions for writes to original widget fields (one per line: file, field, which functions may write it, reason). Writes to these fields from functions not on the list are always red
NATIVE_FIELD_OK = {
('dm_cursor.c', '0x19c'): (('ui_note_dock_pump', 'note_dock_restore'), 'NotificationPanel 停靠目标 y:原版只在重排时按布局抄进、滑入滑出按它插值写 +0x74;'
'改 +0x74 会被动画每帧盖回(试过)。原值我们自己记、停靠条件一结束当场写回(面板关 / 读取画面 / 保存并退出 / 回到前端)'),
('dm_cursor.c', '0x74'): (('note_dock_snap',), 'NotificationPanel 矩形 y:停靠目标切换(开 / 关面板)那一刻框已停稳(原版停稳不写坐标)才写成新目标一次,动画期不写;写后下一帧核'),
}
def field_write_scan(text, where, off, ok, what):
ptr = re.compile(r'(?:int32_t|,)\s*\*\s*(\w+)\s*=\s*\(int32_t\s*\*\)\s*\([^;)]*\+\s*%s' % off) # 基址只看本括号:同一行别的变量读别的字段不算;逗号后的第二个声明也认 | the base only counts within its own parentheses: other variables on the same line reading other fields do not count; a second declaration after a comma is recognised too
direct = re.compile(r'\*\s*\(int32_t\s*\*\)\s*\([^)]*\+\s*%s\)\s*=(?!=)' % off)
bad, fn, ptrs = [], None, set()
for no, line in enumerate(text.split('\n'), 1):
m = re.match(r'(?:static\s+)?\w+\s+\*?(\w+)\(', line)
if m and not line.startswith(' '): fn, ptrs = m.group(1), set()
code = line.split('//', 1)[0]
for pm in RECT_PTR.finditer(code): ptrs.add(pm.group(1))
code = RECT_PTR.sub('', code) # 声明那一处(int32_t *名 = …)本身不算写 | the declaration itself (int32_t *name = ...) does not count as a write
hit = RECT_DIRECT.search(code) or any(re.search(r'(?<![\w.>])(?:\*\s*%s|%s\s*\[\s*\d\s*\])\s*=(?!=)' % (q, q), code) for q in ptrs)
if hit and fn not in RECT_OK: bad.append('%s:%d 在 %s 里直接写了控件矩形(原版控件走 mv_offset、我们的走 ui_move_ours):%s' % (where, no, fn, line.strip()[:120]))
for pm in ptr.finditer(code): ptrs.add(pm.group(1))
code = ptr.sub('', code) # 声明那一处(int32_t *名 = …)本身不算写 | the declaration itself (int32_t *name = ...) does not count as a write
hit = direct.search(code) or any(re.search(r'(?<![\w.>])(?:\*\s*%s|%s\s*\[\s*\d\s*\])\s*=(?!=)' % (q, q), code) for q in ptrs)
if hit and fn not in ok: bad.append('%s:%d 在 %s 里直接写了%s:%s' % (where, no, fn, what, line.strip()[:120]))
return bad
def rect_scan(text, where):
exc = [off for (f, off) in NATIVE_FIELD_OK if where.startswith(f) and off in RECT_OFFS] # 矩形字段的登记例外:从矩形扫描里拿出来,按例外单独扫 | registered exceptions for rectangle fields: taken out of the rectangle scan and scanned separately as exceptions
bad = field_write_scan(text, where, '(?:%s)\\b' % '|'.join(o for o in RECT_OFFS if o not in exc), RECT_OK, '控件矩形(原版控件走 mv_offset、我们的走 ui_move_ours)')
for (f, off), (fns, why) in NATIVE_FIELD_OK.items():
if where.startswith(f): bad += field_write_scan(text, where, re.escape(off) + r'\b', fns + (RECT_OK if off in RECT_OFFS else ()), '原版控件字段 +%s(登记例外只许在 %s 里写)' % (off, ' / '.join(fns)))
return bad
def pages_pump(src):
@@ -66,6 +80,9 @@ def main():
if not scan(' vu_show(vu_find(bk, "grid", 2), 0);', 'selftest') or scan(' vu_show(vu_find(vt, "TouchV_Back", 0), 1); // "grid" 只在注释里', 'selftest') \
or not vis_scan('static void f(uint64_t w) {\n *(uint8_t *)(w + 0x50) = 0;\n}', 'selftest') or vis_scan('static void ui_show_ours(uint64_t w, int on) {\n *(uint8_t *)(w + 0x50) = 1;\n}\n if (*(uint8_t *)(w + 0x50) == 1) x();', 'selftest') \
or not rect_scan('static void f(uint64_t w) {\n int32_t *r = (int32_t *)(w + 0x70); r[0] = 5;\n}', 'selftest') or not rect_scan('static void g(uint64_t w) {\n *(int32_t *)(w + 0x74) = 3;\n}', 'selftest') \
or rect_scan('static void ui_note_dock_pump(uint64_t w) {\n int32_t *t = (int32_t *)(w + 0x19c), h = *(int32_t *)(w + 0x7c); *t = h;\n}', 'dm_cursor.c') \
or not rect_scan('static void n(uint64_t w) {\n int32_t *t = (int32_t *)(w + 0x19c); *t = 1;\n}', 'dm_cursor.c') \
or not rect_scan('static void n2(uint64_t w) {\n int32_t *t = (int32_t *)(w + 0x19c), *ry = (int32_t *)(w + 0x74); *ry = 1;\n}', 'dm_cursor.c') \
or rect_scan('static void k(uint64_t w) {\n int32_t *rx = (int32_t *)(w + 0x70), ww = *(int32_t *)(w + 0x78); if (*rx) x();\n}\nstatic void mv_offset(uint64_t w) {\n int32_t *v = (int32_t *)(w + 0x70); *v = 1;\n}\nstatic int h(float *r) {\n r[0] = 1.0f; int x = *(int32_t *)(w + 0x70); return x;\n}', 'selftest'):
print('✗ native_write_scan 自检失败:该报的没报或不该报的报了'); return 1
print('✓ native_write_scan 自检:违规行会报红、注释里的名字不算')
+12
View File
@@ -13,6 +13,18 @@ static _Atomic int g_sig;
void hle_signal_system_event(void *g) { (void)g; atomic_fetch_add_explicit(&g_sig, 1, memory_order_seq_cst); }
void hle_bind_system_event(void *g, int autoclear) { (void)g; (void)autoclear; } // 真实现要客体线程 + SDK 内核事件;单测只数触发次数 | the real implementation needs a guest thread + SDK kernel event; the unit test only counts triggers
int main(void) {
{ // 5.1 下混(期望按 Q15 系数手算:0.707·0.707 = 16384/32768 = 0.5,0.707 = 23170/32768):顺序 左前 右前 中置 低音 左后 右后 | 5.1 downmix (expected values worked out by hand from the Q15 coefficients: 0.707*0.707 = 16384/32768 = 0.5, 0.707 = 23170/32768): order front left, front right, centre, LFE, rear left, rear right
static const struct { int16_t in[6]; int16_t l, r; const char *what; } c[] = {
{ { 0, 0, 10000, 0, 0, 0 }, 5000, 5000, "只有中置(对白)→ 左右各 5000" },
{ { 0, 0, 0, 0, 10000, 0 }, 5000, 0, "只有左后 → 左 5000、右 0" },
{ { 10000, 0, 0, 0, 0, 0 }, 7070, 0, "只有左前 → 左 7070(−3 dB)" },
{ { 0, 0, 0, 30000, 0, 0 }, 0, 0, "只有低音 → 不并入,0" },
{ { 32767, 32767, 32767, 0, 32767, 32767 }, 32767, 32767, "满幅叠加 → 饱和到 32767" },
{ { -32768, -32768, -32768, 0, -32768, -32768 }, -32768, -32768, "负满幅叠加 → 饱和到 −32768" } };
int bad = 0;
for (unsigned i = 0; i < sizeof c / sizeof *c; i++) { int16_t o[2]; downmix51(c[i].in, o, 1); int ok = o[0] == c[i].l && o[1] == c[i].r; bad |= !ok;
printf("下混:%s:期望 (%d,%d) → 真结果 (%d,%d) %s\n", c[i].what, c[i].l, c[i].r, o[0], o[1], ok ? "✓" : "✗"); }
if (bad) return 1; }
char out[64], ev[64]; uint8_t prm[16]; gbuf b[3]; static int16_t pcm[3][4800 * 2];
h_au_InitParam(prm);
if (h_au_Open(out, ev, NULL, prm)) return 1;
+75 -10
View File
@@ -10,6 +10,8 @@
#include <unistd.h>
int dm_cloud_sync(const char *save, const char *cloud, const char *bak, const char *statef, int allow_down, uint64_t now_ms, int (*ready)(const char *unit));
int dm_cloud_conflict_take(void);
int dm_cloud_char_conflict_take(char *out, size_t n);
int dm_cloud_inbox_add(const char *save, const char *statef, const char *pack);
#if __has_include("../stash_seed.h") // 公开仓库不带这份预置(它是游戏生成的一份存档的字节):不在时跳过用到它的 ⑱ ⑲ 两组 | the public repository does not ship this seed (it is the bytes of a save the game generated): when it is absent, the two groups that use it, 18 and 19, are skipped
#include "../stash_seed.h"
#define T_HAVE_STASH_SEED 1
@@ -41,6 +43,10 @@ static void put_d2i(const char *dev, int items, int chron, long sec) {
put_bin(dev, "save/ModernSharedStashSoftCoreV2/ModernSharedStashSoftCoreV2.d2i", b, 68 + l2, sec);
}
static void put_vault(const char *dev, int n, long sec) { uint8_t b[8] = { 'S', 'W', 'V', 'T', 1, 0, (uint8_t)n, 0 }; put_bin(dev, "save/ModernSharedStashSoftCoreV2.swvault", b, 8, sec); }
static int inbox_n(const char *dev) { char d[1024]; path(d, dev, "save/_cloudinbox"); DIR *dp = opendir(d); struct dirent *e; int n = 0; while (dp && (e = readdir(dp))) n += e->d_name[0] != '.'; if (dp) closedir(dp); return n; }
static int inbox_has(const char *dev, const char *f) { // 收件箱里有没有哪个条目带这个文件 | whether any inbox entry carries this file
char d[1024]; path(d, dev, "save/_cloudinbox"); DIR *dp = opendir(d); struct dirent *e; int k = 0; struct stat st;
while (dp && (e = readdir(dp))) { if (e->d_name[0] == '.') continue; char p[1400]; snprintf(p, sizeof p, "%s/%s/%s", d, e->d_name, f); k |= !stat(p, &st); } if (dp) closedir(dp); return k; }
static int d2i_items(const char *dev, const char *rel) { char p[1024]; path(p, dev, rel); FILE *f = fopen(p, "rb"); if (!f) return -1; uint8_t b[70]; size_t n = fread(b, 1, 70, f); fclose(f); return n >= 67 ? b[66] : -1; }
int main(void) {
@@ -139,20 +145,24 @@ int main(void) {
CHECK(S3("H", 0) == 0 && d2i_items("H", D2I) == 0, "⑪ 新设备运行中首次同步:不传不改(不能拿空仓库盖云端)");
CHECK(S3("H", 1) == 1 && d2i_items("H", D2I) == 5 && get("H", "save/ModernSharedStashSoftCoreV2.swvault"), "⑪ 新设备启动首次同步:以云端为准,拿到 5 件与编年史仓库");
CHECK(count_bak("H", "_stash-") == 1, "⑪ 新设备本来那份空仓库进备份");
CHECK(!dm_cloud_conflict_take(), "⑪ 正常首次同步不算冲突");
CHECK(!dm_cloud_conflict_take() && inbox_n("H") == 0, "⑪ 本机那份是新建空档:不进收件箱、不提示");
put_d2i("G", 6, 400, 6000); CHECK(S3("G", 0) == 1, "⑭ G 编年史变长(400)照常上传");
CHECK(S3("H", 1) == 1 && d2i_items("H", D2I) == 6, "⑭ H 启动拿到 G 的新版");
put_d2i("H", 0, 148, 7000); // H 上的共享仓库不知为何变空(编年史 148、0 件),时刻更新 | the shared stash on H somehow became empty (chronicle 148, 0 items), with a newer timestamp
CHECK(S3("H", 0) == 0, "⑬ H 运行中要上传变空的那份:拦下");
CHECK(dm_cloud_conflict_take() == 1, "⑬ 拦下记冲突(进局弹提示)");
CHECK(S3("H", 0) == 0, "⑬ H 运行中要上传变空的那份:分叉,运行中不动");
CHECK(!dm_cloud_conflict_take(), "⑬ 运行中不提示(不再永久拦)");
CHECK(S3("G", 1) == 0 && d2i_items("G", D2I) == 6, "⑬ 云端没被盖:G 仍是 6 件");
CHECK(S3("H", 1) == 1 && d2i_items("H", D2I) == 6, "⑬ H 启动:云端为现行版,拿回 6 件");
CHECK(inbox_n("H") == 1 && dm_cloud_conflict_take() == 1, "⑬ 本机那份共享仓库空了、但编年史仓库侧文件还有 3 件:进收件箱、提示一次");
put_d2i("H", 7, 500, 7500); CHECK(S3("H", 0) == 1, "⑮ H 正常玩:编年史 500 上传");
put_d2i("G", 6, 450, 7600); // G 没同步到 H 的 500 就自己写了 450(两边都改,G 后写) | G wrote 450 itself without having synced H's 500 (both sides changed, G wrote later)
CHECK(S3("G", 0) == 0, "⑮ G 运行中要拿编年史 450 盖云端的 500:拦下");
CHECK(S3("G", 1) == 0 && d2i_items("G", D2I) == 6, "⑮ G 启动:云端 500 比本机 450 时刻早但编年史长——按后写赢会上传,被拦;本机不动");
CHECK(dm_cloud_conflict_take() == 1, "⑮ 记冲突");
CHECK(S3("G", 0) == 0, "⑮ G 运行中要拿编年史 450 盖云端的 500:分叉,运行中不动");
CHECK(S3("G", 1) == 1 && d2i_items("G", D2I) == 7, "⑮ G 启动:云端(7 件、500)为现行版");
CHECK(inbox_n("G") == 1 && inbox_has("G", "mine.pack") && inbox_has("G", "base.pack"), "⑮ G 本机那份(6 件、450)进收件箱,带上次同步的基准(6 件、400)");
CHECK(dm_cloud_conflict_take() == 1, "⑮ 收进收件箱:进局提示一次");
CHECK(S3("G", 1) == 0 && inbox_n("G") == 1, "⑮ 再启动:一致、无动作、不再收(不是永久状态)");
{ char p3[1024]; path(p3, "H", "save/ModernSharedStashSoftCoreV2.swvault"); unlink(p3); } put_d2i("H", 7, 500, 8000);
CHECK(S3("H", 0) == 0 && dm_cloud_conflict_take() == 1, "⑬ 编年史仓库侧文件没了(云端有 3 件):拦下");
CHECK(S3("H", 0) == 0 && !dm_cloud_conflict_take(), "⑬ 编年史仓库侧文件没了(云端有 3 件):分叉,运行中不动");
put_vault("H", 0, 8100); put_d2i("H", 0, 500, 8100);
CHECK(S3("H", 0) == 1 && !dm_cloud_conflict_take(), "⑯ 正常玩法:共享仓库物品取空、编年史仓库取空(文件还在,0 件),编年史没变短——照常上传");
// ⑰ rf3 那个形状:云端专家仓库 2 件、编年史还是新建的 148;本机这份被换成游戏新建的空档(0 件、148),状态记录还在、云端没变 = 走「只本机改了」的上传
@@ -161,8 +171,8 @@ int main(void) {
#define S4(dev, down) (path(s3, dev, "save"), path(b3, dev, "bak"), path(t3, dev, "state"), dm_cloud_sync(s3, cd, b3, t3, down, 0, NULL))
put_d2i("J", 2, 148, 1000); CHECK(S4("J", 1) == 1, "⑰ 准备:J 上传 2 件、编年史 148 的仓库");
put_d2i("J", 0, 148, 2000); dm_cloud_conflict_take();
CHECK(S4("J", 0) == 0 && dm_cloud_conflict_take() == 1, "⑰ 运行中要拿新建空档(0 件、148)盖 2 件的那份:拦下");
CHECK(S4("J", 1) == 0, "⑰ 启动时同样拦下(不上传)");
CHECK(S4("J", 0) == 0 && !dm_cloud_conflict_take(), "⑰ 运行中要拿新建空档(0 件、148)盖 2 件的那份:分叉,运行中不动");
CHECK(S4("J", 1) == 1 && d2i_items("J", D2I) == 2 && inbox_n("J") == 0, "⑰ 启动:拿回云端 2 件;本机空档不进收件箱");
put_d2i("J", 0, 300, 3000); CHECK(S4("J", 0) == 1, "⑰ 编年史长过新建大小的仓库取空:照常上传");
// ⑱ rf3 真形状:云端专家仓库是另一台的预置(stash_seed.h),本机还没有专家仓库档(启动同步跑在写预置之前)→ 不拦、不弹;本机写了预置后上传也不拦
// (18) The real rf3 shape: the cloud hardcore stash is another device's preset (stash_seed.h), and the local device has no hardcore stash file yet (startup sync runs before the preset is written) -> not blocked, no prompt; uploading after the local device writes the preset is not blocked either
@@ -180,7 +190,7 @@ int main(void) {
{ uint8_t big[700]; memset(big, 0, sizeof big); uint32_t l1 = 68, l2 = 300; memcpy(big, "\x55\xaa\x55\xaa", 4); memcpy(big + 16, &l1, 4); memcpy(big + 64, "JM", 2); big[66] = 9; memcpy(big + 68, "\x55\xaa\x55\xaa", 4); memcpy(big + 84, &l2, 4); big[132] = 0xc0;
put_bin("K", HC, big, 68 + 300, 5000); CHECK(S5("K", 0) == 1, "⑲ 准备:专家仓库有 9 件、编年史 300 上传"); }
put_bin("K", HC, g_stash_seed, sizeof g_stash_seed, 6000);
CHECK(S5("K", 0) == 0 && dm_cloud_conflict_take() == 1, "⑲ 本机变回预置要盖 9 件的那份:拦下");
CHECK(S5("K", 0) == 0 && !dm_cloud_conflict_take(), "⑲ 本机变回预置要盖 9 件的那份:分叉,运行中不动");
#undef HC
#undef S5
}
@@ -192,6 +202,61 @@ int main(void) {
#undef D2I
#undef S3
}
// ⑳ 同名角色(iCloud 离线冲突第 3 条):云端有 P 的 Foo(1000 秒);新设备 Q 从没同步过、离线建了同名 Foo(5000 秒)和 Bar → 首次同步:Foo 用云端那份、
// 本机 Foo 整份进备份 Foo-5000000、记下名字待进局提示(取一次后清空);Bar 上传、不进提示
// (20) Same-name character (iCloud offline conflict item 3): the cloud has P's Foo (1000 s); new device Q has never synced and created a Foo with the same name (5000 s) and a Bar offline -> first sync: Foo uses the cloud copy,
// the local Foo goes into the backup whole as Foo-5000000, the name is recorded for a notice after entering a run (cleared once taken); Bar is uploaded and not part of the notice
{ char c6[1024], s6[1024], b6[1024], t6[1024]; snprintf(c6, sizeof c6, "%s/cloud6", R); mkdir(c6, 0755); char nm[256];
#define S6(dev, down) (path(s6, dev, "save"), path(b6, dev, "bak"), path(t6, dev, "state"), dm_cloud_sync(s6, c6, b6, t6, down, 0, NULL))
put("P", "save/Foo/Foo.d2s", "fooP", 1000); CHECK(S6("P", 1) == 1, "⑳ 准备:P 上传 Foo");
dm_cloud_char_conflict_take(nm, sizeof nm);
put("Q", "save/Foo/Foo.d2s", "fooQ", 5000); put("Q", "save/Bar/Bar.d2s", "barQ", 5000);
CHECK(S6("Q", 1) == 2, "⑳ Q 首次同步:Foo 下载、Bar 上传,共 2 个动作");
CHECK(get("Q", "save/Foo/Foo.d2s") && !strcmp(get("Q", "save/Foo/Foo.d2s"), "fooP"), "⑳ Q 的 Foo 应换成云端那份 fooP");
CHECK(count_bak("Q", "Foo-5000000") == 1, "⑳ Q 本机那份 Foo 应进备份 Foo-5000000");
CHECK(dm_cloud_char_conflict_take(nm, sizeof nm) == 1 && !strcmp(nm, "Foo"), "⑳ 记下同名角色 Foo 待提示,实为「%s」", nm);
CHECK(dm_cloud_char_conflict_take(nm, sizeof nm) == 0, "⑳ 取过一次后清空");
CHECK(S6("Q", 1) == 0 && dm_cloud_char_conflict_take(nm, sizeof nm) == 0, "⑳ 再同步无动作、不再提示");
#undef S6
}
// ㉑ iCloud 离线冲突三个场景(第一笔口径:两台设备的全部数据都在——仓库或收件箱,且没有永久拦截)。老设备 A:10 件、编年史 600,已上云
// (21) Three iCloud offline conflict scenarios (first-step criterion: all data of both devices is kept - in the stash or the inbox - and nothing is blocked forever). Old device A: 10 items, chronicle 600, already in the cloud
{ char c7[1024], s7[1024], b7[1024], t7[1024], cq[1024]; snprintf(c7, sizeof c7, "%s/cloud7", R); mkdir(c7, 0755); snprintf(cq, sizeof cq, "%s/cloud7q", R); mkdir(cq, 0755);
#define S7(dev, cl, down) (path(s7, dev, "save"), path(b7, dev, "bak"), path(t7, dev, "state"), dm_cloud_sync(s7, cl, b7, t7, down, 0, NULL))
#define D2I7 "save/ModernSharedStashSoftCoreV2/ModernSharedStashSoftCoreV2.d2i"
put_d2i("A7", 10, 600, 1000); CHECK(S7("A7", c7, 1) == 1, "㉑ 准备:A 上传 10 件");
dm_cloud_conflict_take();
// ① 新设备 N 没登录时离线玩(3 件、编年史 300),之后登录、启动同步
// (1) new device N plays offline while not signed in (3 items, chronicle 300), then signs in and syncs at launch
put_d2i("N7", 3, 300, 5000);
CHECK(S7("N7", c7, 1) == 1 && d2i_items("N7", D2I7) == 10, "㉑① N 首次同步:仓库是云端的 10 件");
CHECK(inbox_n("N7") == 1 && inbox_has("N7", "mine.pack") && !inbox_has("N7", "base.pack") && dm_cloud_conflict_take() == 1, "㉑① N 本机 3 件进收件箱(没有基准)、提示一次");
CHECK(S7("N7", c7, 1) == 0 && inbox_n("N7") == 1 && d2i_items("A7", D2I7) == 10, "㉑① 再启动无动作(没有永久状态);A 的 10 件不动");
// ② 新设备 M 离线期间编年史比云端长(900 > 600):原先永久拦住,现在同样云端为现行版 + 收件箱
// (2) new device M's chronicle grew longer than the cloud's while offline (900 > 600): previously blocked forever, now likewise the cloud is the current version + inbox
put_d2i("M7", 3, 900, 5000);
CHECK(S7("M7", c7, 0) == 0 && inbox_n("M7") == 0, "㉑② M 运行中:不动、不收(等启动)");
CHECK(S7("M7", c7, 1) == 1 && d2i_items("M7", D2I7) == 10 && inbox_n("M7") == 1 && dm_cloud_conflict_take() == 1, "㉑② M 启动:仓库 10 件,本机 3 件进收件箱");
CHECK(S7("M7", c7, 1) == 0 && S7("M7", c7, 0) == 0 && inbox_n("M7") == 1, "㉑② 再启动、再运行中都无动作:不是永久拦截");
// ③ 新设备 Q 登录但离线、看到的云端是空的(cloud7q),上传了 3 件;联网后 iCloud 拿 Q 的包当现行版(盖到 cloud7 上)
// (3) new device Q signs in but is offline and sees an empty cloud (cloud7q), uploads 3 items; once online, iCloud takes Q's pack as the current version (overwriting cloud7)
put_d2i("Q7", 3, 300, 5000); CHECK(S7("Q7", cq, 1) == 1, "㉑③ 准备:Q 往看着是空的云端传了 3 件");
char sp[1300], dp[1300], keep[1300]; snprintf(sp, sizeof sp, "%s/_stash.pack", cq); snprintf(dp, sizeof dp, "%s/_stash.pack", c7); snprintf(keep, sizeof keep, "%s/a_old.pack", R);
rename(dp, keep); { FILE *fi = fopen(sp, "rb"), *fo = fopen(dp, "wb"); char buf[8192]; size_t k; while ((k = fread(buf, 1, sizeof buf, fi)) > 0) fwrite(buf, 1, k, fo); fclose(fi); fclose(fo); }
CHECK(S7("A7", c7, 1) == 1 && d2i_items("A7", D2I7) == 3, "㉑③ A 启动:云端(Q 的 3 件)为现行版");
CHECK(inbox_n("A7") == 1 && inbox_has("A7", "base.pack") && dm_cloud_conflict_take() == 1, "㉑③ A 本机 10 件进收件箱,带上次同步的基准");
CHECK(S7("A7", c7, 1) == 0 && inbox_n("A7") == 1, "㉑③ 再启动无动作");
// iCloud 冲突版本:A 那台读出被换下的旧版本(a_old.pack,10 件)收进收件箱;只有预置 / 空档的版本不收
// iCloud conflict version: device A reads out the replaced old version (a_old.pack, 10 items) and stores it in the inbox; a version with only the preset / an empty save is not stored
{ char ts7[1100]; path(s7, "A7", "save"); path(ts7, "A7", "state");
CHECK(dm_cloud_inbox_add(s7, ts7, keep) == 0 && inbox_n("A7") == 2 && dm_cloud_conflict_take() == 1, "㉑③ 冲突版本(10 件)收进收件箱");
put_d2i("E7", 0, 148, 100); { char e7[1100], ee[1100], et[1100], pk[1300]; path(e7, "E7", "save"); path(ee, "E7", "bak"); path(et, "E7", "state"); char ce[1300]; snprintf(ce, sizeof ce, "%s/cloud7e", R); mkdir(ce, 0755);
dm_cloud_sync(e7, ce, ee, et, 1, 0, NULL); snprintf(pk, sizeof pk, "%s/_stash.pack", ce);
CHECK(dm_cloud_inbox_add(s7, ts7, pk) == 0 && inbox_n("A7") == 2, "㉑③ 空档的冲突版本:没东西,不收"); }
CHECK(dm_cloud_inbox_add(s7, ts7, "/nonexistent.pack") == -1, "㉑③ 读不了的冲突版本:返回 -1"); }
#undef S7
#undef D2I7
}
printf("t_cloudsync: %d 项,%d 失败\n", checks, fails);
return fails != 0;
}
+39
View File
@@ -26,6 +26,7 @@ ssize_t pwrite(int, const void *, size_t, off_t);
struct dm_flags g_flag; uint64_t g_t0_ns; uint64_t now_ns(void) { return 0; } // 日志时间戳与读路径的桩(写路径不用) | stubs for log timestamps and the read path (not used by the write path)
void dm_prof_add(int id, uint64_t ns, uint64_t b) { (void)id; (void)ns; (void)b; } void dm_guest_write_prepare(void *a, size_t n) { (void)a; (void)n; }
void dm_fs_save_poison(int e);
extern int g_nfail, g_lasterr; // 前端通知计数(t_fs_stub.c 的强实现替掉 hle_fs.c 的弱实现) | front-end notification count (the strong implementation in t_fs_stub.c replaces the weak one in hle_fs.c)
static int g_mode, g_calls; // 0 照常写;1 一律返回 0;2 第一次只写 3 字节 | 0 write normally; 1 always return 0; 2 write only 3 bytes the first time
static ssize_t fake_pwrite(int fd, const void *buf, size_t n, off_t off) {
@@ -143,6 +144,44 @@ int main(void) {
snprintf(p, sizeof p, "%s/a", work); CHECK(same(p, "new"), "工作目录 a 回到已提交版 new");
snprintf(p, sizeof p, "%s/b", work); CHECK(same(p, "7"), "工作目录 b = 已提交的 7");
printf("⑥ 写失败收场不退出(DM_TEST_FS_FAILAT)\n");
unsetenv("DM_TEST_FS_FAIL");
// ⑥a 提交被拒后重新克隆失败:不退出、工作目录不动、已提交版不变;下次提交照样拒绝并重新克隆成功;再下一个事务照常提交
// 6a Recloning after a refused commit fails: do not exit, the work directory is untouched and the committed version unchanged; the next commit is refused again and the reclone succeeds; the transaction after that commits normally
setenv("DM_TEST_FS_FAILAT", "reclone:1", 1);
CHECK(write_save("save:/a", "bad") == RES_OK, "写 a=bad");
dm_fs_save_poison(ENOSPC); int nf0 = g_nfail;
CHECK(h_fs_Commit("save") == RES_FAIL && g_nfail == nf0 + 1, "本事务被拒(重新克隆注入失败),进程还在,前端通知 1 次");
snprintf(p, sizeof p, "%s/a", save); CHECK(same(p, "new"), "已提交目录 a 仍是 new");
snprintf(p, sizeof p, "%s/a", work); CHECK(same(p, "bad"), "工作目录没删(a 还是 bad)");
CHECK(h_fs_Commit("save") == RES_FAIL && g_nfail == nf0 + 2, "仍是已污染:下一次提交照样拒绝");
snprintf(p, sizeof p, "%s/a", work); CHECK(same(p, "new"), "这次重新克隆成了:工作目录 a 回到 new");
snprintf(p, sizeof p, "%s.re", work); CHECK(access(p, F_OK) != 0, "没有 .re 残留");
CHECK(write_save("save:/a", "good") == RES_OK && h_fs_Commit("save") == RES_OK, "下一个事务写 a=good,提交成功");
snprintf(p, sizeof p, "%s/a", save); CHECK(same(p, "good"), "已提交 a = good");
// ⑥b 改名后写客体名失败、回退也失败:不退出;文件在事务存档里 → 本事务提交被拒、已提交版不变;重新克隆后照常
// 6b Writing the guest name after a rename fails and the rollback fails too: do not exit; the file is in a transactional save, so this transaction's commit is refused and the committed version is unchanged; after recloning everything works
setenv("DM_TEST_FS_FAILAT", "guestname:1,renameback:1", 1);
h_fs_CreateFile("save:/c", 0); CHECK(write_save("save:/c", "c") == RES_OK, "写 c");
CHECK(h_fs_RenameFile("save:/c", "save:/d") != RES_OK, "改名 c → d 返回失败(两步都注入失败),进程还在");
nf0 = g_nfail; CHECK(h_fs_Commit("save") == RES_FAIL && g_nfail == nf0 + 1, "本事务提交被拒");
snprintf(p, sizeof p, "%s/c", save); CHECK(access(p, F_OK) != 0, "已提交目录没有 c");
snprintf(p, sizeof p, "%s/d", save); CHECK(access(p, F_OK) != 0, "已提交目录没有 d");
snprintf(p, sizeof p, "%s/a", save); CHECK(same(p, "good"), "已提交 a 仍是 good");
CHECK(write_save("save:/a", "ok2") == RES_OK && h_fs_Commit("save") == RES_OK, "下一个事务照常提交");
// ⑥c 挂载时克隆工作目录失败:不退出,改成只读挂载已提交目录——读得到、写不进、提交是空操作、已提交版不变、前端通知 1 次;下次正常挂载照旧
// 6c Cloning the work directory at mount fails: do not exit; mount the committed directory read-only instead. Reads work, writes fail, commits are no-ops, the committed version is unchanged, and the front end is notified once; the next normal mount works as before
setenv("DM_TEST_FS_FAILAT", "mountclone:1", 1); g_nmnt = 0; nf0 = g_nfail;
snprintf(p, sizeof p, "rm -rf '%s'", work); system(p);
CHECK(h_fs_MountSave("save", NULL) == RES_OK && g_nfail == nf0 + 1, "挂载返回成功、前端通知 1 次(实际 %d 次)", g_nfail - nf0);
CHECK(read_fs("save:/a", got, sizeof got) && !strcmp(got, "ok2"), "只读挂载下读得到已提交的 a=ok2(读到 %s)", got);
CHECK(write_save("save:/a", "zzz") != RES_OK, "写不进去");
CHECK(h_fs_Commit("save") == RES_OK, "提交是空操作");
snprintf(p, sizeof p, "%s/a", save); CHECK(same(p, "ok2"), "已提交 a 仍是 ok2");
unsetenv("DM_TEST_FS_FAILAT"); g_nmnt = 0;
CHECK(h_fs_MountSave("save", NULL) == RES_OK && write_save("save:/a", "ok3") == RES_OK && h_fs_Commit("save") == RES_OK, "去掉注入重新挂载:事务式照常,写 a=ok3 提交成功");
snprintf(p, sizeof p, "%s/a", save); CHECK(same(p, "ok3"), "已提交 a = ok3");
// 语言开关改写设置文件(settings_lang_apply):期望值按规则手算——只在「与开关不符」时把 Language / VoiceLanguage 改成 0(英文)或 8(简中),别的键和别的语言不动
// Language switch rewriting the settings file (settings_lang_apply): expected values computed by hand from the rule -- only when it "does not match the switch" are Language / VoiceLanguage changed to 0 (English) or 8 (Simplified Chinese); other keys and other languages are untouched
{ extern int g_t_lang; char sd[1200], sf[1300], gotj[512]; snprintf(sd, sizeof sd, "%s/langt", root); mkdir(sd, 0755); snprintf(sf, sizeof sf, "%s/Settings", sd); mkdir(sf, 0755); snprintf(sf, sizeof sf, "%s/Settings/Settings.json", sd);
+22
View File
@@ -51,6 +51,28 @@ int main(void) {
K.tier = 100; if (10819454LL * hi_duo_x1000(0) / 1000 > 8388607LL) { fails++; printf(" ✗ 100 层巴尔 × s 过了属性上限\n"); }
K.guards[0] = 7; K.guards[1] = 9; K.guards[2] = 0; if (!is_guard(7) || !is_guard(9) || is_guard(0) || is_guard(8)) { fails++; printf(" ✗ is_guard 认错\n"); }
printf("hi_duo %s:4 格系数 + 巴尔不过上限 + 认守护者\n", fails ? "失败" : "OK");
// 闯入首领也算「特殊单位」(不按普通怪计分、不按普通怪再改属性):在场的(K.inv_id)与已退场、还没被真移除的(g_inv_gone)都算——
// 后者漏掉的话,退场后那几秒里被打死会按普通金怪计 10 分(实测过:进度 400 → 410)
// Invading bosses also count as "special units" (not scored as ordinary monsters, not scaled again as ordinary monsters): both the one present (K.inv_id) and one that has left but is not yet truly removed (g_inv_gone) -
// if the latter is missed, being killed in the few seconds after leaving would score 10 points as an ordinary unique monster (measured: progress 400 -> 410)
K.guards[0] = K.guards[1] = K.guards[2] = 0; K.inv_id[0] = 21; K.inv_id[1] = 0; g_inv_gone[0] = 0; g_inv_gone[1] = 33;
if (!is_guard(21) || !is_guard(33) || is_guard(22) || is_guard(0)) { fails++; printf(" ✗ is_guard 没认全闯入首领(在场 21、已退场 33)\n"); }
K.inv_id[0] = 0; g_inv_gone[1] = 0; if (is_guard(21) || is_guard(33)) { fails++; printf(" ✗ 清掉之后 is_guard 还认\n"); }
// 首领召唤物按类号认:巴尔触手 562–566、分身 570;巴尔本体 544、它的小怪 571、普通怪不算
// Boss summons are recognised by class id: Baal's tentacles 562–566 and clone 570; Baal himself 544, his minions 571 and ordinary monsters do not count
{ static const struct { uint32_t cls; int want; } bc[] = { { 561, 0 }, { 562, 1 }, { 564, 1 }, { 566, 1 }, { 567, 0 }, { 570, 1 }, { 571, 0 }, { 544, 0 }, { 45, 0 } };
for (unsigned i = 0; i < sizeof bc / sizeof *bc; i++) if (boss_summon(bc[i].cls) != bc[i].want) { fails++; printf(" ✗ boss_summon(%u) 应为 %d\n", bc[i].cls, bc[i].want); } }
printf("invader_guard %s:在场与已退场的闯入首领都算特殊单位\n", fails ? "失败" : "OK");
// 特殊精英的梯度(设计稿第二十四节):原生怪留几成 / 一场最多几组 / 同时在场几组。74 层及以下 = 100% / 0 / —(逐位不变)
// Special elite gradient (design draft section 24): share of native monsters kept / max groups per run / groups present at once. Level 74 and below = 100% / 0 / - (unchanged bit for bit)
{ static const struct { int tier, nat, quota, cap; } sc[] = { { 1, 100, 0, 2 }, { 74, 100, 0, 2 }, { 75, 80, 2, 2 }, { 79, 80, 2, 2 }, { 80, 55, 5, 2 }, { 84, 55, 5, 2 }, { 85, 30, 7, 2 }, { 89, 30, 7, 2 }, { 90, 0, 1 << 30, 3 }, { 100, 0, 1 << 30, 3 } };
for (unsigned i = 0; i < sizeof sc / sizeof *sc; i++) if (su_nat_pct(sc[i].tier) != sc[i].nat || su_quota(sc[i].tier) != sc[i].quota || su_cap(sc[i].tier) != sc[i].cap) { fails++; printf(" ✗ 第 %d 层特殊精英梯度应为 %d%% / %d 组 / 同时 %d 组\n", sc[i].tier, sc[i].nat, sc[i].quota, sc[i].cap); }
// 池:43 行、不重样、不含剔掉的 23 行、含女伯爵(6)与随从 9 只的三行(24、36、38,有巴尔的场在抽的时候跳过)
// Pool: 43 rows, no duplicates, none of the 23 removed rows, includes the Countess (6) and the three rows with 9 minions (24, 36, 38; skipped when drawing for a run with Baal)
static const uint8_t out[] = { 5, 10, 15, 18, 20, 26, 27, 28, 29, 30, 31, 39, 41, 42, 43, 44, 45, 60, 61, 62, 63, 64, 65 }; int seen[66] = { 0 }, bad = sizeof k_su_pool != 43;
for (unsigned i = 0; i < sizeof k_su_pool; i++) { if (k_su_pool[i] > 65 || seen[k_su_pool[i]]++) bad = 1; } for (unsigned i = 0; i < sizeof out; i++) bad |= seen[out[i]]; bad |= !seen[6] || !seen[24] || !seen[36] || !seen[38];
if (bad) { fails++; printf(" ✗ 特殊精英的池不对(应 43 行、不重样、不含剔掉的 23 行)\n"); }
printf("su_tiers %s:10 格梯度 + 池 43 行\n", fails ? "失败" : "OK"); }
printf("t_rift_next %s:%d 格(层 × 晋级量)下一层 = 手写期望且 ≤ 100,宿主与顶部条同值\n", fails ? "失败" : "OK", n);
return fails != 0;
}
+6
View File
@@ -33,6 +33,12 @@ int main(void) {
for (unsigned i = 0; i < sizeof oc / sizeof *oc; i++) { atomic_store(&K.st, oc[i].st); K.t0_ns = guest_ns() - (uint64_t)oc[i].ago * 1000000000ull; dm_rift_hud_t h = {0}; dm_rift_menu_t m = {0}; dm_rift_hud(&h); menu_fill(&m, 2);
if (rift_overtime() != oc[i].want || m.overtime != oc[i].want || (oc[i].st != ST_IDLE && h.overtime != oc[i].want)) { fails++; printf(" ✗ 状态 %d 开局 %d 秒前:超时量应为 %d,得 %d(顶部条 %d、菜单 %d)\n", oc[i].st, oc[i].ago, oc[i].want, rift_overtime(), h.overtime, m.overtime); } }
printf("rift_overtime %s:6 格\n", fails ? "失败" : "OK");
// 顶部条第二行写哪一句(dm_rift_hud 的 goal,宿主一处定):按「是否超时 × 守护者是否在场 × 守护者几位」手写期望
// Which sentence the second line of the top bar shows (goal of dm_rift_hud, decided in one place in the host): expected values written by hand over "overtime or not x Guardians present or not x how many Guardians"
static const struct { int ago, guard, dead, total, want; } gc[] = { { 100, 0, 0, 0, 0 }, { 100, 1, 0, 1, 1 }, { 100, 1, 0, 2, 2 }, { 100, 1, 1, 2, 2 }, { 100, 1, 1, 3, 2 }, { 901, 0, 0, 0, 3 }, { 901, 1, 0, 1, 4 }, { 901, 1, 1, 2, 5 } };
for (unsigned i = 0; i < sizeof gc / sizeof *gc; i++) { atomic_store(&K.st, ST_RUN); K.t0_ns = guest_ns() - (uint64_t)gc[i].ago * 1000000000ull; K.guard = gc[i].guard ? 7 : 0; atomic_store(&K.guard_dead, 0); atomic_store(&K.gdead, gc[i].dead); atomic_store(&K.gtotal, gc[i].total);
dm_rift_hud_t h = {0}; dm_rift_hud(&h); if (h.goal != gc[i].want || h.gdead != gc[i].dead || h.gtotal != gc[i].total) { fails++; printf(" ✗ 开局 %d 秒前 守护者在场 %d(%d/%d):第二行应为 %d,得 %d\n", gc[i].ago, gc[i].guard, gc[i].dead, gc[i].total, gc[i].want, h.goal); } }
K.guard = 0; printf("hud_goal %s:8 格\n", fails ? "失败" : "OK");
printf("t_rift_oldrun %s:%d 格城里入口给页 + 新局重置清请求\n", fails ? "失败" : "OK", n);
return fails != 0;
}
+1
View File
@@ -33,6 +33,7 @@ void dm_elysium_arm(int on) { (void)on; } // 极乐世界勾选(dm_elysium.c
void dm_custom_on_uimsg(const char *cat, const char *act, const char *arg) { (void)cat; (void)act; (void)arg; } // 「自定义」设置(dm_custom.c)的桩 | stub for the "Custom" settings (dm_custom.c)
void dm_belt_put(unsigned id) { (void)id; }
void dm_ui_rect(int *x, int *y, int *w, int *h) { *x = *y = *w = *h = 0; }
void dm_uiscreen_set_panel(int on) { (void)on; }
int dm_screen_real(int *w, int *h) { (void)w; (void)h; return 0; }
int dm_uiscreen_ingame(void) { return 0; }
void dm_uiscreen_set_ingame(int on) { (void)on; } // 界面矩形(dm_uiscreen.c)的桩:没开真全屏 | stub for the UI rectangle (dm_uiscreen.c): true full screen not enabled
+1
View File
@@ -79,6 +79,7 @@ float dm_ui_ny(float ny) { return ny; }
int dm_screen_real(int *w, int *h) { (void)w; (void)h; return 0; }
void dm_uiscreen_enable(int m) { (void)m; }
void dm_ui_rect(int *x, int *y, int *w, int *h) { *x = *y = *w = *h = 0; }
void dm_uiscreen_set_panel(int on) { (void)on; }
int dm_uiscreen_ingame(void) { return 0; }
void dm_uiscreen_set_ingame(int on) { (void)on; }
void dm_held_stow(void) {}