3 #include "GVOGameProcess.h"
4 #include "GVOWorldMap.h"
5 #include "GVOSurveyCoordExtractor.h"
8 //
\89æ
\91\9c\89ð
\90Í
\83f
\83o
\83b
\83O
\97p
\81BGVOGameProcess
9 //#define GVO_ANALYZE_DEBUG
12 #ifdef GVO_ANALYZE_DEBUG
13 LPCWSTR const k_debugImageFileName = L"debug5.bmp";
16 LPWSTR const k_gvoWindowClassName = L"Greate Voyages Online Game MainFrame";
17 LPWSTR const k_gvoWindowCaption = L"
\91å
\8dq
\8aC
\8e\9e\91ã Online";
19 const POINT k_surveyCoordOffsetFromRightBottom = { 70, 273 };
20 const SIZE k_surveyCoordSize = { 60, 11 };
25 void GVOGameProcess::clear()
28 ::CloseHandle( m_process );
35 void GVOGameProcess::setConfig( const GVOConfig& config )
37 m_surveyCoord = config.m_initialSurveyCoord;
40 bool GVOGameProcess::updateState()
42 #ifdef GVO_ANALYZE_DEBUG
44 static bool done = false;
52 static GVOImage debugImage;
53 if ( !debugImage.bitmapHandle() ) {
54 if ( !debugImage.loadFromFile( ::g_makeFullPath( k_debugImageFileName ) ) ) {
55 ::MessageBox( NULL, L"
\83f
\83o
\83b
\83O
\83C
\83\81\81[
\83W
\82ª
\82È
\82¢
\82æ", L"
\82¦
\82ç
\81[", MB_ICONERROR );
59 HDC hdc = ::GetWindowDC( ::GetDesktopWindow() );
60 HDC hdcMem = ::CreateCompatibleDC( hdc );
62 ::SelectObject( hdcMem, debugImage.bitmapHandle() );
63 grabImage( hdcMem, POINT(), debugImage.size() );
65 ::RestoreDC( hdcMem, -1 );
67 ::ReleaseDC( NULL, hdc );
74 m_window = ::FindWindow( k_gvoWindowClassName, k_gvoWindowCaption );
79 ::GetWindowThreadProcessId( m_window, &pid );
80 m_process = ::OpenProcess( SYNCHRONIZE, FALSE, pid );
84 POINT clientOrg = { 0 };
85 ::ClientToScreen( m_window, &clientOrg );
86 ::GetClientRect( m_window, &rc );
91 HDC hdc = ::GetDC( ::GetDesktopWindow() );
95 grabImage( hdc, clientOrg, size );
96 ::ReleaseDC( ::GetDesktopWindow(), hdc );
97 m_timeStamp = ::timeGetTime();
99 if ( !updateSurveyCoord() ) {
107 void GVOGameProcess::grabImage( HDC hdc, const POINT& offset, const SIZE& size )
109 if ( !m_surveyCoordImage.bitmapHandle() ) {
110 m_surveyCoordImage.createDIBImage( k_surveyCoordSize );
113 HDC hdcMem = ::CreateCompatibleDC( hdc );
116 const int leftEdge = offset.x;
117 const int rightEdge = leftEdge + size.cx;
118 const int topEdge = offset.y;
119 const int bottomEdge = offset.y + size.cy;
121 //
\91ª
\97Ê
\8dÀ
\95W
\83L
\83\83\83v
\83`
\83\83
122 const int xSurvey = rightEdge - k_surveyCoordOffsetFromRightBottom.x;
123 const int ySurvey = bottomEdge - k_surveyCoordOffsetFromRightBottom.y;
124 ::SelectObject( hdcMem, m_surveyCoordImage.bitmapHandle() );
125 ::BitBlt( hdcMem, 0, 0, k_surveyCoordSize.cx, k_surveyCoordSize.cy, hdc, xSurvey, ySurvey, SRCCOPY );
128 ::RestoreDC( hdcMem, -1 );
129 ::DeleteDC( hdcMem );
132 bool GVOGameProcess::updateSurveyCoord()
134 bool succeeded = false;
135 GVOSurveyCoordExtractor extractor( m_surveyCoordImage );
137 const std::vector<int>& values = extractor.extractNumbers();
138 if ( values.size() == 2 ) {
139 m_surveyCoord.x = values[0];
140 m_surveyCoord.y = values[1];