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>
83 lines
6.0 KiB
Java
83 lines
6.0 KiB
Java
package com.xiaoboluo.d2r.widget;
|
|
|
|
import java.nio.ByteBuffer;
|
|
import java.nio.ByteOrder;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.util.Arrays;
|
|
import java.util.Comparator;
|
|
|
|
/** 仅生成合成存档,绝不访问玩家目录。 | Generates synthetic saves only; never reads a player's directory. */
|
|
public final class SaveSummaryReaderTest {
|
|
private static int checks;
|
|
private static void check(boolean value,String label) { ++checks; if (!value) throw new AssertionError(label); }
|
|
private static void sign(byte[] bytes) {
|
|
ByteBuffer data=ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN); data.putInt(8,bytes.length); data.putInt(12,0);
|
|
int sum=0; for (byte b:bytes) sum=Integer.rotateLeft(sum,1)+Byte.toUnsignedInt(b);
|
|
data.putInt(12,sum);
|
|
}
|
|
private static int bits(byte[] bytes,int offset,int width,long value) {
|
|
for (int i=0;i<width;++i) if ((value&(1L<<i))!=0) bytes[(offset+i)/8]|=(byte)(1<<((offset+i)%8));
|
|
return offset+width;
|
|
}
|
|
private static byte[] save(String name,long played) {
|
|
byte[] bytes=new byte[1024]; ByteBuffer data=ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
|
|
data.putInt(0,0xaa55aa55); data.putInt(4,0x69); data.putInt(0x20,(int)played);
|
|
bytes[0x18]=1; bytes[0x1b]=42;
|
|
byte[] utf8=name.getBytes(StandardCharsets.UTF_8); System.arraycopy(utf8,0,bytes,0x12b,Math.min(47,utf8.length));
|
|
bytes[0x180]=0x67; bytes[0x181]=0x66; int p=0x182*8;
|
|
p=bits(bytes,p,9,12); p=bits(bytes,p,7,42);
|
|
p=bits(bytes,p,9,13); p=bits(bytes,p,32,4_000_000_000L);
|
|
p=bits(bytes,p,9,14); p=bits(bytes,p,25,12345);
|
|
p=bits(bytes,p,9,15); p=bits(bytes,p,25,54321);
|
|
bits(bytes,p,9,0x1ff); sign(bytes); return bytes;
|
|
}
|
|
public static void main(String[] args) throws Exception {
|
|
byte[] valid=save("法师gf",4_100_000_000L), original=valid.clone();
|
|
SaveSummaryReader.Hero hero=SaveSummaryReader.parse(valid);
|
|
check(hero!=null,"valid v0x69"); check(hero.name.equals("法师gf"),"strict UTF-8 and gf inside name");
|
|
check(hero.level==42 && hero.classIndex==1,"header fields"); check(hero.lastPlayed==4_100_000_000L,"unsigned timestamp");
|
|
check(hero.experience==4_000_000_000L,"unsigned 32-bit experience"); check(hero.gold==66666,"carried plus bank gold");
|
|
check(Arrays.equals(original,valid),"parser never mutates input");
|
|
byte[] bad=valid.clone(); bad[4]=0x61; sign(bad); check(SaveSummaryReader.parse(bad)!=null,"supported v0x61");
|
|
bad[4]=0x60; sign(bad); check(SaveSummaryReader.parse(bad)==null,"unknown version rejected");
|
|
bad=valid.clone(); bad[100]^=1; check(SaveSummaryReader.parse(bad)==null,"checksum mismatch rejected");
|
|
bad=valid.clone(); bad[8]=1; check(SaveSummaryReader.parse(bad)==null,"length mismatch rejected");
|
|
check(SaveSummaryReader.parse(new byte[10])==null,"short header rejected");
|
|
bad=valid.clone(); bad[0x12b]=(byte)0xff; sign(bad); check(SaveSummaryReader.parse(bad)==null,"malformed UTF-8 rejected");
|
|
bad=valid.clone(); bad[0x12b]='\n'; sign(bad); check(SaveSummaryReader.parse(bad)==null,"control character rejected");
|
|
bad=valid.clone(); bad[0x18]=8; sign(bad); check(SaveSummaryReader.parse(bad)==null,"unknown class rejected");
|
|
bad=valid.clone(); bad[0x1b]=0; sign(bad); check(SaveSummaryReader.parse(bad)==null,"invalid level rejected");
|
|
bad=valid.clone(); bad[0x180]=0; sign(bad); hero=SaveSummaryReader.parse(bad);
|
|
check(hero!=null && hero.experience==-1 && hero.gold==-1,"missing stats remain unknown");
|
|
bad=valid.clone(); bad[0x182]=(byte)0xff; bad[0x183]=(byte)0xff; sign(bad); hero=SaveSummaryReader.parse(bad);
|
|
check(hero!=null && hero.gold==-1,"invalid stats never report invented gold");
|
|
Path temp=Files.createTempDirectory("d2r-widget-synthetic-");
|
|
try {
|
|
Path root=temp.resolve("save");
|
|
check(SaveSummaryReader.read(root).state==SaveSummaryReader.State.EMPTY,"absent directory is empty");
|
|
Files.createDirectory(root); check(SaveSummaryReader.read(root).state==SaveSummaryReader.State.EMPTY,"empty directory");
|
|
Path first=Files.createDirectory(root.resolve("First")); Path file=first.resolve("First.d2s"); Files.write(file,valid);
|
|
Path second=Files.createDirectory(root.resolve("Second")); Files.write(second.resolve("Second.d2s"),save("Older",100));
|
|
SaveSummaryReader.Result result=SaveSummaryReader.read(root);
|
|
check(result.state==SaveSummaryReader.State.READY && result.heroes.size()==2,"two valid saves");
|
|
check(result.heroes.get(0).name.equals("法师gf"),"newest first");
|
|
check(Arrays.equals(Files.readAllBytes(file),valid),"reader never writes saves");
|
|
Path broken=Files.createDirectory(root.resolve("Broken")); Files.write(broken.resolve("Broken.d2s"),new byte[400]);
|
|
result=SaveSummaryReader.read(root); check(result.state==SaveSummaryReader.State.PARTIAL && result.rejectedFiles==1,"mixed validity reported");
|
|
check(SaveSummaryReader.read(temp.resolve("save.work")).state==SaveSummaryReader.State.ERROR,"working directory rejected");
|
|
Files.delete(file); Files.delete(second.resolve("Second.d2s"));
|
|
check(SaveSummaryReader.read(root).state==SaveSummaryReader.State.ERROR,"only invalid saves is an error");
|
|
boolean immutable=false; try { result.heroes.clear(); } catch (UnsupportedOperationException ex) { immutable=true; }
|
|
check(immutable,"result cannot mutate cached hero list");
|
|
} finally {
|
|
/* 只清理由本测试创建的临时树。 | Remove only the temporary tree created by this test. */
|
|
try (java.util.stream.Stream<Path> paths=Files.walk(temp)) {
|
|
for (Path path:(Iterable<Path>)paths.sorted(Comparator.reverseOrder())::iterator) Files.delete(path);
|
|
}
|
|
}
|
|
System.out.println("SaveSummaryReader OK ("+checks+" synthetic checks; no player data)");
|
|
}
|
|
}
|