summaryrefslogtreecommitdiff
path: root/src/Companion.cpp
diff options
context:
space:
mode:
authorpetrie911 <69443847+petrie911@users.noreply.github.com>2024-03-16 15:37:37 -0500
committerGitHub <noreply@github.com>2024-03-16 14:37:37 -0600
commit3330d5bd39bd4e0da8c8530290aba59fda849c17 (patch)
treedbce6b7876b018f6b8cc5bd0faaad86666a42400 /src/Companion.cpp
parent02f2c2f03c5fb386258e62c377a0fcd686b57690 (diff)
Add Vec3f factory and AddAsset (#44)
* 3D * and env * so much to fix * Everything can be solved with triangles * fixes * initfix * stuff
Diffstat (limited to 'src/Companion.cpp')
-rw-r--r--src/Companion.cpp55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/Companion.cpp b/src/Companion.cpp
index 9bbef7e..4f87364 100644
--- a/src/Companion.cpp
+++ b/src/Companion.cpp
@@ -18,6 +18,7 @@
#include "factories/DisplayListOverrides.h"
#include "factories/BlobFactory.h"
#include "factories/LightsFactory.h"
+#include "factories/Vec3fFactory.h"
#include "factories/mk64/CourseVtx.h"
#include "factories/mk64/Waypoints.h"
#include "factories/mk64/TrackSections.h"
@@ -39,6 +40,7 @@
#include "factories/sf64/ObjInitFactory.h"
#include "factories/sf64/TriangleFactory.h"
#include <regex>
+#include "utils/TorchUtils.h"
using namespace std::chrono;
namespace fs = std::filesystem;
@@ -61,6 +63,7 @@ void Companion::Init(const ExportType type) {
this->RegisterFactory("SEQUENCE", std::make_shared<SequenceFactory>());
this->RegisterFactory("SAMPLE", std::make_shared<SampleFactory>());
this->RegisterFactory("BANK", std::make_shared<BankFactory>());
+ this->RegisterFactory("VEC3F", std::make_shared<Vec3fFactory>());
// SM64 specific
this->RegisterFactory("SM64:DIALOG", std::make_shared<SM64::DialogFactory>());
@@ -966,4 +969,54 @@ std::string Companion::NormalizeAsset(const std::string& name) const {
std::string Companion::CalculateHash(const std::vector<uint8_t>& data) {
return Chocobo1::SHA1().addData(data).finalize().toString();
-} \ No newline at end of file
+}
+
+static std::string ConvertType(std::string type) {
+ int index;
+
+ if((index = type.find(':')) != std::string::npos) {
+ type = type.substr(index + 1);
+ }
+ type = std::regex_replace(type, std::regex(R"([^_A-Za-z0-9]*)"), "");
+ std::transform(type.begin(), type.end(), type.begin(), ::tolower);
+ return type;
+}
+
+std::optional<YAML::Node> Companion::AddAsset(YAML::Node asset) {
+ if(!asset["offset"] || !asset["type"]) {
+ return std::nullopt;
+ }
+ const auto type = GetSafeNode<std::string>(asset, "type");
+ const auto offset = GetSafeNode<uint32_t>(asset, "offset");
+ const auto symbol = GetSafeNode<std::string>(asset, "symbol", "");
+ const auto decl = this->GetNodeByAddr(offset);
+
+ if(decl.has_value()) {
+ return std::get<1>(decl.value());
+ }
+
+ auto rom = this->GetRomData();
+ auto factory = this->GetFactory(type)->get();
+
+ std::string output;
+ std::string typeId = ConvertType(type);
+ int index;
+
+ if(symbol != "") {
+ output = symbol;
+ } else if(Decompressor::IsSegmented(offset)){
+ output = this->NormalizeAsset("seg" + std::to_string(SEGMENT_NUMBER(offset)) +"_" + typeId + "_" + Torch::to_hex(SEGMENT_OFFSET(offset), false));
+ } else {
+ output = this->NormalizeAsset(typeId + "_" + Torch::to_hex(offset, false));
+ }
+ asset["autogen"] = true;
+ asset["symbol"] = output;
+
+ auto result = factory->parse(rom, asset);
+
+ if(result.has_value()){
+ return std::get<1>(this->RegisterAsset(output, asset).value());
+ }
+
+ return std::nullopt;
+}