From feaa821ac3baf3bab39d14097f7c4b3c443604fa Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Thu, 27 Feb 2025 16:04:13 -0500 Subject: [PATCH] Convert Injecting Skull token counts --- soh/soh/Enhancements/InjectItemCounts.cpp | 43 +++++++++++++++++++++++ soh/soh/OTRGlobals.cpp | 27 +------------- soh/soh/z_message_OTR.cpp | 16 --------- 3 files changed, 44 insertions(+), 42 deletions(-) create mode 100644 soh/soh/Enhancements/InjectItemCounts.cpp diff --git a/soh/soh/Enhancements/InjectItemCounts.cpp b/soh/soh/Enhancements/InjectItemCounts.cpp new file mode 100644 index 000000000..e5888b6f3 --- /dev/null +++ b/soh/soh/Enhancements/InjectItemCounts.cpp @@ -0,0 +1,43 @@ +#include + +extern "C" { +#include "variables.h" +} + +#define RAND_GET_OPTION(rsk) OTRGlobals::Instance->gRandoContext->GetOption(rsk) + +void BuildSkulltulaMessage(uint16_t* textId, bool* loadFromMessageTable) { + CustomMessage msg = CustomMessage( + "You got a %rGold Skulltula Token%w!&You've collected %r[[gsCount]]%w tokens&in total!", + "Ein %rGoldenes Skulltula-Symbol%w!&Du hast nun insgesamt %r[[gsCount]]&%wGoldene " + "Skulltula-Symbole&gesammelt!", + "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collecté %r[[gsCount]]%w symboles en " + "tout!", + TEXTBOX_TYPE_BLUE); + // The freeze text cannot be manually dismissed and must be auto-dismissed. + // This is fine and even wanted when skull tokens are not shuffled, but when + // when they are shuffled we don't want to be able to manually dismiss the box. + // Otherwise if we get a token from a chest or an NPC we get stuck in the ItemGet + // animation until the text box auto-dismisses. + // RANDOTODO: Implement a way to determine if an item came from a skulltula and + // inject the auto-dismiss control code if it did. + if (CVarGetInteger(CVAR_ENHANCEMENT("SkulltulaFreeze"), 0) != 0 && + !(IS_RANDO && RAND_GET_OPTION(RSK_SHUFFLE_TOKENS).IsNot(RO_TOKENSANITY_OFF))) { + // Auto dismiss textbox after 0x3C (60) frames (about 3 seconds for OoT) + msg = msg + "\x0E\x3C"; + } + int16_t gsCount = gSaveContext.inventory.gsTokens + (IS_RANDO ? 1 : 0); + msg.Replace("[[gscount]]", std::to_string(gsCount)); + msg.AutoFormat(); + msg.LoadIntoFont(); + *loadFromMessageTable = false; +} + +void InjectItemCounts_Register() { + COND_ID_HOOK(OnOpenText, TEXT_GS_FREEZE, CVAR_ENHANCEMENT("InjectItemCounts.GoldSkulltula"), BuildSkulltulaMessage); + COND_ID_HOOK(OnOpenText, TEXT_GS_NO_FREEZE, CVAR_ENHANCEMENT("InjectItemCounts.GoldSkulltula"), BuildSkulltulaMessage); +} + +RegisterShipInitFunc initFunc(InjectItemCounts_Register, { + CVAR_ENHANCEMENT("InjectItemCounts.GoldSkulltula"), +}); \ No newline at end of file diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index f1dc1dc72..01f8b0ebb 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -2084,32 +2084,7 @@ extern "C" int CustomMessage_RetrieveIfExists(PlayState* play) { const int maxBufferSize = sizeof(font->msgBuf); CustomMessage messageEntry; s16 actorParams = 0; - if (textId == TEXT_GS_NO_FREEZE || textId == TEXT_GS_FREEZE) { - if (CVarGetInteger(CVAR_ENHANCEMENT("InjectItemCounts.GoldSkulltula"), 0) != 0) { - // The freeze text cannot be manually dismissed and must be auto-dismissed. - // This is fine and even wanted when skull tokens are not shuffled, but when - // when they are shuffled we want to be able to manually dismiss the box. - // Otherwise if we get a token from a chest or an NPC we get stuck in the ItemGet - // animation until the text box auto-dismisses. - // RANDOTODO: Implement a way to determine if an item came from a skulltula and - // inject the auto-dismiss control code if it did. - if (CVarGetInteger(CVAR_ENHANCEMENT("SkulltulaFreeze"), 0) != 0 && - !(IS_RANDO && Randomizer_GetSettingValue(RSK_SHUFFLE_TOKENS) != RO_TOKENSANITY_OFF)) { - textId = TEXT_GS_NO_FREEZE; - } else { - textId = TEXT_GS_FREEZE; - } - // In vanilla, GS token count is incremented prior to the text box displaying - // In rando we need to bump the token count by one to show the correct count - s16 gsCount = gSaveContext.inventory.gsTokens + (IS_RANDO ? 1 : 0); - messageEntry = CustomMessageManager::Instance->RetrieveMessage(customMessageTableID, textId, MF_FORMATTED); - messageEntry.Replace("[[gsCount]]", std::to_string(gsCount)); - } else if (CVarGetInteger(CVAR_ENHANCEMENT("SkulltulaFreeze"), 0) != 0 && (!IS_RANDO || Randomizer_GetSettingValue(RSK_SHUFFLE_TOKENS) == RO_TOKENSANITY_OFF)) { - messageEntry = CustomMessage::LoadVanillaMessageTableEntry(TEXT_GS_FREEZE); - messageEntry.Replace(CustomMessage::MESSAGE_END(), "\x0E\x3C"); - messageEntry += CustomMessage::MESSAGE_END(); - } - } else if ((IS_RANDO || CVarGetInteger(CVAR_ENHANCEMENT("BetterBombchuShopping"), 0)) && + if ((IS_RANDO || CVarGetInteger(CVAR_ENHANCEMENT("BetterBombchuShopping"), 0)) && (textId == TEXT_BUY_BOMBCHUS_10_DESC || textId == TEXT_BUY_BOMBCHUS_10_PROMPT)) { messageEntry = CustomMessageManager::Instance->RetrieveMessage(customMessageTableID, textId, MF_FORMATTED); } else if (textId == TEXT_HEART_CONTAINER && CVarGetInteger(CVAR_ENHANCEMENT("InjectItemCounts.HeartContainer"), 0)) { diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index 22c217182..5b89d3eb8 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -135,22 +135,6 @@ extern "C" void OTRMessage_Init() } CustomMessageManager::Instance->AddCustomMessageTable(customMessageTableID); - CustomMessageManager::Instance->CreateGetItemMessage( - customMessageTableID, (GetItemID)TEXT_GS_NO_FREEZE, ITEM_SKULL_TOKEN, - CustomMessage("You got a %rGold Skulltula Token%w!&You've collected %r[[gsCount]]%w tokens&in total!\x0E\x3C", - "Ein %rGoldenes Skulltula-Symbol%w!&Du hast nun insgesamt %r[[gsCount]]&%wGoldene " - "Skulltula-Symbole&gesammelt!\x0E\x3C", - "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collecté %r[[gsCount]]%w symboles en " - "tout!\x0E\x3C", - TEXTBOX_TYPE_BLUE)); - CustomMessageManager::Instance->CreateGetItemMessage( - customMessageTableID, (GetItemID)TEXT_GS_FREEZE, ITEM_SKULL_TOKEN, - CustomMessage( - "You got a %rGold Skulltula Token%w!&You've collected %r[[gsCount]]%w tokens&in total!", - "Ein %rGoldenes Skulltula-Symbol%w!&Du hast nun insgesamt %r[[gsCount]]&%wGoldene " - "Skulltula-Symbole&gesammelt!", - "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collecté %r[[gsCount]]%w symboles en tout!", - TEXTBOX_TYPE_BLUE)); CustomMessageManager::Instance->CreateMessage( customMessageTableID, TEXT_BUY_BOMBCHUS_10_DESC, CustomMessage("\x08%rBombchu 10 pieces 99 Rupees&%wThis looks like a toy mouse, but&it's actually a "