madden-franchise 2.2.1 → 2.2.5

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
@@ -52,7 +52,6 @@ class FranchiseFile extends EventEmitter {
52
52
 
53
53
  parse() {
54
54
  const that = this;
55
- console.log(this.type);
56
55
  this.strategy = StrategyPicker.pick(this.type);
57
56
 
58
57
  let schemaPromise = new Promise((resolve, reject) => {
@@ -10,6 +10,7 @@ class FranchiseFileRecord extends EventEmitter {
10
10
  this.index = index;
11
11
  this._fields = parseRecordFields(data, offsetTable);
12
12
  this.isChanged = false;
13
+ this.arraySize = null;
13
14
 
14
15
  const that = this;
15
16
  this._fields.forEach((field) => {
@@ -24,7 +25,31 @@ class FranchiseFileRecord extends EventEmitter {
24
25
 
25
26
  field.on('change', function () {
26
27
  that._data = utilService.replaceAt(that._data, this.offset.offset, this.unformattedValue);
27
- that.emit('change');
28
+
29
+ // NOTE: At this time, we can only change the size of arrays of references.
30
+ // I'm not sure how to change the size of non-reference arrays, or if it's even possible.
31
+ if (that.arraySize) {
32
+ const referenceData = this.referenceData;
33
+
34
+ // If the field is outside of the previous array size and was edited to a valid reference,
35
+ // then reset the array size
36
+ if (this.offset.index >= that.arraySize) {
37
+ if (this.isReference) {
38
+ if (referenceData.tableId !== 0 || referenceData.rowNumber !== 0) {
39
+ that.arraySize = this.offset.index + 1;
40
+ }
41
+ }
42
+ }
43
+
44
+ // If the value was changed to 0s, then shrink the array size to this index.
45
+ else if (this.isReference) {
46
+ if (referenceData.tableId === 0 && referenceData.rowNumber === 0) {
47
+ that.arraySize = this.offset.index;
48
+ }
49
+ }
50
+ }
51
+
52
+ that.emit('change', this.offset);
28
53
  });
29
54
  });
30
55
  };
@@ -21,6 +21,7 @@ class FranchiseFileTable extends EventEmitter {
21
21
  this.isChanged = false;
22
22
  this.records = [];
23
23
  this.table2Records = [];
24
+ this.arraySizes = [];
24
25
  };
25
26
 
26
27
  get hexData () {
@@ -31,6 +32,21 @@ class FranchiseFileTable extends EventEmitter {
31
32
  let currentOffset = 0;
32
33
  let bufferArrays = [];
33
34
 
35
+ // Add all of the array sizes to the buffer if the table is an array
36
+ if (this.isArray) {
37
+ // Push the header data
38
+ bufferArrays.push(this.data.slice(currentOffset, this.header.headerSize));
39
+
40
+ let arraySizeBuffer = Buffer.alloc(this.header.data1RecordCount * 4);
41
+
42
+ this.arraySizes.forEach((arraySize) => {
43
+ arraySizeBuffer.writeUInt32BE(arraySize);
44
+ });
45
+
46
+ bufferArrays.push(arraySizeBuffer);
47
+ currentOffset += this.header.headerSize + this.header.data1RecordCount * 4;
48
+ }
49
+
34
50
  for (let i = 0; i < changedRecords.length; i++) {
35
51
  let record = changedRecords[i];
36
52
  record.isChanged = false;
@@ -74,6 +90,7 @@ class FranchiseFileTable extends EventEmitter {
74
90
  } else if (this.isArray) {
75
91
  const numberOfFields = this.header.record1Size / 4;
76
92
  let offsetTable = [];
93
+ let arraySizes = [];
77
94
 
78
95
  for (let i = 0; i < numberOfFields; i++) {
79
96
  const offset = {
@@ -96,7 +113,12 @@ class FranchiseFileTable extends EventEmitter {
96
113
  offsetTable.push(offset);
97
114
  }
98
115
 
116
+ for (let i = 0; i < this.header.data1RecordCount; i++) {
117
+ arraySizes.push(this.data.readUInt32BE(this.header.headerSize + (i * 4)));
118
+ }
119
+
99
120
  this.offsetTable = offsetTable;
121
+ this.arraySizes = arraySizes;
100
122
  } else {
101
123
  reject('Cannot read records: Schema is not defined.');
102
124
  }
@@ -122,9 +144,14 @@ class FranchiseFileTable extends EventEmitter {
122
144
  }
123
145
 
124
146
  this.records.forEach((record, index) => {
147
+ if (this.isArray) {
148
+ record.arraySize = this.arraySizes[index];
149
+ }
150
+
125
151
  const that = this;
126
- record.on('change', function () {
152
+ record.on('change', function (changedOffset) {
127
153
  this.isChanged = true;
154
+ that.arraySizes[index] = this.arraySize;
128
155
  that.emit('change');
129
156
  });
130
157
  });
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "madden-franchise",
3
- "version": "2.2.1",
3
+ "version": "2.2.5",
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 20\\FranchiseData\\Franchise-Expression-binary-modified.frt';
5
- const outputPath = 'D:\\Projects\\Madden 20\\FranchiseData\\Franchise-Expression-Binary1.FTC'
4
+ const filePath = 'D:\\Projects\\Madden 22\\Expressions\\franchise-expressions-binary.frt';
5
+ const outputPath = 'D:\\Projects\\Madden 22\\Expressions\\modified-Franchise-Expression-binary.FTC'
6
6
 
7
7
  const stream = fs.createReadStream(filePath)
8
8
 
@@ -54,9 +54,9 @@ M19TableHeaderStrategy.parseHeader = (data) => {
54
54
  let records1Size = 0;
55
55
 
56
56
  if (isArray) {
57
- headerSize = 0xE8 + tableStoreLength;
58
- const binaryData = utilService.getBitArray(data.slice(0, headerSize));
59
- records1Size = utilService.bin2dec(binaryData.slice(records1SizeOffset, records1SizeOffset+9));
57
+ headerSize = 0xE4 + tableStoreLength;
58
+ // const binaryData = utilService.getBitArray(data.slice(0, headerSize));
59
+ records1Size = data2RecordWords * 4;
60
60
  }
61
61
 
62
62
  return {
@@ -93,8 +93,8 @@ M19TableHeaderStrategy.parseHeader = (data) => {
93
93
  'table1Length2': table1Length2,
94
94
  'tableTotalLength': tableTotalLength,
95
95
  'hasSecondTable': hasSecondTable,
96
- 'table1StartIndex': tableStoreLength === 0 && !isArray ? headerSize : headerSize - 4 + (data1RecordCount * 4),
97
- 'table2StartIndex': tableStoreLength === 0 && !isArray ? headerSize + (data1RecordCount * records1Size) : (headerSize -4 + (data1RecordCount * 4)) + (data1RecordCount * records1Size),
96
+ 'table1StartIndex': tableStoreLength === 0 && !isArray ? headerSize : headerSize + (data1RecordCount * 4),
97
+ 'table2StartIndex': tableStoreLength === 0 && !isArray ? headerSize + (data1RecordCount * records1Size) : headerSize + (data1RecordCount * 4) + (data1RecordCount * records1Size),
98
98
  'data2recordWords': data2RecordWords,
99
99
  'data2RecordCapacity': data2RecordCapacity,
100
100
  'data2IndexEntries': data2IndexEntries,
@@ -103,16 +103,26 @@ M19TableHeaderStrategy.parseHeader = (data) => {
103
103
  };
104
104
 
105
105
  M19TableHeaderStrategy.parseHeaderAttributesFromSchema = (schema, data, header) => {
106
- headerSize = header.headerOffset + (schema.numMembers * 4) + header.tableStoreLength;
107
- const binaryData = utilService.getBitArray(data.slice(0, headerSize));
108
- records1Size = utilService.bin2dec(binaryData.slice(header.record1SizeOffset, header.record1SizeOffset + header.record1SizeLength));
109
-
110
- return {
111
- 'headerSize': headerSize,
112
- 'record1Size': records1Size,
113
- 'table1StartIndex': headerSize,
114
- 'table2StartIndex': headerSize + (header.data1RecordCount * records1Size)
115
- };
106
+ if (header.isArray) {
107
+ return {
108
+ 'headerSize': header.headerSize,
109
+ 'record1Size': header.record1Size,
110
+ 'table1StartIndex': header.table1StartIndex,
111
+ 'table2StartIndex': header.table2StartIndex
112
+ }
113
+ }
114
+ else {
115
+ headerSize = header.headerOffset + (schema.numMembers * 4) + header.tableStoreLength;
116
+ const binaryData = utilService.getBitArray(data.slice(0, headerSize));
117
+ records1Size = utilService.bin2dec(binaryData.slice(header.record1SizeOffset, header.record1SizeOffset + header.record1SizeLength));
118
+
119
+ return {
120
+ 'headerSize': headerSize,
121
+ 'record1Size': records1Size,
122
+ 'table1StartIndex': headerSize,
123
+ 'table2StartIndex': headerSize + (header.data1RecordCount * records1Size)
124
+ };
125
+ }
116
126
  };
117
127
 
118
128
  module.exports = M19TableHeaderStrategy;
@@ -68,7 +68,6 @@ M20TableHeaderStrategy.parseHeader = (data) => {
68
68
  table2StartIndex = table1StartIndex + (data1RecordCount * records1Size)
69
69
  }
70
70
 
71
-
72
71
  return {
73
72
  'name': tableName,
74
73
  'isArray': isArray,
Binary file