mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Revert back to using verctors for detours
Enabling LTCG caused the emplacement order to be different, which is most likely due to additional optimizations for the binary search logic. Reverted to fix this bug.
This commit is contained in:
parent
261a9ea204
commit
2ca1a290e2
@ -170,10 +170,9 @@ void Systems_Init()
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
|
||||
// Hook functions
|
||||
for (const auto& elem : g_DetourMap)
|
||||
for (const IDetour* Detour : g_DetourVec)
|
||||
{
|
||||
const IDetour* detour = elem.second;
|
||||
detour->Attach();
|
||||
Detour->Attach();
|
||||
}
|
||||
|
||||
// Patch instructions
|
||||
@ -216,10 +215,9 @@ void Systems_Shutdown()
|
||||
DetourUpdateThread(GetCurrentThread());
|
||||
|
||||
// Unhook functions
|
||||
for (const auto& elem : g_DetourMap)
|
||||
for (const IDetour* Detour : g_DetourVec)
|
||||
{
|
||||
const IDetour* detour = elem.second;
|
||||
detour->Detach();
|
||||
Detour->Detach();
|
||||
}
|
||||
|
||||
// Commit the transaction
|
||||
@ -344,13 +342,11 @@ void DetourInit() // Run the sigscan
|
||||
g_SigCache.SetDisabled(bNoSmap);
|
||||
g_SigCache.LoadCache(SIGDB_FILE);
|
||||
|
||||
for (const auto& elem : g_DetourMap)
|
||||
for (const IDetour* Detour : g_DetourVec)
|
||||
{
|
||||
const IDetour* detour = elem.second;
|
||||
|
||||
detour->GetCon(); // Constants.
|
||||
detour->GetFun(); // Functions.
|
||||
detour->GetVar(); // Variables.
|
||||
Detour->GetCon(); // Constants.
|
||||
Detour->GetFun(); // Functions.
|
||||
Detour->GetVar(); // Variables.
|
||||
|
||||
if (bLogAdr)
|
||||
{
|
||||
@ -359,7 +355,7 @@ void DetourInit() // Run the sigscan
|
||||
bInitDivider = true;
|
||||
spdlog::debug("+---------------------------------------------------------------------+\n");
|
||||
}
|
||||
detour->GetAdr();
|
||||
Detour->GetAdr();
|
||||
spdlog::debug("+---------------------------------------------------------------------+\n");
|
||||
}
|
||||
}
|
||||
@ -376,11 +372,9 @@ void DetourInit() // Run the sigscan
|
||||
void DetourAddress() // Test the sigscan results
|
||||
{
|
||||
spdlog::debug("+---------------------------------------------------------------------+\n");
|
||||
for (const auto& elem : g_DetourMap)
|
||||
for (const IDetour* Detour : g_DetourVec)
|
||||
{
|
||||
const IDetour* detour = elem.second;
|
||||
|
||||
detour->GetAdr();
|
||||
Detour->GetAdr();
|
||||
spdlog::debug("+---------------------------------------------------------------------+\n");
|
||||
}
|
||||
}
|
||||
|
2
r5dev/thirdparty/detours/include/idetour.h
vendored
2
r5dev/thirdparty/detours/include/idetour.h
vendored
@ -17,7 +17,7 @@ public:
|
||||
virtual void Detach(void) const = 0;
|
||||
};
|
||||
|
||||
extern std::map<const void*, const IDetour*> g_DetourMap;
|
||||
extern std::vector<IDetour*> g_DetourVec;
|
||||
std::size_t AddDetour(IDetour* pDetour);
|
||||
|
||||
#define ADDDETOUR(x,y) static std::size_t dummy_reg_##y = AddDetour( new x() );
|
||||
|
16
r5dev/thirdparty/detours/src/idetour.cpp
vendored
16
r5dev/thirdparty/detours/src/idetour.cpp
vendored
@ -4,27 +4,27 @@
|
||||
//
|
||||
//===========================================================================//
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <unordered_set>
|
||||
#include "../include/idetour.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Contains a VFTable pointer, and the class instance. A VFTable can only be
|
||||
// used by one class instance. This is to avoid duplicate registrations.
|
||||
//-----------------------------------------------------------------------------
|
||||
std::map<const void*, const IDetour*> g_DetourMap;
|
||||
std::vector<IDetour*> g_DetourVec;
|
||||
std::unordered_set<IDetour*> g_DetourSet;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: adds a detour context to the list
|
||||
//-----------------------------------------------------------------------------
|
||||
std::size_t AddDetour(IDetour* pDetour)
|
||||
{
|
||||
const void* pVFTable = reinterpret_cast<const void**>(pDetour)[0];
|
||||
auto p = g_DetourMap.emplace(pVFTable, pDetour); // Only register if VFTable isn't already registered.
|
||||
IDetour* pVFTable = reinterpret_cast<IDetour**>(pDetour)[0];
|
||||
auto p = g_DetourSet.insert(pVFTable); // Only register if VFTable isn't already registered.
|
||||
|
||||
assert(p.second); // Code bug: duplicate registration!!! (called 'REGISTER(...)' from a header file?).
|
||||
p.second ? g_DetourVec.push_back(pDetour) : delete pDetour;
|
||||
|
||||
if (!p.second)
|
||||
delete pDetour;
|
||||
|
||||
return g_DetourMap.size();
|
||||
return g_DetourVec.size();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user