mirror of
https://github.com/EricPlayZ/EGameTools.git
synced 2025-07-18 17:37:53 +08:00
optimize some code
This commit is contained in:
@ -90,7 +90,7 @@ namespace GamePH {
|
||||
hooked = true;
|
||||
}
|
||||
|
||||
const DWORD64 PlayerVariables::GetFloatPlayerVariableVT() {
|
||||
DWORD64 PlayerVariables::GetFloatPlayerVariableVT() {
|
||||
if (FloatPlayerVariableVT != NULL)
|
||||
return FloatPlayerVariableVT;
|
||||
if (Offsets::Get_InitializePlayerVariablesOffset() == NULL)
|
||||
@ -102,7 +102,7 @@ namespace GamePH {
|
||||
|
||||
return FloatPlayerVariableVT = offsetToInstr + sizeof(DWORD) + floatPlayerVariableVTOffset;
|
||||
}
|
||||
const DWORD64 PlayerVariables::GetBoolPlayerVariableVT() {
|
||||
DWORD64 PlayerVariables::GetBoolPlayerVariableVT() {
|
||||
if (BoolPlayerVariableVT != NULL)
|
||||
return BoolPlayerVariableVT;
|
||||
if (Offsets::Get_InitializePlayerVariablesOffset() == NULL)
|
||||
|
@ -42,8 +42,8 @@ namespace GamePH {
|
||||
static bool hooked;
|
||||
static void RunHooks();
|
||||
|
||||
static const DWORD64 GetFloatPlayerVariableVT();
|
||||
static const DWORD64 GetBoolPlayerVariableVT();
|
||||
static DWORD64 GetFloatPlayerVariableVT();
|
||||
static DWORD64 GetBoolPlayerVariableVT();
|
||||
static void GetPlayerVars();
|
||||
|
||||
static PlayerVariables* Get();
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace Hook {
|
||||
// VTable hooking
|
||||
static const int VTHookUnprotect(LPVOID region) {
|
||||
static int VTHookUnprotect(LPVOID region) {
|
||||
MEMORY_BASIC_INFORMATION mbi{};
|
||||
VirtualQuery(static_cast<LPCVOID>(region), &mbi, sizeof(mbi));
|
||||
VirtualProtect(mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, &mbi.Protect);
|
||||
@ -28,7 +28,7 @@ namespace Hook {
|
||||
}
|
||||
|
||||
// Trampoline hooking
|
||||
const DETOUR_INFO MidFuncHook(DWORD64* pTarget, DWORD64* pHookedFunc, const size_t nops, const size_t bytesToSkip) {
|
||||
DETOUR_INFO MidFuncHook(DWORD64* pTarget, DWORD64* pHookedFunc, const size_t nops, const size_t bytesToSkip) {
|
||||
DWORD dwOldProtect, dwBkup{};
|
||||
|
||||
const size_t finalHookSize = 13 + nops;
|
||||
|
@ -20,7 +20,7 @@ namespace Hook {
|
||||
|
||||
extern void VTHook(LPVOID instance, LPVOID pDetour, LPVOID* ppOriginal, const DWORD offset);
|
||||
|
||||
extern const DETOUR_INFO MidFuncHook(DWORD64* pTarget, DWORD64* hookedFunc, const size_t nops = 0, const size_t bytesToSkip = 0);
|
||||
extern DETOUR_INFO MidFuncHook(DWORD64* pTarget, DWORD64* hookedFunc, const size_t nops = 0, const size_t bytesToSkip = 0);
|
||||
|
||||
class BreakpointHook {
|
||||
private:
|
||||
|
@ -1,10 +1,9 @@
|
||||
#include <Windows.h>
|
||||
#include <Psapi.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace Memory {
|
||||
const MODULEINFO GetModuleInfo(const std::string_view szModule) {
|
||||
const HMODULE hModule = GetModuleHandle(szModule.data());
|
||||
MODULEINFO GetModuleInfo(const char* szModule) {
|
||||
const HMODULE hModule = GetModuleHandle(szModule);
|
||||
if (hModule == 0)
|
||||
return MODULEINFO();
|
||||
|
||||
@ -13,8 +12,8 @@ namespace Memory {
|
||||
return moduleInfo;
|
||||
}
|
||||
|
||||
const bool IsAddressValidMod(const DWORD64 ptr, const std::string_view moduleName) {
|
||||
const MODULEINFO moduleInf = GetModuleInfo(moduleName);
|
||||
bool IsAddressValidMod(const DWORD64 ptr, const char* moduleName) {
|
||||
MODULEINFO moduleInf = GetModuleInfo(moduleName);
|
||||
|
||||
const DWORD64 moduleEntryPoint = reinterpret_cast<DWORD64>(moduleInf.EntryPoint);
|
||||
const DWORD64 moduleEndPoint = moduleEntryPoint + moduleInf.SizeOfImage;
|
||||
|
@ -1,20 +1,19 @@
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
#include <Psapi.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace Memory {
|
||||
extern const MODULEINFO GetModuleInfo(const std::string_view szModule);
|
||||
extern MODULEINFO GetModuleInfo(const char* szModule);
|
||||
|
||||
extern const bool IsAddressValidMod(const DWORD64 ptr, const std::string_view moduleName);
|
||||
extern bool IsAddressValidMod(const DWORD64 ptr, const char* moduleName);
|
||||
|
||||
template<typename ptrT>
|
||||
const bool IsValidPtr(ptrT ptr) {
|
||||
bool IsValidPtr(ptrT ptr) {
|
||||
return !IsBadReadPtr(reinterpret_cast<LPVOID>(ptr), sizeof(LPVOID));
|
||||
}
|
||||
|
||||
template<typename ptrT = LPVOID>
|
||||
const bool IsValidPtrMod(ptrT ptr, const std::string_view moduleName, const bool checkForVT = true) {
|
||||
bool IsValidPtrMod(ptrT ptr, const char* moduleName, const bool checkForVT = true) {
|
||||
return IsValidPtr<ptrT>(ptr) && IsAddressValidMod(checkForVT ? *(DWORD64*)(ptr) : (DWORD64)(ptr), moduleName);
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <Windows.h>
|
||||
|
||||
namespace Utils {
|
||||
const WindowsVersion GetWindowsVersion() {
|
||||
WindowsVersion GetWindowsVersion() {
|
||||
OSVERSIONINFOEX info{};
|
||||
DWORDLONG dwlConditionMask = 0;
|
||||
|
||||
|
@ -6,5 +6,5 @@ enum class WindowsVersion {
|
||||
};
|
||||
|
||||
namespace Utils {
|
||||
extern const WindowsVersion GetWindowsVersion();
|
||||
extern WindowsVersion GetWindowsVersion();
|
||||
}
|
Reference in New Issue
Block a user