diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-21 19:26:40 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-21 19:26:40 +0300 |
| commit | 44eefefe67a4a5f514faa4594370346fd1b54996 (patch) | |
| tree | a8853a8ecd49ddbb87c6cc19904ec6bb5419ee83 /pkg/classes/stringTables.go | |
| parent | add strings builder, customize ALL outputs (#6) (diff) | |
| download | sdp.go-1.1.1.tar.gz sdp.go-1.1.1.tar.bz2 sdp.go-1.1.1.zip | |
organize packets and classes (#9)v1.1.1
Diffstat (limited to 'pkg/classes/stringTables.go')
| -rw-r--r-- | pkg/classes/stringTables.go | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/pkg/classes/stringTables.go b/pkg/classes/stringTables.go new file mode 100644 index 0000000..01939b2 --- /dev/null +++ b/pkg/classes/stringTables.go | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 6 | ) | ||
| 7 | |||
| 8 | type StringTables struct { | ||
| 9 | Size int32 | ||
| 10 | Data []StringTable | ||
| 11 | } | ||
| 12 | |||
| 13 | type StringTable struct { | ||
| 14 | Name string | ||
| 15 | TableEntries []StringTableEntry | ||
| 16 | Classes []StringTableClass | ||
| 17 | } | ||
| 18 | |||
| 19 | type StringTableEntry struct { | ||
| 20 | Name string | ||
| 21 | EntryData StringTableEntryData | ||
| 22 | } | ||
| 23 | |||
| 24 | type StringTableEntryData struct { | ||
| 25 | // TODO: Parse StringTableEntry | ||
| 26 | } | ||
| 27 | |||
| 28 | type StringTableClass struct { | ||
| 29 | Name string | ||
| 30 | Data string | ||
| 31 | } | ||
| 32 | |||
| 33 | func (stringTables *StringTables) ParseStringTables(reader *bitreader.Reader) { | ||
| 34 | stringTables.Size = reader.TryReadSInt32() | ||
| 35 | stringTableReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(uint64(stringTables.Size)), true) | ||
| 36 | tableCount := stringTableReader.TryReadBits(8) | ||
| 37 | tables := make([]StringTable, tableCount) | ||
| 38 | for i := 0; i < int(tableCount); i++ { | ||
| 39 | var table StringTable | ||
| 40 | table.ParseStream(stringTableReader) | ||
| 41 | tables[i] = table | ||
| 42 | } | ||
| 43 | stringTables.Data = tables | ||
| 44 | } | ||
| 45 | |||
| 46 | func (stringTable *StringTable) ParseStream(reader *bitreader.Reader) { | ||
| 47 | stringTable.Name = reader.TryReadString() | ||
| 48 | entryCount := reader.TryReadBits(16) | ||
| 49 | writer.AppendLine("\tTable Name: %s", stringTable.Name) | ||
| 50 | stringTable.TableEntries = make([]StringTableEntry, entryCount) | ||
| 51 | |||
| 52 | for i := 0; i < int(entryCount); i++ { | ||
| 53 | var entry StringTableEntry | ||
| 54 | entry.Parse(reader) | ||
| 55 | stringTable.TableEntries[i] = entry | ||
| 56 | } | ||
| 57 | if entryCount != 0 { | ||
| 58 | writer.AppendLine("\t\t%d Table Entries:", entryCount) | ||
| 59 | writer.AppendOutputFromTemp() | ||
| 60 | } else { | ||
| 61 | writer.AppendLine("\t\tNo Table Entries") | ||
| 62 | } | ||
| 63 | if reader.TryReadBool() { | ||
| 64 | classCount := reader.TryReadBits(16) | ||
| 65 | stringTable.Classes = make([]StringTableClass, classCount) | ||
| 66 | |||
| 67 | for i := 0; i < int(classCount); i++ { | ||
| 68 | var class StringTableClass | ||
| 69 | class.Parse(reader) | ||
| 70 | stringTable.Classes[i] = class | ||
| 71 | } | ||
| 72 | writer.AppendLine("\t\t%d Classes:", classCount) | ||
| 73 | writer.AppendOutputFromTemp() | ||
| 74 | } else { | ||
| 75 | writer.AppendLine("\t\tNo Class Entries") | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | func (stringTableEntry *StringTableEntry) Parse(reader *bitreader.Reader) { | ||
| 80 | stringTableEntry.Name = reader.TryReadString() | ||
| 81 | if reader.TryReadBool() { | ||
| 82 | byteLen, err := reader.ReadBits(16) | ||
| 83 | if err != nil { | ||
| 84 | return | ||
| 85 | } | ||
| 86 | dataBsr := reader.TryReadBytesToSlice(byteLen) | ||
| 87 | _ = bitreader.NewReaderFromBytes(dataBsr, true) // TODO: Parse StringTableEntry | ||
| 88 | // stringTableEntry.EntryData.ParseStream(entryReader) | ||
| 89 | } | ||
| 90 | } | ||
| 91 | |||
| 92 | func (stringTableClass *StringTableClass) Parse(reader *bitreader.Reader) { | ||
| 93 | stringTableClass.Name = reader.TryReadString() | ||
| 94 | writer.TempAppendLine("\t\t\tName: %s", stringTableClass.Name) | ||
| 95 | if reader.TryReadBool() { | ||
| 96 | dataLen := reader.TryReadBits(16) | ||
| 97 | stringTableClass.Data = reader.TryReadStringLength(dataLen) | ||
| 98 | writer.TempAppendLine("\t\t\tData: %s", stringTableClass.Data) | ||
| 99 | } | ||
| 100 | } | ||