Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nonmatchings in JirachiWish, sub_8036B28, UpdateDungeonMusic #309

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions include/trade_items_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,9 @@ enum TradeItemsModes
TRADE_ITEMS_RECEIVE_ITEM_MODE
};

struct TradeSubStruct
struct TradeItem
{
union ItemIdx {
u8 id; // item id?
u32 id_u32;
} itemIdx;
u8 itemId;
u32 quantity; // number of items?
};

Expand All @@ -54,11 +51,11 @@ struct TradeItemsMenu
UnkTextStruct2 unk1E4[4];

// TODO These might be structs...
struct TradeSubStruct unk244;
struct TradeItem unk244;

struct TradeSubStruct unk24C;
struct TradeItem unk24C;

/* 0x254 */ struct TradeSubStruct sentItem;
/* 0x254 */ struct TradeItem sentItem;

/* 0x25C */ Item itemToSend;

Expand All @@ -69,4 +66,4 @@ s32 UpdateTradeItemsMenu(void);
s32 CreateTradeItemsMenu(void);
void CleanTradeItemsMenu(void);

#endif // GUARD_TRADE_ITEMS_MENU_H
#endif // GUARD_TRADE_ITEMS_MENU_H
71 changes: 30 additions & 41 deletions src/dungeon_cutscenes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3982,20 +3982,10 @@ void sub_808B50C(void)

void JirachiWish(void)
{
u8 friendArea;
Entity *jirachiEntity;
DungeonPos *LeaderPos;
Entity *leaderEntity;
s32 wishChoice;
s32 counter;
u32 direction;
s32 index;
Item auStack152 [9];
Item itemStack [9];
Item strengthItems [9];
DungeonPos pos1;
DungeonPos pos2;
DungeonPos pos3;

jirachiEntity = GetEntityFromMonsterBehavior(BEHAVIOR_JIRACHI);
CopyMonsterNameToBuffer(gFormatBuffer_Monsters[2], MONSTER_JIRACHI);
Expand Down Expand Up @@ -4026,62 +4016,57 @@ void JirachiWish(void)
sub_803E708(10,0x46);
while( 1 ) {
while (1) {
#ifndef NONMATCHING
register void* r0 asm("r0");
asm("mov\t%0, #0":"=r"(r0));
#else
void* r0 = 0;
#endif
wishChoice = DisplayDungeonMenuMessage(r0,gUnknown_8105798,gUnknown_810579C,0x705);
wishChoice = DisplayDungeonMenuMessage(NULL,gUnknown_8105798,gUnknown_810579C,0x705);
if (wishChoice >= 1) break;
}
sub_803E708(10,0x46);
if (wishChoice == 1) {
s32 r8;
s32 counter, index;
DungeonPos pos;
Item moneyItems [9];
// Lots of Money
DisplayDungeonDialogue(&gUnknown_810581C);
sub_803E708(10,0x46);
JirachiWishGrantDialogue(jirachiEntity);

for(counter = 0; counter < 6; counter = r8)
for(counter = 0; counter < 6; counter++)
{
r8 = counter + 1;
for(index = 0; index < 9; index++)
{
sub_8045C28(&auStack152[index], ITEM_POKE, 0);
sub_8045C28(&moneyItems[index], ITEM_POKE, 0);
}
pos1.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1);
pos1.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1);
if ((GetTileMut(pos1.x, pos1.y)->terrainType & 3) != 0) {
pos.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1);
pos.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1);
if ((GetTileMut(pos.x, pos.y)->terrainType & 3) != 0) {
PlaySoundEffect(0x14c);
sub_808BB3C(&pos1);
sub_8046860(jirachiEntity,&pos1,auStack152,9);
sub_808BB3C(&pos);
sub_8046860(jirachiEntity,&pos,moneyItems,9);
}
}
GetEntInfo(jirachiEntity)->unk15D = 0;
}
if (wishChoice == 2) {
s32 counter, index;
DungeonPos pos;
Item items [9];
// Lots of Items
DisplayDungeonDialogue(&gUnknown_8105974);
sub_803E708(10,0x46);
JirachiWishGrantDialogue(jirachiEntity);

for(counter = 0; counter < 6; counter++)
{
#ifndef NONMATCHING
asm("" : : : "sl");
#endif
for(index = 0; index < 9; index++)
{
sub_8045C28(&itemStack[index], sub_803D73C(0),0);
sub_8045C28(&items[index], sub_803D73C(0),0);
}
pos2.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1);
pos2.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1);
pos.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1);
pos.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1);

if ((GetTileMut(pos2.x, pos2.y)->terrainType & 3) != 0) {
if ((GetTileMut(pos.x, pos.y)->terrainType & 3) != 0) {
PlaySoundEffect(400);
sub_808BB3C(&pos2);
sub_8046860(jirachiEntity,&pos2,itemStack,9);
sub_808BB3C(&pos);
sub_8046860(jirachiEntity,&pos,items,9);
}
}
GetEntInfo(jirachiEntity)->unk15D = 0;
Expand All @@ -4090,7 +4075,7 @@ void JirachiWish(void)
if (wishChoice == 3)
{
// A Friend Area
friendArea = JirachiFriendAreaSearch();
s32 friendArea = JirachiFriendAreaSearch();
if (friendArea == NUM_FRIEND_AREAS)
{
// You want a friend area? But you already have many friend areas...
Expand All @@ -4116,6 +4101,9 @@ void JirachiWish(void)
}
}
if (wishChoice == 4) {
s32 counter, index;
DungeonPos pos;
Item strengthItems [9];
// More Strength..
DisplayDungeonDialogue(&gUnknown_8105BA8);
sub_803E708(10,0x46);
Expand All @@ -4129,20 +4117,21 @@ void JirachiWish(void)
sub_8045C28(&strengthItems[index],gUnknown_81074FC[DungeonRandInt(8)],0);
}

pos3.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1);
pos3.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1);
pos.x = (jirachiEntity->pos.x + DungeonRandInt(3) - 1);
pos.y = (jirachiEntity->pos.y + DungeonRandInt(3) + -1);

if ((GetTileMut(pos3.x, pos3.y)->terrainType & 3) != 0) {
if ((GetTileMut(pos.x, pos.y)->terrainType & 3) != 0) {
PlaySoundEffect(400);
sub_808BB3C(&pos3);
sub_8046860(jirachiEntity,&pos3,strengthItems,4);
sub_808BB3C(&pos);
sub_8046860(jirachiEntity,&pos,strengthItems,4);
}
}
GetEntInfo(jirachiEntity)->unk15D = 0;
DisplayDungeonDialogue(&gUnknown_8105BF4);
sub_803E708(10,0x46);
}
if (wishChoice == 5) {
s32 direction;
// Something Good...
DisplayDungeonDialogue(&gUnknown_8105D2C);
sub_803E708(10,0x46);
Expand Down
32 changes: 13 additions & 19 deletions src/dungeon_music.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,14 @@ void StopDungeonBGM(void)

void UpdateDungeonMusic(void)
{
#ifndef NONMATCHING
register s32 currSongIndex asm("r1");
register u16 *bossSongIndex asm("r3");
#else
s32 currSongIndex;
u16 *bossSongIndex;
#endif
s32 newSongIndex;
DungeonMusicPlayer *musPlayer;
DungeonMusicPlayer *musPlayer = &gDungeon->musPlayer;

musPlayer = &gDungeon->musPlayer;

bossSongIndex = &gDungeon->unk644.bossSongIndex;
newSongIndex = *bossSongIndex;
if (newSongIndex == STOP_BGM) {
if (gDungeon->unk644.unk2B != 0) {
if (gDungeon->unk644.bossSongIndex != STOP_BGM) {
newSongIndex = gDungeon->unk644.bossSongIndex;
}
else {
if (gDungeon->unk644.unk2B != 0) {
newSongIndex = MUS_STOP_THIEF;
}
else if (gDungeon->unk644.monsterHouseTriggeredEvent) {
Expand All @@ -298,6 +290,7 @@ void UpdateDungeonMusic(void)
newSongIndex = musPlayer->queuedSongIndex;
}
}

if (musPlayer->state == 4) {
if (newSongIndex != musPlayer->pastSongIndex) {
musPlayer->state = 2;
Expand All @@ -308,22 +301,22 @@ void UpdateDungeonMusic(void)
musPlayer->state = 1;
musPlayer->songIndex = newSongIndex;
}

switch(musPlayer->state) {
case 0:
case 4:
default:
break;
case 1:
currSongIndex = musPlayer->songIndex;
if (currSongIndex == STOP_BGM) {
if (musPlayer->songIndex == STOP_BGM) {
musPlayer->state = 0;
}
else {
if ((currSongIndex & DUNGEON_MUSIC_FADE_IN)) {
StartNewBGM(currSongIndex & ~(DUNGEON_MUSIC_FADE_IN));
if ((musPlayer->songIndex & DUNGEON_MUSIC_FADE_IN)) {
StartNewBGM(musPlayer->songIndex & ~(DUNGEON_MUSIC_FADE_IN));
}
else {
FadeInNewBGM(currSongIndex & ~(DUNGEON_MUSIC_FADE_IN), musPlayer->fadeInSpeed);
FadeInNewBGM(musPlayer->songIndex & ~(DUNGEON_MUSIC_FADE_IN), musPlayer->fadeInSpeed);
}
musPlayer->pastSongIndex = musPlayer->songIndex;
musPlayer->state = 4;
Expand All @@ -339,6 +332,7 @@ void UpdateDungeonMusic(void)
if ((musPlayer->fadeOutSpeed != 0) && (musPlayer->fadeOutSpeed--, musPlayer->fadeOutSpeed != 0)) {
break;
}

if (musPlayer->songIndex == STOP_BGM) {
StopBGM();
musPlayer->state = 0;
Expand Down
48 changes: 13 additions & 35 deletions src/trade_items_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void sub_8036788(void)
case 3:
// Confirm # of item
sTradeItemsMenu->itemToSend.quantity = sTradeItemsMenu->unk14.unk0;
sTradeItemsMenu->sentItem.itemIdx.id = sTradeItemsMenu->itemToSend.id;
sTradeItemsMenu->sentItem.itemId = sTradeItemsMenu->itemToSend.id;
sTradeItemsMenu->sentItem.quantity = sTradeItemsMenu->unk14.unk0;
sub_801CBB8();
SetTradeItemMenu(TRADE_ITEMS_SEND_ITEM_CONFIRM);
Expand Down Expand Up @@ -323,7 +323,7 @@ void sub_80368D4(void)
break;
case 7:
case 0:
if ((sTradeItemsMenu->sentItem.itemIdx.id != ITEM_NOTHING) && (sTradeItemsMenu->sentItem.quantity != 0))
if ((sTradeItemsMenu->sentItem.itemId != ITEM_NOTHING) && (sTradeItemsMenu->sentItem.quantity != 0))
{
TradeItem_AddItem();
SetTradeItemMenu(TRADE_ITEMS_PRE_EXIT);
Expand Down Expand Up @@ -360,7 +360,7 @@ void sub_8036950(void)
break;
}
}
else if (((sTradeItemsMenu->itemMode == TRADE_ITEMS_SEND_ITEM_MODE) && (sTradeItemsMenu->sentItem.itemIdx.id != ITEM_NOTHING)) && (sTradeItemsMenu->sentItem.quantity != 0)) {
else if (((sTradeItemsMenu->itemMode == TRADE_ITEMS_SEND_ITEM_MODE) && (sTradeItemsMenu->sentItem.itemId != ITEM_NOTHING)) && (sTradeItemsMenu->sentItem.quantity != 0)) {
// Link Failure
TradeItem_AddItem(); // Add back the item
SetTradeItemMenu(0xb);
Expand All @@ -377,9 +377,9 @@ void TradeItem_AddItem(void)
{
// Use temp var to get correct statements
u16 load;
load = gTeamInventoryRef->teamStorage[sTradeItemsMenu->sentItem.itemIdx.id];
load = gTeamInventoryRef->teamStorage[sTradeItemsMenu->sentItem.itemId];
load += sTradeItemsMenu->sentItem.quantity;
gTeamInventoryRef->teamStorage[sTradeItemsMenu->sentItem.itemIdx.id] = load;
gTeamInventoryRef->teamStorage[sTradeItemsMenu->sentItem.itemId] = load;
}

void sub_80369FC(void)
Expand Down Expand Up @@ -478,17 +478,9 @@ void nullsub_52(void)
{
}


void sub_8036B28(void)
{
int linkStatus;
u32 load_2;
struct TradeSubStruct *temp;
struct TradeSubStruct *temp2;
struct TradeSubStruct *temp3;
struct TradeSubStruct *temp4;
s32 r2;
s32 r3;

switch(sTradeItemsMenu->currMenu) {
case TRADE_ITEMS_MAIN_MENU:
Expand Down Expand Up @@ -540,21 +532,11 @@ void sub_8036B28(void)
case 10:
sTradeItemsMenu->linkStatus = COMMS_GOOD;

#ifndef NONMATCHING
asm("mov\t%0, #0":"=r"(r2));
asm("mov\t%0, #0":"=r"(r3));
#else
r2 = 0;
r3 = 0;
#endif

temp4 = &sTradeItemsMenu->unk244;
temp4->itemIdx.id_u32 = r2;
temp4->quantity = r3;

temp3 = &sTradeItemsMenu->unk24C;
temp3->itemIdx.id_u32 = r2;
temp3->quantity = r3;
{
struct TradeItem tradeItemZeroed = {0};
sTradeItemsMenu->unk244 = tradeItemZeroed;
sTradeItemsMenu->unk24C = tradeItemZeroed;
}

sub_8011830();
linkStatus = sub_8037B28(sTradeItemsMenu->itemMode);
Expand All @@ -563,11 +545,7 @@ void sub_8036B28(void)
switch(sTradeItemsMenu->itemMode){
// Fallthrough needed on each case
case TRADE_ITEMS_SEND_ITEM_MODE:
temp = &sTradeItemsMenu->unk244;
temp2 = &sTradeItemsMenu->sentItem;
load_2 = temp2->quantity;
temp->itemIdx.id_u32 = temp2->itemIdx.id_u32;
temp->quantity = load_2;
sTradeItemsMenu->unk244 = sTradeItemsMenu->sentItem;
case TRADE_ITEMS_RECEIVE_ITEM_MODE:
sTradeItemsMenu->linkStatus = sub_8037D64(sTradeItemsMenu->itemMode,&sTradeItemsMenu->unk244,&sTradeItemsMenu->unk24C);
default:
Expand All @@ -583,11 +561,11 @@ void sub_8036B28(void)
case 0xe:
if (sTradeItemsMenu->unk24C.quantity == 0) {
gFormatArgs[0] = sTradeItemsMenu->unk244.quantity;
BufferItemName(gFormatBuffer_Items[0],sTradeItemsMenu->unk244.itemIdx.id,NULL);
BufferItemName(gFormatBuffer_Items[0],sTradeItemsMenu->unk244.itemId,NULL);
}
else {
gFormatArgs[0] = sTradeItemsMenu->unk24C.quantity;
BufferItemName(gFormatBuffer_Items[0],sTradeItemsMenu->unk24C.itemIdx.id,NULL);
BufferItemName(gFormatBuffer_Items[0],sTradeItemsMenu->unk24C.itemId,NULL);
}
CreateDialogueBoxAndPortrait(sFmtYouReceived,0,0,0x101);
break;
Expand Down
Loading