This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL2String.cs
132 lines (105 loc) · 3.13 KB
/
L2String.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace LEdit
{
public class L2String
{
string val;
public string Value { get { return val; } set { val = value; } }
public L2String()
{
val = string.Empty;
}
public L2String(string value)
{
val = value;
}
public L2String(BinaryReader br)
{
FromStream(br);
}
public L2String(BinaryReader br, int len)
{
FromStream(br, len);
}
public void ToStream(BinaryWriter bw, int len, bool zero_termination)
{
char[] str = val.ToCharArray();
if (len == 0 || len > str.Length)
len = str.Length;
for (int i = 0; i < len; i++)
{
switch (str[i])
{
case '\n':
break;
case '\r':
bw.Write((byte)0x03);
break;
case 'ö':
bw.Write((byte)0x28);
break;
case 'ü':
bw.Write((byte)0x3B);
break;
case 'ä':
bw.Write((byte)0x3C);
break;
case 'ß':
bw.Write((byte)0x7C);
break;
default:
bw.Write((byte)str[i]);
break;
}
}
if (zero_termination)
bw.Write((byte)0x00);
}
public void FromStream(BinaryReader br)
{
long pos = br.BaseStream.Position;
int len = 0;
for (byte b = br.ReadByte(); b != 0; b = br.ReadByte())
++len;
++len;
br.BaseStream.Position = pos;
FromStream(br, len);
}
public void FromStream(BinaryReader br, int len)
{
byte[] str = br.ReadBytes(len);
val = string.Empty;
for (int i = 0; i < len; i++)
{
switch (str[i])
{
case 0x00: //End of string
case 0x05: //Read from table
case 0xE0: //Unknown
break;
case 0x03:
val += "\r\n";
break;
case 0x28: //'('
val += "ö";
break;
case 0x3B: //';'
val += "ü";
break;
case 0x3C: //'<'
val += "ä";
break;
case 0x7C: //'|'
val += "ß";
break;
default:
val += (char)str[i];
break;
}
}
}
}
}