Advertisement
Aeoris2K18

Untitled

Jun 10th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #include "plugin.h"
  2. #include <d3dx8.h>
  3. #include "src/detours.h"
  4. #pragma comment(lib,"d3dx8.lib")
  5. using namespace plugin;
  6. typedef HRESULT(__stdcall* hCreateDevice)
  7. (
  8. IDirect3D8* pDirect3D, // this
  9. UINT Adapter,
  10. D3DDEVTYPE DeviceType,
  11. HWND hFocusWindow,
  12. DWORD BehaviorFlags,
  13. D3DPRESENT_PARAMETERS* pPresentationParameters,
  14. IDirect3DDevice8** ppReturnedDeviceInterface
  15. );
  16. static auto OLD_CreateDevice = (hCreateDevice)nullptr;
  17.  
  18. class d3d8_test {
  19. public:
  20. d3d8_test()
  21. {
  22. if (AllocConsole())
  23. {
  24. freopen("CONIN$", "r", stdin);
  25. freopen("CONOUT$", "w", stdout);
  26. freopen("CONOUT$", "w", stderr);
  27. }
  28. myDevice = nullptr;
  29. if (GetFunctionAddress())
  30. {
  31. HookFunctions();
  32. }
  33. }
  34.  
  35.  
  36. bool GetFunctionAddress()
  37. {
  38. HMODULE lib = GetModuleHandleW(L"d3d8.dll");
  39. if (!lib)
  40. {
  41. lib = LoadLibraryW(L"d3d8.dll");
  42. if (!lib)
  43. {
  44. printf("failed to load d3d8.dll");
  45. return false;
  46. }
  47. }
  48.  
  49. OLD_CreateDevice = (hCreateDevice)GetProcAddress(lib, "CreateDevice");
  50. if (!OLD_CreateDevice)
  51. {
  52. printf("GetProcAddress failed");
  53. return false;
  54. }
  55. return true;
  56. }
  57.  
  58. void HookFunctions()
  59. {
  60. DetourRestoreAfterWith();
  61. DetourTransactionBegin();
  62. DetourUpdateThread(GetCurrentThread());
  63.  
  64. DetourAttach(&(PVOID&)OLD_CreateDevice, NEW_CreateDevice);
  65.  
  66. DetourTransactionCommit();
  67. }
  68.  
  69. static bool NEW_CreateDevice
  70. (
  71. IDirect3D8* pDirect3D, // this
  72. UINT Adapter,
  73. D3DDEVTYPE DeviceType,
  74. HWND hFocusWindow,
  75. DWORD BehaviorFlags,
  76. D3DPRESENT_PARAMETERS* pPresentationParameters,
  77. IDirect3DDevice8** ppReturnedDeviceInterface
  78. )
  79. {
  80. HRESULT hr = OLD_CreateDevice(pDirect3D, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);
  81. if (SUCCEEDED(hr))
  82. {
  83. printf("device created successfully\n");
  84. myDevice = *ppReturnedDeviceInterface;
  85. }
  86. else
  87. {
  88. printf("failed to create device\n");
  89. }
  90. return hr;
  91. }
  92. private:
  93. static IDirect3DDevice8* myDevice;
  94. } _d3d8_test;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement