230 lines
9.2 KiB
JavaScript
230 lines
9.2 KiB
JavaScript
// Simple script to extract all game data using global variables
|
|
// Paste this into the developer console (F12) while the game is running
|
|
|
|
(function() {
|
|
console.log('Starting data extraction...');
|
|
|
|
// Create extraction folder
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const extractPath = path.join(process.cwd(), 'package.nw', 'extracted_data');
|
|
|
|
if (!fs.existsSync(extractPath)) {
|
|
fs.mkdirSync(extractPath, { recursive: true });
|
|
console.log('Created extraction folder:', extractPath);
|
|
}
|
|
|
|
// Map of global variables to filenames
|
|
const dataMap = {
|
|
// Standard RPG Maker data
|
|
'$dataActors': 'Actors.json',
|
|
'$dataAnimations': 'Animations.json',
|
|
'$dataArmors': 'Armors.json',
|
|
'$dataClasses': 'Classes.json',
|
|
'$dataCommonEvents': 'CommonEvents.json',
|
|
'$dataEnemies': 'Enemies.json',
|
|
'$dataItems': 'Items.json',
|
|
'$dataMapInfos': 'MapInfos.json',
|
|
'$dataSkills': 'Skills.json',
|
|
'$dataStates': 'States.json',
|
|
'$dataTilesets': 'Tilesets.json',
|
|
'$dataTroops': 'Troops.json',
|
|
'$dataWeapons': 'Weapons.json'
|
|
};
|
|
|
|
// Custom game data mappings from plugins.js
|
|
const customDataMap = {
|
|
// Based on CustomData plugin configuration
|
|
'gallery': 'Gallery.json',
|
|
'db_1': 'DB_enmt.json',
|
|
'msg_1': 'MSG_enmt.json',
|
|
'testScenario': 'testScenario.json',
|
|
'areaName': 'Area.json',
|
|
'scnText': 'StartAndEnd.json',
|
|
'credits': 'CreditList.json',
|
|
'frames': 'Frames.json',
|
|
'destinations': 'Destinations.json'
|
|
};
|
|
|
|
// Try additional possible variable names
|
|
const additionalVars = [
|
|
'TrpParticleGroups', 'TrpParticles'
|
|
];
|
|
|
|
let extractedCount = 0;
|
|
let failedCount = 0;
|
|
const results = [];
|
|
|
|
console.log('\nExtracting data from global variables...');
|
|
console.log('='.repeat(50));
|
|
|
|
// Extract standard RPG Maker data
|
|
Object.entries(dataMap).forEach(([varName, filename]) => {
|
|
try {
|
|
const data = window[varName];
|
|
|
|
if (data !== undefined && data !== null) {
|
|
console.log(`Extracting: ${filename} from ${varName}`);
|
|
|
|
const outputPath = path.join(extractPath, filename);
|
|
const jsonContent = JSON.stringify(data, null, 2);
|
|
fs.writeFileSync(outputPath, jsonContent, 'utf8');
|
|
|
|
extractedCount++;
|
|
const size = Array.isArray(data) ? data.length : Object.keys(data).length;
|
|
results.push(`✓ ${filename} - Success (${size} entries)`);
|
|
console.log(`✓ Extracted: ${filename}`);
|
|
} else {
|
|
results.push(`⚠ ${filename} - Skipped (variable not loaded)`);
|
|
console.log(`⚠ Skipped: ${filename} (${varName} not available)`);
|
|
}
|
|
|
|
} catch (error) {
|
|
failedCount++;
|
|
results.push(`✗ ${filename} - Failed: ${error.message}`);
|
|
console.error(`✗ Failed to extract ${filename}:`, error);
|
|
}
|
|
});
|
|
|
|
// Extract custom game data (these might be in $gameSystem or other locations)
|
|
Object.entries(customDataMap).forEach(([propName, filename]) => {
|
|
try {
|
|
// Try multiple possible locations for custom data
|
|
let data = null;
|
|
const possibleLocations = [
|
|
() => window[propName],
|
|
() => window['$data' + propName],
|
|
() => window['$gameSystem'] && window['$gameSystem'][propName],
|
|
() => window['$gameTemp'] && window['$gameTemp'][propName],
|
|
() => window['$gameVariables'] && window['$gameVariables'][propName]
|
|
];
|
|
|
|
for (const getLocation of possibleLocations) {
|
|
try {
|
|
const locationData = getLocation();
|
|
if (locationData !== undefined && locationData !== null) {
|
|
data = locationData;
|
|
break;
|
|
}
|
|
} catch (e) {
|
|
// Continue to next location
|
|
}
|
|
}
|
|
|
|
if (data !== null) {
|
|
console.log(`Extracting: ${filename} from custom data (${propName})`);
|
|
|
|
const outputPath = path.join(extractPath, filename);
|
|
const jsonContent = JSON.stringify(data, null, 2);
|
|
fs.writeFileSync(outputPath, jsonContent, 'utf8');
|
|
|
|
extractedCount++;
|
|
const size = Array.isArray(data) ? data.length : Object.keys(data).length;
|
|
results.push(`✓ ${filename} - Success (${size} entries)`);
|
|
console.log(`✓ Extracted: ${filename}`);
|
|
} else {
|
|
results.push(`⚠ ${filename} - Skipped (custom data not found)`);
|
|
console.log(`⚠ Skipped: ${filename} (${propName} not available)`);
|
|
}
|
|
|
|
} catch (error) {
|
|
failedCount++;
|
|
results.push(`✗ ${filename} - Failed: ${error.message}`);
|
|
console.error(`✗ Failed to extract ${filename}:`, error);
|
|
}
|
|
});
|
|
|
|
// Try additional variables that might exist
|
|
additionalVars.forEach(varName => {
|
|
try {
|
|
const filename = varName + '.json';
|
|
const possibleVars = [`$data${varName}`, varName, `$gameSystem.${varName}`];
|
|
|
|
for (const testVar of possibleVars) {
|
|
try {
|
|
let data;
|
|
if (testVar.includes('.')) {
|
|
const parts = testVar.split('.');
|
|
data = window[parts[0]] && window[parts[0]][parts[1]];
|
|
} else {
|
|
data = window[testVar];
|
|
}
|
|
|
|
if (data !== undefined && data !== null) {
|
|
console.log(`Extracting: ${filename} from ${testVar}`);
|
|
|
|
const outputPath = path.join(extractPath, filename);
|
|
const jsonContent = JSON.stringify(data, null, 2);
|
|
fs.writeFileSync(outputPath, jsonContent, 'utf8');
|
|
|
|
extractedCount++;
|
|
const size = Array.isArray(data) ? data.length : Object.keys(data).length;
|
|
results.push(`✓ ${filename} - Success (${size} entries)`);
|
|
console.log(`✓ Extracted: ${filename}`);
|
|
break;
|
|
}
|
|
} catch (e) {
|
|
// Continue to next variable
|
|
}
|
|
}
|
|
} catch (error) {
|
|
console.log(`Note: ${varName} not available or failed to extract`);
|
|
}
|
|
});
|
|
|
|
// Try to extract CSV files if they exist as global variables
|
|
const csvVars = ['$dataExternMessage_ab003'];
|
|
csvVars.forEach(varName => {
|
|
try {
|
|
const data = window[varName];
|
|
if (data !== undefined && data !== null) {
|
|
const filename = varName.replace('$data', '') + '.csv';
|
|
console.log(`Extracting CSV: ${filename} from ${varName}`);
|
|
|
|
const outputPath = path.join(extractPath, filename);
|
|
let csvContent;
|
|
|
|
if (Array.isArray(data)) {
|
|
csvContent = data.join('\n');
|
|
} else {
|
|
csvContent = JSON.stringify(data, null, 2);
|
|
}
|
|
|
|
fs.writeFileSync(outputPath, csvContent, 'utf8');
|
|
extractedCount++;
|
|
results.push(`✓ ${filename} - Success`);
|
|
console.log(`✓ Extracted: ${filename}`);
|
|
}
|
|
} catch (error) {
|
|
console.log(`Note: ${varName} not available or failed to extract`);
|
|
}
|
|
});
|
|
|
|
// Summary
|
|
console.log('\n' + '='.repeat(50));
|
|
console.log('EXTRACTION SUMMARY:');
|
|
console.log('='.repeat(50));
|
|
const totalAttempted = Object.keys(dataMap).length + Object.keys(customDataMap).length + additionalVars.length;
|
|
console.log(`Total attempted: ${totalAttempted}`);
|
|
console.log(`Successfully extracted: ${extractedCount}`);
|
|
console.log(`Failed: ${failedCount}`);
|
|
console.log(`Output folder: ${extractPath}`);
|
|
|
|
console.log('\nDetailed results:');
|
|
results.forEach(result => console.log(result));
|
|
|
|
if (extractedCount > 0) {
|
|
console.log(`\n🎉 Extraction complete! Check the 'extracted_data' folder for your files.`);
|
|
console.log(`📁 Path: ${extractPath}`);
|
|
} else {
|
|
console.log('\n❌ No files were successfully extracted. Make sure you are in the game and data is loaded.');
|
|
}
|
|
|
|
return {
|
|
success: extractedCount,
|
|
failed: failedCount,
|
|
total: totalAttempted,
|
|
outputPath: extractPath,
|
|
results: results
|
|
};
|
|
})();
|