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 | |
parent | 40b28b03c150b453e00c6bc4f8d6957caea59c51 (diff) |
FORMAT: Run clang-format 10 on all C/CXX source-files
Diffstat (limited to 'overlay')
-rw-r--r-- | overlay/D11StateBlock.cpp | 49 | ||||
-rw-r--r-- | overlay/D11StateBlock.h | 60 | ||||
-rw-r--r-- | overlay/HardHook.cpp | 4 | ||||
-rw-r--r-- | overlay/HardHook.h | 4 | ||||
-rw-r--r-- | overlay/HardHook_minhook.cpp | 30 | ||||
-rw-r--r-- | overlay/HardHook_minhook.h | 14 | ||||
-rw-r--r-- | overlay/HardHook_x86.cpp | 94 | ||||
-rw-r--r-- | overlay/HardHook_x86.h | 12 | ||||
-rw-r--r-- | overlay/ancestor.cpp | 19 | ||||
-rw-r--r-- | overlay/ancestor.h | 5 | ||||
-rw-r--r-- | overlay/d3d10.cpp | 342 | ||||
-rw-r--r-- | overlay/d3d11.cpp | 344 | ||||
-rw-r--r-- | overlay/d3d9.cpp | 503 | ||||
-rw-r--r-- | overlay/dxgi.cpp | 56 | ||||
-rw-r--r-- | overlay/excludecheck.cpp | 53 | ||||
-rw-r--r-- | overlay/lib.cpp | 275 | ||||
-rw-r--r-- | overlay/lib.h | 94 | ||||
-rw-r--r-- | overlay/ods.cpp | 6 | ||||
-rw-r--r-- | overlay/olsettings.cpp | 97 | ||||
-rw-r--r-- | overlay/olsettings.h | 8 | ||||
-rw-r--r-- | overlay/opengl.cpp | 156 | ||||
-rw-r--r-- | overlay/overlay_blacklist.h | 78 | ||||
-rw-r--r-- | overlay/overlay_exe/overlay_exe.cpp | 31 | ||||
-rw-r--r-- | overlay/overlay_exe/overlay_exe.h | 30 | ||||
-rw-r--r-- | overlay/overlay_launchers.h | 20 | ||||
-rw-r--r-- | overlay/overlay_whitelist.h | 3 | ||||
-rw-r--r-- | overlay/util.h | 18 |
27 files changed, 1224 insertions, 1181 deletions
diff --git a/overlay/D11StateBlock.cpp b/overlay/D11StateBlock.cpp index ca1bfea9a..f1acb91e4 100644 --- a/overlay/D11StateBlock.cpp +++ b/overlay/D11StateBlock.cpp @@ -13,13 +13,13 @@ are met: - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. - Neither the name of the Mumble Developers nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -36,23 +36,20 @@ #include "D11StateBlock.h" -void D11CreateStateBlock(ID3D11DeviceContext *pDeviceContext, D11StateBlock **ppStateBlock) -{ +void D11CreateStateBlock(ID3D11DeviceContext *pDeviceContext, D11StateBlock **ppStateBlock) { *ppStateBlock = new D11StateBlock(pDeviceContext); } D11StateBlock::D11StateBlock(ID3D11DeviceContext *pDC) - : pRasterizerState(0), uiSampleMask(0) - , Format(DXGI_FORMAT_UNKNOWN), Topology(D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED) - , pBlendState(0), pIndexBuffer(0), pInputLayout(0), uiOffset(0) - , pDepthStencilView(0) { + : pRasterizerState(0), uiSampleMask(0), Format(DXGI_FORMAT_UNKNOWN), Topology(D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED), + pBlendState(0), pIndexBuffer(0), pInputLayout(0), uiOffset(0), pDepthStencilView(0) { uiNumViewports = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ZeroMemory(pViewports, sizeof(pViewports)); - ZeroMemory(pRenderTargetViews, sizeof (pRenderTargetViews)); - ZeroMemory(fBlendFactor, sizeof (fBlendFactor)); - ZeroMemory(pVertexBuffers, sizeof (pVertexBuffers)); - ZeroMemory(uiStrides, sizeof (uiStrides)); - ZeroMemory(uiOffsets, sizeof (uiOffsets)); + ZeroMemory(pRenderTargetViews, sizeof(pRenderTargetViews)); + ZeroMemory(fBlendFactor, sizeof(fBlendFactor)); + ZeroMemory(pVertexBuffers, sizeof(pVertexBuffers)); + ZeroMemory(uiStrides, sizeof(uiStrides)); + ZeroMemory(uiOffsets, sizeof(uiOffsets)); pDeviceContext = pDC; pDeviceContext->AddRef(); @@ -63,8 +60,7 @@ D11StateBlock::~D11StateBlock() { pDeviceContext->Release(); } -void D11StateBlock::Capture() -{ +void D11StateBlock::Capture() { // Release potential references to make sure we have no leaks. ReleaseObjects(); @@ -76,11 +72,11 @@ void D11StateBlock::Capture() pDeviceContext->IAGetInputLayout(&pInputLayout); pDeviceContext->IAGetIndexBuffer(&pIndexBuffer, &Format, &uiOffset); pDeviceContext->IAGetPrimitiveTopology(&Topology); - pDeviceContext->IAGetVertexBuffers(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, pVertexBuffers, uiStrides, uiOffsets); + pDeviceContext->IAGetVertexBuffers(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, pVertexBuffers, uiStrides, + uiOffsets); } -void D11StateBlock::Apply() -{ +void D11StateBlock::Apply() { pDeviceContext->RSSetState(pRasterizerState); pDeviceContext->RSSetViewports(uiNumViewports, pViewports); pDeviceContext->OMSetRenderTargets(D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, pRenderTargetViews, pDepthStencilView); @@ -88,19 +84,19 @@ void D11StateBlock::Apply() pDeviceContext->IASetInputLayout(pInputLayout); pDeviceContext->IASetIndexBuffer(pIndexBuffer, Format, uiOffset); pDeviceContext->IASetPrimitiveTopology(Topology); - pDeviceContext->IASetVertexBuffers(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, pVertexBuffers, uiStrides, uiOffsets); + pDeviceContext->IASetVertexBuffers(0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, pVertexBuffers, uiStrides, + uiOffsets); ReleaseObjects(); } /// Release state information -void D11StateBlock::ReleaseObjects() -{ +void D11StateBlock::ReleaseObjects() { if (pRasterizerState) { pRasterizerState->Release(); pRasterizerState = nullptr; } - for (int i=0; i<D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++) + for (int i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++) if (pRenderTargetViews[i]) { pRenderTargetViews[i]->Release(); pRenderTargetViews[i] = nullptr; @@ -127,10 +123,9 @@ void D11StateBlock::ReleaseObjects() pIndexBuffer = nullptr; } - for (int i=0; i<D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++) + for (int i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; i++) if (pVertexBuffers[i]) { pVertexBuffers[i]->Release(); pVertexBuffers[i] = nullptr; } - } diff --git a/overlay/D11StateBlock.h b/overlay/D11StateBlock.h index 54397ee24..b1a59cf52 100644 --- a/overlay/D11StateBlock.h +++ b/overlay/D11StateBlock.h @@ -13,13 +13,13 @@ are met: - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. - Neither the name of the Mumble Developers nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -46,40 +46,40 @@ class D11StateBlock; void D11CreateStateBlock(ID3D11DeviceContext *, D11StateBlock **); class D11StateBlock { - public: - D11StateBlock(ID3D11DeviceContext *); - ~D11StateBlock(); +public: + D11StateBlock(ID3D11DeviceContext *); + ~D11StateBlock(); - void Capture(); - void Apply(); - void ReleaseObjects(); - void ReleaseAllDeviceObjects(); + void Capture(); + void Apply(); + void ReleaseObjects(); + void ReleaseAllDeviceObjects(); - private: - ID3D11DeviceContext *pDeviceContext; +private: + ID3D11DeviceContext *pDeviceContext; - ID3D11RasterizerState *pRasterizerState; - UINT uiNumViewports; - D3D11_VIEWPORT pViewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; + ID3D11RasterizerState *pRasterizerState; + UINT uiNumViewports; + D3D11_VIEWPORT pViewports[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE]; - ID3D11RenderTargetView *pRenderTargetViews[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; - ID3D11DepthStencilView *pDepthStencilView; + ID3D11RenderTargetView *pRenderTargetViews[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT]; + ID3D11DepthStencilView *pDepthStencilView; - ID3D11BlendState *pBlendState; - float fBlendFactor[4]; - UINT32 uiSampleMask; + ID3D11BlendState *pBlendState; + float fBlendFactor[4]; + UINT32 uiSampleMask; - ID3D11InputLayout *pInputLayout; + ID3D11InputLayout *pInputLayout; - ID3D11Buffer *pIndexBuffer; - DXGI_FORMAT Format; - UINT uiOffset; + ID3D11Buffer *pIndexBuffer; + DXGI_FORMAT Format; + UINT uiOffset; - D3D11_PRIMITIVE_TOPOLOGY Topology; + D3D11_PRIMITIVE_TOPOLOGY Topology; - ID3D11Buffer *pVertexBuffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; - UINT uiStrides[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; - UINT uiOffsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; + ID3D11Buffer *pVertexBuffers[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; + UINT uiStrides[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; + UINT uiOffsets[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT]; }; #endif /* !D11STATEBLOCK_H_ */ diff --git a/overlay/HardHook.cpp b/overlay/HardHook.cpp index 19da263a6..6c14ae611 100644 --- a/overlay/HardHook.cpp +++ b/overlay/HardHook.cpp @@ -4,7 +4,7 @@ // Mumble source tree or at <https://www.mumble.info/LICENSE>.
#ifdef USE_MINHOOK
-# include "HardHook_minhook.cpp"
+# include "HardHook_minhook.cpp"
#else
-# include "HardHook_x86.cpp"
+# include "HardHook_x86.cpp"
#endif
diff --git a/overlay/HardHook.h b/overlay/HardHook.h index bec64de23..9a18cb9ef 100644 --- a/overlay/HardHook.h +++ b/overlay/HardHook.h @@ -7,9 +7,9 @@ #define MUMBLE_HARDHOOK_H_
#ifdef USE_MINHOOK
-# include "HardHook_minhook.h"
+# include "HardHook_minhook.h"
#else
-# include "HardHook_x86.h"
+# include "HardHook_x86.h"
#endif
#endif
diff --git a/overlay/HardHook_minhook.cpp b/overlay/HardHook_minhook.cpp index bd0bb2afe..1b9b52d68 100644 --- a/overlay/HardHook_minhook.cpp +++ b/overlay/HardHook_minhook.cpp @@ -26,10 +26,7 @@ static void EnsureMinHookInitialized() { /** * @brief Constructs a new hook without actually injecting. */ -HardHook::HardHook() - : m_func(nullptr) - , m_replacement(nullptr) - , call(nullptr) { +HardHook::HardHook() : m_func(nullptr), m_replacement(nullptr), call(nullptr) { EnsureMinHookInitialized(); } @@ -39,10 +36,7 @@ HardHook::HardHook() * @param func Funktion to inject replacement into. * @param replacement Function to inject into func. */ -HardHook::HardHook(voidFunc func, voidFunc replacement) - : m_func(nullptr) - , m_replacement(nullptr) - , call(nullptr) { +HardHook::HardHook(voidFunc func, voidFunc replacement) : m_func(nullptr), m_replacement(nullptr), call(nullptr) { EnsureMinHookInitialized(); setup(func, replacement); @@ -57,10 +51,10 @@ HardHook::HardHook(voidFunc func, voidFunc replacement) * @param replacement Pointer to code to redirect to. */ void HardHook::setup(voidFunc func, voidFunc replacement) { - m_func = func; + m_func = func; m_replacement = replacement; - MH_STATUS status = MH_CreateHook((LPVOID) func, (LPVOID)replacement, (LPVOID *)&call); + MH_STATUS status = MH_CreateHook((LPVOID) func, (LPVOID) replacement, (LPVOID *) &call); if (status != MH_OK) { fods("HardHook: setup failed, MH_CreateHook returned %s", MH_StatusToString(status)); } @@ -70,15 +64,15 @@ void HardHook::setup(voidFunc func, voidFunc replacement) { void HardHook::setupInterface(IUnknown *unkn, LONG funcoffset, voidFunc replacement) { fods("HardHook: setupInterface: Replacing %p function #%ld", unkn, funcoffset); - void **ptr = reinterpret_cast<void **>(unkn); - ptr = reinterpret_cast<void **>(ptr[0]); - setup(reinterpret_cast<voidFunc>(ptr[funcoffset]), replacement); + void **ptr = reinterpret_cast< void ** >(unkn); + ptr = reinterpret_cast< void ** >(ptr[0]); + setup(reinterpret_cast< voidFunc >(ptr[funcoffset]), replacement); } void HardHook::reset() { - m_func = nullptr; + m_func = nullptr; m_replacement = nullptr; - call = nullptr; + call = nullptr; } /** @@ -94,7 +88,7 @@ void HardHook::inject(bool force) { return; } - MH_STATUS status = MH_EnableHook((LPVOID)m_func); + MH_STATUS status = MH_EnableHook((LPVOID) m_func); if (status != MH_OK) { fods("HardHook: inject() failed: MH_EnableHook returned %s", MH_StatusToString(status)); } @@ -113,7 +107,7 @@ void HardHook::restore(bool force) { return; } - MH_STATUS status = MH_DisableHook((LPVOID)m_func); + MH_STATUS status = MH_DisableHook((LPVOID) m_func); if (status != MH_OK) { fods("HardHook: restore() failed: MH_DisableHook returned %s", MH_StatusToString(status)); } @@ -127,5 +121,5 @@ void HardHook::print() { * @brief No-op in MinHook-based HardHook implementation. */ void HardHook::check() { - fods("HardHook: unused 'check' method called for MinHook-based HardHook"); + fods("HardHook: unused 'check' method called for MinHook-based HardHook"); } diff --git a/overlay/HardHook_minhook.h b/overlay/HardHook_minhook.h index 22880434c..105940976 100644 --- a/overlay/HardHook_minhook.h +++ b/overlay/HardHook_minhook.h @@ -6,13 +6,13 @@ #ifndef MUMBLE_HARDHOOK_MINHOOK_H_ #define MUMBLE_HARDHOOK_MINHOOK_H_ -#include <stdio.h> -#include <stdarg.h> -#include <ctype.h> #include <cmath> +#include <ctype.h> #include <map> -#include <vector> +#include <stdarg.h> +#include <stdio.h> #include <string> +#include <vector> #include <windows.h> #include <unknwn.h> @@ -20,9 +20,9 @@ typedef void *(*voidFunc)(); struct HardHook { - voidFunc m_func; - voidFunc m_replacement; - voidFunc call; + voidFunc m_func; + voidFunc m_replacement; + voidFunc call; HardHook(); HardHook(voidFunc func, voidFunc replacement); diff --git a/overlay/HardHook_x86.cpp b/overlay/HardHook_x86.cpp index 7c16ba54f..79cc469eb 100644 --- a/overlay/HardHook_x86.cpp +++ b/overlay/HardHook_x86.cpp @@ -6,7 +6,7 @@ #include "HardHook.h"
#include "ods.h"
-void *HardHook::pCode = nullptr;
+void *HardHook::pCode = nullptr;
unsigned int HardHook::uiCode = 0;
const int HardHook::CODEREPLACESIZE = 6;
@@ -20,8 +20,8 @@ HardHook::HardHook() : bTrampoline(false), call(0), baseptr(nullptr) { orig[i] = replace[i] = 0;
}
-// assert(CODEREPLACESIZE == sizeof(orig) / sizeof(orig[0]));
-// assert(CODEREPLACESIZE == sizeof(replace) / sizeof(replace[0]));
+ // assert(CODEREPLACESIZE == sizeof(orig) / sizeof(orig[0]));
+ // assert(CODEREPLACESIZE == sizeof(replace) / sizeof(replace[0]));
}
/**
@@ -30,8 +30,7 @@ HardHook::HardHook() : bTrampoline(false), call(0), baseptr(nullptr) { * @param func Funktion to inject replacement into.
* @param replacement Function to inject into func.
*/
-HardHook::HardHook(voidFunc func, voidFunc replacement)
- : bTrampoline(false), call(0), baseptr(nullptr) {
+HardHook::HardHook(voidFunc func, voidFunc replacement) : bTrampoline(false), call(0), baseptr(nullptr) {
for (int i = 0; i < CODEREPLACESIZE; ++i)
orig[i] = replace[i] = 0;
setup(func, replacement);
@@ -95,13 +94,12 @@ static unsigned int modrmbytes(unsigned char a, unsigned char b) { * @return Pointer to trampoline on success. nullptr if trampoline construction failed.
*/
void *HardHook::cloneCode(void **porig) {
-
- if (! pCode || uiCode > 4000) {
- pCode = VirtualAlloc(nullptr, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
+ if (!pCode || uiCode > 4000) {
+ pCode = VirtualAlloc(nullptr, 4096, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
uiCode = 0;
}
// If we have no memory to clone to, return.
- if (! pCode) {
+ if (!pCode) {
return nullptr;
}
@@ -118,7 +116,7 @@ void *HardHook::cloneCode(void **porig) { // end of the chain. Hence these jumps need not be part of the trampoline.
while (*o == 0xe9) { // JMP
unsigned char *tmp = o;
- int *iptr = reinterpret_cast<int *>(o+1);
+ int *iptr = reinterpret_cast< int * >(o + 1);
o += *iptr + 5;
fods("HardHook: CloneCode: Skipping jump from %p to %p", *porig, o);
@@ -139,9 +137,9 @@ void *HardHook::cloneCode(void **porig) { do {
unsigned char opcode = o[idx];
- unsigned char a = o[idx+1];
- unsigned char b = o[idx+2];
- unsigned int extra = 0;
+ unsigned char a = o[idx + 1];
+ unsigned char b = o[idx + 2];
+ unsigned int extra = 0;
switch (opcode) {
case 0x50: // PUSH
@@ -168,23 +166,24 @@ void *HardHook::cloneCode(void **porig) { extra = 4;
break;
case 0x81: // CMP immediate
- extra = modrmbytes(a,b) + 5;
+ extra = modrmbytes(a, b) + 5;
break;
- case 0x83: // CMP
- extra = modrmbytes(a,b) + 2;
+ case 0x83: // CMP
+ extra = modrmbytes(a, b) + 2;
break;
- case 0x8b: // MOV
- extra = modrmbytes(a,b) + 1;
+ case 0x8b: // MOV
+ extra = modrmbytes(a, b) + 1;
break;
default: {
- int rmop = ((a>>3) & 7);
+ int rmop = ((a >> 3) & 7);
if (opcode == 0xff && rmop == 6) { // PUSH memory
- extra = modrmbytes(a,b) + 1;
+ extra = modrmbytes(a, b) + 1;
break;
}
- fods("HardHook: CloneCode failed; Unknown opcode %02x at %d: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
- opcode, idx, o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], o[11]);
+ fods("HardHook: CloneCode failed; Unknown opcode %02x at %d: %02x %02x %02x %02x %02x %02x %02x %02x "
+ "%02x %02x %02x %02x",
+ opcode, idx, o[0], o[1], o[2], o[3], o[4], o[5], o[6], o[7], o[8], o[9], o[10], o[11]);
DWORD tempProtect;
VirtualProtect(o, CODEPROTECTSIZE, origProtect, &tempProtect);
return nullptr;
@@ -196,7 +195,7 @@ void *HardHook::cloneCode(void **porig) { ++idx;
for (unsigned int i = 0; i < extra; ++i)
- n[idx+i] = o[idx+i];
+ n[idx + i] = o[idx + i];
idx += extra;
} while (idx < CODEREPLACESIZE);
@@ -205,11 +204,11 @@ void *HardHook::cloneCode(void **porig) { VirtualProtect(o, CODEPROTECTSIZE, origProtect, &tempProtect);
// Add a relative jmp back to the original code, to after the copied code
- n[idx++] = 0xe9;
- int *iptr = reinterpret_cast<int *>(&n[idx]);
+ n[idx++] = 0xe9;
+ int *iptr = reinterpret_cast< int * >(&n[idx]);
const int JMP_OP_SIZE = 5;
- int offs = o - n - JMP_OP_SIZE;
- *iptr = offs;
+ int offs = o - n - JMP_OP_SIZE;
+ *iptr = offs;
idx += 4;
uiCode += idx;
@@ -237,8 +236,8 @@ void HardHook::setup(voidFunc func, voidFunc replacement) { fods("HardHook: Setup: Asked to replace %p with %p", func, replacement);
- unsigned char *fptr = reinterpret_cast<unsigned char *>(func);
- unsigned char *nptr = reinterpret_cast<unsigned char *>(replacement);
+ unsigned char *fptr = reinterpret_cast< unsigned char * >(func);
+ unsigned char *nptr = reinterpret_cast< unsigned char * >(replacement);
call = (voidFunc) cloneCode((void **) &fptr);
@@ -249,15 +248,15 @@ void HardHook::setup(voidFunc func, voidFunc replacement) { // This alternative method is dependant on the replacement code
// restoring before calling the original. Otherwise we get a jump recursion
bTrampoline = false;
- call = func;
+ call = func;
}
DWORD origProtect;
if (VirtualProtect(fptr, CODEPROTECTSIZE, PAGE_EXECUTE_READ, &origProtect)) {
- replace[0] = 0x68; // PUSH immediate 1 Byte
- unsigned char **iptr = reinterpret_cast<unsigned char **>(&replace[1]);
- *iptr = nptr; // (imm. value = nptr) 4 Byte
- replace[5] = 0xc3; // RETN 1 Byte
+ replace[0] = 0x68; // PUSH immediate 1 Byte
+ unsigned char **iptr = reinterpret_cast< unsigned char ** >(&replace[1]);
+ *iptr = nptr; // (imm. value = nptr) 4 Byte
+ replace[5] = 0xc3; // RETN 1 Byte
// Save original 6 bytes at start of original function
for (int i = 0; i < CODEREPLACESIZE; ++i)
@@ -276,15 +275,15 @@ void HardHook::setup(voidFunc func, voidFunc replacement) { void HardHook::setupInterface(IUnknown *unkn, LONG funcoffset, voidFunc replacement) {
fods("HardHook: setupInterface: Replacing %p function #%ld", unkn, funcoffset);
- void **ptr = reinterpret_cast<void **>(unkn);
- ptr = reinterpret_cast<void **>(ptr[0]);
- setup(reinterpret_cast<voidFunc>(ptr[funcoffset]), replacement);
+ void **ptr = reinterpret_cast< void ** >(unkn);
+ ptr = reinterpret_cast< void ** >(ptr[0]);
+ setup(reinterpret_cast< voidFunc >(ptr[funcoffset]), replacement);
}
void HardHook::reset() {
- baseptr = 0;
+ baseptr = 0;
bTrampoline = false;
- call = nullptr;
+ call = nullptr;
for (int i = 0; i < CODEREPLACESIZE; ++i) {
orig[i] = replace[i] = 0;
}
@@ -301,9 +300,9 @@ void HardHook::reset() { * @param force Perform injection even when trampoline is available.
*/
void HardHook::inject(bool force) {
- if (! baseptr)
+ if (!baseptr)
return;
- if (! force && bTrampoline)
+ if (!force && bTrampoline)
return;
DWORD origProtect;
@@ -337,10 +336,9 @@ void HardHook::inject(bool force) { * @param force If true injection will be reverted even when trampoline is available.
*/
void HardHook::restore(bool force) {
-
- if (! baseptr)
+ if (!baseptr)
return;
- if (! force && bTrampoline)
+ if (!force && bTrampoline)
return;
DWORD origProtect;
@@ -355,10 +353,10 @@ void HardHook::restore(bool force) { }
void HardHook::print() {
- fods("HardHook: code replacement: %02x %02x %02x %02x %02x => %02x %02x %02x %02x %02x (currently effective: %02x %02x %02x %02x %02x)",
- orig[0], orig[1], orig[2], orig[3], orig[4],
- replace[0], replace[1], replace[2], replace[3], replace[4],
- baseptr[0], baseptr[1], baseptr[2], baseptr[3], baseptr[4]);
+ fods("HardHook: code replacement: %02x %02x %02x %02x %02x => %02x %02x %02x %02x %02x (currently effective: %02x "
+ "%02x %02x %02x %02x)",
+ orig[0], orig[1], orig[2], orig[3], orig[4], replace[0], replace[1], replace[2], replace[3], replace[4],
+ baseptr[0], baseptr[1], baseptr[2], baseptr[3], baseptr[4]);
}
/**
diff --git a/overlay/HardHook_x86.h b/overlay/HardHook_x86.h index 6d369e193..356803e55 100644 --- a/overlay/HardHook_x86.h +++ b/overlay/HardHook_x86.h @@ -8,17 +8,17 @@ #define _UNICODE
#ifndef _WIN32_WINNT
-#define _WIN32_WINNT 0x0501
+# define _WIN32_WINNT 0x0501
#endif
-#include <stdio.h>
-#include <stdarg.h>
-#include <ctype.h>
#include <windows.h>
-#include <unknwn.h>
#include <cmath>
+#include <ctype.h>
#include <map>
-#include <vector>
+#include <stdarg.h>
+#include <stdio.h>
#include <string>
+#include <unknwn.h>
+#include <vector>
typedef void *(*voidFunc)();
diff --git a/overlay/ancestor.cpp b/overlay/ancestor.cpp index 404a9639c..a858224ab 100644 --- a/overlay/ancestor.cpp +++ b/overlay/ancestor.cpp @@ -16,8 +16,8 @@ /// Returns false on failure, and does not touch |parent|. static bool findParentProcessForChild(DWORD childpid, PROCESSENTRY32 *parent) { DWORD parentpid = 0; - HANDLE hSnap = nullptr; - bool done = false; + HANDLE hSnap = nullptr; + bool done = false; PROCESSENTRY32 pe; pe.dwSize = sizeof(pe); @@ -60,7 +60,7 @@ static bool findParentProcessForChild(DWORD childpid, PROCESSENTRY32 *parent) { while (ok) { if (pe.th32ProcessID == parentpid) { memcpy(parent, &pe, sizeof(pe)); - ok = FALSE; + ok = FALSE; done = true; break; } @@ -79,7 +79,7 @@ static bool findParentProcessForChild(DWORD childpid, PROCESSENTRY32 *parent) { /// Returns false on failure, and does not touch |module|. static bool getModuleForParent(PROCESSENTRY32 *parent, MODULEENTRY32 *module) { HANDLE hSnap = nullptr; - bool done = false; + bool done = false; MODULEENTRY32 me; me.dwSize = sizeof(me); @@ -101,14 +101,15 @@ out: return done; } -bool GetProcessAncestorChain(std::vector<std::string> &absAncestorExeNames, std::vector<std::string> &ancestorExeNames) { +bool GetProcessAncestorChain(std::vector< std::string > &absAncestorExeNames, + std::vector< std::string > &ancestorExeNames) { PROCESSENTRY32 parent; MODULEENTRY32 module; - std::vector<std::string> abs; - std::vector<std::string> rel; + std::vector< std::string > abs; + std::vector< std::string > rel; - bool ok = true; + bool ok = true; DWORD childpid = GetCurrentProcessId(); while (ok) { ok = findParentProcessForChild(childpid, &parent); @@ -125,7 +126,7 @@ bool GetProcessAncestorChain(std::vector<std::string> &absAncestorExeNames, std: ok = abs.size() > 0; if (ok) { absAncestorExeNames = abs; - ancestorExeNames = rel; + ancestorExeNames = rel; } return ok; diff --git a/overlay/ancestor.h b/overlay/ancestor.h index 736143ba7..a1a387f64 100644 --- a/overlay/ancestor.h +++ b/overlay/ancestor.h @@ -6,14 +6,15 @@ #ifndef MUMBLE_ANCESTOR_H_ #define MUMBLE_ANCESTOR_H_ -#include <vector> #include <string> +#include <vector> /// Return the absolute and relative exe names of this process's ancestors in /// |absAncestorExeNames| and |ancestorExeNames|. /// /// Returns true on success and fills out |absAncestorExeNames| and |ancestorExeNames|. /// Returns false on failure, and does not change |absAncestorExeNames| and |ancestorExeNames|. -bool GetProcessAncestorChain(std::vector<std::string> &absAncestorExeNames, std::vector<std::string> &ancestorExeNames); +bool GetProcessAncestorChain(std::vector< std::string > &absAncestorExeNames, + std::vector< std::string > &ancestorExeNames); #endif 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); diff --git a/overlay/d3d11.cpp b/overlay/d3d11.cpp index 89453565e..67cf347b0 100644 --- a/overlay/d3d11.cpp +++ b/overlay/d3d11.cpp @@ -14,13 +14,13 @@ are met: - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. - Neither the name of the Mumble Developers nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -35,10 +35,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include "lib.h" #include "D11StateBlock.h" -#include "overlay11.vs.h" +#include "lib.h" #include "overlay11.ps.h" +#include "overlay11.vs.h" #include <d3d11.h> #include <time.h> @@ -49,7 +49,11 @@ static HardHook hhAddRef; static HardHook hhRelease; typedef HRESULT(__stdcall *CreateDXGIFactory1Type)(REFIID, void **); -typedef HRESULT(__stdcall *D3D11CreateDeviceAndSwapChainType)(IDXGIAdapter *, D3D_DRIVER_TYPE, HMODULE Software, UINT Flags, const D3D_FEATURE_LEVEL *, UINT, UINT, const DXGI_SWAP_CHAIN_DESC *, IDXGISwapChain **, ID3D11Device **, D3D_FEATURE_LEVEL *, ID3D11DeviceContext **); +typedef HRESULT(__stdcall *D3D11CreateDeviceAndSwapChainType)(IDXGIAdapter *, D3D_DRIVER_TYPE, HMODULE Software, + UINT Flags, const D3D_FEATURE_LEVEL *, UINT, UINT, + const DXGI_SWAP_CHAIN_DESC *, IDXGISwapChain **, + ID3D11Device **, D3D_FEATURE_LEVEL *, + ID3D11DeviceContext **); typedef ULONG(__stdcall *AddRefType)(ID3D11Device *); typedef ULONG(__stdcall *ReleaseType)(ID3D11Device *); @@ -74,75 +78,74 @@ struct SimpleVertex { static const int VERTEXBUFFER_SIZE = 4 * sizeof(SimpleVertex); -class D11State: protected Pipe { - public: - ULONG lHighMark; - - LONG initRefCount; - LONG refCount; - LONG myRefCount; - - D3D11_VIEWPORT vp; - - ID3D11Device *pDevice; - ID3D11DeviceContext *pDeviceContext; - bool bDeferredContext; - IDXGISwapChain *pSwapChain; - - D11StateBlock *pOrigStateBlock; - D11StateBlock *pMyStateBlock; - ID3D11RenderTargetView *pRTV; - ID3D11VertexShader *pVertexShader; - ID3D11PixelShader *pPixelShader; - ID3D11InputLayout *pVertexLayout; - ID3D11Buffer *pVertexBuffer; - ID3D11Buffer *pIndexBuffer; - ID3D11BlendState *pBlendState; - - ID3D11Texture2D *pTexture; - ID3D11ShaderResourceView *pSRView; - - clock_t timeT; - unsigned int frameCount; - - D11State(IDXGISwapChain *, ID3D11Device *); - virtual ~D11State(); - 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); +class D11State : protected Pipe { +public: + ULONG lHighMark; + + LONG initRefCount; + LONG refCount; + LONG myRefCount; + + D3D11_VIEWPORT vp; + + ID3D11Device *pDevice; + ID3D11DeviceContext *pDeviceContext; + bool bDeferredContext; + IDXGISwapChain *pSwapChain; + + D11StateBlock *pOrigStateBlock; + D11StateBlock *pMyStateBlock; + ID3D11RenderTargetView *pRTV; + ID3D11VertexShader *pVertexShader; + ID3D11PixelShader *pPixelShader; + ID3D11InputLayout *pVertexLayout; + ID3D11Buffer *pVertexBuffer; + ID3D11Buffer *pIndexBuffer; + ID3D11BlendState *pBlendState; + + ID3D11Texture2D *pTexture; + ID3D11ShaderResourceView *pSRView; + + clock_t timeT; + unsigned int frameCount; + + D11State(IDXGISwapChain *, ID3D11Device *); + virtual ~D11State(); + 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); }; -typedef map<IDXGISwapChain *, D11State *> SwapchainMap; +typedef map< IDXGISwapChain *, D11State * > SwapchainMap; SwapchainMap chains; -typedef map<ID3D11Device *, D11State *> DeviceMap; +typedef map< ID3D11Device *, D11State * > DeviceMap; DeviceMap devices; -D11State::D11State(IDXGISwapChain *pSwapChain, ID3D11Device *pDevice) - : bDeferredContext(false) { +D11State::D11State(IDXGISwapChain *pSwapChain, ID3D11Device *pDevice) : bDeferredContext(false) { 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; - pVertexShader = nullptr; - pPixelShader = nullptr; - pVertexLayout = nullptr; - pVertexBuffer = nullptr; - pIndexBuffer = nullptr; - pBlendState = nullptr; - pTexture = nullptr; - pSRView = nullptr; - pDeviceContext = nullptr; - - timeT = clock(); + pMyStateBlock = nullptr; + pRTV = nullptr; + pVertexShader = nullptr; + pPixelShader = nullptr; + pVertexLayout = nullptr; + pVertexBuffer = nullptr; + pIndexBuffer = nullptr; + pBlendState = nullptr; + pTexture = nullptr; + pSRView = nullptr; + pDeviceContext = nullptr; + + timeT = clock(); frameCount = 0; pDevice->AddRef(); @@ -154,7 +157,7 @@ void D11State::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int ods("D3D11: Blit %d %d %d %d", x, y, w, h); - if (! pTexture || ! pSRView || uiLeft == uiRight) + if (!pTexture || !pSRView || uiLeft == uiRight) return; D3D11_MAPPED_SUBRESOURCE mappedTex; @@ -163,11 +166,11 @@ void D11State::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int ods("D3D11: 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); } @@ -179,22 +182,22 @@ void D11State::setRect() { ods("D3D11: 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("D3D11: Vertex (%f %f) (%f %f)", left, top, right, bottom); @@ -212,7 +215,8 @@ void D11State::setRect() { hr = pDeviceContext->Map(pVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &res); const int verticesSize = sizeof(vertices); - static_assert(verticesSize == VERTEXBUFFER_SIZE, "The vertex buffer size differs from the locally created vertex buffer."); + static_assert(verticesSize == VERTEXBUFFER_SIZE, + "The vertex buffer size differs from the locally created vertex buffer."); memcpy(res.pData, vertices, verticesSize); ods("D3D11: Map: %lx %d", hr, sizeof(vertices)); pDeviceContext->Unmap(pVertexBuffer, 0); @@ -235,15 +239,15 @@ void D11State::newTexture(unsigned int w, unsigned int h) { D3D11_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 = D3D11_USAGE_DYNAMIC; - desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - hr = pDevice->CreateTexture2D(&desc, nullptr, &pTexture); + desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + desc.SampleDesc.Count = 1; + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + hr = pDevice->CreateTexture2D(&desc, nullptr, &pTexture); if (FAILED(hr)) { pTexture = nullptr; @@ -253,10 +257,10 @@ void D11State::newTexture(unsigned int w, unsigned int h) { D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; ZeroMemory(&srvDesc, sizeof(srvDesc)); - srvDesc.Format = desc.Format; - srvDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srvDesc.Format = desc.Format; + srvDesc.ViewDimension = D3D11_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)) { @@ -271,8 +275,8 @@ void D11State::newTexture(unsigned int w, unsigned int h) { bool D11State::init() { HRESULT hr; - ID3D11Texture2D* pBackBuffer = nullptr; - hr = pSwapChain->GetBuffer(0, __uuidof(*pBackBuffer), (LPVOID*)&pBackBuffer); + ID3D11Texture2D *pBackBuffer = nullptr; + hr = pSwapChain->GetBuffer(0, __uuidof(*pBackBuffer), (LPVOID *) &pBackBuffer); if (FAILED(hr)) { ods("D3D11: pSwapChain->GetBuffer failure!"); return false; @@ -300,8 +304,8 @@ bool D11State::init() { pBackBuffer->GetDesc(&backBufferSurfaceDesc); ZeroMemory(&vp, sizeof(vp)); - vp.Width = static_cast<float>(backBufferSurfaceDesc.Width); - vp.Height = static_cast<float>(backBufferSurfaceDesc.Height); + vp.Width = static_cast< float >(backBufferSurfaceDesc.Width); + vp.Height = static_cast< float >(backBufferSurfaceDesc.Height); vp.MinDepth = 0; vp.MaxDepth = 1; vp.TopLeftX = 0; @@ -320,13 +324,13 @@ bool D11State::init() { // https://en.wikipedia.org/w/index.php?title=Alpha_compositing&oldid=580659153#Description D3D11_BLEND_DESC blend; ZeroMemory(&blend, sizeof(blend)); - blend.RenderTarget[0].BlendEnable = TRUE; - blend.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; - blend.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - blend.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - blend.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - blend.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - blend.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + blend.RenderTarget[0].BlendEnable = TRUE; + blend.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE; + blend.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; + blend.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; + blend.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; + blend.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + blend.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; blend.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; pDevice->CreateBlendState(&blend, &pBlendState); @@ -350,7 +354,7 @@ bool D11State::init() { } pTexture = nullptr; - pSRView = nullptr; + pSRView = nullptr; // Define the input layout D3D11_INPUT_ELEMENT_DESC layout[] = { @@ -358,7 +362,8 @@ bool D11State::init() { { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; - hr = pDevice->CreateInputLayout(layout, ARRAY_NUM_ELEMENTS(layout), g_vertex_shader, sizeof(g_vertex_shader), &pVertexLayout); + hr = pDevice->CreateInputLayout(layout, ARRAY_NUM_ELEMENTS(layout), g_vertex_shader, sizeof(g_vertex_shader), + &pVertexLayout); if (FAILED(hr)) { ods("D3D11: pDevice->CreateInputLayout failure!"); return false; @@ -368,11 +373,11 @@ bool D11State::init() { D3D11_BUFFER_DESC bd; ZeroMemory(&bd, sizeof(bd)); - bd.Usage = D3D11_USAGE_DYNAMIC; - bd.ByteWidth = VERTEXBUFFER_SIZE; - bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; + bd.Usage = D3D11_USAGE_DYNAMIC; + bd.ByteWidth = VERTEXBUFFER_SIZE; + bd.BindFlags = D3D11_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - bd.MiscFlags = 0; + bd.MiscFlags = 0; hr = pDevice->CreateBuffer(&bd, nullptr, &pVertexBuffer); if (FAILED(hr)) { @@ -381,16 +386,15 @@ bool D11State::init() { } DWORD indices[] = { - 0,1,3, - 1,2,3, + 0, 1, 3, 1, 2, 3, }; ZeroMemory(&bd, sizeof(bd)); - bd.Usage = D3D11_USAGE_IMMUTABLE; - bd.ByteWidth = sizeof(DWORD) * 6; - bd.BindFlags = D3D11_BIND_INDEX_BUFFER; + bd.Usage = D3D11_USAGE_IMMUTABLE; + bd.ByteWidth = sizeof(DWORD) * 6; + bd.BindFlags = D3D11_BIND_INDEX_BUFFER; bd.CPUAccessFlags = 0; - bd.MiscFlags = 0; + bd.MiscFlags = 0; D3D11_SUBRESOURCE_DATA InitData; ZeroMemory(&InitData, sizeof(InitData)); InitData.pSysMem = indices; @@ -447,23 +451,23 @@ D11State::~D11State() { } void D11State::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(static_cast<unsigned int>(vp.Width), static_cast<unsigned int>(vp.Height)); + checkMessage(static_cast< unsigned int >(vp.Width), static_cast< unsigned int >(vp.Height)); if (a_ucTexture && pSRView && (uiLeft != uiRight)) { if (!bDeferredContext) { @@ -501,12 +505,11 @@ void D11State::draw() { // D3D11 specific logic for the Present function. extern void presentD3D11(IDXGISwapChain *pSwapChain) { - ID3D11Device *pDevice = nullptr; - HRESULT hr = pSwapChain->GetDevice(__uuidof(ID3D11Device), (void **) &pDevice); + HRESULT hr = pSwapChain->GetDevice(__uuidof(ID3D11Device), (void **) &pDevice); if (SUCCEEDED(hr) && pDevice) { SwapchainMap::iterator it = chains.find(pSwapChain); - D11State *ds = it != chains.end() ? it->second : nullptr; + D11State *ds = it != chains.end() ? it->second : nullptr; if (ds && ds->pDevice != pDevice) { ods("D3D11: SwapChain device changed"); devices.erase(ds->pDevice); @@ -523,17 +526,17 @@ extern void presentD3D11(IDXGISwapChain *pSwapChain) { } 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, this is expected if // another version is used (like D3D10). ods("D3D11: Could not draw because ID3D11Device could not be retrieved."); - #endif +#endif } } @@ -549,7 +552,7 @@ extern void resizeD3D11(IDXGISwapChain *pSwapChain) { } static ULONG __stdcall myAddRef(ID3D11Device *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(); @@ -566,7 +569,7 @@ static ULONG __stdcall myAddRef(ID3D11Device *pDevice) { } static ULONG __stdcall myRelease(ID3D11Device *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(); @@ -595,8 +598,8 @@ static ULONG __stdcall myRelease(ID3D11Device *pDevice) { static void HookAddRelease(voidFunc vfAdd, voidFunc vfRelease) { ods("D3D11: 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)); } void hookD3D11(HMODULE hD3D11, bool preonly); @@ -614,21 +617,21 @@ void checkDXGI11Hook(bool preonly) { bCheckHookActive = true; - HMODULE hDXGI = GetModuleHandleW(L"DXGI.DLL"); + HMODULE hDXGI = GetModuleHandleW(L"DXGI.DLL"); HMODULE hD3D11 = GetModuleHandleW(L"D3D11.DLL"); if (hDXGI && hD3D11) { - if (! bHooked) { + if (!bHooked) { hookD3D11(hD3D11, preonly); } } else { - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT if (hDXGI) { ods("D3D11: No DXGI.DLL found as loaded. No hooking at this point."); } else { ods("D3D11: No D3D11.DLL found as loaded. No hooking at this point."); } - #endif +#endif } bCheckHookActive = false; @@ -636,10 +639,9 @@ void checkDXGI11Hook(bool preonly) { /// @param hD3D11 must be a valid module handle void hookD3D11(HMODULE hD3D11, 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>(&hookD3D11), &hTempSelf); + GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast< LPCTSTR >(&hookD3D11), &hTempSelf); bHooked = true; @@ -650,7 +652,7 @@ void hookD3D11(HMODULE hD3D11, bool preonly) { if (_wcsicmp(d3d11->wcFileName, modulename) == 0) { unsigned char *raw = (unsigned char *) hD3D11; HookAddRelease((voidFunc)(raw + d3d11->offsetAddRef), (voidFunc)(raw + d3d11->offsetRelease)); - } else if (! preonly) { + } else if (!preonly) { ods("D3D11: Interface changed, can't rawpatch. Current: %ls ; Previously: %ls", modulename, d3d11->wcFileName); } else { bHooked = false; @@ -662,26 +664,25 @@ void hookD3D11(HMODULE hD3D11, bool preonly) { /// (This data can later be used for hooking / code injection.) /// /// Adjusts the data behind the global variables dxgi and d3d11. -void PrepareDXGI11(IDXGIAdapter1* pAdapter, bool initializeDXGIData) { - +void PrepareDXGI11(IDXGIAdapter1 *pAdapter, bool initializeDXGIData) { if (!dxgi || !d3d11 || !pAdapter) return; ods("D3D11: Preparing static data for DXGI and D3D11 Injection"); d3d11->wcFileName[0] = 0; - d3d11->offsetAddRef = 0; + d3d11->offsetAddRef = 0; d3d11->offsetRelease = 0; HMODULE hD3D11 = LoadLibrary("D3D11.DLL"); if (hD3D11) { + 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); - - D3D11CreateDeviceAndSwapChainType pD3D11CreateDeviceAndSwapChain = reinterpret_cast<D3D11CreateDeviceAndSwapChainType>(GetProcAddress(hD3D11, "D3D11CreateDeviceAndSwapChain")); + D3D11CreateDeviceAndSwapChainType pD3D11CreateDeviceAndSwapChain = + reinterpret_cast< D3D11CreateDeviceAndSwapChainType >( + GetProcAddress(hD3D11, "D3D11CreateDeviceAndSwapChain")); DXGI_SWAP_CHAIN_DESC desc; ZeroMemory(&desc, sizeof(desc)); @@ -689,18 +690,18 @@ void PrepareDXGI11(IDXGIAdapter1* pAdapter, bool initializeDXGIData) { RECT rcWnd; BOOL success = GetClientRect(hwnd, &rcWnd); if (success) { - desc.BufferDesc.Width = rcWnd.right - rcWnd.left; + desc.BufferDesc.Width = rcWnd.right - rcWnd.left; desc.BufferDesc.Height = rcWnd.bottom - rcWnd.top; ods("D3D11: 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; @@ -714,46 +715,57 @@ void PrepareDXGI11(IDXGIAdapter1* pAdapter, bool initializeDXGIData) { desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; IDXGISwapChain *pSwapChain = nullptr; - ID3D11Device *pDevice = nullptr; + ID3D11Device *pDevice = nullptr; D3D_FEATURE_LEVEL featureLevel; ID3D11DeviceContext *pDeviceContext = nullptr; - HRESULT hr = pD3D11CreateDeviceAndSwapChain(pAdapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0, nullptr, 0, D3D11_SDK_VERSION, &desc, &pSwapChain, &pDevice, &featureLevel, &pDeviceContext); + HRESULT hr = pD3D11CreateDeviceAndSwapChain(pAdapter, D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0, nullptr, 0, + D3D11_SDK_VERSION, &desc, &pSwapChain, &pDevice, &featureLevel, + &pDeviceContext); if (FAILED(hr)) ods("D3D11: pD3D11CreateDeviceAndSwapChain failure!"); if (pDevice && pDeviceContext && 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), "D3D11", "Present"); + boost::optional< size_t > offset = + GetFnOffsetInModule(reinterpret_cast< voidFunc >(pPresent), dxgi->wcFileName, + ARRAY_NUM_ELEMENTS(dxgi->wcFileName), "D3D11", "Present"); if (offset) { if (initializeDXGIData) { dxgi->offsetPresent = *offset; ods("D3D11: Successfully found Present offset: %ls: %d", dxgi->wcFileName, dxgi->offsetPresent); } else { if (dxgi->offsetPresent == *offset) { - ods("D3D11: Successfully verified Present offset: %ls: %d", dxgi->wcFileName, dxgi->offsetPresent); + ods("D3D11: Successfully verified Present offset: %ls: %d", dxgi->wcFileName, + dxgi->offsetPresent); } else { - ods("D3D11: Failed to verify Present offset for %ls. Found %d, but previously found %d.", dxgi->wcFileName, offset, dxgi->offsetPresent); + ods("D3D11: 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), "D3D11", "ResizeBuffers"); + offset = GetFnOffsetInModule(reinterpret_cast< voidFunc >(pResize), dxgi->wcFileName, + ARRAY_NUM_ELEMENTS(dxgi->wcFileName), "D3D11", "ResizeBuffers"); if (offset) { if (initializeDXGIData) { dxgi->offsetResize = *offset; - ods("D3D11: Successfully found ResizeBuffers offset: %ls: %d", dxgi->wcFileName, dxgi->offsetResize); + ods("D3D11: Successfully found ResizeBuffers offset: %ls: %d", dxgi->wcFileName, + dxgi->offsetResize); } else { if (dxgi->offsetResize == *offset) { - ods("D3D11: Successfully verified ResizeBuffers offset: %ls: %d", dxgi->wcFileName, dxgi->offsetResize); + ods("D3D11: Successfully verified ResizeBuffers offset: %ls: %d", dxgi->wcFileName, + dxgi->offsetResize); } else { - ods("D3D11: Failed to verify ResizeBuffers offset for %ls. Found %d, but previously found %d.", dxgi->wcFileName, offset, dxgi->offsetResize); + ods("D3D11: Failed to verify ResizeBuffers offset for %ls. Found %d, but previously found " + "%d.", + dxgi->wcFileName, offset, dxgi->offsetResize); } } } @@ -761,14 +773,16 @@ void PrepareDXGI11(IDXGIAdapter1* pAdapter, bool initializeDXGIData) { vtbl = (void ***) pDevice; void *pAddRef = (*vtbl)[1]; - offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pAddRef), d3d11->wcFileName, ARRAY_NUM_ELEMENTS(d3d11->wcFileName), "D3D11", "AddRef"); + offset = GetFnOffsetInModule(reinterpret_cast< voidFunc >(pAddRef), d3d11->wcFileName, + ARRAY_NUM_ELEMENTS(d3d11->wcFileName), "D3D11", "AddRef"); if (offset) { d3d11->offsetAddRef = *offset; ods("D3D11: Successfully found AddRef offset: %ls: %d", d3d11->wcFileName, d3d11->offsetAddRef); } void *pRelease = (*vtbl)[2]; - offset = GetFnOffsetInModule(reinterpret_cast<voidFunc>(pRelease), d3d11->wcFileName, ARRAY_NUM_ELEMENTS(d3d11->wcFileName), "D3D11", "Release"); + offset = GetFnOffsetInModule(reinterpret_cast< voidFunc >(pRelease), d3d11->wcFileName, + ARRAY_NUM_ELEMENTS(d3d11->wcFileName), "D3D11", "Release"); if (offset) { d3d11->offsetRelease = *offset; ods("D3D11: Successfully found Release offset: %ls: %d", d3d11->wcFileName, d3d11->offsetRelease); diff --git a/overlay/d3d9.cpp b/overlay/d3d9.cpp index c5dcb87f4..f954ef74d 100644 --- a/overlay/d3d9.cpp +++ b/overlay/d3d9.cpp @@ -9,20 +9,13 @@ Direct3D9Data *d3dd = nullptr; -typedef IDirect3D9* (WINAPI *pDirect3DCreate9)(UINT SDKVersion) ; -typedef HRESULT (WINAPI *pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex **ppD3D) ; +typedef IDirect3D9 *(WINAPI *pDirect3DCreate9)(UINT SDKVersion); +typedef HRESULT(WINAPI *pDirect3DCreate9Ex)(UINT SDKVersion, IDirect3D9Ex **ppD3D); -template<class T> -class Stash { +template< class T > class Stash { public: - Stash(T *variable, T newValue) - : var(variable) - , value(*var) { - *variable = newValue; - } - ~Stash() { - *var = value; - } + Stash(T *variable, T newValue) : var(variable), value(*var) { *variable = newValue; } + ~Stash() { *var = value; } private: T *var; @@ -30,41 +23,41 @@ private: }; struct D3DTLVERTEX { - float x, y, z, rhw; // Position - float tu, tv; // Texture coordinates + float x, y, z, rhw; // Position + float tu, tv; // Texture coordinates }; static const DWORD D3DFVF_TLVERTEX = D3DFVF_XYZRHW | D3DFVF_TEX1; class DevState : public Pipe { - public: - IDirect3DDevice9 *dev; - IDirect3DStateBlock9 *pSB; - - /// Non-Win8: Initial ref count, directly after device creation. - /// Win8: Unused - LONG initRefCount; - LONG refCount; - /// Refcount of self (library). Used to make the overlay transparent - /// (invisible) to the outside. - LONG myRefCount; - DWORD dwMyThread; - - D3DTLVERTEX vertices[4]; - LPDIRECT3DTEXTURE9 texTexture; - - clock_t timeT; - unsigned int frameCount; - - DevState(); - - void createCleanState(); - void releaseData(); - void releaseAll(); - 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 width, unsigned int height); +public: + IDirect3DDevice9 *dev; + IDirect3DStateBlock9 *pSB; + + /// Non-Win8: Initial ref count, directly after device creation. + /// Win8: Unused + LONG initRefCount; + LONG refCount; + /// Refcount of self (library). Used to make the overlay transparent + /// (invisible) to the outside. + LONG myRefCount; + DWORD dwMyThread; + + D3DTLVERTEX vertices[4]; + LPDIRECT3DTEXTURE9 texTexture; + + clock_t timeT; + unsigned int frameCount; + + DevState(); + + void createCleanState(); + void releaseData(); + void releaseAll(); + 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 width, unsigned int height); }; /// Vtable offset; see d3d9.h of win-/D3D-API. @@ -74,20 +67,20 @@ static const int VTABLE_OFFSET_ID3D_CREATEDEVICE = 16; /// Offset: 3 from IUnknown + 14 from IDirect3D9 + 4 in IDirect3D9Ex, 0-based => 20 static const int VTABLE_OFFSET_ID3D_CREATEDEVICE_EX = 20; -typedef map<IDirect3DDevice9 *, DevState *> DevMapType; +typedef map< IDirect3DDevice9 *, DevState * > DevMapType; static DevMapType devMap; static bool bHooked = false; DevState::DevState() { - dev = nullptr; - pSB = nullptr; - dwMyThread = 0; + dev = nullptr; + pSB = nullptr; + dwMyThread = 0; initRefCount = 0; - refCount = 0; - myRefCount = 0; - texTexture = nullptr; + refCount = 0; + myRefCount = 0; + texTexture = nullptr; - timeT = clock(); + timeT = clock(); frameCount = 0; for (int i = 0; i < 4; ++i) { @@ -107,12 +100,12 @@ void DevState::releaseData() { } void DevState::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h) { - // Blit is called often. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// Blit is called often. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Blit %d %d %d %d", x, y, w, h); - #endif +#endif - if (! texTexture || !a_ucTexture || uiLeft == uiRight) + if (!texTexture || !a_ucTexture || uiLeft == uiRight) return; D3DLOCKED_RECT lr; @@ -123,17 +116,17 @@ void DevState::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int } else { RECT r; - r.left = x; - r.top = y; - r.right = x + w; + r.left = x; + r.top = y; + r.right = x + w; r.bottom = y + h; if (texTexture->LockRect(0, &lr, &r, 0) != D3D_OK) return; } - for (unsigned int r=0;r < h;++r) { - unsigned char *dptr = reinterpret_cast<unsigned char *>(lr.pBits) + r * lr.Pitch; + for (unsigned int r = 0; r < h; ++r) { + unsigned char *dptr = reinterpret_cast< unsigned char * >(lr.pBits) + r * lr.Pitch; unsigned char *sptr = a_ucTexture + 4 * ((y + r) * uiWidth + x); memcpy(dptr, sptr, w * 4); } @@ -144,36 +137,36 @@ void DevState::blit(unsigned int x, unsigned int y, unsigned int w, unsigned int void DevState::setRect() { ods("D3D9: New subrect"); - 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; - vertices[0].x = left; - vertices[0].y = top; + vertices[0].x = left; + vertices[0].y = top; vertices[0].tu = texl; vertices[0].tv = text; - vertices[1].x = right; - vertices[1].y = top; + vertices[1].x = right; + vertices[1].y = top; vertices[1].tu = texr; vertices[1].tv = text; - vertices[2].x = right; - vertices[2].y = bottom; + vertices[2].x = right; + vertices[2].y = bottom; vertices[2].tu = texr; vertices[2].tv = texb; - vertices[3].x = left; - vertices[3].y = bottom; + vertices[3].x = left; + vertices[3].y = bottom; vertices[3].tu = texl; vertices[3].tv = texb; } @@ -191,7 +184,7 @@ void DevState::newTexture(unsigned int width, unsigned int height) { for (int i = 0; i < 4; ++i) { vertices[i].x = vertices[i].y = vertices[i].z = 0.0f; vertices[i].tu = vertices[i].tv = 0.0f; - vertices[i].rhw = 1.0f; + vertices[i].rhw = 1.0f; } } @@ -204,20 +197,20 @@ void DevState::releaseAll() { } void DevState::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; } D3DVIEWPORT9 vp; @@ -225,10 +218,10 @@ void DevState::draw() { checkMessage(vp.Width, vp.Height); - if (! a_ucTexture || (uiLeft == uiRight)) + if (!a_ucTexture || (uiLeft == uiRight)) return; - if (! texTexture) { + if (!texTexture) { unsigned int l, r, t, b; l = uiLeft; r = uiRight; @@ -237,9 +230,9 @@ void DevState::draw() { newTexture(uiWidth, uiHeight); blit(0, 0, uiWidth, uiHeight); - uiLeft = l; - uiRight = r; - uiTop = t; + uiLeft = l; + uiRight = r; + uiTop = t; uiBottom = b; setRect(); } @@ -252,21 +245,21 @@ void DevState::createCleanState() { if (dwMyThread != 0) { ods("D3D9: CreateCleanState from other thread."); } - Stash<DWORD> stashThread(&dwMyThread, GetCurrentThreadId()); + Stash< DWORD > stashThread(&dwMyThread, GetCurrentThreadId()); if (pSB) pSB->Release(); pSB = nullptr; - IDirect3DStateBlock9* pStateBlock = nullptr; + IDirect3DStateBlock9 *pStateBlock = nullptr; dev->CreateStateBlock(D3DSBT_ALL, &pStateBlock); - if (! pStateBlock) + if (!pStateBlock) return; pStateBlock->Capture(); dev->CreateStateBlock(D3DSBT_ALL, &pSB); - if (! pSB) { + if (!pSB) { pStateBlock->Release(); return; } @@ -281,10 +274,10 @@ void DevState::createCleanState() { dev->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); dev->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // 0x16 - dev->SetRenderState(D3DRS_WRAP0, FALSE); // 0x80 + dev->SetRenderState(D3DRS_WRAP0, FALSE); // 0x80 dev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); - dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); + dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE); dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); dev->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); @@ -339,14 +332,14 @@ static HardHook hhSwapPresent; /// every frame, etc. static void doPresent(IDirect3DDevice9 *idd, IDirect3DSwapChain9 *ids) { DevMapType::iterator it = devMap.find(idd); - DevState *ds = it != devMap.end() ? it->second : nullptr; + DevState *ds = it != devMap.end() ? it->second : nullptr; HRESULT hres; if (ds && ds->pSB) { if (ds->dwMyThread != 0) { ods("D3D9: doPresent from other thread"); } - Stash<DWORD> stashThread(&(ds->dwMyThread), GetCurrentThreadId()); + Stash< DWORD > stashThread(&(ds->dwMyThread), GetCurrentThreadId()); // Get the back buffer. // If we're called via IDirect3DSwapChain9, acquire it via the swap chain object. @@ -356,7 +349,8 @@ static void doPresent(IDirect3DDevice9 *idd, IDirect3DSwapChain9 *ids) { hres = ids->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pTarget); if (FAILED(hres)) { if (hres == D3DERR_INVALIDCALL) { - ods("D3D9: IDirect3DSwapChain9::GetBackBuffer failed. BackBuffer index equals or exceeds the total number of back buffers"); + ods("D3D9: IDirect3DSwapChain9::GetBackBuffer failed. BackBuffer index equals or exceeds the total " + "number of back buffers"); } else { ods("D3D9: IDirect3DSwapChain9::GetBackBuffer failed"); } @@ -365,7 +359,8 @@ static void doPresent(IDirect3DDevice9 *idd, IDirect3DSwapChain9 *ids) { hres = idd->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pTarget); if (FAILED(hres)) { if (hres == D3DERR_INVALIDCALL) { - ods("D3D9: IDirect3DDevice9::GetBackBuffer failed. BackBuffer index equals or exceeds the total number of back buffers"); + ods("D3D9: IDirect3DDevice9::GetBackBuffer failed. BackBuffer index equals or exceeds the total " + "number of back buffers"); } else { ods("D3D9: IDirect3DDevice9::GetBackBuffer failed"); } @@ -373,10 +368,11 @@ static void doPresent(IDirect3DDevice9 *idd, IDirect3DSwapChain9 *ids) { } IDirect3DSurface9 *pRenderTarget = nullptr; - hres = idd->GetRenderTarget(0, &pRenderTarget); + hres = idd->GetRenderTarget(0, &pRenderTarget); if (FAILED(hres)) { if (hres == D3DERR_NOTFOUND) { - ods("D3D9: IDirect3DDevice9::GetRenderTarget failed. There is no render target with the specified index"); + ods("D3D9: IDirect3DDevice9::GetRenderTarget failed. There is no render target with the specified " + "index"); } else if (hres == D3DERR_INVALIDCALL) { ods("D3D9: IDirect3DDevice9::GetRenderTarget failed. One of the passed arguments was invalid"); } else { @@ -384,12 +380,12 @@ static void doPresent(IDirect3DDevice9 *idd, IDirect3DSwapChain9 *ids) { } } - // Present is called for each frame. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// Present is called for each frame. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: doPresent BackB %p RenderT %p", pTarget, pRenderTarget); - #endif +#endif - IDirect3DStateBlock9* pStateBlock = nullptr; + IDirect3DStateBlock9 *pStateBlock = nullptr; idd->CreateStateBlock(D3DSBT_ALL, &pStateBlock); pStateBlock->Capture(); @@ -428,12 +424,12 @@ static void doPresent(IDirect3DDevice9 *idd, IDirect3DSwapChain9 *ids) { } else { if (pp.BackBufferWidth != 0 && pp.BackBufferHeight != 0) { D3DVIEWPORT9 vp; - vp.X = 0; - vp.Y = 0; - vp.Width = pp.BackBufferWidth; + vp.X = 0; + vp.Y = 0; + vp.Width = pp.BackBufferWidth; vp.Height = pp.BackBufferHeight; - vp.MinZ = 0.0f; - vp.MaxZ = 1.0f; + vp.MinZ = 0.0f; + vp.MaxZ = 1.0f; idd->SetViewport(&vp); } @@ -450,17 +446,19 @@ static void doPresent(IDirect3DDevice9 *idd, IDirect3DSwapChain9 *ids) { pRenderTarget->Release(); pTarget->Release(); -// ods("D3D9: Finished ref is %d %d", ds->myRefCount, ds->refCount); + // ods("D3D9: Finished ref is %d %d", ds->myRefCount, ds->refCount); } } -typedef HRESULT(__stdcall *SwapPresentType)(IDirect3DSwapChain9 *, CONST RECT *, CONST RECT *, HWND, CONST RGNDATA *, DWORD); -static HRESULT __stdcall mySwapPresent(IDirect3DSwapChain9 *ids, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) { - // Present is called for each frame. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +typedef HRESULT(__stdcall *SwapPresentType)(IDirect3DSwapChain9 *, CONST RECT *, CONST RECT *, HWND, CONST RGNDATA *, + DWORD); +static HRESULT __stdcall mySwapPresent(IDirect3DSwapChain9 *ids, CONST RECT *pSourceRect, CONST RECT *pDestRect, + HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) { +// Present is called for each frame. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: SwapChain Present"); - #endif +#endif IDirect3DDevice9 *idd = nullptr; ids->GetDevice(&idd); @@ -469,7 +467,7 @@ static HRESULT __stdcall mySwapPresent(IDirect3DSwapChain9 *ids, CONST RECT *pSo idd->Release(); } - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. SwapPresentType oSwapPresent = (SwapPresentType) hhSwapPresent.call; hhSwapPresent.restore(); @@ -480,15 +478,16 @@ static HRESULT __stdcall mySwapPresent(IDirect3DSwapChain9 *ids, CONST RECT *pSo } typedef HRESULT(__stdcall *PresentType)(IDirect3DDevice9 *, CONST RECT *, CONST RECT *, HWND, CONST RGNDATA *); -static HRESULT __stdcall myPresent(IDirect3DDevice9 *idd, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride,CONST RGNDATA *pDirtyRegion) { - // Present is called for each frame. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +static HRESULT __stdcall myPresent(IDirect3DDevice9 *idd, CONST RECT *pSourceRect, CONST RECT *pDestRect, + HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion) { +// Present is called for each frame. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Device Present"); - #endif +#endif doPresent(idd, nullptr); - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. PresentType oPresent = (PresentType) hhPresent.call; hhPresent.restore(); @@ -498,12 +497,14 @@ static HRESULT __stdcall myPresent(IDirect3DDevice9 *idd, CONST RECT *pSourceRec return hr; } -typedef HRESULT(__stdcall *PresentExType)(IDirect3DDevice9Ex *, CONST RECT *, CONST RECT *, HWND, CONST RGNDATA *, DWORD); -static HRESULT __stdcall myPresentEx(IDirect3DDevice9Ex *idd, CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) { - // Present is called for each frame. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +typedef HRESULT(__stdcall *PresentExType)(IDirect3DDevice9Ex *, CONST RECT *, CONST RECT *, HWND, CONST RGNDATA *, + DWORD); +static HRESULT __stdcall myPresentEx(IDirect3DDevice9Ex *idd, CONST RECT *pSourceRect, CONST RECT *pDestRect, + HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion, DWORD dwFlags) { +// Present is called for each frame. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Device Present Ex"); - #endif +#endif doPresent(idd, nullptr); @@ -520,17 +521,17 @@ static HRESULT __stdcall myReset(IDirect3DDevice9 *idd, D3DPRESENT_PARAMETERS *p ods("D3D9: Chaining Reset"); DevMapType::iterator it = devMap.find(idd); - DevState *ds = it != devMap.end() ? it->second : nullptr; + DevState *ds = it != devMap.end() ? it->second : nullptr; if (ds) { if (ds->dwMyThread != 0) { ods("D3D9: myReset from other thread"); } - Stash<DWORD> stashThread(&(ds->dwMyThread), GetCurrentThreadId()); + Stash< DWORD > stashThread(&(ds->dwMyThread), GetCurrentThreadId()); ds->releaseAll(); } - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. ResetType oReset = (ResetType) hhReset.call; hhReset.restore(); @@ -548,17 +549,17 @@ static HRESULT __stdcall myResetEx(IDirect3DDevice9Ex *idd, D3DPRESENT_PARAMETER ods("D3D9: Chaining ResetEx"); DevMapType::iterator it = devMap.find(idd); - DevState *ds = it != devMap.end() ? it->second : nullptr; + DevState *ds = it != devMap.end() ? it->second : nullptr; if (ds) { if (ds->dwMyThread) { ods("D3D9: myResetEx from other thread"); } - Stash<DWORD> stashThread(&(ds->dwMyThread), GetCurrentThreadId()); + Stash< DWORD > stashThread(&(ds->dwMyThread), GetCurrentThreadId()); ds->releaseAll(); } - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. ResetExType oResetEx = (ResetExType) hhResetEx.call; hhResetEx.restore(); @@ -577,12 +578,12 @@ static ULONG __stdcall myAddRef(IDirect3DDevice9 *idd) { Mutex m; DevMapType::iterator it = devMap.find(idd); - DevState *ds = it != devMap.end() ? it->second : nullptr; + DevState *ds = it != devMap.end() ? it->second : nullptr; if (ds) { - // AddRef is called very often. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// AddRef is called very often. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Using own Refcount implementation for call to AddRef."); - #endif +#endif if (ds->dwMyThread == GetCurrentThreadId()) { ds->myRefCount++; @@ -592,17 +593,17 @@ static ULONG __stdcall myAddRef(IDirect3DDevice9 *idd) { return ds->initRefCount + ds->refCount; } - //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(); ULONG res = oAddRef(idd); hhAddRef.inject(); - // AddRef is called very often. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// AddRef is called very often. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Chained AddRef with result %d", res); - #endif +#endif return res; } @@ -611,18 +612,18 @@ static ULONG __stdcall myWin8AddRef(IDirect3DDevice9 *idd) { Mutex m; DevMapType::iterator it = devMap.find(idd); - DevState *ds = it != devMap.end() ? it->second : nullptr; + DevState *ds = it != devMap.end() ? it->second : nullptr; if (ds && ds->dwMyThread == GetCurrentThreadId()) { - // AddRef is called very often. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// AddRef is called very often. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Using own Refcount implementation for call to AddRef (Win8)."); - #endif +#endif ds->myRefCount++; return ds->refCount; } - //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(); @@ -632,10 +633,10 @@ static ULONG __stdcall myWin8AddRef(IDirect3DDevice9 *idd) { if (ds) ds->refCount = res; - // AddRef is called very often. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// AddRef is called very often. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Chained AddRef (Win8) with result %d", res); - #endif +#endif return res; } @@ -646,12 +647,12 @@ static ULONG __stdcall myRelease(IDirect3DDevice9 *idd) { Mutex m; DevMapType::iterator it = devMap.find(idd); - DevState *ds = it != devMap.end() ? it->second : nullptr; + DevState *ds = it != devMap.end() ? it->second : nullptr; if (ds) { - // Release is called very often. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// Release is called very often. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Using own Refcount implementation for call to Release."); - #endif +#endif if (ds->dwMyThread == GetCurrentThreadId()) { ds->myRefCount--; @@ -676,7 +677,7 @@ static ULONG __stdcall myRelease(IDirect3DDevice9 *idd) { // Codeblock for stashing threadid { - Stash<DWORD> stashThread(&(ds->dwMyThread), GetCurrentThreadId()); + Stash< DWORD > stashThread(&(ds->dwMyThread), GetCurrentThreadId()); ds->releaseAll(); } @@ -688,17 +689,17 @@ static ULONG __stdcall myRelease(IDirect3DDevice9 *idd) { ds = nullptr; } - //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(); ULONG res = oRelease(idd); hhRelease.inject(); - // Release is called very often. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// Release is called very often. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Chained Release with result %d", res); - #endif +#endif return res; } @@ -707,12 +708,12 @@ static ULONG __stdcall myWin8Release(IDirect3DDevice9 *idd) { Mutex m; DevMapType::iterator it = devMap.find(idd); - DevState *ds = it != devMap.end() ? it->second : nullptr; + DevState *ds = it != devMap.end() ? it->second : nullptr; if (ds) { - // Release is called very often. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// Release is called very often. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Using own Refcount implementation for call to Release."); - #endif +#endif if (ds->dwMyThread == GetCurrentThreadId()) { ds->myRefCount--; @@ -729,7 +730,7 @@ static ULONG __stdcall myWin8Release(IDirect3DDevice9 *idd) { // Codeblock for stashing threadid { - Stash<DWORD> stashThread(&(ds->dwMyThread), GetCurrentThreadId()); + Stash< DWORD > stashThread(&(ds->dwMyThread), GetCurrentThreadId()); ds->releaseAll(); } @@ -742,7 +743,7 @@ static ULONG __stdcall myWin8Release(IDirect3DDevice9 *idd) { } } - //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(); @@ -752,23 +753,20 @@ static ULONG __stdcall myWin8Release(IDirect3DDevice9 *idd) { if (ds) ds->refCount = res; - // Release is called very often. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// Release is called very often. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Chained Release (Win8) with result: %d", res); - #endif +#endif return res; } -static IDirect3DDevice9* findOriginalDevice(IDirect3DDevice9 *device) { - +static IDirect3DDevice9 *findOriginalDevice(IDirect3DDevice9 *device) { IDirect3DSwapChain9 *pSwap = nullptr; device->GetSwapChain(0, &pSwap); if (pSwap) { - IDirect3DDevice9 *originalDevice = nullptr; if (SUCCEEDED(pSwap->GetDevice(&originalDevice))) { - if (originalDevice == device) { // Found the original device. Release responsibility is passed // to the caller. @@ -789,19 +787,23 @@ static IDirect3DDevice9* findOriginalDevice(IDirect3DDevice9 *device) { return device; } -typedef HRESULT(__stdcall *CreateDeviceType)(IDirect3D9 *, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS *, IDirect3DDevice9 **); -static HRESULT __stdcall myCreateDevice(IDirect3D9 *id3d, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DDevice9 **ppReturnedDeviceInterface) { +typedef HRESULT(__stdcall *CreateDeviceType)(IDirect3D9 *, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS *, + IDirect3DDevice9 **); +static HRESULT __stdcall myCreateDevice(IDirect3D9 *id3d, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, + DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, + IDirect3DDevice9 **ppReturnedDeviceInterface) { Mutex m; ods("D3D9: Chaining CreateDevice"); -// BehaviorFlags &= ~D3DCREATE_PUREDEVICE; + // BehaviorFlags &= ~D3DCREATE_PUREDEVICE; - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. CreateDeviceType oCreateDevice = (CreateDeviceType) hhCreateDevice.call; hhCreateDevice.restore(); - HRESULT hr = oCreateDevice(id3d, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface); + HRESULT hr = oCreateDevice(id3d, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, + ppReturnedDeviceInterface); hhCreateDevice.inject(); if (FAILED(hr)) @@ -817,14 +819,15 @@ static HRESULT __stdcall myCreateDevice(IDirect3D9 *id3d, UINT Adapter, D3DDEVTY } DevState *ds = new DevState; - ds->dev = idd; + ds->dev = idd; idd->AddRef(); ds->initRefCount = idd->Release(); DevMapType::iterator it = devMap.find(idd); if (it != devMap.end()) { - ods("Device exists in devMap already - canceling injection into device. Thread prev: %d ; new: %d", it->second->dwMyThread, GetCurrentThreadId()); + ods("Device exists in devMap already - canceling injection into device. Thread prev: %d ; new: %d", + it->second->dwMyThread, GetCurrentThreadId()); delete ds; return hr; @@ -833,19 +836,19 @@ static HRESULT __stdcall myCreateDevice(IDirect3D9 *id3d, UINT Adapter, D3DDEVTY // The offsets are dependent on the declaration order of the struct. // See IDirect3DDevice9 (2nd, 3rd, 17th, 18th functions) - const unsigned int offsetAddref = 1; + const unsigned int offsetAddref = 1; const unsigned int offsetRelease = 2; - const unsigned int offsetReset = 16; + const unsigned int offsetReset = 16; const unsigned int offsetPresent = 17; if (bIsWin8) { - hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast<voidFunc>(myWin8AddRef)); - hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast<voidFunc>(myWin8Release)); + hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast< voidFunc >(myWin8AddRef)); + hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast< voidFunc >(myWin8Release)); } else { - hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast<voidFunc>(myAddRef)); - hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast<voidFunc>(myRelease)); + hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast< voidFunc >(myAddRef)); + hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast< voidFunc >(myRelease)); } - hhReset.setupInterface(idd, offsetReset, reinterpret_cast<voidFunc>(myReset)); - hhPresent.setupInterface(idd, offsetPresent, reinterpret_cast<voidFunc>(myPresent)); + hhReset.setupInterface(idd, offsetReset, reinterpret_cast< voidFunc >(myReset)); + hhPresent.setupInterface(idd, offsetPresent, reinterpret_cast< voidFunc >(myPresent)); IDirect3DSwapChain9 *pSwap = nullptr; idd->GetSwapChain(0, &pSwap); @@ -853,7 +856,7 @@ static HRESULT __stdcall myCreateDevice(IDirect3D9 *id3d, UINT Adapter, D3DDEVTY // The offset is dependent on the declaration order of the struct. // See IDirect3DSwapChain9 (Present is the fourth function) const unsigned int offsetPresent = 3; - hhSwapPresent.setupInterface(pSwap, offsetPresent, reinterpret_cast<voidFunc>(mySwapPresent)); + hhSwapPresent.setupInterface(pSwap, offsetPresent, reinterpret_cast< voidFunc >(mySwapPresent)); pSwap->Release(); } else { ods("D3D9: Failed to get swapchain"); @@ -864,18 +867,23 @@ static HRESULT __stdcall myCreateDevice(IDirect3D9 *id3d, UINT Adapter, D3DDEVTY return hr; } -typedef HRESULT(__stdcall *CreateDeviceExType)(IDirect3D9Ex *, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS *, D3DDISPLAYMODEEX *, IDirect3DDevice9Ex **); -static HRESULT __stdcall myCreateDeviceEx(IDirect3D9Ex *id3d, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX *pFullscreenDisplayMode, IDirect3DDevice9Ex **ppReturnedDeviceInterface) { +typedef HRESULT(__stdcall *CreateDeviceExType)(IDirect3D9Ex *, UINT, D3DDEVTYPE, HWND, DWORD, D3DPRESENT_PARAMETERS *, + D3DDISPLAYMODEEX *, IDirect3DDevice9Ex **); +static HRESULT __stdcall myCreateDeviceEx(IDirect3D9Ex *id3d, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, + DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, + D3DDISPLAYMODEEX *pFullscreenDisplayMode, + IDirect3DDevice9Ex **ppReturnedDeviceInterface) { Mutex m; ods("D3D9: Chaining CreateDeviceEx"); -// BehaviorFlags &= ~D3DCREATE_PUREDEVICE; + // BehaviorFlags &= ~D3DCREATE_PUREDEVICE; - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. CreateDeviceExType oCreateDeviceEx = (CreateDeviceExType) hhCreateDeviceEx.call; hhCreateDeviceEx.restore(); - HRESULT hr = oCreateDeviceEx(id3d, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface); + HRESULT hr = oCreateDeviceEx(id3d, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, + pFullscreenDisplayMode, ppReturnedDeviceInterface); hhCreateDeviceEx.inject(); if (FAILED(hr)) @@ -884,14 +892,15 @@ static HRESULT __stdcall myCreateDeviceEx(IDirect3D9Ex *id3d, UINT Adapter, D3DD IDirect3DDevice9Ex *idd = *ppReturnedDeviceInterface; DevState *ds = new DevState; - ds->dev = idd; + ds->dev = idd; idd->AddRef(); ds->initRefCount = idd->Release(); DevMapType::iterator it = devMap.find(idd); if (it != devMap.end()) { - ods("Device exists in devMap already - canceling injection into device. Thread prev: %d ; new: %d", it->second->dwMyThread, GetCurrentThreadId()); + ods("Device exists in devMap already - canceling injection into device. Thread prev: %d ; new: %d", + it->second->dwMyThread, GetCurrentThreadId()); delete ds; return hr; @@ -900,24 +909,24 @@ static HRESULT __stdcall myCreateDeviceEx(IDirect3D9Ex *id3d, UINT Adapter, D3DD // The offsets are dependent on the declaration order of the struct. // See IDirect3DDevice9 (2nd, 3rd, 17th, 18th functions) - const unsigned int offsetAddref = 1; + const unsigned int offsetAddref = 1; const unsigned int offsetRelease = 2; - const unsigned int offsetReset = 16; + const unsigned int offsetReset = 16; const unsigned int offsetPresent = 17; // On IDirect3DDevice9Ex const unsigned int offsetPresentEx = 121; - const unsigned int offsetResetEx = 132; + const unsigned int offsetResetEx = 132; if (bIsWin8) { - hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast<voidFunc>(myWin8AddRef)); - hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast<voidFunc>(myWin8Release)); + hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast< voidFunc >(myWin8AddRef)); + hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast< voidFunc >(myWin8Release)); } else { - hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast<voidFunc>(myAddRef)); - hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast<voidFunc>(myRelease)); + hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast< voidFunc >(myAddRef)); + hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast< voidFunc >(myRelease)); } - hhReset.setupInterface(idd, offsetReset, reinterpret_cast<voidFunc>(myReset)); - hhResetEx.setupInterface(idd, offsetResetEx, reinterpret_cast<voidFunc>(myResetEx)); - hhPresent.setupInterface(idd, offsetPresent, reinterpret_cast<voidFunc>(myPresent)); - hhPresentEx.setupInterface(idd, offsetPresentEx, reinterpret_cast<voidFunc>(myPresentEx)); + hhReset.setupInterface(idd, offsetReset, reinterpret_cast< voidFunc >(myReset)); + hhResetEx.setupInterface(idd, offsetResetEx, reinterpret_cast< voidFunc >(myResetEx)); + hhPresent.setupInterface(idd, offsetPresent, reinterpret_cast< voidFunc >(myPresent)); + hhPresentEx.setupInterface(idd, offsetPresentEx, reinterpret_cast< voidFunc >(myPresentEx)); IDirect3DSwapChain9 *pSwap = nullptr; idd->GetSwapChain(0, &pSwap); @@ -925,7 +934,7 @@ static HRESULT __stdcall myCreateDeviceEx(IDirect3D9Ex *id3d, UINT Adapter, D3DD // The offset is dependent on the declaration order of the struct. // See IDirect3DSwapChain9 (Present is the fourth function) const unsigned int offsetPresent = 3; - hhSwapPresent.setupInterface(pSwap, offsetPresent, reinterpret_cast<voidFunc>(mySwapPresent)); + hhSwapPresent.setupInterface(pSwap, offsetPresent, reinterpret_cast< voidFunc >(mySwapPresent)); pSwap->Release(); } else { ods("D3D9: Failed to get swapchain for DevEx"); @@ -937,18 +946,18 @@ static HRESULT __stdcall myCreateDeviceEx(IDirect3D9Ex *id3d, UINT Adapter, D3DD static void HookCreateRaw(voidFunc vfCreate) { ods("D3D9: Injecting CreateDevice Raw"); - hhCreateDevice.setup(vfCreate, reinterpret_cast<voidFunc>(myCreateDevice)); + hhCreateDevice.setup(vfCreate, reinterpret_cast< voidFunc >(myCreateDevice)); } static void HookCreateRawEx(voidFunc vfCreate) { ods("D3D9: Injecting CreateDeviceEx Raw"); - hhCreateDeviceEx.setup(vfCreate, reinterpret_cast<voidFunc>(myCreateDeviceEx)); + hhCreateDeviceEx.setup(vfCreate, reinterpret_cast< voidFunc >(myCreateDeviceEx)); } static void HookCreate(IDirect3D9 *pD3D) { ods("D3D9: Injecting CreateDevice"); - hhCreateDevice.setupInterface(pD3D, VTABLE_OFFSET_ID3D_CREATEDEVICE, reinterpret_cast<voidFunc>(myCreateDevice)); + hhCreateDevice.setupInterface(pD3D, VTABLE_OFFSET_ID3D_CREATEDEVICE, reinterpret_cast< voidFunc >(myCreateDevice)); } static void HookCreateEx(IDirect3D9Ex *pD3D) { @@ -958,7 +967,8 @@ static void HookCreateEx(IDirect3D9Ex *pD3D) { // previously this setup call is safely ignored by the hook. HookCreate(pD3D); - hhCreateDeviceEx.setupInterface(pD3D, VTABLE_OFFSET_ID3D_CREATEDEVICE_EX, reinterpret_cast<voidFunc>(myCreateDeviceEx)); + hhCreateDeviceEx.setupInterface(pD3D, VTABLE_OFFSET_ID3D_CREATEDEVICE_EX, + reinterpret_cast< voidFunc >(myCreateDeviceEx)); } static void hookD3D9(HMODULE hD3D, bool preonly); @@ -978,27 +988,26 @@ void checkD3D9Hook(bool preonly) { HMODULE hD3D = GetModuleHandle("D3D9.DLL"); if (hD3D) { - if (! bHooked) { + if (!bHooked) { hookD3D9(hD3D, preonly); } } else { - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: No D3D9.DLL found as loaded. No hooking at this point."); - #endif +#endif } bCheckHookActive = false; } static void hookD3D9(HMODULE hD3D, bool preonly) { - char procname[MODULEFILEPATH_BUFLEN]; GetModuleFileName(nullptr, procname, ARRAY_NUM_ELEMENTS(procname)); ods("D3D9: hookD3D9 in App '%s'", procname); // 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>(&hookD3D9), &hTempSelf); + GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast< LPCTSTR >(&hookD3D9), &hTempSelf); bHooked = true; @@ -1014,10 +1023,10 @@ static void hookD3D9(HMODULE hD3D, bool preonly) { HookCreateRawEx((voidFunc)(raw + d3dd->offsetCreateEx)); } - } else if (! preonly) { + } else if (!preonly) { ods("D3D9: Interface changed, can't rawpatch. Current: %ls ; Previously: %ls", modulename, d3dd->wcFileName); - pDirect3DCreate9 d3dcreate9 = reinterpret_cast<pDirect3DCreate9>(GetProcAddress(hD3D, "Direct3DCreate9")); + pDirect3DCreate9 d3dcreate9 = reinterpret_cast< pDirect3DCreate9 >(GetProcAddress(hD3D, "Direct3DCreate9")); if (d3dcreate9) { ods("D3D9: Got %p for Direct3DCreate9", d3dcreate9); @@ -1032,11 +1041,12 @@ static void hookD3D9(HMODULE hD3D, bool preonly) { ods("D3D9: Library without Direct3DCreate9?"); } - pDirect3DCreate9Ex d3dcreate9ex = reinterpret_cast<pDirect3DCreate9Ex>(GetProcAddress(hD3D, "Direct3DCreate9Ex")); + pDirect3DCreate9Ex d3dcreate9ex = + reinterpret_cast< pDirect3DCreate9Ex >(GetProcAddress(hD3D, "Direct3DCreate9Ex")); if (d3dcreate9ex) { ods("D3D9: Got %p for Direct3DCreate9Ex", d3dcreate9ex); - IDirect3D9Ex** id3d9ex = 0; - HRESULT hr = d3dcreate9ex(D3D_SDK_VERSION, id3d9ex); + IDirect3D9Ex **id3d9ex = 0; + HRESULT hr = d3dcreate9ex(D3D_SDK_VERSION, id3d9ex); if (SUCCEEDED(hr)) { HookCreateEx(*id3d9ex); (*id3d9ex)->Release(); @@ -1060,7 +1070,7 @@ static void hookD3D9(HMODULE hD3D, bool preonly) { } extern "C" __declspec(dllexport) void __cdecl PrepareD3D9() { - if (! d3dd) + if (!d3dd) return; ods("D3D9: Preparing static data for D3D9 Injection"); @@ -1068,15 +1078,14 @@ extern "C" __declspec(dllexport) void __cdecl PrepareD3D9() { HMODULE hD3D = LoadLibrary("D3D9.DLL"); if (hD3D) { - GetModuleFileNameW(hD3D, d3dd->wcFileName, ARRAY_NUM_ELEMENTS(d3dd->wcFileName)); std::string d3d9FnName("Direct3DCreate9"); - pDirect3DCreate9 d3dcreate9 = reinterpret_cast<pDirect3DCreate9>(GetProcAddress(hD3D, d3d9FnName.c_str())); - if (! d3dcreate9) { + pDirect3DCreate9 d3dcreate9 = reinterpret_cast< pDirect3DCreate9 >(GetProcAddress(hD3D, d3d9FnName.c_str())); + if (!d3dcreate9) { ods(("D3D9: Library without " + d3d9FnName).c_str()); } else { - if (!IsFnInModule(reinterpret_cast<voidFunc>(d3dcreate9), d3dd->wcFileName, "D3D9", d3d9FnName)) { + if (!IsFnInModule(reinterpret_cast< voidFunc >(d3dcreate9), d3dd->wcFileName, "D3D9", d3d9FnName)) { ods(("D3D9: " + d3d9FnName + " is not in D3D9 library").c_str()); } else { IDirect3D9 *id3d9 = d3dcreate9(D3D_SDK_VERSION); @@ -1085,43 +1094,49 @@ extern "C" __declspec(dllexport) void __cdecl PrepareD3D9() { void *pCreate = (*vtbl)[VTABLE_OFFSET_ID3D_CREATEDEVICE]; - if (!IsFnInModule(reinterpret_cast<voidFunc>(pCreate), d3dd->wcFileName, "D3D9", "CreateDevice")) { + if (!IsFnInModule(reinterpret_cast< voidFunc >(pCreate), d3dd->wcFileName, "D3D9", + "CreateDevice")) { ods("D3D9: CreateDevice is not in D3D9 library"); } else { - size_t fn = reinterpret_cast<size_t>(pCreate); - size_t base = reinterpret_cast<size_t>(hD3D); + size_t fn = reinterpret_cast< size_t >(pCreate); + size_t base = reinterpret_cast< size_t >(hD3D); d3dd->offsetCreate = fn - base; - ods("D3D9: Successfully found prepatch offset: %p %p %p: %d", hD3D, d3dcreate9, pCreate, d3dd->offsetCreate); } + ods("D3D9: Successfully found prepatch offset: %p %p %p: %d", hD3D, d3dcreate9, pCreate, + d3dd->offsetCreate); + } id3d9->Release(); } } } std::string d3d9exFnName("Direct3DCreate9Ex"); - pDirect3DCreate9Ex d3dcreate9ex = reinterpret_cast<pDirect3DCreate9Ex>(GetProcAddress(hD3D, d3d9exFnName.c_str())); - if (! d3dcreate9ex) { + pDirect3DCreate9Ex d3dcreate9ex = + reinterpret_cast< pDirect3DCreate9Ex >(GetProcAddress(hD3D, d3d9exFnName.c_str())); + if (!d3dcreate9ex) { ods(("D3D9: Library without " + d3d9exFnName).c_str()); } else { - if (!IsFnInModule(reinterpret_cast<voidFunc>(d3dcreate9ex), d3dd->wcFileName, "D3D9", d3d9exFnName)) { + if (!IsFnInModule(reinterpret_cast< voidFunc >(d3dcreate9ex), d3dd->wcFileName, "D3D9", d3d9exFnName)) { ods(("D3D9: " + d3d9exFnName + " is not in D3D9 library").c_str()); } else { - IDirect3D9Ex *id3d9 = nullptr; - d3dcreate9ex(D3D_SDK_VERSION, &id3d9); - if (id3d9) { - void ***vtbl = (void ***) id3d9; - void *pCreateEx = (*vtbl)[VTABLE_OFFSET_ID3D_CREATEDEVICE_EX]; - - if (!IsFnInModule(reinterpret_cast<voidFunc>(pCreateEx), d3dd->wcFileName, "D3D9", "CreateDeviceEx")) { - ods("D3D9: CreateDeviceEx is not in D3D9 library"); - } else { - size_t fn = reinterpret_cast<size_t>(pCreateEx); - size_t base = reinterpret_cast<size_t>(hD3D); - d3dd->offsetCreateEx = fn - base; - ods("D3D9: Successfully found prepatch ex offset: %p %p %p: %d", hD3D, d3dcreate9ex, pCreateEx, d3dd->offsetCreateEx); - } - - id3d9->Release(); + IDirect3D9Ex *id3d9 = nullptr; + d3dcreate9ex(D3D_SDK_VERSION, &id3d9); + if (id3d9) { + void ***vtbl = (void ***) id3d9; + void *pCreateEx = (*vtbl)[VTABLE_OFFSET_ID3D_CREATEDEVICE_EX]; + + if (!IsFnInModule(reinterpret_cast< voidFunc >(pCreateEx), d3dd->wcFileName, "D3D9", + "CreateDeviceEx")) { + ods("D3D9: CreateDeviceEx is not in D3D9 library"); + } else { + size_t fn = reinterpret_cast< size_t >(pCreateEx); + size_t base = reinterpret_cast< size_t >(hD3D); + d3dd->offsetCreateEx = fn - base; + ods("D3D9: Successfully found prepatch ex offset: %p %p %p: %d", hD3D, d3dcreate9ex, pCreateEx, + d3dd->offsetCreateEx); } + + id3d9->Release(); + } } } diff --git a/overlay/dxgi.cpp b/overlay/dxgi.cpp index f71da9165..3d732c231 100644 --- a/overlay/dxgi.cpp +++ b/overlay/dxgi.cpp @@ -14,13 +14,13 @@ are met: - Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. + this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. - Neither the name of the Mumble Developers nor the names of its - contributors may be used to endorse or promote products derived from this - software without specific prior written permission. + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT @@ -58,10 +58,10 @@ extern void presentD3D10(IDXGISwapChain *pSwapChain); extern void presentD3D11(IDXGISwapChain *pSwapChain); static HRESULT __stdcall myPresent(IDXGISwapChain *pSwapChain, UINT SyncInterval, UINT Flags) { - // Present is called for each frame. Thus, we do not want to always log here. - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +// Present is called for each frame. Thus, we do not want to always log here. +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("DXGI: Call to Present; Drawing and then chaining the call to the original logic"); - #endif +#endif // From this D3D-version-independent point, call the present logic for both // D3D 10 and 11. Those that apply will be executed adequately, those that @@ -69,7 +69,7 @@ static HRESULT __stdcall myPresent(IDXGISwapChain *pSwapChain, UINT SyncInterval presentD3D10(pSwapChain); presentD3D11(pSwapChain); - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. PresentType oPresent = (PresentType) hhPresent.call; hhPresent.restore(); @@ -84,15 +84,16 @@ extern void resizeD3D10(IDXGISwapChain *pSwapChain); // From d3d11.cpp extern void resizeD3D11(IDXGISwapChain *pSwapChain); -static HRESULT __stdcall myResize(IDXGISwapChain *pSwapChain, UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags) { - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +static HRESULT __stdcall myResize(IDXGISwapChain *pSwapChain, UINT BufferCount, UINT Width, UINT Height, + DXGI_FORMAT NewFormat, UINT SwapChainFlags) { +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("DXGI: Call to Resize. Forwarding to D3D10 and D3D11 custom implementations before calling original logic ..."); - #endif +#endif resizeD3D10(pSwapChain); resizeD3D11(pSwapChain); - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. ResizeBuffersType oResize = (ResizeBuffersType) hhResize.call; hhResize.restore(); @@ -103,12 +104,12 @@ static HRESULT __stdcall myResize(IDXGISwapChain *pSwapChain, UINT BufferCount, static void HookPresentRaw(voidFunc vfPresent) { ods("DXGI: Injecting Present"); - hhPresent.setup(vfPresent, reinterpret_cast<voidFunc>(myPresent)); + hhPresent.setup(vfPresent, reinterpret_cast< voidFunc >(myPresent)); } static void HookResizeRaw(voidFunc vfResize) { ods("DXGI: Injecting ResizeBuffers Raw"); - hhResize.setup(vfResize, reinterpret_cast<voidFunc>(myResize)); + hhResize.setup(vfResize, reinterpret_cast< voidFunc >(myResize)); } void hookDXGI(HMODULE hDXGI, bool preonly); @@ -128,13 +129,13 @@ void checkDXGIHook(bool preonly) { HMODULE hDXGI = GetModuleHandleW(L"DXGI.DLL"); if (hDXGI) { - if (! bHooked) { + if (!bHooked) { hookDXGI(hDXGI, preonly); } - #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT +#ifdef EXTENDED_OVERLAY_DEBUGOUTPUT } else { ods("DXGI: No DXGI.DLL found as loaded. No hooking at this point."); - #endif +#endif } bCheckHookActive = false; @@ -148,7 +149,7 @@ void hookDXGI(HMODULE hDXGI, 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>(&hookDXGI), &hTempSelf); + GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast< LPCTSTR >(&hookDXGI), &hTempSelf); bHooked = true; @@ -161,7 +162,7 @@ void hookDXGI(HMODULE hDXGI, bool preonly) { HookPresentRaw((voidFunc)(raw + dxgi->offsetPresent)); HookResizeRaw((voidFunc)(raw + dxgi->offsetResize)); - } else if (! preonly) { + } else if (!preonly) { ods("DXGI: Interface changed, can't rawpatch. Current: %ls ; Previously: %ls", modulename, dxgi->wcFileName); } else { bHooked = false; @@ -171,27 +172,27 @@ void hookDXGI(HMODULE hDXGI, bool preonly) { // From d3d10.cpp extern void PrepareDXGI10(IDXGIAdapter1 *pAdapter, bool initializeDXGIData); // From d3d11.cpp -extern void PrepareDXGI11(IDXGIAdapter1* pAdapter, bool initializeDXGIData); +extern void PrepareDXGI11(IDXGIAdapter1 *pAdapter, bool initializeDXGIData); /// This function is called by the Mumble client in Mumble's scope /// mainly to extract the offsets of various functions in the IDXGISwapChain /// and IDXGIObject interfaces that need to be hooked in target /// applications. The data is stored in the dxgi shared memory structure. extern "C" __declspec(dllexport) void __cdecl PrepareDXGI() { - if (! dxgi) + if (!dxgi) return; ods("DXGI: Preparing static data for DXGI Injection"); dxgi->wcFileName[0] = 0; dxgi->offsetPresent = 0; - dxgi->offsetResize = 0; + dxgi->offsetResize = 0; // Make sure this is Vista or greater as quite a number of <=WinXP users have fake DX10 libs installed OSVERSIONINFOEXW ovi; memset(&ovi, 0, sizeof(ovi)); ovi.dwOSVersionInfoSize = sizeof(ovi); - GetVersionExW(reinterpret_cast<OSVERSIONINFOW *>(&ovi)); + GetVersionExW(reinterpret_cast< OSVERSIONINFOW * >(&ovi)); if (ovi.dwMajorVersion < 6 || (ovi.dwMajorVersion == 6 && ovi.dwBuildNumber < 6001)) { ods("DXGI: No DXGI pre-Vista - skipping prepare"); return; @@ -202,11 +203,12 @@ extern "C" __declspec(dllexport) void __cdecl PrepareDXGI() { if (hDXGI) { GetModuleFileNameW(hDXGI, dxgi->wcFileName, ARRAY_NUM_ELEMENTS(dxgi->wcFileName)); - CreateDXGIFactory1Type pCreateDXGIFactory1 = reinterpret_cast<CreateDXGIFactory1Type>(GetProcAddress(hDXGI, "CreateDXGIFactory1")); + CreateDXGIFactory1Type pCreateDXGIFactory1 = + reinterpret_cast< CreateDXGIFactory1Type >(GetProcAddress(hDXGI, "CreateDXGIFactory1")); ods("DXGI: Got CreateDXGIFactory1 at %p", pCreateDXGIFactory1); if (pCreateDXGIFactory1) { - IDXGIFactory1 * pFactory; - HRESULT hr = pCreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&pFactory)); + IDXGIFactory1 *pFactory; + HRESULT hr = pCreateDXGIFactory1(__uuidof(IDXGIFactory1), (void **) (&pFactory)); if (FAILED(hr)) ods("DXGI: Call to pCreateDXGIFactory1 failed!"); if (pFactory) { diff --git a/overlay/excludecheck.cpp b/overlay/excludecheck.cpp index 6d5a4d262..9821641e6 100644 --- a/overlay/excludecheck.cpp +++ b/overlay/excludecheck.cpp @@ -3,10 +3,10 @@ // that can be found in the LICENSE file at the root of the // Mumble source tree or at <https://www.mumble.info/LICENSE>. +#include "ancestor.h" #include "lib.h" #include "olsettings.h" #include "util.h" -#include "ancestor.h" #include <algorithm> #include <string> @@ -15,10 +15,10 @@ static bool bExcludeCheckInitialized = false; static OverlayExclusionMode oemExcludeMode = LauncherFilterExclusionMode; -static std::vector<std::string> vLaunchers; -static std::vector<std::string> vWhitelist; -static std::vector<std::string> vPaths; -static std::vector<std::string> vBlacklist; +static std::vector< std::string > vLaunchers; +static std::vector< std::string > vWhitelist; +static std::vector< std::string > vPaths; +static std::vector< std::string > vBlacklist; /// Ensure the ExcludeCheck module is initialized. static void ExcludeCheckEnsureInitialized() { @@ -27,10 +27,10 @@ static void ExcludeCheckEnsureInitialized() { } oemExcludeMode = SettingsGetExclusionMode(); - vLaunchers = SettingsGetLaunchers(); - vWhitelist = SettingsGetWhitelist(); - vPaths = SettingsGetPaths(); - vBlacklist = SettingsGetBlacklist(); + vLaunchers = SettingsGetLaunchers(); + vWhitelist = SettingsGetWhitelist(); + vPaths = SettingsGetPaths(); + vBlacklist = SettingsGetBlacklist(); bExcludeCheckInitialized = true; } @@ -41,7 +41,7 @@ static void ExcludeCheckEnsureInitialized() { /// Note that programs that are added as launchers /// are also implicitly treated as being blacklisted. static bool isBlacklistedExe(const std::string &absExeName, const std::string &exeName) { - std::vector<string> combinedBlacklist = vmerge(vBlacklist, vLaunchers); + std::vector< string > combinedBlacklist = vmerge(vBlacklist, vLaunchers); for (size_t i = 0; i < combinedBlacklist.size(); i++) { std::string &val = combinedBlacklist.at(i); if (isAbsPath(val)) { @@ -92,7 +92,8 @@ static bool isWhitelistedPath(const std::string &absExeName) { /// |absAncestorExeNames| (or |ancestorExeNames|, /// for relative paths) is in the Mumble overlay's /// launcher whitelist. -static bool hasWhitelistedAncestor(const std::vector<std::string> &absAncestorExeNames, const std::vector<std::string> &ancestorExeNames) { +static bool hasWhitelistedAncestor(const std::vector< std::string > &absAncestorExeNames, + const std::vector< std::string > &ancestorExeNames) { for (size_t i = 0; i < vLaunchers.size(); i++) { std::string &val = vLaunchers.at(i); if (isAbsPath(val)) { @@ -112,7 +113,7 @@ bool ExcludeCheckIsOverlayEnabled(std::string absExeName_, std::string exeName_) bool enableOverlay = true; std::string absExeName = slowercase(absExeName_); - std::string exeName = slowercase(exeName_); + std::string exeName = slowercase(exeName_); ExcludeCheckEnsureInitialized(); @@ -120,19 +121,19 @@ bool ExcludeCheckIsOverlayEnabled(std::string absExeName_, std::string exeName_) case LauncherFilterExclusionMode: { ods("ExcludeCheck: using 'launcher filter' exclusion mode..."); - std::vector<std::string> absAncestorExeNames; - std::vector<std::string> ancestorExeNames; + std::vector< std::string > absAncestorExeNames; + std::vector< std::string > ancestorExeNames; if (!GetProcessAncestorChain(absAncestorExeNames, ancestorExeNames)) { // Unable to get ancestor chain. Process is allowed. ods("ExcludeCheck: Unable to find parent. Process allowed."); enableOverlay = true; } absAncestorExeNames = vlowercase(absAncestorExeNames); - ancestorExeNames = vlowercase(ancestorExeNames); + ancestorExeNames = vlowercase(ancestorExeNames); for (size_t i = 0; i < absAncestorExeNames.size(); i++) { std::string absAncestorExeName = absAncestorExeNames.at(i); - ods("ExcludeCheck: Ancestor #%i is '%s'", i+1, absAncestorExeName.c_str()); + ods("ExcludeCheck: Ancestor #%i is '%s'", i + 1, absAncestorExeName.c_str()); } // The blacklist always wins. @@ -140,25 +141,25 @@ bool ExcludeCheckIsOverlayEnabled(std::string absExeName_, std::string exeName_) if (isBlacklistedExe(absExeName, exeName)) { ods("ExcludeCheck: '%s' is blacklisted. Overlay disabled.", absExeName.c_str()); enableOverlay = false; - // If the process's exe name is whitelisted, allow the overlay to be shown. + // If the process's exe name is whitelisted, allow the overlay to be shown. } else if (isWhitelistedExe(absExeName, exeName)) { ods("ExcludeCheck: '%s' is whitelisted. Overlay enabled.", absExeName.c_str()); enableOverlay = true; - // If the exe is within a whitelisted path, allow the overlay to be shown. - // An example is: - // Whitelisted path: d:\games - // absExeName: d:\games\World of Warcraft\Wow-64.exe - // The overlay would be shown in WoW (and any game that lives under d:\games) + // If the exe is within a whitelisted path, allow the overlay to be shown. + // An example is: + // Whitelisted path: d:\games + // absExeName: d:\games\World of Warcraft\Wow-64.exe + // The overlay would be shown in WoW (and any game that lives under d:\games) } else if (isWhitelistedPath(absExeName)) { ods("ExcludeCheck: '%s' is within a whitelisted path. Overlay enabled.", absExeName.c_str()); enableOverlay = true; - // If any of the process's ancestors are whitelisted, allow the process through. - // This allows us to whitelist Steam.exe, etc. -- and have the overlay - // show up in all Steam titles. + // If any of the process's ancestors are whitelisted, allow the process through. + // This allows us to whitelist Steam.exe, etc. -- and have the overlay + // show up in all Steam titles. } else if (hasWhitelistedAncestor(absAncestorExeNames, ancestorExeNames)) { ods("ExcludeCheck: An ancestor of '%s' is whitelisted. Overlay enabled.", exeName.c_str()); enableOverlay = true; - // If nothing matched, do not show the overlay. + // If nothing matched, do not show the overlay. } else { ods("ExcludeCheck: No matching overlay exclusion rule found. Overlay disabled."); enableOverlay = false; diff --git a/overlay/lib.cpp b/overlay/lib.cpp index 779b6ada2..6be0b2fed 100644 --- a/overlay/lib.cpp +++ b/overlay/lib.cpp @@ -10,12 +10,12 @@ static HANDLE hMapObject = nullptr; static HANDLE hHookMutex = nullptr; -static HHOOK hhookWnd = 0; +static HHOOK hhookWnd = 0; BOOL bIsWin8 = FALSE; -static BOOL bMumble = FALSE; -static BOOL bDebug = FALSE; +static BOOL bMumble = FALSE; +static BOOL bDebug = FALSE; static BOOL bEnableOverlay = TRUE; static HardHook hhLoad; @@ -30,7 +30,7 @@ void Mutex::init() { } Mutex::Mutex() { - if (! TryEnterCriticalSection(&cs)) { + if (!TryEnterCriticalSection(&cs)) { ods("Lib: Mutex: CritFail - blocking until able to enter critical section"); EnterCriticalSection(&cs); } @@ -60,8 +60,8 @@ void __cdecl checkForWPF() { } Pipe::Pipe() { - hSocket = INVALID_HANDLE_VALUE; - hMemory = nullptr; + hSocket = INVALID_HANDLE_VALUE; + hMemory = nullptr; a_ucTexture = nullptr; omMsg.omh.iLength = -1; @@ -96,8 +96,8 @@ void Pipe::disconnect() { CloseHandle(hSocket); hSocket = INVALID_HANDLE_VALUE; } - uiWidth = 0; - uiHeight = 0; + uiWidth = 0; + uiHeight = 0; omMsg.omh.iLength = -1; } @@ -115,26 +115,27 @@ bool Pipe::sendMessage(const OverlayMsg &om) { } void Pipe::checkMessage(unsigned int width, unsigned int height) { - if (!width || ! height) + if (!width || !height) return; if (hSocket == INVALID_HANDLE_VALUE) { - hSocket = CreateFileW(L"\\\\.\\pipe\\MumbleOverlayPipe", GENERIC_READ | GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, nullptr); + hSocket = CreateFileW(L"\\\\.\\pipe\\MumbleOverlayPipe", GENERIC_READ | GENERIC_WRITE, 0, nullptr, + OPEN_EXISTING, 0, nullptr); if (hSocket == INVALID_HANDLE_VALUE) { ods("Pipe: Connection failed"); return; } ods("Pipe: Connected"); - uiWidth = 0; + uiWidth = 0; uiHeight = 0; // initially, instantiate and send an OverlayMessage with the current process id OverlayMsg om; om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; - om.omh.uiType = OVERLAY_MSGTYPE_PID; + om.omh.uiType = OVERLAY_MSGTYPE_PID; om.omh.iLength = sizeof(OverlayMsgPid); - om.omp.pid = GetCurrentProcessId(); + om.omp.pid = GetCurrentProcessId(); if (!sendMessage(om)) return; @@ -146,15 +147,15 @@ void Pipe::checkMessage(unsigned int width, unsigned int height) { if ((uiWidth != width) || (uiHeight != height)) { release(); - uiWidth = width; + uiWidth = width; uiHeight = height; // instantiate and send an initialization-OverlayMessage OverlayMsg om; - om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; - om.omh.uiType = OVERLAY_MSGTYPE_INIT; - om.omh.iLength = sizeof(OverlayMsgInit); - om.omi.uiWidth = uiWidth; + om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; + om.omh.uiType = OVERLAY_MSGTYPE_INIT; + om.omh.iLength = sizeof(OverlayMsgInit); + om.omi.uiWidth = uiWidth; om.omi.uiHeight = uiHeight; if (!sendMessage(om)) @@ -163,23 +164,24 @@ void Pipe::checkMessage(unsigned int width, unsigned int height) { ods("Pipe: SentInitMsg with w h %d %d", uiWidth, uiHeight); } - std::vector<RECT> blits; + std::vector< RECT > blits; while (1) { DWORD dwBytesLeft; DWORD dwBytesRead; - if (! PeekNamedPipe(hSocket, nullptr, 0, nullptr, &dwBytesLeft, nullptr)) { + if (!PeekNamedPipe(hSocket, nullptr, 0, nullptr, &dwBytesLeft, nullptr)) { ods("Pipe: Could not peek"); disconnect(); return; } - if (! dwBytesLeft) + if (!dwBytesLeft) break; if (omMsg.omh.iLength == -1) { - if (! ReadFile(hSocket, reinterpret_cast<unsigned char *>(omMsg.headerbuffer) + dwAlreadyRead, sizeof(OverlayMsgHeader) - dwAlreadyRead, &dwBytesRead, nullptr)) { + if (!ReadFile(hSocket, reinterpret_cast< unsigned char * >(omMsg.headerbuffer) + dwAlreadyRead, + sizeof(OverlayMsgHeader) - dwAlreadyRead, &dwBytesRead, nullptr)) { ods("Pipe: Read header fail"); disconnect(); return; @@ -200,11 +202,12 @@ void Pipe::checkMessage(unsigned int width, unsigned int height) { return; } - if (static_cast<int>(dwBytesLeft) < omMsg.omh.iLength) + if (static_cast< int >(dwBytesLeft) < omMsg.omh.iLength) continue; } - if (! ReadFile(hSocket, reinterpret_cast<unsigned char *>(omMsg.msgbuffer) + dwAlreadyRead, omMsg.omh.iLength - dwAlreadyRead, &dwBytesRead, nullptr)) { + if (!ReadFile(hSocket, reinterpret_cast< unsigned char * >(omMsg.msgbuffer) + dwAlreadyRead, + omMsg.omh.iLength - dwAlreadyRead, &dwBytesRead, nullptr)) { ods("Pipe: Read data fail"); disconnect(); return; @@ -212,101 +215,97 @@ void Pipe::checkMessage(unsigned int width, unsigned int height) { dwAlreadyRead += dwBytesRead; - if (static_cast<int>(dwBytesLeft) < omMsg.omh.iLength) + if (static_cast< int >(dwBytesLeft) < omMsg.omh.iLength) continue; dwAlreadyRead = 0; switch (omMsg.omh.uiType) { case OVERLAY_MSGTYPE_SHMEM: { - wchar_t memname[2048]; - memname[0] = 0; - - MultiByteToWideChar(CP_UTF8, 0, omMsg.oms.a_cName, omMsg.omh.iLength, memname, 2048); - - release(); + wchar_t memname[2048]; + memname[0] = 0; - hMemory = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, uiWidth * uiHeight * 4, memname); + MultiByteToWideChar(CP_UTF8, 0, omMsg.oms.a_cName, omMsg.omh.iLength, memname, 2048); - if (GetLastError() != ERROR_ALREADY_EXISTS) { - ods("Pipe: Memory %s(%d) => %ls doesn't exist", omMsg.oms.a_cName, omMsg.omh.iLength, memname); - if (hMemory) { - CloseHandle(hMemory); - hMemory = nullptr; - break; - } - } - - if (! hMemory) { - ods("Pipe: CreateFileMapping failed"); - break; - } + release(); - a_ucTexture = reinterpret_cast<unsigned char *>(MapViewOfFile(hMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0)); + hMemory = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, uiWidth * uiHeight * 4, + memname); - if (!a_ucTexture) { - ods("Pipe: Failed to map memory"); + if (GetLastError() != ERROR_ALREADY_EXISTS) { + ods("Pipe: Memory %s(%d) => %ls doesn't exist", omMsg.oms.a_cName, omMsg.omh.iLength, memname); + if (hMemory) { CloseHandle(hMemory); hMemory = nullptr; break; } + } - MEMORY_BASIC_INFORMATION mbi; - memset(&mbi, 0, sizeof(mbi)); - if ((VirtualQuery(a_ucTexture, &mbi, sizeof(mbi)) == 0) || (mbi.RegionSize < (uiHeight * uiWidth * 4))) { - ods("Pipe: Memory too small"); - UnmapViewOfFile(a_ucTexture); - CloseHandle(hMemory); - a_ucTexture = nullptr; - hMemory = nullptr; - break; - } + if (!hMemory) { + ods("Pipe: CreateFileMapping failed"); + break; + } - OverlayMsg om; - om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; - om.omh.uiType = OVERLAY_MSGTYPE_SHMEM; - om.omh.iLength = 0; + a_ucTexture = reinterpret_cast< unsigned char * >(MapViewOfFile(hMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0)); - if (!sendMessage(om)) - return; + if (!a_ucTexture) { + ods("Pipe: Failed to map memory"); + CloseHandle(hMemory); + hMemory = nullptr; + break; + } - newTexture(uiWidth, uiHeight); + MEMORY_BASIC_INFORMATION mbi; + memset(&mbi, 0, sizeof(mbi)); + if ((VirtualQuery(a_ucTexture, &mbi, sizeof(mbi)) == 0) + || (mbi.RegionSize < (uiHeight * uiWidth * 4))) { + ods("Pipe: Memory too small"); + UnmapViewOfFile(a_ucTexture); + CloseHandle(hMemory); + a_ucTexture = nullptr; + hMemory = nullptr; + break; } - break; + + OverlayMsg om; + om.omh.uiMagic = OVERLAY_MAGIC_NUMBER; + om.omh.uiType = OVERLAY_MSGTYPE_SHMEM; + om.omh.iLength = 0; + + if (!sendMessage(om)) + return; + + newTexture(uiWidth, uiHeight); + } break; case OVERLAY_MSGTYPE_BLIT: { - RECT r = { - static_cast<LONG>(omMsg.omb.x), - static_cast<LONG>(omMsg.omb.y), - static_cast<LONG>(omMsg.omb.x + omMsg.omb.w), - static_cast<LONG>(omMsg.omb.y + omMsg.omb.h) - }; - - std::vector<RECT>::iterator i = blits.begin(); - while (i != blits.end()) { - RECT is; - if (::IntersectRect(&is, &r, & *i)) { - ::UnionRect(&is, &r, & *i); - r = is; - blits.erase(i); - i = blits.begin(); - } else { - ++i; - } + RECT r = { static_cast< LONG >(omMsg.omb.x), static_cast< LONG >(omMsg.omb.y), + static_cast< LONG >(omMsg.omb.x + omMsg.omb.w), + static_cast< LONG >(omMsg.omb.y + omMsg.omb.h) }; + + std::vector< RECT >::iterator i = blits.begin(); + while (i != blits.end()) { + RECT is; + if (::IntersectRect(&is, &r, &*i)) { + ::UnionRect(&is, &r, &*i); + r = is; + blits.erase(i); + i = blits.begin(); + } else { + ++i; } - blits.push_back(r); } - break; + blits.push_back(r); + } break; case OVERLAY_MSGTYPE_ACTIVE: { - uiLeft = omMsg.oma.x; - uiTop = omMsg.oma.y; - uiRight = omMsg.oma.x + omMsg.oma.w; - uiBottom = omMsg.oma.y + omMsg.oma.h; - if (a_ucTexture) { - setRect(); - blit(0, 0, uiWidth, uiHeight); - } + uiLeft = omMsg.oma.x; + uiTop = omMsg.oma.y; + uiRight = omMsg.oma.x + omMsg.oma.w; + uiBottom = omMsg.oma.y + omMsg.oma.h; + if (a_ucTexture) { + setRect(); + blit(0, 0, uiWidth, uiHeight); } - break; + } break; default: break; } @@ -316,7 +315,7 @@ void Pipe::checkMessage(unsigned int width, unsigned int height) { if (!a_ucTexture) return; - for (std::vector<RECT>::iterator i = blits.begin(); i != blits.end(); ++i) + for (std::vector< RECT >::iterator i = blits.begin(); i != blits.end(); ++i) blit((*i).left, (*i).top, (*i).right - (*i).left, (*i).bottom - (*i).top); } @@ -330,7 +329,7 @@ static void checkHooks(bool preonly) { typedef HMODULE(__stdcall *LoadLibraryAType)(const char *); static HMODULE WINAPI MyLoadLibrary(const char *lpFileName) { - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. LoadLibraryAType oLoadLibrary = (LoadLibraryAType) hhLoad.call; hhLoad.restore(); @@ -348,7 +347,7 @@ static HMODULE WINAPI MyLoadLibrary(const char *lpFileName) { typedef HMODULE(__stdcall *LoadLibraryWType)(const wchar_t *); static HMODULE WINAPI MyLoadLibraryW(const wchar_t *lpFileName) { - //TODO: Move logic to HardHook. + // TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. LoadLibraryWType oLoadLibrary = (LoadLibraryWType) hhLoadW.call; hhLoadW.restore(); @@ -387,9 +386,10 @@ extern "C" __declspec(dllexport) void __cdecl RemoveHooks() { extern "C" __declspec(dllexport) void __cdecl InstallHooks() { DWORD dwWaitResult = WaitForSingleObject(hHookMutex, 1000L); if (dwWaitResult == WAIT_OBJECT_0) { - if (sd && ! sd->bHooked) { + if (sd && !sd->bHooked) { HMODULE hSelf = nullptr; - GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast<LPCTSTR>(&InstallHooks), &hSelf); + GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast< LPCTSTR >(&InstallHooks), &hSelf); if (!hSelf) { ods("Lib: Failed to find myself"); } else { @@ -414,8 +414,8 @@ extern "C" __declspec(dllexport) void __cdecl PrepareD3D9(); extern "C" __declspec(dllexport) void __cdecl PrepareDXGI(); void __stdcall OverlayHelperProcessParentDeathThread(void *udata) { - HANDLE parent = reinterpret_cast<HANDLE>(udata); - DWORD status = WaitForSingleObject(parent, INFINITE); + HANDLE parent = reinterpret_cast< HANDLE >(udata); + DWORD status = WaitForSingleObject(parent, INFINITE); if (status != WAIT_OBJECT_0) { ExitProcess(OVERLAY_HELPER_ERROR_DLL_PDEATH_WAIT_FAIL); } @@ -431,7 +431,7 @@ extern "C" __declspec(dllexport) int __cdecl OverlayHelperProcessMain(unsigned i } HANDLE pcheckHandle = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE) OverlayHelperProcessParentDeathThread, - reinterpret_cast<void *>(parent), 0, nullptr); + reinterpret_cast< void * >(parent), 0, nullptr); if (pcheckHandle == 0) { return OVERLAY_HELPER_ERROR_DLL_PDEATH_THREAD_ERROR; } @@ -478,7 +478,8 @@ static bool createSharedDataMap(); // we shouldn't inject into it. static void checkNoOverlayFile(const std::string &dir) { std::string nooverlay = dir + "\\nooverlay"; - HANDLE h = CreateFile(nooverlay.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + HANDLE h = CreateFile(nooverlay.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, nullptr); if (h != INVALID_HANDLE_VALUE) { CloseHandle(h); ods("Lib: Overlay disable %s found", dir.c_str()); @@ -493,7 +494,8 @@ static void checkNoOverlayFile(const std::string &dir) { static void checkDebugOverlayFile(const std::string &dir) { // check for "debugoverlay" file, which would enable overlay debugging std::string debugoverlay = dir + "\\debugoverlay"; - HANDLE h = CreateFile(debugoverlay.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + HANDLE h = CreateFile(debugoverlay.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, nullptr); if (h != INVALID_HANDLE_VALUE) { CloseHandle(h); ods("Lib: Overlay debug %s found", debugoverlay.c_str()); @@ -519,8 +521,8 @@ static bool parseProcName(char *procname, std::string &absExeName, std::string & } absExeName = std::string(procname); - dir = std::string(procname, p - procname); - exeName = std::string(p + 1); + dir = std::string(procname, p - procname); + exeName = std::string(p + 1); return true; } @@ -538,7 +540,7 @@ static bool dllmainProcAttach(char *procname) { } else if (GetProcAddress(nullptr, "mumbleSelfDetection")) { ods("Lib: Attached to overlay helper or Mumble process. Blacklisted - no overlay injection."); bEnableOverlay = FALSE; - bMumble = TRUE; + bMumble = TRUE; } else { checkNoOverlayFile(dir); checkDebugOverlayFile(dir); @@ -555,7 +557,7 @@ static bool dllmainProcAttach(char *procname) { OSVERSIONINFOEX ovi; memset(&ovi, 0, sizeof(ovi)); ovi.dwOSVersionInfoSize = sizeof(ovi); - GetVersionEx(reinterpret_cast<OSVERSIONINFO *>(&ovi)); + GetVersionEx(reinterpret_cast< OSVERSIONINFO * >(&ovi)); bIsWin8 = (ovi.dwMajorVersion >= 7) || ((ovi.dwMajorVersion == 6) && (ovi.dwBuildNumber >= 9200)); ods("Lib: bIsWin8: %i", bIsWin8); @@ -567,13 +569,13 @@ static bool dllmainProcAttach(char *procname) { return false; } - if(!createSharedDataMap()) + if (!createSharedDataMap()) return false; - if (! bMumble) { + if (!bMumble) { // Hook our own LoadLibrary functions so we notice when a new library (like the d3d ones) is loaded. - hhLoad.setup(reinterpret_cast<voidFunc>(LoadLibraryA), reinterpret_cast<voidFunc>(MyLoadLibrary)); - hhLoadW.setup(reinterpret_cast<voidFunc>(LoadLibraryW), reinterpret_cast<voidFunc>(MyLoadLibraryW)); + hhLoad.setup(reinterpret_cast< voidFunc >(LoadLibraryA), reinterpret_cast< voidFunc >(MyLoadLibrary)); + hhLoadW.setup(reinterpret_cast< voidFunc >(LoadLibraryW), reinterpret_cast< voidFunc >(MyLoadLibraryW)); checkHooks(true); ods("Lib: Injected into %s", procname); @@ -583,14 +585,15 @@ static bool dllmainProcAttach(char *procname) { } static bool createSharedDataMap() { - DWORD dwSharedSize = sizeof(SharedData) + sizeof(Direct3D9Data) + sizeof(DXGIData) + sizeof(D3D10Data) + sizeof(D3D11Data); + DWORD dwSharedSize = + sizeof(SharedData) + sizeof(Direct3D9Data) + sizeof(DXGIData) + sizeof(D3D10Data) + sizeof(D3D11Data); #if defined(_M_IX86) const char *name = "MumbleOverlayPrivate-x86"; #elif defined(_M_X64) const char *name = "MumbleOverlayPrivate-x64"; #else -# error Unsupported architecture +# error Unsupported architecture #endif hMapObject = CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, dwSharedSize, name); @@ -599,11 +602,11 @@ static bool createSharedDataMap() { return false; } - //Note: If the mapping exists dwSharedSize value will be ignored and existing handle returned + // Note: If the mapping exists dwSharedSize value will be ignored and existing handle returned bool bInit = (GetLastError() != ERROR_ALREADY_EXISTS); - unsigned char *rawSharedPointer = static_cast<unsigned char *>( - MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, dwSharedSize)); + unsigned char *rawSharedPointer = + static_cast< unsigned char * >(MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, dwSharedSize)); if (!rawSharedPointer) { ods("Lib: MapViewOfFile failed"); @@ -613,26 +616,25 @@ static bool createSharedDataMap() { if (bInit) memset(rawSharedPointer, 0, dwSharedSize); - sd = reinterpret_cast<SharedData *>(rawSharedPointer); + sd = reinterpret_cast< SharedData * >(rawSharedPointer); rawSharedPointer += sizeof(SharedData); - d3dd = reinterpret_cast<Direct3D9Data *>(rawSharedPointer); + d3dd = reinterpret_cast< Direct3D9Data * >(rawSharedPointer); rawSharedPointer += sizeof(Direct3D9Data); - dxgi = reinterpret_cast<DXGIData *>(rawSharedPointer); + dxgi = reinterpret_cast< DXGIData * >(rawSharedPointer); rawSharedPointer += sizeof(DXGIData); - d3d10 = reinterpret_cast<D3D10Data *>(rawSharedPointer); + d3d10 = reinterpret_cast< D3D10Data * >(rawSharedPointer); rawSharedPointer += sizeof(D3D10Data); - d3d11 = reinterpret_cast<D3D11Data *>(rawSharedPointer); + d3d11 = reinterpret_cast< D3D11Data * >(rawSharedPointer); rawSharedPointer += sizeof(D3D11Data); return true; } static void dllmainProcDetach() { - hhLoad.restore(true); hhLoad.reset(); hhLoadW.restore(true); @@ -648,7 +650,7 @@ static void dllmainProcDetach() { static void dllmainThreadAttach() { static bool bTriedHook = false; - if (bEnableOverlay && sd && ! bTriedHook) { + if (bEnableOverlay && sd && !bTriedHook) { bTriedHook = true; checkForWPF(); @@ -688,12 +690,11 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) { } bool IsFnInModule(voidFunc fnptr, wchar_t *refmodulepath, const std::string &logPrefix, const std::string &fnName) { - HMODULE hModule = nullptr; - BOOL success = GetModuleHandleEx( - GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, - reinterpret_cast<LPCTSTR>(fnptr), &hModule); + BOOL success = + GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast< LPCTSTR >(fnptr), &hModule); if (!success) { ods((logPrefix + ": Failed to get module for " + fnName).c_str()); } else { @@ -704,11 +705,12 @@ bool IsFnInModule(voidFunc fnptr, wchar_t *refmodulepath, const std::string &log return false; } -boost::optional<size_t> GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, unsigned int refmodulepathLen, const std::string &logPrefix, const std::string &fnName) { - +boost::optional< size_t > GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, unsigned int refmodulepathLen, + const std::string &logPrefix, const std::string &fnName) { HMODULE hModule = nullptr; - if (! GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, reinterpret_cast<LPCTSTR>(fnptr), &hModule)) { + if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + reinterpret_cast< LPCTSTR >(fnptr), &hModule)) { ods((logPrefix + ": Failed to get module for " + fnName).c_str()); return boost::none; } @@ -720,13 +722,16 @@ boost::optional<size_t> GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepa wchar_t modulename[MODULEFILEPATH_BUFLEN]; GetModuleFileNameW(hModule, modulename, ARRAY_NUM_ELEMENTS(modulename)); if (_wcsicmp(modulename, refmodulepath) != 0) { - ods((logPrefix + ": " + fnName + " functions module path does not match previously found. Now: '%ls', Previously: '%ls'").c_str(), modulename, refmodulepath); + ods((logPrefix + ": " + fnName + + " functions module path does not match previously found. Now: '%ls', Previously: '%ls'") + .c_str(), + modulename, refmodulepath); return boost::none; } } - size_t fn = reinterpret_cast<size_t>(fnptr); - size_t base = reinterpret_cast<size_t>(hModule); + size_t fn = reinterpret_cast< size_t >(fnptr); + size_t base = reinterpret_cast< size_t >(hModule); return fn - base; } diff --git a/overlay/lib.h b/overlay/lib.h index 0327da971..96ddee91b 100644 --- a/overlay/lib.h +++ b/overlay/lib.h @@ -8,34 +8,34 @@ #define _UNICODE #ifdef _WIN32_WINNT -# undef _WIN32_WINNT +# undef _WIN32_WINNT #endif -#define _WIN32_WINNT 0x0501 -#include <stdio.h> -#include <stdarg.h> -#include <ctype.h> +#define _WIN32_WINNT 0x0501 #include <windows.h> +#include "HardHook.h" +#include "ods.h" +#include "overlay.h" +#include <boost/optional.hpp> #include <cmath> +#include <ctype.h> #include <map> -#include <vector> +#include <stdarg.h> +#include <stdio.h> #include <string> -#include <boost/optional.hpp> -#include "overlay.h" -#include "HardHook.h" -#include "ods.h" +#include <vector> -#define lround(x) static_cast<long int>((x) + (((x) >= 0.0) ? 0.5 : -0.5)) +#define lround(x) static_cast< long int >((x) + (((x) >= 0.0) ? 0.5 : -0.5)) #define ARRAY_SIZE_BYTES(x) sizeof(x) -#define ARRAY_NUM_ELEMENTS(x) (sizeof(x)/sizeof((x)[0])) +#define ARRAY_NUM_ELEMENTS(x) (sizeof(x) / sizeof((x)[0])) using namespace std; void __cdecl ods(const char *format, ...); -const int MODULEFILEPATH_BUFLEN = 2048; -const int PROCNAMEFILEPATH_BUFLEN = 1024; -const int PROCNAMEFILEPATH_EXTENDED_EXTLEN = 64; +const int MODULEFILEPATH_BUFLEN = 2048; +const int PROCNAMEFILEPATH_BUFLEN = 1024; +const int PROCNAMEFILEPATH_EXTENDED_EXTLEN = 64; const int PROCNAMEFILEPATH_EXTENDED_BUFFER_BUFLEN = PROCNAMEFILEPATH_BUFLEN + PROCNAMEFILEPATH_EXTENDED_EXTLEN; struct Direct3D9Data { @@ -71,36 +71,39 @@ struct SharedData { }; class Mutex { - protected: - static CRITICAL_SECTION cs; - public: - static void init(); - Mutex(); - ~Mutex(); +protected: + static CRITICAL_SECTION cs; + +public: + static void init(); + Mutex(); + ~Mutex(); }; class Pipe { - private: - HANDLE hSocket; - HANDLE hMemory; - - void release(); - protected: - unsigned int uiWidth, uiHeight; - unsigned int uiLeft, uiTop, uiRight, uiBottom; - unsigned char *a_ucTexture; - DWORD dwAlreadyRead; - OverlayMsg omMsg; - - void checkMessage(unsigned int w, unsigned int h); - bool sendMessage(const OverlayMsg &m); - virtual void blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h) = 0; - virtual void setRect() = 0; - virtual void newTexture(unsigned int w, unsigned int h) = 0; - Pipe(); - virtual ~Pipe(); - public: - void disconnect(); +private: + HANDLE hSocket; + HANDLE hMemory; + + void release(); + +protected: + unsigned int uiWidth, uiHeight; + unsigned int uiLeft, uiTop, uiRight, uiBottom; + unsigned char *a_ucTexture; + DWORD dwAlreadyRead; + OverlayMsg omMsg; + + void checkMessage(unsigned int w, unsigned int h); + bool sendMessage(const OverlayMsg &m); + virtual void blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h) = 0; + virtual void setRect() = 0; + virtual void newTexture(unsigned int w, unsigned int h) = 0; + Pipe(); + virtual ~Pipe(); + +public: + void disconnect(); }; // From lib.cpp @@ -136,12 +139,15 @@ extern BOOL bIsWin8; /// @param logPrefix Used for debug logging. /// @param fnName name of the method fnptr points to. used for debug logging /// @return true if the module filepath of the function pointer matches the reference one -extern bool IsFnInModule(voidFunc fnptr, wchar_t *refmodulepath, const std::string &logPrefix, const std::string &fnName); +extern bool IsFnInModule(voidFunc fnptr, wchar_t *refmodulepath, const std::string &logPrefix, + const std::string &fnName); // From lib.cpp /// Checks fnptr is in a loaded module with module path refmodulepath. /// /// @return Offset as int or < 0 on failure. -extern boost::optional<size_t> GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, unsigned int refmodulepathLen, const std::string &logPrefix, const std::string &fnName); +extern boost::optional< size_t > GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, + unsigned int refmodulepathLen, const std::string &logPrefix, + const std::string &fnName); #endif diff --git a/overlay/ods.cpp b/overlay/ods.cpp index 4d551930d..4c7693932 100644 --- a/overlay/ods.cpp +++ b/overlay/ods.cpp @@ -3,10 +3,10 @@ // that can be found in the LICENSE file at the root of the // Mumble source tree or at <https://www.mumble.info/LICENSE>. -#include <stdio.h> -#include <ctype.h> -#include <windows.h> #include "ods.h" +#include <windows.h> +#include <ctype.h> +#include <stdio.h> void __cdecl _ods_out(const char *format, va_list *args) { char buf[4096], *p = buf + 2; diff --git a/overlay/olsettings.cpp b/overlay/olsettings.cpp index fb98c7bf6..8daef0996 100644 --- a/overlay/olsettings.cpp +++ b/overlay/olsettings.cpp @@ -9,17 +9,17 @@ #include "util.h" #include <algorithm> +#include <iterator> #include <string> #include <vector> -#include <iterator> #include "overlay_blacklist.h" -#include "overlay_whitelist.h" #include "overlay_launchers.h" +#include "overlay_whitelist.h" // Get the default blacklist (from overlay_blacklist.h) as a string vector. -static std::vector<std::string> defaultBlacklistVector() { - std::vector<std::string> out; +static std::vector< std::string > defaultBlacklistVector() { + std::vector< std::string > out; size_t i = 0; while (overlayBlacklist[i]) { out.push_back(std::string(overlayBlacklist[i])); @@ -29,8 +29,8 @@ static std::vector<std::string> defaultBlacklistVector() { } // Get the default whitelist (from overlay_whitelist.h) as a string vector. -static std::vector<std::string> defaultWhitelistVector() { - std::vector<std::string> out; +static std::vector< std::string > defaultWhitelistVector() { + std::vector< std::string > out; size_t i = 0; while (overlayWhitelist[i]) { out.push_back(std::string(overlayWhitelist[i])); @@ -40,8 +40,8 @@ static std::vector<std::string> defaultWhitelistVector() { } // Get the default launcher list (from overlay_launchers.h) as a string vector. -static std::vector<std::string> defaultLaunchersVector() { - std::vector<std::string> out; +static std::vector< std::string > defaultLaunchersVector() { + std::vector< std::string > out; size_t i = 0; while (overlayLaunchers[i]) { out.push_back(std::string(overlayLaunchers[i])); @@ -52,13 +52,11 @@ static std::vector<std::string> defaultLaunchersVector() { // Read a REG_MULTI_SZ value from the Windows registry and return it as a string vector. // Returns an empty vector on failure. -static std::vector<std::string> regReadMultiString(HKEY key, - const std::string &subKey, - const std::string &valueName) -{ +static std::vector< std::string > regReadMultiString(HKEY key, const std::string &subKey, + const std::string &valueName) { LONG err = 0; - std::vector<std::string> out; - char *buf = nullptr; + std::vector< std::string > out; + char *buf = nullptr; HKEY subKeyHandle = 0; err = RegOpenKeyExA(key, subKey.c_str(), 0, KEY_READ, &subKeyHandle); @@ -66,9 +64,9 @@ static std::vector<std::string> regReadMultiString(HKEY key, goto err; } - DWORD sz = 0; + DWORD sz = 0; DWORD type = 0; - err = RegQueryValueExA(subKeyHandle, valueName.c_str(), nullptr, &type, nullptr, &sz); + err = RegQueryValueExA(subKeyHandle, valueName.c_str(), nullptr, &type, nullptr, &sz); if (err != ERROR_SUCCESS) { goto err; } @@ -78,16 +76,16 @@ static std::vector<std::string> regReadMultiString(HKEY key, } // If the size is longer than 4MB, treat it as an error. - if (sz > 4*1024*1024) { + if (sz > 4 * 1024 * 1024) { goto err; } - buf = reinterpret_cast<char *>(malloc(sz)); + buf = reinterpret_cast< char * >(malloc(sz)); if (!buf) { goto err; } - err = RegQueryValueExA(subKeyHandle, valueName.c_str(), nullptr, &type, reinterpret_cast<BYTE *>(buf), &sz); + err = RegQueryValueExA(subKeyHandle, valueName.c_str(), nullptr, &type, reinterpret_cast< BYTE * >(buf), &sz); if (err != ERROR_SUCCESS) { goto err; } @@ -112,8 +110,8 @@ err: // Get the Mumble client's configured overlay exclusion mode as an integer. // Returns -1 if the function could not read the value from the Windows registry. static int getModeInternal() { - LONG err = 0; - HKEY key = nullptr; + LONG err = 0; + HKEY key = nullptr; DWORD mode = -1; err = RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", 0, KEY_READ, &key); @@ -122,7 +120,7 @@ static int getModeInternal() { } DWORD sz = sizeof(mode); - err = RegQueryValueExA(key, "mode", nullptr, nullptr, reinterpret_cast<BYTE *>(&mode), &sz); + err = RegQueryValueExA(key, "mode", nullptr, nullptr, reinterpret_cast< BYTE * >(&mode), &sz); if (err != ERROR_SUCCESS) { return -1; } @@ -130,7 +128,7 @@ static int getModeInternal() { return -1; } - return static_cast<int>(mode); + return static_cast< int >(mode); } OverlayExclusionMode SettingsGetExclusionMode() { @@ -140,42 +138,51 @@ OverlayExclusionMode SettingsGetExclusionMode() { // use the launcher filter. return LauncherFilterExclusionMode; } - return static_cast<OverlayExclusionMode>(mode); + return static_cast< OverlayExclusionMode >(mode); } -std::vector<std::string> SettingsGetLaunchers() { - std::vector<std::string> defaultLaunchers = vlowercase(defaultLaunchersVector()); - std::vector<std::string> userLaunchers = vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "launchers")); - std::vector<std::string> userExcludedLaunchers = vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "launchersexclude")); - std::vector<std::string> actualExcludedLaunchers = vintersect(defaultLaunchers, userExcludedLaunchers); +std::vector< std::string > SettingsGetLaunchers() { + std::vector< std::string > defaultLaunchers = vlowercase(defaultLaunchersVector()); + std::vector< std::string > userLaunchers = + vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "launchers")); + std::vector< std::string > userExcludedLaunchers = + vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "launchersexclude")); + std::vector< std::string > actualExcludedLaunchers = vintersect(defaultLaunchers, userExcludedLaunchers); return vexclude(vmerge(defaultLaunchers, userLaunchers), actualExcludedLaunchers); } -std::vector<std::string> SettingsGetWhitelist() { - std::vector<std::string> defaultWhitelist = vlowercase(defaultWhitelistVector()); +std::vector< std::string > SettingsGetWhitelist() { + std::vector< std::string > defaultWhitelist = vlowercase(defaultWhitelistVector()); // We don't consider Mumble's built-in whitelist when in WhitelistExclusionMode. // The built-in whitelist is only used in LauncherFilterExclusionMode. if (SettingsGetExclusionMode() == WhitelistExclusionMode) { - defaultWhitelist = std::vector<std::string>(); + defaultWhitelist = std::vector< std::string >(); } - std::vector<std::string> userWhitelist = vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "whitelist")); - std::vector<std::string> userExcludedWhitelistEntries = vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "whitelistexclude")); - std::vector<std::string> actualExcludedWhitelistEntries = vintersect(defaultWhitelist, userExcludedWhitelistEntries); + std::vector< std::string > userWhitelist = + vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "whitelist")); + std::vector< std::string > userExcludedWhitelistEntries = + vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "whitelistexclude")); + std::vector< std::string > actualExcludedWhitelistEntries = + vintersect(defaultWhitelist, userExcludedWhitelistEntries); return vexclude(vmerge(defaultWhitelist, userWhitelist), actualExcludedWhitelistEntries); } -std::vector<std::string> SettingsGetPaths() { - std::vector<std::string> defaultPaths; - std::vector<std::string> userPaths = vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "paths")); - std::vector<std::string> userExcludedPaths = vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "pathsexclude")); - std::vector<std::string> actualExcludedPaths = vintersect(defaultPaths, userExcludedPaths); +std::vector< std::string > SettingsGetPaths() { + std::vector< std::string > defaultPaths; + std::vector< std::string > userPaths = + vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "paths")); + std::vector< std::string > userExcludedPaths = + vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "pathsexclude")); + std::vector< std::string > actualExcludedPaths = vintersect(defaultPaths, userExcludedPaths); return vexclude(vmerge(defaultPaths, userPaths), actualExcludedPaths); } -std::vector<std::string> SettingsGetBlacklist() { - std::vector<std::string> defaultBlacklist = vlowercase(defaultBlacklistVector()); - std::vector<std::string> userBlacklist = vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "blacklist")); - std::vector<std::string> userExcludedBlacklistEntries = vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "blacklistexclude")); - std::vector<std::string> actualExcludedPaths = vintersect(defaultBlacklist, userExcludedBlacklistEntries); +std::vector< std::string > SettingsGetBlacklist() { + std::vector< std::string > defaultBlacklist = vlowercase(defaultBlacklistVector()); + std::vector< std::string > userBlacklist = + vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "blacklist")); + std::vector< std::string > userExcludedBlacklistEntries = + vlowercase(regReadMultiString(HKEY_CURRENT_USER, "Software\\Mumble\\Mumble\\overlay", "blacklistexclude")); + std::vector< std::string > actualExcludedPaths = vintersect(defaultBlacklist, userExcludedBlacklistEntries); return vexclude(vmerge(defaultBlacklist, userBlacklist), actualExcludedPaths); } diff --git a/overlay/olsettings.h b/overlay/olsettings.h index a3d221566..a251be8f4 100644 --- a/overlay/olsettings.h +++ b/overlay/olsettings.h @@ -25,18 +25,18 @@ OverlayExclusionMode SettingsGetExclusionMode(); /// Get the list of launcher programs to consider when /// checking the overlay exclusion rules. -std::vector<std::string> SettingsGetLaunchers(); +std::vector< std::string > SettingsGetLaunchers(); /// Get the list of whitelisted programs to consider when /// checking the overlay exclusion rules. -std::vector<std::string> SettingsGetWhitelist(); +std::vector< std::string > SettingsGetWhitelist(); /// Get the list of whitelisted paths to consider when /// checking the overlay exclusion rules. -std::vector<std::string> SettingsGetPaths(); +std::vector< std::string > SettingsGetPaths(); /// Get the list of blacklisted programs to consider when /// checking the overlay exclusion rules. -std::vector<std::string> SettingsGetBlacklist(); +std::vector< std::string > SettingsGetBlacklist(); #endif diff --git a/overlay/opengl.cpp b/overlay/opengl.cpp index 494e4e25b..f8645c490 100644 --- a/overlay/opengl.cpp +++ b/overlay/opengl.cpp @@ -12,72 +12,76 @@ #include "../3rdparty/GL/glext.h" -#define TDEF(ret, name, arg) typedef ret (__stdcall * t##name) arg -#define GLDEF(ret, name, arg) TDEF(ret, name, arg); t##name o##name = nullptr +#define TDEF(ret, name, arg) typedef ret(__stdcall *t##name) arg +#define GLDEF(ret, name, arg) \ + TDEF(ret, name, arg); \ + t##name o##name = nullptr GLDEF(HGLRC, wglCreateContext, (HDC)); -GLDEF(void, glGenTextures, (GLsizei, GLuint *)); -GLDEF(void, glDeleteTextures, (GLsizei, GLuint *)); +GLDEF(void, glGenTextures, (GLsizei, GLuint *) ); +GLDEF(void, glDeleteTextures, (GLsizei, GLuint *) ); GLDEF(void, glEnable, (GLenum)); GLDEF(void, glDisable, (GLenum)); GLDEF(void, glBlendFunc, (GLenum, GLenum)); GLDEF(void, glViewport, (GLint, GLint, GLsizei, GLsizei)); GLDEF(void, glMatrixMode, (GLenum)); -GLDEF(void, glLoadIdentity, (void)); +GLDEF(void, glLoadIdentity, (void) ); GLDEF(void, glOrtho, (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble)); GLDEF(void, glBindTexture, (GLenum, GLuint)); -GLDEF(void, glPushMatrix, (void)); +GLDEF(void, glPushMatrix, (void) ); GLDEF(void, glBegin, (GLenum)); -GLDEF(void, glEnd, (void)); +GLDEF(void, glEnd, (void) ); GLDEF(void, glTexCoord2f, (GLfloat, GLfloat)); GLDEF(void, glVertex2f, (GLfloat, GLfloat)); -GLDEF(void, glPopMatrix, (void)); +GLDEF(void, glPopMatrix, (void) ); GLDEF(void, glTexParameteri, (GLenum, GLenum, GLint)); GLDEF(void, glTexEnvi, (GLenum, GLenum, GLint)); -GLDEF(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *)); -GLDEF(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *)); +GLDEF(void, glTexImage2D, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, const GLvoid *) ); +GLDEF(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *) ); GLDEF(void, glPixelStorei, (GLenum, GLint)); GLDEF(void, wglMakeCurrent, (HDC, HGLRC)); -GLDEF(HGLRC, wglGetCurrentContext, (void)); -GLDEF(HDC, wglGetCurrentDC, (void)); -GLDEF(int, GetDeviceCaps, (HDC, int)); +GLDEF(HGLRC, wglGetCurrentContext, (void) ); +GLDEF(HDC, wglGetCurrentDC, (void) ); +GLDEF(int, GetDeviceCaps, (HDC, int) ); -#define INJDEF(ret, name, arg) GLDEF(ret, name, arg); static HardHook hh##name +#define INJDEF(ret, name, arg) \ + GLDEF(ret, name, arg); \ + static HardHook hh##name INJDEF(BOOL, wglSwapBuffers, (HDC)); static bool bHooked = false; class Context : protected Pipe { - public: - Context(HDC hdc); - void draw(HDC hdc); +public: + Context(HDC hdc); + void draw(HDC hdc); - protected: - virtual void blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h); - virtual void setRect(); - virtual void newTexture(unsigned int width, unsigned int height); +protected: + virtual void blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h); + virtual void setRect(); + virtual void newTexture(unsigned int width, unsigned int height); - private: - HGLRC ctx; - GLuint texture; +private: + HGLRC ctx; + GLuint texture; - clock_t timeT; - unsigned int frameCount; + clock_t timeT; + unsigned int frameCount; - void initContext(); - void doDraw(HDC hdc); + void initContext(); + void doDraw(HDC hdc); }; Context::Context(HDC hdc) { - timeT = clock(); + timeT = clock(); frameCount = 0; texture = ~0; - ctx = owglCreateContext(hdc); + ctx = owglCreateContext(hdc); HGLRC oldctx = owglGetCurrentContext(); - HDC oldhdc = owglGetCurrentDC(); + HDC oldhdc = owglGetCurrentDC(); owglMakeCurrent(hdc, ctx); initContext(); @@ -158,15 +162,15 @@ void Context::newTexture(unsigned int width, unsigned int height) { oglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); oglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - unsigned char *ptr = new unsigned char[width*height*4]; - memset(ptr, 0, width*height*4); + unsigned char *ptr = new unsigned char[width * height * 4]; + memset(ptr, 0, width * height * 4); oglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, ptr); - delete [] ptr; + delete[] ptr; } void Context::draw(HDC hdc) { HGLRC oldctx = owglGetCurrentContext(); - HDC oldhdc = owglGetCurrentDC(); + HDC oldhdc = owglGetCurrentDC(); owglMakeCurrent(hdc, ctx); doDraw(hdc); @@ -176,34 +180,34 @@ void Context::draw(HDC hdc) { void Context::doDraw(HDC hdc) { // DEBUG - //sm->bDebug = true; + // sm->bDebug = true; - 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; } unsigned int width, height; - width = oGetDeviceCaps(hdc, HORZRES); + width = oGetDeviceCaps(hdc, HORZRES); height = oGetDeviceCaps(hdc, VERTRES); HWND hwnd = WindowFromDC(hdc); if (hwnd) { RECT r; if (GetClientRect(hwnd, &r)) { - width = r.right - r.left; + width = r.right - r.left; height = r.bottom - r.top; } } @@ -224,16 +228,16 @@ void Context::doDraw(HDC hdc) { oglPushMatrix(); oglLoadIdentity(); - 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); - float top = static_cast<float>(uiTop); - float right = static_cast<float>(uiRight); - float bottom = static_cast<float>(uiBottom); + float left = static_cast< float >(uiLeft); + float top = static_cast< float >(uiTop); + float right = static_cast< float >(uiRight); + float bottom = static_cast< float >(uiBottom); - float xm = (left) / w; - float ym = (top) / h; + float xm = (left) / w; + float ym = (top) / h; float xmx = (right) / w; float ymx = (bottom) / h; @@ -254,17 +258,16 @@ void Context::doDraw(HDC hdc) { oglEnd(); oglPopMatrix(); - } -static map<HDC, Context *> contexts; +static map< HDC, Context * > contexts; static void doSwap(HDC hdc) { Context *c = contexts[hdc]; if (!c) { ods("OpenGL: New context for device %p", hdc); - c = new Context(hdc); + c = new Context(hdc); contexts[hdc] = c; } else { ods("OpenGL: Reusing old context"); @@ -277,7 +280,7 @@ static BOOL __stdcall mywglSwapBuffers(HDC hdc) { doSwap(hdc); hhwglSwapBuffers.restore(); - BOOL ret=owglSwapBuffers(hdc); + BOOL ret = owglSwapBuffers(hdc); hhwglSwapBuffers.inject(); return ret; @@ -288,15 +291,16 @@ static BOOL __stdcall mywglSwapBuffers(HDC hdc) { /// @return true if all symbols have been looked up and are available. /// Otherwise false. static bool lookupSymbols(HMODULE hGL) { -#define FNFIND(handle, name) {\ - if (!o##name) {\ - o##name = reinterpret_cast<t##name>(GetProcAddress(handle, #name));\ - if (!o##name) {\ - ods("OpenGL: Could not resolve symbol %s in %s", #name, #handle);\ - return false;\ - }\ - }\ -} +#define FNFIND(handle, name) \ + { \ + if (!o##name) { \ + o##name = reinterpret_cast< t##name >(GetProcAddress(handle, #name)); \ + if (!o##name) { \ + ods("OpenGL: Could not resolve symbol %s in %s", #name, #handle); \ + return false; \ + } \ + } \ + } if (!hGL) { return false; @@ -360,17 +364,19 @@ void checkOpenGLHook() { // 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>(&checkOpenGLHook), &hTempSelf); - -#define INJECT(handle, name) {\ - o##name = reinterpret_cast<t##name>(GetProcAddress(handle, #name));\ - if (o##name) {\ - hh##name.setup(reinterpret_cast<voidFunc>(o##name), reinterpret_cast<voidFunc>(my##name));\ - o##name = (t##name) hh##name.call;\ - } else {\ - ods("OpenGL: Could not resolve symbol %s in %s", #name, #handle);\ - }\ -} + GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast< LPCTSTR >(&checkOpenGLHook), + &hTempSelf); + +#define INJECT(handle, name) \ + { \ + o##name = reinterpret_cast< t##name >(GetProcAddress(handle, #name)); \ + if (o##name) { \ + hh##name.setup(reinterpret_cast< voidFunc >(o##name), reinterpret_cast< voidFunc >(my##name)); \ + o##name = (t##name) hh##name.call; \ + } else { \ + ods("OpenGL: Could not resolve symbol %s in %s", #name, #handle); \ + } \ + } INJECT(hGL, wglSwapBuffers); } } else { diff --git a/overlay/overlay_blacklist.h b/overlay/overlay_blacklist.h index 6a0c3bfa1..32d26ff22 100644 --- a/overlay/overlay_blacklist.h +++ b/overlay/overlay_blacklist.h @@ -7,61 +7,41 @@ #define MUMBLE_OVERLAY_BLACKLIST_H_ static const char *overlayBlacklist[] = { - "iexplore.exe", - "ieuser.exe", - "vlc.exe", - "crimecraft.exe", - "dbgview.exe", - "opera.exe", - "chrome.exe", - "acrord32.exe", - "explorer.exe", - "sihost.exe", - "ApplicationFrameHost.exe", - "dllhost.exe", - "wmpnscfg.exe", - "firefox.exe", - "thunderbird.exe", - "instantbird.exe", - "wlmail.exe", // Windows Live Suite (mshtml.dll) - "msnmsgr.exe", - "MovieMaker.exe", - "WLXPhotoGallery.exe", + "iexplore.exe", "ieuser.exe", "vlc.exe", "crimecraft.exe", "dbgview.exe", "opera.exe", "chrome.exe", "acrord32.exe", + "explorer.exe", "sihost.exe", "ApplicationFrameHost.exe", "dllhost.exe", "wmpnscfg.exe", "firefox.exe", + "thunderbird.exe", "instantbird.exe", + "wlmail.exe", // Windows Live Suite (mshtml.dll) + "msnmsgr.exe", "MovieMaker.exe", "WLXPhotoGallery.exe", "psi.exe", // Secunia PSI (uses mshtml.dll) - "Photoshop.exe", - "blender.exe", - "googleearth.exe", - "XBMC.exe", // http://xbmc.org/ - "kodi.exe", // https://kodi.tv/ - "BOXEE.exe", // http://www.boxee.tv/ - "hammer.exe", // VALVE Hammer Editor - "hlmv.exe", // Half-Life Model Viewer - "hlfaceposer.exe", // Face Poser (from Source SDK) - "LoLLauncher.exe", // League of Legends Launcher/Patcher - "acrobat.exe", // Adobe Acrobat - "Steam.exe", // Prevent invisible hooking - "RzSynapse.exe", // Prevent invisible hooking - Razer Synapse (settings online synchronization) - "IpOverUsbSvc.exe", // Windows Phone IP over USB Transport - "Origin.exe", // EA Origin - "HydraSysTray.exe", // Razer Hydra system tray - "devenv.exe", // Microsoft Visual Studio - "spotify.exe", // Spotify + "Photoshop.exe", "blender.exe", "googleearth.exe", + "XBMC.exe", // http://xbmc.org/ + "kodi.exe", // https://kodi.tv/ + "BOXEE.exe", // http://www.boxee.tv/ + "hammer.exe", // VALVE Hammer Editor + "hlmv.exe", // Half-Life Model Viewer + "hlfaceposer.exe", // Face Poser (from Source SDK) + "LoLLauncher.exe", // League of Legends Launcher/Patcher + "acrobat.exe", // Adobe Acrobat + "Steam.exe", // Prevent invisible hooking + "RzSynapse.exe", // Prevent invisible hooking - Razer Synapse (settings online synchronization) + "IpOverUsbSvc.exe", // Windows Phone IP over USB Transport + "Origin.exe", // EA Origin + "HydraSysTray.exe", // Razer Hydra system tray + "devenv.exe", // Microsoft Visual Studio + "spotify.exe", // Spotify "EpicGamesLauncher.exe", // Epic, Unreal Tournament launcher - "dwm.exe", // Windows Desktop Window Manager - "MouseKeyboardCenter.exe", - "RadeonSettings.exe", + "dwm.exe", // Windows Desktop Window Manager + "MouseKeyboardCenter.exe", "RadeonSettings.exe", "mstsc.exe", // Microsoft Remote Desktop Connection - "iCloudServices.exe", - "BethesdaNetLauncher.exe", - "GTAVLauncher.exe", + "iCloudServices.exe", "BethesdaNetLauncher.exe", "GTAVLauncher.exe", // Microsoft Office - "outlook.exe", // Outlook - "winword.exe", // Word - "excel.exe", // Excel + "outlook.exe", // Outlook + "winword.exe", // Word + "excel.exe", // Excel "powerpnt.exe", // PowerPoint - "onenote.exe", // OneNote - "mspub.exe", // Publisher + "onenote.exe", // OneNote + "mspub.exe", // Publisher "msaccess.exe", // Access nullptr diff --git a/overlay/overlay_exe/overlay_exe.cpp b/overlay/overlay_exe/overlay_exe.cpp index 460336b8b..7bca1c3de 100644 --- a/overlay/overlay_exe/overlay_exe.cpp +++ b/overlay/overlay_exe/overlay_exe.cpp @@ -4,9 +4,9 @@ // Mumble source tree or at <https://www.mumble.info/LICENSE>. #include <windows.h> +#include <shellapi.h> #include <shlwapi.h> #include <stdio.h> -#include <shellapi.h> #include <string> #include <vector> @@ -14,17 +14,17 @@ #include "../overlay.h" #include "overlay_exe.h" -#define UNUSED(x) ((void)x) +#define UNUSED(x) ((void) x) typedef int (*OverlayHelperProcessMain)(unsigned int magic, HANDLE parent); // Signal to the overlay DLL that it should not inject // into this process. -extern "C" __declspec(dllexport) void mumbleSelfDetection() {}; +extern "C" __declspec(dllexport) void mumbleSelfDetection(){}; // Alert shows a fatal error dialog and waits for the user to click OK. static void Alert(LPCWSTR title, LPCWSTR msg) { - MessageBox(nullptr, msg, title, MB_OK|MB_ICONERROR); + MessageBox(nullptr, msg, title, MB_OK | MB_ICONERROR); } // GetExecutableDirPath returns the directory that @@ -75,15 +75,15 @@ static std::wstring GetAbsoluteMumbleOverlayDllPath() { // passed to the process. // If the returned vector has a length of 0, an unknown // error occurred. -static std::vector<std::wstring> GetCommandLineArgs() { - std::vector<std::wstring> args; +static std::vector< std::wstring > GetCommandLineArgs() { + std::vector< std::wstring > args; LPWSTR cmdLine = GetCommandLine(); if (!cmdLine) { return args; } - int argc = 0; + int argc = 0; LPWSTR *argv = CommandLineToArgvW(cmdLine, &argc); if (!argv) { return args; @@ -115,11 +115,11 @@ int main(int argc, char **argv) { // initiated launches by checking if we were passed any // arguments at all. If no parameters are passed, we // display a nice alert dialog directing users to - // 'mumble.exe' instead. + // 'mumble.exe' instead. unsigned int magic = 0; - HANDLE parent = 0; + HANDLE parent = 0; { - std::vector<std::wstring> args = GetCommandLineArgs(); + std::vector< std::wstring > args = GetCommandLineArgs(); // If there is only a single argument, it's the program name. // That probably means that a user has double-clicked @@ -140,19 +140,19 @@ int main(int argc, char **argv) { } std::wstring magicNumberStr = args[1]; - std::wstring handleStr = args[2]; + std::wstring handleStr = args[2]; try { unsigned long passedInMagic = std::stoul(magicNumberStr); - magic = static_cast<unsigned int>(passedInMagic); + magic = static_cast< unsigned int >(passedInMagic); } catch (std::exception &) { return OVERLAY_HELPER_ERROR_EXE_INVALID_MAGIC_ARGUMENT; } try { unsigned long long passedInHandle = std::stoull(handleStr); - parent = reinterpret_cast<HANDLE>(passedInHandle & 0xFFFFFFFFULL); - } catch(std::exception &) { + parent = reinterpret_cast< HANDLE >(passedInHandle & 0xFFFFFFFFULL); + } catch (std::exception &) { return OVERLAY_HELPER_ERROR_EXE_INVALID_HANDLE_ARGUMENT; } } @@ -175,7 +175,8 @@ int main(int argc, char **argv) { return OVERLAY_HELPER_ERROR_EXE_LOAD_DLL; } - OverlayHelperProcessMain entryPoint = reinterpret_cast<OverlayHelperProcessMain>(GetProcAddress(dll, "OverlayHelperProcessMain")); + OverlayHelperProcessMain entryPoint = + reinterpret_cast< OverlayHelperProcessMain >(GetProcAddress(dll, "OverlayHelperProcessMain")); if (!entryPoint) { return OVERLAY_HELPER_ERROR_EXE_LOOKUP_ENTRY_POINT; } diff --git a/overlay/overlay_exe/overlay_exe.h b/overlay/overlay_exe/overlay_exe.h index 4daab98fb..9799e3149 100644 --- a/overlay/overlay_exe/overlay_exe.h +++ b/overlay/overlay_exe/overlay_exe.h @@ -8,7 +8,7 @@ #if defined(_M_IX86)
const wchar_t *MUMBLE_OVERLAY_DLL_NAME = L"mumble_ol.dll";
-#elif defined (_M_X64)
+#elif defined(_M_X64)
const wchar_t *MUMBLE_OVERLAY_DLL_NAME = L"mumble_ol_x64.dll";
#endif
@@ -17,33 +17,33 @@ const wchar_t *MUMBLE_OVERLAY_DLL_NAME = L"mumble_ol_x64.dll"; enum OverlayHelperError {
/// The overlay helper process was not passed any
/// arguments.
- OVERLAY_HELPER_ERROR_EXE_NO_ARGUMENTS = 0x0F000001,
+ OVERLAY_HELPER_ERROR_EXE_NO_ARGUMENTS = 0x0F000001,
/// The magic number on the command line of the overlay
/// helper process could not be converted to an integer.
- OVERLAY_HELPER_ERROR_EXE_INVALID_MAGIC_ARGUMENT = 0x0F000002,
+ OVERLAY_HELPER_ERROR_EXE_INVALID_MAGIC_ARGUMENT = 0x0F000002,
/// The magic number on the command line of the overlay
/// helper did not match the built-in magic number of
/// the helper process.
- OVERLAY_HELPER_ERROR_EXE_MAGIC_MISMATCH = 0x0F000003,
+ OVERLAY_HELPER_ERROR_EXE_MAGIC_MISMATCH = 0x0F000003,
/// The overlay helper process was unable to configure
/// its environment in preparation of loading the
/// overlay DLL.
- OVERLAY_HELPER_ERROR_EXE_CONFIGURE_ENVIRONMENT = 0x0F000004,
+ OVERLAY_HELPER_ERROR_EXE_CONFIGURE_ENVIRONMENT = 0x0F000004,
/// The overlay helper process was unable to get the
/// path to the overlay DLL.
- OVERLAY_HELPER_ERROR_EXE_GET_DLL_PATH = 0x0F000005,
+ OVERLAY_HELPER_ERROR_EXE_GET_DLL_PATH = 0x0F000005,
/// The overlay helper process was unable to load the
/// overlay DLL.
- OVERLAY_HELPER_ERROR_EXE_LOAD_DLL = 0x0F000006,
+ OVERLAY_HELPER_ERROR_EXE_LOAD_DLL = 0x0F000006,
/// The overlay helper process was uanble to look up
/// the 'OverlayHelperProcessMain' entry point in the
/// overlay DLL.
- OVERLAY_HELPER_ERROR_EXE_LOOKUP_ENTRY_POINT = 0x0F000007,
+ OVERLAY_HELPER_ERROR_EXE_LOOKUP_ENTRY_POINT = 0x0F000007,
/// The overlay helper process was uanble to parse
/// the commandline arguments it was passed.
/// The helper process exepcts two arguments, and this
/// error occurs if it only finds one.
- OVERLAY_HELPER_ERROR_TOO_FEW_ARGUMENTS = 0x0F000008,
+ OVERLAY_HELPER_ERROR_TOO_FEW_ARGUMENTS = 0x0F000008,
/// The magic number on the command line of the overlay
/// helper process could not be converted to a HANDLE.
OVERLAY_HELPER_ERROR_EXE_INVALID_HANDLE_ARGUMENT = 0x0F000009,
@@ -51,21 +51,23 @@ enum OverlayHelperError { /// The magic number passed to the overlay DLL's
/// OverlayHelperProcessMain function did not match
/// the overlay DLL's built-in magic number.
- OVERLAY_HELPER_ERROR_DLL_MAGIC_MISMATCH = 0x0FF00000,
+ OVERLAY_HELPER_ERROR_DLL_MAGIC_MISMATCH = 0x0FF00000,
/// The overlay helper process exited due to an error
/// in the Windows message loop.
- OVERLAY_HELPER_ERROR_DLL_MESSAGE_LOOP = 0x0FF00001,
+ OVERLAY_HELPER_ERROR_DLL_MESSAGE_LOOP = 0x0FF00001,
/// The parent death thread could not be created.
- OVERLAY_HELPER_ERROR_DLL_PDEATH_THREAD_ERROR = 0x0FF00002,
+ OVERLAY_HELPER_ERROR_DLL_PDEATH_THREAD_ERROR = 0x0FF00002,
/// The helper's WaitForSingleObject call on its parent
/// process failed unexpectedly.
- OVERLAY_HELPER_ERROR_DLL_PDEATH_WAIT_FAIL = 0x0FF00003,
+ OVERLAY_HELPER_ERROR_DLL_PDEATH_WAIT_FAIL = 0x0FF00003,
};
/// OverlayHelperErrorToString converts an OverlayHelperError value
/// to a printable string representation.
static inline const char *OverlayHelperErrorToString(OverlayHelperError err) {
- #define OHE(x) case x: return #x
+#define OHE(x) \
+ case x: \
+ return #x
switch (err) {
OHE(OVERLAY_HELPER_ERROR_EXE_NO_ARGUMENTS);
OHE(OVERLAY_HELPER_ERROR_EXE_INVALID_MAGIC_ARGUMENT);
diff --git a/overlay/overlay_launchers.h b/overlay/overlay_launchers.h index e0a6d0f49..02c0f5690 100644 --- a/overlay/overlay_launchers.h +++ b/overlay/overlay_launchers.h @@ -7,19 +7,19 @@ #define MUMBLE_OVERLAY_LAUNCHERS_H_ static const char *overlayLaunchers[] = { - "Steam.exe", // Steam - "Origin.exe", // Origin - "Battle.net.exe", // Battle.net - "GalaxyClient.exe", // GOG Galaxy - "UbisoftGameLauncher.exe", // Uplay + "Steam.exe", // Steam + "Origin.exe", // Origin + "Battle.net.exe", // Battle.net + "GalaxyClient.exe", // GOG Galaxy + "UbisoftGameLauncher.exe", // Uplay "UbisoftGameLauncher64.exe", // Uplay - "itch.exe", // itch.io - "LaunchPad.exe", // Daybreak Games LaunchPad + "itch.exe", // itch.io + "LaunchPad.exe", // Daybreak Games LaunchPad - "evelauncher.exe", // EVE Online launcher + "evelauncher.exe", // EVE Online launcher "ffxivlauncher.exe", // Final Fantasy XIV Launcher - "LoLPatcher.exe", // League of Legends Patcher (note: this isn't its launcher, but an intermediate process) - "GTAVLauncher.exe", // Grand Theft Auto V + "LoLPatcher.exe", // League of Legends Patcher (note: this isn't its launcher, but an intermediate process) + "GTAVLauncher.exe", // Grand Theft Auto V nullptr }; diff --git a/overlay/overlay_whitelist.h b/overlay/overlay_whitelist.h index 614908473..24215c361 100644 --- a/overlay/overlay_whitelist.h +++ b/overlay/overlay_whitelist.h @@ -8,8 +8,7 @@ static const char *overlayWhitelist[] = { // We can't whitelist the GW2 launcher - "gw2.exe", - "gw2-64.exe", + "gw2.exe", "gw2-64.exe", nullptr }; diff --git a/overlay/util.h b/overlay/util.h index 9d2bbdf5b..29d29c651 100644 --- a/overlay/util.h +++ b/overlay/util.h @@ -23,31 +23,29 @@ static inline std::string slowercase(std::string s) { }
/// Convert all entries of |vec| to lowercase and return the resulting vector.
-static inline std::vector<std::string> vlowercase(std::vector<std::string> vec) {
+static inline std::vector< std::string > vlowercase(std::vector< std::string > vec) {
std::transform(vec.begin(), vec.end(), vec.begin(), slowercase);
return vec;
-
}
/// Merge |v1| and |v2| and return the result.
-template<typename T>
-static inline std::vector<T> vmerge(std::vector<T> v1, const std::vector<T> &v2) {
+template< typename T > static inline std::vector< T > vmerge(std::vector< T > v1, const std::vector< T > &v2) {
v1.insert(v1.end(), v2.begin(), v2.end());
return v1;
}
/// Filter out all entries of |vremove| from |v| and return the result.
-template<typename T>
-static inline std::vector<T> vexclude(const std::vector<T> &v, const std::vector<T> &vremove) {
- std::vector<T> out;
+template< typename T >
+static inline std::vector< T > vexclude(const std::vector< T > &v, const std::vector< T > &vremove) {
+ std::vector< T > out;
std::set_difference(v.begin(), v.end(), vremove.begin(), vremove.end(), std::inserter(out, out.begin()));
return out;
}
/// Find the intersection between |v1| and |v2| and return the result.
-template<typename T>
-static inline std::vector<T> vintersect(const std::vector<T> &v1, const std::vector<T> &v2) {
- std::vector<T> out;
+template< typename T >
+static inline std::vector< T > vintersect(const std::vector< T > &v1, const std::vector< T > &v2) {
+ std::vector< T > out;
std::set_intersection(v1.begin(), v1.end(), v2.begin(), v2.end(), std::inserter(out, out.begin()));
return out;
}
|