void HandleResponse(string data) { string cmd = data.Split(' ')[0]; if (data.Split(' ').Count() > 1) { data = data.Substring(cmd.Length + 1); } switch (cmd) { case "Restart": Log("Restarting bot"); BotMain.Stop(); Thread.Sleep(1000); BotMain.Start(); Reset(); break; case "LoadProfile": LoadProfile(data); break; case "MonsterPower": var powerlevel = Convert.ToInt32(data.Trim()); Log("Recieved MonsterPowerLevel: {0}", powerlevel); if (powerlevel >= 0) { CharacterSettings.Instance.MonsterPowerLevel = powerlevel; } break; case "ForceEnableAll": ForceEnableAllPlugins(); break; case "ForceEnableYar": ForceEnableYar(); break; case "FixPulse": FixPulse(); break; case "Shutdown": Log("Received Shutdown command"); SafeCloseProcess(); break; case "Roger!": case "Unknown command!": break; default: Log("Unknown response! \"{0} {1}\"", cmd, data); break; } _recieved = true; }
private void LoadProfile(string profile) { BotMain.Stop(false, "YetAnotherRelogger -> Load new profile"); if (ZetaDia.IsInGame) { ZetaDia.Service.Party.LeaveGame(); while (ZetaDia.IsInGame) { Thread.Sleep(1000); } } Thread.Sleep(2000); Log("Loading profile: {0}", profile); ProfileManager.Load(profile.Trim()); Thread.Sleep(5000); BotMain.Start(); }
private void ForceEnableAllPlugins() { PluginContainer test; DateTime limit; var disabledPlugins = PluginManager.Plugins.Where(p => !p.Enabled); if (!disabledPlugins.Any()) { return; } Log("Disabled plugins found. User requested all plugins be enabled through YAR. Stopping bot to enable plugins..."); BotMain.Stop(); Thread.Sleep(1000); foreach (var plugin in disabledPlugins) { try { Log("Force enable: \"{0}\"", plugin.Plugin.Name); plugin.Enabled = true; limit = DateTime.Now; while ((test = PluginManager.Plugins.FirstOrDefault(x => x.Plugin.Name.Equals(plugin.Plugin.Name))) != null && !test.Enabled) { if (DateTime.Now.Subtract(limit).TotalSeconds > 5) { Log("Failed to enable: Timeout ({0} seconds) \"{1}\"", DateTime.Now.Subtract(limit).TotalSeconds, plugin.Plugin.Name); break; } Thread.Sleep(100); } } catch (Exception ex) { Log("Failed to enable: \"{0}\"", plugin.Plugin.Name); LogException(ex); } } Log("Finished enabling plugins. Starting the bot..."); BotMain.Start(); }
void HandleResponse(string data) { string cmd = data.Split(' ')[0]; if (data.Split(' ').Count() > 1) { data = data.Substring(cmd.Length + 1); } switch (cmd) { case "Restart": Log("Restarting bot"); BotMain.Stop(); Thread.Sleep(1000); BotMain.Start(); Reset(); break; case "LoadProfile": LoadProfile(data); break; case "ForceEnableAll": ForceEnableAllPlugins(); break; case "ForceEnableYar": ForceEnableYar(); break; case "FixPulse": FixPulse(); break; case "Roger!": case "Unknown command!": break; default: Log("Unknown response! \"{0} {1}\"", cmd, data); break; } _recieved = true; }
/// <summary> /// Selects the Trinity routine in the RoutineManager /// </summary> private static void SelectTrinityRoutine() { if (!IsLatestRoutineInstalled) { return; } Application.Current.Dispatcher.BeginInvoke((Action)(() => { Logger.LogNormal("Stopping bot to select latest routine"); BotMain.Stop(); CombatRoutine trinityRoutine = (CombatRoutine)RoutineManager.Routines.FirstOrDefault(r => r.Name == "Trinity"); RoutineManager.Current = trinityRoutine; Logger.LogNormal("Routine selected, starting bot"); BotMain.Start(); })); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); mDispatcher = new DispatcherImpl(this); mBrowser.CoreWebView2InitializationCompleted += MBrowser_CoreWebView2InitializationCompleted; mBrowser.EnsureCoreWebView2Async(); //TEST COM CONNECTION. TO BE REMOVED string[] ports = SerialPort.GetPortNames(); if (ports.Length > 0) { BotMain bot = new BotMain(mDispatcher, "test"); ComConnection con = new ComConnection(mDispatcher); con.SetPortName(ports[0]); bot.SetConnection(con); bot.OnModAdded += Bot_OnModAdded; bot.IsAvailableChanged += Bot_IsAvailableChanged; bot.RunningChanged += Bot_RunningChanged; bot.Start(); } }
private void FixPulse() { DateTime timeout; s_logger.Information("############## Pulse Fix ##############"); // Check if plugin is enabled PluginContainer plugin = PluginManager.Plugins.FirstOrDefault(x => x.Plugin.Name.Equals(Name)); if (plugin != null && plugin.Enabled) { s_logger.Information("PulseFix: Plugin is already enabled -> Disable it for now"); _pulseFix = true; // Prevent our thread from begin aborted plugin.Enabled = false; timeout = DateTime.UtcNow; while (plugin.Enabled) { if (DateTime.UtcNow.Subtract(timeout).TotalSeconds > 10) { s_logger.Information("PulseFix: Failed to disable plugin"); Application.Current.Shutdown(0); return; } Thread.Sleep(100); } } else { s_logger.Information("PulseFix: Plugin is not enabled!"); } // Force enable yar plugin ForceEnableYar(); var attempt = 0; while (!BotMain.IsRunning) { attempt++; if (attempt >= 4) { s_logger.Information("PulseFix: Fix attempts failed, closing demonbuddy!"); Application.Current.Shutdown(); } if (BotMain.BotThread == null) { s_logger.Information("PulseFix: Mainbot thread is not running"); s_logger.Information("PulseFix: Force start bot"); BotMain.Start(); } else if (BotMain.BotThread != null) { if (BotMain.IsPaused || BotMain.IsPausedForStateExecution) { s_logger.Information("PulseFix: DB is Paused!"); } s_logger.Information("PulseFix: Force stop bot"); BotMain.BotThread.Abort(); Thread.Sleep(1000); s_logger.Information("PulseFix: Force start bot"); BotMain.Start(); } Thread.Sleep(1000); } // Check if we get a pulse within 10 seconds s_logger.Information("PulseFix: Waiting for first pulse"); _pulseCheck = false; timeout = DateTime.UtcNow; while (!_pulseCheck) { if (DateTime.UtcNow.Subtract(timeout).TotalSeconds > 10) { s_logger.Information("PulseFix: Failed to recieve a pulse within 10 seconds"); SafeCloseProcess(); break; } Thread.Sleep(100); } s_logger.Information("############## End Fix ##############"); }
private async void PacketReceived(UdpReceiveResult packet) { var cmd = (BotCommand)packet.Buffer[0]; switch (cmd) { case BotCommand.Ack: s_logger.Information("Acknowledged"); _acknowledged = true; break; case BotCommand.Restart: s_logger.Information("Restarting bot"); try { s_logger.Information("Stopping Bot"); BotMain.Stop(); await Application.Current.Dispatcher.BeginInvoke((System.Action)(() => { try { s_logger.Information("Starting Bot"); Thread.Sleep(1000); BotMain.Start(); } catch (Exception ex) { s_logger.Warning(ex, "Error during start"); } })); } catch (Exception ex) { s_logger.Warning(ex, "Error during restart"); } Reset(); break; case BotCommand.Shutdown: s_logger.Information("Received Shutdown command"); SafeCloseProcess(); break; case BotCommand.ForceEnableAll: ForceEnableAllPlugins(); break; case BotCommand.ForceEnableYar: ForceEnableYar(); break; case BotCommand.FixPulse: FixPulse(); break; case BotCommand.LoadProfile: var profile = Encoding.UTF8.GetString(packet.Buffer.Skip(1).ToArray()); s_logger.Information("Received {profile}", profile); LoadProfile(profile); break; case BotCommand.SwitchDifficultyLevel: var difficultyLevel = (GameDifficulty)BitConverter.ToInt32(packet.Buffer, 1); if (difficultyLevel >= 0) { s_logger.Information("Recieved DifficultyLevel: {difficultyLevel}", difficultyLevel); CharacterSettings.Instance.GameDifficulty = difficultyLevel; } break; default: s_logger.Warning("Unknown command {cmd}", cmd); break; } }
/// <summary> /// Receive Pulse event from DemonBuddy. /// </summary> public void OnPulse() { using (new PerformanceLogger("OnPulse")) { try { // At Login screen, derp! var loginSubmitButton = Zeta.Game.Internals.UIElement.FromName("Root.NormalLayer.BattleNetLogin_main.LayoutRoot.LoginContainer.SubmitButton"); if (loginSubmitButton != null && loginSubmitButton.IsValid && loginSubmitButton.IsVisible && BotMain.IsRunning) { new Thread(() => { BotMain.Stop(); Thread.Sleep(1000); BotMain.Start(); }) { IsBackground = true, Name = "LoginScreenBouncer", }.Start(); return; } if (ZetaDia.Me == null) { return; } if (!ZetaDia.IsInGame || !ZetaDia.Me.IsValid || ZetaDia.IsLoadingWorld) { return; } GameUI.SafeClickUIButtons(); if (ZetaDia.Me.IsDead) { return; } using (new PerformanceLogger("LazyRaiderClickToPause")) { if (Settings.Advanced.LazyRaiderClickToPause && !BotMain.IsPaused) { BotMain.PauseWhile(MouseLeft); } } // See if we should update the stats file if (DateTime.UtcNow.Subtract(ItemStatsLastPostedReport).TotalSeconds > 10) { ItemStatsLastPostedReport = DateTime.UtcNow; OutputReport(); } // Recording of all the XML's in use this run UsedProfileManager.RecordProfile(); Monk_MaintainTempestRush(); } catch (AccessViolationException) { // woof! } catch (Exception ex) { Logger.Log(LogCategory.UserInformation, "Exception in Pulse: {0}", ex.ToString()); } } }
void HandleResponse(string data) { string cmd = data.Split(' ')[0]; if (data.Split(' ').Count() > 1) { data = data.Substring(cmd.Length + 1); } switch (cmd) { case "Restart": Log("Restarting bot"); try { Log("Stopping Bot"); BotMain.Stop(); Application.Current.Dispatcher.BeginInvoke((System.Action)(() => { try { Log("Starting Bot"); Thread.Sleep(1000); BotMain.Start(); } catch (Exception ex) { LogException(ex); } })); } catch (Exception ex) { LogException(ex); } Reset(); break; case "LoadProfile": LoadProfile(data); break; case "DifficultyLevel": var difficulty_level = Convert.ToInt32(data.Trim()); if (difficulty_level >= 0) { var difficulty = (GameDifficulty)System.Enum.Parse(typeof(GameDifficulty), data.Trim(), true); Log("Recieved DifficultyLevel: {0}", difficulty); CharacterSettings.Instance.GameDifficulty = difficulty; } break; case "ForceEnableAll": ForceEnableAllPlugins(); break; case "ForceEnableYar": ForceEnableYar(); break; case "FixPulse": FixPulse(); break; case "Shutdown": Log("Received Shutdown command"); SafeCloseProcess(); break; case "Roger!": case "Unknown command!": break; default: Log("Unknown response! \"{0} {1}\"", cmd, data); break; } _recieved = true; }