diff --git a/_cache_service_worker.js b/_cache_service_worker.js index 36eeefb..bc3ddc4 100644 --- a/_cache_service_worker.js +++ b/_cache_service_worker.js @@ -14,7 +14,7 @@ */ var PRECACHE_ID='rom-patcher-js'; -var PRECACHE_VERSION='v261c'; +var PRECACHE_VERSION='v27'; var PRECACHE_URLS=[ '/RomPatcher.js/','/RomPatcher.js/index.html', '/RomPatcher.js/manifest.json', diff --git a/index.html b/index.html index 542e846..dfc4ab9 100644 --- a/index.html +++ b/index.html @@ -179,7 +179,7 @@ - Rom Patcher JS v2.6.1 by Marc Robledo + Rom Patcher JS v2.7 by Marc Robledo
See on GitHub Donate @@ -205,6 +205,7 @@ + @@ -214,7 +215,6 @@ - @@ -225,6 +225,11 @@
+
+
+
+ +
diff --git a/js/RomPatcher.js b/js/RomPatcher.js index 3921246..2d5fbf5 100644 --- a/js/RomPatcher.js +++ b/js/RomPatcher.js @@ -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 HEADERS_INFO=[ @@ -246,6 +246,7 @@ var UI={ var AppSettings={ langCode:(typeof navigator.userLanguage==='string')? navigator.userLanguage.substr(0,2) : 'en', outputFileNameMatch:false, + fixChecksum:false, lightTheme:false, load:function(){ @@ -261,6 +262,10 @@ var AppSettings={ this.outputFileNameMatch=loadedSettings.outputFileNameMatch; 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){ this.lightTheme=loadedSettings.lightTheme; el('switch-theme').className='switch enabled'; @@ -429,6 +434,16 @@ addEvent(window,'load',function(){ } 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(){ if(this.className==='switch enabled'){ 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>> 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(){ setTabApplyEnabled(false); patchFile.littleEndian=false; @@ -622,18 +713,18 @@ function preparePatchedRom(originalRom, patchedRom, headerSize){ /* 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'); patchedRom.save(); - - - /*if(fixedChecksum){ - setMessage('apply','Checksum was fixed','warning'); - }*/ //debug: create unheadered patch /*if(headerSize && el('checkbox-addheader').checked){ @@ -642,6 +733,8 @@ function preparePatchedRom(originalRom, patchedRom, headerSize){ } + + /*function removeHeader(romFile){ //r._dataView=new DataView(r._dataView.buffer, headerSize); oldHeader=romFile.slice(0,headerSize); diff --git a/js/locale.js b/js/locale.js index 9ecc6fe..f336221 100644 --- a/js/locale.js +++ b/js/locale.js @@ -3,6 +3,7 @@ const LOCALIZATION={ 'creator_mode': 'Creator mode', 'settings': 'Settings', 'alternate_output_name': 'Use patch name for output', + 'fix_checksum': 'Fix ROM header checksum', 'light_theme': 'Light theme', 'apply_patch': 'Apply patch', @@ -14,6 +15,7 @@ const LOCALIZATION={ 'applying_patch': 'Applying patch...', 'downloading': 'Downloading...', 'unzipping': 'Unzipping...', + 'fix_checksum_prompt': 'Fix ROM header checksum?', 'create_patch': 'Create patch', 'original_rom': 'Original ROM:', @@ -33,6 +35,7 @@ const LOCALIZATION={ 'creator_mode': 'Modo creador', 'settings': 'Configuración', 'alternate_output_name': 'Guardar con nombre del parche', + 'fix_checksum': 'Corregir checksum cabecera ROM', 'light_theme': 'Tema claro', 'apply_patch': 'Aplicar parche', @@ -44,6 +47,7 @@ const LOCALIZATION={ 'applying_patch': 'Aplicando parche...', 'downloading': 'Descargando...', 'unzipping': 'Descomprimiendo...', + 'fix_checksum_prompt': '¿Corregir checksum en la cabecera de la ROM?', 'create_patch': 'Crear parche', 'original_rom': 'ROM original:',