Skip to content

Instantly share code, notes, and snippets.

@gokaygurcan
Created October 29, 2018 14:58
Show Gist options
  • Select an option

  • Save gokaygurcan/80e1b94042d0cba4df765192f233505b to your computer and use it in GitHub Desktop.

Select an option

Save gokaygurcan/80e1b94042d0cba4df765192f233505b to your computer and use it in GitHub Desktop.
read tiledata.mul and create m_LandData and m_ItemData lists. yaay.
const { readFileSync } = require('fs');
const { normalize, join } = require('path');
const { hexy } = require('hexy');
const { cwd } = process;
const fileName = 'tiledata.mul';
const tiledata = readFileSync(normalize(join(cwd(), 'muls', fileName)), {
flags: 'r'
});
const dump = buffer => {
console.log(hexy(buffer, {
width: 32,
numbering: 'none',
format: 'twos'
}));
};
// ----------------------------------------------------
let m_LandData = [];
let landheader = [];
let currpos = 0;
let j = 0;
for (let i = 0; i < 0x4000; i += 32) {
let ptrheader = tiledata.readUInt32BE(currpos);
currpos += 4;
landheader[j++] = ptrheader;
for (let count = 0; count < 32; ++count) {
let ptr = tiledata.readUInt32BE(currpos);
let cur = {
flags: tiledata.slice(currpos, currpos + 4).readUInt32BE(),
unk1: tiledata.slice(currpos + 4, currpos + 8).readUInt32BE(),
texID: tiledata.slice(currpos + 8, currpos + 10).readUInt16BE(),
name: tiledata.slice(currpos + 10, currpos + 30).toString().split('\0')[0]
};
currpos += 30; // 4 + 4 + 2 + 20
m_LandData[i + count] = cur;
}
}
for (let i = 0; i < m_LandData.length; ++i) {
console.log(`${m_LandData[i].flags} - ${m_LandData[i].unk1} - ${m_LandData[i].texID} - ${m_LandData[i].name}`);
}
let remaining = tiledata.length - currpos;
let structsize = 4 + 4 + 1 + 1 + 2 + 1 + 1 + 2 + 1 + 1 + 1 + 1 + 1 + 20; // 41
let itemheader = [];
let itemlength = (remaining / ((structsize * 32) + 4)) * 32;
let m_ItemData = [];
let m_HeightTable = [];
j = 0;
for (let i = 0; i < itemlength; i += 32) {
let ptrheader = tiledata.readUInt32BE(currpos);
currpos += 4;
itemheader[j++] = ptrheader;
for (let count = 0; count < 32; ++count) {
let ptr = tiledata.readUInt32BE(currpos);
let cur = {
flags: tiledata.slice(currpos, currpos + 4).readUInt32BE(),
unk1: tiledata.slice(currpos + 4, currpos + 8).readUInt32BE(),
weight: tiledata.slice(currpos + 8, currpos + 9).readUInt8(),
quality: tiledata.slice(currpos + 9, currpos + 10).readUInt8(),
miscdata: tiledata.slice(currpos + 10, currpos + 12).readUInt16BE(),
unk2: tiledata.slice(currpos + 12, currpos + 13).readUInt8(),
quantity: tiledata.slice(currpos + 13, currpos + 14).readUInt8(),
anim: tiledata.slice(currpos + 14, currpos + 16).readUInt16BE(),
unk3: tiledata.slice(currpos + 16, currpos + 17).readUInt8(),
hue: tiledata.slice(currpos + 17, currpos + 18).readUInt8(),
stackingoffset: tiledata.slice(currpos + 18, currpos + 19).readUInt8(),
value: tiledata.slice(currpos + 19, currpos + 20).readUInt8(),
height: tiledata.slice(currpos + 20, currpos + 21).readUInt8(),
name: tiledata.slice(currpos + 21, currpos + 41).toString().split('\0')[0]
};
m_ItemData[i + count] = cur;
m_HeightTable[i + count] = cur.height;
currpos += structsize;
}
}
for (let i = 0; i < m_ItemData.length; ++i) {
console.log(`${m_ItemData[i].flags} - ${m_ItemData[i].unk1} - ${m_ItemData[i].weight} - ${m_ItemData[i].quality} - ${m_ItemData[i].miscdata} - ${m_ItemData[i].unk2} - ${m_ItemData[i].quantity} - ${m_ItemData[i].anim} - ${m_ItemData[i].unk3} - ${m_ItemData[i].hue} - ${m_ItemData[i].stackingoffset} - ${m_ItemData[i].value} - ${m_ItemData[i].height} - ${m_ItemData[i].name}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment