From fc08229a4618e9ac0cdde91d43f6ab99ab690c32 Mon Sep 17 00:00:00 2001 From: lilDavid <1337lilDavid@gmail.com> Date: Wed, 10 Aug 2022 10:50:13 -0500 Subject: [PATCH] Save editor: Link adult trade item slot and flags --- .../Enhancements/debugger/debugSaveEditor.cpp | 16 ++++++++++++++++ soh/src/code/z_kankyo.c | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp index 9acf3d1cc..90e4ca0ff 100644 --- a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp +++ b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp @@ -15,6 +15,7 @@ extern "C" { #include "variables.h" #include "functions.h" #include "macros.h" +#include "soh/Enhancements/randomizer/adult_trade_shuffle.h" extern GlobalContext* gGlobalCtx; #include "textures/icon_item_static/icon_item_static.h" @@ -535,8 +536,12 @@ void DrawBGSItemFlag(uint8_t itemID) { ImGui::Checkbox(("##adultTradeFlag" + std::to_string(itemID)).c_str(), &hasItem); if (hasItem) { gSaveContext.adultTradeItems |= (1 << tradeIndex); + if (INV_CONTENT(ITEM_TRADE_ADULT) == ITEM_NONE) { + INV_CONTENT(ITEM_TRADE_ADULT) = ITEM_POCKET_EGG + tradeIndex; + } } else { gSaveContext.adultTradeItems &= ~(1 << tradeIndex); + Inventory_ReplaceItem(gGlobalCtx, INV_CONTENT(ITEM_TRADE_ADULT), Randomizer_GetNextAdultTradeItem()); } } @@ -611,6 +616,17 @@ void DrawInventoryTab() { if (ImGui::ImageButton(SohImGui::GetTextureByName(slotEntry.name), ImVec2(32.0f, 32.0f), ImVec2(0, 0), ImVec2(1, 1), 0)) { gSaveContext.inventory.items[selectedIndex] = slotEntry.id; + // Set adult trade item flag if you're playing adult trade shuffle in rando + if (gSaveContext.n64ddFlag && + OTRGlobals::Instance->gRandomizer->GetRandoSettingValue(RSK_SHUFFLE_ADULT_TRADE) && + selectedIndex == SLOT_TRADE_ADULT) { + if (slotEntry.id == ITEM_NONE) { + gSaveContext.adultTradeItems = 0; + } else if (slotEntry.id >= ITEM_POCKET_EGG && slotEntry.id <= ITEM_CLAIM_CHECK) { + uint32_t tradeID = slotEntry.id - ITEM_POCKET_EGG; + gSaveContext.adultTradeItems |= tradeID; + } + } ImGui::CloseCurrentPopup(); } SetLastItemHoverText(SohUtils::GetItemName(slotEntry.id)); diff --git a/soh/src/code/z_kankyo.c b/soh/src/code/z_kankyo.c index f59a9c70d..140f5f832 100644 --- a/soh/src/code/z_kankyo.c +++ b/soh/src/code/z_kankyo.c @@ -2058,8 +2058,8 @@ bool HatchPocketEgg(GlobalContext* globalCtx) { return 0; } - // Swap the flags, then replace the item if it's selected - gSaveContext.adultTradeItems ^= ADULT_TRADE_FLAG(ITEM_POCKET_EGG) | ADULT_TRADE_FLAG(ITEM_POCKET_CUCCO); + gSaveContext.adultTradeItems &= ~ADULT_TRADE_FLAG(ITEM_POCKET_EGG); + gSaveContext.adultTradeItems |= ADULT_TRADE_FLAG(ITEM_POCKET_CUCCO); Inventory_ReplaceItem(globalCtx, ITEM_POCKET_EGG, ITEM_POCKET_CUCCO); return 1; }