madden-franchise 2.3.12 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/FranchiseFile.js CHANGED
@@ -286,6 +286,29 @@ class FranchiseFile extends EventEmitter {
286
286
  return null;
287
287
  }
288
288
  };
289
+
290
+ getReferencesToRecord(tableId, recordIndex) {
291
+ const referencedTable = this.getTableById(tableId);
292
+
293
+ if (referencedTable) {
294
+ const fullBinary = utilService.getBinaryReferenceData(tableId, recordIndex);
295
+ const hex = utilService.bin2hex(fullBinary);
296
+
297
+ return this.tables.filter((table) => {
298
+ return table.schema && table.schema.attributes.find((attribute) => {
299
+ return attribute.type === referencedTable.name;
300
+ });
301
+ }).filter((table) => {
302
+ return table.data.indexOf(hex, 0, 'hex') !== -1;
303
+ }).map((table) => {
304
+ return {
305
+ tableId: table.header.tableId,
306
+ name: table.name,
307
+ table: table
308
+ }
309
+ });
310
+ }
311
+ };
289
312
  };
290
313
 
291
314
  module.exports = FranchiseFile;
@@ -379,7 +402,7 @@ function getGameYear(data, isCompressed, format) {
379
402
  'max': 95
380
403
  },
381
404
  {
382
- 'year': 20,
405
+ 'year': 22,
383
406
  'max': 999
384
407
  }
385
408
  ];
@@ -431,7 +454,7 @@ function getGameYear(data, isCompressed, format) {
431
454
  return 21;
432
455
  }
433
456
  else {
434
- return 20;
457
+ return null;
435
458
  }
436
459
  }
437
460
  }
@@ -44,10 +44,30 @@ class FranchiseFileTable extends EventEmitter {
44
44
  get schema () {
45
45
  return this._schema;
46
46
  };
47
+
48
+ getBinaryReferenceToRecord(index) {
49
+ return utilService.getBinaryReferenceData(this.header.tableId, index);
50
+ };
47
51
 
48
52
  updateBuffer() {
49
53
  // need to check table2 data first because it may change offsets of the legit records.
50
54
  const table2Data = this.strategy.getTable2BinaryData(this.table2Records, this.data.slice(this.header.table2StartIndex));
55
+
56
+ // update table2 length and table total length in table header (only if records have been read)
57
+ if (this.recordsRead) {
58
+ let table2DataLength = 0;
59
+
60
+ // Get length of all table2Data sub arrays
61
+ table2Data.forEach((arr) => {
62
+ table2DataLength += arr.length;
63
+ });
64
+
65
+ this.header.table2Length = table2DataLength;
66
+ this.header.tableTotalLength = this.header.table1Length + this.header.table2Length;
67
+
68
+ this.data.writeUInt32BE(this.header.table2Length , this.header.offsetStart - 44);
69
+ this.data.writeUInt32BE(this.header.tableTotalLength, this.header.offsetStart - 24);
70
+ }
51
71
 
52
72
  const changedRecords = this.records.filter((record) => { return record.isChanged; });
53
73
  let currentOffset = 0;
@@ -176,6 +196,8 @@ class FranchiseFileTable extends EventEmitter {
176
196
  this.arraySizes = [];
177
197
  this.emptyRecords = new Map();
178
198
 
199
+ this.emit('change');
200
+
179
201
  // Re-read records if desired
180
202
  if (shouldReadRecords) {
181
203
  return this.readRecords();
@@ -574,7 +596,7 @@ function readOffsetTable(data, schema, header) {
574
596
  'originalIndex': parseInt(attribute.index),
575
597
  'name': attribute.name,
576
598
  'type': (minValue < 0 || maxValue < 0) ? 's_' + attribute.type : attribute.type,
577
- 'isReference': !attribute.enum && (attribute.type[0] == attribute.type[0].toUpperCase() || attribute.type.includes('[]')) ? true : false,
599
+ 'isReference': !attribute.enum && (attribute.type[0] == attribute.type[0].toUpperCase() || attribute.type.includes('[]') || attribute.type === 'record') ? true : false,
578
600
  'valueInSecondTable': header.hasSecondTable && attribute.type === 'string',
579
601
  'isSigned': minValue < 0 || maxValue < 0,
580
602
  'minValue': minValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "madden-franchise",
3
- "version": "2.3.12",
3
+ "version": "2.4.0",
4
4
  "description": "Tools to read a madden franchise file and get data from it",
5
5
  "main": "FranchiseFile.js",
6
6
  "scripts": {
@@ -1,8 +1,8 @@
1
1
  const fs = require('fs');
2
2
  const zlib = require('zlib');
3
3
 
4
- const filePath = 'D:\\Projects\\Madden 22\\Expressions\\sabo-expression-binary.frt';
5
- const outputPath = 'D:\\Projects\\Madden 22\\Expressions\\modified-Franchise-Expression-binary.FTC'
4
+ const filePath = 'D:\\Projects\\Madden 22\\Misc\\FTC\\tuning.frt';
5
+ const outputPath = 'D:\\Projects\\Madden 22\\Misc\\FTC\\modified-Tuning.FTC'
6
6
 
7
7
  const stream = fs.createReadStream(filePath)
8
8
 
@@ -67,7 +67,14 @@ function getSchemasInFolder(dir) {
67
67
  function findApplicableSchema(schemaMeta, gameYear, major, minor) {
68
68
  // check if game year exists
69
69
  if (schemaMeta) {
70
- const schemasToSearch = schemaMeta.filter((schema) => { return schema.gameYear == gameYear || schema.gameYear === null && schema.major !== null && schema.minor !== null; });
70
+ const schemasToSearch = schemaMeta.filter((schema) => {
71
+ if (gameYear) {
72
+ return schema.gameYear == gameYear || schema.gameYear === null && schema.major !== null && schema.minor !== null;
73
+ }
74
+ else {
75
+ return schema.major !== null && schema.minor !== null;
76
+ }
77
+ });
71
78
 
72
79
  // check if exact major exists
73
80
  const exactMajor = schemasToSearch.filter((schema) => { return schema.major == major });
@@ -223,4 +223,10 @@ utilService.getReferenceData = function (value) {
223
223
  }
224
224
  };
225
225
 
226
+ utilService.getBinaryReferenceData = function (tableId, rowNumber) {
227
+ const referenceBinary = utilService.dec2bin(tableId, 15);
228
+ const recordIndexBinary = utilService.dec2bin(rowNumber, 17);
229
+ return referenceBinary + recordIndexBinary;
230
+ };
231
+
226
232
  module.exports = utilService;
@@ -2,7 +2,9 @@ const CommonAlgorithms = require('../CommonAlgorithms');
2
2
 
3
3
  let FTCTableStrategy = {};
4
4
 
5
- FTCTableStrategy.getTable2BinaryData = CommonAlgorithms.save;
5
+ FTCTableStrategy.getTable2BinaryData = (table2Records, fullTable2Buffer) => {
6
+ return [CommonAlgorithms.save(table2Records, fullTable2Buffer)];
7
+ };
6
8
 
7
9
  FTCTableStrategy.getMandatoryOffsets = (offsets) => {
8
10
  return offsets.filter((offset) => {
@@ -8,20 +8,20 @@ FranchiseTableStrategy.getTable2BinaryData = (table2Records, fullTable2Buffer) =
8
8
  let currentOffset = 0;
9
9
 
10
10
  for (let i = 0; i < changedTable2Records.length; i++) {
11
- let record = changedTable2Records[i];
12
- record.isChanged = false;
13
- const recordOffset = record.index;
11
+ let record = changedTable2Records[i];
12
+ record.isChanged = false;
13
+ const recordOffset = record.index;
14
14
 
15
- if (i > 0 && recordOffset === 0) {
16
- // this case is true for the last few rows with no data in them. They reference the first table2 value.
17
- break;
18
- }
15
+ if (i > 0 && recordOffset === 0) {
16
+ // this case is true for the last few rows with no data in them. They reference the first table2 value.
17
+ break;
18
+ }
19
19
 
20
- table2Data.push(fullTable2Buffer.slice(currentOffset, recordOffset));
21
- const recordHexData = record.hexData;
22
- table2Data.push(recordHexData);
20
+ table2Data.push(fullTable2Buffer.slice(currentOffset, recordOffset));
21
+ const recordHexData = record.hexData;
22
+ table2Data.push(recordHexData);
23
23
 
24
- currentOffset = recordOffset + recordHexData.length;
24
+ currentOffset = recordOffset + recordHexData.length;
25
25
  }
26
26
 
27
27
  table2Data.push(fullTable2Buffer.slice(currentOffset));