From cd01e8b7781d1b74ff7a77907666963691006d86 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Mon, 25 Jul 2022 21:31:17 -0400 Subject: [PATCH] Moves deku scrub messages into CustomMessageTable. --- .../custom_message/CustomMessage.cpp | 25 ++++++------ .../Enhancements/randomizer/randomizer.cpp | 39 +++++++++++++++++++ soh/soh/Enhancements/randomizer/randomizer.h | 1 + soh/soh/OTRGlobals.cpp | 16 ++++++++ soh/src/code/z_message_PAL.c | 10 ++--- 5 files changed, 70 insertions(+), 21 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.cpp b/soh/soh/Enhancements/custom_message/CustomMessage.cpp index 7f26fb616..6ea820aa9 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessage.cpp @@ -4,13 +4,13 @@ using namespace std::literals::string_literals; CustomMessage::CustomMessage() { - this->textBoxSpecialCharacters = { { "", 0x80 }, { "", 0x81 }, { "", 0x82 }, { "", 0x83 }, { "", 0x84 }, - { "", 0x85 }, { "", 0x86 }, { "", 0x87 }, { "", 0x88 }, { "", 0x89 }, - { "", 0x8A }, { "", 0x8B }, { "", 0x8C }, { "", 0x8D }, { "", 0x8E }, - { "", 0x8F }, { "", 0x90 }, { "", 0x91 }, { "", 0x92 }, { "", 0x93 }, - { "", 0x94 }, { "", 0x95 }, { "", 0x96 }, { "", 0x97 }, { "", 0x98 }, - { "", 0x99 }, { "", 0x9A }, { "", 0x9B }, { "", 0x9C }, { "", 0x9D }, - { "", 0x9E } }; + this->textBoxSpecialCharacters = { { "À", 0x80 }, { "î", 0x81 }, { "Â", 0x82 }, { "Ä", 0x83 }, { "Ç", 0x84 }, + { "È", 0x85 }, { "É", 0x86 }, { "Ê", 0x87 }, { "Ë", 0x88 }, { "Ï", 0x89 }, + { "Ô", 0x8A }, { "Ö", 0x8B }, { "Ù", 0x8C }, { "Û", 0x8D }, { "Ü", 0x8E }, + { "ß", 0x8F }, { "à", 0x90 }, { "á", 0x91 }, { "â", 0x92 }, { "ä", 0x93 }, + { "ç", 0x94 }, { "è", 0x95 }, { "é", 0x96 }, { "ê", 0x97 }, { "ë", 0x98 }, + { "ï", 0x99 }, { "ô", 0x9A }, { "ö", 0x9B }, { "ù", 0x9C }, { "û", 0x9D }, + { "ü", 0x9E } }; this->colors = { { "w", QM_WHITE }, { "r", QM_RED }, { "g", QM_GREEN }, { "b", QM_BLUE }, { "c", QM_LBLUE }, { "p", QM_PINK }, { "y", QM_YELLOW }, { "B", QM_BLACK } }; } @@ -23,11 +23,11 @@ CustomMessage::~CustomMessage() { void CustomMessage::ReplaceSpecialCharacters(std::string& string) { // add special characters - for (auto specialCharacterPair : textBoxSpecialCharacters) { + for (auto specialCharacterPair : this->textBoxSpecialCharacters) { size_t start_pos = 0; - std::string textBoxSpecialCharacterString = ""; + std::string textBoxSpecialCharacterString = ""s; textBoxSpecialCharacterString += specialCharacterPair.second; - while ((start_pos = string.find(specialCharacterPair.first, start_pos)) != std::string::npos) { + while ((start_pos = string.find(specialCharacterPair.first, 0)) != std::string::npos) { string.replace(start_pos, specialCharacterPair.first.length(), textBoxSpecialCharacterString); start_pos += textBoxSpecialCharacterString.length(); } @@ -63,10 +63,7 @@ void CustomMessage::FormatCustomMessage(std::string& message, ItemID iid) { void CustomMessage::FormatCustomMessage(std::string& message) { size_t start_pos = 0; std::replace(message.begin(), message.end(), '&', NEWLINE()[0]); - while ((start_pos = message.find('^', start_pos)) != std::string::npos) { - message.replace(start_pos, 1, WAIT_FOR_INPUT()); - start_pos += 3; - } + std::replace(message.begin(), message.end(), '^', WAIT_FOR_INPUT()[0]); std::replace(message.begin(), message.end(), '@', PLAYER_NAME()[0]); ReplaceSpecialCharacters(message); ReplaceColors(message); diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index ec5914c07..5159de0da 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -17,6 +17,7 @@ #include using json = nlohmann::json; +using namespace std::literals::string_literals; std::unordered_map gSeedTextures; @@ -24,6 +25,7 @@ u8 generated; const std::string Randomizer::getItemMessageTableID = "Randomizer"; const std::string Randomizer::hintMessageTableID = "RandomizerHints"; +const std::string Randomizer::scrubMessageTableID = "RandomizerScrubs"; Randomizer::Randomizer() { Sprite bowSprite = { dgFairyBowIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b, 0 }; @@ -1822,6 +1824,25 @@ std::string AltarIconString(char iconChar) { std::string FormatJsonHintText(std::string jsonHint) { std::string formattedHintMessage = jsonHint; + + std::unordered_map textBoxSpecialCharacters = { + { "À", 0x80 }, { "î", 0x81 }, { "Â", 0x82 }, { "Ä", 0x83 }, { "Ç", 0x84 }, { "È", 0x85 }, { "É", 0x86 }, + { "Ê", 0x87 }, { "Ë", 0x88 }, { "Ï", 0x89 }, { "Ô", 0x8A }, { "Ö", 0x8B }, { "Ù", 0x8C }, { "Û", 0x8D }, + { "Ü", 0x8E }, { "ß", 0x8F }, { "à", 0x90 }, { "á", 0x91 }, { "â", 0x92 }, { "ä", 0x93 }, { "ç", 0x94 }, + { "è", 0x95 }, { "é", 0x96 }, { "ê", 0x97 }, { "ë", 0x98 }, { "ï", 0x99 }, { "ô", 0x9A }, { "ö", 0x9B }, + { "ù", 0x9C }, { "û", 0x9D }, { "ü", 0x9E } + }; + + // add special characters + for (auto specialCharacterPair : textBoxSpecialCharacters) { + size_t start_pos = 0; + std::string textBoxSpecialCharacterString = ""; + textBoxSpecialCharacterString += specialCharacterPair.second; + while ((start_pos = formattedHintMessage.find(specialCharacterPair.first, start_pos)) != std::string::npos) { + formattedHintMessage.replace(start_pos, specialCharacterPair.first.length(), textBoxSpecialCharacterString); + start_pos += textBoxSpecialCharacterString.length(); + } + } // add icons to altar text for (char iconChar : {'0', '1', '2', '3', '4', '5', '6', '7', '8', 'o', 'c', 'i', 'l', 'b', 'L', 'k'}) { @@ -4739,6 +4760,23 @@ void CreateGetItemMessages(std::vector messageEntries) { } } +void CreateScrubMessages() { + CustomMessage* customMessage = CustomMessage::Instance; + customMessage->AddCustomMessageTable(Randomizer::scrubMessageTableID); + const std::vector prices = { 10, 40 }; + for (u8 price : prices) { + customMessage->CreateMessage(Randomizer::scrubMessageTableID, price, + { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, + "\x12\x38\x82\All right! You win! In return for&sparing me, I will sell you a&%gmysterious item%w!&%r" + + std::to_string(price) + " Rupees%w it is!\x07\x10\xA3", + "\x12\x38\x82\All right! You win! In return for&sparing me, I will sell you a&%gmysterious item%w!&%r" + + std::to_string(price) + " Rupees%w it is!\x07\x10\xA3", + "\x12\x38\x82J'abandonne! Tu veux bien m'acheter&un %gobjet mystérieux%w?&Ça fera %r" + + std::to_string(price) + " Rubis%w!\x07\x10\xA3" + }); + } +} + #define GIMESSAGE(giid, iid, english, german, french) \ { giid, iid, english, german, french } @@ -4781,6 +4819,7 @@ void Randomizer::CreateCustomMessages() { "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this..."), }; CreateGetItemMessages(getItemMessages); + CreateScrubMessages(); } void InitRando() { diff --git a/soh/soh/Enhancements/randomizer/randomizer.h b/soh/soh/Enhancements/randomizer/randomizer.h index ec27d684d..a89c1f706 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.h +++ b/soh/soh/Enhancements/randomizer/randomizer.h @@ -28,6 +28,7 @@ class Randomizer { static const std::string getItemMessageTableID; static const std::string hintMessageTableID; + static const std::string scrubMessageTableID; static Sprite* GetSeedTexture(uint8_t index); s16 GetItemModelFromId(s16 itemId); diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 658ee9a5a..156fb4d77 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1401,6 +1401,20 @@ extern "C" RandomizerCheck Randomizer_GetCheckFromActor(s16 sceneNum, s16 actorI return OTRGlobals::Instance->gRandomizer->GetCheckFromActor(sceneNum, actorId, actorParams); } +extern "C" CustomMessageEntry Randomizer_CopyScrubMessage(u16 scrubTextId) { + int price = 0; + switch (scrubTextId) { + case 0x10A2: + price = 10; + break; + case 0x10DC: + case 0x10DD: + price = 40; + break; + } + return CustomMessage::Instance->RetrieveMessage(Randomizer::scrubMessageTableID, price); +} + extern "C" int CopyScrubMessage(u16 scrubTextId, char* buffer, const int maxBufferSize) { std::string scrubText(""); int language = CVar_GetS32("gLanguages", 0); @@ -1554,6 +1568,8 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { } else { messageEntry = Randomizer_CopyGanonHintText(); } + } else if (textId == 0x10A2 || textId == 0x10DC || textId == 0x10DD) { + messageEntry = Randomizer_CopyScrubMessage(textId); } } if (textId == 0x00B4 || textId == 0x00B5) { diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index 57eafa1d7..3da2a0fc8 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1675,13 +1675,9 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { //font->msgLength, __FILE__, __LINE__); } else { Message_FindMessage(globalCtx, textId); - if (gSaveContext.n64ddFlag && (textId == 0x10A2 || textId == 0x10DC || textId == 0x10DD)) { - msgCtx->msgLength = font->msgLength = CopyScrubMessage(textId, font->msgBuf, sizeof(font->msgBuf)); - } else { - msgCtx->msgLength = font->msgLength; - char* src = (uintptr_t)font->msgOffset; - memcpy(font->msgBuf, src, font->msgLength); - } + msgCtx->msgLength = font->msgLength; + char* src = (uintptr_t)font->msgOffset; + memcpy(font->msgBuf, src, font->msgLength); } msgCtx->textBoxProperties = font->charTexBuf[0];