2024-10-08 13:18:55 +02:00
|
|
|
#!/usr/bin/env node
|
2024-08-09 19:30:49 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
CLI implementation for Rom Patcher JS
|
|
|
|
https://github.com/marcrobledo/RomPatcher.js
|
|
|
|
by Marc Robledo, released under MIT license: https://github.com/marcrobledo/RomPatcher.js/blob/master/LICENSE
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
Install needed dependencies:
|
|
|
|
> npm install
|
|
|
|
|
|
|
|
Patch a ROM:
|
|
|
|
> node index.js patch "my_rom.bin" "my_patch.ips"
|
|
|
|
|
|
|
|
Create a patch from two ROMs:
|
|
|
|
> node index.js create "original_rom.bin" "modified_rom.bin"
|
|
|
|
|
|
|
|
For more options:
|
|
|
|
> node index.js patch --help
|
|
|
|
> node index.js create --help
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
const chalk=require('chalk');
|
|
|
|
const { program } = require('commander')
|
2024-09-15 07:39:11 +01:00
|
|
|
const RomPatcher = require('./rom-patcher-js/RomPatcher');
|
2024-08-09 19:30:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
program
|
|
|
|
.command('patch')
|
|
|
|
.description('patches a ROM')
|
|
|
|
.argument('<rom_file>','the ROM file that will be patched')
|
|
|
|
.argument('<patch_file>', 'the patch to apply')
|
|
|
|
.option('-v, --validate-checksum','should validate checksum')
|
|
|
|
.option('-h1, --add-header','adds a temporary header to the provided ROM for patches that require headered ROMs')
|
|
|
|
.option('-h0, --remove-header','removes ROM header temporarily for patches that require headerless ROMs')
|
|
|
|
.option('-f, --fix-checksum','fixes any known ROM header checksum if possible')
|
|
|
|
.option('-s, --output-suffix','add a (patched) suffix to output ROM file name')
|
|
|
|
.action(function(romPath, patchPath, options) {
|
|
|
|
try{
|
|
|
|
const romFile=new BinFile(romPath);
|
|
|
|
const patchFile=new BinFile(patchPath);
|
|
|
|
|
|
|
|
const patch=RomPatcher.parsePatchFile(patchFile);
|
|
|
|
if(!patch)
|
|
|
|
throw new Error('Invalid patch file');
|
|
|
|
|
|
|
|
const patchedRom=RomPatcher.applyPatch(romFile, patch, options);
|
|
|
|
patchedRom.save();
|
|
|
|
console.log(chalk.green('successfully saved to ' + patchedRom.fileName));
|
|
|
|
}catch(err){
|
|
|
|
console.log(chalk.bgRed('error: ' + err.message));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
program
|
|
|
|
.command('create')
|
|
|
|
.description('creates a patch based on two ROMs')
|
|
|
|
.argument('<original_rom_file>', 'the original ROM')
|
|
|
|
.argument('<modified_rom_file>','the modified ROM')
|
2025-04-27 17:43:07 +09:30
|
|
|
.option('-f, --format <format>','patch format (allowed values: ips [default], bps, ppf, ups, aps, rup, ebp)')
|
2024-08-09 19:30:49 +02:00
|
|
|
.action(function(originalRomPath, modifiedRomPath, options) {
|
2024-10-08 13:54:57 +02:00
|
|
|
console.log(options);
|
2024-08-09 19:30:49 +02:00
|
|
|
try{
|
|
|
|
const originalFile=new BinFile(originalRomPath);
|
|
|
|
const modifiedFile=new BinFile(modifiedRomPath);
|
|
|
|
|
|
|
|
const patch=RomPatcher.createPatch(originalFile, modifiedFile, options.format);
|
2024-10-08 13:54:57 +02:00
|
|
|
const patchFile=patch.export();
|
|
|
|
patchFile.setName(modifiedFile.getName());
|
|
|
|
patchFile.save();
|
2024-08-09 19:30:49 +02:00
|
|
|
}catch(err){
|
|
|
|
console.log(chalk.bgBlue('Error: ' + err.message));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
program.parse()
|