Skip to content

Commit

Permalink
Moved battle.net parsers to separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
Shauren committed Oct 7, 2015
1 parent 5cb3223 commit 3716bc9
Show file tree
Hide file tree
Showing 30 changed files with 997 additions and 523 deletions.
6 changes: 6 additions & 0 deletions WowPacketParser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{597FD2
.nuget\NuGet.targets = .nuget\NuGet.targets
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WowPacketParserModule.BattleNetV37165", "WowPacketParserModule.BattleNet.V37165\WowPacketParserModule.BattleNetV37165.csproj", "{61D9896F-2192-4D82-B9B2-71D4AFF431A2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -86,6 +88,10 @@ Global
{63484313-34D2-4133-B157-A19D12B69D9B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{63484313-34D2-4133-B157-A19D12B69D9B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{63484313-34D2-4133-B157-A19D12B69D9B}.Release|Any CPU.Build.0 = Release|Any CPU
{61D9896F-2192-4D82-B9B2-71D4AFF431A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61D9896F-2192-4D82-B9B2-71D4AFF431A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61D9896F-2192-4D82-B9B2-71D4AFF431A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61D9896F-2192-4D82-B9B2-71D4AFF431A2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion WowPacketParser/Enums/Battlenet/BattlenetChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public enum BattlenetChannel : byte
Authentication = 0,
Connection = 1,
WoWRealm = 2,
Friend = 3,
Friends = 3,
Presence = 4,
Chat = 5,
Support = 7,
Expand Down
119 changes: 0 additions & 119 deletions WowPacketParser/Enums/Battlenet/BattlenetOpcode.cs

This file was deleted.

129 changes: 129 additions & 0 deletions WowPacketParser/Enums/Battlenet/Command.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
namespace WowPacketParser.Enums.Battlenet
{
public enum AuthenticationClientCommand : ushort
{
LogonRequest = 0,
ResumeRequest = 1,
ProofResponse = 2,
GenerateSingleSignOnTokenRequest2 = 8,
LogonRequest3 = 9,
SingleSignOnRequest3 = 10
}

public enum AuthenticationServerCommand : ushort
{
LogonResponse3 = 0,
ResumeResponse = 1,
ProofRequest = 2,
Patch = 3,
AuthorizedLicenses = 4,
GenerateSingleSignOnTokenResponse2 = 8
}

public enum ConnectionClientCommand : ushort
{
Ping = 0,
EnableEncyption = 5,
LogoutRequest = 6,
DisconnectRequest = 7,
ConnectionClosing = 9
}

public enum ConnectionServerCommand : ushort
{
Pong = 0,
Boom = 1,
RegulatorUpdate = 2,
ServerVersion = 3,
STUNServers = 4
}

public enum WoWRealmClientCommand : ushort
{
ListSubscribeRequest = 0,
ListUnsubscribe = 1,
JoinRequestV2 = 8,
MultiLogonRequestV2 = 9
}

public enum WoWRealmServerCommand : ushort
{
ListSubscribeResponse = 0,
ListUpdate = 2,
ListComplete = 3,
ToonReady = 6,
ToonLoggedOut = 7,
JoinResponseV2 = 8
}

public enum FriendsClientCommand : ushort
{
}

public enum FriendsServerCommand : ushort
{
}

public enum PresenceClientCommand : ushort
{
}

public enum PresenceServerCommand : ushort
{
}

public enum ChatClientCommand : ushort
{
}

public enum ChatServerCommand : ushort
{
}

public enum SupportClientCommand : ushort
{
}

public enum SupportServerCommand : ushort
{
}

public enum AchievementClientCommand : ushort
{
}

public enum AchievementServerCommand : ushort
{
}

public enum CacheClientCommand : ushort
{
GatewayLookupRequest = 2,
ConnectRequest = 4,
DataChunk = 7,
GetStreamItemsRequest = 9
}

public enum CacheServerCommand : ushort
{
GatewayLookupResponse = 3,
ConnectResponse = 4,
PublishListResponse = 7,
Result = 8,
GetStreamItemsResponse = 9,
GetConfigHandleResponse = 10
}

public enum ProfileClientCommand : ushort
{
}

public enum ProfileServerCommand : ushort
{
ReadResponse = 0,
AddressQueryResponse = 1,
ResolveToonHandleToNameResponse = 2,
ResolveToonNameToHandleResponse = 3,
SettingsAvailable = 4,
}
}
4 changes: 4 additions & 0 deletions WowPacketParser/Enums/ClientVersionBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public enum ClientVersionBuild
V6_2_0_20338 = 20338,
V6_2_2_20444 = 20444,
V6_2_2a_20490 = 20490,

// Battle.net - should probably not mix this but oh well
BattleNetV37165 = 37165,

// ReSharper restore InconsistentNaming
}
}
61 changes: 6 additions & 55 deletions WowPacketParser/Misc/BattlenetPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public BattlenetPacket(Packet packet)
Header.Direction = packet.Direction;
}

public string GetHeader()
public string GetHeader(string packetName)
{
return string.Format("{0}: {1} (0x{2}) Channel: {3} Length: {4} Time: {5} Number: {6}",
Stream.Direction, BattlenetOpcodeName.GetName(Header.Opcode, (byte)Header.Channel, Stream.Direction), Header.Opcode.ToString("X2"), Header.Channel,
Stream.Direction, packetName, Header.Opcode.ToString("X2"), Header.Channel,
Stream.Length, Stream.Time.ToString("MM/dd/yyyy HH:mm:ss.fff"),
Stream.Number);
}
Expand Down Expand Up @@ -69,55 +69,6 @@ public byte[] ReadBytes(string name, int length, params object[] indexes)
return value;
}

public T Read<T>()
{
var type = typeof(T).IsEnum ? typeof(T).GetEnumUnderlyingType() : typeof(T);
object value;
switch (Type.GetTypeCode(type))
{
case TypeCode.Boolean:
value = Stream.ReadBoolean();
break;
case TypeCode.SByte:
value = Stream.ReadSByte();
break;
case TypeCode.Byte:
value = Stream.ReadByte();
break;
case TypeCode.Char:
value = Stream.ReadChar();
break;
case TypeCode.Int16:
value = Stream.ReadInt16();
break;
case TypeCode.UInt16:
value = Stream.ReadUInt16();
break;
case TypeCode.Int32:
value = Stream.ReadInt32();
break;
case TypeCode.UInt32:
value = Stream.ReadUInt32();
break;
case TypeCode.Int64:
value = Stream.ReadInt64();
break;
case TypeCode.UInt64:
value = Stream.ReadUInt64();
break;
case TypeCode.Single:
value = Stream.ReadSingle();
break;
case TypeCode.Double:
value = Stream.ReadDouble();
break;
default:
throw new InvalidCastException("");
}

return (T)value;
}

public byte[] ReadBytes(int count)
{
_count = 0;
Expand All @@ -132,6 +83,7 @@ public string ReadString(int count)
return Encoding.UTF8.GetString(ReadBytes(count));
}

// TODO: Add "minValue" parameter, return value + minValue, needed for proper enum decoding
public T Read<T>(int bits)
{
ulong value = 0;
Expand All @@ -140,9 +92,8 @@ public T Read<T>(int bits)
{
if ((_count % 8) == 0)
{
_bytePart = Read<byte>();

ProcessedBytes += 1;
_bytePart = Stream.ReadByte();
++ProcessedBytes;
}

var shiftedBits = _count & 7;
Expand All @@ -159,7 +110,7 @@ public T Read<T>(int bits)
_count += bitsToRead;
}

return (T)Convert.ChangeType(value, typeof(T));
return (T)Convert.ChangeType(value, typeof(T).IsEnum ? typeof(T).GetEnumUnderlyingType() : typeof(T));
}

public string ReadFourCC()
Expand Down
1 change: 1 addition & 0 deletions WowPacketParser/Misc/ClientVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public static void SetVersion(ClientVersionBuild version)
Trace.WriteLine($"Loading module WowPacketParserModule.{VersionDefiningBuild}.dll");

Handler.LoadHandlers(asm, VersionDefiningBuild);
Handler.LoadBattlenetHandlers(asm);

// This is a huge hack to handle the abnormal situation that appeared with builds 6.0 and 6.1 having mostly the same packet structures
if (!UpdateFields.LoadUFDictionaries(asm, version))
Expand Down
Loading

0 comments on commit 3716bc9

Please sign in to comment.