From 582b2a1933e0c87935479688256a79aa42343aeb Mon Sep 17 00:00:00 2001 From: modeco80 Date: Sun, 19 Nov 2023 07:29:42 -0500 Subject: [PATCH] pull in decompiled decompressor I need to figure out how decompressed sizes are done before fully making this work. --- src/main.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1426d58..45b1897 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,67 @@ #include #include +std::vector BoltDecompress(std::span data) { + u8* inptr = data.data(); + std::vector res; + + i32 iVar3; + i32 iVar6; + u32 uVar5; + u32 pbVar4; // outrun + + for(u32 i = 0; i < data.size(); ++i) { + auto uVar7 = inptr[i]; + + if(uVar7 < 128) { + iVar3 = iVar3 + uVar5 * 8 + ((int)(uVar7 & 0x70) >> 4); + pbVar4 = -(iVar6 * 0x10 + (uVar7 & 0xf) + 1); + iVar6 = iVar3 + 1; + + + + if(iVar3 != -2) { + do { + //*pOut = *pbVar4; + pbVar4 = pbVar4 + 1; + //bVar1 = iVar6 != 0; + // pOut = pOut + 1; + iVar6 = iVar6 + -1; + } while(iVar6 != 0); + } + iVar6 = 0; + iVar3 = 0; + uVar5 = 0; + } else if(uVar7 < 144) { + iVar3 = uVar5 * 0x10 + (uVar7 & 0xf) + 1; + while(iVar3 != 0) { + iVar3 = iVar3 + -1; + //*pOut = *pbRam00590aa8; + // pOut = pOut + 1; + // pbRam00590aa8 = pbRam00590aa8 + 1; + // iRam00590ab0 = iRam00590ab0 + -1; + // if(iRam00590ab0 == 0) { + // NextBlock(); + //} + } + iVar3 = 0; + uVar5 = 0; + } else if(uVar7 < 160) { + uVar5 = uVar7 & 3; + iVar3 = iVar3 + 1; + iVar6 = (int)(uVar7 & 0xc) >> 2; + } else if(uVar7 < 192) { + uVar5 = uVar5 * 0x20 + (uVar7 & 0x1f); + iVar3 = iVar3 + 1; + } else { + iVar3 = iVar3 + 1; + iVar6 = iVar6 * 0x40 + (uVar7 & 0x3f); + } + } + + return res; +} + struct BoltReader { struct ParsedTableEntry { std::string_view filename; @@ -64,17 +125,10 @@ struct BoltReader { if(file.uncompressedData.empty()) { auto gid = (file.gid >> 8); auto entries = lib->GroupDescriptors()[gid].Entries(boltFile.GetMapping()); - - // std::cout << std::format("ptr: {} {:08x}\n", (void*)entries.data(), (u32)(std::bit_cast(entries.data()) - (usize)lib)); - auto size = entries[file.index & 0x00ff].fileSize; auto offset = entries[file.index & 0x00ff].fileOffset; file.uncompressedData = { std::bit_cast(boltFile.GetMapping() + offset), size }; - - // for(i32 i = 0; i < entries.size(); ++i) { - // std::cout << std::format("dick {}: {:08x}\n", i, entries[i].fileOffset); - // } } if(!f(file))