Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <stdio.h>
- template< typename Fn >
- __forceinline Fn get_vfunc(void* pVmt, int iIndex) {
- return (*(Fn**)pVmt)[iIndex];
- }
- class CBaseEntity {
- public:
- char __pad[0x64];
- int index;
- int GetHealth();
- };
- int CBaseEntity::GetHealth()
- {
- return *(int*)((DWORD)this + 0x000000FC);
- }
- class IClientEntityList {
- public:
- CBaseEntity* GetClientEntity(int iIndex)
- {
- // return type // class to insert // index //args to pass
- return get_vfunc<CBaseEntity*(__thiscall*)(IClientEntityList*, int)>(this, 3)(this, iIndex);
- }
- };
- class IEngineClient {
- public:
- int GetLocalPlayer()
- {
- // return type // class to insert // index //args to pass
- return get_vfunc<int(__thiscall*)(IEngineClient*)>(this, 12)(this);
- }
- };
- IClientEntityList* EntList;
- IEngineClient* Engine;
- typedef void* (*CreateInterfaceFn)(const char *pName, int *pReturnCode);
- template< typename Interface >
- Interface* GetInterface(const char* pszModule, const char* pszInterfaceName) {
- Interface* pTemp = nullptr;
- char szBuf[64] = { 0 };
- auto Factory = (CreateInterfaceFn)GetProcAddress(GetModuleHandleA(pszModule), "CreateInterface");
- for (int i = 0; i < 100; i++) {
- sprintf_s(szBuf, "%s%03d", pszInterfaceName, i);
- pTemp = (Interface*)Factory(szBuf, 0);
- if (pTemp) break;
- }
- return pTemp;
- }
- static void Init() {
- auto pEntList = GetInterface<IClientEntityList>("client.dll", "VClientEntityList");
- auto pEngine = GetInterface<IEngineClient>("engine.dll", "VEngineClient");
- Engine = pEngine;
- EntList = pEntList;
- char buf[16];
- sprintf_s(buf, "%d", EntList->GetClientEntity(Engine->GetLocalPlayer())->GetHealth());
- MessageBoxA(NULL, buf, "hi", MB_OK);
- }
- BOOL WINAPI DllMain(void*, DWORD reason, void*) {
- if (reason == DLL_PROCESS_ATTACH)
- CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Init, 0, 0, 0);
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement