Skip to content

Commit

Permalink
Add manifest support to -I
Browse files Browse the repository at this point in the history
  • Loading branch information
Alcaro committed May 17, 2017
1 parent ef813f6 commit 37db058
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
45 changes: 43 additions & 2 deletions flips.cpp
Expand Up @@ -839,7 +839,7 @@ struct errorinfo CreatePatch(LPCWSTR inromname, LPCWSTR outromname, enum patchty
return errinf;
}

int patchinfo(LPCWSTR patchname)
int patchinfo(LPCWSTR patchname, struct manifestinfo * manifestinfo)
{
GUIClaimConsole();

Expand All @@ -860,6 +860,28 @@ int patchinfo(LPCWSTR patchname)
return bpserrors[info.error].level;
}

struct mem meta = {};
if (info.meta_size)
{
meta.len = info.meta_size;
meta.ptr = (uint8_t*)malloc(info.meta_size);
patch->read(meta.ptr, info.meta_start, info.meta_size);

if (manifestinfo->required)
{
if (manifestinfo->name)
{
filewrite::write(manifestinfo->name, meta);
}
else
{
fwrite(meta.ptr, 1,meta.len, stdout);
free(meta.ptr);
return 0;
}
}
}

LPCWSTR inromname = FindRomForPatch(patch, NULL);
#ifdef FLIPS_WINDOWS
#define z "I"
Expand All @@ -876,6 +898,25 @@ int patchinfo(LPCWSTR patchname)
//Windows MulDiv could also work, but it's kinda nonportable.
//printf("Change index: %i / 1000\n", (int)(info.change_num / (float)info.change_denom * 1000));

if (info.meta_size)
{
printf("Metadata: %" z "u bytes:\n", info.meta_size);
char* meta_iter = (char*)meta.ptr;
char* meta_end = meta_iter + meta.len;
for (int i=0;i<3;i++)
{
int n_chars = meta_end-meta_iter;
if (n_chars > 75) n_chars = 75;
char* nextline = (char*)memchr(meta_iter, '\n', n_chars);
if (nextline && nextline-meta_iter < n_chars) n_chars = nextline-meta_iter;
if (!nextline && !n_chars) break; // wipe trailing linebreaks
printf(" %.*s\n", n_chars, meta_iter);
if (!nextline) break;
meta_iter = nextline+1;
}
}

free(meta.ptr);
return 0;
}
puts("No information available for this patch type");
Expand Down Expand Up @@ -1115,7 +1156,7 @@ int flipsmain(int argc, WCHAR * argv[])
case a_info:
{
if (numargs!=1) usage();
return patchinfo(arg[0]);
return patchinfo(arg[0], &manifestinfo);
}
}
return 99;//doesn't happen
Expand Down
2 changes: 1 addition & 1 deletion global.h
Expand Up @@ -33,7 +33,7 @@ class file {
virtual size_t len() = 0;
virtual bool read(uint8_t* target, size_t start, size_t len) = 0;

//these two add sizeof(WCHAR) 00s after the actual data, so you can cast it to LPCWSTR (assuming it's aligned)
//these two add sizeof(WCHAR) 00s after the actual data, so you can cast it to LPCWSTR
static struct mem read(LPCWSTR filename); // provided by Flips core
struct mem read(); // provided by Flips core

Expand Down
3 changes: 3 additions & 0 deletions libbps.cpp
Expand Up @@ -410,6 +410,9 @@ struct bpsinfo bps_get_info(file* patch, bool changefrac)
if (!decodenum(patchdat, ret.size_in)) error(bps_too_big);
if (!decodenum(patchdat, ret.size_out)) error(bps_too_big);

if (!decodenum(patchdat, ret.meta_size)) error(bps_too_big);
ret.meta_start = patchdat - top;

uint8_t checksums[12];
if (!patch->read(checksums, len-12, 12)) error(bps_io);
ret.crc_in = read32(checksums+0);
Expand Down
3 changes: 3 additions & 0 deletions libbps.h
Expand Up @@ -74,6 +74,9 @@ struct bpsinfo {
uint32_t crc_out;
uint32_t crc_patch;

size_t meta_start;
size_t meta_size;

//Tells approximately how much of the input ROM is changed compared to the output ROM.
//It's quite heuristic. The algorithm may change with or without notice.
//As of writing, I believe this is accurate to 2 significant digits in base 10.
Expand Down

0 comments on commit 37db058

Please sign in to comment.