| ... | ... |
@@ -53,7 +53,7 @@ SDAT::SDAT(PseudoFile &file, std::uint32_t sseqToLoad) : sseq(), sbnk(), player( |
| 53 | 53 |
// Read SSEQ |
| 54 | 54 |
if (infoSection.SEQrecord.entries.count(sseqToLoad)) |
| 55 | 55 |
{
|
| 56 |
- std::uint32_t fileID = infoSection.SEQrecord.entries[sseqToLoad].fileID; |
|
| 56 |
+ std::uint16_t fileID = infoSection.SEQrecord.entries[sseqToLoad].fileID; |
|
| 57 | 57 |
std::string name = "SSEQ" + NumToHexString(fileID).substr(2); |
| 58 | 58 |
if (SYMBOffset) |
| 59 | 59 |
name = NumToHexString(sseqToLoad).substr(6) + " - " + symbSection.SEQrecord.entries[sseqToLoad]; |
* Use enum class instead of enum (except for the enums for the resource IDs, not really necessary there).
* For NCSF specifically, included a function to convert an enum class to its underlying integral type (as this is needed for use with the std::bitset class).
* Cleanup headers so all the ones needed in a file are explicitly included even if they may possibly be included in another header.
* Used forward declarations in a few spots.
* Explicitly namespaced all (u)int*_t uses (this might seem like overkill, but it helps me see when the standard types are being used with a simple search for std::).
* Made sure it all builds with MinGW-w64 as well (both gcc and clang).
* Removed some std::move from DialogBuilder.cpp based on clang's warnings for that.
* Replaced use of std::copy_n on strings in DialogBuilder.cpp with my CopyToString functions that use wcscpy.
* Replaced CHAR_MIN/CHAR_MAX in eqstr.h and ltstr.h with std::numeric_limits<char>::min/max().
| ... | ... |
@@ -6,25 +6,31 @@ |
| 6 | 6 |
* http://www.feshrine.net/hacking/doc/nds-sdat.html |
| 7 | 7 |
*/ |
| 8 | 8 |
|
| 9 |
-#include "SDAT.h" |
|
| 9 |
+#include <stdexcept> |
|
| 10 |
+#include <string> |
|
| 11 |
+#include <cstdint> |
|
| 12 |
+#include "FATSection.h" |
|
| 13 |
+#include "INFOSection.h" |
|
| 10 | 14 |
#include "NDSStdHeader.h" |
| 15 |
+#include "SBNK.h" |
|
| 16 |
+#include "SDAT.h" |
|
| 17 |
+#include "SSEQ.h" |
|
| 18 |
+#include "SWAR.h" |
|
| 11 | 19 |
#include "SYMBSection.h" |
| 12 |
-#include "INFOSection.h" |
|
| 13 |
-#include "FATSection.h" |
|
| 14 |
-#include "convert.h" |
|
| 20 |
+#include "common.h" |
|
| 15 | 21 |
|
| 16 |
-SDAT::SDAT(PseudoFile &file, uint32_t sseqToLoad) : sseq(), sbnk(), player() |
|
| 22 |
+SDAT::SDAT(PseudoFile &file, std::uint32_t sseqToLoad) : sseq(), sbnk(), player() |
|
| 17 | 23 |
{
|
| 18 | 24 |
// Read sections |
| 19 | 25 |
NDSStdHeader header; |
| 20 | 26 |
header.Read(file); |
| 21 | 27 |
header.Verify("SDAT", 0x0100FEFF);
|
| 22 |
- uint32_t SYMBOffset = file.ReadLE<uint32_t>(); |
|
| 23 |
- file.ReadLE<uint32_t>(); // SYMB size |
|
| 24 |
- uint32_t INFOOffset = file.ReadLE<uint32_t>(); |
|
| 25 |
- file.ReadLE<uint32_t>(); // INFO size |
|
| 26 |
- uint32_t FATOffset = file.ReadLE<uint32_t>(); |
|
| 27 |
- file.ReadLE<uint32_t>(); // FAT Size |
|
| 28 |
+ std::uint32_t SYMBOffset = file.ReadLE<std::uint32_t>(); |
|
| 29 |
+ file.ReadLE<std::uint32_t>(); // SYMB size |
|
| 30 |
+ std::uint32_t INFOOffset = file.ReadLE<std::uint32_t>(); |
|
| 31 |
+ file.ReadLE<std::uint32_t>(); // INFO size |
|
| 32 |
+ std::uint32_t FATOffset = file.ReadLE<std::uint32_t>(); |
|
| 33 |
+ file.ReadLE<std::uint32_t>(); // FAT Size |
|
| 28 | 34 |
SYMBSection symbSection; |
| 29 | 35 |
if (SYMBOffset) |
| 30 | 36 |
{
|
| ... | ... |
@@ -47,7 +53,7 @@ SDAT::SDAT(PseudoFile &file, uint32_t sseqToLoad) : sseq(), sbnk(), player() |
| 47 | 53 |
// Read SSEQ |
| 48 | 54 |
if (infoSection.SEQrecord.entries.count(sseqToLoad)) |
| 49 | 55 |
{
|
| 50 |
- uint16_t fileID = infoSection.SEQrecord.entries[sseqToLoad].fileID; |
|
| 56 |
+ std::uint32_t fileID = infoSection.SEQrecord.entries[sseqToLoad].fileID; |
|
| 51 | 57 |
std::string name = "SSEQ" + NumToHexString(fileID).substr(2); |
| 52 | 58 |
if (SYMBOffset) |
| 53 | 59 |
name = NumToHexString(sseqToLoad).substr(6) + " - " + symbSection.SEQrecord.entries[sseqToLoad]; |
| ... | ... |
@@ -58,7 +64,7 @@ SDAT::SDAT(PseudoFile &file, uint32_t sseqToLoad) : sseq(), sbnk(), player() |
| 58 | 64 |
this->sseq.reset(newSSEQ); |
| 59 | 65 |
|
| 60 | 66 |
// Read SBNK for this SSEQ |
| 61 |
- uint16_t bank = newSSEQ->info.bank; |
|
| 67 |
+ std::uint16_t bank = newSSEQ->info.bank; |
|
| 62 | 68 |
fileID = infoSection.BANKrecord.entries[bank].fileID; |
| 63 | 69 |
name = "SBNK" + NumToHexString(fileID).substr(2); |
| 64 | 70 |
if (SYMBOffset) |
| ... | ... |
@@ -74,7 +80,7 @@ SDAT::SDAT(PseudoFile &file, uint32_t sseqToLoad) : sseq(), sbnk(), player() |
| 74 | 80 |
for (int i = 0; i < 4; ++i) |
| 75 | 81 |
if (newSBNK->info.waveArc[i] != 0xFFFF) |
| 76 | 82 |
{
|
| 77 |
- uint16_t waveArc = newSBNK->info.waveArc[i]; |
|
| 83 |
+ std::uint16_t waveArc = newSBNK->info.waveArc[i]; |
|
| 78 | 84 |
fileID = infoSection.WAVEARCrecord.entries[waveArc].fileID; |
| 79 | 85 |
name = "SWAR" + NumToHexString(fileID).substr(2); |
| 80 | 86 |
if (SYMBOffset) |
* Replace the (w)stringify functions with the standard std::to_(w)string functions.
* Replace convertTo with versions that use type_traits to determine which standard string conversion function to call, as well as handle enums specically.
| ... | ... |
@@ -42,7 +42,7 @@ SDAT::SDAT(PseudoFile &file, uint32_t sseqToLoad) : sseq(), sbnk(), player() |
| 42 | 42 |
throw std::logic_error("No SSEQ records found in SDAT");
|
| 43 | 43 |
|
| 44 | 44 |
if (!infoSection.SEQrecord.entries.count(sseqToLoad)) |
| 45 |
- throw std::range_error("SSEQ of " + stringify(sseqToLoad) + " is not found");
|
|
| 45 |
+ throw std::range_error("SSEQ of " + std::to_string(sseqToLoad) + " is not found");
|
|
| 46 | 46 |
|
| 47 | 47 |
// Read SSEQ |
| 48 | 48 |
if (infoSection.SEQrecord.entries.count(sseqToLoad)) |
(I never remember to update these and besides, GitHub history can show when they were last modified.)
Backwards compatibility is kept by treating the lack of PLAYER info as
if all channels are able to be allocated.
| ... | ... |
@@ -1,7 +1,7 @@ |
| 1 | 1 |
/* |
| 2 | 2 |
* SSEQ Player - SDAT structure |
| 3 | 3 |
* By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com] |
| 4 |
- * Last modification on 2013-03-21 |
|
| 4 |
+ * Last modification on 2014-10-25 |
|
| 5 | 5 |
* |
| 6 | 6 |
* Nintendo DS Nitro Composer (SDAT) Specification document found at |
| 7 | 7 |
* http://www.feshrine.net/hacking/doc/nds-sdat.html |
| ... | ... |
@@ -14,7 +14,7 @@ |
| 14 | 14 |
#include "FATSection.h" |
| 15 | 15 |
#include "convert.h" |
| 16 | 16 |
|
| 17 |
-SDAT::SDAT(PseudoFile &file, uint32_t sseqToLoad) : sseq(), sbnk() |
|
| 17 |
+SDAT::SDAT(PseudoFile &file, uint32_t sseqToLoad) : sseq(), sbnk(), player() |
|
| 18 | 18 |
{
|
| 19 | 19 |
// Read sections |
| 20 | 20 |
NDSStdHeader header; |
| ... | ... |
@@ -89,5 +89,11 @@ SDAT::SDAT(PseudoFile &file, uint32_t sseqToLoad) : sseq(), sbnk() |
| 89 | 89 |
} |
| 90 | 90 |
else |
| 91 | 91 |
this->swar[i].release(); |
| 92 |
+ |
|
| 93 |
+ // Get PLAYER for this SSEQ, if it exists |
|
| 94 |
+ if (!infoSection.PLAYERrecord.entries.empty()) |
|
| 95 |
+ this->player = infoSection.PLAYERrecord.entries[this->sseq->info.ply]; |
|
| 96 |
+ if (!this->player.channelMask) |
|
| 97 |
+ this->player.channelMask = 0xFFFF; |
|
| 92 | 98 |
} |
| 93 | 99 |
} |
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,93 @@ |
| 1 |
+/* |
|
| 2 |
+ * SSEQ Player - SDAT structure |
|
| 3 |
+ * By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com] |
|
| 4 |
+ * Last modification on 2013-03-21 |
|
| 5 |
+ * |
|
| 6 |
+ * Nintendo DS Nitro Composer (SDAT) Specification document found at |
|
| 7 |
+ * http://www.feshrine.net/hacking/doc/nds-sdat.html |
|
| 8 |
+ */ |
|
| 9 |
+ |
|
| 10 |
+#include "SDAT.h" |
|
| 11 |
+#include "NDSStdHeader.h" |
|
| 12 |
+#include "SYMBSection.h" |
|
| 13 |
+#include "INFOSection.h" |
|
| 14 |
+#include "FATSection.h" |
|
| 15 |
+#include "convert.h" |
|
| 16 |
+ |
|
| 17 |
+SDAT::SDAT(PseudoFile &file, uint32_t sseqToLoad) : sseq(), sbnk() |
|
| 18 |
+{
|
|
| 19 |
+ // Read sections |
|
| 20 |
+ NDSStdHeader header; |
|
| 21 |
+ header.Read(file); |
|
| 22 |
+ header.Verify("SDAT", 0x0100FEFF);
|
|
| 23 |
+ uint32_t SYMBOffset = file.ReadLE<uint32_t>(); |
|
| 24 |
+ file.ReadLE<uint32_t>(); // SYMB size |
|
| 25 |
+ uint32_t INFOOffset = file.ReadLE<uint32_t>(); |
|
| 26 |
+ file.ReadLE<uint32_t>(); // INFO size |
|
| 27 |
+ uint32_t FATOffset = file.ReadLE<uint32_t>(); |
|
| 28 |
+ file.ReadLE<uint32_t>(); // FAT Size |
|
| 29 |
+ SYMBSection symbSection; |
|
| 30 |
+ if (SYMBOffset) |
|
| 31 |
+ {
|
|
| 32 |
+ file.pos = SYMBOffset; |
|
| 33 |
+ symbSection.Read(file); |
|
| 34 |
+ } |
|
| 35 |
+ file.pos = INFOOffset; |
|
| 36 |
+ INFOSection infoSection; |
|
| 37 |
+ infoSection.Read(file); |
|
| 38 |
+ file.pos = FATOffset; |
|
| 39 |
+ FATSection fatSection; |
|
| 40 |
+ fatSection.Read(file); |
|
| 41 |
+ |
|
| 42 |
+ if (infoSection.SEQrecord.entries.empty()) |
|
| 43 |
+ throw std::logic_error("No SSEQ records found in SDAT");
|
|
| 44 |
+ |
|
| 45 |
+ if (!infoSection.SEQrecord.entries.count(sseqToLoad)) |
|
| 46 |
+ throw std::range_error("SSEQ of " + stringify(sseqToLoad) + " is not found");
|
|
| 47 |
+ |
|
| 48 |
+ // Read SSEQ |
|
| 49 |
+ if (infoSection.SEQrecord.entries.count(sseqToLoad)) |
|
| 50 |
+ {
|
|
| 51 |
+ uint16_t fileID = infoSection.SEQrecord.entries[sseqToLoad].fileID; |
|
| 52 |
+ std::string name = "SSEQ" + NumToHexString(fileID).substr(2); |
|
| 53 |
+ if (SYMBOffset) |
|
| 54 |
+ name = NumToHexString(sseqToLoad).substr(6) + " - " + symbSection.SEQrecord.entries[sseqToLoad]; |
|
| 55 |
+ file.pos = fatSection.records[fileID].offset; |
|
| 56 |
+ SSEQ *newSSEQ = new SSEQ(name); |
|
| 57 |
+ newSSEQ->info = infoSection.SEQrecord.entries[sseqToLoad]; |
|
| 58 |
+ newSSEQ->Read(file); |
|
| 59 |
+ this->sseq.reset(newSSEQ); |
|
| 60 |
+ |
|
| 61 |
+ // Read SBNK for this SSEQ |
|
| 62 |
+ uint16_t bank = newSSEQ->info.bank; |
|
| 63 |
+ fileID = infoSection.BANKrecord.entries[bank].fileID; |
|
| 64 |
+ name = "SBNK" + NumToHexString(fileID).substr(2); |
|
| 65 |
+ if (SYMBOffset) |
|
| 66 |
+ name = NumToHexString(bank).substr(2) + " - " + symbSection.BANKrecord.entries[bank]; |
|
| 67 |
+ file.pos = fatSection.records[fileID].offset; |
|
| 68 |
+ SBNK *newSBNK = new SBNK(name); |
|
| 69 |
+ newSSEQ->bank = newSBNK; |
|
| 70 |
+ newSBNK->info = infoSection.BANKrecord.entries[bank]; |
|
| 71 |
+ newSBNK->Read(file); |
|
| 72 |
+ this->sbnk.reset(newSBNK); |
|
| 73 |
+ |
|
| 74 |
+ // Read SWARs for this SBNK |
|
| 75 |
+ for (int i = 0; i < 4; ++i) |
|
| 76 |
+ if (newSBNK->info.waveArc[i] != 0xFFFF) |
|
| 77 |
+ {
|
|
| 78 |
+ uint16_t waveArc = newSBNK->info.waveArc[i]; |
|
| 79 |
+ fileID = infoSection.WAVEARCrecord.entries[waveArc].fileID; |
|
| 80 |
+ name = "SWAR" + NumToHexString(fileID).substr(2); |
|
| 81 |
+ if (SYMBOffset) |
|
| 82 |
+ name = NumToHexString(waveArc).substr(2) + " - " + symbSection.WAVEARCrecord.entries[waveArc]; |
|
| 83 |
+ file.pos = fatSection.records[fileID].offset; |
|
| 84 |
+ SWAR *newSWAR = new SWAR(name); |
|
| 85 |
+ newSBNK->waveArc[i] = newSWAR; |
|
| 86 |
+ newSWAR->info = infoSection.WAVEARCrecord.entries[waveArc]; |
|
| 87 |
+ newSWAR->Read(file); |
|
| 88 |
+ this->swar[i].reset(newSWAR); |
|
| 89 |
+ } |
|
| 90 |
+ else |
|
| 91 |
+ this->swar[i].release(); |
|
| 92 |
+ } |
|
| 93 |
+} |