romshift.js 822 B

12345678910111213141516171819202122232425262728293031323334
  1. // node.js tool
  2. const fs = require("fs");
  3. const args = process.argv.slice(2);
  4. if (!args[0] || !parseInt(args[0])) throw "Argument 0 needs to be the number to shift";
  5. var romshift = parseInt(args[0]);
  6. var romloc = args[1] || "./roms/";
  7. function getChildFiles(dir) {
  8. var children = fs.readdirSync(dir);
  9. var files = [];
  10. for (var i = 0; i < children.length; i++) {
  11. if (!fs.statSync(dir + children[i]).isDirectory()) files.push(children[i]);
  12. }
  13. return files;
  14. }
  15. function avShift(array, shift) {
  16. for (var i = 0; i < array.length; i++) {
  17. array[i] += shift;
  18. }
  19. return array;
  20. }
  21. var roms = getChildFiles(romloc);
  22. for (var i = 0; i < roms.length; i++) {
  23. fs.writeFileSync(romloc + roms[i], Buffer.from(avShift(new Uint8Array(fs.readFileSync(romloc + roms[i])), romshift)));
  24. }
  25. console.log("Done");
  26. console.log(roms);