summaryrefslogtreecommitdiff
path: root/src/pokemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pokemon.c')
-rw-r--r--src/pokemon.c61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/pokemon.c b/src/pokemon.c
index a0e655d1e..188624d6a 100644
--- a/src/pokemon.c
+++ b/src/pokemon.c
@@ -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, NULL};
+EWRAM_DATA struct Unknown_806F160_Struct *gUnknown_020249B4[2] = {NULL};
// const rom data
#include "data/battle_moves.h"
@@ -5746,29 +5746,25 @@ u8 GetTrainerEncounterMusicId(u16 trainerOpponentId)
u16 ModifyStatByNature(u8 nature, u16 n, u8 statIndex)
{
- u16 retVal;
// Dont modify HP, Accuracy, or Evasion by nature
if (statIndex <= STAT_HP || statIndex > NUM_NATURE_STATS)
{
- return n;
+ // Should just be "return n", but it wouldn't match without this.
+ u16 retVal = n;
+ retVal++;
+ retVal--;
+ return retVal;
}
switch (gNatureStatTable[nature][statIndex - 1])
{
case 1:
- retVal = n * 110;
- retVal /= 100;
- break;
+ return (u16)(n * 110) / 100; // NOTE: will overflow for n > 595 because the intermediate value is cast to u16 before the division. Fix by removing (u16) cast
case -1:
- retVal = n * 90;
- retVal /= 100;
- break;
- default:
- retVal = n;
- break;
+ return (u16)(n * 90) / 100; // NOTE: will overflow for n > 728, see above
}
- return retVal;
+ return n;
}
#define IS_LEAGUE_BATTLE \
@@ -6808,16 +6804,19 @@ static bool8 ShouldSkipFriendshipChange(void)
return FALSE;
}
-#define MAGIC_NUMBER 0xA3
+#define FORCE_SIGNED(x)(-(x * (-1)))
static void sub_806F160(struct Unknown_806F160_Struct* structPtr)
{
u16 i, j;
- for (i = 0; i < structPtr->field_0_0; i++)
+ for (i = 0; i < FORCE_SIGNED(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];
@@ -6827,7 +6826,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 < structPtr->field_0_0; i++)
+ for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++)
{
structPtr->templates[i] = gUnknown_08329F28;
for (j = 0; j < structPtr->field_1; j++)
@@ -6858,7 +6857,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->size = 1;
+ structPtr->field_3_0 = 1;
structPtr->field_3_1 = 2;
break;
case 0:
@@ -6866,12 +6865,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->size = 1;
+ structPtr->field_3_0 = 1;
structPtr->field_3_1 = 0;
break;
}
- structPtr->bytes = AllocZeroed(structPtr->size * 0x800 * 4 * structPtr->field_0_0);
+ structPtr->bytes = AllocZeroed(structPtr->field_3_0 * 0x800 * 4 * structPtr->field_0_0);
structPtr->byteArrays = AllocZeroed(structPtr->field_0_0 * 32);
if (structPtr->bytes == NULL || structPtr->byteArrays == NULL)
{
@@ -6879,8 +6878,8 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
}
else
{
- for (i = 0; i < structPtr->field_0_0; i++)
- structPtr->byteArrays[i] = structPtr->bytes + (structPtr->size * (i << 0xD));
+ for (i = 0; i < FORCE_SIGNED(structPtr->field_0_0); i++)
+ structPtr->byteArrays[i] = structPtr->bytes + (structPtr->field_3_0 * (i << 0xD));
}
structPtr->templates = AllocZeroed(sizeof(struct SpriteTemplate) * structPtr->field_0_0);
@@ -6899,8 +6898,8 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
case 2:
sub_806F1FC(structPtr);
break;
- case 1:
case 0:
+ case 1:
default:
sub_806F160(structPtr);
break;
@@ -6929,7 +6928,7 @@ struct Unknown_806F160_Struct *sub_806F2AC(u8 id, u8 arg1)
}
else
{
- structPtr->magic = MAGIC_NUMBER;
+ structPtr->magic = 0xA3;
gUnknown_020249B4[id] = structPtr;
}
@@ -6940,12 +6939,12 @@ void sub_806F47C(u8 id)
{
struct Unknown_806F160_Struct *structPtr;
- id &= 1;
+ id %= 2;
structPtr = gUnknown_020249B4[id];
if (structPtr == NULL)
return;
- if (structPtr->magic != MAGIC_NUMBER)
+ if (structPtr->magic != 0xA3)
{
memset(structPtr, 0, sizeof(struct Unknown_806F160_Struct));
}
@@ -6969,13 +6968,15 @@ void sub_806F47C(u8 id)
u8 *sub_806F4F8(u8 id, u8 arg1)
{
struct Unknown_806F160_Struct *structPtr = gUnknown_020249B4[id % 2];
- if (structPtr->magic != MAGIC_NUMBER)
+ if (structPtr->magic != 0xA3)
{
return NULL;
}
-
- if (arg1 >= structPtr->field_0_0)
- arg1 = 0;
+ else
+ {
+ if (arg1 >= FORCE_SIGNED(structPtr->field_0_0))
+ arg1 = 0;
- return structPtr->byteArrays[arg1];
+ return structPtr->byteArrays[arg1];
+ }
}