forked from Nifyr/Fire-Emblem-Three-Houses-Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextBinMessage.cs
77 lines (70 loc) · 2.48 KB
/
TextBinMessage.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
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 TextBinMessage
{
List<uint> linePointers;
List<uint> otherEntries;
List<TextBinLine> lines;
public TextBinMessage (byte[] buffer, uint messagePointer, uint messageStart, List<byte> flags)
{
int offset = (int)messagePointer;
linePointers = new List<uint>();
otherEntries = new List<uint>();
lines = new List<TextBinLine>();
for (int i = 0; i < flags.Count; i++)
{
if (flags[i] == 0)
{
linePointers.Add(BitConverter.ToUInt32(buffer, offset));
lines.Add(new TextBinLine(buffer, messageStart + linePointers[i]));
}
else
otherEntries.Add(BitConverter.ToUInt32(buffer, offset));
offset += 4;
}
}
public List<byte> getPointerBytes()
{
List<byte> bytes = new List<byte>();
for (int i = 0; i < linePointers.Count; i++)
bytes.AddRange(BitConverter.GetBytes(linePointers[i]));
for (int i = 0; i < otherEntries.Count; i++)
bytes.AddRange(BitConverter.GetBytes(otherEntries[i]));
return bytes;
}
public List<byte> getLineBytes()
{
List<byte> bytes = new List<byte>();
for (int i = 0; i < lines.Count; i++)
bytes.AddRange(lines[i].getBytes());
return bytes;
}
public void fixPointers(uint lineOffset)
{
for (int i = 0; i < lines.Count; i++)
{
linePointers[i] = lineOffset;
lineOffset += (uint)lines[i].getBytes().Count;
}
}
public List<string> getStrings(bool includeInvalids)
{
List<string> strings = new List<string>();
for (int i = 0; i < lines.Count; i++)
if (lines[i].valid() || includeInvalids)
strings.Add(lines[i].getString());
return strings;
}
public void setStrings(List<string> strings, bool includeInvalids)
{
for (int i = 0; i < lines.Count; i++)
if (lines[i].valid() || includeInvalids)
lines[i].setString(strings);
}
}
}