pickup combining, almost finish shadow stones, fix some bugs with gadgets, clean up some code.
This commit is contained in:
Milxnor
2023-05-02 23:48:05 -04:00
parent 3b0f0ad4e1
commit f49f166c2d
27 changed files with 574 additions and 216 deletions

View File

@@ -338,4 +338,43 @@ namespace Hooking
*Addr = Original;
} */
}
}
static inline void ChangeBytesThing(uint8_t* instrAddr, uint8_t* DetourAddr, int Offset)
{
int64_t delta = DetourAddr - (instrAddr + Offset + 4);
*(int32_t*)(instrAddr + Offset) = static_cast<int32_t>(delta);
}
enum ERelativeOffsets
{
CALL = 1,
LEA = 3
};
static inline void HookInstruction(uint64 instrAddr, void* Detour, const std::string& FunctionToReplace, ERelativeOffsets Offset, UObject* DefaultClass = nullptr) // we need better name
{
if (!instrAddr)
return;
auto UFunc = FindObject<UFunction>(FunctionToReplace);
uint64 FunctionAddr = __int64(UFunc->GetFunc()); // GetFunctionIdxOrPtr(FindObject<UFunction>(FunctionToReplace));
if (IsBadReadPtr((void*)FunctionAddr))
{
auto Idx = FunctionAddr / 8;
FunctionAddr = (uint64)DefaultClass->VFTable[Idx];
}
if (__int64(instrAddr) - FunctionAddr < 0) // We do not want the FunctionAddr (detour) to be less than where we are replacing.
{
LOG_INFO(LogDev, "Hooking Instruction will not work! Function is after ({})!", FunctionToReplace);
return;
}
Hooking::MinHook::Hook((PVOID)FunctionAddr, Detour, nullptr, FunctionToReplace);
ChangeBytesThing((uint8_t*)instrAddr, (uint8_t*)FunctionAddr, (int)Offset);
}