#include "file_management.h" #include #include #include "common/log/log.h" #include "common/util/json_util.h" #include "third-party/fmt/core.h" std::vector find_source_files(const std::string& game_name, const std::vector& dgos, const std::string& single_file) { std::vector result; auto base_dir = file_util::get_jak_project_dir() / "test" / "decompiler" / "reference" / game_name; auto ref_file_paths = file_util::find_files_recursively(base_dir, std::regex(".*_REF\\..*")); std::unordered_map ref_file_names = {}; for (const auto& path : ref_file_paths) { auto ref_name = path.filename().replace_extension().string(); ref_name.erase(ref_name.begin() + ref_name.find("_REF"), ref_name.end()); if (single_file.empty() || ref_name == single_file) { ref_file_names[ref_name] = path; } } lg::info("Found {} reference files", ref_file_paths.size()); // use the all_objs.json file to place them in the correct build order auto obj_json = parse_commented_json( file_util::read_text_file( (file_util::get_jak_project_dir() / "goal_src" / game_name / "build" / "all_objs.json") .string()), "all_objs.json"); std::unordered_set matched_files; for (auto& x : obj_json) { auto unique_name = x[0].get(); std::vector dgoList = x[3].get>(); auto it = ref_file_names.find(unique_name); if (it != ref_file_names.end()) { // Check to see if we've included atleast one of the DGO/CGOs in our hardcoded list // If not BLOW UP std::optional containing_dgo = {}; for (int i = 0; i < (int)dgoList.size(); i++) { std::string& dgo = dgoList.at(i); // can either be in the DGO or CGO folder, and can either end with .CGO or .DGO if (std::find(dgos.begin(), dgos.end(), fmt::format("DGO/{}.DGO", dgo)) != dgos.end() || std::find(dgos.begin(), dgos.end(), fmt::format("DGO/{}.CGO", dgo)) != dgos.end() || std::find(dgos.begin(), dgos.end(), fmt::format("CGO/{}.DGO", dgo)) != dgos.end() || std::find(dgos.begin(), dgos.end(), fmt::format("CGO/{}.CGO", dgo)) != dgos.end()) { containing_dgo = dgo; break; } } if (!containing_dgo) { lg::error( "File [{}] is in the following DGOs [{}], and not one of these is in our list! Add " "it!", unique_name, fmt::join(dgoList, ", ")); exit(1); } OfflineTestSourceFile file(it->second, containing_dgo.value(), x[1], it->first); result.push_back(file); matched_files.insert(unique_name); } } if (matched_files.size() != ref_file_names.size()) { lg::error("Some REF files were not matched to files in all_objs.json:"); for (const auto& [path, flag] : ref_file_names) { if (matched_files.count(path) == 0) { lg::error("- '{}'", path); } } exit(1); } return result; } std::unordered_map> find_art_files( const std::string& game_name) { // Pull from the json database of all art file data // this is generated via 'dump_art_group_info' in the config file auto file_name = file_util::get_jak_project_dir() / "test" / "offline" / "data" / game_name / "art-group-info.min.json"; if (!file_util::file_exists(file_name.string())) { lg::error("couldn't locate {}, exiting", file_name.string()); } auto art_group_info = parse_commented_json(file_util::read_text_file(file_name), "art-group-info.min.json"); return art_group_info; }