Skip to content

Commit

Permalink
Remove Hooks::MinHook class and use MinHook from Hooks/MinHook.h instead
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkrupinski committed Jun 21, 2020
1 parent 2c9eb04 commit 5877967
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 37 deletions.
8 changes: 2 additions & 6 deletions Osiris/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "imgui/imgui_impl_dx9.h"
#include "imgui/imgui_impl_win32.h"

#include "MinHook/MinHook.h"

#include "Config.h"
#include "EventListener.h"
#include "GUI.h"
Expand Down Expand Up @@ -704,9 +706,3 @@ void Hooks::Vmt::restore() noexcept
if (newVmt)
ZeroMemory(newVmt, length * sizeof(uintptr_t));
}

bool Hooks::MinHook::init(void* const base) noexcept
{
this->base = base;
return true;
}
32 changes: 1 addition & 31 deletions Osiris/Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <unordered_map>
#include <Windows.h>

#include "MinHook/MinHook.h"
#include "Hooks/MinHook.h"

struct SoundInfo;

Expand Down Expand Up @@ -54,36 +54,6 @@ class Hooks {
size_t length = 0;
};

// TODO: Make an interface class to easily switch between hooking methods
class MinHook {
public:
bool init(void* const) noexcept;

void hookAt(std::size_t index, void* fun) noexcept
{
void* orig;
MH_CreateHook((*reinterpret_cast<void***>(base))[index], fun, &orig);
originals[index] = std::uintptr_t(orig);
}

template <typename T, std::size_t Idx, typename ...Args>
auto callOriginal(Args... args) noexcept
{
return reinterpret_cast<T(__thiscall*)(void*, Args...)>(originals[Idx])(base, args...);
}

template <typename T, typename ...Args>
auto getOriginal(std::size_t index, Args... args) noexcept
{
return reinterpret_cast<T(__thiscall*)(void*, Args...)>(originals[index]);
}

void restore() noexcept {}
private:
void* base = nullptr;
std::unordered_map<std::size_t, std::uintptr_t> originals;
};

Vmt svCheats;

MinHook bspQuery;
Expand Down

0 comments on commit 5877967

Please sign in to comment.