Created
July 17, 2023 06:35
-
-
Save kion-dgl/678769fa54d881b2d31b2dde88f6583b to your computer and use it in GitHub Desktop.
Decompresses a pcsxr save state, pulls out the memory into it's own file, and any time that memory file is edited, the save ste is updated with new memory.
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
// Imports | |
const { readFileSync, writeFileSync, watchFile } = require('fs') | |
const { gunzipSync, gzipSync } = require('zlib') | |
// Constants | |
const dir = "/home/benjamin/.pcsxr/sstates" | |
const src = "MEGAMAN_LEGENDS2-SLUS01140.002" | |
const dst = "MEGAMAN_LEGENDS2-SLUS01140.004" | |
const memPath = "./mem.bin" | |
// Read the save state | |
const compressedState = readFileSync(`${dir}/${src}`); | |
// Make a copy of the original | |
writeFileSync(`${dir}/${dst}`, compressedState); | |
// Decompress the state | |
const decompressedState = gunzipSync(compressedState); | |
// Split the memory into it's own file | |
const mem_len = 0x200000; | |
const mem_ofs = 0x9025; | |
const mem = decompressedState.slice(mem_ofs, mem_ofs + mem_len); | |
// Write the memory to it's own file | |
writeFileSync(memPath, mem); | |
// Set up a watcher to check for changes | |
const interval = 100; | |
const options = { interval } | |
watchFile(memPath, () => { | |
console.log("File updated"); | |
const updatedMem = readFileSync(memPath) | |
decompressedState.set(updatedMem, mem_ofs) | |
const updatedState = gzipSync(decompressedState) | |
writeFileSync(`${dir}/${dst}`, updatedState); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment