1
0
Fork 0
mirror of https://github.com/marcrobledo/RomPatcher.js.git synced 2025-06-27 16:25:54 +00:00

patch builder can now set metadata information to RUP and EBP patches

This commit is contained in:
Marc Robledo 2025-04-30 11:39:23 +02:00
parent 72e62674ae
commit 1e8c2060f9
7 changed files with 70 additions and 16 deletions

View file

@ -230,7 +230,7 @@ const RomPatcher = (function () {
return patchedRom;
},
createPatch: function (originalFile, modifiedFile, format) {
createPatch: function (originalFile, modifiedFile, format, metadata) {
if (!(originalFile instanceof BinFile))
throw new Error('Original ROM file is not an instance of BinFile');
else if (!(modifiedFile instanceof BinFile))
@ -253,9 +253,10 @@ const RomPatcher = (function () {
} else if (format === 'aps') {
patch = APS.buildFromRoms(originalFile, modifiedFile);
} else if (format === 'rup') {
patch = RUP.buildFromRoms(originalFile, modifiedFile);
if(metadata)
patch = RUP.buildFromRoms(originalFile, modifiedFile, metadata && metadata.Description? metadata.Description : null);
} else if (format === 'ebp') {
patch = IPS.buildFromRoms(originalFile, modifiedFile, true);
patch = IPS.buildFromRoms(originalFile, modifiedFile, metadata);
} else {
throw new Error('Invalid patch format');
}

View file

@ -7,7 +7,7 @@
*
* MIT License
*
* Copyright (c) 2016-2024 Marc Robledo
* Copyright (c) 2016-2025 Marc Robledo
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -1559,6 +1559,23 @@ const PatchBuilderWeb = (function (romPatcherWeb) {
}
};
const _getMetadataFields = function (patchFormat) {
if (patchFormat === 'rup') {
return ['Description'];
} else if (patchFormat === 'ebp') {
return ['Author', 'Title', 'Description'];
}
return [];
};
const _buildMetadataObject = function (patchFormat) {
return _getMetadataFields(patchFormat).reduce((metadata, field) => {
const input = document.getElementById('patch-builder-input-metadata-' + field.toLowerCase().replace(/\s+/g, '-'));
if (input && input.value.trim())
metadata[field] = input.value.trim();
return metadata;
}, {});
};
var webWorkerCreate;
var initialized = false;
@ -1644,18 +1661,35 @@ const PatchBuilderWeb = (function (romPatcherWeb) {
_setToastError(_('Patch creation is not compatible with zipped ROMs'), 'warning');
});
});
document.getElementById('patch-builder-select-patch-type').addEventListener('change', function () {
if (!document.getElementById('patch-builder-container-metadata-inputs'))
return;
document.getElementById('patch-builder-container-metadata-inputs').innerHTML = '';
_getMetadataFields(this.value).forEach(function (field) {
const input = document.createElement('input');
input.id = 'patch-builder-input-metadata-' + field.toLowerCase().replace(/\s+/g, '-');
input.className = 'patch-builder-input-metadata';
input.type = 'text';
input.placeholder = _(field);
document.getElementById('patch-builder-container-metadata-inputs').appendChild(input);
});
});
document.getElementById('patch-builder-button-create').addEventListener('click', function () {
const patchFormat=document.getElementById('patch-builder-select-patch-type').value;
_setElementsStatus(false);
_setCreateButtonSpinner(true);
webWorkerCreate.postMessage(
{
originalRomU8Array: originalRom._u8array,
modifiedRomU8Array: modifiedRom._u8array,
format: document.getElementById('patch-builder-select-patch-type').value
format: patchFormat,
metadata: _buildMetadataObject(patchFormat)
}, [
originalRom._u8array.buffer,
modifiedRom._u8array.buffer
]
originalRom._u8array.buffer,
modifiedRom._u8array.buffer
]
);
});
@ -1780,6 +1814,9 @@ const ROM_PATCHER_LOCALE = {
'Modified ROM:': 'ROM modificada:',
'Patch type:': 'Tipo de parche:',
'Creating patch...': 'Creando parche...',
'Author': 'Autor',
'Title': 'Título',
'Description': 'Descripción',
'Source ROM checksum mismatch': 'Checksum de ROM original no válida',
'Target ROM checksum mismatch': 'Checksum de ROM creada no válida',
@ -1914,6 +1951,9 @@ const ROM_PATCHER_LOCALE = {
'Modified ROM:': 'ROM modificada:',
'Patch type:': 'Tipus de pedaç:',
'Creating patch...': 'Creant pedaç...',
'Author': 'Autor',
'Title': 'Títol',
'Description': 'Descripció',
'Source ROM checksum mismatch': 'Checksum de ROM original no vàlida',
'Target ROM checksum mismatch': 'Checksum de ROM creada no vàlida',

View file

@ -17,8 +17,9 @@ self.onmessage = event => { // listen for messages from the main thread
const originalFile=new BinFile(event.data.originalRomU8Array);
const modifiedFile=new BinFile(event.data.modifiedRomU8Array);
const format=event.data.format;
const metadata=event.data.metadata;
const patch=RomPatcher.createPatch(originalFile, modifiedFile, format);
const patch=RomPatcher.createPatch(originalFile, modifiedFile, format, metadata);
const patchFile=patch.export('my_patch');
self.postMessage(

View file

@ -1,4 +1,4 @@
/* RUP module for Rom Patcher JS v20241102 - Marc Robledo 2018-2024 - http://www.marcrobledo.com/license */
/* RUP module for Rom Patcher JS v20250430 - Marc Robledo 2018-2025 - http://www.marcrobledo.com/license */
/* File format specification: http://www.romhacking.net/documents/288/ */
const RUP_MAGIC='NINJA2';
@ -332,11 +332,13 @@ RUP.prototype.export=function(fileName){
RUP.buildFromRoms=function(original, modified){
RUP.buildFromRoms=function(original, modified, description){
var patch=new RUP();
var today=new Date();
patch.date=(today.getYear()+1900)+RUP.padZeroes(today.getMonth()+1, 1)+RUP.padZeroes(today.getDate(), 1);
if(description)
patch.description=description;
var file={
fileName:'',