-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTextBinLanguageSection.cs
77 lines (70 loc) · 2.51 KB
/
TextBinLanguageSection.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 TextBinLanguageSection
{
uint tableCount;
List<uint> tablePointers;
List<uint> tableSizes;
List<TextBinTable> tables;
public TextBinLanguageSection (byte[] buffer, uint languagePointer)
{
int offset = (int)languagePointer;
tableCount = BitConverter.ToUInt32(buffer, offset);
offset += 4;
tablePointers = new List<uint>();
tableSizes = new List<uint>();
tables = new List<TextBinTable>();
for (int i = 0; i < tableCount; i++)
{
tablePointers.Add(BitConverter.ToUInt32(buffer, offset + 0));
tableSizes.Add(BitConverter.ToUInt32(buffer, offset + 4));
tables.Add(new TextBinTable(buffer, languagePointer + tablePointers[i]));
offset += 8;
}
}
public List<byte> getBytes()
{
fixPointers();
List<byte> bytes = new List<byte>();
bytes.AddRange(BitConverter.GetBytes(tableCount));
for (int i = 0; i < tables.Count; i++)
{
bytes.AddRange(BitConverter.GetBytes(tablePointers[i]));
bytes.AddRange(BitConverter.GetBytes(tableSizes[i]));
}
for (int i = 0; i < tables.Count; i++)
bytes.AddRange(tables[i].getBytes());
return bytes;
}
private void fixPointers()
{
uint offset = 4;
for (int i = 0; i < tables.Count; i++)
offset += 8;
for (int i = 0; i < tables.Count; i++)
{
tablePointers[i] = offset;
tableSizes[i] = (uint)tables[i].getBytes().Count;
tables[i].fixPointers(tableSizes[i]);
offset += tableSizes[i];
}
}
public List<string> getStrings(bool includeInvalids)
{
List<string> strings = new List<string>();
for (int i = 0; i < tables.Count; i++)
strings.AddRange(tables[i].getStrings(includeInvalids));
return strings;
}
public void setStrings(List<string> strings, bool includeInvalids)
{
for (int i = 0; i < tables.Count; i++)
tables[i].setStrings(strings, includeInvalids);
}
}
}