NSUNI/NSLAR Library a250670
Loading...
Searching...
No Matches
dig.hpp
Go to the documentation of this file.
1
12#pragma once
13
14#include <map>
15#include <vector>
16
18#include "NNL/common/io.hpp"
19
20namespace nnl {
21
29
34namespace dig {
40
52template <typename TData = Buffer>
60
68
76
90using Dig = std::vector<FileRecord>;
101using DigView = std::vector<FileRecordView>;
102
115bool IsOfType(BufferView buffer);
116
117bool IsOfType(const std::filesystem::path& path);
118
119bool IsOfType(Reader& f);
139
140Dig Import(const std::filesystem::path& path);
141
142Dig Import(Reader& f);
162
172[[nodiscard]] Buffer Export(const Dig& cfcdig);
173
174void Export(const Dig& cfcdig, const std::filesystem::path& path);
175
176void Export(const Dig& cfcdig, Writer& f);
177
178[[nodiscard]] Buffer Export(const DigView& cfcdig);
179
180void Export(const DigView& cfcdig, const std::filesystem::path& path);
181
182void Export(const DigView& cfcdig, Writer& f);
184
191
204Buffer Decompress(BufferView buffer, u32 decompressed_size);
215
216namespace raw {
223constexpr u32 kBlockSize = 0x800U;
224
225NNL_PACK(struct RFileRecord {
226 u32 offset = 0; // in blocks (*0x800)
227 u32 compressed_size = 0;
228 u16 num_entries = 0;
229 u16 is_compressed = 0;
230 u32 decompressed_size = 0;
231});
232
233static_assert(sizeof(RFileRecord) == 0x10);
234
235template <typename TData = Buffer>
236struct RDig {
237 std::vector<RFileRecord> file_records;
238
239 // Maps of offsets (used in the structures above) to their data:
240 std::map<u32, TData> file_buffers;
241};
242
243RDig<Buffer> Parse(Reader& f);
244
245RDig<BufferView> ParseView(BufferView f);
246
247Dig Convert(RDig<Buffer>&& cfcdig);
248
249DigView Convert(RDig<BufferView>&& cfcdig);
251} // namespace raw
252
253} // namespace dig
254
255} // namespace nnl
Contains macros and definitions for fixed-width types.
Buffer Compress(BufferView buffer)
Compress binary data.
Buffer Decompress(BufferView buffer, u32 decompressed_size)
Decompress binary data.
bool is_compressed
Definition dig.hpp:54
u32 decompressed_size
Definition dig.hpp:55
Buffer buffer
Definition dig.hpp:58
u16 num_entries
Definition dig.hpp:57
A raw entry in the dig archive.
Definition dig.hpp:53
TFileRecord< BufferView > FileRecordView
A raw entry in the dig archive.
Definition dig.hpp:75
TFileRecord< Buffer > FileRecord
A raw entry in the dig archive.
Definition dig.hpp:67
std::vector< FileRecord > Dig
A primary game data archive.
Definition dig.hpp:90
std::vector< FileRecordView > DigView
A non-owning view of a dig archive.
Definition dig.hpp:101
bool IsOfType(BufferView buffer)
Tests if the provided file is a dig archive.
DigView ImportView(BufferView buffer)
Parses a binary file and converts it into DigView.
Buffer Export(const Dig &cfcdig)
Converts a dig archive to a binary file representation.
Dig Import(BufferView buffer)
Parses a binary file and converts it into a Dig object.
constexpr u32 kBlockSize
The size of an LBA sector in bytes.
Definition dig.hpp:223
std::uint16_t u16
16-bit unsigned integer
Definition fixed_type.hpp:62
std::uint32_t u32
32-bit unsigned integer
Definition fixed_type.hpp:60
#define NNL_PACK(...)
A structure packing directive.
Definition fixed_type.hpp:41
Reader implementation for read-only memory buffers.
Definition io.hpp:598
Abstract class for writing data.
Definition io.hpp:136
Abstract class for reading data.
Definition io.hpp:78
std::vector< u8 > Buffer
A type alias for std::vector<u8> that denotes a raw, contiguous memory region that may be interpreted...
Definition io.hpp:40
Provides classes for reading and writing binary data to and from various sources.
Provides structures and functions to manage primary game archives.
Definition dig.hpp:34
Definition exception.hpp:56