diff --git a/README.en.md b/README.en.md index d4688e36..a0168a6a 100644 --- a/README.en.md +++ b/README.en.md @@ -218,6 +218,9 @@ On Apple Silicon macOS, downloads and imports use Android 15 Google Play `arm64- - The disk is `/data/local/tmp/modavd-dldisk//dl.img` in the guest, a sparse file of at most 16 GB; space of deleted packages goes back to the data disk. Downloading is faster than unpacking, so finished packages queue up on the disk: during a full resource download the data disk's peak use is about 6 GB higher than before. No disk is made when the data disk has less than 2 GB free. - The list holds Arknights, official `com.hypergryph.arknights` and bilibili `com.hypergryph.arknights.bilibili` (not tested on the latter; the folder is the same), and Arknights: Endfield `com.hypergryph.endfield` (same downloader, same folder and write pattern). - Boot with the environment variable `MODAVD_DL_DISK=off` to move unfinished downloads back into the plain folder, delete the disk and start no watcher. +- Arknights' resource index and manifests (official and bilibili) are watched (guest script `modavd-reswatch.sh`, Windows only, read-only), to find out why the game now and then downloads all its resources again (ModAVD/ModAVD#89). + - A watcher looks at `*.idx`, `hot_update_list.json` and `persistent_res_list.json` in `Bundles` every 3 seconds and logs a line to the guest log only when one changed (size, modification time, md5); when the game reports a resource load error, it logs at once what those files look like in each storage view, the memory state and the kernel log. Problem reports carry the guest log. + - Nothing is written into the game's folders, and the log is not read while neither game is installed. Boot with the environment variable `MODAVD_RES_WATCH=off` to stop it and start none. - Honkai: Star Rail (official `com.miHoYo.hkrpg` and bilibili `com.miHoYo.hkrpg.bilibili`, not tested on the latter) gets its display mode set to Vulkan in advance (guest script `modavd-vkmode.sh`, Windows only). At its first start the game picks OpenGL ES on its own and closes on ModAVD about fifteen seconds later; in Vulkan mode (Normal Mode under Settings > Graphics > Display Settings in the game) it runs. - A watcher looks every 3 seconds: once the game is installed, before its first start, it writes `vulkancaps.bin` and `customvulkancaps.bin` in the game's `Android/data//files`. A game already stuck in OpenGL ES after such a crash is switched to Vulkan as well, at the next boot or once it has exited. - A display mode chosen in the game's settings (`customvulkancaps.bin` is there and not empty) is left alone; so is a running game; no folder is made for a game that is not installed. diff --git a/README.md b/README.md index c7dffff8..c25bcf65 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,9 @@ Apple Silicon macOS 的下载与导入使用 Android 15 Google Play `arm64-v8a` - 盘是客体里的 `/data/local/tmp/modavd-dldisk/<包名>/dl.img`,一个最大 16 GB 的稀疏文件,删掉的包占的空间会还给数据盘。下载比解压快,下好的包会先堆在盘里:下整包资源时,数据盘的占用高峰比以前多约 6 GB。数据盘剩余不到 2 GB 时不建盘。 - 名单里是明日方舟官服 `com.hypergryph.arknights`、B 服 `com.hypergryph.arknights.bilibili`(B 服没有实测,目录相同),以及明日方舟:终末地 `com.hypergryph.endfield`(同一套下载器,目录和写法相同)。 - 设环境变量 `MODAVD_DL_DISK=off` 再开机:把盘里还没下完的搬回普通目录,删掉盘,不再起守护。 +- 明日方舟(官服、B 服)的资源索引和清单有人盯着(客体脚本 `modavd-reswatch.sh`,只在 Windows 上,只读),用来查偶尔整包重下的原因(ModAVD/ModAVD#89)。 + - 守护每 3 秒看一次 `Bundles` 里的 `*.idx`、`hot_update_list.json`、`persistent_res_list.json`,文件变了才往客体日志记一行大小、修改时间和 md5;游戏报资源加载失败时,当场记下这些文件在几处存储视图里的状态、内存和内核日志。问题包带着客体日志。 + - 不往游戏目录写任何东西;没装这两个游戏时不读日志。设环境变量 `MODAVD_RES_WATCH=off` 再开机就停掉、不再起。 - 崩坏:星穹铁道(官服 `com.miHoYo.hkrpg`、B 服 `com.miHoYo.hkrpg.bilibili`,B 服没有实测)的显示模式预先设成 Vulkan(客体脚本 `modavd-vkmode.sh`,只在 Windows 上)。游戏第一次启动时自己选 OpenGL ES,在 ModAVD 上十几秒后闪退;在游戏设置里的显示设置(Display Settings)选 Vulkan 模式就正常。 - 守护每 3 秒看一次:游戏装上以后、第一次启动之前,在它的 `Android/data/<包名>/files` 里写好 `vulkancaps.bin`、`customvulkancaps.bin`。已经因为闪退停在 OpenGL ES 的,下次开机或游戏退出后也改成 Vulkan。 - 在游戏设置里选过显示模式的(`customvulkancaps.bin` 已经在、不是空文件)不动;游戏开着时不动;没装的游戏不建任何目录。 diff --git a/changelog.d/89-reswatch.feat.md b/changelog.d/89-reswatch.feat.md new file mode 100644 index 00000000..f82168ea --- /dev/null +++ b/changelog.d/89-reswatch.feat.md @@ -0,0 +1,2 @@ +问题包记下明日方舟每次启动的结果、资源出错当场的文件状态和内核日志、关机时是否在下载 (ModAVD/ModAVD#89) +Problem reports log each Arknights start, its resource file state at a load error, the kernel log, downloads at shutdown diff --git a/internal/emu/afterboot.go b/internal/emu/afterboot.go index 2b360d9a..21cc3a18 100644 --- a/internal/emu/afterboot.go +++ b/internal/emu/afterboot.go @@ -260,6 +260,10 @@ func (m *Manager) afterBoot(ctx context.Context, inst *avd.Instance, mode bootSe // 12) download disks (dldisk.go). After the guest library fixes (0a): the framework restart there remounts the // shared storage, and a disk mounted on it before would be gone with it func() { m.setupDownloadDisk(ctx, i) }, + // 12a) Arknights' resource files watched, and what they hold when the game cannot load them (reswatch.go, + // ModAVD/ModAVD#89). Also after 0a: a scene compares /data/media with the FUSE view, which the framework + // restart there mounts anew. Every mode, an adopted instance too: the script starts no second watcher + func() { m.setupResWatch(ctx, i) }, // 12b) listed games that have not chosen a display mode start in Vulkan (vkmode.go, ModAVD#222) func() { m.setupVulkanMode(ctx, i) }, // 13) the guest's clock source into the log, its kernel log's clock lines saved when an x86_64 guest is not on diff --git a/internal/emu/manager.go b/internal/emu/manager.go index 4a114803..408faeaa 100644 --- a/internal/emu/manager.go +++ b/internal/emu/manager.go @@ -47,6 +47,8 @@ const ( // the sync leaves of the 4 s, at least 1 s) + terminate wait 1 => 4 + 2 + 2 + 2 + 14 + 2 + 1 + 1 = 28 // (fallbackKillTimeout); // private adb unusable: 4 + console kill 3 + exit wait 12 + terminate wait 5 = 24; Force: 4 + sync 3 + 5 = 12. + // Between prepare and HOME the graceful path records what it needs for ModAVD/ModAVD#89 (stop_record.go), within + // what prepare left of those 4 s minus 1 s (beforeShutdownBudget), so the 14 s for Android and these sums stand. adbServerStartOnClose = 4 * time.Second homeTimeout = 2 * time.Second shutdownSyncTimeout = 2 * time.Second diff --git a/internal/emu/reswatch.go b/internal/emu/reswatch.go new file mode 100644 index 00000000..15bcdb59 --- /dev/null +++ b/internal/emu/reswatch.go @@ -0,0 +1,96 @@ +package emu + +import ( + "context" + "fmt" + "os" + "strings" + "time" + + "modavd/internal/guest" + "modavd/internal/root" +) + +// The resource file watch (guest.ResWatch, ModAVD/ModAVD#89). Now and then Arknights fails right after START on its +// title page ("[ResourceManager] Init failed"), takes its local resources for invalid and downloads all of them again +// at the next start. The cause is unknown; what decides between the emulator's storage and the game is what the game +// read at that moment. A guest watcher logs every change of the game's resource index and manifests (size, mtime, +// md5), and on the game's error what those files hold in each view of the storage, against the last pass, plus the +// memory state and the kernel log: all in logcat, which the problem report carries. Read-only; the script's header has +// the details. +// +// On by default: it is for the user's machine, where the failure happens and where nobody would turn on a switch +// beforehand. Windows only so far, like the download disk next to it. + +// envResWatch set to "off" stops the watcher and starts none. +const envResWatch = "MODAVD_RES_WATCH" + +// resWatchTimeout: daemon only starts the two loops in the background and waits up to a second for them (the +// baseline pass with its md5s runs in the watcher, not here). +const resWatchTimeout = 20 * time.Second + +// setupResWatch starts the watcher and the logcat reader of the resource files, unless they run already (an adopted +// instance: the script starts at most one of each). +func (m *Manager) setupResWatch(ctx context.Context, i int) { + if !root.CurrentPlatform().Windows() { + return + } + remote, ok := m.pushGuestScript(ctx, i, guest.ResWatch) + if !ok { + return + } + if strings.EqualFold(strings.TrimSpace(os.Getenv(envResWatch)), "off") { + m.shell(ctx, i, "su 0 sh "+remote+" off", resWatchTimeout) + m.Log.Infof("实例 %d 资源文件监视: 已按 %s=off 关闭", i, envResWatch) + return + } + started := m.shell(ctx, i, "su 0 sh "+remote+" daemon", resWatchTimeout).Out + status := m.shell(ctx, i, "su 0 sh "+remote+" status", 0).Out + if warn, msg := resWatchReport(i, started, status); warn { + m.Log.Warnf("%s", msg) + } else { + m.Log.Infof("%s", msg) + } +} + +// resWatchReport judges `modavd-reswatch.sh daemon` + `status`: running when both the pass loop and the logcat loop +// list a pid. The message names the listed games that are installed and what the script says about each. +func resWatchReport(i int, started, status string) (warn bool, msg string) { + lines := parseStatusLines(status) + if lines["watchers"] == "" || lines["errwatch"] == "" { + return true, fmt.Sprintf("实例 %d 资源文件监视没起来: %s", i, tail(strings.TrimSpace(started)+" / "+status, 300)) + } + var games []string + for _, line := range outputLines(status) { + pkg, state, ok := strings.Cut(line, ":") + state = strings.TrimSpace(state) + if !ok || pkg == "watchers" || pkg == "errwatch" || state == "" || state == "not installed" { + continue + } + games = append(games, pkg+"("+resWatchState(state)+")") + } + if len(games) == 0 { + return false, fmt.Sprintf("实例 %d 资源文件监视: 守护已起(pid %s,读日志 pid %s),名单里的游戏都没装", i, + lines["watchers"], lines["errwatch"]) + } + return false, fmt.Sprintf("实例 %d 资源文件监视: 守护已起(pid %s,读日志 pid %s);%s", i, lines["watchers"], + lines["errwatch"], strings.Join(games, ",")) +} + +// resWatchState puts the script's status of a package into the log's language: "not scanned yet", or "watching N +// files, M missing" with "; last scene at