static void handle_button(int m_x, int m_y, int bstate, int kstate, int breturn) { int wh; WINDOWP window; if (!all_iconified) { wake_mouse(); wh = wind_find(m_x, m_y); window = get_window(wh); if (window != NULL) click_window(window, m_x, m_y, bstate, kstate, breturn); } }
int main(int argc, char *argv[]) { /*! blitz window handle */ HWND hWnd = 0; /*! blitz window client rectangle */ RECT clientRect = { 0 }; /*! directdraw interfaces */ IDirectDraw *pDD = NULL; IDirectDraw7 *pDD7 = NULL; /*! return code */ HRESULT hRet; /*! advertise */ { printf("autoblitz\n"); printf("\n"); } /*! ask user for blitz hwnd (found using spyxx, for example) */ { printf("hwnd : "); scanf("%X", &hWnd); } /*! retrieve blitz window rectangle */ GetWindowRect(hWnd, &windowRect); /*! retrieve blitz window client rectangle */ GetClientRect(hWnd, &clientRect); /*! calculate blitz window width/height */ windowWidth = windowRect.right - windowRect.left; windowHeight = windowRect.bottom - windowRect.top; /*! allocate rgb data */ rgb32 = (uint32*)calloc(windowWidth*windowHeight*4, 1); /*! initialize capture */ { rp_debug_trace("DirectDrawCreate\n"); hRet = DirectDrawCreate(NULL, &pDD, NULL); if(FAILED(hRet)) { goto cleanup; } rp_debug_trace("pDD->QueryInterface\n"); hRet = pDD->QueryInterface(IID_IDirectDraw7, (void**)&pDD7); if(FAILED(hRet)) { goto cleanup; } rp_debug_trace("pDD7->SetCooperativeLevel\n"); hRet = pDD7->SetCooperativeLevel(NULL, DDSCL_NORMAL); if(FAILED(hRet)) { goto cleanup; } rp_debug_trace("pDD7->CreateSurface\n"); /*! initialize surfaces */ { DDSURFACEDESC2 ddsd; ZeroMemory(&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; hRet = pDD7->CreateSurface(&ddsd, &pDDSurface7, NULL); if(FAILED(hRet)) { goto cleanup; } rp_debug_trace("pDD7->CreateSurface (Sys)\n"); ZeroMemory(&ddsd, sizeof(DDSURFACEDESC2)); ZeroMemory(&ddsd.ddpfPixelFormat, sizeof(DDPIXELFORMAT)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_LPSURFACE | DDSD_PITCH | DDSD_PIXELFORMAT | DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; ddsd.dwWidth = windowWidth; ddsd.dwHeight = windowHeight; ddsd.lPitch = windowWidth*4; ddsd.lpSurface = rgb32; ddsd.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT); ddsd.ddpfPixelFormat.dwFlags= DDPF_RGB; ddsd.ddpfPixelFormat.dwRGBBitCount = (DWORD)4*8; ddsd.ddpfPixelFormat.dwRBitMask = 0x00FF0000; ddsd.ddpfPixelFormat.dwGBitMask = 0x0000FF00; ddsd.ddpfPixelFormat.dwBBitMask = 0x000000FF; hRet = pDD7->CreateSurface(&ddsd, &pDDSysSurface7, NULL); if(FAILED(hRet)) { goto cleanup; } } rp_debug_trace("Init success!\n"); /*! press button to start the game */ click_window(hWnd, 229, 196); while(true) { /*! wait for user to tell us when to continue on to the next move */ //int ret = MessageBox(0, L"Press OK to take the next move (wait for animation to stop)", L"autoblitz [blog.caustik.com]", MB_OKCANCEL); /*! if cancel was pressed, we're done */ //if(ret == IDCANCEL) { break; } /*! if mouse cursor is within the flash window, wait */ { POINT pt; GetCursorPos(&pt); if( (pt.x > windowRect.left) && (pt.x < windowRect.right) && (pt.y > windowRect.top) && (pt.y < windowRect.bottom) ) { printf("(cursor is inside window..waiting)\n"); rp_thread::sleep(100); continue; } } /*! current grid */ blockColor gameBoard[8][8]; /*! capture the board */ capture_board(gameBoard); /*! display gameboard */ { printf("\n"); printf("- current game board -\n"); printf("\n"); display_board(gameBoard); } /*! check for end of game */ { int x; for(x=0;x<8;x++) { if(gameBoard[7][x] != BC_BLUE) { break; } /*! if last row was entirely blue, click the "play again?" button */ if(x == 7) { int clickX = baseX + eachW*1 + halfW; int clickY = baseY + eachH*6 + halfH; click_window(hWnd, clickX, clickY); } } } /*! analyze gameBoard and make the best move */ { int aX=0, aY=0, bX=0, bY=0; /*! analyze gameBoard */ analyze_board(gameBoard, aX, aY, bX, bY); /*! click first piece */ { int clickX = baseX + eachW*aX + halfW; int clickY = baseY + eachH*aY + halfH; click_window(hWnd, clickX, clickY); } rp_thread::sleep(150); /*! click second piece */ { int clickX = baseX + eachW*bX + halfW; int clickY = baseY + eachH*bY + halfH; click_window(hWnd, clickX, clickY); } } #if 0 /*! wait for animation to start */ rp_thread::sleep(250); /*! wait for board to stabilize */ while(true) { /*! current grid */ blockColor tmpBoard[8][8]; /*! wait a little */ rp_thread::sleep(150); /*! capture current game board */ capture_board(tmpBoard); /*! if board has not changed, stop waiting */ if(memcmp(tmpBoard, gameBoard, sizeof(tmpBoard)) == 0) { break; } /*! remember this board for next loop */ memcpy(gameBoard, tmpBoard, sizeof(tmpBoard)); } #endif } } cleanup: /*! cleanup rgb pixels */ if(rgb32 != 0) { free(rgb32); } /*! cleanup system service */ if(pDDSysSurface7 != 0) { pDDSysSurface7->Release(); } /*! cleanup primary surface */ if(pDDSurface7 != 0) { pDDSurface7->Release(); } /*! cleanup directdraw7 */ if(pDD7 != 0) { pDD7->Release(); } /*! cleanup directdraw */ if(pDD != 0) { pDD->Release(); } return 0; }