forked from TheBrain0110/oni-item-processor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regolate.js
71 lines (61 loc) · 2.03 KB
/
regolate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const {
readFileSync,
writeFileSync
} = require("fs");
const {
parseSaveGame,
writeSaveGame
} = require("oni-save-parser");
// Put the name of your save file here
const savename = "Regolith"
function loadFile(fileName) {
const fileData = readFileSync(`./${fileName}.sav`);
return parseSaveGame(fileData.buffer);
}
function saveFile(fileName, save) {
const fileData = writeSaveGame(save);
writeFileSync(`./${fileName}.sav`, new Uint8Array(fileData));
console.log("Save File Written");
}
function modifyItems(itemName, newMass, newTemp) {
const items = saveData.gameObjects.find(x => x.name === itemName);
for (const item of items.gameObjects) {
var element = item.behaviors.find(x => x.name === "PrimaryElement");
if (newMass) {element.templateData.Units = newMass;}
if (newTemp) {element.templateData._Temperature = newTemp;}
}
console.log(`${itemName} Processed`)
}
function checkItems(itemName) {
const items = saveData.gameObjects.find(x => x.name === itemName);
for (const item of items.gameObjects) {
var element = item.behaviors.find(x => x.name === "PrimaryElement");
var mass = element.templateData.Units;
var temp = element.templateData._Temperature;
console.log(`${itemName} Mass: ${mass}`);
console.log(`${itemName} Temp: ${temp}`);
}
}
function printDataStructure(itemName) {
const items = saveData.gameObjects.find(x => x.name === itemName);
for (const item of items.gameObjects) {
console.log(`\n${itemName}`);
console.log(item.behaviors);
}
}
const saveData = loadFile(savename);
console.log("Save File Parsed");
modifyItems("Regolith", 1, 10);
checkItems("Regolith");
modifyItems("BunkerTile", null, 100);
checkItems("BunkerTile");
modifyItems("ExteriorWall", null, 100);
checkItems("ExteriorWall");
modifyItems("SolarPanel", null, 100);
checkItems("SolarPanel");
//printDataStructure("SolarPanel");
modifyItems("Iron", null, 200)
modifyItems("BunkerDoor", null, 100)
modifyItems("GlassTile", null, 100)
printDataStructure("BunkerDoor");
saveFile(`${savename}-pruned`, saveData);