diff options
author | Robert <krzmbrzl@gmail.com> | 2020-09-11 19:29:33 +0300 |
---|---|---|
committer | Robert <krzmbrzl@gmail.com> | 2020-09-11 19:29:33 +0300 |
commit | af7dac72f4063dd8d4dac71973ea51c25896089a (patch) | |
tree | 35558695aea94d48fd9e77d164d63fd8b7c76e90 /overlay/d3d10.cpp | |
parent | 40b28b03c150b453e00c6bc4f8d6957caea59c51 (diff) |
FORMAT: Run clang-format 10 on all C/CXX source-files
Diffstat (limited to 'overlay/d3d10.cpp')
-rw-r--r-- | overlay/d3d10.cpp | 342 |
1 files changed, 180 insertions, 162 deletions
diff --git a/overlay/d3d10.cpp b/overlay/d3d10.cpp index 5eb7aedd6..2c487ecbd 100644 --- a/overlay/d3d10.cpp +++ b/overlay/d3d10.cpp @@ -15,11 +15,14 @@ static HardHook hhAddRef; static HardHook hhRelease; typedef HRESULT(__stdcall *CreateDXGIFactoryType)(REFIID, void **); -typedef HRESULT(__stdcall *D3D10CreateDeviceAndSwapChainType)(IDXGIAdapter *, D3D10_DRIVER_TYPE, HMODULE, UINT, UINT, DXGI_SWAP_CHAIN_DESC *, IDXGISwapChain **, ID3D10Device **); +typedef HRESULT(__stdcall *D3D10CreateDeviceAndSwapChainType)(IDXGIAdapter *, D3D10_DRIVER_TYPE, HMODULE, UINT, UINT, + DXGI_SWAP_CHAIN_DESC *, IDXGISwapChain **, + ID3D10Device **); typedef HRESULT(__stdcall *D3D10CreateStateBlockType)(ID3D10Device *, D3D10_STATE_BLOCK_MASK *, ID3D10StateBlock **); typedef HRESULT(__stdcall *D3D10StateBlockMaskEnableAllType)(D3D10_STATE_BLOCK_MASK *); -typedef HRESULT(__stdcall *D3D10CreateEffectFromMemoryType)(void *, SIZE_T, UINT, ID3D10Device *, ID3D10EffectPool *, ID3D10Effect **); +typedef HRESULT(__stdcall *D3D10CreateEffectFromMemoryType)(void *, SIZE_T, UINT, ID3D10Device *, ID3D10EffectPool *, + ID3D10Effect **); typedef ULONG(__stdcall *AddRefType)(ID3D10Device *); typedef ULONG(__stdcall *ReleaseType)(ID3D10Device *); @@ -44,72 +47,72 @@ struct SimpleVertex { SimpleVec2 Tex; }; -class D10State: protected Pipe { - public: - ULONG lHighMark; +class D10State : protected Pipe { +public: + ULONG lHighMark; - LONG initRefCount; - LONG refCount; - LONG myRefCount; + LONG initRefCount; + LONG refCount; + LONG myRefCount; - D3D10_VIEWPORT vp; + D3D10_VIEWPORT vp; - ID3D10Device *pDevice; - IDXGISwapChain *pSwapChain; + ID3D10Device *pDevice; + IDXGISwapChain *pSwapChain; - ID3D10StateBlock *pOrigStateBlock; - ID3D10StateBlock *pMyStateBlock; - ID3D10RenderTargetView *pRTV; - ID3D10Effect *pEffect; - ID3D10EffectTechnique *pTechnique; - ID3D10EffectShaderResourceVariable * pDiffuseTexture; - ID3D10InputLayout *pVertexLayout; - ID3D10Buffer *pVertexBuffer; - ID3D10Buffer *pIndexBuffer; - ID3D10BlendState *pBlendState; + ID3D10StateBlock *pOrigStateBlock; + ID3D10StateBlock *pMyStateBlock; + ID3D10RenderTargetView *pRTV; + ID3D10Effect *pEffect; + ID3D10EffectTechnique *pTechnique; + ID3D10EffectShaderResourceVariable *pDiffuseTexture; + ID3D10InputLayout *pVertexLayout; + ID3D10Buffer *pVertexBuffer; + ID3D10Buffer *pIndexBuffer; + ID3D10BlendState *pBlendState; - ID3D10Texture2D *pTexture; - ID3D10ShaderResourceView *pSRView; + ID3D10Texture2D *pTexture; + ID3D10ShaderResourceView *pSRView; - clock_t timeT; - unsigned int frameCount; + clock_t timeT; + unsigned int frameCount; - D10State(IDXGISwapChain *, ID3D10Device *); - virtual ~D10State(); - bool init(); - void draw(); + D10State(IDXGISwapChain *, ID3D10Device *); + virtual ~D10State(); + bool init(); + void draw(); - virtual void blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h); - virtual void setRect(); - virtual void newTexture(unsigned int w, unsigned int h); + virtual void blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h); + virtual void setRect(); + virtual void newTexture(unsigned int w, unsigned int h); }; -typedef map<IDXGISwapChain *, D10State *> SwapchainMap; +typedef map< IDXGISwapChain *, D10State * > SwapchainMap; SwapchainMap chains; -typedef map<ID3D10Device *, D10State *> DeviceMap; +typedef map< ID3D10Device *, D10State * > DeviceMap; DeviceMap devices; D10State::D10State(IDXGISwapChain *pSwapChain, ID3D10Device *pDevice) { this->pSwapChain = pSwapChain; - this->pDevice = pDevice; + this->pDevice = pDevice; - lHighMark = initRefCount = refCount = myRefCount = 0; + lHighMark = initRefCount = refCount = myRefCount = 0; ZeroMemory(&vp, sizeof(vp)); pOrigStateBlock = nullptr; - pMyStateBlock = nullptr; - pRTV = nullptr; - pEffect = nullptr; - pTechnique = nullptr; + pMyStateBlock = nullptr; + pRTV = nullptr; + pEffect = nullptr; + pTechnique = nullptr; pDiffuseTexture = nullptr; - pVertexLayout = nullptr; - pVertexBuffer = nullptr; - pIndexBuffer = nullptr; - pBlendState = nullptr; - pTexture = nullptr; - pSRView = nullptr; - - timeT = clock(); + pVertexLayout = nullptr; + pVertexBuffer = nullptr; + pIndexBuffer = nullptr; + pBlendState = nullptr; + pTexture = nullptr; + pSRView = nullptr; + + timeT = clock(); frameCount = 0; pDevice->AddRef(); @@ -121,7 +124,7 @@ void D10State::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int ods("D3D10: Blit %d %d %d %d", x, y, w, h); - if (! pTexture || ! pSRView || uiLeft == uiRight) + if (!pTexture || !pSRView || uiLeft == uiRight) return; D3D10_MAPPED_TEXTURE2D mappedTex; @@ -130,11 +133,11 @@ void D10State::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int ods("D3D10: Failed map"); } - UCHAR* pTexels = (UCHAR*)mappedTex.pData; + UCHAR *pTexels = (UCHAR *) mappedTex.pData; - for (unsigned int r=0;r< uiHeight; ++r) { + for (unsigned int r = 0; r < uiHeight; ++r) { unsigned char *sptr = a_ucTexture + r * uiWidth * 4; - unsigned char *dptr = reinterpret_cast<unsigned char *>(pTexels) + r * mappedTex.RowPitch; + unsigned char *dptr = reinterpret_cast< unsigned char * >(pTexels) + r * mappedTex.RowPitch; memcpy(dptr, sptr, uiWidth * 4); } @@ -146,22 +149,22 @@ void D10State::setRect() { ods("D3D10: SetRect"); - float w = static_cast<float>(uiWidth); - float h = static_cast<float>(uiHeight); + float w = static_cast< float >(uiWidth); + float h = static_cast< float >(uiHeight); - float left = static_cast<float>(uiLeft) - 0.5f; - float top = static_cast<float>(uiTop) - 0.5f; - float right = static_cast<float>(uiRight) + 0.5f; - float bottom = static_cast<float>(uiBottom) + 0.5f; + float left = static_cast< float >(uiLeft) - 0.5f; + float top = static_cast< float >(uiTop) - 0.5f; + float right = static_cast< float >(uiRight) + 0.5f; + float bottom = static_cast< float >(uiBottom) + 0.5f; float texl = (left) / w; float text = (top) / h; float texr = (right + 1.0f) / w; float texb = (bottom + 1.0f) / h; - left = 2.0f * (left / vp.Width) - 1.0f; - right = 2.0f * (right / vp.Width) - 1.0f; - top = -2.0f * (top / vp.Height) + 1.0f; + left = 2.0f * (left / vp.Width) - 1.0f; + right = 2.0f * (right / vp.Width) - 1.0f; + top = -2.0f * (top / vp.Height) + 1.0f; bottom = -2.0f * (bottom / vp.Height) + 1.0f; ods("D3D10: Vertex (%f %f) (%f %f)", left, top, right, bottom); @@ -199,15 +202,15 @@ void D10State::newTexture(unsigned int w, unsigned int h) { D3D10_TEXTURE2D_DESC desc; ZeroMemory(&desc, sizeof(desc)); - desc.Width = w; - desc.Height = h; + desc.Width = w; + desc.Height = h; desc.MipLevels = desc.ArraySize = 1; - desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - desc.SampleDesc.Count = 1; - desc.Usage = D3D10_USAGE_DYNAMIC; - desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; - hr = pDevice->CreateTexture2D(&desc, nullptr, &pTexture); + desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + desc.SampleDesc.Count = 1; + desc.Usage = D3D10_USAGE_DYNAMIC; + desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; + hr = pDevice->CreateTexture2D(&desc, nullptr, &pTexture); if (FAILED(hr)) { pTexture = nullptr; @@ -217,10 +220,10 @@ void D10State::newTexture(unsigned int w, unsigned int h) { D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc; ZeroMemory(&srvDesc, sizeof(srvDesc)); - srvDesc.Format = desc.Format; - srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; + srvDesc.Format = desc.Format; + srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MostDetailedMip = 0; - srvDesc.Texture2D.MipLevels = desc.MipLevels; + srvDesc.Texture2D.MipLevels = desc.MipLevels; hr = pDevice->CreateShaderResourceView(pTexture, &srvDesc, &pSRView); if (FAILED(hr)) { @@ -236,7 +239,7 @@ bool D10State::init() { static HMODREF(GetModuleHandleW(L"D3D10.DLL"), D3D10CreateEffectFromMemory); static HMODREF(GetModuleHandleW(L"D3D10.DLL"), D3D10CreateStateBlock); static HMODREF(GetModuleHandleW(L"D3D10.DLL"), D3D10StateBlockMaskEnableAll); - + if (!pD3D10CreateEffectFromMemory || !pD3D10CreateStateBlock || !pD3D10StateBlockMaskEnableAll) { ods("D3D10: Could not get handles for all required D3D10 state initialization functions"); return false; @@ -251,13 +254,13 @@ bool D10State::init() { ods("D3D10: D3D10StateBlockMaskEnableAll failed"); return false; } - + hr = pD3D10CreateStateBlock(pDevice, &StateBlockMask, &pOrigStateBlock); if (FAILED(hr)) { ods("D3D10: D3D10CreateStateBlock for pOrigStateBlock failed"); return false; } - + hr = pD3D10CreateStateBlock(pDevice, &StateBlockMask, &pMyStateBlock); if (FAILED(hr)) { ods("D3D10: D3D10CreateStateBlock for pMyStateBlock failed"); @@ -271,7 +274,7 @@ bool D10State::init() { } ID3D10Texture2D *pBackBuffer = nullptr; - hr = pSwapChain->GetBuffer(0, __uuidof(*pBackBuffer), (LPVOID*)&pBackBuffer); + hr = pSwapChain->GetBuffer(0, __uuidof(*pBackBuffer), (LPVOID *) &pBackBuffer); if (FAILED(hr)) { ods("D3D10: pSwapChain->GetBuffer failure!"); return false; @@ -283,8 +286,8 @@ bool D10State::init() { pBackBuffer->GetDesc(&backBufferSurfaceDesc); ZeroMemory(&vp, sizeof(vp)); - vp.Width = backBufferSurfaceDesc.Width; - vp.Height = backBufferSurfaceDesc.Height; + vp.Width = backBufferSurfaceDesc.Width; + vp.Height = backBufferSurfaceDesc.Height; vp.MinDepth = 0; vp.MaxDepth = 1; vp.TopLeftX = 0; @@ -303,13 +306,13 @@ bool D10State::init() { // https://en.wikipedia.org/w/index.php?title=Alpha_compositing&oldid=580659153#Description D3D10_BLEND_DESC blend; ZeroMemory(&blend, sizeof(blend)); - blend.BlendEnable[0] = TRUE; - blend.SrcBlend = D3D10_BLEND_ONE; - blend.DestBlend = D3D10_BLEND_INV_SRC_ALPHA; - blend.BlendOp = D3D10_BLEND_OP_ADD; - blend.SrcBlendAlpha = D3D10_BLEND_ONE; - blend.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA; - blend.BlendOpAlpha = D3D10_BLEND_OP_ADD; + blend.BlendEnable[0] = TRUE; + blend.SrcBlend = D3D10_BLEND_ONE; + blend.DestBlend = D3D10_BLEND_INV_SRC_ALPHA; + blend.BlendOp = D3D10_BLEND_OP_ADD; + blend.SrcBlendAlpha = D3D10_BLEND_ONE; + blend.DestBlendAlpha = D3D10_BLEND_INV_SRC_ALPHA; + blend.BlendOpAlpha = D3D10_BLEND_OP_ADD; blend.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL; hr = pDevice->CreateBlendState(&blend, &pBlendState); @@ -317,7 +320,7 @@ bool D10State::init() { ods("D3D10: pDevice->CreateBlendState failed!"); return false; } - + pDevice->OMSetBlendState(pBlendState, nullptr, 0xffffffff); hr = pD3D10CreateEffectFromMemory((void *) g_main, sizeof(g_main), 0, pDevice, nullptr, &pEffect); @@ -331,7 +334,7 @@ bool D10State::init() { ods("D3D10: Could not get technique for name 'Render'"); return false; } - + pDiffuseTexture = pEffect->GetVariableByName("txDiffuse")->AsShaderResource(); if (!pDiffuseTexture) { ods("D3D10: Could not get variable by name 'txDiffuse'"); @@ -339,7 +342,7 @@ bool D10State::init() { } pTexture = nullptr; - pSRView = nullptr; + pSRView = nullptr; // Define the input layout D3D10_INPUT_ELEMENT_DESC layout[] = { @@ -355,23 +358,24 @@ bool D10State::init() { ods("D3D10: Couldn't get pass description for technique"); return false; } - - hr = pDevice->CreateInputLayout(layout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, &pVertexLayout); + + hr = pDevice->CreateInputLayout(layout, numElements, PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize, + &pVertexLayout); if (FAILED(hr)) { ods("D3D10: pDevice->CreateInputLayout failure!"); return false; } - + pDevice->IASetInputLayout(pVertexLayout); D3D10_BUFFER_DESC bd; ZeroMemory(&bd, sizeof(bd)); - bd.Usage = D3D10_USAGE_DYNAMIC; - bd.ByteWidth = sizeof(SimpleVertex) * 4; - bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; + bd.Usage = D3D10_USAGE_DYNAMIC; + bd.ByteWidth = sizeof(SimpleVertex) * 4; + bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; - bd.MiscFlags = 0; - + bd.MiscFlags = 0; + hr = pDevice->CreateBuffer(&bd, nullptr, &pVertexBuffer); if (FAILED(hr)) { ods("D3D10: pDevice->CreateBuffer failure!"); @@ -379,19 +383,18 @@ bool D10State::init() { } DWORD indices[] = { - 0,1,3, - 1,2,3, + 0, 1, 3, 1, 2, 3, }; - bd.Usage = D3D10_USAGE_DEFAULT; - bd.ByteWidth = sizeof(DWORD) * 6; - bd.BindFlags = D3D10_BIND_INDEX_BUFFER; + bd.Usage = D3D10_USAGE_DEFAULT; + bd.ByteWidth = sizeof(DWORD) * 6; + bd.BindFlags = D3D10_BIND_INDEX_BUFFER; bd.CPUAccessFlags = 0; - bd.MiscFlags = 0; + bd.MiscFlags = 0; D3D10_SUBRESOURCE_DATA InitData; ZeroMemory(&InitData, sizeof(InitData)); InitData.pSysMem = indices; - + hr = pDevice->CreateBuffer(&bd, &InitData, &pIndexBuffer); if (FAILED(hr)) { ods("D3D10: pDevice->CreateBuffer failure!"); @@ -409,7 +412,7 @@ bool D10State::init() { ods("D3D10: Failed to capture newly created state block"); return false; } - + hr = pOrigStateBlock->Apply(); if (FAILED(hr)) { ods("D3D10: Failed to restore original state block during init"); @@ -422,14 +425,22 @@ bool D10State::init() { } D10State::~D10State() { - if (pBlendState) pBlendState->Release(); - if (pVertexBuffer) pVertexBuffer->Release(); - if (pIndexBuffer) pIndexBuffer->Release(); - if (pVertexLayout) pVertexLayout->Release(); - if (pEffect) pEffect->Release(); - if (pRTV) pRTV->Release(); - if (pTexture) pTexture->Release(); - if (pSRView) pSRView->Release(); + if (pBlendState) + pBlendState->Release(); + if (pVertexBuffer) + pVertexBuffer->Release(); + if (pIndexBuffer) + pIndexBuffer->Release(); + if (pVertexLayout) + pVertexLayout->Release(); + if (pEffect) + pEffect->Release(); + if (pRTV) + pRTV->Release(); + if (pTexture) + pTexture->Release(); + if (pSRView) + pSRView->Release(); if (pMyStateBlock) { pMyStateBlock->ReleaseAllDeviceObjects(); @@ -443,20 +454,20 @@ D10State::~D10State() { } void D10State::draw() { - clock_t t = clock(); - float elapsed = static_cast<float>(t - timeT) / CLOCKS_PER_SEC; + clock_t t = clock(); + float elapsed = static_cast< float >(t - timeT) / CLOCKS_PER_SEC; ++frameCount; if (elapsed > OVERLAY_FPS_INTERVAL) { OverlayMsg om; om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; - om.omh.uiType = OVERLAY_MSGTYPE_FPS; + om.omh.uiType = OVERLAY_MSGTYPE_FPS; om.omh.iLength = sizeof(OverlayMsgFps); - om.omf.fps = frameCount / elapsed; + om.omf.fps = frameCount / elapsed; sendMessage(om); frameCount = 0; - timeT = t; + timeT = t; } checkMessage(vp.Width, vp.Height); @@ -488,12 +499,11 @@ void D10State::draw() { // D3D10 specific logic for the Present function. void presentD3D10(IDXGISwapChain *pSwapChain) { - ID3D10Device *pDevice = nullptr; - HRESULT hr = pSwapChain->GetDevice(__uuidof(ID3D10Device), (void **) &pDevice); + HRESULT hr = pSwapChain->GetDevice(__uuidof(ID3D10Device), (void **) &pDevice); if (SUCCEEDED(hr) && pDevice) { SwapchainMap::iterator it = chains.find(pSwapChain); - D10State *ds = it != chains.end() ? it->second : nullptr; + D10State *ds = it != chains.end() ? it->second : nullptr; if (ds && ds->pDevice != pDevice) { ods("D3D10: SwapChain device changed"); @@ -509,21 +519,20 @@ void presentD3D10(IDXGISwapChain *pSwapChain) { delete ds; return; } - + chains[pSwapChain] = ds; - devices[pDevice] = ds; - + devices[pDevice] = ds; } ds->draw(); pDevice->Release(); } else { - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT // DXGI is used for multiple D3D versions. Thus, it is possible a device // associated with the DXGISwapChain may very well not be a D3D10 one, // in which case we can safely ignore it. ods("D3D10: Could not draw because ID3D10Device could not be retrieved."); - #endif +#endif } } @@ -539,7 +548,7 @@ void resizeD3D10(IDXGISwapChain *pSwapChain) { } static ULONG __stdcall myAddRef(ID3D10Device *pDevice) { - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. AddRefType oAddRef = (AddRefType) hhAddRef.call; hhAddRef.restore(); @@ -556,7 +565,7 @@ static ULONG __stdcall myAddRef(ID3D10Device *pDevice) { } static ULONG __stdcall myRelease(ID3D10Device *pDevice) { - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. ReleaseType oRelease = (ReleaseType) hhRelease.call; hhRelease.restore(); @@ -585,8 +594,8 @@ static ULONG __stdcall myRelease(ID3D10Device *pDevice) { static void HookAddRelease(voidFunc vfAdd, voidFunc vfRelease) { ods("D3D10: Injecting device add/remove"); - hhAddRef.setup(vfAdd, reinterpret_cast<voidFunc>(myAddRef)); - hhRelease.setup(vfRelease, reinterpret_cast<voidFunc>(myRelease)); + hhAddRef.setup(vfAdd, reinterpret_cast< voidFunc >(myAddRef)); + hhRelease.setup(vfRelease, reinterpret_cast< voidFunc >(myRelease)); } static void hookD3D10(HMODULE hD3D10, bool preonly); @@ -607,17 +616,17 @@ void checkDXGI10Hook(bool preonly) { HMODULE hD3D10 = GetModuleHandleW(L"D3D10CORE.DLL"); if (hD3D10) { - if (! bHooked) { + if (!bHooked) { hookD3D10(hD3D10, preonly); } } else { - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT if (hDXGI) { ods("D3D10: No DXGI.DLL found as loaded. No hooking at this point."); } else { ods("D3D10: No D3D10CORE.DLL found as loaded. No hooking at this point."); } - #endif +#endif } bCheckHookActive = false; @@ -625,10 +634,9 @@ void checkDXGI10Hook(bool preonly) { /// @param hD3D10 must be a valid module handle void hookD3D10(HMODULE hD3D10, bool preonly) { - // Add a ref to ourselves; we do NOT want to get unloaded directly from this process. HMODULE hTempSelf = nullptr; - GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCTSTR>(&hookD3D10), &hTempSelf); + GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast< LPCTSTR >(&hookD3D10), &hTempSelf); bHooked = true; @@ -638,7 +646,7 @@ void hookD3D10(HMODULE hD3D10, bool preonly) { if (_wcsicmp(d3d10->wcFileName, modulename) == 0) { unsigned char *raw = (unsigned char *) hD3D10; HookAddRelease((voidFunc)(raw + d3d10->offsetAddRef), (voidFunc)(raw + d3d10->offsetRelease)); - } else if (! preonly) { + } else if (!preonly) { ods("D3D10: Interface changed, can't rawpatch. Current: %ls ; Previously: %ls", modulename, d3d10->wcFileName); } else { bHooked = false; @@ -651,43 +659,42 @@ void hookD3D10(HMODULE hD3D10, bool preonly) { /// /// Adjusts the data behind the global variables dxgi and d3d10. void PrepareDXGI10(IDXGIAdapter1 *pAdapter, bool initializeDXGIData) { - if (!dxgi || !d3d10 || !pAdapter) return; ods("D3D10: Preparing static data for DXGI and D3D10 Injection"); d3d10->wcFileName[0] = 0; - d3d10->offsetAddRef = 0; + d3d10->offsetAddRef = 0; d3d10->offsetRelease = 0; HMODULE hD3D10 = LoadLibrary("D3D10.DLL"); if (hD3D10) { + HWND hwnd = CreateWindowW(L"STATIC", L"Mumble DXGI Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, + 640, 480, 0, nullptr, nullptr, 0); - HWND hwnd = CreateWindowW(L"STATIC", L"Mumble DXGI Window", WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, 0, - nullptr, nullptr, 0); - - D3D10CreateDeviceAndSwapChainType pD3D10CreateDeviceAndSwapChain = reinterpret_cast<D3D10CreateDeviceAndSwapChainType>(GetProcAddress(hD3D10, "D3D10CreateDeviceAndSwapChain")); + D3D10CreateDeviceAndSwapChainType pD3D10CreateDeviceAndSwapChain = + reinterpret_cast< D3D10CreateDeviceAndSwapChainType >( + GetProcAddress(hD3D10, "D3D10CreateDeviceAndSwapChain")); DXGI_SWAP_CHAIN_DESC desc; ZeroMemory(&desc, sizeof(desc)); RECT rcWnd; GetClientRect(hwnd, &rcWnd); - desc.BufferDesc.Width = rcWnd.right - rcWnd.left; + desc.BufferDesc.Width = rcWnd.right - rcWnd.left; desc.BufferDesc.Height = rcWnd.bottom - rcWnd.top; ods("D3D10: Got ClientRect W %d H %d", desc.BufferDesc.Width, desc.BufferDesc.Height); - desc.BufferDesc.RefreshRate.Numerator = 60; + desc.BufferDesc.RefreshRate.Numerator = 60; desc.BufferDesc.RefreshRate.Denominator = 1; - desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; - desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; - desc.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED; + desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; + desc.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED; - desc.SampleDesc.Count = 1; + desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; @@ -701,44 +708,53 @@ void PrepareDXGI10(IDXGIAdapter1 *pAdapter, bool initializeDXGIData) { desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; IDXGISwapChain *pSwapChain = nullptr; - ID3D10Device *pDevice = nullptr; - HRESULT hr = pD3D10CreateDeviceAndSwapChain(pAdapter, D3D10_DRIVER_TYPE_HARDWARE, nullptr, 0, D3D10_SDK_VERSION, &desc, &pSwapChain, &pDevice); + ID3D10Device *pDevice = nullptr; + HRESULT hr = pD3D10CreateDeviceAndSwapChain(pAdapter, D3D10_DRIVER_TYPE_HARDWARE, nullptr, 0, D3D10_SDK_VERSION, + &desc, &pSwapChain, &pDevice); if (FAILED(hr)) ods("D3D10: pD3D10CreateDeviceAndSwapChain failure!"); if (pDevice && pSwapChain) { - - // For VC++ the vtable is located at the base addr. of the object and each function entry is a single pointer. Since p.e. the base classes - // of IDXGISwapChain have a total of 8 functions the 8+Xth entry points to the Xth added function in the derived interface. + // For VC++ the vtable is located at the base addr. of the object and each function entry is a single + // pointer. Since p.e. the base classes of IDXGISwapChain have a total of 8 functions the 8+Xth entry points + // to the Xth added function in the derived interface. void ***vtbl = (void ***) pSwapChain; void *pPresent = (*vtbl)[8]; - boost::optional<size_t> offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pPresent), dxgi->wcFileName, ARRAY_NUM_ELEMENTS(dxgi->wcFileName), "D3D10", "Present"); + boost::optional< size_t > offset = + GetFnOffsetInModule(reinterpret_cast< voidFunc >(pPresent), dxgi->wcFileName, + ARRAY_NUM_ELEMENTS(dxgi->wcFileName), "D3D10", "Present"); if (offset) { if (initializeDXGIData) { dxgi->offsetPresent = *offset; ods("D3D10: Successfully found Present offset: %ls: %d", dxgi->wcFileName, dxgi->offsetPresent); } else { if (dxgi->offsetPresent == *offset) { - ods("D3D10: Successfully verified Present offset: %ls: %d", dxgi->wcFileName, dxgi->offsetPresent); + ods("D3D10: Successfully verified Present offset: %ls: %d", dxgi->wcFileName, + dxgi->offsetPresent); } else { - ods("D3D10: Failed to verify Present offset for %ls. Found %d, but previously found %d.", dxgi->wcFileName, offset, dxgi->offsetPresent); + ods("D3D10: Failed to verify Present offset for %ls. Found %d, but previously found %d.", + dxgi->wcFileName, offset, dxgi->offsetPresent); } } } void *pResize = (*vtbl)[13]; - offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pResize), dxgi->wcFileName, ARRAY_NUM_ELEMENTS(dxgi->wcFileName), "D3D10", "ResizeBuffers"); + offset = GetFnOffsetInModule(reinterpret_cast< voidFunc >(pResize), dxgi->wcFileName, + ARRAY_NUM_ELEMENTS(dxgi->wcFileName), "D3D10", "ResizeBuffers"); if (offset) { if (initializeDXGIData) { dxgi->offsetResize = *offset; - ods("D3D10: Successfully found ResizeBuffers offset: %ls: %d", dxgi->wcFileName, dxgi->offsetResize); + ods("D3D10: Successfully found ResizeBuffers offset: %ls: %d", dxgi->wcFileName, + dxgi->offsetResize); } else { if (dxgi->offsetResize == *offset) { - ods("D3D10: Successfully verified ResizeBuffers offset: %ls: %d", dxgi->wcFileName, dxgi->offsetResize); + ods("D3D10: Successfully verified ResizeBuffers offset: %ls: %d", dxgi->wcFileName, + dxgi->offsetResize); } else { - ods("D3D10: Failed to verify ResizeBuffers offset for %ls. Found %d, but previously found %d.", dxgi->wcFileName, offset, dxgi->offsetResize); + ods("D3D10: Failed to verify ResizeBuffers offset for %ls. Found %d, but previously found %d.", + dxgi->wcFileName, offset, dxgi->offsetResize); } } } @@ -746,14 +762,16 @@ void PrepareDXGI10(IDXGIAdapter1 *pAdapter, bool initializeDXGIData) { vtbl = (void ***) pDevice; void *pAddRef = (*vtbl)[1]; - offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pAddRef), d3d10->wcFileName, ARRAY_NUM_ELEMENTS(d3d10->wcFileName), "D3D10", "AddRef"); + offset = GetFnOffsetInModule(reinterpret_cast< voidFunc >(pAddRef), d3d10->wcFileName, + ARRAY_NUM_ELEMENTS(d3d10->wcFileName), "D3D10", "AddRef"); if (offset) { d3d10->offsetAddRef = *offset; ods("D3D10: Successfully found AddRef offset: %ls: %d", d3d10->wcFileName, d3d10->offsetAddRef); } void *pRelease = (*vtbl)[2]; - offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pRelease), d3d10->wcFileName, ARRAY_NUM_ELEMENTS(d3d10->wcFileName), "D3D10", "Release"); + offset = GetFnOffsetInModule(reinterpret_cast< voidFunc >(pRelease), d3d10->wcFileName, + ARRAY_NUM_ELEMENTS(d3d10->wcFileName), "D3D10", "Release"); if (offset) { d3d10->offsetRelease = *offset; ods("D3D10: Successfully found Release offset: %ls: %d", d3d10->wcFileName, d3d10->offsetRelease); |