class NWN::Key::Bif

A Bif object encapsulates an open file handle pointing to a .bif file. It's contents are indexed on first access, not on creation by NWN::Key::Key (to speed up things).

Attributes

contained[R]

A hash containing the resources contained. Usually not needed, accessed by the encapsulating Key object.

io[R]

The IO object pointing to the .bif file.

key[R]

The Key object this Bif belongs to.

Public Class Methods

new(key, io) click to toggle source
# File lib/nwn/key.rb, line 19
def initialize key, io
  @key = key
  @io = io

  @contained = {}

  @file_type, @file_version,
    @var_res_count, @fix_res_count,
    @var_table_offset =
    io.e_read(4 + 4 + 3 * 4, "header").unpack("a4 a4 V V V")

  @io.seek(@var_table_offset)
  data = @io.e_read(@var_res_count * 16, "var res table")
  i = 0
  while (x = data[i, 16]) && x.size == 16
    i += 16
    id, offset, size, restype = x.unpack("V V V V")
    id &= 0xfffff
    @contained[id] = [offset, size, restype]
  end
end

Public Instance Methods

get_res_id(id) click to toggle source
# File lib/nwn/key.rb, line 45
def get_res_id id
  offset, size, restype = @contained[id]
  @io.seek(offset)
  @io.e_read(size, "resource #{id} of type #{restype}")
end
has_res_id?(id) click to toggle source
# File lib/nwn/key.rb, line 41
def has_res_id? id
  @contained[id] != nil
end