Update br_ips to generate an empty patch when no hunks are found
This commit is contained in:
@@ -255,9 +255,13 @@ 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 (rom != NULL) {
|
||||||
|
readbuf = malloc(0x10000);
|
||||||
if (readbuf == NULL) FATAL_ERROR("failed to allocate write buffer\n");
|
if (readbuf == NULL) FATAL_ERROR("failed to allocate write buffer\n");
|
||||||
|
}
|
||||||
fwrite("PATCH", 1, 5, file); // magic
|
fwrite("PATCH", 1, 5, file); // magic
|
||||||
|
if (readbuf != NULL) {
|
||||||
for (int i = 0; i < num; i++) {
|
for (int i = 0; i < num; i++) {
|
||||||
// Encode the offset
|
// Encode the offset
|
||||||
uint32_t offset = hunks[i].offset;
|
uint32_t offset = hunks[i].offset;
|
||||||
@@ -274,6 +278,7 @@ static void writePatch(const char * filename, const hunk_t * hunks, size_t num,
|
|||||||
if (fwrite(readbuf, 1, size, file) != size) FATAL_ERROR("write\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.
|
// Communicate status to the user.
|
||||||
puts("IPS file created at baserom.ips\n");
|
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