Skip to content

Commit 7ef2c2f

Browse files
authored
decomp: add a new config flag to disable var-name casts (#3338)
This is handy when you want to try comparing the decompiler's output across games (ie. for checking if only naming differs)
1 parent 3eb6cfc commit 7ef2c2f

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

decompiler/config.cpp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ Config make_config_via_json(nlohmann::json& json) {
9797
if (json.contains("read_spools")) {
9898
config.read_spools = json.at("read_spools").get<bool>();
9999
}
100+
if (json.contains("ignore_var_name_casts")) {
101+
config.ignore_var_name_casts = json.at("ignore_var_name_casts").get<bool>();
102+
}
100103
if (json.contains("old_all_types_file")) {
101104
config.old_all_types_file = json.at("old_all_types_file").get<std::string>();
102105
}
@@ -156,29 +159,31 @@ Config make_config_via_json(nlohmann::json& json) {
156159
config.anon_function_types_by_obj_by_id[obj_file_name][id] = type_name;
157160
}
158161
}
159-
auto var_names_json = read_json_file_from_config(json, "var_names_file");
160-
for (auto& kv : var_names_json.items()) {
161-
auto& function_name = kv.key();
162-
auto arg = kv.value().find("args");
163-
if (arg != kv.value().end()) {
164-
for (auto& x : arg.value()) {
165-
config.function_arg_names[function_name].push_back(x);
162+
if (!config.ignore_var_name_casts) {
163+
auto var_names_json = read_json_file_from_config(json, "var_names_file");
164+
for (auto& kv : var_names_json.items()) {
165+
auto& function_name = kv.key();
166+
auto arg = kv.value().find("args");
167+
if (arg != kv.value().end()) {
168+
for (auto& x : arg.value()) {
169+
config.function_arg_names[function_name].push_back(x);
170+
}
166171
}
167-
}
168172

169-
auto var = kv.value().find("vars");
170-
if (var != kv.value().end()) {
171-
for (auto& vkv : var->get<std::unordered_map<std::string, nlohmann::json>>()) {
172-
LocalVarOverride override;
173-
if (vkv.second.is_string()) {
174-
override.name = vkv.second.get<std::string>();
175-
} else if (vkv.second.is_array()) {
176-
override.name = vkv.second[0].get<std::string>();
177-
override.type = vkv.second[1].get<std::string>();
178-
} else {
179-
throw std::runtime_error("Invalid function var override.");
173+
auto var = kv.value().find("vars");
174+
if (var != kv.value().end()) {
175+
for (auto& vkv : var->get<std::unordered_map<std::string, nlohmann::json>>()) {
176+
LocalVarOverride override;
177+
if (vkv.second.is_string()) {
178+
override.name = vkv.second.get<std::string>();
179+
} else if (vkv.second.is_array()) {
180+
override.name = vkv.second[0].get<std::string>();
181+
override.type = vkv.second[1].get<std::string>();
182+
} else {
183+
throw std::runtime_error("Invalid function var override.");
184+
}
185+
config.function_var_overrides[function_name][vkv.first] = override;
180186
}
181-
config.function_var_overrides[function_name][vkv.first] = override;
182187
}
183188
}
184189
}

decompiler/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ struct Config {
121121
bool extract_collision = false;
122122
bool find_functions = false;
123123
bool read_spools = false;
124+
bool ignore_var_name_casts = false;
124125

125126
bool write_hex_near_instructions = false;
126127
bool hexdump_code = false;

0 commit comments

Comments
 (0)