Auto pad and overlap detection (#47)

* Fully implemented pad and overlap detection

* Cleaned code, fixed pad generation and added alignment

* Added debug size on pads
This commit is contained in:
Lywx
2024-03-20 21:17:11 -06:00
committed by GitHub
parent 8465919ab7
commit f0c70f855a
62 changed files with 405 additions and 407 deletions
+6 -6
View File
@@ -6,29 +6,29 @@
#include "utils/TorchUtils.h"
TypeData::TypeData(uint32_t data): mData(data) {
}
void TypeHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
ExportResult TypeHeaderExporter::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 char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return;
return std::nullopt;
}
write << "extern Type " << symbol << ";\n";
// write << "extern Type " << symbol << "[];\n";
}
void TypeCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult TypeCodeExporter::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);
const auto offset = GetSafeNode<uint32_t>(node, "offset");
auto data = std::static_pointer_cast<TypeData>(raw);
}
void TypeBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult TypeBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
}
+3 -7
View File
@@ -12,23 +12,20 @@ public:
};
class TypeHeaderExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class TypeBinaryExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class TypeCodeExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class TypeFactory : public BaseFactory {
public:
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override {
return std::nullopt;
}
inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
return {
REGISTER(Code, TypeCodeExporter)
@@ -36,6 +33,5 @@ public:
REGISTER(Binary, TypeBinaryExporter)
};
}
bool SupportModdedAssets() override { return false; }
};
// }
+109 -35
View File
@@ -48,6 +48,8 @@ namespace fs = std::filesystem;
static const std::string regular = "[%Y-%m-%d %H:%M:%S.%e] [%l] %v";
static const std::string line = "[%Y-%m-%d %H:%M:%S.%e] [%l] > %v";
#define ABS(x) ((x) < 0 ? -(x) : (x))
void Companion::Init(const ExportType type) {
spdlog::set_level(spdlog::level::debug);
@@ -137,7 +139,7 @@ void Companion::ParseEnums(std::string& header) {
enumIndex++;
this->gEnums[enumName][enumIndex] = line;
}
}
}
@@ -210,6 +212,8 @@ void Companion::ExtractNode(YAML::Node& node, std::string& name, SWrapper* binar
spdlog::set_pattern(line);
}
ExportResult endptr = std::nullopt;
switch (this->gConfig.exporterType) {
case ExportType::Binary: {
if(binary == nullptr) {
@@ -246,29 +250,58 @@ void Companion::ExtractNode(YAML::Node& node, std::string& name, SWrapper* binar
file.close();
break;
}
default: {
exporter->get()->Export(stream, result.value(), name, node, &name);
if(this->gConfig.exporterType == ExportType::Code) {
if(node["pad"]){
auto filename = this->gCurrentDirectory.filename().string();
auto pad = GetSafeNode<uint32_t>(node, "pad");
stream << "char pad_" << filename << "_" << std::to_string(gCurrentPad++) << "[] = {\n" << tab;
for(int i = 0; i < pad; i++){
stream << "0x00, ";
}
stream << "\n};\n\n";
}
case ExportType::Code: {
endptr = exporter->get()->Export(stream, result.value(), name, node, &name);
if (this->IsDebug() && endptr.has_value() && endptr->index() == 0) {
stream << "// 0x" << std::hex << std::uppercase << std::get<0>(endptr.value()) << "\n\n";
}
break;
}
default: {
endptr = exporter->get()->Export(stream, result.value(), name, node, &name);
break;
}
}
SPDLOG_INFO("Processed {}", name);
WriteEntry entry;
if(node["offset"]) {
this->gWriteMap[this->gCurrentFile][type].emplace_back(node["offset"].as<uint32_t>(), stream.str());
auto alignment = GetSafeNode<uint32_t>(node, "alignment", impl->GetAlignment());
if(!endptr.has_value()) {
entry = {
node["offset"].as<uint32_t>(),
alignment,
stream.str(),
std::nullopt
};
} else {
switch (endptr->index()) {
case 0:
entry = {
node["offset"].as<uint32_t>(),
alignment,
stream.str(),
std::get<size_t>(endptr.value())
};
break;
case 1: {
const auto oentry = std::get<OffsetEntry>(endptr.value());
entry = {
oentry.start,
alignment,
stream.str(),
oentry.end
};
break;
}
default:
SPDLOG_ERROR("Invalid endptr index {}", endptr->index());
SPDLOG_ERROR("Type of endptr: {}", typeid(endptr).name());
throw std::runtime_error("We should never reach this point");
}
}
}
this->gWriteMap[this->gCurrentFile][type].push_back(entry);
}
void Companion::ParseModdingConfig() {
@@ -355,6 +388,8 @@ void Companion::ParseCurrentFileConfig(YAML::Node node) {
const auto offset = GetSafeNode<uint32_t>(vram, "offset");
this->gCurrentVram = { addr, offset };
}
this->gEnablePadGen = GetSafeNode<bool>(node, "autopads", true);
}
void Companion::Process() {
@@ -699,44 +734,83 @@ void Companion::Process() {
std::ostringstream stream;
std::vector<WriteEntry> entries;
if(std::holds_alternative<std::string>(this->gWriteOrder)) {
auto sort = std::get<std::string>(this->gWriteOrder);
std::vector<std::pair<uint32_t, std::string>> outbuf;
for (const auto& [type, buffer] : this->gWriteMap[this->gCurrentFile]) {
outbuf.insert(outbuf.end(), buffer.begin(), buffer.end());
for (const auto& [type, raw] : this->gWriteMap[this->gCurrentFile]) {
entries.insert(entries.end(), raw.begin(), raw.end());
}
this->gWriteMap.clear();
if(sort == "OFFSET") {
std::sort(outbuf.begin(), outbuf.end(), [](const auto& a, const auto& b) {
return std::get<uint32_t>(a) < std::get<uint32_t>(b);
std::sort(entries.begin(), entries.end(), [](const auto& a, const auto& b) {
return a.addr < b.addr;
});
} else if(sort == "ROFFSET") {
std::sort(outbuf.begin(), outbuf.end(), [](const auto& a, const auto& b) {
return std::get<uint32_t>(a) > std::get<uint32_t>(b);
std::sort(entries.begin(), entries.end(), [](const auto& a, const auto& b) {
return a.addr > b.addr;
});
} else if(sort != "LINEAR") {
throw std::runtime_error("Invalid write order");
}
for (auto& [symbol, buffer] : outbuf) {
stream << buffer;
}
outbuf.clear();
} else {
for (const auto& type : std::get<std::vector<std::string>>(this->gWriteOrder)) {
std::vector<std::pair<uint32_t, std::string>> outbuf = this->gWriteMap[this->gCurrentFile][type];
entries = this->gWriteMap[this->gCurrentFile][type];
std::sort(outbuf.begin(), outbuf.end(), [](const auto& a, const auto& b) {
return std::get<uint32_t>(a) > std::get<uint32_t>(b);
std::sort(entries.begin(), entries.end(), [](const auto& a, const auto& b) {
return a.addr > b.addr;
});
}
}
for (auto& [symbol, buffer] : outbuf) {
stream << buffer;
for (size_t i = 0; i < entries.size(); i++) {
const auto result = entries[i];
stream << result.buffer;
if(i < entries.size() - 1 && this->gConfig.exporterType == ExportType::Code){
auto endptr = result.endptr;
if(!endptr.has_value()){
continue;
}
#define ASSET_PTR(x) IS_SEGMENTED(x) ? SEGMENT_OFFSET(x) : x
uint32_t startptr = ASSET_PTR(result.endptr.value());
uint32_t end = ASSET_PTR(entries[i + 1].addr);
uint32_t alignment = entries[i + 1].alignment;
int32_t gap = end - startptr;
if(gap < 0x10 && gap >= alignment && end % 0x10 == 0 && this->gEnablePadGen) {
SPDLOG_WARN("Gap detected between 0x{:X} and 0x{:X} with size 0x{:X} on file {}", startptr, end, gap, this->gCurrentFile);
SPDLOG_WARN("Creating pad of 0x{:X} bytes", gap);
const auto padfile = this->gCurrentDirectory.filename().string();
if(this->IsDebug()){
stream << "// 0x" << std::hex << startptr << "\n";
}
stream << "char pad_" << padfile << "_" << std::to_string(gCurrentPad++) << "[] = {\n" << tab;
auto gapSize = gap & ~3;
for(size_t j = 0; j < gapSize; j++){
stream << "0x00, ";
}
stream << "\n};\n";
if(this->IsDebug()){
stream << "// 0x" << std::hex << end << "\n\n";
} else {
stream << "\n";
}
} else if(gap > 0x10) {
stream << "\n// WARNING: Gap detected between 0x" << std::hex << startptr << " and 0x" << end << " with size 0x" << gap << " on file " << this->gCurrentFile << "\n";
}
if(gap < 0) {
SPDLOG_WARN("Overlap detected between 0x{:X} and 0x{:X}", startptr, end);
}
}
}
this->gWriteMap.clear();
std::string buffer = stream.str();
if(buffer.empty()) {
@@ -1002,7 +1076,7 @@ std::optional<YAML::Node> Companion::AddAsset(YAML::Node asset) {
std::string output;
std::string typeId = ConvertType(type);
int index;
if(symbol != "") {
output = symbol;
} else if(Decompressor::IsSegmented(offset)){
+9 -1
View File
@@ -51,6 +51,13 @@ struct VRAMEntry {
uint32_t offset;
};
struct WriteEntry {
uint32_t addr;
uint32_t alignment;
std::string buffer;
std::optional<uint32_t> endptr;
};
struct GBIConfig {
GBIVersion version = GBIVersion::f3d;
GBIMinorVersion subversion = GBIMinorVersion::None;
@@ -123,6 +130,7 @@ private:
// Temporal Variables
std::string gCurrentFile;
std::string gFileHeader;
bool gEnablePadGen = false;
uint32_t gCurrentPad = 0;
uint32_t gCurrentFileOffset;
uint32_t gCurrentSegmentNumber;
@@ -132,8 +140,8 @@ private:
std::variant<std::vector<std::string>, std::string> gWriteOrder;
std::unordered_map<std::string, std::shared_ptr<BaseFactory>> gFactories;
std::unordered_map<std::string, std::string> gModdedAssetPaths;
std::unordered_map<std::string, std::map<std::string, std::vector<WriteEntry>>> gWriteMap;
std::unordered_map<std::string, std::map<std::string, std::pair<YAML::Node, bool>>> gAssetDependencies;
std::unordered_map<std::string, std::map<std::string, std::vector<std::pair<uint32_t, std::string>>>> gWriteMap;
std::unordered_map<std::string, std::unordered_map<uint32_t, std::tuple<std::string, YAML::Node>>> gAddrMap;
void ParseEnums(std::string& file);
-4
View File
@@ -5,11 +5,7 @@
class AudioHeaderFactory : public BaseFactory {
public:
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override {
return std::nullopt;
}
inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
return {};
}
bool SupportModdedAssets() override { return false; }
};
+2 -1
View File
@@ -1,7 +1,7 @@
#include "BankFactory.h"
#include "Companion.h"
void BankBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult BankBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto writer = LUS::BinaryWriter();
auto bank = std::static_pointer_cast<BankData>(raw);
@@ -84,6 +84,7 @@ void BankBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData
}
writer.Finish(write);
return std::nullopt;
}
std::optional<std::shared_ptr<IParsedData>> BankFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& data) {
+1 -5
View File
@@ -14,19 +14,15 @@ public:
};
class BankBinaryExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class BankFactory : public BaseFactory {
public:
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override {
return std::nullopt;
}
inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
return {
REGISTER(Binary, BankBinaryExporter)
};
}
bool SupportModdedAssets() override { return false; }
};
+18 -3
View File
@@ -4,6 +4,7 @@
#include "n64/Cartridge.h"
#include <cstdint>
#include <iostream>
#include <any>
#include <memory>
#include <vector>
#include <string>
@@ -23,6 +24,13 @@
#define tab "\t"
#define fourSpaceTab " "
struct OffsetEntry {
uint32_t start;
uint32_t end;
};
typedef std::optional<std::variant<size_t, OffsetEntry>> ExportResult;
enum class ExportType {
Header,
Code,
@@ -67,14 +75,16 @@ public:
class BaseExporter {
public:
virtual void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) = 0;
virtual ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) = 0;
static void WriteHeader(LUS::BinaryWriter& write, LUS::ResourceType resType, int32_t version);
};
class BaseFactory {
public:
virtual std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) = 0;
virtual std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) = 0;
virtual std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) {
return std::nullopt;
}
std::optional<std::shared_ptr<BaseExporter>> GetExporter(ExportType type) {
auto exporters = this->GetExporters();
if (exporters.find(type) != exporters.end()) {
@@ -82,7 +92,12 @@ public:
}
return std::nullopt;
}
virtual bool SupportModdedAssets() = 0;
virtual bool SupportModdedAssets() {
return false;
}
virtual uint32_t GetAlignment() {
return 4;
};
private:
virtual std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() = 0;
};
+5 -10
View File
@@ -3,7 +3,7 @@
#include "utils/Decompressor.h"
#include <iomanip>
void BlobCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult BlobCodeExporter::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;
@@ -31,19 +31,13 @@ void BlobCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData>
write << "\n};\n";
if (Companion::Instance->IsDebug()) {
const auto sz = data.size();
write << "// size: 0x" << std::hex << std::uppercase << sz << "\n";
if (IS_SEGMENTED(offset)) {
offset = SEGMENT_OFFSET(offset);
}
write << "// 0x" << std::hex << std::uppercase << (offset + sz) << "\n";
write << "// size: 0x" << std::hex << std::uppercase << data.size() << "\n";
}
write << "\n";
return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + data.size();
}
void BlobBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult BlobBinaryExporter::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;
@@ -51,6 +45,7 @@ void BlobBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData
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>> BlobFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
+2 -6
View File
@@ -3,24 +3,20 @@
#include "BaseFactory.h"
#include "../types/RawBuffer.h"
class BlobBinaryExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class BlobCodeExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class BlobFactory : public BaseFactory {
public:
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override {
return std::nullopt;
}
inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
return {
REGISTER(Binary, BlobBinaryExporter)
REGISTER(Code, BlobCodeExporter)
};
}
bool SupportModdedAssets() override { return false; }
};
+7 -11
View File
@@ -64,18 +64,19 @@ void GFXDSetGBIVersion(){
}
}
void DListHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
ExportResult DListHeaderExporter::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 char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return;
return std::nullopt;
}
write << "extern Gfx " << symbol << "[];\n";
return std::nullopt;
}
void DListCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult DListCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
const auto cmds = std::static_pointer_cast<DListData>(raw)->mGfxs;
const auto symbol = GetSafeNode(node, "symbol", entryName);
auto offset = GetSafeNode<uint32_t>(node, "offset");
@@ -125,18 +126,13 @@ void DListCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData>
write << std::string(out);
write << "};\n";
const auto sz = (sizeof(uint32_t) * cmds.size());
if (Companion::Instance->IsDebug()) {
const auto sz = (sizeof(uint32_t) * cmds.size());
write << "// count: " << std::to_string(sz / 8) << " Gfx\n";
if (IS_SEGMENTED(offset)) {
offset = SEGMENT_OFFSET(offset);
}
write << "// 0x" << std::hex << std::uppercase << (offset + sz) << "\n";
}
write << "\n";
return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + sz;
}
void DebugDisplayList(uint32_t w0, uint32_t w1){
@@ -181,7 +177,7 @@ std::optional<std::tuple<std::string, YAML::Node>> SearchVtx(uint32_t ptr){
return std::nullopt;
}
void DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto cmds = std::static_pointer_cast<DListData>(raw)->mGfxs;
auto writer = LUS::BinaryWriter();
+6 -7
View File
@@ -12,23 +12,20 @@ public:
};
class DListHeaderExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class DListBinaryExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class DListCodeExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class DListFactory : public BaseFactory {
public:
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override {
return std::nullopt;
}
std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
return {
REGISTER(Header, DListHeaderExporter)
@@ -36,5 +33,7 @@ public:
REGISTER(Code, DListCodeExporter)
};
}
bool SupportModdedAssets() override { return false; }
uint32_t GetAlignment() override {
return 8;
};
};
+7 -4
View File
@@ -4,18 +4,19 @@
#include "spdlog/spdlog.h"
#include "Companion.h"
void LightsHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
ExportResult LightsHeaderExporter::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 char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return;
return std::nullopt;
}
write << "extern Lights1 " << symbol << ";\n";
return std::nullopt;
}
void LightsCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult LightsCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto light = std::static_pointer_cast<LightsData>(raw)->mLights;
auto symbol = GetSafeNode(node, "symbol", entryName);
@@ -44,9 +45,10 @@ void LightsCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData
write << r2 << ", " << g2 << ", " << b2 << ", " << x << ", " << y << ", " << z << "\n";
write << ");\n\n";
return std::nullopt;
}
void LightsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult LightsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto light = std::static_pointer_cast<LightsData>(raw)->mLights;
auto writer = LUS::BinaryWriter();
auto size = sizeof(light.l) / sizeof(LightRaw);
@@ -65,6 +67,7 @@ void LightsBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedDa
}
writer.Finish(write);
writer.Close();
return std::nullopt;
}
std::optional<std::shared_ptr<IParsedData>> LightsFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& node) {
+3 -7
View File
@@ -42,23 +42,20 @@ public:
};
class LightsHeaderExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class LightsBinaryExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class LightsCodeExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class LightsFactory : public BaseFactory {
public:
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override {
return std::nullopt;
}
inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
return {
REGISTER(Code, LightsCodeExporter)
@@ -66,5 +63,4 @@ public:
REGISTER(Binary, LightsBinaryExporter)
};
}
bool SupportModdedAssets() override { return false; }
};
+2 -1
View File
@@ -1,6 +1,6 @@
#include "SampleFactory.h"
void SampleBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult SampleBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto writer = LUS::BinaryWriter();
auto sample = std::static_pointer_cast<SampleData>(raw)->mSample;
@@ -30,6 +30,7 @@ void SampleBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedDa
writer.Write(sample.name);
writer.Finish(write);
return std::nullopt;
}
std::optional<std::shared_ptr<IParsedData>> SampleFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& data) {
+1 -5
View File
@@ -13,19 +13,15 @@ public:
};
class SampleBinaryExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class SampleFactory : public BaseFactory {
public:
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override {
return std::nullopt;
}
std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
return {
REGISTER(Binary, SampleBinaryExporter)
};
}
bool SupportModdedAssets() override { return false; }
};
+2 -1
View File
@@ -1,6 +1,6 @@
#include "SequenceFactory.h"
void SequenceBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
ExportResult SequenceBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
auto writer = LUS::BinaryWriter();
const auto sequence = std::static_pointer_cast<SequenceData>(raw);
@@ -13,6 +13,7 @@ void SequenceBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsed
writer.Write( sequence->mSize);
writer.Write(reinterpret_cast<char*>(sequence->mBuffer.data()), sequence->mSize);
writer.Finish(write);
return std::nullopt;
}
std::optional<std::shared_ptr<IParsedData>> SequenceFactory::parse(std::vector<uint8_t>& buffer, YAML::Node& data) {
+1 -5
View File
@@ -15,19 +15,15 @@ public:
};
class SequenceBinaryExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class SequenceFactory : public BaseFactory {
public:
std::optional<std::shared_ptr<IParsedData>> parse(std::vector<uint8_t>& buffer, YAML::Node& data) override;
std::optional<std::shared_ptr<IParsedData>> parse_modding(std::vector<uint8_t>& buffer, YAML::Node& data) override {
return std::nullopt;
}
inline std::unordered_map<ExportType, std::shared_ptr<BaseExporter>> GetExporters() override {
return {
REGISTER(Binary, SequenceBinaryExporter)
};
}
bool SupportModdedAssets() override { return false; }
};
+12 -15
View File
@@ -79,14 +79,14 @@ std::vector<uint8_t> alloc_ia8_text_from_i1(uint16_t *in, int16_t width, int16_t
return result;
}
void TextureHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
ExportResult TextureHeaderExporter::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);
const auto offset = GetSafeNode<uint32_t>(node, "offset");
auto data = std::static_pointer_cast<TextureData>(raw)->mBuffer;
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return;
return std::nullopt;
}
const auto searchTable = Companion::Instance->SearchTable(offset);
@@ -95,16 +95,17 @@ void TextureHeaderExporter::Export(std::ostream &write, std::shared_ptr<IParsedD
const auto [name, start, end, mode] = searchTable.value();
if(start != offset){
return;
return std::nullopt;
}
write << "extern " << GetSafeNode<std::string>(node, "ctype", "u8") << " " << name << "[][" << data.size() << "];\n";
} else {
write << "extern " << GetSafeNode<std::string>(node, "ctype", "u8") << " " << symbol << "[];\n";
}
return std::nullopt;
}
void TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
ExportResult TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
auto texture = std::static_pointer_cast<TextureData>(raw);
auto data = texture->mBuffer;
auto offset = GetSafeNode<uint32_t>(node, "offset");
@@ -169,27 +170,21 @@ void TextureCodeExporter::Export(std::ostream &write, std::shared_ptr<IParsedDat
}
write << "// 0x" << std::hex << std::uppercase << offset << "\n";
}
write << GetSafeNode<std::string>(node, "ctype", "static const u8") << " " << symbol << "[] = {\n";
write << tab << "#include \"" << Companion::Instance->GetOutputPath() + "/" << *replacement << ".inc.c\"\n";
write << "};\n";
const auto sz = data.size();
if (Companion::Instance->IsDebug()) {
const auto sz = data.size();
write << "// size: 0x" << std::hex << std::uppercase << sz << "\n";
if (IS_SEGMENTED(offset)) {
offset = SEGMENT_OFFSET(offset);
}
write << "// 0x" << std::hex << std::uppercase << (offset + sz) << "\n";
}
write << "\n";
}
return (IS_SEGMENTED(offset) ? SEGMENT_OFFSET(offset) : offset) + data.size();
}
void TextureBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
ExportResult TextureBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement) {
auto writer = LUS::BinaryWriter();
auto texture = std::static_pointer_cast<TextureData>(raw);
auto data = texture->mBuffer;
@@ -203,9 +198,10 @@ void TextureBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedD
writer.Write((uint32_t) data.size());
writer.Write((char*) data.data(), data.size());
writer.Finish(write);
return std::nullopt;
}
void TextureModdingExporter::Export(std::ostream&write, std::shared_ptr<IParsedData> data, std::string&entryName, YAML::Node&node, std::string* replacement) {
ExportResult TextureModdingExporter::Export(std::ostream&write, std::shared_ptr<IParsedData> data, std::string&entryName, YAML::Node&node, std::string* replacement) {
auto texture = std::static_pointer_cast<TextureData>(data);
auto format = texture->mFormat;
uint8_t* raw = new uint8_t[CalculateTextureSize(format.type, texture->mWidth, texture->mHeight) * 2];
@@ -258,6 +254,7 @@ void TextureModdingExporter::Export(std::ostream&write, std::shared_ptr<IParsedD
}
write.write(reinterpret_cast<char*>(raw), size);
return std::nullopt;
}
+4 -4
View File
@@ -33,19 +33,19 @@ public:
};
class TextureHeaderExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class TextureCodeExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class TextureBinaryExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class TextureModdingExporter : public BaseExporter {
void Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
ExportResult Export(std::ostream& write, std::shared_ptr<IParsedData> data, std::string& entryName, YAML::Node& node, std::string* replacement) override;
};
class TextureFactory : public BaseFactory {

Some files were not shown because too many files have changed in this diff Show More