class WolfRpg::Database
Constants
- DAT_MAGIC_NUMBER
- DAT_SEED_INDICES
- DAT_TYPE_SEPARATOR
Attributes
types[RW]
Public Class Methods
new(project_filename, dat_filename)
click to toggle source
# File lib/wolfrpg/database.rb, line 11 def initialize(project_filename, dat_filename) FileCoder.open(project_filename, :read) do |coder| @types = Array.new(coder.read_int) @types.each_index do |i| @types[i] = Type.new(coder) end end FileCoder.open(dat_filename, :read, DAT_SEED_INDICES) do |coder| if coder.encrypted? @crypt_header = coder.crypt_header @unknown_encrypted_1 = coder.read_byte else coder.verify(DAT_MAGIC_NUMBER) end num_types = coder.read_int unless num_types == @types.size raise "database project and dat Type count mismatch (#{@types.size} vs. #{num_types})" end @types.each do |type| type.read_dat(coder) end if coder.read_byte != 0xC1 STDERR.puts "warning: no C1 terminator at the end of '#{dat_filename}'" end end end
Public Instance Methods
dump(project_filename, dat_filename)
click to toggle source
# File lib/wolfrpg/database.rb, line 38 def dump(project_filename, dat_filename) FileCoder.open(project_filename, :write) do |coder| coder.write_int(@types.size) @types.each do |type| type.dump_project(coder) end end FileCoder.open(dat_filename, :write, DAT_SEED_INDICES, @crypt_header) do |coder| if encrypted? coder.write_byte(@unknown_encrypted_1) else coder.write(DAT_MAGIC_NUMBER) end coder.write_int(@types.size) @types.each do |type| type.dump_dat(coder) end coder.write_byte(0xC1) end end
each_filename() { |fn| ... }
click to toggle source
# File lib/wolfrpg/database.rb, line 59 def each_filename @types.each do |type| type.data.each do |datum| datum.each_filename do |fn| yield fn end end end end
encrypted?()
click to toggle source
# File lib/wolfrpg/database.rb, line 5 def encrypted? @crypt_header != nil end
grep(needle)
click to toggle source
# File lib/wolfrpg/database.rb, line 69 def grep(needle) @types.each_with_index do |type, type_index| type.data.each_with_index do |datum, datum_index| datum.each_translatable do |value, field| next unless value =~ needle puts "DB:[#{type_index}]#{type.name}/[#{datum_index}]#{datum.name}/[#{field.index}]#{field.name}" puts "\t" + value end end end end