-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParseUseBinaryReader.cs
77 lines (62 loc) · 1.8 KB
/
ParseUseBinaryReader.cs
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
namespace SupReSyncTool
{
public class ParseUseBinaryReader : BinaryReader
{
public ParseUseBinaryReader(Stream stream) : base(stream)
{
}
public ParseUseBinaryReader(byte[] data) : base(new MemoryStream(data))
{
}
public ushort ReadTwoBytes()
{
byte[] buffer = base.ReadBytes(2);
if (buffer.Length < 2)
{
return 0;
}
return (ushort)((buffer[0] << 8) + buffer[1]);
}
public uint ReadThreeBytes()
{
byte[] buffer = base.ReadBytes(3);
if (buffer.Length < 3)
{
return 0;
}
return (uint)((buffer[0] << 16) + (buffer[1] << 8) + buffer[2]);
}
public uint ReadFourBytes()
{
byte[] buffer = base.ReadBytes(4);
if (buffer.Length < 4)
{
return 0;
}
return (uint)((buffer[0] << 24) + (buffer[1] << 16) + (buffer[2] << 8) + (buffer[3]));
}
public bool Back(int Count = 1)
{
if (!BaseStream.CanSeek)
{
return false;
}
if (BaseStream.Position <= Count)
{
BaseStream.Seek(0, SeekOrigin.Begin);
}
else
{
BaseStream.Seek(Count * -1, SeekOrigin.Current);
}
return true;
}
public byte[] ReadBytes(ushort count)
{
var buf = new byte[count];
BaseStream.Read(buf, 0, count);
return buf;
}
public bool EOF => BaseStream.Position == BaseStream.Length;
}
}