├── README.md └── minhook.cpp /README.md: -------------------------------------------------------------------------------- 1 | # Opengl-Hooking-STALCRAFT-X 2 | Opengl Hooking glow esp or player 3 | ![image](https://github.com/user-attachments/assets/b3b60cff-1195-4756-86f0-6133ea4c418c) 4 | ![image](https://github.com/user-attachments/assets/36e078e7-2ee6-4cbb-b756-6146b434578f) 5 | 6 | -------------------------------------------------------------------------------- /minhook.cpp: -------------------------------------------------------------------------------- 1 | #include "pch.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | typedef BOOL(APIENTRY* twglSwapBuffers)(_In_ HDC hDc); 18 | typedef void(APIENTRY* tglDrawElements)(GLenum mode, GLsizei count, GLenum type, const void* indices); 19 | typedef void(APIENTRY* tglUniform4fv)(GLint location, GLsizei count, const GLfloat* value); 20 | typedef void(APIENTRY* tglGetQueryObjectiv)(GLuint id, GLenum pname, GLint* params); 21 | typedef void(APIENTRY* tglGetQueryObjectuiv)(GLuint id, GLenum pname, GLuint* params); 22 | typedef void(APIENTRY* tglUniform4ui)(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3); 23 | typedef PROC(APIENTRY* func_wglGetProcAddress_t)(LPCSTR lpszProc); 24 | 25 | static twglSwapBuffers owglSwapBuffers = nullptr; 26 | static tglDrawElements oglDrawElements = nullptr; 27 | static tglUniform4fv oglUniform4fv = nullptr; 28 | static tglGetQueryObjectiv oglGetQueryObjectiv = nullptr; 29 | static tglGetQueryObjectuiv oglGetQueryObjectuiv = nullptr; 30 | static tglUniform4ui oglUniform4ui = nullptr; 31 | static func_wglGetProcAddress_t owglGetProcAddress = nullptr; 32 | 33 | static tglDrawElements oglDrawElementsHook = nullptr; 34 | static tglUniform4fv oglUniform4fvHook = nullptr; 35 | static tglGetQueryObjectiv oglGetQueryObjectivHook = nullptr; 36 | static tglGetQueryObjectuiv oglGetQueryObjectuivHook = nullptr; 37 | static tglUniform4ui oglUniform4uiHook = nullptr; 38 | 39 | static bool FirstInit = false; 40 | static GLuint greenTexture = 0; 41 | static bool uniform4fvCalled = false; 42 | static bool arta = false; 43 | static bool sat = false; 44 | static bool drawBoxFlag = false; 45 | 46 | void drawBox(); 47 | void chaaamsd(); 48 | 49 | BOOL APIENTRY hwglSwapBuffers(_In_ HDC hDc) { 50 | if (!FirstInit) { 51 | glewExperimental = GL_TRUE; 52 | if (glewInit() != GLEW_OK) { 53 | std::cerr << "GLEW initialization failed!" << std::endl; 54 | } 55 | FirstInit = true; 56 | } 57 | return owglSwapBuffers(hDc); 58 | } 59 | 60 | void drawBox() { 61 | GLfloat depthRange[2]; 62 | glGetFloatv(GL_DEPTH_RANGE, depthRange); 63 | 64 | GLint blendSrc, blendDst; 65 | glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrc); 66 | glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDst); 67 | 68 | GLfloat blendColor[4]; 69 | glGetFloatv(GL_BLEND_COLOR, blendColor); 70 | 71 | GLfloat lineWidth; 72 | glGetFloatv(GL_LINE_WIDTH, &lineWidth); 73 | 74 | GLboolean blendEnabled = glIsEnabled(GL_BLEND); 75 | GLboolean depthTestEnabled = glIsEnabled(GL_DEPTH_TEST); 76 | 77 | glDepthRangef(1, 0.0); 78 | glLineWidth(2.0); 79 | glEnable(GL_BLEND); 80 | glBlendFunc(GL_ONE, GL_CONSTANT_COLOR); 81 | glBlendColor(0.0f, 1.0f, 0.0f, 0.0f); 82 | glDisable(GL_DEPTH_TEST); 83 | glBegin(GL_LINES); 84 | { 85 | glVertex3f(0.1f, -0.1f, 0.1f); 86 | glVertex3f(0.1f, 0.1f, 0.1f); 87 | 88 | glVertex3f(-0.1f, -0.1f, 0.1f); 89 | glVertex3f(0.1f, -0.1f, 0.1f); 90 | 91 | glVertex3f(-0.1f, -0.1f, 0.1f); 92 | glVertex3f(-0.1f, 0.1f, 0.1f); 93 | 94 | glVertex3f(-0.1f, 0.1f, 0.1f); 95 | glVertex3f(0.1f, 0.1f, 0.1f); 96 | 97 | glVertex3f(0.1f, 0.1f, 0.1f); 98 | glVertex3f(0.1f, 0.1f, -0.1f); 99 | 100 | glVertex3f(0.1f, 0.1f, -0.1f); 101 | glVertex3f(0.1f, -0.1f, -0.1f); 102 | 103 | glVertex3f(0.1f, 0.1f, -0.1f); 104 | glVertex3f(-0.1f, 0.1f, -0.1f); 105 | 106 | glVertex3f(-0.1f, 0.1f, -0.1f); 107 | glVertex3f(-0.1f, 0.1f, 0.1f); 108 | 109 | glVertex3f(-0.1f, 0.1f, -0.1f); 110 | glVertex3f(-0.1f, -0.1f, -0.1f); 111 | 112 | glVertex3f(-0.1f, -0.1f, -0.1f); 113 | glVertex3f(0.1f, -0.1f, -0.1f); 114 | 115 | glVertex3f(-0.1f, -0.1f, -0.1f); 116 | glVertex3f(-0.1f, -0.1f, 0.1f); 117 | 118 | glVertex3f(0.1f, -0.1f, -0.1f); 119 | glVertex3f(0.1f, -0.1f, 0.1f); 120 | } 121 | glEnd(); 122 | glDepthRangef(depthRange[0], depthRange[1]); 123 | glBlendFunc(blendSrc, blendDst); 124 | glBlendColor(blendColor[0], blendColor[1], blendColor[2], blendColor[3]); 125 | glLineWidth(lineWidth); 126 | 127 | if (blendEnabled == GL_TRUE) { 128 | glEnable(GL_BLEND); 129 | } 130 | else { 131 | glDisable(GL_BLEND); 132 | } 133 | 134 | if (depthTestEnabled == GL_TRUE) { 135 | glEnable(GL_DEPTH_TEST); 136 | } 137 | else { 138 | glDisable(GL_DEPTH_TEST); 139 | } 140 | } 141 | 142 | void mglGetQueryObjectivHook(GLuint id, GLenum pname, GLint* params) { 143 | oglGetQueryObjectiv(id, pname, params); 144 | } 145 | 146 | void mglGetQueryObjectuivHook(GLuint id, GLenum pname, GLuint* params) { 147 | oglGetQueryObjectuiv(id, pname, params); 148 | if (pname == GL_QUERY_RESULT_AVAILABLE) 149 | *params = GL_TRUE; 150 | else if (pname == GL_QUERY_RESULT) 151 | *params = 1; 152 | } 153 | // 154 | //void chaaamsd() { 155 | // glDisable(GL_DEPTH_TEST); 156 | // arta = true; 157 | // if (greenTexture == 0) { 158 | // glGenTextures(1, &greenTexture); 159 | // glBindTexture(GL_TEXTURE_2D, greenTexture); 160 | // unsigned char greenPixel[] = { 0, 255, 0, 255 }; 161 | // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, greenPixel); 162 | // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 163 | // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 164 | // } 165 | // glBindTexture(GL_TEXTURE_2D, greenTexture); 166 | //} 167 | 168 | void mglUniform4fv(GLint location, GLsizei count, const GLfloat* value) { 169 | if (location == 20) 170 | { 171 | if (count == 8 || count == 6 || count == 4) { 172 | arta = true; 173 | } 174 | } 175 | if (count > 24) 176 | { 177 | if (location == 20 || location == 19 || location == 26 || location == 22 || location == 21) 178 | { 179 | uniform4fvCalled = true; 180 | } 181 | } 182 | if (location == 20) 183 | { 184 | if (count == 1) { 185 | sat = true; 186 | } 187 | } 188 | oglUniform4fv(location, count, value); 189 | } 190 | 191 | void mglUniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3) { 192 | drawBoxFlag = true; 193 | oglUniform4ui(location, v0, v1, v2, v3); 194 | } 195 | 196 | void mglDrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices) { 197 | if (drawBoxFlag && count == 3918) { 198 | drawBox(); 199 | drawBoxFlag = false; 200 | } 201 | 202 | if (sat) { 203 | if (count == 5580) { 204 | GLfloat depthRange[2]; 205 | glGetFloatv(GL_DEPTH_RANGE, depthRange); 206 | 207 | GLint blendSrc, blendDst; 208 | glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrc); 209 | glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDst); 210 | 211 | GLfloat blendColor[4]; 212 | glGetFloatv(GL_BLEND_COLOR, blendColor); 213 | 214 | GLfloat lineWidth; 215 | glGetFloatv(GL_LINE_WIDTH, &lineWidth); 216 | 217 | 218 | GLboolean blendEnabled = glIsEnabled(GL_BLEND); 219 | GLboolean depthTestEnabled = glIsEnabled(GL_DEPTH_TEST); 220 | 221 | oglDrawElements(mode, count, type, indices); 222 | 223 | 224 | glDepthRangef(1, 0); 225 | glLineWidth(3.8); 226 | glEnable(GL_BLEND); 227 | glBlendFunc(GL_CONSTANT_COLOR, GL_CONSTANT_ALPHA); 228 | glBlendColor(0, 0, 0, 1); 229 | 230 | oglDrawElements(GL_TRIANGLES, count, type, indices); 231 | 232 | 233 | glDepthRangef(1, 0.5); 234 | glBlendColor(1, 0, 0, 1); 235 | oglDrawElements(GL_LINES, count, type, indices); 236 | 237 | glDepthRangef(depthRange[0], depthRange[1]); 238 | glBlendFunc(blendSrc, blendDst); 239 | glBlendColor(blendColor[0], blendColor[1], blendColor[2], blendColor[3]); 240 | glLineWidth(lineWidth); 241 | 242 | if (blendEnabled == GL_TRUE) { 243 | glEnable(GL_BLEND); 244 | } 245 | else { 246 | glDisable(GL_BLEND); 247 | } 248 | 249 | if (depthTestEnabled == GL_TRUE) { 250 | glEnable(GL_DEPTH_TEST); 251 | } 252 | else { 253 | glDisable(GL_DEPTH_TEST); 254 | } 255 | } 256 | sat = false; 257 | } 258 | 259 | if (arta) { 260 | if (count == 5580 || count == 1632 || count == 3318 || count == 5364) { 261 | GLfloat depthRange[2]; 262 | glGetFloatv(GL_DEPTH_RANGE, depthRange); 263 | 264 | GLint blendSrc, blendDst; 265 | glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrc); 266 | glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDst); 267 | 268 | GLfloat blendColor[4]; 269 | glGetFloatv(GL_BLEND_COLOR, blendColor); 270 | 271 | GLfloat lineWidth; 272 | glGetFloatv(GL_LINE_WIDTH, &lineWidth); 273 | 274 | 275 | GLboolean blendEnabled = glIsEnabled(GL_BLEND); 276 | GLboolean depthTestEnabled = glIsEnabled(GL_DEPTH_TEST); 277 | 278 | oglDrawElements(mode, count, type, indices); 279 | 280 | glDepthRangef(1, 0); 281 | glLineWidth(3.8); 282 | glEnable(GL_BLEND); 283 | glBlendFunc(GL_CONSTANT_COLOR, GL_CONSTANT_ALPHA); 284 | glBlendColor(0, 0, 0, 1); 285 | 286 | oglDrawElements(GL_TRIANGLES, count, type, indices); 287 | 288 | glDepthRangef(1, 0.5); 289 | glBlendColor(1, 0, 0, 1); 290 | oglDrawElements(GL_LINES, count, type, indices); 291 | 292 | glDepthRangef(depthRange[0], depthRange[1]); 293 | glBlendFunc(blendSrc, blendDst); 294 | glBlendColor(blendColor[0], blendColor[1], blendColor[2], blendColor[3]); 295 | glLineWidth(lineWidth); 296 | 297 | if (blendEnabled == GL_TRUE) { 298 | glEnable(GL_BLEND); 299 | } 300 | else { 301 | glDisable(GL_BLEND); 302 | } 303 | 304 | if (depthTestEnabled == GL_TRUE) { 305 | glEnable(GL_DEPTH_TEST); 306 | } 307 | else { 308 | glDisable(GL_DEPTH_TEST); 309 | } 310 | } 311 | arta = false; 312 | } 313 | 314 | if (uniform4fvCalled && count != 1242 && count != 1308 && count != 402 && count != 13608 && count != 20280 && count != 37410) { 315 | GLfloat depthRange[2]; 316 | glGetFloatv(GL_DEPTH_RANGE, depthRange); 317 | 318 | GLint blendSrc, blendDst; 319 | glGetIntegerv(GL_BLEND_SRC_ALPHA, &blendSrc); 320 | glGetIntegerv(GL_BLEND_DST_ALPHA, &blendDst); 321 | 322 | GLfloat blendColor[4]; 323 | glGetFloatv(GL_BLEND_COLOR, blendColor); 324 | 325 | GLfloat lineWidth; 326 | glGetFloatv(GL_LINE_WIDTH, &lineWidth); 327 | 328 | GLboolean blendEnabled = glIsEnabled(GL_BLEND); 329 | GLboolean depthTestEnabled = glIsEnabled(GL_DEPTH_TEST); 330 | 331 | oglDrawElements(mode, count, type, indices); 332 | 333 | glDepthRangef(1, 0); 334 | glLineWidth(3.8); 335 | glEnable(GL_BLEND); 336 | glBlendFunc(GL_CONSTANT_COLOR, GL_CONSTANT_ALPHA); 337 | glBlendColor(0, 0, 0, 1); 338 | 339 | oglDrawElements(GL_TRIANGLES, count, type, indices); 340 | 341 | glDepthRangef(1, 0.5); 342 | glBlendColor(1, 0, 0, 1); 343 | oglDrawElements(GL_LINES, count, type, indices); 344 | 345 | glDepthRangef(depthRange[0], depthRange[1]); 346 | glBlendFunc(blendSrc, blendDst); 347 | glBlendColor(blendColor[0], blendColor[1], blendColor[2], blendColor[3]); 348 | glLineWidth(lineWidth); 349 | 350 | if (blendEnabled == GL_TRUE) { 351 | glEnable(GL_BLEND); 352 | } 353 | else { 354 | glDisable(GL_BLEND); 355 | } 356 | 357 | if (depthTestEnabled == GL_TRUE) { 358 | glEnable(GL_DEPTH_TEST); 359 | } 360 | else { 361 | glDisable(GL_DEPTH_TEST); 362 | } 363 | uniform4fvCalled = false; 364 | } 365 | else { 366 | oglDrawElements(mode, count, type, indices); 367 | } 368 | } 369 | 370 | PROC APIENTRY hwglGetProcAddress(LPCSTR ProcName) { 371 | HMODULE hMod = GetModuleHandle(L"opengl32.dll"); 372 | 373 | if (!strcmp(ProcName, "glDrawElements")) { 374 | if (!oglDrawElementsHook) { 375 | MH_Initialize(); 376 | oglDrawElementsHook = (tglDrawElements)owglGetProcAddress(ProcName); 377 | if (MH_CreateHook(oglDrawElementsHook, mglDrawElements, (void**)&oglDrawElements) != MH_OK) { 378 | std::cerr << "Failed to create hook for glDrawElements" << std::endl; 379 | } 380 | MH_EnableHook(oglDrawElementsHook); 381 | } 382 | } 383 | else if (!strcmp(ProcName, "glUniform4fv")) { 384 | if (!oglUniform4fvHook) { 385 | MH_Initialize(); 386 | oglUniform4fvHook = (tglUniform4fv)owglGetProcAddress(ProcName); 387 | if (MH_CreateHook(oglUniform4fvHook, mglUniform4fv, (void**)&oglUniform4fv) != MH_OK) { 388 | std::cerr << "Failed to create hook for glUniform4fv" << std::endl; 389 | } 390 | MH_EnableHook(oglUniform4fvHook); 391 | } 392 | } 393 | else if (!strcmp(ProcName, "glUniform4ui")) { 394 | if (!oglUniform4uiHook) { 395 | MH_Initialize(); 396 | oglUniform4uiHook = (tglUniform4ui)owglGetProcAddress(ProcName); 397 | if (MH_CreateHook(oglUniform4uiHook, mglUniform4ui, (void**)&oglUniform4ui) != MH_OK) { 398 | std::cerr << "Failed to create hook for glUniform4ui" << std::endl; 399 | } 400 | MH_EnableHook(oglUniform4uiHook); 401 | } 402 | } 403 | else if (!strcmp(ProcName, "glGetQueryObjectiv")) { 404 | if (!oglGetQueryObjectivHook) { 405 | MH_Initialize(); 406 | oglGetQueryObjectivHook = (tglGetQueryObjectiv)owglGetProcAddress(ProcName); 407 | if (MH_CreateHook(oglGetQueryObjectivHook, mglGetQueryObjectivHook, (void**)&oglGetQueryObjectiv) != MH_OK) { 408 | std::cerr << "Failed to create hook for glGetQueryObjectiv" << std::endl; 409 | } 410 | MH_EnableHook(oglGetQueryObjectivHook); 411 | } 412 | } 413 | else if (!strcmp(ProcName, "glGetQueryObjectuiv")) { 414 | if (!oglGetQueryObjectuivHook) { 415 | MH_Initialize(); 416 | oglGetQueryObjectuivHook = (tglGetQueryObjectuiv)owglGetProcAddress(ProcName); 417 | if (MH_CreateHook(oglGetQueryObjectuivHook, mglGetQueryObjectuivHook, (void**)&oglGetQueryObjectuiv) != MH_OK) { 418 | std::cerr << "Failed to create hook for glGetQueryObjectuiv" << std::endl; 419 | } 420 | MH_EnableHook(oglGetQueryObjectuivHook); 421 | } 422 | } 423 | 424 | return owglGetProcAddress(ProcName); 425 | } 426 | 427 | DWORD WINAPI OpenglInit(__in LPVOID lpParameter) { 428 | while (GetModuleHandle(L"opengl32.dll") == 0) { 429 | Sleep(100); 430 | } 431 | 432 | HMODULE hMod = GetModuleHandle(L"opengl32.dll"); 433 | if (hMod) { 434 | void* ptr = GetProcAddress(hMod, "wglSwapBuffers"); 435 | if (ptr) { 436 | MH_Initialize(); 437 | if (MH_CreateHook(ptr, hwglSwapBuffers, reinterpret_cast(&owglSwapBuffers)) != MH_OK) { 438 | std::cerr << "Failed to create hook for wglSwapBuffers" << std::endl; 439 | } 440 | MH_EnableHook(ptr); 441 | } 442 | else { 443 | std::cerr << "Failed to get wglSwapBuffers address" << std::endl; 444 | return 1; 445 | } 446 | 447 | auto wglGetProcAddressFunc = (func_wglGetProcAddress_t)GetProcAddress(hMod, "wglGetProcAddress"); 448 | if (wglGetProcAddressFunc) 449 | { 450 | if (MH_CreateHook(wglGetProcAddressFunc, hwglGetProcAddress, (void**)&owglGetProcAddress) != MH_OK) 451 | { 452 | std::cerr << "Failed to create hook for wglGetProcAddress" << std::endl; 453 | } 454 | MH_EnableHook(wglGetProcAddressFunc); 455 | } 456 | else { 457 | std::cerr << "Failed to get wglGetProcAddress address" << std::endl; 458 | return 1; 459 | } 460 | } 461 | return 1; 462 | } 463 | 464 | 465 | 466 | BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { 467 | switch (ul_reason_for_call) { 468 | case DLL_PROCESS_ATTACH: 469 | CreateThread(0, 0, LPTHREAD_START_ROUTINE(OpenglInit), hModule, 0, 0); 470 | break; 471 | } 472 | return TRUE; 473 | } 474 | --------------------------------------------------------------------------------