Last active
August 6, 2020 16:33
-
-
Save MestreKarin/240f7319ddff996ca568dc93ef0c9592 to your computer and use it in GitHub Desktop.
Little cheat to warstone td game.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const readline = require('readline'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
function readFile(path) { | |
return new Promise((resolve, reject) => { | |
fs.readFile(path, 'utf8', (err, data) => { | |
if (err) { | |
return reject(err); | |
} | |
try { | |
data = JSON.parse(data); | |
} catch { | |
data = null; | |
} | |
return resolve(data); | |
}); | |
}); | |
} | |
function readPath(path) { | |
return new Promise((resolve, reject) => { | |
fs.readdir(path, (err, files) => { | |
if (err) { | |
return reject(err); | |
} | |
return resolve(files); | |
}); | |
}); | |
} | |
function writeFile(path, data) { | |
return new Promise((resolve, reject) => { | |
fs.writeFile(path, data, 'utf8', (err) => { | |
if (err) { | |
return reject(err); | |
} | |
return resolve(); | |
}); | |
}); | |
} | |
const cheat = { | |
sheet: {}, | |
isMap: function(obj) { | |
let defs = ['map', 'waves', 'gold', 'stone_count']; | |
for (let i = 0; i < defs.length; i++) { | |
if (obj[defs[i]] === undefined) { | |
return false; | |
} | |
} | |
return true; | |
}, | |
readSheet: async function(path) { | |
let cf = await readFile(`${path}/cheat.json`); | |
if (cf) { | |
cheat.sheet = cf; | |
} | |
}, | |
updateConfig: async function(path) { | |
// Update magics and scrolls. | |
let config = await readFile(`${path}/config.txt`); | |
if (config) { | |
// Update magics. | |
console.log('[*] Updating magics'); | |
config.magics.forEach(m => { | |
if (m.cost !== undefined) { | |
m.cost = 0; | |
} | |
if (m.cd !== undefined) { | |
m.cd = 500; | |
} | |
if (m.levels !== undefined && m.levels.length > 0) { | |
m.levels.forEach(lv => { | |
if (lv.cost !== undefined) { | |
lv.cost = 0; | |
} | |
if (lv.cd !== undefined) { | |
lv.cd = 500; | |
} | |
}); | |
} | |
if (cheat.sheet.magics !== undefined && cheat.sheet.magics[m.eng_name] !== undefined) { | |
for (let k in cheat.sheet.magics[m.eng_name]) { | |
if (m[k] !== undefined) { | |
m[k] = cheat.sheet.magics[m.eng_name][k]; | |
} | |
if (m.levels !== undefined && m.levels.length > 0) { | |
m.levels.forEach(lv => { | |
if (lv[k] !== undefined) { | |
lv[k] = cheat.sheet.magics[m.eng_name][k]; | |
} | |
}); | |
} | |
} | |
} | |
}); | |
// Update scrolls receive count. | |
config.inv_items.forEach(m => { | |
if (m.eng_name.indexOf('Scroll of') >= 0) { | |
m.v2 = 100; | |
} | |
if (cheat.sheet.inv_items !== undefined && cheat.sheet.inv_items[m.eng_name] !== undefined) { | |
let csi = cheat.sheet.inv_items[m.eng_name]; | |
for (let k in csi) { | |
if (m[k] !== undefined) { | |
m[k] = csi[k]; | |
} | |
if (m.levels !== undefined) { | |
m.levels.forEach(lv => { | |
if (lv[k] !== undefined) { | |
lv[k] = csi[k]; | |
} | |
}); | |
} | |
} | |
} | |
}); | |
// Update tower build time. | |
console.log('[*] Updating towers'); | |
config.towers.forEach(tw => { | |
tw.buildtime = 500; | |
}); | |
await writeFile(`${path}/config.txt`, JSON.stringify(config)); | |
config = {}; | |
} | |
}, | |
updateMaps: async function(path) { | |
let files = await readPath(path); | |
for (let i = 0; i < files.length; i++) { | |
if (!files[i].endsWith('.txt')) { | |
continue; | |
} | |
let data = await readFile(`${path}/${files[i]}`); | |
if (!data || !cheat.isMap(data)) { | |
continue; | |
} | |
data.stone_count = 30; | |
data.gold = 15000; | |
await writeFile(`${path}/${files[i]}`, JSON.stringify(data)); | |
} | |
} | |
} | |
rl.question('Warstone path: ', async path => { | |
let basePath = `${path}/configs`; | |
let levelsPath = `${basePath}/levels`; | |
await cheat.readSheet(path); | |
// Update maps. | |
console.log('[*] Updating maps'); | |
await cheat.updateMaps(basePath); | |
await cheat.updateMaps(levelsPath); | |
// Update config. | |
await cheat.updateConfig(basePath); | |
// Done. | |
console.log('Done!'); | |
rl.close(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment