summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKiritoDv <kiritodev01@gmail.com>2024-11-19 18:50:28 -0600
committerLywx <kiritodev01@gmail.com>2024-11-21 00:05:17 -0600
commit7ee72b8a9f09877d53dd81cf34e9ffb1865df33e (patch)
treeb6fa089ce6ec98b2ee750bbc5c938e4eebbb7b5f
parentfe18878a73cb184dfd844127f2d8a959fd887470 (diff)
Extracted Sequences
-rw-r--r--src/Companion.cpp2
-rw-r--r--src/factories/ResourceType.h2
-rw-r--r--src/factories/naudio/v1/AudioTableFactory.cpp20
-rw-r--r--src/factories/naudio/v1/SequenceFactory.cpp65
-rw-r--r--src/factories/naudio/v1/SequenceFactory.h28
5 files changed, 111 insertions, 6 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp
index 19c4f1a..e16c670 100644
--- a/src/Companion.cpp
+++ b/src/Companion.cpp
@@ -76,6 +76,7 @@
#include "factories/naudio/v1/EnvelopeFactory.h"
#include "factories/naudio/v1/LoopFactory.h"
#include "factories/naudio/v1/BookFactory.h"
+#include "factories/naudio/v1/SequenceFactory.h"
using namespace std::chrono;
namespace fs = std::filesystem;
@@ -159,6 +160,7 @@ void Companion::Init(const ExportType type) {
this->RegisterFactory("NAUDIO:V1:ENVELOPE", std::make_shared<EnvelopeFactory>());
this->RegisterFactory("NAUDIO:V1:ADPCM_LOOP", std::make_shared<ADPCMLoopFactory>());
this->RegisterFactory("NAUDIO:V1:ADPCM_BOOK", std::make_shared<ADPCMBookFactory>());
+ this->RegisterFactory("NAUDIO:V1:SEQUENCE", std::make_shared<NSequenceFactory>());
this->Process();
}
diff --git a/src/factories/ResourceType.h b/src/factories/ResourceType.h
index 9c9a062..b92be30 100644
--- a/src/factories/ResourceType.h
+++ b/src/factories/ResourceType.h
@@ -73,6 +73,6 @@ enum class ResourceType {
AdpcmLoop = 0x4150434C, // APCL
AdpcmBook = 0x41504342, // APCB
Envelope = 0x45564C50, // EVLP
- AudioTable = 0x4154424C
+ AudioTable = 0x4154424C // ATBL
};
} // namespace LUS
diff --git a/src/factories/naudio/v1/AudioTableFactory.cpp b/src/factories/naudio/v1/AudioTableFactory.cpp
index b30c7c9..7a7f265 100644
--- a/src/factories/naudio/v1/AudioTableFactory.cpp
+++ b/src/factories/naudio/v1/AudioTableFactory.cpp
@@ -132,11 +132,21 @@ std::optional<std::shared_ptr<IParsedData>> AudioTableFactory::parse(std::vector
auto entry = AudioTableEntry { addr, size, medium, policy, sd1, sd2, sd3 };
entries.push_back(entry);
- if(type == AudioTableType::FONT_TABLE){
- YAML::Node font;
- font["type"] = "NAUDIO:V1:SOUND_FONT";
- font["offset"] = addr;
- Companion::Instance->AddAsset(font);
+ switch (type) {
+ case AudioTableType::FONT_TABLE: {
+ YAML::Node font;
+ font["type"] = "NAUDIO:V1:SOUND_FONT";
+ font["offset"] = addr;
+ Companion::Instance->AddAsset(font);
+ break;
+ }
+ case AudioTableType::SEQ_TABLE: {
+ YAML::Node seq;
+ seq["type"] = "NAUDIO:V1:SEQUENCE";
+ seq["offset"] = addr;
+ Companion::Instance->AddAsset(seq);
+ break;
+ }
}
AudioContext::tables[type][addr] = entry;
diff --git a/src/factories/naudio/v1/SequenceFactory.cpp b/src/factories/naudio/v1/SequenceFactory.cpp
new file mode 100644
index 0000000..1d95cf4
--- /dev/null
+++ b/src/factories/naudio/v1/SequenceFactory.cpp
@@ -0,0 +1,65 @@
+#include "SequenceFactory.h"
+#include "Companion.h"
+#include "utils/Decompressor.h"
+#include "AudioContext.h"
+
+ExportResult NSequenceHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
+ const auto symbol = GetSafeNode(node, "symbol", entryName);
+
+ if(Companion::Instance->IsOTRMode()){
+ write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
+ return std::nullopt;
+ }
+
+ write << "extern u8 " << symbol << "[];\n";
+
+ return std::nullopt;
+}
+
+ExportResult NSequenceCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
+ auto symbol = GetSafeNode(node, "symbol", entryName);
+ auto offset = GetSafeNode<uint32_t>(node, "offset");
+ auto data = std::static_pointer_cast<RawBuffer>(raw)->mBuffer;
+
+ if(Companion::Instance->IsOTRMode()){
+ write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
+ return std::nullopt;
+ }
+
+ write << GetSafeNode<std::string>(node, "ctype", "u8") << " " << symbol << "[] = {\n" << tab_t;
+
+ for (int i = 0; i < data.size(); i++) {
+ if ((i % 15 == 0) && i != 0) {
+ write << "\n" << tab_t;
+ }
+
+ write << "0x" << std::hex << std::setw(2) << std::setfill('0') << (int) data[i] << ", ";
+ }
+ write << "\n};\n";
+
+ if (Companion::Instance->IsDebug()) {
+ write << "// size: 0x" << std::hex << std::uppercase << data.size() << "\n";
+ }
+
+ return offset + data.size();
+}
+
+ExportResult NSequenceBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
+ auto writer = LUS::BinaryWriter();
+ auto data = std::static_pointer_cast<RawBuffer>(raw)->mBuffer;
+
+ // Its the same shit as a blob
+ WriteHeader(writer, Torch::ResourceType::Blob, 0);
+ writer.Write((uint32_t) data.size());
+ writer.Write((char*) data.data(), data.size());
+ writer.Finish(write);
+ return std::nullopt;
+}
+
+std::optional<std::shared_ptr<IParsedData>> NSequenceFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
+ auto offset = GetSafeNode<uint32_t>(node, "offset");
+ auto entry = AudioContext::tables[AudioTableType::SEQ_TABLE].at(offset);
+ auto data = AudioContext::data[AudioTableType::SEQ_TABLE];
+
+ return std::make_shared<RawBuffer>((uint8_t*) data.data() + entry.addr, entry.size);
+}
diff --git a/src/factories/naudio/v1/SequenceFactory.h b/src/factories/naudio/v1/SequenceFactory.h
new file mode 100644
index 0000000..bc4e89d
--- /dev/null
+++ b/src/factories/naudio/v1/SequenceFactory.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "factories/BaseFactory.h"
+#include "types/RawBuffer.h"
+
+class NSequenceHeaderExporter : public BaseExporter {
+ ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
+};
+
+class NSequenceBinaryExporter : public BaseExporter {
+ ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
+};
+
+class NSequenceCodeExporter : public BaseExporter {
+ ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
+};
+
+class NSequenceFactory : public BaseFactory {
+public:
+ std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
+ inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
+ return {
+ REGISTER(Header, NSequenceHeaderExporter)
+ REGISTER(Binary, NSequenceBinaryExporter)
+ REGISTER(Code, NSequenceCodeExporter)
+ };
+ }
+};