mirror of
https://github.com/izzy2lost/Torch.git
synced 2026-07-06 00:18:35 -07:00
Implemented GetSafeNodeByAddr
This commit is contained in:
@@ -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
@@ -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; };
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user