From 4f9e5e1141637804494703e0335869667e1585fd Mon Sep 17 00:00:00 2001 From: Sepalani Date: Wed, 23 Nov 2016 00:09:48 +0000 Subject: [PATCH] [HLE] Added GetFirstFunctionIndex matching the start address --- Source/Core/Core/HLE/HLE.cpp | 13 +++++++++++-- Source/Core/Core/HLE/HLE.h | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/HLE/HLE.cpp b/Source/Core/Core/HLE/HLE.cpp index c4ff14e63a..dc29237439 100644 --- a/Source/Core/Core/HLE/HLE.cpp +++ b/Source/Core/Core/HLE/HLE.cpp @@ -183,12 +183,21 @@ void Execute(u32 _CurrentPC, u32 _Instruction) // OSPatches[pos].m_szPatchName); } -u32 GetFunctionIndex(u32 addr) +u32 GetFunctionIndex(u32 address) { - auto iter = s_original_instructions.find(addr); + auto iter = s_original_instructions.find(address); return (iter != s_original_instructions.end()) ? iter->second : 0; } +u32 GetFirstFunctionIndex(u32 address) +{ + u32 index = GetFunctionIndex(address); + auto first = std::find_if( + s_original_instructions.begin(), s_original_instructions.end(), + [=](const auto& entry) { return entry.second == index && entry.first < address; }); + return first == std::end(s_original_instructions) ? index : 0; +} + int GetFunctionTypeByIndex(u32 index) { return OSPatches[index].type; diff --git a/Source/Core/Core/HLE/HLE.h b/Source/Core/Core/HLE/HLE.h index 8cc513124f..2ea49640f9 100644 --- a/Source/Core/Core/HLE/HLE.h +++ b/Source/Core/Core/HLE/HLE.h @@ -34,7 +34,10 @@ u32 UnPatch(const std::string& patchName); bool UnPatch(u32 addr, const std::string& name = {}); void Execute(u32 _CurrentPC, u32 _Instruction); -u32 GetFunctionIndex(u32 em_address); +// Returns the HLE function index if the address is located in the function +u32 GetFunctionIndex(u32 address); +// Returns the HLE function index if the address matches the function start +u32 GetFirstFunctionIndex(u32 address); int GetFunctionTypeByIndex(u32 index); int GetFunctionFlagsByIndex(u32 index);