[Help] Messaging packet version 5630+

02/05/2013 22:22 JobvdH#1
Hello guys,

I need some little help here.
I've been making a server lately and I need the message packet structure for 5630+ versions.

I've tried allot of offsets without any result.

Here is a dump of the packet I send:
[Only registered and activated users can see links. Click Here To Register...]

The structure I currently use:
Code:
            WriteUInt((uint)Color.White.ToArgb(), 4);
            WriteUInt(Type, 8);
            WriteUInt(EntityID, 12);
            WriteByte(4, 24);
            WriteStringWithLength(From, 26);
            WriteStringWithLength(To, 28 + From.Length);
            WriteString("", 0, 29 + From.Length);
            WriteStringWithLength(Message, 31 + (From.Length + To.Length));
I hope someone can help me!

Thanks in advance,
JobvdH!
02/05/2013 22:59 { Angelius }#2
ushort Length = (ushort)(34 + Msg.Length + From.Length + To.Length + Date.Length);

OffsetValue
0 Length
2 1004
4 Color.ToArgb
8 Message Type
12 Message ID
16 Unknown.. at least to me
20 Mesh
24 String count = 4
25 From.Length
26 From as string
26 + From.Length To.Length
27 + From.Length To as string
27 + From.Length + To.Length Date.Length
28 + From.Length + To.Length Date as string
28 + From.Length + To.Length + Date.Length Msg.Length
29 + From.Length + To.Length + Date.Length Msg as string

Good luck.
02/06/2013 17:49 JobvdH#3
Alright thanks for sharing.

I still can't login for some weird reason.
Here is my packet:
Code:
            WriteUInt((uint)Color.White.ToArgb(), 4);
            WriteUInt(Type, 8);
            WriteUInt(EntityID, 12);
            WriteUInt(client.Mesh, 20);
            WriteByte(6, 24);
            WriteStringWithLength(From, 26);
            WriteStringWithLength(To, 27 + From.Length);
            WriteStringWithLength(Date, 28 + From.Length + To.Length);
            WriteStringWithLength(Message, 29 + From.Length + To.Length + Date.Length);
I send the following thing:
Code:
var MessageToSend = new SendChat(client, message, "ALL", "SYSTEM", 2101, response.Identity, DateTime.Now.ToString());
NOTE: I've also triend "ALLUSERS", that didn't work too.

And here is the dump of the packet which I send:
[Only registered and activated users can see links. Click Here To Register...]

I hope you can help me.

PS: I've upgraded to the latest patch (5699), it didn't work on 5630 too)

Thanks in advance,
JobvdH!
02/06/2013 19:50 nTL3fTy#4
I'm not quite sure where you got this idea that there's 6 strings in the list, but I just logged these from the latest patch:

Code:
MsgTalk<1004>
{
	UInt32 Color;			// offset: 4, sample: 16777215
	UInt16 Attribute;		// offset: 8, sample: 2101
	UInt16 Style;			// offset: 10, sample: 0
	Int32 Time;			// offset: 12, sample: 1044
	UInt32 Unknown;			// offset: 16, sample: 0
	UInt32 SpeakerLookface;		// offset: 20, sample: 0
	TQStringList StringList;	// offset: 24, sample: "SYSTEM", "ALLUSERS", "", "ANSWER_OK"
}
Code:
MsgTalk<1004>
{
	UInt32 Color;			// offset: 4, sample: 16776960
	UInt16 Attribute;		// offset: 8, sample: 2000
	UInt16 Style;			// offset: 10, sample: 0
	Int32 Time;			// offset: 12, sample: 1044
	UInt32 Unknown;			// offset: 16, sample: 0
	UInt32 SpeakerLookface;		// offset: 20, sample: 0
	TQStringList StringList;	// offset: 24, sample: "SYSTEM", "Monkenstein", "", "Welcome to Conquer Online!"
}
02/06/2013 20:00 Super Aids#5
He didn't even write 6 strings to it.
02/06/2013 20:06 JobvdH#6
I just have no idea what's wrong, I've added a 4 to the coint of strings too.
It just doesn't work..
02/06/2013 20:11 { Angelius }#7
Quote:
Originally Posted by nTL3fTy View Post
I'm not quite sure where you got this idea that there's 6 strings in the list, but I just logged these from the latest patch:
Quote:
Originally Posted by Super Aids View Post
He didn't even write 6 strings to it.
Isn't it Obvious enough i made a mistake and i wrote the "SYSTEM" length which is 6 instead of 4 in the string count offset?

PHP Code:
04 06 53 59 53 54 45 4D 
And YES the string count can be 6 without writing 6 strings to the packet... try logging a talk packet coming from the client and take a look at the string count... TQ is that stupid...

PHP Code:
Len55Type1004
37 00 EC 03 FF FF FF FF D0 07 00 00 5B 04 00 00      
;7 ìÿÿÿÿР [  
00 00 00 00 00 00 00 00 06 0F 21 3F 5F BD AC 2B      ;        !?_½¬+
A6 75 34 A1 35 5B 50 4D 5D 04 41 6C 6C 20 00 02      ;¦u4¡5[PM]All  
48 69 00 00 00 00 00                                 
;Hi 
02/06/2013 20:22 JobvdH#8
Quote:
Originally Posted by JobvdH View Post
I just have no idea what's wrong, I've added a 4 to the coint of strings too.
It just doesn't work..
.
02/07/2013 00:29 { Angelius }#9
Code:
            WriteUInt(0, 4);//in your case color = 0 will work just fine 
            WriteUInt(Type, 8);//2101
            WriteUInt(EntityID, 12);//1311 for the test purpose 
            WriteUInt(0, 20);//in your case you don't need to add the mesh 
            WriteByte(4, 24);
            WriteStringWithLength(From, 25);//"SYSTEM"
            WriteStringWithLength(To, 26 + From.Length);//"ALLUSERS"
            //WriteStringWithLength(Date, 27 + From.Length + To.Length);//in your case you don't need to add the Date its used only in offline messages
            WriteStringWithLength(Message, 28 + From.Length + To.Length );// + Date.length only in an offline message
Here is the packet dumb...

Code:
36 00 EC 03 FF FF FF 00 35 08 00 00 6F 04 00 00      ;6 ìÿÿÿ 5  o  
00 00 00 00 00 00 00 00 04 06 53 59 53 54 45 4D      ;        SYSTEM
08 41 4C 4C 55 53 45 52 53 00 08 4E 45 57 5F 52      ;ALLUSERS NEW_R
4F 4C 45 00 00 00                                    ;OLE
See if that works.. if not then i am sorry i can't help you anymore you need to learn how to sniff/structure packets on your own... And for that there is a lot of guides here on the forums.. you just need to search
02/07/2013 02:08 Super Aids#10
I know your mistakes. They are all off with 1 offset.

Look here:
WriteStringWithLength(From, 26);

You write the from length at 26 when it should be 25.

#Edit Angelius got it

And also Angelius @ the obvious, not really obvious
02/07/2013 02:46 nTL3fTy#11
Here's a protip: don't specify offsets when constructing packets -- or, you could make a method that will do it for you.
Then you won't run into problems like this.

As a side note, constructing packets like this always makes me think back to LOTF:
Code:
public byte[] SendMsg(uint MessageID, uint Color, string From, string To, string Message, ChatType Type)
{
    byte[] Packet = new byte[29 + From.Length + To.Length + Message.Length];
    fixed (byte* p = Packet)
    {
        *((ushort*)p) = (ushort)Packet.Length;
        *((ushort*)(p + 2)) = 0x3EC;
        *((uint*)(p + 4)) = Color;
        *((uint*)(p + 8)) = (uint)Type;
        *((uint*)(p + 12)) = MessageID;
        //blanks?
        *(p + 24) = 4;
        *(p + 25) = (byte)From.Length;
        for (byte i = 0; i < From.Length; i++) *(p + 26 + i) = (byte)From[i];
        *(p + 26 + From.Length) = (byte)To.Length;
        for (byte i = 0; i < To.Length; i++) *(p + 27 + From.Length + i) = (byte)To[i];
        //blank
        *(p + 28 + From.Length + To.Length) = (byte)Message.Length;
        for (byte i = 0; i < Message.Length; i++) *(p + 29 + From.Length + To.Length + i) = (byte)Message[i];
    }
    return Packet;
}
I suppose we haven't come very far.
02/07/2013 09:46 { Angelius }#12
Quote:
Originally Posted by nTL3fTy View Post
Here's a protip: don't specify offsets when constructing packets-- or, you could make a method that will do it for you.
Then you won't run into problems like this.

As a side note, constructing packets like this always makes me think back to LOTF:
Code:
public byte[] SendMsg(uint MessageID, uint Color, string From, string To, string Message, ChatType Type)
{
    byte[] Packet = new byte[29 + From.Length + To.Length + Message.Length];
    fixed (byte* p = Packet)
    {
        *((ushort*)p) = (ushort)Packet.Length;
        *((ushort*)(p + 2)) = 0x3EC;
        *((uint*)(p + 4)) = Color;
        *((uint*)(p + 8)) = (uint)Type;
        *((uint*)(p + 12)) = MessageID;
        //blanks?
        *(p + 24) = 4;
        *(p + 25) = (byte)From.Length;
        for (byte i = 0; i < From.Length; i++) *(p + 26 + i) = (byte)From[i];
        *(p + 26 + From.Length) = (byte)To.Length;
        for (byte i = 0; i < To.Length; i++) *(p + 27 + From.Length + i) = (byte)To[i];
        //blank
        *(p + 28 + From.Length + To.Length) = (byte)Message.Length;
        for (byte i = 0; i < Message.Length; i++) *(p + 29 + From.Length + To.Length + i) = (byte)Message[i];
    }
    return Packet;
}
I suppose we haven't come very far.
Generally.. C# beginners that never touched C++ don't have a clue on how to use Pointers\fixed Statements\Unsafe code and if they do they'll never bother...

I really don't think that a member who downloaded a public source and decided to start adding stuff to it will ever bother to Replace\Rebuild the packets builder class..
02/07/2013 16:22 Super Aids#13
Quote:
Originally Posted by nTL3fTy View Post
Here's a protip: don't specify offsets when constructing packets -- or, you could make a method that will do it for you.
Then you won't run into problems like this.

As a side note, constructing packets like this always makes me think back to LOTF:
Code:
public byte[] SendMsg(uint MessageID, uint Color, string From, string To, string Message, ChatType Type)
{
    byte[] Packet = new byte[29 + From.Length + To.Length + Message.Length];
    fixed (byte* p = Packet)
    {
        *((ushort*)p) = (ushort)Packet.Length;
        *((ushort*)(p + 2)) = 0x3EC;
        *((uint*)(p + 4)) = Color;
        *((uint*)(p + 8)) = (uint)Type;
        *((uint*)(p + 12)) = MessageID;
        //blanks?
        *(p + 24) = 4;
        *(p + 25) = (byte)From.Length;
        for (byte i = 0; i < From.Length; i++) *(p + 26 + i) = (byte)From[i];
        *(p + 26 + From.Length) = (byte)To.Length;
        for (byte i = 0; i < To.Length; i++) *(p + 27 + From.Length + i) = (byte)To[i];
        //blank
        *(p + 28 + From.Length + To.Length) = (byte)Message.Length;
        for (byte i = 0; i < Message.Length; i++) *(p + 29 + From.Length + To.Length + i) = (byte)Message[i];
    }
    return Packet;
}
I suppose we haven't come very far.
We all have our preferences. The reason I do static offsets is because IMO it gives a better look over the packet and where the hell data is written in it.

I do my messagepacket like this:
Code:
using System;
using ProjectX_V3_Lib.Network;

namespace ProjectX_V3_Game.Packets
{
	/// <summary>
	/// Client -> Server
	/// Server -> Client
	/// </summary>
	public class MessagePacket : DataPacket
	{
		public MessagePacket(DataPacket inPacket)
			: base(inPacket)
		{
			string[] strings = StringPacker.Analyze(inPacket, 24);
			From = strings[0];
			To = strings[1];
			Unknown = strings[2];
			Message = strings[3];
		}
		
		public MessagePacket(StringPacker Message)
			: base((ushort)(24 + Message.Size), PacketType.MessagePacket)
		{
			Message.AppendAndFinish(this, 24);
			Time = 0;
		}
		
		public readonly string From;
		public readonly string To;
		public readonly string Unknown;
		public readonly string Message;
		
		public System.Drawing.Color Color
		{
			get { return (System.Drawing.Color.FromArgb((int)ReadUInt32(4))); }
			set { WriteUInt32((uint)value.ToArgb(), 4); }
		}
		
		public Enums.ChatType ChatType
		{
			get { return (Enums.ChatType)ReadUInt32(8); }
			set { WriteUInt32((uint)value, 8); }
		}
		
		public uint Time
		{
			get { return ReadUInt32(12); }
			set { WriteUInt32(value, 12); }
		}
		
		public uint ToFace
		{
			get { return ReadUInt32(16); }
			set { WriteUInt32(value, 16); }
		}
		
		public uint FromFace
		{
			get { return ReadUInt32(20); }
			set { WriteUInt32(value, 20); }
		}
		
		public static void Handle(Client.GameClient client, DataPacket packet)
		{
			using (var message = new MessagePacket(packet))
			{
				if (message.Message.StartsWith("/") || message.Message.StartsWith("@"))
				{
					Packets.Message.Commands.Handle(client, message.Message, message.Message.Split(' '));
				}
				else
				{
					Console.WriteLine("{0} speaks to {1}: {2}", message.From, message.To, message.Message);
				}
			}
		}
	}
}
02/07/2013 17:08 Lateralus#14
Where did you get your Packet class?
02/07/2013 17:31 JobvdH#15
Quote:
Originally Posted by Lateralus View Post
Where did you get your Packet class?
If you mean me?
I used Fang's packet writer.
Besides that everyone is sending me all kind of offsets and none of them really works.