-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextBinLine.cs
163 lines (148 loc) · 5.59 KB
/
TextBinLine.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fire_Emblem_Three_Houses_Randomizer_V2
{
internal class TextBinLine
{
List<byte> encodedText;
public TextBinLine (byte[] buffer, uint linePointer)
{
int offset = (int)linePointer;
encodedText = new List<byte>();
while (buffer[offset] != 0)
{
encodedText.Add(buffer[offset]);
offset++;
}
encodedText.Add(0);
}
public List<byte> getBytes()
{
return encodedText;
}
public string getString()
{
byte[] utf8Bytes = new byte[encodedText.Count - 1];
for (int i = 0; i < utf8Bytes.Length; i++)
utf8Bytes[i] = encodedText[i];
UTF8Encoding utf8 = new UTF8Encoding();
return utf8.GetString(utf8Bytes);
}
public void setString(List<string> strings)
{
UTF8Encoding utf8 = new UTF8Encoding();
byte[] utf8Bytes = utf8.GetBytes(strings[0]);
encodedText = new List<byte>();
for (int i = 0; i < utf8Bytes.Length; i++)
encodedText.Add(utf8Bytes[i]);
encodedText.Add(0);
strings.RemoveAt(0);
}
public bool valid()
{
bool hasInvalidChar = false;
for (int i = 0; i < getString().Length && !hasInvalidChar; i++)
if (getString().ElementAt(i) >= 0x3040)
hasInvalidChar = true;
return encodedText.Count > 1 &&
!hasInvalidChar &&
getString() != "iron_untranslated" &&
getString().ToLower() != "dummy" &&
getString() != "Unused" &&
!getString().StartsWith("Spare") &&
!getString().StartsWith("Character exclusive spare") &&
getString() != "-" &&
getString() != " " &&
!getString().StartsWith("Placeholder") &&
getString() != "0" &&
!(getString().StartsWith("Item ") && getString().Length == 7) &&
!getString().StartsWith("Dish ") &&
!(getString().StartsWith("Bait ") && getString().Length == 7) &&
!getString().StartsWith("seeds") &&
!getString().StartsWith("Ore ") &&
!(getString().StartsWith("Fish ") && getString().Length == 7) &&
!getString().StartsWith("Crops") &&
!(getString().StartsWith("Meat ") && getString().Length == 7) &&
!getString().StartsWith("Tea Leaves ") &&
getString() != "TBD" &&
getString() != "On Hold" &&
getString() != "Undecided" &&
!getString().StartsWith("Dining Together Menu Item") &&
!getString().StartsWith("Reserved") &&
getString() != "Map Battle Boss Reserved" &&
!getString().StartsWith("conversation event placeholder") &&
!getString().StartsWith("Accepted Quest Character Message") &&
!getString().StartsWith("Mission text message") &&
!getString().StartsWith("Quest Reported Character Message") &&
!getString().StartsWith("Sothis Message") &&
!getString().Contains("") &&
getString() != "tTemporarymessage";
}
}
internal class ConvoLine
{
readonly int preLineLength = 6;
List<byte> preLine;
List<byte> encodedText;
List<byte> postLine;
public ConvoLine(byte[] buffer, uint linePointer)
{
int offset = (int)linePointer;
preLine = new List<byte>();
encodedText = new List<byte>();
postLine = new List<byte>();
for (int i = 0; i < preLineLength; i++)
{
preLine.Add(buffer[offset]);
offset++;
}
while (buffer[offset] != 239)
{
encodedText.Add(buffer[offset]);
offset++;
}
while (buffer[offset] != 0)
{
postLine.Add(buffer[offset]);
offset++;
}
postLine.Add(0);
}
public List<byte> getBytes()
{
List<byte> bytes = new List<byte>();
bytes.AddRange(preLine);
bytes.AddRange(encodedText);
bytes.AddRange(postLine);
return bytes;
}
public string getString()
{
byte[] utf8Bytes = new byte[encodedText.Count];
for (int i = 0; i < utf8Bytes.Length; i++)
utf8Bytes[i] = encodedText[i];
UTF8Encoding utf8 = new UTF8Encoding();
return utf8.GetString(utf8Bytes);
}
public void setString(List<string> strings)
{
UTF8Encoding utf8 = new UTF8Encoding();
byte[] utf8Bytes = utf8.GetBytes(strings[0]);
encodedText = new List<byte>();
for (int i = 0; i < utf8Bytes.Length; i++)
encodedText.Add(utf8Bytes[i]);
strings.RemoveAt(0);
}
public bool valid()
{
bool hasInvalidChar = false;
for (int i = 0; i < getString().Length && !hasInvalidChar; i++)
if (getString().ElementAt(i) >= 0x3040)
hasInvalidChar = true;
return getString().Length > 0 && !hasInvalidChar && getString() != "NULL#00";
}
}
}