Skip to content

Commit

Permalink
add code (non-functional)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenni009 committed Feb 16, 2024
1 parent 710d823 commit 53fd4c5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.exe
saves
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"deno.enable": true
}
42 changes: 42 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Buffer } from "https://deno.land/std@0.141.0/node/buffer.ts";
import lz4 from "npm:lz4";

function decompressSave(file: Uint8Array) {
const buf = Buffer.from(file);

let index = 0;
const chunks = [];

while (index < buf.length) {
const magic = buf.readUIntLE(index, 4);
index += 4;

if (magic !== 0xfeeda1e5) {
console.error("Invalid Block assuming already decompressed");
return buf.toString("binary");
}

const compressedSize = buf.readUIntLE(index, 4);
index += 4;
const uncompressedSize = buf.readUIntLE(index, 4);
index += 4;

index += 4; // skip 4 bytes

const output = Buffer.alloc(uncompressedSize);
lz4.decodeBlock(buf, output, index, index + compressedSize);
index += compressedSize;

chunks.push(output);
}

return Buffer.concat(chunks).toString("binary").slice(0, -1);
}

const filePath = Deno.args[0];

const file = Deno.readFileSync(filePath);

const decompressedFile = decompressSave(file);

Deno.writeTextFileSync('result.json', decompressedFile);

0 comments on commit 53fd4c5

Please sign in to comment.