Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: BPS patch TARGET_COPY reading #816

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/types/patches/bpsPatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,18 @@ export default class BPSPatch extends Patch {
sourceRelativeOffset += (offset & 1 ? -1 : +1) * (offset >> 1);
await targetFile.write(await sourceFile.readAt(sourceRelativeOffset, length));
sourceRelativeOffset += length;
} else {
} else if (action === BPSAction.TARGET_COPY) {
const offset = await Patch.readUpsUint(patchFile);
targetRelativeOffset += (offset & 1 ? -1 : +1) * (offset >> 1);
await targetFile.write(await targetFile.readAt(targetRelativeOffset, length));
targetRelativeOffset += length;
// WARN: you explicitly can't read the target file all at once, you have to read byte by
// byte, because later iterations of the loop may need to read data that was changed by
// earlier iterations of the loop.
for (let i = 0; i < length; i += 1) {
await targetFile.write(await targetFile.readAt(targetRelativeOffset, 1));
targetRelativeOffset += 1;
}
} else {
throw new Error(`BPS action ${action} isn't supported`);
}
}
}
Expand Down
Loading