madden-franchise 2.3.9 → 2.3.14

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
@@ -379,7 +379,7 @@ function getGameYear(data, isCompressed, format) {
379
379
  'max': 95
380
380
  },
381
381
  {
382
- 'year': 20,
382
+ 'year': 22,
383
383
  'max': 999
384
384
  }
385
385
  ];
@@ -431,7 +431,7 @@ function getGameYear(data, isCompressed, format) {
431
431
  return 21;
432
432
  }
433
433
  else {
434
- return 20;
434
+ return null;
435
435
  }
436
436
  }
437
437
  }
@@ -48,6 +48,22 @@ class FranchiseFileTable extends EventEmitter {
48
48
  updateBuffer() {
49
49
  // need to check table2 data first because it may change offsets of the legit records.
50
50
  const table2Data = this.strategy.getTable2BinaryData(this.table2Records, this.data.slice(this.header.table2StartIndex));
51
+
52
+ // update table2 length and table total length in table header (only if records have been read)
53
+ if (this.recordsRead) {
54
+ let table2DataLength = 0;
55
+
56
+ // Get length of all table2Data sub arrays
57
+ table2Data.forEach((arr) => {
58
+ table2DataLength += arr.length;
59
+ });
60
+
61
+ this.header.table2Length = table2DataLength;
62
+ this.header.tableTotalLength = this.header.table1Length + this.header.table2Length;
63
+
64
+ this.data.writeUInt32BE(this.header.table2Length , this.header.offsetStart - 44);
65
+ this.data.writeUInt32BE(this.header.tableTotalLength, this.header.offsetStart - 24);
66
+ }
51
67
 
52
68
  const changedRecords = this.records.filter((record) => { return record.isChanged; });
53
69
  let currentOffset = 0;
@@ -103,7 +119,7 @@ class FranchiseFileTable extends EventEmitter {
103
119
  this.header.nextRecordToUse = index;
104
120
 
105
121
  // And finally update the buffer to reflect this change
106
- this.data.writeUInt32BE(index, this.header.headerOffset - 4);
122
+ this.data.writeUInt32BE(index, this.header.offsetStart - 4);
107
123
  };
108
124
 
109
125
  recalculateEmptyRecordReferences() {
@@ -157,6 +173,30 @@ class FranchiseFileTable extends EventEmitter {
157
173
 
158
174
  this._setNextRecordToUseBuffer(nextRecordToUse);
159
175
  this.emptyRecords = this._parseEmptyRecords();
176
+ this.emit('change');
177
+ }
178
+ };
179
+
180
+ async replaceRawData(buf, shouldReadRecords) {
181
+ this.data = buf;
182
+
183
+ // Reset fields
184
+ this.recordsRead = false;
185
+ this.header = this.strategy.parseHeader(this.data);
186
+ this.name = this.header.name;
187
+ this.isArray = this.header.isArray;
188
+ this.loadedOffsets = [];
189
+ this.isChanged = false;
190
+ this.records = [];
191
+ this.table2Records = [];
192
+ this.arraySizes = [];
193
+ this.emptyRecords = new Map();
194
+
195
+ this.emit('change');
196
+
197
+ // Re-read records if desired
198
+ if (shouldReadRecords) {
199
+ return this.readRecords();
160
200
  }
161
201
  };
162
202
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "madden-franchise",
3
- "version": "2.3.9",
3
+ "version": "2.3.14",
4
4
  "description": "Tools to read a madden franchise file and get data from it",
5
5
  "main": "FranchiseFile.js",
6
6
  "scripts": {
@@ -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 });
@@ -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));