diff options
| author | KiritoDv <kiritodev01@gmail.com> | 2024-04-08 18:09:12 -0600 |
|---|---|---|
| committer | Lywx <kiritodev01@gmail.com> | 2024-04-08 18:09:34 -0600 |
| commit | 3918fde51a84f5035d6f74740195f0d91dd5c604 (patch) | |
| tree | b6274c3503af7cff7831b2272668d5659353631b /src | |
| parent | b1d39534f3ee1f04601cdadffbc8a96bcbf0b4a6 (diff) | |
Fixed otr header generation and fixed some binary exporters
Diffstat (limited to 'src')
31 files changed, 244 insertions, 183 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp index 53c1fb8..314d86a 100644 --- a/src/Companion.cpp +++ b/src/Companion.cpp @@ -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) { diff --git a/src/factories/BaseFactory.cpp b/src/factories/BaseFactory.cpp index c0da8cd..ba84109 100644 --- a/src/factories/BaseFactory.cpp +++ b/src/factories/BaseFactory.cpp @@ -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 diff --git a/src/factories/BlobFactory.cpp b/src/factories/BlobFactory.cpp index 2b7f7fe..43e075c 100644 --- a/src/factories/BlobFactory.cpp +++ b/src/factories/BlobFactory.cpp @@ -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++) { diff --git a/src/factories/DisplayListFactory.cpp b/src/factories/DisplayListFactory.cpp index 82f8f55..8886d7d 100644 --- a/src/factories/DisplayListFactory.cpp +++ b/src/factories/DisplayListFactory.cpp @@ -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); diff --git a/src/factories/FloatFactory.cpp b/src/factories/FloatFactory.cpp index dfaf5a3..5465999 100644 --- a/src/factories/FloatFactory.cpp +++ b/src/factories/FloatFactory.cpp @@ -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) { diff --git a/src/factories/GenericArrayFactory.cpp b/src/factories/GenericArrayFactory.cpp index 91819f5..c91dbe2 100644 --- a/src/factories/GenericArrayFactory.cpp +++ b/src/factories/GenericArrayFactory.cpp @@ -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; } diff --git a/src/factories/IncludeFactory.cpp b/src/factories/IncludeFactory.cpp index ab38c28..f1cde4c 100644 --- a/src/factories/IncludeFactory.cpp +++ b/src/factories/IncludeFactory.cpp @@ -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; } diff --git a/src/factories/LightsFactory.cpp b/src/factories/LightsFactory.cpp index fd930aa..44b7195 100644 --- a/src/factories/LightsFactory.cpp +++ b/src/factories/LightsFactory.cpp @@ -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"; diff --git a/src/factories/MtxFactory.cpp b/src/factories/MtxFactory.cpp index 15ca03b..d8f720d 100644 --- a/src/factories/MtxFactory.cpp +++ b/src/factories/MtxFactory.cpp @@ -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); diff --git a/src/factories/TextureFactory.cpp b/src/factories/TextureFactory.cpp index 5d7ebc0..5eb188d 100644 --- a/src/factories/TextureFactory.cpp +++ b/src/factories/TextureFactory.cpp @@ -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"; + + tableEntries.push_back(symbol); - write << "extern " << GetSafeNode<std::string>(node, "ctype", "u8") << " " << name << "[][" << (data.size() / byteSize) << "];\n"; + 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); diff --git a/src/factories/TextureFactory.h b/src/factories/TextureFactory.h index e2698d8..102ee54 100644 --- a/src/factories/TextureFactory.h +++ b/src/factories/TextureFactory.h @@ -10,10 +10,10 @@ enum class TextureType { Palette8bpp, Grayscale4bpp, Grayscale8bpp, - GrayscaleAlpha1bpp, GrayscaleAlpha4bpp, GrayscaleAlpha8bpp, GrayscaleAlpha16bpp, + GrayscaleAlpha1bpp, TLUT }; diff --git a/src/factories/Vec3fFactory.cpp b/src/factories/Vec3fFactory.cpp index ef55dcc..1bb1c73 100644 --- a/src/factories/Vec3fFactory.cpp +++ b/src/factories/Vec3fFactory.cpp @@ -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; } diff --git a/src/factories/Vec3sFactory.cpp b/src/factories/Vec3sFactory.cpp index 60bba9f..a7290a4 100644 --- a/src/factories/Vec3sFactory.cpp +++ b/src/factories/Vec3sFactory.cpp @@ -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; } diff --git a/src/factories/VtxFactory.cpp b/src/factories/VtxFactory.cpp index 450ad3c..e4f1dcf 100644 --- a/src/factories/VtxFactory.cpp +++ b/src/factories/VtxFactory.cpp @@ -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"; diff --git a/src/factories/mk64/CourseVtx.cpp b/src/factories/mk64/CourseVtx.cpp index d1d9b3a..d0e32db 100644 --- a/src/factories/mk64/CourseVtx.cpp +++ b/src/factories/mk64/CourseVtx.cpp @@ -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; } diff --git a/src/factories/mk64/DrivingBehaviour.cpp b/src/factories/mk64/DrivingBehaviour.cpp index c6af5ce..2be093a 100644 --- a/src/factories/mk64/DrivingBehaviour.cpp +++ b/src/factories/mk64/DrivingBehaviour.cpp @@ -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; } diff --git a/src/factories/mk64/SpawnData.cpp b/src/factories/mk64/SpawnData.cpp index 44f710a..44554ea 100644 --- a/src/factories/mk64/SpawnData.cpp +++ b/src/factories/mk64/SpawnData.cpp @@ -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; } diff --git a/src/factories/mk64/TrackSections.cpp b/src/factories/mk64/TrackSections.cpp index 8e8690f..4d13ed8 100644 --- a/src/factories/mk64/TrackSections.cpp +++ b/src/factories/mk64/TrackSections.cpp @@ -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; } diff --git a/src/factories/mk64/Waypoints.cpp b/src/factories/mk64/Waypoints.cpp index ec203f2..6dfae5a 100644 --- a/src/factories/mk64/Waypoints.cpp +++ b/src/factories/mk64/Waypoints.cpp @@ -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; } diff --git a/src/factories/sf64/AnimFactory.cpp b/src/factories/sf64/AnimFactory.cpp index 1b21d92..76a97b3 100644 --- a/src/factories/sf64/AnimFactory.cpp +++ b/src/factories/sf64/AnimFactory.cpp @@ -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; diff --git a/src/factories/sf64/ColPolyFactory.cpp b/src/factories/sf64/ColPolyFactory.cpp index b4f739f..71433bb 100644 --- a/src/factories/sf64/ColPolyFactory.cpp +++ b/src/factories/sf64/ColPolyFactory.cpp @@ -18,7 +18,7 @@ ExportResult SF64::ColPolyHeaderExporter::Export(std::ostream &write, std::share 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; } diff --git a/src/factories/sf64/EnvSettingsFactory.cpp b/src/factories/sf64/EnvSettingsFactory.cpp index a57cfcb..bdf27f3 100644 --- a/src/factories/sf64/EnvSettingsFactory.cpp +++ b/src/factories/sf64/EnvSettingsFactory.cpp @@ -13,7 +13,7 @@ ExportResult SF64::EnvSettingsHeaderExporter::Export(std::ostream &write, std::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; } diff --git a/src/factories/sf64/HitboxFactory.cpp b/src/factories/sf64/HitboxFactory.cpp index b7d9427..150d21f 100644 --- a/src/factories/sf64/HitboxFactory.cpp +++ b/src/factories/sf64/HitboxFactory.cpp @@ -34,7 +34,7 @@ ExportResult SF64::HitboxHeaderExporter::Export(std::ostream &write, std::shared 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; } diff --git a/src/factories/sf64/MessageFactory.cpp b/src/factories/sf64/MessageFactory.cpp index 039db8a..c8d5ae5 100644 --- a/src/factories/sf64/MessageFactory.cpp +++ b/src/factories/sf64/MessageFactory.cpp @@ -53,7 +53,7 @@ ExportResult SF64::MessageHeaderExporter::Export(std::ostream &write, std::share const auto symbol = GetSafeNode(node, "symbol", entryName); if(Companion::Instance->IsOTRMode()){ - write << "static const char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; + write << "static ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; return std::nullopt; } @@ -130,9 +130,10 @@ ExportResult SF64::MessageBinaryExporter::Export(std::ostream &write, std::share WriteHeader(writer, LUS::ResourceType::Message, 0); - writer.Write(static_cast<uint32_t>(data->mMessage.size())); - for(auto m : data->mMessage) { - writer.Write(m); + auto count = data->mMessage.size(); + writer.Write(static_cast<uint32_t>(count)); + for(size_t i = 0; i < count; i++) { + writer.Write((uint16_t) data->mMessage[i]); } writer.Finish(write); return std::nullopt; @@ -145,12 +146,12 @@ std::optional<std::shared_ptr<IParsedData>> SF64::MessageFactory::parse(std::vec LUS::BinaryReader reader(segment.data, segment.size); reader.SetEndianness(LUS::Endianness::Big); - uint16_t c = reader.ReadUInt16(); - while(c != END_CODE){ + bool processing = true; + while(processing){ + uint16_t c = reader.ReadUInt16(); message.push_back(c); - c = reader.ReadUInt16(); + processing = c != END_CODE; } - message.push_back(END_CODE); return std::make_shared<MessageData>(message); }
\ No newline at end of file diff --git a/src/factories/sf64/MessageLookupFactory.cpp b/src/factories/sf64/MessageLookupFactory.cpp index 6aeae05..61e329a 100644 --- a/src/factories/sf64/MessageLookupFactory.cpp +++ b/src/factories/sf64/MessageLookupFactory.cpp @@ -8,7 +8,7 @@ ExportResult SF64::MessageLookupHeaderExporter::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; } @@ -50,10 +50,20 @@ ExportResult SF64::MessageLookupBinaryExporter::Export(std::ostream &write, std: WriteHeader(writer, LUS::ResourceType::MessageTable, 0); - writer.Write(static_cast<uint32_t>(data->mTable.size())); + const auto count = data->mTable.size(); + SPDLOG_INFO("Message Count: {}", count); + writer.Write(static_cast<uint32_t>(count)); for(auto m : data->mTable) { writer.Write(m.id); - writer.Write(m.ptr); + auto dec = Companion::Instance->GetNodeByAddr(m.ptr); + if(dec.has_value()){ + std::string path = std::get<0>(dec.value()); + SPDLOG_INFO("Message ID: {} Ptr: {:X} Path: {}", m.id, m.ptr, path); + writer.Write(CRC64(path.c_str())); + } else { + writer.Write((uint64_t) 0); + SPDLOG_WARN("Failed to find message ID: {} Ptr: {:X}", m.id, m.ptr); + } } writer.Finish(write); return std::nullopt; diff --git a/src/factories/sf64/ObjInitFactory.cpp b/src/factories/sf64/ObjInitFactory.cpp index 8b7175e..38d03df 100644 --- a/src/factories/sf64/ObjInitFactory.cpp +++ b/src/factories/sf64/ObjInitFactory.cpp @@ -9,7 +9,7 @@ ExportResult SF64::ObjInitHeaderExporter::Export(std::ostream &write, std::share 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; } diff --git a/src/factories/sf64/ScriptFactory.cpp b/src/factories/sf64/ScriptFactory.cpp index 64c6a31..9251cf2 100644 --- a/src/factories/sf64/ScriptFactory.cpp +++ b/src/factories/sf64/ScriptFactory.cpp @@ -4,14 +4,10 @@ #include "Companion.h" #include "utils/Decompressor.h" #include "utils/TorchUtils.h" -#include "regex.h" +#include <regex> #include "storm/SWrapper.h" -#define CLAMP_MAX(val, max) (((val) < (max)) ? (val) : (max)) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#define VALUE_TO_ENUM(val, enumname, fallback) (Companion::Instance->GetEnumFromValue(enumname, val).value_or("/*" + std::string(fallback) + " */ " + std::to_string(val))); - SF64::ScriptData::ScriptData(std::vector<uint32_t> ptrs, std::vector<uint16_t> cmds, std::map<uint32_t, int> sizeMap, uint32_t ptrsStart, uint32_t cmdsStart): mPtrs(ptrs), mCmds(cmds), mSizeMap(sizeMap), mPtrsStart(ptrsStart), mCmdsStart(cmdsStart) { } @@ -20,7 +16,7 @@ ExportResult SF64::ScriptHeaderExporter::Export(std::ostream &write, std::shared 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,21 +30,20 @@ std::string MakeScriptCmd(uint16_t s1, uint16_t s2) { std::ostringstream cmd; std::ostringstream comment; - + auto enumName = Companion::Instance->GetEnumFromValue("EventOpcode", opcode).value_or("/* EVOP_UNK */ " + std::to_string(opcode)); switch (opcode) { case 0: case 1: { auto f3 = arg1 & 0x7F; - // auto zm = (arg1 >> 7) & 3; - // auto zmode = Companion::Instance->GetEnumFromValue("EventModeZ", zm).value_or("/* EVOP_UNK */ " + std::to_string(zm)); - auto zmode = VALUE_TO_ENUM((arg1 >> 7) & 3, "EventModeZ", "EVOP_UNK"); - - cmd << "EVENT_SET_" << (opcode ? "ACCEL" : "SPEED") << "(" << std::dec << f3 << ", " << zmode << ", " << s2; + auto zm = (arg1 >> 7) & 3; + auto zmode = Companion::Instance->GetEnumFromValue("EventModeZ", zm).value_or("/* EVOP_UNK */ " + std::to_string(zm)); + + cmd << "EVENT_SET_" << (opcode ? "ACCEL" : "SPEED") << "(" << std::dec << f3 << ", " << zmode << ", " << s2 << "),"; comment << " // wait " << s2 << " frames"; } break; case 2: - cmd << "EVENT_SET_BASE_ZVEL(" << std::dec << s2; + cmd << "EVENT_SET_BASE_ZVEL(" << std::dec << s2 << "),"; break; case 9: case 10: @@ -60,124 +55,97 @@ std::string MakeScriptCmd(uint16_t s1, uint16_t s2) { case 19: case 20: case 21: { - auto rotcmd = VALUE_TO_ENUM(opcode, "EventOpcode", "EVOP_UNK"); - cmd << rotcmd.replace(0, 4, "EVENT") << "(" << std::dec << s2 << ", " << std::fixed << std::setprecision(1) << arg1 / 10.0f; + auto rotcmd = enumName.replace(0, 4, "EVENT"); + cmd << rotcmd << "(" << std::dec << s2 << ", " << std::fixed << std::setprecision(1) << arg1 / 10.0f << "),"; if(opcode < 16 && arg1 != 0) { comment << " // wait " << 10 * s2 / arg1 << " frames"; } } break; case 24: - cmd << "EVENT_SET_ROTATE("; + cmd << "EVENT_SET_ROTATE(),"; break; case 25: - cmd << "EVENT_STOP_ROTATE("; - break; - case 44: - cmd << "EVENT_CHASE_TARGET(" << std::dec << arg1 << ", " << s2; + cmd << "EVENT_STOP_ROTATE(),"; break; - case 45: { - auto teamId = VALUE_TO_ENUM(arg1, "TeamId", "TEAMID_UNK"); - cmd << "EVENT_SET_TARGET(" << teamId << ", " << std::dec << s2; - } break; case 56: - cmd << "EVENT_SET_CALL(" << std::dec << s2 << ", " << arg1; + cmd << "EVENT_SET_CALL(" << std::dec << s2 << ", " << arg1 << "),"; + break; + case 57: + cmd << "EVENT_RESTORE_TEAM(" << std::dec << s2 << "),"; break; - case 57: { - auto teamId = VALUE_TO_ENUM(s2, "TeamId", "TEAMID_UNK"); - cmd << "EVENT_RESTORE_TEAM(" << teamId; - } break; - case 58: + case 58: { + auto sfxIndex = Companion::Instance->GetEnumFromValue("EventSfx", s2).value_or("/* EVSFX_UNK */ " + std::to_string(s2)); + cmd << "EVENT_PLAY_SFX(" << sfxIndex << "),"; + } break; case 59: { - // auto sfxIndex = Companion::Instance->GetEnumFromValue("EventSfx", s2).value_or("/* EVSFX_UNK */ " + std::to_string(s2)); - auto sfxIndex = VALUE_TO_ENUM(s2, "EventSfx", "EVSFX_UNK"); - cmd << "EVENT_" << ((opcode == 58) ? "PLAY" : "STOP") << "_SFX(" << sfxIndex; + auto sfxIndex = Companion::Instance->GetEnumFromValue("EventSfx", s2).value_or("/* EVSFX_UNK */ " + std::to_string(s2)); + cmd << "EVENT_STOP_SFX(" << sfxIndex << "),"; } break; - // case 59: { - // auto sfxIndex = Companion::Instance->GetEnumFromValue("EventSfx", s2).value_or("/* EVSFX_UNK */ " + std::to_string(s2)); - // cmd << "EVENT_STOP_SFX(" << sfxIndex; - // } break; - case 96: - cmd << ((s2 == 0) ? "EVENT_CLEAR_TRIGGER(" : "EVENT_SET_TRIGGER("); - if(s2 != 0) { - auto condition = VALUE_TO_ENUM(MIN(s2, 100), "EventCondition", "EVC_UNK"); - cmd << condition << ((s2 < 100) ? "" : " + " + std::to_string(s2 - 100)) << ", "; + case 96: + if(s2 == 0) { + cmd << "EVENT_CLEAR_TRIGGER(" << std::dec << arg1 << "),"; + } else if(s2 >= 100) { + auto condition = Companion::Instance->GetEnumFromValue("EventCondition", 100).value_or("/* EVC_UNK */ " + std::to_string(s2)); + cmd << "EVENT_SET_TRIGGER(" << condition << " + " << std::dec << (s2 - 100) << ", " << std::dec << arg1 << "),"; + } else { + auto condition = Companion::Instance->GetEnumFromValue("EventCondition", s2).value_or("/* EVC_UNK */ " + std::to_string(s2)); + cmd << "EVENT_SET_TRIGGER(" << condition << ", " << std::dec << arg1 << "),"; } - cmd << ((arg1 < 200) ? "" : "EVENT_AI_CHANGE + ") << std::dec << ((arg1 < 200) ? arg1 : arg1 - 200); break; case 104: { - // auto actorinfo = Companion::Instance->GetEnumFromValue("EventActorInfo", s2).value_or("/* EINFO_UNK */ " + std::to_string(s2)); - auto actorInfo = VALUE_TO_ENUM(s2, "EventActorInfo", "EINFO_UNK"); - cmd << "EVENT_INIT_ACTOR(" << actorInfo << ", " << std::dec << arg1; - } break; - case 105: { - auto teamId = VALUE_TO_ENUM(s2, "TeamId", "TEAMID_UNK"); - cmd << "EVENT_SET_TEAM_ID(" << teamId; + auto actorinfo = Companion::Instance->GetEnumFromValue("EventActorInfo", s2).value_or("/* EINFO_UNK */ " + std::to_string(s2)); + cmd << "EVENT_INIT_ACTOR(" << actorinfo << ", " << std::dec << arg1 << "),"; } break; case 112:{ - // auto actiontype = Companion::Instance->GetEnumFromValue("EventAction", s2).value_or("/* EVACT_UNK */ " + std::to_string(s2)); - auto actiontype = VALUE_TO_ENUM(s2, "EventAction", "EVACT_UNK"); - cmd << "EVENT_SET_ACTION(" << actiontype; + auto actiontype = Companion::Instance->GetEnumFromValue("EventAction", s2).value_or("/* EVACT_UNK */ " + std::to_string(s2)); + cmd << "EVENT_SET_ACTION(" << actiontype << "),"; if((s2 == 14 || s2 == 15)) { comment << " // wait 1 frame"; } } break; case 113: - cmd << "EVENT_ADD_TO_GROUP(" << std::dec << s2 << ", " << arg1; + cmd << "EVENT_ADD_TO_GROUP(" << std::dec << s2 << ", " << arg1 << "),"; break; case 116: { - // auto itemtype = Companion::Instance->GetEnumFromValue("ItemDrop", s2).value_or("/* DROP_UNK */ " + std::to_string(s2)); - auto itemType = VALUE_TO_ENUM(s2, "ItemDrop", "DROP_UNK"); - cmd << "EVENT_DROP_ITEM(" << itemType; + auto itemtype = Companion::Instance->GetEnumFromValue("ItemDrop", s2).value_or("/* DROP_UNK */ " + std::to_string(s2)); + cmd << "EVENT_DROP_ITEM(" << itemtype << "),"; } break; - case 118: - cmd << "EVENT_SET_REVERB(" << std::dec << s2; + case 118: + cmd << "EVENT_SET_REVERB(" << std::dec << s2 << "),"; break; case 119: { - // auto groundtype = Companion::Instance->GetEnumFromValue("GroundType", s2).value_or("/* GROUNDTYPE_UNK */ " + std::to_string(s2)); - auto groundtype = VALUE_TO_ENUM(s2, "GroundType", "GROUNDTYPE_UNK"); - cmd << "EVENT_SET_GROUND(" << groundtype; + auto groundtype = Companion::Instance->GetEnumFromValue("GroundType", s2).value_or("/* GROUNDTYPE_UNK */ " + std::to_string(s2)); + cmd << "EVENT_SET_GROUND(" << groundtype << "),"; } break; case 120: { - // auto rcidName = Companion::Instance->GetEnumFromValue("RadioCharacterId", arg1).value_or("/* RCID_UNK */ " + std::to_string(arg1)); - auto rcidName = VALUE_TO_ENUM(arg1, "RadioCharacterId", "RCID_UNK"); - cmd << "EVENT_PLAY_MSG(" << rcidName << ", " << std::dec << s2; - } break; - case 121: { - auto teamId = VALUE_TO_ENUM(s2, "TeamId", "TEAMID_UNK"); - cmd << "EVENT_DAMAGE_TEAM(" << teamId << ", " << std::dec << arg1; + auto rcidName = Companion::Instance->GetEnumFromValue("RadioCharacterId", arg1).value_or("/* RCID_UNK */ " + std::to_string(arg1)); + cmd << "EVENT_PLAY_MSG(" << rcidName << ", " << std::dec << std::setw(5) << s2 << "),"; } break; - case 122: - cmd << "EVENT_STOP_BGM("; + case 122: + cmd << "EVENT_STOP_BGM(),"; break; case 124: { - // auto color = Companion::Instance->GetEnumFromValue("TexLineColor", s2).value_or("/* TXLC_UNK */ " + std::to_string(s2)); - auto color = VALUE_TO_ENUM(s2, "TexLineColor", "TXLC_UNK"); - cmd << "EVENT_MAKE_TEXLINE(" << color; + auto color = Companion::Instance->GetEnumFromValue("TexLineColor", s2).value_or("/* TXLC_UNK */ " + std::to_string(s2)); + cmd << "EVENT_MAKE_TEXLINE(" << color << "),"; } break; case 125: - cmd << "EVENT_STOP_TEXLINE("; + cmd << "EVENT_STOP_TEXLINE(),"; break; - case 126: - cmd << ((s2 == 0) ? "EVENT_GOTO(" : "EVENT_LOOP("); - if(s2 != 0) { - cmd << std::dec << s2 << ", "; - } - cmd << ((arg1 < 200) ? "" : "EVENT_AI_CHANGE + ") << std::dec << ((arg1 < 200) ? arg1 : arg1 - 200); + case 126: + cmd << "EVENT_LOOP(" << std::dec << arg1 << ", " << s2 << "),"; break; case 127: - cmd << "EVENT_STOP_SCRIPT("; + cmd << "EVENT_STOP_SCRIPT(),"; comment << "// wait"; break; - default: { - // auto opcodeName = Companion::Instance->GetEnumFromValue("EventOpcode", opcode).value_or("/* EVOP_UNK */ " + std::to_string(opcode)); - auto opcodeName = VALUE_TO_ENUM(opcode, "EventOpcode", "EVOP_UNK"); - cmd << "EVENT_CMD(" << opcodeName << ", " << std::dec << arg1 << ", " << s2; + default: + cmd << "EVENT_CMD(" << enumName << ", " << std::dec << arg1 << ", " << s2 << "),"; if(opcode >= 40 && opcode <= 48) { comment << " // wait"; } - } break; + break; } - cmd << "), " << comment.str(); + cmd << comment.str(); return cmd.str(); } @@ -210,7 +178,7 @@ ExportResult SF64::ScriptCodeExporter::Export(std::ostream &write, std::shared_p // } write << MakeScriptCmd(script->mCmds[cmdIndex], script->mCmds[cmdIndex + 1]); } - + write << "\n};\n"; cmdOff += 4 * cmdCount; @@ -255,8 +223,6 @@ ExportResult SF64::ScriptBinaryExporter::Export(std::ostream &write, std::shared for (auto ptr : sortedPtrs) { auto wrapper = Companion::Instance->GetCurrentWrapper(); std::ostringstream stream; - stream.str(""); - stream.clear(); auto cmdWriter = LUS::BinaryWriter(); WriteHeader(cmdWriter, LUS::ResourceType::ScriptCmd, 0); @@ -283,9 +249,10 @@ ExportResult SF64::ScriptBinaryExporter::Export(std::ostream &write, std::shared // Export Script WriteHeader(scriptWriter, LUS::ResourceType::Script, 0); - scriptWriter.Write((uint32_t) script->mPtrs.size()); - for (auto &ptr : script->mPtrs) { - scriptWriter.Write(ptrMap.at(ptr)); + auto count = script->mPtrs.size(); + scriptWriter.Write((uint32_t) count); + for (size_t i = 0; i < script->mPtrs.size(); i++) { + scriptWriter.Write(ptrMap.at(script->mPtrs.at(i))); } scriptWriter.Finish(write); diff --git a/src/factories/sf64/SkeletonFactory.cpp b/src/factories/sf64/SkeletonFactory.cpp index 4de3f2d..901acc8 100644 --- a/src/factories/sf64/SkeletonFactory.cpp +++ b/src/factories/sf64/SkeletonFactory.cpp @@ -19,7 +19,7 @@ ExportResult SF64::SkeletonHeaderExporter::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; } @@ -106,22 +106,24 @@ ExportResult SF64::SkeletonBinaryExporter::Export(std::ostream &write, std::shar for (auto &limb : limbs) { auto wrapper = Companion::Instance->GetCurrentWrapper(); std::ostringstream stream; - stream.str(""); - stream.clear(); auto limbWriter = LUS::BinaryWriter(); WriteHeader(limbWriter, LUS::ResourceType::Limb, 0); - uint64_t hash = 0; - if (limb.mDList != 0) { + bool hasDList = limb.mDList != 0 && (SEGMENT_NUMBER(limb.mDList) == SEGMENT_NUMBER(limb.mAddr)); + + if(hasDList){ auto dec = Companion::Instance->GetNodeByAddr(limb.mDList); if (dec.has_value()){ - hash = CRC64(std::get<0>(dec.value()).c_str()); - SPDLOG_INFO("Found display list: 0x{:X} Hash: 0x{:X} Path: {}", limb.mDList, hash, std::get<0>(dec.value())); + std::string path = std::get<0>(dec.value()); + limbWriter.Write(CRC64(path.c_str())); + SPDLOG_INFO("Found display list: 0x{:X} at {} with size {}", limb.mDList, path, path.size()); } else { SPDLOG_WARN("Could not find dlist at 0x{:X}", limb.mDList); + throw std::runtime_error("Could not find dlist at 0x" + std::to_string(limb.mDList)); } + } else { + limbWriter.Write((uint64_t) 0); } - limbWriter.Write(hash); auto [transX, transY, transZ] = limb.mTrans; limbWriter.Write(transX); limbWriter.Write(transY); @@ -148,8 +150,6 @@ ExportResult SF64::SkeletonBinaryExporter::Export(std::ostream &write, std::shar } skeletonWriter.Finish(write); - - return std::nullopt; } diff --git a/src/factories/sf64/TriangleFactory.cpp b/src/factories/sf64/TriangleFactory.cpp index db77405..f67fc12 100644 --- a/src/factories/sf64/TriangleFactory.cpp +++ b/src/factories/sf64/TriangleFactory.cpp @@ -17,7 +17,7 @@ ExportResult SF64::TriangleHeaderExporter::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; } @@ -105,7 +105,7 @@ std::optional<std::shared_ptr<IParsedData>> SF64::TriangleFactory::parse(std::ve } } else { std::ostringstream offsetSeg; - + offsetSeg << std::uppercase << std::hex << meshOffset; meshSymbol = std::regex_replace(meshSymbol, std::regex(R"(OFFSET)"), offsetSeg.str()); } diff --git a/src/factories/sm64/CollisionFactory.cpp b/src/factories/sm64/CollisionFactory.cpp index 53dd0f5..4e0ca06 100644 --- a/src/factories/sm64/CollisionFactory.cpp +++ b/src/factories/sm64/CollisionFactory.cpp @@ -247,7 +247,7 @@ ExportResult SM64::CollisionHeaderExporter::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; } diff --git a/src/storm/SWrapper.cpp b/src/storm/SWrapper.cpp index 4fa585d..788c273 100644 --- a/src/storm/SWrapper.cpp +++ b/src/storm/SWrapper.cpp @@ -43,33 +43,28 @@ bool SWrapper::CreateFile(const std::string& path, std::vector<char> data) { time(&theTime); #endif - char* raw = (char*) data.data(); + char* raw = data.data(); size_t size = data.size(); if(size == 0){ SPDLOG_ERROR("File at path {} is empty", path); - std::cout << "File empty: " << path << std::endl; return false; } if(size >> 32){ - SPDLOG_ERROR("File at path {} is too large with size {}", path, size); - return false; + throw std::runtime_error("File at path " + path + " is too large with size " + std::to_string(size)); } if(!SFileCreateFile(this->hMpq, path.c_str(), theTime, size, 0, MPQ_FILE_COMPRESS, &hFile)){ - SPDLOG_ERROR("Failed to create file at path {} with error {}", path, GetLastError()); - return false; + throw std::runtime_error("Failed to create file at path " + path + " with error " + std::to_string(GetLastError())); } if(!SFileWriteFile(hFile, (void*) raw, size, MPQ_COMPRESSION_ZLIB)){ - SPDLOG_ERROR("Failed to write file at path {} with error {}", path, GetLastError()); - return false; + throw std::runtime_error("Failed to write file at path " + path + " with error " + std::to_string(GetLastError())); } if(!SFileCloseFile(hFile)){ - SPDLOG_ERROR("Failed to close file at path {} with error {}", path, GetLastError()); - return false; + throw std::runtime_error("Failed to close file at path " + path + " with error " + std::to_string(GetLastError())); } return true; |
