mirror of
https://github.com/marcrobledo/RomPatcher.js.git
synced 2025-06-27 16:25:54 +00:00
added SNES header removal option before patching
This commit is contained in:
parent
c54fe27006
commit
14cae45bf9
6 changed files with 71 additions and 26 deletions
|
@ -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)}
|
||||
|
@ -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);
|
||||
el('checkbox-removeheader').checked=false;
|
||||
unheaderedRomFile=null;
|
||||
|
||||
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/>';
|
||||
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(){
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
|
6
aps.js
6
aps.js
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
5
bps.js
5
bps.js
|
@ -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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
12
index.html
12
index.html
|
@ -43,7 +43,17 @@
|
|||
<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>
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
CACHE MANIFEST
|
||||
#v20171103
|
||||
#v20171112
|
||||
#CACHE:
|
||||
index.html
|
||||
RomPatcher.css
|
||||
|
|
9
ups.js
9
ups.js
|
@ -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';
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue