HLE: Make naming closer to the current coding style
This commit is contained in:
parent
e0605d7911
commit
6b05e48bd6
|
@ -21,23 +21,22 @@
|
|||
|
||||
namespace HLE
|
||||
{
|
||||
using namespace PowerPC;
|
||||
using HookFunction = void (*)();
|
||||
|
||||
typedef void (*TPatchFunction)();
|
||||
// Map addresses to the HLE hook function id
|
||||
static std::map<u32, u32> s_hooked_addresses;
|
||||
|
||||
static std::map<u32, u32> s_original_instructions;
|
||||
|
||||
struct SPatch
|
||||
struct Hook
|
||||
{
|
||||
char m_szPatchName[128];
|
||||
TPatchFunction PatchFunction;
|
||||
char name[128];
|
||||
HookFunction function;
|
||||
HookType type;
|
||||
HookFlag flags;
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
constexpr std::array<SPatch, 23> OSPatches{{
|
||||
// Placeholder, OSPatches[0] is the "non-existent function" index
|
||||
constexpr std::array<Hook, 23> os_patches{{
|
||||
// Placeholder, os_patches[0] is the "non-existent function" index
|
||||
{"FAKE_TO_SKIP_0", HLE_Misc::UnimplementedFunction, HookType::Replace, HookFlag::Generic},
|
||||
|
||||
// Name doesn't matter, installed in CBoot::BootUp()
|
||||
|
@ -74,11 +73,11 @@ constexpr std::array<SPatch, 23> OSPatches{{
|
|||
|
||||
void Patch(u32 addr, std::string_view func_name)
|
||||
{
|
||||
for (u32 i = 1; i < OSPatches.size(); ++i)
|
||||
for (u32 i = 1; i < os_patches.size(); ++i)
|
||||
{
|
||||
if (OSPatches[i].m_szPatchName == func_name)
|
||||
if (os_patches[i].name == func_name)
|
||||
{
|
||||
s_original_instructions[addr] = i;
|
||||
s_hooked_addresses[addr] = i;
|
||||
PowerPC::ppcState.iCache.Invalidate(addr);
|
||||
return;
|
||||
}
|
||||
|
@ -106,12 +105,12 @@ void PatchFixedFunctions()
|
|||
void PatchFunctions()
|
||||
{
|
||||
// Remove all hooks that aren't fixed address hooks
|
||||
for (auto i = s_original_instructions.begin(); i != s_original_instructions.end();)
|
||||
for (auto i = s_hooked_addresses.begin(); i != s_hooked_addresses.end();)
|
||||
{
|
||||
if (OSPatches[i->second].flags != HookFlag::Fixed)
|
||||
if (os_patches[i->second].flags != HookFlag::Fixed)
|
||||
{
|
||||
PowerPC::ppcState.iCache.Invalidate(i->first);
|
||||
i = s_original_instructions.erase(i);
|
||||
i = s_hooked_addresses.erase(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -119,27 +118,27 @@ void PatchFunctions()
|
|||
}
|
||||
}
|
||||
|
||||
for (u32 i = 1; i < OSPatches.size(); ++i)
|
||||
for (u32 i = 1; i < os_patches.size(); ++i)
|
||||
{
|
||||
// Fixed hooks don't map to symbols
|
||||
if (OSPatches[i].flags == HookFlag::Fixed)
|
||||
if (os_patches[i].flags == HookFlag::Fixed)
|
||||
continue;
|
||||
|
||||
for (const auto& symbol : g_symbolDB.GetSymbolsFromName(OSPatches[i].m_szPatchName))
|
||||
for (const auto& symbol : g_symbolDB.GetSymbolsFromName(os_patches[i].name))
|
||||
{
|
||||
for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4)
|
||||
{
|
||||
s_original_instructions[addr] = i;
|
||||
s_hooked_addresses[addr] = i;
|
||||
PowerPC::ppcState.iCache.Invalidate(addr);
|
||||
}
|
||||
INFO_LOG(OSHLE, "Patching %s %08x", OSPatches[i].m_szPatchName, symbol->address);
|
||||
INFO_LOG(OSHLE, "Patching %s %08x", os_patches[i].name, symbol->address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
s_original_instructions.clear();
|
||||
s_hooked_addresses.clear();
|
||||
}
|
||||
|
||||
void Reload()
|
||||
|
@ -149,30 +148,30 @@ void Reload()
|
|||
PatchFunctions();
|
||||
}
|
||||
|
||||
void Execute(u32 _CurrentPC, u32 _Instruction)
|
||||
void Execute(u32 current_pc, u32 instruction)
|
||||
{
|
||||
unsigned int FunctionIndex = _Instruction & 0xFFFFF;
|
||||
if (FunctionIndex > 0 && FunctionIndex < OSPatches.size())
|
||||
const unsigned int function_index = instruction & 0xFFFFF;
|
||||
if (function_index > 0 && function_index < os_patches.size())
|
||||
{
|
||||
OSPatches[FunctionIndex].PatchFunction();
|
||||
os_patches[function_index].function();
|
||||
}
|
||||
else
|
||||
{
|
||||
PanicAlert("HLE system tried to call an undefined HLE function %i.", FunctionIndex);
|
||||
PanicAlert("HLE system tried to call an undefined HLE function %i.", function_index);
|
||||
}
|
||||
}
|
||||
|
||||
u32 GetFunctionIndex(u32 address)
|
||||
{
|
||||
auto iter = s_original_instructions.find(address);
|
||||
return (iter != s_original_instructions.end()) ? iter->second : 0;
|
||||
auto iter = s_hooked_addresses.find(address);
|
||||
return (iter != s_hooked_addresses.end()) ? iter->second : 0;
|
||||
}
|
||||
|
||||
u32 GetFirstFunctionIndex(u32 address)
|
||||
{
|
||||
const u32 index = GetFunctionIndex(address);
|
||||
// Fixed hooks use a fixed address and don't patch the whole function
|
||||
if (index == 0 || OSPatches[index].flags == HookFlag::Fixed)
|
||||
if (index == 0 || os_patches[index].flags == HookFlag::Fixed)
|
||||
return index;
|
||||
|
||||
const auto symbol = g_symbolDB.GetSymbolFromAddr(address);
|
||||
|
@ -181,12 +180,12 @@ u32 GetFirstFunctionIndex(u32 address)
|
|||
|
||||
HookType GetFunctionTypeByIndex(u32 index)
|
||||
{
|
||||
return OSPatches[index].type;
|
||||
return os_patches[index].type;
|
||||
}
|
||||
|
||||
HookFlag GetFunctionFlagsByIndex(u32 index)
|
||||
{
|
||||
return OSPatches[index].flags;
|
||||
return os_patches[index].flags;
|
||||
}
|
||||
|
||||
bool IsEnabled(HookFlag flag)
|
||||
|
@ -197,23 +196,23 @@ bool IsEnabled(HookFlag flag)
|
|||
|
||||
u32 UnPatch(std::string_view patch_name)
|
||||
{
|
||||
const auto patch = std::find_if(std::begin(OSPatches), std::end(OSPatches),
|
||||
[&](const SPatch& p) { return patch_name == p.m_szPatchName; });
|
||||
if (patch == std::end(OSPatches))
|
||||
const auto patch = std::find_if(std::begin(os_patches), std::end(os_patches),
|
||||
[&](const Hook& p) { return patch_name == p.name; });
|
||||
if (patch == std::end(os_patches))
|
||||
return 0;
|
||||
|
||||
if (patch->flags == HookFlag::Fixed)
|
||||
{
|
||||
const u32 patch_idx = static_cast<u32>(std::distance(OSPatches.begin(), patch));
|
||||
const u32 patch_idx = static_cast<u32>(std::distance(os_patches.begin(), patch));
|
||||
u32 addr = 0;
|
||||
// Reverse search by OSPatch key instead of address
|
||||
for (auto i = s_original_instructions.begin(); i != s_original_instructions.end();)
|
||||
for (auto i = s_hooked_addresses.begin(); i != s_hooked_addresses.end();)
|
||||
{
|
||||
if (i->second == patch_idx)
|
||||
{
|
||||
addr = i->first;
|
||||
PowerPC::ppcState.iCache.Invalidate(i->first);
|
||||
i = s_original_instructions.erase(i);
|
||||
i = s_hooked_addresses.erase(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -229,7 +228,7 @@ u32 UnPatch(std::string_view patch_name)
|
|||
const auto& symbol = symbols[0];
|
||||
for (u32 addr = symbol->address; addr < symbol->address + symbol->size; addr += 4)
|
||||
{
|
||||
s_original_instructions.erase(addr);
|
||||
s_hooked_addresses.erase(addr);
|
||||
PowerPC::ppcState.iCache.Invalidate(addr);
|
||||
}
|
||||
return symbol->address;
|
||||
|
|
Loading…
Reference in New Issue