diff --git a/common/util/set_util.h b/common/util/set_util.h new file mode 100644 index 0000000000..43d93860e5 --- /dev/null +++ b/common/util/set_util.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace set_util { +template +std::unordered_set intersection(std::unordered_set& set1, std::unordered_set& set2) { + if (set2.size() < set1.size()) { + auto temp = set1; + set1 = set2; + set2 = temp; + } + std::unordered_set m(set1.begin(), set1.end()); + std::unordered_set res; + for (auto a : set2) + if (m.count(a)) { + res.insert(a); + m.erase(a); + } + return res; +} +} // namespace set_util diff --git a/decompiler/main.cpp b/decompiler/main.cpp index ea451c47c2..2409b4e911 100644 --- a/decompiler/main.cpp +++ b/decompiler/main.cpp @@ -9,6 +9,7 @@ #include "common/util/Timer.h" #include "common/util/diff.h" #include "common/util/os.h" +#include "common/util/set_util.h" #include "common/util/unicode_util.h" #include "common/versions.h" @@ -66,6 +67,14 @@ int main(int argc, char** argv) { return 1; } + // Check if any banned objects are also in the allowed objects list + // if so, throw an error as this can be a confusing situation + auto intersection = set_util::intersection(config.allowed_objects, config.banned_objects); + if (!intersection.empty()) { + lg::error("Aborting - There is an overlap between 'allowed_objects' and 'banned_objects'"); + return 1; + } + in_folder = in_folder / config.game_name; // Verify the in_folder is correct if (!exists(in_folder)) { @@ -119,6 +128,21 @@ int main(int argc, char** argv) { lg::info("Setting up object file DB..."); ObjectFileDB db(dgos, fs::path(config.obj_file_name_map_file), objs, strs, config); + // Explicitly fail if a file in the 'allowed_objects' list wasn't found in the DB + // as this is another silent error that can be confusing + if (!config.allowed_objects.empty()) { + for (const auto& expected_obj : config.allowed_objects) { + if (db.obj_files_by_name.count(expected_obj) == 0) { + // TODO - this is wrong for jak1, fix eventually as this is now done in 3 places + lg::error( + "Expected to find '{}' in the ObjectFileDB but did not. Check " + "./decompiler/config/{}/inputs.jsonc", + expected_obj, config.game_name); + return 1; + } + } + } + lg::info("[Mem] After DB setup: {} MB", get_peak_rss() / (1024 * 1024)); // write out DGO file info