Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

18 figure out how to pack binary into model format #19

Merged
merged 7 commits into from
Jul 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
find offset test
kion-dgl committed Jul 19, 2024
commit 48a1834d56f7671f1b8e35d701d6f49c5a1f550e
Binary file added fixtures/mem.bin
Binary file not shown.
65 changes: 65 additions & 0 deletions test/find-offset.test.ts
Original file line number Diff line number Diff line change
@@ -32,3 +32,68 @@ test("ISO 9660 File Offset Finder", () => {
expect(fileOffset).not.toEqual(-1);
});
});

test("Megaman Model Offset Reference", () => {
const binFilePath = process.env.SRC_ROM;
if (!binFilePath) {
console.log("SRC_ROM environment variable not set. Skipping tests.");
return;
}

const PLAYER_OFFSET = 0x110800;
const body = 0x80;
const head = 0xb60;
const rightArm = 0x26f0;
const eof = 0x2b40;
const leftArm = 0x1dd0;
const buster = 0x2220;
const feet = 0x1800;

const rom = readFileSync(binFilePath);

let found = false;
let ofs = -1;
for (let i = 0; i < rom.length - 0x20; i += 4) {
const a = (rom.readUInt32LE(i + 0) & 0xffffff) - PLAYER_OFFSET;
const b = (rom.readUInt32LE(i + 4) & 0xffffff) - PLAYER_OFFSET;
const c = (rom.readUInt32LE(i + 8) & 0xffffff) - PLAYER_OFFSET;
const d = (rom.readUInt32LE(i + 12) & 0xffffff) - PLAYER_OFFSET;
const e = (rom.readUInt32LE(i + 16) & 0xffffff) - PLAYER_OFFSET;
const f = (rom.readUInt32LE(i + 20) & 0xffffff) - PLAYER_OFFSET;
const g = (rom.readUInt32LE(i + 24) & 0xffffff) - PLAYER_OFFSET;

if (a !== body) {
continue;
}

if (b !== head) {
continue;
}

if (c !== rightArm) {
continue;
}

if (d !== eof) {
continue;
}

if (e !== leftArm) {
continue;
}

if (f !== buster) {
continue;
}

if (g !== feet) {
continue;
}

found = true;
console.log("Offset found at 0x%s", i.toString(16));
break;
}

expect(found).toBeTrue();
});