Skip to content

Commit

Permalink
Implement some new features
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseurae committed Jul 3, 2023
1 parent 579ea48 commit 8b2183c
Show file tree
Hide file tree
Showing 16 changed files with 575 additions and 3 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 = -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)
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 -Wno-unused -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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ This patch is mostly compatible with vanilla saves. The bag expansion patch **wi
- Disease type removal
- Type icons reverted to default Ruby ones
- Emerald style Save Prompt
- Colored stat values based on nature
- Repeated item usage

<details>

Expand Down
7 changes: 7 additions & 0 deletions config.asm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
; Enable this to have shadows on NPCs like in HGSS.
.definelabel OW_EVENT_SHADOWS, 1

; Nature based colored stats in the Summary Screen.
.definelabel COLORED_STATS, 1

; WIP
; Use items repeatedly without going back to the bag each time.
.definelabel REPEATED_ITEM, 1

; Bugfixes
; --------

Expand Down
379 changes: 379 additions & 0 deletions include/constants/songs.h

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions include/item_use.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

extern u16 gSpecialVar_ItemId;
1 change: 1 addition & 0 deletions include/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern u16 gMenuTextTileOffset;
u8 *AlignStringInMenuWindow(u8 *, const u8 *, u8, u8);
void Menu_PrintText(const u8 *str, u8 left, u8 top);
u8 Menu_PrintTextPixelCoords(const u8 *text, u8 left, u16 top, u8 a4);
void MenuPrint_Centered(const u8 *, u8, u8, u16);
void MenuPrint_RightAligned(const u8 *, u8, u8);
void AppendToList(u8 *list, u8 *pindex, u32 value);
u8 *AlignInt1InMenuWindow(u8 *dest, s32 value, u8 alignAmount, u8 alignType);
Expand Down
62 changes: 62 additions & 0 deletions include/party_menu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#pragma once

extern u8 gPartyMenuUseExitCallback;

#define pmStatGrowths data
#define pmSetupState data[0]
#define pmMonIndex data[1]
#define pmUnk268 data[2]
#define pmUnk272 data[7]
#define pmUnk27E data[13]
#define pmUnk280 data[14]
#define pmUnk282 data[15]

struct Unk201B000
{
struct Pokemon unk0[6];
u8 menuType;
u8 promptTextId;
TaskFunc menuHandler;
u8 menuHandlerTaskId;
u8 unk261;
u8 unk262; // Never read
u8 unk263;
s16 data[16];
};

struct PartyMenu
{
/*0x00*/ struct Pokemon *pokemon;
/*0x04*/ u8 unk4;
/*0x05*/ u8 primarySelectedMonIndex;
/*0x06*/ u16 secondarySelectedIndex;
/*0x08*/ u16 unk8;
/*0x0A*/ u8 pad_0A[2];
/*0x0C*/ s32 unkC;
/*0x10*/ TaskFunc unk10;
/*0x14*/ TaskFunc unk14;
};

extern struct Unk201B000 gPartyMenu2;
extern struct PartyMenu gPartyMenu;

u8 *GetMonNickname(struct Pokemon *pokemon, u8 *stringBuffer);
bool8 IsBlueYellowRedFlute(u16);
u8 GetMonStatusAndPokerus(struct Pokemon *mon);
void sub_806F8AC(u8 taskId);
void sub_806E8D0(u8 taskId, u16 b, TaskFunc c);
bool8 IsMedicineIneffective(struct Pokemon *pkmn, u16 item);
bool8 IsHPRecoveryItem(u16 item);
bool8 ExecuteTableBasedItemEffect__(u8, u16, u8);
void GetMedicineItemEffectMessage(u16);
void TryPrintPartyMenuMonNickname(u8 monIndex, struct Pokemon *pokemon);
void PartyMenuUpdateLevelOrStatus(struct Pokemon *, u8);
void Task_ClosePartyMenuAfterText(u8 taskId);
u8 DisplayPartyMenuMessage(const u8 *message, u8 noClearAfter);
void PrintPartyMenuPromptText(u8 textId, u8 b);
void ReturnToBagFromPartyMenu(u8 taskId);

void HandleItemUsePartyMenu(u8 taskID);
u8 GetItemEffectType(u16 item);
void PartyMenuEraseMsgBoxAndFrame(void);

5 changes: 4 additions & 1 deletion include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ bool8 CheckIfMonCanUseHM(struct Pokemon *mon, u16 hm);
bool8 CheckIfPartyCanUseTM(u16 tm);
u8 CalculatePPWithBonus(u16 move, u8 ppBonuses, u8 moveIndex);
bool8 IsHMMove(u16 move);
u8 GetNature(struct Pokemon *mon);

enum
{
Expand All @@ -104,4 +105,6 @@ enum
STAT_STAGE_SPDEF, // 5
STAT_STAGE_ACC, // 6
STAT_STAGE_EVASION, // 7
};
};

extern const s8 gNatureStatTable[25][5];
3 changes: 3 additions & 0 deletions include/sound.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

void PlaySE(u16 songNum);
1 change: 1 addition & 0 deletions include/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ u8 CreateTask(TaskFunc func, u8 priority);
bool8 FuncIsActiveTask(TaskFunc func);
u8 FindTaskIdByFunc(TaskFunc func);
u8 DestroyTask(u8 taskId);
void TaskDummy(u8 taskId);
2 changes: 2 additions & 0 deletions main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@

.include "scripts/bag_expansion.asm"
.include "scripts/colored_field_moves.asm"
.include "scripts/colored_stats.asm"
.include "scripts/emerald_save_prompt.asm"
.include "scripts/hm_system.asm"
.include "scripts/ow_shadows.asm"
.include "scripts/ps_split.asm"
.include "scripts/repeated_item.asm"
.include "scripts/repel_prompt.asm"
.include "scripts/reusable_tms.asm"
.include "scripts/summary_screen.asm"
Expand Down
31 changes: 30 additions & 1 deletion rom.ld
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ memcpy = 0x815b890 | 1;

gBattleMoves = 0x81fb12c;
gItems = 0x83c5564;
gSpecialVar_ItemId = 0x203855e;
gNatureStatTable = 0x81fd070;
gPartyMenuUseExitCallback = 0x202e8f4;
sMonSummaryScreen = 0x2018000;
gPartyMenu = 0x201C000;
gPartyMenu2 = 0x201B000;
gObjectEvents = 0x30048a0;
gPlayerAvatar = 0x202e858;
gFieldEffectArguments = 0x202ff84;
Expand Down Expand Up @@ -90,6 +95,7 @@ gOtherText_Player = 0x842c983;
gOtherText_Badges = 0x842c98a;
gOtherText_Pokedex = 0x842c992;
gOtherText_PlayTime = 0x842c99a;
gOtherText_WontHaveAnyEffect = 0x840ef85;
gWeatherFuncs = 0x8396fc8;
gWeatherPalStateFuncs = 0x83970b8;

Expand All @@ -103,6 +109,7 @@ ConvertIntToDecimalStringN = 0x8006bc4 | 1;
ConvertIntToDecimalString = 0x8006ddc | 1;
AlignStringInMenuWindow = 0x8072c74 | 1;
Menu_PrintText = 0x8071e50 | 1;
MenuPrint_Centered = 0x8072bd8 | 1;
MenuPrint_RightAligned = 0x8072b4c | 1;
HighlightSelectedOption = 0x80a425c | 1;
PrintCancelOption = 0x80a42b0 | 1;
Expand Down Expand Up @@ -144,6 +151,7 @@ BeginNormalPaletteFade = 0x8073bf4 | 1;
Weather_SetBlendCoeffs = 0x807db64 | 1;
ApplyGammaShift = 0x807cebc | 1;
CreateTask = 0x807aa88 | 1;
TaskDummy = 0x807ac50 | 1;
FuncIsActiveTask = 0x807acbc | 1;
Task_WeatherInit = 0x807c9e4 | 1;
Task_WeatherMain = 0x807ca34 | 1;
Expand Down Expand Up @@ -242,4 +250,25 @@ ObjectEventIsMovementOverridden = 0x806051c | 1;
ObjectEventClearHeldMovementIfActive = 0x80605b4 | 1;
SetRainStrengthFromSoundEffect = 0x807dd5c | 1;

FieldEffectStop = 0x808583c | 1;
FieldEffectStop = 0x808583c | 1;

sub_806E8D0 = 0x806E8D0 | 1;
IsHPRecoveryItem = 0x806fb7c | 1;
IsMedicineIneffective = 0x806fd90 | 1;
ExecuteTableBasedItemEffect__ = 0x806fdc4 | 1;
GetMedicineItemEffectMessage = 0x806fbd0 | 1;
TryPrintPartyMenuMonNickname = 0x806e07c | 1;
sub_806F8AC = 0x806f8ac | 1;
IsBlueYellowRedFlute = 0x807002c | 1;
GetMonNickname = 0x806e0ec | 1;
GetMonStatusAndPokerus = 0x80a1cd8 | 1;
PartyMenuUpdateLevelOrStatus = 0x806fbb4 | 1;
Task_ClosePartyMenuAfterText = 0x806fb0c | 1;
DisplayPartyMenuMessage = 0x806e834 | 1;
PrintPartyMenuPromptText = 0x806d538 | 1;
PlaySE = 0x8075494 | 1;
ReturnToBagFromPartyMenu = 0x808B224 | 1;
HandleItemUsePartyMenu = 0x808B0C0 | 1;
GetItemEffectType = 0x8070e48 | 1;
PartyMenuEraseMsgBoxAndFrame = 0x806d5a4 | 1;
GetNature = 0x803f464 | 1;
16 changes: 16 additions & 0 deletions scripts/colored_stats.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.if COLORED_STATS
.org 0x809ffbc
ldr r0, =(@Hook | 1)
bx r0
.pool

.autoregion
.align 2
@Hook:
mov r0, r5
bl SummaryScreen_PrintPokemonStats
ldr r0, =(0x80A0048 | 1)
bx r0
.pool
.endautoregion
.endif
4 changes: 4 additions & 0 deletions scripts/repeated_item.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.if REPEATED_ITEM
.org 0x808b178
.word (Task_ItemUseCallback | 1)
.endif
25 changes: 25 additions & 0 deletions src/party_menu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "types.h"
#include "pokemon.h"
#include "task.h"
#include "item.h"
#include "party_menu.h"
#include "item_menu.h"
#include "menu.h"
#include "item_use.h"
#include "sound.h"
#include "text.h"
#include "constants/songs.h"
#include "constants/pokemon.h"
#include "palette.h"

void Task_ItemUseCallback(u8 taskId)
{
if (GetItemEffectType(gSpecialVar_ItemId) && CheckBagHasItem(gSpecialVar_ItemId, 1))
{
Menu_EraseWindowRect(3, 14, 26, 19);
PrintPartyMenuPromptText(gPartyMenu2.promptTextId, 0);
gTasks[taskId].func = HandleItemUsePartyMenu;
}
else
ReturnToBagFromPartyMenu(taskId);
}
35 changes: 35 additions & 0 deletions src/summary_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,38 @@ s8 ChangeSummaryPokemonNormal(s8 delta)

return index;
}

void PrintStatText(struct Pokemon *mon, u8 stat, u8 nature, u8 left, u8 top, u16 width)
{
u8 *buffer = gStringVar1;
s8 mod = gNatureStatTable[nature][stat - MON_DATA_ATK];

*(buffer++) = EXT_CTRL_CODE_BEGIN;
*(buffer++) = EXT_CTRL_CODE_COLOR;

switch (mod)
{
case 0: // Neutral
*(buffer++) = 0xF; // Black
break;
case 1: // Increased
*(buffer++) = 0x9; // Red
break;
case -1: // Decreased
*(buffer++) = 0x2; // Light Blue
break;
}

ConvertIntToDecimalString(buffer, GetMonData(mon, stat));
MenuPrint_Centered(gStringVar1, left, top, width);
}

void SummaryScreen_PrintPokemonStats(struct Pokemon *mon)
{
u8 nature = GetNature(mon);
PrintStatText(mon, MON_DATA_ATK, nature, 16, 9, 50);
PrintStatText(mon, MON_DATA_DEF, nature, 16, 11, 50);
PrintStatText(mon, MON_DATA_SPATK, nature, 27, 7, 18);
PrintStatText(mon, MON_DATA_SPDEF, nature, 27, 9, 18);
PrintStatText(mon, MON_DATA_SPEED, nature, 27, 11, 18);
}

0 comments on commit 8b2183c

Please sign in to comment.