forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameserverPacket.cs
More file actions
88 lines (70 loc) · 2.1 KB
/
Copy pathGameserverPacket.cs
File metadata and controls
88 lines (70 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.IO;
namespace L2dotNET.Network
{
public abstract class GameserverPacket
{
private readonly MemoryStream _stream = new MemoryStream();
protected void WriteBytesArray(byte[] value)
{
_stream.Write(value, 0, value.Length);
}
protected void WriteBytesArray(byte[] value, int offset, int length)
{
_stream.Write(value, offset, length);
}
protected void WriteInt(uint value = 0)
{
WriteBytesArray(BitConverter.GetBytes(value));
}
protected void WriteInt(int value = 0)
{
WriteBytesArray(BitConverter.GetBytes(value));
}
protected void WriteInt(double value = 0.0)
{
WriteBytesArray(BitConverter.GetBytes((int)value));
}
protected void WriteShort(ushort value = 0)
{
WriteBytesArray(BitConverter.GetBytes(value));
}
protected void WriteShort(short value = 0)
{
WriteBytesArray(BitConverter.GetBytes(value));
}
protected void WriteShort(int value = 0)
{
WriteBytesArray(BitConverter.GetBytes((short)value));
}
protected void WriteByte(byte value)
{
_stream.WriteByte(value);
}
protected void WriteByte(int value)
{
_stream.WriteByte((byte)value);
}
protected void WriteDouble(double value)
{
WriteBytesArray(BitConverter.GetBytes(value));
}
protected void WriteString(string value)
{
if (value != null)
WriteBytesArray(System.Text.Encoding.Unicode.GetBytes(value));
_stream.WriteByte(0);
_stream.WriteByte(0);
}
protected void WriteLong(long value)
{
WriteBytesArray(BitConverter.GetBytes(value));
}
public byte[] ToByteArray()
{
return _stream.ToArray();
}
public long Length => _stream.Length;
public abstract void Write();
}
}