Advertisement
Guest User

Untitled

a guest
Apr 4th, 2018
1,215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. #include <windows.h>
  2. #include <d3d9.h>
  3. #include <d3dx9.h>
  4. #include <Mmsystem.h>
  5. #include <time.h>
  6. #include <stdio.h>
  7.  
  8. #include <iostream>
  9. #include <string>
  10. #include <sstream>
  11.  
  12. #include "CDetour/CDetour.h"
  13. #include "ImGui/imgui.h"
  14. #include "ImGui/imgui_impl_dx9.h"
  15. #include "ImGui/imgui_internal.h"
  16.  
  17. #pragma comment( lib, "winmm.lib" )
  18. #pragma comment( lib, "d3d9.lib" )
  19. #pragma comment( lib, "d3dx9.lib" )
  20.  
  21. CDetour d3dcreateDetour;
  22. CDetour d3d9endsceneDetour;
  23. CDetour d3d9resetDetour;
  24.  
  25. ID3DXFont *Fonte;
  26. IDirect3DDevice9 *pInterface;
  27. bool CriarComponentes = true;
  28. bool b2 = false;
  29.  
  30. int __stdcall DllMain( HMODULE, DWORD, LPVOID );
  31. void ApplyHooks( int );
  32.  
  33. void __stdcall myCreateDevice( IDirect3D9*, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS* , IDirect3DDevice9 ** );
  34. void __stdcall myEndScene( IDirect3DDevice9* );
  35.  
  36. HRESULT __stdcall myReset( IDirect3DDevice9*, D3DPRESENT_PARAMETERS* );
  37.  
  38. WNDPROC oriWndProc = NULL;
  39.  
  40. extern LRESULT ImGui_ImplDX9_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  41.  
  42.  
  43. bool isImGUiOK = false, testbool;
  44. float testslider;
  45. bool bShowMenu;
  46.  
  47. D3DDEVICE_CREATION_PARAMETERS d3dcp;
  48.  
  49.  
  50.  
  51. LRESULT CALLBACK hWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  52. {
  53.  
  54. if (ImGui_ImplDX9_WndProcHandler(hwnd, uMsg, wParam, lParam) && GetKeyState(VK_INSERT) == 1)
  55. {
  56. return 1l;
  57. }
  58. return CallWindowProc(oriWndProc, hwnd, uMsg, wParam, lParam);
  59. }
  60.  
  61. void MenuRender()
  62. {
  63. if (!bShowMenu)
  64. return;
  65.  
  66. std::cout << "atleast we reach a point" << std::endl;
  67. ImGui_ImplDX9_NewFrame();
  68. if (ImGui::Begin("Test Menu", 0, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_ShowBorders))
  69. {
  70. ImGui::Text("Example");
  71. if (ImGui::Button("Start", ImVec2(50, 25)))
  72. {
  73.  
  74. }
  75. ImGui::SameLine();
  76. ImGui::SliderFloat("Slider", &testslider, 0, 360);
  77.  
  78. ImGui::Checkbox("CheckBox Function", &testbool);
  79. ImGui::End();
  80. }
  81. ImGui::Render();
  82.  
  83. std::cout << "WE GOOD" << std::endl;
  84. }
  85.  
  86. void WriteTextOnScreen( int X, int Y, D3DCOLOR Cor, const char *Texto, ...)
  87. {
  88. RECT Rect; Rect.bottom = Y + 1000; Rect.left = X; Rect.right = X + 1000; Rect.top = Y;
  89.  
  90. char sTexto[256];
  91. va_list vArgumentList;
  92. va_start( vArgumentList, Texto);
  93. _vsnprintf_s( sTexto, sizeof( sTexto), sizeof( sTexto), Texto, vArgumentList );
  94. va_end( vArgumentList );
  95.  
  96. //BORDER BLACK
  97. RECT Rect2 = { X + 1, Y + 1, X + 1, Y + 1 };
  98. Fonte->DrawTextA( NULL, sTexto, -1, &Rect2, DT_NOCLIP, 0xFF000000 );
  99.  
  100. Fonte->DrawTextA( NULL, sTexto, -1, &Rect, 0, Cor );
  101. }
  102.  
  103. void __stdcall myEndScene(LPDIRECT3DDEVICE9 UnidadeD3D9 )
  104. {
  105.  
  106. if( CriarComponentes )
  107. {
  108. D3DXCreateFontA( UnidadeD3D9, 16, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, 6, DEFAULT_PITCH | FF_DONTCARE, "Arial", &Fonte );
  109. CriarComponentes = false;
  110. }
  111.  
  112. if( Fonte )
  113. WriteTextOnScreen( 10, 10, D3DCOLOR_ARGB( 255, 0, 255, 0 ), "Testing D3D9 SRO Hooking !" );
  114.  
  115. if (!isImGUiOK)
  116. {
  117. ImGuiIO& io = ImGui::GetIO();
  118. io.DeltaTime = 1.0f / 60.0f;
  119.  
  120. UnidadeD3D9->GetCreationParameters(&d3dcp);
  121. io.Fonts->AddFontDefault();
  122. if (!ImGui_ImplDX9_Init(&d3dcp, UnidadeD3D9))
  123. std::cout << "here a ba4a" << std::endl;
  124. isImGUiOK = true;
  125.  
  126. }
  127.  
  128. if (GetAsyncKeyState(VK_INSERT) & 1)
  129. {
  130. bShowMenu = !bShowMenu;
  131. }
  132. DWORD dwOld_D3DRS_COLORWRITEENABLE;
  133. UnidadeD3D9->GetRenderState(D3DRS_COLORWRITEENABLE, &dwOld_D3DRS_COLORWRITEENABLE); // Lets us draw without Net_Graph
  134. UnidadeD3D9->SetRenderState(D3DRS_COLORWRITEENABLE, 0xffffffff);
  135.  
  136. MenuRender();
  137.  
  138. UnidadeD3D9->SetRenderState(D3DRS_COLORWRITEENABLE, dwOld_D3DRS_COLORWRITEENABLE);
  139. ImGui::GetIO().MouseDrawCursor = bShowMenu;
  140.  
  141.  
  142. }
  143.  
  144. HRESULT __stdcall myReset( IDirect3DDevice9 *UnidadeD3D9, D3DPRESENT_PARAMETERS* PresentationParameters )
  145. {
  146. __asm pushad
  147.  
  148. if( Fonte ){
  149. Fonte->OnLostDevice();
  150. }
  151.  
  152. HRESULT hRetn = (HRESULT)d3d9resetDetour.Org( UnidadeD3D9, PresentationParameters );
  153.  
  154. if( SUCCEEDED( hRetn ) ){
  155. if(Fonte)
  156. Fonte->OnResetDevice();
  157.  
  158. }
  159.  
  160. __asm popad
  161.  
  162. return hRetn;
  163. }
  164.  
  165. void __stdcall myCreateDevice( IDirect3D9* d3d, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface )
  166. {
  167. d3dcreateDetour.Org( d3d, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface );
  168.  
  169. pInterface = *ppReturnedDeviceInterface;
  170.  
  171. if( !b2 )
  172. ApplyHooks( 2 );
  173. }
  174.  
  175. void ApplyHooks( int nType )
  176. {
  177. if( nType == 1 )
  178. {
  179. unsigned long* pD3DVTable;
  180.  
  181. IDirect3D9* pD3D = Direct3DCreate9( D3D_SDK_VERSION );
  182.  
  183. if( !pD3D ) // INVALID OBJECT
  184. return;
  185.  
  186. pD3DVTable = (unsigned long*)*(unsigned long*)pD3D;
  187. pD3D->Release();
  188.  
  189. // pD3DVTable[16] = IDirect3D9::CreateDevice
  190. d3dcreateDetour.Detour( (unsigned char*)pD3DVTable[16], (unsigned char*)myCreateDevice );
  191. d3dcreateDetour.Apply();
  192. }
  193. else if( nType == 2 )
  194. {
  195. unsigned long* pD3D9VTable;
  196.  
  197. if( !pInterface )
  198. return;
  199.  
  200. pD3D9VTable = (unsigned long*)*(unsigned long*)pInterface;
  201.  
  202. // pD3D9VTable[42] = IDirect3DDevice9::EndScene
  203. d3d9endsceneDetour.Detour( (unsigned char*)pD3D9VTable[42], (unsigned char*)myEndScene, true );
  204. d3d9endsceneDetour.Apply();
  205.  
  206. // pD3D9VTable[16] = IDirect3DDevice9::Reset
  207. d3d9resetDetour.Detour( (unsigned char*)pD3D9VTable[16], (unsigned char*)myReset );
  208. d3d9resetDetour.Apply();
  209.  
  210. b2 = true;
  211. }
  212. }
  213.  
  214. void User_Initialize()
  215. {
  216.  
  217. Sleep(2000);
  218. oriWndProc = (WNDPROC)SetWindowLongPtr(FindWindow(NULL, "SRO_Client"),
  219. GWL_WNDPROC, (LONG)(LONG_PTR)hWndProc);
  220.  
  221. if (oriWndProc == NULL)
  222. std::cout << "Failed to hook wndproc " << std::endl;
  223.  
  224. else
  225. std::cout << "nice hook wndproc " << std::endl;
  226. }
  227.  
  228. int __stdcall DllMain( HMODULE hModule, DWORD dwReason, LPVOID )
  229. {
  230. DisableThreadLibraryCalls( hModule );
  231.  
  232. if( dwReason == DLL_PROCESS_ATTACH )
  233. {
  234. AllocConsole();
  235. freopen("CONIN$", "r", stdin);
  236. freopen("CONOUT$", "w", stdout);
  237. std::cout << "--------------------------------" << std::endl;
  238. std::cout << "Sro Library starting in debug mode" << std::endl;
  239. std::cout << "Compile time " << __DATE__ << " " << __TIME__ << std::endl;
  240. std::cout << "--------------------------------" << std::endl;
  241. std::cout << "New SRO Window TEST Initialized " << std::endl;
  242. std::cout << "--------------------------------" << std::endl;
  243.  
  244. ApplyHooks( 1 );
  245. CreateThread(0, 0, (LPTHREAD_START_ROUTINE)User_Initialize, 0, 0, 0);
  246. }
  247.  
  248. return true;
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement