Beispiel #1
0
        /// <summary>
        /// FEZのゲーム画面のウィンドウハンドルを指定し,初期化する
        /// </summary>
        /// <param name="handle"></param>
        public FEZWindow( IntPtr handle, bool useMessageDialogCloser = true )
        {
            this.windowHandle = handle;

            var geometry = new WindowsAPI.RECT();
            WindowsAPI.GetWindowRect( handle, ref geometry );
            this._width = geometry.right - geometry.left;
            this._height = geometry.bottom - geometry.top;

            if( useMessageDialogCloser ) {
                this.closer = new MessageDialogCloser( this );
                Thread thread = new Thread( new ThreadStart( this.closer.Run ) );
                thread.Start();
            }
        }
 private void CheckClientException()
 {
     var dialogHandle = WindowsAPI.FindWindow( "#32770", "FEzero_Client.exe" );
     if( dialogHandle == IntPtr.Zero ) {
         return;
     }
     var buttonHandle = WindowsAPI.FindWindowEx( dialogHandle, IntPtr.Zero, null, "送信しない(&D)" );
     var geometry = new WindowsAPI.RECT();
     WindowsAPI.GetWindowRect( buttonHandle, ref geometry );
     int x = (geometry.left + geometry.right) / 2;
     int y = (geometry.top + geometry.bottom) / 2;
     WindowsAPI.SetForegroundWindow( dialogHandle );
     Thread.Sleep( TimeSpan.FromMilliseconds( 500 ) );
     FEZWindow.DoClick( x, y );
 }
Beispiel #3
0
        /// <summary>
        /// 画面の指定した位置をクリックする.座標には,ゲーム画面に対する相対座標を指定する
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public void Click( Point position )
        {
            var geometry = new WindowsAPI.RECT();
            WindowsAPI.GetWindowRect( this.windowHandle, ref geometry );
            var clickPosition = new Point();
            clickPosition.X = geometry.left + position.X;
            clickPosition.Y = geometry.top + position.Y;

            DoClick( clickPosition.X, clickPosition.Y );
        }
Beispiel #4
0
        /// <summary>
        /// ゲームウィンドウ全体の画像を取得する
        /// </summary>
        /// <returns></returns>
        public Bitmap CaptureWindow()
        {
            IntPtr winDC = WindowsAPI.GetWindowDC( this.windowHandle );
            WindowsAPI.RECT winRect = new WindowsAPI.RECT();
            if( !WindowsAPI.GetWindowRect( this.windowHandle, ref winRect ) ) {
                throw new FEZBotException( "ウィンドウサイズを取得できなかった" );
            }
            Bitmap bmp = new Bitmap( winRect.right - winRect.left,
                winRect.bottom - winRect.top );

            Graphics g = Graphics.FromImage( bmp );
            IntPtr hDC = g.GetHdc();
            WindowsAPI.BitBlt( hDC, 0, 0, bmp.Width, bmp.Height,
                winDC, 0, 0, WindowsAPI.SRCCOPY );

            g.ReleaseHdc( hDC );
            g.Dispose();
            WindowsAPI.ReleaseDC( this.windowHandle, winDC );

            return bmp;
        }
        /// <summary>
        /// ランチャーを起動し,ランチャーの「START」ボタンを押すことでクライアント本体を起動する
        /// </summary>
        private IntPtr StartClient()
        {
            StartUpdater();

            // ランチャーを起動
            IntPtr updater = IntPtr.Zero;
            while( updater == IntPtr.Zero && stopRequested == false ) {
                updater = FEZWindow.GetLauncherWindow();
                Thread.Sleep( TimeSpan.FromSeconds( 1 ) );
                var errorDialogOKButton = FEZWindow.GetLauncherErrorWindowOKButton();
                if( errorDialogOKButton != IntPtr.Zero ) {
                    // OKボタンを押す
                    var rect = new WindowsAPI.RECT();
                    WindowsAPI.GetWindowRect( errorDialogOKButton, ref rect );
                    FEZWindow.DoClick( (rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2 );
                    StartUpdater();
                    Thread.Sleep( TimeSpan.FromSeconds( 1 ) );
                }
            }
            if( updater == IntPtr.Zero ) {
                throw new FEZBotException( "クライアント・ランチャが起動できなかった" );
            }

            // ランチャーの「START」ボタンを押す
            // STARTボタンが出現するまで待機
            IntPtr startButton = IntPtr.Zero;
            while( startButton == IntPtr.Zero ) {
                startButton = WindowsAPI.FindWindowEx( updater, IntPtr.Zero, "BUTTON", "START" );
                Thread.Sleep( TimeSpan.FromSeconds( 1 ) );
            }

            // STARTボタンがENABLE状態になるまで待機
            while( !WindowsAPI.IsWindowEnabled( startButton ) ) {
                Thread.Sleep( TimeSpan.FromSeconds( 1 ) );
            }

            WindowsAPI.RECT startButtonGeometry = new WindowsAPI.RECT();
            WindowsAPI.GetWindowRect( startButton, ref startButtonGeometry );
            var x = (startButtonGeometry.left + startButtonGeometry.right) / 2;
            var y = (startButtonGeometry.top + startButtonGeometry.bottom) / 2;
            FEZWindow.DoClick( x, y );

            // 起動するのを待つ
            var client = IntPtr.Zero;
            while( client == IntPtr.Zero && stopRequested == false ) {
                client = FEZWindow.GetClientWindow();
                Thread.Sleep( TimeSpan.FromSeconds( 1 ) );
            }
            return client;
        }