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 | |
| parent | add strings builder, customize ALL outputs (#6) (diff) | |
| download | sdp.go-44eefefe67a4a5f514faa4594370346fd1b54996.tar.gz sdp.go-44eefefe67a4a5f514faa4594370346fd1b54996.tar.bz2 sdp.go-44eefefe67a4a5f514faa4594370346fd1b54996.zip | |
organize packets and classes (#9)v1.1.1
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/classes/cmdInfo.go | 63 | ||||
| -rw-r--r-- | pkg/classes/consoleCmd.go | 19 | ||||
| -rw-r--r-- | pkg/classes/customData.go | 30 | ||||
| -rw-r--r-- | pkg/classes/dataTables.go (renamed from pkg/classes/sendTable.go) | 151 | ||||
| -rw-r--r-- | pkg/classes/packet.go | 90 | ||||
| -rw-r--r-- | pkg/classes/serverClassInfo.go | 33 | ||||
| -rw-r--r-- | pkg/classes/signOn.go | 52 | ||||
| -rw-r--r-- | pkg/classes/stop.go | 17 | ||||
| -rw-r--r-- | pkg/classes/stringTables.go (renamed from pkg/classes/stringTable.go) | 19 | ||||
| -rw-r--r-- | pkg/classes/syncTick.go | 5 | ||||
| -rw-r--r-- | pkg/classes/userCmd.go | 231 | ||||
| -rw-r--r-- | pkg/classes/userCmdInfo.go | 87 | ||||
| -rw-r--r-- | pkg/messages/messages.go | 2 | ||||
| -rw-r--r-- | pkg/packets/packets.go | 125 | ||||
| -rw-r--r-- | pkg/packets/types.go | 53 |
15 files changed, 580 insertions, 397 deletions
diff --git a/pkg/classes/cmdInfo.go b/pkg/classes/cmdInfo.go deleted file mode 100644 index eccfe99..0000000 --- a/pkg/classes/cmdInfo.go +++ /dev/null | |||
| @@ -1,63 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 8 | ) | ||
| 9 | |||
| 10 | type CmdInfo struct { | ||
| 11 | Flags string | ||
| 12 | ViewOrigin []float32 | ||
| 13 | ViewAngles []float32 | ||
| 14 | LocalViewAngles []float32 | ||
| 15 | ViewOrigin2 []float32 | ||
| 16 | ViewAngles2 []float32 | ||
| 17 | LocalViewAngles2 []float32 | ||
| 18 | } | ||
| 19 | |||
| 20 | type CmdInfoFlags int | ||
| 21 | |||
| 22 | const ( | ||
| 23 | ECmdInfoFlagsNone = 0 | ||
| 24 | ECmdInfoFlagsUseOrigin2 = 1 | ||
| 25 | ECmdInfoFlagsUserAngles2 = 1 << 1 | ||
| 26 | ECmdInfoFlagsNoInterp = 1 << 2 | ||
| 27 | ) | ||
| 28 | |||
| 29 | func (cmdInfoFlags CmdInfoFlags) String() string { | ||
| 30 | switch cmdInfoFlags { | ||
| 31 | case ECmdInfoFlagsNone: | ||
| 32 | return "None" | ||
| 33 | case ECmdInfoFlagsUseOrigin2: | ||
| 34 | return "UseOrigin2" | ||
| 35 | case ECmdInfoFlagsUserAngles2: | ||
| 36 | return "UserAngles2" | ||
| 37 | case ECmdInfoFlagsNoInterp: | ||
| 38 | return "NoInterp" | ||
| 39 | default: | ||
| 40 | return fmt.Sprintf("%d", int(cmdInfoFlags)) | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | func ParseCmdInfo(reader *bitreader.Reader) CmdInfo { | ||
| 45 | cmdInfo := CmdInfo{ | ||
| 46 | Flags: CmdInfoFlags(reader.TryReadUInt32()).String(), | ||
| 47 | ViewOrigin: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 48 | ViewAngles: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 49 | LocalViewAngles: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 50 | ViewOrigin2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 51 | ViewAngles2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 52 | LocalViewAngles2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 53 | } | ||
| 54 | writer.AppendLine("\tFlags: %s", cmdInfo.Flags) | ||
| 55 | writer.AppendLine("\tView Origin: %v", cmdInfo.ViewOrigin) | ||
| 56 | writer.AppendLine("\tView Angles: %v", cmdInfo.ViewAngles) | ||
| 57 | writer.AppendLine("\tLocal View Angles: %v", cmdInfo.LocalViewAngles) | ||
| 58 | writer.AppendLine("\tView Origin 2: %v", cmdInfo.ViewOrigin2) | ||
| 59 | writer.AppendLine("\tView Angles 2: %v", cmdInfo.ViewAngles2) | ||
| 60 | writer.AppendLine("\tLocal View Angles 2: %v", cmdInfo.LocalViewAngles2) | ||
| 61 | writer.AppendLine("") | ||
| 62 | return cmdInfo | ||
| 63 | } | ||
diff --git a/pkg/classes/consoleCmd.go b/pkg/classes/consoleCmd.go new file mode 100644 index 0000000..75a56eb --- /dev/null +++ b/pkg/classes/consoleCmd.go | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "strings" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 8 | ) | ||
| 9 | |||
| 10 | type ConsoleCmd struct { | ||
| 11 | Size int32 | ||
| 12 | Data string | ||
| 13 | } | ||
| 14 | |||
| 15 | func (consoleCmd *ConsoleCmd) ParseConsoleCmd(reader *bitreader.Reader) { | ||
| 16 | consoleCmd.Size = reader.TryReadSInt32() | ||
| 17 | consoleCmd.Data = reader.TryReadStringLength(uint64(consoleCmd.Size)) | ||
| 18 | writer.AppendLine("\t%s", strings.TrimSpace(consoleCmd.Data)) | ||
| 19 | } | ||
diff --git a/pkg/classes/customData.go b/pkg/classes/customData.go new file mode 100644 index 0000000..2dadde4 --- /dev/null +++ b/pkg/classes/customData.go | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 6 | ) | ||
| 7 | |||
| 8 | type CustomData struct { | ||
| 9 | Type int32 | ||
| 10 | Size int32 | ||
| 11 | Data string | ||
| 12 | } | ||
| 13 | |||
| 14 | func (customData *CustomData) ParseCustomData(reader *bitreader.Reader, tickNumber int32, packetType uint8) { | ||
| 15 | customData.Type = reader.TryReadSInt32() | ||
| 16 | customData.Size = reader.TryReadSInt32() | ||
| 17 | if customData.Type != 0 || customData.Size == 8 { | ||
| 18 | // Not SAR data | ||
| 19 | writer.AppendLine("[%d] %s (%d):", tickNumber, "CUSTOMDATA", packetType) | ||
| 20 | customData.Data = string(reader.TryReadBytesToSlice(uint64(customData.Size))) | ||
| 21 | writer.AppendLine("\t%s", customData.Data) | ||
| 22 | return | ||
| 23 | } | ||
| 24 | // SAR data | ||
| 25 | writer.AppendLine("[%d] %s (%d):", tickNumber, "SARDATA", packetType) | ||
| 26 | sarData := SarData{} | ||
| 27 | data := reader.TryReadBytesToSlice(uint64(customData.Size)) | ||
| 28 | sarReader := bitreader.NewReaderFromBytes(data, true) | ||
| 29 | sarData.ParseSarData(sarReader) | ||
| 30 | } | ||
diff --git a/pkg/classes/sendTable.go b/pkg/classes/dataTables.go index 927d967..27ab9e4 100644 --- a/pkg/classes/sendTable.go +++ b/pkg/classes/dataTables.go | |||
| @@ -7,6 +7,12 @@ import ( | |||
| 7 | "github.com/pektezol/demoparser/pkg/writer" | 7 | "github.com/pektezol/demoparser/pkg/writer" |
| 8 | ) | 8 | ) |
| 9 | 9 | ||
| 10 | type DataTables struct { | ||
| 11 | Size int32 | ||
| 12 | SendTable []SendTable | ||
| 13 | ServerClassInfo []ServerClassInfo | ||
| 14 | } | ||
| 15 | |||
| 10 | type SendTable struct { | 16 | type SendTable struct { |
| 11 | NeedsDecoder bool | 17 | NeedsDecoder bool |
| 12 | NetTableName string | 18 | NetTableName string |
| @@ -14,6 +20,12 @@ type SendTable struct { | |||
| 14 | Props []prop | 20 | Props []prop |
| 15 | } | 21 | } |
| 16 | 22 | ||
| 23 | type ServerClassInfo struct { | ||
| 24 | ClassId uint16 | ||
| 25 | ClassName string | ||
| 26 | DataTableName string | ||
| 27 | } | ||
| 28 | |||
| 17 | type prop struct { | 29 | type prop struct { |
| 18 | SendPropType sendPropType | 30 | SendPropType sendPropType |
| 19 | SendPropName string | 31 | SendPropName string |
| @@ -26,6 +38,95 @@ type prop struct { | |||
| 26 | NumElements int32 | 38 | NumElements int32 |
| 27 | } | 39 | } |
| 28 | 40 | ||
| 41 | func (dataTables *DataTables) ParseDataTables(reader *bitreader.Reader) { | ||
| 42 | dataTables.Size = int32(reader.TryReadSInt32()) | ||
| 43 | dataTableReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(uint64(dataTables.Size)), true) | ||
| 44 | count := 0 | ||
| 45 | for dataTableReader.TryReadBool() { | ||
| 46 | count++ | ||
| 47 | dataTables.SendTable = append(dataTables.SendTable, ParseSendTable(dataTableReader)) | ||
| 48 | } | ||
| 49 | writer.AppendLine("\t%d Send Tables:", count) | ||
| 50 | writer.AppendOutputFromTemp() | ||
| 51 | numOfClasses := dataTableReader.TryReadBits(16) | ||
| 52 | for count = 0; count < int(numOfClasses); count++ { | ||
| 53 | dataTables.ServerClassInfo = append(dataTables.ServerClassInfo, ParseServerClassInfo(dataTableReader, count, int(numOfClasses))) | ||
| 54 | } | ||
| 55 | writer.AppendLine("\t%d Classes:", count) | ||
| 56 | writer.AppendOutputFromTemp() | ||
| 57 | } | ||
| 58 | |||
| 59 | func ParseSendTable(reader *bitreader.Reader) SendTable { | ||
| 60 | sendTable := SendTable{ | ||
| 61 | NeedsDecoder: reader.TryReadBool(), | ||
| 62 | NetTableName: reader.TryReadString(), | ||
| 63 | NumOfProps: int16(reader.TryReadBits(10)), | ||
| 64 | } | ||
| 65 | if sendTable.NumOfProps < 0 { | ||
| 66 | return sendTable | ||
| 67 | } | ||
| 68 | writer.TempAppendLine("\t\t%s (%d Props):", sendTable.NetTableName, sendTable.NumOfProps) | ||
| 69 | for count := 0; count < int(sendTable.NumOfProps); count++ { | ||
| 70 | propType := int8(reader.TryReadBits(5)) | ||
| 71 | if propType >= int8(7) { | ||
| 72 | return sendTable | ||
| 73 | } | ||
| 74 | prop := prop{ | ||
| 75 | SendPropType: sendPropType(propType), | ||
| 76 | SendPropName: reader.TryReadString(), | ||
| 77 | SendPropFlags: uint32(reader.TryReadBits(19)), | ||
| 78 | Priority: reader.TryReadUInt8(), | ||
| 79 | } | ||
| 80 | writer.TempAppend("\t\t\t%s\t", prop.SendPropType) | ||
| 81 | if propType == int8(ESendPropTypeDataTable) || checkBit(prop.SendPropFlags, 6) { | ||
| 82 | prop.ExcludeDtName = reader.TryReadString() | ||
| 83 | writer.TempAppend(":\t%s\t", prop.ExcludeDtName) | ||
| 84 | } else { | ||
| 85 | switch propType { | ||
| 86 | case int8(ESendPropTypeString), int8(ESendPropTypeInt), int8(ESendPropTypeFloat), int8(ESendPropTypeVector3), int8(ESendPropTypeVector2): | ||
| 87 | prop.LowValue = reader.TryReadFloat32() | ||
| 88 | prop.HighValue = reader.TryReadFloat32() | ||
| 89 | prop.NumBits = int32(reader.TryReadBits(7)) | ||
| 90 | writer.TempAppend("Low: %f\tHigh: %f\t%d bits\t", prop.LowValue, prop.HighValue, prop.NumBits) | ||
| 91 | case int8(ESendPropTypeArray): | ||
| 92 | prop.NumElements = int32(reader.TryReadBits(10)) | ||
| 93 | writer.TempAppend("Elements: %d\t", prop.NumElements) | ||
| 94 | default: | ||
| 95 | writer.TempAppend("Unknown Prop Type: %v\t", propType) | ||
| 96 | return sendTable | ||
| 97 | } | ||
| 98 | } | ||
| 99 | writer.TempAppend("Flags: %v\tPriority: %d\n", prop.GetFlags(), prop.Priority) | ||
| 100 | sendTable.Props = append(sendTable.Props, prop) | ||
| 101 | } | ||
| 102 | return sendTable | ||
| 103 | } | ||
| 104 | |||
| 105 | func ParseServerClassInfo(reader *bitreader.Reader, count int, numOfClasses int) ServerClassInfo { | ||
| 106 | serverClassInfo := ServerClassInfo{ | ||
| 107 | ClassId: reader.TryReadUInt16(), | ||
| 108 | ClassName: reader.TryReadString(), | ||
| 109 | DataTableName: reader.TryReadString(), | ||
| 110 | } | ||
| 111 | writer.TempAppendLine("\t\t\t[%d] %s (%s)", serverClassInfo.ClassId, serverClassInfo.ClassName, serverClassInfo.DataTableName) | ||
| 112 | return serverClassInfo | ||
| 113 | } | ||
| 114 | |||
| 115 | // func serverClassBits(numOfClasses int) int { | ||
| 116 | // return highestBitIndex(uint(numOfClasses)) + 1 | ||
| 117 | // } | ||
| 118 | |||
| 119 | // func highestBitIndex(i uint) int { | ||
| 120 | // var j int | ||
| 121 | // for j = 31; j >= 0 && (i&(1<<j)) == 0; j-- { | ||
| 122 | // } | ||
| 123 | // return j | ||
| 124 | // } | ||
| 125 | |||
| 126 | func checkBit(val uint32, bit int) bool { | ||
| 127 | return (val & (uint32(1) << bit)) != 0 | ||
| 128 | } | ||
| 129 | |||
| 29 | type sendPropType int | 130 | type sendPropType int |
| 30 | 131 | ||
| 31 | const ( | 132 | const ( |
| @@ -142,53 +243,3 @@ func (sendPropType sendPropType) String() string { | |||
| 142 | return fmt.Sprintf("%d", int(sendPropType)) | 243 | return fmt.Sprintf("%d", int(sendPropType)) |
| 143 | } | 244 | } |
| 144 | } | 245 | } |
| 145 | |||
| 146 | func ParseSendTable(reader *bitreader.Reader) SendTable { | ||
| 147 | sendTable := SendTable{ | ||
| 148 | NeedsDecoder: reader.TryReadBool(), | ||
| 149 | NetTableName: reader.TryReadString(), | ||
| 150 | NumOfProps: int16(reader.TryReadBits(10)), | ||
| 151 | } | ||
| 152 | if sendTable.NumOfProps < 0 { | ||
| 153 | return sendTable | ||
| 154 | } | ||
| 155 | writer.TempAppendLine("\t\t%s (%d Props):", sendTable.NetTableName, sendTable.NumOfProps) | ||
| 156 | for count := 0; count < int(sendTable.NumOfProps); count++ { | ||
| 157 | propType := int8(reader.TryReadBits(5)) | ||
| 158 | if propType >= int8(7) { | ||
| 159 | return sendTable | ||
| 160 | } | ||
| 161 | prop := prop{ | ||
| 162 | SendPropType: sendPropType(propType), | ||
| 163 | SendPropName: reader.TryReadString(), | ||
| 164 | SendPropFlags: uint32(reader.TryReadBits(19)), | ||
| 165 | Priority: reader.TryReadUInt8(), | ||
| 166 | } | ||
| 167 | writer.TempAppend("\t\t\t%s\t", prop.SendPropType) | ||
| 168 | if propType == int8(ESendPropTypeDataTable) || checkBit(prop.SendPropFlags, 6) { | ||
| 169 | prop.ExcludeDtName = reader.TryReadString() | ||
| 170 | writer.TempAppend(":\t%s\t", prop.ExcludeDtName) | ||
| 171 | } else { | ||
| 172 | switch propType { | ||
| 173 | case int8(ESendPropTypeString), int8(ESendPropTypeInt), int8(ESendPropTypeFloat), int8(ESendPropTypeVector3), int8(ESendPropTypeVector2): | ||
| 174 | prop.LowValue = reader.TryReadFloat32() | ||
| 175 | prop.HighValue = reader.TryReadFloat32() | ||
| 176 | prop.NumBits = int32(reader.TryReadBits(7)) | ||
| 177 | writer.TempAppend("Low: %f\tHigh: %f\t%d bits\t", prop.LowValue, prop.HighValue, prop.NumBits) | ||
| 178 | case int8(ESendPropTypeArray): | ||
| 179 | prop.NumElements = int32(reader.TryReadBits(10)) | ||
| 180 | writer.TempAppend("Elements: %d\t", prop.NumElements) | ||
| 181 | default: | ||
| 182 | writer.TempAppend("Unknown Prop Type: %v\t", propType) | ||
| 183 | return sendTable | ||
| 184 | } | ||
| 185 | } | ||
| 186 | writer.TempAppend("Flags: %v\tPriority: %d\n", prop.GetFlags(), prop.Priority) | ||
| 187 | sendTable.Props = append(sendTable.Props, prop) | ||
| 188 | } | ||
| 189 | return sendTable | ||
| 190 | } | ||
| 191 | |||
| 192 | func checkBit(val uint32, bit int) bool { | ||
| 193 | return (val & (uint32(1) << bit)) != 0 | ||
| 194 | } | ||
diff --git a/pkg/classes/packet.go b/pkg/classes/packet.go new file mode 100644 index 0000000..0bba102 --- /dev/null +++ b/pkg/classes/packet.go | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | "github.com/pektezol/demoparser/pkg/messages" | ||
| 8 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 9 | ) | ||
| 10 | |||
| 11 | const MSSC int = 2 | ||
| 12 | |||
| 13 | type Packet struct { | ||
| 14 | PacketInfo []CmdInfo | ||
| 15 | InSequence uint32 | ||
| 16 | OutSequence uint32 | ||
| 17 | Size uint32 | ||
| 18 | Data []any | ||
| 19 | } | ||
| 20 | |||
| 21 | type CmdInfo struct { | ||
| 22 | Flags uint32 | ||
| 23 | ViewOrigin []float32 | ||
| 24 | ViewAngles []float32 | ||
| 25 | LocalViewAngles []float32 | ||
| 26 | ViewOrigin2 []float32 | ||
| 27 | ViewAngles2 []float32 | ||
| 28 | LocalViewAngles2 []float32 | ||
| 29 | } | ||
| 30 | |||
| 31 | func (packet *Packet) ParsePacket(reader *bitreader.Reader) { | ||
| 32 | for count := 0; count < MSSC; count++ { | ||
| 33 | packet.ParseCmdInfo(reader) | ||
| 34 | } | ||
| 35 | packet.InSequence = reader.TryReadUInt32() | ||
| 36 | packet.OutSequence = reader.TryReadUInt32() | ||
| 37 | packet.Size = reader.TryReadUInt32() | ||
| 38 | packetReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(uint64(packet.Size)), true) | ||
| 39 | for { | ||
| 40 | messageType, err := packetReader.ReadBits(6) | ||
| 41 | if err != nil { | ||
| 42 | break | ||
| 43 | } | ||
| 44 | packet.Data = append(packet.Data, messages.ParseMessages(messageType, packetReader)) | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | func (packet *Packet) ParseCmdInfo(reader *bitreader.Reader) { | ||
| 49 | packet.PacketInfo = append(packet.PacketInfo, CmdInfo{ | ||
| 50 | Flags: reader.TryReadUInt32(), | ||
| 51 | ViewOrigin: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 52 | ViewAngles: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 53 | LocalViewAngles: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 54 | ViewOrigin2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 55 | ViewAngles2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 56 | LocalViewAngles2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 57 | }) | ||
| 58 | writer.AppendLine("\tFlags: %s", CmdInfoFlags(packet.PacketInfo[len(packet.PacketInfo)-1].Flags).String()) | ||
| 59 | writer.AppendLine("\tView Origin: %v", packet.PacketInfo[len(packet.PacketInfo)-1].ViewOrigin) | ||
| 60 | writer.AppendLine("\tView Angles: %v", packet.PacketInfo[len(packet.PacketInfo)-1].ViewAngles) | ||
| 61 | writer.AppendLine("\tLocal View Angles: %v", packet.PacketInfo[len(packet.PacketInfo)-1].LocalViewAngles) | ||
| 62 | writer.AppendLine("\tView Origin 2: %v", packet.PacketInfo[len(packet.PacketInfo)-1].ViewOrigin2) | ||
| 63 | writer.AppendLine("\tView Angles 2: %v", packet.PacketInfo[len(packet.PacketInfo)-1].ViewAngles2) | ||
| 64 | writer.AppendLine("\tLocal View Angles 2: %v", packet.PacketInfo[len(packet.PacketInfo)-1].LocalViewAngles2) | ||
| 65 | writer.AppendLine("") | ||
| 66 | } | ||
| 67 | |||
| 68 | type CmdInfoFlags int | ||
| 69 | |||
| 70 | const ( | ||
| 71 | ECmdInfoFlagsNone = 0 | ||
| 72 | ECmdInfoFlagsUseOrigin2 = 1 | ||
| 73 | ECmdInfoFlagsUserAngles2 = 1 << 1 | ||
| 74 | ECmdInfoFlagsNoInterp = 1 << 2 | ||
| 75 | ) | ||
| 76 | |||
| 77 | func (cmdInfoFlags CmdInfoFlags) String() string { | ||
| 78 | switch cmdInfoFlags { | ||
| 79 | case ECmdInfoFlagsNone: | ||
| 80 | return "None" | ||
| 81 | case ECmdInfoFlagsUseOrigin2: | ||
| 82 | return "UseOrigin2" | ||
| 83 | case ECmdInfoFlagsUserAngles2: | ||
| 84 | return "UserAngles2" | ||
| 85 | case ECmdInfoFlagsNoInterp: | ||
| 86 | return "NoInterp" | ||
| 87 | default: | ||
| 88 | return fmt.Sprintf("%d", int(cmdInfoFlags)) | ||
| 89 | } | ||
| 90 | } | ||
diff --git a/pkg/classes/serverClassInfo.go b/pkg/classes/serverClassInfo.go deleted file mode 100644 index c0d2a2a..0000000 --- a/pkg/classes/serverClassInfo.go +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 6 | ) | ||
| 7 | |||
| 8 | type ServerClassInfo struct { | ||
| 9 | ClassId uint16 | ||
| 10 | ClassName string | ||
| 11 | DataTableName string | ||
| 12 | } | ||
| 13 | |||
| 14 | func ParseServerClassInfo(reader *bitreader.Reader, count int, numOfClasses int) ServerClassInfo { | ||
| 15 | serverClassInfo := ServerClassInfo{ | ||
| 16 | ClassId: reader.TryReadUInt16(), | ||
| 17 | ClassName: reader.TryReadString(), | ||
| 18 | DataTableName: reader.TryReadString(), | ||
| 19 | } | ||
| 20 | writer.TempAppendLine("\t\t\t[%d] %s (%s)", serverClassInfo.ClassId, serverClassInfo.ClassName, serverClassInfo.DataTableName) | ||
| 21 | return serverClassInfo | ||
| 22 | } | ||
| 23 | |||
| 24 | // func serverClassBits(numOfClasses int) int { | ||
| 25 | // return highestBitIndex(uint(numOfClasses)) + 1 | ||
| 26 | // } | ||
| 27 | |||
| 28 | // func highestBitIndex(i uint) int { | ||
| 29 | // var j int | ||
| 30 | // for j = 31; j >= 0 && (i&(1<<j)) == 0; j-- { | ||
| 31 | // } | ||
| 32 | // return j | ||
| 33 | // } | ||
diff --git a/pkg/classes/signOn.go b/pkg/classes/signOn.go new file mode 100644 index 0000000..fad696c --- /dev/null +++ b/pkg/classes/signOn.go | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | "github.com/pektezol/demoparser/pkg/messages" | ||
| 6 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 7 | ) | ||
| 8 | |||
| 9 | type SignOn struct { | ||
| 10 | PacketInfo []CmdInfo | ||
| 11 | InSequence uint32 | ||
| 12 | OutSequence uint32 | ||
| 13 | Size uint32 | ||
| 14 | Data []any | ||
| 15 | } | ||
| 16 | |||
| 17 | func (signOn *SignOn) ParseSignOn(reader *bitreader.Reader) { | ||
| 18 | for count := 0; count < MSSC; count++ { | ||
| 19 | signOn.ParseCmdInfo(reader) | ||
| 20 | } | ||
| 21 | signOn.InSequence = reader.TryReadUInt32() | ||
| 22 | signOn.OutSequence = reader.TryReadUInt32() | ||
| 23 | signOn.Size = reader.TryReadUInt32() | ||
| 24 | packetReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(uint64(signOn.Size)), true) | ||
| 25 | for { | ||
| 26 | messageType, err := packetReader.ReadBits(6) | ||
| 27 | if err != nil { | ||
| 28 | break | ||
| 29 | } | ||
| 30 | signOn.Data = append(signOn.Data, messages.ParseMessages(messageType, packetReader)) | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | func (signOn *SignOn) ParseCmdInfo(reader *bitreader.Reader) { | ||
| 35 | signOn.PacketInfo = append(signOn.PacketInfo, CmdInfo{ | ||
| 36 | Flags: reader.TryReadUInt32(), | ||
| 37 | ViewOrigin: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 38 | ViewAngles: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 39 | LocalViewAngles: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 40 | ViewOrigin2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 41 | ViewAngles2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 42 | LocalViewAngles2: []float32{reader.TryReadFloat32(), reader.TryReadFloat32(), reader.TryReadFloat32()}, | ||
| 43 | }) | ||
| 44 | writer.AppendLine("\tFlags: %s", CmdInfoFlags(signOn.PacketInfo[len(signOn.PacketInfo)-1].Flags).String()) | ||
| 45 | writer.AppendLine("\tView Origin: %v", signOn.PacketInfo[len(signOn.PacketInfo)-1].ViewOrigin) | ||
| 46 | writer.AppendLine("\tView Angles: %v", signOn.PacketInfo[len(signOn.PacketInfo)-1].ViewAngles) | ||
| 47 | writer.AppendLine("\tLocal View Angles: %v", signOn.PacketInfo[len(signOn.PacketInfo)-1].LocalViewAngles) | ||
| 48 | writer.AppendLine("\tView Origin 2: %v", signOn.PacketInfo[len(signOn.PacketInfo)-1].ViewOrigin2) | ||
| 49 | writer.AppendLine("\tView Angles 2: %v", signOn.PacketInfo[len(signOn.PacketInfo)-1].ViewAngles2) | ||
| 50 | writer.AppendLine("\tLocal View Angles 2: %v", signOn.PacketInfo[len(signOn.PacketInfo)-1].LocalViewAngles2) | ||
| 51 | writer.AppendLine("") | ||
| 52 | } | ||
diff --git a/pkg/classes/stop.go b/pkg/classes/stop.go new file mode 100644 index 0000000..753be19 --- /dev/null +++ b/pkg/classes/stop.go | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 6 | ) | ||
| 7 | |||
| 8 | type Stop struct { | ||
| 9 | RemainingData []byte | ||
| 10 | } | ||
| 11 | |||
| 12 | func (stop *Stop) ParseStop(reader *bitreader.Reader) { | ||
| 13 | if reader.TryReadBool() { | ||
| 14 | stop.RemainingData = reader.TryReadBitsToSlice(uint64(reader.TryReadRemainingBits())) | ||
| 15 | writer.AppendLine("\tRemaining Data: %v", stop.RemainingData) | ||
| 16 | } | ||
| 17 | } | ||
diff --git a/pkg/classes/stringTable.go b/pkg/classes/stringTables.go index 44d8a73..01939b2 100644 --- a/pkg/classes/stringTable.go +++ b/pkg/classes/stringTables.go | |||
| @@ -5,6 +5,11 @@ import ( | |||
| 5 | "github.com/pektezol/demoparser/pkg/writer" | 5 | "github.com/pektezol/demoparser/pkg/writer" |
| 6 | ) | 6 | ) |
| 7 | 7 | ||
| 8 | type StringTables struct { | ||
| 9 | Size int32 | ||
| 10 | Data []StringTable | ||
| 11 | } | ||
| 12 | |||
| 8 | type StringTable struct { | 13 | type StringTable struct { |
| 9 | Name string | 14 | Name string |
| 10 | TableEntries []StringTableEntry | 15 | TableEntries []StringTableEntry |
| @@ -25,15 +30,17 @@ type StringTableClass struct { | |||
| 25 | Data string | 30 | Data string |
| 26 | } | 31 | } |
| 27 | 32 | ||
| 28 | func ParseStringTables(reader *bitreader.Reader) []StringTable { | 33 | func (stringTables *StringTables) ParseStringTables(reader *bitreader.Reader) { |
| 29 | tableCount := reader.TryReadBits(8) | 34 | stringTables.Size = reader.TryReadSInt32() |
| 30 | stringTables := make([]StringTable, tableCount) | 35 | stringTableReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(uint64(stringTables.Size)), true) |
| 36 | tableCount := stringTableReader.TryReadBits(8) | ||
| 37 | tables := make([]StringTable, tableCount) | ||
| 31 | for i := 0; i < int(tableCount); i++ { | 38 | for i := 0; i < int(tableCount); i++ { |
| 32 | var table StringTable | 39 | var table StringTable |
| 33 | table.ParseStream(reader) | 40 | table.ParseStream(stringTableReader) |
| 34 | stringTables[i] = table | 41 | tables[i] = table |
| 35 | } | 42 | } |
| 36 | return stringTables | 43 | stringTables.Data = tables |
| 37 | } | 44 | } |
| 38 | 45 | ||
| 39 | func (stringTable *StringTable) ParseStream(reader *bitreader.Reader) { | 46 | func (stringTable *StringTable) ParseStream(reader *bitreader.Reader) { |
diff --git a/pkg/classes/syncTick.go b/pkg/classes/syncTick.go new file mode 100644 index 0000000..2f9df3e --- /dev/null +++ b/pkg/classes/syncTick.go | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | type SyncTick struct{} | ||
| 4 | |||
| 5 | func (syncTick *SyncTick) ParseSyncTick() {} | ||
diff --git a/pkg/classes/userCmd.go b/pkg/classes/userCmd.go new file mode 100644 index 0000000..24969f1 --- /dev/null +++ b/pkg/classes/userCmd.go | |||
| @@ -0,0 +1,231 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 6 | ) | ||
| 7 | |||
| 8 | type UserCmd struct { | ||
| 9 | Cmd uint32 | ||
| 10 | Size uint32 | ||
| 11 | Data UserCmdInfo | ||
| 12 | } | ||
| 13 | |||
| 14 | type UserCmdInfo struct { | ||
| 15 | CommandNumber uint32 | ||
| 16 | TickCount uint32 | ||
| 17 | ViewAnglesX float32 | ||
| 18 | ViewAnglesY float32 | ||
| 19 | ViewAnglesZ float32 | ||
| 20 | ForwardMove float32 | ||
| 21 | SideMove float32 | ||
| 22 | UpMove float32 | ||
| 23 | Buttons uint32 | ||
| 24 | Impulse uint8 | ||
| 25 | WeaponSelect uint16 | ||
| 26 | WeaponSubType uint8 | ||
| 27 | MouseDx uint16 | ||
| 28 | MouseDy uint16 | ||
| 29 | } | ||
| 30 | |||
| 31 | func (userCmd *UserCmd) ParseUserCmd(reader *bitreader.Reader) { | ||
| 32 | userCmd.Cmd = reader.TryReadUInt32() | ||
| 33 | userCmd.Size = reader.TryReadUInt32() | ||
| 34 | userCmdReader := bitreader.NewReaderFromBytes(reader.TryReadBytesToSlice(uint64(userCmd.Size)), true) | ||
| 35 | userCmd.ParseUserCmdInfo(userCmdReader) | ||
| 36 | } | ||
| 37 | |||
| 38 | func (userCmd *UserCmd) ParseUserCmdInfo(reader *bitreader.Reader) { | ||
| 39 | if reader.TryReadBool() { | ||
| 40 | userCmd.Data.CommandNumber = reader.TryReadUInt32() | ||
| 41 | } | ||
| 42 | if reader.TryReadBool() { | ||
| 43 | userCmd.Data.TickCount = reader.TryReadUInt32() | ||
| 44 | } | ||
| 45 | if reader.TryReadBool() { | ||
| 46 | userCmd.Data.ViewAnglesX = reader.TryReadFloat32() | ||
| 47 | } | ||
| 48 | if reader.TryReadBool() { | ||
| 49 | userCmd.Data.ViewAnglesY = reader.TryReadFloat32() | ||
| 50 | } | ||
| 51 | if reader.TryReadBool() { | ||
| 52 | userCmd.Data.ViewAnglesZ = reader.TryReadFloat32() | ||
| 53 | } | ||
| 54 | if reader.TryReadBool() { | ||
| 55 | userCmd.Data.ForwardMove = reader.TryReadFloat32() | ||
| 56 | } | ||
| 57 | if reader.TryReadBool() { | ||
| 58 | userCmd.Data.SideMove = reader.TryReadFloat32() | ||
| 59 | } | ||
| 60 | if reader.TryReadBool() { | ||
| 61 | userCmd.Data.UpMove = reader.TryReadFloat32() | ||
| 62 | } | ||
| 63 | if reader.TryReadBool() { | ||
| 64 | userCmd.Data.Buttons = reader.TryReadUInt32() | ||
| 65 | } | ||
| 66 | if reader.TryReadBool() { | ||
| 67 | userCmd.Data.Impulse = reader.TryReadUInt8() | ||
| 68 | } | ||
| 69 | if reader.TryReadBool() { | ||
| 70 | userCmd.Data.WeaponSelect = uint16(reader.TryReadBits(11)) | ||
| 71 | if reader.TryReadBool() { | ||
| 72 | userCmd.Data.WeaponSubType = uint8(reader.TryReadBits(6)) | ||
| 73 | } | ||
| 74 | } | ||
| 75 | if reader.TryReadBool() { | ||
| 76 | userCmd.Data.MouseDx = reader.TryReadUInt16() | ||
| 77 | } | ||
| 78 | if reader.TryReadBool() { | ||
| 79 | userCmd.Data.MouseDy = reader.TryReadUInt16() | ||
| 80 | } | ||
| 81 | writer.AppendLine("\tCommand Number: %v", userCmd.Data.CommandNumber) | ||
| 82 | writer.AppendLine("\tTick Count: %v", userCmd.Data.TickCount) | ||
| 83 | writer.AppendLine("\tView Angles: %v", []float32{userCmd.Data.ViewAnglesX, userCmd.Data.ViewAnglesY, userCmd.Data.ViewAnglesZ}) | ||
| 84 | writer.AppendLine("\tMovement: %v", []float32{userCmd.Data.ForwardMove, userCmd.Data.SideMove, userCmd.Data.UpMove}) | ||
| 85 | writer.AppendLine("\tButtons: %v", Buttons(userCmd.Data.Buttons).GetButtons()) | ||
| 86 | writer.AppendLine("\tImpulse: %v", userCmd.Data.Impulse) | ||
| 87 | writer.AppendLine("\tWeapon, Subtype: %v, %v", userCmd.Data.WeaponSelect, userCmd.Data.WeaponSubType) | ||
| 88 | writer.AppendLine("\tMouse Dx, Mouse Dy: %v, %v", userCmd.Data.MouseDx, userCmd.Data.MouseDy) | ||
| 89 | } | ||
| 90 | |||
| 91 | func (button Buttons) GetButtons() []string { | ||
| 92 | flags := []string{} | ||
| 93 | if button == 0 { | ||
| 94 | flags = append(flags, EButtonsNone) | ||
| 95 | } | ||
| 96 | if checkBit(uint32(button), 0) { | ||
| 97 | flags = append(flags, EButtonsAttack) | ||
| 98 | } | ||
| 99 | if checkBit(uint32(button), 1) { | ||
| 100 | flags = append(flags, EButtonsJump) | ||
| 101 | } | ||
| 102 | if checkBit(uint32(button), 2) { | ||
| 103 | flags = append(flags, EButtonsDuck) | ||
| 104 | } | ||
| 105 | if checkBit(uint32(button), 3) { | ||
| 106 | flags = append(flags, EButtonsForward) | ||
| 107 | } | ||
| 108 | if checkBit(uint32(button), 4) { | ||
| 109 | flags = append(flags, EButtonsBack) | ||
| 110 | } | ||
| 111 | if checkBit(uint32(button), 5) { | ||
| 112 | flags = append(flags, EButtonsUse) | ||
| 113 | } | ||
| 114 | if checkBit(uint32(button), 6) { | ||
| 115 | flags = append(flags, EButtonsCancel) | ||
| 116 | } | ||
| 117 | if checkBit(uint32(button), 7) { | ||
| 118 | flags = append(flags, EButtonsLeft) | ||
| 119 | } | ||
| 120 | if checkBit(uint32(button), 8) { | ||
| 121 | flags = append(flags, EButtonsRight) | ||
| 122 | } | ||
| 123 | if checkBit(uint32(button), 9) { | ||
| 124 | flags = append(flags, EButtonsMoveLeft) | ||
| 125 | } | ||
| 126 | if checkBit(uint32(button), 10) { | ||
| 127 | flags = append(flags, EButtonsMoveRight) | ||
| 128 | } | ||
| 129 | if checkBit(uint32(button), 11) { | ||
| 130 | flags = append(flags, EButtonsAttack2) | ||
| 131 | } | ||
| 132 | if checkBit(uint32(button), 12) { | ||
| 133 | flags = append(flags, EButtonsRun) | ||
| 134 | } | ||
| 135 | if checkBit(uint32(button), 13) { | ||
| 136 | flags = append(flags, EButtonsReload) | ||
| 137 | } | ||
| 138 | if checkBit(uint32(button), 14) { | ||
| 139 | flags = append(flags, EButtonsAlt1) | ||
| 140 | } | ||
| 141 | if checkBit(uint32(button), 15) { | ||
| 142 | flags = append(flags, EButtonsAlt2) | ||
| 143 | } | ||
| 144 | if checkBit(uint32(button), 16) { | ||
| 145 | flags = append(flags, EButtonsScore) | ||
| 146 | } | ||
| 147 | if checkBit(uint32(button), 17) { | ||
| 148 | flags = append(flags, EButtonsSpeed) | ||
| 149 | } | ||
| 150 | if checkBit(uint32(button), 18) { | ||
| 151 | flags = append(flags, EButtonsWalk) | ||
| 152 | } | ||
| 153 | if checkBit(uint32(button), 19) { | ||
| 154 | flags = append(flags, EButtonsZoom) | ||
| 155 | } | ||
| 156 | if checkBit(uint32(button), 20) { | ||
| 157 | flags = append(flags, EButtonsWeapon1) | ||
| 158 | } | ||
| 159 | if checkBit(uint32(button), 21) { | ||
| 160 | flags = append(flags, EButtonsWeapon2) | ||
| 161 | } | ||
| 162 | if checkBit(uint32(button), 22) { | ||
| 163 | flags = append(flags, EButtonsBullRush) | ||
| 164 | } | ||
| 165 | if checkBit(uint32(button), 23) { | ||
| 166 | flags = append(flags, EButtonsGrenade1) | ||
| 167 | } | ||
| 168 | if checkBit(uint32(button), 24) { | ||
| 169 | flags = append(flags, EButtonsGrenade2) | ||
| 170 | } | ||
| 171 | if checkBit(uint32(button), 25) { | ||
| 172 | flags = append(flags, EButtonsLookSpin) | ||
| 173 | } | ||
| 174 | if checkBit(uint32(button), 26) { | ||
| 175 | flags = append(flags, EButtonsCurrentAbility) | ||
| 176 | } | ||
| 177 | if checkBit(uint32(button), 27) { | ||
| 178 | flags = append(flags, EButtonsPreviousAbility) | ||
| 179 | } | ||
| 180 | if checkBit(uint32(button), 28) { | ||
| 181 | flags = append(flags, EButtonsAbility1) | ||
| 182 | } | ||
| 183 | if checkBit(uint32(button), 29) { | ||
| 184 | flags = append(flags, EButtonsAbility2) | ||
| 185 | } | ||
| 186 | if checkBit(uint32(button), 30) { | ||
| 187 | flags = append(flags, EButtonsAbility3) | ||
| 188 | } | ||
| 189 | if checkBit(uint32(button), 31) { | ||
| 190 | flags = append(flags, EButtonsAbility4) | ||
| 191 | } | ||
| 192 | return flags | ||
| 193 | } | ||
| 194 | |||
| 195 | type Buttons int | ||
| 196 | |||
| 197 | const ( | ||
| 198 | EButtonsNone string = "None" | ||
| 199 | EButtonsAttack string = "Attack" | ||
| 200 | EButtonsJump string = "Jump" | ||
| 201 | EButtonsDuck string = "Duck" | ||
| 202 | EButtonsForward string = "Forward" | ||
| 203 | EButtonsBack string = "Back" | ||
| 204 | EButtonsUse string = "Use" | ||
| 205 | EButtonsCancel string = "Cancel" | ||
| 206 | EButtonsLeft string = "Left" | ||
| 207 | EButtonsRight string = "Right" | ||
| 208 | EButtonsMoveLeft string = "MoveLeft" | ||
| 209 | EButtonsMoveRight string = "MoveRight" | ||
| 210 | EButtonsAttack2 string = "Attack2" | ||
| 211 | EButtonsRun string = "Run" | ||
| 212 | EButtonsReload string = "Reload" | ||
| 213 | EButtonsAlt1 string = "Alt1" | ||
| 214 | EButtonsAlt2 string = "Alt2" | ||
| 215 | EButtonsScore string = "Score" | ||
| 216 | EButtonsSpeed string = "Speed" | ||
| 217 | EButtonsWalk string = "Walk" | ||
| 218 | EButtonsZoom string = "Zoom" | ||
| 219 | EButtonsWeapon1 string = "Weapon1" | ||
| 220 | EButtonsWeapon2 string = "Weapon2" | ||
| 221 | EButtonsBullRush string = "BullRush" | ||
| 222 | EButtonsGrenade1 string = "Grenade1" | ||
| 223 | EButtonsGrenade2 string = "Grenade2" | ||
| 224 | EButtonsLookSpin string = "LookSpin" | ||
| 225 | EButtonsCurrentAbility string = "CurrentAbility" | ||
| 226 | EButtonsPreviousAbility string = "PreviousAbility" | ||
| 227 | EButtonsAbility1 string = "Ability1" | ||
| 228 | EButtonsAbility2 string = "Ability2" | ||
| 229 | EButtonsAbility3 string = "Ability3" | ||
| 230 | EButtonsAbility4 string = "Ability4" | ||
| 231 | ) | ||
diff --git a/pkg/classes/userCmdInfo.go b/pkg/classes/userCmdInfo.go deleted file mode 100644 index f1bb613..0000000 --- a/pkg/classes/userCmdInfo.go +++ /dev/null | |||
| @@ -1,87 +0,0 @@ | |||
| 1 | package classes | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bytes" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | "github.com/pektezol/demoparser/pkg/writer" | ||
| 8 | ) | ||
| 9 | |||
| 10 | type UserCmdInfo struct { | ||
| 11 | CommandNumber int32 | ||
| 12 | TickCount int32 | ||
| 13 | ViewAnglesX float32 | ||
| 14 | ViewAnglesY float32 | ||
| 15 | ViewAnglesZ float32 | ||
| 16 | ForwardMove float32 | ||
| 17 | SideMove float32 | ||
| 18 | UpMove float32 | ||
| 19 | Buttons int32 | ||
| 20 | Impulse int8 | ||
| 21 | WeaponSelect int16 | ||
| 22 | WeaponSubType int8 | ||
| 23 | MouseDx int16 | ||
| 24 | MouseDy int16 | ||
| 25 | } | ||
| 26 | |||
| 27 | func ParseUserCmdInfo(data []byte) UserCmdInfo { | ||
| 28 | reader := bitreader.NewReader(bytes.NewReader(data), true) | ||
| 29 | userCmdInfo := UserCmdInfo{} | ||
| 30 | if reader.TryReadBool() { | ||
| 31 | userCmdInfo.CommandNumber = int32(reader.TryReadBits(32)) | ||
| 32 | } | ||
| 33 | if reader.TryReadBool() { | ||
| 34 | userCmdInfo.TickCount = int32(reader.TryReadBits(32)) | ||
| 35 | } | ||
| 36 | if reader.TryReadBool() { | ||
| 37 | userCmdInfo.ViewAnglesX = reader.TryReadFloat32() | ||
| 38 | } | ||
| 39 | if reader.TryReadBool() { | ||
| 40 | userCmdInfo.ViewAnglesY = reader.TryReadFloat32() | ||
| 41 | } | ||
| 42 | if reader.TryReadBool() { | ||
| 43 | userCmdInfo.ViewAnglesZ = reader.TryReadFloat32() | ||
| 44 | } | ||
| 45 | if reader.TryReadBool() { | ||
| 46 | userCmdInfo.ForwardMove = reader.TryReadFloat32() | ||
| 47 | } | ||
| 48 | if reader.TryReadBool() { | ||
| 49 | userCmdInfo.SideMove = reader.TryReadFloat32() | ||
| 50 | } | ||
| 51 | if reader.TryReadBool() { | ||
| 52 | userCmdInfo.UpMove = reader.TryReadFloat32() | ||
| 53 | } | ||
| 54 | if reader.TryReadBool() { | ||
| 55 | userCmdInfo.Buttons = int32(reader.TryReadBits(32)) | ||
| 56 | } | ||
| 57 | if reader.TryReadBool() { | ||
| 58 | userCmdInfo.Impulse = int8(reader.TryReadBits(8)) | ||
| 59 | } | ||
| 60 | if reader.TryReadBool() { | ||
| 61 | userCmdInfo.WeaponSelect = int16(reader.TryReadBits(11)) | ||
| 62 | if reader.TryReadBool() { | ||
| 63 | userCmdInfo.WeaponSubType = int8(reader.TryReadBits(6)) | ||
| 64 | } | ||
| 65 | } | ||
| 66 | if reader.TryReadBool() { | ||
| 67 | userCmdInfo.MouseDx = int16(reader.TryReadBits(16)) | ||
| 68 | } | ||
| 69 | if reader.TryReadBool() { | ||
| 70 | userCmdInfo.MouseDy = int16(reader.TryReadBits(16)) | ||
| 71 | } | ||
| 72 | writer.AppendLine("\tCommand Number: %v", userCmdInfo.CommandNumber) | ||
| 73 | writer.AppendLine("\tTick Count: %v", userCmdInfo.TickCount) | ||
| 74 | writer.AppendLine("\tView Angles X: %v", userCmdInfo.ViewAnglesX) | ||
| 75 | writer.AppendLine("\tView Angles Y: %v", userCmdInfo.ViewAnglesY) | ||
| 76 | writer.AppendLine("\tView Angles Z: %v", userCmdInfo.ViewAnglesZ) | ||
| 77 | writer.AppendLine("\tForward Move: %v", userCmdInfo.ForwardMove) | ||
| 78 | writer.AppendLine("\tSide Move: %v", userCmdInfo.SideMove) | ||
| 79 | writer.AppendLine("\tUp Move: %v", userCmdInfo.UpMove) | ||
| 80 | writer.AppendLine("\tButtons: %v", userCmdInfo.Buttons) | ||
| 81 | writer.AppendLine("\tImpulse: %v", userCmdInfo.Impulse) | ||
| 82 | writer.AppendLine("\tWeapon Select: %v", userCmdInfo.WeaponSelect) | ||
| 83 | writer.AppendLine("\tWeapon Sub Type: %v", userCmdInfo.WeaponSubType) | ||
| 84 | writer.AppendLine("\tMouse Dx: %v", userCmdInfo.MouseDx) | ||
| 85 | writer.AppendLine("\tMouse Dy: %v", userCmdInfo.MouseDy) | ||
| 86 | return userCmdInfo | ||
| 87 | } | ||
diff --git a/pkg/messages/messages.go b/pkg/messages/messages.go index efa9460..5cc781d 100644 --- a/pkg/messages/messages.go +++ b/pkg/messages/messages.go | |||
| @@ -8,7 +8,7 @@ import ( | |||
| 8 | "github.com/pektezol/demoparser/pkg/writer" | 8 | "github.com/pektezol/demoparser/pkg/writer" |
| 9 | ) | 9 | ) |
| 10 | 10 | ||
| 11 | func ParseMessages(messageType int, reader *bitreader.Reader) any { | 11 | func ParseMessages(messageType uint64, reader *bitreader.Reader) any { |
| 12 | var messageData any | 12 | var messageData any |
| 13 | switch messageType { | 13 | switch messageType { |
| 14 | case 0: | 14 | case 0: |
diff --git a/pkg/packets/packets.go b/pkg/packets/packets.go index 33350d5..b1d6a40 100644 --- a/pkg/packets/packets.go +++ b/pkg/packets/packets.go | |||
| @@ -3,7 +3,6 @@ package packets | |||
| 3 | import ( | 3 | import ( |
| 4 | "github.com/pektezol/bitreader" | 4 | "github.com/pektezol/bitreader" |
| 5 | "github.com/pektezol/demoparser/pkg/classes" | 5 | "github.com/pektezol/demoparser/pkg/classes" |
| 6 | "github.com/pektezol/demoparser/pkg/messages" | ||
| 7 | "github.com/pektezol/demoparser/pkg/writer" | 6 | "github.com/pektezol/demoparser/pkg/writer" |
| 8 | ) | 7 | ) |
| 9 | 8 | ||
| @@ -11,130 +10,49 @@ type PacketMessageInfo struct { | |||
| 11 | PacketType uint8 | 10 | PacketType uint8 |
| 12 | TickNumber int32 | 11 | TickNumber int32 |
| 13 | SlotNumber uint8 | 12 | SlotNumber uint8 |
| 14 | Data any | ||
| 15 | } | 13 | } |
| 16 | 14 | ||
| 17 | const MSSC int = 2 | ||
| 18 | |||
| 19 | func ParsePackets(reader *bitreader.Reader) PacketMessageInfo { | 15 | func ParsePackets(reader *bitreader.Reader) PacketMessageInfo { |
| 20 | packetType := reader.TryReadUInt8() | 16 | packetType := reader.TryReadUInt8() |
| 21 | tickNumber := reader.TryReadSInt32() | 17 | tickNumber := reader.TryReadSInt32() |
| 22 | slotNumber := reader.TryReadUInt8() | 18 | slotNumber := reader.TryReadUInt8() |
| 23 | var packetData any | ||
| 24 | switch packetType { | 19 | switch packetType { |
| 25 | case 1: // SignOn | 20 | case 1: // SignOn |
| 26 | signOn := SignOn{} | ||
| 27 | writer.AppendLine("[%d] %s (%d):", tickNumber, "SIGNON", packetType) | 21 | writer.AppendLine("[%d] %s (%d):", tickNumber, "SIGNON", packetType) |
| 28 | for count := 0; count < MSSC; count++ { | 22 | signOn := classes.SignOn{} |
| 29 | signOn.PacketInfo = append(signOn.PacketInfo, classes.ParseCmdInfo(reader)) | 23 | signOn.ParseSignOn(reader) |
| 30 | } | ||
| 31 | signOn.InSequence = int32(reader.TryReadBits(32)) | ||
| 32 | signOn.OutSequence = int32(reader.TryReadBits(32)) | ||
| 33 | signOn.Size = int32(reader.TryReadSInt32()) | ||
| 34 | data := reader.TryReadBytesToSlice(uint64(signOn.Size)) | ||
| 35 | packetReader := bitreader.NewReaderFromBytes(data, true) | ||
| 36 | for { | ||
| 37 | messageType, err := packetReader.ReadBits(6) | ||
| 38 | if err != nil { | ||
| 39 | break | ||
| 40 | } | ||
| 41 | signOn.Data = append(signOn.Data, messages.ParseMessages(int(messageType), packetReader)) | ||
| 42 | } | ||
| 43 | packetData = signOn | ||
| 44 | case 2: // Packet | 24 | case 2: // Packet |
| 45 | packet := Packet{} | ||
| 46 | writer.AppendLine("[%d] %s (%d):", tickNumber, "PACKET", packetType) | 25 | writer.AppendLine("[%d] %s (%d):", tickNumber, "PACKET", packetType) |
| 47 | for count := 0; count < MSSC; count++ { | 26 | packet := classes.Packet{} |
| 48 | packet.PacketInfo = append(packet.PacketInfo, classes.ParseCmdInfo(reader)) | 27 | packet.ParsePacket(reader) |
| 49 | } | ||
| 50 | packet.InSequence = int32(reader.TryReadBits(32)) | ||
| 51 | packet.OutSequence = int32(reader.TryReadBits(32)) | ||
| 52 | packet.Size = int32(reader.TryReadSInt32()) | ||
| 53 | data := reader.TryReadBytesToSlice(uint64(packet.Size)) | ||
| 54 | packetReader := bitreader.NewReaderFromBytes(data, true) | ||
| 55 | for { | ||
| 56 | messageType, err := packetReader.ReadBits(6) | ||
| 57 | if err != nil { | ||
| 58 | break | ||
| 59 | } | ||
| 60 | packet.Data = append(packet.Data, messages.ParseMessages(int(messageType), packetReader)) | ||
| 61 | } | ||
| 62 | packetData = packet | ||
| 63 | case 3: // SyncTick | 28 | case 3: // SyncTick |
| 64 | syncTick := SyncTick{} | ||
| 65 | writer.AppendLine("[%d] %s (%d):", tickNumber, "SYNCTICK", packetType) | 29 | writer.AppendLine("[%d] %s (%d):", tickNumber, "SYNCTICK", packetType) |
| 66 | packetData = syncTick | 30 | syncTick := classes.SyncTick{} |
| 31 | syncTick.ParseSyncTick() | ||
| 67 | case 4: // ConsoleCmd | 32 | case 4: // ConsoleCmd |
| 68 | consoleCmd := ConsoleCmd{} | ||
| 69 | writer.AppendLine("[%d] %s (%d):", tickNumber, "CONSOLECMD", packetType) | 33 | writer.AppendLine("[%d] %s (%d):", tickNumber, "CONSOLECMD", packetType) |
| 70 | consoleCmd.Size = reader.TryReadSInt32() | 34 | consoleCmd := classes.ConsoleCmd{} |
| 71 | consoleCmd.Data = reader.TryReadStringLength(uint64(consoleCmd.Size)) | 35 | consoleCmd.ParseConsoleCmd(reader) |
| 72 | writer.AppendLine("\t%s", consoleCmd.Data) | 36 | case 5: // UserCmd |
| 73 | packetData = consoleCmd | ||
| 74 | case 5: // UserCmd TODO: usercmdinfo refactor | ||
| 75 | userCmd := UserCmd{} | ||
| 76 | writer.AppendLine("[%d] %s (%d):", tickNumber, "USERCMD", packetType) | 37 | writer.AppendLine("[%d] %s (%d):", tickNumber, "USERCMD", packetType) |
| 77 | userCmd.Cmd = int32(reader.TryReadSInt32()) | 38 | userCmd := classes.UserCmd{} |
| 78 | userCmd.Size = int32(reader.TryReadSInt32()) | 39 | userCmd.ParseUserCmd(reader) |
| 79 | data := reader.TryReadBytesToSlice(uint64(userCmd.Size)) | 40 | case 6: // DataTables |
| 80 | userCmd.Data = classes.ParseUserCmdInfo(data) | ||
| 81 | packetData = userCmd | ||
| 82 | case 6: // DataTables TODO: prop stuff | ||
| 83 | dataTables := DataTables{} | ||
| 84 | writer.AppendLine("[%d] %s (%d):", tickNumber, "DATATABLES", packetType) | 41 | writer.AppendLine("[%d] %s (%d):", tickNumber, "DATATABLES", packetType) |
| 85 | dataTables.Size = int32(reader.TryReadSInt32()) | 42 | dataTables := classes.DataTables{} |
| 86 | data := reader.TryReadBytesToSlice(uint64(dataTables.Size)) | 43 | dataTables.ParseDataTables(reader) |
| 87 | dataTableReader := bitreader.NewReaderFromBytes(data, true) | ||
| 88 | count := 0 | ||
| 89 | for dataTableReader.TryReadBool() { | ||
| 90 | count++ | ||
| 91 | dataTables.SendTable = append(dataTables.SendTable, classes.ParseSendTable(dataTableReader)) | ||
| 92 | } | ||
| 93 | writer.AppendLine("\t%d Send Tables:", count) | ||
| 94 | writer.AppendOutputFromTemp() | ||
| 95 | numOfClasses := dataTableReader.TryReadBits(16) | ||
| 96 | for count = 0; count < int(numOfClasses); count++ { | ||
| 97 | dataTables.ServerClassInfo = append(dataTables.ServerClassInfo, classes.ParseServerClassInfo(dataTableReader, count, int(numOfClasses))) | ||
| 98 | } | ||
| 99 | writer.AppendLine("\t%d Classes:", count) | ||
| 100 | writer.AppendOutputFromTemp() | ||
| 101 | packetData = dataTables | ||
| 102 | case 7: // Stop | 44 | case 7: // Stop |
| 103 | stop := Stop{} | ||
| 104 | writer.AppendLine("[%d] %s (%d):", tickNumber, "STOP", packetType) | 45 | writer.AppendLine("[%d] %s (%d):", tickNumber, "STOP", packetType) |
| 105 | if reader.TryReadBool() { | 46 | stop := classes.Stop{} |
| 106 | stop.RemainingData = reader.TryReadBitsToSlice(uint64(reader.TryReadRemainingBits())) | 47 | stop.ParseStop(reader) |
| 107 | writer.AppendLine("\tRemaining Data: %v", stop.RemainingData) | ||
| 108 | } | ||
| 109 | packetData = stop | ||
| 110 | case 8: // CustomData TODO: not sar data | 48 | case 8: // CustomData TODO: not sar data |
| 111 | customData := CustomData{} | 49 | customData := classes.CustomData{} |
| 112 | customData.Type = reader.TryReadSInt32() | 50 | customData.ParseCustomData(reader, tickNumber, packetType) |
| 113 | customData.Size = reader.TryReadSInt32() | ||
| 114 | if customData.Type != 0 || customData.Size == 8 { | ||
| 115 | // Not SAR data | ||
| 116 | writer.AppendLine("[%d] %s (%d):", tickNumber, "CUSTOMDATA", packetType) | ||
| 117 | customData.Data = string(reader.TryReadBytesToSlice(uint64(customData.Size))) | ||
| 118 | writer.AppendLine("\t%s", customData.Data) | ||
| 119 | packetData = customData | ||
| 120 | break | ||
| 121 | } | ||
| 122 | // SAR data | ||
| 123 | sarData := classes.SarData{} | ||
| 124 | writer.AppendLine("[%d] %s (%d):", tickNumber, "SARDATA", packetType) | ||
| 125 | data := reader.TryReadBytesToSlice(uint64(customData.Size)) | ||
| 126 | sarReader := bitreader.NewReaderFromBytes(data, true) | ||
| 127 | sarData.ParseSarData(sarReader) | ||
| 128 | packetData = sarData | ||
| 129 | case 9: // StringTables TODO: parsing string table data | 51 | case 9: // StringTables TODO: parsing string table data |
| 130 | stringTables := StringTables{} | ||
| 131 | writer.AppendLine("[%d] %s (%d):", tickNumber, "STRINGTABLES", packetType) | 52 | writer.AppendLine("[%d] %s (%d):", tickNumber, "STRINGTABLES", packetType) |
| 132 | stringTables.Size = reader.TryReadSInt32() | 53 | stringTables := classes.StringTables{} |
| 133 | data := reader.TryReadBytesToSlice(uint64(stringTables.Size)) | 54 | stringTables.ParseStringTables(reader) |
| 134 | stringTableReader := bitreader.NewReaderFromBytes(data, true) | 55 | default: // Invalid |
| 135 | stringTables.Data = classes.ParseStringTables(stringTableReader) | ||
| 136 | packetData = stringTables | ||
| 137 | default: // invalid | ||
| 138 | writer.AppendLine("[%d] %s (%d):", tickNumber, "INVALID", packetType) | 56 | writer.AppendLine("[%d] %s (%d):", tickNumber, "INVALID", packetType) |
| 139 | panic("invalid packet type") | 57 | panic("invalid packet type") |
| 140 | } | 58 | } |
| @@ -142,6 +60,5 @@ func ParsePackets(reader *bitreader.Reader) PacketMessageInfo { | |||
| 142 | PacketType: packetType, | 60 | PacketType: packetType, |
| 143 | TickNumber: tickNumber, | 61 | TickNumber: tickNumber, |
| 144 | SlotNumber: slotNumber, | 62 | SlotNumber: slotNumber, |
| 145 | Data: packetData, | ||
| 146 | } | 63 | } |
| 147 | } | 64 | } |
diff --git a/pkg/packets/types.go b/pkg/packets/types.go deleted file mode 100644 index a2fb78f..0000000 --- a/pkg/packets/types.go +++ /dev/null | |||
| @@ -1,53 +0,0 @@ | |||
| 1 | package packets | ||
| 2 | |||
| 3 | import "github.com/pektezol/demoparser/pkg/classes" | ||
| 4 | |||
| 5 | type SignOn struct { | ||
| 6 | PacketInfo []classes.CmdInfo | ||
| 7 | InSequence int32 | ||
| 8 | OutSequence int32 | ||
| 9 | Size int32 | ||
| 10 | Data []any | ||
| 11 | } | ||
| 12 | |||
| 13 | type Packet struct { | ||
| 14 | PacketInfo []classes.CmdInfo | ||
| 15 | InSequence int32 | ||
| 16 | OutSequence int32 | ||
| 17 | Size int32 | ||
| 18 | Data []any | ||
| 19 | } | ||
| 20 | |||
| 21 | type SyncTick struct{} | ||
| 22 | |||
| 23 | type ConsoleCmd struct { | ||
| 24 | Size int32 | ||
| 25 | Data string | ||
| 26 | } | ||
| 27 | |||
| 28 | type UserCmd struct { | ||
| 29 | Cmd int32 | ||
| 30 | Size int32 | ||
| 31 | Data classes.UserCmdInfo | ||
| 32 | } | ||
| 33 | |||
| 34 | type DataTables struct { | ||
| 35 | Size int32 | ||
| 36 | SendTable []classes.SendTable | ||
| 37 | ServerClassInfo []classes.ServerClassInfo | ||
| 38 | } | ||
| 39 | |||
| 40 | type Stop struct { | ||
| 41 | RemainingData []byte | ||
| 42 | } | ||
| 43 | |||
| 44 | type CustomData struct { | ||
| 45 | Type int32 | ||
| 46 | Size int32 | ||
| 47 | Data string | ||
| 48 | } | ||
| 49 | |||
| 50 | type StringTables struct { | ||
| 51 | Size int32 | ||
| 52 | Data []classes.StringTable | ||
| 53 | } | ||