diff options
Diffstat (limited to 'src/preprocess/CompTool.cpp')
| -rw-r--r-- | src/preprocess/CompTool.cpp | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/preprocess/CompTool.cpp b/src/preprocess/CompTool.cpp index bd7182e..3b04a2e 100644 --- a/src/preprocess/CompTool.cpp +++ b/src/preprocess/CompTool.cpp @@ -6,15 +6,17 @@ #include <cstring> uint32_t CompTool::FindFileTable(std::vector<uint8_t>& rom) { - uint8_t query_one[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x50, 0x00, 0x00, 0x00, 0x00 }; - uint8_t query_two[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x60, 0x00, 0x00, 0x00, 0x00 }; + uint8_t query_one[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x10, 0x50, 0x00, 0x00, 0x00, 0x00 }; + uint8_t query_two[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x10, 0x60, 0x00, 0x00, 0x00, 0x00 }; - for(size_t i = 0; i < rom.size() - sizeof(query_one); i++) { - if(memcmp(rom.data() + i, query_one, sizeof(query_one)) == 0){ + for (size_t i = 0; i < rom.size() - sizeof(query_one); i++) { + if (memcmp(rom.data() + i, query_one, sizeof(query_one)) == 0) { return i; } - if(memcmp(rom.data() + i, query_two, sizeof(query_two)) == 0){ + if (memcmp(rom.data() + i, query_two, sizeof(query_two)) == 0) { return i; } } @@ -24,8 +26,7 @@ uint32_t CompTool::FindFileTable(std::vector<uint8_t>& rom) { #define ROL(i, b) ((i << (b)) | (i >> (32 - (b)))) -std::pair<uint32_t, uint32_t> CompTool::CalculateCRCs(LUS::BinaryWriter& decompFile) -{ +std::pair<uint32_t, uint32_t> CompTool::CalculateCRCs(LUS::BinaryWriter& decompFile) { uint32_t start = 0x1000; uint32_t end = 0x101000; LUS::BinaryReader readFile(decompFile.GetStream()); @@ -55,8 +56,8 @@ std::pair<uint32_t, uint32_t> CompTool::CalculateCRCs(LUS::BinaryWriter& decompF return std::make_pair(t6 ^ t4 ^ t3, t5 ^ t2 ^ t1); } -std::vector<uint8_t> CompTool::Decompress(std::vector<uint8_t> rom){ - LUS::BinaryReader basefile((char*) rom.data(), rom.size()); +std::vector<uint8_t> CompTool::Decompress(std::vector<uint8_t> rom) { + LUS::BinaryReader basefile((char*)rom.data(), rom.size()); basefile.SetEndianness(Torch::Endianness::Big); LUS::BinaryWriter decompfile; @@ -65,7 +66,7 @@ std::vector<uint8_t> CompTool::Decompress(std::vector<uint8_t> rom){ uint32_t table = CompTool::FindFileTable(rom); uint32_t count = 0; - while (true){ + while (true) { auto entry = table + 0x10 * count; basefile.Seek(entry, LUS::SeekOffsetType::Start); @@ -75,19 +76,19 @@ std::vector<uint8_t> CompTool::Decompress(std::vector<uint8_t> rom){ auto comp_flag = basefile.ReadInt32(); auto p_size = p_end - p_begin; - auto v_size = (int32_t) 0; + auto v_size = (int32_t)0; DataChunk* decoded = nullptr; - if(v_begin == 0 && p_end == 0){ + if (v_begin == 0 && p_end == 0) { break; } basefile.Seek(p_begin, LUS::SeekOffsetType::Start); auto bytes = new uint8_t[p_size]; - basefile.Read((char*) bytes, p_size); + basefile.Read((char*)bytes, p_size); - switch ((CompType) comp_flag) { + switch ((CompType)comp_flag) { case CompType::UNCOMPRESSED: v_size = p_size; break; @@ -101,13 +102,13 @@ std::vector<uint8_t> CompTool::Decompress(std::vector<uint8_t> rom){ } decompfile.Seek(v_begin, LUS::SeekOffsetType::Start); - decompfile.Write((char*) bytes, v_size); + decompfile.Write((char*)bytes, v_size); auto v_end = v_begin + v_size; decompfile.Seek(entry + 4, LUS::SeekOffsetType::Start); decompfile.Write(v_begin); decompfile.Write(v_end); - decompfile.Write((uint32_t) CompType::UNCOMPRESSED); + decompfile.Write((uint32_t)CompType::UNCOMPRESSED); count++; } @@ -115,9 +116,9 @@ std::vector<uint8_t> CompTool::Decompress(std::vector<uint8_t> rom){ decompfile.Seek(0x10, LUS::SeekOffsetType::Start); - decompfile.Write(crcs.first); // CRC1 + decompfile.Write(crcs.first); // CRC1 decompfile.Write(crcs.second); // CRC2 auto result = decompfile.ToVector(); - return { (uint8_t*) result.data(), (uint8_t*) result.data() + result.size() }; + return { (uint8_t*)result.data(), (uint8_t*)result.data() + result.size() }; }
\ No newline at end of file |
