v1.0.15: shell is now build input (.zip), launch self-check for incomplete packages and devices without Metal 3, graphics translation on its own thread, save with the pause menu open, wide-iPhone item tooltip and Chronicle rewards fixes
This commit is contained in:
@@ -298,6 +298,9 @@ static _Atomic int g_imbue_open; /* 单件任务槽面板开着(灌魔 / 打
|
||||
static _Atomic int g_cube_open; /* 赫拉迪克方块页开着:双击 = 按住 Y(原版「移到另一侧」:背包 → 方块 / 方块 → 背包),不是「使用 / 装备」 | Horadric Cube page open: double tap = hold Y (the original game's "move to the other side": inventory → cube / cube → inventory), not "use / equip" */
|
||||
static _Atomic int g_vault_open; /* 储藏箱开在第六页「编年史」:双击背包物品 = 存进编年史仓库(走 use_seq,宿主 ui_use_pump 判页),不发原版「按住 Y」——那一页游戏当魔盒页 | Stash open on page six 「编年史」(Chronicle): double-tapping an inventory item = store it in the Chronicle vault (goes through use_seq; the host's ui_use_pump determines the page); do not send the original game's "hold Y" -- the game treats that page as the cube page */
|
||||
static _Atomic int g_bank_open; /* 储藏箱开着(前端从宿主读游戏面板树的结果设进来,不靠开关消息):双击 = 按住 Y(移到另一侧) | Stash open (set by the front end from the host's reading of the game panel tree, not from open/close messages): double tap = hold Y (move to the other side) */
|
||||
int dm_tc_panel_mode(int nav, const dm_tc_scene *scene, int blocked) { /* 原在 front_ios.m(nmode);菜单上又开了雇佣列表这类页时读数 > 0,不算「只开着对话菜单」 | formerly in front_ios.m (nmode); when a page such as the hire list is also open over the menu the reading is > 0, which does not count as "only the dialog menu open" */
|
||||
return nav ? (dm_tc_scene_dead() ? 2 : dm_tc_scene_dialog_only(scene) && blocked <= 0 ? 3 : 1) : 0;
|
||||
}
|
||||
void dm_tc_set_panel_state(int bits) { atomic_store(&g_bank_open, (bits & 1) != 0); atomic_store(&g_vendor_open, (bits & 2) != 0); atomic_store(&g_dead_modal, (bits & 4) != 0); atomic_store(&g_imbue_open, (bits & 16) != 0); atomic_store(&g_cube_open, (bits & 32) != 0); atomic_store(&g_vault_open, (bits & 64) != 0); } /* 位同 dm_cursor.h 的 DM_PS_*;宿主读游戏状态得来 | Bits are the same as DM_PS_* in dm_cursor.h; obtained by the host reading the game state */
|
||||
|
||||
static void pointer_drag_begin(dm_tc_state *s, dm_tc_finger *f) {
|
||||
|
||||
@@ -135,6 +135,11 @@ typedef struct { int game; uint64_t panels; } dm_tc_scene;
|
||||
int dm_tc_navigation(dm_tc_scene *scene, const char *cat, const char *act, const char *arg);
|
||||
int dm_tc_scene_dialog_only(const dm_tc_scene *scene); /* 只开着 NPC 对话菜单 | Only the NPC dialog menu is open */
|
||||
int dm_tc_scene_dead(void); /* 死亡弹窗开着(导航态,但不给手柄圆钮) | Death popup open (navigation state, but no controller round buttons) */
|
||||
/* 面板模式(前端两端共用一个算式,iOS front_ios.m 与 Mac touch_mac.c):0 = 游戏态;1 = 面板态;2 = 死亡页;3 = 只开着 NPC 对话菜单。
|
||||
nav = 手势层的导航判断(dm_tc_navigation,再并上「面板栈里还开着非常驻面板」);blocked = 面板栈读数(dm_hud_stack_msg:只开着对话菜单时 -1)
|
||||
Panel mode (one formula shared by both front ends, iOS front_ios.m and Mac touch_mac.c): 0 = game; 1 = panel; 2 = death screen; 3 = only the NPC dialog menu open.
|
||||
nav = the gesture layer's navigation judgment (dm_tc_navigation, combined with "a non-resident panel is still open in the panel stack"); blocked = the panel stack reading (dm_hud_stack_msg: -1 when only the dialog menu is open) */
|
||||
int dm_tc_panel_mode(int nav, const dm_tc_scene *scene, int blocked);
|
||||
|
||||
/* 坐标使用 UIKit 点;布局本身不画球、不声称游戏已绑定回城/腰带。 | Coordinates use UIKit points; the layout itself does not draw the orbs and does not claim the game has bound town portal/belt. */
|
||||
/* 安全区左右内缩(点);在 init / resize 之前设,之后的布局按它把右侧技能键组与左摇杆移进安全区。缺省 0。 | Left/right safe-area insets (points); set before init / resize, and the layout afterwards uses them to move the right-side skill key group and the left stick into the safe area. Default 0. */
|
||||
|
||||
+16
-72
@@ -750,65 +750,16 @@ static BOOL touch_done(UITouch *t) { UITouchPhase ph=t.phase; return ph==UITouch
|
||||
// 底部 UI v4 的 UIKit 底栏只在「局内常态」画:维护面板开合栈,常驻 HUD 层之外任何面板开着就不画(未知面板默认让开,免挡游戏自己的画面)。
|
||||
// 常驻层 = 营地无操作时 OpenPanel 后一直不关的 13 个(实测 UI 消息流)+ 存档提示 / 通知 / 组队消息 / 帮助按钮 / 手柄提示层 / 自动地图(战斗叠加)
|
||||
// 名单在宿主 dm_cursor.c 的 dm_ui_panel_resident(面板状态安全阀同用一份)
|
||||
// The UIKit bottom bar of bottom UI v4 is drawn only in the "normal in-run state": maintain a panel open / close stack, and do not draw when any panel other than the always-on HUD layers is open (unknown panels yield by default, to avoid covering the game's own picture).
|
||||
// Always-on layers = the 13 that stay open after OpenPanel when idle in camp (measured UI message stream) + save hint / notification / party message / help button / controller hint layer / automap (combat overlay)
|
||||
// The list is in the host's dm_cursor.c dm_ui_panel_resident (shared with the panel state safety valve)
|
||||
enum { HUD_STACK_MAX=64 };
|
||||
static struct { char name[64]; int open; } g_hud_stack[HUD_STACK_MAX];
|
||||
static _Atomic int g_hud_blocked; // 栈里还开着的非常驻面板数 | Number of panels other than the always-on layers still open in the stack
|
||||
// 面板开合栈搬到宿主 dm_cursor.c(dm_hud_stack_msg,Mac touch_mac.c 共用同一份);这里只记「连续多久非零」并通知 UIKit 底栏让开
|
||||
// The UIKit bottom bar of bottom UI v4 is only drawn in the normal in-game state: maintain the panel stack; whenever any panel other than the resident HUD layers is open, it is not drawn (unknown panels make way by default so they do not cover the game's own picture).
|
||||
// Resident layers = the 13 panels that are opened and never closed in camp when idle (measured from the UI message stream) + save notice / notifications / party messages / help button / gamepad hint layer / automap (combat overlay).
|
||||
// The list is dm_ui_panel_resident in the host's dm_cursor.c (shared with the panel state safety valve).
|
||||
// The panel stack moved to the host's dm_cursor.c (dm_hud_stack_msg, shared with Mac touch_mac.c); here we only track how long it has been non-zero and tell the UIKit bottom bar to make way
|
||||
int dm_hud_stack_msg(const char *act, const char *arg); void dm_hud_stack_dump(void);
|
||||
static _Atomic int g_hud_blocked; // 栈读数:开着的非常驻面板数(只开着 NPC 对话菜单时 -1) | Stack reading: number of open non-resident panels (-1 when only the NPC dialog menu is open)
|
||||
static uint64_t g_hud_blocked_since;
|
||||
static void hud_stack_message(const char *act,const char *arg) {
|
||||
// 读取画面撤下:清掉此刻在游戏面板树里已经看不见的记录(防只开不关的漏配),屏上还在的照记——
|
||||
// 通关页是读取画面撤下前 0.5 秒开的(OpenExclusivePanel EndScreenPanelExpansion → UnloadPanel LoadScreenPanel),原先整栈清零把它也清了:
|
||||
// 底栏和技能钮盖在通关页上、点「好」变成点世界
|
||||
// Loading screen removed: clear the records no longer visible in the game's panel tree at this moment (guards against open-without-close mismatches), and keep those still on screen --
|
||||
// the game-completion page is opened 0.5 seconds before the loading screen is removed (OpenExclusivePanel EndScreenPanelExpansion → UnloadPanel LoadScreenPanel); previously the whole stack was zeroed, clearing it too:
|
||||
// the bottom bar and skill buttons covered the game-completion page, and tapping 「好」(OK) became a world tap
|
||||
if(!strcmp(act,"UnloadPanel") && !strcmp(arg,"LoadScreenPanel")) {
|
||||
for(int i=0;i<HUD_STACK_MAX;i++) {
|
||||
if(g_hud_stack[i].open>0 && strcmp(g_hud_stack[i].name,"LoadScreenPanel") && dm_ui_panel_shown(g_hud_stack[i].name)) fprintf(stderr,"[hud] 面板栈 读取画面撤下:%s 屏上还在,照记\n",g_hud_stack[i].name);
|
||||
else memset(&g_hud_stack[i],0,sizeof g_hud_stack[i]);
|
||||
}
|
||||
}
|
||||
else if(!strcmp(act,"UnloadAll")) memset(g_hud_stack,0,sizeof g_hud_stack);
|
||||
else {
|
||||
// PanelManager 的面板动作全集(读码:它的消息分发 main+0xb1dc60 只认这 8 个,与全部日志里出现过的一致):
|
||||
// OpenPanel / OpenExclusivePanel = 开;ClosePanel / UnloadPanel = 关(读取画面那条见上);TogglePanel = 按当前记录翻转(高级属性页走它);
|
||||
// UnloadAll = 全清(见上);LoadPanel = 预载、不上屏,不算开关;HideGameInfo = 隐藏游戏信息层,与面板开关无关
|
||||
// Full set of PanelManager panel actions (from reading the code: its message dispatch main+0xb1dc60 only recognizes these 8, matching what has appeared across all logs):
|
||||
// OpenPanel / OpenExclusivePanel = open; ClosePanel / UnloadPanel = close (for the loading screen one see above); TogglePanel = flip according to the current record (the advanced stats page uses it);
|
||||
// UnloadAll = clear all (see above); LoadPanel = preload without showing, not counted as open or close; HideGameInfo = hide the game info layer, unrelated to panel open / close
|
||||
int tog=!strcmp(act,"TogglePanel");
|
||||
int open=!strcmp(act,"OpenPanel")||!strcmp(act,"OpenExclusivePanel"), close=!strcmp(act,"ClosePanel")||!strcmp(act,"UnloadPanel");
|
||||
if(!open && !close && !tog) return;
|
||||
if(dm_ui_panel_resident(arg)) return;
|
||||
int slot=-1; for(int i=0;i<HUD_STACK_MAX;i++) if(!strcmp(g_hud_stack[i].name,arg)) { slot=i; break; }
|
||||
if(slot<0) for(int i=0;i<HUD_STACK_MAX;i++) if(!g_hud_stack[i].name[0]) { slot=i; strlcpy(g_hud_stack[i].name,arg,sizeof g_hud_stack[i].name); break; }
|
||||
if(slot<0) return;
|
||||
if(tog) { open=g_hud_stack[slot].open<=0; close=!open; }
|
||||
// 没开着就收到关闭 = 空操作,不是漏配:游戏开功能页 / 切页签时对一批互斥面板(仓库、方块、商店、小站、对话…)统一发 ClosePanel,不管开没开;
|
||||
// 启动时选角页也是先关再开(读界面消息流水;之前记成红,玩家路径每次启动 14 条假红)。真漏接了打开的后果是底栏不让开,由下面 60 秒巡检兜
|
||||
// A close received while not open = no-op, not a missing mapping: when opening a function page / switching tabs the game sends ClosePanel to a batch of mutually exclusive panels (storage, cube, shop, waypoint, dialog…) regardless of whether they are open;
|
||||
// at launch the character select page is also closed first and then opened (from reading the UI message log; previously logged as a failure, 14 false failures per launch on the player path). The consequence of really missing an open is the bottom bar not yielding, which the 60-second patrol below covers
|
||||
if(close && g_hud_stack[slot].open<=0) return;
|
||||
// 按「开 / 没开」记,不按次数累加:游戏对已经开着的面板再发一次 OpenPanel 是常态——雇佣列表上的替换确认框每被关掉一次,
|
||||
// 就重发一次 OpenPanel HireMenuPanel(中间没有关闭),而整段对话结束时只发固定次数的关闭。按次数加的话多出确认框两回再雇成,计数留在 1:
|
||||
// 屏上已没有面板,前端却一直按面板态(没摇杆、没技能钮、点哪里都是「面板外」)。809 份日志里计数到过 2 以上的只有 4 个面板
|
||||
// (主菜单链接、选角页、起名候选栏、雇佣列表),没有一个是真叠两层要关两次的。dm_tc_navigation 那一路本来就是幂等位图,两路口径一致了
|
||||
// Recorded as "open / not open", not accumulated by count: the game sending OpenPanel again for an already open panel is normal -- each time the replacement confirmation box on the hire list is dismissed,
|
||||
// OpenPanel HireMenuPanel is sent again (with no close in between), while at the end of the whole dialog only a fixed number of closes is sent. Adding by count, when the confirmation box comes up two extra times and the hire then succeeds, leaves the count at 1:
|
||||
// no panel left on screen, yet the front end stays in panel mode (no stick, no skill buttons, every tap is "outside the panel"). Across 809 logs only 4 panels ever reached a count of 2 or more
|
||||
// (main menu links, character select page, naming candidate bar, hire list), and none of them was a real two-layer stack needing two closes. The dm_tc_navigation path was already an idempotent bitmap, so the two paths now agree
|
||||
if(open && g_hud_stack[slot].open>0) { fprintf(stderr,"[hud] 面板栈 %s %s:已经开着,不重复计\n",act,arg); return; }
|
||||
g_hud_stack[slot].open=open?1:0;
|
||||
fprintf(stderr,"[hud] 面板栈 %s %s → %d\n",act,arg,g_hud_stack[slot].open);
|
||||
}
|
||||
// NPC 对话菜单(交谈 / 交易…那一小列)不挡底栏:只开着它时底栏照常显示(否则 UIKit 层让开、露出游戏层那份底栏,难度格和回城书不见、腰带样子也变)。
|
||||
// 编码进同一个数:对话菜单开着且没有别的面板 → -1(底栏不让开、且免除导航态的隐藏)
|
||||
// The NPC dialog menu (the small column of Talk / Trade…) does not block the bottom bar: with only it open the bottom bar shows as usual (otherwise the UIKit layer yields and exposes the game layer's bottom bar; the difficulty cell and Tome of Town Portal disappear and the belt looks different too).
|
||||
// Encoded into the same number: dialog menu open with no other panel → -1 (the bottom bar does not yield, and navigation-mode hiding is waived)
|
||||
int n=0, dlg=0; for(int i=0;i<HUD_STACK_MAX;i++) { if(!strcmp(g_hud_stack[i].name,"NpcDialogPanel")||!strcmp(g_hud_stack[i].name,"ScrollSpeechPanel")) dlg|=g_hud_stack[i].open>0; else n+=g_hud_stack[i].open; } // ScrollSpeechPanel = NPC 说话的滚动文字框(屏幕上方一小块),同样不挡底栏 | ScrollSpeechPanel = the scrolling text box of NPC speech (a small block at the top of the screen); it likewise does not block the bottom bar
|
||||
if(!n && dlg) n=-1;
|
||||
int n=dm_hud_stack_msg(act,arg);
|
||||
uint64_t t=now_ns();
|
||||
if(n>0 && !g_hud_blocked_since) g_hud_blocked_since=t;
|
||||
if(n<=0) g_hud_blocked_since=0;
|
||||
@@ -823,7 +774,7 @@ static void hud_stack_message(const char *act,const char *arg) {
|
||||
static void hud_stack_watch(void) {
|
||||
if(g_hud_blocked_since && now_ns()-g_hud_blocked_since>60000000000ull) {
|
||||
fprintf(stderr,"[hud] 面板栈已连续 60 秒非零(线索,非缺陷):");
|
||||
for(int i=0;i<HUD_STACK_MAX;i++) if(g_hud_stack[i].open) fprintf(stderr,"%s×%d ",g_hud_stack[i].name,g_hud_stack[i].open);
|
||||
dm_hud_stack_dump();
|
||||
fprintf(stderr,"\n"); g_hud_blocked_since=now_ns();
|
||||
}
|
||||
}
|
||||
@@ -855,7 +806,7 @@ static void touch_ui_message(const char *cat,const char *act,const char *arg) {
|
||||
// 测试:DM_TOUCH_SCRIPT_START=menu 时触点脚本从主菜单出现起计时(缺省从首次进局起),前端页面的玩家路径用例用
|
||||
// Test: with DM_TOUCH_SCRIPT_START=menu the touch script times from when the main menu appears (default: from first entering a run); used by player-path cases on front-end pages
|
||||
if(getenv("DM_TOUCH_SCRIPT_START") && !strcmp(cat,"PanelManager") && !strcmp(act,"OpenPanel") && !strcmp(arg,"MainMenuButtonRibbon")) dispatch_async(dispatch_get_main_queue(),^{ touch_script_start(); });
|
||||
int nmode=mode ? (dm_tc_scene_dead() ? 2 : dm_tc_scene_dialog_only(&scene) && atomic_load(&g_hud_blocked)<=0 ? 3 : 1) : 0; // 3 = 只开着 NPC 对话菜单(面板栈读数 -1);菜单上又开了雇佣列表这类不在名单里的页就不算(那时底栏十字不该露出来) | 3 = only the NPC dialog menu is open (panel stack reading -1); if a page not on the list such as the hire list is opened on top of the menu, it does not count (the bottom bar cross should not show then)
|
||||
int nmode=dm_tc_panel_mode(mode,&scene,atomic_load(&g_hud_blocked)); // 3 = 只开着 NPC 对话菜单(面板栈读数 -1);菜单上又开了雇佣列表这类不在名单里的页就不算(那时底栏十字不该露出来) | 3 = only the NPC dialog menu is open (panel stack reading -1); if a page not on the list such as the hire list is opened on top of the menu, it does not count (the bottom bar cross should not show then)
|
||||
if(atomic_exchange(&g_touch_navigation,nmode)!=nmode) dispatch_async(dispatch_get_main_queue(),^{ [g_touch_view navigationMode:nmode]; });
|
||||
dm_uiscreen_set_panel(nmode==1); // iPad 真全屏:面板模式下界面移到正中;没开真全屏时宿主不动 | iPad true fullscreen: in panel mode the UI moves to the center; without true fullscreen the host does nothing
|
||||
}
|
||||
@@ -1177,20 +1128,13 @@ static void audio_apply(void) { dm_audio_suspend(g_audio_bg || g_audio_intr); }
|
||||
// In the enter-background callback (the system gives this callback 10 seconds): wait only in a run. Wait until "a save commit has appeared after sending the background focus, and no new commit for 0.2 seconds after that" (character and shared stash are two containers and may commit separately), at most 2.5 seconds.
|
||||
// During this time the game main loop runs as usual and presented frames are simply dropped. Outside a run (main menu / character select) do not wait: there is no unsaved progress there
|
||||
static void background_wait_save(void) {
|
||||
int dm_ingame_now(void); uint64_t dm_fs_commit_count(void); void mtl_present_discard(int on); uint64_t now_ns(void);
|
||||
int dm_request_save(void);
|
||||
if (!dm_ingame_now() || !dm_request_save()) return; // 让游戏下一拍走它自己的定时自动存盘(diag.c) | Let the game run its own timed auto-save on the next tick (diag.c)
|
||||
uint64_t c0 = dm_fs_commit_count(), t0 = now_ns(), last = c0, last_t = 0;
|
||||
int dm_ingame_now(void); void mtl_present_discard(int on); int dm_save_wait(double max_s, uint64_t *commits, int *froze, double *ms);
|
||||
if (!dm_ingame_now()) return;
|
||||
uint64_t n = 0; int froze = 0; double ms = 0;
|
||||
mtl_present_discard(1);
|
||||
for (;;) {
|
||||
usleep(20000);
|
||||
uint64_t c = dm_fs_commit_count(), t = now_ns();
|
||||
if (c != last) { last = c; last_t = t; }
|
||||
if (last_t && t - last_t >= 200000000ull) break;
|
||||
if (t - t0 >= 2500000000ull) break;
|
||||
}
|
||||
dm_save_wait(2.5, &n, &froze, &ms); // 游戏停着(暂停菜单开着)时冻住世界、临时放开暂停存这一次,存完写回(diag.c) | If the game is stopped (pause menu open), freeze the world and temporarily release the pause for this one save, then write it back (diag.c)
|
||||
mtl_present_discard(0);
|
||||
LOG("前端:进后台等游戏存盘 %.0f ms,期间存档提交 %llu 次%s", (now_ns() - t0) / 1e6, (unsigned long long)(last - c0), last == c0 ? "【红】(2.5 秒内没等到)" : "");
|
||||
LOG("前端:进后台等游戏存盘 %.0f ms,期间存档提交 %llu 次%s%s", ms, (unsigned long long)n, froze ? "(原先暂停着:冻结世界存盘、已恢复暂停)" : "", n ? "" : "【红】(2.5 秒内没等到)");
|
||||
}
|
||||
// 失活时也请游戏存一次盘(查 #22 发现的缺口):上划进多任务界面时 App 多半只「失活」、不进后台,在那里直接划掉进程
|
||||
// 走不到进后台的存盘,丢掉距上次定时存盘(游戏 5 分钟一次)以来的进度。只置游戏「下一拍就自动存盘」的计时(同 dm_request_save),不等提交、不挡主线程;
|
||||
@@ -1479,7 +1423,7 @@ void front_ios_lifecycle_install(void) {
|
||||
LOG("前端:测试回前台(DM_TEST_BG)"); mtl_link_pause(0); front_ios_focus_event(2); front_ios_focus_event(3);
|
||||
uint64_t c0 = dm_audio_render_calls();
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2000000000), dispatch_get_main_queue(), ^{
|
||||
LOG("前端:测试回前台后 2 s 声卡回调 +%llu(客体时钟 %.3f s)", (unsigned long long)(dm_audio_render_calls() - c0), guest_ns() / 1e9); }); });
|
||||
int dm_game_paused(void); LOG("前端:测试回前台后 2 s 声卡回调 +%llu(客体时钟 %.3f s;原版暂停 %d)", (unsigned long long)(dm_audio_render_calls() - c0), guest_ns() / 1e9, dm_game_paused()); }); });
|
||||
}
|
||||
// 测试开关 DM_TEST_RESIGN=秒:到点只发「失活」(sceneWillResignActive),不进后台——模仿上划停在多任务界面;配合测试脚本随后 kill -9 = 在多任务界面里划掉
|
||||
// Test switch DM_TEST_RESIGN=seconds: at that time send only "resign active" (sceneWillResignActive) without going to background -- mimics swiping up and stopping in the app switcher; combined with the test script's subsequent kill -9 = swiping it away in the app switcher
|
||||
|
||||
+80
-12
@@ -365,11 +365,20 @@ static int g_pack_wait; // 托管资源包的目录已经在、系统还没说
|
||||
static int g_doc_stray; // 另一条附带结论:「D2R Mobile」里有文件夹但没有一个是资源(why = 现有哪些文件夹),托管资源包也没到——照常去试托管下载,下载站也走不通时把 why 给玩家看 | The other side conclusion: 「D2R Mobile」 has folders but none of them is assets (why = which folders exist now), and the hosted asset pack has not arrived either -- try the hosted download as usual, and show why to the player when the download site is unreachable too
|
||||
// 本包有没有配置苹果的托管资源包(Info.plist 的 BAHasManagedAssetPacks)。没配置的包(免费账号档、不带游戏内容的壳:tools/project_free.py、
|
||||
// tools/shell_build.sh 把那几项去掉了)一碰 BAAssetPackManager,系统接口内部断言直接让进程退出——真机实测:没有资源的第一次启动必崩。
|
||||
// 所以凡是要问那个接口的地方先问这里。
|
||||
// Whether this bundle is configured with Apple managed asset packs (BAHasManagedAssetPacks in Info.plist). In a bundle without it (the free-account build and the shell with no game content: tools/project_free.py and
|
||||
// tools/shell_build.sh remove those keys), merely touching BAAssetPackManager trips an assertion inside the system framework and the process exits -- measured on a device: the first launch with no resources always crashed.
|
||||
// So every place that is about to ask that framework asks here first.
|
||||
static BOOL ba_configured(void) { return [[NSBundle.mainBundle objectForInfoDictionaryKey:@"BAHasManagedAssetPacks"] boolValue]; }
|
||||
// 所以凡是要问那个接口的地方先问这里。另一种同样会崩的包:Info.plist 还声明着,但签名里没有它要的 app group(用自己的 Apple ID / 自签工具重签的
|
||||
// 包——描述文件里没有我们的 app group):系统 Swift 层报「app group … is inaccessible」致命错误。所以还要核声明的 app group 拿得到容器目录(拿不到 = 签名没带这项权限)
|
||||
// Whether this package configures Apple's managed asset packs (BAHasManagedAssetPacks in Info.plist). In packages without it (the free-account build, and the shell without game content: tools/project_free.py and
|
||||
// tools/shell_build.sh remove those entries), touching BAAssetPackManager makes an assertion inside the system interface terminate the process; measured on a device, the first launch without resources always crashed.
|
||||
// So every place that would ask that interface asks here first. Another kind of package crashes the same way: Info.plist still declares it, but the signature lacks the app group it needs (packages re-signed with your own Apple ID / a sideloading tool,
|
||||
// whose provisioning profile does not include our app group): the system Swift layer raises a fatal "app group ... is inaccessible" error. So we also check that the declared app group returns a container directory (none = the signature does not carry that entitlement)
|
||||
static BOOL ba_configured(void) {
|
||||
static int v = -1; if (v >= 0) return v;
|
||||
NSString *g = [NSBundle.mainBundle objectForInfoDictionaryKey:@"BAAppGroupID"];
|
||||
if (![[NSBundle.mainBundle objectForInfoDictionaryKey:@"BAHasManagedAssetPacks"] boolValue]) v = 0;
|
||||
else if (!g.length || ![NSFileManager.defaultManager containerURLForSecurityApplicationGroupIdentifier:g]) { v = 0; plog("boot: 本包声明了托管资源包,但签名里没有它要的 app group「%s」(自签 / 重签的包),不走托管资源包", g.UTF8String ?: "未声明"); }
|
||||
else v = 1;
|
||||
return v;
|
||||
}
|
||||
|
||||
static NSString *romfs_locate(char *why, size_t n) {
|
||||
g_doc_bad = 0; g_doc_stray = 0;
|
||||
@@ -507,6 +516,51 @@ static BOOL astc_dl_configured(void) { // 自动下载地址配了没有:测
|
||||
for (NSString *l in [t componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]) { NSString *v = [l stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet]; if (v.length && ![v hasPrefix:@"#"]) return YES; }
|
||||
return NO;
|
||||
}
|
||||
// 安装包自检(只查从发布页的壳做出来的包:壳带着 dm/shell_manifest.txt;Xcode 出的包没有它,不查)。壳清单里每一项都要由 d2rm_pack.py 做进来,
|
||||
// 缺 = 装的是没做过第一步的壳(或拼装的包)——起宿主会在装载器读 dm/main.fixups.tsv 处退出(线上闪退)。另比产物代号:打包记录 dm/pack_info.txt 与壳的
|
||||
// dm/shell_info.txt(两份都在才比,旧版打包工具不写打包记录)。不过就不起宿主,弹框说明缺什么、该做哪一步
|
||||
// Install package self-check (only for packages made from the shell on the releases page: the shell carries dm/shell_manifest.txt; packages built with Xcode do not have it and are not checked). Every item in the shell manifest must have been built in by d2rm_pack.py;
|
||||
// missing = the shell was installed without doing step 1 (or the package was assembled), and starting the host would exit where the loader reads dm/main.fixups.tsv (a crash for players). The product generation is also compared: the pack record dm/pack_info.txt against the shell's
|
||||
// dm/shell_info.txt (only when both exist; older pack tools did not write a pack record). If the check fails, do not start the host; show a message saying what is missing and which step to do
|
||||
static NSString *g_block_title, *g_block_msg, *g_block_why; // 非空 = 这台设备 / 这个安装包起不了游戏:不起宿主,场景里弹框(BlockVC)说明;why 进日志 | Non-empty = this device / this install package cannot start the game: do not start the host, show a message in the scene (BlockVC); why goes to the log
|
||||
static NSString *g_romfs; static char g_romfs_why[2048]; // 起宿主前那次资源校验的结果(host_start 写,boot_prepare 用) | Result of the resource check before starting the host (written by host_start, used by boot_prepare)
|
||||
static UIWindow *g_window;
|
||||
static NSString *kv_file(NSString *path, NSString *key) {
|
||||
NSString *t = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
|
||||
for (NSString *l in [t componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]) if ([l hasPrefix:[key stringByAppendingString:@"="]]) return [l substringFromIndex:key.length + 1];
|
||||
return nil;
|
||||
}
|
||||
static NSString *pack_check(void) {
|
||||
NSString *app = NSBundle.mainBundle.resourcePath; NSFileManager *fm = NSFileManager.defaultManager;
|
||||
// 只测试用:DM_TEST_PACK_MANIFEST=<文件,相对 Documents> 换一份壳清单、DM_TEST_PACK_INFO=<文件> 换一份打包记录(Xcode 包里没有壳信息时,同一文件的 SHELL_PRODUCT= 充当壳的代号;造「缺项」「代号不一致」现场,不动包内文件、不破签名)
|
||||
// Test only: DM_TEST_PACK_MANIFEST=<file, relative to Documents> substitutes the shell manifest and DM_TEST_PACK_INFO=<file> substitutes the pack record (in an Xcode package, which has no shell info, SHELL_PRODUCT= in the same file stands in for the shell's generation), to create "missing item" and "generation mismatch" cases without touching files in the package or breaking the signature
|
||||
NSString *(^tpath)(const char *) = ^NSString *(const char *e) { if (!e) return nil; NSString *p = @(e); return [p hasPrefix:@"/"] ? p : // 相对路径按 Documents 解析(沙盒读不到容器外;真机容器路径每次变) | Relative paths are resolved against Documents (the sandbox cannot read outside the container, and the device container path changes every time)
|
||||
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:p]; };
|
||||
NSString *tm = tpath(getenv("DM_TEST_PACK_MANIFEST")), *ti = tpath(getenv("DM_TEST_PACK_INFO"));
|
||||
NSString *man = [NSString stringWithContentsOfFile:tm ?: [app stringByAppendingPathComponent:@"dm/shell_manifest.txt"] encoding:NSUTF8StringEncoding error:nil];
|
||||
if (!man) { plog("boot: 安装包自检:没有壳清单(Xcode 出的包),不查"); return nil; }
|
||||
NSMutableArray<NSString *> *miss = [NSMutableArray array]; int total = 0;
|
||||
for (NSString *l in [man componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]) {
|
||||
NSString *m = [l stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet]; if (!m.length) continue; total++;
|
||||
BOOL dir = NO; if (![fm fileExistsAtPath:[app stringByAppendingPathComponent:m] isDirectory:&dir] || dir != [m hasSuffix:@"/"]) [miss addObject:m]; }
|
||||
if (miss.count) {
|
||||
plog("boot: 🔴 安装包自检:壳清单 %d 项缺 %lu 项:%s", total, (unsigned long)miss.count, [miss componentsJoinedByString:@", "].UTF8String);
|
||||
return [NSString stringWithFormat:T("dmPackBadMiss"), (int)miss.count, [[miss subarrayWithRange:NSMakeRange(0, MIN(miss.count, (NSUInteger)3))] componentsJoinedByString:@", "]]; }
|
||||
NSString *sp = kv_file([app stringByAppendingPathComponent:@"dm/shell_info.txt"], @"PRODUCT") ?: (ti ? kv_file(ti, @"SHELL_PRODUCT") : nil), *pp = kv_file(ti ?: [app stringByAppendingPathComponent:@"dm/pack_info.txt"], @"PRODUCT");
|
||||
if (sp && pp && ![sp isEqualToString:pp]) { plog("boot: 🔴 安装包自检:壳的产物代号 %s,打包记录 %s,不一致", sp.UTF8String, pp.UTF8String); return [NSString stringWithFormat:T("dmPackBadProd"), sp, pp]; }
|
||||
plog("boot: 安装包自检通过:壳清单 %d 项齐全;产物代号 壳 %s / 打包记录 %s", total, sp.UTF8String ?: "无", pp.UTF8String ?: "无(旧版打包工具)");
|
||||
return nil;
|
||||
}
|
||||
@interface BlockVC : UIViewController @end
|
||||
@implementation BlockVC
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
[super viewDidAppear:animated]; static int shown; if (shown++) return;
|
||||
UIAlertController *a = [UIAlertController alertControllerWithTitle:g_block_title message:g_block_msg preferredStyle:UIAlertControllerStyleAlert];
|
||||
[a addAction:[UIAlertAction actionWithTitle:T("dmOldQuit") style:UIAlertActionStyleCancel handler:^(UIAlertAction *x) { plog("boot: 玩家点了「退出」(%s)", g_block_why.UTF8String); exit(0); }]];
|
||||
[self presentViewController:a animated:YES completion:nil];
|
||||
plog("boot: 已弹框(%s)|屏上标题:%s|正文:%s", g_block_why.UTF8String, a.title.UTF8String, [a.message stringByReplacingOccurrencesOfString:@"\n" withString:@" ⏎ "].UTF8String);
|
||||
}
|
||||
@end
|
||||
@interface NoBcVC : UIViewController @property (strong) UILabel *label; @property (strong) UIProgressView *bar; @property (assign) BOOL shown; @end
|
||||
@implementation NoBcVC
|
||||
- (void)viewDidLoad {
|
||||
@@ -561,10 +615,10 @@ static void boot_prepare(void) {
|
||||
NSFileManager *fm = NSFileManager.defaultManager;
|
||||
[fm createDirectoryAtPath:romfs withIntermediateDirectories:YES attributes:nil error:nil];
|
||||
NSURL *romURL = [NSURL fileURLWithPath:romfs]; NSNumber *excluded = @YES; [romURL setResourceValue:excluded forKey:NSURLIsExcludedFromBackupKey error:nil];
|
||||
char romwhy[2048];
|
||||
NSString *found = romfs_locate(romwhy, sizeof romwhy);
|
||||
const char *romwhy = g_romfs_why;
|
||||
NSString *found = g_romfs; // host_start 起宿主前刚校验过(唯一一次);没过的不会走到这里 | host_start checked right before starting the host (the only time); failures never reach here
|
||||
if (!found) {
|
||||
plog("boot: 🔴 RomFS 校验失败:%s", romwhy);
|
||||
plog("boot: 🔴 RomFS 没经过起宿主前的校验(不应发生):%s", romwhy);
|
||||
plog("boot: 请推送原版 RomFS:xcrun devicectl device copy to --device <设备> --domain-type appDataContainer --domain-identifier <包名> --source $DM_ROOT/data/switch/3.3.94012/Update/RomFS --destination 'Library/Application Support/romfs'");
|
||||
abort();
|
||||
}
|
||||
@@ -685,6 +739,9 @@ static void log_promote(void) { // 场景第一次到前台:这一轮是玩
|
||||
static void host_start(void) {
|
||||
if (g_host_up) return;
|
||||
if (getenv("DM_TEST_BG_RELAUNCH")) return; // 这次启动只为造后台拉起(见 bg_relaunch_test),马上自己退出 | this launch exists only to stage a background relaunch (see bg_relaunch_test) and exits by itself right away
|
||||
{ NSString *r = romfs_locate(g_romfs_why, sizeof g_romfs_why); // 资源校验:起宿主前只在这里做一次(boot_prepare 用这次结果)。没过(启动判定之后资源被挪 / 删)就回资源界面,不闪退 | Resource check: done only once, here, before starting the host (boot_prepare uses this result). If it fails (resources moved / deleted after the launch decision), go back to the resources screen instead of crashing
|
||||
if (!r) { plog("boot: 起宿主前资源校验没过(%s),回到资源界面", g_romfs_why); if (g_window) astc_handoff(g_window); return; }
|
||||
g_romfs = r; }
|
||||
#ifdef DM_SHELL
|
||||
// 壳:着色器是以源码进包的话,进游戏之前先一次编完(dm_shader_prep.m,带进度页);做完它回头再调这里
|
||||
// Shell: if the shaders are shipped as source in the package, compile them all in one go before entering the game (dm_shader_prep.m, with a progress page); when done it calls back here
|
||||
@@ -1009,10 +1066,11 @@ static void astc_handoff(UIWindow *w) { // 补充包到位(玩家刚拷好 /
|
||||
@implementation SceneDelegate
|
||||
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)s options:(UISceneConnectionOptions *)o {
|
||||
UIWindowScene *ws = (UIWindowScene *)scene;
|
||||
self.window = [[UIWindow alloc] initWithWindowScene:ws];
|
||||
self.window = [[UIWindow alloc] initWithWindowScene:ws]; g_window = self.window;
|
||||
UIViewController *vc = [DmGameVC new];
|
||||
vc.view.backgroundColor = UIColor.blackColor;
|
||||
if ([g_mode isEqualToString:@"boot"] && g_no_bc) { vc = [NoBcVC new]; vc.view.backgroundColor = UIColor.blackColor; } // 本机型不支持:只弹框 | This device model is not supported: only show an alert
|
||||
if ([g_mode isEqualToString:@"boot"] && g_block_title) { vc = [BlockVC new]; vc.view.backgroundColor = UIColor.blackColor; } // 图形芯片不支持 / 安装包不完整:只弹框 | Graphics chip not supported / install package incomplete: only show the message
|
||||
else if ([g_mode isEqualToString:@"boot"] && g_no_bc) { vc = [NoBcVC new]; vc.view.backgroundColor = UIColor.blackColor; } // 本机型不支持:只弹框 | This device model is not supported: only show an alert
|
||||
else if ([g_mode isEqualToString:@"boot"] && g_need_assets) vc = [AssetVC new]; // 资源包没到:下载界面 | Asset pack not here yet: download screen
|
||||
else if ([g_mode isEqualToString:@"boot"]) vc.view = front_ios_view(ws.coordinateSpace.bounds); // 图形后端出图的层(不叠任何控件) | The layer the graphics backend presents into (no widgets stacked on it)
|
||||
else if ([g_mode isEqualToString:@"blank"]) { UIView *front_ios_blank_view(CGRect); vc.view = front_ios_blank_view(ws.coordinateSpace.bounds); } // 发热负对照 | Heat negative control
|
||||
@@ -1027,7 +1085,7 @@ static void astc_handoff(UIWindow *w) { // 补充包到位(玩家刚拷好 /
|
||||
}
|
||||
- (void)sceneWillResignActive:(UIScene *)s { if (g_host_up) front_ios_focus_event(0); }
|
||||
- (void)sceneDidEnterBackground:(UIScene *)s { if (g_host_up) front_ios_focus_event(1); }
|
||||
- (void)sceneWillEnterForeground:(UIScene *)s { log_promote(); if ([g_mode isEqualToString:@"boot"] && !g_need_assets && !g_no_bc) { host_start(); if (g_host_up) front_ios_focus_event(2); } }
|
||||
- (void)sceneWillEnterForeground:(UIScene *)s { log_promote(); if ([g_mode isEqualToString:@"boot"] && !g_need_assets && !g_no_bc && !g_block_title) { host_start(); if (g_host_up) front_ios_focus_event(2); } }
|
||||
- (void)sceneDidBecomeActive:(UIScene *)s { if (g_host_up) front_ios_focus_event(3); }
|
||||
// 场景断开 / App 终止:宿主有序收尾后 _exit(hle_lifecycle.c)。注意:用户在多任务界面划掉一个已在后台挂起的 App 时,系统直接 SIGKILL,不走这两个回调
|
||||
// Scene disconnect / App termination: the host shuts down in order, then _exit (hle_lifecycle.c). Note: when the user swipes away an App already suspended in the background from the multitasking screen, the system sends SIGKILL directly and neither of these two callbacks runs
|
||||
@@ -1171,13 +1229,23 @@ int main(int argc, char *argv[]) {
|
||||
metal_cache_report_and_clean();
|
||||
char why[2048];
|
||||
{ id<MTLDevice> dev = MTLCreateSystemDefaultDevice(); g_no_bc = !dev.supportsBCTextureCompression || getenv("DM_TEST_NO_BC");
|
||||
// 图形层要 Metal 3(参数缓冲里直接写 gpuAddress 的无绑定用法):A14 / M1(Apple7 家族)起才有,A13 及更早不支持。不支持就不起游戏、弹框说明(不再走到解包 / 建管线时闪退)。
|
||||
// 测试开关 DM_TEST_NO_METAL3=1 当成不支持
|
||||
// The graphics layer needs Metal 3 (bindless use that writes gpuAddress directly into argument buffers): available from A14 / M1 (the Apple7 family); A13 and earlier do not support it. If unsupported, do not start the game and show a message (instead of crashing later while unpacking / building pipelines).
|
||||
// Test switch DM_TEST_NO_METAL3=1 treats the device as unsupported
|
||||
if (![dev supportsFamily:MTLGPUFamilyMetal3] || getenv("DM_TEST_NO_METAL3")) {
|
||||
g_block_title = T("dmGpuOldTitle"); g_block_msg = T("dmGpuOldMsg"); g_block_why = @"图形芯片不支持 Metal 3";
|
||||
plog("boot: 🔴 显卡 %s 不支持 Metal 3%s——不起游戏,弹框说明", dev.name.UTF8String, getenv("DM_TEST_NO_METAL3") ? "(测试开关 DM_TEST_NO_METAL3)" : ""); }
|
||||
plog("boot: 显卡 %s,BC 压缩格式%s", dev.name.UTF8String, g_no_bc ? (getenv("DM_TEST_NO_BC") ? "按测试开关 DM_TEST_NO_BC 当成不支持" : "不支持——不起游戏,弹框说明后退出") : "支持"); }
|
||||
if (g_no_bc) { // 不支持 BC:有配套的老机型补充包就照常起(覆盖层换 ASTC 版,见 boot_prepare),没有就弹框 | BC not supported: if the matching Legacy Device Pack is present, start as usual (the overlay switches to the ASTC version, see boot_prepare); otherwise show an alert
|
||||
NSString *d = astc_pack_locate(g_astc_why, sizeof g_astc_why);
|
||||
if (d) { g_astc_dir = d; g_no_bc = 0; plog("boot: 用老机型补充包 %s", d.UTF8String); }
|
||||
else plog("boot: 老机型补充包未就绪:%s", g_astc_why);
|
||||
}
|
||||
if (g_no_bc) {}
|
||||
NSString *pb = g_block_title ? nil : pack_check();
|
||||
if (pb) { g_block_title = T("dmPackBadTitle"); g_block_msg = [NSString stringWithFormat:@"%@\n\n%@", pb, T("dmPackBadHow")]; g_block_why = @"安装包自检没过"; }
|
||||
if (g_block_title) {} // 起不了游戏:不起宿主,场景里弹框(BlockVC) | The game cannot start: do not start the host; show a message in the scene (BlockVC)
|
||||
else if (g_no_bc) {}
|
||||
else if (getenv("DM_ASSETS_TEST") || getenv("DM_TEST_BA")) { g_need_assets = 1; plog("boot: DM_ASSETS_TEST——强制走资源下载界面再就地起宿主(测这条路径)"); }
|
||||
else if (romfs_locate(why, sizeof why)) plog("boot: 游戏资源就绪,宿主等场景到前台再装载");
|
||||
else { g_need_assets = 1; plog("boot: 游戏资源还没到(%s),先显示资源下载界面", why); }
|
||||
|
||||
Reference in New Issue
Block a user