aboutsummaryrefslogtreecommitdiff
path: root/messages
diff options
context:
space:
mode:
Diffstat (limited to 'messages')
-rw-r--r--messages/messages.go78
-rw-r--r--messages/types.go20
2 files changed, 62 insertions, 36 deletions
diff --git a/messages/messages.go b/messages/messages.go
index 04c7268..7d00ec1 100644
--- a/messages/messages.go
+++ b/messages/messages.go
@@ -3,43 +3,38 @@ package messages
3import ( 3import (
4 "fmt" 4 "fmt"
5 "os" 5 "os"
6 "parser/classes"
7 "parser/utils" 6 "parser/utils"
8) 7)
9 8
10const ( 9const MSSC int32 = 2
11 MSSC int32 = 2
12)
13 10
14func MessageTypeCheck(file *os.File) (statusCode int) { 11func ParseMessage(file *os.File) (statusCode int) {
15 Type := make([]byte, 1) 12 var message Message
16 Tick := make([]byte, 4) 13 message.Type = utils.ReadByteFromFile(file, 1)[0]
17 Slot := make([]byte, 1) 14 message.Tick = int(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
18 file.Read(Type) 15 message.Slot = utils.ReadByteFromFile(file, 1)[0]
19 file.Read(Tick) 16 switch message.Type {
20 file.Read(Slot)
21 switch Type[0] {
22 case 0x01: // SignOn 17 case 0x01: // SignOn
23 var packet Packet 18 var packet Packet
24 var cmdinfo classes.CmdInfo 19 // var cmdinfo classes.CmdInfo
25 packet.PacketInfo = utils.ReadByteFromFile(file, 76*MSSC) 20 packet.PacketInfo = utils.ReadByteFromFile(file, 76*MSSC)
26 packet.InSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 21 packet.InSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
27 packet.OutSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 22 packet.OutSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
28 packet.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 23 packet.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
29 packet.Data = utils.ReadByteFromFile(file, packet.Size) 24 packet.Data = utils.ReadByteFromFile(file, packet.Size)
30 cmdinfo = classes.CmdInfoInit(packet.PacketInfo) 25 // cmdinfo = classes.CmdInfoInit(packet.PacketInfo)
31 fmt.Println(cmdinfo) 26 // fmt.Println(cmdinfo)
32 return 1 27 return 1
33 case 0x02: // Packet 28 case 0x02: // Packet
34 var packet Packet 29 var packet Packet
35 var cmdinfo classes.CmdInfo 30 // var cmdinfo classes.CmdInfo
36 packet.PacketInfo = utils.ReadByteFromFile(file, 76*MSSC) 31 packet.PacketInfo = utils.ReadByteFromFile(file, 76*MSSC)
37 packet.InSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 32 packet.InSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
38 packet.OutSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 33 packet.OutSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
39 packet.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 34 packet.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
40 packet.Data = utils.ReadByteFromFile(file, packet.Size) 35 packet.Data = utils.ReadByteFromFile(file, packet.Size)
41 cmdinfo = classes.CmdInfoInit(packet.PacketInfo) 36 // cmdinfo = classes.CmdInfoInit(packet.PacketInfo)
42 fmt.Printf("[%d] %v\n", utils.IntFromBytes(Tick), cmdinfo) 37 // fmt.Printf("[%d] %v\n", utils.IntFromBytes(Tick), cmdinfo)
43 return 2 38 return 2
44 case 0x03: // SyncTick 39 case 0x03: // SyncTick
45 return 3 40 return 3
@@ -47,16 +42,16 @@ func MessageTypeCheck(file *os.File) (statusCode int) {
47 var consolecmd ConsoleCmd 42 var consolecmd ConsoleCmd
48 consolecmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 43 consolecmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
49 consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size)) 44 consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size))
50 fmt.Printf("[%d] %s\n", utils.IntFromBytes(Tick), consolecmd.Data) 45 fmt.Printf("[%d] %s\n", message.Tick, consolecmd.Data)
51 return 4 46 return 4
52 case 0x05: // Usercmd FIXME: Correct bit-packing inside classes 47 case 0x05: // Usercmd FIXME: Correct bit-packing inside classes
53 var usercmd UserCmd 48 var usercmd UserCmd
54 var usercmdinfo classes.UserCmdInfo 49 // var usercmdinfo classes.UserCmdInfo
55 usercmd.Cmd = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 50 usercmd.Cmd = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
56 usercmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 51 usercmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
57 usercmd.Data = utils.ReadByteFromFile(file, usercmd.Size) 52 usercmd.Data = utils.ReadByteFromFile(file, usercmd.Size)
58 usercmdinfo = classes.UserCmdInfoInit(usercmd.Data, int(usercmd.Size)) 53 // usercmdinfo = classes.UserCmdInfoInit(usercmd.Data, int(usercmd.Size))
59 fmt.Printf("[%d] UserCmd: %v\n", utils.IntFromBytes(Tick), usercmdinfo) 54 // fmt.Printf("[%d] UserCmd: %v\n", utils.IntFromBytes(Tick), usercmdinfo)
60 return 5 55 return 5
61 case 0x06: // DataTables 56 case 0x06: // DataTables
62 var datatables DataTables 57 var datatables DataTables
@@ -67,26 +62,37 @@ func MessageTypeCheck(file *os.File) (statusCode int) {
67 // fmt.Printf("[%d] DataTables: %v\n", utils.IntFromBytes(Size), stringtable) 62 // fmt.Printf("[%d] DataTables: %v\n", utils.IntFromBytes(Size), stringtable)
68 return 6 63 return 6
69 case 0x07: // Stop 64 case 0x07: // Stop
70 fmt.Println("Stop") 65 fmt.Println("Stop - End of Demo")
71 return 7 66 return 7
72 case 0x08: // CustomData 67 case 0x08: // CustomData
73 Unknown := make([]byte, 4) 68 var customdata CustomData
74 file.Read(Unknown) 69 customdata.Unknown = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
75 Size := make([]byte, 4) 70 customdata.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
76 file.Read(Size) 71 customdata.Data = utils.ReadByteFromFile(file, customdata.Size)
77 Data := make([]byte, utils.IntFromBytes(Size))
78 file.Read(Data)
79 return 8 72 return 8
80 case 0x09: // StringTables 73 case 0x09: // StringTables
81 Size := make([]byte, 4) 74 var stringtables StringTables
82 file.Read(Size) 75 stringtables.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
83 Data := make([]byte, utils.IntFromBytes(Size)) 76 stringtables.Data = utils.ReadByteFromFile(file, stringtables.Size)
84 file.Read(Data)
85 return 9 77 return 9
86 default: 78 default:
87 return 0 79 return 0
88 } 80 }
89 //fmt.Println(Type[0]) 81
90 //fmt.Println(utils.IntFromBytes(Tick)) 82}
91 //fmt.Println(Slot[0]) 83
84func ParseHeader(file *os.File) {
85 var header Header
86 header.DemoFileStamp = string(utils.ReadByteFromFile(file, 8))
87 header.DemoProtocol = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
88 header.NetworkProtocol = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
89 header.ServerName = string(utils.ReadByteFromFile(file, 260))
90 header.ClientName = string(utils.ReadByteFromFile(file, 260))
91 header.MapName = string(utils.ReadByteFromFile(file, 260))
92 header.GameDirectory = string(utils.ReadByteFromFile(file, 260))
93 header.PlaybackTime = float32(utils.FloatFromBytes(utils.ReadByteFromFile(file, 4)))
94 header.PlaybackTicks = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
95 header.PlaybackFrames = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
96 header.SignOnLength = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
97 fmt.Println(header)
92} 98}
diff --git a/messages/types.go b/messages/types.go
index ee42a96..bb19444 100644
--- a/messages/types.go
+++ b/messages/types.go
@@ -1,5 +1,25 @@
1package messages 1package messages
2 2
3type Header struct {
4 DemoFileStamp string
5 DemoProtocol int32
6 NetworkProtocol int32
7 ServerName string
8 ClientName string
9 MapName string
10 GameDirectory string
11 PlaybackTime float32
12 PlaybackTicks int32
13 PlaybackFrames int32
14 SignOnLength int32
15}
16
17type Message struct {
18 Type byte
19 Tick int
20 Slot byte
21}
22
3type Packet struct { 23type Packet struct {
4 PacketInfo []byte 24 PacketInfo []byte
5 InSequence int32 25 InSequence int32