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

Merge branch 'marcrobledo:master' into main

This commit is contained in:
xenophile 2024-08-28 12:24:44 -07:00 committed by GitHub
commit 146231dde7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 217 additions and 193 deletions

View file

@ -6,7 +6,7 @@
*/
var PRECACHE_ID = 'rom-patcher-js';
var PRECACHE_VERSION = 'v30rc2b';
var PRECACHE_VERSION = 'v30rc4';
var PRECACHE_URLS = [
'/RomPatcher.js/', '/RomPatcher.js/index.html',
'/RomPatcher.js/manifest.json',

View file

@ -151,7 +151,7 @@
<button id="button-settings" class="btn-transparent"><img src="./webapp/icon_settings.svg" loading="lazy" class="icon settings" /> <span data-localize="yes">Settings</span></button>
</div>
Rom Patcher JS <small>v3.0 <a style="color:rgb(255, 197, 7)" href="legacy/" rel="nofollow">RC2</a></small> by <a href="/">Marc Robledo</a>
Rom Patcher JS <small>v3.0 <a style="color:rgb(255, 197, 7)" href="legacy/" rel="nofollow">RC4</a></small> by <a href="/">Marc Robledo</a>
<br />
<img src="./webapp/icon_github.svg" loading="lazy" class="icon github" /> <a href="https://github.com/marcrobledo/RomPatcher.js/" target="_blank">See on GitHub</a>
<img src="./webapp/icon_heart.svg" loading="lazy" class="icon heart" /> <a href="https://www.paypal.me/marcrobledo/5" target="_blank" rel="nofollow">Donate</a>

View file

@ -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,6 +737,7 @@ var RomPatcherWeb = (function () {
if (ZIPManager.isZipFile(binFile)) {
ZIPManager.unzipPatches(binFile._u8array.buffer);
} else {
try{
const parsedPatch = RomPatcher.parsePatchFile(binFile);
if (parsedPatch) {
patch = parsedPatch;
@ -828,6 +839,9 @@ var RomPatcherWeb = (function () {
} else {
_setToastError(_('Invalid patch file'));
}
}catch(ex){
_setToastError(ex.message);
}
}
}

View file

@ -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;

View file

@ -204,7 +204,6 @@ APS.buildFromRoms=function(original, modified){
}else{
patch.addRecord(offset, differentBytes);
}
//NO se puede comentar??? why????
}
}

View file

@ -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;
}

14
test.js
View file

@ -114,11 +114,11 @@ const TEST_DATA = (new Uint8Array([
_test('HashCalculator integrity', function () {
if (HashCalculator.md5(TEST_DATA) !== '55c76e7e683fd7cd63c673c5df3efa6e')
throw new Error('invalid MD5');
if(HashCalculator.crc32(TEST_DATA).toString(16) !== '903a031b')
if (HashCalculator.crc32(TEST_DATA) !== 0x903a031b)
throw new Error('invalid CRC32');
if(HashCalculator.adler32(TEST_DATA).toString(16) !== 'ef984205')
if (HashCalculator.adler32(TEST_DATA) !== 0xef984205)
throw new Error('invalid ADLER32');
if(HashCalculator.crc16(TEST_DATA).toString(16) !== '96e4')
if (HashCalculator.crc16(TEST_DATA) !== 0x96e4)
throw new Error('invalid SHA1');
});
@ -132,6 +132,14 @@ const MODIFIED_TEST_DATA = (new Uint8Array([
const modifiedFile = new BinFile(MODIFIED_TEST_DATA);
const patch = RomPatcher.createPatch(originalFile, modifiedFile, patchFormat);
const patchedFile = RomPatcher.applyPatch(originalFile, patch, { requireValidation: true });
if (patchFormat === 'bps') {
if (patch.patchChecksum !== patch.calculateFileChecksum())
throw new Error('invalid patch checksum');
else if (patch.export().hashCRC32() !== 0x2144df1c)
throw new Error('invalid BPS crc32');
}
if (patchedFile.hashCRC32() !== modifiedFile.hashCRC32())
throw new Error('modified and patched files\' crc32 do not match');
})