From d09ecd85f879bbe856fec2a08ce39e00333e407b Mon Sep 17 00:00:00 2001 From: Brandon-T Date: Sat, 30 Aug 2014 15:38:59 -0400 Subject: [PATCH] Fixed issue #2 found by Kasi-Reddy. Fixed issue where the DC needed to be released or else data-capturing would fail. Added support for mapping external windows using the window handle instead of the PID. --- DXI/DXI.depend | 53 --- DXI/DXI.layout | 34 -- DXI/main.cpp | 42 +-- d3d9/Hooks/Direct3DDevice9Proxy.cpp | 7 +- d3d9/SMARTPlugin.hpp | 2 +- d3d9/SmartJNI.cpp | 5 +- d3d9/d3d9.depend | 485 ---------------------------- d3d9/d3d9.layout | 74 ----- 8 files changed, 31 insertions(+), 671 deletions(-) delete mode 100644 DXI/DXI.depend delete mode 100644 DXI/DXI.layout delete mode 100644 d3d9/d3d9.depend delete mode 100644 d3d9/d3d9.layout diff --git a/DXI/DXI.depend b/DXI/DXI.depend deleted file mode 100644 index fb961b7..0000000 --- a/DXI/DXI.depend +++ /dev/null @@ -1,53 +0,0 @@ -# depslib dependency file v1.0 -1388751552 source:c:\users\brandon\desktop\dxi\sharedmemory.cpp - "SharedMemory.hpp" - -1388751552 c:\users\brandon\desktop\dxi\sharedmemory.hpp - - - - - - - - - - -1388753939 source:c:\users\brandon\desktop\dxi\main.cpp - - - "SharedMemory.hpp" - -1390706742 source:c:\users\school\desktop\dxi\main.cpp - - - "SharedMemory.hpp" - "Utilities.hpp" - -1390040825 c:\users\school\desktop\dxi\sharedmemory.hpp - - - - - - - - - - -1390706771 c:\users\school\desktop\dxi\utilities.hpp - - - "Resources/Resource.hpp" - -1390040825 source:c:\users\school\desktop\dxi\sharedmemory.cpp - "SharedMemory.hpp" - -1390703838 c:\users\school\desktop\dxi\resources\resource.hpp - -1390710079 source:c:\users\school\desktop\dxi\resources\resource.rc - "Resource.hpp" - -1390706727 source:c:\users\school\desktop\dxi\utilities.cpp - "Utilities.hpp" - diff --git a/DXI/DXI.layout b/DXI/DXI.layout deleted file mode 100644 index 9f4497e..0000000 --- a/DXI/DXI.layout +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/DXI/main.cpp b/DXI/main.cpp index 0841d82..2ce3244 100644 --- a/DXI/main.cpp +++ b/DXI/main.cpp @@ -15,7 +15,8 @@ std::string SharedImageName = "Local\\DXIImage_"; char* Exports[] = { - (char*)"DXISetup", (char*)"Function DXISetup(ProcessID: Integer): Boolean;", + (char*)"DXISetup", (char*)"Function DXISetup(WindowHandle: PtrUInt32): Boolean;", + (char*)"DXISetupEx", (char*)"Function DXISetup(WindowHandle: PtrUInt32; Width, Height: UInt32): Boolean; overload;", (char*)"DXIImagePointer", (char*)"Function DXIImagePointer: Pointer;", (char*)"DXIDebugPointer", (char*)"Function DXIDebugPointer: Pointer;", (char*)"DXIAutoFix", (char*)"Function DXIAutoFix(Plugins_Path: String): Boolean;" @@ -36,13 +37,13 @@ extern "C" int __declspec(dllexport) GetFunctionInfo(int Index, void*& Address, if (Index < ExportCount) { Address = reinterpret_cast(GetProcAddress(hInstance, Exports[Index * 2])); -#ifdef _MSC_VER -#pragma warning(disable: 4996) + #ifdef _MSC_VER + #pragma warning(disable: 4996) strcpy(Definition, Exports[Index * 2 + 1]); //strcpy_s(Definition, Exports[Index * 2 + 1]); -#else + #else strcpy(Definition, Exports[Index * 2 + 1]); -#endif + #endif return Index; } return -1; @@ -50,27 +51,21 @@ extern "C" int __declspec(dllexport) GetFunctionInfo(int Index, void*& Address, void GetDesktopResolution(int& width, int& height) { -#if defined _WIN32 || defined _WIN64 + #if defined _WIN32 || defined _WIN64 RECT desktop = {0}; const HWND hDesktop = GetDesktopWindow(); GetWindowRect(hDesktop, &desktop); width = desktop.right; height = desktop.bottom; -#endif + #endif } -bool CreateSharedMemory(int ProcessID) +bool OpenSharedMemory(DWORD ProcessID, unsigned int Width, unsigned int Height) { - int Width = 0, Height = 0; - GetDesktopResolution(Width, Height); - SharedImageData.reset(new SharedMemory(SharedImageName + std::to_string(ProcessID))); - return SharedImageData->MapMemory(Width || Height == 0 ? TotalImageSize : Width * Height * 4 * 2); -} - -bool OpenSharedMemory(int ProcessID) -{ - int Width = 0, Height = 0; - GetDesktopResolution(Width, Height); + if (Width == 0 || Height == 0) + { + GetDesktopResolution((int&)Width, (int&)Height); + } SharedImageData.reset(new SharedMemory(SharedImageName + std::to_string(ProcessID))); return SharedImageData->OpenMemoryMap(Width || Height == 0 ? SharedImageSize : Width * Height * 4 * 2); } @@ -81,9 +76,16 @@ bool UnMapSharedMemory() return true; } -extern "C" bool __declspec(dllexport) DXISetup(int ProcessID) +extern "C" bool __declspec(dllexport) DXISetupEx(HWND WindowHandle, unsigned int Width, unsigned int Height) +{ + DWORD PID = 0; + GetWindowThreadProcessId(WindowHandle, &PID); + return OpenSharedMemory(PID, Width, Height); +} + +extern "C" bool __declspec(dllexport) DXISetup(HWND WindowHandle) { - return OpenSharedMemory(ProcessID); + return DXISetupEx(WindowHandle, 0, 0); } extern "C" void* __declspec(dllexport) DXIImagePointer() diff --git a/d3d9/Hooks/Direct3DDevice9Proxy.cpp b/d3d9/Hooks/Direct3DDevice9Proxy.cpp index 5ef6e14..22cab3a 100644 --- a/d3d9/Hooks/Direct3DDevice9Proxy.cpp +++ b/d3d9/Hooks/Direct3DDevice9Proxy.cpp @@ -227,10 +227,11 @@ HRESULT Direct3DDevice9Proxy::BeginScene() HRESULT Direct3DDevice9Proxy::EndScene() { - HDC hdc = nullptr; + bool isMinimised = false; + if (SmartGlobal && SmartGlobal->version) { - dxReadPixels(ptr_Direct3DDevice9, SmartGlobal->img, hdc, SmartGlobal->width, SmartGlobal->height); + dxReadPixels(ptr_Direct3DDevice9, SmartGlobal->img, isMinimised, SmartGlobal->width, SmartGlobal->height); IDirect3DStateBlock9* block; ptr_Direct3DDevice9->CreateStateBlock(D3DSBT_ALL, &block); @@ -246,7 +247,7 @@ HRESULT Direct3DDevice9Proxy::EndScene() ptr_Direct3DDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); - if (SmartDebugEnabled) + if (SmartDebugEnabled && !isMinimised) { BltSmartBuffer(ptr_Direct3DDevice9); } diff --git a/d3d9/SMARTPlugin.hpp b/d3d9/SMARTPlugin.hpp index 03f9f72..77c6c55 100644 --- a/d3d9/SMARTPlugin.hpp +++ b/d3d9/SMARTPlugin.hpp @@ -56,7 +56,7 @@ extern bool SmartDebugEnabled; extern bool SmartDirectXEnabled; void BltSmartBuffer(IDirect3DDevice9* Device); -HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, HDC &DC, int &Width, int &Height, D3DFORMAT Format = D3DFMT_UNKNOWN); +HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, bool& Minimised, int &Width, int &Height, D3DFORMAT Format = D3DFMT_UNKNOWN); void DrawCircle(IDirect3DDevice9* Device, float mx, float my, float r, D3DCOLOR colour = D3DCOLOR_RGBA(0xFF, 0x00, 0x00, 0xFF)); #endif diff --git a/d3d9/SmartJNI.cpp b/d3d9/SmartJNI.cpp index 7b01457..f056f01 100644 --- a/d3d9/SmartJNI.cpp +++ b/d3d9/SmartJNI.cpp @@ -162,7 +162,7 @@ void BltSmartBuffer(IDirect3DDevice9* Device) } } -HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, HDC& DC, int& Width, int& Height, D3DFORMAT Format) +HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, bool& Minimised, int& Width, int& Height, D3DFORMAT Format) { IDirect3DSurface9* RenderTarget = nullptr; IDirect3DSurface9* DestTarget = nullptr; @@ -179,7 +179,10 @@ HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, HDC& DC, int& Width Format = descriptor.Format; } + HDC DC = nullptr; RenderTarget->GetDC(&DC); + Minimised = IsIconic(WindowFromDC(DC)); + RenderTarget->ReleaseDC(DC); result = Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &DestTarget, nullptr); result = Device->GetRenderTargetData(RenderTarget, DestTarget); diff --git a/d3d9/d3d9.depend b/d3d9/d3d9.depend deleted file mode 100644 index 0907856..0000000 --- a/d3d9/d3d9.depend +++ /dev/null @@ -1,485 +0,0 @@ -# depslib dependency file v1.0 -1382646564 source:c:\users\brandon\desktop\glx\d3d9\main.cpp - "Hooks/Exports.hpp" - -1387416012 c:\users\brandon\desktop\glx\d3d9\hooks\exports.hpp - - - "Library.hpp" - "IDirect3D9Proxy.hpp" - -1382650830 c:\users\brandon\desktop\glx\d3d9\hooks\library.hpp - - - - - -1387393415 c:\users\brandon\desktop\glx\d3d9\hooks\idirect3d9proxy.hpp - - "Direct3DDevice9Proxy.hpp" - -1387433169 c:\users\brandon\desktop\glx\d3d9\hooks\direct3ddevice9proxy.hpp - - -1387505582 source:c:\users\brandon\desktop\glx\d3d9\hooks\direct3ddevice9proxy.cpp - "Direct3DDevice9Proxy.hpp" - "../Graphics.hpp" - "../BaseForm.hpp" - - - -1387415998 source:c:\users\brandon\desktop\glx\d3d9\hooks\exports.cpp - "Exports.hpp" - -1387400262 source:c:\users\brandon\desktop\glx\d3d9\hooks\idirect3d9proxy.cpp - "IDirect3D9Proxy.hpp" - -1382646543 source:c:\users\brandon\desktop\glx\d3d9\hooks\library.cpp - "Library.hpp" - -1387505446 source:c:\users\brandon\desktop\glx\d3d9\images.cpp - "Images.hpp" - -1387505562 c:\users\brandon\desktop\glx\d3d9\images.hpp - - - - - - - -1387502790 source:c:\users\brandon\desktop\glx\d3d9\graphics.cpp - "Graphics.hpp" - -1387502775 c:\users\brandon\desktop\glx\d3d9\graphics.hpp - - - - - "Images.hpp" - -1387504871 c:\users\brandon\desktop\glx\d3d9\baseform.hpp - - - -1388751552 source:c:\users\brandon\desktop\d3d9\hooks\exports.cpp - "Exports.hpp" - -1388751552 c:\users\brandon\desktop\d3d9\hooks\exports.hpp - - - "Library.hpp" - "IDirect3D9Proxy.hpp" - -1388751552 c:\users\brandon\desktop\d3d9\hooks\library.hpp - - - - - -1388751552 c:\users\brandon\desktop\d3d9\hooks\idirect3d9proxy.hpp - - "Direct3DDevice9Proxy.hpp" - -1388751552 c:\users\brandon\desktop\d3d9\hooks\direct3ddevice9proxy.hpp - - -1388751552 source:c:\users\brandon\desktop\d3d9\hooks\idirect3d9proxy.cpp - "IDirect3D9Proxy.hpp" - -1388751552 source:c:\users\brandon\desktop\d3d9\hooks\library.cpp - "Library.hpp" - -1387505446 source:c:\users\brandon\desktop\d3d9\images.cpp - "Images.hpp" - -1388751551 c:\users\brandon\desktop\d3d9\images.hpp - - - - - - - -1388753442 source:c:\users\brandon\desktop\d3d9\main.cpp - "Hooks/Exports.hpp" - -1388751551 source:c:\users\brandon\desktop\d3d9\graphics.cpp - "Graphics.hpp" - -1388751551 c:\users\brandon\desktop\d3d9\graphics.hpp - - - - - "Images.hpp" - -1388753479 source:c:\users\brandon\desktop\d3d9\hooks\direct3ddevice9proxy.cpp - "Direct3DDevice9Proxy.hpp" - "../Graphics.hpp" - "../SMARTPlugin.hpp" - "Hooks.hpp" - - -1388751551 source:c:\users\brandon\desktop\d3d9\sharedmemory.cpp - "SharedMemory.hpp" - -1388751551 c:\users\brandon\desktop\d3d9\sharedmemory.hpp - - - - - - - - - - -1388751551 source:c:\users\brandon\desktop\d3d9\smartjni.cpp - "SmartPlugin.hpp" - - -1388751551 c:\users\brandon\desktop\d3d9\smartplugin.hpp - - - -1388753879 source:c:\users\brandon\desktop\d3d9\hooks\hooks.cpp - "Hooks.hpp" - -1388751552 c:\users\brandon\desktop\d3d9\hooks\hooks.hpp - - - - "Exports.hpp" - "../SharedMemory.hpp" - "../SMARTPlugin.hpp" - -1390040825 source:c:\users\school\desktop\direct-x\d3d9\graphics.cpp - "Graphics.hpp" - -1390040825 c:\users\school\desktop\direct-x\d3d9\graphics.hpp - - - - - "Images.hpp" - -1390040825 c:\users\school\desktop\direct-x\d3d9\images.hpp - - - - - - - -1390554438 source:c:\users\school\desktop\direct-x\d3d9\hooks\direct3ddevice9proxy.cpp - "Direct3DDevice9Proxy.hpp" - -1390524285 c:\users\school\desktop\direct-x\d3d9\hooks\direct3ddevice9proxy.hpp - - "../Graphics.hpp" - "../SMARTPlugin.hpp" - -1390561458 c:\users\school\desktop\direct-x\d3d9\smartplugin.hpp - - - "Graphics.hpp" - -1390524628 c:\users\school\desktop\direct-x\d3d9\hooks\hooks.hpp - - - - "Exports.hpp" - "../SharedMemory.hpp" - "../SMARTPlugin.hpp" - -1390524508 c:\users\school\desktop\direct-x\d3d9\hooks\exports.hpp - - - "Library.hpp" - "IDirect3D9Proxy.hpp" - -1390040826 c:\users\school\desktop\direct-x\d3d9\hooks\library.hpp - - - - - -1390040826 c:\users\school\desktop\direct-x\d3d9\hooks\idirect3d9proxy.hpp - - "Direct3DDevice9Proxy.hpp" - -1390040825 c:\users\school\desktop\direct-x\d3d9\sharedmemory.hpp - - - - - - - - - - -1390040826 source:c:\users\school\desktop\direct-x\d3d9\hooks\exports.cpp - "Exports.hpp" - -1390040826 source:c:\users\school\desktop\direct-x\d3d9\hooks\hooks.cpp - "Hooks.hpp" - -1390040826 source:c:\users\school\desktop\direct-x\d3d9\hooks\idirect3d9proxy.cpp - "IDirect3D9Proxy.hpp" - -1390040826 source:c:\users\school\desktop\direct-x\d3d9\hooks\library.cpp - "Library.hpp" - -1390040825 source:c:\users\school\desktop\direct-x\d3d9\sharedmemory.cpp - "SharedMemory.hpp" - -1390561464 source:c:\users\school\desktop\direct-x\d3d9\smartjni.cpp - "SmartPlugin.hpp" - - -1390554680 source:c:\users\school\desktop\direct-x\d3d9\main.cpp - "Hooks/Exports.hpp" - -1391233088 source:c:\users\school\desktop\d3d9\graphics.cpp - "Graphics.hpp" - -1391233088 c:\users\school\desktop\d3d9\graphics.hpp - - - - - "Images.hpp" - -1391233088 c:\users\school\desktop\d3d9\images.hpp - - - - - - - -1391233088 source:c:\users\school\desktop\d3d9\hooks\exports.cpp - "Exports.hpp" - -1391233088 c:\users\school\desktop\d3d9\hooks\exports.hpp - - - "Library.hpp" - "IDirect3D9Proxy.hpp" - -1391233088 c:\users\school\desktop\d3d9\hooks\library.hpp - - - - - -1391233088 c:\users\school\desktop\d3d9\hooks\idirect3d9proxy.hpp - - "Direct3DDevice9Proxy.hpp" - -1391233088 c:\users\school\desktop\d3d9\hooks\direct3ddevice9proxy.hpp - - "../Graphics.hpp" - "../SMARTPlugin.hpp" - -1391233088 c:\users\school\desktop\d3d9\smartplugin.hpp - - - "Graphics.hpp" - -1391233088 source:c:\users\school\desktop\d3d9\hooks\hooks.cpp - "Hooks.hpp" - -1391233088 c:\users\school\desktop\d3d9\hooks\hooks.hpp - - - - "Exports.hpp" - "../SharedMemory.hpp" - "../SMARTPlugin.hpp" - -1391233088 c:\users\school\desktop\d3d9\sharedmemory.hpp - - - - - - - - - - -1391233088 source:c:\users\school\desktop\d3d9\hooks\idirect3d9proxy.cpp - "IDirect3D9Proxy.hpp" - -1391233088 source:c:\users\school\desktop\d3d9\hooks\library.cpp - "Library.hpp" - -1391233088 source:c:\users\school\desktop\d3d9\main.cpp - "Hooks/Exports.hpp" - -1391233088 source:c:\users\school\desktop\d3d9\sharedmemory.cpp - "SharedMemory.hpp" - -1391233252 source:c:\users\school\desktop\d3d9\smartjni.cpp - "SmartPlugin.hpp" - - -1391233088 source:c:\users\school\desktop\d3d9 - copy\graphics.cpp - "Graphics.hpp" - -1391233088 c:\users\school\desktop\d3d9 - copy\graphics.hpp - - - - - "Images.hpp" - -1391233088 c:\users\school\desktop\d3d9 - copy\images.hpp - - - - - - - -1391233088 source:c:\users\school\desktop\d3d9 - copy\hooks\exports.cpp - "Exports.hpp" - -1391233088 c:\users\school\desktop\d3d9 - copy\hooks\exports.hpp - - - "Library.hpp" - "IDirect3D9Proxy.hpp" - -1391233088 c:\users\school\desktop\d3d9 - copy\hooks\library.hpp - - - - - -1391233088 c:\users\school\desktop\d3d9 - copy\hooks\idirect3d9proxy.hpp - - "Direct3DDevice9Proxy.hpp" - -1391282057 c:\users\school\desktop\d3d9 - copy\hooks\direct3ddevice9proxy.hpp - - "../SMARTPlugin.hpp" - -1391282007 c:\users\school\desktop\d3d9 - copy\smartplugin.hpp - - - - - -1391233088 source:c:\users\school\desktop\d3d9 - copy\hooks\hooks.cpp - "Hooks.hpp" - -1391233088 c:\users\school\desktop\d3d9 - copy\hooks\hooks.hpp - - - - "Exports.hpp" - "../SharedMemory.hpp" - "../SMARTPlugin.hpp" - -1391233088 c:\users\school\desktop\d3d9 - copy\sharedmemory.hpp - - - - - - - - - - -1391233088 source:c:\users\school\desktop\d3d9 - copy\hooks\idirect3d9proxy.cpp - "IDirect3D9Proxy.hpp" - -1391233088 source:c:\users\school\desktop\d3d9 - copy\hooks\library.cpp - "Library.hpp" - -1391281937 source:c:\users\school\desktop\d3d9 - copy\main.cpp - "Hooks/Exports.hpp" - -1391233088 source:c:\users\school\desktop\d3d9 - copy\sharedmemory.cpp - "SharedMemory.hpp" - -1391282746 source:c:\users\school\desktop\d3d9 - copy\hooks\direct3ddevice9proxy.cpp - "Direct3DDevice9Proxy.hpp" - -1391281889 source:c:\users\school\desktop\d3d9 - copy\smartjni.cpp - "SmartPlugin.hpp" - -1395252587 source:c:\users\brandon\desktop\dxi-master\d3d9\hooks\direct3ddevice9proxy.cpp - "Direct3DDevice9Proxy.hpp" - -1393640051 c:\users\brandon\desktop\dxi-master\d3d9\hooks\direct3ddevice9proxy.hpp - - "../SMARTPlugin.hpp" - -1393640050 c:\users\brandon\desktop\dxi-master\d3d9\smartplugin.hpp - - - - - -1393640051 source:c:\users\brandon\desktop\dxi-master\d3d9\hooks\hooks.cpp - "Hooks.hpp" - -1393640051 c:\users\brandon\desktop\dxi-master\d3d9\hooks\hooks.hpp - - - - "Exports.hpp" - "../SharedMemory.hpp" - "../SMARTPlugin.hpp" - -1393640051 c:\users\brandon\desktop\dxi-master\d3d9\hooks\exports.hpp - - - "Library.hpp" - "IDirect3D9Proxy.hpp" - -1393640051 c:\users\brandon\desktop\dxi-master\d3d9\hooks\library.hpp - - - - - -1393640051 c:\users\brandon\desktop\dxi-master\d3d9\hooks\idirect3d9proxy.hpp - - "Direct3DDevice9Proxy.hpp" - -1393640050 c:\users\brandon\desktop\dxi-master\d3d9\sharedmemory.hpp - - - - - - - - - - -1393640051 source:c:\users\brandon\desktop\dxi-master\d3d9\hooks\idirect3d9proxy.cpp - "IDirect3D9Proxy.hpp" - -1393640051 source:c:\users\brandon\desktop\dxi-master\d3d9\hooks\library.cpp - "Library.hpp" - -1393640051 source:c:\users\brandon\desktop\dxi-master\d3d9\main.cpp - "Hooks/Exports.hpp" - -1393640050 source:c:\users\brandon\desktop\dxi-master\d3d9\sharedmemory.cpp - "SharedMemory.hpp" - -1393640050 source:c:\users\brandon\desktop\dxi-master\d3d9\smartjni.cpp - "SmartPlugin.hpp" - -1395252385 source:c:\users\brandon\desktop\dxi-master\d3d9\hooks\exports.cpp - "Exports.hpp" - diff --git a/d3d9/d3d9.layout b/d3d9/d3d9.layout deleted file mode 100644 index bb41aa2..0000000 --- a/d3d9/d3d9.layout +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -