aboutsummaryrefslogtreecommitdiff
path: root/messages/messages.go
blob: db9d027f5239eef3ad47955bfee48c8bdb1b8b5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package messages

import (
	"fmt"
	"os"
	"parser/classes"
	"parser/utils"
)

func MessageTypeCheck(file *os.File) (statusCode int) {
	var MSSC int32 = 2
	Type := make([]byte, 1)
	Tick := make([]byte, 4)
	Slot := make([]byte, 1)
	file.Read(Type)
	file.Read(Tick)
	file.Read(Slot)
	switch Type[0] {
	case 0x01: // SignOn
		var packet Packet
		var cmdinfo classes.CmdInfo
		packet.PacketInfo = utils.ReadByteFromFile(file, 76*MSSC)
		packet.InSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
		packet.OutSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
		packet.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
		packet.Data = utils.ReadByteFromFile(file, packet.Size)
		cmdinfo = classes.CmdInfoInit(packet.PacketInfo)
		fmt.Println(cmdinfo)
		return 1
	case 0x02: // Packet
		var packet Packet
		var cmdinfo classes.CmdInfo
		packet.PacketInfo = utils.ReadByteFromFile(file, 76*MSSC)
		packet.InSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
		packet.OutSequence = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
		packet.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
		packet.Data = utils.ReadByteFromFile(file, packet.Size)
		cmdinfo = classes.CmdInfoInit(packet.PacketInfo)
		fmt.Printf("[%d] %v\n", utils.IntFromBytes(Tick), cmdinfo)
		return 2
	case 0x03: // SyncTick
		return 3
	case 0x04: // Consolecmd
		var consolecmd ConsoleCmd
		consolecmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
		consolecmd.Data = string(utils.ReadByteFromFile(file, consolecmd.Size))
		fmt.Printf("[%d] %s\n", utils.IntFromBytes(Tick), consolecmd.Data)
		return 4
	case 0x05: // Usercmd FIXME: Correct bit-packing inside classes
		var usercmd UserCmd
		//var usercmdinfo classes.UserCmdInfo
		usercmd.Cmd = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
		usercmd.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
		usercmd.Data = utils.ReadByteFromFile(file, usercmd.Size)
		//usercmdinfo = classes.UserCmdInfoInit(usercmd.Data, int(usercmd.Size))
		//fmt.Printf("[%d] UserCmd: %v\n", utils.IntFromBytes(Tick), usercmdinfo)
		return 5
	case 0x06: // DataTables
		var datatables DataTables
		//var stringtable classes.StringTable
		datatables.Size = int32(utils.IntFromBytes(utils.ReadByteFromFile(file, 4)))
		datatables.Data = utils.ReadByteFromFile(file, datatables.Size)
		// stringtable = classes.StringTableInit(Data)
		// fmt.Printf("[%d] DataTables: %v\n", utils.IntFromBytes(Size), stringtable)
		return 6
	case 0x07: // Stop
		fmt.Println("Stop")
		return 7
	case 0x08: // CustomData
		Unknown := make([]byte, 4)
		file.Read(Unknown)
		Size := make([]byte, 4)
		file.Read(Size)
		Data := make([]byte, utils.IntFromBytes(Size))
		file.Read(Data)
		return 8
	case 0x09: // StringTables
		Size := make([]byte, 4)
		file.Read(Size)
		Data := make([]byte, utils.IntFromBytes(Size))
		file.Read(Data)
		return 9
	default:
		return 0
	}
	//fmt.Println(Type[0])
	//fmt.Println(utils.IntFromBytes(Tick))
	//fmt.Println(Slot[0])
}