阅读 DirectX 游戏覆盖
Read DirectX Game Overlay
我一直在努力访问游戏的像素颜色,但收效甚微。我已经研究并尝试了几种方法,包括BitBlt,SharpDX库,桌面复制(由于Windows 8限制而无法使用)和GetPixel()(这已经奏效了,但它太慢了,没有用)。
由于游戏的叠加层,这些(除了GetPixel())都不起作用(我可能只是没有发现合适的SharpDX/D3D功能)。
我已经研究了镜像驱动程序,但我找不到足够的文档来使用它们,或者知道它们是否有效。
有没有办法访问 DirectX 游戏叠加层的像素?
由于direct-x游戏通常是双缓冲的,因此GetPixel或Bitblt有50%的可能性可以工作。如果你真的需要游戏中的实时像素,你可以用dll/detour挂上它,并通过共享内存或某种形式的进程间通信将像素馈送到你想要的任何应用程序。
作为旁注,既然你说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);
}
相关文章:
- 使用ios:ate写入到流会覆盖现有文件
- 在C++游戏中与库存系统作斗争
- 我可以重新分配/覆盖std::字符串吗
- 换位表导致测试失败(但在游戏中运行良好)
- 叮叮当当在修复时插入多个"覆盖"说明符
- 谷歌模拟和覆盖关键字
- Craps游戏问题,忽略if语句
- TMap::Emplace() 在应用现有密钥时会覆盖吗?
- 矢量下标超出SFML游戏中的范围
- 我是 c++ 的新手.学习基本知识后,我想做井字游戏.对于印刷板,我在下面写代码,但它显示错误
- 此测试()中发生了什么意外过程?为什么总是覆盖 ch[0 1 2..]?
- 使用子类覆盖基类中定义的函数
- 我在贪吃蛇游戏中收到了错误代码 -1073741571
- 当覆盖存在时调用基本虚拟"binded to object"函数
- 我应该在简单的策略游戏中为各个派系使用类吗 - C++
- 游戏体验和升级
- 阅读 DirectX 游戏覆盖
- dll注入:使用opengl绘制简单的游戏覆盖图
- 井字游戏覆盖阵列用户输入
- DirectX 9,10挂钩覆盖内容在全屏游戏