/// <summary>
        /// Exit program when game process is closed or a demo is finished (game state in a menu)
        /// </summary>
        private void watcher()
        {
            var fullLoaded = false;

            int delay = 50;
            var pm    = new ProcessMemory();

            try
            {
                pm = ProcessMemory.ForProcess(p);
            }
            catch { }

            bool windowOpened = false;
            bool inMenu = false, gameLoaded = false;

            // FIXME: this code inside while can throw exception if abort button was clicked in Form2 (cause process killed)
            while (p != null && !p.HasExited)
            {
                // loading screen is opened
                if (!windowOpened)
                {
                    windowOpened = true;

                    /*
                     * var wnd = WinApi.FindWindow("Tloadi", "Need For Kill Console");
                     * //var mwnd = WinApi.FindWindowEx(wnd, IntPtr.Zero, "TMemo", null);
                     * //var wnd2 = WinApi.FindWindowEx(IntPtr.Zero, IntPtr.Zero, null, "Need For Kill Console");
                     * //Debug.WriteLine("wnd {0}", wnd);
                     * if (wnd != IntPtr.Zero)
                     * {
                     *  //var windows = WinApi.GetProcessWindows(p.Id);
                     *  //if (windows.Length > 0)
                     *  //{
                     *  //    foreach (var w in windows)
                     *  //        WinApi.HideWindow(w);
                     *  //
                     *  //    windowOpened = true;
                     *  //}
                     *  WinApi.HideWindow(wnd);
                     *  //WinApi.HideWindow(wnd2);
                     *  //WinApi.HideWindow(mwnd);
                     *  windowOpened = true;
                     * }
                     */
                }

                try
                {
                    // read data from the game memory
                    inMenu     = pm.AtOffset(NFKHelper.IsMenuOffset).AsByte() == 1;
                    gameLoaded = pm.AtOffset(NFKHelper.IsGameLoadedOffset).AsByte() == 1;
                    //System.Diagnostics.Debug.WriteLine("{0} | {1} | {2} / {3}", p.Handle, p.MainWindowHandle, inMenu, gameLoaded);
                }
                catch { }

                if (!fullLoaded && !inMenu && gameLoaded)
                {
                    // close intro
                    Intro.CloseFlag = true;

                    fullLoaded = true;
                    sw.Stop();
                    // update load time
                    Properties.Settings.Default.GameLoadTime = (int)sw.ElapsedMilliseconds;
                    Properties.Settings.Default.Save();
                }

                // exit only if in menu + game loaded
                if (fullLoaded && inMenu /* && totalDelay > maxDelayTime*/)
                {
                    GameRunning = false;
                    break;
                }
                // check NFK memory every delay milliseconds
                Thread.Sleep(delay);
            }
            GameRunning = false;
        }
 public bool Equals(ProcessMemory other)
 {
     return(Address == other.Address && Equals(Process, other.Process));
 }