feat(p2p): Port overrides for Splatoon and MK8

This commit is contained in:
Ash Logan 2024-11-29 21:39:50 +11:00
commit a6b91be935
4 changed files with 78 additions and 14 deletions

View file

@ -73,17 +73,30 @@ void replaceBulk(uint32_t start, uint32_t size, std::span<const replacement> rep
#endif
}
bool replace_instruction(uint32_t *inst, uint32_t orignal_value, uint32_t new_value) {
if (*inst != orignal_value) return false;
template <typename U>
requires std::integral<U>
bool replace_unsigned(U *addr, U original_value, U new_value) {
if (*addr != original_value) return false;
KernelCopyData(
OSEffectiveToPhysical((uint32_t) inst),
OSEffectiveToPhysical((uint32_t) addr),
OSEffectiveToPhysical((uint32_t) &new_value),
sizeof(new_value)
);
DCFlushRange(inst, sizeof(new_value));
ICInvalidateRange(inst, sizeof(new_value));
DCFlushRange(addr, sizeof(new_value));
DEBUG_FUNCTION_LINE_VERBOSE("%08x is now %08x", inst, *inst);
return *inst == new_value;
return *addr == new_value;
}
template bool replace_unsigned<uint64_t>(uint64_t *, uint64_t, uint64_t);
template bool replace_unsigned<uint32_t>(uint32_t *, uint32_t, uint32_t);
template bool replace_unsigned<uint16_t>(uint16_t *, uint16_t, uint16_t);
template bool replace_unsigned<uint8_t>(uint8_t *, uint8_t, uint8_t);
bool replace_instruction(uint32_t *inst, uint32_t original_value, uint32_t new_value) {
bool res = replace_unsigned<uint32_t>(inst, original_value, new_value);
if (!res) return res;
ICInvalidateRange(inst, sizeof(new_value));
return true;
}

View file

@ -28,4 +28,8 @@ struct replacement {
void replaceBulk(uint32_t start, uint32_t size, std::span<const replacement> replacements);
bool replace_instruction(uint32_t *inst, uint32_t orignal_value, uint32_t new_value);
template <typename U>
requires std::integral<U>
bool replace_unsigned(U *addr, U original_value, U new_value);
bool replace_instruction(uint32_t *inst, uint32_t original_value, uint32_t new_value);

View file

@ -19,10 +19,10 @@
std::optional<OSDynLoad_NotifyData> search_for_rpl(std::string_view name);
constexpr uint32_t *rpl_addr(OSDynLoad_NotifyData rpl, uint32_t cemu_addr) {
constexpr void *rpl_addr(OSDynLoad_NotifyData rpl, uint32_t cemu_addr) {
if (cemu_addr < 0x1000'0000) {
return (uint32_t *)(rpl.textAddr + cemu_addr - 0x0200'0000);
return (void *)(rpl.textAddr + cemu_addr - 0x0200'0000);
} else {
return (uint32_t *)(rpl.dataAddr + cemu_addr - 0x1000'0000);
return (void *)(rpl.dataAddr + cemu_addr - 0x1000'0000);
}
}