コード例 #1
0
        public void Stop()
        {
            // try to aquire lock, if fail then kill process anyways.
            bool lockAquried = Monitor.TryEnter(_lockObject, 500);

            if (IsRunning)
            {
                if (WowHook != null && WowHook.Installed)
                {
                    WowHook.DisposeHooking();
                }
                if (_wowLoginTimer != null)
                {
                    _wowLoginTimer.Dispose();
                }
                WowHook = null;
                CloseGameProcess();
                IsRunning = false;
                StartupSequenceIsComplete = false;
            }
            if (lockAquried)
            {
                Monitor.Exit(_lockObject);
            }
        }
コード例 #2
0
        public void Pulse()
        {
            lock (_lockObject)
            {
                if (IsRunning)
                {
                    // restart wow WoW if it has exited
                    if (GameProcess == null || GameProcess.HasExited)
                    {
                        if (_waitingToStart)
                        {
                            Profile.Status = "Waiting to start";
                        }
                        else
                        {
                            Profile.Log("WoW process was terminated. Restarting");
                            Profile.Status = "WoW process was terminated. Restarting";
                        }
                        StartWoW();
                        return;
                    }
                    // return if wow isn't ready for input.
                    if (!GameProcess.WaitForInputIdle(0))
                    {
                        return;
                    }
                    if (WowHook == null)
                    {
                        WowHook = new Hook(GameProcess);
                    }
                    if (!StartupSequenceIsComplete && !InGame && !IsConnectiongOrLoading)
                    {
                        if (!WowHook.Installed)
                        {
                            Profile.Log("Installing Endscene hook");
                            Profile.Status = "Logging into WoW";
                            // check if we need to scan for offsets
                            if (string.IsNullOrEmpty(HbRelogManager.Settings.WowVersion) ||
                                !HbRelogManager.Settings.WowVersion.Equals(GameProcess.VersionString()))
                            {
                                ScanForOffset();
                            }
                            WowHook.InstallHook();
                            Lua = new Lua(WowHook);
                            UpdateLoginString();
                        }
                        // hook is installed so lets assume proces is ready for input.
                        else if (!_processIsReadyForInput)
                        {
                            // change window title
                            NativeMethods.SetWindowText(GameProcess.MainWindowHandle, string.Format("{0} - ProcID: {1}", Profile.Settings.ProfileName, GameProcess.Id));
                            // resize and position window.
                            if (Settings.WowWindowWidth > 0 && Settings.WowWindowHeight > 0)
                            {
                                Profile.Log("Setting Window location to X:{0}, Y:{1} and Size to Width {2}, Height:{3}",
                                            Settings.WowWindowX, Settings.WowWindowY,
                                            Settings.WowWindowWidth, Settings.WowWindowHeight);

                                Utility.ResizeAndMoveWindow(GameProcess.MainWindowHandle, Settings.WowWindowX,
                                                            Settings.WowWindowY,
                                                            Settings.WowWindowWidth, Settings.WowWindowHeight);
                            }
                            _processIsReadyForInput = true;
                        }
                        LoginWoW();
                    }
                    // remove hook since its nolonger needed.
                    if (WowHook.Installed && (InGame || IsConnectiongOrLoading) && WowHook != null)
                    {
                        Profile.Log("Login sequence complete. Removing hook");
                        Profile.Status = "Logged into WoW";
                        WowHook.DisposeHooking();
                        StartupSequenceIsComplete = true;
                        if (OnStartupSequenceIsComplete != null)
                        {
                            OnStartupSequenceIsComplete(this, new ProfileEventArgs(Profile));
                        }
                    }
                    // if WoW has disconnected or crashed close wow and start the login sequence again.

                    if ((StartupSequenceIsComplete && (GlueStatus == GlueState.Disconnected || WowIsLoggedOutForTooLong)) ||
                        !WoWIsResponding || WowHasCrashed)
                    {
                        if (!WoWIsResponding)
                        {
                            Profile.Status = "WoW is not responding. restarting";
                            Profile.Log("WoW is not responding.. So lets restart WoW");
                        }
                        else if (WowHasCrashed)
                        {
                            Profile.Status = "WoW has crashed. restarting";
                            Profile.Log("WoW has crashed.. So lets restart WoW");
                        }
                        else if (WowIsLoggedOutForTooLong)
                        {
                            Profile.Log("Restarting wow because it was logged out for more than 40 seconds");
                            Profile.Status = "WoW was logged out for too long. restarting";
                        }
                        else
                        {
                            Profile.Log("WoW has disconnected.. So lets restart WoW");
                            Profile.Status = "WoW has DCed. restarting";
                        }
                        CloseGameProcess();
                    }
                }
            }
        }