mirror of
https://github.com/marcrobledo/RomPatcher.js.git
synced 2025-06-27 16:25:54 +00:00
fixed important bugs while creating IPS patches and applying some BPS patches
This commit is contained in:
parent
860a2c33c4
commit
9d85db3baa
5 changed files with 24 additions and 10 deletions
|
@ -1,8 +1,9 @@
|
||||||
/* RomPatcher.js v20180920 - Marc Robledo 2016-2018 - http://www.marcrobledo.com/license */
|
/* RomPatcher.js v20180924 - Marc Robledo 2016-2018 - http://www.marcrobledo.com/license */
|
||||||
var MAX_ROM_SIZE=33554432;
|
var MAX_ROM_SIZE=33554432;
|
||||||
var MORE_SNES_SIZES_HEADERLESS=[786432,1310720,1572864,2621440,3145728,5242880,6291456];
|
var MORE_SNES_SIZES_HEADERLESS=[393216,786432,1310720,1572864,2621440,3145728,5242880,6291456]; //note: 393216 is a PCE file size
|
||||||
|
|
||||||
|
|
||||||
|
var DEBUG_CREATE_UNHEADERED_PATCH=false;
|
||||||
|
|
||||||
var romFile, headeredRomFile, unheaderedRomFile, patch, romFile1, romFile2, tempFile;
|
var romFile, headeredRomFile, unheaderedRomFile, patch, romFile1, romFile2, tempFile;
|
||||||
/* Shortcuts */
|
/* Shortcuts */
|
||||||
|
@ -96,7 +97,7 @@ addEvent(window,'load',function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
function isPowerOfTwo(romFile){return romFile.fileSize && (romFile.fileSize & (romFile.fileSize-1))===0}
|
function isPowerOfTwo(romFile){return romFile.fileSize && (romFile.fileSize & (romFile.fileSize-1))===0}
|
||||||
function isSNESExtension(romFile){return /\.(smc|sfc|fig|swc)$/.test(romFile.fileName)}
|
function isSNESExtension(romFile){return /\.(smc|sfc|fig|swc|pce)$/.test(romFile.fileName)}
|
||||||
function isSNESHeaderless(romFile){return isSNESExtension(romFile) && (isPowerOfTwo(romFile) || MORE_SNES_SIZES_HEADERLESS.indexOf(romFile.fileSize)>=0)}
|
function isSNESHeaderless(romFile){return isSNESExtension(romFile) && (isPowerOfTwo(romFile) || MORE_SNES_SIZES_HEADERLESS.indexOf(romFile.fileSize)>=0)}
|
||||||
function isSNESHeadered(romFile){return isSNESExtension(romFile) && (isPowerOfTwo(romFile.fileSize-512) || MORE_SNES_SIZES_HEADERLESS.indexOf(romFile.fileSize-512)>=0)}
|
function isSNESHeadered(romFile){return isSNESExtension(romFile) && (isPowerOfTwo(romFile.fileSize-512) || MORE_SNES_SIZES_HEADERLESS.indexOf(romFile.fileSize-512)>=0)}
|
||||||
|
|
||||||
|
@ -149,6 +150,13 @@ function applyPatchFile(p,r){
|
||||||
unheaderedPatchedROM.fileName=patchedROM.fileName;
|
unheaderedPatchedROM.fileName=patchedROM.fileName;
|
||||||
unheaderedPatchedROM.writeBytes(0, patchedROM.readBytes(512, patchedROM.fileSize-512));
|
unheaderedPatchedROM.writeBytes(0, patchedROM.readBytes(512, patchedROM.fileSize-512));
|
||||||
unheaderedPatchedROM.save();
|
unheaderedPatchedROM.save();
|
||||||
|
|
||||||
|
if(DEBUG_CREATE_UNHEADERED_PATCH){
|
||||||
|
romFile1=unheaderedRomFile;
|
||||||
|
romFile2=unheaderedPatchedROM;
|
||||||
|
unheaderedPatchedROM.fileName=unheaderedPatchedROM.fileName.replace(' (patched)','');
|
||||||
|
createPatchFile();
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
patchedROM.save();
|
patchedROM.save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ limitations under the License.
|
||||||
mod by marcrobledo, original from: https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/basic/service-worker.js
|
mod by marcrobledo, original from: https://github.com/GoogleChrome/samples/blob/gh-pages/service-worker/basic/service-worker.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const PRECACHE_ID='v20180920';
|
const PRECACHE_ID='v20180926';
|
||||||
const PRECACHE_FILES=[
|
const PRECACHE_FILES=[
|
||||||
'index.html','./',
|
'index.html','./',
|
||||||
'RomPatcher.css',
|
'RomPatcher.css',
|
||||||
|
|
12
bps.js
12
bps.js
|
@ -1,4 +1,4 @@
|
||||||
/* BPS module for RomPatcher.js v20180428 - Marc Robledo 2016-2018 - http://www.marcrobledo.com/license */
|
/* BPS module for RomPatcher.js v20180926 - Marc Robledo 2016-2018 - http://www.marcrobledo.com/license */
|
||||||
/* File format specification: https://www.romhacking.net/documents/746/ */
|
/* File format specification: https://www.romhacking.net/documents/746/ */
|
||||||
|
|
||||||
var BPS_MAGIC='BPS1';
|
var BPS_MAGIC='BPS1';
|
||||||
|
@ -49,9 +49,12 @@ BPS.prototype.apply=function(romFile){
|
||||||
seek+=action.length;
|
seek+=action.length;
|
||||||
}else if(action.type===BPS_ACTION_SOURCE_COPY || action.type===BPS_ACTION_TARGET_COPY){
|
}else if(action.type===BPS_ACTION_SOURCE_COPY || action.type===BPS_ACTION_TARGET_COPY){
|
||||||
seek+=decodeBPS(this.file, seek).length;
|
seek+=decodeBPS(this.file, seek).length;
|
||||||
|
}else{
|
||||||
|
//console.log(action.type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tempFile=new MarcBinFile(newFileSize);
|
tempFile=new MarcBinFile(newFileSize);
|
||||||
|
//alert(newFileSize);
|
||||||
|
|
||||||
|
|
||||||
//patch
|
//patch
|
||||||
|
@ -68,6 +71,7 @@ BPS.prototype.apply=function(romFile){
|
||||||
if(action.type===BPS_ACTION_SOURCE_READ){
|
if(action.type===BPS_ACTION_SOURCE_READ){
|
||||||
tempFile.writeBytes(outputOffset, romFile.readBytes(outputOffset, action.length));
|
tempFile.writeBytes(outputOffset, romFile.readBytes(outputOffset, action.length));
|
||||||
outputOffset+=action.length;
|
outputOffset+=action.length;
|
||||||
|
//seek+=action.length;
|
||||||
|
|
||||||
}else if(action.type===BPS_ACTION_TARGET_READ){
|
}else if(action.type===BPS_ACTION_TARGET_READ){
|
||||||
tempFile.writeBytes(outputOffset, this.file.readBytes(seek, action.length));
|
tempFile.writeBytes(outputOffset, this.file.readBytes(seek, action.length));
|
||||||
|
@ -118,8 +122,10 @@ function readBPSFile(file){
|
||||||
|
|
||||||
var decodedMetaDataLength=decodeBPS(file, seek);
|
var decodedMetaDataLength=decodeBPS(file, seek);
|
||||||
seek+=decodedMetaDataLength.length;
|
seek+=decodedMetaDataLength.length;
|
||||||
patchFile.metaData=file.readString(seek, decodedMetaDataLength.length);
|
if(decodedMetaDataLength.number){
|
||||||
seek+=patchFile.metaData.length;
|
patchFile.metaData=file.readString(seek, decodedMetaDataLength.number);
|
||||||
|
seek+=patchFile.metaData.number;
|
||||||
|
}
|
||||||
|
|
||||||
patchFile.actionsOffset=seek;
|
patchFile.actionsOffset=seek;
|
||||||
patchFile.file=file;
|
patchFile.file=file;
|
||||||
|
|
|
@ -103,7 +103,7 @@
|
||||||
|
|
||||||
<!-- FOOTER -->
|
<!-- FOOTER -->
|
||||||
<footer>
|
<footer>
|
||||||
Rom Patcher JS <small>rev20180920</small> by <a href="/">Marc Robledo</a>
|
Rom Patcher JS <small>rev20180926</small> by <a href="/">Marc Robledo</a>
|
||||||
<br />
|
<br />
|
||||||
<i class="icon github"></i> <a href="https://github.com/marcrobledo/RomPatcher.js/" target="_blank">See on GitHub</a>
|
<i class="icon github"></i> <a href="https://github.com/marcrobledo/RomPatcher.js/" target="_blank">See on GitHub</a>
|
||||||
<i class="icon heart"></i> <a href="https://www.paypal.me/marcrobledo/5" target="_blank" rel="nofollow">Donate</a>
|
<i class="icon heart"></i> <a href="https://www.paypal.me/marcrobledo/5" target="_blank" rel="nofollow">Donate</a>
|
||||||
|
|
4
ips.js
4
ips.js
|
@ -1,4 +1,4 @@
|
||||||
/* IPS module for RomPatcher.js v20180919 - Marc Robledo 2016-2018 - http://www.marcrobledo.com/license */
|
/* IPS module for RomPatcher.js v20180925 - Marc Robledo 2016-2018 - http://www.marcrobledo.com/license */
|
||||||
/* File format specification: http://www.smwiki.net/wiki/IPS_file_format */
|
/* File format specification: http://www.smwiki.net/wiki/IPS_file_format */
|
||||||
|
|
||||||
var MAX_IPS_SIZE=16777216;
|
var MAX_IPS_SIZE=16777216;
|
||||||
|
@ -169,7 +169,7 @@ function createIPSFromFiles(original, modified){
|
||||||
/* force length to be 0xffff-6 bytes to keep IPS standard */
|
/* force length to be 0xffff-6 bytes to keep IPS standard */
|
||||||
var nearbyDifference=true;
|
var nearbyDifference=true;
|
||||||
while(nearbyDifference && length<(0xffff-6)){
|
while(nearbyDifference && length<(0xffff-6)){
|
||||||
if(seek+6>modified.fileSize){
|
if((seek+6)>=modified.fileSize){
|
||||||
var finalSeek=modified.fileSize-seek-1;
|
var finalSeek=modified.fileSize-seek-1;
|
||||||
length+=finalSeek;
|
length+=finalSeek;
|
||||||
seek+=finalSeek;
|
seek+=finalSeek;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue