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:
parent
72e62674ae
commit
1e8c2060f9
7 changed files with 70 additions and 16 deletions
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var PRECACHE_ID = 'rom-patcher-js';
|
var PRECACHE_ID = 'rom-patcher-js';
|
||||||
var PRECACHE_VERSION = 'v31';
|
var PRECACHE_VERSION = 'v32';
|
||||||
var PRECACHE_URLS = [
|
var PRECACHE_URLS = [
|
||||||
'/RomPatcher.js/', '/RomPatcher.js/index.html',
|
'/RomPatcher.js/', '/RomPatcher.js/index.html',
|
||||||
'/RomPatcher.js/manifest.json',
|
'/RomPatcher.js/manifest.json',
|
||||||
|
|
|
@ -131,6 +131,11 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div></div>
|
||||||
|
<div id="patch-builder-container-metadata-inputs"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="buttons text-center">
|
<div class="buttons text-center">
|
||||||
<div id="patch-builder-row-error-message" class="m-b"><span id="patch-builder-error-message"></span></div>
|
<div id="patch-builder-row-error-message" class="m-b"><span id="patch-builder-error-message"></span></div>
|
||||||
<button id="patch-builder-button-create" disabled data-localize="yes" disabled>Create patch</button>
|
<button id="patch-builder-button-create" disabled data-localize="yes" disabled>Create patch</button>
|
||||||
|
|
|
@ -230,7 +230,7 @@ const RomPatcher = (function () {
|
||||||
return patchedRom;
|
return patchedRom;
|
||||||
},
|
},
|
||||||
|
|
||||||
createPatch: function (originalFile, modifiedFile, format) {
|
createPatch: function (originalFile, modifiedFile, format, metadata) {
|
||||||
if (!(originalFile instanceof BinFile))
|
if (!(originalFile instanceof BinFile))
|
||||||
throw new Error('Original ROM file is not an instance of BinFile');
|
throw new Error('Original ROM file is not an instance of BinFile');
|
||||||
else if (!(modifiedFile instanceof BinFile))
|
else if (!(modifiedFile instanceof BinFile))
|
||||||
|
@ -253,9 +253,10 @@ const RomPatcher = (function () {
|
||||||
} else if (format === 'aps') {
|
} else if (format === 'aps') {
|
||||||
patch = APS.buildFromRoms(originalFile, modifiedFile);
|
patch = APS.buildFromRoms(originalFile, modifiedFile);
|
||||||
} else if (format === 'rup') {
|
} 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') {
|
} else if (format === 'ebp') {
|
||||||
patch = IPS.buildFromRoms(originalFile, modifiedFile, true);
|
patch = IPS.buildFromRoms(originalFile, modifiedFile, metadata);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Invalid patch format');
|
throw new Error('Invalid patch format');
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*
|
*
|
||||||
* MIT License
|
* 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
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* 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 webWorkerCreate;
|
||||||
|
|
||||||
var initialized = false;
|
var initialized = false;
|
||||||
|
@ -1644,18 +1661,35 @@ const PatchBuilderWeb = (function (romPatcherWeb) {
|
||||||
_setToastError(_('Patch creation is not compatible with zipped ROMs'), 'warning');
|
_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 () {
|
document.getElementById('patch-builder-button-create').addEventListener('click', function () {
|
||||||
|
const patchFormat=document.getElementById('patch-builder-select-patch-type').value;
|
||||||
_setElementsStatus(false);
|
_setElementsStatus(false);
|
||||||
_setCreateButtonSpinner(true);
|
_setCreateButtonSpinner(true);
|
||||||
webWorkerCreate.postMessage(
|
webWorkerCreate.postMessage(
|
||||||
{
|
{
|
||||||
originalRomU8Array: originalRom._u8array,
|
originalRomU8Array: originalRom._u8array,
|
||||||
modifiedRomU8Array: modifiedRom._u8array,
|
modifiedRomU8Array: modifiedRom._u8array,
|
||||||
format: document.getElementById('patch-builder-select-patch-type').value
|
format: patchFormat,
|
||||||
|
metadata: _buildMetadataObject(patchFormat)
|
||||||
}, [
|
}, [
|
||||||
originalRom._u8array.buffer,
|
originalRom._u8array.buffer,
|
||||||
modifiedRom._u8array.buffer
|
modifiedRom._u8array.buffer
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1780,6 +1814,9 @@ const ROM_PATCHER_LOCALE = {
|
||||||
'Modified ROM:': 'ROM modificada:',
|
'Modified ROM:': 'ROM modificada:',
|
||||||
'Patch type:': 'Tipo de parche:',
|
'Patch type:': 'Tipo de parche:',
|
||||||
'Creating patch...': 'Creando parche...',
|
'Creating patch...': 'Creando parche...',
|
||||||
|
'Author': 'Autor',
|
||||||
|
'Title': 'Título',
|
||||||
|
'Description': 'Descripción',
|
||||||
|
|
||||||
'Source ROM checksum mismatch': 'Checksum de ROM original no válida',
|
'Source ROM checksum mismatch': 'Checksum de ROM original no válida',
|
||||||
'Target ROM checksum mismatch': 'Checksum de ROM creada 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:',
|
'Modified ROM:': 'ROM modificada:',
|
||||||
'Patch type:': 'Tipus de pedaç:',
|
'Patch type:': 'Tipus de pedaç:',
|
||||||
'Creating patch...': 'Creant pedaç...',
|
'Creating patch...': 'Creant pedaç...',
|
||||||
|
'Author': 'Autor',
|
||||||
|
'Title': 'Títol',
|
||||||
|
'Description': 'Descripció',
|
||||||
|
|
||||||
'Source ROM checksum mismatch': 'Checksum de ROM original no vàlida',
|
'Source ROM checksum mismatch': 'Checksum de ROM original no vàlida',
|
||||||
'Target ROM checksum mismatch': 'Checksum de ROM creada no vàlida',
|
'Target ROM checksum mismatch': 'Checksum de ROM creada no vàlida',
|
||||||
|
|
|
@ -17,8 +17,9 @@ self.onmessage = event => { // listen for messages from the main thread
|
||||||
const originalFile=new BinFile(event.data.originalRomU8Array);
|
const originalFile=new BinFile(event.data.originalRomU8Array);
|
||||||
const modifiedFile=new BinFile(event.data.modifiedRomU8Array);
|
const modifiedFile=new BinFile(event.data.modifiedRomU8Array);
|
||||||
const format=event.data.format;
|
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');
|
const patchFile=patch.export('my_patch');
|
||||||
|
|
||||||
self.postMessage(
|
self.postMessage(
|
||||||
|
|
|
@ -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/ */
|
/* File format specification: http://www.romhacking.net/documents/288/ */
|
||||||
|
|
||||||
const RUP_MAGIC='NINJA2';
|
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 patch=new RUP();
|
||||||
|
|
||||||
var today=new Date();
|
var today=new Date();
|
||||||
patch.date=(today.getYear()+1900)+RUP.padZeroes(today.getMonth()+1, 1)+RUP.padZeroes(today.getDate(), 1);
|
patch.date=(today.getYear()+1900)+RUP.padZeroes(today.getMonth()+1, 1)+RUP.padZeroes(today.getDate(), 1);
|
||||||
|
if(description)
|
||||||
|
patch.description=description;
|
||||||
|
|
||||||
var file={
|
var file={
|
||||||
fileName:'',
|
fileName:'',
|
||||||
|
|
|
@ -193,7 +193,7 @@ hr{border:none;border-top:1px dotted #bbb;margin:15px 0}
|
||||||
|
|
||||||
|
|
||||||
/* forms */
|
/* forms */
|
||||||
input[type=file], input[type=checkbox], select{
|
input[type=file], input[type=text], input[type=checkbox], select{
|
||||||
box-sizing:border-box;
|
box-sizing:border-box;
|
||||||
max-width:100%;
|
max-width:100%;
|
||||||
font-family:inherit;
|
font-family:inherit;
|
||||||
|
@ -204,20 +204,24 @@ input[type=file], input[type=checkbox], select{
|
||||||
background-color:#edefef;
|
background-color:#edefef;
|
||||||
}
|
}
|
||||||
input[type=file]:focus:not(:disabled),
|
input[type=file]:focus:not(:disabled),
|
||||||
|
input[type=text]:focus:not(:disabled),
|
||||||
select:focus:not(:disabled),
|
select:focus:not(:disabled),
|
||||||
input[type=checkbox].styled:focus:not(:disabled){
|
input[type=checkbox].styled:focus:not(:disabled){
|
||||||
box-shadow: var(--rom-patcher-color-primary-focus) 0 0 0 2px;
|
box-shadow: var(--rom-patcher-color-primary-focus) 0 0 0 2px;
|
||||||
}
|
}
|
||||||
#rom-patcher-container input[type=file],
|
#rom-patcher-container input[type=file],
|
||||||
#rom-patcher-container select,
|
#rom-patcher-container select,
|
||||||
#patch-builder-container input[type=file]
|
#patch-builder-container input[type=file],
|
||||||
|
#patch-builder-container input[type=text]
|
||||||
{width:100%}
|
{width:100%}
|
||||||
input[type=file]{padding:6px 10px}
|
input[type=file],input[type=text]{padding:6px 10px}
|
||||||
|
#patch-builder-container-metadata-inputs input[type=text]:not(:last-child){margin-bottom:8px;}
|
||||||
input[type=file].no-file-selector-button::file-selector-button{display:none}
|
input[type=file].no-file-selector-button::file-selector-button{display:none}
|
||||||
select{
|
select{
|
||||||
padding:6px 18px 6px 10px;
|
padding:6px 18px 6px 10px;
|
||||||
-webkit-appearance:none;
|
-webkit-appearance:none;
|
||||||
-moz-appearance:none;
|
-moz-appearance:none;
|
||||||
|
appearance:none;
|
||||||
text-overflow:'';
|
text-overflow:'';
|
||||||
|
|
||||||
background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgeD0iMTJweCIgeT0iMHB4IiB3aWR0aD0iMjRweCIgaGVpZ2h0PSIzcHgiIHZpZXdCb3g9IjAgMCA2IDMiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDYgMyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBvbHlnb24gcG9pbnRzPSI1Ljk5MiwwIDIuOTkyLDMgLTAuMDA4LDAgIi8+PC9zdmc+");
|
background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgeD0iMTJweCIgeT0iMHB4IiB3aWR0aD0iMjRweCIgaGVpZ2h0PSIzcHgiIHZpZXdCb3g9IjAgMCA2IDMiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDYgMyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBvbHlnb24gcG9pbnRzPSI1Ljk5MiwwIDIuOTkyLDMgLTAuMDA4LDAgIi8+PC9zdmc+");
|
||||||
|
@ -225,7 +229,8 @@ select{
|
||||||
background-repeat:no-repeat;
|
background-repeat:no-repeat;
|
||||||
}
|
}
|
||||||
select::-ms-expand{display:none}
|
select::-ms-expand{display:none}
|
||||||
input[type=file]:hover:not(:disabled),select:hover:not(:disabled){cursor:pointer;background-color:#dee1e1}
|
input[type=file]:hover:not(:disabled),input[type=text]:hover:not(:disabled),select:hover:not(:disabled){background-color:#dee1e1}
|
||||||
|
input[type=file]:hover:not(:disabled),select:hover:not(:disabled){cursor:pointer;}
|
||||||
input[type=file]:disabled,select:disabled{color:var(--rom-patcher-color-muted)}
|
input[type=file]:disabled,select:disabled{color:var(--rom-patcher-color-muted)}
|
||||||
|
|
||||||
/* select:focus > option{background-color:#fff} */
|
/* select:focus > option{background-color:#fff} */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue