mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Extracted Sequences
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -73,6 +73,6 @@ enum class ResourceType {
|
||||
AdpcmLoop = 0x4150434C, // APCL
|
||||
AdpcmBook = 0x41504342, // APCB
|
||||
Envelope = 0x45564C50, // EVLP
|
||||
AudioTable = 0x4154424C
|
||||
AudioTable = 0x4154424C // ATBL
|
||||
};
|
||||
} // namespace LUS
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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)
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user