diff options
Diffstat (limited to 'pkg/types')
| -rw-r--r-- | pkg/types/gameevent.go | 80 | ||||
| -rw-r--r-- | pkg/types/types.go | 71 |
2 files changed, 151 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 | } | ||
diff --git a/pkg/types/types.go b/pkg/types/types.go new file mode 100644 index 0000000..341e875 --- /dev/null +++ b/pkg/types/types.go | |||
| @@ -0,0 +1,71 @@ | |||
| 1 | package types | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "github.com/pektezol/sdp.go/pkg/writer" | ||
| 5 | ) | ||
| 6 | |||
| 7 | type Demo struct { | ||
| 8 | Headers Headers `json:"headers"` | ||
| 9 | Messages []Message `json:"messages"` | ||
| 10 | Writer *writer.Writer `json:"-"` | ||
| 11 | GameEventList *SvcGameEventList `json:"-"` | ||
| 12 | } | ||
| 13 | |||
| 14 | type Headers struct { | ||
| 15 | DemoFileStamp string `json:"demo_file_stamp"` | ||
| 16 | DemoProtocol int32 `json:"demo_protocol"` | ||
| 17 | NetworkProtocol int32 `json:"network_protocol"` | ||
| 18 | ServerName string `json:"server_name"` | ||
| 19 | ClientName string `json:"client_name"` | ||
| 20 | MapName string `json:"map_name"` | ||
| 21 | GameDirectory string `json:"game_directory"` | ||
| 22 | PlaybackTime float32 `json:"playback_time"` | ||
| 23 | PlaybackTicks int32 `json:"playback_ticks"` | ||
| 24 | PlaybackFrames int32 `json:"playback_frames"` | ||
| 25 | SignOnLength int32 `json:"sign_on_length"` | ||
| 26 | } | ||
| 27 | |||
| 28 | type Message struct { | ||
| 29 | PacketType MessageType `json:"packet_type"` | ||
| 30 | TickNumber int32 `json:"tick_number"` | ||
| 31 | SlotNumber uint8 `json:"slot_number"` | ||
| 32 | Data any `json:"data"` | ||
| 33 | } | ||
| 34 | |||
| 35 | type MessageType uint8 | ||
| 36 | |||
| 37 | const ( | ||
| 38 | SignOn MessageType = iota + 1 | ||
| 39 | Packet | ||
| 40 | SyncTick | ||
| 41 | ConsoleCmd | ||
| 42 | UserCmd | ||
| 43 | DataTables | ||
| 44 | Stop | ||
| 45 | CustomData | ||
| 46 | StringTables | ||
| 47 | ) | ||
| 48 | |||
| 49 | func (t MessageType) String() string { | ||
| 50 | switch t { | ||
| 51 | case SignOn: | ||
| 52 | return "SIGNON" | ||
| 53 | case Packet: | ||
| 54 | return "PACKET" | ||
| 55 | case SyncTick: | ||
| 56 | return "SYNCTICK" | ||
| 57 | case ConsoleCmd: | ||
| 58 | return "CONSOLECMD" | ||
| 59 | case UserCmd: | ||
| 60 | return "USERCMD" | ||
| 61 | case DataTables: | ||
| 62 | return "DATATABLES" | ||
| 63 | case Stop: | ||
| 64 | return "STOP" | ||
| 65 | case CustomData: | ||
| 66 | return "CUSTOMDATA" | ||
| 67 | case StringTables: | ||
| 68 | return "STRINGTABLES" | ||
| 69 | } | ||
| 70 | return "INVALID" | ||
| 71 | } | ||