Skip to content

Commit

Permalink
added SNES header removal option before patching
Browse files Browse the repository at this point in the history
  • Loading branch information
marcrobledo committed Nov 12, 2017
1 parent c54fe27 commit 14cae45
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 27 deletions.
65 changes: 50 additions & 15 deletions RomPatcher.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/* RomPatcher.js v20171102 - Marc Robledo 2016-2017 - http://www.marcrobledo.com/license */
var MAX_ROM_SIZE=33554432;
var romFile, patch, romFile1, romFile2, tempFile, romHashes={};
/* RomPatcher.js v20171107 - Marc Robledo 2016-2017 - http://www.marcrobledo.com/license */
var MAX_ROM_SIZE=33554432;var SNES_HEADERED_ROMS_SIZE=[
262144+512,
524288+512,
1048576+512,
2097152+512,
4194304+512,
8388608+512,
16777216+512,
33554432+512,
50331648+512
];
var romFile, headeredRomFile, unheaderedRomFile, patch, romFile1, romFile2, tempFile;
/* Shortcuts */
function addEvent(e,ev,f){e.addEventListener(ev,f,false)}
function el(e){return document.getElementById(e)}
Expand All @@ -17,16 +27,16 @@ addEvent(window,'load',function(){

addEvent(el('input-file-rom'), 'change', function(){
romFile=new MarcBinFile(this, function(){
el('rom-info').innerHTML='';
sha1(romFile);
romHashes.crc32=crc32(romFile);
romHashes.md5=md5(romFile);

var crc32str=romHashes.crc32.toString(16);
while(crc32str.length<8)
crc32str='0'+crc32str;
el('rom-info').innerHTML+='CRC32: '+crc32str+'<br/>';
el('rom-info').innerHTML+='MD5: '+romHashes.md5+'<br/>';
el('checkbox-removeheader').checked=false;
unheaderedRomFile=null;

if(SNES_HEADERED_ROMS_SIZE.indexOf(romFile.fileSize)>=0){
el('row-removeheader').style.display='flex';
}else{
el('row-removeheader').style.display='none';
}

updateChecksums(romFile);
});
});
addEvent(el('input-file-patch'), 'change', function(){
Expand All @@ -38,10 +48,36 @@ addEvent(window,'load',function(){
addEvent(el('input-file-rom2'), 'change', function(){
romFile2=new MarcBinFile(this);
});

addEvent(el('checkbox-removeheader'), 'change', function(){
if(!unheaderedRomFile){
headeredRomFile=romFile;
unheaderedRomFile=new MarcBinFile(headeredRomFile.fileSize-512);
unheaderedRomFile.writeBytes(0, headeredRomFile.readBytes(512, headeredRomFile.fileSize-512));
unheaderedRomFile.fileName=headeredRomFile.fileName;
}

if(this.checked)
romFile=unheaderedRomFile;
else
romFile=headeredRomFile;


updateChecksums(romFile);
});
});


function updateChecksums(file){
el('rom-info').style.display='block';
sha1(file);

var crc32str=crc32(file).toString(16);
while(crc32str.length<8)
crc32str='0'+crc32str;
el('crc32').innerHTML=crc32str;
el('md5').innerHTML=md5(file);
}



Expand Down Expand Up @@ -130,8 +166,7 @@ function sha1(file){
hexString+='0'+bytes[i].toString(16);
else
hexString+=bytes[i].toString(16);
romHashes.sha1=hexString;
el('rom-info').innerHTML+='SHA-1: '+romHashes.sha1+'<br/>';
el('sha1').innerHTML=hexString;
}).catch(function(error){
console.error(error);
});
Expand Down
6 changes: 3 additions & 3 deletions aps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* APS (N64) module for RomPatcher.js v20170723 - Marc Robledo 2017 - http://www.marcrobledo.com/license */
/* APS (N64) module for RomPatcher.js v20171112 - Marc Robledo 2017 - http://www.marcrobledo.com/license */
/* File format specification: https://github.com/btimofeev/UniPatcher/wiki/APS-(N64) */

var RECORD_RLE=0x0000;
Expand Down Expand Up @@ -90,7 +90,7 @@ APS.prototype.export=function(){
APS.prototype.apply=function(romFile){
if(this.headerType===1){
if(romFile.readString(0x3c, 3)!==this.header.cartId){
MarcDialogs.alert('Invalid ROM cart id');
MarcDialogs.alert('Error: invalid ROM cart id');
return false;
}
var crc=romFile.readBytes(0x10, 8);
Expand All @@ -100,7 +100,7 @@ APS.prototype.apply=function(romFile){
crcOk=false;
}
if(!crcOk){
MarcDialogs.alert('Invalid ROM checksum');
MarcDialogs.alert('Error: invalid ROM checksum');
return false;
}
}
Expand Down
5 changes: 3 additions & 2 deletions bps.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* BPS module for RomPatcher.js v20171103 - Marc Robledo 2016-2017 - http://www.marcrobledo.com/license */
/* BPS module for RomPatcher.js v20171112 - Marc Robledo 2016-2017 - http://www.marcrobledo.com/license */
/* File format specification: https://www.romhacking.net/documents/746/ */

var BPS_MAGIC='BPS1';
Expand Down Expand Up @@ -30,7 +30,8 @@ BPS.prototype.toString=function(){
}*/
BPS.prototype.apply=function(romFile){
if(this.sourceChecksum!==crc32(romFile,false)){
MarcDialogs.alert('Warning: invalid source ROM checksum');
MarcDialogs.alert('Error: invalid source ROM checksum');
return false;
}


Expand Down
12 changes: 11 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,17 @@ <h3 class="red">Apply patch</h3>
<div class="six columns text-right"><label for="input-file-rom">ROM file:</label></div>
<div class="six columns">
<input type="file" id="input-file-rom" />
<div id="rom-info" class="mono" style="font-size:12px"></div>
<div id="rom-info" class="mono" style="display:none;font-size:12px">
CRC32: <span id="crc32"></span><br/>
MD5: <span id="md5"></span><br/>
SHA-1: <span id="sha1"></span><br/>
</div>
</div>
</div>
<div class="row" id="row-removeheader" style="display:none">
<div class="six columns text-right"><label for="checkbox-removeheader">Remove header:</label></div>
<div class="six columns">
<input type="checkbox" id="checkbox-removeheader" />
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion manifest.appcache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CACHE MANIFEST
#v20171103
#v20171112
#CACHE:
index.html
RomPatcher.css
Expand Down
9 changes: 4 additions & 5 deletions ups.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* UPS module for RomPatcher.js v20170723 - Marc Robledo 2017 - http://www.marcrobledo.com/license */
/* UPS module for RomPatcher.js v20171112 - Marc Robledo 2017 - http://www.marcrobledo.com/license */
/* File format specification: http://www.romhacking.net/documents/392/ */

var UPS_MAGIC='UPS1';
Expand Down Expand Up @@ -62,7 +62,7 @@ UPS.prototype.export=function(){
}
UPS.prototype.apply=function(romFile){
if(crc32(romFile)!==this.checksumInput){
MarcDialogs.alert('Invalid input ROM');
MarcDialogs.alert('Error: invalid input ROM checksum');
return false;
}

Expand All @@ -83,8 +83,7 @@ UPS.prototype.apply=function(romFile){
}

if(crc32(tempFile)!==this.checksumOutput){
MarcDialogs.alert('Invalid output ROM');
return false;
MarcDialogs.alert('Warning: invalid output ROM checksum');
}

return tempFile
Expand Down Expand Up @@ -159,7 +158,7 @@ function readUPSFile(file){
patchFile.checksumOutput=tempFile.readInt(seek+4);

if(tempFile.readInt(seek+8)!==crc32(file, true)){
MarcDialogs.alert('Invalid patch checksum');
MarcDialogs.alert('Warning: invalid patch checksum');
}
return patchFile;
}
Expand Down

0 comments on commit 14cae45

Please sign in to comment.