applyPatch function
- Uint8List rom,
- Uint8List patch, {
- PatchFormat? format,
Applies a patch to a ROM with automatic format detection.
rom
is the original ROM data.
patch
is the patch data.
format
is the patch format. If null, the format will be auto-detected.
Returns the patched ROM data.
Throws PatchException if the patch is invalid or application fails.
Implementation
Uint8List applyPatch(
Uint8List rom,
Uint8List patch, {
PatchFormat? format,
}) {
try {
// Auto-detect format if not specified
final detectedFormat = format ?? detectPatchFormat(patch);
// Apply patch based on format
switch (detectedFormat) {
case PatchFormat.ips:
return IpsPatcher.applyPatch(rom, patch);
case PatchFormat.bps:
return BpsPatcher.applyPatch(rom, patch);
case PatchFormat.ups:
return UpsPatcher.applyPatch(rom, patch);
}
} catch (e) {
if (e is PatchException) {
rethrow;
}
throw PatchException(
PatchErrorCode.unexpectedError,
'Unexpected error during patch application: $e',
);
}
}