diff --git a/asm/code_807E5AC.s b/asm/code_807E5AC.s index 91304f75e..814e560e5 100644 --- a/asm/code_807E5AC.s +++ b/asm/code_807E5AC.s @@ -5,313 +5,8 @@ .text - thumb_func_start sub_807E698 -sub_807E698: - push {r4-r7,lr} - mov r7, r10 - mov r6, r9 - mov r5, r8 - push {r5-r7} - sub sp, 0xC - lsls r0, 24 - lsrs r0, 24 - str r0, [sp] - movs r0, 0 - bl GetApparentWeather - lsls r0, 24 - lsrs r0, 16 - str r0, [sp, 0x4] - ldr r0, _0807E724 - ldr r0, [r0] - ldr r0, [r0, 0x4] - mov r10, r0 - movs r0, 0 - bl GetApparentWeather - lsls r0, 24 - lsrs r0, 24 - ldr r1, [sp] - bl sub_8042818 - movs r0, 0x25 - bl sub_803E46C - movs r0, 0x1 - bl sub_804178C - ldr r1, _0807E728 - ldrb r0, [r1] - str r0, [sp, 0x8] - movs r0, 0x1 - strb r0, [r1] - movs r1, 0 - mov r9, r1 - ldr r2, _0807E72C - mov r8, r2 -_0807E6EC: - movs r7, 0 - movs r0, 0x25 - bl sub_803E46C - movs r6, 0 - ldr r1, [sp, 0x4] - lsls r0, r1, 2 - mov r2, r10 - adds r5, r0, r2 - movs r0, 0xFF - mov r12, r0 -_0807E702: - mov r1, r8 - ldr r0, [r1] - adds r0, r6 - movs r2, 0xBE - lsls r2, 1 - adds r4, r0, r2 - ldrb r0, [r4] - ldrb r3, [r5] - subs r1, r0, r3 - cmp r1, 0 - bge _0807E71A - negs r1, r1 -_0807E71A: - cmp r1, 0x9 - bgt _0807E730 - strb r3, [r4] - b _0807E746 - .align 2, 0 -_0807E724: .4byte gUnknown_202ECA0 -_0807E728: .4byte gUnknown_203B40D -_0807E72C: .4byte gDungeon -_0807E730: - movs r7, 0x1 - adds r2, r0, 0 - adds r1, r3, 0 - cmp r2, r1 - bcs _0807E73E - adds r0, 0xA - b _0807E744 -_0807E73E: - cmp r2, r1 - bls _0807E746 - subs r0, 0xA -_0807E744: - strb r0, [r4] -_0807E746: - mov r1, r8 - ldr r0, [r1] - adds r0, r6 - ldr r2, _0807E764 - adds r4, r0, r2 - ldrb r0, [r4] - ldrb r3, [r5, 0x1] - subs r1, r0, r3 - cmp r1, 0 - bge _0807E75C - negs r1, r1 -_0807E75C: - cmp r1, 0x9 - bgt _0807E768 - strb r3, [r4] - b _0807E77E - .align 2, 0 -_0807E764: .4byte 0x0000017d -_0807E768: - movs r7, 0x1 - adds r2, r0, 0 - adds r1, r3, 0 - cmp r2, r1 - bcs _0807E776 - adds r0, 0xA - b _0807E77C -_0807E776: - cmp r2, r1 - bls _0807E77E - subs r0, 0xA -_0807E77C: - strb r0, [r4] -_0807E77E: - mov r1, r8 - ldr r0, [r1] - adds r0, r6 - movs r2, 0xBF - lsls r2, 1 - adds r4, r0, r2 - ldrb r0, [r4] - ldrb r3, [r5, 0x2] - subs r1, r0, r3 - cmp r1, 0 - bge _0807E796 - negs r1, r1 -_0807E796: - cmp r1, 0x9 - bgt _0807E79E - strb r3, [r4] - b _0807E7B4 -_0807E79E: - movs r7, 0x1 - adds r2, r0, 0 - adds r1, r3, 0 - cmp r2, r1 - bcs _0807E7AC - adds r0, 0xA - b _0807E7B2 -_0807E7AC: - cmp r2, r1 - bls _0807E7B4 - subs r0, 0xA -_0807E7B2: - strb r0, [r4] -_0807E7B4: - adds r6, 0x4 - adds r5, 0x4 - movs r0, 0x1 - negs r0, r0 - add r12, r0 - mov r1, r12 - cmp r1, 0 - bge _0807E702 - movs r0, 0 - movs r1, 0 - bl sub_803E874 - cmp r7, 0 - beq _0807E7DA - movs r2, 0x1 - add r9, r2 - mov r0, r9 - cmp r0, 0x3F - ble _0807E6EC -_0807E7DA: - ldr r0, _0807E7F8 - mov r1, sp - ldrb r1, [r1, 0x8] - strb r1, [r0] - ldr r0, [sp] - bl sub_807E7FC - add sp, 0xC - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0807E7F8: .4byte gUnknown_203B40D - thumb_func_end sub_807E698 - thumb_func_start sub_807E7FC -sub_807E7FC: - push {r4-r6,lr} - lsls r0, 24 - lsrs r4, r0, 24 - ldr r6, _0807E874 - ldr r0, [r6] - ldr r1, _0807E878 - adds r0, r1 - ldr r5, [r0] - cmp r5, 0 - bne _0807E816 - bl GetLeader - adds r5, r0, 0 -_0807E816: - cmp r4, 0 - beq _0807E844 - ldr r0, [r6] - ldr r2, _0807E87C - adds r0, r2 - ldrb r0, [r0] - cmp r0, 0 - bne _0807E844 - ldr r4, _0807E880 - movs r0, 0 - bl GetApparentWeather - adds r1, r0, 0 - lsls r1, 24 - lsrs r1, 24 - adds r0, r4, 0 - bl GetWeatherName - ldr r0, _0807E884 - ldr r1, [r0] - adds r0, r5, 0 - bl LogMessageByIdWithPopupCheckUser -_0807E844: - movs r5, 0 -_0807E846: - ldr r0, _0807E874 - ldr r0, [r0] - lsls r1, r5, 2 - ldr r2, _0807E888 - adds r0, r2 - adds r0, r1 - ldr r4, [r0] - adds r0, r4, 0 - bl EntityExists - lsls r0, 24 - cmp r0, 0 - beq _0807E866 - adds r0, r4, 0 - bl sub_807E8F0 -_0807E866: - adds r5, 0x1 - cmp r5, 0x13 - ble _0807E846 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_0807E874: .4byte gDungeon -_0807E878: .4byte 0x000181f8 -_0807E87C: .4byte 0x0001356c -_0807E880: .4byte gFormatBuffer_Monsters -_0807E884: .4byte gUnknown_80FC5E0 -_0807E888: .4byte 0x000135cc - thumb_func_end sub_807E7FC - thumb_func_start sub_807E88C -sub_807E88C: - push {r4-r7,lr} - movs r0, 0 - bl GetApparentWeather - lsls r0, 24 - ldr r1, _0807E8E4 - ldr r1, [r1] - ldr r1, [r1, 0x4] - movs r4, 0 - ldr r5, _0807E8E8 - lsrs r0, 14 - adds r3, r0, r1 - movs r6, 0xBE - lsls r6, 1 -_0807E8A8: - ldr r0, [r5] - lsls r2, r4, 2 - adds r0, r2 - ldrb r1, [r3] - adds r0, r6 - strb r1, [r0] - ldr r0, [r5] - adds r0, r2 - ldrb r1, [r3, 0x1] - ldr r7, _0807E8EC - adds r0, r7 - strb r1, [r0] - ldr r0, [r5] - adds r0, r2 - ldrb r1, [r3, 0x2] - movs r2, 0xBF - lsls r2, 1 - adds r0, r2 - strb r1, [r0] - adds r3, 0x4 - adds r4, 0x1 - cmp r4, 0xFF - ble _0807E8A8 - movs r0, 0 - movs r1, 0 - bl sub_803E874 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0807E8E4: .4byte gUnknown_202ECA0 -_0807E8E8: .4byte gDungeon -_0807E8EC: .4byte 0x0000017d - thumb_func_end sub_807E88C thumb_func_start sub_807E8F0 sub_807E8F0: @@ -363,7 +58,7 @@ _0807E90E: strb r1, [r7] b _0807E984 .align 2, 0 -_0807E954: .4byte gUnknown_80F520C +_0807E954: .4byte gCastformByWeather _0807E958: adds r0, r4, 0 adds r0, 0xC4 diff --git a/data/data_80F4E2C.s b/data/data_80F4E2C.s index a95b7e466..d7a7917c0 100644 --- a/data/data_80F4E2C.s +++ b/data/data_80F4E2C.s @@ -809,8 +809,8 @@ gUnknown_80F51EC: @ 80F51EC .4byte 512 .4byte 512 - .global gUnknown_80F520C -gUnknown_80F520C: @ 80F520C + .global gCastformByWeather +gCastformByWeather: @ 80F520C @ replacing .incbin "baserom.gba", 0x000f520c, 0x20 .byte 0x01, 0x00, 0x78, 0x01 .byte 0x02, 0x00, 0x7a, 0x01 diff --git a/include/constants/weather.h b/include/constants/weather.h index 2a8cf42ee..688e1100a 100644 --- a/include/constants/weather.h +++ b/include/constants/weather.h @@ -9,6 +9,6 @@ #define WEATHER_HAIL 5 #define WEATHER_FOG 6 #define WEATHER_SNOW 7 -#define WEATHER_RANDOM 8 +#define WEATHER_COUNT 8 #endif // GUARD_CONSTANTS_WEATHER_H diff --git a/include/structs/str_dungeon.h b/include/structs/str_dungeon.h index 3ecb838a3..c751ce3a0 100644 --- a/include/structs/str_dungeon.h +++ b/include/structs/str_dungeon.h @@ -328,6 +328,8 @@ typedef struct unkDungeon57C s32 unk40; } unkDungeon57C; +#define COLOR_RAMP_COUNT 256 + // size: 0x1CEDC typedef struct Dungeon { @@ -357,7 +359,7 @@ typedef struct Dungeon Entity *unkBC; u8 fillC0[0x134 - 0xC0]; struct unkStruct_Dungeon134_sub unk134; - /* 0x47C */ RGB colorRamp[0x100]; + /* 0x17C */ RGB colorRamp[COLOR_RAMP_COUNT]; /* 0x57C */ unkDungeon57C unk57C; /* 0x5C0 */ s32 unk5C0; /* 0x5C4 */ struct unkStruct_Dungeon5C4_sub unk5C4[3]; diff --git a/ld_script.txt b/ld_script.txt index 5d27fce8b..5b6924e3c 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -266,6 +266,7 @@ SECTIONS { src/code_807CD9C.o(.text); src/code_807E1A0.o(.text); src/weather.o(.text); + src/code_807E5AC.o(.text); asm/code_807E5AC.o(.text); src/trap.o(.text); asm/code_807FCD4.o(.text); diff --git a/src/code_8069E0C.c b/src/code_8069E0C.c index ffe3ae31e..ebfa049f4 100644 --- a/src/code_8069E0C.c +++ b/src/code_8069E0C.c @@ -41,15 +41,13 @@ #include "structs/str_806B7F8.h" #include "structs/str_202ED28.h" -struct unkStruct_80F520C +struct CastformWeatherData { - u8 unk0; // types0 - u8 unk1; // Most likely just padding and should be removed - s16 unk2; // monsterID + u8 type; + s16 monsterId; }; -// Castform Forecast ability data -extern const struct unkStruct_80F520C gUnknown_80F520C[WEATHER_RANDOM]; +extern const struct CastformWeatherData gCastformByWeather[WEATHER_COUNT]; extern u8 gUnknown_80F51E4[]; extern u8 *gUnknown_80FCC7C[]; @@ -109,7 +107,7 @@ void sub_8069E0C(Entity *pokemon) entityInfo = GetEntInfo(pokemon); if (AbilityIsActive(pokemon, ABILITY_FORECAST)) { - entityInfo->types[0] = gUnknown_80F520C[GetApparentWeather(pokemon)].unk0; + entityInfo->types[0] = gCastformByWeather[GetApparentWeather(pokemon)].type; entityInfo->types[1] = TYPE_NONE; } else { @@ -156,7 +154,7 @@ s32 GetMonsterApparentID(Entity *pokemon, s32 _id) s16 id = (s16)(_id); if (id == MONSTER_CASTFORM || IS_CASTFORM_FORM_MONSTER(id)) { if (AbilityIsActive(pokemon, ABILITY_FORECAST)) - return gUnknown_80F520C[GetApparentWeather(pokemon)].unk2; + return gCastformByWeather[GetApparentWeather(pokemon)].monsterId; return MONSTER_CASTFORM; } @@ -1863,7 +1861,7 @@ void ResetMonEntityData(EntityInfo *entInfo, bool8 setStatsToOne) } if (hasForecast) { - entInfo->types[0] = gUnknown_80F520C[GetApparentWeather(NULL)].unk0; + entInfo->types[0] = gCastformByWeather[GetApparentWeather(NULL)].type; entInfo->types[1] = TYPE_NONE; } else { diff --git a/src/code_807E5AC.c b/src/code_807E5AC.c new file mode 100644 index 000000000..a4d3d5627 --- /dev/null +++ b/src/code_807E5AC.c @@ -0,0 +1,177 @@ +#include "global.h" +#include "weather.h" +#include "code_804267C.h" +#include "code_803E46C.h" +#include "dungeon.h" +#include "dungeon_leader.h" +#include "dungeon_util.h" +#include "dungeon_message.h" +#include "string_format.h" + +extern u8 gUnknown_203B40D; +extern OpenedFile *gUnknown_202ECA0; +extern void sub_804178C(u32); + +void sub_803E874(bool8 r10, s32 r9); +void GetWeatherName(u8 *dst, u8 weatherId); + +void sub_807E7FC(bool8 arg0); +void sub_807E8F0(Entity *pokemon); + +extern const u8 *const gUnknown_80FC5E0; + +// Note: gUnknown_202ECA0 file's 2d array is read as 1d array in functions below, be careful! +void sub_807E698(bool8 arg0) +{ + s32 i, j; + s32 weatherArrId = GetApparentWeather(NULL) * COLOR_RAMP_COUNT; + RGB *fileData = (void *) gUnknown_202ECA0->data; + u8 savedByte; + + sub_8042818(GetApparentWeather(NULL), arg0); + sub_803E46C(0x25); + sub_804178C(1); + savedByte = gUnknown_203B40D; + gUnknown_203B40D = 1; + + for (i = 0; i < 64; i++) { + bool8 r7 = FALSE; + + sub_803E46C(0x25); + for (j = 0; j < COLOR_RAMP_COUNT; j++) { + if (abs(gDungeon->colorRamp[j].r - fileData[weatherArrId + j].r) < 10) { + gDungeon->colorRamp[j].r = fileData[weatherArrId + j].r; + } + else { + r7 = TRUE; + if (gDungeon->colorRamp[j].r < fileData[weatherArrId + j].r) { + gDungeon->colorRamp[j].r += 10; + } + else if (gDungeon->colorRamp[j].r > fileData[weatherArrId + j].r) { + gDungeon->colorRamp[j].r -= 10; + } + } + + if (abs(gDungeon->colorRamp[j].g - fileData[weatherArrId + j].g) < 10) { + gDungeon->colorRamp[j].g = fileData[weatherArrId + j].g; + } + else { + r7 = TRUE; + if (gDungeon->colorRamp[j].g < fileData[weatherArrId + j].g) { + gDungeon->colorRamp[j].g += 10; + } + else if (gDungeon->colorRamp[j].g > fileData[weatherArrId + j].g) { + gDungeon->colorRamp[j].g -= 10; + } + } + + if (abs(gDungeon->colorRamp[j].b - fileData[weatherArrId + j].b) < 10) { + gDungeon->colorRamp[j].b = fileData[weatherArrId + j].b; + } + else { + r7 = TRUE; + if (gDungeon->colorRamp[j].b < fileData[weatherArrId + j].b) { + gDungeon->colorRamp[j].b += 10; + } + else if (gDungeon->colorRamp[j].b > fileData[weatherArrId + j].b) { + gDungeon->colorRamp[j].b -= 10; + } + } + } + + sub_803E874(FALSE, 0); + if (!r7) + break; + } + + gUnknown_203B40D = savedByte; + sub_807E7FC(arg0); +} + +void sub_807E7FC(bool8 r0) +{ + s32 i; + + Entity *cameraTarget = gDungeon->unk181e8.cameraTarget; + if (cameraTarget == NULL) { + cameraTarget = GetLeader(); + } + + if (r0) { + if (gDungeon->unk1356C == 0) { + GetWeatherName(gFormatBuffer_Monsters[0], GetApparentWeather(NULL)); + LogMessageByIdWithPopupCheckUser(cameraTarget, gUnknown_80FC5E0); // Weather: {ARG_POKEMON_0} + } + } + + for (i = 0; i < DUNGEON_MAX_POKEMON; i++) { + Entity *pokemon = gDungeon->activePokemon[i]; + if (EntityExists(pokemon)) { + sub_807E8F0(pokemon); + } + } +} + +void sub_807E88C(void) +{ + s32 i; + s32 weatherArrId = GetApparentWeather(0) * COLOR_RAMP_COUNT; + RGB *fileData = (void *) gUnknown_202ECA0->data; + + for (i = 0; i < COLOR_RAMP_COUNT; i++) { + gDungeon->colorRamp[i].r = fileData[weatherArrId + i].r; + gDungeon->colorRamp[i].g = fileData[weatherArrId + i].g; + gDungeon->colorRamp[i].b = fileData[weatherArrId + i].b; + } + + sub_803E874(0, 0); +} + +/* +void sub_807E8F0(Entity *pokemon) +{ + u8 oldTypes[2]; + u8 uVar4; + OpenedFile *sprite; + bool8 flag = FALSE; + + if (EntityExists(pokemon)) { + EntityInfo *info = GetEntInfo(pokemon); + s32 apparentID = info->apparentID; + oldTypes[0] = info->types[0]; + oldTypes[1] = info->types[1]; + CalcSpeedStage(pokemon); + if (HasAbility(pokemon, ABILITY_FORECAST)) { + info->types[0] = (gUnknown_80F520C)[GetApparentWeather(pokemon) << 2]; + info->types[1] = TYPE_NONE; + } + else { + if ((info->protectionStatus != 0xC) && (info->isColorChanged == FALSE)) { + info->types[0] = GetPokemonType(info->id, 0); + info->types[1] = GetPokemonType(info->id, 1); + } + } + if ((oldTypes[0] != info->types[0]) || (oldTypes[1] != info->types[1])) { + flag = TRUE; + } + if ((u16)(info->id - 0x178U) < 4) { + if (HasAbility(pokemon, ABILITY_FORECAST)) { + info->apparentID = sub_8069F54(pokemon, info->id); + } + else { + info->apparentID = 0x178; + } + if (info->apparentID != apparentID) { + sprite = sub_80687D0(); + pokemon->sprite = sprite; + uVar4 = sub_806CEBC(pokemon); + sub_806CCB4(pokemon,uVar4); + flag = TRUE; + } + } + if (flag) { + sub_80429D8(pokemon); + } + } +} +*/ diff --git a/src/weather.c b/src/weather.c index 3293f369f..1a5976f7f 100644 --- a/src/weather.c +++ b/src/weather.c @@ -25,8 +25,8 @@ void sub_807E5AC(void) { u8 weather; weather = gDungeon->unk1C574.unk4; - if(weather == WEATHER_RANDOM) - weather = DungeonRandInt(WEATHER_RANDOM); + if(weather == WEATHER_COUNT) + weather = DungeonRandInt(WEATHER_COUNT); sub_807E5E4(weather); TriggerWeatherAbilities(); sub_807EAA0(0, 1);