aboutsummaryrefslogtreecommitdiff
path: root/messages/messages.go
diff options
context:
space:
mode:
authorBiSaXa <1669855+BiSaXa@users.noreply.github.com>2022-09-07 19:40:16 +0300
committerArda Serdar Pektezol <1669855+pektezol@users.noreply.github.com>2023-09-16 21:39:36 +0300
commit4e71a481884c0c43aea3d0ee695ae68cdec56478 (patch)
treed75c96612526a7c686d9f4d85af6b89c7cd864e6 /messages/messages.go
parentfinal commit before rewrite (diff)
downloadsdp.go-4e71a481884c0c43aea3d0ee695ae68cdec56478.tar.gz
sdp.go-4e71a481884c0c43aea3d0ee695ae68cdec56478.tar.bz2
sdp.go-4e71a481884c0c43aea3d0ee695ae68cdec56478.zip
first rewrite commit using bisaxa/bitreader
Diffstat (limited to 'messages/messages.go')
-rw-r--r--messages/messages.go91
1 files changed, 30 insertions, 61 deletions
diff --git a/messages/messages.go b/messages/messages.go
index a2b0ebd..4d94728 100644
--- a/messages/messages.go
+++ b/messages/messages.go
@@ -4,97 +4,66 @@ import (
4 "fmt" 4 "fmt"
5 "os" 5 "os"
6 6
7 "github.com/bisaxa/bitreader"
7 "github.com/bisaxa/demoparser/classes" 8 "github.com/bisaxa/demoparser/classes"
8 "github.com/bisaxa/demoparser/utils" 9 "github.com/bisaxa/demoparser/utils"
9) 10)
10 11
11const MSSC int32 = 2
12
13func ParseMessage(file *os.File) (statusCode int) { 12func ParseMessage(file *os.File) (statusCode int) {
14 var message Message 13 reader := bitreader.Reader(file, true)
15 message.Type = utils.ReadByteFromFile(file, 1)[0] 14 messageType := reader.TryReadInt8()
16 message.Tick = int(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 15 messageTick := reader.TryReadInt32()
17 message.Slot = utils.ReadByteFromFile(file, 1)[0] 16 messageSlot := reader.TryReadInt8()
18 switch message.Type { 17 fmt.Println(messageType, messageTick, messageSlot)
18 switch messageType {
19 case 0x01: // SignOn 19 case 0x01: // SignOn
20 var packet Packet 20 var packet Packet
21 // var cmdinfo classes.CmdInfo 21 packet.PacketInfo = classes.ParseCmdInfo(file, 2)
22 packet.PacketInfo = utils.ReadByteFromFile(file, 76*MSSC) 22 packet.InSequence = int32(reader.TryReadInt32())
23 packet.InSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 23 packet.OutSequence = int32(reader.TryReadInt32())
24 packet.OutSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 24 packet.Size = int32(reader.TryReadInt32())
25 packet.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 25 reader.SkipBytes(int(packet.Size))
26 packet.Data = utils.ReadByteFromFile(file, packet.Size)
27 // cmdinfo = classes.CmdInfoInit(packet.PacketInfo)
28 // fmt.Println(cmdinfo)
29 return 1 26 return 1
30 case 0x02: // Packet 27 case 0x02: // Packet
31 var packet Packet 28 var packet Packet
32 // var cmdinfo classes.CmdInfo 29 packet.PacketInfo = classes.ParseCmdInfo(file, 2)
33 packet.PacketInfo = utils.ReadByteFromFile(file, 76*MSSC) 30 packet.InSequence = int32(reader.TryReadInt32())
34 packet.InSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 31 packet.OutSequence = int32(reader.TryReadInt32())
35 packet.OutSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 32 packet.Size = int32(reader.TryReadInt32())
36 packet.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 33 reader.SkipBytes(int(packet.Size))
37 packet.Data = utils.ReadByteFromFile(file, packet.Size)
38 // cmdinfo = classes.CmdInfoInit(packet.PacketInfo)
39 // fmt.Printf("[%d] %v\n", utils.IntFromBytes(Tick), cmdinfo)
40 return 2 34 return 2
41 case 0x03: // SyncTick 35 case 0x03: // SyncTick
42 return 3 36 return 3
43 case 0x04: // Consolecmd 37 case 0x04: // ConsoleCmd
44 var consolecmd ConsoleCmd 38 var consolecmd ConsoleCmd
45 consolecmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 39 consolecmd.Size = int32(reader.TryReadInt32())
46 consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size)) 40 consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size))
47 //fmt.Printf("[%d] %s\n", message.Tick, consolecmd.Data)
48 return 4 41 return 4
49 case 0x05: // Usercmd 42 case 0x05: // UserCmd
50 var usercmd UserCmd 43 var usercmd UserCmd
51 var usercmdinfo classes.UserCmdInfo 44 usercmd.Cmd = int32(reader.TryReadInt32())
52 usercmd.Cmd = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 45 usercmd.Size = int32(reader.TryReadInt32())
53 usercmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 46 usercmd.Data = classes.ParseUserCmdInfo(file, int(usercmd.Size))
54 usercmd.Data = utils.ReadByteFromFile(file, usercmd.Size)
55 usercmdinfo = classes.UserCmdInfoInit(usercmd.Data, usercmd.Size)
56 fmt.Printf("[%d] UserCmd: %v\n", message.Tick, usercmdinfo)
57 return 5 47 return 5
58 case 0x06: // DataTables 48 case 0x06: // DataTables
59 var datatables DataTables 49 var datatables DataTables
60 //var stringtable classes.StringTable 50 datatables.Size = int32(reader.TryReadInt32())
61 datatables.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 51 reader.SkipBytes(int(datatables.Size))
62 datatables.Data = utils.ReadByteFromFile(file, datatables.Size)
63 // stringtable = classes.StringTableInit(Data)
64 // fmt.Printf("[%d] DataTables: %v\n", utils.IntFromBytes(Size), stringtable)
65 return 6 52 return 6
66 case 0x07: // Stop 53 case 0x07: // Stop
67 fmt.Println("Stop - End of Demo")
68 return 7 54 return 7
69 case 0x08: // CustomData 55 case 0x08: // CustomData
70 var customdata CustomData 56 var customdata CustomData
71 customdata.Unknown = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 57 customdata.Unknown = int32(reader.TryReadInt32())
72 customdata.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 58 customdata.Size = int32(reader.TryReadInt32())
73 customdata.Data = utils.ReadByteFromFile(file, customdata.Size) 59 reader.SkipBytes(int(customdata.Size))
74 return 8 60 return 8
75 case 0x09: // StringTables 61 case 0x09: // StringTables
76 var stringtables StringTables 62 var stringtables StringTables
77 stringtables.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4))) 63 stringtables.Size = int32(reader.TryReadInt32())
78 stringtables.Data = utils.ReadByteFromFile(file, stringtables.Size) 64 reader.SkipBytes(int(stringtables.Size))
79 return 9 65 return 9
80 default: 66 default:
81 return 0 67 return 0
82 } 68 }
83
84}
85
86func ParseHeader(file *os.File) {
87 var header Header
88 header.DemoFileStamp = string(utils.ReadByteFromFile(file, 8))
89 header.DemoProtocol = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
90 header.NetworkProtocol = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
91 header.ServerName = string(utils.ReadByteFromFile(file, 260))
92 header.ClientName = string(utils.ReadByteFromFile(file, 260))
93 header.MapName = string(utils.ReadByteFromFile(file, 260))
94 header.GameDirectory = string(utils.ReadByteFromFile(file, 260))
95 header.PlaybackTime = float32(utils.FloatFromBytes(utils.ReadByteFromFile(file, 4)))
96 header.PlaybackTicks = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
97 header.PlaybackFrames = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
98 header.SignOnLength = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
99 fmt.Println(header)
100} 69}