mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Added animation factory and some random tools
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
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');
|
||||
for(let file of fs.readdirSync(_parent)){
|
||||
let pdir = path.join(_parent, file);
|
||||
let lines = fs.readFileSync(pdir, 'utf8').split('\n').map((line) =>
|
||||
line.replace('const u16', 'let')
|
||||
.replace('const s16', 'let')
|
||||
.replace('#include "animation_table.h"', '')
|
||||
.replace('const struct Animation', 'let')
|
||||
.replace('[] = {', ' = [')
|
||||
.replace('};', ']')
|
||||
);
|
||||
let func = "function ANIMINDEX_NUMPARTS(animindex) {\n return Math.floor(animindex.length / 6) - 1;\n}".split('\n');
|
||||
let output = path.join('assets/js', file).replace('.inc.c', '.js');
|
||||
fs.writeFileSync(output, [
|
||||
...func,
|
||||
...lines,
|
||||
`module.exports = { ${output.replace('.js', '').split('_').slice(1).map(m => `anim_${m}`).join(', ')} };`,
|
||||
].join('\n'));
|
||||
await parseAnim(output);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env python3
|
||||
import os
|
||||
|
||||
# This script generates the offsets for the animation files.
|
||||
|
||||
OFFSET = 0x4EC690
|
||||
HEADER_SIZE = 0x18
|
||||
ANIMS_SIZE = 3
|
||||
|
||||
# struct Animation {
|
||||
# /*0x00*/ s16 flags;
|
||||
# /*0x02*/ s16 animYTransDivisor;
|
||||
# /*0x04*/ s16 startFrame;
|
||||
# /*0x06*/ s16 loopStart;
|
||||
# /*0x08*/ s16 loopEnd;
|
||||
# /*0x0A*/ s16 unusedBoneCount;
|
||||
# /*0x0C*/ const s16 *values;
|
||||
# /*0x10*/ const u16 *index;
|
||||
# /*0x14*/ u32 length; // only used with Mario animations to determine how much to load. 0 otherwise.
|
||||
# };
|
||||
|
||||
# ./anim_01_02.inc.c./anim_07_08.inc.c./anim_0B_0C.inc.c./anim_0F_10.inc.c./anim_2C_2D.inc.c./anim_3C_3D.inc.c./anim_45_46.inc.c./anim_4D_4E.inc.c./anim_56_57.inc.c./anim_6F_70.inc.c./anim_72_73.inc.c./anim_88_89.inc.c./anim_8E_8F.inc.c./anim_B5_B6.inc.c./anim_BC_BD.inc.c./anim_CB_CC.inc.c%
|
||||
|
||||
multi = [0x01, 0x07, 0x0B, 0x0F, 0x2C, 0x3C, 0x45, 0x4D, 0x56, 0x6F, 0x72, 0x88, 0x8E, 0xB5, 0xBC, 0xCB]
|
||||
|
||||
if __name__ == "__main__":
|
||||
with open("baserom.us.z64", "rb") as f:
|
||||
f.seek(OFFSET)
|
||||
for i in range(ANIMS_SIZE):
|
||||
for j in range(2 if i in multi else 1):
|
||||
flags = int.from_bytes(f.read(2), byteorder="big")
|
||||
animYTransDivisor = int.from_bytes(f.read(2), byteorder="big")
|
||||
startFrame = int.from_bytes(f.read(2), byteorder="big")
|
||||
loopStart = int.from_bytes(f.read(2), byteorder="big")
|
||||
loopEnd = int.from_bytes(f.read(2), byteorder="big")
|
||||
unusedBoneCount = int.from_bytes(f.read(2), byteorder="big")
|
||||
values = int.from_bytes(f.read(4), byteorder="little")
|
||||
index = int.from_bytes(f.read(4), byteorder="little")
|
||||
length = int.from_bytes(f.read(2), byteorder="big")
|
||||
print(f"0x{OFFSET + i * HEADER_SIZE:08X}")
|
||||
print(f" flags: {flags}")
|
||||
print(f" animYTransDivisor: {animYTransDivisor}")
|
||||
print(f" startFrame: {startFrame}")
|
||||
print(f" loopStart: {loopStart}")
|
||||
print(f" loopEnd: {loopEnd}")
|
||||
print(f" unusedBoneCount: {unusedBoneCount}")
|
||||
print(f" values: 0x{values:08X}")
|
||||
print(f" index: 0x{index:08X}")
|
||||
print(f" length: {length}")
|
||||
f.seek(HEADER_SIZE, os.SEEK_CUR)
|
||||
f.seek(0x18, os.SEEK_CUR)
|
||||
@@ -0,0 +1,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();
|
||||
Reference in New Issue
Block a user