mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Heavy output code cleanup
Only add to detour if the VFTable pointer didn't exist yet. Not declaring these in the anonymous namespace significantly reduces code size and unnecessary memory allocations. We might want to consider refactoring this, although it will probably require a big change.
This commit is contained in:
parent
9e7495e407
commit
d20250e436
@ -27,6 +27,7 @@
|
||||
#include <iomanip>
|
||||
#include <cassert>
|
||||
#include <filesystem>
|
||||
#include <unordered_set>
|
||||
|
||||
#if !defined(DEDICATED) && !defined(SDKLAUNCHER) && !defined (NETCONSOLE) && !defined(PLUGINSDK)
|
||||
#include <d3d11.h>
|
||||
|
15
r5dev/thirdparty/detours/include/idetour.h
vendored
15
r5dev/thirdparty/detours/include/idetour.h
vendored
@ -1,7 +1,7 @@
|
||||
#ifndef IDETOUR_H
|
||||
#define IDETOUR_H
|
||||
|
||||
#define ADDDETOUR(x,y) static std::size_t dummy_reg_##y = AddDetour( new x() );
|
||||
#define ADDDETOUR(x,y) static std::size_t dummy_reg_##y = AddDetour( new x(), #x );
|
||||
#define XREGISTER(x,y) ADDDETOUR(x, y)
|
||||
#define REGISTER(x) XREGISTER(x, __COUNTER__)
|
||||
|
||||
@ -29,15 +29,16 @@ class VDetour : public IDetour
|
||||
virtual void Detach(void) const { }
|
||||
};
|
||||
|
||||
namespace
|
||||
inline std::vector<IDetour*> vDetour;
|
||||
inline std::unordered_set<IDetour*> sDetour;
|
||||
inline std::size_t AddDetour(IDetour* pDetour, const char* pszName)
|
||||
{
|
||||
std::vector<IDetour*> vDetour;
|
||||
std::size_t AddDetour(IDetour* pDetour)
|
||||
{
|
||||
vDetour.push_back(pDetour);
|
||||
IDetour* pVFTable = reinterpret_cast<IDetour**>(pDetour)[0];
|
||||
auto p = sDetour.insert(pVFTable); // Only register if VFTable isn't already registered.
|
||||
|
||||
p.second ? vDetour.push_back(pDetour) : delete pDetour;
|
||||
return vDetour.size();
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER(VDetour);
|
||||
#endif // IDETOUR_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user