diff --git a/src/common/mmap.h b/src/common/mmap.h index 9e076b5..5a8a9ce 100644 --- a/src/common/mmap.h +++ b/src/common/mmap.h @@ -19,4 +19,12 @@ struct stream { p += sizeof(T) * len; return s; } + template + void operator=(const T &v) { + memcpy(p, (uint8_t*)&v, sizeof(v)); + p += sizeof(v); + } + void skip(size_t len) { + p += len; + } }; diff --git a/src/common/types.h b/src/common/types.h index ec72cc7..5bd57e1 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -327,6 +327,20 @@ struct ModificatorMask #pragma pack(push, 1) struct pak { + static constexpr uint32_t default_block_size = 0x4000; + + struct segment { + // some file offset? trash? crc? m1 has zlib crc table (png)? + uint32_t unk1; + uint32_t algorithm; + uint32_t offset; + }; + struct file_description { + char name[0x50]; + uint32_t offset; + uint32_t size; + }; + uint32_t magic; uint16_t unk0; uint32_t n_files; @@ -334,20 +348,4 @@ struct pak { uint32_t block_size; uint32_t unk1; }; -struct file_description { - const char name[0x50]; - uint32_t offset; - uint32_t size; -}; -struct segment { - enum decode_algorithm : uint32_t { - none = 0x0, - // none = 0x1, // ? - }; - - // some file offset? trash? crc? m1 has zlib crc table (png)? - uint32_t unk1; - decode_algorithm algorithm; - uint32_t offset; -}; #pragma pack(pop) diff --git a/src/unpaker/unpaker.cpp b/src/unpaker/unpaker.cpp index be90d4c..2e6bb6c 100644 --- a/src/unpaker/unpaker.cpp +++ b/src/unpaker/unpaker.cpp @@ -44,8 +44,8 @@ void unpack_file(path fn) { primitives::templates2::mmap_file f{fn}; stream s{f}; pak p = s; - auto descs = s.span(p.n_files); - auto segments = s.span(p.n_blocks); + auto descs = s.span(p.n_files); + auto segments = s.span(p.n_blocks); std::vector decoded; decoded.resize((segments.size() + 1) * p.block_size * 4); auto pp = decoded.data();