Fix OnItemReceive hook for items in the extendedVanillaGetItem table (#3063)

This commit is contained in:
Garrett Cox 2023-12-04 13:26:55 +00:00 committed by GitHub
parent 19cede44c3
commit 1fea642f33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 63 additions and 16 deletions

View File

@ -665,7 +665,7 @@ extern "C" void VanillaItemTable_Init() {
} }
} }
std::unordered_map<uint32_t, uint32_t> ItemIDtoGetItemID{ std::unordered_map<ItemID, GetItemID> ItemIDtoGetItemIDMap {
{ ITEM_ARROWS_LARGE, GI_ARROWS_LARGE }, { ITEM_ARROWS_LARGE, GI_ARROWS_LARGE },
{ ITEM_ARROWS_MEDIUM, GI_ARROWS_MEDIUM }, { ITEM_ARROWS_MEDIUM, GI_ARROWS_MEDIUM },
{ ITEM_ARROWS_SMALL, GI_ARROWS_SMALL }, { ITEM_ARROWS_SMALL, GI_ARROWS_SMALL },
@ -695,7 +695,8 @@ std::unordered_map<uint32_t, uint32_t> ItemIDtoGetItemID{
{ ITEM_BUG, GI_BUGS }, { ITEM_BUG, GI_BUGS },
{ ITEM_BULLET_BAG_30, GI_BULLET_BAG_30 }, { ITEM_BULLET_BAG_30, GI_BULLET_BAG_30 },
{ ITEM_BULLET_BAG_40, GI_BULLET_BAG_40 }, { ITEM_BULLET_BAG_40, GI_BULLET_BAG_40 },
{ ITEM_BULLET_BAG_50, GI_BULLET_BAG_50 }, { ITEM_CHICKEN, GI_CHICKEN }, { ITEM_BULLET_BAG_50, GI_BULLET_BAG_50 },
{ ITEM_CHICKEN, GI_CHICKEN },
{ ITEM_CLAIM_CHECK, GI_CLAIM_CHECK }, { ITEM_CLAIM_CHECK, GI_CLAIM_CHECK },
{ ITEM_COJIRO, GI_COJIRO }, { ITEM_COJIRO, GI_COJIRO },
{ ITEM_COMPASS, GI_COMPASS }, { ITEM_COMPASS, GI_COMPASS },
@ -791,11 +792,42 @@ std::unordered_map<uint32_t, uint32_t> ItemIDtoGetItemID{
{ ITEM_WEIRD_EGG, GI_WEIRD_EGG } { ITEM_WEIRD_EGG, GI_WEIRD_EGG }
}; };
extern "C" int32_t GetGIID(uint32_t itemID) { extern "C" GetItemID RetrieveGetItemIDFromItemID(ItemID itemID) {
if (ItemIDtoGetItemID.contains(itemID)) { if (ItemIDtoGetItemIDMap.contains(itemID)) {
return ItemIDtoGetItemID.at(itemID); return ItemIDtoGetItemIDMap.at(itemID);
} }
return -1; return GI_MAX;
}
std::unordered_map<ItemID, RandomizerGet> ItemIDtoRandomizerGetMap {
{ ITEM_SONG_MINUET, RG_MINUET_OF_FOREST },
{ ITEM_SONG_BOLERO, RG_BOLERO_OF_FIRE },
{ ITEM_SONG_SERENADE, RG_SERENADE_OF_WATER },
{ ITEM_SONG_REQUIEM, RG_REQUIEM_OF_SPIRIT },
{ ITEM_SONG_NOCTURNE, RG_NOCTURNE_OF_SHADOW },
{ ITEM_SONG_PRELUDE, RG_PRELUDE_OF_LIGHT },
{ ITEM_SONG_LULLABY, RG_ZELDAS_LULLABY },
{ ITEM_SONG_EPONA, RG_EPONAS_SONG },
{ ITEM_SONG_SARIA, RG_SARIAS_SONG },
{ ITEM_SONG_SUN, RG_SUNS_SONG },
{ ITEM_SONG_TIME, RG_SONG_OF_TIME },
{ ITEM_SONG_STORMS, RG_SONG_OF_STORMS },
{ ITEM_MEDALLION_FOREST, RG_FOREST_MEDALLION },
{ ITEM_MEDALLION_FIRE, RG_FIRE_MEDALLION },
{ ITEM_MEDALLION_WATER, RG_WATER_MEDALLION },
{ ITEM_MEDALLION_SPIRIT, RG_SPIRIT_MEDALLION },
{ ITEM_MEDALLION_SHADOW, RG_SHADOW_MEDALLION },
{ ITEM_MEDALLION_LIGHT, RG_LIGHT_MEDALLION },
{ ITEM_KOKIRI_EMERALD, RG_KOKIRI_EMERALD },
{ ITEM_GORON_RUBY, RG_GORON_RUBY },
{ ITEM_ZORA_SAPPHIRE, RG_ZORA_SAPPHIRE },
};
extern "C" RandomizerGet RetrieveRandomizerGetFromItemID(ItemID itemID) {
if (ItemIDtoRandomizerGetMap.contains(itemID)) {
return ItemIDtoRandomizerGetMap.at(itemID);
}
return RG_MAX;
} }
extern "C" void OTRExtScanner() { extern "C" void OTRExtScanner() {

View File

@ -180,7 +180,8 @@ void SaveManager_ThreadPoolWait();
void CheckTracker_OnMessageClose(); void CheckTracker_OnMessageClose();
void SoH_ProcessDroppedFiles(); void SoH_ProcessDroppedFiles();
int32_t GetGIID(uint32_t itemID); GetItemID RetrieveGetItemIDFromItemID(ItemID itemID);
RandomizerGet RetrieveRandomizerGetFromItemID(ItemID itemID);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1804,12 +1804,22 @@ u8 Return_Item(u8 itemID, ModIndex modId, ItemID returnItem) {
GetItemEntry gie = { ITEM_SOLD_OUT, 0, 0, 0, 0, 0, 0, 0, false, ITEM_FROM_NPC, ITEM_CATEGORY_LESSER, NULL }; GetItemEntry gie = { ITEM_SOLD_OUT, 0, 0, 0, 0, 0, 0, 0, false, ITEM_FROM_NPC, ITEM_CATEGORY_LESSER, NULL };
return Return_Item_Entry(gie, returnItem); return Return_Item_Entry(gie, returnItem);
} }
int32_t get = GetGIID(itemID);
if (get == -1) { GetItemID getItemID = RetrieveGetItemIDFromItemID(itemID);
modId = MOD_RANDOMIZER; if (getItemID != GI_MAX) {
get = itemID; // Vanilla ItemID with an associated GetItemID
return Return_Item_Entry(ItemTable_RetrieveEntry(modId, getItemID), returnItem);
} }
return Return_Item_Entry(ItemTable_RetrieveEntry(modId, get), returnItem);
RandomizerGet randomizerGet = RetrieveRandomizerGetFromItemID(itemID);
if (randomizerGet != RG_MAX) {
// Vanilla ItemID with an associated RandomizerGet (These are items in extendedVanillaGetItemTable)
return Return_Item_Entry(ItemTable_RetrieveEntry(MOD_RANDOMIZER, randomizerGet), returnItem);
}
// All randomizer items should go through Randomizer_Item_Give, so this should never be reached
// but leaving this here just in case, as it was in the original behavior
return Return_Item_Entry(ItemTable_RetrieveEntry(MOD_RANDOMIZER, itemID), returnItem);
} }
/** /**
@ -6556,11 +6566,15 @@ void Interface_Update(PlayState* play) {
gSaveContext.pendingSale = ITEM_NONE; gSaveContext.pendingSale = ITEM_NONE;
gSaveContext.pendingSaleMod = MOD_NONE; gSaveContext.pendingSaleMod = MOD_NONE;
if (tempSaleMod == MOD_NONE) { if (tempSaleMod == MOD_NONE) {
s16 giid = GetGIID(tempSaleItem); GetItemID getItemID = RetrieveGetItemIDFromItemID(tempSaleItem);
if (giid == -1) { RandomizerGet randomizerGet = RetrieveRandomizerGetFromItemID(tempSaleItem);
tempSaleMod = MOD_RANDOMIZER; if (getItemID != GI_MAX) {
tempSaleItem = getItemID;
} else { } else {
tempSaleItem = giid; if (randomizerGet != RG_MAX) {
tempSaleItem = randomizerGet;
}
tempSaleMod = MOD_RANDOMIZER;
} }
} }
GameInteractor_ExecuteOnSaleEndHooks(ItemTable_RetrieveEntry(tempSaleMod, tempSaleItem)); GameInteractor_ExecuteOnSaleEndHooks(ItemTable_RetrieveEntry(tempSaleMod, tempSaleItem));