Convert Injecting Skull token counts

This commit is contained in:
Christopher Leggett 2025-02-27 16:04:13 -05:00
commit feaa821ac3
No known key found for this signature in database
GPG key ID: F2121C0AF9938ABF
3 changed files with 44 additions and 42 deletions

View file

@ -0,0 +1,43 @@
#include <soh/OTRGlobals.h>
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"),
});

View file

@ -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)) {

View file

@ -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 "