Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Detect save file types by their size
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark committed Aug 7, 2016
1 parent ec21d36 commit e27cc55
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .babelrc
@@ -1,3 +1,3 @@
{
"plugins": ["transform-async-to-generator"]
"plugins": ["transform-async-to-generator", "transform-exponentiation-operator"]
}
3 changes: 2 additions & 1 deletion client/.babelrc
Expand Up @@ -2,6 +2,7 @@
"presets": ["es2015"],
"plugins": [
"lodash",
"transform-async-to-generator"
"transform-async-to-generator",
"transform-exponentiation-operator"
]
}
15 changes: 12 additions & 3 deletions client/add/parseSaveFile.js
Expand Up @@ -153,10 +153,19 @@ function copy(src, off1, dest, off2, length) {
}
}

const FILE_SIZES = {
483328: 'ORAS',
415232: 'XY',
[232 * 30 * 32]: 'YABD',
[232 * 30 * 31]: 'PCDATA',
458752: 'ORASRAM'
};

module.exports = saveFile => {
for (const fileType of ['ORAS', 'XY', 'YABD', 'PCDATA', 'XYRAM', 'ORASRAM']) {
const pk6Files = new SaveReaderDecrypted(saveFile, fileType).getAllPkx();
if (pk6Files.length) return pk6Files.map(file => file.data);
if (saveFile.length === 2 ** 20 + 156 || saveFile.length === 2 ** 20 + 410) {
saveFile = saveFile.subarray(-(2 ** 20));
}
const fileType = FILE_SIZES[saveFile.length];
if (fileType) return new SaveReaderDecrypted(saveFile, fileType).getAllPkx().map(pkx => pkx.data);
return [];
};
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -17,6 +17,7 @@
"babel-eslint": "^6.0.2",
"babel-plugin-lodash": "^3.1.4",
"babel-plugin-transform-async-to-generator": "^6.7.4",
"babel-plugin-transform-exponentiation-operator": "^6.8.0",
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babelify": "^7.2.0",
Expand Down

0 comments on commit e27cc55

Please sign in to comment.