diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-06-15 13:58:30 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-15 13:58:30 +0300 |
| commit | 77e4b066cb8d506b4bc944ab4eb2d6e4679e2202 (patch) | |
| tree | 1d549eca619ed36cb881e487cb054c4643ac8376 /pkg/types/gameevent.go | |
| parent | change project name to sdp.go (diff) | |
| download | sdp.go-77e4b066cb8d506b4bc944ab4eb2d6e4679e2202.tar.gz sdp.go-77e4b066cb8d506b4bc944ab4eb2d6e4679e2202.tar.bz2 sdp.go-77e4b066cb8d506b4bc944ab4eb2d6e4679e2202.zip | |
enable multithreading with goroutines (#20)
Diffstat (limited to 'pkg/types/gameevent.go')
| -rw-r--r-- | pkg/types/gameevent.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/pkg/types/gameevent.go b/pkg/types/gameevent.go new file mode 100644 index 0000000..4f00bc0 --- /dev/null +++ b/pkg/types/gameevent.go | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | package types | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | |||
| 6 | "github.com/pektezol/bitreader" | ||
| 7 | ) | ||
| 8 | |||
| 9 | type SvcGameEventList struct { | ||
| 10 | Events int16 `json:"events"` | ||
| 11 | Length int32 `json:"length"` | ||
| 12 | GameEventDescriptor []GameEventDescriptor `json:"game_event_descriptor"` | ||
| 13 | } | ||
| 14 | |||
| 15 | type GameEventDescriptor struct { | ||
| 16 | EventID uint32 `json:"event_id"` | ||
| 17 | Name string `json:"name"` | ||
| 18 | Keys []GameEventDescriptorKey `json:"keys"` | ||
| 19 | } | ||
| 20 | |||
| 21 | type GameEventDescriptorKey struct { | ||
| 22 | Name string `json:"name"` | ||
| 23 | Type EventDescriptor `json:"type"` | ||
| 24 | } | ||
| 25 | |||
| 26 | type EventDescriptor uint8 | ||
| 27 | |||
| 28 | func (svcGameEventList *SvcGameEventList) ParseGameEventDescriptor(reader *bitreader.Reader, demo *Demo) { | ||
| 29 | svcGameEventList.GameEventDescriptor = make([]GameEventDescriptor, svcGameEventList.Events) | ||
| 30 | for event := 0; event < int(svcGameEventList.Events); event++ { | ||
| 31 | svcGameEventList.GameEventDescriptor[event] = GameEventDescriptor{ | ||
| 32 | EventID: uint32(reader.TryReadBits(9)), | ||
| 33 | Name: reader.TryReadString(), | ||
| 34 | } | ||
| 35 | demo.Writer.TempAppendLine("\t\t\t%d: %s", svcGameEventList.GameEventDescriptor[event].EventID, svcGameEventList.GameEventDescriptor[event].Name) | ||
| 36 | for { | ||
| 37 | descriptorType := reader.TryReadBits(3) | ||
| 38 | if descriptorType == 0 { | ||
| 39 | break | ||
| 40 | } | ||
| 41 | KeyName := reader.TryReadString() | ||
| 42 | svcGameEventList.GameEventDescriptor[event].Keys = append(svcGameEventList.GameEventDescriptor[event].Keys, GameEventDescriptorKey{ | ||
| 43 | Name: KeyName, | ||
| 44 | Type: EventDescriptor(descriptorType), | ||
| 45 | }) | ||
| 46 | } | ||
| 47 | demo.Writer.TempAppendLine("\t\t\t\tKeys: %v", svcGameEventList.GameEventDescriptor[event].Keys) | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | const ( | ||
| 52 | EventDescriptorString EventDescriptor = iota + 1 | ||
| 53 | EventDescriptorFloat | ||
| 54 | EventDescriptorInt32 | ||
| 55 | EventDescriptorInt16 | ||
| 56 | EventDescriptorInt8 | ||
| 57 | EventDescriptorBool | ||
| 58 | EventDescriptorUInt64 | ||
| 59 | ) | ||
| 60 | |||
| 61 | func (eventDescriptor EventDescriptor) String() string { | ||
| 62 | switch eventDescriptor { | ||
| 63 | case EventDescriptorString: | ||
| 64 | return "String" | ||
| 65 | case EventDescriptorFloat: | ||
| 66 | return "Float" | ||
| 67 | case EventDescriptorInt32: | ||
| 68 | return "Int32" | ||
| 69 | case EventDescriptorInt16: | ||
| 70 | return "Int16" | ||
| 71 | case EventDescriptorInt8: | ||
| 72 | return "Int8" | ||
| 73 | case EventDescriptorBool: | ||
| 74 | return "Bool" | ||
| 75 | case EventDescriptorUInt64: | ||
| 76 | return "UInt64" | ||
| 77 | default: | ||
| 78 | return fmt.Sprintf("%d", eventDescriptor) | ||
| 79 | } | ||
| 80 | } | ||