From 7612e386419ef913bda5a62a5c8f234190542bb0 Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:52:50 -0500 Subject: [PATCH 01/10] fix: improved FadeScreenHardware during fade-in --- src/palette.c | 41 +++++++++++++++++++++++++++++------------ src/scrcmd.c | 2 ++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/palette.c b/src/palette.c index 303e6ced42..59fbdcfab4 100644 --- a/src/palette.c +++ b/src/palette.c @@ -2,8 +2,10 @@ #include "palette.h" #include "util.h" #include "decompress.h" +#include "field_weather.h" #include "gpu_regs.h" #include "task.h" +#include "constants/field_weather.h" #include "constants/rgb.h" enum @@ -967,25 +969,41 @@ static void UpdateBlendRegisters(void) { SetGpuReg(REG_OFFSET_BLDCNT, (u16)gPaletteFade_blendCnt); SetGpuReg(REG_OFFSET_BLDY, gPaletteFade.y); - // If fade-out, also adjust BLDALPHA and DISPCNT - if (!gPaletteFade.yDec /*&& gPaletteFade.mode == HARDWARE_FADE*/) { + // if TGT2 enabled, also adjust BLDALPHA and DISPCNT + if (((u16)gPaletteFade_blendCnt) & BLDCNT_TGT2_ALL) { u16 bldAlpha = GetGpuReg(REG_OFFSET_BLDALPHA); u8 tgt1 = BLDALPHA_TGT1(bldAlpha); u8 tgt2 = BLDALPHA_TGT2(bldAlpha); - u8 bldFade; + u8 mode = (gPaletteFade_blendCnt & BLDCNT_EFFECT_EFF_MASK) == BLDCNT_EFFECT_LIGHTEN ? FADE_FROM_WHITE : FADE_FROM_BLACK; + if (!gPaletteFade.yDec) + mode++; - switch (gPaletteFade_blendCnt & BLDCNT_EFFECT_EFF_MASK) + ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_FORCED_BLANK); + + switch (mode) { - // FADE_TO_BLACK - case BLDCNT_EFFECT_DARKEN: - bldFade = BLDALPHA_TGT1(max(0, 16 - gPaletteFade.y)); + case FADE_FROM_BLACK: + // increment each target until reaching weather's values SetGpuReg( REG_OFFSET_BLDALPHA, - BLDALPHA_BLEND(min(tgt1, bldFade), min(tgt2, bldFade)) + BLDALPHA_BLEND( + min(++tgt1, gWeatherPtr->currBlendEVA), + min(++tgt2, gWeatherPtr->currBlendEVB) + ) ); break; - // FADE_TO_WHITE - case BLDCNT_EFFECT_LIGHTEN: + case FADE_TO_BLACK: + bldAlpha = BLDALPHA_TGT1(max(0, 16 - gPaletteFade.y)); + SetGpuReg( + REG_OFFSET_BLDALPHA, + BLDALPHA_BLEND(min(tgt1, bldAlpha), min(tgt2, bldAlpha)) + ); + break; + // Not handled; blend sprites will pop in, + // but the effect coming from white looks okay + // case FADE_FROM_WHITE: + // break; + case FADE_TO_WHITE: SetGpuReg( REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(min(++tgt1, 31), min(++tgt2, 31)) @@ -996,8 +1014,7 @@ static void UpdateBlendRegisters(void) SetGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_FORCED_BLANK); break; } - } else - ClearGpuRegBits(REG_OFFSET_DISPCNT, DISPCNT_FORCED_BLANK); + } if (gPaletteFade.hardwareFadeFinishing) { diff --git a/src/scrcmd.c b/src/scrcmd.c index edca8dbbbe..b6f15b2fbe 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -663,6 +663,8 @@ bool8 ScrCmd_fadescreenswapbuffers(struct ScriptContext *ctx) switch (mode) { case FADE_FROM_BLACK: + SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(0, 0)); + break; case FADE_FROM_WHITE: // Restore last weather blend before fading in, // since BLDALPHA was modified by fade-out From 73e891a88a61dfdf3ed11d5c91cad80e5349d519 Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Sat, 8 Mar 2025 02:15:32 -0500 Subject: [PATCH 02/10] fix: rainy castform is no longer a Ninja Boy on return-to-field --- src/event_object_movement.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 513931c035..633167f4e2 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -2772,13 +2772,13 @@ const struct ObjectEventGraphicsInfo *GetObjectEventGraphicsInfo(u16 graphicsId) if (graphicsId >= OBJ_EVENT_GFX_VARS && graphicsId <= OBJ_EVENT_GFX_VAR_F) graphicsId = VarGetObjectEventGraphicsId(graphicsId - OBJ_EVENT_GFX_VARS); - if (graphicsId >= OBJ_EVENT_GFX_MON_BASE + SPECIES_SHINY_TAG) - graphicsId -= SPECIES_SHINY_TAG; // graphicsId may contain mon form info if (graphicsId > OBJ_EVENT_GFX_SPECIES_MASK) { form = graphicsId >> OBJ_EVENT_GFX_SPECIES_BITS; graphicsId = graphicsId & OBJ_EVENT_GFX_SPECIES_MASK; } + if (graphicsId >= OBJ_EVENT_GFX_MON_BASE + SPECIES_SHINY_TAG) + graphicsId -= SPECIES_SHINY_TAG; if (graphicsId == OBJ_EVENT_GFX_BARD) { return gMauvilleOldManGraphicsInfoPointers[GetCurrentMauvilleOldMan()]; From 07fd8a28fbd5b23a6828846e4606fc3ecd54c3d9 Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Sun, 30 Mar 2025 18:01:04 -0400 Subject: [PATCH 03/10] fix: hide followers when player enters Battle Pike curtains --- data/scripts/battle_pike.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/data/scripts/battle_pike.inc b/data/scripts/battle_pike.inc index 3393f808d3..9262dc46e8 100644 --- a/data/scripts/battle_pike.inc +++ b/data/scripts/battle_pike.inc @@ -86,6 +86,7 @@ BattleFrontier_BattlePikeThreePathRoom_EventScript_RightRoomWarp:: end BattleFrontier_BattlePikeThreePathRoom_EventScript_RoomWarp:: + clearflag FLAG_SAFE_FOLLOWER_MOVEMENT pike_get PIKE_DATA_WIN_STREAK addvar VAR_RESULT, 1 pike_set PIKE_DATA_WIN_STREAK, VAR_RESULT From 1f2fe7396b68d82da356b93fca10cc5736d3159c Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Sat, 3 May 2025 21:44:52 -0400 Subject: [PATCH 04/10] feat: added abnormal weather follower message Includes support for follower matching != species --- include/constants/flags.h | 1 + include/follower_helper.h | 4 +++- src/event_object_movement.c | 7 ++++++- src/follower_helper.c | 12 ++++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/constants/flags.h b/include/constants/flags.h index b7388d6bd0..4863c0980a 100644 --- a/include/constants/flags.h +++ b/include/constants/flags.h @@ -1397,6 +1397,7 @@ #define FLAG_SYS_USE_FLASH (SYSTEM_FLAGS + 0x28) #define FLAG_SYS_USE_STRENGTH (SYSTEM_FLAGS + 0x29) +// Sets abnormal weather on maps that check for it #define FLAG_SYS_WEATHER_CTRL (SYSTEM_FLAGS + 0x2A) #define FLAG_SYS_CYCLING_ROAD (SYSTEM_FLAGS + 0x2B) #define FLAG_SYS_SAFARI_MODE (SYSTEM_FLAGS + 0x2C) diff --git a/include/follower_helper.h b/include/follower_helper.h index 4d316ba1a3..e5787de5c7 100644 --- a/include/follower_helper.h +++ b/include/follower_helper.h @@ -62,7 +62,8 @@ struct FollowerMsgInfoExtended { #define MATCH_U16(type, value1, value2) {type, {.split = {.hw = value1, .b = value2}}} #define MATCH_U8(type, v1, v2, v3) {type, {.bytes = {v1, v2, v3}}} -#define MATCH_SPECIES(species) MATCH_U24(MSG_COND_SPECIES, species) +#define MATCH_SPECIES(species) MATCH_U16(MSG_COND_SPECIES, species, 0) +#define MATCH_NOT_SPECIES(species) MATCH_U16(MSG_COND_SPECIES, species, 1) #define MATCH_TYPES(type1, type2) MATCH_U8(MSG_COND_TYPE, type1, type2, 0) // Checks that follower has *neither* of the two types #define MATCH_NOT_TYPES(type1, type2) MATCH_U8(MSG_COND_TYPE, type1, type2, TYPE_NONE | 1) @@ -107,6 +108,7 @@ enum { COND_MSG_LEAVES, COND_MSG_ICE, COND_MSG_BURN, + COND_MSG_ABNORMAL_WEATHER, COND_MSG_COUNT, }; diff --git a/src/event_object_movement.c b/src/event_object_movement.c index e0bc0619ae..630e3dffb3 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -2125,7 +2125,12 @@ bool32 CheckMsgCondition(const struct MsgCondition *cond, struct Pokemon *mon, u switch (cond->type) { case MSG_COND_SPECIES: - return (cond->data.raw == species); + multi = cond->data.split.hw; + // if byte nonzero, invert; check != species! + if (cond->data.split.b) + return (cond->data.split.hw != species); + else + return (cond->data.split.hw == species); case MSG_COND_TYPE: multi = (SpeciesHasType(species, cond->data.bytes[0]) || SpeciesHasType(species, cond->data.bytes[1])); diff --git a/src/follower_helper.c b/src/follower_helper.c index be52877c5f..3df1cfa0a9 100644 --- a/src/follower_helper.c +++ b/src/follower_helper.c @@ -65,6 +65,7 @@ static const u8 sCondMsg40[] = _("{STR_VAR_1} is gnawing at the ice."); static const u8 sCondMsg41[] = _("{STR_VAR_1} is touching the ice."); static const u8* const sIceTexts[] = {sCondMsg26, sCondMsg40, sCondMsg41, NULL}; static const u8 sCondMsg42[] = _("{STR_VAR_1}'s burn looks painful!"); +static const u8 sCondMsg50[] = _("{STR_VAR_1} is disturbed by the\nabnormal weather!"); // See the struct definition in follower_helper.h for more info const struct FollowerMsgInfoExtended gFollowerConditionalMessages[COND_MSG_COUNT] = { @@ -276,6 +277,17 @@ const struct FollowerMsgInfoExtended gFollowerConditionalMessages[COND_MSG_COUNT .emotion = FOLLOWER_EMOTION_SAD, .conditions = {MATCH_STATUS(STATUS1_BURN)}, }, + [COND_MSG_ABNORMAL_WEATHER] = + { + .text = sCondMsg50, + .emotion = FOLLOWER_EMOTION_SURPRISE, + .conditions = { + MATCH_MUSIC(MUS_ABNORMAL_WEATHER), + MATCH_NOT_SPECIES(SPECIES_KYOGRE), + MATCH_NOT_SPECIES(SPECIES_GROUDON), + MATCH_NOT_SPECIES(SPECIES_RAYQUAZA), + } + }, }; // Pool of "unconditional" follower messages From 143500a1f95bf5951c001ec88db8b9d3f55d43e7 Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Tue, 20 May 2025 23:08:48 -0400 Subject: [PATCH 05/10] fix: capitalization in follower splash message --- src/follower_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/follower_helper.c b/src/follower_helper.c index 3df1cfa0a9..db24895a38 100644 --- a/src/follower_helper.c +++ b/src/follower_helper.c @@ -35,7 +35,7 @@ static const u8 sCondMsg16[] = _("{STR_VAR_1} doesn't want to get off\nthe boat static const u8* const sBoatTexts[] = {sCondMsg14, sCondMsg15, sCondMsg16, NULL}; static const u8 sCondMsg17[] = _("{STR_VAR_1} is listening to the\nsound of the machines."); static const u8* const sMachineTexts[] = {sCondMsg13, sCondMsg17, NULL}; -static const u8 sCondMsg18[] = _("Waah! your POKéMON suddenly splashed\nwater!"); +static const u8 sCondMsg18[] = _("Waah! Your POKéMON suddenly splashed\nwater!"); static const u8 sCondMsg19[] = _("Your POKéMON is blowing sand in the\nair!"); static const u8 sCondMsg20[] = _("{STR_VAR_1} is playing around,\nplucking bits of grass."); static const u8 sCondMsg21[] = _("Your POKéMON is happily looking at\nyour footprints!"); From 200ef41fce5071a2032ef34e4ba64b71368cfccd Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Fri, 30 May 2025 01:32:48 -0400 Subject: [PATCH 06/10] fix: mapjson missing cstdint --- tools/mapjson/json11.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/mapjson/json11.cpp b/tools/mapjson/json11.cpp index 3ac5f392a0..50c2209c57 100644 --- a/tools/mapjson/json11.cpp +++ b/tools/mapjson/json11.cpp @@ -20,6 +20,7 @@ #include "json11.h" #include #include +#include #include #include #include From cab7f8b24b0dfaa26de8d63938cc3c9737d127a6 Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Tue, 24 Jun 2025 19:52:45 -0400 Subject: [PATCH 07/10] fix: removed sweet scent field effect dependence on gPaletteDecompressionBuffer --- src/fldeff_sweetscent.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/fldeff_sweetscent.c b/src/fldeff_sweetscent.c index dd979c77a8..c7da9ddb68 100644 --- a/src/fldeff_sweetscent.c +++ b/src/fldeff_sweetscent.c @@ -6,6 +6,7 @@ #include "field_screen_effect.h" #include "field_weather.h" #include "fldeff.h" +#include "malloc.h" #include "mirage_tower.h" #include "palette.h" #include "party_menu.h" @@ -50,13 +51,19 @@ bool8 FldEff_SweetScent(void) static void StartSweetScentFieldEffect(void) { u8 taskId; + u32 palettes = ~(1 << (gSprites[GetPlayerAvatarSpriteId()].oam.paletteNum + 16) | (1 << 13) | (1 << 14) | (1 << 15)); + u32 *buffer = Alloc(PLTT_SIZE); PlaySE(SE_M_SWEET_SCENT); - CpuFastCopy(gPlttBufferUnfaded, gPaletteDecompressionBuffer, PLTT_SIZE); - CpuFastCopy(gPlttBufferFaded, gPlttBufferUnfaded, PLTT_SIZE); - BeginNormalPaletteFade(~(1 << (gSprites[GetPlayerAvatarSpriteId()].oam.paletteNum + 16)), 4, 0, 8, RGB_RED); + if (buffer) { + CpuFastCopy(gPlttBufferUnfaded, buffer, PLTT_SIZE); + CpuFastCopy(gPlttBufferFaded, gPlttBufferUnfaded, PLTT_SIZE); + } + BeginNormalPaletteFade(palettes, 4, 0, 8, RGB_RED); taskId = CreateTask(TrySweetScentEncounter, 0); gTasks[taskId].data[0] = 0; + gTasks[taskId].data[1] = (u32) buffer >> 16; + gTasks[taskId].data[2] = (u32) buffer; FieldEffectActiveListRemove(FLDEFF_SWEET_SCENT); } @@ -71,6 +78,8 @@ static void TrySweetScentEncounter(u8 taskId) gTasks[taskId].data[0] = 0; if (SweetScentWildEncounter() == TRUE) { + u32 *buffer = (u32*)(((u16)gTasks[taskId].data[1] << 16) | (u16)gTasks[taskId].data[2]); + TRY_FREE_AND_SET_NULL(buffer); DestroyTask(taskId); } else @@ -91,7 +100,11 @@ static void FailSweetScentEncounter(u8 taskId) { if (!gPaletteFade.active) { - CpuFastCopy(gPaletteDecompressionBuffer, gPlttBufferUnfaded, PLTT_SIZE); + u32 *buffer = (u32*)(((u16)gTasks[taskId].data[1] << 16) | (u16)gTasks[taskId].data[2]); + if (buffer) { + CpuFastCopy(buffer, gPlttBufferUnfaded, PLTT_SIZE); + Free(buffer); + } SetWeatherPalStateIdle(); ScriptContext_SetupScript(EventScript_FailSweetScent); DestroyTask(taskId); From 1cc2c7f2a02c350c0d724ab661ea0b78d108df51 Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Tue, 24 Jun 2025 19:57:04 -0400 Subject: [PATCH 08/10] fix: destroy shadows during battle transition intro --- src/battle_transition.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/battle_transition.c b/src/battle_transition.c index 0d66dfbf01..dbee25968f 100644 --- a/src/battle_transition.c +++ b/src/battle_transition.c @@ -1068,6 +1068,9 @@ static void Task_BattleTransition(u8 taskId) static bool8 Transition_StartIntro(struct Task *task) { SetWeatherScreenFadeOut(); + // cause all shadow sprites to destroy themselves, + // freeing up sprite slots for the transition + gWeatherPtr->noShadows = TRUE; CpuCopy32(gPlttBufferFaded, gPlttBufferUnfaded, PLTT_SIZE); if (sTasks_Intro[task->tTransitionId] != NULL) { From f6efe480fa4363eacf59538e6e68ec34fa6f6a1d Mon Sep 17 00:00:00 2001 From: Ariel A <24759293+aarant@users.noreply.github.com> Date: Sun, 9 Mar 2025 19:41:16 -0400 Subject: [PATCH 09/10] fix: ignore trainerRange on OW templates when trainerType nonzero --- src/event_object_movement.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/event_object_movement.c b/src/event_object_movement.c index f63624e135..be4c5abfd8 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1738,7 +1738,7 @@ static u16 PackGraphicsId(const struct ObjectEventTemplate *template) { if (template->script && template->script[0] == 0x7d) { form = T1_READ_16(&template->script[2]); form = (form >> 10) & 0x1F; - } else if (template->trainerRange_berryTreeId) { + } else if (template->trainerRange_berryTreeId && !template->trainerType) { form = template->trainerRange_berryTreeId & 0x1F; } graphicsId |= form << OBJ_EVENT_GFX_SPECIES_BITS; From 9ca6562874d92d7dd9562fc10e5026d9ef64b7d4 Mon Sep 17 00:00:00 2001 From: Hedara Date: Wed, 25 Jun 2025 18:04:12 +0200 Subject: [PATCH 10/10] Cleanup of merrp merge --- tools/mapjson/json11.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/mapjson/json11.cpp b/tools/mapjson/json11.cpp index 74f9272313..fcacdbeb39 100644 --- a/tools/mapjson/json11.cpp +++ b/tools/mapjson/json11.cpp @@ -20,7 +20,6 @@ #include "json11.h" #include #include -#include #include #include #include