Skip to content

Commit

Permalink
feat: update game version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
3Shain committed Oct 23, 2024
1 parent 0cfac7d commit 59f7dd7
Showing 1 changed file with 42 additions and 18 deletions.
60 changes: 42 additions & 18 deletions src/clients/mhy/unity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
}
Expand Down

0 comments on commit 59f7dd7

Please sign in to comment.