summaryrefslogtreecommitdiff
path: root/csgo_wh/src
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2018-07-02 01:06:39 +0200
committerToni Uhlig <matzeton@googlemail.com>2018-07-02 03:08:59 +0200
commitc2a2445897af17adb56a32dcf111312763a575d4 (patch)
treead459cdd682aff3a011d11b6f2a3c518c60dec6a /csgo_wh/src
initial commit
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'csgo_wh/src')
-rwxr-xr-xcsgo_wh/src/D9DW.cpp119
-rwxr-xr-xcsgo_wh/src/D9DW_Rectangle.cpp36
-rwxr-xr-xcsgo_wh/src/D9DW_Text.cpp44
-rwxr-xr-xcsgo_wh/src/DLLMain.cpp78
-rwxr-xr-xcsgo_wh/src/Game.cpp100
-rwxr-xr-xcsgo_wh/src/Hook.cpp72
6 files changed, 449 insertions, 0 deletions
diff --git a/csgo_wh/src/D9DW.cpp b/csgo_wh/src/D9DW.cpp
new file mode 100755
index 0000000..4efd7be
--- /dev/null
+++ b/csgo_wh/src/D9DW.cpp
@@ -0,0 +1,119 @@
+#include "DLLMain.h"
+
+#include <cstdio>
+#include <d3d9.h>
+#include <d3dx9.h>
+#include <stdarg.h>
+#include <windows.h>
+#include <psapi.h>
+#include <commctrl.h>
+
+#include "D9DW.h"
+
+#define MENUCOLOR_DEFAULT D3DCOLOR_ARGB(0xAA, 0x77, 0x00, 0x77)
+#define MENUCOLOR_ACTIVE D3DCOLOR_ARGB(0xAA, 0x11, 0xAA, 0x00)
+#define MENUCOLOR_INACTIVE D3DCOLOR_ARGB(0xAA, 0xAA, 0x11, 0x00)
+
+
+typedef void (__stdcall *keyPressed_t)(D9DW *, Game *, bool);
+struct st_menuEntry
+{
+ bool active;
+ char *name;
+ int id;
+ keyPressed_t callback;
+};
+typedef struct st_menuEntry st_menuEntry;
+
+
+void __stdcall showDebugCB(D9DW *cPtr, Game *game, bool active)
+{
+ UINT32 i;
+ cPtr->pTxt.DrawText(450, 1 , MENUCOLOR_DEFAULT, "%u x %u / %u", game->dwWidth, game->dwHeight, game->dwFov);
+ for (i = 0; i < game->dwPlayerCount; i++)
+ {
+ cPtr->pTxt.DrawText(450, 20+(i*15), MENUCOLOR_DEFAULT, "[%u] [%8.2f,%8.2f,%8.2f]", i, game->g_entities[i].p_pos[0], game->g_entities[i].p_pos[1], game->g_entities[i].p_pos[2]);
+ }
+}
+
+
+static st_menuEntry menuEntries[] = { { false, (char*) "toggle esp", VK_F2, NULL }, { false, (char*) "toggle debug", VK_F3, showDebugCB } };
+static const int bMenuKey = VK_F1;
+static bool bMenu = false;
+
+
+void __stdcall D9DW::doMenu(Game *game, int startx, int starty, int heightpad)
+{
+ size_t idx;
+
+ if (GetKeyState(bMenuKey) &1)
+ {
+ bMenu = !bMenu;
+ }
+ if (bMenu)
+ {
+ this->pTxt.DrawText(startx, starty, MENUCOLOR_INACTIVE, "disable menu");
+ }
+ for (idx = 0; idx < sizeof(menuEntries)/sizeof(menuEntries[0]); idx++)
+ {
+ if (GetKeyState(menuEntries[idx].id) &1)
+ {
+ menuEntries[idx].active = !menuEntries[idx].active;
+ if (menuEntries[idx].callback) menuEntries[idx].callback(this, game, menuEntries[idx].active);
+ }
+ if (bMenu)
+ {
+ DEBUG_LOG("%u: %s", idx, menuEntries[idx].name);
+ this->pTxt.DrawText(startx, starty + ((idx+1)*heightpad), (menuEntries[idx].active ? MENUCOLOR_ACTIVE : MENUCOLOR_INACTIVE), "[%d] - %s", menuEntries[idx].id, menuEntries[idx].name);
+ }
+ }
+}
+
+void __stdcall D9DW::Render(Game* game, bool bActive)
+{
+ if (bActive)
+ {
+ //this->doMenu(game, 5, 300, 12);
+ this->pTxt.DrawText(2, 1 , MENUCOLOR_DEFAULT, "%s %s - [F1 MENU] - %d Player", COPYRIGHT, VERSION, game->dwPlayerCount);
+ }
+ else
+ {
+ this->pTxt.DrawText(2, 1 , MENUCOLOR_DEFAULT, "%s %s - WAITING FOR GAME ...", COPYRIGHT, VERSION, game->dwPlayerCount);
+ }
+}
+
+void D9DW::Create(IDirect3DDevice9 *pDev)
+{
+ this->pDevice = pDev;
+ this->pTxt.Create(pDev);
+ this->pRec.Create(pDev);
+}
+
+void D9DW::Release(void)
+{
+ this->pTxt.Release();
+ this->pRec.Release();
+}
+
+HRESULT D9DW::checkDxDevice(void)
+{
+ return ( D9DW::pDevice->TestCooperativeLevel() );
+}
+
+void D9DW::drawESP(UINT32 idx, ENTITY *ent, FLOAT pos[3])
+{
+}
+
+void D9DW::doESP(Game *game)
+{
+ UINT32 i;
+ FLOAT pos[3];
+
+ for (i = 0; i < game->dwPlayerCount; i++)
+ {
+ pos[0] = game->g_entities[i].p_pos[0] - game->g_localPlayer->p_pos[0];
+ pos[1] = game->g_entities[i].p_pos[1] - game->g_localPlayer->p_pos[1];;
+ pos[2] = game->g_entities[i].p_pos[2] - game->g_localPlayer->p_pos[2];;
+ this->drawESP(i, &game->g_entities[i], pos);
+ }
+}
diff --git a/csgo_wh/src/D9DW_Rectangle.cpp b/csgo_wh/src/D9DW_Rectangle.cpp
new file mode 100755
index 0000000..f9f267d
--- /dev/null
+++ b/csgo_wh/src/D9DW_Rectangle.cpp
@@ -0,0 +1,36 @@
+#include "DLLMain.h"
+#include "D9DW_Rectangle.h"
+
+#include <cstdio>
+#include <d3d9.h>
+#include <d3dx9.h>
+
+
+inline void D9DW_Rectangle::clearoutArea(int x, int y, int width, int height, UINT32 rgb_alpha)
+{
+ D3DRECT rect;
+ rect.x1 = x;
+ rect.x2 = x + width;
+ rect.y1 = y;
+ rect.y2 = y + height;
+ this->pDev->Clear(1, &rect, D3DCLEAR_TARGET, rgb_alpha, 0.0f, 0);
+}
+
+void D9DW_Rectangle::Draw(int x , int y, int width, int height, UINT32 rgb_alpha, bool doFill)
+{
+ D3DXVECTOR2 points[8];
+ points[0] = D3DXVECTOR2(x, y);
+ points[1] = D3DXVECTOR2(x + width, y);
+ points[2] = D3DXVECTOR2(x + width, y);
+ points[3] = D3DXVECTOR2(x + width, y + height);
+ points[4] = D3DXVECTOR2(x + width, y + height);
+ points[5] = D3DXVECTOR2(x, y + height);
+ points[6] = D3DXVECTOR2(x, y + height);
+ points[7] = D3DXVECTOR2(x, y);
+ this->gLine->SetPattern(0xffffffff);
+ this->gLine->SetPatternScale(2.0f);
+ this->gLine->Begin();
+ this->gLine->Draw(points, 8, rgb_alpha);
+ this->gLine->End();
+ D9DW_Rectangle::clearoutArea(x+3, y+3, width-6, height-6, 0x770077AA);
+}
diff --git a/csgo_wh/src/D9DW_Text.cpp b/csgo_wh/src/D9DW_Text.cpp
new file mode 100755
index 0000000..9b2e833
--- /dev/null
+++ b/csgo_wh/src/D9DW_Text.cpp
@@ -0,0 +1,44 @@
+#include "DLLMain.h"
+
+#include <cstdio>
+#include <d3d9.h>
+#include <d3dx9.h>
+
+#include "D9DW_Text.h"
+
+bool D9DW_Text::bInit = false;
+ID3DXFont* D9DW_Text::m_pFont = NULL;
+
+
+void D9DW_Text::Create(IDirect3DDevice9* pDev)
+{
+ if (!bInit)
+ {
+ D3DXCreateFont(pDev, 15, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &m_pFont);
+ bInit = true;
+ }
+}
+
+void D9DW_Text::Release(void)
+{
+ if (bInit)
+ {
+ bInit = false;
+ m_pFont->Release();
+ m_pFont = NULL;
+ }
+}
+
+void D9DW_Text::DrawText(int x, int y, UINT32 rgb_alpha, const char *s_text, va_list p_va)
+{
+ if (!bInit) return;
+ RECT rct;
+ rct.left=x;
+ rct.top=y;
+ rct.right=rct.left+350;
+ rct.bottom=rct.top+350;
+ char logbuf[100] = {0};
+ memset(&logbuf[0], '\0', 100);
+ _vsnprintf(logbuf, sizeof(logbuf), s_text, p_va);
+ m_pFont->DrawTextA(NULL, logbuf, sizeof(logbuf), &rct, 0, rgb_alpha);
+}
diff --git a/csgo_wh/src/DLLMain.cpp b/csgo_wh/src/DLLMain.cpp
new file mode 100755
index 0000000..b9d12cb
--- /dev/null
+++ b/csgo_wh/src/DLLMain.cpp
@@ -0,0 +1,78 @@
+#include "DLLMain.h"
+
+#include <cstdio>
+#include <d3d9.h>
+#include <stdarg.h>
+#include <windows.h>
+#include <psapi.h>
+#include <commctrl.h>
+
+#include "Hook.h"
+#include "D9DW.h"
+#include "Game.h"
+
+#define DXD9DEVICE_OFFSET 0x198298 + 0x44
+
+
+typedef __int32 (__stdcall* EndScene_t)(LPDIRECT3DDEVICE9);
+
+static LPDIRECT3DDEVICE9 pDevice = NULL;
+static bool bActive = true;
+static EndScene_t pEndScene = NULL;
+static D9DW ddraw;
+//static Game game;
+
+
+__int32 __stdcall hkEndScene(LPDIRECT3DDEVICE9 pDevice_t)
+{
+ asm volatile ("nop; nop; nop");
+ int retOrigEndScene = D3D_OK;
+ if(pDevice == NULL)
+ {
+ pDevice = pDevice_t;
+ //DEBUG_LOG("D3D9 Device (%X): %p", (UINT32)((UINT32) game.m_shaderapi.lpBaseOfDll + DXD9DEVICE_OFFSET), pDevice);
+ DEBUG_LOG("EndScene Arg: %p", pDevice_t);
+ DEBUG_FLUSH;
+ ddraw.Create(pDevice);
+ }
+ else
+ {
+ HRESULT c_ret = ddraw.checkDxDevice();
+ if (c_ret == D3D_OK)
+ {
+ //game.ReadCVars();
+ ddraw.Render(/* &game */ NULL, /* game.ReadEntities() */ false);
+ }
+ else pEndScene = NULL;
+ retOrigEndScene = (pEndScene != NULL ? pEndScene(pDevice_t) : D3D_OK);
+ }
+ asm volatile ("nop; nop; nop");
+ return retOrigEndScene;
+}
+
+DWORD WINAPI MainThread(void *arg)
+{
+ //game.Init();
+ Hook::hookEndScene(hkEndScene, &pEndScene, false);
+ while ( bActive )
+ {
+ Sleep(500);
+ if ( GetForegroundWindow() != FindWindow( 0, "Counter-Strike: Global Offensive" ) )
+ {
+ pDevice = NULL;
+ ddraw.Release();
+ }
+ }
+ return 0;
+}
+
+__declspec(dllexport) BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+ if (fdwReason == DLL_PROCESS_ATTACH)
+ {
+ DWORD dwThreadId;
+ DisableThreadLibraryCalls(hinstDLL);
+ CreateThread(NULL, 0, MainThread, NULL, 0, &dwThreadId);
+ }
+ return TRUE; // succesful
+}
diff --git a/csgo_wh/src/Game.cpp b/csgo_wh/src/Game.cpp
new file mode 100755
index 0000000..379fd48
--- /dev/null
+++ b/csgo_wh/src/Game.cpp
@@ -0,0 +1,100 @@
+#include <cstdio>
+#include <stdlib.h>
+#include <math.h>
+
+#include "Game.h"
+
+
+#ifdef ENABLE_DEBUG
+FILE* Game::pLogFile = NULL;
+#endif
+
+
+bool Game::Init(void)
+{
+ DEBUG_INIT;
+ this->init = true;
+ if ( (h_clientDLL = GetModuleHandle("client.dll")) == NULL ) return false;
+ if ( (h_shaderapiDLL = GetModuleHandle("shaderapidx9.dll")) == NULL ) return false;
+ memset(&this->m_client, '\0', sizeof(MODULEINFO));
+ memset(&this->m_shaderapi, '\0', sizeof(MODULEINFO));
+ if (GetModuleInformation(GetCurrentProcess(), h_clientDLL, &this->m_client, sizeof(MODULEINFO)) == TRUE)
+ {
+ DEBUG_LOG("MODINFO(client.dll): 0x%p (%lu)", this->m_client.lpBaseOfDll, this->m_client.SizeOfImage);
+ }
+ else return false;
+ if (GetModuleInformation(GetCurrentProcess(), h_shaderapiDLL, &this->m_shaderapi, sizeof(MODULEINFO)) == TRUE)
+ {
+ DEBUG_LOG("MODINFO(shaderapidx9.dll): 0x%p (%lu)", this->m_shaderapi.lpBaseOfDll, this->m_shaderapi.SizeOfImage);
+ }
+ else return false;
+ return ( true );
+}
+
+bool Game::Reset(void)
+{
+ this->init = false;
+ DEBUG_CLOSE;
+ return (this->Init());
+}
+
+bool Game::ReadEntities(void)
+{
+ UINT32 i;
+ PVOID pLocalPlayer;
+ BYTE bLocalPlayerTeam;
+ bool bLocalPlayerFound = false;
+
+ if (this->init != true) return false;
+ memset(&g_entities, '\0', sizeof(ENTITY)*MAXPLAYER);
+ memset(&g_localPlayer, '\0', sizeof(ENTITY));
+ pLocalPlayer = (PVOID) *(UINT32*)( (UINT32) this->m_client.lpBaseOfDll + (UINT32) OFF_LOCALPLAYER );
+ if ( pLocalPlayer == NULL ) return false;
+ bLocalPlayerTeam = *(BYTE*)( (UINT32) pLocalPlayer + ENTTEAM);
+ if ( bLocalPlayerTeam != TEAM_COUNTER && bLocalPlayerTeam != TEAM_TERROR ) return false;
+ dwPlayerCount = 0;
+ for (i = 0; i < MAXPLAYER; i++)
+ {
+
+ g_entities[i].p_adr = (PVOID) *(UINT32*)( (UINT32) this->m_client.lpBaseOfDll + (UINT32) OFF_ENTITIES + (UINT32) (ENTLOOP * i) );
+ if (g_entities[i].p_adr == NULL)
+ {
+ break;
+ }
+ dwPlayerCount++;
+ }
+ for (i = 0; i < dwPlayerCount; i++)
+ {
+ if (g_entities[i].p_adr != NULL)
+ {
+ g_entities[i].p_pos[0] = *(FLOAT *) ( (UINT32) g_entities[i].p_adr + (UINT32) ENTPOS );
+ g_entities[i].p_pos[1] = *(FLOAT *) ( (UINT32) g_entities[i].p_adr + (UINT32) ENTPOS + 0x4 );
+ g_entities[i].p_pos[2] = *(FLOAT *) ( (UINT32) g_entities[i].p_adr + (UINT32) ENTPOS + 0x8 );
+
+ g_entities[i].p_aim[0] = *(FLOAT *) ( (UINT32) g_entities[i].p_adr + (UINT32) ENTAIMX );
+ g_entities[i].p_aim[1] = *(FLOAT *) ( (UINT32) g_entities[i].p_adr + (UINT32) ENTAIMY );
+ g_entities[i].p_team = *(BYTE *) ( (UINT32) g_entities[i].p_adr + (UINT32) ENTTEAM );
+
+ if (!bLocalPlayerFound && pLocalPlayer == g_entities[i].p_adr)
+ {
+ g_localPlayer = &g_entities[i];
+ bLocalPlayerFound = true;
+ }
+ }
+ else break;
+ }
+
+ return bLocalPlayerFound;
+}
+
+void Game::ReadCVars(void)
+{
+ //dwWidth = *(UINT32*)( (UINT32) this->m_client.lpBaseOfDll + (UINT32) OFF_RESOLUTION );
+ //dwHeight = *(UINT32*)( (UINT32) this->m_client.lpBaseOfDll + (UINT32) OFF_RESOLUTION + 0x4 );
+ //dwFov = *(UINT32*)( (UINT32) this->m_client.lpBaseOfDll + (UINT32) OFF_FOV );
+}
+
+FLOAT Game::calcVecDist(float v1[3], float v2[3])
+{
+ return sqrtf( powf(v1[0] - v2[0], 2.0f) + powf(v1[1] - v2[1], 2.0f) + powf(v1[2] - v2[2], 2.0f) );
+}
diff --git a/csgo_wh/src/Hook.cpp b/csgo_wh/src/Hook.cpp
new file mode 100755
index 0000000..61dc1ca
--- /dev/null
+++ b/csgo_wh/src/Hook.cpp
@@ -0,0 +1,72 @@
+#include <cstdio>
+#include <d3d9.h>
+#include <d3dx9.h>
+#include <stdarg.h>
+#include <windows.h>
+#include <psapi.h>
+#include <commctrl.h>
+
+#include "Hook.h"
+#include "Game.h"
+
+
+bool Hook::hookEndScene(EndScene_t pHookFunc, EndScene_t *pEndScene, bool unhook)
+{
+ HMODULE hm_ddrw = GetModuleHandleA("d3d9.dll");
+ MODULEINFO md_ddrw;
+ LPVOID p_fEndScene;
+
+
+ memset(&md_ddrw, '\0', sizeof(md_ddrw));
+ if (hm_ddrw != NULL && GetModuleInformation(GetCurrentProcess(), hm_ddrw, &md_ddrw, sizeof(md_ddrw)) == TRUE)
+ {
+ DEBUG_LOG("MODINFO(d3d9.dll): 0x%p (%lu)", md_ddrw.lpBaseOfDll, md_ddrw.SizeOfImage);
+ if ( (p_fEndScene = (LPVOID)( (PBYTE)md_ddrw.lpBaseOfDll + ENDSCENE_OFFSET )) != NULL )
+ {
+ DEBUG_LOG("ENDSCENE: 0x%p | HOOK: 0x%p | REL_OFF: %lu", p_fEndScene, pHookFunc, (DWORD)( (DWORD)pHookFunc - (DWORD)p_fEndScene));
+ if (!unhook)
+ {
+ *pEndScene = (EndScene_t) Hook::Detour((PBYTE)p_fEndScene,(PBYTE)pHookFunc);
+ }
+ else
+ {
+ Hook::UnDetour((PBYTE)p_fEndScene);
+ }
+ }
+ else return false;
+ }
+ else return false;
+ return true;
+}
+
+BYTE* Hook::Detour(BYTE *src, const BYTE *dst)
+{
+ BYTE *jmp = (BYTE *) calloc(1, 0x5);
+ DWORD dwback;
+ VirtualProtect(src - 0x5, 0x7, PAGE_READWRITE, &dwback); // important for changing opcodes in the code section
+ jmp[0] = 0xE9; // far jump (32bit offset signed)
+ *(DWORD*)(jmp+1) = (DWORD)(dst - src);
+ memcpy(src - 0x5, jmp, 0x5);
+ src[0] = 0xEB; // short jump (8bit offset signed)
+ src[1] = 0xF9; // two complement -> -0x7
+ VirtualProtect(src - 0x5, 0x7, dwback, &dwback);
+ free(jmp);
+ return (src + 0x2); // return the REAL function addr -> MOV EDI,EDI = 2 bytes
+}
+
+void Hook::UnDetour(BYTE *src)
+{
+ BYTE *jmp = (BYTE *) calloc(1, 0x5);
+ DWORD dwback;
+ VirtualProtect(src - 0x5, 0x7, PAGE_READWRITE, &dwback);
+ src[0] = 0x8B; // MOV opcode
+ src[1] = 0xFF; // operand0: EDI, operand1: EDI
+ jmp[0] = 0x90; // overwrite JMP with NOP-sled
+ jmp[1] = 0x90;
+ jmp[2] = 0x90;
+ jmp[3] = 0x90;
+ jmp[4] = 0x90;
+ memcpy(src - 0x5, jmp, 0x5);
+ VirtualProtect(src - 0x5, 0x7, dwback, &dwback);
+ free(jmp);
+}