Update br_ips to generate an empty patch when no hunks are found
This commit is contained in:
+26
-20
@@ -255,25 +255,30 @@ static void writePatch(const char * filename, const hunk_t * hunks, size_t num,
|
|||||||
// Maximum hunk size is 65535 bytes. For convenience, we allocate a
|
// Maximum hunk size is 65535 bytes. For convenience, we allocate a
|
||||||
// round 65536 (0x10000). This has no effect on memory consumption,
|
// round 65536 (0x10000). This has no effect on memory consumption,
|
||||||
// as malloc will round this up anyway.
|
// as malloc will round this up anyway.
|
||||||
char * readbuf = malloc(0x10000);
|
char * readbuf = NULL;
|
||||||
if (readbuf == NULL) FATAL_ERROR("failed to allocate write buffer\n");
|
if (rom != NULL) {
|
||||||
fwrite("PATCH", 1, 5, file); // magic
|
readbuf = malloc(0x10000);
|
||||||
for (int i = 0; i < num; i++) {
|
if (readbuf == NULL) FATAL_ERROR("failed to allocate write buffer\n");
|
||||||
// Encode the offset
|
}
|
||||||
uint32_t offset = hunks[i].offset;
|
fwrite("PATCH", 1, 5, file); // magic
|
||||||
putc(offset >> 16, file);
|
if (readbuf != NULL) {
|
||||||
putc(offset >> 8, file);
|
for (int i = 0; i < num; i++) {
|
||||||
putc(offset >> 0, file);
|
// Encode the offset
|
||||||
// Encode the size
|
uint32_t offset = hunks[i].offset;
|
||||||
size_t size = hunks[i].size;
|
putc(offset >> 16, file);
|
||||||
putc(size >> 8, file);
|
putc(offset >> 8, file);
|
||||||
putc(size >> 0, file);
|
putc(offset >> 0, file);
|
||||||
// Yank the data straight from the ROM
|
// Encode the size
|
||||||
if (fseek(rom, offset, SEEK_SET)) FATAL_ERROR("seek\n");
|
size_t size = hunks[i].size;
|
||||||
if (fread(readbuf, 1, size, rom) != size) FATAL_ERROR("read\n");
|
putc(size >> 8, file);
|
||||||
if (fwrite(readbuf, 1, size, file) != size) FATAL_ERROR("write\n");
|
putc(size >> 0, file);
|
||||||
|
// Yank the data straight from the ROM
|
||||||
|
if (fseek(rom, offset, SEEK_SET)) FATAL_ERROR("seek\n");
|
||||||
|
if (fread(readbuf, 1, size, rom) != size) FATAL_ERROR("read\n");
|
||||||
|
if (fwrite(readbuf, 1, size, file) != size) FATAL_ERROR("write\n");
|
||||||
|
}
|
||||||
|
free(readbuf);
|
||||||
}
|
}
|
||||||
free(readbuf);
|
|
||||||
// Write the EOF magic
|
// Write the EOF magic
|
||||||
fwrite("EOF", 1, 3, file);
|
fwrite("EOF", 1, 3, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
@@ -307,14 +312,15 @@ int main(int argc, char ** argv) {
|
|||||||
"If there are baserom.gba hunks in this project,\n"
|
"If there are baserom.gba hunks in this project,\n"
|
||||||
"please ping PikalaxALT on the pret discord,\n"
|
"please ping PikalaxALT on the pret discord,\n"
|
||||||
"channel #gen-3-help.\n");
|
"channel #gen-3-help.\n");
|
||||||
|
writePatch("baserom.ips", NULL, 0, NULL);
|
||||||
} else {
|
} else {
|
||||||
// Merge neighboring hunks to reduce the number of hunks.
|
// Merge neighboring hunks to reduce the number of hunks.
|
||||||
collapseIncbins(hunks, &num);
|
collapseIncbins(hunks, &num);
|
||||||
// Encode the hunks in the IPS patch.
|
// Encode the hunks in the IPS patch.
|
||||||
writePatch("baserom.ips", hunks, num, rom);
|
writePatch("baserom.ips", hunks, num, rom);
|
||||||
// Communicate status to the user.
|
|
||||||
puts("IPS file created at baserom.ips\n");
|
|
||||||
}
|
}
|
||||||
|
// Communicate status to the user.
|
||||||
|
puts("IPS file created at baserom.ips\n");
|
||||||
// Clean up and return.
|
// Clean up and return.
|
||||||
fclose(rom);
|
fclose(rom);
|
||||||
free(hunks);
|
free(hunks);
|
||||||
|
|||||||
Reference in New Issue
Block a user