mirror of
https://github.com/N64Recomp/N64Recomp.git
synced 2026-04-28 13:01:58 +00:00
Replace after_vram by before_vram
This commit is contained in:
parent
079bf0e8cd
commit
f32e47f930
4 changed files with 26 additions and 28 deletions
|
|
@ -42,7 +42,7 @@ namespace RecompPort {
|
|||
|
||||
struct FunctionHook {
|
||||
std::string func_name;
|
||||
int32_t after_vram;
|
||||
int32_t before_vram;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ std::vector<RecompPort::FunctionHook> get_function_hooks(const toml::table* patc
|
|||
const toml::table& cur_hook = *el.as_table();
|
||||
|
||||
// Get the vram and make sure it's 4-byte aligned.
|
||||
std::optional<uint32_t> after_vram = cur_hook["after_vram"].value<uint32_t>();
|
||||
std::optional<uint32_t> before_vram = cur_hook["before_vram"].value<uint32_t>();
|
||||
std::optional<std::string> func_name = cur_hook["func"].value<std::string>();
|
||||
std::optional<std::string> text = cur_hook["text"].value<std::string>();
|
||||
|
||||
|
|
@ -248,14 +248,14 @@ std::vector<RecompPort::FunctionHook> get_function_hooks(const toml::table* patc
|
|||
throw toml::parse_error("Function hook is missing required value(s)", el.source());
|
||||
}
|
||||
|
||||
if (after_vram.has_value() && after_vram.value() & 0b11) {
|
||||
if (before_vram.has_value() && before_vram.value() & 0b11) {
|
||||
// Not properly aligned, so throw an error (and make it look like a normal toml one).
|
||||
throw toml::parse_error("after_vram is not word-aligned", el.source());
|
||||
throw toml::parse_error("before_vram is not word-aligned", el.source());
|
||||
}
|
||||
|
||||
ret.push_back(RecompPort::FunctionHook{
|
||||
.func_name = func_name.value(),
|
||||
.after_vram = after_vram.has_value() ? (int32_t)after_vram.value() : 0,
|
||||
.before_vram = before_vram.has_value() ? (int32_t)before_vram.value() : 0,
|
||||
.text = text.value(),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
10
src/main.cpp
10
src/main.cpp
|
|
@ -1514,22 +1514,22 @@ int main(int argc, char** argv) {
|
|||
int32_t func_vram = func.vram;
|
||||
|
||||
// Check that the function actually contains this vram address.
|
||||
if (patch.after_vram < func_vram || patch.after_vram >= func_vram + func.words.size() * sizeof(func.words[0])) {
|
||||
exit_failure(fmt::format("Function {} has a function hook for vram 0x{:08X} but doesn't contain that vram address!", patch.func_name, (uint32_t)patch.after_vram));
|
||||
if (patch.before_vram < func_vram || patch.before_vram >= func_vram + func.words.size() * sizeof(func.words[0])) {
|
||||
exit_failure(fmt::format("Function {} has a function hook for vram 0x{:08X} but doesn't contain that vram address!", patch.func_name, (uint32_t)patch.before_vram));
|
||||
}
|
||||
|
||||
// No after_vram means this will be placed at the start of the function
|
||||
size_t instruction_index = -1;
|
||||
|
||||
// Calculate the instruction index.
|
||||
if (patch.after_vram != 0) {
|
||||
instruction_index = (static_cast<size_t>(patch.after_vram) - func_vram) / sizeof(uint32_t);
|
||||
if (patch.before_vram != 0) {
|
||||
instruction_index = (static_cast<size_t>(patch.before_vram) - func_vram) / sizeof(uint32_t);
|
||||
}
|
||||
|
||||
// Check if a function hook already exits for that instruction index.
|
||||
auto hook_find = func.function_hooks.find(instruction_index);
|
||||
if (hook_find != func.function_hooks.end()) {
|
||||
exit_failure(fmt::format("Function {} already has a function hook for vram 0x{:08X}!", patch.func_name, (uint32_t)patch.after_vram));
|
||||
exit_failure(fmt::format("Function {} already has a function hook for vram 0x{:08X}!", patch.func_name, (uint32_t)patch.before_vram));
|
||||
}
|
||||
|
||||
func.function_hooks[instruction_index] = patch.text;
|
||||
|
|
|
|||
|
|
@ -24,23 +24,33 @@ bool process_instruction(const RecompPort::Context& context, const RecompPort::C
|
|||
const auto& instr = instructions[instr_index];
|
||||
needs_link_branch = false;
|
||||
is_branch_likely = false;
|
||||
uint32_t instr_vram = instr.getVram();
|
||||
|
||||
auto print_indent = [&]() {
|
||||
fmt::print(output_file, " ");
|
||||
};
|
||||
|
||||
auto hook_find = func.function_hooks.find(instr_index);
|
||||
if (hook_find != func.function_hooks.end()) {
|
||||
fmt::print(output_file, " {}\n", hook_find->second);
|
||||
if (indent) {
|
||||
print_indent();
|
||||
}
|
||||
}
|
||||
|
||||
// Output a comment with the original instruction
|
||||
if (instr.isBranch() || instr.getUniqueId() == InstrId::cpu_j) {
|
||||
fmt::print(output_file, " // {}\n", instr.disassemble(0, fmt::format("L_{:08X}", (uint32_t)instr.getBranchVramGeneric())));
|
||||
fmt::print(output_file, " // 0x{:08X}: {}\n", instr_vram, instr.disassemble(0, fmt::format("L_{:08X}", (uint32_t)instr.getBranchVramGeneric())));
|
||||
} else if (instr.getUniqueId() == InstrId::cpu_jal) {
|
||||
fmt::print(output_file, " // {}\n", instr.disassemble(0, fmt::format("0x{:08X}", (uint32_t)instr.getBranchVramGeneric())));
|
||||
fmt::print(output_file, " // 0x{:08X}: {}\n", instr_vram, instr.disassemble(0, fmt::format("0x{:08X}", (uint32_t)instr.getBranchVramGeneric())));
|
||||
} else {
|
||||
fmt::print(output_file, " // {}\n", instr.disassemble(0));
|
||||
fmt::print(output_file, " // 0x{:08X}: {}\n", instr_vram, instr.disassemble(0));
|
||||
}
|
||||
|
||||
uint32_t instr_vram = instr.getVram();
|
||||
|
||||
if (skipped_insns.contains(instr_vram)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool at_reloc = false;
|
||||
bool reloc_handled = false;
|
||||
RecompPort::RelocType reloc_type = RecompPort::RelocType::R_MIPS_NONE;
|
||||
|
|
@ -71,10 +81,6 @@ bool process_instruction(const RecompPort::Context& context, const RecompPort::C
|
|||
}
|
||||
}
|
||||
|
||||
auto print_indent = [&]() {
|
||||
fmt::print(output_file, " ");
|
||||
};
|
||||
|
||||
auto print_line = [&]<typename... Ts>(fmt::format_string<Ts...> fmt_str, Ts ...args) {
|
||||
print_indent();
|
||||
fmt::vprint(output_file, fmt_str, fmt::make_format_args(args...));
|
||||
|
|
@ -1082,14 +1088,6 @@ bool process_instruction(const RecompPort::Context& context, const RecompPort::C
|
|||
return false;
|
||||
}
|
||||
|
||||
auto hook_find = func.function_hooks.find(instr_index);
|
||||
if (hook_find != func.function_hooks.end()) {
|
||||
if (indent) {
|
||||
print_indent();
|
||||
}
|
||||
fmt::print(output_file, " {}\n", hook_find->second);
|
||||
}
|
||||
|
||||
// TODO is this used?
|
||||
if (emit_link_branch) {
|
||||
fmt::print(output_file, " after_{}:\n", link_branch_index);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue