Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ID3D11Device* t_d3d11dev;
- ID3D11DeviceContext* t_d3d11con;
- int dgVoodooBase;
- extern "C"
- {
- IDirect3D8* WINAPI Direct3DCreate8(UINT SDKVersion);
- IDirect3D8* WINAPI VoodooCreate8(UINT SDKVersion);
- }
- typedef IDirect3D8* (WINAPI* PFN_Direct3DCreate8)
- (
- UINT SDKVersion
- );
- extern PFN_Direct3DCreate8 _Direct3DCreate8 = NULL;
- typedef HRESULT(WINAPI* PFN_CreateDXGIFactory1)
- (
- REFIID riid,
- void** ppFactory
- );
- extern PFN_CreateDXGIFactory1 _CreateDXGIFactory1 = NULL;
- HRESULT WINAPI CallCreateDXGIFactory1(
- const IID &rrid,
- void** ppFactory
- )
- {
- //debug(L"CreateDXGIFactory called.");
- if (_CreateDXGIFactory1 == NULL)
- {
- const HMODULE module = LoadLibrary(TEXT("dxgi.dll"));
- if (module != nullptr)
- {
- _CreateDXGIFactory1 = reinterpret_cast<PFN_CreateDXGIFactory1>(GetProcAddress(module, "CreateDXGIFactory1"));
- if (!_CreateDXGIFactory1)
- return DXGI_ERROR_SDK_COMPONENT_MISSING;
- }
- else
- return DXGI_ERROR_SDK_COMPONENT_MISSING;
- }
- HRESULT res = _CreateDXGIFactory1(rrid, ppFactory);
- if (ppFactory)
- {
- IDXGIFactory1* df = (IDXGIFactory1*)*ppFactory;
- //IDXGIAdapter1* da = NULL;
- //DXGI_ADAPTER_DESC1 ds;
- if (t_dxgi1 == NULL)
- t_dxgi1 = df;
- else
- t_dxgi2 = df;
- /*
- UINT i = 0;
- while (df->EnumAdapters1(i, &da) != DXGI_ERROR_NOT_FOUND)
- {
- da->GetDesc1(&ds);
- da->Release();
- debug(L"Adapter %i (%s) Vendor: %04x", i, ds.Description, ds.VendorId);
- i++;
- }
- debug(L"DXGI = %08X", (unsigned)*ppFactory);*/
- }
- return res;
- }
- typedef HRESULT(WINAPI* PFN_D3D11CreateDevice)
- (
- IDXGIAdapter* pAdapter,
- D3D_DRIVER_TYPE DriverType,
- HMODULE Software,
- UINT Flags,
- const D3D_FEATURE_LEVEL* pFeatureLevels,
- UINT FeatureLevels,
- UINT SDKVersion,
- ID3D11Device** ppDevice,
- D3D_FEATURE_LEVEL* pFeatureLevel,
- ID3D11DeviceContext** ppImmediateContext
- );
- extern PFN_D3D11CreateDevice _D3D11CreateDevice = NULL;
- HRESULT WINAPI CallD3D11CreateDevice(
- IDXGIAdapter* pAdapter,
- D3D_DRIVER_TYPE DriverType,
- HMODULE Software,
- UINT Flags,
- const D3D_FEATURE_LEVEL* pFeatureLevels,
- UINT FeatureLevels,
- UINT SDKVersion,
- ID3D11Device** ppDevice,
- D3D_FEATURE_LEVEL* pFeatureLevel,
- ID3D11DeviceContext** ppImmediateContext
- )
- {
- //debug(L"D3D11CreateDevice called.");
- if (_D3D11CreateDevice == NULL)
- {
- const HMODULE module = LoadLibrary(TEXT("d3d11.dll"));
- if (module != nullptr)
- {
- _D3D11CreateDevice = reinterpret_cast<PFN_D3D11CreateDevice>(GetProcAddress(module, "D3D11CreateDevice"));
- if (!_D3D11CreateDevice)
- return DXGI_ERROR_SDK_COMPONENT_MISSING;
- }
- else
- return DXGI_ERROR_SDK_COMPONENT_MISSING;
- }
- HRESULT res = _D3D11CreateDevice(pAdapter, DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, ppDevice, pFeatureLevel, ppImmediateContext);
- if (ppDevice)
- t_d3d11dev = *ppDevice;
- if (ppImmediateContext)
- t_d3d11con = *ppImmediateContext;
- //debug(L"D3D11Device = %08X, D3D11DeviceContext = %08X", (unsigned)t_d3d11dev, (unsigned)t_d3d11con);
- //debug(L"Feature level = %04x", t_d3d11dev->GetFeatureLevel());
- return res;
- };
- FARPROC __stdcall MyGetProc(
- HMODULE hModule,
- LPCSTR lpProcName
- )
- {
- wchar_t buf[256];
- wchar_t* n;
- FARPROC fp = GetProcAddress(hModule, lpProcName);
- MultiByteToWideChar(CP_UTF8, 0, lpProcName, -1, &buf[0], 255);
- //debug(L"GetProcAddress called for %s (%08X)", buf, (unsigned)fp);
- n = wcsstr(buf, L"3D11CreateDevice");
- if ((n) && (n != buf))
- {
- // hijack D3D11CreateDevice
- return (FARPROC)&CallD3D11CreateDevice;
- }
- n = wcsstr(buf, L"reateDXGIFactory1");
- if ((n) && (n != buf))
- {
- // hijack CreateDXGIFactory1
- return (FARPROC)&CallCreateDXGIFactory1;
- }
- return fp;
- }
- extern "C" IDirect3D8 * WINAPI VoodooCreate8(UINT SDKVersion)
- {
- // Try for the dgVoodoo version first
- // The dgVoodoo offsets are only valid for 2.79.1
- IDirect3D8* d3d = NULL;
- if (!_Direct3DCreate8)
- {
- const HMODULE module = LoadLibrary(TEXT("dgVoodoo_d3d8.dll"));
- if (module != nullptr)
- {
- dgVoodooBase = (int)module;
- //PatchJMP((dgVoodooBase + 0x57c16), (dgVoodooBase + 0x57c1c), (int)&AllowMipMaps);
- *(int*)((unsigned)module + 0x95070) = (int)&MyGetProc;
- _Direct3DCreate8 = reinterpret_cast<PFN_Direct3DCreate8>(GetProcAddress(module, "Direct3DCreate8"));
- if (!_Direct3DCreate8)
- {
- debug(L"Couldn't find dgVoodoo version of Direct3DCreate8!");
- using_D3D11 = 0;
- }
- else
- {
- d3d = _Direct3DCreate8(SDKVersion);
- return d3d;
- }
- }
- }
- __asm {
- push SDKVersion;
- mov eax, 8BEFF2h;
- call eax;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement