diff options
Diffstat (limited to 'messages')
| -rw-r--r-- | messages/header.go | 29 | ||||
| -rw-r--r-- | messages/messages.go | 78 | ||||
| -rw-r--r-- | messages/types.go | 52 |
3 files changed, 0 insertions, 159 deletions
diff --git a/messages/header.go b/messages/header.go deleted file mode 100644 index 34b36d3..0000000 --- a/messages/header.go +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "os" | ||
| 6 | |||
| 7 | "github.com/pektezol/bitreader" | ||
| 8 | "github.com/pektezol/demoparser/utils" | ||
| 9 | ) | ||
| 10 | |||
| 11 | func ParseHeader(file *os.File) { | ||
| 12 | var header Header | ||
| 13 | reader := bitreader.Reader(file, true) | ||
| 14 | header.DemoFileStamp = string(utils.ReadByteFromFile(file, 8)) | ||
| 15 | header.DemoProtocol = int32(reader.TryReadInt32()) | ||
| 16 | header.NetworkProtocol = int32(reader.TryReadInt32()) | ||
| 17 | header.ServerName = string(utils.ReadByteFromFile(file, 260)) | ||
| 18 | header.ClientName = string(utils.ReadByteFromFile(file, 260)) | ||
| 19 | header.MapName = string(utils.ReadByteFromFile(file, 260)) | ||
| 20 | header.GameDirectory = string(utils.ReadByteFromFile(file, 260)) | ||
| 21 | header.PlaybackTime = float32(reader.TryReadFloat32()) | ||
| 22 | header.PlaybackTicks = int32(reader.TryReadInt32()) | ||
| 23 | header.PlaybackFrames = 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 | } | ||
| 28 | fmt.Printf("%+v", header) | ||
| 29 | } | ||
diff --git a/messages/messages.go b/messages/messages.go deleted file mode 100644 index b40684b..0000000 --- a/messages/messages.go +++ /dev/null | |||
| @@ -1,78 +0,0 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "os" | ||
| 6 | |||
| 7 | "github.com/pektezol/bitreader" | ||
| 8 | "github.com/pektezol/demoparser/classes" | ||
| 9 | "github.com/pektezol/demoparser/classes/netsvc" | ||
| 10 | "github.com/pektezol/demoparser/utils" | ||
| 11 | ) | ||
| 12 | |||
| 13 | func ParseMessage(file *os.File) (statusCode int) { | ||
| 14 | reader := bitreader.Reader(file, true) | ||
| 15 | messageType := reader.TryReadInt8() | ||
| 16 | messageTick := reader.TryReadInt32() | ||
| 17 | messageSlot := reader.TryReadInt8() | ||
| 18 | //fmt.Println(messageType, messageTick, messageSlot) | ||
| 19 | switch messageType { | ||
| 20 | case 0x01: // SignOn | ||
| 21 | var packet Packet | ||
| 22 | packet.PacketInfo = classes.ParseCmdInfo(file, 2) | ||
| 23 | packet.InSequence = int32(reader.TryReadInt32()) | ||
| 24 | packet.OutSequence = int32(reader.TryReadInt32()) | ||
| 25 | packet.Size = int32(reader.TryReadInt32()) | ||
| 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 | ||
| 30 | fmt.Printf("[%d] (%d) SignOn: %v\n", messageTick, messageSlot, packet) | ||
| 31 | return 1 | ||
| 32 | case 0x02: // Packet | ||
| 33 | var packet Packet | ||
| 34 | packet.PacketInfo = classes.ParseCmdInfo(file, 2) | ||
| 35 | packet.InSequence = int32(reader.TryReadInt32()) | ||
| 36 | packet.OutSequence = int32(reader.TryReadInt32()) | ||
| 37 | packet.Size = int32(reader.TryReadInt32()) | ||
| 38 | reader.SkipBytes(int(packet.Size)) // TODO: NET/SVC Message Parsing | ||
| 39 | //fmt.Printf("[%d] Packet: %v\n", messageTick, packet) | ||
| 40 | return 2 | ||
| 41 | case 0x03: // SyncTick | ||
| 42 | return 3 | ||
| 43 | case 0x04: // ConsoleCmd | ||
| 44 | var consolecmd ConsoleCmd | ||
| 45 | consolecmd.Size = int32(reader.TryReadInt32()) | ||
| 46 | consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size)) | ||
| 47 | //fmt.Printf("[%d] ConsoleCmd: %s\n", messageTick, consolecmd.Data) | ||
| 48 | return 4 | ||
| 49 | case 0x05: // UserCmd | ||
| 50 | var usercmd UserCmd | ||
| 51 | usercmd.Cmd = int32(reader.TryReadInt32()) | ||
| 52 | usercmd.Size = int32(reader.TryReadInt32()) | ||
| 53 | usercmd.Data = classes.ParseUserCmdInfo(file, int(usercmd.Size)) | ||
| 54 | //fmt.Printf("[%d] UserCmd: %v\n", messageTick, usercmd.Data) | ||
| 55 | return 5 | ||
| 56 | case 0x06: // DataTables | ||
| 57 | var datatables DataTables | ||
| 58 | datatables.Size = int32(reader.TryReadInt32()) | ||
| 59 | reader.SkipBytes(int(datatables.Size)) // TODO: DataTables Data | ||
| 60 | return 6 | ||
| 61 | case 0x07: // Stop | ||
| 62 | fmt.Printf("[%d] Stop\n", messageTick) | ||
| 63 | return 7 | ||
| 64 | case 0x08: // CustomData | ||
| 65 | var customdata CustomData | ||
| 66 | customdata.Unknown = int32(reader.TryReadInt32()) | ||
| 67 | customdata.Size = int32(reader.TryReadInt32()) | ||
| 68 | reader.SkipBytes(int(customdata.Size)) // TODO: CustomData Data | ||
| 69 | return 8 | ||
| 70 | case 0x09: // StringTables | ||
| 71 | var stringtables StringTables | ||
| 72 | stringtables.Size = int32(reader.TryReadInt32()) | ||
| 73 | reader.SkipBytes(int(stringtables.Size)) // TODO: StringTables Data | ||
| 74 | return 9 | ||
| 75 | default: | ||
| 76 | return 0 | ||
| 77 | } | ||
| 78 | } | ||
diff --git a/messages/types.go b/messages/types.go deleted file mode 100644 index 9c92c54..0000000 --- a/messages/types.go +++ /dev/null | |||
| @@ -1,52 +0,0 @@ | |||
| 1 | package messages | ||
| 2 | |||
| 3 | import "github.com/pektezol/demoparser/classes" | ||
| 4 | |||
| 5 | type Header struct { | ||
| 6 | DemoFileStamp string | ||
| 7 | DemoProtocol int32 | ||
| 8 | NetworkProtocol int32 | ||
| 9 | ServerName string | ||
| 10 | ClientName string | ||
| 11 | MapName string | ||
| 12 | GameDirectory string | ||
| 13 | PlaybackTime float32 | ||
| 14 | PlaybackTicks int32 | ||
| 15 | PlaybackFrames int32 | ||
| 16 | SignOnLength int32 | ||
| 17 | } | ||
| 18 | |||
| 19 | type Packet struct { | ||
| 20 | PacketInfo []classes.CmdInfo | ||
| 21 | InSequence int32 | ||
| 22 | OutSequence int32 | ||
| 23 | Size int32 | ||
| 24 | Data []byte | ||
| 25 | } | ||
| 26 | |||
| 27 | type ConsoleCmd struct { | ||
| 28 | Size int32 | ||
| 29 | Data string | ||
| 30 | } | ||
| 31 | |||
| 32 | type UserCmd struct { | ||
| 33 | Cmd int32 | ||
| 34 | Size int32 | ||
| 35 | Data classes.UserCmdInfo | ||
| 36 | } | ||
| 37 | |||
| 38 | type DataTables struct { | ||
| 39 | Size int32 | ||
| 40 | Data classes.DataTables | ||
| 41 | } | ||
| 42 | |||
| 43 | type CustomData struct { | ||
| 44 | Unknown int32 | ||
| 45 | Size int32 | ||
| 46 | Data []byte | ||
| 47 | } | ||
| 48 | |||
| 49 | type StringTables struct { | ||
| 50 | Size int32 | ||
| 51 | Data []classes.StringTable | ||
| 52 | } | ||