2013-10-25 1 views
0

저는 게임의 픽셀 색상에 거의 아무런 영향을 미치지 않고 작업하고 있습니다. 필자는 BitBlt, SharpDX 라이브러리, Desktop Duplication (Windows 8 제한으로 인해 사용할 수 없음) 및 GetPixel() (이 방법이 효과적이기는하지만 너무 유용합니다)과 같은 여러 가지 방법을 연구하고 시도했습니다.DirectX 게임 오버레이 읽기

게임의 오버레이 때문에 GetPixel()을 제외하고는 아무 것도 작동하지 않습니다 (아마도 적절한 SharpDX/D3D 기능을 찾지 못했을 것입니다).

미러 드라이버를 조사했지만 활용하기에 충분한 설명서를 찾지 못하거나 제대로 작동하는지 알 수 없습니다.

DirectX 게임의 오버레이 픽셀에 액세스 할 수있는 방법이 있습니까?

+0

오버레이는 DirectX의 특수한 종류의 표면이며, Microsoft는 오버레이 표면에서 데이터를 가져 오기위한 공용 인터페이스를 제공하지 않으므로 후킹을 제외하고는 아무런 방법이 없습니다! – zdd

답변

1

direct-x 게임은 일반적으로 이중 버퍼링되기 때문에 GetPixel 또는 Bitblt가 전혀 작동하지 않을 가능성이 50 %입니다. 게임에서 실시간 픽셀이 정말로 필요한 경우 dll/공유 메모리 또는 일부 형식의 프로세스 간 통신을 통해 원하는 모든 응용 프로그램으로 픽셀을 우회 및 공급할 수 있습니다. 보조 노트로

, 당신은 getPixel와 당신을 위해 작동 말 때문에, 당신은 항상 지정된 윈도우의 스크린 샷을 잡아하고 .. 당신은 GDI32에 링크를 필요

을에는 GDIPlus 것이다 저장하기 위해 다음과 같은 시도 할 수 있습니다
#include <windows.h> 
#include <iostream> 
#include <fstream> 

typedef struct 
{ 
    HBITMAP hBmp; 
    int Width, Height; 
    unsigned int* Pixels; 
    unsigned short BitsPerPixel; 
} BmpData; 

bool ScreenShot(BmpData &Data, HDC DC) 
{ 
    bool Result = false; 
    memset(&Data, 0, sizeof(Data)); 
    HDC hdcMem = CreateCompatibleDC(DC); 
    Data.Width = GetDeviceCaps(DC, HORZRES); 
    Data.Height = GetDeviceCaps(DC, VERTRES); 

    unsigned char* Pixels = NULL; 
    unsigned short BitsPerPixel = 32; 
    BITMAPINFO Info = {{sizeof(BITMAPINFOHEADER), Data.Width, -Data.Height, 1, BitsPerPixel, BI_RGB, 0, 0, 0, 0, 0}}; 

    Data.hBmp = CreateDIBSection(DC, &Info, DIB_RGB_COLORS, reinterpret_cast<void**>(&Pixels), NULL, 0); 
    if(Data.hBmp) 
    { 
     HBITMAP hOld = reinterpret_cast<HBITMAP>(SelectObject(hdcMem, Data.hBmp)); 
     BitBlt(hdcMem, 0, 0, Data.Width, Data.Height, DC, 0, 0, SRCCOPY); 
     SelectObject(hdcMem, hOld); 
     Data.Height *= -1; 
     Data.BitsPerPixel = BitsPerPixel; 
     Data.Pixels = reinterpret_cast<unsigned int*>(Pixels); 
     Result = true; 
    } 

    DeleteDC(hdcMem); 
    return Result; 
} 

/*Portable way to save a bitmap =)*/ 
void SaveBitmap(const char* FilePath, const BmpData &Data) 
{ 
    std::fstream hFile(FilePath, std::ios::out | std::ios::binary); 
    if (!hFile.is_open()) 
    { 
     printf("%s", "Error. Cannot Create Bitmap."); 
     return; 
    } 

    unsigned int Trash = 0; 
    unsigned short Planes = 1; 
    unsigned int biSize = 40; 
    unsigned short Type = 0x4D42; 
    unsigned int compression = 0; 
    unsigned int PixelsOffsetBits = 54; 
    int Width = Data.Width; 
    int Height = -Data.Height; 
    unsigned short BitsPerPixel = Data.BitsPerPixel; 
    unsigned int size = ((Width * BitsPerPixel + 31)/32) * 4 * Height; 
    unsigned int bfSize = 54 + size; 
    Height *= -1; 

    hFile.write(reinterpret_cast<char*>(&Type), sizeof(Type)); 
    hFile.write(reinterpret_cast<char*>(&bfSize), sizeof(bfSize)); 
    hFile.write(reinterpret_cast<char*>(&Trash), sizeof(unsigned int)); 
    hFile.write(reinterpret_cast<char*>(&PixelsOffsetBits), sizeof(PixelsOffsetBits)); 
    hFile.write(reinterpret_cast<char*>(&biSize), sizeof(biSize)); 
    hFile.write(reinterpret_cast<char*>(&Width), sizeof(Width)); 
    hFile.write(reinterpret_cast<char*>(&Height), sizeof(Height)); 
    hFile.write(reinterpret_cast<char*>(&Planes), sizeof(Planes)); 
    hFile.write(reinterpret_cast<char*>(&BitsPerPixel), sizeof(BitsPerPixel)); 
    hFile.write(reinterpret_cast<char*>(&compression), sizeof(compression)); 
    hFile.write(reinterpret_cast<char*>(&size), sizeof(size)); 
    hFile.write(reinterpret_cast<char*>(&Trash), sizeof(unsigned int)); 
    hFile.write(reinterpret_cast<char*>(&Trash), sizeof(unsigned int)); 
    hFile.write(reinterpret_cast<char*>(&Trash), sizeof(unsigned int)); 
    hFile.write(reinterpret_cast<char*>(&Trash), sizeof(unsigned int)); 
    hFile.write(reinterpret_cast<char*>(Data.Pixels), size); 
    hFile.close(); 
} 

int main() 
{ 
    HWND MyWindow = nullptr; //Handle to the window that you want to screenshot.. 

    BmpData data; 
    HDC Screen = GetDC(MyWindow); //Get a DC.. 
    ScreenShot(data, Screen); 
    SaveBitmap("C:/Users/Brandon/desktop/Foo.bmp", data); 
    DeleteDC(Screen); 
    DeleteObject(data.hBmp); 
} 
+0

불행히도 스크린 샷이 작동하지 않습니다 : /. 오버레이 캡처가 아닌 검은 스크린 샷이 여전히 필요합니다. dll/detour 메소드를 살펴보기 시작할 것입니다. 조언 해 주셔서 감사합니다. – asqapro