I will explain the new habbo packet handling
What's the difference?
- No base encoding anymore. They using Bits.
How to handle an Integer?
Get 4 Numbers (as bits).
Bits explaining
Code:
Example:
1-0-0-0 = 1 as int
0-1-0-0 = 256 as int
1-1-0-0 = 257 as int (1x 256 + 1)
1-2-0-0 = 513 as int (2x 256 + 1)
You have to count further.
Like having 4 Row(s) in an byte array.
Every row has an max of 255 (bit).
1-2-3-4 Rows.
If the row has reaches his max then the next row gets + 1.
Thent he old row will be set to 0, to count again.
Every single item stands for an integer of an max of (255).
Int lengths
Int32 = 4 (bits)
Int16(short) = 2 (bits) [Used for HeaderId and string lengths]
Something weird
Habbo reversed the bytes sometimes.
Boolean explaining
They just used a single bit for the boolean.
Code:
Example
True = 1
False = 0
String explaining
Not that hard, they just used as first.
[String Length (as short)] + Text of string.
Characters explaining
Just use your bitconverter to do this.
With all pleasure :)
Like if you know more after reading this!
New ServerMessage
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HabboTCP.Messages.Library
{
class ServerMessage
{
private List<byte> Context = new List<byte>();
public ServerMessage(short HeaderId) { Append(HeaderId); }
public void Append(object Item)
{
if (Item is Int32 || Item is int)
{
AddInt32((Int32)Item);
}
else if (Item is Int16 || Item is short)
{
AddInt16((Int16)Item);
}
else if (Item is Boolean || Item is bool)
{
AddBoolean((Boolean)Item);
}
else if (Item is String || Item is string)
{
AddString(Item as string);
}
}
private void AddInt32(Int32 Item)
{
AddBytes(BitConverter.GetBytes(Item), ReverseType.Reversed);
}
private void AddInt16(Int16 Item)
{
AddBytes(BitConverter.GetBytes(Item), ReverseType.Reversed);
}
private void AddBoolean(Boolean Item)
{
AddBytes(new byte[] { (byte)(Item ? 1 : 0) }, ReverseType.Fresh);
}
private void AddString(String Item)
{
AddInt16((short)Item.Length);
AddBytes(Encoding.ASCII.GetBytes(Item), ReverseType.Fresh);
}
private void AddBytes(byte[] Bytes, ReverseType Type)
{
if (Type == ReverseType.Reversed)
{
for (int i = (Bytes.Length - 1); i > -1; i--)
{
Context.Add(Bytes[i]);
}
}
else
{
Context.AddRange(Bytes);
}
}
public byte[] Bytes()
{
var Result = new List<byte>();
Result.AddRange(BitConverter.GetBytes(Context.Count));
Result.Reverse();
Result.AddRange(Context);
return Result.ToArray();
}
}
enum ReverseType
{
Fresh,
Reversed
}
}