more pokemon2 decomp

This commit is contained in:
DizzyEggg 2017-09-11 22:28:36 +02:00
parent e69606b5cb
commit 738e776630
12 changed files with 870 additions and 2111 deletions

File diff suppressed because it is too large Load Diff

View File

@ -11184,7 +11184,7 @@ sub_813B21C: @ 813B21C
lsls r0, 24
cmp r0, 0
bne _0813B258
bl get_preferred_box
bl StorageGetCurrentBox
adds r4, r0, 0
lsls r4, 24
lsrs r4, 24
@ -11215,7 +11215,7 @@ sub_813B260: @ 813B260
lsls r0, 24
lsrs r0, 24
bl set_unknown_box_id
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r4, r0, 24
_0813B278:
@ -11226,7 +11226,7 @@ _0813B27E:
lsls r1, r5, 24
lsrs r1, 24
lsrs r0, r6, 24
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
movs r1, 0xB
movs r2, 0
bl GetBoxMonData
@ -11257,7 +11257,7 @@ _0813B2C0:
bne _0813B2CE
movs r4, 0
_0813B2CE:
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
cmp r4, r0

View File

@ -1763,7 +1763,7 @@ _080C7DA8:
bl CreateTask
ldr r1, [r4]
strb r0, [r1, 0x4]
bl get_preferred_box
bl StorageGetCurrentBox
ldr r1, =gUnknown_02039D10
strb r0, [r1]
ldr r0, =c2_Box
@ -2102,7 +2102,7 @@ _080C80EC:
bl sub_80CA704
b _080C8198
_080C80F2:
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
bl sub_80CC32C
@ -2459,7 +2459,7 @@ _080C8440:
_080C844C:
movs r0, 0x5
bl PlaySE
bl get_preferred_box
bl StorageGetCurrentBox
ldr r4, =gUnknown_02039D08
ldr r1, [r4]
lsls r0, 24
@ -2483,7 +2483,7 @@ _080C846E:
_080C8484:
movs r0, 0x5
bl PlaySE
bl get_preferred_box
bl StorageGetCurrentBox
ldr r4, =gUnknown_02039D08
ldr r1, [r4]
lsls r0, 24
@ -4859,7 +4859,7 @@ _080C99FE:
movs r1, 0xA
movs r3, 0x3
bl sub_80C77E8
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
bl sub_80C78D4
@ -4888,7 +4888,7 @@ _080C9A2C:
cmp r0, 0xC9
beq _080C9A6C
adds r4, r0, 0
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
cmp r4, r0
@ -5421,7 +5421,7 @@ _080C9F04:
.pool
_080C9F1C:
bl sub_80C9FC8
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
bl sav3_get_box_name
@ -6895,7 +6895,7 @@ _080CABDA:
sub_80CABE0: @ 80CABE0
push {r4,lr}
ldr r4, =gUnknown_02039D10
bl get_preferred_box
bl StorageGetCurrentBox
ldrb r1, [r4]
lsls r0, 24
lsrs r0, 24
@ -6904,7 +6904,7 @@ sub_80CABE0: @ 80CABE0
ldr r0, =0x000008d7
bl FlagReset
ldr r4, =0x00004036
bl get_preferred_box
bl StorageGetCurrentBox
adds r1, r0, 0
lsls r1, 24
lsrs r1, 24
@ -10143,7 +10143,7 @@ sub_80CC644: @ 80CC644
push {r4,lr}
lsls r0, 24
lsrs r4, r0, 24
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r1, r0, 24
movs r2, 0
@ -10180,7 +10180,7 @@ sub_80CC680: @ 80CC680
adds r4, r0, 0
lsls r4, 24
lsrs r4, 24
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
adds r1, r4, 0
@ -10244,7 +10244,7 @@ _080CC718:
lsls r0, 24
cmp r0, 0
bne _080CC794
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
movs r1, 0
@ -11229,7 +11229,7 @@ _080CCF96:
thumb_func_start sub_80CCF9C
sub_80CCF9C: @ 80CCF9C
push {lr}
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
bl sub_80D20F8
@ -12975,7 +12975,7 @@ _080CDDFE:
b _080CDE2A
.pool
_080CDE20:
bl get_preferred_box
bl StorageGetCurrentBox
ldr r1, [r4]
ldr r2, =0x00000d91
adds r1, r2
@ -13141,7 +13141,7 @@ _080CDF68:
ldrb r0, [r0]
cmp r0, 0
bne _080CDF8E
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
ldr r4, =gUnknown_02039D79
@ -13182,7 +13182,7 @@ sub_80CDFAC: @ 80CDFAC
b _080CDFF8
.pool
_080CDFDC:
bl get_preferred_box
bl StorageGetCurrentBox
adds r4, r0, 0
lsls r4, 24
lsrs r4, 24
@ -13417,7 +13417,7 @@ _080CE1DC:
ldrb r0, [r5]
bl sub_80CBB68
_080CE1F6:
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
cmp r6, r0
@ -13539,7 +13539,7 @@ _080CE2F0:
b _080CE30C
.pool
_080CE304:
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r2, r0, 24
_080CE30C:
@ -13687,7 +13687,7 @@ _080CE418:
b _080CE488
.pool
_080CE464:
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
ldr r1, =gUnknown_02039D79
@ -13697,7 +13697,7 @@ _080CE464:
ldr r3, =0x00002108
adds r2, r3
bl sub_80D2054
bl get_preferred_box
bl StorageGetCurrentBox
ldr r1, [r4]
ldr r2, =0x00002170
adds r1, r2
@ -14140,11 +14140,11 @@ _080CE838:
b _080CE8CA
.pool
_080CE894:
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
movs r1, 0
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
ldr r3, =gUnknown_02039D08
ldr r2, [r3]
ldr r4, =0x0000218c
@ -14527,12 +14527,12 @@ _080CEBB0:
bl sub_80CEC00
b _080CEBD0
_080CEBBA:
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
ldr r1, =gUnknown_02039D79
ldrb r1, [r1]
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
movs r1, 0x1
bl sub_80CEC00
_080CEBD0:
@ -15491,7 +15491,7 @@ _080CF428:
adds r1, r0
movs r0, 0x2
strb r0, [r1]
bl get_preferred_box
bl StorageGetCurrentBox
ldr r1, =gUnknown_02039D7B
strb r0, [r1]
movs r0, 0x17
@ -18075,7 +18075,7 @@ _080D0902:
_080D0914:
adds r0, 0x1
strb r0, [r2, 0xB]
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
mov r10, r0
@ -18111,7 +18111,7 @@ _080D093C:
_080D095A:
mov r0, r10
adds r1, r5, 0
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
adds r1, r0, 0
ldr r2, =gUnknown_02039D80
ldr r0, [r2]
@ -18161,7 +18161,7 @@ sub_80D09A4: @ 80D09A4
ldrb r0, [r0, 0xB]
adds r1, r0
mov r9, r1
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
mov r8, r0
@ -18305,7 +18305,7 @@ sub_80D0AAC: @ 80D0AAC
ldrb r0, [r0, 0xB]
adds r1, r0
str r1, [sp]
bl get_preferred_box
bl StorageGetCurrentBox
lsls r0, 24
lsrs r0, 24
str r0, [sp, 0x4]
@ -20559,15 +20559,15 @@ nullsub_98: @ 80D1D08
bx lr
thumb_func_end nullsub_98
thumb_func_start get_preferred_box
@ char get_preferred_box()
get_preferred_box: @ 80D1D0C
thumb_func_start StorageGetCurrentBox
@ char StorageGetCurrentBox()
StorageGetCurrentBox: @ 80D1D0C
ldr r0, =gPokemonStoragePtr
ldr r0, [r0]
ldrb r0, [r0]
bx lr
.pool
thumb_func_end get_preferred_box
thumb_func_end StorageGetCurrentBox
thumb_func_start sub_80D1D18
sub_80D1D18: @ 80D1D18
@ -21050,9 +21050,9 @@ _080D2088:
.pool
thumb_func_end sub_80D2054
thumb_func_start get_pokemon_by_box_and_pos
@ pokemon *get_pokemon_by_box_and_pos(u8 box_id, u8 pos)
get_pokemon_by_box_and_pos: @ 80D2094
thumb_func_start GetBoxedMonPtr
@ pokemon *GetBoxedMonPtr(u8 box_id, u8 pos)
GetBoxedMonPtr: @ 80D2094
push {r4,lr}
lsls r0, 24
lsrs r3, r0, 24
@ -21083,7 +21083,7 @@ _080D20CA:
pop {r4}
pop {r1}
bx r1
thumb_func_end get_pokemon_by_box_and_pos
thumb_func_end GetBoxedMonPtr
thumb_func_start sav3_get_box_name
sav3_get_box_name: @ 80D20D0

View File

@ -28946,7 +28946,7 @@ _081CD690:
_081CD6E0:
mov r0, r8
mov r1, r9
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
adds r4, r0, 0
bl GetBoxMonGender
lsls r0, 24
@ -33128,7 +33128,7 @@ sub_81CF8E4: @ 81CF8E4
_081CF924:
ldrb r0, [r2]
ldrb r1, [r2, 0x1]
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
adds r4, r0, 0
bl GetBoxMonGender
lsls r0, 24
@ -34505,7 +34505,7 @@ sub_81D035C: @ 81D035C
_081D03A4:
ldrb r0, [r7]
ldrb r1, [r7, 0x1]
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
adds r4, r0, 0
bl GetBoxMonGender
lsls r0, 24
@ -34992,7 +34992,7 @@ sub_81D06E4: @ 81D06E4
_081D0730:
ldrb r0, [r1]
ldrb r1, [r1, 0x1]
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
adds r4, r0, 0
bl GetBoxMonGender
strb r0, [r6]
@ -35049,7 +35049,7 @@ sub_81D0760: @ 81D0760
_081D07AC:
ldrb r0, [r1]
ldrb r1, [r1, 0x1]
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
adds r4, r0, 0
movs r1, 0xB
bl GetBoxMonData
@ -39990,7 +39990,7 @@ _081D2D70:
lsrs r0, 24
lsls r1, r6, 24
lsrs r1, 24
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
adds r4, r0, 0
bl GetBoxMonGender
lsls r0, 24

View File

@ -288,7 +288,7 @@ sub_80773AC: @ 80773AC
ldr r0, =gMain
movs r1, 0
str r1, [r0]
ldr r0, =gUnknown_020244EA
ldr r0, =gEnemyPartyCount
strb r1, [r0]
pop {r0}
bx r0
@ -600,7 +600,7 @@ _080776A8:
adds r0, 0x36
strb r1, [r0]
ldr r0, [r2]
ldr r1, =gUnknown_020244EA
ldr r1, =gEnemyPartyCount
ldrb r1, [r1]
adds r0, 0x37
strb r1, [r0]
@ -1211,7 +1211,7 @@ _08077C6C:
adds r0, 0x36
strb r1, [r0]
ldr r0, [r4]
ldr r1, =gUnknown_020244EA
ldr r1, =gEnemyPartyCount
ldrb r1, [r1]
adds r0, 0x37
strb r1, [r0]

View File

@ -7570,7 +7570,7 @@ sub_80EFEC4: @ 80EFEC4
ldrb r0, [r0]
ldr r1, =gSpecialVar_0x8013
ldrb r1, [r1]
bl get_pokemon_by_box_and_pos
bl GetBoxedMonPtr
adds r6, r0, 0
ldr r2, =gStringVar3
movs r1, 0x2

View File

@ -84,6 +84,8 @@
#define SYS_CTRL_OBJ_DELETE CODE_FLAGS + 0x61
#define SYS_RESET_RTC_ENABLE CODE_FLAGS + 0x62
#define SYS_STORAGE_UNKNOWN_FLAG CODE_FLAGS + 0x77
#define SYS_MYSTERY_GIFT_ENABLE CODE_FLAGS + 0x7B
// SPECIAL FLAGS (unknown purpose)

View File

@ -81,10 +81,10 @@
#define MON_DATA_GIFT_RIBBON_6 77
#define MON_DATA_GIFT_RIBBON_7 78
#define MON_DATA_FATEFUL_ENCOUNTER 79
#define MON_DATA_KNOWN_MOVES 80
#define MON_DATA_RIBBON_COUNT 81
#define MON_DATA_RIBBONS 82
#define MON_DATA_83 83
#define MON_DATA_OBEDIENCE 80
#define MON_DATA_KNOWN_MOVES 81
#define MON_DATA_RIBBON_COUNT 82
#define MON_DATA_RIBBONS 83
#define MON_DATA_ATK2 84
#define MON_DATA_DEF2 85
#define MON_DATA_SPD2 86
@ -95,6 +95,14 @@
#define OT_ID_PRESET 1
#define OT_ID_PLAYER_ID 0
#define MON_GIVEN_TO_PARTY 0x0
#define MON_GIVEN_TO_PC 0x1
#define MON_CANT_GIVE 0x2
#define PLAYER_HAS_TWO_USABLE_MONS 0x0
#define PLAYER_HAS_ONE_MON 0x1
#define PLAYER_HAS_ONE_USABLE_MON 0x2
#define MON_MALE 0x00
#define MON_FEMALE 0xFE
#define MON_GENDERLESS 0xFF
@ -240,7 +248,8 @@ struct PokemonSubstruct3
/* 0x0B */ u32 giftRibbon5:1;
/* 0x0B */ u32 giftRibbon6:1;
/* 0x0B */ u32 giftRibbon7:1;
/* 0x0B */ u32 fatefulEncounter:5; // unused in Ruby/Sapphire, but the high bit must be set for Mew/Deoxys to obey in FR/LG/Emerald
/* 0x0B */ u32 fatefulEncounter:4;
/* 0x0B */ u32 obedient:1;
};
union PokemonSubstruct

View File

@ -74,6 +74,7 @@
#define EOS 0xFF // end of string
#define EXT_CTRL_CODE_JPN 0x15
#define EXT_CTRL_CODE_ENG 0x16
#define NUM_TEXT_PRINTERS 32

View File

@ -28,6 +28,7 @@
#define VAR_DAYS 0x4040
#define VAR_DEPT_STORE_FLOOR 0x4043
#define VAR_STORAGE_UNKNOWN 0x4036
#define VAR_POKELOT_PRIZE 0x4045
#define VAR_NATIONAL_DEX 0x4046
#define VAR_SEEDOT_SIZE_RECORD 0x4047

View File

@ -302,9 +302,10 @@ union PokemonSubstruct *GetSubstruct(struct BoxPokemon *boxMon, u32 personality,
extern u16 GetDeoxysStat(struct Pokemon *mon, s32 statId);
u32 GetMonData(struct Pokemon *mon, s32 field, u8 *data)
u32 GetMonData(struct Pokemon *mon, s32 field, u8* data)
{
u32 ret;
switch (field)
{
case MON_DATA_STATUS:
@ -368,3 +369,801 @@ u32 GetMonData(struct Pokemon *mon, s32 field, u8 *data)
}
return ret;
}
u32 GetBoxMonData(struct BoxPokemon *boxMon, s32 field, u8 *data)
{
s32 i;
u32 retVal = 0;
struct PokemonSubstruct0 *substruct0 = NULL;
struct PokemonSubstruct1 *substruct1 = NULL;
struct PokemonSubstruct2 *substruct2 = NULL;
struct PokemonSubstruct3 *substruct3 = NULL;
if (field > MON_DATA_10)
{
substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0);
substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1);
substruct2 = &(GetSubstruct(boxMon, boxMon->personality, 2)->type2);
substruct3 = &(GetSubstruct(boxMon, boxMon->personality, 3)->type3);
DecryptBoxMon(boxMon);
if (CalculateBoxMonChecksum(boxMon) != boxMon->checksum)
{
boxMon->isBadEgg = 1;
boxMon->isEgg = 1;
substruct3->isEgg = 1;
}
}
switch (field)
{
case MON_DATA_PERSONALITY:
retVal = boxMon->personality;
break;
case MON_DATA_OT_ID:
retVal = boxMon->otId;
break;
case MON_DATA_NICKNAME:
{
if (boxMon->isBadEgg)
{
for (retVal = 0;
retVal < POKEMON_NAME_LENGTH && gBadEggNickname[retVal] != EOS;
data[retVal] = gBadEggNickname[retVal], retVal++) {}
data[retVal] = EOS;
}
else if (boxMon->isEgg)
{
StringCopy(data, gEggNickname);
retVal = StringLength(data);
}
else if (boxMon->language == LANGUAGE_JAPANESE)
{
data[0] = EXT_CTRL_CODE_BEGIN;
data[1] = EXT_CTRL_CODE_JPN;
for (retVal = 2, i = 0;
i < 5 && boxMon->nickname[i] != EOS;
data[retVal] = boxMon->nickname[i], retVal++, i++) {}
data[retVal++] = EXT_CTRL_CODE_BEGIN;
data[retVal++] = EXT_CTRL_CODE_ENG;
data[retVal] = EOS;
}
else
{
for (retVal = 0;
retVal < POKEMON_NAME_LENGTH;
data[retVal] = boxMon->nickname[retVal], retVal++){}
data[retVal] = EOS;
}
break;
}
case MON_DATA_LANGUAGE:
retVal = boxMon->language;
break;
case MON_DATA_SANITY_BIT1:
retVal = boxMon->isBadEgg;
break;
case MON_DATA_SANITY_BIT2:
retVal = boxMon->hasSpecies;
break;
case MON_DATA_SANITY_BIT3:
retVal = boxMon->isEgg;
break;
case MON_DATA_OT_NAME:
{
retVal = 0;
while (retVal < OT_NAME_LENGTH)
{
data[retVal] = boxMon->otName[retVal];
retVal++;
}
data[retVal] = EOS;
break;
}
case MON_DATA_MARKINGS:
retVal = boxMon->markings;
break;
case MON_DATA_CHECKSUM:
retVal = boxMon->checksum;
break;
case MON_DATA_10:
retVal = boxMon->unknown;
break;
case MON_DATA_SPECIES:
retVal = boxMon->isBadEgg ? SPECIES_EGG : substruct0->species;
break;
case MON_DATA_HELD_ITEM:
retVal = substruct0->heldItem;
break;
case MON_DATA_EXP:
retVal = substruct0->experience;
break;
case MON_DATA_PP_BONUSES:
retVal = substruct0->ppBonuses;
break;
case MON_DATA_FRIENDSHIP:
retVal = substruct0->friendship;
break;
case MON_DATA_MOVE1:
case MON_DATA_MOVE2:
case MON_DATA_MOVE3:
case MON_DATA_MOVE4:
retVal = substruct1->moves[field - MON_DATA_MOVE1];
break;
case MON_DATA_PP1:
case MON_DATA_PP2:
case MON_DATA_PP3:
case MON_DATA_PP4:
retVal = substruct1->pp[field - MON_DATA_PP1];
break;
case MON_DATA_HP_EV:
retVal = substruct2->hpEV;
break;
case MON_DATA_ATK_EV:
retVal = substruct2->attackEV;
break;
case MON_DATA_DEF_EV:
retVal = substruct2->defenseEV;
break;
case MON_DATA_SPD_EV:
retVal = substruct2->speedEV;
break;
case MON_DATA_SPATK_EV:
retVal = substruct2->spAttackEV;
break;
case MON_DATA_SPDEF_EV:
retVal = substruct2->spDefenseEV;
break;
case MON_DATA_COOL:
retVal = substruct2->cool;
break;
case MON_DATA_BEAUTY:
retVal = substruct2->beauty;
break;
case MON_DATA_CUTE:
retVal = substruct2->cute;
break;
case MON_DATA_SMART:
retVal = substruct2->smart;
break;
case MON_DATA_TOUGH:
retVal = substruct2->tough;
break;
case MON_DATA_SHEEN:
retVal = substruct2->sheen;
break;
case MON_DATA_POKERUS:
retVal = substruct3->pokerus;
break;
case MON_DATA_MET_LOCATION:
retVal = substruct3->metLocation;
break;
case MON_DATA_MET_LEVEL:
retVal = substruct3->metLevel;
break;
case MON_DATA_MET_GAME:
retVal = substruct3->metGame;
break;
case MON_DATA_POKEBALL:
retVal = substruct3->pokeball;
break;
case MON_DATA_OT_GENDER:
retVal = substruct3->otGender;
break;
case MON_DATA_HP_IV:
retVal = substruct3->hpIV;
break;
case MON_DATA_ATK_IV:
retVal = substruct3->attackIV;
break;
case MON_DATA_DEF_IV:
retVal = substruct3->defenseIV;
break;
case MON_DATA_SPD_IV:
retVal = substruct3->speedIV;
break;
case MON_DATA_SPATK_IV:
retVal = substruct3->spAttackIV;
break;
case MON_DATA_SPDEF_IV:
retVal = substruct3->spDefenseIV;
break;
case MON_DATA_IS_EGG:
retVal = substruct3->isEgg;
break;
case MON_DATA_ALT_ABILITY:
retVal = substruct3->altAbility;
break;
case MON_DATA_COOL_RIBBON:
retVal = substruct3->coolRibbon;
break;
case MON_DATA_BEAUTY_RIBBON:
retVal = substruct3->beautyRibbon;
break;
case MON_DATA_CUTE_RIBBON:
retVal = substruct3->cuteRibbon;
break;
case MON_DATA_SMART_RIBBON:
retVal = substruct3->smartRibbon;
break;
case MON_DATA_TOUGH_RIBBON:
retVal = substruct3->toughRibbon;
break;
case MON_DATA_CHAMPION_RIBBON:
retVal = substruct3->championRibbon;
break;
case MON_DATA_WINNING_RIBBON:
retVal = substruct3->winningRibbon;
break;
case MON_DATA_VICTORY_RIBBON:
retVal = substruct3->victoryRibbon;
break;
case MON_DATA_ARTIST_RIBBON:
retVal = substruct3->artistRibbon;
break;
case MON_DATA_EFFORT_RIBBON:
retVal = substruct3->effortRibbon;
break;
case MON_DATA_GIFT_RIBBON_1:
retVal = substruct3->giftRibbon1;
break;
case MON_DATA_GIFT_RIBBON_2:
retVal = substruct3->giftRibbon2;
break;
case MON_DATA_GIFT_RIBBON_3:
retVal = substruct3->giftRibbon3;
break;
case MON_DATA_GIFT_RIBBON_4:
retVal = substruct3->giftRibbon4;
break;
case MON_DATA_GIFT_RIBBON_5:
retVal = substruct3->giftRibbon5;
break;
case MON_DATA_GIFT_RIBBON_6:
retVal = substruct3->giftRibbon6;
break;
case MON_DATA_GIFT_RIBBON_7:
retVal = substruct3->giftRibbon7;
break;
case MON_DATA_FATEFUL_ENCOUNTER:
retVal = substruct3->fatefulEncounter;
break;
case MON_DATA_OBEDIENCE:
retVal = substruct3->obedient;
break;
case MON_DATA_SPECIES2:
retVal = substruct0->species;
if (substruct0->species && (substruct3->isEgg || boxMon->isBadEgg))
retVal = SPECIES_EGG;
break;
case MON_DATA_IVS:
retVal = substruct3->hpIV | (substruct3->attackIV << 5) | (substruct3->defenseIV << 10) | (substruct3->speedIV << 15) | (substruct3->spAttackIV << 20) | (substruct3->spDefenseIV << 25);
break;
case MON_DATA_KNOWN_MOVES:
if (substruct0->species && !substruct3->isEgg)
{
u16 *moves = (u16 *)data;
s32 i = 0;
while (moves[i] != 355)
{
u16 move = moves[i];
if (substruct1->moves[0] == move
|| substruct1->moves[1] == move
|| substruct1->moves[2] == move
|| substruct1->moves[3] == move)
retVal |= gBitTable[i];
i++;
}
}
break;
case MON_DATA_RIBBON_COUNT:
retVal = 0;
if (substruct0->species && !substruct3->isEgg)
{
retVal += substruct3->coolRibbon;
retVal += substruct3->beautyRibbon;
retVal += substruct3->cuteRibbon;
retVal += substruct3->smartRibbon;
retVal += substruct3->toughRibbon;
retVal += substruct3->championRibbon;
retVal += substruct3->winningRibbon;
retVal += substruct3->victoryRibbon;
retVal += substruct3->artistRibbon;
retVal += substruct3->effortRibbon;
retVal += substruct3->giftRibbon1;
retVal += substruct3->giftRibbon2;
retVal += substruct3->giftRibbon3;
retVal += substruct3->giftRibbon4;
retVal += substruct3->giftRibbon5;
retVal += substruct3->giftRibbon6;
retVal += substruct3->giftRibbon7;
}
break;
case MON_DATA_RIBBONS:
retVal = 0;
if (substruct0->species && !substruct3->isEgg)
{
retVal = substruct3->championRibbon
| (substruct3->coolRibbon << 1)
| (substruct3->beautyRibbon << 4)
| (substruct3->cuteRibbon << 7)
| (substruct3->smartRibbon << 10)
| (substruct3->toughRibbon << 13)
| (substruct3->winningRibbon << 16)
| (substruct3->victoryRibbon << 17)
| (substruct3->artistRibbon << 18)
| (substruct3->effortRibbon << 19)
| (substruct3->giftRibbon1 << 20)
| (substruct3->giftRibbon2 << 21)
| (substruct3->giftRibbon3 << 22)
| (substruct3->giftRibbon4 << 23)
| (substruct3->giftRibbon5 << 24)
| (substruct3->giftRibbon6 << 25)
| (substruct3->giftRibbon7 << 26);
}
break;
default:
break;
}
if (field > MON_DATA_10)
EncryptBoxMon(boxMon);
return retVal;
}
#define SET8(lhs) (lhs) = *data
#define SET16(lhs) (lhs) = data[0] + (data[1] << 8)
#define SET32(lhs) (lhs) = data[0] + (data[1] << 8) + (data[2] << 16) + (data[3] << 24)
void SetMonData(struct Pokemon *mon, s32 field, const void *dataArg)
{
const u8* data = dataArg;
switch (field)
{
case MON_DATA_STATUS:
SET32(mon->status);
break;
case MON_DATA_LEVEL:
SET8(mon->level);
break;
case MON_DATA_HP:
SET16(mon->hp);
break;
case MON_DATA_MAX_HP:
SET16(mon->maxHP);
break;
case MON_DATA_ATK:
SET16(mon->attack);
break;
case MON_DATA_DEF:
SET16(mon->defense);
break;
case MON_DATA_SPD:
SET16(mon->speed);
break;
case MON_DATA_SPATK:
SET16(mon->spAttack);
break;
case MON_DATA_SPDEF:
SET16(mon->spDefense);
break;
case MON_DATA_MAIL:
SET8(mon->mail);
break;
case MON_DATA_SPECIES2:
break;
default:
SetBoxMonData(&mon->box, field, data);
break;
}
}
void SetBoxMonData(struct BoxPokemon *boxMon, s32 field, const void *dataArg)
{
const u8* data = dataArg;
struct PokemonSubstruct0 *substruct0 = NULL;
struct PokemonSubstruct1 *substruct1 = NULL;
struct PokemonSubstruct2 *substruct2 = NULL;
struct PokemonSubstruct3 *substruct3 = NULL;
if (field > MON_DATA_10)
{
substruct0 = &(GetSubstruct(boxMon, boxMon->personality, 0)->type0);
substruct1 = &(GetSubstruct(boxMon, boxMon->personality, 1)->type1);
substruct2 = &(GetSubstruct(boxMon, boxMon->personality, 2)->type2);
substruct3 = &(GetSubstruct(boxMon, boxMon->personality, 3)->type3);
DecryptBoxMon(boxMon);
if (CalculateBoxMonChecksum(boxMon) != boxMon->checksum)
{
boxMon->isBadEgg = 1;
boxMon->isEgg = 1;
substruct3->isEgg = 1;
EncryptBoxMon(boxMon);
return;
}
}
switch (field)
{
case MON_DATA_PERSONALITY:
SET32(boxMon->personality);
break;
case MON_DATA_OT_ID:
SET32(boxMon->otId);
break;
case MON_DATA_NICKNAME:
{
s32 i;
for (i = 0; i < POKEMON_NAME_LENGTH; i++)
boxMon->nickname[i] = data[i];
break;
}
case MON_DATA_LANGUAGE:
SET8(boxMon->language);
break;
case MON_DATA_SANITY_BIT1:
SET8(boxMon->isBadEgg);
break;
case MON_DATA_SANITY_BIT2:
SET8(boxMon->hasSpecies);
break;
case MON_DATA_SANITY_BIT3:
SET8(boxMon->isEgg);
break;
case MON_DATA_OT_NAME:
{
s32 i;
for (i = 0; i < OT_NAME_LENGTH; i++)
boxMon->otName[i] = data[i];
break;
}
case MON_DATA_MARKINGS:
SET8(boxMon->markings);
break;
case MON_DATA_CHECKSUM:
SET16(boxMon->checksum);
break;
case MON_DATA_10:
SET16(boxMon->unknown);
break;
case MON_DATA_SPECIES:
{
SET16(substruct0->species);
if (substruct0->species)
boxMon->hasSpecies = 1;
else
boxMon->hasSpecies = 0;
break;
}
case MON_DATA_HELD_ITEM:
SET16(substruct0->heldItem);
break;
case MON_DATA_EXP:
SET32(substruct0->experience);
break;
case MON_DATA_PP_BONUSES:
SET8(substruct0->ppBonuses);
break;
case MON_DATA_FRIENDSHIP:
SET8(substruct0->friendship);
break;
case MON_DATA_MOVE1:
case MON_DATA_MOVE2:
case MON_DATA_MOVE3:
case MON_DATA_MOVE4:
SET16(substruct1->moves[field - MON_DATA_MOVE1]);
break;
case MON_DATA_PP1:
case MON_DATA_PP2:
case MON_DATA_PP3:
case MON_DATA_PP4:
SET8(substruct1->pp[field - MON_DATA_PP1]);
break;
case MON_DATA_HP_EV:
SET8(substruct2->hpEV);
break;
case MON_DATA_ATK_EV:
SET8(substruct2->attackEV);
break;
case MON_DATA_DEF_EV:
SET8(substruct2->defenseEV);
break;
case MON_DATA_SPD_EV:
SET8(substruct2->speedEV);
break;
case MON_DATA_SPATK_EV:
SET8(substruct2->spAttackEV);
break;
case MON_DATA_SPDEF_EV:
SET8(substruct2->spDefenseEV);
break;
case MON_DATA_COOL:
SET8(substruct2->cool);
break;
case MON_DATA_BEAUTY:
SET8(substruct2->beauty);
break;
case MON_DATA_CUTE:
SET8(substruct2->cute);
break;
case MON_DATA_SMART:
SET8(substruct2->smart);
break;
case MON_DATA_TOUGH:
SET8(substruct2->tough);
break;
case MON_DATA_SHEEN:
SET8(substruct2->sheen);
break;
case MON_DATA_POKERUS:
SET8(substruct3->pokerus);
break;
case MON_DATA_MET_LOCATION:
SET8(substruct3->metLocation);
break;
case MON_DATA_MET_LEVEL:
{
u8 metLevel = *data;
substruct3->metLevel = metLevel;
break;
}
case MON_DATA_MET_GAME:
SET8(substruct3->metGame);
break;
case MON_DATA_POKEBALL:
{
u8 pokeball = *data;
substruct3->pokeball = pokeball;
break;
}
case MON_DATA_OT_GENDER:
SET8(substruct3->otGender);
break;
case MON_DATA_HP_IV:
SET8(substruct3->hpIV);
break;
case MON_DATA_ATK_IV:
SET8(substruct3->attackIV);
break;
case MON_DATA_DEF_IV:
SET8(substruct3->defenseIV);
break;
case MON_DATA_SPD_IV:
SET8(substruct3->speedIV);
break;
case MON_DATA_SPATK_IV:
SET8(substruct3->spAttackIV);
break;
case MON_DATA_SPDEF_IV:
SET8(substruct3->spDefenseIV);
break;
case MON_DATA_IS_EGG:
SET8(substruct3->isEgg);
if (substruct3->isEgg)
boxMon->isEgg = 1;
else
boxMon->isEgg = 0;
break;
case MON_DATA_ALT_ABILITY:
SET8(substruct3->altAbility);
break;
case MON_DATA_COOL_RIBBON:
SET8(substruct3->coolRibbon);
break;
case MON_DATA_BEAUTY_RIBBON:
SET8(substruct3->beautyRibbon);
break;
case MON_DATA_CUTE_RIBBON:
SET8(substruct3->cuteRibbon);
break;
case MON_DATA_SMART_RIBBON:
SET8(substruct3->smartRibbon);
break;
case MON_DATA_TOUGH_RIBBON:
SET8(substruct3->toughRibbon);
break;
case MON_DATA_CHAMPION_RIBBON:
SET8(substruct3->championRibbon);
break;
case MON_DATA_WINNING_RIBBON:
SET8(substruct3->winningRibbon);
break;
case MON_DATA_VICTORY_RIBBON:
SET8(substruct3->victoryRibbon);
break;
case MON_DATA_ARTIST_RIBBON:
SET8(substruct3->artistRibbon);
break;
case MON_DATA_EFFORT_RIBBON:
SET8(substruct3->effortRibbon);
break;
case MON_DATA_GIFT_RIBBON_1:
SET8(substruct3->giftRibbon1);
break;
case MON_DATA_GIFT_RIBBON_2:
SET8(substruct3->giftRibbon2);
break;
case MON_DATA_GIFT_RIBBON_3:
SET8(substruct3->giftRibbon3);
break;
case MON_DATA_GIFT_RIBBON_4:
SET8(substruct3->giftRibbon4);
break;
case MON_DATA_GIFT_RIBBON_5:
SET8(substruct3->giftRibbon5);
break;
case MON_DATA_GIFT_RIBBON_6:
SET8(substruct3->giftRibbon6);
break;
case MON_DATA_GIFT_RIBBON_7:
SET8(substruct3->giftRibbon7);
break;
case MON_DATA_FATEFUL_ENCOUNTER:
SET8(substruct3->fatefulEncounter);
break;
case MON_DATA_OBEDIENCE:
SET8(substruct3->obedient);
break;
case MON_DATA_IVS:
{
u32 ivs = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
substruct3->hpIV = ivs & 0x1F;
substruct3->attackIV = (ivs >> 5) & 0x1F;
substruct3->defenseIV = (ivs >> 10) & 0x1F;
substruct3->speedIV = (ivs >> 15) & 0x1F;
substruct3->spAttackIV = (ivs >> 20) & 0x1F;
substruct3->spDefenseIV = (ivs >> 25) & 0x1F;
break;
}
default:
break;
}
if (field > MON_DATA_10)
{
boxMon->checksum = CalculateBoxMonChecksum(boxMon);
EncryptBoxMon(boxMon);
}
}
void CopyMon(void *dest, void *src, size_t size)
{
memcpy(dest, src, size);
}
u8 GiveMonToPlayer(struct Pokemon *mon)
{
s32 i;
SetMonData(mon, MON_DATA_OT_NAME, gSaveBlock2Ptr->playerName);
SetMonData(mon, MON_DATA_OT_GENDER, &gSaveBlock2Ptr->playerGender);
SetMonData(mon, MON_DATA_OT_ID, gSaveBlock2Ptr->playerTrainerId);
i = 0;
while (i < 6 && GetMonData(&gPlayerParty[i], MON_DATA_SPECIES, NULL) != SPECIES_NONE)
i++;
if (i >= 6)
return SendMonToPC(mon);
CopyMon(&gPlayerParty[i], mon, sizeof(*mon));
gPlayerPartyCount = i + 1;
return MON_GIVEN_TO_PARTY;
}
extern u16 get_unknown_box_id(void);
extern u8 StorageGetCurrentBox(void);
extern void set_unknown_box_id(u8);
extern struct BoxPokemon* GetBoxedMonPtr(u8 boxNumber, u8 boxPosition);
u8 SendMonToPC(struct Pokemon* mon)
{
s32 boxNo, boxPos;
set_unknown_box_id(VarGet(VAR_STORAGE_UNKNOWN));
boxNo = StorageGetCurrentBox();
do
{
for (boxPos = 0; boxPos < 30; boxPos++)
{
struct BoxPokemon* checkingMon = GetBoxedMonPtr(boxNo, boxPos);
if (GetBoxMonData(checkingMon, MON_DATA_SPECIES, NULL) == SPECIES_NONE)
{
MonRestorePP(mon);
CopyMon(checkingMon, &mon->box, sizeof(mon->box));
gSpecialVar_0x8012 = boxNo;
gSpecialVar_0x8013 = boxPos;
if (get_unknown_box_id() != boxNo)
FlagReset(SYS_STORAGE_UNKNOWN_FLAG);
VarSet(VAR_STORAGE_UNKNOWN, boxNo);
return MON_GIVEN_TO_PC;
}
}
boxNo++;
if (boxNo == 14)
boxNo = 0;
} while (boxNo != StorageGetCurrentBox());
return MON_CANT_GIVE;
}
u8 CalculatePlayerPartyCount(void)
{
gPlayerPartyCount = 0;
while (gPlayerPartyCount < 6
&& GetMonData(&gPlayerParty[gPlayerPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE)
{
gPlayerPartyCount++;
}
return gPlayerPartyCount;
}
u8 CalculateEnemyPartyCount(void)
{
gEnemyPartyCount = 0;
while (gEnemyPartyCount < 6
&& GetMonData(&gEnemyParty[gEnemyPartyCount], MON_DATA_SPECIES, NULL) != SPECIES_NONE)
{
gEnemyPartyCount++;
}
return gEnemyPartyCount;
}
u8 GetMonsStateToDoubles(void)
{
s32 aliveCount = 0;
s32 i;
CalculatePlayerPartyCount();
if (gPlayerPartyCount == 1)
return gPlayerPartyCount; // PLAYER_HAS_ONE_MON
for (i = 0; i < gPlayerPartyCount; i++)
{
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_EGG
&& GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0
&& GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL) != SPECIES_NONE)
aliveCount++;
}
return (aliveCount > 1) ? PLAYER_HAS_TWO_USABLE_MONS : PLAYER_HAS_ONE_USABLE_MON;
}
u8 GetMonsStateToDoubles_2(void)
{
s32 aliveCount = 0;
s32 i;
for (i = 0; i < 6; i++)
{
u32 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2, NULL);
if (species != SPECIES_EGG && species != SPECIES_NONE
&& GetMonData(&gPlayerParty[i], MON_DATA_HP, NULL) != 0)
aliveCount++;
}
if (aliveCount == 1)
return PLAYER_HAS_ONE_MON; // may have more than one, but only one is alive
return (aliveCount > 1) ? PLAYER_HAS_TWO_USABLE_MONS : PLAYER_HAS_ONE_USABLE_MON;
}

View File

@ -550,7 +550,7 @@ sLearningMoveTableID: @ 20244E8
gPlayerPartyCount: @ 20244E9
.space 0x1
gUnknown_020244EA: @ 20244EA
gEnemyPartyCount: @ 20244EA
.space 0x2
gPlayerParty: @ 20244EC