From 59f7dd7c15961fd883a309c4cbce9c95e318c59c Mon Sep 17 00:00:00 2001 From: 3Shain Date: Wed, 23 Oct 2024 09:00:32 +0800 Subject: [PATCH] feat: update game version detection --- src/clients/mhy/unity.ts | 60 ++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/src/clients/mhy/unity.ts b/src/clients/mhy/unity.ts index 3b2cac0..12b7668 100644 --- a/src/clients/mhy/unity.ts +++ b/src/clients/mhy/unity.ts @@ -27,30 +27,54 @@ export async function getGameVersion2019(gameDataDir: string) { const view = new Uint8Array(await readBinary(ggmPath)); const index = binaryPatternSearch( view, - [0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x2e, 0x67] + [0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79] ); if (index == -1) { throw new Error("pattern not found"); //FIXME } else { let str = ""; let offset = 0; - for (let i = 0; i < 3; i++) { - for (;;) { - const w = view[index + 0x40 + offset]; - if (w - 48 == -2) { - // dot - str += "."; - offset++; - break; - } else if (w - 48 >= 0 && w - 48 < 10) { - // decimal - str += String.fromCharCode(w); - offset++; - continue; - } else if (i == 2) { - return str; - } else { - throw new Error("Falied to parse version"); + try { + for (let i = 0; i < 3; i++) { + for (;;) { + const w = view[index + 0x40 + offset]; + if (w - 48 == -2) { + // dot + str += "."; + offset++; + break; + } else if (w - 48 >= 0 && w - 48 < 10) { + // decimal + str += String.fromCharCode(w); + offset++; + continue; + } else if (i == 2) { + return str; + } else { + throw new Error("Falied to parse version"); + } + } + } + } catch { + // second attempt + for (let i = 0; i < 3; i++) { + for (;;) { + const w = view[index + 0x35 + offset]; + if (w - 48 == -2) { + // dot + str += "."; + offset++; + break; + } else if (w - 48 >= 0 && w - 48 < 10) { + // decimal + str += String.fromCharCode(w); + offset++; + continue; + } else if (i == 2) { + return str; + } else { + throw new Error("Falied to parse version"); + } } } }