diff --git a/LiveRecomp/live_generator.cpp b/LiveRecomp/live_generator.cpp index b93d7ef..39ee42f 100644 --- a/LiveRecomp/live_generator.cpp +++ b/LiveRecomp/live_generator.cpp @@ -1563,8 +1563,14 @@ void N64Recomp::LiveGenerator::emit_switch(const Context& recompiler_context, co // Get the relocated address of the jump table. uint32_t section_offset = jtbl.vram - jtbl_section.ram_addr; + // Get the section index to use for relocation at runtime. + uint16_t reloc_section_index = jtbl.section_index; + if (!inputs.original_section_indices.empty()) { + reloc_section_index = inputs.original_section_indices[reloc_section_index]; + } + // Populate the necessary fields of the dummy context and load the relocated address into temp2. - dummy_context.reloc_section_index = jtbl.section_index; + dummy_context.reloc_section_index = reloc_section_index; dummy_context.reloc_target_section_offset = section_offset; load_relocated_address(dummy_context, Registers::arithmetic_temp2); diff --git a/include/recompiler/live_recompiler.h b/include/recompiler/live_recompiler.h index b85d894..d155b83 100644 --- a/include/recompiler/live_recompiler.h +++ b/include/recompiler/live_recompiler.h @@ -83,6 +83,9 @@ namespace N64Recomp { std::unordered_map entry_func_hooks; // Maps function index in recompiler context to function's return hook slot. std::unordered_map return_func_hooks; + // Maps section index in the generated code to original section index. Used by regenerated + // code to relocate using the corresponding original section's address. + std::vector original_section_indices; }; class LiveGenerator final : public Generator { public: