From e203f09fe4acc1279a2831d9f28e1039d97281a2 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Sat, 19 Nov 2022 10:25:31 +0100 Subject: [PATCH] Add projectile snap item --- lib/snapshot/items/projectile.rb | 25 +++++++++ lib/snapshot/unpacker.rb | 88 +++----------------------------- 2 files changed, 32 insertions(+), 81 deletions(-) create mode 100644 lib/snapshot/items/projectile.rb diff --git a/lib/snapshot/items/projectile.rb b/lib/snapshot/items/projectile.rb new file mode 100644 index 0000000..764a9a9 --- /dev/null +++ b/lib/snapshot/items/projectile.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require_relative '../snap_item_base' + +class NetObj + class Projectile < SnapItemBase + attr_accessor :x, :y, :vel_x, :vel_y, :type, :start_tick + + def initialize(hash_or_raw) + @field_names = %i[ + x + y + vel_x + vel_y + type + start_tick + ] + super + end + + def self.match_type?(type) + type == NETOBJTYPE_PROJECTILE + end + end +end diff --git a/lib/snapshot/unpacker.rb b/lib/snapshot/unpacker.rb index 064bff5..6c834b5 100644 --- a/lib/snapshot/unpacker.rb +++ b/lib/snapshot/unpacker.rb @@ -3,6 +3,7 @@ require_relative 'items/game_data' require_relative 'items/character' require_relative 'items/player_info' +require_relative 'items/projectile' require_relative '../packer' class SnapshotUnpacker @@ -63,62 +64,6 @@ class SnapshotUnpacker puts "\n payload:" notes = [] - @sizes = [ - 0, - 10, - 6, - 5, - 3, - 3, - 3, - 2, - 4, - 15, - 22, - 3, - 4, - 58, - 5, - 32, - 2, - 2, - 2, - 2, - 3, - 3, - 5 - ] - - @snap_items = [ - { name: 'placeholder', size: 0 }, - { name: 'obj_player_input', size: 10 }, - { name: 'obj_projectile', size: 6 }, - { name: 'obj_laser', size: 5 }, - { name: 'obj_pickup', size: 3 }, - { name: 'obj_flag', size: 3 }, - { name: 'obj_game_data', size: 3, fields: [ - { type: 'int', name: 'start_tick' }, - { type: 'int', name: 'flags' }, - { type: 'int', name: 'end_tick' } - ] }, - { name: 'obj_game_data_team', size: 2 }, - { name: 'obj_game_data_flag', size: 4 }, - { name: 'obj_character_core', size: 15 }, - { name: 'obj_character', size: 22 }, - { name: 'obj_player_info', size: 3 }, - { name: 'obj_spectator_info', size: 4 }, - { name: 'obj_client_info', size: 58 }, - { name: 'obj_game_info', size: 5 }, - { name: 'obj_tune_params', size: 32 }, - { name: 'event_common', size: 2 }, - { name: 'event_explosion', size: 2 }, - { name: 'event_spawn', size: 2 }, - { name: 'event_hammerhit', size: 2 }, - { name: 'event_death', size: 3 }, - { name: 'event_sound_world', size: 3 }, - { name: 'event_damage', size: 5 } - ] - data = u.get_raw # tw decompresses all bytes at once @@ -142,6 +87,7 @@ class SnapshotUnpacker notes.push([:red, p[:pos], p[:len], "del[#{i}]=#{deleted}"]) end + invalid = false item_type = u.get_int id_parsed = u.parsed.last while item_type @@ -152,6 +98,8 @@ class SnapshotUnpacker 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 @verbose puts "no match #{item_type}" end @@ -164,6 +112,7 @@ class SnapshotUnpacker "type=#{item_type} #{obj.name}" ]) else + invalid = true notes.push([ :bg_red, id_parsed[:pos], @@ -175,35 +124,12 @@ class SnapshotUnpacker id_parsed = u.parsed.last end - # item_delta = u.get_int - # while item_delta - # item_type = item_delta - # item_meta = @snap_items[item_type] - # item_name = item_meta[:name] - - # p = u.parsed.last - # notes.push([:green, p[:pos], p[:len], "type = #{item_type} #{item_name}"]) - - # item_id = u.get_int - # p = u.parsed.last - # notes.push([:cyan, p[:pos], p[:len], "id=#{item_id}"]) - - # size = item_meta[:size] - # (0...size).each do |i| - # val = u.get_int - # p = u.parsed.last - # color = (i % 2).zero? ? :yellow : :pink - # fields = item_meta[:fields] - # desc = '' - # desc = fields[i][:name] unless fields.nil? || fields[i].nil? - # notes.push([color, p[:pos], p[:len], "data[#{i}]=#{val} #{desc}"]) - # end - # item_delta = u.get_int - # end hexdump_lines(data.pack('C*'), 1, notes, legend: :inline).each do |hex| puts " #{hex}" end + # exit 1 if invalid + game_tick end end