Fixed otr header generation and fixed some binary exporters

This commit is contained in:
KiritoDv
2024-04-08 18:09:34 -06:00
committed by Lywx
parent b1d39534f3
commit 3918fde51a
31 changed files with 245 additions and 184 deletions
+3 -1
View File
@@ -973,7 +973,9 @@ void Companion::Process() {
file.close();
}
this->gHashNode[this->gCurrentFile]["extracted"][ExportTypeToString(this->gConfig.exporterType)] = true;
if(this->gConfig.exporterType != ExportType::Binary) {
this->gHashNode[this->gCurrentFile]["extracted"][ExportTypeToString(this->gConfig.exporterType)] = true;
}
}
if(wrapper != nullptr) {
+4 -4
View File
@@ -1,10 +1,10 @@
#include "BaseFactory.h"
void BaseExporter::WriteHeader(LUS::BinaryWriter &writer, LUS::ResourceType resType, int32_t version) {
writer.Write((uint8_t)(LUS::Endianness::Native)); // 0x00
writer.Write((uint8_t)0); // 0x01
writer.Write((uint8_t)0); // 0x02
writer.Write((uint8_t)0); // 0x03
writer.Write((int8_t)(LUS::Endianness::Native)); // 0x00 - Endianness
writer.Write((int8_t)0); // 0x01 - Is Asset Custom
writer.Write((int8_t)0); // 0x02 -
writer.Write((int8_t)0); // 0x03
writer.Write((uint32_t) resType); // 0x04
writer.Write((uint32_t) version); // 0x08
writer.Write((uint64_t) 0xDEADBEEFDEADBEEF); // id, 0x0C
+5
View File
@@ -8,6 +8,11 @@ ExportResult BlobCodeExporter::Export(std::ostream &write, std::shared_ptr<IPars
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;
for (int i = 0; i < data.size(); i++) {
+64 -5
View File
@@ -82,7 +82,7 @@ ExportResult DListHeaderExporter::Export(std::ostream &write, std::shared_ptr<IP
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
@@ -188,13 +188,14 @@ std::optional<std::tuple<std::string, YAML::Node>> SearchVtx(uint32_t ptr){
}
ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IParsedData> raw, std::string& entryName, YAML::Node &node, std::string* replacement ) {
const auto gbi = Companion::Instance->GetGBIVersion();
auto cmds = std::static_pointer_cast<DListData>(raw)->mGfxs;
auto writer = LUS::BinaryWriter();
WriteHeader(writer, LUS::ResourceType::DisplayList, 0);
while (writer.GetBaseAddress() % 8 != 0)
writer.Write(static_cast<uint8_t>(0xFF));
writer.Write(static_cast<int8_t>(0xFF));
auto bhash = CRC64((*replacement).c_str());
writer.Write(static_cast<uint32_t>((G_MARKER << 24)));
@@ -208,9 +209,53 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
uint8_t opcode = w0 >> 24;
if(opcode == GBI(G_VTX)) {
auto nvtx = (C0(0, 16)) / sizeof(Vtx);
auto didx = C0(16, 4);
size_t nvtx;
size_t didx;
switch (gbi) {
case GBIVersion::f3dex2:
nvtx = C0(12, 8);
didx = C0(1, 7) - C0(12, 8);
break;
case GBIVersion::f3dex:
case GBIVersion::f3dexb:
nvtx = C0(10, 6);
didx = C0(17, 7);
break;
default:
nvtx = (C0(0, 16)) / sizeof(Vtx_t);
didx = C0(16, 4);
break;
}
auto ptr = w1;
auto overlap = GFXDOverride::GetVtxOverlap(ptr);
if(overlap.has_value()){
auto ovnode = std::get<1>(overlap.value());
uint64_t hash = CRC64(std::get<0>(overlap.value()).c_str());
SPDLOG_INFO("Found vtx: 0x{:X} Hash: 0x{:X} Path: {}", ptr, hash, std::get<0>(overlap.value()));
auto offset = GetSafeNode<uint32_t>(ovnode, "offset");
auto count = GetSafeNode<uint32_t>(ovnode, "count");
auto diff = ASSET_PTR(ptr) - ASSET_PTR(offset);
Gfx value = gsSPVertexOTR(diff, nvtx, ((didx >> 1) - nvtx));
SPDLOG_INFO("gsSPVertexOTR({}, {}, {})", diff, nvtx, didx);
w0 = value.words.w0;
w1 = value.words.w1;
writer.Write(w0);
writer.Write(w1);
w0 = hash >> 32;
w1 = hash & 0xFFFFFFFF;
} else {
SPDLOG_WARN("Could not find vtx at 0x{:X}", ptr);
}
auto dec = Companion::Instance->GetNodeByAddr(ptr);
if(dec.has_value()){
@@ -260,9 +305,23 @@ ExportResult DListBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
auto ptr = w1;
auto dec = Companion::Instance->GetNodeByAddr(ptr);
uint8_t index = 0;
uint8_t offset = 0;
switch (gbi) {
case GBIVersion::f3d:
index = C0(0, 8);
offset = 0;
break;
default:
index = C0(0, 8);
offset = C0(8, 8) * 8;
break;
}
w0 &= 0x00FFFFFF;
w0 += G_MOVEMEM_OTR_HASH << 24;
w1 = 0;
w1 = _SHIFTL(index, 24, 8) | _SHIFTL(offset, 16, 8);
writer.Write(w0);
writer.Write(w1);
+2 -2
View File
@@ -11,7 +11,7 @@ ExportResult FloatHeaderExporter::Export(std::ostream &write, std::shared_ptr<IP
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
@@ -41,7 +41,7 @@ ExportResult FloatCodeExporter::Export(std::ostream &write, std::shared_ptr<IPar
* f32 sym[] = {
* 0.1, 0.2, 0.3,
* };
*
*
*/
for (int i = 0; i < f.size(); ++i) {
+1 -1
View File
@@ -165,7 +165,7 @@ ExportResult ArrayHeaderExporter::Export(std::ostream &write, std::shared_ptr<IP
const auto type = GetSafeNode<std::string>(node, "array_type");
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
+1 -1
View File
@@ -12,7 +12,7 @@ ExportResult IncludeHeaderExporter::Export(std::ostream &write, std::shared_ptr<
auto ctype = GetSafeNode<std::string>(node, "ctype");
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
+2 -2
View File
@@ -8,7 +8,7 @@ ExportResult LightsHeaderExporter::Export(std::ostream &write, std::shared_ptr<I
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
@@ -37,7 +37,7 @@ ExportResult LightsCodeExporter::Export(std::ostream &write, std::shared_ptr<IPa
if(searchTable.has_value()){
const auto [name, start, end, mode] = searchTable.value();
if(start == offset){
write << "Lights1 " << name << "[] = {\n";
+6 -6
View File
@@ -11,7 +11,7 @@ ExportResult MtxHeaderExporter::Export(std::ostream &write, std::shared_ptr<IPar
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
@@ -34,7 +34,7 @@ ExportResult MtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParse
}
write << "// 0x" << std::hex << std::uppercase << offset << "\n";
}
#define fiveFourSpaceTabs fourSpaceTab << fourSpaceTab << fourSpaceTab << fourSpaceTab << fourSpaceTab << " "
/**
@@ -43,7 +43,7 @@ ExportResult MtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParse
* 0.0, 0.0, 1.0, 0.0,
* 0.0, 0.0, 0.0, 1.0);
*/
write << "Mtx " << symbol << " = {\n";
for (int i = 0; i < m.size(); ++i) {
@@ -64,7 +64,7 @@ ExportResult MtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParse
write << std::fixed << std::setprecision(6) << m[i].mtx[j];
}
}
// Add comma for all but the last arg
if (j < 15) {
write << ", ";
@@ -80,7 +80,7 @@ ExportResult MtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParse
}
break;
}
// Add lots of spaces for start of a new line
if ((j + 1) % 4 == 0) {
write << "\n" << fiveFourSpaceTabs;
@@ -206,7 +206,7 @@ std::optional<std::shared_ptr<IParsedData>> MtxFactory::parse(std::vector<uint8_
m13, m14, m15, m16,
}));
}
#undef FIXTOF
return std::make_shared<MtxData>(matrix);
+28 -10
View File
@@ -11,6 +11,7 @@ extern "C" {
}
bool isTable = false;
std::vector<std::string> tableEntries;
static const std::unordered_map <std::string, TextureFormat> gTextureFormats = {
{ "RGBA16", { TextureType::RGBA16bpp, 16 } },
@@ -83,28 +84,41 @@ std::vector<uint8_t> alloc_ia8_text_from_i1(uint16_t *in, int16_t width, int16_t
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 format = GetSafeNode<std::string>(node, "format");
auto texture = std::static_pointer_cast<TextureData>(raw);
auto data = texture->mBuffer;
auto isOTR = Companion::Instance->IsOTRMode();
size_t byteSize = std::max(1, (int) (texture->mFormat.depth / 8));
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
const auto searchTable = Companion::Instance->SearchTable(offset);
if(searchTable.has_value()){
const auto [name, start, end, mode] = searchTable.value();
if(start != offset){
return std::nullopt;
}
if(isOTR){
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "extern " << GetSafeNode<std::string>(node, "ctype", "u8") << " " << name << "[][" << (data.size() / byteSize) << "];\n";
tableEntries.push_back(symbol);
if(end == offset){
write << "static const char* " << name << "[] = {\n";
for(auto& entry : tableEntries){
write << tab << entry << ",\n";
}
write << "};\n\n";
tableEntries.clear();
}
} else {
write << "extern " << GetSafeNode<std::string>(node, "ctype", "u8") << " " << name << "[][" << (data.size() / byteSize) << "];\n";
}
} else {
write << "extern " << GetSafeNode<std::string>(node, "ctype", "u8") << " " << symbol << "[];\n";
if(isOTR){
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
} else {
write << "extern " << GetSafeNode<std::string>(node, "ctype", "u8") << " " << symbol << "[];\n";
}
}
return std::nullopt;
}
@@ -192,6 +206,10 @@ ExportResult TextureBinaryExporter::Export(std::ostream &write, std::shared_ptr<
WriteHeader(writer, LUS::ResourceType::Texture, 0);
if(texture->mFormat.type == TextureType::TLUT) {
texture->mFormat.type = TextureType::RGBA16bpp;
}
writer.Write((uint32_t) texture->mFormat.type);
writer.Write(texture->mWidth);
writer.Write(texture->mHeight);
+1 -1
View File
@@ -10,10 +10,10 @@ enum class TextureType {
Palette8bpp,
Grayscale4bpp,
Grayscale8bpp,
GrayscaleAlpha1bpp,
GrayscaleAlpha4bpp,
GrayscaleAlpha8bpp,
GrayscaleAlpha16bpp,
GrayscaleAlpha1bpp,
TLUT
};
+2 -2
View File
@@ -20,7 +20,7 @@ ExportResult Vec3fHeaderExporter::Export(std::ostream &write, std::shared_ptr<IP
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
@@ -71,7 +71,7 @@ ExportResult Vec3fBinaryExporter::Export(std::ostream &write, std::shared_ptr<IP
writer.Write(y);
writer.Write(z);
}
writer.Finish(write);
return std::nullopt;
}
+1 -1
View File
@@ -18,7 +18,7 @@ ExportResult Vec3sHeaderExporter::Export(std::ostream &write, std::shared_ptr<IP
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
+2 -2
View File
@@ -13,7 +13,7 @@ ExportResult VtxHeaderExporter::Export(std::ostream &write, std::shared_ptr<IPar
const auto offset = GetSafeNode<uint32_t>(node, "offset");
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
@@ -42,7 +42,7 @@ ExportResult VtxCodeExporter::Export(std::ostream &write, std::shared_ptr<IParse
if(searchTable.has_value()){
const auto [name, start, end, mode] = searchTable.value();
if(start == offset){
write << "Vtx " << name << "[][" << vtx.size() << "] = {\n";
+1 -1
View File
@@ -10,7 +10,7 @@ ExportResult MK64::CourseVtxHeaderExporter::Export(std::ostream &write, std::sha
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
+1 -1
View File
@@ -11,7 +11,7 @@ ExportResult MK64::DrivingBehaviourHeaderExporter::Export(std::ostream &write, s
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
+1 -1
View File
@@ -10,7 +10,7 @@ ExportResult MK64::SpawnDataHeaderExporter::Export(std::ostream &write, std::sha
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
+1 -1
View File
@@ -10,7 +10,7 @@ ExportResult MK64::TrackSectionsHeaderExporter::Export(std::ostream &write, std:
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
+1 -1
View File
@@ -10,7 +10,7 @@ ExportResult MK64::WaypointHeaderExporter::Export(std::ostream &write, std::shar
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
+12 -8
View File
@@ -27,7 +27,7 @@ ExportResult SF64::AnimHeaderExporter::Export(std::ostream &write, std::shared_p
const auto symbol = GetSafeNode(node, "symbol", entryName);
if(Companion::Instance->IsOTRMode()){
write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n";
return std::nullopt;
}
@@ -106,16 +106,20 @@ ExportResult SF64::AnimBinaryExporter::Export(std::ostream &write, std::shared_p
WriteHeader(writer, LUS::ResourceType::AnimData, 0);
writer.Write(anim->mFrameCount);
writer.Write(anim->mLimbCount);
writer.Write((uint32_t) anim->mFrameData.size());
writer.Write((uint32_t) anim->mJointKeys.size());
auto jointSize = anim->mJointKeys.size();
writer.Write((uint32_t) jointSize);
SPDLOG_INFO("Joint Size: {}", jointSize);
for(auto joint : anim->mJointKeys) {
for (int i = 0; i < 6; i++) {
writer.Write(joint.keys[i]);
}
writer.Write((char*) joint.keys, sizeof(joint.keys));
}
for(auto data : anim->mFrameData) {
writer.Write(data);
auto frameSize = anim->mFrameData.size();
writer.Write((uint32_t) frameSize);
SPDLOG_INFO("Frame Size: {}", frameSize);
for(size_t i = 0; i < frameSize; i++) {
writer.Write(anim->mFrameData[i]);
}
writer.Finish(write);
return std::nullopt;

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