Fill in more features

This commit is contained in:
Alcaro
2017-01-05 03:52:07 +01:00
parent aae27f20da
commit cd7d68256b
7 changed files with 253 additions and 162 deletions

View File

@@ -7,8 +7,8 @@
// or maybe only Read/Copy commands? Read is TargetRead, Copy treats target as concatenated to source
//- Invert 0x80 bit in the encoded numbers, set means continue; it would simplify the decoder
//- Replace BPS1 signature with something not containing an 1
// while DWORD alignment sounds nice, it's useless for a byte-oriented format like this; even the checksums aren't aligned
// four-byte signatures are nicer than three, but '1' is the wrong choice for the last byte; PNGs \x89 would work
// I prefer four-byte signatures over three, but this format is intended to never ever change, so appending '1' is the wrong choice
// PNGs \x89 would work
//- Make the checksums mandatory
// (1) Ignoring them allows all files of that size, including ones that are clearly not the proper source
// (2) Even if a ROM hacker is careful to only change a few bytes, BPS likes copying stuff around,
@@ -67,7 +67,7 @@ result apply(arrayview<byte> patchmem, arrayview<byte> inmem, array<byte>& outme
size_t metadatalen;
decodeto(metadatalen);
patch.bytes(metadatalen); // discard this, grab it from info::parse
patch.bytes(metadatalen); // discard this, you can grab it from info::parse
while (patch.remaining())
{

View File

@@ -5,18 +5,23 @@ type identify(const file& patch)
{
byte head[16];
size_t len = patch.read(arrayview<byte>(head));
if (len>=5 && !memcmp(head, "PATCH", 5)) return t_ips;
if (len>=4 && !memcmp(head, "UPS1", 4)) return t_ups;
if (len>=4 && !memcmp(head, "BPS1", 4)) return t_bps;
return t_unknown;
return identify(arrayview<byte>(head, len));
}
type identify(arrayview<byte> patch)
{
if (patch.size()>=5 && !memcmp(patch.ptr(), "PATCH", 5)) return ty_ips;
if (patch.size()>=4 && !memcmp(patch.ptr(), "UPS1", 4)) return ty_ups;
if (patch.size()>=4 && !memcmp(patch.ptr(), "BPS1", 4)) return ty_bps;
return ty_unknown;
}
type identify_ext(cstring path)
{
if (path.endswith(".ips")) return t_ips;
if (path.endswith(".ups")) return t_ups;
if (path.endswith(".bps")) return t_bps;
return t_unknown;
if (path.endswith(".ips")) return ty_ips;
if (path.endswith(".ups")) return ty_ups;
if (path.endswith(".bps")) return ty_bps;
return ty_unknown;
}
bool memstream::bpsnum(size_t* out)

View File

@@ -3,12 +3,13 @@
namespace patch {
enum type {
t_unknown,
t_ips,
t_ups,
t_bps
ty_unknown,
ty_ips,
ty_ups,
ty_bps
};
type identify(const file& patch);
type identify(arrayview<byte> patch);
type identify_ext(cstring path);
enum result {

View File

@@ -175,13 +175,13 @@ test("the big ones")
testbps=true;
//testbps=false;
array<byte> smw = file::read("patch/test/smw.sfc");
array<byte> smw_bps = file::read("patch/test/smwcp.bps");
array<byte> dl = file::read("patch/test/langrisser.sfc");
array<byte> dl_ups = file::read("patch/test/dl.ups");
array<byte> sm64 = file::read("patch/test/sm64.z64");
array<byte> sm64_bps = file::read("patch/test/star.bps");
if (!smw || !smw_bps || !dl || !dl_ups || !sm64 || !sm64_bps) test_skip("test files not present; see patch/test/readme.txt");
array<byte> smw = file::read("test/smw.sfc");
array<byte> smw_bps = file::read("test/smwcp.bps");
array<byte> dl = file::read("test/langrisser.sfc");
array<byte> dl_ups = file::read("test/dl.ups");
array<byte> sm64 = file::read("test/sm64.z64");
array<byte> sm64_bps = file::read("test/star.bps");
if (!smw || !smw_bps || !dl || !dl_ups || !sm64 || !sm64_bps) test_skip("test files not present; see test/readme.txt");
array<byte> smwhack;
result smwr = bps::apply(smw_bps, smw, smwhack);

View File

@@ -1,9 +0,0 @@
These files are copyrighted, large, and not very relevant to Floating IPS. You'll have to fill them in yourself.
MD5 checksums and sources:
8134163af1e658a3f1af130afd66d17a dl.ups http://superfamicom.org/translations/info/der-langrisser-english
91d62c4cb790fc2fb38b10b68616e228 langrisser.sfc
20b854b239203baf6c961b850a4a51a2 sm64.z64
b38466ee8ae3130f3cf1c94f9c7655c0 smwcp.bps https://smwc.me/s/5420
cdd3c8c37322978ca8669b34bc89c804 smw.sfc
461ae37a8c9d3a4e1990c9b8907b716f star.bps https://smwc.me/s/13353