mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-11-16 19:47:35 +01:00
Merge pull request #1182 from PokeCodec/PokemonLogicFix
Fix more fakematches
This commit is contained in:
commit
d260943249
@ -123,12 +123,12 @@ struct Pokemon
|
||||
|
||||
struct Unknown_806F160_Struct
|
||||
{
|
||||
u8 field_0_0:4;
|
||||
u8 field_0_1:4;
|
||||
u8 field_1;
|
||||
u8 magic;
|
||||
u8 field_3_0:4;
|
||||
u8 field_3_1:4;
|
||||
u32 field_0_0:4;
|
||||
u32 field_0_1:4;
|
||||
u32 field_1:8;
|
||||
u16 magic:8;
|
||||
u32 size:4;
|
||||
u16 field_3_1:4;
|
||||
void *bytes;
|
||||
u8 **byteArrays;
|
||||
struct SpriteTemplate *templates;
|
||||
|
@ -7127,18 +7127,12 @@ static void Cmd_forcerandomswitch(void)
|
||||
s32 i;
|
||||
s32 battler1PartyId = 0;
|
||||
s32 battler2PartyId = 0;
|
||||
|
||||
#ifdef NONMATCHING
|
||||
s32 lastMonId = 0; // + 1
|
||||
#else
|
||||
register s32 lastMonId asm("r8") = 0; // + 1
|
||||
#endif // NONMATCHING
|
||||
|
||||
s32 firstMonId = 0;
|
||||
s32 monsCount = 0;
|
||||
s32 firstMonId;
|
||||
s32 lastMonId = 0; // + 1
|
||||
s32 monsCount;
|
||||
struct Pokemon* party = NULL;
|
||||
s32 validMons = 0;
|
||||
s32 minNeeded = 0;
|
||||
s32 minNeeded;
|
||||
|
||||
if ((gBattleTypeFlags & BATTLE_TYPE_TRAINER))
|
||||
{
|
||||
@ -7250,14 +7244,14 @@ static void Cmd_forcerandomswitch(void)
|
||||
{
|
||||
do
|
||||
{
|
||||
i = Random() % monsCount;
|
||||
i += firstMonId;
|
||||
}
|
||||
while (i == battler2PartyId
|
||||
|| i == battler1PartyId
|
||||
|| GetMonData(&party[i], MON_DATA_SPECIES) == SPECIES_NONE
|
||||
do
|
||||
{
|
||||
i = Random() % monsCount;
|
||||
i += firstMonId;
|
||||
} while (i == battler2PartyId || i == battler1PartyId);
|
||||
} while (GetMonData(&party[i], MON_DATA_SPECIES) == SPECIES_NONE
|
||||
|| GetMonData(&party[i], MON_DATA_IS_EGG) == TRUE
|
||||
|| GetMonData(&party[i], MON_DATA_HP) == 0);
|
||||
|| GetMonData(&party[i], MON_DATA_HP) == 0); // Should be one while loop, conjoined by an ||, but that doesn't match. Equivalent logic though
|
||||
}
|
||||
*(gBattleStruct->monToSwitchIntoId + gBattlerTarget) = i;
|
||||
|
||||
|
@ -1447,7 +1447,7 @@ u8 GetFrontierOpponentClass(u16 trainerId)
|
||||
}
|
||||
else if (trainerId == TRAINER_FRONTIER_BRAIN)
|
||||
{
|
||||
trainerClass = GetFrontierBrainTrainerClass();
|
||||
return GetFrontierBrainTrainerClass(); // This sticks out like a sore thumb, but this is the only other way that matches. Maybe it SHOULD be assigned to ret, or all early returns. I don't know.
|
||||
}
|
||||
else if (trainerId == TRAINER_STEVEN_PARTNER)
|
||||
{
|
||||
@ -1466,9 +1466,6 @@ u8 GetFrontierOpponentClass(u16 trainerId)
|
||||
else
|
||||
{
|
||||
trainerClass = gFacilityClassToTrainerClass[gSaveBlock2Ptr->frontier.towerRecords[trainerId - TRAINER_RECORD_MIXING_FRIEND].facilityClass];
|
||||
#ifndef NONMATCHING
|
||||
asm("");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1480,9 +1477,6 @@ u8 GetFrontierOpponentClass(u16 trainerId)
|
||||
else
|
||||
{
|
||||
trainerClass = gFacilityClassToTrainerClass[gApprentices[gSaveBlock2Ptr->apprentices[trainerId - TRAINER_RECORD_MIXING_APPRENTICE].id].facilityClass];
|
||||
#ifndef NONMATCHING
|
||||
asm("");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -245,46 +245,46 @@ static bool8 sub_8122A58(struct EasyChatPair *a, struct EasyChatPair *b, u8 c)
|
||||
{
|
||||
case 0:
|
||||
if (a->unk0_0 > b->unk0_0)
|
||||
return 1;
|
||||
return TRUE;
|
||||
if (a->unk0_0 < b->unk0_0)
|
||||
return 0;
|
||||
return FALSE;
|
||||
if (a->unk0_7 > b->unk0_7)
|
||||
return 1;
|
||||
return TRUE;
|
||||
if (a->unk0_7 < b->unk0_7)
|
||||
return 0;
|
||||
return FALSE;
|
||||
break;
|
||||
case 1:
|
||||
if (a->unk0_7 > b->unk0_7)
|
||||
return 1;
|
||||
return TRUE;
|
||||
if (a->unk0_7 < b->unk0_7)
|
||||
return 0;
|
||||
return FALSE;
|
||||
if (a->unk0_0 > b->unk0_0)
|
||||
return 1;
|
||||
return TRUE;
|
||||
if (a->unk0_0 < b->unk0_0)
|
||||
return 0;
|
||||
return FALSE;
|
||||
break;
|
||||
case 2:
|
||||
if (a->unk0_0 > b->unk0_0)
|
||||
return 1;
|
||||
return TRUE;
|
||||
if (a->unk0_0 < b->unk0_0)
|
||||
return 0;
|
||||
return FALSE;
|
||||
if (a->unk0_7 > b->unk0_7)
|
||||
return 1;
|
||||
return TRUE;
|
||||
if (a->unk0_7 < b->unk0_7)
|
||||
return 0;
|
||||
return FALSE;
|
||||
if (a->unk2 > b->unk2)
|
||||
return 1;
|
||||
return TRUE;
|
||||
if (a->unk2 < b->unk2)
|
||||
return 0;
|
||||
return FALSE;
|
||||
if (a->words[0] > b->words[0])
|
||||
return 1;
|
||||
return TRUE;
|
||||
if (a->words[0] < b->words[0])
|
||||
return 0;
|
||||
return FALSE;
|
||||
if (a->words[1] > b->words[1])
|
||||
return 1;
|
||||
return TRUE;
|
||||
if (a->words[1] < b->words[1])
|
||||
return 0;
|
||||
return 1;
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
return Random() & 1;
|
||||
}
|
||||
|
@ -5453,8 +5453,8 @@ static void PrintSearchParameterText(u8 taskId)
|
||||
const struct SearchOptionText *texts = sSearchOptions[gTasks[taskId].tMenuItem].texts;
|
||||
const u16 *cursorPos = &gTasks[taskId].data[sSearchOptions[gTasks[taskId].tMenuItem].taskDataCursorPos];
|
||||
const u16 *scrollOffset = &gTasks[taskId].data[sSearchOptions[gTasks[taskId].tMenuItem].taskDataScrollOffset];
|
||||
u16 i;
|
||||
u16 j;
|
||||
|
||||
u16 i, j;
|
||||
|
||||
ClearSearchParameterBoxText();
|
||||
|
||||
@ -5543,8 +5543,7 @@ static bool8 SearchParamCantScrollUp(u8 taskId)
|
||||
|
||||
if (lastOption > MAX_SEARCH_PARAM_CURSOR_POS && *scrollOffset != 0)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static bool8 SearchParamCantScrollDown(u8 taskId)
|
||||
@ -5555,8 +5554,7 @@ static bool8 SearchParamCantScrollDown(u8 taskId)
|
||||
|
||||
if (lastOption > MAX_SEARCH_PARAM_CURSOR_POS && *scrollOffset < lastOption - MAX_SEARCH_PARAM_CURSOR_POS)
|
||||
return FALSE;
|
||||
else
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#define sTaskId data[0]
|
||||
|
@ -70,7 +70,7 @@ EWRAM_DATA u8 gEnemyPartyCount = 0;
|
||||
EWRAM_DATA struct Pokemon gPlayerParty[PARTY_SIZE] = {0};
|
||||
EWRAM_DATA struct Pokemon gEnemyParty[PARTY_SIZE] = {0};
|
||||
EWRAM_DATA struct SpriteTemplate gMultiuseSpriteTemplate = {0};
|
||||
EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL};
|
||||
EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL, NULL};
|
||||
|
||||
// const rom data
|
||||
#include "data/battle_moves.h"
|
||||
@ -6808,19 +6808,16 @@ static bool8 ShouldSkipFriendshipChange(void)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#define FORCE_SIGNED(x)(-(x * (-1)))
|
||||
#define MAGIC_NUMBER 0xA3
|
||||
|
||||
static void sub_806F160(struct Unknown_806F160_Struct* structPtr)
|
||||
{
|
||||
u16 i, j;
|
||||
for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++)
|
||||
for (i = 0; i < structPtr->field_0_0; i++)
|
||||
{
|
||||
structPtr->templates[i] = gUnknown_08329D98[i];
|
||||
for (j = 0; j < structPtr->field_1; j++)
|
||||
{
|
||||
#ifndef NONMATCHING
|
||||
asm("");
|
||||
#endif
|
||||
structPtr->frameImages[i * structPtr->field_1 + j].data = &structPtr->byteArrays[i][j * 0x800];
|
||||
}
|
||||
structPtr->templates[i].images = &structPtr->frameImages[i * structPtr->field_1];
|
||||
@ -6830,7 +6827,7 @@ static void sub_806F160(struct Unknown_806F160_Struct* structPtr)
|
||||
static void sub_806F1FC(struct Unknown_806F160_Struct* structPtr)
|
||||
{
|
||||
u16 i, j;
|
||||
for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++)
|
||||
for (i = 0; i < structPtr->field_0_0; i++)
|
||||
{
|
||||
structPtr->templates[i] = gUnknown_08329F28;
|
||||
for (j = 0; j < structPtr->field_1; j++)
|
||||
@ -6861,7 +6858,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
|
||||
structPtr->field_0_0 = 7;
|
||||
structPtr->field_0_1 = 7;
|
||||
structPtr->field_1 = 4;
|
||||
structPtr->field_3_0 = 1;
|
||||
structPtr->size = 1;
|
||||
structPtr->field_3_1 = 2;
|
||||
break;
|
||||
case 0:
|
||||
@ -6869,12 +6866,12 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
|
||||
structPtr->field_0_0 = 4;
|
||||
structPtr->field_0_1 = 4;
|
||||
structPtr->field_1 = 4;
|
||||
structPtr->field_3_0 = 1;
|
||||
structPtr->size = 1;
|
||||
structPtr->field_3_1 = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
structPtr->bytes = AllocZeroed(structPtr->field_3_0 * 0x800 * 4 * structPtr->field_0_0);
|
||||
structPtr->bytes = AllocZeroed(structPtr->size * 0x800 * 4 * structPtr->field_0_0);
|
||||
structPtr->byteArrays = AllocZeroed(structPtr->field_0_0 * 32);
|
||||
if (structPtr->bytes == NULL || structPtr->byteArrays == NULL)
|
||||
{
|
||||
@ -6882,8 +6879,8 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++)
|
||||
structPtr->byteArrays[i] = structPtr->bytes + (structPtr->field_3_0 * (i << 0xD));
|
||||
for (i = 0; i < structPtr->field_0_0; i++)
|
||||
structPtr->byteArrays[i] = structPtr->bytes + (structPtr->size * (i << 0xD));
|
||||
}
|
||||
|
||||
structPtr->templates = AllocZeroed(sizeof(struct SpriteTemplate) * structPtr->field_0_0);
|
||||
@ -6902,8 +6899,8 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
|
||||
case 2:
|
||||
sub_806F1FC(structPtr);
|
||||
break;
|
||||
case 0:
|
||||
case 1:
|
||||
case 0:
|
||||
default:
|
||||
sub_806F160(structPtr);
|
||||
break;
|
||||
@ -6932,7 +6929,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
|
||||
}
|
||||
else
|
||||
{
|
||||
structPtr->magic = 0xA3;
|
||||
structPtr->magic = MAGIC_NUMBER;
|
||||
gUnknown_020249B4[id] = structPtr;
|
||||
}
|
||||
|
||||
@ -6943,12 +6940,12 @@ void sub_806F47C(u8 id)
|
||||
{
|
||||
struct Unknown_806F160_Struct *structPtr;
|
||||
|
||||
id %= 2;
|
||||
id &= 1;
|
||||
structPtr = gUnknown_020249B4[id];
|
||||
if (structPtr == NULL)
|
||||
return;
|
||||
|
||||
if (structPtr->magic != 0xA3)
|
||||
if (structPtr->magic != MAGIC_NUMBER)
|
||||
{
|
||||
memset(structPtr, 0, sizeof(struct Unknown_806F160_Struct));
|
||||
}
|
||||
@ -6972,15 +6969,13 @@ void sub_806F47C(u8 id)
|
||||
u8 *sub_806F4F8(u8 id, u8 arg1)
|
||||
{
|
||||
struct Unknown_806F160_Struct *structPtr = gUnknown_020249B4[id % 2];
|
||||
if (structPtr->magic != 0xA3)
|
||||
if (structPtr->magic != MAGIC_NUMBER)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (arg1 >= FORCE_SIGNED(structPtr->field_0_0))
|
||||
arg1 = 0;
|
||||
|
||||
if (arg1 >= structPtr->field_0_0)
|
||||
arg1 = 0;
|
||||
|
||||
return structPtr->byteArrays[arg1];
|
||||
}
|
||||
return structPtr->byteArrays[arg1];
|
||||
}
|
||||
|
@ -2884,13 +2884,10 @@ static void sub_8181C2C(struct Sprite *sprite)
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifndef NONMATCHING
|
||||
register s32 var asm("r4") = sUnknown_03001240[sprite->data[0]].field_8;
|
||||
#else
|
||||
s32 var = sUnknown_03001240[sprite->data[0]].field_8;
|
||||
#endif
|
||||
|
||||
sprite->pos2.x = (var << 3) * (counter % 128) / 128 - (sUnknown_03001240[sprite->data[0]].field_8 * 8);
|
||||
const s16 var = sUnknown_03001240[sprite->data[0]].field_8;
|
||||
|
||||
sprite->pos2.x = var * ((counter % 128) * 8) / 128 + 8 * -var; //Should be - 8 * var instead of + 8 * -var, but that doesn't match
|
||||
sprite->pos2.y = -(Sin(counter % 128, 8));
|
||||
}
|
||||
|
||||
|
@ -713,17 +713,18 @@ static u8 sub_80E7A9C(struct DayCareMail *rmMail)
|
||||
return rmMail->message.itemId;
|
||||
}
|
||||
|
||||
static void sub_80E7AA4(struct RecordMixingDayCareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1)
|
||||
static void ExchangeMail(struct RecordMixingDayCareMail *src, size_t recordSize, u8 (*idxs)[2], u8 which0, u8 which1)
|
||||
{
|
||||
struct DayCareMail buffer;
|
||||
struct RecordMixingDayCareMail *mail1;
|
||||
struct RecordMixingDayCareMail *mail2;
|
||||
|
||||
mail1 = (void *)src + recordSize * idxs[which0][0];
|
||||
memcpy(&buffer, &mail1->mail[idxs[which0][1]], sizeof(struct DayCareMail));
|
||||
buffer = mail1->mail[idxs[which0][1]];
|
||||
|
||||
mail2 = (void *)src + recordSize * idxs[which1][0];
|
||||
memcpy(&mail1->mail[idxs[which0][1]], &mail2->mail[idxs[which1][1]], sizeof(struct DayCareMail));
|
||||
memcpy(&mail2->mail[idxs[which1][1]], &buffer, sizeof(struct DayCareMail));
|
||||
mail1->mail[idxs[which0][1]] = mail2->mail[idxs[which1][1]];
|
||||
mail2->mail[idxs[which1][1]] = buffer;
|
||||
}
|
||||
|
||||
static void sub_80E7B2C(const u8 *src)
|
||||
@ -865,28 +866,23 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r
|
||||
}
|
||||
else if (sp1c[i][0] == TRUE && sp1c[i][1] == TRUE)
|
||||
{
|
||||
u32 var1, var2;
|
||||
u8 mail1, mail2;
|
||||
|
||||
sp24[j][0] = i;
|
||||
var1 = sub_80E7A9C(&_src->mail[0]);
|
||||
var2 = sub_80E7A9C(&_src->mail[1]);
|
||||
if (!var1 && var2)
|
||||
mail1 = sub_80E7A9C(&_src->mail[0]);
|
||||
mail2 = sub_80E7A9C(&_src->mail[1]);
|
||||
if (!(mail1 || mail2) || (mail1 && mail2)) //Logical (not bitwise) XOR. Should be ((mail1 || mail2) && !(mail1 && mail2)), but that doesn't match.
|
||||
{
|
||||
#ifndef NONMATCHING
|
||||
register u8 one asm("r0") = 1; // boo, a fakematch
|
||||
sp24[j][1] = one;
|
||||
#else
|
||||
sp24[j][1] = 1;
|
||||
#endif
|
||||
sp24[j][1] = Random2() % 2;
|
||||
}
|
||||
else if ((var1 && var2) || (!var1 && !var2))
|
||||
{
|
||||
sp24[j][1] = Random2() % 2;
|
||||
}
|
||||
else if (var1 && !var2)
|
||||
else if (mail1 && !mail2)
|
||||
{
|
||||
sp24[j][1] = 0;
|
||||
}
|
||||
else if (!mail1 && mail2)
|
||||
{
|
||||
sp24[j][1] = 1;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
}
|
||||
@ -901,27 +897,27 @@ static void ReceiveDaycareMailData(struct RecordMixingDayCareMail *src, size_t r
|
||||
switch (sp34)
|
||||
{
|
||||
case 2:
|
||||
sub_80E7AA4(src, recordSize, sp24, 0, 1);
|
||||
ExchangeMail(src, recordSize, sp24, 0, 1);
|
||||
break;
|
||||
case 3:
|
||||
which0 = gUnknown_0858CFB8[tableId][0];
|
||||
which1 = gUnknown_0858CFB8[tableId][1];
|
||||
sub_80E7AA4(src, recordSize, sp24, which0, which1);
|
||||
ExchangeMail(src, recordSize, sp24, which0, which1);
|
||||
break;
|
||||
case 4:
|
||||
ptr = sp24;
|
||||
which0 = gUnknown_0858CFBE[tableId][0];
|
||||
which1 = gUnknown_0858CFBE[tableId][1];
|
||||
sub_80E7AA4(src, recordSize, ptr, which0, which1);
|
||||
ExchangeMail(src, recordSize, ptr, which0, which1);
|
||||
which0 = gUnknown_0858CFBE[tableId][2];
|
||||
which1 = gUnknown_0858CFBE[tableId][3];
|
||||
sub_80E7AA4(src, recordSize, ptr, which0, which1);
|
||||
ExchangeMail(src, recordSize, ptr, which0, which1);
|
||||
break;
|
||||
}
|
||||
|
||||
_src = (void *)src + which * recordSize;
|
||||
memcpy(&gSaveBlock1Ptr->daycare.mons[0].mail, &_src->mail[0], sizeof(struct DayCareMail));
|
||||
memcpy(&gSaveBlock1Ptr->daycare.mons[1].mail, &_src->mail[1], sizeof(struct DayCareMail));
|
||||
gSaveBlock1Ptr->daycare.mons[0].mail = _src->mail[0];
|
||||
gSaveBlock1Ptr->daycare.mons[1].mail = _src->mail[1];
|
||||
SeedRng(oldSeed);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user