mirror of
https://github.com/jhaizhou-ops/d2r-mobile
synced 2026-11-26 13:57:52 +08:00
- Android (#113, @yyan160; graphics engine and shader-bundle packer from @biglawine's HarmonyOS port): an Android app (dm/android) with a JNI host, a touch overlay on the shared touch state machine, Vulkan presentation and AAudio sound; an NVN-to-Vulkan replay engine (dm/gfx/vulkan) behind the same backend interface as Metal; the shared host now builds for Apple and Android, and the module rewriter has an Android target (DM_TARGET=android; Apple output unchanged). Measured by the authors at a median 60 fps on a Redmi K50 Ultra. - Android install with your own game files: the release APK (dm/android/tools/shell_apk.sh) contains no game content; dm/tools/d2rm_android.py makes an import pack (rewritten program, Vulkan shader bundles, touch overlay, data tables) that the App imports from Download/S2X/D2R Mobile/android with a progress screen. The shader export step (dm/gfx/tools/dmsh_vk.py) makes the 6,927 game shader bundles byte-for-byte identical to the tested set. - Android rewriter fix (#113, @yyan160): rewrite blocks no longer stash registers below sp (Android has no red zone); equiv.py checks Android outputs, structck.py recognizes the Android block shapes. Apple output unchanged. - Android touch controls drawn as on iOS (sockets, silver skill silhouettes, joystick), no map key in game state, no virtual pad buttons over panels; dm/android/tools/art_compare.sh compares the two drawings pixel by pixel. - HarmonyOS (#114, @biglawine): a HarmonyOS NEXT app (dm/harmony, ArkTS shell + N-API library) on the same shared host and Vulkan engine as Android; shared changes are behind __OHOS__ or opt-in switches (adaptive present tier, fence waits woken on completion, OHAudio, HiTrace markers, a byte-identical BC fast path). - HarmonyOS install with your own game files (@biglawine, 0.19.4 / code122): the release HAP is unsigned and contains no game content; players re-sign it with their own debug certificate and import a pack made with dm/tools/d2rm_android.py --target ohos. The registering stand-ins read the tables only when dm_derived_reload() is called (on __OHOS__); first import creates the target folders; outside a game a map toggle request is dropped before the AutoMap exists. Run by the author on a Mate 90 Pro Max: re-sign, install, import, in game, save and exit. - Vulkan: NaN-ignoring min / max / clamp as on Maxwell (#113, @yyan160), fixing one-frame black tiles on the OnePlus 13. - Xbox controllers (from #110, @rrroy5640): recognized automatically and given the PC / Xbox layout (bottom confirms, right goes back) with the game's Xbox button icons; other controllers are unchanged. The Mac-only keyboard prompt switch became a three-way prompt style (Switch / keyboard / Xbox) on every platform. - Separate base and update packages (#106, @PowerBeef): setup.sh and extract_game.sh take both packages and read the title keys from their tickets. - Mac App (#108, #109, @PowerBeef): the project's icon by default; the pointer hides after resting 3 s. - run.sh install no longer goes through the test-device battery gate (#107, @PowerBeef). - Chinese wording (#101, @zzz6519003): 「旧接口版」 and 「默认构建」 throughout. - Dynamic 3D resolution (from #113): a run of dropped frames counts only its first 3 frames unless it lasts 1 s, so one-off stalls no longer lower the resolution. - In-game Korean (#118, @soulsakura): a 한국어 column for all our UI text, a fifth option in the language row (each checkbox now sits before its name), Korean touch wording and map name plates, Korean voice when the game files carry it; a Korean system language picks Korean on first install. - iPhone Duo: in full screen the output size follows the window when the phone is unfolded or folded, up to the size the game started with; needs Xcode 27.1 for the inner screen to be filled. Test switches DM_TEST_FOLD and DM_TEST_SCREEN simulate the two screens with the iOS package on a Mac. - README: Android and HarmonyOS sections, device table and credits in all three languages; dependency list for Android. Every change was ported into the internal tree with its authors credited. For the shared files, the code changes match the pull requests' after stripping comments. Host / graphics / iOS unit tests, the full acceptance gate and the Mac smoke test passed; the rewriter's rule sets were rebuilt and passed the equivalence regression; an iOS build of this code was played on an iPhone; the Android APK with an import pack made from our own game files was played on a vivo X200 Ultra. Exported from main 8055e5212. Co-authored-by: Yuechuan Yang <22333122+yyan160@users.noreply.github.com> Co-authored-by: biglawine <26263820+biglawine@users.noreply.github.com> Co-authored-by: rrroy <hly5640@gmail.com> Co-authored-by: Patrice Déry <109446870+PowerBeef@users.noreply.github.com> Co-authored-by: Sam Snowman(赵正中) <zhengzhongzhao@gmail.com> Co-authored-by: soulsakura <74704744+soulsakura@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
5.6 KiB
C
55 lines
5.6 KiB
C
// 壳(不含任何游戏内容的 App)里,从游戏文件生成的几张表不编进代码,运行时从安装包里的 dm/derived.tsv 读。
|
|
// 这个文件只被壳构建时生成的替身文件包含(ios/tools/shell_stubs.py 写出的 dm_hud_exp.h、dm_vault_tab.h、dm_touch_native_art.c),
|
|
// 内测 / 自己用 Xcode 构建的包不走这里:它们的三份生成文件里是真实数据。
|
|
// 安卓的发布包同理(dm/android/tools/shell_apk.sh):表在导入的 files/dm/derived.tsv,路径由 DmActivity 在加载原生库之前放进环境变量 DM_DERIVED。
|
|
// 鸿蒙也读 DM_DERIVED,但原生库随 ArkTS 静态导入一加载就跑构造函数,那时路径还没设、导入包可能还没导入:替身在构造函数里只登记读表函数,
|
|
// 由平台层设好路径后调 dm_derived_reload() 显式读;读不全返回 -1、不记成已读,可以重试(导入完再调一次)。苹果 / 安卓仍在登记时当场读,行为不变。
|
|
// derived.tsv 由使用者自己的游戏文件生成(dm/tools/d2rm_pack.py):每行「标签<TAB>字段<TAB>…」,UTF-8,字段里没有制表符与换行。
|
|
// In the shell (an App with no game content), the few tables generated from the game files are not compiled in; they are read at run time from dm/derived.tsv in the install package.
|
|
// Only the stand-in files generated when building the shell include this file (dm_hud_exp.h, dm_vault_tab.h, dm_touch_native_art.c written by ios/tools/shell_stubs.py);
|
|
// test builds and packages you build yourself with Xcode do not come here: their three generated files hold the real data.
|
|
// The Android release APK works the same way (dm/android/tools/shell_apk.sh): the tables are in the imported files/dm/derived.tsv, whose path DmActivity puts in the environment variable DM_DERIVED before loading the native library.
|
|
// HarmonyOS reads DM_DERIVED too, but the native library is loaded by the static ArkTS import and runs its constructors right away, before the path is set and possibly before the import pack is imported: there the stand-ins' constructors only register their loaders,
|
|
// and the platform layer calls dm_derived_reload() once the path is set; an incomplete read returns -1 and is not remembered as done, so it can be retried (call it again after importing). Apple / Android still read when registering, unchanged.
|
|
// derived.tsv is generated from the user's own game files (dm/tools/d2rm_pack.py): each line is "tag<TAB>field<TAB>...", UTF-8, with no tabs or newlines inside fields.
|
|
#pragma once
|
|
#if !defined(__ANDROID__) && !defined(__OHOS__)
|
|
#include <mach-o/dyld.h>
|
|
#endif
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
// 对每一行标签为 tag 的记录调一次 cb(f[0..n) 是各字段,指向本函数持有的行缓冲;要留着的字符串自己 strdup)。返回这种记录的条数,读不到文件 = -1
|
|
// Calls cb once for every record line whose tag is tag (f[0..n) are the fields, pointing into the line buffer owned by this function; strdup any strings you want to keep). Returns the number of records of this kind; file cannot be read = -1
|
|
static inline int dm_derived_each(const char *tag, void (*cb)(char **f, int n, void *ctx), void *ctx) {
|
|
#if defined(__ANDROID__) || defined(__OHOS__)
|
|
const char *p = getenv("DM_DERIVED"); if (!p) { fprintf(stderr, "[dm] 【红】没有设 DM_DERIVED\n"); return -1; }
|
|
FILE *fp = fopen(p, "r"); if (!fp) { fprintf(stderr, "[dm] 【红】没有 %s:还没导入用游戏文件做的导入包\n", p); return -1; }
|
|
#else
|
|
char p[4096]; uint32_t sz = sizeof p; if (_NSGetExecutablePath(p, &sz)) return -1;
|
|
char *sl = strrchr(p, '/'); if (!sl || (size_t)(sl - p) + 24 > sizeof p) return -1; strcpy(sl, "/dm/derived.tsv");
|
|
FILE *fp = fopen(p, "r"); if (!fp) { fprintf(stderr, "[dm] 【红】安装包里没有 dm/derived.tsv(%s):这个包没有用游戏文件做全\n", p); return -1; }
|
|
#endif
|
|
static char ln[8192]; int cnt = 0; size_t tl = strlen(tag);
|
|
while (fgets(ln, sizeof ln, fp)) { size_t l = strlen(ln); while (l && (ln[l - 1] == '\n' || ln[l - 1] == '\r')) ln[--l] = 0;
|
|
if (strncmp(ln, tag, tl) || ln[tl] != '\t') continue;
|
|
char *f[16]; int n = 0; for (char *q = ln + tl + 1; n < 16; ) { f[n++] = q; q = strchr(q, '\t'); if (!q) break; *q++ = 0; }
|
|
cb(f, n, ctx); cnt++; }
|
|
fclose(fp); return cnt;
|
|
}
|
|
// 读表函数登记表:三份替身各登记一个(读全返回 0,否则 -1)。弱定义,三个编译单元里的同名定义链接时合成一份;没有替身的构建里没人登记
|
|
// Loader registry: each of the three stand-ins registers one (0 when complete, otherwise -1). Weak definitions, so the same-named ones in three translation units merge into one at link time; builds without stand-ins register nothing
|
|
typedef int (*dm_derived_loader)(void);
|
|
__attribute__((weak)) dm_derived_loader dm_derived_loaders[8];
|
|
__attribute__((weak)) int dm_derived_nloaders;
|
|
// 重读全部表:返回 0 = 都读全,-1 = 有没读到的(已读到的照样填进去);鸿蒙平台层在设好 DM_DERIVED 之后调,可重复调
|
|
// Re-read every table: 0 = all complete, -1 = something was not read (what was read is still filled in); the HarmonyOS platform layer calls it once DM_DERIVED is set, and it can be called again
|
|
__attribute__((weak)) int dm_derived_reload(void) { int bad = 0; for (int i = 0; i < dm_derived_nloaders; i++) bad |= dm_derived_loaders[i]() != 0; return bad ? -1 : 0; }
|
|
static inline void dm_derived_register(dm_derived_loader f) {
|
|
if (dm_derived_nloaders < (int)(sizeof dm_derived_loaders / sizeof dm_derived_loaders[0])) dm_derived_loaders[dm_derived_nloaders++] = f;
|
|
#ifndef __OHOS__
|
|
f();
|
|
#endif
|
|
}
|