Skip to content

Commit

Permalink
Fix issues related to OW sprite shadows
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit e9dfe2b378416a41f4ba894bae5612bdc278e6c6
Author: Pseurae <[email protected]>
Date:   Mon Jul 3 00:24:38 2023 +0530

    Set REG_BLDALPHA using Weather_SetBlendCoeff

commit a94cbc7d218c960a7ba9c61ec53381773d9ddbcc
Author: Pseurae <[email protected]>
Date:   Sun Jul 2 15:19:54 2023 +0530

    Fix shadow duplication issue

commit 2baf044da96b62332ba331152cc836c0386885e8
Author: Pseurae <[email protected]>
Date:   Sat Jul 1 12:22:41 2023 +0530

    Implement FindShadowFieldEffectSprite
  • Loading branch information
Pseurae committed Jul 2, 2023
1 parent 9e1fe4e commit 708d7b7
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 45 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include $(DEVKITARM)/base_tools
SRC_FILES ?= $(wildcard src/*.c)
OBJ_FILES ?= $(SRC_FILES:src/%.c=build/src/%.o)

CFLAGS = -Os -Iinclude -mlong-calls -Wall -Wextra -mthumb -mno-thumb-interwork -fno-inline -fno-builtin -std=gnu11 -mabi=apcs-gnu -mcpu=arm7tdmi -march=armv4t -mtune=arm7tdmi -x c -c -MMD $(EXTRA_CFLAGS)
CFLAGS = -Iinclude -mlong-calls -Wall -Wextra -mthumb -mno-thumb-interwork -fno-inline -fno-builtin -std=gnu11 -mabi=apcs-gnu -mcpu=arm7tdmi -march=armv4t -mtune=arm7tdmi -x c -c -MMD -g -mthumb-interwork -Wimplicit -Wparentheses -Wunused -Werror -fno-toplevel-reorder -fno-aggressive-loop-optimizations -Wno-pointer-to-int-cast -Wno-stringop-overflow $(EXTRA_CFLAGS)

LD = $(PREFIX)ld
LDFLAGS = --relocatable -T rom.ld $(EXTRA_LDFLAGS)
Expand Down
9 changes: 9 additions & 0 deletions include/event_object_movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ u8 GetObjectEventIdByLocalIdAndMap(u8, u8, u8);
const struct ObjectEventGraphicsInfo *GetObjectEventGraphicsInfo(u8);
bool8 TryGetObjectEventIdByLocalIdAndMap(u8, u8, u8, u8 *);
void DoShadowFieldEffect(struct ObjectEvent *);
bool8 ObjectEventIsMovementOverridden(struct ObjectEvent *);
u8 ObjectEventClearHeldMovementIfFinished(struct ObjectEvent *);
void CameraObjectReset2(void);
void SetSurfBlob_BobState(u8, u8);
u8 GetPlayerAvatarGraphicsIdByStateId(u8);
void ObjectEventSetGraphicsId(struct ObjectEvent *, u8);
void ObjectEventTurn(struct ObjectEvent *, u8);
void ObjectEventGetLocalIdAndMap(struct ObjectEvent *, void *, void *, void *);
void ObjectEventClearHeldMovementIfActive(struct ObjectEvent *);

#define GROUND_EFFECT_FLAG_TALL_GRASS_ON_SPAWN (1 << 0)
#define GROUND_EFFECT_FLAG_TALL_GRASS_ON_MOVE (1 << 1)
Expand Down
5 changes: 5 additions & 0 deletions include/field_effect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

u8 CreateFlyBirdSprite(void);
void StartFlyBirdSwoopDown(u8);
void SetFlyBirdPlayerSpriteId(u8, u8);
4 changes: 3 additions & 1 deletion include/field_effect_helpers.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#pragma once

extern const u16 gShadowVerticalOffsets[];
extern const u16 gShadowVerticalOffsets[4];
extern const void *const gFieldEffectObjectTemplatePointers[];
extern const u8 gShadowEffectTemplateIds[];
extern s32 gFieldEffectArguments[8];

void FieldEffectStop(struct Sprite *sprite, u8 id);
u32 FldEff_Shadow_(void);
void UpdateShadowFieldEffect(struct Sprite *sprite);
38 changes: 38 additions & 0 deletions include/field_player_avatar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

enum {
PLAYER_AVATAR_STATE_NORMAL,
PLAYER_AVATAR_STATE_MACH_BIKE,
PLAYER_AVATAR_STATE_ACRO_BIKE,
PLAYER_AVATAR_STATE_SURFING,
PLAYER_AVATAR_STATE_UNDERWATER,
PLAYER_AVATAR_STATE_FIELD_MOVE,
PLAYER_AVATAR_STATE_FISHING,
PLAYER_AVATAR_STATE_WATERING,
};

struct PlayerAvatar /* 0x202E858 */
{
/*0x00*/ u8 flags;
/*0x01*/ u8 unk1; // used to be named bike, but its definitely not that. seems to be some transition flags
/*0x02*/ u8 runningState; // this is a static running state. 00 is not moving, 01 is turn direction, 02 is moving.
/*0x03*/ u8 tileTransitionState; // this is a transition running state: 00 is not moving, 01 is transition between tiles, 02 means you are on the frame in which you have centered on a tile but are about to keep moving, even if changing directions. 2 is also used for a ledge hop, since you are transitioning.
/*0x04*/ u8 spriteId;
/*0x05*/ u8 objectEventId;
/*0x06*/ bool8 preventStep;
/*0x07*/ u8 gender;
/*0x08*/ u8 acroBikeState; // 00 is normal, 01 is turning, 02 is standing wheelie, 03 is hopping wheelie
/*0x09*/ u8 newDirBackup; // during bike movement, the new direction as opposed to player's direction is backed up here.
/*0x0A*/ u8 bikeFrameCounter; // on the mach bike, when this value is 1, the bike is moving but not accelerating yet for 1 tile. on the acro bike, this acts as a timer for acro bike.
/*0x0B*/ u8 bikeSpeed;
// acro bike only
/*0x0C*/ u32 directionHistory; // up/down/left/right history is stored in each nybble, but using the field directions and not the io inputs.
/*0x10*/ u32 abStartSelectHistory; // same as above but for A + B + start + select only
// these two are timer history arrays which [0] is the active timer for acro bike. every element is backed up to the next element upon update.
/*0x14*/ u8 dirTimerHistory[8];
/*0x1C*/ u8 abStartSelectTimerHistory[8];
};

extern struct PlayerAvatar gPlayerAvatar;

void SetPlayerAvatarStateMask(u8 a);
3 changes: 3 additions & 0 deletions include/field_weather.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ struct WeatherCallbacks
};

void Weather_SetBlendCoeffs(u8, u8);
void SetRainStrengthFromSoundEffect(u16 soundEffect);
void PreservePaletteInWeather(u8 preservedPalIndex);

extern const struct WeatherCallbacks gWeatherFuncs[];
extern struct Weather *const gWeatherPtr;
extern void (*const gWeatherPalStateFuncs[4])(void);
45 changes: 23 additions & 22 deletions include/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct SpriteTemplate
void (*callback)(void *);
};

struct OamData
struct PACKED OamData
{
/*0x00*/ u32 y:8;
/*0x01*/ u32 affineMode:2; // 0x1, 0x2 = 0x3
Expand All @@ -32,10 +32,10 @@ struct OamData
/*0x06*/ u16 affineParam;
};

struct Sprite;
struct PACKED Sprite;
typedef void (*SpriteCallback)(struct Sprite *);

struct Sprite
struct PACKED Sprite
{
/*0x00*/ struct OamData oam;
/*0x08*/ const union AnimCmd *const *anims;
Expand All @@ -53,43 +53,44 @@ struct Sprite
/*0x2A*/ u8 animNum;
/*0x2B*/ u8 animCmdIndex;
/*0x2C*/ u8 animDelayCounter:6;
u8 animPaused:1;
u8 affineAnimPaused:1;
u8 animPaused:1;
u8 affineAnimPaused:1;
/*0x2D*/ u8 animLoopCounter;

// general purpose data fields
/*0x2E*/ s16 data[8];

/*0x3E*/ u16 inUse:1; // 1
u16 coordOffsetEnabled:1; // 2
bool16 invisible:1; // 4
u16 flags_3:1; // 8
u16 flags_4:1; // 0x10
u16 flags_5:1; // 0x20
u16 flags_6:1; // 0x40
u16 flags_7:1; // 0x80
/*0x3E*/ u16 inUse:1; //1
u16 coordOffsetEnabled:1; //2
bool16 invisible:1; //4
u16 flags_3:1; //8
u16 flags_4:1; //0x10
u16 flags_5:1; //0x20
u16 flags_6:1; //0x40
u16 flags_7:1; //0x80
/*0x3F*/ u16 hFlip:1;
u16 vFlip:1;
u16 animBeginning:1;
u16 affineAnimBeginning:1;
u16 animEnded:1;
u16 affineAnimEnded:1;
u16 usingSheet:1;
u16 flags_f:1;
u16 vFlip:1;
u16 animBeginning:1;
u16 affineAnimBeginning:1;
u16 animEnded:1;
u16 affineAnimEnded:1;
u16 usingSheet:1;
u16 flags_f:1;

/*0x40*/ u16 sheetTileStart;

/*0x42*/ u8 subspriteTableNum:6;
u8 subspriteMode:2;
u8 subspriteMode:2;

/*0x43*/ u8 subpriority;
};

extern struct Sprite gSprites[];
extern struct Sprite gSprites[MAX_SPRITES];
extern struct SpriteTemplate gCreatingSpriteTemplate;

u8 IndexOfSpritePaletteTag(u16 tag);
u8 CreateSprite(const void *template, s16 x, s16 y, u8 subpriority);
u8 CreateSpriteAtEnd(const void *template, s16 x, s16 y, u8 subpriority);
void SpriteCallbackDummy(struct Sprite *sprite);
void FreeResourcesAndDestroySprite(struct Sprite *sprite);
void StartSpriteAnim(struct Sprite *sprite, u8 animNum);
24 changes: 12 additions & 12 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

#include <stdint.h>

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;

typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef signed char s8;
typedef signed short s16;
typedef signed int s32;

typedef volatile uint8_t vu8;
typedef volatile uint16_t vu16;
typedef volatile uint32_t vu32;
typedef volatile u8 vu8;
typedef volatile u16 vu16;
typedef volatile u32 vu32;

typedef volatile int8_t vs8;
typedef volatile int16_t vs16;
typedef volatile int32_t vs32;
typedef volatile s8 vs8;
typedef volatile s16 vs16;
typedef volatile s32 vs32;

typedef u8 bool8;
typedef u16 bool16;
Expand Down
6 changes: 5 additions & 1 deletion main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
.include "scripts/include/types.asm"
.include "scripts/include/vars_flags.asm"

.org 0x886D1F0
.org 0x8729e20
.region 0xaca0
.endregion

.org 0x886d1f0
.region 0x9850
.endregion

Expand Down
22 changes: 20 additions & 2 deletions rom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gBattleMoves = 0x81fb12c;
gItems = 0x83c5564;
sMonSummaryScreen = 0x2018000;
gObjectEvents = 0x30048a0;
gPlayerAvatar = 0x202e858;
gFieldEffectArguments = 0x202ff84;
gBGTilemapBuffers = 0x20211cc;
gMoveNames = 0x81f8320;
Expand Down Expand Up @@ -89,6 +90,8 @@ gOtherText_Player = 0x842c983;
gOtherText_Badges = 0x842c98a;
gOtherText_Pokedex = 0x842c992;
gOtherText_PlayTime = 0x842c99a;
gWeatherFuncs = 0x8396fc8;
gWeatherPalStateFuncs = 0x83970b8 | 1;

gSpecialVar_0x8004 = 0x202e8cc;
gSpecialVar_Result = 0x202e8dc;
Expand Down Expand Up @@ -220,8 +223,23 @@ MetatileBehavior_IsPuddle = 0x80573bc | 1;

TryGetObjectEventIdByLocalIdAndMap = 0x805aba8 | 1;
GetObjectEventIdByLocalIdAndMap = 0x805ab84 | 1;
GetObjectEventGraphicsInfo = 0x0805bc10 | 1;
GetObjectEventGraphicsInfo = 0x805bc10 | 1;
DoShadowFieldEffect = 0x8064a1c | 1;
UpdateShadowFieldEffect = 0x8126d10 | 1;
ObjectEventClearHeldMovementIfFinished = 0x8060614 | 1;
SetSurfBlob_BobState = 0x8127ed0 | 1;
GetPlayerAvatarGraphicsIdByStateId = 0x805986c | 1;
CameraObjectReset2 = 0x805c42c | 1;
SetPlayerAvatarStateMask = 0x80599f4 | 1;
ObjectEventSetGraphicsId = 0x805b980 | 1;
ObjectEventTurn = 0x805bac0 | 1;
UpdateShadowFieldEffect = 0x8126d10 | 1;
ObjectEventGetLocalIdAndMap = 0x805bcac | 1;
StartSpriteAnim = 0x8001f58 | 1;
CreateFlyBirdSprite = 0x8088f60 | 1;
StartFlyBirdSwoopDown = 0x8088fc0 | 1;
SetFlyBirdPlayerSpriteId = 0x8088ffc | 1;
ObjectEventIsMovementOverridden = 0x806051c | 1;
ObjectEventClearHeldMovementIfActive = 0x80605b4 | 1;
SetRainStrengthFromSoundEffect = 0x807dd5c | 1;

FieldEffectStop = 0x808583c | 1;
92 changes: 89 additions & 3 deletions scripts/ow_shadows.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
; TODO: After using Fly, there seems to be two shadow sprites attached to the player.
; Does not affect anything else, and seems to fix itself when another map is loaded. (warping)
.macro @NopShadowFlagSetting, offset
.org offset + 0x16
.area 0x2 * 4
nop
nop
nop
nop
.endarea
.endmacro

.if OW_EVENT_SHADOWS
.org 0x80635f0 ; GetAllGroundEffectFlags_OnSpawn
Expand All @@ -24,5 +31,84 @@ bx r7

.org 0x81D9C46
.byte 0x3
.word FldEff_Shadow_ | 1
.word (FldEff_Shadow_ | 1 )

; Jump 2
@NopShadowFlagSetting 0x80613d4
@NopShadowFlagSetting 0x806142c
@NopShadowFlagSetting 0x8061484
@NopShadowFlagSetting 0x80614dc

; Jump
@NopShadowFlagSetting 0x80621bc
@NopShadowFlagSetting 0x8062214
@NopShadowFlagSetting 0x806226c
@NopShadowFlagSetting 0x80622c4

; JumpInPlace
@NopShadowFlagSetting 0x806231c
@NopShadowFlagSetting 0x8062374
@NopShadowFlagSetting 0x80623cc
@NopShadowFlagSetting 0x8062424

; Mixed JumpInPlace
@NopShadowFlagSetting 0x806247c
@NopShadowFlagSetting 0x80624d4
@NopShadowFlagSetting 0x806252c
@NopShadowFlagSetting 0x8062584

; AcroWheelieHop
@NopShadowFlagSetting 0x8062bfc
@NopShadowFlagSetting 0x8062c54
@NopShadowFlagSetting 0x8062cac
@NopShadowFlagSetting 0x8062d04

; AcroWheelieHop
@NopShadowFlagSetting 0x8062d5c
@NopShadowFlagSetting 0x8062db4
@NopShadowFlagSetting 0x8062e0c
@NopShadowFlagSetting 0x8062e64

; AcroWheelieJump
@NopShadowFlagSetting 0x8062ebc
@NopShadowFlagSetting 0x8062f14
@NopShadowFlagSetting 0x8062f6c
@NopShadowFlagSetting 0x8062fc4

.org 0x839F454
.word (FlyInFieldEffect_BirdSwoopDown | 1)

.org 0x08374560 + 0x14
.word (UpdateShadowFieldEffect_ | 1)

.org 0x08374578 + 0x14
.word (UpdateShadowFieldEffect_ | 1)

.org 0x08374590 + 0x14
.word (UpdateShadowFieldEffect_ | 1)

.org 0x083745a8 + 0x14
.word (UpdateShadowFieldEffect_ | 1)

.org 0x807cae8
ldr r7, = (None_InitVars | 1)
bx r7
.pool

.org 0x807df9c
ldr r0, = (Sunny_InitVars | 1)
bx r0
.pool

.org 0x8080430
ldr r7, =(Shade_InitVars | 1)
bx r7
.pool

.org 0x807df24
mov r0, #0x8
mov r1, #0xc

set_nop_bl 0x807dea8

.endif
7 changes: 5 additions & 2 deletions src/event_object_movement.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "sprite.h"
#include "field_weather.h"
#include "metatile_behavior.h"
#include "field_effect_helpers.h"
#include "constants/field_effects.h"
#include "constants/weather.h"
#include "constants/gba.h"
Expand Down Expand Up @@ -41,6 +42,7 @@ static bool8 IsSuitableWeatherForShadow(void)
case WEATHER_NONE:
case WEATHER_SUNNY:
case WEATHER_SHADE:
case WEATHER_CLOUDS:
return TRUE;
}

Expand Down Expand Up @@ -74,8 +76,9 @@ static void GetGroundEffectFlags_Shadow(struct ObjectEvent *objEvent, u32 *flags
void GroundEffect_Shadow(struct ObjectEvent *objEvent, struct Sprite *sprite)
{
(void)sprite;
StartFieldEffectForObjectEvent(FLDEFF_SHADOW, objEvent);
REG_BLDALPHA = BLDALPHA_BLEND(7, 13);
// StartFieldEffectForObjectEvent(FLDEFF_SHADOW, objEvent);
ObjectEventGetLocalIdAndMap(objEvent, &gFieldEffectArguments[0], &gFieldEffectArguments[1], &gFieldEffectArguments[2]);
FldEff_Shadow_();
}

void StartTriggeredGroundEffects(struct ObjectEvent *objEvent, struct Sprite *sprite, u32 flags)
Expand Down
Loading

0 comments on commit 708d7b7

Please sign in to comment.