mirror of
https://github.com/marcrobledo/RomPatcher.js.git
synced 2025-09-15 17:26:57 +00:00
Merge branch 'marcrobledo:master' into main
This commit is contained in:
commit
146231dde7
7 changed files with 217 additions and 193 deletions
|
@ -318,7 +318,8 @@ var RomPatcherWeb = (function () {
|
|||
return fallback || 0;
|
||||
},
|
||||
setFakeFile: function (id, fileName) {
|
||||
if (document.getElementById('rom-patcher-input-file-' + id)) {
|
||||
const isBrowserSafari = /Safari/i.test(navigator.userAgent); /* safari does not show fake file name: https://pqina.nl/blog/set-value-to-file-input/#but-safari */
|
||||
if (!isBrowserSafari && document.getElementById('rom-patcher-input-file-' + id)) {
|
||||
try {
|
||||
/* add a fake file to the input file, so it shows the chosen file name */
|
||||
const fakeFile = new File(new Uint8Array(0), fileName);
|
||||
|
@ -508,6 +509,15 @@ var RomPatcherWeb = (function () {
|
|||
return false;
|
||||
}
|
||||
|
||||
const _dragEventContainsFiles = function (evt) {
|
||||
if (evt.dataTransfer.types) {
|
||||
for (var i = 0; i < evt.dataTransfer.types.length; i++) {
|
||||
if (evt.dataTransfer.types[i] === 'Files')
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const _initialize = function (newSettings, embededPatchInfo) {
|
||||
/* embeded patches */
|
||||
var validEmbededPatch = _checkEmbededPatchParameter(embededPatchInfo);
|
||||
|
@ -727,106 +737,110 @@ var RomPatcherWeb = (function () {
|
|||
if (ZIPManager.isZipFile(binFile)) {
|
||||
ZIPManager.unzipPatches(binFile._u8array.buffer);
|
||||
} else {
|
||||
const parsedPatch = RomPatcher.parsePatchFile(binFile);
|
||||
if (parsedPatch) {
|
||||
patch = parsedPatch;
|
||||
_setPatchInputSpinner(false);
|
||||
|
||||
const embededPatchInfo = _getEmbededPatchInfo(binFile.fileName);
|
||||
if (embededPatchInfo) {
|
||||
/* custom crc32s validation */
|
||||
if (embededPatchInfo.inputCrc32) {
|
||||
patch.validateSource = function (romFile, headerSize) {
|
||||
for (var i = 0; i < embededPatchInfo.inputCrc32.length; i++) {
|
||||
if (embededPatchInfo.inputCrc32[i] === romFile.hashCRC32(headerSize))
|
||||
return true;
|
||||
try{
|
||||
const parsedPatch = RomPatcher.parsePatchFile(binFile);
|
||||
if (parsedPatch) {
|
||||
patch = parsedPatch;
|
||||
_setPatchInputSpinner(false);
|
||||
|
||||
const embededPatchInfo = _getEmbededPatchInfo(binFile.fileName);
|
||||
if (embededPatchInfo) {
|
||||
/* custom crc32s validation */
|
||||
if (embededPatchInfo.inputCrc32) {
|
||||
patch.validateSource = function (romFile, headerSize) {
|
||||
for (var i = 0; i < embededPatchInfo.inputCrc32.length; i++) {
|
||||
if (embededPatchInfo.inputCrc32[i] === romFile.hashCRC32(headerSize))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
patch.getValidationInfo = function () {
|
||||
return {
|
||||
'type': 'CRC32',
|
||||
'value': embededPatchInfo.inputCrc32
|
||||
}
|
||||
};
|
||||
}
|
||||
patch.getValidationInfo = function () {
|
||||
return {
|
||||
'type': 'CRC32',
|
||||
'value': embededPatchInfo.inputCrc32
|
||||
|
||||
/* custom description */
|
||||
if (embededPatchInfo.description) {
|
||||
patch.getDescription = function () {
|
||||
return embededPatchInfo.description;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/* custom description */
|
||||
if (embededPatchInfo.description) {
|
||||
patch.getDescription = function () {
|
||||
return embededPatchInfo.description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* toggle ROM requirements */
|
||||
if (htmlElements.get('row-patch-requirements') && htmlElements.get('patch-requirements-value')) {
|
||||
if (typeof patch.getValidationInfo === 'function' && patch.getValidationInfo()) {
|
||||
var validationInfo = patch.getValidationInfo();
|
||||
if (Array.isArray(validationInfo) || !validationInfo.type) {
|
||||
validationInfo = {
|
||||
type: 'ROM',
|
||||
value: validationInfo
|
||||
}
|
||||
}
|
||||
htmlElements.setText('patch-requirements-value', '');
|
||||
|
||||
htmlElements.setText('patch-requirements-type', validationInfo.type === 'ROM' ? _('Required ROM:') : _('Required %s:').replace('%s', validationInfo.type));
|
||||
|
||||
if (!Array.isArray(validationInfo.value))
|
||||
validationInfo.value = [validationInfo.value];
|
||||
|
||||
validationInfo.value.forEach(function (value) {
|
||||
var line = document.createElement('div');
|
||||
if (typeof value !== 'string') {
|
||||
if (validationInfo.type === 'CRC32') {
|
||||
value = value.toString(16);
|
||||
while (value.length < 8)
|
||||
value = '0' + value;
|
||||
} else {
|
||||
value = value.toString();
|
||||
|
||||
/* toggle ROM requirements */
|
||||
if (htmlElements.get('row-patch-requirements') && htmlElements.get('patch-requirements-value')) {
|
||||
if (typeof patch.getValidationInfo === 'function' && patch.getValidationInfo()) {
|
||||
var validationInfo = patch.getValidationInfo();
|
||||
if (Array.isArray(validationInfo) || !validationInfo.type) {
|
||||
validationInfo = {
|
||||
type: 'ROM',
|
||||
value: validationInfo
|
||||
}
|
||||
}
|
||||
/*
|
||||
var a=document.createElement('a');
|
||||
a.href='https://www.google.com/search?q=%22'+value+'%22';
|
||||
a.target='_blank';
|
||||
a.className='clickable';
|
||||
a.innerHTML=value;
|
||||
line.appendChild(a);
|
||||
*/
|
||||
line.innerHTML = value;
|
||||
htmlElements.get('patch-requirements-value').appendChild(line);
|
||||
});
|
||||
htmlElements.addClass('row-patch-requirements', 'show');
|
||||
} else {
|
||||
htmlElements.setText('patch-requirements-value', '');
|
||||
htmlElements.removeClass('row-patch-requirements', 'show');
|
||||
htmlElements.setText('patch-requirements-value', '');
|
||||
|
||||
htmlElements.setText('patch-requirements-type', validationInfo.type === 'ROM' ? _('Required ROM:') : _('Required %s:').replace('%s', validationInfo.type));
|
||||
|
||||
if (!Array.isArray(validationInfo.value))
|
||||
validationInfo.value = [validationInfo.value];
|
||||
|
||||
validationInfo.value.forEach(function (value) {
|
||||
var line = document.createElement('div');
|
||||
if (typeof value !== 'string') {
|
||||
if (validationInfo.type === 'CRC32') {
|
||||
value = value.toString(16);
|
||||
while (value.length < 8)
|
||||
value = '0' + value;
|
||||
} else {
|
||||
value = value.toString();
|
||||
}
|
||||
}
|
||||
/*
|
||||
var a=document.createElement('a');
|
||||
a.href='https://www.google.com/search?q=%22'+value+'%22';
|
||||
a.target='_blank';
|
||||
a.className='clickable';
|
||||
a.innerHTML=value;
|
||||
line.appendChild(a);
|
||||
*/
|
||||
line.innerHTML = value;
|
||||
htmlElements.get('patch-requirements-value').appendChild(line);
|
||||
});
|
||||
htmlElements.addClass('row-patch-requirements', 'show');
|
||||
} else {
|
||||
htmlElements.setText('patch-requirements-value', '');
|
||||
htmlElements.removeClass('row-patch-requirements', 'show');
|
||||
}
|
||||
}
|
||||
|
||||
/* toggle patch description */
|
||||
if (typeof patch.getDescription === 'function' && patch.getDescription()) {
|
||||
htmlElements.setText('patch-description', patch.getDescription()/* .replace(/\n/g, '<br/>') */);
|
||||
//htmlElements.setTitle('patch-description', patch.getDescription());
|
||||
htmlElements.addClass('row-patch-description', 'show');
|
||||
} else {
|
||||
htmlElements.setText('patch-description', '');
|
||||
//htmlElements.setTitle('patch-description', '');
|
||||
htmlElements.removeClass('row-patch-description', 'show');
|
||||
}
|
||||
|
||||
RomPatcherWeb.validateCurrentRom(_getChecksumStartOffset());
|
||||
|
||||
if (typeof settings.onloadpatch === 'function') {
|
||||
settings.onloadpatch(binFile, embededPatchInfo, parsedPatch);
|
||||
}
|
||||
|
||||
if (transferFakeFile) {
|
||||
htmlElements.setFakeFile('patch', binFile.fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/* toggle patch description */
|
||||
if (typeof patch.getDescription === 'function' && patch.getDescription()) {
|
||||
htmlElements.setText('patch-description', patch.getDescription()/* .replace(/\n/g, '<br/>') */);
|
||||
//htmlElements.setTitle('patch-description', patch.getDescription());
|
||||
htmlElements.addClass('row-patch-description', 'show');
|
||||
} else {
|
||||
htmlElements.setText('patch-description', '');
|
||||
//htmlElements.setTitle('patch-description', '');
|
||||
htmlElements.removeClass('row-patch-description', 'show');
|
||||
_setToastError(_('Invalid patch file'));
|
||||
}
|
||||
|
||||
RomPatcherWeb.validateCurrentRom(_getChecksumStartOffset());
|
||||
|
||||
if (typeof settings.onloadpatch === 'function') {
|
||||
settings.onloadpatch(binFile, embededPatchInfo, parsedPatch);
|
||||
}
|
||||
|
||||
if (transferFakeFile) {
|
||||
htmlElements.setFakeFile('patch', binFile.fileName);
|
||||
}
|
||||
} else {
|
||||
_setToastError(_('Invalid patch file'));
|
||||
}catch(ex){
|
||||
_setToastError(ex.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* BinFile.js (last update: 2024-02-27)
|
||||
* BinFile.js (last update: 2024-08-21)
|
||||
* by Marc Robledo, https://www.marcrobledo.com
|
||||
*
|
||||
* a JS class for reading/writing sequentially binary data from/to a file
|
||||
|
@ -188,7 +188,7 @@ BinFile.prototype.slice = function (offset, len, doNotClone) {
|
|||
else if (len === 0)
|
||||
throw new Error('zero length provided for slicing');
|
||||
else
|
||||
offset = Math.floor(offset);
|
||||
len = Math.floor(len);
|
||||
|
||||
if (offset === 0 && len === this.fileSize && doNotClone)
|
||||
return this;
|
||||
|
|
|
@ -204,7 +204,6 @@ APS.buildFromRoms=function(original, modified){
|
|||
}else{
|
||||
patch.addRecord(offset, differentBytes);
|
||||
}
|
||||
//NO se puede comentar??? why????
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* BPS module for Rom Patcher JS v20240721 - Marc Robledo 2016-2024 - http://www.marcrobledo.com/license */
|
||||
/* BPS module for Rom Patcher JS v20240821 - Marc Robledo 2016-2024 - http://www.marcrobledo.com/license */
|
||||
/* File format specification: https://www.romhacking.net/documents/746/ */
|
||||
|
||||
const BPS_MAGIC='BPS1';
|
||||
|
@ -26,6 +26,10 @@ BPS.prototype.toString=function(){
|
|||
s+='\n#Actions: '+this.actions.length;
|
||||
return s
|
||||
}
|
||||
BPS.prototype.calculateFileChecksum = function () {
|
||||
var patchFile = this.export();
|
||||
return patchFile.hashCRC32(0, patchFile.fileSize - 4);
|
||||
}
|
||||
BPS.prototype.validateSource=function(romFile,headerSize){return this.sourceChecksum===romFile.hashCRC32(headerSize)}
|
||||
BPS.prototype.getValidationInfo=function(){
|
||||
return {
|
||||
|
@ -121,7 +125,7 @@ BPS.fromFile=function(file){
|
|||
patch.targetChecksum=file.readU32();
|
||||
patch.patchChecksum=file.readU32();
|
||||
|
||||
if(patch.patchChecksum!==file.hashCRC32(0, file.fileSize - 4)){
|
||||
if (patch.patchChecksum !== patch.calculateFileChecksum()) {
|
||||
throw new Error('Patch checksum mismatch');
|
||||
}
|
||||
|
||||
|
@ -238,10 +242,9 @@ BPS.buildFromRoms=function(original, modified, deltaMode){
|
|||
patch.actions=createBPSFromFilesLinear(original, modified);
|
||||
}
|
||||
|
||||
var patchFile=patch.export();
|
||||
patch.sourceChecksum=original.hashCRC32();
|
||||
patch.targetChecksum=modified.hashCRC32();
|
||||
patch.patchChecksum=patchFile.hashCRC32(0, patchFile.fileSize - 4);
|
||||
patch.patchChecksum = patch.calculateFileChecksum();
|
||||
return patch;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue