diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2022-11-06 17:27:56 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-16 21:39:36 +0300 |
| commit | b8c9cdc9996706047b605fcb179161a678fcb8db (patch) | |
| tree | 9e8b7b345e8e9a6533ed4e1a7257b78f5f01ec8d | |
| parent | class parses and other stuff (diff) | |
| download | sdp.go-b8c9cdc9996706047b605fcb179161a678fcb8db.tar.gz sdp.go-b8c9cdc9996706047b605fcb179161a678fcb8db.tar.bz2 sdp.go-b8c9cdc9996706047b605fcb179161a678fcb8db.zip | |
changed github username + other stuff that i don't remember
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | classes/classes.go | 4 | ||||
| -rw-r--r-- | classes/netsvc/netsvc.go | 32 | ||||
| -rw-r--r-- | classes/netsvc/types.go | 106 | ||||
| -rw-r--r-- | go.mod | 4 | ||||
| -rw-r--r-- | go.sum | 6 | ||||
| -rw-r--r-- | main.go | 2 | ||||
| -rw-r--r-- | messages/header.go | 7 | ||||
| -rw-r--r-- | messages/messages.go | 18 | ||||
| -rw-r--r-- | messages/types.go | 2 | ||||
| -rw-r--r-- | utils/utils.go | 17 |
11 files changed, 179 insertions, 21 deletions
| @@ -1,2 +1,2 @@ | |||
| 1 | # DemoParser [](https://goreportcard.com/report/github.com/bisaxa/demoparser) [](https://github.com/BiSaXa/DemoParser/actions/workflows/CI.yml) [](https://github.com/BiSaXa/DemoParser/blob/main/LICENSE) | 1 | # DemoParser [](https://goreportcard.com/report/github.com/pektezol/demoparser) [](https://github.com/pektezol/DemoParser/actions/workflows/CI.yml) [](https://github.com/pektezol/DemoParser/blob/main/LICENSE) |
| 2 | Work-In-Progress demo parser for Portal 2. \ No newline at end of file | 2 | Work-In-Progress demo parser for Portal 2. \ No newline at end of file |
diff --git a/classes/classes.go b/classes/classes.go index 1a431f3..4d6acb0 100644 --- a/classes/classes.go +++ b/classes/classes.go | |||
| @@ -4,8 +4,8 @@ import ( | |||
| 4 | "encoding/binary" | 4 | "encoding/binary" |
| 5 | "os" | 5 | "os" |
| 6 | 6 | ||
| 7 | "github.com/bisaxa/bitreader" | 7 | "github.com/pektezol/bitreader" |
| 8 | "github.com/bisaxa/demoparser/utils" | 8 | "github.com/pektezol/demoparser/utils" |
| 9 | ) | 9 | ) |
| 10 | 10 | ||
| 11 | func ParseCmdInfo(file *os.File, MSSC int) []CmdInfo { | 11 | func ParseCmdInfo(file *os.File, MSSC int) []CmdInfo { |
diff --git a/classes/netsvc/netsvc.go b/classes/netsvc/netsvc.go new file mode 100644 index 0000000..a454310 --- /dev/null +++ b/classes/netsvc/netsvc.go | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | package netsvc | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "bytes" | ||
| 5 | "fmt" | ||
| 6 | |||
| 7 | "github.com/pektezol/bitreader" | ||
| 8 | "github.com/pektezol/demoparser/utils" | ||
| 9 | ) | ||
| 10 | |||
| 11 | const NET_TICK_SCALEUP = 10000 | ||
| 12 | |||
| 13 | func ParseNetSvcMessage(file []byte) { | ||
| 14 | reader := bitreader.Reader(bytes.NewReader(file), true) | ||
| 15 | bitsRead := 0 | ||
| 16 | for { | ||
| 17 | messageType, err := reader.ReadBits(6) | ||
| 18 | if err != nil { // No remaining bits left | ||
| 19 | break | ||
| 20 | } | ||
| 21 | switch messageType { | ||
| 22 | case 16: | ||
| 23 | var svcprint SvcPrint | ||
| 24 | svcprint.Message = utils.ReadStringFromSlice(file) | ||
| 25 | fmt.Println(svcprint) | ||
| 26 | bitsRead += len(svcprint.Message) * 8 | ||
| 27 | default: | ||
| 28 | //fmt.Println("default") | ||
| 29 | break | ||
| 30 | } | ||
| 31 | } | ||
| 32 | } | ||
diff --git a/classes/netsvc/types.go b/classes/netsvc/types.go new file mode 100644 index 0000000..2a52f96 --- /dev/null +++ b/classes/netsvc/types.go | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | package netsvc | ||
| 2 | |||
| 3 | type NetDisconnect struct { | ||
| 4 | Text string | ||
| 5 | } | ||
| 6 | |||
| 7 | type NetFile struct { | ||
| 8 | TransferId int32 | ||
| 9 | FileName string | ||
| 10 | FileRequested bool | ||
| 11 | } | ||
| 12 | |||
| 13 | type NetSplitScreenUser struct { | ||
| 14 | Unknown bool | ||
| 15 | } | ||
| 16 | |||
| 17 | type NetTick struct { | ||
| 18 | Tick int32 | ||
| 19 | HostFrameTime int16 | ||
| 20 | HostFrameTimeStdDeviation int16 | ||
| 21 | } | ||
| 22 | |||
| 23 | type NetStringCmd struct { | ||
| 24 | Command string | ||
| 25 | } | ||
| 26 | |||
| 27 | type ConVar struct { | ||
| 28 | Name string | ||
| 29 | Value string | ||
| 30 | } | ||
| 31 | |||
| 32 | type NetSetConVar struct { | ||
| 33 | Length int8 | ||
| 34 | ConVars []ConVar | ||
| 35 | } | ||
| 36 | |||
| 37 | type NetSignonStateOE struct { | ||
| 38 | SignonState int8 | ||
| 39 | SpawnCount int32 | ||
| 40 | } | ||
| 41 | |||
| 42 | type NetSignonStateNE struct { | ||
| 43 | NetSignonStateOE | ||
| 44 | NumServerPlayers int32 | ||
| 45 | IdsLength int32 | ||
| 46 | PlayerNetworkIds []byte | ||
| 47 | MapNameLength int32 | ||
| 48 | MapName string | ||
| 49 | } | ||
| 50 | |||
| 51 | type SvcServerInfo struct { | ||
| 52 | Protocol int8 | ||
| 53 | ServerCount int32 | ||
| 54 | IsHltv bool | ||
| 55 | IsDedicated bool | ||
| 56 | ClientCrc int32 | ||
| 57 | MaxClasses int16 | ||
| 58 | MapCrc int32 | ||
| 59 | PlayerSlot int8 | ||
| 60 | MaxClients int8 | ||
| 61 | Unk int32 // NE | ||
| 62 | TickInterval float32 | ||
| 63 | COs byte | ||
| 64 | GameDir string | ||
| 65 | MapName string | ||
| 66 | SkyName string | ||
| 67 | HostName string | ||
| 68 | } | ||
| 69 | |||
| 70 | type SvcSendTable struct { | ||
| 71 | NeedsDecoder bool | ||
| 72 | Length int8 | ||
| 73 | Props int // ? | ||
| 74 | } | ||
| 75 | |||
| 76 | type ServerClass struct { | ||
| 77 | ClassId int8 | ||
| 78 | ClassName string | ||
| 79 | DataTableName string | ||
| 80 | } | ||
| 81 | |||
| 82 | type SvcClassInfo struct { | ||
| 83 | Length int16 | ||
| 84 | CreateOnClient bool | ||
| 85 | ServerClasses []ServerClass | ||
| 86 | } | ||
| 87 | |||
| 88 | type SvcSetPause struct { | ||
| 89 | Paused bool | ||
| 90 | } | ||
| 91 | |||
| 92 | type SvcCreateStringTable struct { | ||
| 93 | Name string | ||
| 94 | MaxEntries int16 | ||
| 95 | NumEntries int8 | ||
| 96 | Length int32 | ||
| 97 | UserDataFixedSize bool | ||
| 98 | UserDataSize int32 | ||
| 99 | UserDataSizeBits int8 | ||
| 100 | Flags int8 | ||
| 101 | StringData int // ? | ||
| 102 | } | ||
| 103 | |||
| 104 | type SvcPrint struct { | ||
| 105 | Message string | ||
| 106 | } | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | module github.com/bisaxa/demoparser | 1 | module github.com/pektezol/demoparser |
| 2 | 2 | ||
| 3 | go 1.19 | 3 | go 1.19 |
| 4 | 4 | ||
| 5 | require github.com/bisaxa/bitreader v1.0.1-0.20220907151525-64e0e23b8a0f | 5 | require github.com/pektezol/bitreader v1.1.2 |
| @@ -1,4 +1,2 @@ | |||
| 1 | github.com/bisaxa/bitreader v1.0.1-0.20220907142402-05d7eb4e0f7b h1:OBmlKXvF6Uo+uMowYnu3y3BJWAnZlQzLAJYuwXS97HI= | 1 | github.com/pektezol/bitreader v1.1.2 h1:F0u8qiauIwh52lwiwy7UMQ03/bw4NuEXQU0UFBL+A2w= |
| 2 | github.com/bisaxa/bitreader v1.0.1-0.20220907142402-05d7eb4e0f7b/go.mod h1:AKIwOt+ZqRtuT7SyjGAF8x0kVPhlK8fgTVMlPEh7d0I= | 2 | github.com/pektezol/bitreader v1.1.2/go.mod h1:RKAUiA//jCPJzO10P+VSkBq4wfY38TaNjpCjQ+DmbcQ= |
| 3 | github.com/bisaxa/bitreader v1.0.1-0.20220907151525-64e0e23b8a0f h1:b48EQo2AaOOAxsWGk3NI+ZJDrXe9YT9KKSXz/agSuzQ= | ||
| 4 | github.com/bisaxa/bitreader v1.0.1-0.20220907151525-64e0e23b8a0f/go.mod h1:AKIwOt+ZqRtuT7SyjGAF8x0kVPhlK8fgTVMlPEh7d0I= | ||
| @@ -6,7 +6,7 @@ import ( | |||
| 6 | "log" | 6 | "log" |
| 7 | "os" | 7 | "os" |
| 8 | 8 | ||
| 9 | "github.com/bisaxa/demoparser/messages" | 9 | "github.com/pektezol/demoparser/messages" |
| 10 | ) | 10 | ) |
| 11 | 11 | ||
| 12 | func main() { | 12 | func main() { |
diff --git a/messages/header.go b/messages/header.go index 6320c71..34b36d3 100644 --- a/messages/header.go +++ b/messages/header.go | |||
| @@ -4,8 +4,8 @@ import ( | |||
| 4 | "fmt" | 4 | "fmt" |
| 5 | "os" | 5 | "os" |
| 6 | 6 | ||
| 7 | "github.com/bisaxa/bitreader" | 7 | "github.com/pektezol/bitreader" |
| 8 | "github.com/bisaxa/demoparser/utils" | 8 | "github.com/pektezol/demoparser/utils" |
| 9 | ) | 9 | ) |
| 10 | 10 | ||
| 11 | func ParseHeader(file *os.File) { | 11 | func ParseHeader(file *os.File) { |
| @@ -22,5 +22,8 @@ func ParseHeader(file *os.File) { | |||
| 22 | header.PlaybackTicks = int32(reader.TryReadInt32()) | 22 | header.PlaybackTicks = int32(reader.TryReadInt32()) |
| 23 | header.PlaybackFrames = int32(reader.TryReadInt32()) | 23 | header.PlaybackFrames = int32(reader.TryReadInt32()) |
| 24 | header.SignOnLength = int32(reader.TryReadInt32()) | 24 | header.SignOnLength = int32(reader.TryReadInt32()) |
| 25 | if header.DemoProtocol != 4 { // Old Engine == 2, 3 / New Engine == 4 | ||
| 26 | panic("Only New Engine is supported.") | ||
| 27 | } | ||
| 25 | fmt.Printf("%+v", header) | 28 | fmt.Printf("%+v", header) |
| 26 | } | 29 | } |
diff --git a/messages/messages.go b/messages/messages.go index 478b7c7..b40684b 100644 --- a/messages/messages.go +++ b/messages/messages.go | |||
| @@ -4,9 +4,10 @@ import ( | |||
| 4 | "fmt" | 4 | "fmt" |
| 5 | "os" | 5 | "os" |
| 6 | 6 | ||
| 7 | "github.com/bisaxa/bitreader" | 7 | "github.com/pektezol/bitreader" |
| 8 | "github.com/bisaxa/demoparser/classes" | 8 | "github.com/pektezol/demoparser/classes" |
| 9 | "github.com/bisaxa/demoparser/utils" | 9 | "github.com/pektezol/demoparser/classes/netsvc" |
| 10 | "github.com/pektezol/demoparser/utils" | ||
| 10 | ) | 11 | ) |
| 11 | 12 | ||
| 12 | func ParseMessage(file *os.File) (statusCode int) { | 13 | func ParseMessage(file *os.File) (statusCode int) { |
| @@ -22,7 +23,10 @@ func ParseMessage(file *os.File) (statusCode int) { | |||
| 22 | packet.InSequence = int32(reader.TryReadInt32()) | 23 | packet.InSequence = int32(reader.TryReadInt32()) |
| 23 | packet.OutSequence = int32(reader.TryReadInt32()) | 24 | packet.OutSequence = int32(reader.TryReadInt32()) |
| 24 | packet.Size = int32(reader.TryReadInt32()) | 25 | packet.Size = int32(reader.TryReadInt32()) |
| 25 | reader.SkipBytes(int(packet.Size)) // TODO: NET/SVC Message Parsing | 26 | data := utils.ReadByteFromFile(file, packet.Size) |
| 27 | //fmt.Println(data) | ||
| 28 | netsvc.ParseNetSvcMessage(data) | ||
| 29 | //reader.SkipBytes(int(packet.Size)) // TODO: NET/SVC Message Parsing | ||
| 26 | fmt.Printf("[%d] (%d) SignOn: %v\n", messageTick, messageSlot, packet) | 30 | fmt.Printf("[%d] (%d) SignOn: %v\n", messageTick, messageSlot, packet) |
| 27 | return 1 | 31 | return 1 |
| 28 | case 0x02: // Packet | 32 | case 0x02: // Packet |
| @@ -32,7 +36,7 @@ func ParseMessage(file *os.File) (statusCode int) { | |||
| 32 | packet.OutSequence = int32(reader.TryReadInt32()) | 36 | packet.OutSequence = int32(reader.TryReadInt32()) |
| 33 | packet.Size = int32(reader.TryReadInt32()) | 37 | packet.Size = int32(reader.TryReadInt32()) |
| 34 | reader.SkipBytes(int(packet.Size)) // TODO: NET/SVC Message Parsing | 38 | reader.SkipBytes(int(packet.Size)) // TODO: NET/SVC Message Parsing |
| 35 | fmt.Printf("[%d] Packet: %v\n", messageTick, packet) | 39 | //fmt.Printf("[%d] Packet: %v\n", messageTick, packet) |
| 36 | return 2 | 40 | return 2 |
| 37 | case 0x03: // SyncTick | 41 | case 0x03: // SyncTick |
| 38 | return 3 | 42 | return 3 |
| @@ -40,14 +44,14 @@ func ParseMessage(file *os.File) (statusCode int) { | |||
| 40 | var consolecmd ConsoleCmd | 44 | var consolecmd ConsoleCmd |
| 41 | consolecmd.Size = int32(reader.TryReadInt32()) | 45 | consolecmd.Size = int32(reader.TryReadInt32()) |
| 42 | consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size)) | 46 | consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size)) |
| 43 | fmt.Printf("[%d] ConsoleCmd: %s\n", messageTick, consolecmd.Data) | 47 | //fmt.Printf("[%d] ConsoleCmd: %s\n", messageTick, consolecmd.Data) |
| 44 | return 4 | 48 | return 4 |
| 45 | case 0x05: // UserCmd | 49 | case 0x05: // UserCmd |
| 46 | var usercmd UserCmd | 50 | var usercmd UserCmd |
| 47 | usercmd.Cmd = int32(reader.TryReadInt32()) | 51 | usercmd.Cmd = int32(reader.TryReadInt32()) |
| 48 | usercmd.Size = int32(reader.TryReadInt32()) | 52 | usercmd.Size = int32(reader.TryReadInt32()) |
| 49 | usercmd.Data = classes.ParseUserCmdInfo(file, int(usercmd.Size)) | 53 | usercmd.Data = classes.ParseUserCmdInfo(file, int(usercmd.Size)) |
| 50 | fmt.Printf("[%d] UserCmd: %v\n", messageTick, usercmd.Data) | 54 | //fmt.Printf("[%d] UserCmd: %v\n", messageTick, usercmd.Data) |
| 51 | return 5 | 55 | return 5 |
| 52 | case 0x06: // DataTables | 56 | case 0x06: // DataTables |
| 53 | var datatables DataTables | 57 | var datatables DataTables |
diff --git a/messages/types.go b/messages/types.go index a8dd19a..9c92c54 100644 --- a/messages/types.go +++ b/messages/types.go | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | package messages | 1 | package messages |
| 2 | 2 | ||
| 3 | import "github.com/bisaxa/demoparser/classes" | 3 | import "github.com/pektezol/demoparser/classes" |
| 4 | 4 | ||
| 5 | type Header struct { | 5 | type Header struct { |
| 6 | DemoFileStamp string | 6 | DemoFileStamp string |
diff --git a/utils/utils.go b/utils/utils.go index d25fa36..db1b02f 100644 --- a/utils/utils.go +++ b/utils/utils.go | |||
| @@ -1,10 +1,11 @@ | |||
| 1 | package utils | 1 | package utils |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "bytes" | ||
| 4 | "os" | 5 | "os" |
| 5 | "unsafe" | 6 | "unsafe" |
| 6 | 7 | ||
| 7 | "github.com/bisaxa/bitreader" | 8 | "github.com/pektezol/bitreader" |
| 8 | ) | 9 | ) |
| 9 | 10 | ||
| 10 | func CheckError(e error) { | 11 | func CheckError(e error) { |
| @@ -33,6 +34,20 @@ func ReadStringFromFile(file *os.File) string { | |||
| 33 | return output | 34 | return output |
| 34 | } | 35 | } |
| 35 | 36 | ||
| 37 | func ReadStringFromSlice(file []byte) string { | ||
| 38 | var output string | ||
| 39 | reader := bitreader.Reader(bytes.NewReader(file), true) | ||
| 40 | for { | ||
| 41 | value, err := reader.ReadBytes(1) | ||
| 42 | CheckError(err) | ||
| 43 | if value == 0 { | ||
| 44 | break | ||
| 45 | } | ||
| 46 | output += string(rune(value)) | ||
| 47 | } | ||
| 48 | return output | ||
| 49 | } | ||
| 50 | |||
| 36 | func FloatArrFromBytes(byteArr []byte) []float32 { | 51 | func FloatArrFromBytes(byteArr []byte) []float32 { |
| 37 | if len(byteArr) == 0 { | 52 | if len(byteArr) == 0 { |
| 38 | return nil | 53 | return nil |