Skip to content

Instantly share code, notes, and snippets.

@MarvNC
Last active March 21, 2024 06:06
Show Gist options
  • Save MarvNC/69968757ae8f1cc8808fab882861d66d to your computer and use it in GitHub Desktop.
Save MarvNC/69968757ae8f1cc8808fab882861d66d to your computer and use it in GitHub Desktop.
寄甡 Symbiotic Love Script Dump

For 寄甡 (Symbiotic Love)

  • Use asar to extract files in resources
  • Run dump.js in the script folder
  • Scripts will be dumped in script/out

Download scripts zip

const fs = require('fs').promises;
const path = require('path');
const outDir = './out';
async function readAndParseJSON() {
try {
const files = await fs.readdir('./');
for (const file of files) {
const data = await fs.readFile(file, 'utf8');
let jsonData;
try {
jsonData = JSON.parse(data);
// console.log(`JSON data from ${file}:`, jsonData);
} catch (error) {
// console.error(`Error parsing JSON from ${file}:`, error);
}
const script = readPossibleScriptJSON(jsonData);
// If script exists, write it as a txt file
if (script) {
let filename = `${script.id}${script.title ? `-${script.title}` : ''}`;
// Append length to filename
filename += `-${script.lines.length}`;
// Replace invalid characters
filename = filename.replace(/[\\/:*?"<>|]/g, '');
// Create outDir if it doesn't exist
try {
await fs.access(outDir);
} catch (error) {
await fs.mkdir(outDir);
}
const filepath = path.join(outDir, `${filename}.txt`);
await fs.writeFile(filepath, script.lines, 'utf8');
console.log(`Script written to filepath: ${filepath}`);
}
}
} catch (err) {
console.error('Error reading directory:', err);
}
}
readAndParseJSON();
/**
* Check if it's a script, return script text if so
* @param {*} data
*/
function readPossibleScriptJSON(data) {
const lines = [];
// Check if data is array
if (!Array.isArray(data)) {
return null;
}
const id = data[0][3].id;
const title = data[0][3].title;
for (const line of data) {
if (line && line[3] && line[3].text) {
lines.push(line[3].text);
}
}
if (lines.length > 0) {
return {
id,
title,
lines: lines.join('\n'),
};
} else {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment