Advertisement
Guest User

Untitled

a guest
Aug 21st, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. ID3D11Device* t_d3d11dev;
  2. ID3D11DeviceContext* t_d3d11con;
  3. int dgVoodooBase;
  4.  
  5. extern "C"
  6. {
  7. IDirect3D8* WINAPI Direct3DCreate8(UINT SDKVersion);
  8. IDirect3D8* WINAPI VoodooCreate8(UINT SDKVersion);
  9. }
  10.  
  11.  
  12. typedef IDirect3D8* (WINAPI* PFN_Direct3DCreate8)
  13. (
  14. UINT SDKVersion
  15. );
  16.  
  17. extern PFN_Direct3DCreate8 _Direct3DCreate8 = NULL;
  18.  
  19. typedef HRESULT(WINAPI* PFN_CreateDXGIFactory1)
  20. (
  21. REFIID riid,
  22. void** ppFactory
  23. );
  24.  
  25. extern PFN_CreateDXGIFactory1 _CreateDXGIFactory1 = NULL;
  26.  
  27. HRESULT WINAPI CallCreateDXGIFactory1(
  28. const IID &rrid,
  29. void** ppFactory
  30. )
  31. {
  32. //debug(L"CreateDXGIFactory called.");
  33.  
  34. if (_CreateDXGIFactory1 == NULL)
  35. {
  36. const HMODULE module = LoadLibrary(TEXT("dxgi.dll"));
  37. if (module != nullptr)
  38. {
  39. _CreateDXGIFactory1 = reinterpret_cast<PFN_CreateDXGIFactory1>(GetProcAddress(module, "CreateDXGIFactory1"));
  40. if (!_CreateDXGIFactory1)
  41. return DXGI_ERROR_SDK_COMPONENT_MISSING;
  42. }
  43. else
  44. return DXGI_ERROR_SDK_COMPONENT_MISSING;
  45. }
  46.  
  47. HRESULT res = _CreateDXGIFactory1(rrid, ppFactory);
  48. if (ppFactory)
  49. {
  50. IDXGIFactory1* df = (IDXGIFactory1*)*ppFactory;
  51. //IDXGIAdapter1* da = NULL;
  52. //DXGI_ADAPTER_DESC1 ds;
  53.  
  54. if (t_dxgi1 == NULL)
  55. t_dxgi1 = df;
  56. else
  57. t_dxgi2 = df;
  58.  
  59. /*
  60. UINT i = 0;
  61.  
  62. while (df->EnumAdapters1(i, &da) != DXGI_ERROR_NOT_FOUND)
  63. {
  64. da->GetDesc1(&ds);
  65. da->Release();
  66. debug(L"Adapter %i (%s) Vendor: %04x", i, ds.Description, ds.VendorId);
  67. i++;
  68. }
  69.  
  70. debug(L"DXGI = %08X", (unsigned)*ppFactory);*/
  71. }
  72.  
  73. return res;
  74. }
  75.  
  76. typedef HRESULT(WINAPI* PFN_D3D11CreateDevice)
  77. (
  78. IDXGIAdapter* pAdapter,
  79. D3D_DRIVER_TYPE DriverType,
  80. HMODULE Software,
  81. UINT Flags,
  82. const D3D_FEATURE_LEVEL* pFeatureLevels,
  83. UINT FeatureLevels,
  84. UINT SDKVersion,
  85. ID3D11Device** ppDevice,
  86. D3D_FEATURE_LEVEL* pFeatureLevel,
  87. ID3D11DeviceContext** ppImmediateContext
  88. );
  89.  
  90. extern PFN_D3D11CreateDevice _D3D11CreateDevice = NULL;
  91.  
  92. HRESULT WINAPI CallD3D11CreateDevice(
  93. IDXGIAdapter* pAdapter,
  94. D3D_DRIVER_TYPE DriverType,
  95. HMODULE Software,
  96. UINT Flags,
  97. const D3D_FEATURE_LEVEL* pFeatureLevels,
  98. UINT FeatureLevels,
  99. UINT SDKVersion,
  100. ID3D11Device** ppDevice,
  101. D3D_FEATURE_LEVEL* pFeatureLevel,
  102. ID3D11DeviceContext** ppImmediateContext
  103. )
  104. {
  105. //debug(L"D3D11CreateDevice called.");
  106.  
  107. if (_D3D11CreateDevice == NULL)
  108. {
  109. const HMODULE module = LoadLibrary(TEXT("d3d11.dll"));
  110.  
  111. if (module != nullptr)
  112. {
  113. _D3D11CreateDevice = reinterpret_cast<PFN_D3D11CreateDevice>(GetProcAddress(module, "D3D11CreateDevice"));
  114. if (!_D3D11CreateDevice)
  115. return DXGI_ERROR_SDK_COMPONENT_MISSING;
  116. }
  117. else
  118. return DXGI_ERROR_SDK_COMPONENT_MISSING;
  119. }
  120.  
  121. HRESULT res = _D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext);
  122.  
  123. if (ppDevice)
  124. t_d3d11dev = *ppDevice;
  125.  
  126. if (ppImmediateContext)
  127. t_d3d11con = *ppImmediateContext;
  128.  
  129. //debug(L"D3D11Device = %08X, D3D11DeviceContext = %08X", (unsigned)t_d3d11dev, (unsigned)t_d3d11con);
  130. //debug(L"Feature level = %04x", t_d3d11dev->GetFeatureLevel());
  131.  
  132. return res;
  133. };
  134.  
  135. FARPROC __stdcall MyGetProc(
  136. HMODULE hModule,
  137. LPCSTR lpProcName
  138. )
  139. {
  140. wchar_t buf[256];
  141. wchar_t* n;
  142.  
  143. FARPROC fp = GetProcAddress(hModule, lpProcName);
  144. MultiByteToWideChar(CP_UTF8, 0, lpProcName, -1, &buf[0], 255);
  145. //debug(L"GetProcAddress called for %s (%08X)", buf, (unsigned)fp);
  146. n = wcsstr(buf, L"3D11CreateDevice");
  147. if ((n) && (n != buf))
  148. {
  149. // hijack D3D11CreateDevice
  150. return (FARPROC)&CallD3D11CreateDevice;
  151. }
  152. n = wcsstr(buf, L"reateDXGIFactory1");
  153. if ((n) && (n != buf))
  154. {
  155. // hijack CreateDXGIFactory1
  156. return (FARPROC)&CallCreateDXGIFactory1;
  157. }
  158. return fp;
  159. }
  160.  
  161. extern "C" IDirect3D8 * WINAPI VoodooCreate8(UINT SDKVersion)
  162. {
  163. // Try for the dgVoodoo version first
  164. // The dgVoodoo offsets are only valid for 2.79.1
  165.  
  166. IDirect3D8* d3d = NULL;
  167.  
  168. if (!_Direct3DCreate8)
  169. {
  170. const HMODULE module = LoadLibrary(TEXT("dgVoodoo_d3d8.dll"));
  171.  
  172. if (module != nullptr)
  173. {
  174. dgVoodooBase = (int)module;
  175. //PatchJMP((dgVoodooBase + 0x57c16), (dgVoodooBase + 0x57c1c), (int)&AllowMipMaps);
  176. *(int*)((unsigned)module + 0x95070) = (int)&MyGetProc;
  177. _Direct3DCreate8 = reinterpret_cast<PFN_Direct3DCreate8>(GetProcAddress(module, "Direct3DCreate8"));
  178. if (!_Direct3DCreate8)
  179. {
  180. debug(L"Couldn't find dgVoodoo version of Direct3DCreate8!");
  181. using_D3D11 = 0;
  182. }
  183. else
  184. {
  185. d3d = _Direct3DCreate8(SDKVersion);
  186. return d3d;
  187. }
  188. }
  189. }
  190.  
  191. __asm {
  192. push SDKVersion;
  193. mov eax, 8BEFF2h;
  194. call eax;
  195. }
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement