class RubyGS::SaveFile

Represents a Gold/Silver/Crystal save file.

@gs is set to true if the save file is from Gold/Silver and false otherwise.

@filename is a string of the filename that the save file was originally read from.

@save is the structure containing the save file’s data and is delegated to SaveFile.

Attributes

filename[R]
gs[R]
save[RW]

Public Class Methods

new(save, filename, gs) click to toggle source
# File lib/ruby_gs/save_file_reader.rb, line 60
def initialize save, filename, gs
  @save, @gs, @filename = save, gs, filename
end

Public Instance Methods

hatch_team_egg(slot) click to toggle source

A convenience method for turning an Egg into a Pokemon.

# File lib/ruby_gs/save_file_reader.rb, line 100
def hatch_team_egg slot
  raise "slot index must be between 0 and 5, inclusive" if !(0..5).include? slot
  @save.team.species_list[slot].assign  @save.team.pokemon[slot].species
  @save.team.pokemon[slot].happiness = 20
end
method_missing(sym, *args, &block) click to toggle source
# File lib/ruby_gs/save_file_reader.rb, line 106
def method_missing(sym, *args, &block)
  @save.send(sym, *args, &block)
end
set_team_egg(slot, egg_cycles) click to toggle source

A convenience method for turning a PartyPokemon into an Egg and setting the steps required to hatch it.

# File lib/ruby_gs/save_file_reader.rb, line 92
def set_team_egg slot, egg_cycles
  raise "slot index must be between 0 and 5, inclusive" if !(0..5).include? slot
  @save.team.species_list[slot] = 0xFD
  @save.team.pokemon[slot].happiness = egg_cycles
end
set_team_species(slot, species) click to toggle source

A convenience method for setting the species of a PartyPokemon in its structure and in the Team species_list.

# File lib/ruby_gs/save_file_reader.rb, line 84
def set_team_species slot, species
  return if !(0..5).include? slot
  @save.team.pokemon[slot].species.assign species
  @save.team.species_list[slot].assign species
end
verify_checksums() click to toggle source
# File lib/ruby_gs/save_file_reader.rb, line 64
def verify_checksums
  case gs
  when true
    return verify_gs_checksums
  when false
    return verify_c_checksums
  end 
end
write(loc = @filename) click to toggle source

Writes the save structure to file.

If loc is not provided, it will write directly to the original file.

# File lib/ruby_gs/save_file_reader.rb, line 77
def write(loc = @filename)
  @save.write(File.open(loc, "wb"))
  verify_checksums
end

Private Instance Methods

verify_c_checksums() click to toggle source
# File lib/ruby_gs/save_file_reader.rb, line 116
def verify_c_checksums
          #TODO
end
verify_gs_checksums() click to toggle source
# File lib/ruby_gs/save_file_reader.rb, line 112
def verify_gs_checksums
  SaveFileReader.correct_checksums! File.open(@filename, "rb+")
end