Class: Gen3PokemonStruct
Instance Method Summary
collapse
#compile_bytes, #decompile_bytes, #set_bit, #unset_bit
Constructor Details
Returns a new instance of Gen3PokemonStruct.
8
9
10
11
|
# 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
|
Instance Method Details
#ability ⇒ Object
140
141
142
143
144
145
146
|
# 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 ⇒ Object
352
353
354
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 352
def attack
return compile_bytes(@pdata[90,2])
end
|
#attack=(value) ⇒ Object
356
357
358
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 356
def attack=(value)
@pdata[90,2] = decompile_bytes(value,2)
end
|
#ball_caught_with ⇒ Object
448
449
450
|
# 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 ⇒ Object
Call this before editing any properties of a Gen3PokemonStruct
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 30
def calculate_block_order 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 ⇒ Object
255
256
257
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 255
def change_to_shiny
end
|
#checksum ⇒ Object
304
305
306
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 304
def checksum
return compile_bytes(@pdata[28,2])
end
|
#checksum=(value) ⇒ Object
308
309
310
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 308
def checksum=(value)
@pdata[28,2] = decompile_bytes(value,2)
end
|
#curhp ⇒ Object
336
337
338
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 336
def curhp
return compile_bytes(@pdata[86,2])
end
|
#curhp=(value) ⇒ Object
340
341
342
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 340
def curhp=(value)
@pdata[86,2] = decompile_bytes(value,2)
end
|
#decrypt ⇒ Object
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
|
# 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 ⇒ Object
360
361
362
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 360
def defense
return compile_bytes(@pdata[92,2])
end
|
#defense=(value) ⇒ Object
364
365
366
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 364
def defense=(value)
@pdata[92,2] = decompile_bytes(value,2)
end
|
#egg ⇒ Object
116
117
118
119
120
121
122
|
# 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) ⇒ Object
124
125
126
127
128
129
130
|
# 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 ⇒ Object
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
# 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}) ⇒ Object
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
|
# 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 ⇒ Object
419
420
421
|
# 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) ⇒ Object
423
424
425
426
427
428
429
430
|
# 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 ⇒ Object
220
221
222
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 220
def exp
return compile_bytes(@pdata[@block_g+4,4])
end
|
#exp=(val) ⇒ Object
224
225
226
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 224
def exp=(val)
@pdata[@block_g+4,4] = decompile_bytes(val,4)
end
|
#generate_block_order ⇒ Object
Call this after changing the PID of a Gen3PokemonStruct
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 17
def generate_block_order 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 ⇒ Object
132
133
134
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 132
def happiness
return @pdata[@block_g+9]
end
|
#happiness=(value) ⇒ Object
136
137
138
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 136
def happiness=(value)
@pdata[@block_g+9] = value
end
|
#iv(options = {hp: true}) ⇒ Object
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
# 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 ⇒ Object
409
410
411
412
|
# 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) ⇒ Object
414
415
416
417
|
# 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 ⇒ Object
259
260
261
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 259
def language
return compile_bytes(@pdata[18,2])
end
|
#language=(value) ⇒ Object
282
283
284
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 282
def language=(value)
@pdata[18,2] = decompile_bytes(value,2)
end
|
#language_name ⇒ Object
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# 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 ⇒ Object
320
321
322
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 320
def level
return @pdata[84]
end
|
#level=(value) ⇒ Object
324
325
326
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 324
def level=(value)
@pdata[84] = value & 0xFF
end
|
#marking ⇒ Object
286
287
288
289
290
291
292
293
294
|
# 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) ⇒ Object
296
297
298
299
300
301
302
|
# 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 ⇒ Object
344
345
346
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 344
def maxhp
return compile_bytes(@pdata[88,2])
end
|
#maxhp=(value) ⇒ Object
348
349
350
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 348
def maxhp=(value)
@pdata[88,2] = decompile_bytes(value,2)
end
|
#moves ⇒ Object
452
453
454
|
# 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) ⇒ Object
456
457
458
459
460
461
|
# 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 ⇒ Object
152
153
154
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 152
def nature
return pid % 25
end
|
#nature_name ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# 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 ⇒ Object
228
229
230
231
232
233
234
235
236
|
# 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) ⇒ Object
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
# 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 ⇒ Object
92
93
94
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 92
def otid
return compile_bytes(@pdata[4,2])
end
|
#otid=(value) ⇒ Object
112
113
114
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 112
def otid=(value)
@pdata[4,2] = decompile_bytes(value, 2)
end
|
#pdata ⇒ Object
13
14
15
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 13
def pdata
return @pdata
end
|
#pid ⇒ Object
84
85
86
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 84
def pid
return compile_bytes(@pdata[0,4])
end
|
#pid=(value) ⇒ Object
88
89
90
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 88
def pid=(value)
@pdata[0,4] = decompile_bytes(value, 4)
end
|
#pokedex_species ⇒ Object
211
212
213
214
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 211
def pokedex_species
return species if species <= 251
return species - 25 if species > 251
end
|
#pokerus ⇒ Object
328
329
330
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 328
def pokerus
return @pdata[85]
end
|
#pokerus=(value) ⇒ Object
332
333
334
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 332
def pokerus=(value)
@pdata[85] = value & 0xFF
end
|
#secretid ⇒ Object
96
97
98
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 96
def secretid
return compile_bytes(@pdata[6,2])
end
|
#secretid=(value) ⇒ Object
100
101
102
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 100
def secretid=(value)
@pdata[6,2] = decompile_bytes(value,2)
end
|
#shiny? ⇒ Boolean
104
105
106
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 104
def shiny?
return (((((otid) ^ secretid) ^ (pid & 0xFFFF0000)>>16) ^ pid & 0xFFFF) < 8)
end
|
#special_attack ⇒ Object
376
377
378
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 376
def special_attack
return compile_bytes(@pdata[96,2])
end
|
#special_attack=(value) ⇒ Object
380
381
382
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 380
def special_attack=(value)
@pdata[96,2] = decompile_bytes(value,2)
end
|
#special_defense ⇒ Object
384
385
386
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 384
def special_defense
return compile_bytes(@pdata[98,2])
end
|
#special_defense=(value) ⇒ Object
388
389
390
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 388
def special_defense=(value)
@pdata[98,2] = decompile_bytes(value,2)
end
|
#species ⇒ Object
148
149
150
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 148
def species
return (compile_bytes(@pdata[@block_g,2]))
end
|
#species=(val) ⇒ Object
216
217
218
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 216
def species=(val)
@pdata[@block_g,2] = decompile_bytes(val,2)
end
|
#speed ⇒ Object
368
369
370
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 368
def speed
return compile_bytes(@pdata[94,2])
end
|
#speed=(value) ⇒ Object
372
373
374
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 372
def speed=(value)
@pdata[94,2] = decompile_bytes(value,2)
end
|
#status ⇒ Object
312
313
314
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 312
def status
return compile_bytes(@pdata[80,4])
end
|
#status=(value) ⇒ Object
316
317
318
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 316
def status=(value)
@pdata[80,4] = decompile_bytes(value, 4)
end
|
#wurmple_evolution? ⇒ Boolean
true for Silcoon and false for Cascoon
108
109
110
|
# File 'lib/gen3_pokeedit/Gen3PokemonStruct.rb', line 108
def wurmple_evolution? ((pid & 0xFFFF) ^ 10) < 5 ? true : false
end
|