blob: 45954be85f49fac187677fe453692f01818ec1c7 (
plain) (
blame)
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
|
package classes
import (
"github.com/pektezol/bitreader"
)
type StringTables struct {
Size int32
Data []StringTable
}
type StringTable struct {
Name string
TableEntries []StringTableEntry
Classes []StringTableClass
}
type StringTableEntry struct {
Name string
EntryData StringTableEntryData
}
type StringTableEntryData struct {
// TODO: Parse StringTableEntry
}
type StringTableClass struct {
Name string
Data string
}
func (stringTables *StringTables) ParseStringTables(reader *bitreader.Reader) {
stringTables.Size = reader.TryReadSInt32()
stringTableReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(uint64(stringTables.Size)), true)
tableCount := stringTableReader.TryReadBits(8)
tables := make([]StringTable, tableCount)
for i := 0; i < int(tableCount); i++ {
var table StringTable
table.ParseStream(stringTableReader)
tables[i] = table
}
stringTables.Data = tables
}
func (stringTable *StringTable) ParseStream(reader *bitreader.Reader) {
stringTable.Name = reader.TryReadString()
entryCount := reader.TryReadBits(16)
stringTable.TableEntries = make([]StringTableEntry, entryCount)
for i := 0; i < int(entryCount); i++ {
var entry StringTableEntry
entry.Parse(reader)
stringTable.TableEntries[i] = entry
}
if reader.TryReadBool() {
classCount := reader.TryReadBits(16)
stringTable.Classes = make([]StringTableClass, classCount)
for i := 0; i < int(classCount); i++ {
var class StringTableClass
class.Parse(reader)
stringTable.Classes[i] = class
}
}
}
func (stringTableEntry *StringTableEntry) Parse(reader *bitreader.Reader) {
stringTableEntry.Name = reader.TryReadString()
if reader.TryReadBool() {
byteLen, err := reader.ReadBits(16)
if err != nil {
return
}
dataBsr := reader.TryReadBytesToSlice(byteLen)
_ = bitreader.NewReaderFromBytes(dataBsr, true) // TODO: Parse StringTableEntry
// stringTableEntry.EntryData.ParseStream(entryReader)
}
}
func (stringTableClass *StringTableClass) Parse(reader *bitreader.Reader) {
stringTableClass.Name = reader.TryReadString()
if reader.TryReadBool() {
dataLen := reader.TryReadBits(16)
stringTableClass.Data = reader.TryReadStringLength(dataLen)
}
}
|