From 35fb79196dfeaab433a191e822bc444a5b1e6e71 Mon Sep 17 00:00:00 2001 From: Mahmut YILDIRIM Date: Sun, 23 Jul 2023 20:40:43 +0300 Subject: [PATCH] Added support for VTC-Game (#678) --- .../RSBot/Views/SplashScreen.Designer.cs | 4 +-- .../CreateTrainingAreaDialog.Designer.cs | 2 -- .../RSBot.Core/Components/ClientManager.cs | 34 ++++++++++++++----- .../RSBot.Core/Extensions/PacketExtensions.cs | 1 + Library/RSBot.Core/GameClientType.cs | 1 + .../Character/CharacterDataEndResponse.cs | 6 +++- .../Hooks/Agent/Inventory/BuyItemHook.cs | 1 + Library/RSBot.Core/Objects/Action.cs | 13 +++---- .../Objects/Inventory/InventoryItem.cs | 1 + Library/RSBot.Core/Objects/NpcTalk.cs | 3 +- Plugins/RSBot.General/Components/AutoLogin.cs | 4 ++- .../PacketHandler/AgentLoginRequestHook.cs | 3 +- .../PacketHandler/GatewayLoginRequest.cs | 3 +- .../GatewayServerListResponse.cs | 8 ++++- .../GlobalIdentificationRequest.cs | 3 +- 15 files changed, 62 insertions(+), 25 deletions(-) diff --git a/Application/RSBot/Views/SplashScreen.Designer.cs b/Application/RSBot/Views/SplashScreen.Designer.cs index e3d49c13..d22536a0 100644 --- a/Application/RSBot/Views/SplashScreen.Designer.cs +++ b/Application/RSBot/Views/SplashScreen.Designer.cs @@ -98,7 +98,7 @@ private void InitializeComponent() label2.ForeColor = System.Drawing.Color.FromArgb(0, 0, 0); label2.Gradient = new System.Drawing.Color[] { System.Drawing.Color.RosyBrown, System.Drawing.Color.FromArgb(74, 74, 74) }; label2.GradientAnimation = false; - label2.Location = new System.Drawing.Point(144, 282); + label2.Location = new System.Drawing.Point(140, 282); label2.Name = "label2"; label2.Size = new System.Drawing.Size(271, 17); label2.TabIndex = 5; @@ -115,7 +115,7 @@ private void InitializeComponent() label3.ForeColor = System.Drawing.Color.FromArgb(0, 0, 0); label3.Gradient = new System.Drawing.Color[] { System.Drawing.Color.Gray, System.Drawing.Color.Black }; label3.GradientAnimation = false; - label3.Location = new System.Drawing.Point(161, 314); + label3.Location = new System.Drawing.Point(144, 314); label3.Name = "label3"; label3.Size = new System.Drawing.Size(254, 15); label3.TabIndex = 5; diff --git a/Botbases/RSBot.Default/Views/Dialogs/CreateTrainingAreaDialog.Designer.cs b/Botbases/RSBot.Default/Views/Dialogs/CreateTrainingAreaDialog.Designer.cs index 2f385d0c..8c2be08b 100644 --- a/Botbases/RSBot.Default/Views/Dialogs/CreateTrainingAreaDialog.Designer.cs +++ b/Botbases/RSBot.Default/Views/Dialogs/CreateTrainingAreaDialog.Designer.cs @@ -41,7 +41,6 @@ private void InitializeComponent() this.bottomPanel = new SDUI.Controls.Panel(); this.panel1 = new System.Windows.Forms.Panel(); this.panel2 = new System.Windows.Forms.Panel(); - ((System.ComponentModel.ISupportInitialize)(this.Radius)).BeginInit(); this.bottomPanel.SuspendLayout(); this.panel1.SuspendLayout(); this.panel2.SuspendLayout(); @@ -229,7 +228,6 @@ private void InitializeComponent() this.Text = "Create training area"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.CreateTrainingAreaDialog_FormClosing); this.Load += new System.EventHandler(this.CreateTrainingAreaDialog_Load); - ((System.ComponentModel.ISupportInitialize)(this.Radius)).EndInit(); this.bottomPanel.ResumeLayout(false); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); diff --git a/Library/RSBot.Core/Components/ClientManager.cs b/Library/RSBot.Core/Components/ClientManager.cs index 0c291921..89e4b3f6 100644 --- a/Library/RSBot.Core/Components/ClientManager.cs +++ b/Library/RSBot.Core/Components/ClientManager.cs @@ -81,25 +81,43 @@ public static async Task Start() if (process == null || process.HasExited) return false; - if (Game.ClientType == GameClientType.Turkey) + var isVtcGame = Game.ClientType == GameClientType.VTC_Game; + if (Game.ClientType == GameClientType.Turkey || + isVtcGame) { var moduleMemory = new byte[process.MainModule.ModuleMemorySize]; ReadProcessMemory(process.Handle, process.MainModule.BaseAddress, moduleMemory, process.MainModule.ModuleMemorySize, out _); - var patchNop = new byte[] { 0x90, 0x90 }; + var pattern = !isVtcGame ? + "6A 00 6A 00 FF D6 6A 00 8D 85" : + "6A 00 68 D8 15 26 01 68 E4"; + + var patchNop = new byte[] { 0x90, 0x90 }; + var patchNop2 = new byte[] { 0x90, 0x90, 0x90, 0x90, 0x90 }; var patchJmp = new byte[] { 0xEB }; - var address = FindPattern("6A 00 6A 00 FF D6 6A 00 8D 85", moduleMemory); + var address = FindPattern(pattern, moduleMemory); if (address == IntPtr.Zero) { - Log.Error($"TRSRO XIGNCODE patching error! Maybe signatures are wrong?"); + Log.Error($"XIGNCODE patching error! Maybe signatures are wrong?"); return false; } - WriteProcessMemory(pi.hProcess, address - 0x15, patchNop, 2, out _); - WriteProcessMemory(pi.hProcess, address + 0x04, patchNop, 2, out _); - WriteProcessMemory(pi.hProcess, address + 0x1D, patchJmp, 1, out _); - WriteProcessMemory(pi.hProcess, address + 0x9A, patchJmp, 1, out _); + if(!isVtcGame) + { + WriteProcessMemory(pi.hProcess, address - 0x15, patchNop, 2, out _); + WriteProcessMemory(pi.hProcess, address + 0x04, patchNop, 2, out _); + WriteProcessMemory(pi.hProcess, address + 0x1D, patchJmp, 1, out _); + WriteProcessMemory(pi.hProcess, address + 0x9A, patchJmp, 1, out _); + } + else + { + WriteProcessMemory(pi.hProcess, address - 0x6A, patchJmp, 1, out _); + WriteProcessMemory(pi.hProcess, address + 0xC, patchNop2, 5, out _); + WriteProcessMemory(pi.hProcess, address + 0x13, patchJmp, 1, out _); + WriteProcessMemory(pi.hProcess, address + 0x90, patchJmp, 1, out _); + } + moduleMemory = null; GC.Collect(); diff --git a/Library/RSBot.Core/Extensions/PacketExtensions.cs b/Library/RSBot.Core/Extensions/PacketExtensions.cs index a29cf7ed..233c77d6 100644 --- a/Library/RSBot.Core/Extensions/PacketExtensions.cs +++ b/Library/RSBot.Core/Extensions/PacketExtensions.cs @@ -18,6 +18,7 @@ public static string ReadConditonalString(this Packet packet) case GameClientType.Turkey: case GameClientType.Korean: case GameClientType.Rigid: + case GameClientType.VTC_Game: return packet.ReadUnicode(); default: diff --git a/Library/RSBot.Core/GameClientType.cs b/Library/RSBot.Core/GameClientType.cs index 1d4d3544..842c11ad 100644 --- a/Library/RSBot.Core/GameClientType.cs +++ b/Library/RSBot.Core/GameClientType.cs @@ -11,6 +11,7 @@ public enum GameClientType : byte Chinese, Global, Turkey, + VTC_Game, Korean, Rigid } diff --git a/Library/RSBot.Core/Network/Handler/Agent/Character/CharacterDataEndResponse.cs b/Library/RSBot.Core/Network/Handler/Agent/Character/CharacterDataEndResponse.cs index c842ddc0..a9f6ee9c 100644 --- a/Library/RSBot.Core/Network/Handler/Agent/Character/CharacterDataEndResponse.cs +++ b/Library/RSBot.Core/Network/Handler/Agent/Character/CharacterDataEndResponse.cs @@ -74,12 +74,16 @@ public void Invoke(Packet packet) packet.ReadUInt(); packet.ReadByte(); - if (Game.ClientType == GameClientType.Turkey) + if (Game.ClientType == GameClientType.Turkey || + Game.ClientType == GameClientType.VTC_Game) packet.ReadUInt(); if (Game.ClientType == GameClientType.Rigid) packet.ReadByteArray(12); + if (Game.ClientType == GameClientType.VTC_Game) + packet.ReadByte(); // ?? + var serverCap = packet.ReadByte(); Log.Notify($"The game server cap is {serverCap}!"); diff --git a/Library/RSBot.Core/Network/Hooks/Agent/Inventory/BuyItemHook.cs b/Library/RSBot.Core/Network/Hooks/Agent/Inventory/BuyItemHook.cs index b568b725..78d42c78 100644 --- a/Library/RSBot.Core/Network/Hooks/Agent/Inventory/BuyItemHook.cs +++ b/Library/RSBot.Core/Network/Hooks/Agent/Inventory/BuyItemHook.cs @@ -134,6 +134,7 @@ public Packet ReplacePacket(Packet packet) case GameClientType.Rigid: bindingCount = 4; break; + case GameClientType.VTC_Game: case GameClientType.Korean: bindingCount = 3; break; diff --git a/Library/RSBot.Core/Objects/Action.cs b/Library/RSBot.Core/Objects/Action.cs index fbaf139c..f5b020cc 100644 --- a/Library/RSBot.Core/Objects/Action.cs +++ b/Library/RSBot.Core/Objects/Action.cs @@ -106,7 +106,8 @@ public static Action DeserializeBegin(Packet packet) action.TargetId = packet.ReadUInt(); if (Game.ClientType == GameClientType.Turkey || - Game.ClientType == GameClientType.Global) + Game.ClientType == GameClientType.Global || + Game.ClientType == GameClientType.VTC_Game) { packet.ReadByte(); action.Flag = (ActionStateFlag)packet.ReadByte(); @@ -126,7 +127,7 @@ public static Action DeserializeBegin(Packet packet) action.Flag = (ActionStateFlag)packet.ReadByte();*/ action.SerializeDetail(packet); - if(action.TargetId != 0) + if (action.TargetId != 0) EventManager.FireEvent("OnEntityHit", action.Id, action.ExecutorId, action.TargetId, 0, false); return action; @@ -179,10 +180,10 @@ public void SerializeDetail(Packet packet) { var critStatus = packet.ReadByte(); // 0x01: normal 0x02 critical - var damage = BitConverter.ToInt32(new byte[] { - packet.ReadByte(), - packet.ReadByte(), - packet.ReadByte(), + var damage = BitConverter.ToInt32(new byte[] { + packet.ReadByte(), + packet.ReadByte(), + packet.ReadByte(), 0 }, 0); diff --git a/Library/RSBot.Core/Objects/Inventory/InventoryItem.cs b/Library/RSBot.Core/Objects/Inventory/InventoryItem.cs index fc514207..94889feb 100644 --- a/Library/RSBot.Core/Objects/Inventory/InventoryItem.cs +++ b/Library/RSBot.Core/Objects/Inventory/InventoryItem.cs @@ -321,6 +321,7 @@ public static InventoryItem FromPacket(Packet packet, byte destinationSlot = 0xF case GameClientType.Rigid: bindingCount = 4; break; + case GameClientType.VTC_Game: case GameClientType.Korean: bindingCount = 3; break; diff --git a/Library/RSBot.Core/Objects/NpcTalk.cs b/Library/RSBot.Core/Objects/NpcTalk.cs index 495bcb1d..733960e4 100644 --- a/Library/RSBot.Core/Objects/NpcTalk.cs +++ b/Library/RSBot.Core/Objects/NpcTalk.cs @@ -35,7 +35,8 @@ public void Deserialize(Packet packet) count = packet.ReadByte(); if (Game.ClientType == GameClientType.Global || - Game.ClientType == GameClientType.Turkey) + Game.ClientType == GameClientType.Turkey || + Game.ClientType == GameClientType.VTC_Game) count = 7; Options = packet.ReadByteArray(count); diff --git a/Plugins/RSBot.General/Components/AutoLogin.cs b/Plugins/RSBot.General/Components/AutoLogin.cs index 41c06216..7f015fdf 100644 --- a/Plugins/RSBot.General/Components/AutoLogin.cs +++ b/Plugins/RSBot.General/Components/AutoLogin.cs @@ -1,6 +1,7 @@ using RSBot.Core; using RSBot.Core.Components; using RSBot.Core.Event; +using RSBot.Core.Extensions; using RSBot.Core.Network; using RSBot.Core.Network.SecurityAPI; using RSBot.General.Models; @@ -140,7 +141,8 @@ private static void SendLoginRequest(Account account, Models.Server server) loginPacket.WriteString(account.Username); loginPacket.WriteString(account.Password); - if (Game.ClientType == GameClientType.Turkey) + if (Game.ClientType == GameClientType.Turkey || + Game.ClientType == GameClientType.VTC_Game) loginPacket.WriteByteArray(new byte[6]); // mac loginPacket.WriteUShort(server.Id); diff --git a/Plugins/RSBot.General/PacketHandler/AgentLoginRequestHook.cs b/Plugins/RSBot.General/PacketHandler/AgentLoginRequestHook.cs index 0bfefcae..32fdf176 100644 --- a/Plugins/RSBot.General/PacketHandler/AgentLoginRequestHook.cs +++ b/Plugins/RSBot.General/PacketHandler/AgentLoginRequestHook.cs @@ -46,7 +46,8 @@ public Packet ReplacePacket(Packet packet) packet.WriteUInt(Kernel.Proxy.Token); packet.WriteString(selectedAccount.Username); - if(Game.ClientType == GameClientType.Turkey) + if(Game.ClientType == GameClientType.Turkey || + Game.ClientType == GameClientType.VTC_Game) packet.WriteString(Sha256.ComputeHash(selectedAccount.Password)); else packet.WriteString(selectedAccount.Password); diff --git a/Plugins/RSBot.General/PacketHandler/GatewayLoginRequest.cs b/Plugins/RSBot.General/PacketHandler/GatewayLoginRequest.cs index 81884448..cf4615c2 100644 --- a/Plugins/RSBot.General/PacketHandler/GatewayLoginRequest.cs +++ b/Plugins/RSBot.General/PacketHandler/GatewayLoginRequest.cs @@ -33,7 +33,8 @@ public void Invoke(Packet packet) packet.ReadString();//password if (packet.Opcode == 0x610A && - Game.ClientType == GameClientType.Turkey) + Game.ClientType == GameClientType.Turkey || + Game.ClientType == GameClientType.VTC_Game) packet.ReadByteArray(6); var shardId = packet.ReadUShort(); diff --git a/Plugins/RSBot.General/PacketHandler/GatewayServerListResponse.cs b/Plugins/RSBot.General/PacketHandler/GatewayServerListResponse.cs index 15b355c2..f254af51 100644 --- a/Plugins/RSBot.General/PacketHandler/GatewayServerListResponse.cs +++ b/Plugins/RSBot.General/PacketHandler/GatewayServerListResponse.cs @@ -39,7 +39,7 @@ enum ServerStatusModern /// The packet. public void Invoke(Packet packet) { - Serverlist.Servers = new List(); + Serverlist.Servers = new(); while (packet.ReadByte() != 0) { @@ -80,6 +80,12 @@ public void Invoke(Packet packet) serverName = serverName.Remove(0, 3); } + if (Game.ClientType == GameClientType.VTC_Game) + { + if (serverName.EndsWith("Thien_Kim")) + serverName = serverName.Remove(0, 3); + } + Serverlist.Servers.Add(new Server { Id = id, diff --git a/Plugins/RSBot.General/PacketHandler/GlobalIdentificationRequest.cs b/Plugins/RSBot.General/PacketHandler/GlobalIdentificationRequest.cs index 4407d2a4..7e7107f2 100644 --- a/Plugins/RSBot.General/PacketHandler/GlobalIdentificationRequest.cs +++ b/Plugins/RSBot.General/PacketHandler/GlobalIdentificationRequest.cs @@ -60,7 +60,8 @@ public void Invoke(Packet packet) response.WriteUInt(Kernel.Proxy.Token); response.WriteString(selectedAccount.Username); - if(Game.ClientType == GameClientType.Turkey) + if(Game.ClientType == GameClientType.Turkey || + Game.ClientType == GameClientType.VTC_Game) response.WriteString(Sha256.ComputeHash(selectedAccount.Password)); else response.WriteString(selectedAccount.Password);