Skip to content

Commit 1e8c206

Browse files
author
Marc Robledo
committed
patch builder can now set metadata information to RUP and EBP patches
1 parent 72e6267 commit 1e8c206

7 files changed

Lines changed: 70 additions & 16 deletions

File tree

_cache_service_worker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
var PRECACHE_ID = 'rom-patcher-js';
9-
var PRECACHE_VERSION = 'v31';
9+
var PRECACHE_VERSION = 'v32';
1010
var PRECACHE_URLS = [
1111
'/RomPatcher.js/', '/RomPatcher.js/index.html',
1212
'/RomPatcher.js/manifest.json',

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@
131131
</div>
132132
</div>
133133

134+
<div class="row">
135+
<div></div>
136+
<div id="patch-builder-container-metadata-inputs"></div>
137+
</div>
138+
134139
<div class="buttons text-center">
135140
<div id="patch-builder-row-error-message" class="m-b"><span id="patch-builder-error-message"></span></div>
136141
<button id="patch-builder-button-create" disabled data-localize="yes" disabled>Create patch</button>

rom-patcher-js/RomPatcher.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ const RomPatcher = (function () {
230230
return patchedRom;
231231
},
232232

233-
createPatch: function (originalFile, modifiedFile, format) {
233+
createPatch: function (originalFile, modifiedFile, format, metadata) {
234234
if (!(originalFile instanceof BinFile))
235235
throw new Error('Original ROM file is not an instance of BinFile');
236236
else if (!(modifiedFile instanceof BinFile))
@@ -253,9 +253,10 @@ const RomPatcher = (function () {
253253
} else if (format === 'aps') {
254254
patch = APS.buildFromRoms(originalFile, modifiedFile);
255255
} else if (format === 'rup') {
256-
patch = RUP.buildFromRoms(originalFile, modifiedFile);
256+
if(metadata)
257+
patch = RUP.buildFromRoms(originalFile, modifiedFile, metadata && metadata.Description? metadata.Description : null);
257258
} else if (format === 'ebp') {
258-
patch = IPS.buildFromRoms(originalFile, modifiedFile, true);
259+
patch = IPS.buildFromRoms(originalFile, modifiedFile, metadata);
259260
} else {
260261
throw new Error('Invalid patch format');
261262
}

rom-patcher-js/RomPatcher.webapp.js

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* MIT License
99
*
10-
* Copyright (c) 2016-2024 Marc Robledo
10+
* Copyright (c) 2016-2025 Marc Robledo
1111
*
1212
* Permission is hereby granted, free of charge, to any person obtaining a copy
1313
* of this software and associated documentation files (the "Software"), to deal
@@ -1559,6 +1559,23 @@ const PatchBuilderWeb = (function (romPatcherWeb) {
15591559
}
15601560
};
15611561

1562+
const _getMetadataFields = function (patchFormat) {
1563+
if (patchFormat === 'rup') {
1564+
return ['Description'];
1565+
} else if (patchFormat === 'ebp') {
1566+
return ['Author', 'Title', 'Description'];
1567+
}
1568+
return [];
1569+
};
1570+
const _buildMetadataObject = function (patchFormat) {
1571+
return _getMetadataFields(patchFormat).reduce((metadata, field) => {
1572+
const input = document.getElementById('patch-builder-input-metadata-' + field.toLowerCase().replace(/\s+/g, '-'));
1573+
if (input && input.value.trim())
1574+
metadata[field] = input.value.trim();
1575+
return metadata;
1576+
}, {});
1577+
};
1578+
15621579
var webWorkerCreate;
15631580

15641581
var initialized = false;
@@ -1644,18 +1661,35 @@ const PatchBuilderWeb = (function (romPatcherWeb) {
16441661
_setToastError(_('Patch creation is not compatible with zipped ROMs'), 'warning');
16451662
});
16461663
});
1664+
document.getElementById('patch-builder-select-patch-type').addEventListener('change', function () {
1665+
if (!document.getElementById('patch-builder-container-metadata-inputs'))
1666+
return;
1667+
1668+
document.getElementById('patch-builder-container-metadata-inputs').innerHTML = '';
1669+
1670+
_getMetadataFields(this.value).forEach(function (field) {
1671+
const input = document.createElement('input');
1672+
input.id = 'patch-builder-input-metadata-' + field.toLowerCase().replace(/\s+/g, '-');
1673+
input.className = 'patch-builder-input-metadata';
1674+
input.type = 'text';
1675+
input.placeholder = _(field);
1676+
document.getElementById('patch-builder-container-metadata-inputs').appendChild(input);
1677+
});
1678+
});
16471679
document.getElementById('patch-builder-button-create').addEventListener('click', function () {
1680+
const patchFormat=document.getElementById('patch-builder-select-patch-type').value;
16481681
_setElementsStatus(false);
16491682
_setCreateButtonSpinner(true);
16501683
webWorkerCreate.postMessage(
16511684
{
16521685
originalRomU8Array: originalRom._u8array,
16531686
modifiedRomU8Array: modifiedRom._u8array,
1654-
format: document.getElementById('patch-builder-select-patch-type').value
1687+
format: patchFormat,
1688+
metadata: _buildMetadataObject(patchFormat)
16551689
}, [
1656-
originalRom._u8array.buffer,
1657-
modifiedRom._u8array.buffer
1658-
]
1690+
originalRom._u8array.buffer,
1691+
modifiedRom._u8array.buffer
1692+
]
16591693
);
16601694
});
16611695

@@ -1780,6 +1814,9 @@ const ROM_PATCHER_LOCALE = {
17801814
'Modified ROM:': 'ROM modificada:',
17811815
'Patch type:': 'Tipo de parche:',
17821816
'Creating patch...': 'Creando parche...',
1817+
'Author': 'Autor',
1818+
'Title': 'Título',
1819+
'Description': 'Descripción',
17831820

17841821
'Source ROM checksum mismatch': 'Checksum de ROM original no válida',
17851822
'Target ROM checksum mismatch': 'Checksum de ROM creada no válida',
@@ -1914,6 +1951,9 @@ const ROM_PATCHER_LOCALE = {
19141951
'Modified ROM:': 'ROM modificada:',
19151952
'Patch type:': 'Tipus de pedaç:',
19161953
'Creating patch...': 'Creant pedaç...',
1954+
'Author': 'Autor',
1955+
'Title': 'Títol',
1956+
'Description': 'Descripció',
19171957

19181958
'Source ROM checksum mismatch': 'Checksum de ROM original no vàlida',
19191959
'Target ROM checksum mismatch': 'Checksum de ROM creada no vàlida',

rom-patcher-js/RomPatcher.webworker.create.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ self.onmessage = event => { // listen for messages from the main thread
1717
const originalFile=new BinFile(event.data.originalRomU8Array);
1818
const modifiedFile=new BinFile(event.data.modifiedRomU8Array);
1919
const format=event.data.format;
20+
const metadata=event.data.metadata;
2021

21-
const patch=RomPatcher.createPatch(originalFile, modifiedFile, format);
22+
const patch=RomPatcher.createPatch(originalFile, modifiedFile, format, metadata);
2223
const patchFile=patch.export('my_patch');
2324

2425
self.postMessage(

rom-patcher-js/modules/RomPatcher.format.rup.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* RUP module for Rom Patcher JS v20241102 - Marc Robledo 2018-2024 - http://www.marcrobledo.com/license */
1+
/* RUP module for Rom Patcher JS v20250430 - Marc Robledo 2018-2025 - http://www.marcrobledo.com/license */
22
/* File format specification: http://www.romhacking.net/documents/288/ */
33

44
const RUP_MAGIC='NINJA2';
@@ -332,11 +332,13 @@ RUP.prototype.export=function(fileName){
332332

333333

334334

335-
RUP.buildFromRoms=function(original, modified){
335+
RUP.buildFromRoms=function(original, modified, description){
336336
var patch=new RUP();
337337

338338
var today=new Date();
339339
patch.date=(today.getYear()+1900)+RUP.padZeroes(today.getMonth()+1, 1)+RUP.padZeroes(today.getDate(), 1);
340+
if(description)
341+
patch.description=description;
340342

341343
var file={
342344
fileName:'',

webapp/style.css

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ hr{border:none;border-top:1px dotted #bbb;margin:15px 0}
193193

194194

195195
/* forms */
196-
input[type=file], input[type=checkbox], select{
196+
input[type=file], input[type=text], input[type=checkbox], select{
197197
box-sizing:border-box;
198198
max-width:100%;
199199
font-family:inherit;
@@ -204,28 +204,33 @@ input[type=file], input[type=checkbox], select{
204204
background-color:#edefef;
205205
}
206206
input[type=file]:focus:not(:disabled),
207+
input[type=text]:focus:not(:disabled),
207208
select:focus:not(:disabled),
208209
input[type=checkbox].styled:focus:not(:disabled){
209210
box-shadow: var(--rom-patcher-color-primary-focus) 0 0 0 2px;
210211
}
211212
#rom-patcher-container input[type=file],
212213
#rom-patcher-container select,
213-
#patch-builder-container input[type=file]
214+
#patch-builder-container input[type=file],
215+
#patch-builder-container input[type=text]
214216
{width:100%}
215-
input[type=file]{padding:6px 10px}
217+
input[type=file],input[type=text]{padding:6px 10px}
218+
#patch-builder-container-metadata-inputs input[type=text]:not(:last-child){margin-bottom:8px;}
216219
input[type=file].no-file-selector-button::file-selector-button{display:none}
217220
select{
218221
padding:6px 18px 6px 10px;
219222
-webkit-appearance:none;
220223
-moz-appearance:none;
224+
appearance:none;
221225
text-overflow:'';
222226

223227
background-image:url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZlcnNpb249IjEuMSIgeD0iMTJweCIgeT0iMHB4IiB3aWR0aD0iMjRweCIgaGVpZ2h0PSIzcHgiIHZpZXdCb3g9IjAgMCA2IDMiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDYgMyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBvbHlnb24gcG9pbnRzPSI1Ljk5MiwwIDIuOTkyLDMgLTAuMDA4LDAgIi8+PC9zdmc+");
224228
background-position:100% center;
225229
background-repeat:no-repeat;
226230
}
227231
select::-ms-expand{display:none}
228-
input[type=file]:hover:not(:disabled),select:hover:not(:disabled){cursor:pointer;background-color:#dee1e1}
232+
input[type=file]:hover:not(:disabled),input[type=text]:hover:not(:disabled),select:hover:not(:disabled){background-color:#dee1e1}
233+
input[type=file]:hover:not(:disabled),select:hover:not(:disabled){cursor:pointer;}
229234
input[type=file]:disabled,select:disabled{color:var(--rom-patcher-color-muted)}
230235

231236
/* select:focus > option{background-color:#fff} */

0 commit comments

Comments
 (0)