libnedit
Lightweight C++ library for Nintendo DS(i) formats
Loading...
Searching...
No Matches
fmt_SDAT.hpp
1
2#pragma once
3#include <ntr/fmt/fmt_Common.hpp>
4#include <ntr/fs/fs_Stdio.hpp>
5
6namespace ntr::fmt {
7
8 struct SDAT : public fs::ExternalFsFileFormat {
9
10 struct Header : public CommonHeader<0x54414453 /* "SDAT" */ > {
11 u32 symb_offset;
12 u32 symb_size;
13 u32 info_offset;
14 u32 info_size;
15 u32 fat_offset;
16 u32 fat_size;
17 u32 file_offset;
18 u32 file_size;
19 u8 unk_pad[16];
20 };
21
23 u32 name_offset;
24 std::string name;
25 };
26
27 struct SymbolRecord {
28 u32 entry_count;
29 std::vector<SymbolRecordEntry> entries;
30 };
31
33 u32 name_offset;
34 std::string name;
35 u32 subrecord_offset;
36 SymbolRecord subrecord;
37 };
38
40 u32 entry_count;
41 std::vector<SequenceArchiveSymbolRecordEntry> entries;
42 };
43
44 struct SymbolBlock : public CommonBlock<0x424D5953 /* "SYMB" */ > {
45 u32 seq_record_offset;
46 u32 seq_arc_record_offset;
47 u32 bnk_record_offset;
48 u32 wav_arc_record_offset;
49 u32 player_record_offset;
50 u32 group_record_offset;
51 u32 strm_player_record_offset;
52 u32 strm_record_offset;
53 u8 unk_pad[24];
54 };
55
56 struct SequenceInfo {
57 u32 file_id;
58 u16 bank_file_id;
59 u8 volume;
60 u8 channel_prio;
61 u8 player_prio;
62 u8 player_no;
63 u8 unk_pad[2];
64 };
65
67 u32 file_id;
68 };
69
70 struct BankInfo {
71 u32 file_id;
72 u16 wave_arcs[4];
73 };
74
76 union {
77 struct {
78 u32 file_id : 24;
79 u32 flags : 8;
80 };
81 u32 val;
82 };
83 };
84
85 struct PlayerInfo {
86 u8 seq_max;
87 u8 pad;
88 u16 alloc_ch_bit_flag;
89 u32 heap_size;
90 };
91
92 struct GroupInfo {
93 u32 count;
94 };
95
97 u8 channel_count;
98 u8 channel_nos[16];
99 u8 pad[7];
100 };
101
102 struct StreamInfo {
103 u32 file_id;
104 u8 volume;
105 u8 player_prio;
106 u8 player_no;
107 u8 flags;
108 };
109
110 template<typename T>
112 u32 info_offset;
113 T info;
114 };
115
116 template<typename T>
117 struct InfoRecord {
118 u32 entry_count;
119 std::vector<InfoRecordEntry<T>> entries;
120 };
121
122 struct InfoBlock : public CommonBlock<0x4F464E49 /* "INFO" */ > {
123 u32 seq_record_offset;
124 u32 seq_arc_record_offset;
125 u32 bnk_record_offset;
126 u32 wav_arc_record_offset;
127 u32 player_record_offset;
128 u32 group_record_offset;
129 u32 strm_player_record_offset;
130 u32 strm_record_offset;
131 u8 unk_pad[24];
132 };
133
135 u32 offset;
136 u32 size;
137 u8 unk_pad[8];
138 };
139
140 struct FileAllocationTableBlock : public CommonBlock<0x20544146 /* "FAT " */ > {
141 u32 record_count;
142 };
143
144 struct FileBlock : public CommonBlock<0x454C4946 /* "FILE" */ > {
145 u32 file_count;
146 };
147
148 static constexpr auto SSEQVirtualDirectoryName = "sseq";
149 static constexpr auto SSARVirtualDirectoryName = "ssar";
150 static constexpr auto SBNKVirtualDirectoryName = "sbnk";
151 static constexpr auto SWARVirtualDirectoryName = "swar";
152 static constexpr auto STRMVirtualDirectoryName = "strm";
153
154 inline static std::string MakeSWARPath(const std::string &swar_file) {
155 return SWARVirtualDirectoryName + ("/" + swar_file);
156 }
157
158 Header header;
159 SymbolBlock symb;
160 InfoBlock info;
161 FileAllocationTableBlock fat;
162 FileBlock file;
163
164 SymbolRecord seq_symb_record;
165 SequenceArchiveSymbolRecord seq_arc_symb_record;
166 SymbolRecord bnk_symb_record;
167 SymbolRecord wav_arc_symb_record;
168 SymbolRecord player_symb_record;
169 SymbolRecord group_symb_record;
170 SymbolRecord strm_player_symb_record;
171 SymbolRecord strm_symb_record;
172
173 InfoRecord<SequenceInfo> seq_info_record;
174 InfoRecord<SequenceArchiveInfo> seq_arc_info_record;
175 InfoRecord<BankInfo> bnk_info_record;
176 InfoRecord<WaveArchiveInfo> wav_arc_info_record;
177 InfoRecord<PlayerInfo> player_info_record;
178 InfoRecord<GroupInfo> group_info_record;
179 InfoRecord<StreamPlayerInfo> strm_player_info_record;
180 InfoRecord<StreamInfo> strm_info_record;
181 std::vector<FileAllocationTableRecord> fat_records;
182
183 SDAT() {}
184 SDAT(const SDAT&) = delete;
185
186 inline bool HasSymbols() {
187 return this->header.symb_size > 0;
188 }
189
190 Result LocateFile(const std::string &path, u32 &out_file_id);
191
192 Result ValidateImpl(const std::string &path, std::shared_ptr<fs::FileHandle> file_handle, const fs::FileCompression comp) override;
193 Result ReadImpl(const std::string &path, std::shared_ptr<fs::FileHandle> file_handle, const fs::FileCompression comp) override;
194
195 Result SaveFileSystem() override;
196 };
197
199 u32 file_id;
200 fs::BinaryFile base_bf;
201
202 SDATFileHandle(std::shared_ptr<SDAT> sdat) : fs::ExternalFsFileHandle<SDAT>(sdat) {}
203
204 inline const u32 GetFileOffset() {
205 return this->ext_fs_file->fat_records.at(this->file_id).offset;
206 }
207
208 inline const u32 GetFileSize() {
209 return this->ext_fs_file->fat_records.at(this->file_id).size;
210 }
211
212 bool ExistsImpl(const std::string &path, size_t &out_size) override;
213 Result OpenImpl(const std::string &path) override;
214 Result GetSizeImpl(size_t &out_soze) override;
215 Result SetOffsetImpl(const size_t offset, const fs::Position pos) override;
216 Result GetOffsetImpl(size_t &out_offst) override;
217 Result ReadImpl(void *read_buf, const size_t read_size, size_t &out_read_size) override;
218 Result CloseImpl() override;
219 };
220
221}
Definition fs_BinaryFile.hpp:9
Definition ntr_Include.hpp:75
Definition fmt_Common.hpp:53
Definition fmt_Common.hpp:35
Definition fmt_SDAT.hpp:198
Definition fmt_SDAT.hpp:70
Definition fmt_SDAT.hpp:140
Definition fmt_SDAT.hpp:144
Definition fmt_SDAT.hpp:92
Definition fmt_SDAT.hpp:10
Definition fmt_SDAT.hpp:122
Definition fmt_SDAT.hpp:111
Definition fmt_SDAT.hpp:117
Definition fmt_SDAT.hpp:85
Definition fmt_SDAT.hpp:66
Definition fmt_SDAT.hpp:56
Definition fmt_SDAT.hpp:102
Definition fmt_SDAT.hpp:96
Definition fmt_SDAT.hpp:44
Definition fmt_SDAT.hpp:22
Definition fmt_SDAT.hpp:27
Definition fmt_SDAT.hpp:75
Definition fmt_SDAT.hpp:8
Definition fs_Base.hpp:92
Definition fs_Stdio.hpp:39