Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1.         /*  @'   @+          @;         @@@@@         @@@@@,                  @
  2.             @@  ;@+          @;         @,  @         @'  @,                  @           @
  3.             @@, @@+ +@@@: @@@@; @@@@    @,  @ @; '@   @'  @, @@@@  @@@@ :@@@' @@@@, @@@@:@@@#
  4.             @,@.@#+ ,. ## @  @; @  @    @@@@@ ,@ @:   @'  @, @` @` @  @ +@ :; @, @; @  @' @.
  5.             @ @@:#+ '@@@# @  @; @@@@    @,  @  @ @    @'  @, @  @` @@@@  @@@  @  @; @  @' @.
  6.             @ '@ #+ @. @# @  @; @  .    @,  @  '@     @;  @, @  @` @  . `` +@ @  @; @  @' @.
  7.             @    #+ @@@@# @@@@; @@@@    @@@@@ :@:     @@@@@. @  @. @@@@ '@@@@ @` @; @@@@' @@+ */
  8. #include <Windows.h>
  9. #include "detours.h"
  10. #include "Patternscaning.h"
  11. #include <iostream>
  12.  
  13. #include <d3d9.h>
  14. #include <d3dx9.h>
  15. #pragma comment(lib, "d3d9.lib")
  16. #pragma comment(lib, "d3dx9.lib")
  17.  
  18. #include "../ImGui/imgui.h"
  19. #include "../ImGui/imgui_impl_dx9.h"
  20. #include "../ImGui/imgui_impl_win32.h"
  21.  
  22.  
  23. const char* windowName = "Counter-Strike: Global Offensive";
  24.  
  25. extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  26.  
  27. typedef HRESULT(__stdcall * f_EndScene)(IDirect3DDevice9 * pDevice); // Our function prototype
  28. f_EndScene oEndScene; // Original Endscene
  29.  
  30. typedef LRESULT(CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM);
  31.  
  32. WNDPROC oWndProc;
  33. HRESULT __stdcall Hooked_EndScene(IDirect3DDevice9 * pDevice) // Our hooked endscene
  34. {
  35.     /*D3DRECT BarRect = { 100, 100, 200, 200 };
  36.     pDevice->Clear(1, &BarRect, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 0, 255, 0), 0.0f, 0);*/
  37.  
  38.  
  39.     static bool init = true;
  40.     if (init)
  41.     {
  42.         init = false;
  43.         ImGui::CreateContext();
  44.         ImGuiIO& io = ImGui::GetIO();
  45.        
  46.         ImGui_ImplWin32_Init(FindWindowA(NULL, windowName));
  47.         ImGui_ImplDX9_Init(pDevice);
  48.     }
  49.  
  50.  
  51.     ImGui_ImplDX9_NewFrame();
  52.     ImGui_ImplWin32_NewFrame();
  53.     ImGui::NewFrame();
  54.  
  55.  
  56.     ImGui::Text("Hello, world!");
  57.  
  58.  
  59.     ImGui::EndFrame();
  60.     ImGui::Render();
  61.  
  62.     ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData());
  63.    
  64.     return oEndScene(pDevice); // Call original ensdcene so the game can draw
  65. }
  66.  
  67. LRESULT __stdcall WndProc(const HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
  68.  
  69.     if (true && ImGui_ImplWin32_WndProcHandler(hWnd, uMsg, wParam, lParam))
  70.         return true;
  71.  
  72.     return CallWindowProc(oWndProc, hWnd, uMsg, wParam, lParam);
  73. }
  74.  
  75.  
  76. DWORD WINAPI MainThread(LPVOID param) // Our main thread
  77. {
  78.     HWND  window = FindWindowA(NULL, windowName);
  79.  
  80.     oWndProc = (WNDPROC)SetWindowLongPtr(window, GWLP_WNDPROC, (LONG_PTR)WndProc);
  81.  
  82.     IDirect3D9 * pD3D = Direct3DCreate9(D3D_SDK_VERSION);
  83.  
  84.     if (!pD3D)
  85.         return false;
  86.  
  87.     D3DPRESENT_PARAMETERS d3dpp{ 0 };
  88.     d3dpp.hDeviceWindow = window, d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD , d3dpp.Windowed = TRUE;
  89.    
  90.     IDirect3DDevice9 *Device = nullptr;
  91.     if (FAILED(pD3D->CreateDevice(0, D3DDEVTYPE_HAL, d3dpp.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &Device)))
  92.     {
  93.         pD3D->Release();
  94.         return false;
  95.     }
  96.        
  97.  
  98.     void ** pVTable = *reinterpret_cast<void***>(Device);
  99.  
  100.     if (Device)
  101.         Device->Release() , Device = nullptr;
  102.        
  103.     oEndScene = (f_EndScene)DetourFunction((PBYTE)pVTable[42], (PBYTE)Hooked_EndScene);
  104.    
  105.     return false;
  106. }
  107.  
  108.  
  109. BOOL APIENTRY DllMain(HMODULE hModule,DWORD  ul_reason_for_call,LPVOID lpReserved)
  110. {
  111.     switch (ul_reason_for_call)
  112.     {
  113.     case DLL_PROCESS_ATTACH: // Gets runned when injected
  114.         AllocConsole(); // Enables the console
  115.         freopen("CONIN$", "r", stdin); // Makes it possible to output to output to console with cout.
  116.         freopen("CONOUT$", "w", stdout);
  117.         CreateThread(0, 0, MainThread, hModule, 0, 0); // Creates our thread
  118.         break;
  119.  
  120.     case DLL_THREAD_ATTACH:
  121.     case DLL_THREAD_DETACH:
  122.     case DLL_PROCESS_DETACH:
  123.         break;
  124.     }
  125.     return TRUE;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement