Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "use strict";
- const { readdirSync, readFileSync } = require('fs')
- const path = `../mml2data/DAT/`;
- const files = readdirSync(path);
- const printHeader = () => {
- console.log('| No | Entity Id | Occurences |');
- console.log('|---|---|---|');
- }
- const printRow = (index, id, instances) => {
- const row = ['', index.toString().padStart(3, '0'), id, instances.join(', '), ''];
- console.log(row.join('|'));
- }
- const byteValues = [];
- const unknownValues = [];
- const entities = {};
- files.forEach( filename => {
- const buffer = readFileSync(`${path}/${filename}`);
- const fileType = buffer.readUInt32LE(0x00);
- if(fileType !== 0x0A) {
- return;
- }
- const entityCount = buffer.readUInt32LE(0x30);
- if(entityCount & 0x80000000 || entityCount & 0x40000000) {
- return;
- }
- let ofs = 0x34;
- for(let i = 0; i < entityCount; i++) {
- const entityId = buffer.readUInt32LE(ofs + 0x00);
- const meshOfs = buffer.readUInt32LE(ofs + 0x04);
- const key = `0x${entityId.toString(16).padStart(6, '0')}`;
- if(!entities[key]) {
- entities[key] = {
- count: 0,
- offset: `0x${meshOfs.toString(16).padStart(6, '0')}`,
- files: [],
- bytes: [],
- unknown: [],
- };
- }
- ofs += 0x10;
- const byte = buffer.readUInt8(0x30 + meshOfs + 3);
- const dword = buffer.readUInt32LE(0x30 + meshOfs + 0x1c);
- const unknown = `0x${dword.toString(16).padStart(8, '0')}`;
- entities[key].count++;
- entities[key].files.push(filename);
- entities[key].bytes.push(byte);
- entities[key].unknown.push(unknown);
- if(byteValues.indexOf(byte) === -1) {
- byteValues.push(byte);
- }
- if(unknownValues.indexOf(unknown) === -1) {
- unknownValues.push(unknown);
- }
- }
- });
- const sorted = {};
- const keys = Object.keys(entities);
- keys.sort();
- let max = 0;
- keys.forEach(key => {
- sorted[key] = entities[key];
- });
- console.log(byteValues);
- console.log(unknownValues);
- console.log(JSON.stringify(sorted, null, 2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement