From ee7477b251813db3ba4a6bfcb8267707c8d5719c Mon Sep 17 00:00:00 2001 From: Egezenn Date: Thu, 7 May 2026 13:37:35 +0300 Subject: [PATCH 1/4] =?UTF-8?q?Record=20last=20"line=20guess"=20at=20the?= =?UTF-8?q?=20end=20of=20navigation=20link=20with=20segmentation=20-=20htt?= =?UTF-8?q?ps://github.com/Silkroad-Developer-Community/Silkroad-NavLink/i?= =?UTF-8?q?ssues/1=20-=20Untested,=20don't=20have=20a=20client=20to=20work?= =?UTF-8?q?=20with=20=F0=9F=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RSBot.Training/Bot/NavigationManager.cs | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/Botbases/RSBot.Training/Bot/NavigationManager.cs b/Botbases/RSBot.Training/Bot/NavigationManager.cs index 5fb2bc2e..02443c58 100644 --- a/Botbases/RSBot.Training/Bot/NavigationManager.cs +++ b/Botbases/RSBot.Training/Bot/NavigationManager.cs @@ -19,6 +19,7 @@ internal static class NavigationManager private static readonly object _linkageLock = new(); private static NavigationLinkage _linkage; private static List _activePath; + private static Position _targetPosition; // Persisted metadata for logging after clearing heavy linkage data private static string _linkageVersion; @@ -258,6 +259,7 @@ public static bool CalculatePathToTrainingArea() lock (_linkageLock) { _activePath = path; + _targetPosition = targetPos; _linkage = null; // Clear linkage data once path is cached to save memory } GC.Collect(); @@ -409,17 +411,19 @@ NavigationLinkage linkage public static string GenerateRBSFile() { List activePath; + Position targetPos; + lock (_linkageLock) { if (_activePath == null || _activePath.Count == 0) return null; activePath = new List(_activePath); + targetPos = _targetPosition; _activePath = null; // Clear path after generation } - var timestamp = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); - var fileName = $"{timestamp}.rbs"; + var fileName = $"dynamic_walk_{DateTime.Now:yyyyMMdd_HHmmss}.rbs"; var dynamicScriptsDir = Path.Combine(ScriptManager.InitialDirectory, "Dynamic"); if (!Directory.Exists(dynamicScriptsDir)) @@ -428,21 +432,25 @@ public static string GenerateRBSFile() var filePath = Path.Combine(dynamicScriptsDir, fileName); var rbsLines = new List(); + var lastPos = Game.Player.Movement.Source; + foreach (var step in activePath) { if (step.Edge.Type == "teleport") { rbsLines.Add($"teleport {step.Edge.Npc} {step.Edge.Dest}"); + lastPos = step.Position; } else { - // move XOffset YOffset ZOffset XSector YSector - rbsLines.Add( - $"move {step.Position.XOffset} {step.Position.YOffset} {step.Position.ZOffset} {step.Position.Region.X} {step.Position.Region.Y}" - ); + AddMoveCommands(rbsLines, lastPos, step.Position); + lastPos = step.Position; } } + // Final link to the actual target position + AddMoveCommands(rbsLines, lastPos, targetPos); + File.WriteAllLines(filePath, rbsLines); Log.Notify($"Generated dynamic walk script: {fileName}"); LogLinkageMetadata(); @@ -450,6 +458,36 @@ public static string GenerateRBSFile() return filePath; } + /// + /// Adds interpolated move commands to the list. + /// + private static void AddMoveCommands(List rbsLines, Position start, Position end) + { + var distance = start.DistanceTo(end); + if (distance < 1) + return; + + if (distance <= 50) + { + rbsLines.Add($"move {end.XOffset} {end.YOffset} {end.ZOffset} {end.Region.X} {end.Region.Y}"); + return; + } + + var segments = (int)Math.Ceiling(distance / 50.0); + for (var i = 1; i <= segments; i++) + { + var t = (float)i / segments; + var x = start.X + (end.X - start.X) * t; + var y = start.Y + (end.Y - start.Y) * t; + var z = start.ZOffset + (end.ZOffset - start.ZOffset) * t; + + var interpolatedPos = new Position(x, y, start.Region) { ZOffset = z }; + rbsLines.Add( + $"move {interpolatedPos.XOffset} {interpolatedPos.YOffset} {interpolatedPos.ZOffset} {interpolatedPos.Region.X} {interpolatedPos.Region.Y}" + ); + } + } + private class SemanticEdge { public string ToSid { get; set; } From 747886a59c67f95d30236ccd5002888202c8a3bb Mon Sep 17 00:00:00 2001 From: Egezenn Date: Fri, 5 Jun 2026 10:45:52 +0300 Subject: [PATCH 2/4] Remove GC and make the functionality region aware --- Botbases/RSBot.Training/Bot/NavigationManager.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Botbases/RSBot.Training/Bot/NavigationManager.cs b/Botbases/RSBot.Training/Bot/NavigationManager.cs index 02443c58..bf6e4739 100644 --- a/Botbases/RSBot.Training/Bot/NavigationManager.cs +++ b/Botbases/RSBot.Training/Bot/NavigationManager.cs @@ -262,7 +262,6 @@ public static bool CalculatePathToTrainingArea() _targetPosition = targetPos; _linkage = null; // Clear linkage data once path is cached to save memory } - GC.Collect(); return true; } @@ -481,7 +480,8 @@ private static void AddMoveCommands(List rbsLines, Position start, Posit var y = start.Y + (end.Y - start.Y) * t; var z = start.ZOffset + (end.ZOffset - start.ZOffset) * t; - var interpolatedPos = new Position(x, y, start.Region) { ZOffset = z }; + var currentRegion = t < 0.5 ? start.Region : end.Region; + var interpolatedPos = new Position(x, y, currentRegion) { ZOffset = z }; rbsLines.Add( $"move {interpolatedPos.XOffset} {interpolatedPos.YOffset} {interpolatedPos.ZOffset} {interpolatedPos.Region.X} {interpolatedPos.Region.Y}" ); From d2579dc6ef4e54fd53103235504c3ca3c888d233 Mon Sep 17 00:00:00 2001 From: Egezenn Date: Fri, 5 Jun 2026 10:49:14 +0300 Subject: [PATCH 3/4] Format --- Application/OasisBot/OasisBot.csproj | 1 - Application/OasisBot/Program.cs | 34 ++- .../Views/Controls/Cos/CosControlBase.cs | 48 ++-- Application/OasisBot/Views/Main.cs | 30 +- Botbases/RSBot.Alchemy/AlchemyBase.cs | 4 + Botbases/RSBot.Alchemy/AlchemyView.cs | 5 +- Botbases/RSBot.Alchemy/RSBot.Alchemy.csproj | 1 - Botbases/RSBot.Alchemy/Views/Main.cs | 6 +- Botbases/RSBot.Lure/LureBotbase.cs | 2 +- Botbases/RSBot.Lure/LureView.cs | 5 +- Botbases/RSBot.Lure/RSBot.Lure.csproj | 1 - Botbases/RSBot.Trade/RSBot.Trade.csproj | 1 - Botbases/RSBot.Trade/TradeManager.cs | 4 +- Botbases/RSBot.Trade/TradeView.cs | 5 +- .../Bundle/PartyBuffing/PartyBuffingBundle.cs | 14 +- Botbases/RSBot.Training/RSBot.Training.csproj | 1 - Botbases/RSBot.Training/TrainingBase.cs | 5 +- Botbases/RSBot.Training/TrainingManager.cs | 13 +- Botbases/RSBot.Training/TrainingView.cs | 6 +- Botbases/RSBot.Training/Views/Main.cs | 22 +- Library/RSBot.Core/Bot.cs | 6 +- Library/RSBot.Core/BotCL.cs | 1 + Library/RSBot.Core/Client/ReferenceManager.cs | 1 + .../RSBot.Core/Components/ClientManager.cs | 102 ++++--- .../Components/Command/CoreCLICommands.cs | 2 +- .../RSBot.Core/Components/PickupManager.cs | 3 +- .../RSBot.Core/Components/ShoppingManager.cs | 31 ++- Library/RSBot.Core/Config/GeneralConfig.cs | 12 +- Library/RSBot.Core/Config/GlobalConfig.cs | 5 +- Library/RSBot.Core/Kernel.cs | 2 +- .../Agent/Entity/EntityUpdatePvpFlag.cs | 3 +- .../Agent/Guild/GuildEntityUpdateResponse.cs | 8 +- .../Inventory/InventoryUpdateItemResponse.cs | 13 +- .../Agent/Party/PartyDistributionResponse.cs | 8 +- .../RSBot.Core/Network/NetworkUtilities.cs | 2 +- Library/RSBot.Core/Network/Packet.cs | 12 +- Library/RSBot.Core/Network/Socket/Server.cs | 21 +- .../RSBot.Core/Objects/CharacterInventory.cs | 6 +- .../Objects/Inventory/Item/ItemUpdateFlag.cs | 2 +- .../RSBot.Core/Objects/Inventory/Storage.cs | 6 +- Library/RSBot.Core/Plugins/BotbaseManager.cs | 5 +- Library/RSBot.Core/Plugins/IBotbase.cs | 1 - Library/RSBot.Core/Plugins/PluginManager.cs | 8 +- Library/RSBot.Core/RSBot.Core.csproj | 1 - Plugins/RSBot.Chat/Bundle/Chat.cs | 4 +- .../RSBot.Chat/Bundle/Network/ChatResponse.cs | 44 +-- .../Network/LinkedItemResponseHandler.cs | 4 +- Plugins/RSBot.Chat/ChatCLICommands.cs | 2 +- Plugins/RSBot.Chat/ChatManager.cs | 9 +- Plugins/RSBot.Chat/ChatPlugin.cs | 6 +- Plugins/RSBot.Chat/ChatView.cs | 4 +- Plugins/RSBot.Chat/RSBot.Chat.csproj | 1 - Plugins/RSBot.Chat/Views/Main.cs | 3 +- .../RSBot.CommandCenter.csproj | 1 - Plugins/RSBot.General/GeneralCLICommands.cs | 4 +- Plugins/RSBot.General/GeneralManager.cs | 39 ++- Plugins/RSBot.General/GeneralPlugin.cs | 3 +- Plugins/RSBot.General/GeneralView.cs | 4 +- Plugins/RSBot.General/RSBot.General.csproj | 1 - Plugins/RSBot.General/Views/Main.cs | 44 +-- Plugins/RSBot.Inventory/InventoryManager.cs | 14 +- Plugins/RSBot.Inventory/InventoryPlugin.cs | 2 + Plugins/RSBot.Inventory/InventoryView.cs | 4 +- .../RSBot.Inventory/RSBot.Inventory.csproj | 1 - Plugins/RSBot.Inventory/Views/Main.cs | 4 +- Plugins/RSBot.Items/ItemsManager.cs | 4 +- Plugins/RSBot.Items/ItemsPlugin.cs | 3 +- Plugins/RSBot.Items/ItemsView.cs | 3 +- Plugins/RSBot.Items/RSBot.Items.csproj | 1 - Plugins/RSBot.Log/LogManager.cs | 4 +- Plugins/RSBot.Log/LogPlugin.cs | 3 +- Plugins/RSBot.Log/LogView.cs | 16 +- Plugins/RSBot.Log/RSBot.Log.csproj | 1 - Plugins/RSBot.Map/MapManager.cs | 4 +- Plugins/RSBot.Map/MapPlugin.cs | 4 +- Plugins/RSBot.Map/MapView.cs | 5 +- Plugins/RSBot.Map/RSBot.Map.csproj | 1 - Plugins/RSBot.Map/Views/Main.cs | 7 +- .../Bundle/AutoParty/AutoPartyBundle.cs | 5 +- Plugins/RSBot.Party/PartyView.cs | 5 +- Plugins/RSBot.Party/RSBot.Party.csproj | 1 - Plugins/RSBot.Protection/ProtectionManager.cs | 3 +- Plugins/RSBot.Protection/ProtectionPlugin.cs | 2 + Plugins/RSBot.Protection/ProtectionView.cs | 5 +- .../RSBot.Protection/RSBot.Protection.csproj | 1 - .../Components/API/Core/API.Core.cs | 43 +-- .../Components/API/Core/Config/API.Config.cs | 15 +- .../Components/API/Core/Entity/API.Entity.cs | 98 +++++-- .../API/Core/Inventory/API.Inventory.cs | 30 +- .../Components/API/Core/Quests/API.Quests.cs | 42 ++- .../API/Core/Training/API.Training.cs | 39 ++- .../Components/API/GUI/API.Gui.cs | 256 +++++++++++++----- .../API/GUI/Controls/API.Gui.ButtonWrapper.cs | 1 - .../GUI/Controls/API.Gui.CheckboxWrapper.cs | 3 +- .../GUI/Controls/API.Gui.ComboboxWrapper.cs | 11 +- .../API/GUI/Controls/API.Gui.LabelWrapper.cs | 4 +- .../GUI/Controls/API.Gui.ListBoxWrapper.cs | 14 + .../Controls/API.Gui.RadioButtonWrapper.cs | 3 +- .../GUI/Controls/API.Gui.TextboxWrapper.cs | 2 + .../API/GUI/Wrapper/API.Gui.Wrapper.cs | 8 +- .../API/Handler/PythonErrorHandler.cs | 4 +- .../API/Handler/PythonInfoHandler.cs | 12 +- .../API/ModuleLoader/ModuleLoader.cs | 16 +- .../API/ModuleLoader/PythonPlugin.cs | 2 +- .../API/ModuleLoader/StubGenerator.cs | 91 ++++--- .../Components/Loader/PythonRuntimeManager.cs | 18 +- .../Components/Manager/PythonPluginManager.cs | 27 +- Plugins/RSBot.Python/PythonManager.cs | 4 +- Plugins/RSBot.Python/PythonPlugin.cs | 2 + Plugins/RSBot.Python/PythonView.cs | 5 +- Plugins/RSBot.Python/RSBot.Python.csproj | 28 +- Plugins/RSBot.Python/Views/Main.cs | 46 +++- Plugins/RSBot.Python/Views/View.cs | 2 +- Plugins/RSBot.Quest/QuestPlugin.cs | 2 + Plugins/RSBot.Quest/QuestView.cs | 5 +- Plugins/RSBot.Quest/RSBot.Quest.csproj | 1 - Plugins/RSBot.Quest/Views/Main.cs | 10 +- .../RSBot.ServerInfo/RSBot.ServerInfo.csproj | 1 - Plugins/RSBot.ServerInfo/ServerInfoManager.cs | 4 +- Plugins/RSBot.ServerInfo/ServerInfoPlugin.cs | 2 + Plugins/RSBot.ServerInfo/ServerInfoView.cs | 5 +- Plugins/RSBot.ServerInfo/Views/Main.cs | 2 + Plugins/RSBot.Skills/RSBot.Skills.csproj | 1 - Plugins/RSBot.Skills/SkillsManager.cs | 27 +- Plugins/RSBot.Skills/SkillsPlugin.cs | 7 +- Plugins/RSBot.Skills/SkillsView.cs | 5 +- Plugins/RSBot.Skills/Views/Main.cs | 12 +- .../RSBot.Statistics/RSBot.Statistics.csproj | 1 - Plugins/RSBot.Statistics/StatisticsManager.cs | 4 +- Plugins/RSBot.Statistics/StatisticsPlugin.cs | 2 + Plugins/RSBot.Statistics/StatisticsView.cs | 5 +- 131 files changed, 1015 insertions(+), 652 deletions(-) diff --git a/Application/OasisBot/OasisBot.csproj b/Application/OasisBot/OasisBot.csproj index f722637b..7ffd4512 100644 --- a/Application/OasisBot/OasisBot.csproj +++ b/Application/OasisBot/OasisBot.csproj @@ -47,4 +47,3 @@ - diff --git a/Application/OasisBot/Program.cs b/Application/OasisBot/Program.cs index 9a707b57..d1654beb 100644 --- a/Application/OasisBot/Program.cs +++ b/Application/OasisBot/Program.cs @@ -1,18 +1,18 @@ -using CommandLine; -using CommandLine.Text; -using RSBot.Core; -using RSBot.Core.Components; -using RSBot.Core.Event; -using RSBot.Core.Objects; -using RSBot.Views; using System; using System.Globalization; using System.Linq; using System.Reflection; +using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; +using CommandLine; +using CommandLine.Text; +using RSBot.Core; +using RSBot.Core.Components; using RSBot.Core.Components.Command; -using System.Runtime.InteropServices; +using RSBot.Core.Event; +using RSBot.Core.Objects; +using RSBot.Views; namespace RSBot; @@ -47,6 +47,7 @@ public class CommandLineOptions [Option("launch-clientless", Required = false, HelpText = "Start clientless")] public bool LaunchClientless { get; set; } + [Option("headless", Required = false, HelpText = "Start the bot without graphical user interface")] public bool Headless { get; set; } } @@ -82,7 +83,9 @@ private static void Main(string[] args) .WithNotParsed(errs => { DisplayHelp(parserResult); - var isHelp = errs.Any(e => e.Tag == ErrorType.HelpRequestedError || e.Tag == ErrorType.VersionRequestedError); + var isHelp = errs.Any(e => + e.Tag == ErrorType.HelpRequestedError || e.Tag == ErrorType.VersionRequestedError + ); Environment.Exit(isHelp ? 0 : 1); }); @@ -113,9 +116,13 @@ private static void Main(string[] args) Application.Run(mainForm); } } + private static void RunHeadless() { - EventManager.SubscribeEvent("OnAddLog", (string message, LogLevel level) => Terminal.WriteLog($"[{level}] {message}")); + EventManager.SubscribeEvent( + "OnAddLog", + (string message, LogLevel level) => Terminal.WriteLog($"[{level}] {message}") + ); EventManager.SubscribeEvent("OnChangeStatusText", (string status) => Terminal.WriteLog($"[Status] {status}")); BotCL.Initialize(ProfileManager.SelectedProfile); @@ -124,10 +131,12 @@ private static void RunHeadless() while (running) { var inputLine = Terminal.ReadLine(); - if (string.IsNullOrWhiteSpace(inputLine)) continue; + if (string.IsNullOrWhiteSpace(inputLine)) + continue; var input = inputLine.Split(','); - if (input == null || input.Length == 0) continue; + if (input == null || input.Length == 0) + continue; var command = input[0].ToLowerInvariant(); var args = input.Skip(1).ToArray(); @@ -141,6 +150,7 @@ private static void RunHeadless() CLIManager.Execute(command, args); } } + private static void RunOptions(CommandLineOptions options) { if (options.LaunchClient) diff --git a/Application/OasisBot/Views/Controls/Cos/CosControlBase.cs b/Application/OasisBot/Views/Controls/Cos/CosControlBase.cs index b2415e7f..a3f4ecc0 100644 --- a/Application/OasisBot/Views/Controls/Cos/CosControlBase.cs +++ b/Application/OasisBot/Views/Controls/Cos/CosControlBase.cs @@ -46,53 +46,41 @@ private void InitializeComponent() labelLevel = new Label(); panel1.SuspendLayout(); SuspendLayout(); - // + // // label1 - // + // label1.ApplyGradient = false; label1.AutoSize = true; label1.ForeColor = Color.FromArgb(0, 0, 0); - label1.Gradient = new Color[] -{ - Color.Gray, - Color.Black -}; + label1.Gradient = new Color[] { Color.Gray, Color.Black }; label1.GradientAnimation = false; label1.Location = new Point(14, 44); label1.Name = "label1"; label1.Size = new Size(31, 20); label1.TabIndex = 20; label1.Text = "HP:"; - // + // // lblPetName - // + // lblPetName.ApplyGradient = false; lblPetName.AutoSize = true; lblPetName.Dock = System.Windows.Forms.DockStyle.Left; lblPetName.Font = new Font("Segoe UI", 9F, FontStyle.Bold); lblPetName.ForeColor = Color.FromArgb(0, 0, 0); - lblPetName.Gradient = new Color[] -{ - Color.Gray, - Color.Black -}; + lblPetName.Gradient = new Color[] { Color.Gray, Color.Black }; lblPetName.GradientAnimation = false; lblPetName.Location = new Point(0, 0); lblPetName.Name = "lblPetName"; lblPetName.Size = new Size(103, 20); lblPetName.TabIndex = 19; lblPetName.Text = "No pet found"; - // + // // progressHP - // + // progressHP.BackColor = Color.Transparent; progressHP.DrawHatch = false; progressHP.ForeColor = Color.Firebrick; - progressHP.Gradient = new Color[] -{ - Color.Empty, - Color.Empty -}; + progressHP.Gradient = new Color[] { Color.Empty, Color.Empty }; progressHP.HatchType = HatchStyle.Percent10; progressHP.Location = new Point(48, 45); progressHP.Maximum = 100L; @@ -106,9 +94,9 @@ private void InitializeComponent() progressHP.TabIndex = 18; progressHP.Text = "0 / 100"; progressHP.Value = 0L; - // + // // panel1 - // + // panel1.BackColor = Color.Transparent; panel1.Border = new System.Windows.Forms.Padding(0, 0, 0, 0); panel1.BorderColor = Color.Transparent; @@ -120,27 +108,23 @@ private void InitializeComponent() panel1.ShadowDepth = 4F; panel1.Size = new Size(180, 21); panel1.TabIndex = 21; - // + // // labelLevel - // + // labelLevel.ApplyGradient = false; labelLevel.AutoSize = true; labelLevel.Dock = System.Windows.Forms.DockStyle.Left; labelLevel.Font = new Font("Segoe UI", 9F, FontStyle.Bold); labelLevel.ForeColor = Color.FromArgb(0, 0, 0); - labelLevel.Gradient = new Color[] -{ - Color.Gray, - Color.Black -}; + labelLevel.Gradient = new Color[] { Color.Gray, Color.Black }; labelLevel.GradientAnimation = false; labelLevel.Location = new Point(103, 0); labelLevel.Name = "labelLevel"; labelLevel.Size = new Size(0, 20); labelLevel.TabIndex = 20; - // + // // CosControlBase - // + // Controls.Add(panel1); Controls.Add(label1); Controls.Add(progressHP); diff --git a/Application/OasisBot/Views/Main.cs b/Application/OasisBot/Views/Main.cs index ebd502e5..e89cad07 100644 --- a/Application/OasisBot/Views/Main.cs +++ b/Application/OasisBot/Views/Main.cs @@ -71,7 +71,13 @@ public Main() // TODO private void donateButton_Click(object sender, EventArgs e) { - Process.Start(new ProcessStartInfo { FileName = "https://github.com/Silkroad-Developer-Community/OasisBot", UseShellExecute = true }); + Process.Start( + new ProcessStartInfo + { + FileName = "https://github.com/Silkroad-Developer-Community/OasisBot", + UseShellExecute = true, + } + ); } /// @@ -188,7 +194,11 @@ private async Task SelectBotbase(string name) var control = newBotbaseView.Value.View; control.Name = newBotbaseView.Value.Name; - control.Text = LanguageManager.GetLangBySpecificKey(newBotbaseView.Value.Name, "TabText", newBotbaseView.Value.TabText); + control.Text = LanguageManager.GetLangBySpecificKey( + newBotbaseView.Value.Name, + "TabText", + newBotbaseView.Value.TabText + ); control.Enabled = Game.Ready; windowPageControl.Controls.Add(control); @@ -246,7 +256,7 @@ private void LoadExtensions() var control = extension.Value.View; control.Name = extension.Value.InternalName; - + control.Text = LanguageManager.GetLangBySpecificKey( extension.Value.InternalName, "DisplayName", @@ -254,7 +264,7 @@ private void LoadExtensions() ); control.Enabled = !extension.Value.RequireIngame; control.Dock = DockStyle.Fill; - + windowPageControl.Controls.Add(control); if (control.Name == "RSBot.Python" && !GlobalConfig.Get("RSBot.ShowPythonPlugins", true)) windowPageControl.Controls.Remove(control); @@ -540,11 +550,12 @@ private void InitializeCustomButtons() TabStop = false, Tag = "private", Text = "START + SET AREA", - UseVisualStyleBackColor = false + UseVisualStyleBackColor = false, }; var gap = btnStartStop.Left - (btnSave.Left + btnSave.Width); - if (gap <= 0) gap = 6; + if (gap <= 0) + gap = 6; btnStartSetArea.Location = new Point(btnSave.Left - btnStartSetArea.Width - gap, btnSave.Top); @@ -851,11 +862,12 @@ private void buttonConfig_Click(object sender, EventArgs e) GlobalConfig.Set("RSBot.Network.BindIp", ipAddress.ToString()); } + private void pyPluginsToolStripMenuItem_Click(object sender, EventArgs e) { pyPluginsToolStripMenuItem.Checked = !pyPluginsToolStripMenuItem.Checked; GlobalConfig.Set("RSBot.ShowPythonPlugins", pyPluginsToolStripMenuItem.Checked.ToString()); - foreach( var plugin in Kernel.PluginManager.ExtensionsViews.Values) + foreach (var plugin in Kernel.PluginManager.ExtensionsViews.Values) { if (plugin.InternalName == "RSBot.Python") { @@ -871,7 +883,6 @@ private void pyPluginsToolStripMenuItem_Click(object sender, EventArgs e) if (pluginIndex == currentIndex) windowPageControl.SelectedIndex = 0; } - } } } @@ -1039,7 +1050,4 @@ private static void ApplyPlayerConfig() } #endregion Core events - - } - diff --git a/Botbases/RSBot.Alchemy/AlchemyBase.cs b/Botbases/RSBot.Alchemy/AlchemyBase.cs index ccbe872a..73385498 100644 --- a/Botbases/RSBot.Alchemy/AlchemyBase.cs +++ b/Botbases/RSBot.Alchemy/AlchemyBase.cs @@ -22,6 +22,7 @@ public void Start() Log.AppendFormat(LogLevel.Debug, "[Alchemy] Starting automated alchemy..."); } + public void Stop() { if (Globals.Botbase != null) @@ -29,17 +30,20 @@ public void Stop() Log.AppendFormat(LogLevel.Debug, "[Alchemy] Stopped automated alchemy"); } + public void Register() { Initialize(); Log.Debug("[Alchemy] Botbase registered to the kernel!"); } + public void Tick() { if (!Globals.View.IsRefreshing && !AlchemyManager.IsFusing) Globals.Botbase.Tick(); } + public void Initialize() { AlchemyEventsSubscriber.Subscribe(); diff --git a/Botbases/RSBot.Alchemy/AlchemyView.cs b/Botbases/RSBot.Alchemy/AlchemyView.cs index 6e0cb807..78cba1b2 100644 --- a/Botbases/RSBot.Alchemy/AlchemyView.cs +++ b/Botbases/RSBot.Alchemy/AlchemyView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Alchemy { @@ -11,6 +11,7 @@ public class AlchemyView : IBotbaseView public string DisplayName => "Alchemy"; public string TabText => DisplayName; public Control View => Globals.View; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Botbases/RSBot.Alchemy/RSBot.Alchemy.csproj b/Botbases/RSBot.Alchemy/RSBot.Alchemy.csproj index 40536102..aa977317 100644 --- a/Botbases/RSBot.Alchemy/RSBot.Alchemy.csproj +++ b/Botbases/RSBot.Alchemy/RSBot.Alchemy.csproj @@ -23,4 +23,3 @@ - diff --git a/Botbases/RSBot.Alchemy/Views/Main.cs b/Botbases/RSBot.Alchemy/Views/Main.cs index 7842e067..38c69f53 100644 --- a/Botbases/RSBot.Alchemy/Views/Main.cs +++ b/Botbases/RSBot.Alchemy/Views/Main.cs @@ -148,13 +148,15 @@ private void ReloadItemList() var newComboItem = new InventoryItemComboboxItem(item); int firstSlot = 13; - if (Game.ClientType == GameClientType.Global + if ( + Game.ClientType == GameClientType.Global || Game.ClientType == GameClientType.Korean || Game.ClientType == GameClientType.VTC_Game || Game.ClientType == GameClientType.RuSro || Game.ClientType == GameClientType.Turkey || Game.ClientType == GameClientType.Taiwan - || Game.ClientType == GameClientType.Japanese) + || Game.ClientType == GameClientType.Japanese + ) firstSlot = 17; //4 slots for relics if (item.Slot >= firstSlot) diff --git a/Botbases/RSBot.Lure/LureBotbase.cs b/Botbases/RSBot.Lure/LureBotbase.cs index b2002cf2..b84bb3f5 100644 --- a/Botbases/RSBot.Lure/LureBotbase.cs +++ b/Botbases/RSBot.Lure/LureBotbase.cs @@ -96,5 +96,5 @@ public void Stop() public void Register() { Log.Debug("[Lure] Botbase registered to the kernel!"); - } + } } diff --git a/Botbases/RSBot.Lure/LureView.cs b/Botbases/RSBot.Lure/LureView.cs index b8263392..194797ff 100644 --- a/Botbases/RSBot.Lure/LureView.cs +++ b/Botbases/RSBot.Lure/LureView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Lure { @@ -13,6 +13,7 @@ public class LureView : IBotbaseView public string TabText => DisplayName; public Control View => Views.View.Main; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Botbases/RSBot.Lure/RSBot.Lure.csproj b/Botbases/RSBot.Lure/RSBot.Lure.csproj index c16b3b25..3c422ace 100644 --- a/Botbases/RSBot.Lure/RSBot.Lure.csproj +++ b/Botbases/RSBot.Lure/RSBot.Lure.csproj @@ -23,4 +23,3 @@ - diff --git a/Botbases/RSBot.Trade/RSBot.Trade.csproj b/Botbases/RSBot.Trade/RSBot.Trade.csproj index 579b2ab8..aedb2034 100644 --- a/Botbases/RSBot.Trade/RSBot.Trade.csproj +++ b/Botbases/RSBot.Trade/RSBot.Trade.csproj @@ -23,4 +23,3 @@ - diff --git a/Botbases/RSBot.Trade/TradeManager.cs b/Botbases/RSBot.Trade/TradeManager.cs index 922761e1..5b8dff69 100644 --- a/Botbases/RSBot.Trade/TradeManager.cs +++ b/Botbases/RSBot.Trade/TradeManager.cs @@ -6,7 +6,5 @@ namespace RSBot.Trade { - internal class TradeManager - { - } + internal class TradeManager { } } diff --git a/Botbases/RSBot.Trade/TradeView.cs b/Botbases/RSBot.Trade/TradeView.cs index 6922b782..0e4073fa 100644 --- a/Botbases/RSBot.Trade/TradeView.cs +++ b/Botbases/RSBot.Trade/TradeView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Trade { @@ -11,6 +11,7 @@ public class TradeView : IBotbaseView public string DisplayName => "Trade"; public string TabText => DisplayName; public Control View => Views.View.Main; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Botbases/RSBot.Training/Bundle/PartyBuffing/PartyBuffingBundle.cs b/Botbases/RSBot.Training/Bundle/PartyBuffing/PartyBuffingBundle.cs index 69d01ff8..73771728 100644 --- a/Botbases/RSBot.Training/Bundle/PartyBuffing/PartyBuffingBundle.cs +++ b/Botbases/RSBot.Training/Bundle/PartyBuffing/PartyBuffingBundle.cs @@ -2,10 +2,10 @@ using System.Collections.Generic; using System.Linq; using RSBot.Core; +using RSBot.Core.Components; using RSBot.Core.Event; using RSBot.Core.Objects; using RSBot.Core.Objects.Party; -using RSBot.Core.Components; using RSBot.Core.Objects.Spawn; namespace RSBot.Training.Bundle.PartyBuffing; @@ -43,8 +43,8 @@ public void Invoke() var selectedGroup = PlayerConfig.Get("RSBot.Party.Buffing.SelectedGroup", "Default"); - SpawnManager.TryGetEntities(p => - BuffingPartyMembers.Any(s => s.Group == selectedGroup && s.Name == p.Name), + SpawnManager.TryGetEntities( + p => BuffingPartyMembers.Any(s => s.Group == selectedGroup && s.Name == p.Name), out var members ); @@ -72,9 +72,11 @@ out var members if (skill == null || skill.HasCooldown) continue; - if (!skill.Record.TargetGroup_Ally && - skill.Record.TargetGroup_Party && - !(Game.Party?.Members?.Any(p => p.Name == member.Name) ?? false)) + if ( + !skill.Record.TargetGroup_Ally + && skill.Record.TargetGroup_Party + && !(Game.Party?.Members?.Any(p => p.Name == member.Name) ?? false) + ) { continue; } diff --git a/Botbases/RSBot.Training/RSBot.Training.csproj b/Botbases/RSBot.Training/RSBot.Training.csproj index 52a92037..04b99dcc 100644 --- a/Botbases/RSBot.Training/RSBot.Training.csproj +++ b/Botbases/RSBot.Training/RSBot.Training.csproj @@ -21,4 +21,3 @@ - diff --git a/Botbases/RSBot.Training/TrainingBase.cs b/Botbases/RSBot.Training/TrainingBase.cs index 91b6f20f..2354670d 100644 --- a/Botbases/RSBot.Training/TrainingBase.cs +++ b/Botbases/RSBot.Training/TrainingBase.cs @@ -1,4 +1,5 @@ -using RSBot.Core; +using System; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Objects; using RSBot.Core.Plugins; @@ -6,7 +7,6 @@ using RSBot.Training.Bundle; using RSBot.Training.Components; using RSBot.Training.Subscriber; -using System; namespace RSBot.Training { @@ -56,6 +56,7 @@ public void Tick() Log.Fatal(ex); } } + /// /// Starts this instance. /// diff --git a/Botbases/RSBot.Training/TrainingManager.cs b/Botbases/RSBot.Training/TrainingManager.cs index 575527b5..cf9bce54 100644 --- a/Botbases/RSBot.Training/TrainingManager.cs +++ b/Botbases/RSBot.Training/TrainingManager.cs @@ -1,24 +1,25 @@ -using RSBot.Core; +using System.Timers; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Event; using RSBot.Core.Objects; using RSBot.Training.Bundle; -using System.Timers; namespace RSBot.Training { public class TrainingManager { private readonly Timer _pickPetTimer = new(200); - public TrainingManager() + + public TrainingManager() { _pickPetTimer.Elapsed += OnPickPetTimerElapsed; _pickPetTimer.AutoReset = true; _pickPetTimer.Start(); - } + public static void ApplyTrainingArea(float x, float y, ushort region) - { + { Position pos = new(x, y, region); PlayerConfig.Set("RSBot.Area.Region", pos.Region); @@ -32,11 +33,13 @@ public static void ApplyTrainingArea(float x, float y, ushort region) ); EventManager.FireEvent("OnSetTrainingArea"); } + public static void SetWalkingScript(string script) { PlayerConfig.Set("RSBot.Walkback.File", script); Log.Notify($"[Training area] New walking script set: {script}"); } + private void OnPickPetTimerElapsed(object sender, ElapsedEventArgs e) { if (Kernel.Bot.Running || !Game.Ready) diff --git a/Botbases/RSBot.Training/TrainingView.cs b/Botbases/RSBot.Training/TrainingView.cs index f2749a48..008cf260 100644 --- a/Botbases/RSBot.Training/TrainingView.cs +++ b/Botbases/RSBot.Training/TrainingView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Training { @@ -19,8 +19,6 @@ public class TrainingView : IBotbaseView /// public Control View => Views.View.Instance; - - /// /// Translate the botbase plugin /// diff --git a/Botbases/RSBot.Training/Views/Main.cs b/Botbases/RSBot.Training/Views/Main.cs index c4f1118c..39ded006 100644 --- a/Botbases/RSBot.Training/Views/Main.cs +++ b/Botbases/RSBot.Training/Views/Main.cs @@ -191,16 +191,16 @@ private void LoadAvoidance() var berserk = PlayerConfig.GetEnums("RSBot.Avoidance.Berserk").ToLookup(p => "Berserk", p => p); foreach (var group in avoid.Union(prefer).Union(berserk)) - foreach (var item in group) - { - var listViewItem = lvAvoidance - .Items.Cast() - .FirstOrDefault(p => ((MonsterRarity)p.Tag & item) == item); - if (listViewItem == null) - continue; - - listViewItem.Group = lvAvoidance.Groups[$"grp{group.Key}"]; - } + foreach (var item in group) + { + var listViewItem = lvAvoidance + .Items.Cast() + .FirstOrDefault(p => ((MonsterRarity)p.Tag & item) == item); + if (listViewItem == null) + continue; + + listViewItem.Group = lvAvoidance.Groups[$"grp{group.Key}"]; + } } /// @@ -434,7 +434,7 @@ private void InitializeCustomComponents() Location = new System.Drawing.Point(232, 27), Color = System.Drawing.Color.Transparent, Radius = 6, - ShadowDepth = 4F + ShadowDepth = 4F, }; btnRefetchNavLink.Click += async (s, e) => diff --git a/Library/RSBot.Core/Bot.cs b/Library/RSBot.Core/Bot.cs index 30dd06e3..840469fb 100644 --- a/Library/RSBot.Core/Bot.cs +++ b/Library/RSBot.Core/Bot.cs @@ -1,6 +1,6 @@ -using System.Threading; +using System; +using System.Threading; using System.Threading.Tasks; -using System; using RSBot.Core.Components; using RSBot.Core.Event; using RSBot.Core.Plugins; @@ -44,11 +44,13 @@ public void SetBotbase(IBotbase botBase) EventManager.FireEvent("OnSetBotbase", botBase); } + public void SetBotbaseView(IBotbaseView botBaseView) { BotbaseView = botBaseView; EventManager.FireEvent("OnSetBotbaseView", botBaseView); } + /// /// Starts this instance. /// diff --git a/Library/RSBot.Core/BotCL.cs b/Library/RSBot.Core/BotCL.cs index 8c23c0f3..0f77ab95 100644 --- a/Library/RSBot.Core/BotCL.cs +++ b/Library/RSBot.Core/BotCL.cs @@ -31,6 +31,7 @@ public static void Initialize(string profile) LoadExtensions(); } + public static void LoadExtensions() { foreach (var plugin in Kernel.PluginManager.Extensions.Values) diff --git a/Library/RSBot.Core/Client/ReferenceManager.cs b/Library/RSBot.Core/Client/ReferenceManager.cs index e4a7a922..0b6f5f0a 100644 --- a/Library/RSBot.Core/Client/ReferenceManager.cs +++ b/Library/RSBot.Core/Client/ReferenceManager.cs @@ -98,6 +98,7 @@ public void Load(int languageTab, BackgroundWorker worker) worker.ReportProgress(100, "Done"); EventManager.FireEvent("OnLoadGameData"); } + public void Load() { var sw = Stopwatch.StartNew(); diff --git a/Library/RSBot.Core/Components/ClientManager.cs b/Library/RSBot.Core/Components/ClientManager.cs index c2270f26..df4055ae 100644 --- a/Library/RSBot.Core/Components/ClientManager.cs +++ b/Library/RSBot.Core/Components/ClientManager.cs @@ -31,10 +31,7 @@ public class ClientManager public static async Task Start() { var silkroadDirectory = GlobalConfig.Get("RSBot.SilkroadDirectory"); - var path = Path.Combine( - silkroadDirectory, - GlobalConfig.Get("RSBot.SilkroadExecutable") - ); + var path = Path.Combine(silkroadDirectory, GlobalConfig.Get("RSBot.SilkroadExecutable")); string libraryDllName = "Client.Library.dll"; string fullPath = Path.Combine(Kernel.BasePath, libraryDllName); @@ -51,13 +48,13 @@ public static async Task Start() var si = new STARTUPINFO(); bool specialClient = - Game.ClientType == GameClientType.RuSro || - Game.ClientType == GameClientType.Global || - Game.ClientType == GameClientType.Korean || - Game.ClientType == GameClientType.VTC_Game || - Game.ClientType == GameClientType.Turkey || - Game.ClientType == GameClientType.Taiwan || - Game.ClientType == GameClientType.Japanese; + Game.ClientType == GameClientType.RuSro + || Game.ClientType == GameClientType.Global + || Game.ClientType == GameClientType.Korean + || Game.ClientType == GameClientType.VTC_Game + || Game.ClientType == GameClientType.Turkey + || Game.ClientType == GameClientType.Taiwan + || Game.ClientType == GameClientType.Japanese; if (Game.ClientType == GameClientType.RuSro) { @@ -66,18 +63,20 @@ public static async Task Start() args = $"-LOGIN:{login} -PASSWORD:{password}"; } - if (!CreateProcess( - null, - $"\"{path}\" {args}", - IntPtr.Zero, - IntPtr.Zero, - false, - CREATE_SUSPENDED, - IntPtr.Zero, - silkroadDirectory, - ref si, - out var pi - )) + if ( + !CreateProcess( + null, + $"\"{path}\" {args}", + IntPtr.Zero, + IntPtr.Zero, + false, + CREATE_SUSPENDED, + IntPtr.Zero, + silkroadDirectory, + ref si, + out var pi + ) + ) return false; PrepareTempConfigFile(pi.dwProcessId, divisionIndex); @@ -104,9 +103,9 @@ out var pi SuspendThread(pi.hThread); if ( - Game.ClientType == GameClientType.VTC_Game || - Game.ClientType == GameClientType.Turkey || - Game.ClientType == GameClientType.Taiwan + Game.ClientType == GameClientType.VTC_Game + || Game.ClientType == GameClientType.Turkey + || Game.ClientType == GameClientType.Taiwan ) { ApplyXigncodePatch(sroProcess, pi); @@ -132,13 +131,7 @@ out var pi if (loadLibAddr == IntPtr.Zero) return false; - IntPtr remotePath = VirtualAllocEx( - handle, - IntPtr.Zero, - pathLen, - MEM_COMMIT | MEM_RESERVE, - PAGE_READWRITE - ); + IntPtr remotePath = VirtualAllocEx(handle, IntPtr.Zero, pathLen, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); if (remotePath == IntPtr.Zero) return false; @@ -146,15 +139,7 @@ out var pi if (!WriteProcessMemory(handle, remotePath, buffer, pathLen, out _)) return false; - IntPtr remoteThread = CreateRemoteThread( - handle, - IntPtr.Zero, - 0, - loadLibAddr, - remotePath, - 0, - IntPtr.Zero - ); + IntPtr remoteThread = CreateRemoteThread(handle, IntPtr.Zero, 0, loadLibAddr, remotePath, 0, IntPtr.Zero); if (remoteThread == IntPtr.Zero) return false; @@ -202,7 +187,8 @@ out _ var patchNop2 = new byte[] { 0x90, 0x90, 0x90, 0x90, 0x90 }; var patchJmp = new byte[] { 0xEB }; - string signature = "55 8B EC 83 EC ?? 8B 45 ?? 50 E8 ?? ?? ?? ?? 83 C4 04 89 45 ?? 8B 4D ?? 89 4D ?? 68 ?? ?? ?? ?? 6A 00 6A 00"; + string signature = + "55 8B EC 83 EC ?? 8B 45 ?? 50 E8 ?? ?? ?? ?? 83 C4 04 89 45 ?? 8B 4D ?? 89 4D ?? 68 ?? ?? ?? ?? 6A 00 6A 00"; int baseAddress = process.MainModule.BaseAddress.ToInt32(); var address = FindPattern(signature, moduleMemory, baseAddress); @@ -258,10 +244,12 @@ out _ var callTargetCounts = new System.Collections.Generic.Dictionary(); for (int i = sysEnterOffset; i < searchEnd; i++) { - if (moduleMemory[i] == 0xE8 && - moduleMemory[i + 5] == 0x83 && - moduleMemory[i + 6] == 0xC4 && - moduleMemory[i + 7] == 0x0C) + if ( + moduleMemory[i] == 0xE8 + && moduleMemory[i + 5] == 0x83 + && moduleMemory[i + 6] == 0xC4 + && moduleMemory[i + 7] == 0x0C + ) { int rel = BitConverter.ToInt32(moduleMemory, i + 1); int targetOffset = i + 5 + rel; @@ -323,12 +311,17 @@ private static int FindXigncodeAnchor(byte[] memory, byte[] xigncodeUtf16, int b for (int ci = 0; ci <= memory.Length - 18; ci++) { - if (memory[ci] == 0x6A && memory[ci + 1] == 0x00 && - memory[ci + 2] == 0x68 && - memory[ci + 3] == vaBytes[0] && memory[ci + 4] == vaBytes[1] && - memory[ci + 5] == vaBytes[2] && memory[ci + 6] == vaBytes[3] && - memory[ci + 7] == 0x68 && - memory[ci + 12] == 0xE8) + if ( + memory[ci] == 0x6A + && memory[ci + 1] == 0x00 + && memory[ci + 2] == 0x68 + && memory[ci + 3] == vaBytes[0] + && memory[ci + 4] == vaBytes[1] + && memory[ci + 5] == vaBytes[2] + && memory[ci + 6] == vaBytes[3] + && memory[ci + 7] == 0x68 + && memory[ci + 12] == 0xE8 + ) { return ci; } @@ -434,7 +427,8 @@ private static void PrepareTempConfigFile(uint processId, int divisionIndex) /// private static IntPtr FindPattern(string stringPattern, byte[] buffer, int baseAddress) { - var pattern = stringPattern.Split(' ') + var pattern = stringPattern + .Split(' ') .Select(p => p == "??" || p == "?" ? -1 : int.Parse(p, NumberStyles.AllowHexSpecifier)) .ToArray(); diff --git a/Library/RSBot.Core/Components/Command/CoreCLICommands.cs b/Library/RSBot.Core/Components/Command/CoreCLICommands.cs index c23d2065..603755fc 100644 --- a/Library/RSBot.Core/Components/Command/CoreCLICommands.cs +++ b/Library/RSBot.Core/Components/Command/CoreCLICommands.cs @@ -1,5 +1,5 @@ -using RSBot.Core.Components.Command; using System; +using RSBot.Core.Components.Command; namespace RSBot.Core.Components.Command; diff --git a/Library/RSBot.Core/Components/PickupManager.cs b/Library/RSBot.Core/Components/PickupManager.cs index b08f09e1..46a03233 100644 --- a/Library/RSBot.Core/Components/PickupManager.cs +++ b/Library/RSBot.Core/Components/PickupManager.cs @@ -219,8 +219,7 @@ private static bool Condition( if (applyPickOnlyChar && e.IsBehindObstacle) return false; - bool isItemAutoShareParty = Game.Party.IsInParty && - Game.Party.Settings.GetPartyType() is 2 or 3 or 6 or 7; + bool isItemAutoShareParty = Game.Party.IsInParty && Game.Party.Settings.GetPartyType() is 2 or 3 or 6 or 7; if (isItemAutoShareParty && PickupGold && e.Record.IsGold) { diff --git a/Library/RSBot.Core/Components/ShoppingManager.cs b/Library/RSBot.Core/Components/ShoppingManager.cs index 30a949c7..858c6281 100644 --- a/Library/RSBot.Core/Components/ShoppingManager.cs +++ b/Library/RSBot.Core/Components/ShoppingManager.cs @@ -1,14 +1,14 @@ -using RSBot.Core.Client.ReferenceObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Xml; +using RSBot.Core.Client.ReferenceObjects; using RSBot.Core.Network; using RSBot.Core.Objects; using RSBot.Core.Objects.Cos; using RSBot.Core.Objects.Inventory; using RSBot.Core.Objects.Spawn; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Xml; using static RSBot.Core.Game; namespace RSBot.Core.Components; @@ -433,13 +433,15 @@ public static void RepairItems(string npcCodeName) public static void StoreItems(string npcCodeName) { int firstSlot = 13; - if (Game.ClientType == GameClientType.Global + if ( + Game.ClientType == GameClientType.Global || Game.ClientType == GameClientType.Korean || Game.ClientType == GameClientType.VTC_Game || Game.ClientType == GameClientType.RuSro || Game.ClientType == GameClientType.Turkey || Game.ClientType == GameClientType.Taiwan - || Game.ClientType == GameClientType.Japanese) + || Game.ClientType == GameClientType.Japanese + ) firstSlot = 17; //4 slots for relics var tempInventory = Game.Player.Inventory.GetItems(item => @@ -520,7 +522,7 @@ public static void SortItems(string npcCodeName) Game.Player.GuildStorage.Sort(npc); allStorageItems = Game.Player.GuildStorage.GetItems(item => true); } - + if (allStorageItems == null || allStorageItems.Count == 0) { if (!npc.Record.CodeName.Contains("WAREHOUSE")) @@ -542,17 +544,17 @@ public static void SortItems(string npcCodeName) // Get remaining items at or after slot i, ordered by grouping key List remaining = null; if (npc.Record.CodeName.Contains("WAREHOUSE")) - { - remaining = Game.Player.Storage - .GetItems(it => it.Slot >= i) + { + remaining = Game + .Player.Storage.GetItems(it => it.Slot >= i) .OrderBy(it => it.ItemId) .ThenBy(it => it.Slot) .ToList(); } else { - remaining = Game.Player.GuildStorage - .GetItems(it => it.Slot >= i) + remaining = Game + .Player.GuildStorage.GetItems(it => it.Slot >= i) .OrderBy(it => it.ItemId) .ThenBy(it => it.Slot) .ToList(); @@ -600,7 +602,6 @@ public static void SortItems(string npcCodeName) Thread.Sleep(500); } } - } if (!npc.Record.CodeName.Contains("WAREHOUSE")) diff --git a/Library/RSBot.Core/Config/GeneralConfig.cs b/Library/RSBot.Core/Config/GeneralConfig.cs index cf1957fa..3b8726aa 100644 --- a/Library/RSBot.Core/Config/GeneralConfig.cs +++ b/Library/RSBot.Core/Config/GeneralConfig.cs @@ -26,7 +26,8 @@ public static void Load() /// public static bool Exists(string key) { - if (_config == null) Load(); + if (_config == null) + Load(); return _config.Exists(key); } @@ -37,7 +38,8 @@ public static bool Exists(string key) /// The default value. public static T Get(string key, T defaultValue = default) { - if (_config == null) Load(); + if (_config == null) + Load(); return _config.Get(key, defaultValue); } @@ -48,7 +50,8 @@ public static T Get(string key, T defaultValue = default) /// The value. public static void Set(string key, T value) { - if (_config == null) Load(); + if (_config == null) + Load(); _config.Set(key, value); } @@ -57,7 +60,8 @@ public static void Set(string key, T value) /// public static void Save() { - if (_config == null) return; + if (_config == null) + return; try { diff --git a/Library/RSBot.Core/Config/GlobalConfig.cs b/Library/RSBot.Core/Config/GlobalConfig.cs index d50ed972..1613ab16 100644 --- a/Library/RSBot.Core/Config/GlobalConfig.cs +++ b/Library/RSBot.Core/Config/GlobalConfig.cs @@ -23,10 +23,7 @@ public static void Load() _config = new Config(path); // Migration: PR #934 "RSBot.Default" was moved to "RSBot.Training" - if ( - _config.Exists("RSBot.BotName") - && _config.Get("RSBot.BotName") == "RSBot.Default" - ) + if (_config.Exists("RSBot.BotName") && _config.Get("RSBot.BotName") == "RSBot.Default") { _config.Set("RSBot.BotName", "RSBot.Training"); _config.Save(); diff --git a/Library/RSBot.Core/Kernel.cs b/Library/RSBot.Core/Kernel.cs index b488c0f2..5a3fec89 100644 --- a/Library/RSBot.Core/Kernel.cs +++ b/Library/RSBot.Core/Kernel.cs @@ -3,10 +3,10 @@ using System.Threading; using System.Threading.Tasks; using RSBot.Core.Components; +using RSBot.Core.Components.Command; using RSBot.Core.Event; using RSBot.Core.Network; using RSBot.Core.Plugins; -using RSBot.Core.Components.Command; namespace RSBot.Core; diff --git a/Library/RSBot.Core/Network/Handler/Agent/Entity/EntityUpdatePvpFlag.cs b/Library/RSBot.Core/Network/Handler/Agent/Entity/EntityUpdatePvpFlag.cs index 991c8ab0..49d16858 100644 --- a/Library/RSBot.Core/Network/Handler/Agent/Entity/EntityUpdatePvpFlag.cs +++ b/Library/RSBot.Core/Network/Handler/Agent/Entity/EntityUpdatePvpFlag.cs @@ -18,7 +18,7 @@ public void Invoke(Packet packet) var uniqueId = packet.ReadUInt(); var flag = (PvpFlag)packet.ReadByte(); - if(Game.Player.UniqueId == uniqueId) + if (Game.Player.UniqueId == uniqueId) { var oldFlag = Game.Player.PvpFlag; Game.Player.PvpFlag = flag; @@ -33,7 +33,6 @@ public void Invoke(Packet packet) var oldPvpFlag = entity.PvpCape; entity.PvpCape = flag; - Log.Notify($"[{entity.Name}] pvp status updated from {oldPvpFlag} to {flag}"); } } diff --git a/Library/RSBot.Core/Network/Handler/Agent/Guild/GuildEntityUpdateResponse.cs b/Library/RSBot.Core/Network/Handler/Agent/Guild/GuildEntityUpdateResponse.cs index 07345431..409c1125 100644 --- a/Library/RSBot.Core/Network/Handler/Agent/Guild/GuildEntityUpdateResponse.cs +++ b/Library/RSBot.Core/Network/Handler/Agent/Guild/GuildEntityUpdateResponse.cs @@ -1,10 +1,10 @@ -using RSBot.Core.Components; -using RSBot.Core.Objects.Spawn; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using RSBot.Core.Components; +using RSBot.Core.Objects.Spawn; namespace RSBot.Core.Network.Handler.Agent.Guild { @@ -18,7 +18,7 @@ public void Invoke(Packet packet) { uint entityId = packet.ReadUInt(); packet.ReadUInt(); //guildId - string guildName = packet.ReadString(); + string guildName = packet.ReadString(); packet.ReadString(); //grandName packet.ReadUInt(); //guild emblem packet.ReadUInt(); //unionId diff --git a/Library/RSBot.Core/Network/Handler/Agent/Inventory/InventoryUpdateItemResponse.cs b/Library/RSBot.Core/Network/Handler/Agent/Inventory/InventoryUpdateItemResponse.cs index 8ecbae5b..729cdc4e 100644 --- a/Library/RSBot.Core/Network/Handler/Agent/Inventory/InventoryUpdateItemResponse.cs +++ b/Library/RSBot.Core/Network/Handler/Agent/Inventory/InventoryUpdateItemResponse.cs @@ -29,15 +29,13 @@ internal class InventoryUpdateItemResponse : IPacketHandler /// The packet. public void Invoke(Packet packet) { - if (Game.ClientType == GameClientType.Global - || Game.ClientType == GameClientType.RuSro) + if (Game.ClientType == GameClientType.Global || Game.ClientType == GameClientType.RuSro) if (packet.ReadByte() != 0) //sometimes appears 9 with unknown structure - return; + return; var sourceSlot = packet.ReadByte(); - if (Game.ClientType == GameClientType.Global - || Game.ClientType == GameClientType.RuSro) + if (Game.ClientType == GameClientType.Global || Game.ClientType == GameClientType.RuSro) packet.ReadByte(); //0 - normal, 2 - item disappearing var itemUpdateFlag = (ItemUpdateFlag)packet.ReadByte(); @@ -61,10 +59,7 @@ public void Invoke(Packet packet) if (itemUpdateFlag.HasFlag(ItemUpdateFlag.Durability)) item.Durability = packet.ReadUInt(); - if ( - itemUpdateFlag.HasFlag(ItemUpdateFlag.State) || - itemUpdateFlag.HasFlag(ItemUpdateFlag.State2) - ) + if (itemUpdateFlag.HasFlag(ItemUpdateFlag.State) || itemUpdateFlag.HasFlag(ItemUpdateFlag.State2)) item.State = (InventoryItemState)packet.ReadByte(); if (itemUpdateFlag.HasFlag(ItemUpdateFlag.MagParams)) diff --git a/Library/RSBot.Core/Network/Handler/Agent/Party/PartyDistributionResponse.cs b/Library/RSBot.Core/Network/Handler/Agent/Party/PartyDistributionResponse.cs index e7ac9bb0..bc9239b1 100644 --- a/Library/RSBot.Core/Network/Handler/Agent/Party/PartyDistributionResponse.cs +++ b/Library/RSBot.Core/Network/Handler/Agent/Party/PartyDistributionResponse.cs @@ -29,7 +29,9 @@ public void Invoke(Packet packet) //ITEM_EU_ //ITEM_AVATAR_ byte optLevel = packet.ReadByte(); - Log.Notify($"Item [{item.GetRealName() ?? itemId.ToString()} (+{optLevel})] is distributed to [{member.Name}]."); + Log.Notify( + $"Item [{item.GetRealName() ?? itemId.ToString()} (+{optLevel})] is distributed to [{member.Name}]." + ); } else if (item.TypeID2 == 2) { @@ -40,7 +42,9 @@ public void Invoke(Packet packet) { //ITEM_ETC_ ushort quantity = packet.ReadUShort(); - Log.Notify($"Item [{item.GetRealName() ?? itemId.ToString()} {quantity} pieces] is distributed to [{member.Name}]."); + Log.Notify( + $"Item [{item.GetRealName() ?? itemId.ToString()} {quantity} pieces] is distributed to [{member.Name}]." + ); } } } diff --git a/Library/RSBot.Core/Network/NetworkUtilities.cs b/Library/RSBot.Core/Network/NetworkUtilities.cs index a741a227..d8d0933e 100644 --- a/Library/RSBot.Core/Network/NetworkUtilities.cs +++ b/Library/RSBot.Core/Network/NetworkUtilities.cs @@ -25,7 +25,7 @@ public static ushort GetFreePort(ushort start, ushort end, ushort step = 1) using var listener = new TcpListener(IPAddress.Loopback, port); listener.Start(); listener.Stop(); - return port; // Successfully bound → free + return port; // Successfully bound → free } catch (SocketException) { diff --git a/Library/RSBot.Core/Network/Packet.cs b/Library/RSBot.Core/Network/Packet.cs index db31d1d7..9873ad12 100644 --- a/Library/RSBot.Core/Network/Packet.cs +++ b/Library/RSBot.Core/Network/Packet.cs @@ -591,9 +591,11 @@ public string ReadString(int codepage = 1254) if (Game.ClientType == GameClientType.Japanese) codepage = 932; - if (Game.ClientType == GameClientType.Global + if ( + Game.ClientType == GameClientType.Global || Game.ClientType == GameClientType.VTC_Game - || Game.ClientType == GameClientType.Turkey) + || Game.ClientType == GameClientType.Turkey + ) codepage = 65001; return Encoding.GetEncoding(codepage).GetString(bytes); @@ -1141,9 +1143,11 @@ public void WriteString(string value, int codePage = 1254) if (Game.ClientType == GameClientType.Japanese) codePage = 932; - if (Game.ClientType == GameClientType.Global + if ( + Game.ClientType == GameClientType.Global || Game.ClientType == GameClientType.VTC_Game - || Game.ClientType == GameClientType.Turkey) + || Game.ClientType == GameClientType.Turkey + ) codePage = 65001; var bytes = Encoding.GetEncoding(codePage).GetBytes(value); diff --git a/Library/RSBot.Core/Network/Socket/Server.cs b/Library/RSBot.Core/Network/Socket/Server.cs index 765b5cef..b83d227e 100644 --- a/Library/RSBot.Core/Network/Socket/Server.cs +++ b/Library/RSBot.Core/Network/Socket/Server.cs @@ -1,9 +1,9 @@ -using RSBot.Core.Event; -using RSBot.Core.Extensions; -using RSBot.Core.Network.Protocol; -using System; +using System; using System.Net; using System.Net.Sockets; +using RSBot.Core.Event; +using RSBot.Core.Extensions; +using RSBot.Core.Network.Protocol; namespace RSBot.Core.Network; @@ -67,7 +67,7 @@ public void Connect(string ip, ushort port) { _socket.Connect(ip, port, 3000); } - } + } catch (AggregateException s) { Log.Error(s.Message); @@ -120,8 +120,15 @@ private void OnBeginReceiveCallback(IAsyncResult ar) if (receivedSize == 0 || error != SocketError.Success) { - if (!IsClosing && EnablePacketDispatcher && _receivedInitialHandshake && !_receivedPostInitialHandshakePacket) - Log.Notify("Gateway closed immediately after initial 0x5000 before handshake completed. Possible IP/session limit"); + if ( + !IsClosing + && EnablePacketDispatcher + && _receivedInitialHandshake + && !_receivedPostInitialHandshakePacket + ) + Log.Notify( + "Gateway closed immediately after initial 0x5000 before handshake completed. Possible IP/session limit" + ); OnDisconnected(); return; diff --git a/Library/RSBot.Core/Objects/CharacterInventory.cs b/Library/RSBot.Core/Objects/CharacterInventory.cs index 1d225021..7b608e87 100644 --- a/Library/RSBot.Core/Objects/CharacterInventory.cs +++ b/Library/RSBot.Core/Objects/CharacterInventory.cs @@ -179,13 +179,15 @@ public void Sort() var blacklistedItems = new List(4); int firstSlot = 13; - if (Game.ClientType == GameClientType.Global + if ( + Game.ClientType == GameClientType.Global || Game.ClientType == GameClientType.Korean || Game.ClientType == GameClientType.VTC_Game || Game.ClientType == GameClientType.RuSro || Game.ClientType == GameClientType.Turkey || Game.ClientType == GameClientType.Taiwan - || Game.ClientType == GameClientType.Japanese) + || Game.ClientType == GameClientType.Japanese + ) firstSlot = 17; //4 slots for relics for (var iIteration = 0; iIteration < maxIterations; iIteration++) diff --git a/Library/RSBot.Core/Objects/Inventory/Item/ItemUpdateFlag.cs b/Library/RSBot.Core/Objects/Inventory/Item/ItemUpdateFlag.cs index 1c92e9f5..d8db7686 100644 --- a/Library/RSBot.Core/Objects/Inventory/Item/ItemUpdateFlag.cs +++ b/Library/RSBot.Core/Objects/Inventory/Item/ItemUpdateFlag.cs @@ -13,5 +13,5 @@ public enum ItemUpdateFlag : byte Durability = 16, MagParams = 32, State = 64, - State2 = 128 + State2 = 128, } diff --git a/Library/RSBot.Core/Objects/Inventory/Storage.cs b/Library/RSBot.Core/Objects/Inventory/Storage.cs index 358df3e3..3d67483a 100644 --- a/Library/RSBot.Core/Objects/Inventory/Storage.cs +++ b/Library/RSBot.Core/Objects/Inventory/Storage.cs @@ -1,7 +1,7 @@ -using RSBot.Core.Network; -using RSBot.Core.Objects.Spawn; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; +using RSBot.Core.Network; +using RSBot.Core.Objects.Spawn; namespace RSBot.Core.Objects.Inventory; diff --git a/Library/RSBot.Core/Plugins/BotbaseManager.cs b/Library/RSBot.Core/Plugins/BotbaseManager.cs index 5ed4dc8b..eafc7a53 100644 --- a/Library/RSBot.Core/Plugins/BotbaseManager.cs +++ b/Library/RSBot.Core/Plugins/BotbaseManager.cs @@ -78,7 +78,10 @@ public bool LoadAssemblies(bool isHeadless = false) /// /// The file. /// - private static (Dictionary bots, Dictionary views) GetExtensionsFromAssembly(string file) + private static ( + Dictionary bots, + Dictionary views + ) GetExtensionsFromAssembly(string file) { var bots = new Dictionary(); var views = new Dictionary(); diff --git a/Library/RSBot.Core/Plugins/IBotbase.cs b/Library/RSBot.Core/Plugins/IBotbase.cs index bc8ef80a..00069240 100644 --- a/Library/RSBot.Core/Plugins/IBotbase.cs +++ b/Library/RSBot.Core/Plugins/IBotbase.cs @@ -13,7 +13,6 @@ public interface IBotbase /// public string Name { get; } - /// /// Gets the area. /// diff --git a/Library/RSBot.Core/Plugins/PluginManager.cs b/Library/RSBot.Core/Plugins/PluginManager.cs index bafbf677..1f577a99 100644 --- a/Library/RSBot.Core/Plugins/PluginManager.cs +++ b/Library/RSBot.Core/Plugins/PluginManager.cs @@ -35,7 +35,7 @@ public bool LoadAssemblies(bool isHeadless = false) if (Extensions != null) return false; - Extensions = new Dictionary(); + Extensions = new Dictionary(); ExtensionsViews = new Dictionary(); try @@ -65,7 +65,9 @@ public bool LoadAssemblies(bool isHeadless = false) } } //order by index, not alphabeticaly - ExtensionsViews = ExtensionsViews.OrderBy(entry => entry.Value.Index).ToDictionary(x => x.Key, x => x.Value); + ExtensionsViews = ExtensionsViews + .OrderBy(entry => entry.Value.Index) + .ToDictionary(x => x.Key, x => x.Value); EventManager.FireEvent("OnLoadPlugins"); @@ -90,7 +92,7 @@ private static (Dictionary, Dictionary) Ge { var plugins = new Dictionary(); var views = new Dictionary(); -; + ; try { diff --git a/Library/RSBot.Core/RSBot.Core.csproj b/Library/RSBot.Core/RSBot.Core.csproj index 116f5b50..2b69ca37 100644 --- a/Library/RSBot.Core/RSBot.Core.csproj +++ b/Library/RSBot.Core/RSBot.Core.csproj @@ -18,4 +18,3 @@ - diff --git a/Plugins/RSBot.Chat/Bundle/Chat.cs b/Plugins/RSBot.Chat/Bundle/Chat.cs index c3443612..0ec9cf2a 100644 --- a/Plugins/RSBot.Chat/Bundle/Chat.cs +++ b/Plugins/RSBot.Chat/Bundle/Chat.cs @@ -1,8 +1,8 @@ -using RSBot.Core; +using System.Collections.Generic; +using RSBot.Core; using RSBot.Core.Extensions; using RSBot.Core.Network; using RSBot.Core.Objects; -using System.Collections.Generic; namespace RSBot.Chat.Bundle; diff --git a/Plugins/RSBot.Chat/Bundle/Network/ChatResponse.cs b/Plugins/RSBot.Chat/Bundle/Network/ChatResponse.cs index b2fd06ca..e9266fc2 100644 --- a/Plugins/RSBot.Chat/Bundle/Network/ChatResponse.cs +++ b/Plugins/RSBot.Chat/Bundle/Network/ChatResponse.cs @@ -1,4 +1,7 @@ -using RSBot.Chat.Views; +using System.Collections.Generic; +using System.Numerics; +using System.Text.RegularExpressions; +using RSBot.Chat.Views; using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Event; @@ -6,9 +9,6 @@ using RSBot.Core.Network; using RSBot.Core.Objects; using RSBot.Core.Objects.Spawn; -using System.Collections.Generic; -using System.Numerics; -using System.Text.RegularExpressions; namespace RSBot.Chat.Network; @@ -90,30 +90,32 @@ public static string ReadChatWithLinkedItems(string message) { const string pattern = "\u0002(.*?)\u0003"; - return Regex.Replace(message, pattern, match => - { - string rawValue = match.Groups[1].Value; - - if (uint.TryParse(rawValue, out uint uid)) + return Regex.Replace( + message, + pattern, + match => { - if (Bundle.Chat.LinkedItems.TryGetValue(uid, out var data) && data.itemName != null) + string rawValue = match.Groups[1].Value; + + if (uint.TryParse(rawValue, out uint uid)) { - bool hasSpaceBefore = match.Index > 0 && char.IsWhiteSpace(message[match.Index - 1]); + if (Bundle.Chat.LinkedItems.TryGetValue(uid, out var data) && data.itemName != null) + { + bool hasSpaceBefore = match.Index > 0 && char.IsWhiteSpace(message[match.Index - 1]); - int endOfMatch = match.Index + match.Length; - bool hasSpaceAfter = endOfMatch < message.Length && char.IsWhiteSpace(message[endOfMatch]); + int endOfMatch = match.Index + match.Length; + bool hasSpaceAfter = endOfMatch < message.Length && char.IsWhiteSpace(message[endOfMatch]); - string leftPadding = hasSpaceBefore ? "" : " "; - string rightPadding = hasSpaceAfter ? "" : " "; + string leftPadding = hasSpaceBefore ? "" : " "; + string rightPadding = hasSpaceAfter ? "" : " "; - string displayName = data.amount > 1 - ? $"{data.itemName} [{data.amount}]" - : data.itemName; + string displayName = data.amount > 1 ? $"{data.itemName} [{data.amount}]" : data.itemName; - return $"{leftPadding}< {displayName} >{rightPadding}"; + return $"{leftPadding}< {displayName} >{rightPadding}"; + } } + return match.Value; } - return match.Value; - }); + ); } } diff --git a/Plugins/RSBot.Chat/Bundle/Network/LinkedItemResponseHandler.cs b/Plugins/RSBot.Chat/Bundle/Network/LinkedItemResponseHandler.cs index fd0049c0..7bd25b97 100644 --- a/Plugins/RSBot.Chat/Bundle/Network/LinkedItemResponseHandler.cs +++ b/Plugins/RSBot.Chat/Bundle/Network/LinkedItemResponseHandler.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Collections.Generic; +using RSBot.Core; using RSBot.Core.Client.ReferenceObjects; using RSBot.Core.Network; -using System.Collections.Generic; namespace RSBot.Chat.Bundle.Network { diff --git a/Plugins/RSBot.Chat/ChatCLICommands.cs b/Plugins/RSBot.Chat/ChatCLICommands.cs index 9c955397..a0abc4b4 100644 --- a/Plugins/RSBot.Chat/ChatCLICommands.cs +++ b/Plugins/RSBot.Chat/ChatCLICommands.cs @@ -1,7 +1,7 @@ +using System; using RSBot.Core; using RSBot.Core.Components.Command; using RSBot.Core.Objects; -using System; namespace RSBot.Chat; diff --git a/Plugins/RSBot.Chat/ChatManager.cs b/Plugins/RSBot.Chat/ChatManager.cs index 36a3a0ac..276580e6 100644 --- a/Plugins/RSBot.Chat/ChatManager.cs +++ b/Plugins/RSBot.Chat/ChatManager.cs @@ -7,7 +7,12 @@ namespace RSBot.Chat public class ChatManager { string lastWhisper; - public ChatManager() { SubscribeEvents(); } + + public ChatManager() + { + SubscribeEvents(); + } + public static void Send(ChatType type, string message, string receiver = null) { if (type == ChatType.Global) @@ -18,10 +23,12 @@ public static void Send(ChatType type, string message, string receiver = null) if (type == ChatType.Private) PlayerConfig.Set("RSBot.Chat.LastWhisper", receiver); } + private void SubscribeEvents() { EventManager.SubscribeEvent("OnEnterGame", OnEnterGame); } + private void OnEnterGame() { lastWhisper = PlayerConfig.Get("RSBot.Chat.LastWhisper"); diff --git a/Plugins/RSBot.Chat/ChatPlugin.cs b/Plugins/RSBot.Chat/ChatPlugin.cs index 3b31e29f..ddea05d8 100644 --- a/Plugins/RSBot.Chat/ChatPlugin.cs +++ b/Plugins/RSBot.Chat/ChatPlugin.cs @@ -1,5 +1,5 @@ -using RSBot.Core.Plugins; using RSBot.Core.Components.Command; +using RSBot.Core.Plugins; namespace RSBot.Chat { @@ -8,6 +8,7 @@ public class ChatPlugin : IPlugin public string InternalName => "RSBot.Chat"; public static ChatPlugin Instance { get; private set; } public ChatManager Manager { get; private set; } + public void Initialize() { Instance = this; @@ -15,6 +16,7 @@ public void Initialize() CLIManager.Register(new ChatCLICommand()); } - public void OnLoadCharacter() { } + + public void OnLoadCharacter() { } } } diff --git a/Plugins/RSBot.Chat/ChatView.cs b/Plugins/RSBot.Chat/ChatView.cs index fec07cf0..1d18fd98 100644 --- a/Plugins/RSBot.Chat/ChatView.cs +++ b/Plugins/RSBot.Chat/ChatView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Chat { diff --git a/Plugins/RSBot.Chat/RSBot.Chat.csproj b/Plugins/RSBot.Chat/RSBot.Chat.csproj index 79f1126a..1141110b 100644 --- a/Plugins/RSBot.Chat/RSBot.Chat.csproj +++ b/Plugins/RSBot.Chat/RSBot.Chat.csproj @@ -19,4 +19,3 @@ - diff --git a/Plugins/RSBot.Chat/Views/Main.cs b/Plugins/RSBot.Chat/Views/Main.cs index a6b8d2ac..b54d1879 100644 --- a/Plugins/RSBot.Chat/Views/Main.cs +++ b/Plugins/RSBot.Chat/Views/Main.cs @@ -16,10 +16,12 @@ public Main() InitializeComponent(); SubscribeEvents(); } + private void SubscribeEvents() { EventManager.SubscribeEvent("OnMessageReceived", AppendMessage); } + /// /// Sends the chat message. /// @@ -30,7 +32,6 @@ private void SendChatMessage(Control sender) return; ChatManager.Send(chatType, sender.Text, txtRecievePrivate.Text); - } /// diff --git a/Plugins/RSBot.CommandCenter/RSBot.CommandCenter.csproj b/Plugins/RSBot.CommandCenter/RSBot.CommandCenter.csproj index b492d140..a4aa8eec 100644 --- a/Plugins/RSBot.CommandCenter/RSBot.CommandCenter.csproj +++ b/Plugins/RSBot.CommandCenter/RSBot.CommandCenter.csproj @@ -19,4 +19,3 @@ - diff --git a/Plugins/RSBot.General/GeneralCLICommands.cs b/Plugins/RSBot.General/GeneralCLICommands.cs index bf6f9531..721cfcc4 100644 --- a/Plugins/RSBot.General/GeneralCLICommands.cs +++ b/Plugins/RSBot.General/GeneralCLICommands.cs @@ -1,8 +1,8 @@ +using System; +using System.Threading.Tasks; using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Components.Command; -using System; -using System.Threading.Tasks; namespace RSBot.General; diff --git a/Plugins/RSBot.General/GeneralManager.cs b/Plugins/RSBot.General/GeneralManager.cs index 1ca4e115..f2ab5f7f 100644 --- a/Plugins/RSBot.General/GeneralManager.cs +++ b/Plugins/RSBot.General/GeneralManager.cs @@ -1,22 +1,25 @@ -using RSBot.Core; +using System.IO; +using System.Threading; +using System.Threading.Tasks; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Event; using RSBot.General.Components; -using System.IO; -using System.Threading; -using System.Threading.Tasks; namespace RSBot.General { public class GeneralManager { private static int _reloginSeq; - public static bool IsClientless => Game.Clientless && Kernel.Proxy != null && Kernel.Proxy.IsConnectedToAgentserver; + public static bool IsClientless => + Game.Clientless && Kernel.Proxy != null && Kernel.Proxy.IsConnectedToAgentserver; public static bool IsConnected => Kernel.Proxy != null && Kernel.Proxy.IsConnectedToAgentserver; + public GeneralManager() { SubscribeEvents(); } + private void SubscribeEvents() { ClientlessManager.RegionalAuthHandler = HandleRegionalAuth; @@ -28,6 +31,7 @@ private void SubscribeEvents() EventManager.SubscribeEvent("OnExitClient", OnExitClient); EventManager.SubscribeEvent("OnProfileChanged", OnProfileChanged); } + private static async Task HandleRegionalAuth() { if (Game.ClientType == GameClientType.RuSro) @@ -36,10 +40,12 @@ private static async Task HandleRegionalAuth() return await JSROAuthService.GetTokenAsync(); return true; } + private void OnAgentServerConnected() { Interlocked.Increment(ref _reloginSeq); } + private async void OnAgentServerDisconnected() { Kernel.Bot.Stop(); @@ -78,6 +84,7 @@ private async void OnAgentServerDisconnected() } EventManager.FireEvent("OnClientDisconnected"); } + private async void OnGatewayServerDisconnected() { AutoLogin.Pending = false; @@ -150,6 +157,7 @@ private async void OnGatewayServerDisconnected() Game.Clientless = false; } } + private async void OnEnterGame() { while (!Game.Ready) @@ -164,6 +172,7 @@ private async void OnEnterGame() if (startBot) Kernel.Bot.Start(); } + private void OnExitClient() { Log.StatusLang("Ready"); @@ -180,18 +189,19 @@ private void OnExitClient() if (!Kernel.Proxy.IsConnectedToAgentserver) return; - ClientlessManager.GoClientless(); EventManager.FireEvent("OnSwitchToClientless"); Log.NotifyLang("ClientlessModeActivated"); } - } + } + private void OnProfileChanged() { Accounts.Load(); } + private async Task StartClientProcess() { EventManager.FireEvent("OnClientProcessStarted"); @@ -207,11 +217,13 @@ await Task.Run(async () => } }); } + public static void ChangeSilkroadPath(string path) { GlobalConfig.Set("RSBot.SilkroadDirectory", Path.GetDirectoryName(path)); GlobalConfig.Set("RSBot.SilkroadExecutable", Path.GetFileName(path)); } + public static void GoClientless() { if (Game.Clientless) @@ -222,12 +234,13 @@ public static void GoClientless() EventManager.FireEvent("OnSwitchToClientless"); } + public static async Task StartClientlessAsync() { await Task.Run(async () => { if (!Game.Clientless) - { + { Game.Clientless = true; Log.StatusLang("StartingClientless"); EventManager.FireEvent("OnClientlessProcessStarted"); @@ -241,7 +254,7 @@ await Task.Run(async () => } }); } - + public static async Task DisconnectAsync() { await Task.Run(() => @@ -249,10 +262,11 @@ await Task.Run(() => Game.Clientless = false; EventManager.FireEvent("OnAutoReloginOngoing"); - - Kernel.Proxy.Shutdown(); + + Kernel.Proxy.Shutdown(); }); } + public async Task StartClientAsync() { var userAuthenticated = await HandleRegionalAuth(); @@ -262,10 +276,11 @@ public async Task StartClientAsync() await StartClientProcess(); } } + public static void KillClient() { if (!IsClientless) - { + { ClientManager.Kill(); } } diff --git a/Plugins/RSBot.General/GeneralPlugin.cs b/Plugins/RSBot.General/GeneralPlugin.cs index fa3a709b..af9cdb81 100644 --- a/Plugins/RSBot.General/GeneralPlugin.cs +++ b/Plugins/RSBot.General/GeneralPlugin.cs @@ -1,6 +1,6 @@ +using RSBot.Core.Components.Command; using RSBot.Core.Plugins; using RSBot.General.Components; -using RSBot.Core.Components.Command; namespace RSBot.General { @@ -20,6 +20,7 @@ public void Initialize() CLIManager.Register(new ShowClientCommand()); CLIManager.Register(new HideClientCommand()); } + public void OnLoadCharacter() { } } } diff --git a/Plugins/RSBot.General/GeneralView.cs b/Plugins/RSBot.General/GeneralView.cs index ea63b4a5..13ce5f1b 100644 --- a/Plugins/RSBot.General/GeneralView.cs +++ b/Plugins/RSBot.General/GeneralView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.General { diff --git a/Plugins/RSBot.General/RSBot.General.csproj b/Plugins/RSBot.General/RSBot.General.csproj index f34f4b52..9031482d 100644 --- a/Plugins/RSBot.General/RSBot.General.csproj +++ b/Plugins/RSBot.General/RSBot.General.csproj @@ -27,4 +27,3 @@ - diff --git a/Plugins/RSBot.General/Views/Main.cs b/Plugins/RSBot.General/Views/Main.cs index 32a03643..8bfdf181 100644 --- a/Plugins/RSBot.General/Views/Main.cs +++ b/Plugins/RSBot.General/Views/Main.cs @@ -1,11 +1,4 @@ -using RSBot.Core; -using RSBot.Core.Client; -using RSBot.Core.Components; -using RSBot.Core.Event; -using RSBot.General.Components; -using RSBot.General.Models; -using SDUI.Controls; -using System; +using System; using System.ComponentModel; using System.Drawing; using System.Globalization; @@ -13,6 +6,13 @@ using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; +using RSBot.Core; +using RSBot.Core.Client; +using RSBot.Core.Components; +using RSBot.Core.Event; +using RSBot.General.Components; +using RSBot.General.Models; +using SDUI.Controls; namespace RSBot.General.Views; @@ -114,17 +114,21 @@ private void OnInitialized() await Task.Delay(5000); if (Kernel.LaunchMode == "client") { - BeginInvoke(new Action(() => - { - btnStartClient_Click(btnStartClient, EventArgs.Empty); - })); + BeginInvoke( + new Action(() => + { + btnStartClient_Click(btnStartClient, EventArgs.Empty); + }) + ); } else if (Kernel.LaunchMode == "clientless") { - BeginInvoke(new Action(() => - { - btnStartClientless_Click(btnStartClientless, EventArgs.Empty); - })); + BeginInvoke( + new Action(() => + { + btnStartClientless_Click(btnStartClientless, EventArgs.Empty); + }) + ); } }); } @@ -270,6 +274,7 @@ private void OnAutoLoginAborted() View.PendingWindow?.Hide(); View.PendingWindow?.StopClientlessQueueTask(); } + private void OnAutoReloginStarted() { if (this.InvokeRequired) @@ -280,6 +285,7 @@ private void OnAutoReloginStarted() btnStartClient.Enabled = false; btnStartClientless.Enabled = false; } + private void OnClientDisconnected() { if (this.InvokeRequired) @@ -295,6 +301,7 @@ private void OnClientDisconnected() btnStartClient.Text = LanguageManager.GetLang("Start") + " Client"; btnStartClientless.Text = LanguageManager.GetLang("Start") + " Clientless"; } + private void OnAutoReloginOngoing() { if (this.InvokeRequired) @@ -307,6 +314,7 @@ private void OnAutoReloginOngoing() btnStartClientless.Enabled = true; btnStartClientless.Text = LanguageManager.GetLang("Start") + " Clientless"; } + private void OnClientProcessStarted() { if (this.InvokeRequired) @@ -317,6 +325,7 @@ private void OnClientProcessStarted() btnStartClient.Enabled = false; } + private void OnClientlessProcessStarted() { if (this.InvokeRequired) @@ -327,6 +336,7 @@ private void OnClientlessProcessStarted() btnStartClientless.Text = LanguageManager.GetLang("Disconnect"); } + private void OnEnterGame() { if (this.InvokeRequired) @@ -379,7 +389,7 @@ private void btnBrowseSilkroadPath_Click(object sender, EventArgs e) { Application.Restart(); } - } + } } /// diff --git a/Plugins/RSBot.Inventory/InventoryManager.cs b/Plugins/RSBot.Inventory/InventoryManager.cs index 8c0dafa3..70714d32 100644 --- a/Plugins/RSBot.Inventory/InventoryManager.cs +++ b/Plugins/RSBot.Inventory/InventoryManager.cs @@ -1,6 +1,6 @@ -using RSBot.Core; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; +using RSBot.Core; namespace RSBot.Inventory { @@ -14,6 +14,7 @@ public static void UseItemBySlot(byte slot) var item = Game.Player.Inventory.GetItemAt(slot); item?.Use(); } + /// /// Drops an item from a specific slot /// @@ -22,6 +23,7 @@ public static void DropItemBySlot(byte slot) var item = Game.Player.Inventory.GetItemAt(slot); item?.Drop(); } + /// /// Toggeles the state of an item for the use at the Trainingplace /// @@ -44,6 +46,7 @@ public static bool ToggleItemAtTrainplaceByCodeName(string codeName) PlayerConfig.SetArray("RSBot.Inventory.ItemsAtTrainplace", items); return isEnabled; } + /// /// Toggeles the state of an item for the automatic use /// @@ -67,7 +70,10 @@ public static bool ToggleAutoUseByCodeName(string codeName) return isNowEnabled; } - public static List GetItemsAtTrainplace() => PlayerConfig.GetArray("RSBot.Inventory.ItemsAtTrainplace").ToList(); - public static List GetItemsByPurpose() => PlayerConfig.GetArray("RSBot.Inventory.AutoUseAccordingToPurpose").ToList(); + public static List GetItemsAtTrainplace() => + PlayerConfig.GetArray("RSBot.Inventory.ItemsAtTrainplace").ToList(); + + public static List GetItemsByPurpose() => + PlayerConfig.GetArray("RSBot.Inventory.AutoUseAccordingToPurpose").ToList(); } } diff --git a/Plugins/RSBot.Inventory/InventoryPlugin.cs b/Plugins/RSBot.Inventory/InventoryPlugin.cs index 05a6c84c..a27a2bcd 100644 --- a/Plugins/RSBot.Inventory/InventoryPlugin.cs +++ b/Plugins/RSBot.Inventory/InventoryPlugin.cs @@ -8,6 +8,7 @@ public class InventoryPlugin : IPlugin public string InternalName => "RSBot.Inventory"; public static InventoryPlugin Instance { get; private set; } public InventoryManager Manager { get; private set; } + public void Initialize() { Instance = this; @@ -16,6 +17,7 @@ public void Initialize() InventoryUpdateSubscriber.SubscribeEvents(); UseItemAtTrainplaceSubscriber.SubscribeEvents(); } + public void OnLoadCharacter() { } } } diff --git a/Plugins/RSBot.Inventory/InventoryView.cs b/Plugins/RSBot.Inventory/InventoryView.cs index f204c2f8..ebb628c7 100644 --- a/Plugins/RSBot.Inventory/InventoryView.cs +++ b/Plugins/RSBot.Inventory/InventoryView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Inventory { diff --git a/Plugins/RSBot.Inventory/RSBot.Inventory.csproj b/Plugins/RSBot.Inventory/RSBot.Inventory.csproj index 79f1126a..1141110b 100644 --- a/Plugins/RSBot.Inventory/RSBot.Inventory.csproj +++ b/Plugins/RSBot.Inventory/RSBot.Inventory.csproj @@ -19,4 +19,3 @@ - diff --git a/Plugins/RSBot.Inventory/Views/Main.cs b/Plugins/RSBot.Inventory/Views/Main.cs index 124c076d..17d4bfd7 100644 --- a/Plugins/RSBot.Inventory/Views/Main.cs +++ b/Plugins/RSBot.Inventory/Views/Main.cs @@ -29,7 +29,7 @@ public partial class Main : DoubleBufferedControl /// /// /// - private int _selectedIndex; + private int _selectedIndex; /// /// Initializes a new instance of the class. @@ -600,7 +600,7 @@ private void useItemAtTrainingPlaceMenuItem_Click(object sender, EventArgs e) var useSelectedItem = itemsToUse.Contains(selectedItem.Record.CodeName); if (useSelectedItem) - { + { lvItem.Font = Font; itemsToUse.Remove(selectedItem.Record.CodeName); } diff --git a/Plugins/RSBot.Items/ItemsManager.cs b/Plugins/RSBot.Items/ItemsManager.cs index 50243d1c..6f31e47b 100644 --- a/Plugins/RSBot.Items/ItemsManager.cs +++ b/Plugins/RSBot.Items/ItemsManager.cs @@ -1,6 +1,4 @@ namespace RSBot.Items { - public class ItemsManager - { - } + public class ItemsManager { } } diff --git a/Plugins/RSBot.Items/ItemsPlugin.cs b/Plugins/RSBot.Items/ItemsPlugin.cs index f701eb76..461576da 100644 --- a/Plugins/RSBot.Items/ItemsPlugin.cs +++ b/Plugins/RSBot.Items/ItemsPlugin.cs @@ -10,7 +10,7 @@ public class ItemsPlugin : IPlugin public ItemsManager Manager { get; private set; } /// - public void Initialize() + public void Initialize() { Instance = this; Manager = new ItemsManager(); @@ -18,6 +18,5 @@ public void Initialize() /// public void OnLoadCharacter() { } - } } diff --git a/Plugins/RSBot.Items/ItemsView.cs b/Plugins/RSBot.Items/ItemsView.cs index 7cf07554..dccc5cda 100644 --- a/Plugins/RSBot.Items/ItemsView.cs +++ b/Plugins/RSBot.Items/ItemsView.cs @@ -1,8 +1,7 @@ - +using System.Windows.Forms; using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Items { diff --git a/Plugins/RSBot.Items/RSBot.Items.csproj b/Plugins/RSBot.Items/RSBot.Items.csproj index 79f1126a..1141110b 100644 --- a/Plugins/RSBot.Items/RSBot.Items.csproj +++ b/Plugins/RSBot.Items/RSBot.Items.csproj @@ -19,4 +19,3 @@ - diff --git a/Plugins/RSBot.Log/LogManager.cs b/Plugins/RSBot.Log/LogManager.cs index 8a6960fd..193780e7 100644 --- a/Plugins/RSBot.Log/LogManager.cs +++ b/Plugins/RSBot.Log/LogManager.cs @@ -1,6 +1,4 @@ namespace RSBot.Log { - public class LogManager - { - } + public class LogManager { } } diff --git a/Plugins/RSBot.Log/LogPlugin.cs b/Plugins/RSBot.Log/LogPlugin.cs index 718968d0..56bcace0 100644 --- a/Plugins/RSBot.Log/LogPlugin.cs +++ b/Plugins/RSBot.Log/LogPlugin.cs @@ -8,11 +8,12 @@ public class LogPlugin : IPlugin public static LogPlugin Instance { get; private set; } public LogManager Manager { get; private set; } - public void Initialize() + public void Initialize() { Instance = this; Manager = new LogManager(); } + public void OnLoadCharacter() { } } } diff --git a/Plugins/RSBot.Log/LogView.cs b/Plugins/RSBot.Log/LogView.cs index eb79542d..e45833aa 100644 --- a/Plugins/RSBot.Log/LogView.cs +++ b/Plugins/RSBot.Log/LogView.cs @@ -1,19 +1,19 @@ - +using System.Windows.Forms; using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Log { public class LogView : IPluginView { - public string InternalName => "RSBot.Log"; - public string DisplayName => "Log"; - public bool DisplayAsTab => true; - public int Index => 99; - public bool RequireIngame => false; - public Control View => Views.View.Instance; + public string InternalName => "RSBot.Log"; + public string DisplayName => "Log"; + public bool DisplayAsTab => true; + public int Index => 99; + public bool RequireIngame => false; + public Control View => Views.View.Instance; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Plugins/RSBot.Log/RSBot.Log.csproj b/Plugins/RSBot.Log/RSBot.Log.csproj index 79f1126a..1141110b 100644 --- a/Plugins/RSBot.Log/RSBot.Log.csproj +++ b/Plugins/RSBot.Log/RSBot.Log.csproj @@ -19,4 +19,3 @@ - diff --git a/Plugins/RSBot.Map/MapManager.cs b/Plugins/RSBot.Map/MapManager.cs index 971027e0..a747e63f 100644 --- a/Plugins/RSBot.Map/MapManager.cs +++ b/Plugins/RSBot.Map/MapManager.cs @@ -1,6 +1,4 @@ namespace RSBot.Map { - public class MapManager - { - } + public class MapManager { } } diff --git a/Plugins/RSBot.Map/MapPlugin.cs b/Plugins/RSBot.Map/MapPlugin.cs index 3708fcea..522d2132 100644 --- a/Plugins/RSBot.Map/MapPlugin.cs +++ b/Plugins/RSBot.Map/MapPlugin.cs @@ -7,11 +7,13 @@ public class MapPlugin : IPlugin public string InternalName => "RSBot.Map"; public static MapPlugin Instance { get; private set; } public MapManager Manager { get; private set; } - public void Initialize() + + public void Initialize() { Instance = this; Manager = new MapManager(); } + public void OnLoadCharacter() { Views.View.Instance?.InitUniqueObjects(); diff --git a/Plugins/RSBot.Map/MapView.cs b/Plugins/RSBot.Map/MapView.cs index 556d844c..f0a25388 100644 --- a/Plugins/RSBot.Map/MapView.cs +++ b/Plugins/RSBot.Map/MapView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Map { @@ -13,6 +13,7 @@ public class MapView : IPluginView public int Index => 6; public bool RequireIngame => true; public Control View => Views.View.Instance; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Plugins/RSBot.Map/RSBot.Map.csproj b/Plugins/RSBot.Map/RSBot.Map.csproj index e98d9167..3f2d07b6 100644 --- a/Plugins/RSBot.Map/RSBot.Map.csproj +++ b/Plugins/RSBot.Map/RSBot.Map.csproj @@ -23,4 +23,3 @@ - diff --git a/Plugins/RSBot.Map/Views/Main.cs b/Plugins/RSBot.Map/Views/Main.cs index 93149850..c4e02ee3 100644 --- a/Plugins/RSBot.Map/Views/Main.cs +++ b/Plugins/RSBot.Map/Views/Main.cs @@ -324,7 +324,12 @@ private void PopulateMapAndGrid(Graphics graphics) // Avoid painting vehicles from main player if (Game.Player.Vehicle?.UniqueId != entry.UniqueId) { - AddGridItem(entry.Name, entry.Record?.GetRealName(), entry.Record.Level, entry.Movement.Source); + AddGridItem( + entry.Name, + entry.Record?.GetRealName(), + entry.Record.Level, + entry.Movement.Source + ); DrawPointAt(graphics, entry.Movement.Source, 1); } diff --git a/Plugins/RSBot.Party/Bundle/AutoParty/AutoPartyBundle.cs b/Plugins/RSBot.Party/Bundle/AutoParty/AutoPartyBundle.cs index c34c4c61..08758bcb 100644 --- a/Plugins/RSBot.Party/Bundle/AutoParty/AutoPartyBundle.cs +++ b/Plugins/RSBot.Party/Bundle/AutoParty/AutoPartyBundle.cs @@ -72,7 +72,10 @@ public void Refresh() AcceptIfBotIsStopped = PlayerConfig.Get("RSBot.Party.AcceptIfBotStopped"), LeaveIfMasterNot = PlayerConfig.Get("RSBot.Party.LeaveIfMasterNot"), LeaveIfMasterNotName = PlayerConfig.Get("RSBot.Party.LeaveIfMasterNotName"), - CenterPosition = (Kernel.Bot?.Botbase != null) ? Kernel.Bot.Botbase.Area.Position : (Game.Player?.Position ?? new RSBot.Core.Objects.Position(0, 0, 0)), + CenterPosition = + (Kernel.Bot?.Botbase != null) + ? Kernel.Bot.Botbase.Area.Position + : (Game.Player?.Position ?? new RSBot.Core.Objects.Position(0, 0, 0)), AutoJoinByName = PlayerConfig.Get("RSBot.Party.AutoJoin.ByName", false), AutoJoinByTitle = PlayerConfig.Get("RSBot.Party.AutoJoin.ByTitle", false), AutoJoinByNameContent = PlayerConfig.Get("RSBot.Party.AutoJoin.Name", string.Empty), diff --git a/Plugins/RSBot.Party/PartyView.cs b/Plugins/RSBot.Party/PartyView.cs index 4bd9b000..839ffd81 100644 --- a/Plugins/RSBot.Party/PartyView.cs +++ b/Plugins/RSBot.Party/PartyView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Party { @@ -13,6 +13,7 @@ public class PartyView : IPluginView public int Index => 3; public bool RequireIngame => true; public Control View => Views.View.Instance; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Plugins/RSBot.Party/RSBot.Party.csproj b/Plugins/RSBot.Party/RSBot.Party.csproj index fee6477e..8bd5f41e 100644 --- a/Plugins/RSBot.Party/RSBot.Party.csproj +++ b/Plugins/RSBot.Party/RSBot.Party.csproj @@ -34,4 +34,3 @@ - diff --git a/Plugins/RSBot.Protection/ProtectionManager.cs b/Plugins/RSBot.Protection/ProtectionManager.cs index 4f319c8e..1d55e399 100644 --- a/Plugins/RSBot.Protection/ProtectionManager.cs +++ b/Plugins/RSBot.Protection/ProtectionManager.cs @@ -2,10 +2,11 @@ { public class ProtectionManager { - public ProtectionManager() + public ProtectionManager() { SubscribeEvents(); } + /// /// Subscribes the events. /// diff --git a/Plugins/RSBot.Protection/ProtectionPlugin.cs b/Plugins/RSBot.Protection/ProtectionPlugin.cs index 3136893e..5153d973 100644 --- a/Plugins/RSBot.Protection/ProtectionPlugin.cs +++ b/Plugins/RSBot.Protection/ProtectionPlugin.cs @@ -10,6 +10,7 @@ public class ProtectionPlugin : IPlugin public string InternalName => "RSBot.Protection"; public static ProtectionPlugin Instance { get; private set; } public ProtectionManager Manager { get; private set; } + public void Initialize() { Instance = this; @@ -39,6 +40,7 @@ public void Initialize() DurabilityLowHandler.Initialize(); FatigueHandler.Initialize(); } + public void OnLoadCharacter() { } } } diff --git a/Plugins/RSBot.Protection/ProtectionView.cs b/Plugins/RSBot.Protection/ProtectionView.cs index e5d993c6..899a9e79 100644 --- a/Plugins/RSBot.Protection/ProtectionView.cs +++ b/Plugins/RSBot.Protection/ProtectionView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Protection { @@ -13,6 +13,7 @@ public class ProtectionView : IPluginView public int Index => 2; public bool RequireIngame => true; public Control View => Views.View.Instance; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Plugins/RSBot.Protection/RSBot.Protection.csproj b/Plugins/RSBot.Protection/RSBot.Protection.csproj index 79f1126a..1141110b 100644 --- a/Plugins/RSBot.Protection/RSBot.Protection.csproj +++ b/Plugins/RSBot.Protection/RSBot.Protection.csproj @@ -19,4 +19,3 @@ - diff --git a/Plugins/RSBot.Python/Components/API/Core/API.Core.cs b/Plugins/RSBot.Python/Components/API/Core/API.Core.cs index e3460e37..1841b751 100644 --- a/Plugins/RSBot.Python/Components/API/Core/API.Core.cs +++ b/Plugins/RSBot.Python/Components/API/Core/API.Core.cs @@ -1,10 +1,10 @@ -using RSBot.Python.Components.API.Interface; -using RSBot.Python.Views; -using System; +using System; using System.Linq; using Python.Runtime; using RSBot.Core; using RSBot.Core.Network; +using RSBot.Python.Components.API.Interface; +using RSBot.Python.Views; namespace RSBot.Python.Components.API.Core { @@ -55,14 +55,14 @@ private bool StartBot() return true; } return false; - } catch (Exception ex) { - Log.Error($"[Python-API] Error while trying to start the bot from Plugin: {ex}" ); + Log.Error($"[Python-API] Error while trying to start the bot from Plugin: {ex}"); return false; } } + private bool StopBot() { try @@ -97,18 +97,21 @@ private bool StopBot() return false; } } + private void SendServer(ushort opcode, byte[] data, bool encrypted = false) { - Packet packet = new Packet(opcode,encrypted); + Packet packet = new Packet(opcode, encrypted); packet.WriteBytes(data); PacketManager.SendPacket(packet, PacketDestination.Server); } + private void SendClient(ushort opcode, byte[] data, bool encrypted = false) { Packet packet = new Packet(opcode, encrypted); packet.WriteBytes(data); PacketManager.SendPacket(packet, PacketDestination.Client); } + public void log(params object[] args) { if (args == null || args.Length == 0) @@ -117,34 +120,42 @@ public void log(params object[] args) return; } - string msg = string.Join(" ", args.Select(a => - { - if (a == null) return "None"; - - if (a is PyObject pyObj) + string msg = string.Join( + " ", + args.Select(a => { - using (Py.GIL()) + if (a == null) + return "None"; + + if (a is PyObject pyObj) { - return pyObj.ToString(); + using (Py.GIL()) + { + return pyObj.ToString(); + } } - } - return a.ToString(); - })); + return a.ToString(); + }) + ); _main?.AppendLog(msg); } + public bool start_bot() { return StartBot(); } + public bool stop_bot() { return StopBot(); } + public void send_server(ushort opcode, byte[] data, bool encrypted) { SendServer(opcode, data, encrypted); } + public void send_client(ushort opcode, byte[] data, bool encrypted) { SendClient(opcode, data, encrypted); diff --git a/Plugins/RSBot.Python/Components/API/Core/Config/API.Config.cs b/Plugins/RSBot.Python/Components/API/Core/Config/API.Config.cs index 4fd46f0f..ced77b78 100644 --- a/Plugins/RSBot.Python/Components/API/Core/Config/API.Config.cs +++ b/Plugins/RSBot.Python/Components/API/Core/Config/API.Config.cs @@ -1,9 +1,9 @@ -using Python.Runtime; +using System.IO; +using System.Windows.Forms; +using Python.Runtime; using RSBot.Core; using RSBot.Python.Components.API.Interface; using RSBot.Python.Views; -using System.IO; -using System.Windows.Forms; namespace RSBot.Python.Components.API.Core.Entity { @@ -30,6 +30,7 @@ private string GetConfigDir() { return Path.Combine(projectDir, "User"); } + private string GetConfigPath() { if (Game.Player == null) @@ -38,10 +39,12 @@ private string GetConfigPath() } return Path.Combine(projectDir, "User", "Default", $"{Game.Player.Name}.rs"); } + private string GetLogDir() { return Path.Combine(projectDir, "User", "Logs"); } + private string GetLogPath() { if (Game.Player == null) @@ -50,23 +53,25 @@ private string GetLogPath() } return Path.Combine(projectDir, "User", "Logs", Game.Player.Name); } + public string get_config_dir() { return GetConfigDir(); } + public string get_config_path() { return GetConfigPath(); } + public string get_log_dir() { return GetLogDir(); } + public string get_log_path() { return GetLogPath(); } - - } } diff --git a/Plugins/RSBot.Python/Components/API/Core/Entity/API.Entity.cs b/Plugins/RSBot.Python/Components/API/Core/Entity/API.Entity.cs index 7cf229c0..9b6d1926 100644 --- a/Plugins/RSBot.Python/Components/API/Core/Entity/API.Entity.cs +++ b/Plugins/RSBot.Python/Components/API/Core/Entity/API.Entity.cs @@ -1,17 +1,17 @@ -using Python.Runtime; +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using Python.Runtime; using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Extensions; using RSBot.Core.Objects; +using RSBot.Core.Objects.Party; using RSBot.Core.Objects.Skill; using RSBot.Core.Objects.Spawn; -using RSBot.Core.Objects.Party; using RSBot.General.Components; using RSBot.Python.Components.API.Interface; using RSBot.Python.Views; -using System; -using System.Collections.Generic; -using System.Windows.Forms; namespace RSBot.Python.Components.API.Core.Entity { @@ -32,6 +32,7 @@ public void Init(Main main) { _main = main; } + private PyList BuildMonsterList(IEnumerable monster) { var list = new PyList(); @@ -51,7 +52,10 @@ private PyList BuildMonsterList(IEnumerable monster) pyItem.SetItem(new PyString("y"), new PyString(entry.Position.Y.ToString())); pyItem.SetItem(new PyString("z"), new PyString(entry.Position.ZOffset.ToString())); pyItem.SetItem(new PyString("region"), new PyString(entry.Position.Region.ToString())); - pyItem.SetItem(new PyString("region_name"), new PyString(Game.ReferenceManager.GetTranslation(entry.Position.Region.ToString()))); + pyItem.SetItem( + new PyString("region_name"), + new PyString(Game.ReferenceManager.GetTranslation(entry.Position.Region.ToString())) + ); pyItem.SetItem(new PyString("distance"), new PyString(entry.DistanceToPlayer.ToString())); pyItem.SetItem(new PyString("hp"), new PyString(entry.Health.ToString())); pyItem.SetItem(new PyString("max_hp"), new PyString(entry.MaxHealth.ToString())); @@ -60,6 +64,7 @@ private PyList BuildMonsterList(IEnumerable monster) return list; } + private PyList BuildPartyList() { var list = new PyList(); @@ -86,12 +91,16 @@ private PyList BuildPartyList() pyItem.SetItem(new PyString("y"), new PyString(entry.Player?.Position.Y.ToString() ?? "")); pyItem.SetItem(new PyString("z"), new PyString(entry.Player?.Position.ZOffset.ToString() ?? "")); pyItem.SetItem(new PyString("region"), new PyString(entry.Player?.Position.Region.ToString() ?? "")); - pyItem.SetItem(new PyString("region_name"), new PyString(Game.ReferenceManager.GetTranslation(entry.Player?.Position.Region.ToString() ?? ""))); + pyItem.SetItem( + new PyString("region_name"), + new PyString(Game.ReferenceManager.GetTranslation(entry.Player?.Position.Region.ToString() ?? "")) + ); pyItem.SetItem(new PyString("distance"), new PyString(entry.Player?.DistanceToPlayer.ToString() ?? "")); list.Append(pyItem); } return list; } + private PyList BuildPlayersList(IEnumerable player) { var list = new PyList(); @@ -107,12 +116,16 @@ private PyList BuildPlayersList(IEnumerable player) pyItem.SetItem(new PyString("y"), new PyString(entry.Position.Y.ToString())); pyItem.SetItem(new PyString("z"), new PyString(entry.Position.ZOffset.ToString())); pyItem.SetItem(new PyString("region"), new PyString(entry.Position.Region.ToString())); - pyItem.SetItem(new PyString("region_name"), new PyString(Game.ReferenceManager.GetTranslation(entry.Position.Region.ToString()))); + pyItem.SetItem( + new PyString("region_name"), + new PyString(Game.ReferenceManager.GetTranslation(entry.Position.Region.ToString())) + ); pyItem.SetItem(new PyString("distance"), new PyString(entry.DistanceToPlayer.ToString())); list.Append(pyItem); } return list; } + private PyList BuildNPCList(IEnumerable npc) { var list = new PyList(); @@ -131,13 +144,17 @@ private PyList BuildNPCList(IEnumerable npc) pyItem.SetItem(new PyString("y"), new PyString(entry.Position.Y.ToString())); pyItem.SetItem(new PyString("z"), new PyString(entry.Position.ZOffset.ToString())); pyItem.SetItem(new PyString("region"), new PyString(entry.Position.Region.ToString())); - pyItem.SetItem(new PyString("region_name"), new PyString(Game.ReferenceManager.GetTranslation(entry.Position.Region.ToString()))); + pyItem.SetItem( + new PyString("region_name"), + new PyString(Game.ReferenceManager.GetTranslation(entry.Position.Region.ToString())) + ); pyItem.SetItem(new PyString("distance"), new PyString(entry.DistanceToPlayer.ToString())); list.Append(pyItem); } return list; } + private PyList GetMonsters() { using (Py.GIL()) @@ -149,12 +166,12 @@ private PyList GetMonsters() } if (SpawnManager.TryGetEntities(out var monsters)) { - result = BuildMonsterList(monsters); } return result; } } + private PyList GetPartyMembers() { using (Py.GIL()) @@ -171,6 +188,7 @@ private PyList GetPartyMembers() return result; } } + private PyList GetSpawnedPlayers() { using (Py.GIL()) @@ -187,6 +205,7 @@ private PyList GetSpawnedPlayers() return result; } } + private PyList GetNPCs() { using (Py.GIL()) @@ -203,6 +222,7 @@ private PyList GetNPCs() return result; } } + private PyDict GetCharacter() { using (Py.GIL()) @@ -221,19 +241,26 @@ private PyDict GetCharacter() result.SetItem(new PyString("y"), new PyFloat(Game.Player.Position.Y)); result.SetItem(new PyString("z"), new PyString(Game.Player.Position.ZOffset.ToString())); result.SetItem(new PyString("region"), new PyString(Game.Player.Position.Region.ToString())); - result.SetItem(new PyString("region_name"), new PyString(Game.ReferenceManager.GetTranslation(Game.Player.Position.Region.ToString()))); + result.SetItem( + new PyString("region_name"), + new PyString(Game.ReferenceManager.GetTranslation(Game.Player.Position.Region.ToString())) + ); result.SetItem(new PyString("hp"), new PyInt(Game.Player.Health)); result.SetItem(new PyString("mp"), new PyInt(Game.Player.Mana)); result.SetItem(new PyString("max_hp"), new PyInt(Game.Player.MaximumHealth)); result.SetItem(new PyString("max_mp"), new PyInt(Game.Player.MaximumMana)); result.SetItem(new PyString("exp"), new PyInt(Game.Player.Experience)); - result.SetItem(new PyString("max_exp"), new PyInt(Game.ReferenceManager.GetRefLevel(Game.Player.Level).Exp_C)); + result.SetItem( + new PyString("max_exp"), + new PyInt(Game.ReferenceManager.GetRefLevel(Game.Player.Level).Exp_C) + ); result.SetItem(new PyString("sp"), new PyInt(Game.Player.SkillPoints)); result.SetItem(new PyString("level"), new PyInt(Game.Player.Level)); result.SetItem(new PyString("berserker"), new PyInt(Game.Player.BerzerkPoints)); return result; } } + private PyDict GetPositionTuple() { using (Py.GIL()) @@ -254,6 +281,7 @@ private PyDict GetPositionTuple() return result; } } + private PyList GetActiveSkills() { using (Py.GIL()) @@ -277,6 +305,7 @@ private PyList GetActiveSkills() return result; } } + private PyList GetSkills() { using (Py.GIL()) @@ -295,21 +324,38 @@ private PyList GetSkills() pySkill.SetItem(new PyString("can_cast"), new PyString(skill.CanBeCasted.ToString())); pySkill.SetItem(new PyString("on_cooldown"), new PyString(skill.HasCooldown.ToString())); pySkill.SetItem(new PyString("reuse_time"), new PyInt(skill.Record.Action_ReuseDelay)); - pySkill.SetItem(new PyString("duration"), new PyString(skill.Record.Action_ActionDuration.ToString())); - pySkill.SetItem(new PyString("mastery"), new PyString(Game.ReferenceManager.GetRefSkillMastery(Convert.ToUInt32(skill.Record.ReqCommon_Mastery1)).Name)); + pySkill.SetItem( + new PyString("duration"), + new PyString(skill.Record.Action_ActionDuration.ToString()) + ); + pySkill.SetItem( + new PyString("mastery"), + new PyString( + Game.ReferenceManager.GetRefSkillMastery( + Convert.ToUInt32(skill.Record.ReqCommon_Mastery1) + ).Name + ) + ); pySkill.SetItem(new PyString("mastery_id"), new PyInt(skill.Record.ReqCommon_Mastery1)); pySkill.SetItem(new PyString("group"), new PyString(skill.Record.Basic_Group)); pySkill.SetItem(new PyString("level"), new PyString(skill.Record.Basic_Level.ToString())); - pySkill.SetItem(new PyString("type"), new PyString( skill.IsAttack ? "Attack" : - skill.IsDot ? "Dot" : - skill.IsImbue ? "Imbue" : - skill.IsPassive ? "Passive" :"")); - + pySkill.SetItem( + new PyString("type"), + new PyString( + skill.IsAttack ? "Attack" + : skill.IsDot ? "Dot" + : skill.IsImbue ? "Imbue" + : skill.IsPassive ? "Passive" + : "" + ) + ); + result.Append(pySkill); } return result; } } + private PyList GetMastery() { using (Py.GIL()) @@ -322,7 +368,10 @@ private PyList GetMastery() foreach (MasteryInfo mastery in Game.Player.Skills.Masteries) { var pySkill = new PyDict(); - pySkill.SetItem(new PyString("name"), new PyString(Game.ReferenceManager.GetRefSkillMastery(Convert.ToUInt32(mastery.Id)).Name)); + pySkill.SetItem( + new PyString("name"), + new PyString(Game.ReferenceManager.GetRefSkillMastery(Convert.ToUInt32(mastery.Id)).Name) + ); pySkill.SetItem(new PyString("id"), new PyInt(mastery.Id)); pySkill.SetItem(new PyString("level"), new PyInt(mastery.Level)); @@ -331,38 +380,47 @@ private PyList GetMastery() return result; } } + public PyList get_monsters() { return GetMonsters(); } + public PyList get_party() { return GetPartyMembers(); } + public PyList get_players() { return GetSpawnedPlayers(); } + public PyList get_npcs() { return GetNPCs(); } + public PyDict get_character() { return GetCharacter(); } + public PyDict get_position() { return GetPositionTuple(); } + public PyList get_active_skills() { return GetActiveSkills(); } + public PyList get_skills() { return GetSkills(); } + public PyList get_mastery() { return GetMastery(); diff --git a/Plugins/RSBot.Python/Components/API/Core/Inventory/API.Inventory.cs b/Plugins/RSBot.Python/Components/API/Core/Inventory/API.Inventory.cs index 5bc91ba4..03e5dea8 100644 --- a/Plugins/RSBot.Python/Components/API/Core/Inventory/API.Inventory.cs +++ b/Plugins/RSBot.Python/Components/API/Core/Inventory/API.Inventory.cs @@ -1,11 +1,11 @@ -using Python.Runtime; +using System.Collections.Generic; +using Python.Runtime; using RSBot.Core; using RSBot.Core.Client.ReferenceObjects; using RSBot.Core.Extensions; using RSBot.Core.Objects; using RSBot.Python.Components.API.Interface; using RSBot.Python.Views; -using System.Collections.Generic; using static System.Windows.Forms.Design.AxImporter; namespace RSBot.Python.Components.API.Core.Inventory @@ -27,7 +27,7 @@ public void Init(Main main) { _main = main; } - + private PyList BuildItemList(IEnumerable items) { var list = new PyList(); @@ -55,13 +55,12 @@ private PyList BuildItemList(IEnumerable items) var option = Game.ReferenceManager.GetMagicOption(magicOption.Id); if (option != null) - pyOptions.Append(new PyString(GetFusingTranslation(option,magicOption.Value))); + pyOptions.Append(new PyString(GetFusingTranslation(option, magicOption.Value))); } pyItem.SetItem(new PyString("magic_options"), new PyList(pyOptions)); - } if (item.Attributes != 0) - { + { var availableAttributes = ItemAttributesInfo.GetAvailableAttributeGroupsForItem(item.Record); if (availableAttributes != null) @@ -76,7 +75,6 @@ private PyList BuildItemList(IEnumerable items) } pyItem.SetItem(new PyString("attributes"), new PyList(pyAttributes)); } - } list.Append(pyItem); @@ -84,6 +82,7 @@ private PyList BuildItemList(IEnumerable items) return list; } + private PyDict GetInventory() { using (Py.GIL()) @@ -102,7 +101,7 @@ private PyDict GetInventory() var inventorySize = Game.Player.Inventory.Capacity; var gold = Game.Player.Gold; result.SetItem(new PyString("size"), new PyInt(inventorySize)); - result.SetItem(new PyString("gold"), new PyString(gold.ToString())); + result.SetItem(new PyString("gold"), new PyString(gold.ToString())); var itemsEquipped = Game.Player.Inventory.GetEquippedPartItems(); var itemsInventory = Game.Player.Inventory.GetNormalPartItems(); @@ -119,6 +118,7 @@ private PyDict GetInventory() return result; } } + private PyList GetStorage() { using (Py.GIL()) @@ -133,9 +133,9 @@ private PyList GetStorage() result = BuildItemList(storage); return result; - } } + private PyList GetGuildStorage() { using (Py.GIL()) @@ -150,9 +150,9 @@ private PyList GetGuildStorage() result = BuildItemList(storage); return result; - } } + private PyList GetPetStorage() { using (Py.GIL()) @@ -167,9 +167,9 @@ private PyList GetPetStorage() result = BuildItemList(storage); return result; - } } + private PyDict GetJobPouch() { using (Py.GIL()) @@ -200,29 +200,34 @@ private PyDict GetJobPouch() } result.SetItem(new PyString("items"), list); return result; - } } + public PyDict get_inventory() { return GetInventory(); } + public PyList get_storage() { return GetStorage(); } + public PyList get_guild_storage() { return GetGuildStorage(); } + public PyDict get_job_pouch() { return GetJobPouch(); } + public PyList get_pet_storage() { return GetPetStorage(); } + public string GetFusingTranslation(RefMagicOpt magicOption, uint value) { //TODO: Use and extend GetGroupTranslation instead of hard coding this @@ -329,5 +334,4 @@ public string GetFusingTranslation(RefMagicOpt magicOption, uint value) return magicOption?.Group ?? $"Error. Mag. opt. value: {value}"; } } - } diff --git a/Plugins/RSBot.Python/Components/API/Core/Quests/API.Quests.cs b/Plugins/RSBot.Python/Components/API/Core/Quests/API.Quests.cs index 2e8ceeb7..b7b610dd 100644 --- a/Plugins/RSBot.Python/Components/API/Core/Quests/API.Quests.cs +++ b/Plugins/RSBot.Python/Components/API/Core/Quests/API.Quests.cs @@ -1,4 +1,10 @@ -using Python.Runtime; +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; +using System.Xml.Linq; +using Python.Runtime; using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Extensions; @@ -8,12 +14,6 @@ using RSBot.Core.Objects.Spawn; using RSBot.Python.Components.API.Interface; using RSBot.Python.Views; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Windows.Forms; -using System.Xml.Linq; namespace RSBot.Python.Components.API.Core.Entity { @@ -34,6 +34,7 @@ public void Init(Main main) { _main = main; } + private string GetStatusText(QuestStatus status) { switch (status) @@ -69,12 +70,18 @@ private PyList GetQuests() { var pyQuest = new PyDict(); var quest = activeQuest.Value; - pyQuest.SetItem(new PyString("name"), new PyString(Game.ReferenceManager.GetTranslation(quest.Quest.NameString))); + pyQuest.SetItem( + new PyString("name"), + new PyString(Game.ReferenceManager.GetTranslation(quest.Quest.NameString)) + ); pyQuest.SetItem(new PyString("id"), new PyInt(quest.Id)); pyQuest.SetItem(new PyString("level"), new PyInt(quest.Quest.Level)); pyQuest.SetItem(new PyString("status"), new PyString(GetStatusText(quest.Status))); - pyQuest.SetItem(new PyString("npc"), new PyString(Game.ReferenceManager.GetTranslation(quest.Quest.NoticeNPC))); - + pyQuest.SetItem( + new PyString("npc"), + new PyString(Game.ReferenceManager.GetTranslation(quest.Quest.NoticeNPC)) + ); + if (quest.Npcs?.Length > 0) { foreach (var npcId in quest.Npcs) @@ -82,7 +89,7 @@ private PyList GetQuests() var npc = Game.ReferenceManager.GetRefObjChar(npcId); pyQuest.SetItem(new PyString("npc_name"), new PyInt(npc.NameStrID)); pyQuest.SetItem(new PyString("npc_id"), new PyInt(npc.ID)); - pyQuest.SetItem(new PyString("npc_servername"), new PyString(npc.CodeName)); + pyQuest.SetItem(new PyString("npc_servername"), new PyString(npc.CodeName)); } } if (quest.Quest.Reward != null) @@ -102,10 +109,16 @@ private PyList GetQuests() foreach (var rewardItem in quest.Quest.RewardItems) { if (rewardItem.Item != null) - pyQuest.SetItem(new PyString("reward_item"), new PyString(rewardItem.Item.GetRealName())); + pyQuest.SetItem( + new PyString("reward_item"), + new PyString(rewardItem.Item.GetRealName()) + ); if (rewardItem.OptionalItem != null) - pyQuest.SetItem(new PyString("reward_optional"), new PyString(rewardItem.OptionalItem.GetRealName())); + pyQuest.SetItem( + new PyString("reward_optional"), + new PyString(rewardItem.OptionalItem.GetRealName()) + ); } } @@ -124,7 +137,8 @@ private PyList GetQuests() return result; } - } + } + public PyList get_quests() { return GetQuests(); diff --git a/Plugins/RSBot.Python/Components/API/Core/Training/API.Training.cs b/Plugins/RSBot.Python/Components/API/Core/Training/API.Training.cs index 595b9dea..38fe2aac 100644 --- a/Plugins/RSBot.Python/Components/API/Core/Training/API.Training.cs +++ b/Plugins/RSBot.Python/Components/API/Core/Training/API.Training.cs @@ -1,10 +1,10 @@ -using Python.Runtime; +using System; +using Python.Runtime; using RSBot.Core; using RSBot.Core.Event; using RSBot.Core.Objects; using RSBot.Python.Components.API.Interface; using RSBot.Python.Views; -using System; namespace RSBot.Python.Components.API.Core.Training { @@ -42,15 +42,21 @@ private bool SetTrainingArea(string name) if (trainingArea.Name.Equals(name, StringComparison.OrdinalIgnoreCase)) { - SetTrainingPosition(trainingArea.Position.X, trainingArea.Position.Y, trainingArea.Position.Region, trainingArea.Radius); + SetTrainingPosition( + trainingArea.Position.X, + trainingArea.Position.Y, + trainingArea.Position.Region, + trainingArea.Radius + ); return true; } } return false; } + private bool SetTrainingPosition(float x, float y, ushort region, int radius) { - if(Game.Player == null) + if (Game.Player == null) { return false; } @@ -65,8 +71,10 @@ private bool SetTrainingPosition(float x, float y, ushort region, int radius) PlayerConfig.Set("RSBot.Area.Z", pos.ZOffset); PlayerConfig.Set("RSBot.Area.Radius", radius); - Log.Notify("[Python-API] New training area coordinates set. " + - $"X: {pos.XOffset}, Y: {pos.YOffset}, Z: {pos.ZOffset}, Region: {pos.Region}"); + Log.Notify( + "[Python-API] New training area coordinates set. " + + $"X: {pos.XOffset}, Y: {pos.YOffset}, Z: {pos.ZOffset}, Region: {pos.Region}" + ); EventManager.FireEvent("OnSetTrainingArea"); return true; } @@ -76,10 +84,12 @@ private bool SetTrainingPosition(float x, float y, ushort region, int radius) return false; } } + private bool SetTrainingScript(string path) { return false; } + private PyDict GetTrainingArea(string name) { using (Py.GIL()) @@ -112,6 +122,7 @@ private PyDict GetTrainingArea(string name) return result; } } + private PyDict GetTrainingPosition() { using (Py.GIL()) @@ -127,10 +138,14 @@ private PyDict GetTrainingPosition() result.SetItem(new PyString("z"), new PyFloat(area.Position.ZOffset)); result.SetItem(new PyString("radius"), new PyInt(area.Radius)); result.SetItem(new PyString("region"), new PyInt(area.Position.Region.Id)); - result.SetItem(new PyString("region_name"), new PyString(Game.ReferenceManager.GetTranslation(area.Position.Region.ToString()))); + result.SetItem( + new PyString("region_name"), + new PyString(Game.ReferenceManager.GetTranslation(area.Position.Region.ToString())) + ); return result; } } + private void MoveToCoordinates(float x, float y, ushort region) { if (Game.Player != null) @@ -138,7 +153,7 @@ private void MoveToCoordinates(float x, float y, ushort region) try { Position pos = new(x, y, region); - Game.Player.MoveTo(pos,false); + Game.Player.MoveTo(pos, false); } catch (Exception e) { @@ -146,34 +161,42 @@ private void MoveToCoordinates(float x, float y, ushort region) } } } + private bool GetTrainingScript(string path) { return false; } + public bool set_training_area(string name) { return SetTrainingArea(name); } + public bool set_training_position(float x, float y, ushort region, int radius) { return SetTrainingPosition(x, y, region, radius); } + public bool set_training_script(string path) { return SetTrainingScript(path); } + public PyDict get_training_area(string name) { return GetTrainingArea(name); } + public PyDict get_training_position() { return GetTrainingPosition(); } + public PyDict get_training_script() { return new PyDict(); } + public void move_to(float x, float y, ushort region) { MoveToCoordinates(x, y, region); diff --git a/Plugins/RSBot.Python/Components/API/GUI/API.Gui.cs b/Plugins/RSBot.Python/Components/API/GUI/API.Gui.cs index 3bdd0172..3280bb3b 100644 --- a/Plugins/RSBot.Python/Components/API/GUI/API.Gui.cs +++ b/Plugins/RSBot.Python/Components/API/GUI/API.Gui.cs @@ -1,11 +1,11 @@ -using Python.Runtime; +using System; +using System.Collections.Generic; +using System.Windows.Forms; +using Python.Runtime; using RSBot.Python.Components.API.GUI.Controls; using RSBot.Python.Components.API.GUI.Wrapper; using RSBot.Python.Components.API.Interface; using RSBot.Python.Views; -using System; -using System.Collections.Generic; -using System.Windows.Forms; namespace RSBot.Python.Components.API.GUI { @@ -47,42 +47,89 @@ public LabelWrapper Label(string text, int x, int y, int? width = null, int? hei return wrapper; } - public ButtonWrapper Button(string text, int x, int y, int? width = null, int? height = null, PyObject handler = null) + public ButtonWrapper Button( + string text, + int x, + int y, + int? width = null, + int? height = null, + PyObject handler = null + ) { var btn = _api.CreateButton(PluginName, x, y, text, width, height); var wrapper = new ButtonWrapper(btn, _api.Form, handler); _api._activeControls.Add(wrapper); return wrapper; } - public CheckBoxWrapper CheckBox(string text, int x, int y, int? width = null, int? height = null, PyObject handler = null) + + public CheckBoxWrapper CheckBox( + string text, + int x, + int y, + int? width = null, + int? height = null, + PyObject handler = null + ) { var cb = _api.CreateCheckBox(PluginName, x, y, text, width, height); var wrapper = new CheckBoxWrapper(cb, _api.Form, handler); _api._activeControls.Add(wrapper); return wrapper; } - public TextBoxWrapper TextBox(string text, int x, int y, int? width = null, int? height = null, PyObject handler = null) + + public TextBoxWrapper TextBox( + string text, + int x, + int y, + int? width = null, + int? height = null, + PyObject handler = null + ) { var tb = _api.CreateTextBox(PluginName, x, y, text, width, height); var wrapper = new TextBoxWrapper(tb, _api.Form, handler); _api._activeControls.Add(wrapper); return wrapper; } - public ComboBoxWrapper ComboBox(string text, int x, int y, int? width = null, int? height = null, PyObject handler = null) + + public ComboBoxWrapper ComboBox( + string text, + int x, + int y, + int? width = null, + int? height = null, + PyObject handler = null + ) { var cb = _api.CreateComboBox(PluginName, x, y, text, width, height); var wrapper = new ComboBoxWrapper(cb, _api.Form, handler); _api._activeControls.Add(wrapper); return wrapper; } - public ListBoxWrapper ListBox(string text,int x, int y, int? width = null, int? height = null, PyObject handler = null) + + public ListBoxWrapper ListBox( + string text, + int x, + int y, + int? width = null, + int? height = null, + PyObject handler = null + ) { - var lb = _api.CreateListBox(PluginName, x, y,text, width, height); + var lb = _api.CreateListBox(PluginName, x, y, text, width, height); var wrapper = new ListBoxWrapper(lb, _api.Form, handler); _api._activeControls.Add(wrapper); return wrapper; } - public RadioButtonWrapper RadioButton(string text, int x, int y, int? width = null, int? height = null, PyObject handler = null) + + public RadioButtonWrapper RadioButton( + string text, + int x, + int y, + int? width = null, + int? height = null, + PyObject handler = null + ) { var rb = _api.CreateRadioButton(PluginName, x, y, text, width, height); var wrapper = new RadioButtonWrapper(rb, _api.Form, handler); @@ -103,40 +150,59 @@ private void AddControl(string pluginName, Control c) private void CreatePage(string pluginName) { - if (_form == null) return; + if (_form == null) + return; - _form.Invoke(new Action(() => - { - if (!_pluginPages.ContainsKey(pluginName)) + _form.Invoke( + new Action(() => { - var page = new TabPage + if (!_pluginPages.ContainsKey(pluginName)) { - Name = pluginName, - Text = pluginName, - AutoScroll = true - }; - - _pluginPages[pluginName] = page; - _form.tcPlugin.TabPages.Add(page); - } - })); + var page = new TabPage + { + Name = pluginName, + Text = pluginName, + AutoScroll = true, + }; + + _pluginPages[pluginName] = page; + _form.tcPlugin.TabPages.Add(page); + } + }) + ); } - private SDUI.Controls.Label CreateLabel(string pluginName, int x, int y, string text, int? width = null, int? height = null) + private SDUI.Controls.Label CreateLabel( + string pluginName, + int x, + int y, + string text, + int? width = null, + int? height = null + ) { var lbl = new SDUI.Controls.Label(); lbl.Text = text; lbl.Left = x; lbl.Top = y; lbl.AutoSize = true; - if (width.HasValue) lbl.Width = width.Value; - if (height.HasValue) lbl.Height = height.Value; + if (width.HasValue) + lbl.Width = width.Value; + if (height.HasValue) + lbl.Height = height.Value; AddControl(pluginName, lbl); return lbl; } - private SDUI.Controls.Button CreateButton(string pluginName, int x, int y, string text, int? width = null, int? height = null) + private SDUI.Controls.Button CreateButton( + string pluginName, + int x, + int y, + string text, + int? width = null, + int? height = null + ) { var btn = new SDUI.Controls.Button(); btn.Text = text; @@ -145,7 +211,7 @@ private SDUI.Controls.Button CreateButton(string pluginName, int x, int y, strin btn.AutoSize = true; if (width.HasValue) { - btn.Width = width.Value; + btn.Width = width.Value; } if (height.HasValue) { @@ -155,20 +221,36 @@ private SDUI.Controls.Button CreateButton(string pluginName, int x, int y, strin return btn; } - private SDUI.Controls.CheckBox CreateCheckBox(string pluginName, int x, int y, string text, int? width = null, int? height = null) + private SDUI.Controls.CheckBox CreateCheckBox( + string pluginName, + int x, + int y, + string text, + int? width = null, + int? height = null + ) { var cb = new SDUI.Controls.CheckBox(); cb.Text = text; cb.Left = x; cb.Top = y; cb.AutoSize = true; - if (width.HasValue) cb.Width = width.Value; - if (height.HasValue) cb.Height = height.Value; + if (width.HasValue) + cb.Width = width.Value; + if (height.HasValue) + cb.Height = height.Value; AddControl(pluginName, cb); return cb; } - private SDUI.Controls.TextBox CreateTextBox(string pluginName, int x, int y, string defaultText,int? width = null,int? height = null) + private SDUI.Controls.TextBox CreateTextBox( + string pluginName, + int x, + int y, + string defaultText, + int? width = null, + int? height = null + ) { var tb = new SDUI.Controls.TextBox(); tb.Text = defaultText; @@ -184,7 +266,14 @@ private SDUI.Controls.TextBox CreateTextBox(string pluginName, int x, int y, str return tb; } - private SDUI.Controls.ComboBox CreateComboBox(string pluginName, int x, int y, string? text = null, int? width = null, int? height = null) + private SDUI.Controls.ComboBox CreateComboBox( + string pluginName, + int x, + int y, + string? text = null, + int? width = null, + int? height = null + ) { var cb = new SDUI.Controls.ComboBox(); cb.Text = text; @@ -192,13 +281,23 @@ private SDUI.Controls.ComboBox CreateComboBox(string pluginName, int x, int y, s cb.Top = y; cb.Width = 150; cb.DropDownStyle = ComboBoxStyle.DropDownList; - if (height.HasValue) cb.Height= height.Value; - if (width.HasValue) cb.Width = width.Value; + if (height.HasValue) + cb.Height = height.Value; + if (width.HasValue) + cb.Width = width.Value; AddControl(pluginName, cb); return cb; } - private ListBox CreateListBox(string pluginName, int x, int y, string? text = null, int? width = null, int? height = null) + + private ListBox CreateListBox( + string pluginName, + int x, + int y, + string? text = null, + int? width = null, + int? height = null + ) { ListBox lb = new ListBox { @@ -207,21 +306,33 @@ private ListBox CreateListBox(string pluginName, int x, int y, string? text = nu Width = 150, Text = text, }; - if (height.HasValue) lb.Height = height.Value; - if (width.HasValue) lb.Width = width.Value; + if (height.HasValue) + lb.Height = height.Value; + if (width.HasValue) + lb.Width = width.Value; AddControl(pluginName, lb); return lb; } - private SDUI.Controls.Radio CreateRadioButton(string pluginName, int x, int y, string text, int? width = null, int? height = null) + + private SDUI.Controls.Radio CreateRadioButton( + string pluginName, + int x, + int y, + string text, + int? width = null, + int? height = null + ) { var rb = new SDUI.Controls.Radio(); rb.Text = text; rb.Left = x; rb.Top = y; rb.AutoSize = true; - if (width.HasValue) rb.Width = width.Value; - if (height.HasValue) rb.Height = height.Value; + if (width.HasValue) + rb.Width = width.Value; + if (height.HasValue) + rb.Height = height.Value; AddControl(pluginName, rb); return rb; } @@ -229,51 +340,60 @@ private SDUI.Controls.Radio CreateRadioButton(string pluginName, int x, int y, s #region Reset public void ResetPlugin(string pluginName) { - if (_form == null) return; + if (_form == null) + return; - _form.Invoke(new Action(() => - { - if (_pluginPages.TryGetValue(pluginName, out var page)) + _form.Invoke( + new Action(() => { - foreach (Control c in page.Controls) - c.Dispose(); + if (_pluginPages.TryGetValue(pluginName, out var page)) + { + foreach (Control c in page.Controls) + c.Dispose(); - page.Controls.Clear(); + page.Controls.Clear(); - if (_form.tcPlugin.TabPages.Contains(page)) - _form.tcPlugin.TabPages.Remove(page); + if (_form.tcPlugin.TabPages.Contains(page)) + _form.tcPlugin.TabPages.Remove(page); - page.Dispose(); - } + page.Dispose(); + } - _pluginPages.Remove(pluginName); - })); + _pluginPages.Remove(pluginName); + }) + ); _form.tcPlugin.Refresh(); } public void ClearAllControls() { - if (_form == null) return; + if (_form == null) + return; - _form.Invoke(new Action(() => - { - foreach (var page in _pluginPages.Values) - page.Controls.Clear(); - })); + _form.Invoke( + new Action(() => + { + foreach (var page in _pluginPages.Values) + page.Controls.Clear(); + }) + ); _activeControls.Clear(); } public void ClearAllPagesExceptFirst() { - if (_form == null) return; + if (_form == null) + return; - _form.Invoke(new Action(() => - { - while (_form.tcPlugin.TabPages.Count > 1) - _form.tcPlugin.TabPages.RemoveAt(1); - })); + _form.Invoke( + new Action(() => + { + while (_form.tcPlugin.TabPages.Count > 1) + _form.tcPlugin.TabPages.RemoveAt(1); + }) + ); _pluginPages.Clear(); } diff --git a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ButtonWrapper.cs b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ButtonWrapper.cs index 622c56be..4d405315 100644 --- a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ButtonWrapper.cs +++ b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ButtonWrapper.cs @@ -29,6 +29,5 @@ public ButtonWrapper(Button btn, Main form, PyObject callback) } }; } - } } diff --git a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.CheckboxWrapper.cs b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.CheckboxWrapper.cs index bfadabbe..17c168e8 100644 --- a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.CheckboxWrapper.cs +++ b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.CheckboxWrapper.cs @@ -15,7 +15,6 @@ public CheckBoxWrapper(CheckBox cb, Main form, PyObject callback = null) _callback = callback; if (_callback != null) { - cb.CheckedChanged += (sender, args) => { using (Py.GIL()) @@ -31,7 +30,6 @@ public CheckBoxWrapper(CheckBox cb, Main form, PyObject callback = null) } }; } - } private bool GetChecked() @@ -48,6 +46,7 @@ public bool get_checked() { return GetChecked(); } + public void set_checked(bool value) { SetChecked(value); diff --git a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ComboboxWrapper.cs b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ComboboxWrapper.cs index 656aec3d..f094ad98 100644 --- a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ComboboxWrapper.cs +++ b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ComboboxWrapper.cs @@ -15,7 +15,6 @@ public ComboBoxWrapper(ComboBox cb, Main form, PyObject callback = null) _callback = callback; if (_callback != null) { - cb.SelectedIndexChanged += (sender, args) => { using (Py.GIL()) @@ -47,18 +46,22 @@ private void SetIndex(int index) { Invoke(() => ((ComboBox)Control).SelectedIndex = index); } + private void RemoveItem(int index) { Invoke(() => ((ComboBox)Control).Items.RemoveAt(index)); } + private int GetItemCount() { return ((ComboBox)Control).Items.Count; } + private string GetItem(int index) { return ((ComboBox)Control).Items[index].ToString(); } + private string GetSelectedItem() { return ((ComboBox)Control).SelectedItem.ToString(); @@ -68,26 +71,32 @@ public void add_item(string text) { AddItem(text); } + public int selected_index() { return GetIndex(); } + public void set_index(int index) { SetIndex(index); } + public void remove_item(int index) { RemoveItem(index); } + public int item_count() { return GetItemCount(); } + public string get_item(int index) { return GetItem(index); } + public string get_selected_item() { return GetSelectedItem(); diff --git a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.LabelWrapper.cs b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.LabelWrapper.cs index a407dd64..5550e573 100644 --- a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.LabelWrapper.cs +++ b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.LabelWrapper.cs @@ -7,8 +7,6 @@ namespace RSBot.Python.Components.API.GUI.Controls public class LabelWrapper : GuiControlWrapper { public LabelWrapper(Label lbl, Main form) - : base(lbl, form) - { - } + : base(lbl, form) { } } } diff --git a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ListBoxWrapper.cs b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ListBoxWrapper.cs index 31a4d36e..c3985734 100644 --- a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ListBoxWrapper.cs +++ b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.ListBoxWrapper.cs @@ -43,58 +43,72 @@ private void AddItem(string text) { Invoke(() => ((ListBox)Control).Items.Add(text)); } + private void SetIndex(int index) { Invoke(() => ((ListBox)Control).SelectedIndex = index); } + private void RemoveItem(int index) { Invoke(() => ((ListBox)Control).Items.RemoveAt(index)); } + private int GetIndex() { return ((ListBox)Control).SelectedIndex; } + private int GetItemCount() { return ((ListBox)Control).Items.Count; } + private string GetItem(int index) { return ((ListBox)Control).Items[index].ToString(); } + private string GetSelectedItem() { return ((ListBox)Control).SelectedItem.ToString(); } + public string get_text() { return GetText(); } + public void add_item(string text) { AddItem(text); } + public void set_index(int index) { SetIndex(index); } + public void remove_item(int index) { RemoveItem(index); } + public int selected_index() { return GetIndex(); } + public int item_count() { return GetItemCount(); } + public string get_item(int index) { return GetItem(index); } + public string get_selected_item() { return GetSelectedItem(); diff --git a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.RadioButtonWrapper.cs b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.RadioButtonWrapper.cs index fd6f0ad6..e01234d6 100644 --- a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.RadioButtonWrapper.cs +++ b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.RadioButtonWrapper.cs @@ -15,7 +15,6 @@ public RadioButtonWrapper(Radio rb, Main form, PyObject callback = null) _callback = callback; if (_callback != null) { - rb.CheckedChanged += (sender, args) => { using (Py.GIL()) @@ -31,7 +30,6 @@ public RadioButtonWrapper(Radio rb, Main form, PyObject callback = null) } }; } - } private bool GetChecked() @@ -48,6 +46,7 @@ public bool get_checked() { return GetChecked(); } + public void set_checked(bool value) { SetChecked(value); diff --git a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.TextboxWrapper.cs b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.TextboxWrapper.cs index 677a1756..eed884d8 100644 --- a/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.TextboxWrapper.cs +++ b/Plugins/RSBot.Python/Components/API/GUI/Controls/API.Gui.TextboxWrapper.cs @@ -42,10 +42,12 @@ private void SetTextValue(string text) { Invoke(() => ((SDUI.Controls.TextBox)Control).Text = text); } + public string get_text() { return GetText(); } + public void set_text_value(string text) { SetTextValue(text); diff --git a/Plugins/RSBot.Python/Components/API/GUI/Wrapper/API.Gui.Wrapper.cs b/Plugins/RSBot.Python/Components/API/GUI/Wrapper/API.Gui.Wrapper.cs index 50b62985..5b756855 100644 --- a/Plugins/RSBot.Python/Components/API/GUI/Wrapper/API.Gui.Wrapper.cs +++ b/Plugins/RSBot.Python/Components/API/GUI/Wrapper/API.Gui.Wrapper.cs @@ -1,6 +1,6 @@ -using RSBot.Python.Views; -using System; +using System; using System.Windows.Forms; +using RSBot.Python.Views; namespace RSBot.Python.Components.API.GUI.Wrapper { @@ -37,6 +37,7 @@ private void SetEnabled(bool enabled) { Invoke(() => Control.Enabled = enabled); } + private void Move(int x, int y) { Invoke(() => Control.Location = new System.Drawing.Point(x, y)); @@ -46,14 +47,17 @@ public void set_visible(bool visible) { SetVisible(visible); } + public void set_text(string text) { SetText(text); } + public void set_enabled(bool enabled) { SetEnabled(enabled); } + public void move_position(int x, int y) { Move(x, y); diff --git a/Plugins/RSBot.Python/Components/API/Handler/PythonErrorHandler.cs b/Plugins/RSBot.Python/Components/API/Handler/PythonErrorHandler.cs index 0cbb5964..57cae881 100644 --- a/Plugins/RSBot.Python/Components/API/Handler/PythonErrorHandler.cs +++ b/Plugins/RSBot.Python/Components/API/Handler/PythonErrorHandler.cs @@ -1,6 +1,6 @@ -using Python.Runtime; -using System; +using System; using System.Text; +using Python.Runtime; namespace RSBot.Python.Components.API.Handler { diff --git a/Plugins/RSBot.Python/Components/API/Handler/PythonInfoHandler.cs b/Plugins/RSBot.Python/Components/API/Handler/PythonInfoHandler.cs index 7b52830e..163984e0 100644 --- a/Plugins/RSBot.Python/Components/API/Handler/PythonInfoHandler.cs +++ b/Plugins/RSBot.Python/Components/API/Handler/PythonInfoHandler.cs @@ -1,6 +1,6 @@ -using RSBot.Python.Components.API.ModuleLoader; -using System.IO; +using System.IO; using System.Text.RegularExpressions; +using RSBot.Python.Components.API.ModuleLoader; namespace RSBot.Python.Components.API.Handler { @@ -13,11 +13,7 @@ public static PythonPluginInfo ReadPythonPluginInfo(string filePath) string ReadConst(string key) { - var m = Regex.Match( - text, - $@"^\s*{key}\s*=\s*[""'](?[^""']+)[""']\s*$", - RegexOptions.Multiline - ); + var m = Regex.Match(text, $@"^\s*{key}\s*=\s*[""'](?[^""']+)[""']\s*$", RegexOptions.Multiline); return m.Success ? m.Groups["v"].Value.Trim() : null; } @@ -37,7 +33,7 @@ string ReadHeader(string key) Name = ReadConst("NAME") ?? ReadHeader("Name") ?? Path.GetFileNameWithoutExtension(fileName), Description = ReadConst("DESCRIPTION") ?? ReadHeader("Description") ?? "", Author = ReadConst("AUTHOR") ?? ReadHeader("Author") ?? "", - Version = ReadConst("VERSION") ?? ReadHeader("Version") ?? "" + Version = ReadConst("VERSION") ?? ReadHeader("Version") ?? "", }; } } diff --git a/Plugins/RSBot.Python/Components/API/ModuleLoader/ModuleLoader.cs b/Plugins/RSBot.Python/Components/API/ModuleLoader/ModuleLoader.cs index f013d969..13ca1568 100644 --- a/Plugins/RSBot.Python/Components/API/ModuleLoader/ModuleLoader.cs +++ b/Plugins/RSBot.Python/Components/API/ModuleLoader/ModuleLoader.cs @@ -22,15 +22,14 @@ public static void InitAll(Main form) { var pluginType = typeof(IPythonPlugin); - var pluginInstances = AppDomain.CurrentDomain.GetAssemblies() - .SelectMany(a => a.GetTypes()) - .Where(t => pluginType.IsAssignableFrom(t) - && !t.IsInterface - && !t.IsAbstract) + var pluginInstances = AppDomain + .CurrentDomain.GetAssemblies() + .SelectMany(a => a.GetTypes()) + .Where(t => pluginType.IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract) .Select(t => (IPythonPlugin)Activator.CreateInstance(t)!); foreach (var plugin in pluginInstances) { - plugin.Init(form); + plugin.Init(form); _plugins[plugin.ModuleName] = plugin; form.AppendLog($"[Python-API] Plugin loaded: {plugin.ModuleName}"); } @@ -51,10 +50,7 @@ public static IPythonPlugin Get(string moduleName) /// public static Dictionary GetAll() { - return _plugins.ToDictionary( - x => x.Key, - x => (object)x.Value - ); + return _plugins.ToDictionary(x => x.Key, x => (object)x.Value); } } } diff --git a/Plugins/RSBot.Python/Components/API/ModuleLoader/PythonPlugin.cs b/Plugins/RSBot.Python/Components/API/ModuleLoader/PythonPlugin.cs index f3990792..ef9db8fb 100644 --- a/Plugins/RSBot.Python/Components/API/ModuleLoader/PythonPlugin.cs +++ b/Plugins/RSBot.Python/Components/API/ModuleLoader/PythonPlugin.cs @@ -12,6 +12,7 @@ public static dynamic all() return ModuleLoader.GetAll(); } } + public class PythonPluginInfo { public string FileName { get; set; } @@ -20,5 +21,4 @@ public class PythonPluginInfo public string Author { get; set; } public string Version { get; set; } } - } diff --git a/Plugins/RSBot.Python/Components/API/ModuleLoader/StubGenerator.cs b/Plugins/RSBot.Python/Components/API/ModuleLoader/StubGenerator.cs index ca7efb21..d8ff14bf 100644 --- a/Plugins/RSBot.Python/Components/API/ModuleLoader/StubGenerator.cs +++ b/Plugins/RSBot.Python/Components/API/ModuleLoader/StubGenerator.cs @@ -1,12 +1,11 @@ -using RSBot.Python.Components.API.GUI; -using RSBot.Python.Components.API.GUI.Wrapper; -using System; +using System; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Windows.Forms; - +using RSBot.Python.Components.API.GUI; +using RSBot.Python.Components.API.GUI.Wrapper; namespace RSBot.Python.Components.API.ModuleLoader { @@ -52,20 +51,20 @@ private static void WritePluginFunctions(StringBuilder sb) var type = plugin.GetType(); var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) - .Where(m => - !m.IsSpecialName && - m.Name != "Init" && - m.Name != "ToString" && - m.Name != "Equals" && - m.Name != "GetHashCode" && - m.Name != "GetType"); + .Where(m => + !m.IsSpecialName + && m.Name != "Init" + && m.Name != "ToString" + && m.Name != "Equals" + && m.Name != "GetHashCode" + && m.Name != "GetType" + ); foreach (var method in methods) { var name = method.Name; var parameters = method.GetParameters(); - var paramList = string.Join(", ", - parameters.Select(p => $"{p.Name}: {MapType(p.ParameterType)}")); + var paramList = string.Join(", ", parameters.Select(p => $"{p.Name}: {MapType(p.ParameterType)}")); var returnType = MapType(method.ReturnType); @@ -91,20 +90,21 @@ private static void WriteGuiClass(StringBuilder sb) sb.AppendLine("class GUI:"); sb.AppendLine(" def __init__(self, plugin_name: str) -> None: ..."); - var methods = guiNestedType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) - .Where(m => - !m.IsSpecialName && - m.Name != "ToString" && - m.Name != "Equals" && - m.Name != "GetHashCode" && - m.Name != "GetType"); + var methods = guiNestedType + .GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) + .Where(m => + !m.IsSpecialName + && m.Name != "ToString" + && m.Name != "Equals" + && m.Name != "GetHashCode" + && m.Name != "GetType" + ); foreach (var method in methods) { var name = method.Name; var parameters = method.GetParameters(); - var paramList = string.Join(", ", - parameters.Select(p => $"{p.Name}: {MapType(p.ParameterType)}")); + var paramList = string.Join(", ", parameters.Select(p => $"{p.Name}: {MapType(p.ParameterType)}")); string returnType; @@ -117,22 +117,19 @@ private static void WriteGuiClass(StringBuilder sb) returnType = MapType(method.ReturnType); } - sb.AppendLine($" def {name}(self, {paramList}) -> {returnType}: ..."); } sb.AppendLine(); } + // 3 GuiControlWrapper-Childs private static void WriteGuiWrappers(StringBuilder sb) { var asm = typeof(GuiControlWrapper).Assembly; var wrappers = asm.GetTypes() - .Where(t => - typeof(GuiControlWrapper).IsAssignableFrom(t) && - !t.IsAbstract && - t.IsClass); + .Where(t => typeof(GuiControlWrapper).IsAssignableFrom(t) && !t.IsAbstract && t.IsClass); if (!wrappers.Any()) { @@ -149,15 +146,17 @@ private static void WriteGuiWrappers(StringBuilder sb) var className = wrapperType.Name; sb.AppendLine($"class {className}:"); - var methods = wrapperType.GetMethods(BindingFlags.Public | BindingFlags.Instance) + var methods = wrapperType + .GetMethods(BindingFlags.Public | BindingFlags.Instance) .Where(m => - m.DeclaringType != typeof(object) && - m.DeclaringType != typeof(Control) && - !m.IsSpecialName && - m.Name != "ToString" && - m.Name != "Equals" && - m.Name != "GetHashCode" && - m.Name != "GetType"); + m.DeclaringType != typeof(object) + && m.DeclaringType != typeof(Control) + && !m.IsSpecialName + && m.Name != "ToString" + && m.Name != "Equals" + && m.Name != "GetHashCode" + && m.Name != "GetType" + ); if (!methods.Any()) { @@ -170,8 +169,7 @@ private static void WriteGuiWrappers(StringBuilder sb) { var name = method.Name; var parameters = method.GetParameters(); - var paramList = string.Join(", ", - parameters.Select(p => $"{p.Name}: {MapType(p.ParameterType)}")); + var paramList = string.Join(", ", parameters.Select(p => $"{p.Name}: {MapType(p.ParameterType)}")); string returnType; @@ -184,7 +182,6 @@ private static void WriteGuiWrappers(StringBuilder sb) returnType = MapType(method.ReturnType); } - if (paramList.Length > 0) sb.AppendLine($" def {name}(self, {paramList}) -> {returnType}: ..."); else @@ -198,12 +195,18 @@ private static void WriteGuiWrappers(StringBuilder sb) // Typ-Mapping C# -> Python Typen private static string MapType(Type t) { - if (t == typeof(void)) return "None"; - if (t == typeof(int)) return "int"; - if (t == typeof(long)) return "int"; - if (t == typeof(float) || t == typeof(double) || t == typeof(decimal)) return "float"; - if (t == typeof(string)) return "str"; - if (t == typeof(bool)) return "bool"; + if (t == typeof(void)) + return "None"; + if (t == typeof(int)) + return "int"; + if (t == typeof(long)) + return "int"; + if (t == typeof(float) || t == typeof(double) || t == typeof(decimal)) + return "float"; + if (t == typeof(string)) + return "str"; + if (t == typeof(bool)) + return "bool"; if (typeof(System.Collections.IDictionary).IsAssignableFrom(t)) return "dict"; diff --git a/Plugins/RSBot.Python/Components/Loader/PythonRuntimeManager.cs b/Plugins/RSBot.Python/Components/Loader/PythonRuntimeManager.cs index f0ae208b..4eab7c70 100644 --- a/Plugins/RSBot.Python/Components/Loader/PythonRuntimeManager.cs +++ b/Plugins/RSBot.Python/Components/Loader/PythonRuntimeManager.cs @@ -1,10 +1,9 @@ -using Python.Runtime; -using RSBot.Python.Components.API.Handler; -using RSBot.Python.Components.API.ModuleLoader; -using System; +using System; using System.IO; using System.Linq; - +using Python.Runtime; +using RSBot.Python.Components.API.Handler; +using RSBot.Python.Components.API.ModuleLoader; namespace RSBot.Python.Components.Loader { @@ -14,7 +13,8 @@ public class PythonRuntimeManager public void Initialize(string projectDir, Action log) { - if (IsInitialized) return; + if (IsInitialized) + return; string pythonHome = Path.Combine(projectDir, "Data", "Python", "PyRuntime"); string pythonDll = Directory.GetFiles(pythonHome, "python31*.dll").FirstOrDefault(); @@ -38,7 +38,8 @@ public void Initialize(string projectDir, Action log) { try { - PythonEngine.Exec(@" + PythonEngine.Exec( + @" import clr, sys, types clr.AddReference('RSBot.Python') from RSBot.Python.Components.API.ModuleLoader import PythonPluginAccessor @@ -58,7 +59,8 @@ from RSBot.Python.Components.API.ModuleLoader import PythonPluginAccessor from RSBot.Python.Components.API.GUI import WFAPI RSBot.GUI = WFAPI.GUI -"); +" + ); IsInitialized = true; log("[Python-API] Python initialised and created RSBot Module."); } diff --git a/Plugins/RSBot.Python/Components/Manager/PythonPluginManager.cs b/Plugins/RSBot.Python/Components/Manager/PythonPluginManager.cs index 65c3fe5b..37c2976c 100644 --- a/Plugins/RSBot.Python/Components/Manager/PythonPluginManager.cs +++ b/Plugins/RSBot.Python/Components/Manager/PythonPluginManager.cs @@ -1,11 +1,11 @@ -using Python.Runtime; -using RSBot.Python.Components.API.Handler; -using RSBot.Python.Components.API.ModuleLoader; -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; +using Python.Runtime; +using RSBot.Python.Components.API.Handler; +using RSBot.Python.Components.API.ModuleLoader; namespace RSBot.Python.Plugins { @@ -31,7 +31,7 @@ public List ScanPlugins(string projectDir, Action log) { var info = PluginMetaReader.ReadPythonPluginInfo(file); result.Add(info); - } + } log($"[Python-API] Found {pythonFiles.Length} Plugins."); return result; @@ -64,6 +64,7 @@ public void RunPlugin(string projectDir, string fileName, Action log) } }); } + public void UnloadPlugin(string fileName, Action log) { using (Py.GIL()) @@ -82,7 +83,10 @@ public void UnloadPlugin(string fileName, Action log) { return p.GetAttr("__name__").ToString() == moduleName; } - catch { return false; } + catch + { + return false; + } }); dynamic gc = Py.Import("gc"); @@ -99,7 +103,8 @@ public void UnloadPlugin(string fileName, Action log) public void ResetPlugins() { - if (_loadedPlugins.Count == 0) return; + if (_loadedPlugins.Count == 0) + return; using (Py.GIL()) { @@ -109,14 +114,13 @@ public void ResetPlugins() _loadedPlugins.Clear(); } } + public void CallPluginEvent(string e, Action log, params object[] args) { using (Py.GIL()) { - var pyArgs = args? - .Select(a => a == null ? PyObject.None : a.ToPython()) - .ToArray() - ?? Array.Empty(); + var pyArgs = + args?.Select(a => a == null ? PyObject.None : a.ToPython()).ToArray() ?? Array.Empty(); foreach (PyObject plugin in _loadedPlugins) { @@ -138,6 +142,5 @@ public void CallPluginEvent(string e, Action log, params object[] args) a.Dispose(); } } - } } diff --git a/Plugins/RSBot.Python/PythonManager.cs b/Plugins/RSBot.Python/PythonManager.cs index 16a06b04..9dfec392 100644 --- a/Plugins/RSBot.Python/PythonManager.cs +++ b/Plugins/RSBot.Python/PythonManager.cs @@ -1,6 +1,4 @@ namespace RSBot.Python { - public class PythonManager - { - } + public class PythonManager { } } diff --git a/Plugins/RSBot.Python/PythonPlugin.cs b/Plugins/RSBot.Python/PythonPlugin.cs index 161759c3..bd70de38 100644 --- a/Plugins/RSBot.Python/PythonPlugin.cs +++ b/Plugins/RSBot.Python/PythonPlugin.cs @@ -7,11 +7,13 @@ public class PythonPlugin : IPlugin public string InternalName => "RSBot.Python"; public static PythonPlugin Instance { get; private set; } public PythonManager Manager { get; private set; } + public void Initialize() { Instance = this; Manager = new PythonManager(); } + public void OnLoadCharacter() { } } } diff --git a/Plugins/RSBot.Python/PythonView.cs b/Plugins/RSBot.Python/PythonView.cs index 0da9f44e..aa4d2040 100644 --- a/Plugins/RSBot.Python/PythonView.cs +++ b/Plugins/RSBot.Python/PythonView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Python { @@ -13,6 +13,7 @@ public class PythonView : IPluginView public int Index => 99; public bool RequireIngame => false; public Control View => Views.View.Instance; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Plugins/RSBot.Python/RSBot.Python.csproj b/Plugins/RSBot.Python/RSBot.Python.csproj index 4d8d7694..15bdd654 100644 --- a/Plugins/RSBot.Python/RSBot.Python.csproj +++ b/Plugins/RSBot.Python/RSBot.Python.csproj @@ -1,19 +1,19 @@ - - net8.0-windows - disable - true - disable - .\..\..\Build\Data\Plugins - false - A open source bot for Silkroad Online + + net8.0-windows + disable + true + disable + .\..\..\Build\Data\Plugins + false + A open source bot for Silkroad Online Copyright © 2026 Silkroad Developer Community - https://github.com/Silkroad-Developer-Community/OasisBot - https://github.com/Silkroad-Developer-Community/OasisBot - Library - 3.13.11 - $(OutputPath)\..\Python\PyRuntime\ - + https://github.com/Silkroad-Developer-Community/OasisBot + https://github.com/Silkroad-Developer-Community/OasisBot + Library + 3.13.11 + $(OutputPath)\..\Python\PyRuntime\ + diff --git a/Plugins/RSBot.Python/Views/Main.cs b/Plugins/RSBot.Python/Views/Main.cs index a2cc1c71..9af60d09 100644 --- a/Plugins/RSBot.Python/Views/Main.cs +++ b/Plugins/RSBot.Python/Views/Main.cs @@ -1,4 +1,10 @@ -using Python.Runtime; +using System; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.Threading.Tasks; +using System.Windows.Forms; +using Python.Runtime; using RSBot.Core.Event; using RSBot.Core.Network; using RSBot.Python.Components.API.GUI; @@ -6,12 +12,6 @@ using RSBot.Python.Components.Loader; using RSBot.Python.Plugins; using SDUI.Controls; -using System; -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Windows.Forms; -using System.Threading.Tasks; namespace RSBot.Python.Views; @@ -21,6 +21,7 @@ public partial class Main : DoubleBufferedControl private readonly PythonRuntimeManager _pyRuntime = new(); private readonly PythonPluginManager _pyPlugins = new(); private string projectDir = Directory.GetParent(Application.StartupPath).FullName; + public Main() { InitializeComponent(); @@ -30,6 +31,7 @@ public Main() SubscribeEvents(); InitPythonRuntime(); } + private void SubscribeEvents() { EventManager.SubscribeEvent("OnTeleportComplete", OnTeleportComplete); @@ -39,6 +41,7 @@ private void SubscribeEvents() EventManager.SubscribeEvent("OnEnterGame", OnEnterGame); EventManager.SubscribeEvent("OnAgentServerDisconnected", OnAgentServerDisconnected); } + private void WireEvents() { dgvPlugin.CurrentCellDirtyStateChanged += (s, e) => @@ -48,7 +51,8 @@ private void WireEvents() }; dgvPlugin.CellValueChanged += (s, e) => { - if (e.RowIndex < 0 || e.ColumnIndex != 0) return; + if (e.RowIndex < 0 || e.ColumnIndex != 0) + return; var row = dgvPlugin.Rows[e.RowIndex]; bool isEnabled = Convert.ToBoolean(row.Cells[0].Value); @@ -63,7 +67,7 @@ private void WireEvents() else { AppendLog($"[Python-API] Deactivated plugin: {fileName}"); - + var gui = ModuleLoader.Get("gui") as WFAPI; gui?.ResetPlugin(pluginName); @@ -71,6 +75,7 @@ private void WireEvents() } }; } + public void AppendLog(string text) { if (InvokeRequired) @@ -89,6 +94,7 @@ private void InitPythonRuntime() _pyRuntime.Initialize(projectDir, AppendLog); ReloadPluginGrid(); } + private void ReloadPluginGrid() { dgvPlugin.Rows.Clear(); @@ -101,6 +107,7 @@ private void ReloadPluginGrid() dgvPlugin.Rows.Add(enabled, info.Name, info.Description, info.Author, info.Version, info.FileName); } } + private void RunPythonPlugin(string fileName) { string projectDir = Directory.GetParent(Application.StartupPath).FullName; @@ -113,7 +120,7 @@ private void ResetPythonPlugins() } #endregion - + private void btnReload_Click(object sender, EventArgs e) { var gui = ModuleLoader.Get("gui") as WFAPI; @@ -123,40 +130,49 @@ private void btnReload_Click(object sender, EventArgs e) } ResetPythonPlugins(); ReloadPluginGrid(); - string pluginFolder = Path.Combine(Directory.GetParent(Application.StartupPath).Parent.Parent.FullName, "Plugins"); - + string pluginFolder = Path.Combine( + Directory.GetParent(Application.StartupPath).Parent.Parent.FullName, + "Plugins" + ); } + #region events private void OnTeleportStart() { _pyPlugins.CallPluginEvent("on_teleported", AppendLog, new PyInt(1)); } + private void OnTeleportComplete() { _pyPlugins.CallPluginEvent("on_teleported", AppendLog, new PyInt(2)); } + private void OnClientPacketReceive(Packet packet) { byte[] data = packet.GetBytes(); string opcode = packet.HexCode; string data_hex = BitConverter.ToString(data).Replace("-", " "); - _pyPlugins.CallPluginEvent("on_packet_from_client", AppendLog, opcode,data_hex); + _pyPlugins.CallPluginEvent("on_packet_from_client", AppendLog, opcode, data_hex); } + private void OnServerPacketReceive(Packet packet) { byte[] data = packet.GetBytes(); string opcode = packet.HexCode; string data_hex = BitConverter.ToString(data).Replace("-", " "); - _pyPlugins.CallPluginEvent("on_packet_from_server", AppendLog, opcode,data_hex); + _pyPlugins.CallPluginEvent("on_packet_from_server", AppendLog, opcode, data_hex); } + private void OnEnterGame() { _pyPlugins.CallPluginEvent("on_enter_game", AppendLog); } + private void OnAgentServerDisconnected() { _pyPlugins.CallPluginEvent("on_disconnect", AppendLog); } + private async void timerEventLoop_Tick(object sender, EventArgs e) { try @@ -171,6 +187,6 @@ private async void timerEventLoop_Tick(object sender, EventArgs e) #endregion private void btnOpenFolder_Click(object sender, EventArgs e) { - Process.Start("explorer.exe", Path.Combine(projectDir, "Data", "Python", "Plugins")); + Process.Start("explorer.exe", Path.Combine(projectDir, "Data", "Python", "Plugins")); } } diff --git a/Plugins/RSBot.Python/Views/View.cs b/Plugins/RSBot.Python/Views/View.cs index 2199cde6..37d31153 100644 --- a/Plugins/RSBot.Python/Views/View.cs +++ b/Plugins/RSBot.Python/Views/View.cs @@ -6,4 +6,4 @@ internal class View /// Gets the singleton instance for the Python view. /// public static Main Instance { get; } = new(); -} \ No newline at end of file +} diff --git a/Plugins/RSBot.Quest/QuestPlugin.cs b/Plugins/RSBot.Quest/QuestPlugin.cs index 5eebf2df..14ac2681 100644 --- a/Plugins/RSBot.Quest/QuestPlugin.cs +++ b/Plugins/RSBot.Quest/QuestPlugin.cs @@ -12,10 +12,12 @@ public class QuestPlugin : IPlugin public string InternalName => "RSBot.QuestLog"; public static QuestPlugin Instance { get; private set; } public QuestManager Manager { get; private set; } + public void Initialize() { Instance = this; Manager = new QuestManager(); } + public void OnLoadCharacter() { } } diff --git a/Plugins/RSBot.Quest/QuestView.cs b/Plugins/RSBot.Quest/QuestView.cs index e2c74f0b..15805de4 100644 --- a/Plugins/RSBot.Quest/QuestView.cs +++ b/Plugins/RSBot.Quest/QuestView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Quest { @@ -13,6 +13,7 @@ public class QuestView : IPluginView public int Index => 0; public bool RequireIngame => true; public Control View => Views.View.Main; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Plugins/RSBot.Quest/RSBot.Quest.csproj b/Plugins/RSBot.Quest/RSBot.Quest.csproj index e197df0d..61a018a2 100644 --- a/Plugins/RSBot.Quest/RSBot.Quest.csproj +++ b/Plugins/RSBot.Quest/RSBot.Quest.csproj @@ -25,4 +25,3 @@ - diff --git a/Plugins/RSBot.Quest/Views/Main.cs b/Plugins/RSBot.Quest/Views/Main.cs index ea88c7d1..6610eb32 100644 --- a/Plugins/RSBot.Quest/Views/Main.cs +++ b/Plugins/RSBot.Quest/Views/Main.cs @@ -1,13 +1,13 @@ -using RSBot.Core; +using System; +using System.ComponentModel; +using System.Linq; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Event; using RSBot.Core.Objects.Quests; using RSBot.Quest.Views.Sidebar; using SDUI; using SDUI.Controls; -using System; -using System.ComponentModel; -using System.Linq; -using System.Windows.Forms; namespace RSBot.Quest.Views; diff --git a/Plugins/RSBot.ServerInfo/RSBot.ServerInfo.csproj b/Plugins/RSBot.ServerInfo/RSBot.ServerInfo.csproj index 9b6eb4be..a000be4e 100644 --- a/Plugins/RSBot.ServerInfo/RSBot.ServerInfo.csproj +++ b/Plugins/RSBot.ServerInfo/RSBot.ServerInfo.csproj @@ -20,4 +20,3 @@ - diff --git a/Plugins/RSBot.ServerInfo/ServerInfoManager.cs b/Plugins/RSBot.ServerInfo/ServerInfoManager.cs index f74db6de..1ae72e8d 100644 --- a/Plugins/RSBot.ServerInfo/ServerInfoManager.cs +++ b/Plugins/RSBot.ServerInfo/ServerInfoManager.cs @@ -1,6 +1,6 @@ -using RSBot.General.Components; +using System.Collections.Generic; +using RSBot.General.Components; using RSBot.General.Models; -using System.Collections.Generic; namespace RSBot.ServerInfo { diff --git a/Plugins/RSBot.ServerInfo/ServerInfoPlugin.cs b/Plugins/RSBot.ServerInfo/ServerInfoPlugin.cs index 48139ea2..fdb4783c 100644 --- a/Plugins/RSBot.ServerInfo/ServerInfoPlugin.cs +++ b/Plugins/RSBot.ServerInfo/ServerInfoPlugin.cs @@ -6,9 +6,11 @@ namespace RSBot.ServerInfo; public class ServerInfoPlugin : IPlugin { public string InternalName => "RSBot.ServerInfo"; + public void Initialize() { Log.Notify("[Server Information] Plugin initialized!"); } + public void OnLoadCharacter() { } } diff --git a/Plugins/RSBot.ServerInfo/ServerInfoView.cs b/Plugins/RSBot.ServerInfo/ServerInfoView.cs index d73dab30..8c146c55 100644 --- a/Plugins/RSBot.ServerInfo/ServerInfoView.cs +++ b/Plugins/RSBot.ServerInfo/ServerInfoView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.ServerInfo { @@ -13,6 +13,7 @@ public class ServerInfoView : IPluginView public int Index => 100; public bool RequireIngame => false; public Control View => Views.View.Main; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Plugins/RSBot.ServerInfo/Views/Main.cs b/Plugins/RSBot.ServerInfo/Views/Main.cs index fbcab868..046ddbbf 100644 --- a/Plugins/RSBot.ServerInfo/Views/Main.cs +++ b/Plugins/RSBot.ServerInfo/Views/Main.cs @@ -15,10 +15,12 @@ public Main() SubscribeEvents(); UpdateServerInfo(); } + private void SubscribeEvents() { EventManager.SubscribeEvent("OnServerListUpdated", UpdateServerInfo); } + private void UpdateServerInfo() { if (this.InvokeRequired) diff --git a/Plugins/RSBot.Skills/RSBot.Skills.csproj b/Plugins/RSBot.Skills/RSBot.Skills.csproj index 79f1126a..1141110b 100644 --- a/Plugins/RSBot.Skills/RSBot.Skills.csproj +++ b/Plugins/RSBot.Skills/RSBot.Skills.csproj @@ -19,4 +19,3 @@ - diff --git a/Plugins/RSBot.Skills/SkillsManager.cs b/Plugins/RSBot.Skills/SkillsManager.cs index 216c4c6f..4687643b 100644 --- a/Plugins/RSBot.Skills/SkillsManager.cs +++ b/Plugins/RSBot.Skills/SkillsManager.cs @@ -1,13 +1,13 @@ -using RSBot.Core; +using System; +using System.Linq; +using System.Threading; +using RSBot.Core; using RSBot.Core.Client.ReferenceObjects; using RSBot.Core.Components; using RSBot.Core.Event; using RSBot.Core.Objects; using RSBot.Core.Objects.Skill; using RSBot.Skills.Components; -using System; -using System.Linq; -using System.Threading; namespace RSBot.Skills { @@ -20,6 +20,7 @@ public SkillsManager() { SubscribeEvents(); } + private void SubscribeEvents() { EventManager.SubscribeEvent("OnLoadCharacter", OnLoadCharacter); @@ -30,6 +31,7 @@ private void SubscribeEvents() EventManager.SubscribeEvent("OnResurrectionRequest", OnResurrectionRequest); EventManager.SubscribeEvent("OnExpSpUpdate", OnSpUpdated); } + #region Events /// /// Main_s the on load character. @@ -39,24 +41,28 @@ private void OnLoadCharacter() ApplyAttackSkills(); ApplyBuffSkills(); } + private void OnSkillUpgraded(SkillInfo oldSkill, SkillInfo newSkill) { Log.NotifyLang("SkillUpgraded", newSkill); CheckSkillWithdrawnOrUpgraded(oldSkill, newSkill); } + private void OnWithdrawSkill(SkillInfo oldSkill, SkillInfo newSkill) { Log.NotifyLang("SkillWithdrawn", oldSkill); CheckSkillWithdrawnOrUpgraded(oldSkill, newSkill); } + private void OnResurrectionRequest() { const string key = "RSBot.Skills."; if (Game.AcceptanceRequest != null && PlayerConfig.Get(key + "checkAcceptResurrection")) Game.AcceptanceRequest.Accept(); } + /// /// Will be triggered if EXP/SP were gained. Increases the selected mastery level (if available) /// @@ -76,9 +82,10 @@ private void OnSpUpdated() UpdateMastery(mastery.Level, mastery.Record, gap); } #endregion - public void UpdateMastery(byte level, RefSkillMastery record,decimal gap = 0) + public void UpdateMastery(byte level, RefSkillMastery record, decimal gap = 0) { - if (_isUpdatingMastery) return; + if (_isUpdatingMastery) + return; while (level + gap < Game.Player.Level) { _isUpdatingMastery = true; @@ -99,6 +106,7 @@ public void UpdateMastery(byte level, RefSkillMastery record,decimal gap = 0) } _isUpdatingMastery = false; } + /// /// Applies the attack skills. /// @@ -153,6 +161,7 @@ public static void ApplyAttackSkills() } } } + /// /// Applies the buff skills. /// @@ -175,10 +184,12 @@ public static void ApplyBuffSkills() SkillManager.Buffs.Add(skillInfo); } } + public static void SaveSkills(string monsterType, uint[] skills) { PlayerConfig.SetArray(monsterType, skills); } + public static void CheckSkillWithdrawnOrUpgraded(SkillInfo oldSkill, SkillInfo newSkill) { for (var i = 0; i < _numMonsterTypes; i++) @@ -247,20 +258,24 @@ public static void CheckSkillWithdrawnOrUpgraded(SkillInfo oldSkill, SkillInfo n PlayerConfig.Save(); } + public static void SetImbueSkill(SkillInfo imbue) { SkillManager.ImbueSkill = imbue; PlayerConfig.Set("RSBot.Skills.Imbue", imbue == null ? 0 : imbue.Id); } + public static void SetResurrectionSkill(SkillInfo skill) { SkillManager.ResurrectionSkill = skill; PlayerConfig.Set("RSBot.Skills.ResurrectionSkill", skill == null ? 0 : skill.Id); } + public static void SetMasteryToLearn(string mastery) { PlayerConfig.Set("RSBot.Skills.selectedMastery", mastery); } + public static void SetTeleportSkill(uint skillId) { PlayerConfig.Set("RSBot.Skills.TeleportSkill", skillId); diff --git a/Plugins/RSBot.Skills/SkillsPlugin.cs b/Plugins/RSBot.Skills/SkillsPlugin.cs index 567759f5..cf7e703b 100644 --- a/Plugins/RSBot.Skills/SkillsPlugin.cs +++ b/Plugins/RSBot.Skills/SkillsPlugin.cs @@ -1,5 +1,4 @@ - -using RSBot.Core.Plugins; +using RSBot.Core.Plugins; using RSBot.Skills.Subscriber; namespace RSBot.Skills @@ -9,12 +8,14 @@ public class SkillsPlugin : IPlugin public string InternalName => "RSBot.Skills"; public static SkillsPlugin Instance { get; private set; } public SkillsManager Manager { get; private set; } + public void Initialize() { Instance = this; Manager = new SkillsManager(); LoadCharacterSubscriber.SubscribeEvents(); } - public void OnLoadCharacter() {} + + public void OnLoadCharacter() { } } } diff --git a/Plugins/RSBot.Skills/SkillsView.cs b/Plugins/RSBot.Skills/SkillsView.cs index 1eb3c186..403ccf7d 100644 --- a/Plugins/RSBot.Skills/SkillsView.cs +++ b/Plugins/RSBot.Skills/SkillsView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Skills { @@ -13,6 +13,7 @@ public class SkillsView : IPluginView public int Index => 1; public bool RequireIngame => true; public Control View => Views.View.Instance; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); diff --git a/Plugins/RSBot.Skills/Views/Main.cs b/Plugins/RSBot.Skills/Views/Main.cs index 26c7edc4..740363f1 100644 --- a/Plugins/RSBot.Skills/Views/Main.cs +++ b/Plugins/RSBot.Skills/Views/Main.cs @@ -1,3 +1,7 @@ +using System; +using System.ComponentModel; +using System.Linq; +using System.Windows.Forms; using RSBot.Core; using RSBot.Core.Client.ReferenceObjects; using RSBot.Core.Components; @@ -6,10 +10,6 @@ using RSBot.Core.Objects; using RSBot.Core.Objects.Skill; using SDUI.Controls; -using System; -using System.ComponentModel; -using System.Linq; -using System.Windows.Forms; using CheckBox = SDUI.Controls.CheckBox; using ListViewExtensions = RSBot.Core.Extensions.ListViewExtensions; @@ -102,8 +102,6 @@ private void OnAddItemPerk(uint targetId, uint token) item.LoadSkillImage(); } - - /// /// Loads the settings. /// @@ -555,7 +553,7 @@ private void OnSkillUpgraded(SkillInfo oldSkill, SkillInfo newSkill) { if (this.InvokeRequired) { - this.Invoke(new Action(OnSkillUpgraded), oldSkill, newSkill); + this.Invoke(new Action(OnSkillUpgraded), oldSkill, newSkill); return; } LoadSkills(); diff --git a/Plugins/RSBot.Statistics/RSBot.Statistics.csproj b/Plugins/RSBot.Statistics/RSBot.Statistics.csproj index 79f1126a..1141110b 100644 --- a/Plugins/RSBot.Statistics/RSBot.Statistics.csproj +++ b/Plugins/RSBot.Statistics/RSBot.Statistics.csproj @@ -19,4 +19,3 @@ - diff --git a/Plugins/RSBot.Statistics/StatisticsManager.cs b/Plugins/RSBot.Statistics/StatisticsManager.cs index 5dd6774f..372b5d03 100644 --- a/Plugins/RSBot.Statistics/StatisticsManager.cs +++ b/Plugins/RSBot.Statistics/StatisticsManager.cs @@ -1,6 +1,4 @@ namespace RSBot.Statistics { - public class StatisticsManager - { - } + public class StatisticsManager { } } diff --git a/Plugins/RSBot.Statistics/StatisticsPlugin.cs b/Plugins/RSBot.Statistics/StatisticsPlugin.cs index 924ca1f8..baa4fa30 100644 --- a/Plugins/RSBot.Statistics/StatisticsPlugin.cs +++ b/Plugins/RSBot.Statistics/StatisticsPlugin.cs @@ -6,10 +6,12 @@ namespace RSBot.Statistics public class StatisticsPlugin : IPlugin { public string InternalName => "RSBot.Statistics"; + public void Initialize() { CalculatorRegistry.Initialize(); } + public void OnLoadCharacter() { } } } diff --git a/Plugins/RSBot.Statistics/StatisticsView.cs b/Plugins/RSBot.Statistics/StatisticsView.cs index e64a2520..2b024459 100644 --- a/Plugins/RSBot.Statistics/StatisticsView.cs +++ b/Plugins/RSBot.Statistics/StatisticsView.cs @@ -1,7 +1,7 @@ -using RSBot.Core; +using System.Windows.Forms; +using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Plugins; -using System.Windows.Forms; namespace RSBot.Statistics { @@ -13,6 +13,7 @@ public class StatisticsView : IPluginView public int Index => 97; public bool RequireIngame => true; public Control View => Views.View.Instance; + public void Translate() { LanguageManager.Translate(View, Kernel.Language); From b28bd1e10357a2b750384bda861809dbc17a7928 Mon Sep 17 00:00:00 2001 From: Egezenn Date: Fri, 5 Jun 2026 11:03:07 +0300 Subject: [PATCH 4/4] Update SDUI submodule reference --- SDUI | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SDUI b/SDUI index 76ac9e9c..a965d194 160000 --- a/SDUI +++ b/SDUI @@ -1 +1 @@ -Subproject commit 76ac9e9c4629695844df0cedc91a5e4caf55792b +Subproject commit a965d1943ba19e66171d82bab507f788f8d13f72