From 398e5a1d552f3912f60a9f55d5301399d5175935 Mon Sep 17 00:00:00 2001 From: EtienneDesticourt Date: Wed, 23 Dec 2015 01:07:56 +0100 Subject: [PATCH 01/10] Fix friendlist duplicate entries dictionary crash, added packet sniffer hook --- .../Datastructures/Components/FriendList.cs | 10 ++- .../Modification/Hooks/PacketSnifferHook.cs | 71 +++++++++++++++++++ .../Networking/Protocol/AuthServerMessage.cs | 3 + 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs diff --git a/GuildWarsInterface/Datastructures/Components/FriendList.cs b/GuildWarsInterface/Datastructures/Components/FriendList.cs index f7d1a05..6cf0568 100644 --- a/GuildWarsInterface/Datastructures/Components/FriendList.cs +++ b/GuildWarsInterface/Datastructures/Components/FriendList.cs @@ -38,7 +38,14 @@ public void Add(Type type, string baseCharacterName, string currentCharacterName { var newEntry = new Entry(type, baseCharacterName, currentCharacterName, playerStatus, map); - _entries.Add(newEntry.BaseCharacterName, newEntry); + if (!_entries.ContainsKey(newEntry.BaseCharacterName)) + { + _entries.Add(newEntry.BaseCharacterName, newEntry); + } + else + { + _entries[newEntry.BaseCharacterName] = newEntry; + } if (Game.State == GameState.Playing) { @@ -82,6 +89,7 @@ private static void UpdateEntry(Entry entry) { Network.AuthServer.Send(AuthServerMessage.UpdateFriendList, (uint) entry.PlayerStatus, entry.BaseCharacterName, entry.CurrentCharacterName); + //If a map was specified, show it next to name if (entry.Map != 0) { Network.AuthServer.Send(AuthServerMessage.FriendListLocationInfo, (uint) entry.Map, diff --git a/GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs b/GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs new file mode 100644 index 0000000..d85a954 --- /dev/null +++ b/GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs @@ -0,0 +1,71 @@ +using System; +using System.Runtime.InteropServices; +using Binarysharp.Assemblers.Fasm; +using System.IO; +using GuildWarsInterface.Modification.Native; + +namespace GuildWarsInterface.Modification.Hooks +{ + internal class PacketSnifferHook + { + private static HookType _hookDelegate; + private static readonly IntPtr _hookAddress = (IntPtr)0x5900CB; + private const string filePath = @"E:\Users\Etienne2\Desktop\packetlog.txt"; + + public static void Install() + { + + _hookDelegate = Hook; + + IntPtr codeCave = Marshal.AllocHGlobal(128); + + byte[] code = FasmNet.Assemble(new[] + { + "use32", + "org " + codeCave, + "pushad", + "push esi", + "add eax, ebx", + "sub eax, esi", + "push eax", + "call " + Marshal.GetFunctionPointerForDelegate(_hookDelegate), + "popad", + "mov [ecx+4], edi", + "pop ebx", + "mov [ecx], esi", + "jmp " + (_hookAddress + 6) + }); + Marshal.Copy(code, 0, codeCave, code.Length); + + Jump(_hookAddress, codeCave); + } + + private static int Hook(IntPtr buf, int len) + { + byte[] buffer = new byte[len]; + Marshal.Copy(buf, buffer, 0, len); + File.AppendAllText(filePath, BitConverter.ToString(buffer).Replace("-", " ")); + return 0; + } + + private static void Jump(IntPtr from, IntPtr to) + { + byte[] hook = FasmNet.Assemble(new[] + { + "use32", + "org " + from, + "jmp " + to, + "nop" + }); + + uint dwOldProtection; + Kernel32.VirtualProtect(from, 5, 0x40, out dwOldProtection); + Marshal.Copy(hook, 0, from, 5); + Kernel32.VirtualProtect(from, 5, dwOldProtection, out dwOldProtection); + } + + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate int HookType(IntPtr buf, int len); + + } +} \ No newline at end of file diff --git a/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs b/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs index 3f2e3ac..089140d 100644 --- a/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs +++ b/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs @@ -2,12 +2,15 @@ { internal enum AuthServerMessage { + ComputerInfoReply = 1, TransactionSuccessCode = 3, Character = 7, Dispatch = 9, FriendList = 10, UpdateFriendList = 11, + Whisper = 12, + //FriendListEnd = 5120, AccountPermissions = 17, PlayerStatus = 20, Gui = 22, From af15d344bf413999b8f22706b9f666610b85ae93 Mon Sep 17 00:00:00 2001 From: EtienneDesticourt Date: Wed, 23 Dec 2015 16:41:04 +0100 Subject: [PATCH 02/10] Modified packet sniffer hook to take filePath at install --- .../Modification/Hooks/PacketSnifferHook.cs | 9 +++++---- GuildWarsInterface/Networking/Network.cs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs b/GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs index d85a954..cd47524 100644 --- a/GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs +++ b/GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs @@ -3,6 +3,7 @@ using Binarysharp.Assemblers.Fasm; using System.IO; using GuildWarsInterface.Modification.Native; +using GuildWarsInterface.Debugging; namespace GuildWarsInterface.Modification.Hooks { @@ -10,11 +11,11 @@ internal class PacketSnifferHook { private static HookType _hookDelegate; private static readonly IntPtr _hookAddress = (IntPtr)0x5900CB; - private const string filePath = @"E:\Users\Etienne2\Desktop\packetlog.txt"; + private static string _filePath; - public static void Install() + public static void Install(string filePath) { - + _filePath = filePath; _hookDelegate = Hook; IntPtr codeCave = Marshal.AllocHGlobal(128); @@ -44,7 +45,7 @@ private static int Hook(IntPtr buf, int len) { byte[] buffer = new byte[len]; Marshal.Copy(buf, buffer, 0, len); - File.AppendAllText(filePath, BitConverter.ToString(buffer).Replace("-", " ")); + File.AppendAllText(_filePath, BitConverter.ToString(buffer).Replace("-", " ") + " "); return 0; } diff --git a/GuildWarsInterface/Networking/Network.cs b/GuildWarsInterface/Networking/Network.cs index 9d21936..622b830 100644 --- a/GuildWarsInterface/Networking/Network.cs +++ b/GuildWarsInterface/Networking/Network.cs @@ -20,7 +20,7 @@ public static void Initialize() PortPatch.Apply(); DisableEncryptionPatch.Apply(); GetHostByNameHook.Install(); - + //PacketSnifferHook.Install("FILL ME"); GameProtocolHook.Install(gameProtocol => { GameServer.Protocol = new Protocol.Protocol(gameProtocol); From 231f43f5e5fafd16cf87af48b2164047c57bbbff Mon Sep 17 00:00:00 2001 From: EtienneDesticourt Date: Mon, 18 Apr 2016 15:59:57 +0200 Subject: [PATCH 03/10] Removed packet sniffer and erroneous packet id --- .../Modification/Hooks/PacketSnifferHook.cs | 72 ------------------- GuildWarsInterface/Networking/Network.cs | 1 - .../Networking/Protocol/AuthServerMessage.cs | 1 - 3 files changed, 74 deletions(-) delete mode 100644 GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs diff --git a/GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs b/GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs deleted file mode 100644 index cd47524..0000000 --- a/GuildWarsInterface/Modification/Hooks/PacketSnifferHook.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using Binarysharp.Assemblers.Fasm; -using System.IO; -using GuildWarsInterface.Modification.Native; -using GuildWarsInterface.Debugging; - -namespace GuildWarsInterface.Modification.Hooks -{ - internal class PacketSnifferHook - { - private static HookType _hookDelegate; - private static readonly IntPtr _hookAddress = (IntPtr)0x5900CB; - private static string _filePath; - - public static void Install(string filePath) - { - _filePath = filePath; - _hookDelegate = Hook; - - IntPtr codeCave = Marshal.AllocHGlobal(128); - - byte[] code = FasmNet.Assemble(new[] - { - "use32", - "org " + codeCave, - "pushad", - "push esi", - "add eax, ebx", - "sub eax, esi", - "push eax", - "call " + Marshal.GetFunctionPointerForDelegate(_hookDelegate), - "popad", - "mov [ecx+4], edi", - "pop ebx", - "mov [ecx], esi", - "jmp " + (_hookAddress + 6) - }); - Marshal.Copy(code, 0, codeCave, code.Length); - - Jump(_hookAddress, codeCave); - } - - private static int Hook(IntPtr buf, int len) - { - byte[] buffer = new byte[len]; - Marshal.Copy(buf, buffer, 0, len); - File.AppendAllText(_filePath, BitConverter.ToString(buffer).Replace("-", " ") + " "); - return 0; - } - - private static void Jump(IntPtr from, IntPtr to) - { - byte[] hook = FasmNet.Assemble(new[] - { - "use32", - "org " + from, - "jmp " + to, - "nop" - }); - - uint dwOldProtection; - Kernel32.VirtualProtect(from, 5, 0x40, out dwOldProtection); - Marshal.Copy(hook, 0, from, 5); - Kernel32.VirtualProtect(from, 5, dwOldProtection, out dwOldProtection); - } - - [UnmanagedFunctionPointer(CallingConvention.StdCall)] - private delegate int HookType(IntPtr buf, int len); - - } -} \ No newline at end of file diff --git a/GuildWarsInterface/Networking/Network.cs b/GuildWarsInterface/Networking/Network.cs index 622b830..cd25079 100644 --- a/GuildWarsInterface/Networking/Network.cs +++ b/GuildWarsInterface/Networking/Network.cs @@ -20,7 +20,6 @@ public static void Initialize() PortPatch.Apply(); DisableEncryptionPatch.Apply(); GetHostByNameHook.Install(); - //PacketSnifferHook.Install("FILL ME"); GameProtocolHook.Install(gameProtocol => { GameServer.Protocol = new Protocol.Protocol(gameProtocol); diff --git a/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs b/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs index 089140d..2f8096a 100644 --- a/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs +++ b/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs @@ -10,7 +10,6 @@ internal enum AuthServerMessage FriendList = 10, UpdateFriendList = 11, Whisper = 12, - //FriendListEnd = 5120, AccountPermissions = 17, PlayerStatus = 20, Gui = 22, From a9ab82e49282357db20e8a67da35f4a8c2681286 Mon Sep 17 00:00:00 2001 From: EtienneDesticourt Date: Tue, 19 Apr 2016 10:30:24 +0200 Subject: [PATCH 04/10] Readded white space --- GuildWarsInterface/Networking/Network.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GuildWarsInterface/Networking/Network.cs b/GuildWarsInterface/Networking/Network.cs index cd25079..013db68 100644 --- a/GuildWarsInterface/Networking/Network.cs +++ b/GuildWarsInterface/Networking/Network.cs @@ -20,6 +20,7 @@ public static void Initialize() PortPatch.Apply(); DisableEncryptionPatch.Apply(); GetHostByNameHook.Install(); + GameProtocolHook.Install(gameProtocol => { GameServer.Protocol = new Protocol.Protocol(gameProtocol); @@ -31,4 +32,4 @@ public static void Initialize() GameServer.Start(); } } -} \ No newline at end of file +} From bb25cdfd93478a670138da1a26ea0abdc096cf31 Mon Sep 17 00:00:00 2001 From: EtienneDesticourt Date: Tue, 19 Apr 2016 10:33:16 +0200 Subject: [PATCH 05/10] Removed white space --- GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs b/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs index 2f8096a..3428f2f 100644 --- a/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs +++ b/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs @@ -2,7 +2,6 @@ { internal enum AuthServerMessage { - ComputerInfoReply = 1, TransactionSuccessCode = 3, Character = 7, @@ -16,4 +15,4 @@ internal enum AuthServerMessage FriendListLocationInfo = 32, Response53 = 38, } -} \ No newline at end of file +} From 01d57a7ef470220010108a2403e73928790de43b Mon Sep 17 00:00:00 2001 From: EtienneDesticourt Date: Tue, 19 Apr 2016 10:35:12 +0200 Subject: [PATCH 06/10] Removed change not related to friendlist fix --- GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs b/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs index 3428f2f..0a5a003 100644 --- a/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs +++ b/GuildWarsInterface/Networking/Protocol/AuthServerMessage.cs @@ -8,7 +8,6 @@ internal enum AuthServerMessage Dispatch = 9, FriendList = 10, UpdateFriendList = 11, - Whisper = 12, AccountPermissions = 17, PlayerStatus = 20, Gui = 22, From b7f140edbd43cd98df96b35972f2b6ba02421e39 Mon Sep 17 00:00:00 2001 From: EtienneDesticourt Date: Fri, 20 May 2016 12:03:58 +0200 Subject: [PATCH 07/10] Updated fileserver response --- GuildWarsInterface/Networking/Servers/FileServer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/GuildWarsInterface/Networking/Servers/FileServer.cs b/GuildWarsInterface/Networking/Servers/FileServer.cs index cfc8586..23e6589 100644 --- a/GuildWarsInterface/Networking/Servers/FileServer.cs +++ b/GuildWarsInterface/Networking/Servers/FileServer.cs @@ -20,9 +20,9 @@ protected override void Received(byte[] data) Send(new byte[] { 0xF1, 0x02, 0x20, 0x00, 0x6F, 0xC0, 0x05, 0x00, - 0x7E, 0xC9, 0x05, 0x00, 0x9C, 0x43, 0x05, 0x00, - 0x8C, 0xC9, 0x05, 0x00, 0x8D, 0xC9, 0x05, 0x00, - 0x8E, 0xC9, 0x05, 0x00, 0x8B, 0xC9, 0x05, 0x00 + 0xB3, 0xC9, 0x05, 0x00, 0x9C, 0x43, 0x05, 0x00, + 0xB5, 0xC9, 0x05, 0x00, 0xB6, 0xC9, 0x05, 0x00, + 0xB7, 0xC9, 0x05, 0x00, 0xB4, 0xC9, 0x05, 0x00 }); } } From 0a1c265034ff0427df6ea10b82eb3769e3b23fcc Mon Sep 17 00:00:00 2001 From: EtienneDesticourt Date: Fri, 20 May 2016 12:53:00 +0200 Subject: [PATCH 08/10] Update Network.cs --- GuildWarsInterface/Networking/Network.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/GuildWarsInterface/Networking/Network.cs b/GuildWarsInterface/Networking/Network.cs index 013db68..9469aca 100644 --- a/GuildWarsInterface/Networking/Network.cs +++ b/GuildWarsInterface/Networking/Network.cs @@ -20,7 +20,6 @@ public static void Initialize() PortPatch.Apply(); DisableEncryptionPatch.Apply(); GetHostByNameHook.Install(); - GameProtocolHook.Install(gameProtocol => { GameServer.Protocol = new Protocol.Protocol(gameProtocol); From e23b97aa5ffc991e8f9875c4b11e1038c4bdaace Mon Sep 17 00:00:00 2001 From: EtienneDesticourt Date: Fri, 20 May 2016 12:53:49 +0200 Subject: [PATCH 09/10] Update Network.cs --- GuildWarsInterface/Networking/Network.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/GuildWarsInterface/Networking/Network.cs b/GuildWarsInterface/Networking/Network.cs index 9469aca..5c3f3fb 100644 --- a/GuildWarsInterface/Networking/Network.cs +++ b/GuildWarsInterface/Networking/Network.cs @@ -20,6 +20,7 @@ public static void Initialize() PortPatch.Apply(); DisableEncryptionPatch.Apply(); GetHostByNameHook.Install(); + GameProtocolHook.Install(gameProtocol => { GameServer.Protocol = new Protocol.Protocol(gameProtocol); From 2384e6c741d704216cc15bec0f88d40117d3e862 Mon Sep 17 00:00:00 2001 From: EtienneDesticourt Date: Fri, 20 May 2016 12:57:11 +0200 Subject: [PATCH 10/10] Removed newline char