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

settings: automatic GB/C and Mega Drive/Genesis ROM header fix

This commit is contained in:
Marc Robledo 2022-11-10 19:09:53 +01:00
parent df48e4679c
commit 0709addaf9
4 changed files with 112 additions and 10 deletions

View file

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

View file

@ -179,7 +179,7 @@
<button id="button-settings" class="button-outer"><img src="style/icon_settings.svg" class="icon settings" /> <span data-localize="settings">Settings</span></button> <button id="button-settings" class="button-outer"><img src="style/icon_settings.svg" class="icon settings" /> <span data-localize="settings">Settings</span></button>
</div> </div>
Rom Patcher JS <small>v2.6.1</small> by <a href="/">Marc Robledo</a> Rom Patcher JS <small>v2.7</small> by <a href="/">Marc Robledo</a>
<br /> <br />
<img src="style/icon_github.svg" class="icon github" /> <a href="https://github.com/marcrobledo/RomPatcher.js/" target="_blank">See on GitHub</a> <img src="style/icon_github.svg" class="icon github" /> <a href="https://github.com/marcrobledo/RomPatcher.js/" target="_blank">See on GitHub</a>
<img src="style/icon_heart.svg" class="icon heart" /> <a href="https://www.paypal.me/marcrobledo/5" target="_blank" rel="nofollow">Donate</a> <img src="style/icon_heart.svg" class="icon heart" /> <a href="https://www.paypal.me/marcrobledo/5" target="_blank" rel="nofollow">Donate</a>
@ -205,6 +205,7 @@
<option value="en">English</option> <option value="en">English</option>
<option value="fr">Français</option> <option value="fr">Français</option>
<option value="de">Deutsch</option> <option value="de">Deutsch</option>
<option value="it">Italiano</option>
<option value="es">Español</option> <option value="es">Español</option>
<option value="nl">Nederlands</option> <option value="nl">Nederlands</option>
<option value="sv">Svenska</option> <option value="sv">Svenska</option>
@ -214,7 +215,6 @@
<option value="ru">Russian</option> <option value="ru">Russian</option>
<option value="ja">日本語</option> <option value="ja">日本語</option>
<option value="zh-cn">中文(简体)</option> <option value="zh-cn">中文(简体)</option>
<option value="it">Italiano</option>
</select> </select>
</div> </div>
</div> </div>
@ -225,6 +225,11 @@
</div> </div>
<div class="row m-b"> <div class="row m-b">
<div class="leftcol-lg"><label data-localize="fix_checksum">Fix ROM checksum</label></div>
<div class="rightcol-lg text-right"><span id="switch-fix-checksum" class="switch disabled"></span></div>
</div>
<div class="row">
<div class="leftcol-lg"><label data-localize="light_theme">Light theme</label></div> <div class="leftcol-lg"><label data-localize="light_theme">Light theme</label></div>
<div class="rightcol-lg text-right"><span id="switch-theme" class="switch disabled"></span></div> <div class="rightcol-lg text-right"><span id="switch-theme" class="switch disabled"></span></div>
</div> </div>

View file

@ -1,4 +1,4 @@
/* Rom Patcher JS v20220319 - Marc Robledo 2016-2022 - http://www.marcrobledo.com/license */ /* Rom Patcher JS v20221110 - Marc Robledo 2016-2022 - http://www.marcrobledo.com/license */
const TOO_BIG_ROM_SIZE=67108863; const TOO_BIG_ROM_SIZE=67108863;
const HEADERS_INFO=[ const HEADERS_INFO=[
@ -246,6 +246,7 @@ var UI={
var AppSettings={ var AppSettings={
langCode:(typeof navigator.userLanguage==='string')? navigator.userLanguage.substr(0,2) : 'en', langCode:(typeof navigator.userLanguage==='string')? navigator.userLanguage.substr(0,2) : 'en',
outputFileNameMatch:false, outputFileNameMatch:false,
fixChecksum:false,
lightTheme:false, lightTheme:false,
load:function(){ load:function(){
@ -261,6 +262,10 @@ var AppSettings={
this.outputFileNameMatch=loadedSettings.outputFileNameMatch; this.outputFileNameMatch=loadedSettings.outputFileNameMatch;
el('switch-output-name').className='switch enabled'; el('switch-output-name').className='switch enabled';
} }
if(loadedSettings.fixChecksum===true){
this.fixChecksum=loadedSettings.fixChecksum;
el('switch-fix-checksum').className='switch enabled';
}
if(loadedSettings.lightTheme===true){ if(loadedSettings.lightTheme===true){
this.lightTheme=loadedSettings.lightTheme; this.lightTheme=loadedSettings.lightTheme;
el('switch-theme').className='switch enabled'; el('switch-theme').className='switch enabled';
@ -429,6 +434,16 @@ addEvent(window,'load',function(){
} }
AppSettings.save(); AppSettings.save();
}); });
addEvent(el('switch-fix-checksum'), 'click', function(){
if(this.className==='switch enabled'){
this.className='switch disabled';
AppSettings.fixChecksum=false;
}else{
this.className='switch enabled';
AppSettings.fixChecksum=true;
}
AppSettings.save();
});
addEvent(el('switch-theme'), 'click', function(){ addEvent(el('switch-theme'), 'click', function(){
if(this.className==='switch enabled'){ if(this.className==='switch enabled'){
this.className='switch disabled'; this.className='switch disabled';
@ -557,6 +572,82 @@ function validateSource(){
function _getRomSystem(file){
if(file.fileSize>0x0200 && file.fileSize%4===0){
if(/\.gbc?/i.test(file.fileName)){
var NINTENDO_LOGO=[
0xce, 0xed, 0x66, 0x66, 0xcc, 0x0d, 0x00, 0x0b, 0x03, 0x73, 0x00, 0x83, 0x00, 0x0c, 0x00, 0x0d,
0x00, 0x08, 0x11, 0x1f, 0x88, 0x89, 0x00, 0x0e, 0xdc, 0xcc, 0x6e, 0xe6, 0xdd, 0xdd, 0xd9, 0x99
];
file.offset=0x104;
var valid=true;
for(var i=0; i<NINTENDO_LOGO.length && valid; i++){
if(NINTENDO_LOGO[i]!==file.readU8())
valid=false;
}
if(valid)
return 'gb';
}else if(/\.(bin|md)?/i.test(file.fileName)){
file.offset=0x0100;
if(/SEGA (GENESIS|MEGA DR)/.test(file.readString(12)))
return 'smd';
}
}
return null;
}
function _getHeaderChecksumInfo(file){
var info={
system:_getRomSystem(file),
current:null,
calculated:null,
fix:null
}
if(info.system==='gb'){
/* get current checksum */
file.offset=0x014d;
info.current=file.readU8();
/* calculate checksum */
info.calculated=0x00;
file.offset=0x0134;
for(var i=0; i<=0x18; i++){
info.calculated=((info.calculated - file.readU8() - 1) >>> 0) & 0xff;
}
/* fix checksum */
info.fix=function(file){
file.offset=0x014d;
file.writeU8(this.calculated);
}
}else if(info.system==='smd'){
/* get current checksum */
file.offset=0x018e;
info.current=file.readU16();
/* calculate checksum */
info.calculated=0x0000;
file.offset=0x0200;
while(!file.isEOF()){
info.calculated=((info.calculated + file.readU16()) >>> 0) & 0xffff;
}
/* fix checksum */
info.fix=function(file){
file.offset=0x018e;
file.writeU16(this.calculated);
}
}else{
info=null;
}
return info;
}
function _readPatchFile(){ function _readPatchFile(){
setTabApplyEnabled(false); setTabApplyEnabled(false);
patchFile.littleEndian=false; patchFile.littleEndian=false;
@ -622,18 +713,18 @@ function preparePatchedRom(originalRom, patchedRom, headerSize){
/* fix checksum if needed */ /* fix checksum if needed */
//var fixedChecksum=fixConsoleChecksum(patchedRom); if(AppSettings.fixChecksum){
var checksumInfo=_getHeaderChecksumInfo(patchedRom);
if(checksumInfo && checksumInfo.current!==checksumInfo.calculated && confirm(_('fix_checksum_prompt')+' ('+padZeroes(checksumInfo.current)+' -> '+padZeroes(checksumInfo.calculated)+')')){
checksumInfo.fix(patchedRom);
}
}
setMessage('apply'); setMessage('apply');
patchedRom.save(); patchedRom.save();
/*if(fixedChecksum){
setMessage('apply','Checksum was fixed','warning');
}*/
//debug: create unheadered patch //debug: create unheadered patch
/*if(headerSize && el('checkbox-addheader').checked){ /*if(headerSize && el('checkbox-addheader').checked){
@ -642,6 +733,8 @@ function preparePatchedRom(originalRom, patchedRom, headerSize){
} }
/*function removeHeader(romFile){ /*function removeHeader(romFile){
//r._dataView=new DataView(r._dataView.buffer, headerSize); //r._dataView=new DataView(r._dataView.buffer, headerSize);
oldHeader=romFile.slice(0,headerSize); oldHeader=romFile.slice(0,headerSize);

View file

@ -3,6 +3,7 @@ const LOCALIZATION={
'creator_mode': 'Creator mode', 'creator_mode': 'Creator mode',
'settings': 'Settings', 'settings': 'Settings',
'alternate_output_name': 'Use patch name for output', 'alternate_output_name': 'Use patch name for output',
'fix_checksum': 'Fix ROM header checksum',
'light_theme': 'Light theme', 'light_theme': 'Light theme',
'apply_patch': 'Apply patch', 'apply_patch': 'Apply patch',
@ -14,6 +15,7 @@ const LOCALIZATION={
'applying_patch': 'Applying patch...', 'applying_patch': 'Applying patch...',
'downloading': 'Downloading...', 'downloading': 'Downloading...',
'unzipping': 'Unzipping...', 'unzipping': 'Unzipping...',
'fix_checksum_prompt': 'Fix ROM header checksum?',
'create_patch': 'Create patch', 'create_patch': 'Create patch',
'original_rom': 'Original ROM:', 'original_rom': 'Original ROM:',
@ -33,6 +35,7 @@ const LOCALIZATION={
'creator_mode': 'Modo creador', 'creator_mode': 'Modo creador',
'settings': 'Configuración', 'settings': 'Configuración',
'alternate_output_name': 'Guardar con nombre del parche', 'alternate_output_name': 'Guardar con nombre del parche',
'fix_checksum': 'Corregir checksum cabecera ROM',
'light_theme': 'Tema claro', 'light_theme': 'Tema claro',
'apply_patch': 'Aplicar parche', 'apply_patch': 'Aplicar parche',
@ -44,6 +47,7 @@ const LOCALIZATION={
'applying_patch': 'Aplicando parche...', 'applying_patch': 'Aplicando parche...',
'downloading': 'Descargando...', 'downloading': 'Descargando...',
'unzipping': 'Descomprimiendo...', 'unzipping': 'Descomprimiendo...',
'fix_checksum_prompt': '¿Corregir checksum en la cabecera de la ROM?',
'create_patch': 'Crear parche', 'create_patch': 'Crear parche',
'original_rom': 'ROM original:', 'original_rom': 'ROM original:',