Last active
June 26, 2024 17:50
-
-
Save Kiritow/f85680cdb21a7053a95277bada5f9995 to your computer and use it in GitHub Desktop.
oni-mod-list-syncer
This file contains hidden or 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 { readFileSync, writeFileSync } = require("fs"); | |
const { parseSaveGame } = require('oni-save-parser'); | |
const modsFileContent = JSON.parse(readFileSync('mods.json', { | |
encoding: 'utf-8', | |
})) | |
console.log('parsing game... (this might take a while)') | |
const gameSave = parseSaveGame(readFileSync('QueencardWorld5.sav').buffer, { | |
versionStrictness: 'none' | |
}) | |
const gameActiveMods = gameSave.world.active_mods | |
const steamMods = modsFileContent.mods | |
const gameActiveModIds = gameActiveMods.map(m => m.id) | |
const steamModIds = steamMods.map(m => m.label.id) | |
const missingMods = gameActiveModIds.filter(id => steamModIds.indexOf(id) == -1).map(id => gameActiveMods[gameActiveMods.findIndex(m => m.id == id)]) | |
if (missingMods.length > 0) { | |
console.log('The following mods are missing, please install/subscribe from Steam') | |
console.log(missingMods) | |
process.exit(1) | |
} | |
console.log(steamMods.map(m => m.label.title)) | |
steamMods.sort((a, b) => { | |
const modIDA = a.label.id | |
const modIDB = b.label.id | |
const indexA = gameActiveModIds.indexOf(modIDA) | |
const indexB = gameActiveModIds.indexOf(modIDB) | |
// put active mods before inactive mods | |
if (indexA != -1 && indexB != -1) { | |
return indexA - indexB | |
} | |
if (indexA != -1) { | |
return -1 | |
} | |
if (indexB != -1) { | |
return 1 | |
} | |
// sort inactive mods by name | |
return a.label.title.toLowerCase().localeCompare(b.label.title.toLowerCase()) | |
}) | |
console.log(steamMods.map(m => m.label.title)) | |
gameActiveModIds.forEach(modID => { | |
const currentMod = steamMods[steamModIds.indexOf(modID)] | |
if (!currentMod.enabled) { | |
console.log(`Enable mod ${currentMod.label.title}`) | |
currentMod.enabled = true | |
} | |
}) | |
console.log('saving to mods.json...') | |
writeFileSync('mods.json', JSON.stringify(modsFileContent, null, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment