Beispiel #1
0
        /// <summary>
        /// EventHandler method for the ISXEVE_onFrame LS event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void HandleEveFrame(object sender, LSEventArgs e)
        {
            using (new FrameLock(true))
            {
                //Instance.LogMessage("HandleEveFrame", LogSeverityTypes.Debug, "Beginning frame handler.");

                //Reset the exitResetEvent. We should not attempt to dispose right now.
                _exitResetEvent.Reset();

                //If paused, stop the runtime timer.
                if (!IsEnabled)
                {
                    RunTime.Stop();
                }

                //If doing cleanup go ahead and and do cleanup.
                if (_isDoingInFrameCleanup)
                {
                    //Have ModuleManager do inframe cleanup and set the event
                    //ModuleManager.InFrameCleanup();

                    _isDoingInFrameCleanup = false;
                    _InFrameCleanupResetEvent.Set();
                }

                //If not paused and it's been enough time to pulse again...
                if (Instance.IsEnabled && DateTime.Now.CompareTo(NextPulse) >= 0)
                {
                    //Make sure the runtime timer is running.
                    RunTime.Start();

                    //Now, if it's not been enough pulses to fire the pulse...
                    if (!Instance.ShouldPulse())
                    {
                        //Set the reset event and return.
                        EndPulse();
                        return;
                    }

                    var methodName = "HandleEveFrame";

                    //Set the time of this pulse
                    TimeOfPulse = DateTime.Now;
                    //Increment the pulse count
                    Pulses++;
                    //Core.StealthBot.Logging.LogMessage(Instance.ObjectName, new LogEventArgs(LogSeverityTypes.Debug,
                    //	"HandleEveFrame", String.Format("Pulse check: {0}", Pulses)));

                    #region ISXEVE IsSafe Check

                    //If ISXEve is reporting unsafe, just abort and return. It means
                    //it's not safe to continue logic checks with ISXEVE.
                    if (!_isxeveProvider.Isxeve.IsSafe)
                    {
                        //Logging.LogMessage(Instance.ObjectName, new LogEventArgs(LogSeverityTypes.Debug,
                        //methodName, "Error: ISXEVE reporting not safe. Aborting pulse."));
                        EndPulse();
                        return;
                    }

                    #endregion

                    #region ISXEVE Detection

                    if (!_isxeveProvider.Isxeve.IsReady)
                    {
                        Instance.LogMessage(methodName, LogSeverityTypes.Debug, "ISXEVE is not ready, pausing.");
                        Instance.IsEnabled = false;
                        EndPulse();
                        return;
                    }

                    #endregion

                    #region Me Validity Check

                    //Another check - ME validity
                    if (!MeCache.CheckValidity())
                    {
                        //Logging.LogMessage(Instance.ObjectName, new LogEventArgs(LogSeverityTypes.Debug,
                        //methodName, "Error: InSpace and InStation both false or Me invalid."));

                        if (LavishScriptObject.IsNullOrInvalid(MeCache.Me))
                        {
                            #region Login Screen Detection

                            var login = new Login();
                            if (!LavishScriptObject.IsNullOrInvalid(login))
                            {
                                if (ConfigurationManager.ActiveConfigProfile != null)
                                {
                                    Instance.LogMessage(methodName, LogSeverityTypes.Standard,
                                                        "Login screen detected. Exiting, relaunching if enabled.");
                                    Instance.ExitAndRelaunch();
                                }
                                else
                                {
                                    Instance.LogMessage(methodName, LogSeverityTypes.Standard,
                                                        "Login screen detected. Please close StealthBot, restart EVE, and start StealthBot while fully logged in.");
                                }
                                Instance.IsEnabled = false;
                            }

                            #endregion

                            #region CharSelect Screen Detection

                            var charSelect = new CharSelect();
                            if (!LavishScriptObject.IsNullOrInvalid(charSelect))
                            {
                                Instance.LogMessage(methodName, LogSeverityTypes.Standard,
                                                    "Character Select screen detected. Please close StealthBot, restart EVE, and start StealthBot while fully logged in.");
                                Instance.IsEnabled = false;
                            }

                            #endregion
                        }

                        _exitResetEvent.Set();
                        Logging.LogMessage("StealthBot", methodName, LogSeverityTypes.Debug, "Aborting pulse due to invalidity.");
                        NextPulse = DateTime.Now.AddSeconds(PULSE_FREQUENCY);
                        return;
                    }

                    #endregion

                    //Pulse the ModuleManager.
                    ModuleManager.Pulse();

                    //Fire off the OnPulse event to let the UI know of any changes
                    try
                    {
                        //Instance.LogMessage("HandleEveFrame", LogSeverityTypes.Debug, "Beginning OnPulse.");
                        //Instance.StartMethodProfiling("OnPulse");
                        OnPulse(sender, e);
                        //Instance.EndMethodProfiling();
                        //Instance.LogMessage("HandleEveFrame", LogSeverityTypes.Debug, "Ending OnPulse.");
                    }
                    catch (Exception ex)
                    {
                        LogException(ex, methodName, "Caught excpetion while firing OnPulse event:");
                    }

                    EndPulse();
                }

                //We're done; set the reset event so we can dispose if necessary.
                _exitResetEvent.Set();
                //Instance.LogMessage("HandleEveFrame", LogSeverityTypes.Debug, "Ending EVE Frame.");
            }
        }