No-Xcode route: older devices (A16 and earlier) are supported - give the packaging tool a Legacy Device Pack with D2RM_ASTC_PACK
This commit is contained in:
+19
-3
@@ -6,6 +6,7 @@
|
||||
# 用法:d2rm_pack.py <壳.ipa> <游戏文件目录> <输出.ipa>
|
||||
# 游戏文件目录 = Switch 版 3.3.94012 的 Update 目录,里面有 ExeFS/{main,sdk} 与 RomFS/data/…(怎么从自己的游戏导出)
|
||||
# 工作目录(缓存与中间产物,约 12 GB):环境变量 DM_ROOT,缺省 ~/dm-work;每一步做过就跳过
|
||||
# 老机型(A16 及更早的芯片):先做好贴图包,再带环境变量 D2RM_ASTC_PACK=<贴图包的 pack 目录> 运行本工具
|
||||
# 需要:Python 3.9+ 与 pillow numpy lz4 capstone unicorn;C 编译器(clang 或 gcc,解贴图的小段 C 用);.NET SDK(编着色器翻译工具);
|
||||
# spirv-cross;苹果的 Metal 着色器编译器(Mac 上随 Xcode)。缺什么本工具开头会逐项报。
|
||||
# 它做的事与「./setup.sh + dm/ios/run.sh build 的生成部分」相同,只是最后不调 Xcode 构建,而是把产物放进壳里。
|
||||
@@ -16,6 +17,7 @@
|
||||
# Usage: d2rm_pack.py <shell.ipa> <game files directory> <output.ipa>
|
||||
# game files directory = the Update directory of Switch version 3.3.94012, containing ExeFS/{main,sdk} and RomFS/data/... (how to export it from your own game)
|
||||
# working directory (cache and intermediate outputs, about 12 GB): environment variable DM_ROOT, default ~/dm-work; every step already done is skipped
|
||||
# Older devices (A16 and earlier chips): make the texture pack first, then run this tool with the environment variable D2RM_ASTC_PACK=<the pack directory of the texture pack>
|
||||
# Requires: Python 3.9+ with pillow numpy lz4 capstone unicorn; a C compiler (clang or gcc, for the small piece of C that decodes textures); the .NET SDK (to build the shader translation tool);
|
||||
# spirv-cross; Apple's Metal shader compiler (on a Mac it comes with Xcode). This tool reports whatever is missing item by item at the start.
|
||||
# What it does is the same as "./setup.sh + the generation part of dm/ios/run.sh build", except that at the end it does not invoke an Xcode build but puts the build outputs into the shell.
|
||||
@@ -154,8 +156,22 @@ def main():
|
||||
# 三、覆盖层
|
||||
# 3. Overlay
|
||||
say('生成覆盖层')
|
||||
run([PY, os.path.join(IOS, 'tools', 'gen_romfs_overlay.py'), romfs, os.path.join(stage, 'romfs_overlay')], cwd=IOS, env={'DM_ROMFS_SRC': romfs}, log=os.path.join(stage, 'gen_overlay.log'), what='生成覆盖层')
|
||||
for d in ('romfs_overlay_astc', 'romfs_overlay_astc_variants'): shutil.rmtree(os.path.join(stage, d), ignore_errors=True)
|
||||
# 老机型(显卡不支持 BC 贴图的 A16 及更早芯片):D2RM_ASTC_PACK=<贴图包目录>(astc_pack.py + casc_overlay.py pack + astc_pack.py finalize 的产物,里面有 pack_index.tsv 与 pack.json)
|
||||
# 给了就再出一套 ASTC 版覆盖层放进安装包(索引里那两万多张贴图指向贴图包的数据档,内容不进安装包;App 按其中的 pack.json 核对手机上的贴图包)。
|
||||
# 它是从游戏资源现生成的,壳里不带;贴图包本身由使用者拷进手机。没给就不带,老机型上 App 会说明缺这一步
|
||||
# Older devices (A16 and earlier chips, whose GPU does not support BC textures): D2RM_ASTC_PACK=<texture pack directory> (the output of astc_pack.py + casc_overlay.py pack + astc_pack.py finalize, containing pack_index.tsv and pack.json)
|
||||
# When given, an additional ASTC overlay is produced and put into the install package (its index points the twenty-odd thousand textures at the data archive of the texture pack, whose content does not go into the install package; the App checks the pack on the phone against the pack.json in it).
|
||||
# It is generated on the spot from the game resources and is not carried in the shell; the texture pack itself is copied to the phone by the user. When not given it is left out, and on older devices the App explains that this step is missing
|
||||
astc = os.environ.get('D2RM_ASTC_PACK', '').strip(); astc = os.path.abspath(astc) if astc else ''
|
||||
if astc and not all(os.path.isfile(os.path.join(astc, f)) for f in ('pack_index.tsv', 'pack.json')): die('D2RM_ASTC_PACK 指的目录里没有 pack_index.tsv / pack.json:%s(要的是贴图包三步做完后的那个 pack 目录)' % astc)
|
||||
run([PY, os.path.join(IOS, 'tools', 'gen_romfs_overlay.py'), romfs, os.path.join(stage, 'romfs_overlay')], cwd=IOS, env={'DM_ROMFS_SRC': romfs, 'DM_ASTC_PACK': astc}, log=os.path.join(stage, 'gen_overlay.log'), what='生成覆盖层')
|
||||
extra = []
|
||||
if astc:
|
||||
if not os.path.isfile(os.path.join(stage, 'romfs_overlay_astc', 'pack.json')): die('老机型的覆盖层没生成出来(见 %s)' % os.path.join(stage, 'gen_overlay.log'))
|
||||
extra = ['romfs_overlay_astc/', 'romfs_overlay_astc_variants/']; pj = json.load(open(os.path.join(astc, 'pack.json'), encoding='utf-8'))
|
||||
say('带老机型支持:贴图包 %s(%.2f GB,SHA-256 %s…);装机后把它里面给手机用的那个文件夹(收尾那一步生成的)拷进手机' % (astc, pj['size'] / 1e9, pj['sha256'][:12]))
|
||||
else:
|
||||
for d in ('romfs_overlay_astc', 'romfs_overlay_astc_variants'): shutil.rmtree(os.path.join(stage, d), ignore_errors=True)
|
||||
|
||||
# 四、着色器:取包 → 翻译工具 → 翻译并编成 Metal 库(与 setup.sh 相同)
|
||||
# 4. Shaders: extract the shader packs from the game resources → translation tool → translate and compile into Metal libraries (same as setup.sh)
|
||||
@@ -228,7 +244,7 @@ def main():
|
||||
tmp = out_ipa + '.part'; added = 0
|
||||
with zipfile.ZipFile(tmp, 'w', zipfile.ZIP_DEFLATED, compresslevel=6) as o:
|
||||
for i in z.infolist(): o.writestr(i, z.read(i.filename))
|
||||
for m in manifest:
|
||||
for m in manifest + extra:
|
||||
src = os.path.join(stage, m)
|
||||
files = [os.path.join(d, f) for d, _, fs in sorted(os.walk(src)) for f in sorted(fs)] if m.endswith('/') else [src]
|
||||
for f in files:
|
||||
|
||||
@@ -62,7 +62,7 @@ Afterwards `$D/pack` contains:
|
||||
- **The pack and the App are a matched pair.** The App checks the pack on the phone against the SHA-256 in `pack.json`; if you regenerate the pack, rebuild the App with the new `$D/pack`. The same game files, the same astcenc version and the same preset (`--preset thorough`) produce a byte-identical pack, so normally there is nothing to redo.
|
||||
- If the folder was not copied completely, is in the wrong place, or does not match the App, the App says which it is in the dialog.
|
||||
- The game resource folder is still needed as usual (see [GAME_FILES.md](GAME_FILES.md)); the pack is an additional folder, not a replacement.
|
||||
- This route currently needs a Mac and Xcode. The no-Xcode shell does not carry the older-device part in this version yet.
|
||||
- The above describes the "with a Mac" route. On the no-Xcode route (shell plus packaging tool) the three commands that make the pack are the same and only the way it goes into the install package differs; see the "Older devices" section of [NO_XCODE.md](NO_XCODE.md). On Windows the prebuilt astcenc executable from the upstream release page is all you need.
|
||||
|
||||
## What it does (if you are curious)
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ python3 dm/tools/astc_pack.py finalize "$D/pack" # 3 收尾:
|
||||
- **贴图包和 App 是配对的**。App 按 `pack.json` 里的 SHA-256 核对手机上的贴图包;重新生成过贴图包,就要用新的 `$D/pack` 重新构建 App。同一份游戏文件、同一版 astcenc、同一档(`--preset thorough`)生成的包是逐字节相同的,所以平时不需要重做。
|
||||
- 文件夹没拷完、拷错了位置、或者和 App 不配套,App 会在弹框里直接说是哪一种。
|
||||
- 游戏资源文件夹照常要放(见 [GAME_FILES.zh-CN.md](GAME_FILES.zh-CN.md));贴图包是另外加的一个文件夹,不是替换。
|
||||
- 这条路目前要用 Mac 和 Xcode 构建。「不用 Xcode」的壳这一版还不带老机型的配套部分。
|
||||
- 上面写的是「有 Mac」那条路。不用 Xcode、走壳加做包工具的,做贴图包的三条命令相同,带进安装包的方式不同,见 [NO_XCODE.zh-CN.md](NO_XCODE.zh-CN.md) 里「老机型」一节;Windows 上 astcenc 用上游发布页的现成可执行文件即可。
|
||||
|
||||
## 它做了什么(想了解的话)
|
||||
|
||||
|
||||
@@ -70,6 +70,24 @@ With a package made on a computer without that compiler, the app stops on a "Fir
|
||||
- You can switch away or close the app; when you come back it counts from the start again, but each shader already compiled takes less than a millisecond, so in effect it continues.
|
||||
- The phone gets warm during these minutes; keeping it plugged in and out of a thick case helps.
|
||||
|
||||
## Older devices (A16 and earlier chips)
|
||||
|
||||
The iPhone 14 family, iPhone 15 / 15 Plus and earlier models need an extra texture pack, passed in at step 1. The full explanation is in [LEGACY_DEVICES.md](LEGACY_DEVICES.md); on this route it goes like this:
|
||||
|
||||
1. Get the astcenc encoder: download the archive for your system from the upstream release page and unpack it (<https://github.com/ARM-software/astc-encoder/releases>; on Windows use `bin/astcenc-avx2.exe` from `astcenc-…-windows-x64.zip`).
|
||||
2. Make the texture pack (three commands; `<game files directory>` as above, `D` is an output directory of your choice):
|
||||
|
||||
```
|
||||
python3 dm/tools/astc_pack.py <game files directory>/RomFS D/work --astcenc <path to astcenc> --preset thorough
|
||||
python3 dm/tools/casc_overlay.py pack <game files directory>/RomFS D/pack D/work/repl.tsv 0-8
|
||||
python3 dm/tools/astc_pack.py finalize D/pack
|
||||
```
|
||||
|
||||
3. Pass it when packaging: set the environment variable `D2RM_ASTC_PACK` to the full path of `D/pack`, then run `d2rm_pack.py` as in step 1. The tool prints a line saying older-device support is included.
|
||||
4. When you put the game resources on the phone in step 3, also copy the whole `D/pack/Legacy Device Pack` folder to the phone, at the same level as the game resource folder.
|
||||
|
||||
The texture pack and the install package are a matched pair: if you remake the pack, remake the package.
|
||||
|
||||
## When something goes wrong
|
||||
|
||||
- The tool says the shell and this source are not the same version: use the source of the same release as the shell.
|
||||
|
||||
@@ -70,6 +70,24 @@ python3 dm/tools/d2rm_pack.py <D2RMobile-shell.ipa> <你的游戏文件目录> <
|
||||
- 可以切到后台或关掉;回来从头数一遍,已经编过的每个只要不到一毫秒,等于接着做。
|
||||
- 这几分钟手机会发热,建议插着电、别套太厚的壳。
|
||||
|
||||
## 老机型(A16 及更早的芯片)
|
||||
|
||||
iPhone 14 系列、iPhone 15 / 15 Plus 以及更早的机型,要多做一份贴图包,并在第一步里带上它。完整说明见 [LEGACY_DEVICES.zh-CN.md](LEGACY_DEVICES.zh-CN.md),这条路上的做法是:
|
||||
|
||||
1. 准备编码器 astcenc:从上游发布页下载对应系统的压缩包解开即可(<https://github.com/ARM-software/astc-encoder/releases>,Windows 用 `astcenc-…-windows-x64.zip` 里的 `bin/astcenc-avx2.exe`)。
|
||||
2. 做贴图包(三条命令,`<游戏文件目录>` 同上,`D` 是你选的输出目录):
|
||||
|
||||
```
|
||||
python3 dm/tools/astc_pack.py <游戏文件目录>/RomFS D/work --astcenc <astcenc 的路径> --preset thorough
|
||||
python3 dm/tools/casc_overlay.py pack <游戏文件目录>/RomFS D/pack D/work/repl.tsv 0-8
|
||||
python3 dm/tools/astc_pack.py finalize D/pack
|
||||
```
|
||||
|
||||
3. 做包时带上它:把环境变量 `D2RM_ASTC_PACK` 设成 `D/pack` 的完整路径,再照第一步运行 `d2rm_pack.py`。工具会说一句「带老机型支持」。
|
||||
4. 第三步放游戏资源时,把 `D/pack/Legacy Device Pack` 这个文件夹也整个拷进手机,和游戏资源文件夹放在同一层。
|
||||
|
||||
贴图包和安装包是配对的:重新做了贴图包,就要重新做包。
|
||||
|
||||
## 出了问题
|
||||
|
||||
- 工具报「壳与这份源码不是同一版」:换成与壳同一个发布版本的源码。
|
||||
|
||||
Reference in New Issue
Block a user