Skip to content

Commit

Permalink
Fixed issue #2 found by Kasi-Reddy.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Brandon-T committed Aug 30, 2014
1 parent a602ae7 commit d09ecd8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 671 deletions.
53 changes: 0 additions & 53 deletions DXI/DXI.depend

This file was deleted.

34 changes: 0 additions & 34 deletions DXI/DXI.layout

This file was deleted.

42 changes: 22 additions & 20 deletions DXI/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand All @@ -36,41 +37,35 @@ extern "C" int __declspec(dllexport) GetFunctionInfo(int Index, void*& Address,
if (Index < ExportCount)
{
Address = reinterpret_cast<void*>(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;
}

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);
}
Expand All @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions d3d9/Hooks/Direct3DDevice9Proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -246,7 +247,7 @@ HRESULT Direct3DDevice9Proxy::EndScene()
ptr_Direct3DDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);


if (SmartDebugEnabled)
if (SmartDebugEnabled && !isMinimised)
{
BltSmartBuffer(ptr_Direct3DDevice9);
}
Expand Down
2 changes: 1 addition & 1 deletion d3d9/SMARTPlugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion d3d9/SmartJNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
Loading

0 comments on commit d09ecd8

Please sign in to comment.