i think i got your point
there is many ways like block copy , for example copying all bytes u need in one big byte then send them
but my fav way is the warrper (duno why but i really like this way)
well lets create a byte array in the very first
lets call it packet__17 ?
okay now we need to create methods to write stuff in the packet with certain array with all types
what i mean with all types ? to be able to write strings and ints/uints/short/ushort/long/pla/pla/pla
(ill copy this from the trinity source/ pro4never proxy , same at both)
for better understanding you should really learn from pro4never proxy (it's small so it's less scary than trinity source , but both will give u the same amount of information)
read/write to byte array
Code:
public class ReadWrite
{
public static byte[] ReadBytes(byte[] data, int start, int count)
{
try
{
if (start + count > data.Length)
return new byte[0];
else
{
byte[] info = new byte[count];
for (int i = 0; i < count; i++)
info[i] = data[i + start];
return info;
}
}
catch { return new byte[0]; }
}
public static string ReadString(byte[] data, int start, int length)
{
try
{
return Encoding.ASCII.GetString(ReadBytes(data, start, length));
}
catch { return ""; }
}
public static void WriteString(string arg, int offset, byte[] buffer)
{
try
{
if (buffer.Length >= offset + arg.Length)
{
unsafe
{
#if UNSAFE
fixed (byte* Buffer = buffer)
{
ushort i = 0;
while (i < arg.Length)
{
*((byte*)(Buffer + offset + i)) = (byte)arg[i];
i++;
}
}
#else
ushort i = 0;
while (i < arg.Length)
{
buffer[(ushort)(i + offset)] = (byte)arg[i];
i = (ushort)(i + 1);
}
#endif
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public static void WriteBool(bool Value, int offset, byte[] buffer)
{
try
{
if (Value)
buffer[offset] = (byte)(1);
else
buffer[offset] = (byte)(0);
}
catch (Exception e)
{
Console.WriteLine("offset: " + offset + " value " + Value);
Console.WriteLine(e);
}
}
public static void WriteByte(byte arg, int offset, byte[] buffer)
{
try
{
buffer[offset] = (byte)(arg);
}
catch (Exception e)
{
Console.WriteLine("offset: " + offset + " value " + arg);
Console.WriteLine(e);
}
}
public static void WriteUInt16(ushort arg, int offset, byte[] buffer)
{
try
{
if (buffer.Length >= offset + sizeof(ushort))
{
unsafe
{
#if UNSAFE
fixed (byte* Buffer = buffer)
{
*((ushort*)(Buffer + offset)) = arg;
}
#else
buffer[offset] = (byte)(arg);
buffer[offset + 1] = (byte)(arg >> 8);
#endif
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public static void WriteUInt32(uint arg, int offset, byte[] buffer)
{
try
{
if (buffer.Length >= offset + sizeof(uint))
{
unsafe
{
#if UNSAFE
fixed (byte* Buffer = buffer)
{
*((uint*)(Buffer + offset)) = arg;
}
#else
buffer[offset] = (byte)(arg);
buffer[offset + 1] = (byte)(arg >> 8);
buffer[offset + 2] = (byte)(arg >> 16);
buffer[offset + 3] = (byte)(arg >> 24);
#endif
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
public static void WriteUInt64(ulong arg, int offset, byte[] buffer)
{
try
{
if (buffer.Length >= offset + sizeof(ulong))
{
unsafe
{
#if UNSAFE
fixed (byte* Buffer = buffer)
{
*((ulong*)(Buffer + offset)) = arg;
}
#else
buffer[offset] = (byte)(arg);
buffer[offset + 1] = (byte)(arg >> 8);
buffer[offset + 2] = (byte)(arg >> 16);
buffer[offset + 3] = (byte)(arg >> 24);
buffer[offset + 4] = (byte)(arg >> 32);
buffer[offset + 5] = (byte)(arg >> 40);
buffer[offset + 6] = (byte)(arg >> 48);
buffer[offset + 7] = (byte)(arg >> 56);
#endif
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}
example of me sending a packet
Code:
public void __Packet10010(/*uint Entity_ID,*/ ushort coordx, ushort coordy/*, ushort jump_type*/ , GameUser roleer , string type , string sendto , ushort oldx , ushort oldy)
{
// if (Olddt + 10000 > dt && Olddt != 0) return;
// else
// {
byte[] data;
data = new byte[46];
ReadWrite.WriteString("username", 40, data); //this line just added to show you that you can write strings too inside the packet
ReadWrite.WriteUInt16(0x0026, 0, data); // packet length
ReadWrite.WriteUInt16(0x271A, 2, data); //packet number
ReadWrite.WriteUInt32(0x010DB6F9, 4, data); //packet attacker UID // 0x000F50C0
ReadWrite.WriteUInt16(coordx, 8, data); //packet current coordx
ReadWrite.WriteUInt16(coordy, 10, data); //packet current coordy
ReadWrite.WriteUInt16(oldx, 24, data); //old coordx <<< edited
ReadWrite.WriteUInt16(oldy, 26, data); //old coordy
if (type == "normal")
{
ReadWrite.WriteUInt32(137, 20, data); //packet type of jump
}
else { ReadWrite.WriteUInt32(156, 20, data); } //packet type of jump
// Console.WriteLine("jump packet from : (" + BitConverter.ToString(data, 24, 2) + "," + BitConverter.ToString(data, 26, 2) + ") to (" + BitConverter.ToString(data, 8, 2) + "," + BitConverter.ToString(data, 10, 2) + ")");
if (sendto == "server")
{
roleer.SendToServer(data);
}
else
{
roleer.SendToClient(data);
}
// Olddt = dt;
// }
}
that was the whole read write class , this is an example of generaldata/jumping packet , added to it ReadWrite.WriteString(string string , int offset , byte[] byte_array) for better understanding
you may type in hex with 0x or in dec like coordx and coordy
wish that is what you searching for , but i really want you to read , just read , pro4never proxy or trinity base , it will answer all your questions , enjoy mate
umm was to forget , about the block copy , here is an example
Buffer.BlockCopy(byte[] source_array , int source_offset , byte[] destination , int destination_offset , int count(the number of bytes to copy) );
here is an example in action at splitting packets
Code:
byte[] Packet = new byte[(Length + 8)];
Buffer.BlockCopy(data, 0, Packet, 0, (Length + 8));
byte[] _buffer = new byte[(data.Length - (Length + 8))];
Buffer.BlockCopy(data, (Length + 8), _buffer, 0, (data.Length - (Length + 8)));
data = _buffer;
ReadWrite.WriteString("TQClient", (Packet.Length - 8), Packet);
HandleClient(Packet);