forked from Elfocrash/L2dotNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDlcStream.cs
More file actions
95 lines (81 loc) · 2.32 KB
/
Copy pathDlcStream.cs
File metadata and controls
95 lines (81 loc) · 2.32 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
89
90
91
92
93
94
95
using System;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace L2dotNET.Compression
{
public class DlcStream
{
public GZipStream Stream;
public FileStream Stream2;
private readonly byte[] _dlcStr = Encoding.UTF8.GetBytes("DLC");
public DlcStream(FileStream fstream, CompressionMode cm)
{
Stream = new GZipStream(fstream, cm);
Stream2 = fstream;
if (cm == CompressionMode.Compress)
Stream2.Write(_dlcStr, 0, _dlcStr.Length);
}
public void Close()
{
Stream.Close();
Stream.Dispose();
Stream2.Close();
Stream2.Dispose();
}
public int ReadD()
{
byte[] buff = new byte[4];
Stream.Read(buff, 0, buff.Length);
return BitConverter.ToInt32(buff, 0);
}
public long ReadQ()
{
byte[] buff = new byte[8];
Stream.Read(buff, 0, buff.Length);
return BitConverter.ToInt64(buff, 0);
}
public double ReadF()
{
byte[] buff = new byte[8];
Stream.Read(buff, 0, buff.Length);
return BitConverter.ToDouble(buff, 0);
}
public byte ReadC()
{
byte[] buff = new byte[1];
Stream.Read(buff, 0, buff.Length);
return buff[0];
}
public string ReadS(int len)
{
byte[] buff = new byte[len];
Stream.Read(buff, 0, buff.Length);
return Encoding.UTF8.GetString(buff);
}
public void WriteD(int d)
{
byte[] buff = BitConverter.GetBytes(d);
Stream.Write(buff, 0, buff.Length);
}
public void WriteQ(long q)
{
byte[] buff = BitConverter.GetBytes(q);
Stream.Write(buff, 0, buff.Length);
}
public void WriteC(byte c)
{
Stream.WriteByte(c);
}
public void WriteS(string str)
{
byte[] buff = Encoding.UTF8.GetBytes(str);
Stream.Write(buff, 0, buff.Length);
}
public void WriteF(double f)
{
byte[] buff = BitConverter.GetBytes(f);
Stream.Write(buff, 0, buff.Length);
}
}
}