class Gen3PokemonStruct
Public Class Methods
new()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 8 def initialize @pdata = Array.new(100,0) @block_g = 32; @block_a = 44; @block_e = 56; @block_m = 68 end
Public Instance Methods
ability()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 140 def ability if @pdata[@block_m+3]&128==128 return true else return false end end
attack()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 352 def attack return compile_bytes(@pdata[90,2]) end
attack=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 356 def attack=(value) @pdata[90,2] = decompile_bytes(value,2) end
ball_caught_with()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 448 def ball_caught_with return ((compile_bytes(@pdata[@block_m+2,2]) & 0x7800)>>11) end
calculate_block_order()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 30 def calculate_block_order #Call this before editing any properties of a Gen3PokemonStruct case (pid % 24) when 0 @block_g = 32; @block_a = 44; @block_e = 56; @block_m = 68 when 1 @block_g = 32; @block_a = 44; @block_e = 68; @block_m = 56 when 2 @block_g = 32; @block_a = 56; @block_e = 44; @block_m = 68 when 3 @block_g = 32; @block_a = 68; @block_e = 44; @block_m = 56 when 4 @block_g = 32; @block_a = 56; @block_e = 68; @block_m = 44 when 5 @block_g = 32; @block_a = 68; @block_e = 56; @block_m = 44 when 6 @block_g = 44; @block_a = 32; @block_e = 56; @block_m = 68 when 7 @block_g = 44; @block_a = 32; @block_e = 68; @block_m = 56 when 8 @block_g = 56; @block_a = 32; @block_e = 44; @block_m = 68 when 9 @block_g = 68; @block_a = 32; @block_e = 44; @block_m = 56 when 10 @block_g = 44; @block_a = 32; @block_e = 68; @block_m = 44 when 11 @block_g = 68; @block_a = 32; @block_e = 56; @block_m = 44 when 12 @block_g = 44; @block_a = 56; @block_e = 32; @block_m = 68 when 13 @block_g = 44; @block_a = 68; @block_e = 32; @block_m = 56 when 14 @block_g = 56; @block_a = 44; @block_e = 32; @block_m = 68 when 15 @block_g = 68; @block_a = 44; @block_e = 32; @block_m = 56 when 16 @block_g = 56; @block_a = 68; @block_e = 32; @block_m = 44 when 17 @block_g = 68; @block_a = 56; @block_e = 32; @block_m = 44 when 18 @block_g = 44; @block_a = 56; @block_e = 68; @block_m = 32 when 19 @block_g = 44; @block_a = 68; @block_e = 56; @block_m = 32 when 20 @block_g = 56; @block_a = 44; @block_e = 68; @block_m = 32 when 21 @block_g = 68; @block_a = 44; @block_e = 56; @block_m = 32 when 22 @block_g = 56; @block_a = 68; @block_e = 44; @block_m = 32 when 23 @block_g = 68; @block_a = 56; @block_e = 44; @block_m = 32 end return self end
change_to_shiny()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 255 def change_to_shiny end
checksum()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 304 def checksum return compile_bytes(@pdata[28,2]) end
checksum=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 308 def checksum=(value) @pdata[28,2] = decompile_bytes(value,2) end
curhp()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 336 def curhp return compile_bytes(@pdata[86,2]) end
curhp=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 340 def curhp=(value) @pdata[86,2] = decompile_bytes(value,2) end
decrypt()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 463 def decrypt temp_pks = self.dup decrypt_key = pid ^ (((secretid&0xFFFF)<<16) | (otid&0xFFFF)) calc_checksum = 0 pdata[32,48].each_index do |i| i+=32 if i%4==0 temp_pks.pdata[i,4] = decompile_bytes(decrypt_key ^ compile_bytes(@pdata[i,4]),4) end end pdata[32,48].each_index do |i| i+=32 if i%2==0 calc_checksum += compile_bytes(temp_pks.pdata[i,2]) end end puts "0x" + checksum.to_s(16) + ": Invalid Checksum!!! (Should be 0x" + (calc_checksum&0xFFFF).to_s(16).upcase + ")" if (calc_checksum&0xFFFF) != checksum return temp_pks end
defense()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 360 def defense return compile_bytes(@pdata[92,2]) end
defense=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 364 def defense=(value) @pdata[92,2] = decompile_bytes(value,2) end
egg()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 116 def egg if @pdata[@block_m+3]&64==64 return true else return false end end
egg=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 124 def egg=(value) if value set_bit(@pdata[@block_m+3],7) else unset_bit(@pdata[@block_m+3],7) end end
encrypt()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 483 def encrypt temp_pks = self.dup decrypt_key = pid ^ (((secretid&0xFFFF)<<16) | (otid&0xFFFF)) calc_checksum = 0 pdata[32,48].each_index do |i| i+=32 if i%2==0 calc_checksum += compile_bytes(temp_pks.pdata[i,2]) end end pdata[32,48].each_index do |i| i+=32 temp_pks.pdata[i] = pdata[i] ^ ((decrypt_key & (0xFF << (i%4)*8)) >> ((i%4)*8)) end temp_pks.checksum = calc_checksum return temp_pks end
ev(options = {hp: true})
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 432 def ev(options = {hp: true}) if options[:hp] return @pdata[@block_e] elsif options[:attack] return @pdata[@block_e+1] elsif options[:defense] return @pdata[@block_e+2] elsif options[:speed] return @pdata[@block_e+3] elsif options[:special_attack] return @pdata[@block_e+4] elsif options[:special_defense] return @pdata[@block_e+5] end end
evs()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 419 def evs return {hp: @pdata[@block_e].to_i, attack: @pdata[@block_e+1].to_i, defense: @pdata[@block_e+2].to_i, speed: @pdata[@block_e+3].to_i, special_attack: @pdata[@block_e+4].to_i, special_defense: @pdata[@block_e+5].to_i} end
evs=(val)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 423 def evs=(val) @pdata[@block_e] = val[:hp] @pdata[@block_e+1] = val[:attack] @pdata[@block_e+2] = val[:defense] @pdata[@block_e+3] = val[:speed] @pdata[@block_e+4] = val[:special_attack] @pdata[@block_e+5] = val[:special_defense] end
exp()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 220 def exp return compile_bytes(@pdata[@block_g+4,4]) end
exp=(val)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 224 def exp=(val) @pdata[@block_g+4,4] = decompile_bytes(val,4) end
generate_block_order()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 17 def generate_block_order #Call this after changing the PID of a Gen3PokemonStruct g = @pdata[@block_g,12] a = @pdata[@block_a,12] m = @pdata[@block_m,12] e = @pdata[@block_e,12] calculate_block_order @pdata[@block_g,12] = g @pdata[@block_a,12] = a @pdata[@block_m,12] = m @pdata[@block_e,12] = e return self end
happiness()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 132 def happiness return @pdata[@block_g+9] end
happiness=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 136 def happiness=(value) @pdata[@block_g+9] = value end
iv(options = {hp: true})
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 392 def iv(options = {hp: true}) iv_total = compile_bytes(@pdata[@block_m+4,4]) if options[:hp] return (iv_total & 0x1F) elsif options[:attack] return ((iv_total & 0x3E0)>>5) elsif options[:defense] return ((iv_total & 0x7C00)>>10) elsif options[:speed] return ((iv_total & 0xF8000)>>15) elsif options[:special_attack] return ((iv_total & 0x1F00000)>>20) elsif options[:special_defense] return ((iv_total & 0x3E000000)>>25) end end
ivs()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 409 def ivs iv_total = compile_bytes(@pdata[@block_m+4,4]) return {hp: iv_total & 0x1F, attack: ((iv_total & 0x3E0)>>5), defense: ((iv_total & 0x7C00)>>10), speed: ((iv_total & 0xF8000)>>15), special_attack: ((iv_total & 0x1F00000)>>20), special_defense: ((iv_total & 0x3E000000)>>25)} end
ivs=(val)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 414 def ivs=(val) iv_total = (val[:hp].to_i&0x1F) | ((val[:attack].to_i&0x1F)<<5) | ((val[:defense].to_i&0x1F)<<10) | ((val[:speed].to_i&0x1F)<<15) | ((val[:special_attack].to_i&0x1F)<<20) | ((val[:special_defense].to_i&0x1F)<<25) @pdata[@block_m+4,4] = decompile_bytes(iv_total,4) end
language()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 259 def language return compile_bytes(@pdata[18,2]) end
language=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 282 def language=(value) @pdata[18,2] = decompile_bytes(value,2) end
language_name()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 263 def language_name case language when 0x201 return "Japanese" when 0x202 return "English" when 0x203 return "French" when 0x204 return "Italian" when 0x205 return "German" when 0x206 return "Korean" when 0x207 return "Spanish" end end
level()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 320 def level return @pdata[84] end
level=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 324 def level=(value) @pdata[84] = value & 0xFF end
marking()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 286 def marking tmpmark = @pdata[27] mark = {} mark[:circle] = true if tmpmark & 1 == 1 mark[:square] = true if tmpmark & 2 == 2 mark[:triangle] = true if tmpmark & 4 == 4 mark[:heart] = true if tmpmark & 8 == 8 return mark end
marking=(mark)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 296 def marking=(mark) @pdata[27] = value & 0xFF mark[:circle] ? set_bit(@pdata[27],0) : unset_bit(@pdata[27],0) mark[:square] ? set_bit(@pdata[27],1) : unset_bit(@pdata[27],1) mark[:triangle] ? set_bit(@pdata[27],2) : unset_bit(@pdata[27],2) mark[:heart] ? set_bit(@pdata[27],3) : unset_bit(@pdata[27],3) end
maxhp()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 344 def maxhp return compile_bytes(@pdata[88,2]) end
maxhp=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 348 def maxhp=(value) @pdata[88,2] = decompile_bytes(value,2) end
moves()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 452 def moves return {1=>compile_bytes(@pdata[@block_a,2]), 2=>compile_bytes(@pdata[@block_a+2,2]), 3=>compile_bytes(@pdata[@block_a+4,2]), 4=>compile_bytes(@pdata[@block_a+6,2]) } end
moves=(val)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 456 def moves=(val) @pdata[@block_a,2] = decompile_bytes(val[1],2) @pdata[@block_a+2,2] = decompile_bytes(val[2],2) @pdata[@block_a+4,2] = decompile_bytes(val[3],2) @pdata[@block_a+6,2] = decompile_bytes(val[4],2) end
nature()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 152 def nature return pid % 25 end
nature_name()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 156 def nature_name case nature when 0 return "Hardy" when 1 return "Lonely" when 2 return "Brave" when 3 return "Adamant" when 4 return "Naughty" when 5 return "Bold" when 6 return "Docile" when 7 return "Relaxed" when 8 return "Impish" when 9 return "Lax" when 10 return "Timid" when 11 return "Hasty" when 12 return "Serious" when 13 return "Jolly" when 14 return "Naive" when 15 return "Modest" when 16 return "Mild" when 17 return "Quiet" when 18 return "Bashful" when 19 return "Rash" when 20 return "Calm" when 21 return "Gentle" when 22 return "Sassy" when 23 return "Careful" when 24 return "Quirky" end end
nickname()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 228 def nickname tmpar = @pdata[8,10] return "" if tmpar.uniq.count == 1 && tmpar.uniq[0] == 0 tmpar.slice!(tmpar.find_index(0xFF)..tmpar.length-1) if tmpar.find_index(0xFF) != nil tmpar.each_index do |i| tmpar[i] = tmpar[i].chr end return TextConverter.convert_text_to_ascii(tmpar.join, {gen: 3}).encode('UTF-8') end
nickname=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 238 def nickname=(value) if value != "" newname = TextConverter.convert_text_to_game(value, {gen: 3}) newray = Array.new(10) newname.each_char.with_index do |char, i| newray[i] = char.ord end newray.each_index do |i| if i>=newname.length newray[i] = 0xFF unless newname.length >= 10 end end puts newray @pdata[8,10] = newray[0,10] end end
otid()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 92 def otid return compile_bytes(@pdata[4,2]) end
otid=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 112 def otid=(value) @pdata[4,2] = decompile_bytes(value, 2) end
pdata()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 13 def pdata return @pdata end
pid()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 84 def pid return compile_bytes(@pdata[0,4]) end
pid=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 88 def pid=(value) @pdata[0,4] = decompile_bytes(value, 4) end
pokedex_species()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 211 def pokedex_species return species if species <= 251 return species - 25 if species > 251 end
pokerus()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 328 def pokerus return @pdata[85] end
pokerus=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 332 def pokerus=(value) @pdata[85] = value & 0xFF end
secretid()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 96 def secretid return compile_bytes(@pdata[6,2]) end
secretid=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 100 def secretid=(value) @pdata[6,2] = decompile_bytes(value,2) end
shiny?()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 104 def shiny? return (((((otid) ^ secretid) ^ (pid & 0xFFFF0000)>>16) ^ pid & 0xFFFF) < 8) end
special_attack()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 376 def special_attack return compile_bytes(@pdata[96,2]) end
special_attack=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 380 def special_attack=(value) @pdata[96,2] = decompile_bytes(value,2) end
special_defense()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 384 def special_defense return compile_bytes(@pdata[98,2]) end
special_defense=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 388 def special_defense=(value) @pdata[98,2] = decompile_bytes(value,2) end
species()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 148 def species return (compile_bytes(@pdata[@block_g,2])) end
species=(val)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 216 def species=(val) @pdata[@block_g,2] = decompile_bytes(val,2) end
speed()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 368 def speed return compile_bytes(@pdata[94,2]) end
speed=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 372 def speed=(value) @pdata[94,2] = decompile_bytes(value,2) end
status()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 312 def status return compile_bytes(@pdata[80,4]) end
status=(value)
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 316 def status=(value) @pdata[80,4] = decompile_bytes(value, 4) end
wurmple_evolution?()
click to toggle source
# File lib/gen3_pokeedit/Gen3PokemonStruct.rb, line 108 def wurmple_evolution? #true for Silcoon and false for Cascoon ((pid & 0xFFFF) ^ 10) < 5 ? true : false end