Advertisement
Guest User

Untitled

a guest
Jan 16th, 2022
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. "use strict";
  2.  
  3. const { readdirSync, readFileSync } = require('fs')
  4. const path = `../mml2data/DAT/`;
  5. const files = readdirSync(path);
  6.  
  7. const printHeader = () => {
  8.  
  9. console.log('| No | Entity Id | Occurences |');
  10. console.log('|---|---|---|');
  11.  
  12. }
  13.  
  14. const printRow = (index, id, instances) => {
  15. const row = ['', index.toString().padStart(3, '0'), id, instances.join(', '), ''];
  16. console.log(row.join('|'));
  17. }
  18.  
  19.  
  20. const byteValues = [];
  21. const unknownValues = [];
  22.  
  23. const entities = {};
  24. files.forEach( filename => {
  25.  
  26. const buffer = readFileSync(`${path}/${filename}`);
  27. const fileType = buffer.readUInt32LE(0x00);
  28.  
  29. if(fileType !== 0x0A) {
  30. return;
  31. }
  32.  
  33. const entityCount = buffer.readUInt32LE(0x30);
  34. if(entityCount & 0x80000000 || entityCount & 0x40000000) {
  35. return;
  36. }
  37.  
  38. let ofs = 0x34;
  39.  
  40. for(let i = 0; i < entityCount; i++) {
  41. const entityId = buffer.readUInt32LE(ofs + 0x00);
  42. const meshOfs = buffer.readUInt32LE(ofs + 0x04);
  43. const key = `0x${entityId.toString(16).padStart(6, '0')}`;
  44. if(!entities[key]) {
  45. entities[key] = {
  46. count: 0,
  47. offset: `0x${meshOfs.toString(16).padStart(6, '0')}`,
  48. files: [],
  49. bytes: [],
  50. unknown: [],
  51. };
  52. }
  53.  
  54. ofs += 0x10;
  55. const byte = buffer.readUInt8(0x30 + meshOfs + 3);
  56. const dword = buffer.readUInt32LE(0x30 + meshOfs + 0x1c);
  57. const unknown = `0x${dword.toString(16).padStart(8, '0')}`;
  58.  
  59. entities[key].count++;
  60. entities[key].files.push(filename);
  61. entities[key].bytes.push(byte);
  62. entities[key].unknown.push(unknown);
  63.  
  64. if(byteValues.indexOf(byte) === -1) {
  65. byteValues.push(byte);
  66. }
  67.  
  68. if(unknownValues.indexOf(unknown) === -1) {
  69. unknownValues.push(unknown);
  70. }
  71. }
  72.  
  73. });
  74.  
  75. const sorted = {};
  76. const keys = Object.keys(entities);
  77. keys.sort();
  78. let max = 0;
  79.  
  80. keys.forEach(key => {
  81. sorted[key] = entities[key];
  82. });
  83.  
  84. console.log(byteValues);
  85. console.log(unknownValues);
  86. console.log(JSON.stringify(sorted, null, 2));
  87.  
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement