From ad7ef139269aeecc6378891c35c0a3d0d7037bf2 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sat, 19 Nov 2022 11:24:13 +0100 Subject: [PATCH] More snap item support --- lib/snapshot/events/damage.rb | 24 ++++++++++++++ lib/snapshot/events/death.rb | 20 ++++++++++++ lib/snapshot/events/explosion.rb | 16 ++++++++++ lib/snapshot/events/hammer_hit.rb | 16 ++++++++++ lib/snapshot/events/spawn.rb | 16 ++++++++++ lib/snapshot/items/client_info.rb | 22 +++++++++++++ lib/snapshot/items/flag.rb | 22 +++++++++++++ lib/snapshot/items/game_data_flag.rb | 24 ++++++++++++++ lib/snapshot/items/game_data_team.rb | 21 +++++++++++++ lib/snapshot/items/laser.rb | 24 ++++++++++++++ lib/snapshot/items/pickup.rb | 22 +++++++++++++ lib/snapshot/items/player_input.rb | 32 +++++++++++++++++++ lib/snapshot/items/spectator_info.rb | 23 ++++++++++++++ lib/snapshot/unpacker.rb | 47 +++++++++++++++++++++++++--- 14 files changed, 325 insertions(+), 4 deletions(-) create mode 100644 lib/snapshot/events/damage.rb create mode 100644 lib/snapshot/events/death.rb create mode 100644 lib/snapshot/events/explosion.rb create mode 100644 lib/snapshot/events/hammer_hit.rb create mode 100644 lib/snapshot/events/spawn.rb create mode 100644 lib/snapshot/items/client_info.rb create mode 100644 lib/snapshot/items/flag.rb create mode 100644 lib/snapshot/items/game_data_flag.rb create mode 100644 lib/snapshot/items/game_data_team.rb create mode 100644 lib/snapshot/items/laser.rb create mode 100644 lib/snapshot/items/pickup.rb create mode 100644 lib/snapshot/items/player_input.rb create mode 100644 lib/snapshot/items/spectator_info.rb diff --git a/lib/snapshot/events/damage.rb b/lib/snapshot/events/damage.rb new file mode 100644 index 0000000..0508901 --- /dev/null +++ b/lib/snapshot/events/damage.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative '../snap_event_base' + +class NetEvent + class Damage < SnapEventBase + attr_accessor :client_id, :angle, :health_ammount, :armor_amount, :self + + def initialize(hash_or_raw) + @field_names = %i[ + client_id + angle + health_ammount + armor_amount + self + ] + super + end + + def self.match_type?(type) + type == NETEVENTTYPE_DAMAGE + end + end +end diff --git a/lib/snapshot/events/death.rb b/lib/snapshot/events/death.rb new file mode 100644 index 0000000..e513573 --- /dev/null +++ b/lib/snapshot/events/death.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require_relative '../snap_event_base' + +class NetEvent + class Death < SnapEventBase + attr_accessor :client_id + + def initialize(hash_or_raw) + @field_names = %i[ + client_id + ] + super + end + + def self.match_type?(type) + type == NETEVENTTYPE_DEATH + end + end +end diff --git a/lib/snapshot/events/explosion.rb b/lib/snapshot/events/explosion.rb new file mode 100644 index 0000000..a3a4874 --- /dev/null +++ b/lib/snapshot/events/explosion.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetEvent + class Explosion < SnapEventBase + def initialize(hash_or_raw) + @field_names = [] + super + end + + def self.match_type?(type) + type == NETEVENTTYPE_EXPLOSION + end + end +end diff --git a/lib/snapshot/events/hammer_hit.rb b/lib/snapshot/events/hammer_hit.rb new file mode 100644 index 0000000..689dc56 --- /dev/null +++ b/lib/snapshot/events/hammer_hit.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetEvent + class HammerHit < SnapEventBase + def initialize(hash_or_raw) + @field_names = [] + super + end + + def self.match_type?(type) + type == NETEVENTTYPE_HAMMERHIT + end + end +end diff --git a/lib/snapshot/events/spawn.rb b/lib/snapshot/events/spawn.rb new file mode 100644 index 0000000..01e8811 --- /dev/null +++ b/lib/snapshot/events/spawn.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetEvent + class Spawn < SnapEventBase + def initialize(hash_or_raw) + @field_names = [] + super + end + + def self.match_type?(type) + type == NETEVENTTYPE_SPAWN + end + end +end diff --git a/lib/snapshot/items/client_info.rb b/lib/snapshot/items/client_info.rb new file mode 100644 index 0000000..6063291 --- /dev/null +++ b/lib/snapshot/items/client_info.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetObj + class ClientInfo < SnapItemBase + attr_accessor :local, :team + + def initialize(hash_or_raw) + @field_names = %i[ + local + team + ] + super + raise 'ClientInfo includes strings that is not supported yet' + end + + def self.match_type?(type) + type == NETOBJTYPE_DE_CLIENTINFO + end + end +end diff --git a/lib/snapshot/items/flag.rb b/lib/snapshot/items/flag.rb new file mode 100644 index 0000000..5c85735 --- /dev/null +++ b/lib/snapshot/items/flag.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetObj + class Flag < SnapItemBase + attr_accessor :x, :y, :team + + def initialize(hash_or_raw) + @field_names = %i[ + x + y + team + ] + super + end + + def self.match_type?(type) + type == NETOBJTYPE_FLAG + end + end +end diff --git a/lib/snapshot/items/game_data_flag.rb b/lib/snapshot/items/game_data_flag.rb new file mode 100644 index 0000000..b214703 --- /dev/null +++ b/lib/snapshot/items/game_data_flag.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetObj + class GameDataFlag < SnapItemBase + attr_accessor :flag_carrier_red, :flag_carrier_blue, + :flag_drop_tick_red, :flag_drop_tick_blue + + def initialize(hash_or_raw) + @field_names = %i[ + flag_carrier_red + flag_carrier_blue + flag_drop_tick_red + flag_drop_tick_blue + ] + super + end + + def self.match_type?(type) + type == NETOBJTYPE_GAMEDATAFLAG + end + end +end diff --git a/lib/snapshot/items/game_data_team.rb b/lib/snapshot/items/game_data_team.rb new file mode 100644 index 0000000..3d338c7 --- /dev/null +++ b/lib/snapshot/items/game_data_team.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetObj + class GameDataTeam < SnapItemBase + attr_accessor :teamscore_red, :teamscore_blue + + def initialize(hash_or_raw) + @field_names = %i[ + teamscore_red + teamscore_blue + ] + super + end + + def self.match_type?(type) + type == NETOBJTYPE_GAMEDATATEAM + end + end +end diff --git a/lib/snapshot/items/laser.rb b/lib/snapshot/items/laser.rb new file mode 100644 index 0000000..0a338c1 --- /dev/null +++ b/lib/snapshot/items/laser.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetObj + class Laser < SnapItemBase + attr_accessor :x, :y, :from_x, :from_y, :start_tick + + def initialize(hash_or_raw) + @field_names = %i[ + x + y + from_x + from_y + start_tick + ] + super + end + + def self.match_type?(type) + type == NETOBJTYPE_LASER + end + end +end diff --git a/lib/snapshot/items/pickup.rb b/lib/snapshot/items/pickup.rb new file mode 100644 index 0000000..10d2908 --- /dev/null +++ b/lib/snapshot/items/pickup.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetObj + class Pickup < SnapItemBase + attr_accessor :x, :y, :type + + def initialize(hash_or_raw) + @field_names = %i[ + x + y + type + ] + super + end + + def self.match_type?(type) + type == NETOBJTYPE_PICKUP + end + end +end diff --git a/lib/snapshot/items/player_input.rb b/lib/snapshot/items/player_input.rb new file mode 100644 index 0000000..4b90a47 --- /dev/null +++ b/lib/snapshot/items/player_input.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetObj + class PlayerInput < SnapItemBase + attr_accessor :direction, :target_x, :target_y, + :jump, :fire, :hook, + :player_flags, :wanted_weapon, + :next_weapon, :prev_weapon + + def initialize(hash_or_raw) + @field_names = %i[ + direction + target_x + target_y + jump + fire + hook + player_flags + wanted_weapon + next_weapon + prev_weapon + ] + super + end + + def self.match_type?(type) + type == NETOBJTYPE_PLAYERINPUT + end + end +end diff --git a/lib/snapshot/items/spectator_info.rb b/lib/snapshot/items/spectator_info.rb new file mode 100644 index 0000000..66b64ed --- /dev/null +++ b/lib/snapshot/items/spectator_info.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetObj + class SpectatorInfo < SnapItemBase + attr_accessor :spec_mode, :spectator_id, :x, :y + + def initialize(hash_or_raw) + @field_names = %i[ + spec_mode + spectator_id + x + y + ] + super + end + + def self.match_type?(type) + type == NETOBJTYPE_SPECTATORINFO + end + end +end diff --git a/lib/snapshot/unpacker.rb b/lib/snapshot/unpacker.rb index 39710bd..20e4d66 100644 --- a/lib/snapshot/unpacker.rb +++ b/lib/snapshot/unpacker.rb @@ -2,9 +2,22 @@ require_relative 'items/game_data' require_relative 'items/character' -require_relative 'items/player_info' require_relative 'items/projectile' +require_relative 'items/pickup' +require_relative 'items/flag' +require_relative 'items/game_data_team' +require_relative 'items/game_data_flag' +require_relative 'items/player_input' +require_relative 'items/laser' +require_relative 'items/player_info' +require_relative 'items/spectator_info' +require_relative 'items/client_info' require_relative 'events/sound_world' +require_relative 'events/explosion' +require_relative 'events/spawn' +require_relative 'events/damage' +require_relative 'events/death' +require_relative 'events/hammer_hit' require_relative '../packer' class SnapshotUnpacker @@ -93,16 +106,42 @@ class SnapshotUnpacker id_parsed = u.parsed.last while item_type obj = nil - if NetObj::GameData.match_type?(item_type) + if NetObj::PlayerInput.match_type?(item_type) + obj = NetObj::PlayerInput.new(u) + elsif NetObj::Projectile.match_type?(item_type) + obj = NetObj::Projectile.new(u) + elsif NetObj::Laser.match_type?(item_type) + obj = NetObj::Laser.new(u) + elsif NetObj::Pickup.match_type?(item_type) + obj = NetObj::Pickup.new(u) + elsif NetObj::Flag.match_type?(item_type) + obj = NetObj::Flag.new(u) + elsif NetObj::GameData.match_type?(item_type) obj = NetObj::GameData.new(u) + elsif NetObj::GameDataTeam.match_type?(item_type) + obj = NetObj::GameDataTeam.new(u) + elsif NetObj::GameDataFlag.match_type?(item_type) + obj = NetObj::GameDataFlag.new(u) elsif NetObj::Character.match_type?(item_type) obj = NetObj::Character.new(u) elsif NetObj::PlayerInfo.match_type?(item_type) obj = NetObj::PlayerInfo.new(u) - elsif NetObj::Projectile.match_type?(item_type) - obj = NetObj::Projectile.new(u) + elsif NetObj::SpectatorInfo.match_type?(item_type) + obj = NetObj::SpectatorInfo.new(u) + elsif NetObj::ClientInfo.match_type?(item_type) + obj = NetObj::ClientInfo.new(u) + elsif NetEvent::Explosion.match_type?(item_type) + obj = NetEvent::Explosion.new(u) elsif NetEvent::SoundWorld.match_type?(item_type) obj = NetEvent::SoundWorld.new(u) + elsif NetEvent::Spawn.match_type?(item_type) + obj = NetEvent::Spawn.new(u) + elsif NetEvent::Damage.match_type?(item_type) + obj = NetEvent::Damage.new(u) + elsif NetEvent::Death.match_type?(item_type) + obj = NetEvent::Death.new(u) + elsif NetEvent::HammerHit.match_type?(item_type) + obj = NetEvent::HammerHit.new(u) elsif @verbose puts "no match #{item_type}" end