summaryrefslogtreecommitdiff
path: root/tools/text_offsets.js
blob: 699078c4c9281f0af174fd729b6e4bab51277fbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const fs = require('fs');
const path = require('path');

let _parent = 'assets/reordered';
let bytes = Buffer.alloc(0);

function toHex(value) {
    let hex = value.toString(16);
    if ((hex.length % 2) > 0) {
        hex = "0" + hex;
    }
    return `0x${hex.toUpperCase()}`;
}

function toBEU16(num){
    let d = new Uint16Array(1);
    d[0] = num;
    return Buffer.from(d.buffer).swap16()
}

async function parseAnim(file){
    let fimport = `./${file.replace('.js', '')}`
    let data = require(fimport)
    for(let id of fimport.split('_').slice(1)){
        let anim = data['anim_'+id];
        let hOffset = bytes.indexOf(Buffer.concat(anim.slice(0, 6).map(toBEU16)));

        let bswValues = Buffer.concat(anim[6].map(toBEU16));
        let vsOffset = bytes.indexOf(bswValues);
        let bswIndices = Buffer.concat(anim[7].map(toBEU16));
        let idxOffset = bytes.indexOf(bswIndices);
        console.log(`"assets/anims/anim_${id}.anim": ${JSON.stringify({
            header: [hOffset, 0x18],
            values: [vsOffset, bswValues.length],
            indices: [idxOffset, bswIndices.length],
        })},`);
    }
}

async function main(){
    bytes = fs.readFileSync('./baserom.us.z64');
    let tst = [0x46,0x00,0x52,0x00,0x54,0x00,0x56,0x00,0x58,0x00,0x5a,0x00,0x5c,0x00,0x5e,0x00,0x60,0x00,0x62,0x00,0x64,0x00,0x67,0x00,0x69,0x00,0x6b,0x00,0x6d,0x00,0x6f,0x00,0x71,0x00,0x73,0x00,0x75,0x00,0x77,0x00,0x79,0x00,0x7b,0x00,0x7d,0x00,0x7f,0x00,0x81,0x00,0x83,0x00,0x85,0x00,0x87,0x00,0x89,0x00,0x8b,0x00,0x8d,0x00,0x8f,0x00,0x91,0x00,0x93,0x00,0x95,0x00,0x0b,0x0a,0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00,0x01,0x22,0x01,0x11,0x01,0x22,0x01,0x0e,0x01,0x13,0x01,0x0f,0x01,0x12,0x01,0x0b,0x01,0x0d,0x02,0x21,0x10,0x01,0x14,0x01,0x15,0x01,0x16,0x01,0x17,0x01,0x18,0x01,0x12,0x01,0x19,0x01,0x1f,0x01,0x21,0x01,0x1a,0x01,0x0e,0x01,0x1b,0x01,0x1a,0x01,0x1c,0x01,0x1d,0x01,0x25,0x01,0x14,0x01,0x20,0x01,0x1e,0x01,0x1b,0x01,0x1a,0x01,0x23,0x01,0x24,0x01,0x1b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00];
    let text = Buffer.from(tst)
    console.log(bytes.indexOf(text))
}

main();