mirror of
https://github.com/pret/pmd-red.git
synced 2026-07-06 20:05:15 -05:00
179 lines
4.7 KiB
C
179 lines
4.7 KiB
C
#include "global.h"
|
|
#include "memory.h"
|
|
#include "item.h"
|
|
#include "friend_area.h"
|
|
#include "constants/friend_area.h"
|
|
#include "sub_8095228.h"
|
|
#include "wonder_mail.h"
|
|
#include "constants/wonder_mail.h"
|
|
|
|
struct subStruct_203B490
|
|
{
|
|
// size: 0xC
|
|
u8 unk0;
|
|
u8 unk1;
|
|
u32 unk4;
|
|
u32 unk8;
|
|
};
|
|
|
|
|
|
struct unkStruct_203B490
|
|
{
|
|
// size: 0x330?
|
|
|
|
u8 fill0[0x190];
|
|
u8 unk190[0x28];
|
|
u8 unk1B8[0x78];
|
|
struct subStruct_203B490 unk230[16];
|
|
u8 unk2F0[0x38];
|
|
u8 unk328;
|
|
};
|
|
|
|
|
|
extern bool8 sub_809095C(u8);
|
|
extern s32 sub_8090298(u8);
|
|
extern bool8 sub_809017C(u8 *);
|
|
extern s16 GetBaseSpecies(s16);
|
|
extern bool8 IsInvalidItemReward(u8);
|
|
extern u8 sub_803C1D0(u8 *, u8);
|
|
extern bool8 IsNotMoneyOrUsedTMItem(u8);
|
|
extern u8 xxx_bit_lut_lookup_8091E50(u8 ,u8 );
|
|
extern u32 GetMaxItemCount(u8);
|
|
extern u8 sub_803C0DC(s16);
|
|
extern void sub_8096040(u8);
|
|
extern void sub_80965B8(u8);
|
|
extern void sub_8096C3C(u8);
|
|
extern bool8 ValidateWonderMail(struct WonderMail *);
|
|
|
|
extern struct unkStruct_203B490 *gUnknown_203B490;
|
|
extern struct unkStruct_203B490 gUnknown_2039448;
|
|
|
|
void sub_80958E8()
|
|
{
|
|
gUnknown_203B490 = &gUnknown_2039448;
|
|
}
|
|
|
|
struct unkStruct_203B490 *sub_80958F8(void)
|
|
{
|
|
return &gUnknown_2039448;
|
|
}
|
|
|
|
void sub_8095900(void)
|
|
{
|
|
s32 iVar2;
|
|
for(iVar2 = 0; iVar2 < 4; iVar2++)
|
|
{
|
|
sub_8096040(iVar2);
|
|
}
|
|
for(iVar2 = 0; iVar2 < 8; iVar2++)
|
|
{
|
|
sub_80965B8(iVar2);
|
|
}
|
|
for(iVar2 = 0; iVar2 < 8; iVar2++)
|
|
{
|
|
sub_8096C3C(iVar2);
|
|
}
|
|
for(iVar2 = 0; iVar2 < 0x38; iVar2++)
|
|
{
|
|
gUnknown_203B490->unk2F0[iVar2] = 0;
|
|
}
|
|
gUnknown_203B490->unk328 = 0;
|
|
MemoryClear8(gUnknown_203B490->unk190, sizeof(gUnknown_203B490->unk190));
|
|
MemoryClear8(gUnknown_203B490->unk1B8, sizeof(gUnknown_203B490->unk1B8));
|
|
for(iVar2 = 0; iVar2 < 16; iVar2++)
|
|
{
|
|
gUnknown_203B490->unk230[iVar2].unk0 = 99;
|
|
gUnknown_203B490->unk230[iVar2].unk1 = 1;
|
|
gUnknown_203B490->unk230[iVar2].unk4 = 0;
|
|
gUnknown_203B490->unk230[iVar2].unk8 = 0;
|
|
}
|
|
}
|
|
|
|
bool8 IsValidWonderMail(struct WonderMail *WonderMailData)
|
|
{
|
|
// Has to equal 5 for Wonder Mail
|
|
// https://web.archive.org/web/20080913124416/http://www.upokecenter.com/games/dungeon/guides/passwords.html
|
|
//
|
|
if(WonderMailData->mailType != WONDER_MAIL_TYPE_WONDER)
|
|
{
|
|
return FALSE;
|
|
}
|
|
else
|
|
{
|
|
return ValidateWonderMail(WonderMailData);
|
|
}
|
|
}
|
|
|
|
bool8 ValidateWonderMail(struct WonderMail *data)
|
|
{
|
|
|
|
if(data->missionType > WONDER_MAIL_MISSION_TYPE_DELIVER_ITEM)
|
|
return FALSE;
|
|
else
|
|
{
|
|
if(data->missionType == WONDER_MAIL_MISSION_TYPE_DELIVER_ITEM && GetMaxItemCount(data->dungeon) == 0)
|
|
return FALSE;
|
|
|
|
if(data->unk2 > 9)
|
|
return FALSE;
|
|
|
|
if(sub_809095C(data->dungeon))
|
|
return FALSE;
|
|
if(data->floor >= sub_8090298(data->dungeon))
|
|
return FALSE;
|
|
if(sub_809017C(&(data->dungeon)))
|
|
return FALSE;
|
|
|
|
if(data->clientSpecies == SPECIES_NONE)
|
|
return FALSE;
|
|
if(data->clientSpecies > SPECIES_RAYQUAZA_CUTSCENE)
|
|
return FALSE;
|
|
if(data->clientSpecies != GetBaseSpecies(data->clientSpecies))
|
|
return FALSE;
|
|
if(sub_803C0DC(data->clientSpecies) == 0)
|
|
return FALSE;
|
|
|
|
if(data->targetSpecies > SPECIES_RAYQUAZA_CUTSCENE)
|
|
return FALSE;
|
|
if(data->targetSpecies != GetBaseSpecies(data->targetSpecies))
|
|
return FALSE;
|
|
if(sub_803C0DC(data->targetSpecies) == 0)
|
|
return FALSE;
|
|
|
|
// Item Delivery/Finding
|
|
if((u8)(data->missionType - 1) > WONDER_MAIL_MISSION_TYPE_RESCUE_TARGET)
|
|
if(data->targetSpecies != data->clientSpecies)
|
|
return FALSE;
|
|
|
|
if(IsInvalidItemReward(data->targetItem))
|
|
return FALSE;
|
|
if(IsThrowableItem(data->targetItem))
|
|
return FALSE;
|
|
if(!IsNotMoneyOrUsedTMItem(data->targetItem))
|
|
return FALSE;
|
|
|
|
// Item finding
|
|
if(data->missionType == WONDER_MAIL_MISSION_TYPE_FIND_ITEM && xxx_bit_lut_lookup_8091E50(data->dungeon, data->targetItem) == 0)
|
|
return FALSE;
|
|
|
|
if(data->rewardType == BLANK_4 || data->rewardType == END_REWARDS || data->rewardType > END_REWARDS)
|
|
return FALSE;
|
|
|
|
if(IsInvalidItemReward(data->itemReward))
|
|
return FALSE;
|
|
|
|
// Friend Area Reward
|
|
if(data->friendAreaReward > FINAL_ISLAND)
|
|
return FALSE;
|
|
|
|
if(data->rewardType == FRIEND_AREA)
|
|
{
|
|
if(GetFriendAreaUnlockCondition(data->friendAreaReward) != UNLOCK_WONDER_MAIL)
|
|
return FALSE;
|
|
if(sub_803C1D0(&(data->dungeon), data->missionType) == 0)
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
}
|