Class: Overlook::Csgo::Demo::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/overlook/csgo/demo/header.rb

Constant Summary collapse

InvalidHeader =
Class.new(StandardError)
MAX_STRING_LENGTH =
260.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map_name, ticks) ⇒ Header

Returns a new instance of Header.



12
13
14
15
16
# File 'lib/overlook/csgo/demo/header.rb', line 12

def initialize(map_name, ticks)
  raise ArgumentError 'map_name can\'t be nil' if map_name.nil?
  @map_name = map_name
  @ticks = ticks
end

Instance Attribute Details

#map_nameObject (readonly)

Returns the value of attribute map_name.



10
11
12
# File 'lib/overlook/csgo/demo/header.rb', line 10

def map_name
  @map_name
end

#ticksObject (readonly)

Returns the value of attribute ticks.



10
11
12
# File 'lib/overlook/csgo/demo/header.rb', line 10

def ticks
  @ticks
end

Class Method Details

.from_io(reader) ⇒ Object

Raises:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/overlook/csgo/demo/header.rb', line 26

def self.from_io(reader)
  stamp            = reader.read(8)
  demo_protocol    = reader.signed_int32
  network_protocol = reader.signed_int32
  server_name      = reader.string(MAX_STRING_LENGTH)
  client_name      = reader.string(MAX_STRING_LENGTH)
  map_name         = reader.string(MAX_STRING_LENGTH)
  game_directory   = reader.string(MAX_STRING_LENGTH)
  playtime         = reader.float
  ticks            = reader.signed_int32
  frames           = reader.signed_int32
  signon_length    = reader.signed_int32

  raise InvalidHeader, "#{self.class.name} only supports HL2DEMO, got #{stamp}" if stamp !~ /hl2demo/i
  raise InvalidHeader, "#{self.class.name} only supports Valve demo files." if server_name !~ /valve/i

  new(map_name, ticks)
end

Instance Method Details

#to_hashObject



18
19
20
# File 'lib/overlook/csgo/demo/header.rb', line 18

def to_hash
  { map_name: map_name }
end