외장 개발 읽기 게임 화면 판단 게임 상태
1. 화면 읽기:
byte BitMap[4];
CDC *pDC;// DC
pDC = CDC::FromHandle(GetDC(NULL));// DC
int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);//
int Width = pDC->GetDeviceCaps(HORZRES);//
int Height = pDC->GetDeviceCaps(VERTRES);//
CDC memDC;// DC
memDC.CreateCompatibleDC(pDC);
CBitmap memBitmap, *oldmemBitmap;// bitmap
// BitMap X.Y
memBitmap.CreateCompatibleBitmap(pDC, Width, Height);
oldmemBitmap = memDC.SelectObject(&memBitmap);// memBitmap DC
//
// 1.2: X.Y
// 2.3: X.Y
// 6.7: X.Y
memDC.BitBlt(0, 0, 100, 30, pDC, 0, 25, SRCCOPY);// DC
// memDC
BITMAP bmp;
memBitmap.GetBitmap(&bmp);//
FILE *fp = fopen(filename, "w+b");
BITMAPINFOHEADER bih = {0};//
bih.biBitCount = bmp.bmBitsPixel;//
bih.biCompression = BI_RGB;
bih.biHeight = 30;//
bih.biPlanes = 1;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biSizeImage = (bmp.bmWidthBytes * bmp.bmHeight)/100;//
bih.biWidth = 100;//
BITMAPFILEHEADER bfh = {0};//
bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);//
bfh.bfSize = bfh.bfOffBits + bmp.bmWidthBytes * bmp.bmHeight;//
bfh.bfType = (WORD)0x4d42;
fwrite(&bfh, 1, sizeof(BITMAPFILEHEADER), fp);//
fwrite(&bih, 1, sizeof(BITMAPINFOHEADER), fp);//
byte * p = new byte[bmp.bmWidthBytes * bmp.bmHeight];//
GetDIBits(memDC.m_hDC, (HBITMAP) memBitmap.m_hObject, 0, Height, p,
(LPBITMAPINFO) &bih, DIB_RGB_COLORS);//
fwrite(p, 1, bmp.bmWidthBytes * 30, fp);//
//bmp (Pix_Y * File_X + Pix_X)*3-1
// RGB 4
//RGB BGR 255 B G R
//
// , ,
int pix,x=0,y=0;// X Y
x=(x+1);
y=(30-y);
y=(y-1);
pix=(x+(y*100))*4;
//
BitMap[0] = p[pix-2];
BitMap[1] = p[pix-3];
BitMap[2] = p[pix-4];
BitMap[3] = p[pix-5];
//HeapSize( GetProcessHeap(), 0, p))
delete [] p;
fclose(fp);
memDC.SelectObject(oldmemBitmap);
2. 화면 대비
관심 있는 학생들은 코드에 대해 봉인 최적화를 할 수 있다. 예를 들어 모호한 대비와 픽셀을 읽는 코드의 최적화를 할 수 있다.