Improve hook reliability - fixes GMalloc nullptr and proper alloc size
This commit is contained in:
@@ -48,13 +48,21 @@ namespace SDK
|
|||||||
{
|
{
|
||||||
FString(const wchar_t* other)
|
FString(const wchar_t* other)
|
||||||
{
|
{
|
||||||
Max = Count = *other ? std::wcslen(other) + 1 : 0;
|
const size_t charLen = std::wcslen(other);
|
||||||
|
|
||||||
if (Count)
|
if (charLen == 0)
|
||||||
{
|
{
|
||||||
Data = static_cast<wchar_t*>(GMalloc->Malloc(Count));
|
Count = 0;
|
||||||
|
Max = 0;
|
||||||
|
Data = nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Count = charLen + 1;
|
||||||
|
Max = Count;
|
||||||
|
Data = static_cast<wchar_t*>((*GMalloc)->Malloc(Count * 2));
|
||||||
|
|
||||||
wcscpy_s(Data, Count, other);
|
memcpy(Data, other, charLen * 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,5 +75,5 @@ namespace SDK
|
|||||||
virtual const TCHAR* GetDescriptiveName() = 0;
|
virtual const TCHAR* GetDescriptiveName() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
FMalloc* GMalloc;
|
FMalloc** GMalloc;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,10 +38,7 @@ DWORD WINAPI OnDllAttach(LPVOID base)
|
|||||||
const auto hModulePtr = reinterpret_cast<uintptr_t>(hModule);
|
const auto hModulePtr = reinterpret_cast<uintptr_t>(hModule);
|
||||||
|
|
||||||
// Initialize GMalloc.
|
// Initialize GMalloc.
|
||||||
do
|
SDK::GMalloc = reinterpret_cast<SDK::FMalloc**>(hModulePtr + OffsetGMalloc);
|
||||||
{
|
|
||||||
SDK::GMalloc = *reinterpret_cast<SDK::FMalloc**>(hModulePtr + OffsetGMalloc);
|
|
||||||
} while (SDK::GMalloc == nullptr);
|
|
||||||
|
|
||||||
// Initialize MinHook.
|
// Initialize MinHook.
|
||||||
if (MH_Initialize() != MH_OK)
|
if (MH_Initialize() != MH_OK)
|
||||||
|
|||||||
Reference in New Issue
Block a user