Implemented GetSafeNodeByAddr

This commit is contained in:
KiritoDv
2025-01-30 10:35:05 -06:00
committed by Lywx
parent f3d6841fcb
commit 7b83e15d80
3 changed files with 29 additions and 10 deletions
+18
View File
@@ -1398,6 +1398,24 @@ std::optional<std::tuple<std::string, YAML::Node>> Companion::GetNodeByAddr(cons
return this->gAddrMap[this->gCurrentFile][addr];
}
std::optional<std::tuple<std::string, YAML::Node>> Companion::GetSafeNodeByAddr(const uint32_t addr, std::string type) {
auto node = this->GetNodeByAddr(addr);
if(!node.has_value()) {
return std::nullopt;
}
auto [name, n] = node.value();
auto n_type = GetSafeNode<std::string>(n, "type");
if(n_type != type) {
throw std::runtime_error("Requested node type does not match with the target node type at " + Torch::to_hex(addr, false));
}
return node;
}
std::optional<ParseResultData> Companion::GetParseDataByAddr(uint32_t addr) {
if(!this->gParseResults.contains(this->gCurrentFile)){
for (auto &file : this->gCurrentExternalFiles) {
+2 -1
View File
@@ -146,8 +146,9 @@ public:
std::optional<ParseResultData> GetParseDataBySymbol(const std::string& symbol);
std::optional<std::uint32_t> GetFileOffsetFromSegmentedAddr(uint8_t segment) const;
std::optional<std::tuple<std::string, YAML::Node>> GetNodeByAddr(uint32_t addr);
std::optional<std::shared_ptr<BaseFactory>> GetFactory(const std::string& type);
std::optional<std::tuple<std::string, YAML::Node>> GetNodeByAddr(uint32_t addr);
std::optional<std::tuple<std::string, YAML::Node>> GetSafeNodeByAddr(const uint32_t addr, std::string type);
std::optional<std::vector<std::tuple<std::string, YAML::Node>>> GetNodesByType(const std::string& type);
std::optional<std::uint32_t> GetFileOffset(void) const { return this->gCurrentFileOffset; };
+9 -9
View File
@@ -71,7 +71,7 @@ int Vtx(uint32_t ptr, int32_t num) {
return 1;
}
auto dec = Companion::Instance->GetNodeByAddr(ptr);
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "VTX");
if(dec.has_value()){
auto node = std::get<1>(dec.value());
@@ -86,7 +86,7 @@ int Vtx(uint32_t ptr, int32_t num) {
}
int Texture(uint32_t ptr, int32_t fmt, int32_t siz, int32_t width, int32_t height, int32_t pal) {
auto dec = Companion::Instance->GetNodeByAddr(ptr);
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "TEXTURE");
if(dec.has_value()){
auto node = std::get<1>(dec.value());
@@ -101,7 +101,7 @@ int Texture(uint32_t ptr, int32_t fmt, int32_t siz, int32_t width, int32_t heigh
}
int Palette(uint32_t ptr, int32_t idx, int32_t count) {
auto dec = Companion::Instance->GetNodeByAddr(ptr);
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "TEXTURE");
if(dec.has_value()){
auto node = std::get<1>(dec.value());
@@ -116,7 +116,7 @@ int Palette(uint32_t ptr, int32_t idx, int32_t count) {
}
int Lights(uint32_t ptr, int32_t count) {
auto dec = Companion::Instance->GetNodeByAddr(ptr);
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "LIGHTS");
if(dec.has_value()){
auto node = std::get<1>(dec.value());
@@ -131,7 +131,7 @@ int Lights(uint32_t ptr, int32_t count) {
}
int Light(uint32_t ptr) {
auto res = Companion::Instance->GetNodeByAddr(ptr);
auto res = Companion::Instance->GetSafeNodeByAddr(ptr, "LIGHTS");
if(res.has_value()){
auto node = std::get<1>(res.value());
@@ -141,7 +141,7 @@ int Light(uint32_t ptr) {
return 1;
}
res = Companion::Instance->GetNodeByAddr(ptr - 0x8);
res = Companion::Instance->GetSafeNodeByAddr(ptr - 0x8, "LIGHTS");
if(res.has_value()){
auto node = std::get<1>(res.value());
@@ -156,7 +156,7 @@ int Light(uint32_t ptr) {
}
int DisplayList(uint32_t ptr) {
auto dec = Companion::Instance->GetNodeByAddr(ptr);
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "GFX");
if(dec.has_value()){
auto node = std::get<1>(dec.value());
@@ -171,7 +171,7 @@ int DisplayList(uint32_t ptr) {
}
int Viewport(uint32_t ptr) {
auto dec = Companion::Instance->GetNodeByAddr(ptr);
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "VP");
if(dec.has_value()){
auto node = std::get<1>(dec.value());
@@ -186,7 +186,7 @@ int Viewport(uint32_t ptr) {
}
int Matrix(uint32_t ptr) {
auto dec = Companion::Instance->GetNodeByAddr(ptr);
auto dec = Companion::Instance->GetSafeNodeByAddr(ptr, "MTX");
if(dec.has_value()){
auto node = std::get<1>(dec.value());