-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
global.h
1082 lines (977 loc) · 32.5 KB
/
global.h
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
#ifndef GUARD_GLOBAL_H
#define GUARD_GLOBAL_H
#include <string.h>
#include <limits.h>
#include "config.h" // we need to define config before gba headers as print stuff needs the functions nulled before defines.
#include "gba/gba.h"
#include "constants/global.h"
#include "constants/flags.h"
#include "constants/vars.h"
#include "constants/species.h"
#include "constants/pokedex.h"
#include "constants/berry.h"
#include "constants/maps.h"
#include "constants/pokemon.h"
#include "constants/easy_chat.h"
#include "constants/trainer_hill.h"
// Prevent cross-jump optimization.
#define BLOCK_CROSS_JUMP asm("");
// to help in decompiling
#define asm_unified(x) asm(".syntax unified\n" x "\n.syntax divided")
#define NAKED __attribute__((naked))
/// IDE support
#if defined(__APPLE__) || defined(__CYGWIN__) || defined(__INTELLISENSE__)
// We define these when using certain IDEs to fool preproc
#define _(x) {x}
#define __(x) {x}
#define INCBIN(...) {0}
#define INCBIN_U8 INCBIN
#define INCBIN_U16 INCBIN
#define INCBIN_U32 INCBIN
#define INCBIN_S8 INCBIN
#define INCBIN_S16 INCBIN
#define INCBIN_S32 INCBIN
#endif // IDE support
#define ARRAY_COUNT(array) (size_t)(sizeof(array) / sizeof((array)[0]))
// GameFreak used a macro called "NELEMS", as evidenced by
// AgbAssert calls.
#define NELEMS(arr) (sizeof(arr)/sizeof(*(arr)))
#define SWAP(a, b, temp) \
{ \
temp = a; \
a = b; \
b = temp; \
}
// useful math macros
// Converts a number to Q8.8 fixed-point format
#define Q_8_8(n) ((s16)((n) * 256))
// Converts a number to Q4.12 fixed-point format
#define Q_4_12(n) ((s16)((n) * 4096))
// Converts a number to Q24.8 fixed-point format
#define Q_24_8(n) ((s32)((n) << 8))
// Converts a Q8.8 fixed-point format number to a regular integer
#define Q_8_8_TO_INT(n) ((int)((n) / 256))
// Converts a Q4.12 fixed-point format number to a regular integer
#define Q_4_12_TO_INT(n) ((int)((n) / 4096))
// Converts a Q24.8 fixed-point format number to a regular integer
#define Q_24_8_TO_INT(n) ((int)((n) >> 8))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) >= (b) ? (a) : (b))
#if MODERN
#define abs(x) (((x) < 0) ? -(x) : (x))
#endif
// Used in cases where division by 0 can occur in the retail version.
// Avoids invalid opcodes on some emulators, and the otherwise UB.
#ifdef UBFIX
#define SAFE_DIV(a, b) (((b) != 0) ? (a) / (b) : 0)
#else
#define SAFE_DIV(a, b) ((a) / (b))
#endif
// The below macro does a%n, but (to match) will switch to a&(n-1) if n is a power of 2.
// There are cases where GF does a&(n-1) where we would really like to have a%n, because
// if n is changed to a value that isn't a power of 2 then a&(n-1) is unlikely to work as
// intended, and a%n for powers of 2 isn't always optimized to use &.
#define MOD(a, n) (((n) & ((n)-1)) ? ((a) % (n)) : ((a) & ((n)-1)))
// Extracts the upper 16 bits of a 32-bit number
#define HIHALF(n) (((n) & 0xFFFF0000) >> 16)
// Extracts the lower 16 bits of a 32-bit number
#define LOHALF(n) ((n) & 0xFFFF)
// There are many quirks in the source code which have overarching behavioral differences from
// a number of other files. For example, diploma.c seems to declare rodata before each use while
// other files declare out of order and must be at the beginning. There are also a number of
// macros which differ from one file to the next due to the method of obtaining the result, such
// as these below. Because of this, there is a theory (Two Team Theory) that states that these
// programming projects had more than 1 "programming team" which utilized different macros for
// each of the files that were worked on.
#define T1_READ_8(ptr) ((ptr)[0])
#define T1_READ_16(ptr) ((ptr)[0] | ((ptr)[1] << 8))
#define T1_READ_32(ptr) ((ptr)[0] | ((ptr)[1] << 8) | ((ptr)[2] << 16) | ((ptr)[3] << 24))
#define T1_READ_PTR(ptr) (u8 *) T1_READ_32(ptr)
// T2_READ_8 is a duplicate to remain consistent with each group.
#define T2_READ_8(ptr) ((ptr)[0])
#define T2_READ_16(ptr) ((ptr)[0] + ((ptr)[1] << 8))
#define T2_READ_32(ptr) ((ptr)[0] + ((ptr)[1] << 8) + ((ptr)[2] << 16) + ((ptr)[3] << 24))
#define T2_READ_PTR(ptr) (void *) T2_READ_32(ptr)
// Macros for checking the joypad
#define TEST_BUTTON(field, button) ((field) & (button))
#define JOY_NEW(button) TEST_BUTTON(gMain.newKeys, button)
#define JOY_HELD(button) TEST_BUTTON(gMain.heldKeys, button)
#define JOY_HELD_RAW(button) TEST_BUTTON(gMain.heldKeysRaw, button)
#define JOY_REPEAT(button) TEST_BUTTON(gMain.newAndRepeatedKeys, button)
#define S16TOPOSFLOAT(val) \
({ \
s16 v = (val); \
float f = (float)v; \
if(v < 0) f += 65536.0f; \
f; \
})
#define DIV_ROUND_UP(val, roundBy) (((val) / (roundBy)) + (((val) % (roundBy)) ? 1 : 0))
#define ROUND_BITS_TO_BYTES(numBits) DIV_ROUND_UP(numBits, 8)
// NUM_DEX_FLAG_BYTES allocates more flags than it needs to, as NUM_SPECIES includes the "old unown"
// values that don't appear in the Pokédex. NATIONAL_DEX_COUNT does not include these values.
#define NUM_DEX_FLAG_BYTES ROUND_BITS_TO_BYTES(NUM_SPECIES)
#define NUM_FLAG_BYTES ROUND_BITS_TO_BYTES(FLAGS_COUNT)
#define NUM_TRENDY_SAYING_BYTES ROUND_BITS_TO_BYTES(NUM_TRENDY_SAYINGS)
// This returns the number of arguments passed to it (up to 8).
#define NARG_8(...) NARG_8_(_, ##__VA_ARGS__, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#define NARG_8_(_, a, b, c, d, e, f, g, h, N, ...) N
#define CAT(a, b) CAT_(a, b)
#define CAT_(a, b) a ## b
// This produces an error at compile-time if expr is zero.
// It looks like file.c:line: size of array `id' is negative
#define STATIC_ASSERT(expr, id) typedef char id[(expr) ? 1 : -1];
struct Coords8
{
s8 x;
s8 y;
};
struct UCoords8
{
u8 x;
u8 y;
};
struct Coords16
{
s16 x;
s16 y;
};
struct UCoords16
{
u16 x;
u16 y;
};
struct Coords32
{
s32 x;
s32 y;
};
struct UCoords32
{
u32 x;
u32 y;
};
struct Time
{
/*0x00*/ s16 days;
/*0x02*/ s8 hours;
/*0x03*/ s8 minutes;
/*0x04*/ s8 seconds;
};
struct Pokedex
{
/*0x00*/ u8 order;
/*0x01*/ u8 mode;
/*0x02*/ u8 nationalMagic; // must equal 0xDA in order to have National mode
/*0x03*/ u8 unknown2;
/*0x04*/ u32 unownPersonality; // set when you first see Unown
/*0x08*/ u32 spindaPersonality; // set when you first see Spinda
/*0x0C*/ u32 unknown3;
/*0x10*/ u8 owned[NUM_DEX_FLAG_BYTES];
/*0x44*/ u8 seen[NUM_DEX_FLAG_BYTES];
};
struct PokemonJumpRecords
{
u16 jumpsInRow;
u16 unused1; // Set to 0, never read
u16 excellentsInRow;
u16 gamesWithMaxPlayers;
u32 unused2; // Set to 0, never read
u32 bestJumpScore;
};
struct BerryPickingResults
{
u32 bestScore;
u16 berriesPicked;
u16 berriesPickedInRow;
u8 field_8;
u8 field_9;
u8 field_A;
u8 field_B;
u8 field_C;
u8 field_D;
u8 field_E;
u8 field_F;
};
struct PyramidBag
{
u16 itemId[FRONTIER_LVL_MODE_COUNT][PYRAMID_BAG_ITEMS_COUNT];
u8 quantity[FRONTIER_LVL_MODE_COUNT][PYRAMID_BAG_ITEMS_COUNT];
};
struct BerryCrush
{
u16 pressingSpeeds[4]; // For the record with each possible group size, 2-5 players
u32 berryPowderAmount;
u32 unk;
};
struct ApprenticeMon
{
u16 species;
u16 moves[MAX_MON_MOVES];
u16 item;
};
// This is for past players Apprentices or Apprentices received via Record Mix.
// For the current Apprentice, see struct PlayersApprentice
struct Apprentice
{
u8 id:5;
u8 lvlMode:2;
//u8 padding1:1;
u8 numQuestions;
u8 number;
//u8 padding2;
struct ApprenticeMon party[MULTI_PARTY_SIZE];
u16 speechWon[EASY_CHAT_BATTLE_WORDS_COUNT];
u8 playerId[TRAINER_ID_LENGTH];
u8 playerName[PLAYER_NAME_LENGTH];
u8 language;
u32 checksum;
};
struct BattleTowerPokemon
{
u16 species;
u16 heldItem;
u16 moves[MAX_MON_MOVES];
u8 level;
u8 ppBonuses;
u8 hpEV;
u8 attackEV;
u8 defenseEV;
u8 speedEV;
u8 spAttackEV;
u8 spDefenseEV;
u32 otId;
u32 hpIV:5;
u32 attackIV:5;
u32 defenseIV:5;
u32 speedIV:5;
u32 spAttackIV:5;
u32 spDefenseIV:5;
u32 gap:1;
u32 abilityNum:1;
u32 personality;
u8 nickname[POKEMON_NAME_LENGTH + 1];
u8 friendship;
};
struct EmeraldBattleTowerRecord
{
/*0x00*/ u8 lvlMode; // 0 = level 50, 1 = level 100
/*0x01*/ u8 facilityClass;
/*0x02*/ u16 winStreak;
/*0x04*/ u8 name[PLAYER_NAME_LENGTH + 1];
/*0x0C*/ u8 trainerId[TRAINER_ID_LENGTH];
/*0x10*/ u16 greeting[EASY_CHAT_BATTLE_WORDS_COUNT];
/*0x1C*/ u16 speechWon[EASY_CHAT_BATTLE_WORDS_COUNT];
/*0x28*/ u16 speechLost[EASY_CHAT_BATTLE_WORDS_COUNT];
/*0x34*/ struct BattleTowerPokemon party[MAX_FRONTIER_PARTY_SIZE];
/*0xE4*/ u8 language;
/*0xE7*/ //u8 padding[3];
/*0xE8*/ u32 checksum;
};
struct BattleTowerInterview
{
u16 playerSpecies;
u16 opponentSpecies;
u8 opponentName[PLAYER_NAME_LENGTH + 1];
u8 opponentMonNickname[POKEMON_NAME_LENGTH + 1];
u8 opponentLanguage;
};
struct BattleTowerEReaderTrainer
{
/*0x00*/ u8 unk0;
/*0x01*/ u8 facilityClass;
/*0x02*/ u16 winStreak;
/*0x04*/ u8 name[PLAYER_NAME_LENGTH + 1];
/*0x0C*/ u8 trainerId[TRAINER_ID_LENGTH];
/*0x10*/ u16 greeting[EASY_CHAT_BATTLE_WORDS_COUNT];
/*0x1C*/ u16 farewellPlayerLost[EASY_CHAT_BATTLE_WORDS_COUNT];
/*0x28*/ u16 farewellPlayerWon[EASY_CHAT_BATTLE_WORDS_COUNT];
/*0x34*/ struct BattleTowerPokemon party[FRONTIER_PARTY_SIZE];
/*0xB8*/ u32 checksum;
};
// For displaying party information on the player's Battle Dome tourney page
struct DomeMonData
{
u16 moves[MAX_MON_MOVES];
u8 evs[NUM_STATS];
u8 nature;
//u8 padding;
};
struct RentalMon
{
u16 monId;
//u8 padding1[2];
u32 personality;
u8 ivs;
u8 abilityNum;
//u8 padding2[2];
};
struct BattleDomeTrainer
{
u16 trainerId:10;
u16 isEliminated:1;
u16 eliminatedAt:2;
u16 forfeited:3;
};
#define DOME_TOURNAMENT_TRAINERS_COUNT 16
#define BATTLE_TOWER_RECORD_COUNT 5
struct BattleFrontier
{
/*0x64C*/ struct EmeraldBattleTowerRecord towerPlayer;
/*0x738*/ struct EmeraldBattleTowerRecord towerRecords[BATTLE_TOWER_RECORD_COUNT]; // From record mixing.
/*0xBEB*/ struct BattleTowerInterview towerInterview;
/*0xBEC*/ struct BattleTowerEReaderTrainer ereaderTrainer;
/*0xCA8*/ u8 challengeStatus;
/*0xCA9*/ u8 lvlMode:2;
u8 challengePaused:1;
u8 disableRecordBattle:1;
//u8 padding1:4;
/*0xCAA*/ u16 selectedPartyMons[MAX_FRONTIER_PARTY_SIZE];
/*0xCB2*/ u16 curChallengeBattleNum; // Battle number / room number (Pike) / floor number (Pyramid)
/*0xCB4*/ u16 trainerIds[20];
/*0xCDC*/ u32 winStreakActiveFlags;
/*0xCE0*/ u16 towerWinStreaks[4][FRONTIER_LVL_MODE_COUNT];
/*0xCF0*/ u16 towerRecordWinStreaks[4][FRONTIER_LVL_MODE_COUNT];
/*0xD00*/ u16 battledBrainFlags;
/*0xD02*/ u16 towerSinglesStreak; // Never read
/*0xD04*/ u16 towerNumWins; // Increments to MAX_STREAK but never read otherwise
/*0xD06*/ u8 towerBattleOutcome;
/*0xD07*/ u8 towerLvlMode;
/*0xD08*/ u8 domeAttemptedSingles50:1;
/*0xD08*/ u8 domeAttemptedSinglesOpen:1;
/*0xD08*/ u8 domeHasWonSingles50:1;
/*0xD08*/ u8 domeHasWonSinglesOpen:1;
/*0xD08*/ u8 domeAttemptedDoubles50:1;
/*0xD08*/ u8 domeAttemptedDoublesOpen:1;
/*0xD08*/ u8 domeHasWonDoubles50:1;
/*0xD08*/ u8 domeHasWonDoublesOpen:1;
/*0xD09*/ u8 domeUnused;
/*0xD0A*/ u8 domeLvlMode;
/*0xD0B*/ u8 domeBattleMode;
/*0xD0C*/ u16 domeWinStreaks[2][FRONTIER_LVL_MODE_COUNT];
/*0xD14*/ u16 domeRecordWinStreaks[2][FRONTIER_LVL_MODE_COUNT];
/*0xD1C*/ u16 domeTotalChampionships[2][FRONTIER_LVL_MODE_COUNT];
/*0xD24*/ struct BattleDomeTrainer domeTrainers[DOME_TOURNAMENT_TRAINERS_COUNT];
/*0xD64*/ u16 domeMonIds[DOME_TOURNAMENT_TRAINERS_COUNT][FRONTIER_PARTY_SIZE];
/*0xDC4*/ u16 unused_DC4;
/*0xDC6*/ u16 palacePrize;
/*0xDC8*/ u16 palaceWinStreaks[2][FRONTIER_LVL_MODE_COUNT];
/*0xDD0*/ u16 palaceRecordWinStreaks[2][FRONTIER_LVL_MODE_COUNT];
/*0xDD8*/ u16 arenaPrize;
/*0xDDA*/ u16 arenaWinStreaks[FRONTIER_LVL_MODE_COUNT];
/*0xDDE*/ u16 arenaRecordStreaks[FRONTIER_LVL_MODE_COUNT];
/*0xDE2*/ u16 factoryWinStreaks[2][FRONTIER_LVL_MODE_COUNT];
/*0xDEA*/ u16 factoryRecordWinStreaks[2][FRONTIER_LVL_MODE_COUNT];
/*0xDF6*/ u16 factoryRentsCount[2][FRONTIER_LVL_MODE_COUNT];
/*0xDFA*/ u16 factoryRecordRentsCount[2][FRONTIER_LVL_MODE_COUNT];
/*0xE02*/ u16 pikePrize;
/*0xE04*/ u16 pikeWinStreaks[FRONTIER_LVL_MODE_COUNT];
/*0xE08*/ u16 pikeRecordStreaks[FRONTIER_LVL_MODE_COUNT];
/*0xE0C*/ u16 pikeTotalStreaks[FRONTIER_LVL_MODE_COUNT];
/*0xE10*/ u8 pikeHintedRoomIndex:3;
u8 pikeHintedRoomType:4;
u8 pikeHealingRoomsDisabled:1;
/*0xE11*/ //u8 padding2;
/*0xE12*/ u16 pikeHeldItemsBackup[FRONTIER_PARTY_SIZE];
/*0xE18*/ u16 pyramidPrize;
/*0xE1A*/ u16 pyramidWinStreaks[FRONTIER_LVL_MODE_COUNT];
/*0xE1E*/ u16 pyramidRecordStreaks[FRONTIER_LVL_MODE_COUNT];
/*0xE22*/ u16 pyramidRandoms[4];
/*0xE2A*/ u8 pyramidTrainerFlags; // 1 bit for each trainer (MAX_PYRAMID_TRAINERS)
/*0xE2B*/ //u8 padding3;
/*0xE2C*/ struct PyramidBag pyramidBag;
/*0xE68*/ u8 pyramidLightRadius;
/*0xE69*/ //u8 padding4;
/*0xE6A*/ u16 verdanturfTentPrize;
/*0xE6C*/ u16 fallarborTentPrize;
/*0xE6E*/ u16 slateportTentPrize;
/*0xE70*/ struct RentalMon rentalMons[FRONTIER_PARTY_SIZE * 2];
/*0xEB8*/ u16 battlePoints;
/*0xEBA*/ u16 cardBattlePoints;
/*0xEBC*/ u32 battlesCount;
/*0xEC0*/ u16 domeWinningMoves[DOME_TOURNAMENT_TRAINERS_COUNT];
/*0xEE0*/ u8 trainerFlags;
/*0xEE1*/ u8 opponentNames[FRONTIER_LVL_MODE_COUNT][PLAYER_NAME_LENGTH + 1];
/*0xEF1*/ u8 opponentTrainerIds[FRONTIER_LVL_MODE_COUNT][TRAINER_ID_LENGTH];
/*0xEF9*/ u8 unk_EF9:7; // Never read
/*0xEF9*/ u8 savedGame:1;
/*0xEFA*/ u8 unused_EFA;
/*0xEFB*/ u8 unused_EFB;
/*0xEFC*/ struct DomeMonData domePlayerPartyData[FRONTIER_PARTY_SIZE];
};
struct ApprenticeQuestion
{
u8 questionId:2;
u8 monId:2;
u8 moveSlot:2;
u8 suggestedChange:2; // TRUE if told to use held item or second move, FALSE if told to use no item or first move
//u8 padding;
u16 data; // used both as an itemId and a moveId
};
struct PlayersApprentice
{
/*0xB0*/ u8 id;
/*0xB1*/ u8 lvlMode:2; //0: Unassigned, 1: Lv 50, 2: Open Lv
/*0xB1*/ u8 questionsAnswered:4;
/*0xB1*/ u8 leadMonId:2;
/*0xB2*/ u8 party:3;
u8 saveId:2;
//u8 padding1:3;
/*0xB3*/ u8 unused;
/*0xB4*/ u8 speciesIds[MULTI_PARTY_SIZE];
/*0xB7*/ //u8 padding2;
/*0xB8*/ struct ApprenticeQuestion questions[APPRENTICE_MAX_QUESTIONS];
};
struct RankingHall1P
{
u8 id[TRAINER_ID_LENGTH];
u16 winStreak;
u8 name[PLAYER_NAME_LENGTH + 1];
u8 language;
//u8 padding;
};
struct RankingHall2P
{
u8 id1[TRAINER_ID_LENGTH];
u8 id2[TRAINER_ID_LENGTH];
u16 winStreak;
u8 name1[PLAYER_NAME_LENGTH + 1];
u8 name2[PLAYER_NAME_LENGTH + 1];
u8 language;
//u8 padding;
};
struct SaveBlock2
{
/*0x00*/ u8 playerName[PLAYER_NAME_LENGTH + 1];
/*0x08*/ u8 playerGender; // MALE, FEMALE
/*0x09*/ u8 specialSaveWarpFlags;
/*0x0A*/ u8 playerTrainerId[TRAINER_ID_LENGTH];
/*0x0E*/ u16 playTimeHours;
/*0x10*/ u8 playTimeMinutes;
/*0x11*/ u8 playTimeSeconds;
/*0x12*/ u8 playTimeVBlanks;
/*0x13*/ u8 optionsButtonMode; // OPTIONS_BUTTON_MODE_[NORMAL/LR/L_EQUALS_A]
/*0x14*/ u16 optionsTextSpeed:3; // OPTIONS_TEXT_SPEED_[SLOW/MID/FAST]
u16 optionsWindowFrameType:5; // Specifies one of the 20 decorative borders for text boxes
u16 optionsSound:1; // OPTIONS_SOUND_[MONO/STEREO]
u16 optionsBattleStyle:1; // OPTIONS_BATTLE_STYLE_[SHIFT/SET]
u16 optionsBattleSceneOff:1; // whether battle animations are disabled
u16 regionMapZoom:1; // whether the map is zoomed in
//u16 padding1:4;
//u16 padding2;
/*0x18*/ struct Pokedex pokedex;
/*0x90*/ u8 filler_90[0x8];
/*0x98*/ struct Time localTimeOffset;
/*0xA0*/ struct Time lastBerryTreeUpdate;
/*0xA8*/ u32 gcnLinkFlags; // Read by Pokémon Colosseum/XD
/*0xAC*/ u32 encryptionKey;
/*0xB0*/ struct PlayersApprentice playerApprentice;
/*0xDC*/ struct Apprentice apprentices[APPRENTICE_COUNT];
/*0x1EC*/ struct BerryCrush berryCrush;
/*0x1FC*/ struct PokemonJumpRecords pokeJump;
/*0x20C*/ struct BerryPickingResults berryPick;
/*0x21C*/ struct RankingHall1P hallRecords1P[HALL_FACILITIES_COUNT][FRONTIER_LVL_MODE_COUNT][HALL_RECORDS_COUNT]; // From record mixing.
/*0x57C*/ struct RankingHall2P hallRecords2P[FRONTIER_LVL_MODE_COUNT][HALL_RECORDS_COUNT]; // From record mixing.
/*0x624*/ u16 contestLinkResults[CONTEST_CATEGORIES_COUNT][CONTESTANT_COUNT];
/*0x64C*/ struct BattleFrontier frontier;
}; // sizeof=0xF2C
extern struct SaveBlock2 *gSaveBlock2Ptr;
struct SecretBaseParty
{
u32 personality[PARTY_SIZE];
u16 moves[PARTY_SIZE * MAX_MON_MOVES];
u16 species[PARTY_SIZE];
u16 heldItems[PARTY_SIZE];
u8 levels[PARTY_SIZE];
u8 EVs[PARTY_SIZE];
};
struct SecretBase
{
/*0x1A9C*/ u8 secretBaseId;
/*0x1A9D*/ bool8 toRegister:4;
/*0x1A9D*/ u8 gender:1;
/*0x1A9D*/ u8 battledOwnerToday:1;
/*0x1A9D*/ u8 registryStatus:2;
/*0x1A9E*/ u8 trainerName[PLAYER_NAME_LENGTH];
/*0x1AA5*/ u8 trainerId[TRAINER_ID_LENGTH]; // byte 0 is used for determining trainer class
/*0x1AA9*/ u8 language;
/*0x1AAA*/ u16 numSecretBasesReceived;
/*0x1AAC*/ u8 numTimesEntered;
/*0x1AAD*/ u8 unused;
/*0x1AAE*/ u8 decorations[DECOR_MAX_SECRET_BASE];
/*0x1ABE*/ u8 decorationPositions[DECOR_MAX_SECRET_BASE];
/*0x1ACE*/ //u8 padding[2];
/*0x1AD0*/ struct SecretBaseParty party;
};
#include "constants/game_stat.h"
#include "global.fieldmap.h"
#include "global.berry.h"
#include "global.tv.h"
#include "pokemon.h"
struct WarpData
{
s8 mapGroup;
s8 mapNum;
s8 warpId;
//u8 padding;
s16 x, y;
};
struct ItemSlot
{
u16 itemId;
u16 quantity;
};
struct Pokeblock
{
u8 color;
u8 spicy;
u8 dry;
u8 sweet;
u8 bitter;
u8 sour;
u8 feel;
};
struct Roamer
{
/*0x00*/ u32 ivs;
/*0x04*/ u32 personality;
/*0x08*/ u16 species;
/*0x0A*/ u16 hp;
/*0x0C*/ u8 level;
/*0x0D*/ u8 status;
/*0x0E*/ u8 cool;
/*0x0F*/ u8 beauty;
/*0x10*/ u8 cute;
/*0x11*/ u8 smart;
/*0x12*/ u8 tough;
/*0x13*/ bool8 active;
/*0x14*/ u8 filler[0x8];
};
struct RamScriptData
{
u8 magic;
u8 mapGroup;
u8 mapNum;
u8 objectId;
u8 script[995];
//u8 padding;
};
struct RamScript
{
u32 checksum;
struct RamScriptData data;
};
// See dewford_trend.c
struct DewfordTrend
{
u16 trendiness:7;
u16 maxTrendiness:7;
u16 gainingTrendiness:1;
//u16 padding:1;
u16 rand;
u16 words[2];
}; /*size = 0x8*/
struct MauvilleManCommon
{
u8 id;
};
struct MauvilleManBard
{
/*0x00*/ u8 id;
/*0x01*/ //u8 padding1;
/*0x02*/ u16 songLyrics[BARD_SONG_LENGTH];
/*0x0E*/ u16 temporaryLyrics[BARD_SONG_LENGTH];
/*0x1A*/ u8 playerName[PLAYER_NAME_LENGTH + 1];
/*0x22*/ u8 filler_2DB6[0x3];
/*0x25*/ u8 playerTrainerId[TRAINER_ID_LENGTH];
/*0x29*/ bool8 hasChangedSong;
/*0x2A*/ u8 language;
/*0x2B*/ //u8 padding2;
}; /*size = 0x2C*/
struct MauvilleManStoryteller
{
u8 id;
bool8 alreadyRecorded;
u8 filler2[2];
u8 gameStatIDs[NUM_STORYTELLER_TALES];
u8 trainerNames[NUM_STORYTELLER_TALES][PLAYER_NAME_LENGTH];
u8 statValues[NUM_STORYTELLER_TALES][4];
u8 language[NUM_STORYTELLER_TALES];
};
struct MauvilleManGiddy
{
/*0x00*/ u8 id;
/*0x01*/ u8 taleCounter;
/*0x02*/ u8 questionNum;
/*0x03*/ //u8 padding1;
/*0x04*/ u16 randomWords[GIDDY_MAX_TALES];
/*0x18*/ u8 questionList[GIDDY_MAX_QUESTIONS];
/*0x20*/ u8 language;
/*0x21*/ //u8 padding2;
}; /*size = 0x2C*/
struct MauvilleManHipster
{
u8 id;
bool8 taughtWord;
u8 language;
};
struct MauvilleOldManTrader
{
u8 id;
u8 decorations[NUM_TRADER_ITEMS];
u8 playerNames[NUM_TRADER_ITEMS][11];
u8 alreadyTraded;
u8 language[NUM_TRADER_ITEMS];
};
typedef union OldMan
{
struct MauvilleManCommon common;
struct MauvilleManBard bard;
struct MauvilleManGiddy giddy;
struct MauvilleManHipster hipster;
struct MauvilleOldManTrader trader;
struct MauvilleManStoryteller storyteller;
u8 filler[0x40];
} OldMan;
#define LINK_B_RECORDS_COUNT 5
struct LinkBattleRecord
{
u8 name[PLAYER_NAME_LENGTH + 1];
u16 trainerId;
u16 wins;
u16 losses;
u16 draws;
};
struct LinkBattleRecords
{
struct LinkBattleRecord entries[LINK_B_RECORDS_COUNT];
u8 languages[LINK_B_RECORDS_COUNT];
//u8 padding;
};
struct RecordMixingGiftData
{
u8 unk0;
u8 quantity;
u16 itemId;
u8 filler4[8];
};
struct RecordMixingGift
{
int checksum;
struct RecordMixingGiftData data;
};
struct ContestWinner
{
u32 personality;
u32 trainerId;
u16 species;
u8 contestCategory;
u8 monName[POKEMON_NAME_LENGTH + 1];
u8 trainerName[PLAYER_NAME_LENGTH + 1];
u8 contestRank;
//u8 padding;
};
struct Mail
{
/*0x00*/ u16 words[MAIL_WORDS_COUNT];
/*0x12*/ u8 playerName[PLAYER_NAME_LENGTH + 1];
/*0x1A*/ u8 trainerId[TRAINER_ID_LENGTH];
/*0x1E*/ u16 species;
/*0x20*/ u16 itemId;
};
struct DaycareMail
{
struct Mail message;
u8 otName[PLAYER_NAME_LENGTH + 1];
u8 monName[POKEMON_NAME_LENGTH + 1];
u8 gameLanguage:4;
u8 monLanguage:4;
};
struct DaycareMon
{
struct BoxPokemon mon;
struct DaycareMail mail;
u32 steps;
};
struct DayCare
{
struct DaycareMon mons[DAYCARE_MON_COUNT];
u32 offspringPersonality;
u8 stepCounter;
//u8 padding[3];
};
struct LilycoveLadyQuiz
{
/*0x000*/ u8 id;
/*0x001*/ u8 state;
/*0x002*/ u16 question[QUIZ_QUESTION_LEN];
/*0x014*/ u16 correctAnswer;
/*0x016*/ u16 playerAnswer;
/*0x018*/ u8 playerName[PLAYER_NAME_LENGTH + 1];
/*0x020*/ u16 playerTrainerId[TRAINER_ID_LENGTH];
/*0x028*/ u16 prize;
/*0x02A*/ bool8 waitingForChallenger;
/*0x02B*/ u8 questionId;
/*0x02C*/ u8 prevQuestionId;
/*0x02D*/ u8 language;
};
struct LilycoveLadyFavor
{
/*0x000*/ u8 id;
/*0x001*/ u8 state;
/*0x002*/ bool8 likedItem;
/*0x003*/ u8 numItemsGiven;
/*0x004*/ u8 playerName[PLAYER_NAME_LENGTH + 1];
/*0x00C*/ u8 favorId;
/*0x00D*/ //u8 padding1;
/*0x00E*/ u16 itemId;
/*0x010*/ u16 bestItem;
/*0x012*/ u8 language;
/*0x013*/ //u8 padding2;
};
struct LilycoveLadyContest
{
/*0x000*/ u8 id;
/*0x001*/ bool8 givenPokeblock;
/*0x002*/ u8 numGoodPokeblocksGiven;
/*0x003*/ u8 numOtherPokeblocksGiven;
/*0x004*/ u8 playerName[PLAYER_NAME_LENGTH + 1];
/*0x00C*/ u8 maxSheen;
/*0x00D*/ u8 category;
/*0x00E*/ u8 language;
};
typedef union // 3b58
{
struct LilycoveLadyQuiz quiz;
struct LilycoveLadyFavor favor;
struct LilycoveLadyContest contest;
u8 id;
u8 filler[0x40];
} LilycoveLady;
struct WaldaPhrase
{
u16 colors[2]; // Background, foreground.
u8 text[16];
u8 iconId;
u8 patternId;
bool8 patternUnlocked;
//u8 padding;
};
struct TrainerNameRecord
{
u32 trainerId;
u8 ALIGNED(2) trainerName[PLAYER_NAME_LENGTH + 1];
};
struct TrainerHillSave
{
/*0x3D64*/ u32 timer;
/*0x3D68*/ u32 bestTime;
/*0x3D6C*/ u8 unk_3D6C;
/*0x3D6D*/ u8 unused;
/*0x3D6E*/ u16 receivedPrize:1;
u16 checkedFinalTime:1;
u16 spokeToOwner:1;
u16 hasLost:1;
u16 maybeECardScanDuringChallenge:1;
u16 field_3D6E_0f:1;
u16 mode:2; // HILL_MODE_*
//u16 padding:8;
};
struct WonderNewsMetadata
{
u8 newsType:2;
u8 sentRewardCounter:3;
u8 rewardCounter:3;
u8 berry;
//u8 padding[2];
};
struct WonderNews
{
u16 id;
u8 sendType; // SEND_TYPE_*
u8 bgType;
u8 titleText[WONDER_NEWS_TEXT_LENGTH];
u8 bodyText[WONDER_NEWS_BODY_TEXT_LINES][WONDER_NEWS_TEXT_LENGTH];
};
struct WonderCard
{
u16 flagId; // Event flag (sReceivedGiftFlags) + WONDER_CARD_FLAG_OFFSET
u16 iconSpecies;
u32 idNumber;
u8 type:2; // CARD_TYPE_*
u8 bgType:4;
u8 sendType:2; // SEND_TYPE_*
u8 maxStamps;
u8 titleText[WONDER_CARD_TEXT_LENGTH];
u8 subtitleText[WONDER_CARD_TEXT_LENGTH];
u8 bodyText[WONDER_CARD_BODY_TEXT_LINES][WONDER_CARD_TEXT_LENGTH];
u8 footerLine1Text[WONDER_CARD_TEXT_LENGTH];
u8 footerLine2Text[WONDER_CARD_TEXT_LENGTH];
//u8 padding[2];
};
struct WonderCardMetadata
{
u16 battlesWon;
u16 battlesLost;
u16 numTrades;
u16 iconSpecies;
u16 stampData[2][MAX_STAMP_CARD_STAMPS]; // First element is STAMP_SPECIES, second is STAMP_ID
};
struct MysteryGiftSave
{
u32 newsCrc;
struct WonderNews news;
u32 cardCrc;
struct WonderCard card;
u32 cardMetadataCrc;
struct WonderCardMetadata cardMetadata;
u16 questionnaireWords[NUM_QUESTIONNAIRE_WORDS];
struct WonderNewsMetadata newsMetadata;
u32 trainerIds[2][5]; // Saved ids for 10 trainers, 5 each for battles and trades
}; // 0x36C 0x3598
// For external event data storage. The majority of these may have never been used.
// In Emerald, the only known used fields are the PokeCoupon and BoxRS ones, but hacking the distribution discs allows Emerald to receive events and set the others
struct ExternalEventData
{
u8 unknownExternalDataFields1[7]; // if actually used, may be broken up into different fields.
u32 unknownExternalDataFields2:8;
u32 currentPokeCoupons:24; // PokéCoupons stored by Pokémon Colosseum and XD from Mt. Battle runs. Earned PokéCoupons are also added to totalEarnedPokeCoupons. Colosseum/XD caps this at 9,999,999, but will read up to 16,777,215.
u32 gotGoldPokeCouponTitleReward:1; // Master Ball from JP Colosseum Bonus Disc; for reaching 30,000 totalEarnedPokeCoupons
u32 gotSilverPokeCouponTitleReward:1; // Light Ball Pikachu from JP Colosseum Bonus Disc; for reaching 5000 totalEarnedPokeCoupons
u32 gotBronzePokeCouponTitleReward:1; // PP Max from JP Colosseum Bonus Disc; for reaching 2500 totalEarnedPokeCoupons
u32 receivedAgetoCelebi:1; // from JP Colosseum Bonus Disc
u32 unknownExternalDataFields3:4;
u32 totalEarnedPokeCoupons:24; // Used by the JP Colosseum bonus disc. Determines PokéCoupon rank to distribute rewards. Unread in International games. Colosseum/XD caps this at 9,999,999.
u8 unknownExternalDataFields4[5]; // if actually used, may be broken up into different fields.
} __attribute__((packed)); /*size = 0x14*/
// For external event flags. The majority of these may have never been used.
// In Emerald, Jirachi cannot normally be received, but hacking the distribution discs allows Emerald to receive Jirachi and set the flag
struct ExternalEventFlags
{
u8 usedBoxRS:1; // Set by Pokémon Box: Ruby & Sapphire; denotes whether this save has connected to it and triggered the free False Swipe Swablu Egg giveaway.
u8 boxRSEggsUnlocked:2; // Set by Pokémon Box: Ruby & Sapphire; denotes the number of Eggs unlocked from deposits; 1 for ExtremeSpeed Zigzagoon (at 100 deposited), 2 for Pay Day Skitty (at 500 deposited), 3 for Surf Pichu (at 1499 deposited)
//u8 padding:5;
u8 unknownFlag1;
u8 receivedGCNJirachi; // Both the US Colosseum Bonus Disc and PAL/AUS Pokémon Channel use this field. One cannot receive a WISHMKR Jirachi and CHANNEL Jirachi with the same savefile.
u8 unknownFlag3;
u8 unknownFlag4;
u8 unknownFlag5;
u8 unknownFlag6;
u8 unknownFlag7;
u8 unknownFlag8;
u8 unknownFlag9;
u8 unknownFlag10;
u8 unknownFlag11;
u8 unknownFlag12;
u8 unknownFlag13;
u8 unknownFlag14;
u8 unknownFlag15;
u8 unknownFlag16;
u8 unknownFlag17;
u8 unknownFlag18;
u8 unknownFlag19;
u8 unknownFlag20;
} __attribute__((packed));/*size = 0x15*/
struct SaveBlock1
{
/*0x00*/ struct Coords16 pos;
/*0x04*/ struct WarpData location;
/*0x0C*/ struct WarpData continueGameWarp;
/*0x14*/ struct WarpData dynamicWarp;
/*0x1C*/ struct WarpData lastHealLocation; // used by white-out and teleport
/*0x24*/ struct WarpData escapeWarp; // used by Dig and Escape Rope
/*0x2C*/ u16 savedMusic;
/*0x2E*/ u8 weather;
/*0x2F*/ u8 weatherCycleStage;
/*0x30*/ u8 flashLevel;
/*0x31*/ //u8 padding1;
/*0x32*/ u16 mapLayoutId;
/*0x34*/ u16 mapView[0x100];
/*0x234*/ u8 playerPartyCount;
/*0x235*/ //u8 padding2[3];
/*0x238*/ struct Pokemon playerParty[PARTY_SIZE];
/*0x490*/ u32 money;
/*0x494*/ u16 coins;
/*0x496*/ u16 registeredItem; // registered for use with SELECT button
/*0x498*/ struct ItemSlot pcItems[PC_ITEMS_COUNT];
/*0x560*/ struct ItemSlot bagPocket_Items[BAG_ITEMS_COUNT];
/*0x5D8*/ struct ItemSlot bagPocket_KeyItems[BAG_KEYITEMS_COUNT];
/*0x650*/ struct ItemSlot bagPocket_PokeBalls[BAG_POKEBALLS_COUNT];