diff --git a/include/trade_items_menu.h b/include/trade_items_menu.h index 68453b71..31c1fae0 100644 --- a/include/trade_items_menu.h +++ b/include/trade_items_menu.h @@ -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? }; @@ -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; @@ -69,4 +66,4 @@ s32 UpdateTradeItemsMenu(void); s32 CreateTradeItemsMenu(void); void CleanTradeItemsMenu(void); -#endif // GUARD_TRADE_ITEMS_MENU_H \ No newline at end of file +#endif // GUARD_TRADE_ITEMS_MENU_H diff --git a/src/dungeon_cutscenes.c b/src/dungeon_cutscenes.c index b3c90d20..a8c4a1f3 100644 --- a/src/dungeon_cutscenes.c +++ b/src/dungeon_cutscenes.c @@ -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); @@ -4026,41 +4016,39 @@ 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); @@ -4068,20 +4056,17 @@ void JirachiWish(void) 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; @@ -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... @@ -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); @@ -4129,13 +4117,13 @@ 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; @@ -4143,6 +4131,7 @@ void JirachiWish(void) sub_803E708(10,0x46); } if (wishChoice == 5) { + s32 direction; // Something Good... DisplayDungeonDialogue(&gUnknown_8105D2C); sub_803E708(10,0x46); diff --git a/src/dungeon_music.c b/src/dungeon_music.c index 7a55256c..78da1429 100644 --- a/src/dungeon_music.c +++ b/src/dungeon_music.c @@ -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) { @@ -298,6 +290,7 @@ void UpdateDungeonMusic(void) newSongIndex = musPlayer->queuedSongIndex; } } + if (musPlayer->state == 4) { if (newSongIndex != musPlayer->pastSongIndex) { musPlayer->state = 2; @@ -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; @@ -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; diff --git a/src/trade_items_menu.c b/src/trade_items_menu.c index a9b1415e..fb0edf7d 100644 --- a/src/trade_items_menu.c +++ b/src/trade_items_menu.c @@ -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); @@ -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); @@ -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); @@ -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) @@ -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: @@ -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); @@ -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: @@ -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;