Files
d2r-mobile/dm/android/debug_env.h
b811b90172 v2.0: Android and HarmonyOS ports, Korean, iPhone Duo, Xbox controller layout, separate game packages, Mac icon and pointer
- 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>
2026-10-23 09:21:08 +08:00

67 lines
3.2 KiB
C

/* 安卓性能对照的Debug专用白名单解析;基于D2固定比例A/B要求,不读取游戏内容。
* Debug-only Android allowlist parser for D2 fixed-scale A/B tests; reads no game content. */
#pragma once
#ifdef DM_ANDROID_DEBUG_ENV
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
typedef struct { unsigned present; char value[3][16]; } dm_android_debug_values;
static const char *const dm_android_debug_keys[]={"DM_3D_SCALE","DM_3D_SCALE_DYN","DM_3D_SCALE_FLOOR"};
/* 完整解析后才输出;未知键、重复、超限或floor高于起点使整份失效。
* Publish only a complete parse; unknown keys, duplicates, limits or a floor above the starting scale reject the file. */
static int dm_android_debug_parse(const char *text,size_t bytes,dm_android_debug_values *out) {
if(!text || !out || bytes>4096)return 0;
dm_android_debug_values parsed={0};size_t offset=0;
while(offset<bytes) {
size_t start=offset;
while(offset<bytes && text[offset]!='\n')++offset;
size_t length=offset-start;
if(offset<bytes)++offset;
if(length && text[start+length-1]=='\r')--length;
if(length>127)return 0;
for(size_t i=0;i<length;++i)if((unsigned char)text[start+i]<32 || (unsigned char)text[start+i]>126)return 0;
if(!length || text[start]=='#')continue;
const char *eq=memchr(text+start,'=',length);
if(!eq)return 0;
size_t key_length=(size_t)(eq-(text+start)),value_length=length-key_length-1;
if(!value_length || value_length>=sizeof parsed.value[0])return 0;
unsigned key;
for(key=0;key<3;++key)if(strlen(dm_android_debug_keys[key])==key_length && !memcmp(text+start,dm_android_debug_keys[key],key_length))break;
if(key==3 || (parsed.present&(1u<<key)))return 0;
memcpy(parsed.value[key],eq+1,value_length); parsed.value[key][value_length]=0;
if(key==1) { if(strcmp(parsed.value[key],"0") && strcmp(parsed.value[key],"1"))return 0; }
else {
int dots=0,digits=0;
for(size_t i=0;i<value_length;++i) {
char c=parsed.value[key][i];
if(c=='.') { if(++dots>1)return 0; }
else if(c>='0' && c<='9')++digits;
else return 0;
}
if(!digits)return 0;
double scale=strtod(parsed.value[key],NULL);
if(!(scale>=.50 && scale<=1.00))return 0;
}
parsed.present|=1u<<key;
}
double scale=(parsed.present&1)?strtod(parsed.value[0],NULL):.75;
double floor=(parsed.present&4)?strtod(parsed.value[2],NULL):.60;
if(floor>scale)return 0;
*out=parsed;return 1;
}
/* 缺文件返回0,拒绝返回-1,通过返回1;无有效整份结果时不修改输出。
* Return 0 for absent files, -1 for rejection, 1 for success; never change output without a valid complete result. */
static int dm_android_debug_load(const char *path,dm_android_debug_values *out) {
FILE *file=fopen(path,"rb");
if(!file)return errno==ENOENT?0:-1;
char bytes[4097];size_t count=fread(bytes,1,sizeof bytes,file);
int failed=ferror(file);fclose(file);
if(failed || count>4096 || !dm_android_debug_parse(bytes,count,out))return -1;
return 1;
}
#endif