@@ -505,18 +505,20 @@ recomp::mods::LiveRecompilerCodeHandle::LiveRecompilerCodeHandle(
505505 N64Recomp::LiveGenerator generator{ context.functions .size (), recompiler_inputs };
506506 std::vector<std::vector<uint32_t >> dummy_static_funcs{};
507507
508+ bool errored = false ;
509+
508510 for (size_t func_index = 0 ; func_index < context.functions .size (); func_index++) {
509511 std::ostringstream dummy_ostream{};
510512
511513 if (!N64Recomp::recompile_function_live (generator, context, func_index, dummy_ostream, dummy_static_funcs, true )) {
512- is_good = false ;
514+ errored = true ;
513515 break ;
514516 }
515517 }
516518
517519 // Generate the code.
518520 recompiler_output = std::make_unique<N64Recomp::LiveGeneratorOutput>(generator.finish ());
519- is_good = recompiler_output->good ;
521+ is_good = !errored && recompiler_output->good ;
520522}
521523
522524void recomp::mods::LiveRecompilerCodeHandle::set_imported_function (size_t import_index, GenericFunction func) {
@@ -2167,22 +2169,28 @@ recomp::mods::CodeModLoadError recomp::mods::ModContext::init_mod_code(uint8_t*
21672169 int32_t cur_section_addr = load_address;
21682170 for (size_t section_index = 0 ; section_index < mod_sections.size (); section_index++) {
21692171 const auto & section = mod_sections[section_index];
2170- for (size_t i = 0 ; i < section.size ; i++) {
2171- MEM_B (i, (gpr)cur_section_addr) = binary_data[section.rom_addr + i];
2172+ // Do not load fixed address sections into mod memory. Use their address as-is.
2173+ if (section.fixed_address ) {
2174+ mod.section_load_addresses [section_index] = section.ram_addr ;
21722175 }
2173- mod.section_load_addresses [section_index] = cur_section_addr;
2174- // Calculate the bss section's address based on the size of this section.
2175- cur_section_addr += section.size ;
2176- // Zero the bss section.
2177- for (size_t i = 0 ; i < section.bss_size ; i++) {
2178- MEM_B (i, (gpr)cur_section_addr) = 0 ;
2176+ else {
2177+ for (size_t i = 0 ; i < section.size ; i++) {
2178+ MEM_B (i, (gpr)cur_section_addr) = binary_data[section.rom_addr + i];
2179+ }
2180+ mod.section_load_addresses [section_index] = cur_section_addr;
2181+ // Calculate the bss section's address based on the size of this section.
2182+ cur_section_addr += section.size ;
2183+ // Zero the bss section.
2184+ for (size_t i = 0 ; i < section.bss_size ; i++) {
2185+ MEM_B (i, (gpr)cur_section_addr) = 0 ;
2186+ }
2187+ // Calculate the next section's address based on the size of the bss section.
2188+ cur_section_addr += section.bss_size ;
2189+ // Align the next section's address to 16 bytes.
2190+ cur_section_addr = (cur_section_addr + 15 ) & ~15 ;
2191+ // Add some empty space between mods to act as a buffer for misbehaving mods that have out of bounds accesses.
2192+ cur_section_addr += 0x400 ;
21792193 }
2180- // Calculate the next section's address based on the size of the bss section.
2181- cur_section_addr += section.bss_size ;
2182- // Align the next section's address to 16 bytes.
2183- cur_section_addr = (cur_section_addr + 15 ) & ~15 ;
2184- // Add some empty space between mods to act as a buffer for misbehaving mods that have out of bounds accesses.
2185- cur_section_addr += 0x400 ;
21862194 }
21872195
21882196 // Iterate over each section again after loading them to perform R_MIPS_32 relocations.
@@ -2245,7 +2253,7 @@ recomp::mods::CodeModLoadError recomp::mods::ModContext::load_mod_code(uint8_t*
22452253 std::unordered_map<size_t , size_t > entry_func_hooks{};
22462254 std::unordered_map<size_t , size_t > return_func_hooks{};
22472255
2248- // Scan the replacements and check for any
2256+ // Scan the replacements to handle hooks on the replaced functions.
22492257 for (const auto & replacement : mod.recompiler_context ->replacements ) {
22502258 // Check if there's a hook slot for the entry of this function.
22512259 HookDefinition entry_def {
0 commit comments