Skip to content

Commit

Permalink
Added support for VTC-Game (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
SDClowen authored Jul 23, 2023
1 parent 444a8d7 commit 35fb791
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 25 deletions.
4 changes: 2 additions & 2 deletions Application/RSBot/Views/SplashScreen.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 26 additions & 8 deletions Library/RSBot.Core/Components/ClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,43 @@ public static async Task<bool> 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();
Expand Down
1 change: 1 addition & 0 deletions Library/RSBot.Core/Extensions/PacketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions Library/RSBot.Core/GameClientType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public enum GameClientType : byte
Chinese,
Global,
Turkey,
VTC_Game,
Korean,
Rigid
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}!");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 7 additions & 6 deletions Library/RSBot.Core/Objects/Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions Library/RSBot.Core/Objects/Inventory/InventoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Library/RSBot.Core/Objects/NpcTalk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion Plugins/RSBot.General/Components/AutoLogin.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion Plugins/RSBot.General/PacketHandler/AgentLoginRequestHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion Plugins/RSBot.General/PacketHandler/GatewayLoginRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enum ServerStatusModern
/// <param name="packet">The packet.</param>
public void Invoke(Packet packet)
{
Serverlist.Servers = new List<Server>();
Serverlist.Servers = new();

while (packet.ReadByte() != 0)
{
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 35fb791

Please sign in to comment.