From 747cd9f6acc09d20ea9a8148def8cea88728a5cb Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Fri, 30 Aug 2024 01:21:43 -0400 Subject: [PATCH] Fix export names not being set on functions when parsing mod syms, add missing returns to mod parsing --- OfflineModRecomp/main.cpp | 7 ++++++- src/mod_symbols.cpp | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/OfflineModRecomp/main.cpp b/OfflineModRecomp/main.cpp index eaf61cc..440d49b 100644 --- a/OfflineModRecomp/main.cpp +++ b/OfflineModRecomp/main.cpp @@ -185,9 +185,14 @@ int main(int argc, const char** argv) { output_file << "// Array of this mod's loaded section addresses.\n"; output_file << "RECOMP_EXPORT int32_t section_addresses[" << std::max(size_t{1}, num_sections) << "] = {0};\n\n"; + // Create a set of the export indices to avoid renaming them. + std::unordered_set export_indices{mod_context.exported_funcs.begin(), mod_context.exported_funcs.end()}; + for (size_t func_index = 0; func_index < mod_context.functions.size(); func_index++) { auto& func = mod_context.functions[func_index]; - func.name = "mod_func_" + std::to_string(func_index); + if (!export_indices.contains(func_index)) { + func.name = "mod_func_" + std::to_string(func_index); + } N64Recomp::recompile_function(mod_context, func, output_file, static_funcs_by_section, true); } diff --git a/src/mod_symbols.cpp b/src/mod_symbols.cpp index e0beba3..8ba1859 100644 --- a/src/mod_symbols.cpp +++ b/src/mod_symbols.cpp @@ -234,6 +234,7 @@ bool parse_v1(std::span data, const std::unordered_map= mod_context.sections.size()) { printf("Reloc %zu in section %zu references local section %u, but only %zu exist\n", reloc_index, section_index, reloc_target_section, mod_context.sections.size()); + return false; } } else { @@ -269,6 +270,7 @@ bool parse_v1(std::span data, const std::unordered_map string_data_size) { printf("Dependency %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n", dependency_index, mod_id_start, mod_id_size, string_data_size); + return false; } std::string_view mod_id{ string_data + mod_id_start, string_data + mod_id_start + mod_id_size }; @@ -290,11 +292,13 @@ bool parse_v1(std::span data, const std::unordered_map string_data_size) { printf("Import %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n", import_index, name_start, name_size, string_data_size); + return false; } if (dependency_index >= num_dependencies) { printf("Import %zu belongs to dependency %u, but only %zu dependencies were specified\n", import_index, dependency_index, num_dependencies); + return false; } std::string_view import_name{ string_data + name_start, string_data + name_start + name_size }; @@ -317,6 +321,7 @@ bool parse_v1(std::span data, const std::unordered_map string_data_size) { printf("Dependency event %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n", dependency_event_index, name_start, name_size, string_data_size); + return false; } std::string_view dependency_event_name{ string_data + name_start, string_data + name_start + name_size }; @@ -355,15 +360,29 @@ bool parse_v1(std::span data, const std::unordered_map= mod_context.functions.size()) { printf("Export %zu has a function index of %u, but the symbol file only has %zu functions\n", export_index, func_index, mod_context.functions.size()); + return false; } if (name_start + name_size > string_data_size) { printf("Export %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n", export_index, name_start, name_size, string_data_size); + return false; + } + + std::string_view export_name_view{ string_data + name_start, string_data + name_start + name_size }; + std::string export_name{export_name_view}; + + if (!mod_context.functions[func_index].name.empty()) { + printf("Function %u is exported twice (%s and %s)\n", + func_index, mod_context.functions[func_index].name.c_str(), export_name.c_str()); + return false; } // Add the function to the exported function list. mod_context.exported_funcs[export_index] = func_index; + + // Set the function's name to the export name. + mod_context.functions[func_index].name = std::move(export_name); } const CallbackV1* callbacks = reinterpret_data(data, offset, num_callbacks); @@ -380,15 +399,18 @@ bool parse_v1(std::span data, const std::unordered_map= num_dependency_events) { printf("Callback %zu is connected to dependency event %u, but only %zu dependency events were specified\n", callback_index, dependency_event_index, num_dependency_events); + return false; } if (function_index >= mod_context.functions.size()) { printf("Callback %zu uses function %u, but only %zu functions were specified\n", callback_index, function_index, mod_context.functions.size()); + return false; } if (!mod_context.add_callback(dependency_event_index, function_index)) { printf("Failed to add callback %zu\n", callback_index); + return false; } } @@ -406,6 +428,7 @@ bool parse_v1(std::span data, const std::unordered_map string_data_size) { printf("Event %zu has a name start of %u and size of %u, which extend beyond the string data's total size of %zu\n", event_index, name_start, name_size, string_data_size); + return false; } std::string_view import_name{ string_data + name_start, string_data + name_start + name_size };