Skip to content

Commit 8415566

Browse files
Tim Winchestertimsama
authored andcommitted
added commands to check offsets for ascii/write ascii at an offset
1 parent f258f5d commit 8415566

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

cmd/check-ascii-cmd.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const offsetChecker = require('../lib/offset-checker.js');
2+
const saveFileUtils = require('../util/save-file-utils.js');
3+
const CONFIG = require('../config.json');
4+
5+
const offset = parseInt(process.argv[2]);
6+
const length = parseInt(process.argv[3]);
7+
const offsets = Array.apply(0, new Array(length)).map((e, i) => i * 8 + offset);
8+
const saveFilepath = `${CONFIG.savepath}game_data.sav`;
9+
10+
const values = offsets.map((offset) => offsetChecker(offset, saveFilepath));
11+
const hexStrings = values.map((value) => saveFileUtils.toHexString(value));
12+
const codes = [];
13+
hexStrings.forEach((hexString) => {
14+
hexString.split('').reduce((prev, next) => {
15+
if (prev && next) {
16+
codes.push(`0x${prev}${next}`);
17+
return undefined;
18+
} else {
19+
return next;
20+
}
21+
}, undefined)
22+
});
23+
const chars = codes.map((code) => String.fromCharCode(code));
24+
console.log(chars.join(''));

cmd/set-ascii-cmd.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const offsetSetter = require('../lib/offset-setter.js');
2+
const saveFileUtils = require('../util/save-file-utils.js');
3+
const CONFIG = require('../config.json');
4+
5+
const offset = parseInt(process.argv[2]);
6+
const words = parseInt(process.argv[3]);
7+
const text = process.argv[4];
8+
const offsets = Array.apply(0, new Array(words)).map((e, i) => i * 8 + offset);
9+
const codes = text.split('').map((char) => {
10+
const code = char.charCodeAt(0);
11+
const hexCode = code.toString(16);
12+
return hexCode;
13+
});
14+
const saveFilepath = `${CONFIG.savepath}game_data.sav`;
15+
16+
const entries = [];
17+
const remainder = codes.reduce((acc, next) => {
18+
if (acc.length === 6) {
19+
const entry = acc + next;
20+
entries.push(entry);
21+
return '';
22+
} else {
23+
return acc + next;
24+
}
25+
}, '');
26+
if (remainder.length > 0) {
27+
const padCount = 8 - remainder.length;
28+
const pad = new Array(padCount + 1).join('0');
29+
const entry = remainder + pad;
30+
entries.push(entry);
31+
}
32+
33+
// ensure offsets are clean in case the new string is shorter than the previous one
34+
offsets.forEach((offset) => offsetSetter(offset, 0, saveFilepath));
35+
36+
entries.forEach((entry, i) => {
37+
const offset = offsets[i];
38+
offsetSetter(offset, parseInt(entry, 16), saveFilepath);
39+
});

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"build-raw-changes-from-snapshots": "node cmd/build-raw-changes-from-snapshots-cmd.js",
2424
"build-hex-view": "node cmd/build-hex-view.js",
2525
"check-all-item-slots": "node cmd/check-all-item-slots-cmd.js",
26+
"check-ascii-at-offset": "node cmd/check-ascii-cmd.js",
2627
"check-offset": "node cmd/offset-checker-cmd.js",
2728
"check-item-slot": "node cmd/check-item-slot-cmd.js",
2829
"create-blank-snapshot": "node cmd/create-blank-snapshot-cmd.js",
@@ -45,6 +46,7 @@
4546
"quest-analyzer": "node cmd/quest-analyzer-cmd.js",
4647
"read-changes": "node cmd/read-changes-cmd.js",
4748
"restore-backup": "node cmd/restore-backup-cmd.js",
49+
"set-ascii-at-offset": "node cmd/set-ascii-cmd.js",
4850
"set-hearts": "node cmd/set-hearts-cmd.js",
4951
"set-rupees": "node cmd/set-rupees-cmd.js",
5052
"set-stamina": "node cmd/set-stamina-cmd.js",

0 commit comments

Comments
 (0)