Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Ludicrous
Path: blob/main/public/webretro/utils/romshift.js
1224 views
1
// node.js tool
2
3
const fs = require("fs");
4
const args = process.argv.slice(2);
5
6
if (!args[0] || !parseInt(args[0])) throw "Argument 0 needs to be the number to shift";
7
8
var romshift = parseInt(args[0]);
9
var romloc = args[1] || "../roms/";
10
11
function getChildFiles(dir) {
12
var children = fs.readdirSync(dir);
13
var files = [];
14
for (var i = 0; i < children.length; i++) {
15
if (!fs.statSync(dir + children[i]).isDirectory()) files.push(children[i]);
16
}
17
return files;
18
}
19
20
function avShift(array, shift) {
21
for (var i = 0; i < array.length; i++) {
22
array[i] += shift;
23
}
24
return array;
25
}
26
27
var roms = getChildFiles(romloc);
28
29
for (var i = 0; i < roms.length; i++) {
30
fs.writeFileSync(romloc + roms[i], Buffer.from(avShift(new Uint8Array(fs.readFileSync(romloc + roms[i])), romshift)));
31
}
32
33
console.log("Done");
34
console.log(roms);
35
36