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

show expected ROM source if patch can validate source, for issue #69

This commit is contained in:
Marc Robledo 2024-07-21 11:12:39 +02:00
parent 0992132c57
commit c1293bb3ed
8 changed files with 91 additions and 9 deletions

View file

@ -125,6 +125,7 @@
<input type="file" id="input-file-patch" accept=".ips,.ups,.bps,.aps,.rup,.ppf,.mod,.xdelta,.vcdiff,.zip"/> <input type="file" id="input-file-patch" accept=".ips,.ups,.bps,.aps,.rup,.ppf,.mod,.xdelta,.vcdiff,.zip"/>
</div> </div>
</div> </div>
<div class="row m-b hide" id="row-expected-source-info"></div>
<div class="buttons"> <div class="buttons">
<span id="message-apply" class="message"></span> <span id="message-apply" class="message"></span>
@ -180,7 +181,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.8.1</small> by <a href="/">Marc Robledo</a> Rom Patcher JS <small>v2.9</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>

View file

@ -1,4 +1,4 @@
/* Rom Patcher JS v20230406 - Marc Robledo 2016-2023 - http://www.marcrobledo.com/license */ /* Rom Patcher JS v20240721 - Marc Robledo 2016-2024 - http://www.marcrobledo.com/license */
const TOO_BIG_ROM_SIZE=67108863; const TOO_BIG_ROM_SIZE=67108863;
const HEADERS_INFO=[ const HEADERS_INFO=[
@ -112,7 +112,13 @@ function parseCustomPatch(customPatch){
if(typeof customPatch.crc==='number'){ if(typeof customPatch.crc==='number'){
patch.validateSource=function(romFile,headerSize){ patch.validateSource=function(romFile,headerSize){
return customPatch.crc===crc32(romFile, headerSize) return customPatch.crc===crc32(romFile, headerSize)
} };
patch.getValidationInfo=function(){
return [{
'type':'CRC32',
'value':padZeroes(customPatch.crc,4)
}]
};
}else if(typeof customPatch.crc==='object'){ }else if(typeof customPatch.crc==='object'){
patch.validateSource=function(romFile,headerSize){ patch.validateSource=function(romFile,headerSize){
for(var i=0; i<customPatch.crc.length; i++) for(var i=0; i<customPatch.crc.length; i++)
@ -120,6 +126,14 @@ function parseCustomPatch(customPatch){
return true; return true;
return false; return false;
} }
patch.getValidationInfo=function(){
return customPatch.crc.map(function(crc){
return {
'type':'CRC32',
'value':padZeroes(crc,4)
}
});
};
} }
validateSource(); validateSource();
} }
@ -681,6 +695,33 @@ function _readPatchFile(){
patch=null; patch=null;
setMessage('apply', 'error_invalid_patch', 'error'); setMessage('apply', 'error_invalid_patch', 'error');
} }
if(patch && patch.getValidationInfo){
const validationInfos=patch.getValidationInfo();
el('row-expected-source-info').className='row m-b';
el('row-expected-source-info').innerHTML='';
validationInfos.forEach(function(validationInfo){
var leftCol=document.createElement('div');
leftCol.className='leftcol text-right';
leftCol.innerHTML=_('expected_source').replace('%s', validationInfo.type);
var rightCol=document.createElement('div');
rightCol.className='rightcol';
/*
var a=document.createElement('a');
a.href='https://www.google.com/search?q=%22'+validationInfo.value+'%22';
a.target='_blank';
a.className='clickable';
a.innerHTML=validationInfo.value;
rightCol.appendChild(a);
*/
rightCol.innerHTML=validationInfo.value;
el('row-expected-source-info').appendChild(leftCol);
el('row-expected-source-info').appendChild(rightCol);
});
}else{
el('row-expected-source-info').className='row m-b hide';
el('row-expected-source-info').innerHTML='';
}
validateSource(); validateSource();
setTabApplyEnabled(true); setTabApplyEnabled(true);
} }

View file

@ -1,4 +1,4 @@
/* BPS module for Rom Patcher JS v20180930 - Marc Robledo 2016-2018 - http://www.marcrobledo.com/license */ /* BPS module for Rom Patcher JS v20240721 - Marc Robledo 2016-2024 - http://www.marcrobledo.com/license */
/* File format specification: https://www.romhacking.net/documents/746/ */ /* File format specification: https://www.romhacking.net/documents/746/ */
const BPS_MAGIC='BPS1'; const BPS_MAGIC='BPS1';
@ -25,6 +25,12 @@ BPS.prototype.toString=function(){
return s return s
} }
BPS.prototype.validateSource=function(romFile,headerSize){return this.sourceChecksum===crc32(romFile, headerSize)} BPS.prototype.validateSource=function(romFile,headerSize){return this.sourceChecksum===crc32(romFile, headerSize)}
BPS.prototype.getValidationInfo=function(){
return [{
'type':'CRC32',
'value':padZeroes(this.sourceChecksum,4)
}]
}
BPS.prototype.apply=function(romFile, validate){ BPS.prototype.apply=function(romFile, validate){
if(validate && !this.validateSource(romFile)){ if(validate && !this.validateSource(romFile)){
throw new Error('error_crc_input'); throw new Error('error_crc_input');

View file

@ -1,4 +1,4 @@
/* PMSR (Paper Mario Star Rod) module for Rom Patcher JS v20200225 - Marc Robledo 2020 - http://www.marcrobledo.com/license */ /* PMSR (Paper Mario Star Rod) module for Rom Patcher JS v20240721 - Marc Robledo 2020-2024 - http://www.marcrobledo.com/license */
/* File format specification: http://origami64.net/attachment.php?aid=790 (dead link) */ /* File format specification: http://origami64.net/attachment.php?aid=790 (dead link) */
const PMSR_MAGIC='PMSR'; const PMSR_MAGIC='PMSR';
@ -25,6 +25,12 @@ PMSR.prototype.toString=function(){
PMSR.prototype.validateSource=function(romFile){ PMSR.prototype.validateSource=function(romFile){
return romFile.fileSize===PAPER_MARIO_USA10_FILE_SIZE && crc32(romFile)===PAPER_MARIO_USA10_CRC32; return romFile.fileSize===PAPER_MARIO_USA10_FILE_SIZE && crc32(romFile)===PAPER_MARIO_USA10_CRC32;
} }
PMSR.prototype.getValidationInfo=function(){
return [{
'type':'CRC32',
'value':'a7f5cd7e'
}]
}
PMSR.prototype.apply=function(romFile, validate){ PMSR.prototype.apply=function(romFile, validate){
if(validate && !this.validateSource(romFile)){ if(validate && !this.validateSource(romFile)){
throw new Error('error_crc_input'); throw new Error('error_crc_input');

View file

@ -1,4 +1,4 @@
/* RUP module for Rom Patcher JS v20180930 - Marc Robledo 2018 - http://www.marcrobledo.com/license */ /* RUP module for Rom Patcher JS v20240721 - Marc Robledo 2018-2024 - http://www.marcrobledo.com/license */
/* File format specification: http://www.romhacking.net/documents/288/ */ /* File format specification: http://www.romhacking.net/documents/288/ */
const RUP_MAGIC='NINJA2'; const RUP_MAGIC='NINJA2';
@ -54,6 +54,16 @@ RUP.prototype.validateSource=function(romFile,headerSize){
} }
return false; return false;
} }
RUP.prototype.getValidationInfo=function(){
var ret=[];
for(var i=0; i<this.files.length; i++){
ret.push({
'type':'MD5',
'value':this.files[i].sourceMD5
});
}
return ret;
}
RUP.prototype.apply=function(romFile, validate){ RUP.prototype.apply=function(romFile, validate){
var validFile; var validFile;
if(validate){ if(validate){

View file

@ -1,4 +1,4 @@
/* UPS module for Rom Patcher JS v20220315 - Marc Robledo 2017-2022 - http://www.marcrobledo.com/license */ /* UPS module for Rom Patcher JS v20240721 - Marc Robledo 2017-2024 - http://www.marcrobledo.com/license */
/* File format specification: http://www.romhacking.net/documents/392/ */ /* File format specification: http://www.romhacking.net/documents/392/ */
const UPS_MAGIC='UPS1'; const UPS_MAGIC='UPS1';
@ -52,6 +52,10 @@ UPS.prototype.export=function(fileName){
return tempFile return tempFile
} }
UPS.prototype.validateSource=function(romFile,headerSize){return crc32(romFile,headerSize)===this.checksumInput} UPS.prototype.validateSource=function(romFile,headerSize){return crc32(romFile,headerSize)===this.checksumInput}
UPS.prototype.getValidationInfo=function(){return [{
'type':'CRC32',
'value':padZeroes(this.checksumInput,4)
}];}
UPS.prototype.apply=function(romFile, validate){ UPS.prototype.apply=function(romFile, validate){
if(validate && !this.validateSource(romFile)){ if(validate && !this.validateSource(romFile)){
throw new Error('error_crc_input'); throw new Error('error_crc_input');

View file

@ -9,6 +9,7 @@ const LOCALIZATION={
'apply_patch': 'Apply patch', 'apply_patch': 'Apply patch',
'rom_file': 'ROM file:', 'rom_file': 'ROM file:',
'patch_file': 'Patch file:', 'patch_file': 'Patch file:',
'expected_source': 'Expected ROM %s:',
'remove_header': 'Remove header', 'remove_header': 'Remove header',
'add_header': 'Add temporary header', 'add_header': 'Add temporary header',
'compatible_formats': 'Compatible formats:', 'compatible_formats': 'Compatible formats:',
@ -41,6 +42,7 @@ const LOCALIZATION={
'apply_patch': 'Aplicar parche', 'apply_patch': 'Aplicar parche',
'rom_file': 'Archivo ROM:', 'rom_file': 'Archivo ROM:',
'patch_file': 'Archivo parche:', 'patch_file': 'Archivo parche:',
'expected_source': '%s esperado de ROM:',
'remove_header': 'Quitar cabecera', 'remove_header': 'Quitar cabecera',
'add_header': 'Añadir cabecera temporal', 'add_header': 'Añadir cabecera temporal',
'compatible_formats': 'Formatos compatibles:', 'compatible_formats': 'Formatos compatibles:',
@ -72,6 +74,7 @@ const LOCALIZATION={
'apply_patch': 'Pas patch toe', 'apply_patch': 'Pas patch toe',
'rom_file': 'ROM bestand:', 'rom_file': 'ROM bestand:',
'patch_file': 'Patch bestand:', 'patch_file': 'Patch bestand:',
'expected_source': 'Expected ROM %s:',
'remove_header': 'Verwijder rubriek', 'remove_header': 'Verwijder rubriek',
'add_header': 'Voeg tijdelijk rubriek toe', 'add_header': 'Voeg tijdelijk rubriek toe',
'compatible_formats': 'Compatibele formaten:', 'compatible_formats': 'Compatibele formaten:',
@ -102,6 +105,7 @@ const LOCALIZATION={
'apply_patch': 'Tillämpa korrigeringsfil', 'apply_patch': 'Tillämpa korrigeringsfil',
'rom_file': 'ROM-fil:', 'rom_file': 'ROM-fil:',
'patch_file': 'Korrigeringsfil:', 'patch_file': 'Korrigeringsfil:',
'expected_source': 'Expected ROM %s:',
'remove_header': 'Ta bort rubrik', 'remove_header': 'Ta bort rubrik',
'add_header': 'Lägg till tillfällig rubrik', 'add_header': 'Lägg till tillfällig rubrik',
'compatible_formats': 'Kompatibla format:', 'compatible_formats': 'Kompatibla format:',
@ -132,6 +136,7 @@ const LOCALIZATION={
'apply_patch': 'Aplicar pedaç', 'apply_patch': 'Aplicar pedaç',
'rom_file': 'Arxiu ROM:', 'rom_file': 'Arxiu ROM:',
'patch_file': 'Arxiu pedaç:', 'patch_file': 'Arxiu pedaç:',
'expected_source': '%s esperat de ROM:',
'remove_header': 'Treure capçalera', 'remove_header': 'Treure capçalera',
'add_header': 'Afegir capçalera temporal', 'add_header': 'Afegir capçalera temporal',
'compatible_formats': 'Formats compatibles:', 'compatible_formats': 'Formats compatibles:',
@ -162,6 +167,7 @@ const LOCALIZATION={
'apply_patch': 'Aplicar pedaç', 'apply_patch': 'Aplicar pedaç',
'rom_file': 'Arxiu ROM:', 'rom_file': 'Arxiu ROM:',
'patch_file': 'Arxiu pedaç:', 'patch_file': 'Arxiu pedaç:',
'expected_source': '%s esperat de ROM:',
'remove_header': 'Llevar capçalera', 'remove_header': 'Llevar capçalera',
'add_header': 'Afegir capçalera temporal', 'add_header': 'Afegir capçalera temporal',
'compatible_formats': 'Formats compatibles:', 'compatible_formats': 'Formats compatibles:',
@ -192,6 +198,7 @@ const LOCALIZATION={
'apply_patch': 'Применить патч', 'apply_patch': 'Применить патч',
'rom_file': 'Файл ROM:', 'rom_file': 'Файл ROM:',
'patch_file': 'Файл патча:', 'patch_file': 'Файл патча:',
'expected_source': 'Expected ROM %s:',
'remove_header': 'Удалить заголовок перед применением', 'remove_header': 'Удалить заголовок перед применением',
'add_header': 'Добавить временный заголовок', 'add_header': 'Добавить временный заголовок',
'compatible_formats': 'Совместимые форматы:', 'compatible_formats': 'Совместимые форматы:',
@ -223,6 +230,7 @@ const LOCALIZATION={
'apply_patch': 'Patch anwenden', 'apply_patch': 'Patch anwenden',
'rom_file': 'ROM-Datei:', 'rom_file': 'ROM-Datei:',
'patch_file': 'Patch-Datei:', 'patch_file': 'Patch-Datei:',
'expected_source': 'Expected ROM %s:',
'remove_header': 'Header entfernen', 'remove_header': 'Header entfernen',
'add_header': 'Header temporär hinzufügen', 'add_header': 'Header temporär hinzufügen',
'compatible_formats': 'Unterstützte Formate:', 'compatible_formats': 'Unterstützte Formate:',
@ -255,6 +263,7 @@ const LOCALIZATION={
'apply_patch': 'Aplicar patch', 'apply_patch': 'Aplicar patch',
'rom_file': 'Arquivo da ROM:', 'rom_file': 'Arquivo da ROM:',
'patch_file': 'Arquivo do patch:', 'patch_file': 'Arquivo do patch:',
'expected_source': 'Expected ROM %s:',
'remove_header': 'Remover cabeçalho', 'remove_header': 'Remover cabeçalho',
'add_header': 'Adicionar cabeçalho temporário', 'add_header': 'Adicionar cabeçalho temporário',
'compatible_formats': 'Formatos compatíveis:', 'compatible_formats': 'Formatos compatíveis:',
@ -286,6 +295,7 @@ const LOCALIZATION={
'apply_patch': 'パッチを当て', 'apply_patch': 'パッチを当て',
'rom_file': 'ROMファィル', 'rom_file': 'ROMファィル',
'patch_file': 'パッチファイル:', 'patch_file': 'パッチファイル:',
'expected_source': 'Expected ROM %s:',
'remove_header': 'ヘッダーを削除', 'remove_header': 'ヘッダーを削除',
'add_header': '一時的なヘッダーを追加', 'add_header': '一時的なヘッダーを追加',
'compatible_formats': '互換性のあるフォーマット:', 'compatible_formats': '互換性のあるフォーマット:',
@ -316,6 +326,7 @@ const LOCALIZATION={
'apply_patch': 'Appliquer le patch', 'apply_patch': 'Appliquer le patch',
'rom_file': 'Fichier ROM:', 'rom_file': 'Fichier ROM:',
'patch_file': 'Fichier patch:', 'patch_file': 'Fichier patch:',
'expected_source': 'Expected ROM %s:',
'remove_header': 'Supprimer l\'en-tête', 'remove_header': 'Supprimer l\'en-tête',
'add_header': 'Ajouter une en-tête temporaire', 'add_header': 'Ajouter une en-tête temporaire',
'compatible_formats': 'Formats compatibles:', 'compatible_formats': 'Formats compatibles:',
@ -346,6 +357,7 @@ const LOCALIZATION={
'apply_patch': '打补丁', 'apply_patch': '打补丁',
'rom_file': 'ROM文件', 'rom_file': 'ROM文件',
'patch_file': '补丁文件:', 'patch_file': '补丁文件:',
'expected_source': 'Expected ROM %s:',
'remove_header': '删除文件头', 'remove_header': '删除文件头',
'add_header': '增加临时文件头', 'add_header': '增加临时文件头',
'compatible_formats': '兼容补丁格式:', 'compatible_formats': '兼容补丁格式:',
@ -377,6 +389,7 @@ const LOCALIZATION={
'apply_patch': '套用patch', 'apply_patch': '套用patch',
'rom_file': 'ROM檔', 'rom_file': 'ROM檔',
'patch_file': 'patch檔', 'patch_file': 'patch檔',
'expected_source': 'Expected ROM %s:',
'remove_header': '刪除檔頭', 'remove_header': '刪除檔頭',
'add_header': '增加臨時檔頭', 'add_header': '增加臨時檔頭',
'compatible_formats': '相容格式:', 'compatible_formats': '相容格式:',
@ -407,6 +420,7 @@ const LOCALIZATION={
'apply_patch': 'Applica patch', 'apply_patch': 'Applica patch',
'rom_file': 'File ROM:', 'rom_file': 'File ROM:',
'patch_file': 'File patch:', 'patch_file': 'File patch:',
'expected_source': 'Expected ROM %s:',
'remove_header': 'Rimuovi header', 'remove_header': 'Rimuovi header',
'add_header': 'Aggiungi header temporaneo', 'add_header': 'Aggiungi header temporaneo',
'compatible_formats': 'Formati:', 'compatible_formats': 'Formati:',

View file

@ -230,7 +230,7 @@ button.no-text.with-icon:before{margin-right:0px}
#rom-info{font-family:'Roboto Mono',monospace;color:#888;font-size:12px; #rom-info, #row-expected-source-info{font-family:'Roboto Mono',monospace;color:#888;font-size:12px;
-moz-user-select:text; -moz-user-select:text;
-webkit-user-select: text; -webkit-user-select: text;
-ms-user-select:text; -ms-user-select:text;