forked from kiwon0319/GFDecompress
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathStcBinaryReader.cs
112 lines (84 loc) · 2.65 KB
/
StcBinaryReader.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using NLog;
using NLog.Fluent;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GFDecompress
{
public class StcBinaryReader
{
private static readonly Logger log = LogManager.GetCurrentClassLogger();
public byte[] _buf;
public int _offset;
// constructor
public StcBinaryReader(byte[] buf)
{
_buf = buf;
_offset = 0;
}
public byte ReadByte()
{
byte output = _buf[_offset];
log.Trace("offset: {0} | byte: {1}", _offset, output);
_offset += 1;
return output;
}
public int ReadShort()
{
int output = BitConverter.ToInt16(_buf, _offset);
log.Trace("offset: {0} | short: {1}", _offset, output);
_offset += 2;
return output;
}
public int ReadUShort()
{
int output = BitConverter.ToUInt16(_buf, _offset);
log.Trace("offset: {0} | u_short: {1}", _offset, output);
_offset += 2;
return output;
}
public int ReadInt()
{
int output = BitConverter.ToInt32(_buf, _offset);
log.Trace("offset: {0} | int: {1}", _offset, output);
_offset += 4;
return output;
}
public long ReadLong()
{
long output = BitConverter.ToInt64(_buf, _offset);
log.Trace("offset: {0} | long: {1}", _offset, output);
_offset += 8;
return output;
}
public double ReadSingle()
{
float output = BitConverter.ToSingle(_buf, _offset);
log.Trace("offset: {0} | single: {1}", _offset, output);
_offset += 4;
return output;
}
public double ReadDouble()
{
double output = BitConverter.ToDouble(_buf, _offset);
log.Trace("offset: {0} | double: {1}", _offset, output);
_offset += 8;
return output;
}
public string ReadString()
{
_offset += 1; // 오프셋 +1 해야 위치 맞음
int length = ReadUShort();
byte[] bytes = new byte[length];
Array.Copy(_buf, _offset, bytes, 0, length);
string output = Encoding.UTF8.GetString(bytes);
output = output.Replace("\\u0000", "").Replace("\u0000", "");
log.Trace("offset: {0} | length: {1} | string: {2}", _offset, length, output);
_offset += length;
return output;
}
}
}