diff options
Diffstat (limited to 'pkg/messages')
35 files changed, 795 insertions, 0 deletions
diff --git a/pkg/messages/messages.go b/pkg/messages/messages.go new file mode 100644 index 0000000..39f89e9 --- /dev/null +++ b/pkg/messages/messages.go | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "reflect" | ||
| 6 | |||
| 7 | "github.com/pektezol/bitreader" | ||
| 8 | messages "github.com/pektezol/demoparser/pkg/messages/types" | ||
| 9 | ) | ||
| 10 | |||
| 11 | func ParseMessages(messageType int, reader *bitreader.ReaderType) any { | ||
| 12 | var messageData any | ||
| 13 | switch messageType { | ||
| 14 | case 0: | ||
| 15 | messageData = messages.ParseNetNop(reader) | ||
| 16 | case 1: | ||
| 17 | messageData = messages.ParseNetDisconnect(reader) | ||
| 18 | case 2: | ||
| 19 | messageData = messages.ParseNetFile(reader) | ||
| 20 | case 3: | ||
| 21 | messageData = messages.ParseNetSplitScreenUser(reader) | ||
| 22 | case 4: | ||
| 23 | messageData = messages.ParseNetTick(reader) | ||
| 24 | case 5: | ||
| 25 | messageData = messages.ParseNetStringCmd(reader) | ||
| 26 | case 6: | ||
| 27 | messageData = messages.ParseNetSetConVar(reader) | ||
| 28 | case 7: | ||
| 29 | messageData = messages.ParseNetSignOnState(reader) | ||
| 30 | case 8: | ||
| 31 | messageData = messages.ParseSvcServerInfo(reader) | ||
| 32 | case 9: | ||
| 33 | messageData = messages.ParseSvcSendTable(reader) | ||
| 34 | case 10: | ||
| 35 | messageData = messages.ParseSvcClassInfo(reader) | ||
| 36 | case 11: | ||
| 37 | messageData = messages.ParseSvcSetPause(reader) | ||
| 38 | case 12: | ||
| 39 | messageData = messages.ParseSvcCreateStringTable(reader) | ||
| 40 | case 13: | ||
| 41 | messageData = messages.ParseSvcUpdateStringTable(reader) | ||
| 42 | case 14: | ||
| 43 | messageData = messages.ParseSvcVoiceInit(reader) | ||
| 44 | case 15: | ||
| 45 | messageData = messages.ParseSvcVoiceData(reader) | ||
| 46 | case 16: | ||
| 47 | messageData = messages.ParseSvcPrint(reader) | ||
| 48 | case 17: | ||
| 49 | messageData = messages.ParseSvcSounds(reader) | ||
| 50 | case 18: | ||
| 51 | messageData = messages.ParseSvcSetView(reader) | ||
| 52 | case 19: | ||
| 53 | messageData = messages.ParseSvcFixAngle(reader) | ||
| 54 | case 20: | ||
| 55 | messageData = messages.ParseSvcCrosshairAngle(reader) | ||
| 56 | case 21: | ||
| 57 | messageData = messages.ParseSvcBspDecal(reader) | ||
| 58 | case 22: | ||
| 59 | messageData = messages.ParseSvcSplitScreen(reader) | ||
| 60 | case 23: | ||
| 61 | messageData = messages.ParseSvcUserMessage(reader) | ||
| 62 | case 24: | ||
| 63 | messageData = messages.ParseSvcEntityMessage(reader) | ||
| 64 | case 25: | ||
| 65 | messageData = messages.ParseSvcGameEvent(reader) | ||
| 66 | case 26: | ||
| 67 | messageData = messages.ParseSvcPacketEntities(reader) | ||
| 68 | case 27: | ||
| 69 | messageData = messages.ParseSvcTempEntities(reader) | ||
| 70 | case 28: | ||
| 71 | messageData = messages.ParseSvcPrefetch(reader) | ||
| 72 | case 29: | ||
| 73 | messageData = messages.ParseSvcMenu(reader) | ||
| 74 | case 30: | ||
| 75 | messageData = messages.ParseSvcGameEventList(reader) | ||
| 76 | case 31: | ||
| 77 | messageData = messages.ParseSvcGetCvarValue(reader) | ||
| 78 | case 32: | ||
| 79 | messageData = messages.ParseSvcCmdKeyValues(reader) | ||
| 80 | case 33: | ||
| 81 | messageData = messages.ParseSvcPaintmapData(reader) | ||
| 82 | default: | ||
| 83 | return nil | ||
| 84 | } | ||
| 85 | fmt.Printf("\t\t(%d) %s:\n\t\t\t%+v\n", messageType, reflect.ValueOf(messageData).Type(), messageData) | ||
| 86 | return messageData | ||
| 87 | } | ||
diff --git a/pkg/messages/types/netDisconnect.go b/pkg/messages/types/netDisconnect.go new file mode 100644 index 0000000..69d4a67 --- /dev/null +++ b/pkg/messages/types/netDisconnect.go | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type NetDisconnect struct { | ||
| 6 | Text string | ||
| 7 | } | ||
| 8 | |||
| 9 | func ParseNetDisconnect(reader *bitreader.ReaderType) NetDisconnect { | ||
| 10 | return NetDisconnect{ | ||
| 11 | Text: reader.TryReadString(), | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/pkg/messages/types/netFile.go b/pkg/messages/types/netFile.go new file mode 100644 index 0000000..a41a0cf --- /dev/null +++ b/pkg/messages/types/netFile.go | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type NetFile struct { | ||
| 6 | TransferId int32 | ||
| 7 | FileName string | ||
| 8 | FileRequested bool | ||
| 9 | } | ||
| 10 | |||
| 11 | func ParseNetFile(reader *bitreader.ReaderType) NetFile { | ||
| 12 | return NetFile{ | ||
| 13 | TransferId: int32(reader.TryReadBits(32)), | ||
| 14 | FileName: reader.TryReadString(), | ||
| 15 | FileRequested: reader.TryReadBool(), | ||
| 16 | } | ||
| 17 | } | ||
diff --git a/pkg/messages/types/netNop.go b/pkg/messages/types/netNop.go new file mode 100644 index 0000000..33f8e25 --- /dev/null +++ b/pkg/messages/types/netNop.go | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type NetNop struct{} | ||
| 6 | |||
| 7 | func ParseNetNop(reader *bitreader.ReaderType) NetNop { | ||
| 8 | return NetNop{} | ||
| 9 | } | ||
diff --git a/pkg/messages/types/netSetConVar.go b/pkg/messages/types/netSetConVar.go new file mode 100644 index 0000000..08042ae --- /dev/null +++ b/pkg/messages/types/netSetConVar.go | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type NetSetConVar struct { | ||
| 6 | Length int8 | ||
| 7 | ConVars []conVar | ||
| 8 | } | ||
| 9 | |||
| 10 | type conVar struct { | ||
| 11 | Name string | ||
| 12 | Value string | ||
| 13 | } | ||
| 14 | |||
| 15 | func ParseNetSetConVar(reader *bitreader.ReaderType) NetSetConVar { | ||
| 16 | length := reader.TryReadBits(8) | ||
| 17 | convars := []conVar{} | ||
| 18 | for count := 0; count < int(length); count++ { | ||
| 19 | convar := conVar{ | ||
| 20 | Name: reader.TryReadString(), | ||
| 21 | Value: reader.TryReadString(), | ||
| 22 | } | ||
| 23 | convars = append(convars, convar) | ||
| 24 | } | ||
| 25 | return NetSetConVar{ | ||
| 26 | Length: int8(length), | ||
| 27 | ConVars: convars, | ||
| 28 | } | ||
| 29 | } | ||
diff --git a/pkg/messages/types/netSignOnState.go b/pkg/messages/types/netSignOnState.go new file mode 100644 index 0000000..4609ff2 --- /dev/null +++ b/pkg/messages/types/netSignOnState.go | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type NetSignOnState struct { | ||
| 6 | SignOnState int8 | ||
| 7 | SpawnCount int32 | ||
| 8 | NumServerPlayers int32 | ||
| 9 | IdsLength int32 | ||
| 10 | PlayersNetworksIds []byte | ||
| 11 | MapNameLength int32 | ||
| 12 | MapName string | ||
| 13 | } | ||
| 14 | |||
| 15 | func ParseNetSignOnState(reader *bitreader.ReaderType) NetSignOnState { | ||
| 16 | netSignOnState := NetSignOnState{ | ||
| 17 | SignOnState: int8(reader.TryReadBits(8)), | ||
| 18 | SpawnCount: int32(reader.TryReadBits(32)), | ||
| 19 | NumServerPlayers: int32(reader.TryReadBits(32)), | ||
| 20 | IdsLength: int32(reader.TryReadBits(32)), | ||
| 21 | } | ||
| 22 | netSignOnState.PlayersNetworksIds = reader.TryReadBytesToSlice(int(netSignOnState.IdsLength)) | ||
| 23 | netSignOnState.MapNameLength = int32(reader.TryReadBits(32)) | ||
| 24 | netSignOnState.MapName = reader.TryReadStringLen(int(netSignOnState.MapNameLength)) | ||
| 25 | return netSignOnState | ||
| 26 | } | ||
diff --git a/pkg/messages/types/netSplitScreenUser.go b/pkg/messages/types/netSplitScreenUser.go new file mode 100644 index 0000000..65e85f3 --- /dev/null +++ b/pkg/messages/types/netSplitScreenUser.go | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type NetSplitScreenUser struct { | ||
| 6 | Unknown bool | ||
| 7 | } | ||
| 8 | |||
| 9 | func ParseNetSplitScreenUser(reader *bitreader.ReaderType) NetSplitScreenUser { | ||
| 10 | return NetSplitScreenUser{ | ||
| 11 | Unknown: reader.TryReadBool(), | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/pkg/messages/types/netStringCmd.go b/pkg/messages/types/netStringCmd.go new file mode 100644 index 0000000..158658e --- /dev/null +++ b/pkg/messages/types/netStringCmd.go | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type NetStringCmd struct { | ||
| 6 | Command string | ||
| 7 | } | ||
| 8 | |||
| 9 | func ParseNetStringCmd(reader *bitreader.ReaderType) NetStringCmd { | ||
| 10 | return NetStringCmd{ | ||
| 11 | Command: reader.TryReadString(), | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/pkg/messages/types/netTick.go b/pkg/messages/types/netTick.go new file mode 100644 index 0000000..e14f259 --- /dev/null +++ b/pkg/messages/types/netTick.go | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type NetTick struct { | ||
| 6 | Tick int32 | ||
| 7 | HostFrameTime int16 | ||
| 8 | HostFrameTimeStdDeviation int16 | ||
| 9 | } | ||
| 10 | |||
| 11 | func ParseNetTick(reader *bitreader.ReaderType) NetTick { | ||
| 12 | return NetTick{ | ||
| 13 | Tick: int32(reader.TryReadBits(32)), | ||
| 14 | HostFrameTime: int16(reader.TryReadBits(16) / 10e5), | ||
| 15 | HostFrameTimeStdDeviation: int16(reader.TryReadBits(16) / 10e5), | ||
| 16 | } | ||
| 17 | } | ||
diff --git a/pkg/messages/types/svcBspDecal.go b/pkg/messages/types/svcBspDecal.go new file mode 100644 index 0000000..484497f --- /dev/null +++ b/pkg/messages/types/svcBspDecal.go | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/bitreader" | ||
| 5 | ) | ||
| 6 | |||
| 7 | type SvcBspDecal struct { | ||
| 8 | Pos []vectorCoord | ||
| 9 | DecalTextureIndex int16 | ||
| 10 | EntityIndex int16 | ||
| 11 | ModelIndex int16 | ||
| 12 | LowPriority int8 | ||
| 13 | } | ||
| 14 | |||
| 15 | type vectorCoord struct { | ||
| 16 | Value float32 | ||
| 17 | Valid bool | ||
| 18 | } | ||
| 19 | |||
| 20 | func ParseSvcBspDecal(reader *bitreader.ReaderType) SvcBspDecal { | ||
| 21 | svcBspDecal := SvcBspDecal{ | ||
| 22 | Pos: readVectorCoords(reader), | ||
| 23 | DecalTextureIndex: int16(reader.TryReadBits(9)), | ||
| 24 | } | ||
| 25 | if reader.TryReadBool() { | ||
| 26 | svcBspDecal.EntityIndex = int16(reader.TryReadBits(11)) | ||
| 27 | svcBspDecal.ModelIndex = int16(reader.TryReadBits(11)) | ||
| 28 | } | ||
| 29 | svcBspDecal.LowPriority = int8(reader.TryReadBits(1)) | ||
| 30 | return svcBspDecal | ||
| 31 | } | ||
| 32 | |||
| 33 | func readVectorCoords(reader *bitreader.ReaderType) []vectorCoord { | ||
| 34 | const COORD_INTEGER_BITS uint8 = 14 | ||
| 35 | const COORD_FRACTIONAL_BITS uint8 = 5 | ||
| 36 | const COORD_DENOMINATOR uint8 = 1 << COORD_FRACTIONAL_BITS | ||
| 37 | const COORD_RESOLUTION float32 = 1.0 / float32(COORD_DENOMINATOR) | ||
| 38 | readVectorCoord := func() float32 { | ||
| 39 | value := float32(0) | ||
| 40 | integer := reader.TryReadBits(1) | ||
| 41 | fraction := reader.TryReadBits(1) | ||
| 42 | if integer != 0 || fraction != 0 { | ||
| 43 | sign := reader.TryReadBits(1) | ||
| 44 | if integer != 0 { | ||
| 45 | integer = reader.TryReadBits(int(COORD_INTEGER_BITS)) + 1 | ||
| 46 | } | ||
| 47 | if fraction != 0 { | ||
| 48 | fraction = reader.TryReadBits(int(COORD_FRACTIONAL_BITS)) | ||
| 49 | } | ||
| 50 | value = float32(integer) + float32(fraction)*COORD_RESOLUTION | ||
| 51 | if sign != 0 { | ||
| 52 | value = -value | ||
| 53 | } | ||
| 54 | } | ||
| 55 | return value | ||
| 56 | } | ||
| 57 | x := reader.TryReadBits(1) | ||
| 58 | y := reader.TryReadBits(1) | ||
| 59 | z := reader.TryReadBits(1) | ||
| 60 | return []vectorCoord{{Value: readVectorCoord(), Valid: x != 0}, {Value: readVectorCoord(), Valid: y != 0}, {Value: readVectorCoord(), Valid: z != 0}} | ||
| 61 | } | ||
diff --git a/pkg/messages/types/svcClassInfo.go b/pkg/messages/types/svcClassInfo.go new file mode 100644 index 0000000..9f367d3 --- /dev/null +++ b/pkg/messages/types/svcClassInfo.go | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "math" | ||
| 6 | |||
| 7 | "github.com/pektezol/bitreader" | ||
| 8 | ) | ||
| 9 | |||
| 10 | type SvcClassInfo struct { | ||
| 11 | Length int16 | ||
| 12 | CreateOnClient bool | ||
| 13 | ServerClasses []serverClass | ||
| 14 | } | ||
| 15 | |||
| 16 | type serverClass struct { | ||
| 17 | ClassId int16 | ||
| 18 | ClassName string | ||
| 19 | DataTableName string | ||
| 20 | } | ||
| 21 | |||
| 22 | func ParseSvcClassInfo(reader *bitreader.ReaderType) SvcClassInfo { | ||
| 23 | svcClassInfo := SvcClassInfo{ | ||
| 24 | Length: int16(reader.TryReadBits(16)), | ||
| 25 | CreateOnClient: reader.TryReadBool(), | ||
| 26 | } | ||
| 27 | classes := []serverClass{} | ||
| 28 | if !svcClassInfo.CreateOnClient { | ||
| 29 | for count := 0; count < int(svcClassInfo.Length); count++ { | ||
| 30 | fmt.Println(classes) | ||
| 31 | classes = append(classes, serverClass{ | ||
| 32 | ClassId: int16(reader.TryReadBits(int(math.Log2(float64(svcClassInfo.Length)) + 1))), | ||
| 33 | ClassName: reader.TryReadString(), | ||
| 34 | DataTableName: reader.TryReadString(), | ||
| 35 | }) | ||
| 36 | } | ||
| 37 | } | ||
| 38 | svcClassInfo.ServerClasses = classes | ||
| 39 | return svcClassInfo | ||
| 40 | } | ||
diff --git a/pkg/messages/types/svcCmdKeyValues.go b/pkg/messages/types/svcCmdKeyValues.go new file mode 100644 index 0000000..1c4d819 --- /dev/null +++ b/pkg/messages/types/svcCmdKeyValues.go | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcCmdKeyValues struct { | ||
| 6 | Length int32 | ||
| 7 | Data []byte | ||
| 8 | } | ||
| 9 | |||
| 10 | func ParseSvcCmdKeyValues(reader *bitreader.ReaderType) SvcCmdKeyValues { | ||
| 11 | svcCmdKeyValues := SvcCmdKeyValues{ | ||
| 12 | Length: int32(reader.TryReadBits(32)), | ||
| 13 | } | ||
| 14 | svcCmdKeyValues.Data = reader.TryReadBytesToSlice(int(svcCmdKeyValues.Length)) | ||
| 15 | return svcCmdKeyValues | ||
| 16 | } | ||
diff --git a/pkg/messages/types/svcCreateStringTable.go b/pkg/messages/types/svcCreateStringTable.go new file mode 100644 index 0000000..ed9e477 --- /dev/null +++ b/pkg/messages/types/svcCreateStringTable.go | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "math" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | ) | ||
| 8 | |||
| 9 | type SvcCreateStringTable struct { | ||
| 10 | Name string | ||
| 11 | MaxEntries int16 | ||
| 12 | NumEntries int8 | ||
| 13 | Length int32 | ||
| 14 | UserDataFixedSize bool | ||
| 15 | UserDataSize int16 | ||
| 16 | UserDataSizeBits int8 | ||
| 17 | Flags int8 | ||
| 18 | StringData int | ||
| 19 | } | ||
| 20 | |||
| 21 | func ParseSvcCreateStringTable(reader *bitreader.ReaderType) SvcCreateStringTable { | ||
| 22 | svcCreateStringTable := SvcCreateStringTable{ | ||
| 23 | Name: reader.TryReadString(), | ||
| 24 | MaxEntries: int16(reader.TryReadBits(16)), | ||
| 25 | } | ||
| 26 | svcCreateStringTable.NumEntries = int8(reader.TryReadBits(int(math.Log2(float64(svcCreateStringTable.MaxEntries))) + 1)) | ||
| 27 | svcCreateStringTable.Length = int32(reader.TryReadBits(20)) | ||
| 28 | svcCreateStringTable.UserDataFixedSize = reader.TryReadBool() | ||
| 29 | if svcCreateStringTable.UserDataFixedSize { | ||
| 30 | svcCreateStringTable.UserDataSize = int16(reader.TryReadBits(12)) | ||
| 31 | svcCreateStringTable.UserDataSizeBits = int8(reader.TryReadBits(4)) | ||
| 32 | } | ||
| 33 | svcCreateStringTable.Flags = int8(reader.TryReadBits(2)) | ||
| 34 | reader.SkipBits(int(svcCreateStringTable.Length)) // TODO: StringTable parsing | ||
| 35 | return svcCreateStringTable | ||
| 36 | } | ||
diff --git a/pkg/messages/types/svcCrosshairAngle.go b/pkg/messages/types/svcCrosshairAngle.go new file mode 100644 index 0000000..cf18212 --- /dev/null +++ b/pkg/messages/types/svcCrosshairAngle.go | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcCrosshairAngle struct { | ||
| 6 | Angle []int16 | ||
| 7 | } | ||
| 8 | |||
| 9 | func ParseSvcCrosshairAngle(reader *bitreader.ReaderType) SvcCrosshairAngle { | ||
| 10 | return SvcCrosshairAngle{ | ||
| 11 | Angle: []int16{int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16))}, | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/pkg/messages/types/svcEntityMessage.go b/pkg/messages/types/svcEntityMessage.go new file mode 100644 index 0000000..9726ced --- /dev/null +++ b/pkg/messages/types/svcEntityMessage.go | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcEntityMessage struct { | ||
| 6 | EntityIndex int16 | ||
| 7 | ClassId int16 | ||
| 8 | Length int16 | ||
| 9 | Data []byte | ||
| 10 | } | ||
| 11 | |||
| 12 | func ParseSvcEntityMessage(reader *bitreader.ReaderType) SvcEntityMessage { | ||
| 13 | svcEntityMessage := SvcEntityMessage{ | ||
| 14 | EntityIndex: int16(reader.TryReadBits(11)), | ||
| 15 | ClassId: int16(reader.TryReadBits(9)), | ||
| 16 | Length: int16(reader.TryReadBits(11)), | ||
| 17 | } | ||
| 18 | svcEntityMessage.Data = reader.TryReadBitsToSlice(int(svcEntityMessage.Length)) | ||
| 19 | return svcEntityMessage | ||
| 20 | } | ||
diff --git a/pkg/messages/types/svcFixAngle.go b/pkg/messages/types/svcFixAngle.go new file mode 100644 index 0000000..56acf04 --- /dev/null +++ b/pkg/messages/types/svcFixAngle.go | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcFixAngle struct { | ||
| 6 | Relative bool | ||
| 7 | Angle []int16 | ||
| 8 | } | ||
| 9 | |||
| 10 | func ParseSvcFixAngle(reader *bitreader.ReaderType) SvcFixAngle { | ||
| 11 | return SvcFixAngle{ | ||
| 12 | Relative: reader.TryReadBool(), | ||
| 13 | Angle: []int16{int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16)), int16(reader.TryReadBits(16))}, | ||
| 14 | } | ||
| 15 | } | ||
diff --git a/pkg/messages/types/svcGameEvent.go b/pkg/messages/types/svcGameEvent.go new file mode 100644 index 0000000..6ee4d01 --- /dev/null +++ b/pkg/messages/types/svcGameEvent.go | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcGameEvent struct { | ||
| 6 | Length int16 | ||
| 7 | Data []byte // TODO: GameEvent[] | ||
| 8 | } | ||
| 9 | |||
| 10 | func ParseSvcGameEvent(reader *bitreader.ReaderType) SvcGameEvent { | ||
| 11 | svcGameEvent := SvcGameEvent{ | ||
| 12 | Length: int16(reader.TryReadBits(11)), | ||
| 13 | } | ||
| 14 | svcGameEvent.Data = reader.TryReadBitsToSlice(int(svcGameEvent.Length)) | ||
| 15 | return svcGameEvent | ||
| 16 | } | ||
diff --git a/pkg/messages/types/svcGameEventList.go b/pkg/messages/types/svcGameEventList.go new file mode 100644 index 0000000..b99ce28 --- /dev/null +++ b/pkg/messages/types/svcGameEventList.go | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcGameEventList struct { | ||
| 6 | Events int16 | ||
| 7 | Length int32 | ||
| 8 | GameEventDescriptor []gameEventDescriptor | ||
| 9 | } | ||
| 10 | |||
| 11 | type gameEventDescriptor struct { | ||
| 12 | } | ||
| 13 | |||
| 14 | func ParseSvcGameEventList(reader *bitreader.ReaderType) SvcGameEventList { | ||
| 15 | svcGameEventList := SvcGameEventList{ | ||
| 16 | Events: int16(reader.TryReadBits(9)), | ||
| 17 | Length: int32(reader.TryReadBits(20)), | ||
| 18 | } | ||
| 19 | reader.TryReadBitsToSlice(int(svcGameEventList.Length)) | ||
| 20 | return svcGameEventList | ||
| 21 | } | ||
diff --git a/pkg/messages/types/svcGetCvarValue.go b/pkg/messages/types/svcGetCvarValue.go new file mode 100644 index 0000000..aef5c8e --- /dev/null +++ b/pkg/messages/types/svcGetCvarValue.go | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcGetCvarValue struct { | ||
| 6 | Cookie string | ||
| 7 | CvarName string | ||
| 8 | } | ||
| 9 | |||
| 10 | func ParseSvcGetCvarValue(reader *bitreader.ReaderType) SvcGetCvarValue { | ||
| 11 | svcGetCvarValue := SvcGetCvarValue{ | ||
| 12 | Cookie: reader.TryReadStringLen(4), | ||
| 13 | CvarName: reader.TryReadString(), | ||
| 14 | } | ||
| 15 | return svcGetCvarValue | ||
| 16 | } | ||
diff --git a/pkg/messages/types/svcMenu.go b/pkg/messages/types/svcMenu.go new file mode 100644 index 0000000..d89f52c --- /dev/null +++ b/pkg/messages/types/svcMenu.go | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcMenu struct { | ||
| 6 | MenuType int16 | ||
| 7 | Length int32 | ||
| 8 | Data []byte | ||
| 9 | } | ||
| 10 | |||
| 11 | func ParseSvcMenu(reader *bitreader.ReaderType) SvcMenu { | ||
| 12 | svcMenu := SvcMenu{ | ||
| 13 | MenuType: int16(reader.TryReadBits(16)), | ||
| 14 | Length: int32(reader.TryReadBits(32)), | ||
| 15 | } | ||
| 16 | svcMenu.Data = reader.TryReadBitsToSlice(int(svcMenu.Length)) | ||
| 17 | return svcMenu | ||
| 18 | } | ||
diff --git a/pkg/messages/types/svcPacketEntities.go b/pkg/messages/types/svcPacketEntities.go new file mode 100644 index 0000000..b1c23e5 --- /dev/null +++ b/pkg/messages/types/svcPacketEntities.go | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcPacketEntities struct { | ||
| 6 | MaxEntries int16 | ||
| 7 | IsDelta bool | ||
| 8 | DeltaFrom int32 | ||
| 9 | BaseLine bool | ||
| 10 | UpdatedEntries int16 | ||
| 11 | Length int32 | ||
| 12 | UpdatedBaseline bool | ||
| 13 | Data []byte | ||
| 14 | } | ||
| 15 | |||
| 16 | func ParseSvcPacketEntities(reader *bitreader.ReaderType) SvcPacketEntities { | ||
| 17 | svcPacketEntities := SvcPacketEntities{ | ||
| 18 | MaxEntries: int16(reader.TryReadBits(11)), | ||
| 19 | IsDelta: reader.TryReadBool(), | ||
| 20 | } | ||
| 21 | if svcPacketEntities.IsDelta { | ||
| 22 | svcPacketEntities.DeltaFrom = int32(reader.TryReadBits(32)) | ||
| 23 | } | ||
| 24 | svcPacketEntities.BaseLine = reader.TryReadBool() | ||
| 25 | svcPacketEntities.UpdatedEntries = int16(reader.TryReadBits(11)) | ||
| 26 | svcPacketEntities.Length = int32(reader.TryReadBits(20)) | ||
| 27 | svcPacketEntities.UpdatedBaseline = reader.TryReadBool() | ||
| 28 | svcPacketEntities.Data = reader.TryReadBitsToSlice(int(svcPacketEntities.Length)) | ||
| 29 | return svcPacketEntities | ||
| 30 | } | ||
diff --git a/pkg/messages/types/svcPaintmapData.go b/pkg/messages/types/svcPaintmapData.go new file mode 100644 index 0000000..6b041da --- /dev/null +++ b/pkg/messages/types/svcPaintmapData.go | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcPaintmapData struct { | ||
| 6 | Length int32 | ||
| 7 | Data []byte | ||
| 8 | } | ||
| 9 | |||
| 10 | func ParseSvcPaintmapData(reader *bitreader.ReaderType) SvcPaintmapData { | ||
| 11 | svcPaintmapData := SvcPaintmapData{ | ||
| 12 | Length: int32(reader.TryReadBits(32)), | ||
| 13 | } | ||
| 14 | svcPaintmapData.Data = reader.TryReadBitsToSlice(int(svcPaintmapData.Length)) | ||
| 15 | return svcPaintmapData | ||
| 16 | } | ||
diff --git a/pkg/messages/types/svcPrefetch.go b/pkg/messages/types/svcPrefetch.go new file mode 100644 index 0000000..549f926 --- /dev/null +++ b/pkg/messages/types/svcPrefetch.go | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcPrefetch struct { | ||
| 6 | SoundIndex int16 | ||
| 7 | } | ||
| 8 | |||
| 9 | func ParseSvcPrefetch(reader *bitreader.ReaderType) SvcPrefetch { | ||
| 10 | return SvcPrefetch{ | ||
| 11 | SoundIndex: int16(reader.TryReadBits(13)), | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/pkg/messages/types/svcPrint.go b/pkg/messages/types/svcPrint.go new file mode 100644 index 0000000..8aff927 --- /dev/null +++ b/pkg/messages/types/svcPrint.go | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcPrint struct { | ||
| 6 | Message string | ||
| 7 | } | ||
| 8 | |||
| 9 | func ParseSvcPrint(reader *bitreader.ReaderType) SvcPrint { | ||
| 10 | return SvcPrint{ | ||
| 11 | Message: reader.TryReadString(), | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/pkg/messages/types/svcSendTable.go b/pkg/messages/types/svcSendTable.go new file mode 100644 index 0000000..ae8960b --- /dev/null +++ b/pkg/messages/types/svcSendTable.go | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcSendTable struct { | ||
| 6 | NeedsDecoder int8 | ||
| 7 | Length int8 | ||
| 8 | Props int32 | ||
| 9 | } | ||
| 10 | |||
| 11 | func ParseSvcSendTable(reader *bitreader.ReaderType) SvcSendTable { | ||
| 12 | return SvcSendTable{ | ||
| 13 | NeedsDecoder: int8(reader.TryReadBits(8)), | ||
| 14 | Length: int8(reader.TryReadBits(8)), | ||
| 15 | Props: int32(reader.TryReadBits(32)), | ||
| 16 | } | ||
| 17 | } | ||
diff --git a/pkg/messages/types/svcServerInfo.go b/pkg/messages/types/svcServerInfo.go new file mode 100644 index 0000000..b8bb308 --- /dev/null +++ b/pkg/messages/types/svcServerInfo.go | |||
| @@ -0,0 +1,43 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcServerInfo struct { | ||
| 6 | Protocol int16 | ||
| 7 | ServerCount int32 | ||
| 8 | IsHltv bool | ||
| 9 | IsDedicated bool | ||
| 10 | ClientCrc int32 | ||
| 11 | MaxClasses int16 | ||
| 12 | MapCrc int32 | ||
| 13 | PlayerSlot int8 | ||
| 14 | MaxClients int8 | ||
| 15 | Unk int32 | ||
| 16 | TickInterval int32 | ||
| 17 | COs int8 | ||
| 18 | GameDir string | ||
| 19 | MapName string | ||
| 20 | SkyName string | ||
| 21 | HostName string | ||
| 22 | } | ||
| 23 | |||
| 24 | func ParseSvcServerInfo(reader *bitreader.ReaderType) SvcServerInfo { | ||
| 25 | return SvcServerInfo{ | ||
| 26 | Protocol: int16(reader.TryReadBits(16)), | ||
| 27 | ServerCount: int32(reader.TryReadBits(32)), | ||
| 28 | IsHltv: reader.TryReadBool(), | ||
| 29 | IsDedicated: reader.TryReadBool(), | ||
| 30 | ClientCrc: int32(reader.TryReadBits(32)), | ||
| 31 | MaxClasses: int16(reader.TryReadBits(16)), | ||
| 32 | MapCrc: int32(reader.TryReadBits(32)), | ||
| 33 | PlayerSlot: int8(reader.TryReadBits(8)), | ||
| 34 | MaxClients: int8(reader.TryReadBits(8)), | ||
| 35 | Unk: int32(reader.TryReadBits(32)), | ||
| 36 | TickInterval: int32(reader.TryReadBits(32)), | ||
| 37 | COs: int8(reader.TryReadBits(8)), | ||
| 38 | GameDir: reader.TryReadString(), | ||
| 39 | MapName: reader.TryReadString(), | ||
| 40 | SkyName: reader.TryReadString(), | ||
| 41 | HostName: reader.TryReadString(), | ||
| 42 | } | ||
| 43 | } | ||
diff --git a/pkg/messages/types/svcSetPause.go b/pkg/messages/types/svcSetPause.go new file mode 100644 index 0000000..94303b7 --- /dev/null +++ b/pkg/messages/types/svcSetPause.go | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcSetPause struct { | ||
| 6 | Paused bool | ||
| 7 | } | ||
| 8 | |||
| 9 | func ParseSvcSetPause(reader *bitreader.ReaderType) SvcSetPause { | ||
| 10 | return SvcSetPause{ | ||
| 11 | Paused: reader.TryReadBool(), | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/pkg/messages/types/svcSetView.go b/pkg/messages/types/svcSetView.go new file mode 100644 index 0000000..70d1e2b --- /dev/null +++ b/pkg/messages/types/svcSetView.go | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcSetView struct { | ||
| 6 | EntityIndex int16 | ||
| 7 | } | ||
| 8 | |||
| 9 | func ParseSvcSetView(reader *bitreader.ReaderType) SvcSetView { | ||
| 10 | return SvcSetView{ | ||
| 11 | EntityIndex: int16(reader.TryReadBits(11)), | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/pkg/messages/types/svcSounds.go b/pkg/messages/types/svcSounds.go new file mode 100644 index 0000000..e87d584 --- /dev/null +++ b/pkg/messages/types/svcSounds.go | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcSounds struct { | ||
| 6 | ReliableSound bool | ||
| 7 | Size int8 | ||
| 8 | Length int16 | ||
| 9 | Data []byte | ||
| 10 | } | ||
| 11 | |||
| 12 | func ParseSvcSounds(reader *bitreader.ReaderType) SvcSounds { | ||
| 13 | svcSounds := SvcSounds{ | ||
| 14 | ReliableSound: reader.TryReadBool(), | ||
| 15 | } | ||
| 16 | if svcSounds.ReliableSound { | ||
| 17 | svcSounds.Size = 1 | ||
| 18 | svcSounds.Length = int16(reader.TryReadBits(8)) | ||
| 19 | } else { | ||
| 20 | svcSounds.Size = int8(reader.TryReadBits(8)) | ||
| 21 | svcSounds.Length = int16(reader.TryReadBits(16)) | ||
| 22 | } | ||
| 23 | svcSounds.Data = reader.TryReadBitsToSlice(int(svcSounds.Length)) | ||
| 24 | return svcSounds | ||
| 25 | } | ||
diff --git a/pkg/messages/types/svcSplitScreen.go b/pkg/messages/types/svcSplitScreen.go new file mode 100644 index 0000000..9c808bc --- /dev/null +++ b/pkg/messages/types/svcSplitScreen.go | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcSplitScreen struct { | ||
| 6 | Unk bool | ||
| 7 | Length int16 | ||
| 8 | Data []byte | ||
| 9 | } | ||
| 10 | |||
| 11 | func ParseSvcSplitScreen(reader *bitreader.ReaderType) SvcSplitScreen { | ||
| 12 | svcSplitScreen := SvcSplitScreen{ | ||
| 13 | Unk: reader.TryReadBool(), | ||
| 14 | Length: int16(reader.TryReadBits(11)), | ||
| 15 | } | ||
| 16 | svcSplitScreen.Data = reader.TryReadBitsToSlice(int(svcSplitScreen.Length)) | ||
| 17 | return svcSplitScreen | ||
| 18 | } | ||
diff --git a/pkg/messages/types/svcTempEntities.go b/pkg/messages/types/svcTempEntities.go new file mode 100644 index 0000000..d22423d --- /dev/null +++ b/pkg/messages/types/svcTempEntities.go | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcTempEntities struct { | ||
| 6 | NumEntries int8 | ||
| 7 | Length int32 | ||
| 8 | Data []byte | ||
| 9 | } | ||
| 10 | |||
| 11 | func ParseSvcTempEntities(reader *bitreader.ReaderType) SvcTempEntities { | ||
| 12 | svcTempEntities := SvcTempEntities{ | ||
| 13 | NumEntries: int8(reader.TryReadBits(8)), | ||
| 14 | Length: int32(reader.TryReadBits(17)), | ||
| 15 | } | ||
| 16 | svcTempEntities.Data = reader.TryReadBitsToSlice(int(svcTempEntities.Length)) | ||
| 17 | return svcTempEntities | ||
| 18 | } | ||
diff --git a/pkg/messages/types/svcUpdateStringTable.go b/pkg/messages/types/svcUpdateStringTable.go new file mode 100644 index 0000000..2840482 --- /dev/null +++ b/pkg/messages/types/svcUpdateStringTable.go | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcUpdateStringTable struct { | ||
| 6 | TableId int8 | ||
| 7 | NumChangedEntries int16 | ||
| 8 | Length int32 | ||
| 9 | Data []byte | ||
| 10 | } | ||
| 11 | |||
| 12 | func ParseSvcUpdateStringTable(reader *bitreader.ReaderType) SvcUpdateStringTable { | ||
| 13 | svcUpdateStringTable := SvcUpdateStringTable{ | ||
| 14 | TableId: int8(reader.TryReadBits(5)), | ||
| 15 | } | ||
| 16 | if reader.TryReadBool() { | ||
| 17 | svcUpdateStringTable.NumChangedEntries = int16(reader.TryReadBits(16)) | ||
| 18 | } | ||
| 19 | svcUpdateStringTable.Length = int32(reader.TryReadBits(20)) | ||
| 20 | svcUpdateStringTable.Data = reader.TryReadBitsToSlice(int(svcUpdateStringTable.Length)) | ||
| 21 | return svcUpdateStringTable | ||
| 22 | } | ||
diff --git a/pkg/messages/types/svcUserMessage.go b/pkg/messages/types/svcUserMessage.go new file mode 100644 index 0000000..b53c7c0 --- /dev/null +++ b/pkg/messages/types/svcUserMessage.go | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcUserMessage struct { | ||
| 6 | MsgType int8 | ||
| 7 | Length int16 | ||
| 8 | Data []byte | ||
| 9 | } | ||
| 10 | |||
| 11 | func ParseSvcUserMessage(reader *bitreader.ReaderType) SvcUserMessage { | ||
| 12 | svcUserMessage := SvcUserMessage{ | ||
| 13 | MsgType: int8(reader.TryReadBits(8)), | ||
| 14 | Length: int16(reader.TryReadBits(12)), | ||
| 15 | } | ||
| 16 | svcUserMessage.Data = reader.TryReadBitsToSlice(int(svcUserMessage.Length)) | ||
| 17 | return svcUserMessage | ||
| 18 | } | ||
diff --git a/pkg/messages/types/svcVoiceData.go b/pkg/messages/types/svcVoiceData.go new file mode 100644 index 0000000..b6c81d4 --- /dev/null +++ b/pkg/messages/types/svcVoiceData.go | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcVoiceData struct { | ||
| 6 | Client int8 | ||
| 7 | Proximity int8 | ||
| 8 | Length int16 | ||
| 9 | Data []byte | ||
| 10 | } | ||
| 11 | |||
| 12 | func ParseSvcVoiceData(reader *bitreader.ReaderType) SvcVoiceData { | ||
| 13 | svcVoiceData := SvcVoiceData{ | ||
| 14 | Client: int8(reader.TryReadBits(8)), | ||
| 15 | Proximity: int8(reader.TryReadBits(8)), | ||
| 16 | Length: int16(reader.TryReadBits(16)), | ||
| 17 | } | ||
| 18 | svcVoiceData.Data = reader.TryReadBitsToSlice(int(svcVoiceData.Length)) | ||
| 19 | return svcVoiceData | ||
| 20 | } | ||
diff --git a/pkg/messages/types/svcVoiceInit.go b/pkg/messages/types/svcVoiceInit.go new file mode 100644 index 0000000..4c95aab --- /dev/null +++ b/pkg/messages/types/svcVoiceInit.go | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/bitreader" | ||
| 4 | |||
| 5 | type SvcVoiceInit struct { | ||
| 6 | Codec string | ||
| 7 | Quality uint8 | ||
| 8 | Unk float32 | ||
| 9 | } | ||
| 10 | |||
| 11 | func ParseSvcVoiceInit(reader *bitreader.ReaderType) SvcVoiceInit { | ||
| 12 | svcVoiceInit := SvcVoiceInit{ | ||
| 13 | Codec: reader.TryReadString(), | ||
| 14 | Quality: uint8(reader.TryReadBits(8)), | ||
| 15 | } | ||
| 16 | if svcVoiceInit.Quality == 0b11111111 { | ||
| 17 | svcVoiceInit.Unk = reader.TryReadFloat32() | ||
| 18 | } | ||
| 19 | return svcVoiceInit | ||
| 20 | } | ||