forked from rh-hideout/pokeemerald-expansion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublic_lua_script.lua
More file actions
4365 lines (4180 loc) · 104 KB
/
public_lua_script.lua
File metadata and controls
4365 lines (4180 loc) · 104 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- you do not need this lua script, though it will allow you to with mgba 0.10 to export your pokemon to the calc
-- to use download this file on mgba select tools->scripting then file->open and open this file
-- The below configs should be set to false if you want lua_update_script.py to not parse them to the
-- public_lua_script.lua
local configOverlayPokemon = true
local configCompanion = false
local configPokemonEditing = true
local configPreDamage = true
local configPreStatus = true
local configRandomize = true
local overlayConfig = {}
overlayConfig.enabled = false
overlayConfig.processParty = true
overlayConfig.processBoxes = false
overlayConfig.frameCounter = 0
overlayConfig.checkInterval = 300
overlayConfig.debug = true
local companionConfig = {}
companionConfig.enabled = false
companionConfig.processParty = true
companionConfig.processBoxes = true
companionConfig.frameCounter = 0
companionConfig.checkInterval = 300
companionConfig.debug = true
-- GF HEADER
local gfHeaderAdr = 0x08000100 -- 0x104 src/rom_header_gf.o
local GFRomHeader = {
version = 0x00, -- u32 version
language = 0x04, -- u32 language
gameName = 0x08, -- 32 bytes -- u8 gameName[32]
monFrontPics = 0x28, -- const struct CompressedSpriteSheet *monFrontPics
monBackPics = 0x2C, -- const struct CompressedSpriteSheet *monBackPics
monNormalPalettes = 0x30, -- const struct SpritePalette *monNormalPalettes
monShinyPalettes = 0x34, -- const struct SpritePalette *monShinyPalettes
monIcons = 0x38, -- const u8 *const *monIcons
monIconPaletteIds = 0x3C, -- const u8 *monIconPaletteIds
monIconPalettes = 0x40, -- const struct SpritePalette *monIconPalettes
monSpeciesNames = 0x44, -- const u8 (*monSpeciesNames)[]
moveNames = 0x48, -- const u8 (*moveNames)[]
decorations = 0x4C, -- const struct Decoration *decorations
flagsOffset = 0x50, -- u32 flagsOffset
varsOffset = 0x54, -- u32 varsOffset
pokedexOffset = 0x58, -- u32 pokedexOffset
seen1Offset = 0x5C, -- u32 seen1Offset
seen2Offset = 0x60, -- u32 seen2Offset
pokedexVar = 0x64, -- u32 pokedexVar
pokedexFlag = 0x68, -- u32 pokedexFlag
mysteryEventFlag = 0x6C, -- u32 mysteryEventFlag
pokedexCount = 0x70, -- u32 pokedexCount
playerNameLength = 0x74, -- u8 playerNameLength
trainerNameLength = 0x75, -- u8 trainerNameLength
pokemonNameLength1 = 0x76, -- u8 pokemonNameLength1
pokemonNameLength2 = 0x77, -- u8 pokemonNameLength2
unk5 = 0x78, -- u8 unk5
unk6 = 0x79, -- u8 unk6
unk7 = 0x7A, -- u8 unk7
unk8 = 0x7B, -- u8 unk8
unk9 = 0x7C, -- u8 unk9
unk10 = 0x7D, -- u8 unk10
unk11 = 0x7E, -- u8 unk11
unk12 = 0x7F, -- u8 unk12
unk13 = 0x80, -- u8 unk13
unk14 = 0x81, -- u8 unk14
unk15 = 0x82, -- u8 unk15
unk16 = 0x83, -- u8 unk16
unk17 = 0x84, -- u8 unk17
gfPadding = 0x85, -- (padding: 3 bytes for alignment)
saveBlock2Size = 0x88, -- u32 saveBlock2Size
saveBlock1Size = 0x8C, -- u32 saveBlock1Size
partyCountOffset = 0x90, -- u32 partyCountOffset
partyOffset = 0x94, -- u32 partyOffset
warpFlagsOffset = 0x98, -- u32 warpFlagsOffset
trainerIdOffset = 0x9C, -- u32 trainerIdOffset
playerNameOffset = 0xA0, -- u32 playerNameOffset
playerGenderOffset = 0xA4, -- u32 playerGenderOffset
frontierStatusOffset = 0xA8,
frontierStatusOffset2 = 0xAC,
externalEventFlagsOffset = 0xB0,
externalEventDataOffset = 0xB4,
unk18 = 0xB8,
speciesInfo = 0xBC,
abilityNames = 0xC0,
abilityDescriptions = 0xC4,
items = 0xC8,
moves = 0xCC,
ballGfx = 0xD0,
ballPalettes = 0xD4,
gcnLinkFlagsOffset = 0xD8,
gameClearFlag = 0xDC,
ribbonFlag = 0xE0,
bagCountItems = 0xE4, -- u8 bagCountItems
bagCountKeyItems = 0xE5, -- u8 bagCountKeyItems
bagCountPokeballs = 0xE6, -- u8 bagCountPokeballs
bagCountTMHMs = 0xE7, -- u8 bagCountTMHMs
bagCountBerries = 0xE8, -- u8 bagCountBerries
pcItemsCount = 0xE9,
pcItemsOffset = 0xEC,
giftRibbonsOffset = 0xF0,
enigmaBerryOffset = 0xF4, -- only if FREE_ENIGMA_BERRY == FALSE
enigmaBerrySize = 0xF8, -- same condition
moveDescriptions = 0xFC,
unk20 = 0x100,
}
-- RHH HEADER
local rhhHeaderAdr = 0x08000204 -- 0x18 src/rom_header_rhh.o
local RHHRomHeader = {
rhhMagic = 0x00,
expansionVersionMajor = 0x06,
expansionVersionMinor = 0x07,
expansionVersionPatch = 0x08,
expansionVersionFlags = 0x09,
movesCount = 0x0A, -- u16
numSpecies = 0x0C, -- u16
abilitiesCount = 0x0E, -- u16
abilitiesPtr = 0x10,
itemsCount = 0x14,
itemNameLength = 0x16,
metLocationCount = 0x17,
pokemonStorage = 0x18,
playerParty = 0x1C,
playerPartyCount = 0x20, -- u8
boxPokemonSize = 0x24, -- u32
partyPokemonSize = 0x28, -- u32
speciesSize = 0x2C, -- u32
movesSize = 0x30, -- u32
speciesNameOffset = 0x34, -- u32
moveNameLength = 0x38, -- u8
}
-- From header
-- local saveBlock1Adr = emu:read32(rhhHeaderAdr + RHHRomHeader.saveBlock1)
-- local saveBlock2Adr = emu:read32(rhhHeaderAdr + RHHRomHeader.saveBlock2)
-- local saveBlock3Adr = emu:read32(rhhHeaderAdr + RHHRomHeader.saveBlock3)
local pokemonNameLength = emu:read8(gfHeaderAdr + GFRomHeader.pokemonNameLength1) -- POKEMON_NAME_LENGTH
local playerNameLength2 = emu:read8(gfHeaderAdr + GFRomHeader.playerNameLength) -- PLAYER_NAME_LENGTH
local boxPokemonSize = emu:read32(rhhHeaderAdr + RHHRomHeader.boxPokemonSize) -- sizeof(struct BoxPokemon)
local partyPokemonSize = emu:read32(rhhHeaderAdr + RHHRomHeader.partyPokemonSize) -- sizeof(struct Pokemon)
local speciesSize = emu:read32(rhhHeaderAdr + RHHRomHeader.speciesSize) -- sizeof(struct SpeciesInfo)
local movesSize = emu:read32(rhhHeaderAdr + RHHRomHeader.movesSize) -- sizeof(struct MoveInfo)
local moveNameLength = emu:read8(rhhHeaderAdr + RHHRomHeader.moveNameLength) -- MOVE_NAME_LENGTH
local playerPartyCountAdr = emu:read32(rhhHeaderAdr + RHHRomHeader.playerPartyCount) -- PlayerPartyCount
local partyLocationAdr = emu:read32(rhhHeaderAdr + RHHRomHeader.playerParty) -- PlayerParty
local pokemonStorageAdr = emu:read32(rhhHeaderAdr + RHHRomHeader.pokemonStorage) -- SpeciesInfo
local speciesInfoAdr = emu:read32(gfHeaderAdr + GFRomHeader.speciesInfo) -- PokemonStorage
-- START ORIGINAL LUA NAMING
local terminator=0xFF
local monNameLength=10
local playerNameLength=10
local boxMonSize=80
local partyMonSize=100
local speciesStructSize=260
levelCap = 0 -- Sets the level for all mons based on first party slot
-- Used for mon exporting
local partyCount=0x02033611 -- gPlayerPartyCount
local partyloc=0x02033ac8 -- gPlayerParty
local storageLoc=0x02009580 -- gPokemonStorage
local speciesInfo=0x08682eec -- gSpeciesInfo
-- END ORIGINAL LUA NAMING
-- Used for table generation
local movesCount = emu:read16(rhhHeaderAdr + RHHRomHeader.movesCount)
local numSpecies = emu:read16(rhhHeaderAdr + RHHRomHeader.numSpecies)
local abilitiesCount = emu:read16(rhhHeaderAdr + RHHRomHeader.abilitiesCount)
local metLocationCount = emu:read8(rhhHeaderAdr + RHHRomHeader.metLocationCount)
local movesInfoAdr = emu:read32(gfHeaderAdr + GFRomHeader.moves)
function readPointer(addr)
local ptr = emu:read32(addr)
if ptr >= 0x08000000 and ptr <= 0x09FFFFFF then
return ptr
end
if ptr >= 0x02000000 and ptr <= 0x03007FFF then
return ptr
end
console:log(string.format("Warning: Invalid pointer read at 0x%08X → 0x%08X", addr, ptr))
return nil
end
function getMoveName(n)
local moveStructAddr = movesInfoAdr + (movesSize * n)
local namePtr = readPointer(moveStructAddr)
if not namePtr then
console:log(string.format("Invalid name pointer for move %d", n))
return nil
end
local nameBytes = emu:readRange(namePtr, moveNameLength)
local name = toString(nameBytes)
console:log(string.format("Move name: %s", name))
return name
end
function getMonsName(n)
local speciesStructAddr = speciesInfoAdr + (speciesSize * n)
local namePtr = readPointer(speciesStructAddr + RHHRomHeader.speciesNameOffset)
if not namePtr then
console:log(string.format("Invalid name pointer for species %d", n))
return nil
end
local nameBytes = emu:readRange(namePtr, pokemonNameLength)
local name = toString(nameBytes)
console:log(string.format("Species name: %s", name))
return name
end
move = {}
function getMoveTable()
move[0] = ""
i = 1
while i < movesCount do
move[i+1] = string.format("%s",getMoveName(i))
i = i + 1
end
end
mons = {}
function getMonsTable()
i = 0
while i < numSpecies do
mons[i] = string.format("%s",getMonsName(i))
i = i + 1
end
end
--Start configOverlayPokemon
-- Companion: remove Route 100
metLocation = {
"Littleroot Town",
"Oldale Town",
"Dewford Town",
"Lavaridge Town",
"Fallarbor Town",
"Verdanturf Town",
"Pacifidlog Town",
"Petalburg City",
"Slateport City",
"Mauville City",
"Rustboro City",
"Fortree City",
"Lilycove City",
"Mossdeep City",
"Sootopolis City",
"Ever Grande City",
"Route 100",
"Route 101",
"Route 102",
"Route 103",
"Route 104",
"Route 105",
"Route 106",
"Route 107",
"Route 108",
"Route 109",
"Route 110",
"Route 111",
"Route 112",
"Route 113",
"Route 114",
"Route 115",
"Route 116",
"Route 117",
"Route 118",
"Route 119",
"Route 120",
"Route 121",
"Route 122",
"Route 123",
"Route 124",
"Route 125",
"Route 126",
"Route 127",
"Route 128",
"Route 129",
"Route 130",
"Route 131",
"Route 132",
"Route 133",
"Route 134",
"Underwater 124",
"Underwater 126",
"Underwater 127",
"Underwater 128",
"Underwater Sootopolis",
"Granite Cave",
"Mt Chimney",
"Safari Zone",
"Battle Frontier",
"Petalburg Woods",
"Rusturf Tunnel",
"Abandoned Ship",
"New Mauville",
"Meteor Falls",
"Meteor Falls2",
"Mt Pyre",
"Aqua Hideout Old",
"Shoal Cave",
"Seafloor Cavern",
"Underwater Seafloor Cavern",
"Victory Road",
"Mirage Island",
"Cave Of Origin",
"Southern Island",
"Fiery Path",
"Fiery Path2",
"Jagged Pass",
"Jagged Pass2",
"Sealed Chamber",
"Underwater Sealed Chamber",
"Scorched Slab",
"Island Cave",
"Desert Ruins",
"Ancient Tomb",
"Inside Of Truck",
"Sky Pillar",
"Secret Base",
"Dynamic",
"Pallet Town",
"Viridian City",
"Pewter City",
"Cerulean City",
"Lavender Town",
"Vermilion City",
"Celadon City",
"Fuchsia City",
"Cinnabar Island",
"Indigo Plateau",
"Saffron City",
"Route 4 Pokecenter",
"Route 10 Pokecenter",
"Route 1",
"Route 2",
"Route 3",
"Route 4",
"Route 5",
"Route 6",
"Route 7",
"Route 8",
"Route 9",
"Route 10",
"Route 11",
"Route 12",
"Route 13",
"Route 14",
"Route 15",
"Route 16",
"Route 17",
"Route 18",
"Route 19",
"Route 20",
"Route 21",
"Route 22",
"Route 23",
"Route 24",
"Route 25",
"Viridian Forest",
"Mt Moon",
"S S Anne",
"Underground Path",
"Underground Path 2",
"Digletts Cave",
"Kanto Victory Road",
"Rocket Hideout",
"Silph Co",
"Pokemon Mansion",
"Kanto Safari Zone",
"Pokemon League",
"Rock Tunnel",
"Seafoam Islands",
"Pokemon Tower",
"Cerulean Cave",
"Power Plant",
"One Island",
"Two Island",
"Three Island",
"Four Island",
"Five Island",
"Seven Island",
"Six Island",
"Kindle Road",
"Treasure Beach",
"Cape Brink",
"Bond Bridge",
"Three Isle Port",
"Sevii Isle 6",
"Sevii Isle 7",
"Sevii Isle 8",
"Sevii Isle 9",
"Resort Gorgeous",
"Water Labyrinth",
"Five Isle Meadow",
"Memorial Pillar",
"Outcast Island",
"Green Path",
"Water Path",
"Ruin Valley",
"Trainer Tower",
"Canyon Entrance",
"Sevault Canyon",
"Tanoby Ruins",
"Sevii Isle 22",
"Sevii Isle 23",
"Sevii Isle 24",
"Navel Rock Frlg",
"Mt Ember",
"Berry Forest",
"Icefall Cave",
"Rocket Warehouse",
"Trainer Tower 2",
"Dotted Hole",
"Lost Cave",
"Pattern Bush",
"Altering Cave Frlg",
"Tanoby Chambers",
"Three Isle Path",
"Tanoby Key",
"Birth Island Frlg",
"Monean Chamber",
"Liptoo Chamber",
"Weepth Chamber",
"Dilford Chamber",
"Scufib Chamber",
"Rixy Chamber",
"Viapois Chamber",
"Ember Spa",
"Special Area",
"Aqua Hideout",
"Magma Hideout",
"Mirage Tower",
"Birth Island",
"Faraway Island",
"Artisan Cave",
"Marine Cave",
"Underwater Marine Cave",
"Terra Cave",
"Underwater 105",
"Underwater 125",
"Underwater 129",
"Desert Underpass",
"Altering Cave",
"Navel Rock",
"Trainer Hill"
}
dexNumber = {
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
22,
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,
83,
84,
85,
86,
87,
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99,
100,
101,
102,
103,
104,
105,
106,
107,
108,
109,
110,
111,
112,
113,
114,
115,
116,
117,
118,
119,
120,
121,
122,
123,
124,
125,
126,
127,
128,
129,
130,
131,
132,
133,
134,
135,
136,
137,
138,
139,
140,
141,
142,
143,
144,
145,
146,
147,
148,
149,
150,
151,
152,
153,
154,
155,
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,
210,
211,
212,
213,
214,
215,
216,
217,
218,
219,
220,
221,
222,
223,
224,
225,
226,
227,
228,
229,
230,
231,
232,
233,
234,
235,
236,
237,
238,
239,
240,
241,
242,
243,
244,
245,
246,
247,
248,
249,
250,
251,
252,
253,
254,
255,
256,
257,
258,
259,
260,
261,
262,
263,
264,
265,
266,
267,
268,
269,
270,
271,
272,
273,
274,
275,
276,
277,
278,
279,
280,
281,
282,
283,
284,
285,
286,
287,
288,
289,
290,
291,
292,
293,
294,
295,
296,
297,
298,
299,
300,
301,
302,
303,
304,
305,
306,
307,
308,
309,
310,
311,
312,
313,
314,
315,
316,
317,
318,
319,
320,
321,
322,
323,
324,
325,
326,
327,
328,
329,
330,
331,
332,
333,
334,
335,
336,
337,
338,
339,
340,
341,
342,
343,
344,
345,
346,
347,
348,
349,
350,
351,
352,
353,
354,
355,
356,
357,
358,
359,
360,
361,
362,
363,
364,
365,
366,
367,
368,
369,
370,
371,
372,
373,
374,
375,
376,
377,
378,
379,
380,
381,
382,
383,
384,
385,
386,
387,
388,
389,
390,
391,
392,
393,
394,
395,
396,
397,
398,
399,
400,
401,
402,
403,
404,
405,
406,
407,
408,
409,
410,
411,
412,
413,
414,
415,
416,
417,
418,
419,
420,
421,
422,
423,
424,
425,
426,
427,
428,
429,
430,
431,
432,
433,
434,
435,
436,
437,
438,
439,
440,
441,
442,
443,
444,
445,
446,
447,
448,
449,
450,
451,
452,
453,
454,
455,
456,
457,
458,
459,
460,
461,
462,
463,
464,
465,
466,
467,
468,
469,
470,
471,
472,
473,
137,
475,
476,
477,
478,
479,
480,
481,
482,
483,
484,
485,
486,
487,
488,
489,
490,
491,
492,
493,
494,
495,
496,
497,
498,
499,
500,
501,
502,
503,
504,
505,
506,
507,
508,
509,
510,
511,
512,
513,
514,
515,
516,
517,
518,
519,
520,
521,
522,
523,
524,
525,
526,
527,
528,
529,
530,
531,
532,
533,
534,
535,
536,
537,
538,
539,