Class NWN::Key::Bif

  1. lib/nwn/key.rb
Parent: Object

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).

Methods

public class

  1. new

public instance

  1. get_res_id
  2. has_res_id?

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)
[show 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)
[show 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)
[show source]
# File lib/nwn/key.rb, line 41
      def has_res_id? id
        @contained[id] != nil
      end