mirror of
https://github.com/marcrobledo/RomPatcher.js.git
synced 2025-06-27 16:25:54 +00:00
patch creation can now create IPS patches if offsets are below format limit, rearranged files internally
This commit is contained in:
parent
e5bc46d725
commit
8146f4860a
27 changed files with 190 additions and 171 deletions
83
js/worker_apply.js
Normal file
83
js/worker_apply.js
Normal file
|
@ -0,0 +1,83 @@
|
|||
/* Rom Patcher JS v20200502 - Marc Robledo 2016-2020 - http://www.marcrobledo.com/license */
|
||||
|
||||
self.importScripts(
|
||||
'./MarcFile.js',
|
||||
'./crc.js',
|
||||
'./formats/ips.js',
|
||||
'./formats/aps.js',
|
||||
'./formats/ups.js',
|
||||
'./formats/bps.js',
|
||||
'./formats/rup.js',
|
||||
'./formats/ppf.js',
|
||||
'./formats/pmsr.js',
|
||||
'./formats/vcdiff.js'
|
||||
);
|
||||
|
||||
|
||||
self.onmessage = event => { // listen for messages from the main thread
|
||||
var romFile=new MarcFile(event.data.romFileU8Array);
|
||||
var patchFile=new MarcFile(event.data.patchFileU8Array);
|
||||
|
||||
var errorMessage=false;
|
||||
|
||||
var patch;
|
||||
var header=patchFile.readString(6);
|
||||
if(header.startsWith(IPS_MAGIC)){
|
||||
patch=parseIPSFile(patchFile);
|
||||
}else if(header.startsWith(UPS_MAGIC)){
|
||||
patch=parseUPSFile(patchFile);
|
||||
}else if(header.startsWith(APS_MAGIC)){
|
||||
patch=parseAPSFile(patchFile);
|
||||
}else if(header.startsWith(BPS_MAGIC)){
|
||||
patch=parseBPSFile(patchFile);
|
||||
}else if(header.startsWith(RUP_MAGIC)){
|
||||
patch=parseRUPFile(patchFile);
|
||||
}else if(header.startsWith(PPF_MAGIC)){
|
||||
patch=parsePPFFile(patchFile);
|
||||
}else if(header.startsWith(PMSR_MAGIC)){
|
||||
patch=parseMODFile(patchFile);
|
||||
}else if(header.startsWith(VCDIFF_MAGIC)){
|
||||
patch=parseVCDIFF(patchFile);
|
||||
}else{
|
||||
errorMessage='error_invalid_patch';
|
||||
}
|
||||
|
||||
//console.log('apply');
|
||||
var patchedRom;
|
||||
if(patch){
|
||||
try{
|
||||
patchedRom=patch.apply(romFile, event.data.validateChecksums);
|
||||
}catch(evt){
|
||||
errorMessage=evt.message;
|
||||
}
|
||||
}
|
||||
|
||||
//console.log('postMessage');
|
||||
if(patchedRom){
|
||||
self.postMessage(
|
||||
{
|
||||
romFileU8Array:event.data.romFileU8Array,
|
||||
patchFileU8Array:event.data.patchFileU8Array,
|
||||
patchedRomU8Array:patchedRom._u8array,
|
||||
errorMessage:errorMessage
|
||||
},
|
||||
[
|
||||
event.data.romFileU8Array.buffer,
|
||||
event.data.patchFileU8Array.buffer,
|
||||
patchedRom._u8array.buffer
|
||||
]
|
||||
);
|
||||
}else{
|
||||
self.postMessage(
|
||||
{
|
||||
romFileU8Array:event.data.romFileU8Array,
|
||||
patchFileU8Array:event.data.patchFileU8Array,
|
||||
errorMessage:errorMessage
|
||||
},
|
||||
[
|
||||
event.data.romFileU8Array.buffer,
|
||||
event.data.patchFileU8Array.buffer
|
||||
]
|
||||
);
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue