blob: c6709f542aa1b0dd646660960c97f87f7c0745a3 (
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
|
package classes
import (
"bytes"
"github.com/pektezol/bitreader"
)
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 ParseStringTables(reader *bitreader.ReaderType) []StringTable {
tableCount := reader.TryReadBits(8)
stringTables := make([]StringTable, tableCount)
for i := 0; i < int(tableCount); i++ {
var table StringTable
table.ParseStream(reader)
stringTables[i] = table
}
return stringTables
}
func (stringTable *StringTable) ParseStream(reader *bitreader.ReaderType) {
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.ReaderType) {
stringTableEntry.Name = reader.TryReadString()
if reader.TryReadBool() {
byteLen, err := reader.ReadBits(16)
if err != nil {
return
}
dataBsr := reader.TryReadBytesToSlice(int(byteLen))
_ = bitreader.Reader(bytes.NewReader(dataBsr), true) // TODO: Parse StringTableEntry
// stringTableEntry.EntryData.ParseStream(entryReader)
}
}
func (stringTableClass *StringTableClass) Parse(reader *bitreader.ReaderType) {
stringTableClass.Name = reader.TryReadString()
if reader.TryReadBool() {
dataLen := reader.TryReadBits(16)
stringTableClass.Data = reader.TryReadStringLen(int(dataLen))
}
}
|