aboutsummaryrefslogtreecommitdiff
path: root/pkg/types/gameevent.go
blob: 4f00bc03db4b8682d6daf2194723937662f13bb5 (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
package types

import (
	"fmt"

	"github.com/pektezol/bitreader"
)

type SvcGameEventList struct {
	Events              int16                 `json:"events"`
	Length              int32                 `json:"length"`
	GameEventDescriptor []GameEventDescriptor `json:"game_event_descriptor"`
}

type GameEventDescriptor struct {
	EventID uint32                   `json:"event_id"`
	Name    string                   `json:"name"`
	Keys    []GameEventDescriptorKey `json:"keys"`
}

type GameEventDescriptorKey struct {
	Name string          `json:"name"`
	Type EventDescriptor `json:"type"`
}

type EventDescriptor uint8

func (svcGameEventList *SvcGameEventList) ParseGameEventDescriptor(reader *bitreader.Reader, demo *Demo) {
	svcGameEventList.GameEventDescriptor = make([]GameEventDescriptor, svcGameEventList.Events)
	for event := 0; event < int(svcGameEventList.Events); event++ {
		svcGameEventList.GameEventDescriptor[event] = GameEventDescriptor{
			EventID: uint32(reader.TryReadBits(9)),
			Name:    reader.TryReadString(),
		}
		demo.Writer.TempAppendLine("\t\t\t%d: %s", svcGameEventList.GameEventDescriptor[event].EventID, svcGameEventList.GameEventDescriptor[event].Name)
		for {
			descriptorType := reader.TryReadBits(3)
			if descriptorType == 0 {
				break
			}
			KeyName := reader.TryReadString()
			svcGameEventList.GameEventDescriptor[event].Keys = append(svcGameEventList.GameEventDescriptor[event].Keys, GameEventDescriptorKey{
				Name: KeyName,
				Type: EventDescriptor(descriptorType),
			})
		}
		demo.Writer.TempAppendLine("\t\t\t\tKeys: %v", svcGameEventList.GameEventDescriptor[event].Keys)
	}
}

const (
	EventDescriptorString EventDescriptor = iota + 1
	EventDescriptorFloat
	EventDescriptorInt32
	EventDescriptorInt16
	EventDescriptorInt8
	EventDescriptorBool
	EventDescriptorUInt64
)

func (eventDescriptor EventDescriptor) String() string {
	switch eventDescriptor {
	case EventDescriptorString:
		return "String"
	case EventDescriptorFloat:
		return "Float"
	case EventDescriptorInt32:
		return "Int32"
	case EventDescriptorInt16:
		return "Int16"
	case EventDescriptorInt8:
		return "Int8"
	case EventDescriptorBool:
		return "Bool"
	case EventDescriptorUInt64:
		return "UInt64"
	default:
		return fmt.Sprintf("%d", eventDescriptor)
	}
}