Skip to content

Instantly share code, notes, and snippets.

@menduz
Created July 13, 2019 17:26
Show Gist options
  • Save menduz/c17e919736e5840f8807f9932b9d468c to your computer and use it in GitHub Desktop.
Save menduz/c17e919736e5840f8807f9932b9d468c to your computer and use it in GitHub Desktop.
ao-ind-conversor.js
const bb = require("./bytebuffer");
const fs = require("fs");
function loadBB(src) {
return bb.wrap(fs.readFileSync(src));
}
function loadCabecera(bb) {
bb.skip(255 + 4 + 4);
}
function loadGraphics() {
const bb = loadBB("Graficos.ind");
bb.littleEndian = true;
const version = bb.readInt();
console.log(`Version: ${version}`);
const count = bb.readInt();
console.log(`GrhCount: ${count}`);
const grh = [];
while (bb.offset < bb.limit) {
const id = bb.readInt();
const numFrames = bb.readShort();
const ret = {
id
};
try {
if (numFrames > 1) {
const frames = [];
ret.frames = frames;
for (let i = 0; i < numFrames; i++) {
const frame = bb.readInt();
if (frame <= 0 || frame > count) throw "frame";
frames.push(frame);
}
ret.speed = bb.readFloat();
if (ret.speed <= 0) throw "speed";
} else {
ret.fileNum = bb.readInt();
if (ret.fileNum < 0) throw "fileNum";
ret.x = bb.readShort();
if (ret.x < 0) throw "x";
ret.y = bb.readShort();
if (ret.y < 0) throw "y";
ret.w = bb.readShort();
if (ret.w <= 0) throw "w";
ret.h = bb.readShort();
if (ret.h <= 0) throw "h";
}
} catch (e) {
console.dir(ret);
throw e;
}
grh.push(ret);
}
fs.writeFileSync("graphics.json", JSON.stringify(grh, null, 2));
}
function loadCabezas() {
const bb = loadBB("Cabezas.ind");
bb.littleEndian = true;
loadCabecera(bb);
const count = bb.readShort();
console.log(`HeadCount: ${count}`);
const cabezas = [];
for (let i = 0; i < count; i++) {
const ret = {
id: i + 1,
grh: [bb.readShort(), bb.readShort(), bb.readShort(), bb.readShort()]
};
if (ret.grh.every($ => $ == 0)) continue;
cabezas.push(ret);
}
fs.writeFileSync("heads.json", JSON.stringify(cabezas, null, 2));
}
function loadCascos() {
const bb = loadBB("Cascos.ind");
bb.littleEndian = true;
loadCabecera(bb);
const count = bb.readShort();
console.log(`HelmetCount: ${count}`);
const cabezas = [];
for (let i = 0; i < count; i++) {
const ret = {
id: i + 1,
grh: [bb.readShort(), bb.readShort(), bb.readShort(), bb.readShort()]
};
if (ret.grh.every($ => $ == 0)) continue;
cabezas.push(ret);
}
fs.writeFileSync("helmets.json", JSON.stringify(cabezas, null, 2));
}
function loadCuerpos() {
const bb = loadBB("Personajes.ind");
bb.littleEndian = true;
loadCabecera(bb);
const count = bb.readShort();
console.log(`BodyCount: ${count}`);
const cabezas = [];
for (let i = 0; i < count; i++) {
const ret = {
id: i + 1,
grh: [bb.readShort(), bb.readShort(), bb.readShort(), bb.readShort()],
headX: bb.readShort(),
headY: bb.readShort()
};
if (ret.grh.every($ => $ == 0)) continue;
cabezas.push(ret);
}
fs.writeFileSync("bodies.json", JSON.stringify(cabezas, null, 2));
}
function loadFX() {
const bb = loadBB("FXs.ind");
bb.littleEndian = true;
loadCabecera(bb);
const count = bb.readShort();
console.log(`FXCount: ${count}`);
const cabezas = [];
for (let i = 0; i < count; i++) {
const ret = {
id: i + 1,
grh: bb.readShort(),
offsetX: bb.readShort(),
offsetY: bb.readShort()
};
if (ret.grh === 0) continue;
cabezas.push(ret);
}
fs.writeFileSync("fx.json", JSON.stringify(cabezas, null, 2));
}
loadFX();
loadCuerpos();
loadCascos();
loadCabezas();
loadGraphics();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment