From e9ba8f734f0fb8652e67c6ec7e6f8edd69745c72 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Wed, 13 Jul 2022 20:35:42 -0400 Subject: [PATCH 01/39] Early version of custom messages. --- soh/soh/Enhancements/randomizer/randomizer.cpp | 11 +++++++++++ soh/soh/Enhancements/randomizer/randomizer.h | 1 + soh/soh/OTRGlobals.cpp | 5 +++++ soh/soh/OTRGlobals.h | 1 + soh/src/code/z_message_PAL.c | 3 +++ 5 files changed, 21 insertions(+) diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 43e278ab5..50f90ee5e 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -2419,6 +2419,17 @@ GetItemID Randomizer::GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomiz return GetItemFromGet(this->itemLocations[randomizerCheck], ogId); } +std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { + if (!gSaveContext.n64ddFlag) { + return "Not Randomized."; + } + + switch (giid) { + default: + "There is no custom message for this item."; + } +} + RandomizerCheck Randomizer::GetCheckFromActor(s16 sceneNum, s16 actorId, s16 actorParams) { if (!gSaveContext.n64ddFlag) { return RC_UNKNOWN_CHECK; diff --git a/soh/soh/Enhancements/randomizer/randomizer.h b/soh/soh/Enhancements/randomizer/randomizer.h index 5fe2e0ae4..5d67c8692 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.h +++ b/soh/soh/Enhancements/randomizer/randomizer.h @@ -42,6 +42,7 @@ class Randomizer { std::string GetHintFromCheck(RandomizerCheck check); GetItemID GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); GetItemID GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); + std::string GetCustomGetItemMessage(GetItemID giid); }; #ifdef __cplusplus diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 3a862d58a..265909e5c 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1528,3 +1528,8 @@ extern "C" s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, extern "C" s32 GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId) { return OTRGlobals::Instance->gRandomizer->GetRandomizedItemIdFromKnownCheck(randomizerCheck, ogId); } + +extern "C" int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize) { + const std::string& getItemText = OTRGlobals::Instance->gRandomizer->GetCustomGetItemMessage(giid); + return CopyStringToCharBuffer(getItemText, buffer, maxBufferSize); +} diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 7c56e54c1..bf0384be1 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -99,6 +99,7 @@ s16 GetItemModelFromId(s16 itemId); s32 GetItemIDFromGetItemID(s32 getItemId); s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); s32 GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); +int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize); #endif #endif diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index 9cf592e4f..46b8b7e94 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1735,6 +1735,9 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { } else { msgCtx->msgLength = font->msgLength = CopyGanonHintText(font->msgBuf, sizeof(font->msgBuf)); } + } else if (gSaveContext.n64ddFlag && textId == 0xF8) { + msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( + GET_PLAYER(globalCtx)->getItemId, font->msgBuf, sizeof(font->msgBuf)); } else { msgCtx->msgLength = font->msgLength; char* src = (uintptr_t)font->msgOffset; From 14a87f83b3f93051fec0b2d7009f61bd5b4c736a Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Wed, 13 Jul 2022 21:24:20 -0400 Subject: [PATCH 02/39] Makes sure custom get item textboxes match. Specifically, they are all bottom of the screen and blue. --- soh/src/code/z_message_PAL.c | 1 + 1 file changed, 1 insertion(+) diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index 46b8b7e94..87bc255ab 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1738,6 +1738,7 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { } else if (gSaveContext.n64ddFlag && textId == 0xF8) { msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( GET_PLAYER(globalCtx)->getItemId, font->msgBuf, sizeof(font->msgBuf)); + font->charTexBuf[0] = 0x23; } else { msgCtx->msgLength = font->msgLength; char* src = (uintptr_t)font->msgOffset; From d9277530a2d0fb2308bd00a617efbf728b6bfa70 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Wed, 13 Jul 2022 23:35:45 -0400 Subject: [PATCH 03/39] Refactors custom message code to its own file --- .../randomizer/custom_messages.cpp | 39 +++++++++++++++++++ .../Enhancements/randomizer/custom_messages.h | 19 +++++++++ .../Enhancements/randomizer/randomizer.cpp | 11 ------ 3 files changed, 58 insertions(+), 11 deletions(-) create mode 100644 soh/soh/Enhancements/randomizer/custom_messages.cpp create mode 100644 soh/soh/Enhancements/randomizer/custom_messages.h diff --git a/soh/soh/Enhancements/randomizer/custom_messages.cpp b/soh/soh/Enhancements/randomizer/custom_messages.cpp new file mode 100644 index 000000000..389ae0e9e --- /dev/null +++ b/soh/soh/Enhancements/randomizer/custom_messages.cpp @@ -0,0 +1,39 @@ +#include "custom_messages.h" +#include + +using namespace std::literals::string_literals; + +std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { + if (!gSaveContext.n64ddFlag) { + return "Not Randomized."; + } + + switch (giid) { + default: + switch (gSaveContext.language) { + case LANGUAGE_FRA: + return "Il n'y a pas de message personnalis pour cet lment."; + case LANGUAGE_GER: + return "Fr diesen Artikel gibt es keine benutzerdefinierte Nachricht."; + case LANGUAGE_ENG: + default: + return "There is no custom message for this item."; + } + } +} + +std::string MESSAGE_END() { + return "\x02"s; +} + +std::string ITEM_OBTAINED(uint8_t x) { + return "\x08\x13"s + char(x); +} + +std::string NEWLINE() { + return "\x02"s; +} + +std::string COLOR(uint8_t x) { + return "\x05"s + char(x); +} \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/custom_messages.h b/soh/soh/Enhancements/randomizer/custom_messages.h new file mode 100644 index 000000000..5e208f7e7 --- /dev/null +++ b/soh/soh/Enhancements/randomizer/custom_messages.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include "../../../include/z64item.h" +#include "randomizer.h" + +#define QM_WHITE 0x00 +#define QM_RED 0x41 +#define QM_GREEN 0x42 +#define QM_BLUE 0x43 +#define QM_LBLUE 0x44 +#define QM_PINK 0x45 +#define QM_YELLOW 0x46 +#define QM_BLACK 0x47 + +std::string MESSAGE_END(); +std::string ITEM_OBTAINED(uint8_t x); +std::string NEWLINE(); +std::string COLOR(uint8_t x); \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 50f90ee5e..43e278ab5 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -2419,17 +2419,6 @@ GetItemID Randomizer::GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomiz return GetItemFromGet(this->itemLocations[randomizerCheck], ogId); } -std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { - if (!gSaveContext.n64ddFlag) { - return "Not Randomized."; - } - - switch (giid) { - default: - "There is no custom message for this item."; - } -} - RandomizerCheck Randomizer::GetCheckFromActor(s16 sceneNum, s16 actorId, s16 actorParams) { if (!gSaveContext.n64ddFlag) { return RC_UNKNOWN_CHECK; From a81ecfcfcca19841ea033d9c02788dc574b334ce Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Thu, 14 Jul 2022 00:41:04 -0400 Subject: [PATCH 04/39] Renames the separated custom messages files to prevent conflict. --- soh/soh.vcxproj | 2 ++ .../{custom_messages.cpp => randomizer_custom_messages.cpp} | 2 +- .../{custom_messages.h => randomizer_custom_messages.h} | 0 3 files changed, 3 insertions(+), 1 deletion(-) rename soh/soh/Enhancements/randomizer/{custom_messages.cpp => randomizer_custom_messages.cpp} (95%) rename soh/soh/Enhancements/randomizer/{custom_messages.h => randomizer_custom_messages.h} (100%) diff --git a/soh/soh.vcxproj b/soh/soh.vcxproj index 5f7ea818f..22c44a1b8 100644 --- a/soh/soh.vcxproj +++ b/soh/soh.vcxproj @@ -235,6 +235,7 @@ + @@ -983,6 +984,7 @@ + diff --git a/soh/soh/Enhancements/randomizer/custom_messages.cpp b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp similarity index 95% rename from soh/soh/Enhancements/randomizer/custom_messages.cpp rename to soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp index 389ae0e9e..b5caad7fc 100644 --- a/soh/soh/Enhancements/randomizer/custom_messages.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp @@ -1,4 +1,4 @@ -#include "custom_messages.h" +#include "randomizer_custom_messages.h" #include using namespace std::literals::string_literals; diff --git a/soh/soh/Enhancements/randomizer/custom_messages.h b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h similarity index 100% rename from soh/soh/Enhancements/randomizer/custom_messages.h rename to soh/soh/Enhancements/randomizer/randomizer_custom_messages.h From cd096ce5e977f3e0098ec8b3740a6cddf4df3a47 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Thu, 14 Jul 2022 00:56:47 -0400 Subject: [PATCH 05/39] Fixes newline function to return correct character. --- soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp | 3 ++- soh/soh/Enhancements/randomizer/randomizer_custom_messages.h | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp index b5caad7fc..b52721cff 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp @@ -1,4 +1,5 @@ #include "randomizer_custom_messages.h" +#include "randomizer.h" #include using namespace std::literals::string_literals; @@ -31,7 +32,7 @@ std::string ITEM_OBTAINED(uint8_t x) { } std::string NEWLINE() { - return "\x02"s; + return "\x01"s; } std::string COLOR(uint8_t x) { diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h index 5e208f7e7..15cd859af 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h @@ -2,7 +2,6 @@ #include #include "../../../include/z64item.h" -#include "randomizer.h" #define QM_WHITE 0x00 #define QM_RED 0x41 From 46df17e29fbf2e18b92493ff0dc84d9a6ce16c84 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Thu, 14 Jul 2022 11:17:43 -0400 Subject: [PATCH 06/39] Added an extra helper function and removed instant text control code from ITEM_OBTAINED --- .../Enhancements/randomizer/randomizer_custom_messages.cpp | 6 +++++- .../Enhancements/randomizer/randomizer_custom_messages.h | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp index b52721cff..a70461135 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp @@ -28,7 +28,7 @@ std::string MESSAGE_END() { } std::string ITEM_OBTAINED(uint8_t x) { - return "\x08\x13"s + char(x); + return "\x13"s + char(x); } std::string NEWLINE() { @@ -37,4 +37,8 @@ std::string NEWLINE() { std::string COLOR(uint8_t x) { return "\x05"s + char(x); +} + +std::string WAIT_FOR_INPUT() { + return "\x04"s; } \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h index 15cd859af..cae3c65b5 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h @@ -15,4 +15,5 @@ std::string MESSAGE_END(); std::string ITEM_OBTAINED(uint8_t x); std::string NEWLINE(); -std::string COLOR(uint8_t x); \ No newline at end of file +std::string COLOR(uint8_t x); +std::string WAIT_FOR_INPUT(); \ No newline at end of file From 3f2111a3e61169f95248a7e549f0e7466f429d91 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Fri, 15 Jul 2022 19:48:49 -0400 Subject: [PATCH 07/39] Adds text for Bottle with Blue Fire as a demo. --- .../randomizer/randomizer_custom_messages.cpp | 10 ++++++++++ soh/src/overlays/actors/ovl_player_actor/z_player.c | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp index a70461135..659e68fe8 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp @@ -10,6 +10,16 @@ std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { } switch (giid) { + case GI_BOTTLE_WITH_BLUE_FIRE: + switch (gSaveContext.language) { + case LANGUAGE_FRA: + case LANGUAGE_GER: + case LANGUAGE_ENG: + default: + return ITEM_OBTAINED(ITEM_BLUE_FIRE) + "You got a " + COLOR(QM_RED) + "Bottle with Blue " + + NEWLINE() + "Fire" + COLOR(QM_WHITE) + "! Use it to melt Red Ice!" + + MESSAGE_END(); + } default: switch (gSaveContext.language) { case LANGUAGE_FRA: diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 1973a09a4..c27b78ee8 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -657,7 +657,7 @@ static GetItemEntry sGetItemTable[] = { GET_ITEM(ITEM_BOTTLE_WITH_BLUE_POTION, OBJECT_GI_LIQUID, GID_POTION_BLUE, 0x45, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_FAIRY, OBJECT_GI_BOTTLE, GID_BOTTLE, 0x46, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_FISH, OBJECT_GI_FISH, GID_FISH, 0x47, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BLUE_FIRE, OBJECT_GI_FIRE, GID_BLUE_FIRE, 0x5D, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BLUE_FIRE, OBJECT_GI_FIRE, GID_BLUE_FIRE, 0xF8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_BUGS, OBJECT_GI_INSECT, GID_BUG, 0x7A, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_POE, OBJECT_GI_GHOST, GID_POE, 0x97, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_BIG_POE, OBJECT_GI_GHOST, GID_BIG_POE, 0xF9, 0x80, CHEST_ANIM_LONG), From 4eaf70b85901c10e9f3728ea17195d72c3fb21cd Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 17 Jul 2022 12:34:56 -0400 Subject: [PATCH 08/39] Refactors CustomMessages to not be rando specific. Pulls the Custom Message related code out into it's own class, which has an initialization phase where other enhancements / future features can create messages during an initialization phase to be stored and retrieved later. Along with this refactoring, the 4 bottle messages from the previous rando-specific system are now created and stored during intialization and retrieved by their getItemId. Now that it isn't rando specific, the goal is to move anything text changes that are hard-coded into z_message_PAL.c and refactor it so that future text additions/overrides can be done without modifying that file. --- soh/soh.vcxproj | 4 +- .../custom_message/CustomMessage.cpp | 108 ++++++++++++++++++ .../custom_message/CustomMessage.h | 39 +++++++ .../Enhancements/randomizer/randomizer.cpp | 1 + soh/soh/Enhancements/randomizer/randomizer.h | 2 + .../randomizer/randomizer_custom_messages.cpp | 67 ++++------- .../randomizer/randomizer_custom_messages.h | 19 --- soh/soh/OTRGlobals.cpp | 3 + soh/soh/OTRGlobals.h | 1 - .../actors/ovl_player_actor/z_player.c | 8 +- 10 files changed, 182 insertions(+), 70 deletions(-) create mode 100644 soh/soh/Enhancements/custom_message/CustomMessage.cpp create mode 100644 soh/soh/Enhancements/custom_message/CustomMessage.h delete mode 100644 soh/soh/Enhancements/randomizer/randomizer_custom_messages.h diff --git a/soh/soh.vcxproj b/soh/soh.vcxproj index 037539b2a..43054c711 100644 --- a/soh/soh.vcxproj +++ b/soh/soh.vcxproj @@ -179,6 +179,7 @@ + @@ -942,9 +943,9 @@ - + @@ -985,7 +986,6 @@ - diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.cpp b/soh/soh/Enhancements/custom_message/CustomMessage.cpp new file mode 100644 index 000000000..1985a2bbc --- /dev/null +++ b/soh/soh/Enhancements/custom_message/CustomMessage.cpp @@ -0,0 +1,108 @@ +#include "CustomMessage.h" +#include + +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->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 } }; +} + +CustomMessage::~CustomMessage() { + this->textBoxSpecialCharacters.clear(); +} + +void CustomMessage::ReplaceSpecialCharacters(std::string& string) { + // add special characters + for (auto specialCharacterPair : textBoxSpecialCharacters) { + size_t start_pos = 0; + std::string textBoxSpecialCharacterString = ""; + textBoxSpecialCharacterString += specialCharacterPair.second; + while ((start_pos = string.find(specialCharacterPair.first, start_pos)) != std::string::npos) { + string.replace(start_pos, specialCharacterPair.first.length(), textBoxSpecialCharacterString); + start_pos += textBoxSpecialCharacterString.length(); + } + } +} + +void CustomMessage::ReplaceColors(std::string& string) { + for (auto colorPair : colors) { + std::string textToReplace = "%"; + textToReplace += colorPair.first; + size_t start_pos = 0; + while ((start_pos = string.find(textToReplace)) != std::string::npos) { + string.replace(start_pos, textToReplace.length(), COLOR(colorPair.second)); + start_pos += textToReplace.length(); + } + } +} + +void CustomMessage::CreateGetItemMessage(GetItemID giid, ItemID iid, std::string messages[LANGUAGE_MAX]) { + for (int i = 0; i < LANGUAGE_MAX; i++) { + if (!(messages[i].empty())) { + std::string message = messages[i]; + std::string formattedMessage = ITEM_OBTAINED(iid) + message; + size_t start_pos = 0; + std::replace(formattedMessage.begin(), formattedMessage.end(), '&', NEWLINE()[0]); + while ((start_pos = formattedMessage.find('^', start_pos)) != std::string::npos) { + formattedMessage.replace(start_pos, 1, WAIT_FOR_INPUT() + ITEM_OBTAINED(iid)); + start_pos += 3; + } + std::replace(formattedMessage.begin(), formattedMessage.end(), '@', PLAYER_NAME()[0]); + ReplaceSpecialCharacters(formattedMessage); + ReplaceColors(formattedMessage); + formattedMessage += MESSAGE_END(); + this->getItemMessageTable[i].emplace(giid, formattedMessage); + } else { + this->getItemMessageTable[i].emplace(giid, MESSAGE_END()); + } + } +} + +std::string CustomMessage::RetrieveGetItemMessage(GetItemID giid) { + std::unordered_map::const_iterator result = + getItemMessageTable[gSaveContext.language].find(giid); + if (result == getItemMessageTable[gSaveContext.language].end()) { + switch (gSaveContext.language) { + case LANGUAGE_FRA: + return "Il n'y a pas de message personnalis pour cet lment."; + case LANGUAGE_GER: + return "Fr diesen Artikel gibt es keine benutzerdefinierte Nachricht."; + case LANGUAGE_ENG: + default: + return "There is no custom message for this item."; + } + } + return result->second; +} + +std::string CustomMessage::MESSAGE_END() { + return "\x02"s; +} + +std::string CustomMessage::ITEM_OBTAINED(uint8_t x) { + return "\x13"s + char(x); +} + +std::string CustomMessage::NEWLINE() { + return "\x01"s; +} + +std::string CustomMessage::COLOR(uint8_t x) { + return "\x05"s + char(x); +} + +std::string CustomMessage::WAIT_FOR_INPUT() { + return "\x04"s; +} + +std::string CustomMessage::PLAYER_NAME() { + return "\x0F"s; +} \ No newline at end of file diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.h b/soh/soh/Enhancements/custom_message/CustomMessage.h new file mode 100644 index 000000000..d8cfd8e0d --- /dev/null +++ b/soh/soh/Enhancements/custom_message/CustomMessage.h @@ -0,0 +1,39 @@ +#pragma once +#include +#include +#include "variables.h" + +#define QM_WHITE 0x00 +#define QM_RED 0x41 +#define QM_GREEN 0x42 +#define QM_BLUE 0x43 +#define QM_LBLUE 0x44 +#define QM_PINK 0x45 +#define QM_YELLOW 0x46 +#define QM_BLACK 0x47 + +class CustomMessage { + private: + std::unordered_map textBoxSpecialCharacters; + std::unordered_map colors; + std::unordered_map getItemMessageTable[LANGUAGE_MAX]; + + void ReplaceSpecialCharacters(std::string &string); + void ReplaceColors(std::string& string); + + std::string MESSAGE_END(); + std::string ITEM_OBTAINED(uint8_t x); + std::string NEWLINE(); + std::string COLOR(uint8_t x); + std::string WAIT_FOR_INPUT(); + std::string PLAYER_NAME(); + + public: + static CustomMessage* Instance; + + CustomMessage(); + ~CustomMessage(); + + void CreateGetItemMessage(GetItemID giid, ItemID iid, std::string messages[LANGUAGE_MAX]); + std::string RetrieveGetItemMessage(GetItemID giid); +}; \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 09704e867..4c589ea48 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -4748,6 +4748,7 @@ void DrawRandoEditor(bool& open) { void InitRando() { SohImGui::AddWindow("Randomizer", "Randomizer Settings", DrawRandoEditor); + Randomizer::CreateCustomMessages(); } extern "C" { diff --git a/soh/soh/Enhancements/randomizer/randomizer.h b/soh/soh/Enhancements/randomizer/randomizer.h index 180d91691..6f928bd66 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.h +++ b/soh/soh/Enhancements/randomizer/randomizer.h @@ -5,6 +5,7 @@ #include "../../../include/ultra64.h" #include "../../../include/z64item.h" #include +#include class Randomizer { private: @@ -42,6 +43,7 @@ class Randomizer { GetItemID GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); GetItemID GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); std::string GetCustomGetItemMessage(GetItemID giid); + static void CreateCustomMessages(); }; #ifdef __cplusplus diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp index 659e68fe8..a31edcbee 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp @@ -1,54 +1,33 @@ -#include "randomizer_custom_messages.h" #include "randomizer.h" -#include +#include "soh/Enhancements/custom_message/CustomMessage.h" using namespace std::literals::string_literals; +#define MESSAGES(eng, ger, fra) (new std::string[]{eng, ger, fra}) + +void Randomizer::CreateCustomMessages() { + CustomMessage* customMessage = CustomMessage::Instance; + customMessage->CreateGetItemMessage( + GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, + MESSAGES("You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", "", "")); + customMessage->CreateGetItemMessage( + GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, + MESSAGES("You got a %rBig Poe in a bottle%w!&Sell it to the Ghost Shop!", "", "")); + customMessage->CreateGetItemMessage( + GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, + MESSAGES("You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", "", "")); + customMessage->CreateGetItemMessage( + GI_BOTTLE_WITH_FISH, ITEM_FISH, + MESSAGES("You got a %rFish in a bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", "", + "")); + + +} + std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { if (!gSaveContext.n64ddFlag) { return "Not Randomized."; } - switch (giid) { - case GI_BOTTLE_WITH_BLUE_FIRE: - switch (gSaveContext.language) { - case LANGUAGE_FRA: - case LANGUAGE_GER: - case LANGUAGE_ENG: - default: - return ITEM_OBTAINED(ITEM_BLUE_FIRE) + "You got a " + COLOR(QM_RED) + "Bottle with Blue " + - NEWLINE() + "Fire" + COLOR(QM_WHITE) + "! Use it to melt Red Ice!" + - MESSAGE_END(); - } - default: - switch (gSaveContext.language) { - case LANGUAGE_FRA: - return "Il n'y a pas de message personnalis pour cet lment."; - case LANGUAGE_GER: - return "Fr diesen Artikel gibt es keine benutzerdefinierte Nachricht."; - case LANGUAGE_ENG: - default: - return "There is no custom message for this item."; - } - } -} - -std::string MESSAGE_END() { - return "\x02"s; -} - -std::string ITEM_OBTAINED(uint8_t x) { - return "\x13"s + char(x); -} - -std::string NEWLINE() { - return "\x01"s; -} - -std::string COLOR(uint8_t x) { - return "\x05"s + char(x); -} - -std::string WAIT_FOR_INPUT() { - return "\x04"s; + return CustomMessage::Instance->RetrieveGetItemMessage(giid); } \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h deleted file mode 100644 index cae3c65b5..000000000 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include "../../../include/z64item.h" - -#define QM_WHITE 0x00 -#define QM_RED 0x41 -#define QM_GREEN 0x42 -#define QM_BLUE 0x43 -#define QM_LBLUE 0x44 -#define QM_PINK 0x45 -#define QM_YELLOW 0x46 -#define QM_BLACK 0x47 - -std::string MESSAGE_END(); -std::string ITEM_OBTAINED(uint8_t x); -std::string NEWLINE(); -std::string COLOR(uint8_t x); -std::string WAIT_FOR_INPUT(); \ No newline at end of file diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 5ec051af0..6691127be 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -38,6 +38,7 @@ #include "Enhancements/debugger/debugger.h" #include "Enhancements/randomizer/randomizer.h" #include +#include #include "Enhancements/n64_weird_frame_data.inc" #include "soh/frame_interpolation.h" #include "Utils/BitConverter.h" @@ -55,6 +56,7 @@ OTRGlobals* OTRGlobals::Instance; SaveManager* SaveManager::Instance; +CustomMessage* CustomMessage::Instance; OTRGlobals::OTRGlobals() { context = Ship::GlobalCtx2::CreateInstance("Ship of Harkinian"); @@ -106,6 +108,7 @@ extern "C" void OTRExtScanner() { extern "C" void InitOTR() { OTRGlobals::Instance = new OTRGlobals(); SaveManager::Instance = new SaveManager(); + CustomMessage::Instance = new CustomMessage(); auto t = OTRGlobals::Instance->context->GetResourceManager()->LoadFile("version"); if (!t->bHasLoadError) diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 1cb90fc91..d999f1bda 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -9,7 +9,6 @@ #ifdef __cplusplus #include "Enhancements/savestates.h" #include "Enhancements/randomizer/randomizer.h" - class OTRGlobals { public: diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index c27b78ee8..15ff2e7d8 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -654,13 +654,13 @@ static GetItemEntry sGetItemTable[] = { GET_ITEM(ITEM_BOTTLE_WITH_RED_POTION, OBJECT_GI_LIQUID, GID_POTION_RED, 0x43, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_GREEN_POTION, OBJECT_GI_LIQUID, GID_POTION_GREEN, 0x44, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BLUE_POTION, OBJECT_GI_LIQUID, GID_POTION_BLUE, 0x45, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BLUE_POTION, OBJECT_GI_LIQUID, GID_POTION_BLUE, 0xF8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_FAIRY, OBJECT_GI_BOTTLE, GID_BOTTLE, 0x46, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_FISH, OBJECT_GI_FISH, GID_FISH, 0x47, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_FISH, OBJECT_GI_FISH, GID_FISH, 0xF8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_BLUE_FIRE, OBJECT_GI_FIRE, GID_BLUE_FIRE, 0xF8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_BUGS, OBJECT_GI_INSECT, GID_BUG, 0x7A, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_POE, OBJECT_GI_GHOST, GID_POE, 0x97, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BIG_POE, OBJECT_GI_GHOST, GID_BIG_POE, 0xF9, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_POE, OBJECT_GI_GHOST, GID_POE, 0xF8, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BIG_POE, OBJECT_GI_GHOST, GID_BIG_POE, 0xF8, 0x80, CHEST_ANIM_LONG), GET_ITEM_NONE, GET_ITEM_NONE, From f57a912ca12bde7f780d7c012c7af6b72ed3a7e7 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 17 Jul 2022 13:31:38 -0400 Subject: [PATCH 09/39] Does some cleanup of unecessary code and cases of no string provided. --- .../Enhancements/custom_message/CustomMessage.cpp | 12 +----------- .../randomizer/randomizer_custom_messages.cpp | 2 -- soh/soh/OTRGlobals.cpp | 3 +++ 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.cpp b/soh/soh/Enhancements/custom_message/CustomMessage.cpp index 1985a2bbc..80340801d 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessage.cpp @@ -60,8 +60,6 @@ void CustomMessage::CreateGetItemMessage(GetItemID giid, ItemID iid, std::string ReplaceColors(formattedMessage); formattedMessage += MESSAGE_END(); this->getItemMessageTable[i].emplace(giid, formattedMessage); - } else { - this->getItemMessageTable[i].emplace(giid, MESSAGE_END()); } } } @@ -70,15 +68,7 @@ std::string CustomMessage::RetrieveGetItemMessage(GetItemID giid) { std::unordered_map::const_iterator result = getItemMessageTable[gSaveContext.language].find(giid); if (result == getItemMessageTable[gSaveContext.language].end()) { - switch (gSaveContext.language) { - case LANGUAGE_FRA: - return "Il n'y a pas de message personnalis pour cet lment."; - case LANGUAGE_GER: - return "Fr diesen Artikel gibt es keine benutzerdefinierte Nachricht."; - case LANGUAGE_ENG: - default: - return "There is no custom message for this item."; - } + return ""; } return result->second; } diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp index a31edcbee..61a2559ac 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp @@ -1,8 +1,6 @@ #include "randomizer.h" #include "soh/Enhancements/custom_message/CustomMessage.h" -using namespace std::literals::string_literals; - #define MESSAGES(eng, ger, fra) (new std::string[]{eng, ger, fra}) void Randomizer::CreateCustomMessages() { diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 6691127be..4459e3b19 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1507,5 +1507,8 @@ extern "C" s32 GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck extern "C" int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize) { const std::string& getItemText = OTRGlobals::Instance->gRandomizer->GetCustomGetItemMessage(giid); + if (getItemText == "") { + return false; + } return CopyStringToCharBuffer(getItemText, buffer, maxBufferSize); } From 69d2b5b3a32ae7a89caf907a6b5e329ab7a63b17 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 17 Jul 2022 15:02:08 -0400 Subject: [PATCH 10/39] Implements function to return custom message if one exists. `CustomMessage_RetrieveIfExists` is placed at the very beginning of the z_message_PAL.c `Message_OpenText` if statement after any special changes to textIds are made. This function will either return either true or false and if true it will populate the necessary values of font and msgCtx to display said message. It's placement at the beginning also allows for overriding existing textIds to have new information, which will come in handy later. --- soh/soh/OTRGlobals.cpp | 29 +++++++++++++++++++++++++++++ soh/soh/OTRGlobals.h | 1 + soh/src/code/z_message_PAL.c | 8 +++++--- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 4459e3b19..549b69ed1 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1512,3 +1512,32 @@ extern "C" int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, } return CopyStringToCharBuffer(getItemText, buffer, maxBufferSize); } + +extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx, char* buffer, const int maxBufferSize) { + MessageContext* msgCtx = &globalCtx->msgCtx; + Font* font = &msgCtx->font; + if (gSaveContext.n64ddFlag) { + if (msgCtx->textId == 0xF8) { + if (msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( + (GetItemID)GET_PLAYER(globalCtx)->getItemId, font->msgBuf, sizeof(font->msgBuf))) { + font->charTexBuf[0] = 0x23; + return true; + } else { + switch (gSaveContext.language) { + case LANGUAGE_FRA: + return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer( + "Il n'y a pas de message personnalisé pour cet élément.", buffer, maxBufferSize); + case LANGUAGE_GER: + return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer( + "Für diesen Artikel gibt es keine benutzerdefinierte Nachricht.", buffer, + maxBufferSize); + case LANGUAGE_ENG: + default: + return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer( + "There is no custom message for this item.", buffer, maxBufferSize); + } + } + } + } + return false; +} diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index d999f1bda..0110d7ad1 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -97,6 +97,7 @@ s32 GetItemIDFromGetItemID(s32 getItemId); s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); s32 GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize); +int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx, char* buffer, const int maxBufferSize); #endif #endif diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index 87bc255ab..432c05cfd 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1662,7 +1662,9 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { gSaveContext.eventInf[0] = gSaveContext.eventInf[1] = gSaveContext.eventInf[2] = gSaveContext.eventInf[3] = 0; } - if (sTextIsCredits) { + if (CustomMessage_RetrieveIfExists(globalCtx, font->msgBuf, sizeof(font->msgBuf))) { + osSyncPrintf("Found custom message"); + } else if (sTextIsCredits) { Message_FindCreditsMessage(globalCtx, textId); msgCtx->msgLength = font->msgLength; char* src = (uintptr_t)font->msgOffset; @@ -1735,11 +1737,11 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { } else { msgCtx->msgLength = font->msgLength = CopyGanonHintText(font->msgBuf, sizeof(font->msgBuf)); } - } else if (gSaveContext.n64ddFlag && textId == 0xF8) { + } /*else if (gSaveContext.n64ddFlag && textId == 0xF8) { msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( GET_PLAYER(globalCtx)->getItemId, font->msgBuf, sizeof(font->msgBuf)); font->charTexBuf[0] = 0x23; - } else { + }*/ else { msgCtx->msgLength = font->msgLength; char* src = (uintptr_t)font->msgOffset; memcpy(font->msgBuf, src, font->msgLength); From 98c771cf2c35af469d84e018ac1987e56e524659 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 17 Jul 2022 15:11:16 -0400 Subject: [PATCH 11/39] Simplifies the function signature of `CustomMessage_RetrieveIfExists`. --- soh/soh/OTRGlobals.cpp | 6 ++++-- soh/soh/OTRGlobals.h | 2 +- soh/src/code/z_message_PAL.c | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 549b69ed1..36101e05e 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1513,13 +1513,15 @@ extern "C" int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, return CopyStringToCharBuffer(getItemText, buffer, maxBufferSize); } -extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx, char* buffer, const int maxBufferSize) { +extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { MessageContext* msgCtx = &globalCtx->msgCtx; Font* font = &msgCtx->font; + char* buffer = font->msgBuf; + const int maxBufferSize = sizeof(font->msgBuf); if (gSaveContext.n64ddFlag) { if (msgCtx->textId == 0xF8) { if (msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( - (GetItemID)GET_PLAYER(globalCtx)->getItemId, font->msgBuf, sizeof(font->msgBuf))) { + (GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize)) { font->charTexBuf[0] = 0x23; return true; } else { diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 0110d7ad1..8f46d13fc 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -97,7 +97,7 @@ s32 GetItemIDFromGetItemID(s32 getItemId); s32 GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); s32 GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize); -int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx, char* buffer, const int maxBufferSize); +int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx); #endif #endif diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index 432c05cfd..f0ce90fbd 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1662,7 +1662,7 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { gSaveContext.eventInf[0] = gSaveContext.eventInf[1] = gSaveContext.eventInf[2] = gSaveContext.eventInf[3] = 0; } - if (CustomMessage_RetrieveIfExists(globalCtx, font->msgBuf, sizeof(font->msgBuf))) { + if (CustomMessage_RetrieveIfExists(globalCtx)) { osSyncPrintf("Found custom message"); } else if (sTextIsCredits) { Message_FindCreditsMessage(globalCtx, textId); From ee1270f346b429d3c247cd4b4bb80fe29f9ba76f Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 17 Jul 2022 15:29:02 -0400 Subject: [PATCH 12/39] more cleanup --- soh/soh/OTRGlobals.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 36101e05e..d4a78fb34 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1515,11 +1515,12 @@ extern "C" int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { MessageContext* msgCtx = &globalCtx->msgCtx; + uint16_t textId = msgCtx->textId; Font* font = &msgCtx->font; char* buffer = font->msgBuf; const int maxBufferSize = sizeof(font->msgBuf); if (gSaveContext.n64ddFlag) { - if (msgCtx->textId == 0xF8) { + if (textId == 0xF8) { if (msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( (GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize)) { font->charTexBuf[0] = 0x23; @@ -1528,15 +1529,15 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { switch (gSaveContext.language) { case LANGUAGE_FRA: return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer( - "Il n'y a pas de message personnalisé pour cet élément.", buffer, maxBufferSize); + "Il n'y a pas de message personnalisé pour cet élément.\x02", buffer, maxBufferSize); case LANGUAGE_GER: return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer( - "Für diesen Artikel gibt es keine benutzerdefinierte Nachricht.", buffer, + "Für diesen Artikel gibt es keine benutzerdefinierte Nachricht.\x02", buffer, maxBufferSize); case LANGUAGE_ENG: default: return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer( - "There is no custom message for this item.", buffer, maxBufferSize); + "There is no custom message for this item.\x02", buffer, maxBufferSize); } } } From 1ed45e1433ab25b7e0487df837cd1ed2fae053cc Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 17 Jul 2022 21:03:32 -0400 Subject: [PATCH 13/39] Implements adding message tables and retrieving by an ID. Basically, some external code can choos a unique id and create a message table for itself. The idea is that modders can hook into this as well so they can get their own message table and don't have to worry about conflicting with the base game's textIDs. I have also implemented this setup for Randomizer so that the pre-filled bottles (which didn't exist in the original outside of Ruto's letter) have unique text as compared to the text for the item they are filled with. --- .../custom_message/CustomMessage.cpp | 78 +++++++++++++------ .../custom_message/CustomMessage.h | 16 +++- .../Enhancements/randomizer/randomizer.cpp | 2 + soh/soh/Enhancements/randomizer/randomizer.h | 1 + .../randomizer/randomizer_custom_messages.cpp | 35 ++++++--- soh/soh/OTRGlobals.cpp | 2 +- .../actors/ovl_player_actor/z_player.c | 8 +- 7 files changed, 99 insertions(+), 43 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.cpp b/soh/soh/Enhancements/custom_message/CustomMessage.cpp index 80340801d..d513c8286 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessage.cpp @@ -17,6 +17,8 @@ CustomMessage::CustomMessage() { CustomMessage::~CustomMessage() { this->textBoxSpecialCharacters.clear(); + this->colors.clear(); + this->messageTables.clear(); } void CustomMessage::ReplaceSpecialCharacters(std::string& string) { @@ -44,33 +46,61 @@ void CustomMessage::ReplaceColors(std::string& string) { } } -void CustomMessage::CreateGetItemMessage(GetItemID giid, ItemID iid, std::string messages[LANGUAGE_MAX]) { - for (int i = 0; i < LANGUAGE_MAX; i++) { - if (!(messages[i].empty())) { - std::string message = messages[i]; - std::string formattedMessage = ITEM_OBTAINED(iid) + message; - size_t start_pos = 0; - std::replace(formattedMessage.begin(), formattedMessage.end(), '&', NEWLINE()[0]); - while ((start_pos = formattedMessage.find('^', start_pos)) != std::string::npos) { - formattedMessage.replace(start_pos, 1, WAIT_FOR_INPUT() + ITEM_OBTAINED(iid)); - start_pos += 3; - } - std::replace(formattedMessage.begin(), formattedMessage.end(), '@', PLAYER_NAME()[0]); - ReplaceSpecialCharacters(formattedMessage); - ReplaceColors(formattedMessage); - formattedMessage += MESSAGE_END(); - this->getItemMessageTable[i].emplace(giid, formattedMessage); - } +void CustomMessage::FormatMessage(std::string& message, ItemID iid) { + message.insert(0, ITEM_OBTAINED(iid)); + 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() + ITEM_OBTAINED(iid)); + start_pos += 3; + } + std::replace(message.begin(), message.end(), '@', PLAYER_NAME()[0]); + ReplaceSpecialCharacters(message); + ReplaceColors(message); + message += MESSAGE_END(); +} + + + +bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) { + FormatMessage(messages.english, iid); + FormatMessage(messages.german, iid); + FormatMessage(messages.french, iid); + const uint16_t textID = giid; + auto result = messageTables.find(tableID); + if (result == messageTables.end()) { + return false; + } + auto& messageTable = result->second; + auto success = messageTable.emplace(textID, messages); + return success.second; +} + +std::string CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) { + std::unordered_map::const_iterator result = messageTables.find(tableID); + if (result == messageTables.end()) { + return ""; + } + CustomMessageTable messageTable = result->second; + std::unordered_map::const_iterator message_pair = messageTable.find(textID); + if (message_pair == messageTable.end()) { + return ""; + } + CustomMessageEntry messages = message_pair->second; + switch (gSaveContext.language) { + case LANGUAGE_FRA: + return messages.french; + case LANGUAGE_GER: + return messages.german; + case LANGUAGE_ENG: + default: + return messages.english; } } -std::string CustomMessage::RetrieveGetItemMessage(GetItemID giid) { - std::unordered_map::const_iterator result = - getItemMessageTable[gSaveContext.language].find(giid); - if (result == getItemMessageTable[gSaveContext.language].end()) { - return ""; - } - return result->second; +bool CustomMessage::AddCustomMessageTable(std::string tableID) { + CustomMessageTable newMessageTable; + return messageTables.emplace(tableID, newMessageTable).second; } std::string CustomMessage::MESSAGE_END() { diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.h b/soh/soh/Enhancements/custom_message/CustomMessage.h index d8cfd8e0d..d3d1d8849 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.h +++ b/soh/soh/Enhancements/custom_message/CustomMessage.h @@ -12,14 +12,23 @@ #define QM_YELLOW 0x46 #define QM_BLACK 0x47 +typedef struct { + std::string english; + std::string german; + std::string french; +} CustomMessageEntry; + +typedef std::unordered_map CustomMessageTable; + class CustomMessage { private: std::unordered_map textBoxSpecialCharacters; std::unordered_map colors; - std::unordered_map getItemMessageTable[LANGUAGE_MAX]; + std::unordered_map messageTables; void ReplaceSpecialCharacters(std::string &string); void ReplaceColors(std::string& string); + void FormatMessage(std::string& message, ItemID iid); std::string MESSAGE_END(); std::string ITEM_OBTAINED(uint8_t x); @@ -34,6 +43,7 @@ class CustomMessage { CustomMessage(); ~CustomMessage(); - void CreateGetItemMessage(GetItemID giid, ItemID iid, std::string messages[LANGUAGE_MAX]); - std::string RetrieveGetItemMessage(GetItemID giid); + bool CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages); + std::string RetrieveMessage(std::string tableID, uint16_t textID); + bool AddCustomMessageTable(std::string tableID); }; \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 4c589ea48..2e47c7c80 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -21,6 +21,8 @@ std::unordered_map gSeedTextures; u8 generated; +const std::string Randomizer::customMessageTableID = "Randomizer"; + Randomizer::Randomizer() { Sprite bowSprite = { dgFairyBowIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b, 0 }; gSeedTextures[0] = bowSprite; diff --git a/soh/soh/Enhancements/randomizer/randomizer.h b/soh/soh/Enhancements/randomizer/randomizer.h index 6f928bd66..22047a9d8 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.h +++ b/soh/soh/Enhancements/randomizer/randomizer.h @@ -16,6 +16,7 @@ class Randomizer { std::string ganonHintText; std::string ganonText; std::unordered_map randoSettings; + static const std::string customMessageTableID; GetItemID GetItemFromGet(RandomizerGet randoGet, GetItemID ogItemId); GetItemID GetItemFromActor(s16 actorId, s16 actorParams, s16 sceneNum, GetItemID ogItemId); void ParseRandomizerSettingsFile(const char* spoilerFileName); diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp index 61a2559ac..62e213cda 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp @@ -1,25 +1,38 @@ #include "randomizer.h" #include "soh/Enhancements/custom_message/CustomMessage.h" -#define MESSAGES(eng, ger, fra) (new std::string[]{eng, ger, fra}) +#define MESSAGES(eng, ger, fra) {eng, ger, fra} void Randomizer::CreateCustomMessages() { CustomMessage* customMessage = CustomMessage::Instance; + customMessage->AddCustomMessageTable(Randomizer::customMessageTableID); customMessage->CreateGetItemMessage( - GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, + Randomizer::customMessageTableID, GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, MESSAGES("You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", "", "")); customMessage->CreateGetItemMessage( - GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, - MESSAGES("You got a %rBig Poe in a bottle%w!&Sell it to the Ghost Shop!", "", "")); + Randomizer::customMessageTableID, GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, + MESSAGES("You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", "", "")); customMessage->CreateGetItemMessage( - GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, + Randomizer::customMessageTableID, GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, MESSAGES("You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", "", "")); customMessage->CreateGetItemMessage( - GI_BOTTLE_WITH_FISH, ITEM_FISH, - MESSAGES("You got a %rFish in a bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", "", - "")); - - + Randomizer::customMessageTableID, GI_BOTTLE_WITH_FISH, ITEM_FISH, + MESSAGES("You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", "", "")); + customMessage->CreateGetItemMessage( + Randomizer::customMessageTableID, GI_BOTTLE_WITH_BUGS, ITEM_BUG, + { "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", "", "" }); + customMessage->CreateGetItemMessage( + Randomizer::customMessageTableID, GI_BOTTLE_WITH_FAIRY, ITEM_FAIRY, + { "You got a %rFairy in a Bottle%w!&Use it wisely!", "", "" }); + customMessage->CreateGetItemMessage( + Randomizer::customMessageTableID, GI_BOTTLE_WITH_RED_POTION, ITEM_POTION_RED, + { "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", "", "" }); + customMessage->CreateGetItemMessage( + Randomizer::customMessageTableID, GI_BOTTLE_WITH_GREEN_POTION, ITEM_POTION_GREEN, + { "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", "", "" }); + customMessage->CreateGetItemMessage( + Randomizer::customMessageTableID, GI_BOTTLE_WITH_POE, ITEM_POE, + { "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", "", "" }); } std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { @@ -27,5 +40,5 @@ std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { return "Not Randomized."; } - return CustomMessage::Instance->RetrieveGetItemMessage(giid); + return CustomMessage::Instance->RetrieveMessage(Randomizer::customMessageTableID, giid); } \ No newline at end of file diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index d4a78fb34..2bd04a5e8 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1521,9 +1521,9 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { const int maxBufferSize = sizeof(font->msgBuf); if (gSaveContext.n64ddFlag) { if (textId == 0xF8) { + font->charTexBuf[0] = 0x23; if (msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( (GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize)) { - font->charTexBuf[0] = 0x23; return true; } else { switch (gSaveContext.language) { diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 15ff2e7d8..4d2c6e23b 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -652,13 +652,13 @@ static GetItemEntry sGetItemTable[] = { GET_ITEM(ITEM_DOUBLE_MAGIC, OBJECT_GI_MAGICPOT, GID_MAGIC_LARGE, 0xE8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_DOUBLE_DEFENSE, OBJECT_GI_HEARTS, GID_HEART_CONTAINER, 0xE9, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_RED_POTION, OBJECT_GI_LIQUID, GID_POTION_RED, 0x43, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_GREEN_POTION, OBJECT_GI_LIQUID, GID_POTION_GREEN, 0x44, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_RED_POTION, OBJECT_GI_LIQUID, GID_POTION_RED, 0xF8, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_GREEN_POTION, OBJECT_GI_LIQUID, GID_POTION_GREEN, 0xF8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_BLUE_POTION, OBJECT_GI_LIQUID, GID_POTION_BLUE, 0xF8, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_FAIRY, OBJECT_GI_BOTTLE, GID_BOTTLE, 0x46, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_FAIRY, OBJECT_GI_BOTTLE, GID_BOTTLE, 0xF8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_FISH, OBJECT_GI_FISH, GID_FISH, 0xF8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_BLUE_FIRE, OBJECT_GI_FIRE, GID_BLUE_FIRE, 0xF8, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BUGS, OBJECT_GI_INSECT, GID_BUG, 0x7A, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BUGS, OBJECT_GI_INSECT, GID_BUG, 0xF8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_POE, OBJECT_GI_GHOST, GID_POE, 0xF8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_BOTTLE_WITH_BIG_POE, OBJECT_GI_GHOST, GID_BIG_POE, 0xF8, 0x80, CHEST_ANIM_LONG), From e04b2c80b67c23114a4818b1e39298cbaaed9e1b Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 17 Jul 2022 22:02:22 -0400 Subject: [PATCH 14/39] Implements the custom text for gInjectSkulltulaCount. Also auto-dissmisses the textbox when gSkulltulaFreeze is on. When gInjectSkulltulaCount is off, text is not auto-dismissed just like before, since that is base game text still. --- .../custom_message/CustomMessage.cpp | 8 +++--- .../custom_message/CustomMessage.h | 4 ++- soh/soh/OTRGlobals.cpp | 15 +++++++++++ soh/soh/z_message_OTR.cpp | 18 +++++++++++++ soh/src/code/z_message_PAL.c | 25 +------------------ 5 files changed, 41 insertions(+), 29 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.cpp b/soh/soh/Enhancements/custom_message/CustomMessage.cpp index d513c8286..95e260cf8 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessage.cpp @@ -46,7 +46,7 @@ void CustomMessage::ReplaceColors(std::string& string) { } } -void CustomMessage::FormatMessage(std::string& message, ItemID iid) { +void CustomMessage::FormatCustomMessage(std::string& message, ItemID iid) { message.insert(0, ITEM_OBTAINED(iid)); size_t start_pos = 0; std::replace(message.begin(), message.end(), '&', NEWLINE()[0]); @@ -63,9 +63,9 @@ void CustomMessage::FormatMessage(std::string& message, ItemID iid) { bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) { - FormatMessage(messages.english, iid); - FormatMessage(messages.german, iid); - FormatMessage(messages.french, iid); + FormatCustomMessage(messages.english, iid); + FormatCustomMessage(messages.german, iid); + FormatCustomMessage(messages.french, iid); const uint16_t textID = giid; auto result = messageTables.find(tableID); if (result == messageTables.end()) { diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.h b/soh/soh/Enhancements/custom_message/CustomMessage.h index d3d1d8849..4d35cfb9a 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.h +++ b/soh/soh/Enhancements/custom_message/CustomMessage.h @@ -3,6 +3,8 @@ #include #include "variables.h" +#undef MESSAGE_END + #define QM_WHITE 0x00 #define QM_RED 0x41 #define QM_GREEN 0x42 @@ -28,7 +30,7 @@ class CustomMessage { void ReplaceSpecialCharacters(std::string &string); void ReplaceColors(std::string& string); - void FormatMessage(std::string& message, ItemID iid); + void FormatCustomMessage(std::string& message, ItemID iid); std::string MESSAGE_END(); std::string ITEM_OBTAINED(uint8_t x); diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 2bd04a5e8..14fa89f6c 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1542,5 +1542,20 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { } } } + if (textId == 0x00B4 || textId == 0x00B5) { + if (CVar_GetS32("gInjectSkulltulaCount", 0) != 0) { + font->charTexBuf[0] = 0x03; + std::string message; + if (CVar_GetS32("gSkulltulaFreeze", 0) != 0) { + textId = 0x00B4; + } else { + textId = 0x00B5; + } + message = CustomMessage::Instance->RetrieveMessage("BaseGameOverrides", textId); + if (message != "") { + return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer(message, buffer, maxBufferSize); + } + } + } return false; } diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index 8c1d26a75..e6ef4bb76 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -6,6 +6,7 @@ #include "global.h" #include "vt.h" #include +#include extern "C" MessageTableEntry* sNesMessageEntryTablePtr; extern "C" MessageTableEntry* sGerMessageEntryTablePtr; @@ -13,6 +14,8 @@ extern "C" MessageTableEntry* sFraMessageEntryTablePtr; extern "C" MessageTableEntry* sStaffMessageEntryTablePtr; //extern "C" MessageTableEntry* _message_0xFFFC_nes; +const std::string customMessageTableID = "BaseGameOverrides"; + MessageTableEntry* OTRMessage_LoadTable(const char* filePath, bool isNES) { auto file = std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(filePath)); @@ -92,4 +95,19 @@ extern "C" void OTRMessage_Init() sStaffMessageEntryTablePtr[i].segment = file2->messages[i].msg.c_str(); sStaffMessageEntryTablePtr[i].msgSize = file2->messages[i].msg.size(); } + + CustomMessage::Instance->AddCustomMessageTable(customMessageTableID); + CustomMessage::Instance->CreateGetItemMessage( + customMessageTableID, (GetItemID)0x00B4, ITEM_SKULL_TOKEN, + { + "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!\x0E\x3C", + "Du erhlst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!\x0E\x3C", + "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collect %r\x19\%w symboles en tout!\x0E\x3C" + } + ); + CustomMessage::Instance->CreateGetItemMessage( + customMessageTableID, (GetItemID)0x00B5, ITEM_SKULL_TOKEN, + { "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!", + "Du erhlst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!", + "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collect %r\x19\%w symboles en tout!" }); } \ No newline at end of file diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index f0ce90fbd..ad37aea16 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1710,25 +1710,6 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { } else if (gSaveContext.n64ddFlag && (textId == 0x7040 || textId == 0x7088)) { // rando hints at altar msgCtx->msgLength = font->msgLength = CopyAltarMessage(font->msgBuf, sizeof(font->msgBuf)); - } else if (textId == 0x00b4 && CVar_GetS32("gInjectSkulltulaCount", 0) != 0) { - switch (gSaveContext.language) { - case LANGUAGE_FRA: - strcpy(font->msgBuf, "\x08\x13\x71Vous obtenez un \x05\x41Symbole de\x01Skulltula d'or\x05\x40! " - "Vous avez\x01\collect\x96 " - "\x05\x41\x19\x05\x40 symboles en tout!\x02"); - break; - case LANGUAGE_GER: - strcpy(font->msgBuf, "\x08\x13\x71\Du erh\x93lst ein \x05\x41Goldene\x01Skulltula-Symbol\x05\x40\! " - "Du hast\x01insgesamt " - "\x05\x41\x19\x05\x40 symbol gesammelt!\x02"); - break; - case LANGUAGE_ENG: default: - strcpy(font->msgBuf, - "\x08\x13\x71You got a \x05\x41Gold Skulltula Token\x05\x40!\x01You've collected " - "\x05\x41\x19\x05\x40 tokens\x01in total!\x02"); - break; - } - msgCtx->msgLength = font->msgLength = strlen(font->msgBuf); } else if (gSaveContext.n64ddFlag && (textId == 0x10A2 || textId == 0x10DC || textId == 0x10DD)) { msgCtx->msgLength = font->msgLength = CopyScrubMessage(textId, font->msgBuf, sizeof(font->msgBuf)); } else if (gSaveContext.n64ddFlag && textId == 0x70CC) { @@ -1737,11 +1718,7 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { } else { msgCtx->msgLength = font->msgLength = CopyGanonHintText(font->msgBuf, sizeof(font->msgBuf)); } - } /*else if (gSaveContext.n64ddFlag && textId == 0xF8) { - msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( - GET_PLAYER(globalCtx)->getItemId, font->msgBuf, sizeof(font->msgBuf)); - font->charTexBuf[0] = 0x23; - }*/ else { + } else { msgCtx->msgLength = font->msgLength; char* src = (uintptr_t)font->msgOffset; memcpy(font->msgBuf, src, font->msgLength); From 32abe61554472e37c5c67d3c5186097738c9df21 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 19 Jul 2022 00:31:37 -0400 Subject: [PATCH 15/39] Implements a basic CreateMessage function for non-GetItem text. --- .../custom_message/CustomMessage.cpp | 36 +++++++++++++++---- .../custom_message/CustomMessage.h | 3 ++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.cpp b/soh/soh/Enhancements/custom_message/CustomMessage.cpp index 95e260cf8..437c16ac8 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessage.cpp @@ -60,13 +60,20 @@ void CustomMessage::FormatCustomMessage(std::string& message, ItemID iid) { message += MESSAGE_END(); } +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(), '@', PLAYER_NAME()[0]); + ReplaceSpecialCharacters(message); + ReplaceColors(message); + message += MESSAGE_END(); +} - -bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) { - FormatCustomMessage(messages.english, iid); - FormatCustomMessage(messages.german, iid); - FormatCustomMessage(messages.french, iid); - const uint16_t textID = giid; +bool CustomMessage::InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) { auto result = messageTables.find(tableID); if (result == messageTables.end()) { return false; @@ -76,6 +83,23 @@ bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, It return success.second; } + + +bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) { + FormatCustomMessage(messages.english, iid); + FormatCustomMessage(messages.german, iid); + FormatCustomMessage(messages.french, iid); + const uint16_t textID = giid; + return InsertCustomMessage(tableID, textID, messages); +} + +bool CustomMessage::CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) { + FormatCustomMessage(messages.english); + FormatCustomMessage(messages.german); + FormatCustomMessage(messages.french); + return InsertCustomMessage(tableID, textID, messages); +} + std::string CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) { std::unordered_map::const_iterator result = messageTables.find(tableID); if (result == messageTables.end()) { diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.h b/soh/soh/Enhancements/custom_message/CustomMessage.h index 4d35cfb9a..66afaf15c 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.h +++ b/soh/soh/Enhancements/custom_message/CustomMessage.h @@ -31,6 +31,8 @@ class CustomMessage { void ReplaceSpecialCharacters(std::string &string); void ReplaceColors(std::string& string); void FormatCustomMessage(std::string& message, ItemID iid); + void FormatCustomMessage(std::string& message); + bool InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages); std::string MESSAGE_END(); std::string ITEM_OBTAINED(uint8_t x); @@ -46,6 +48,7 @@ class CustomMessage { ~CustomMessage(); bool CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages); + bool CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages); std::string RetrieveMessage(std::string tableID, uint16_t textID); bool AddCustomMessageTable(std::string tableID); }; \ No newline at end of file From c5f66373c3b125497216eb4ca59b034ec344fc28 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 19 Jul 2022 22:51:39 -0400 Subject: [PATCH 16/39] Adds ability to store and retrieve textbox size and position. --- soh/include/z64.h | 3 ++ .../custom_message/CustomMessage.cpp | 5 ++- .../custom_message/CustomMessage.h | 7 +++- soh/soh/Enhancements/randomizer/randomizer.h | 7 ++-- .../randomizer/randomizer_custom_messages.cpp | 42 +++++++++++-------- soh/soh/OTRGlobals.cpp | 8 ++-- soh/soh/z_message_OTR.cpp | 5 ++- soh/src/code/z_message_PAL.c | 2 +- 8 files changed, 50 insertions(+), 29 deletions(-) diff --git a/soh/include/z64.h b/soh/include/z64.h index fdc634e58..a16134f08 100644 --- a/soh/include/z64.h +++ b/soh/include/z64.h @@ -30,6 +30,9 @@ #include "ichain.h" #include "regs.h" +#define NOGDI +#define WIN32_LEAN_AND_MEAN + #if defined(_WIN64) || defined(__x86_64__) || defined(__arm64__) #define _SOH64 #endif diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.cpp b/soh/soh/Enhancements/custom_message/CustomMessage.cpp index 437c16ac8..20170a7ba 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessage.cpp @@ -100,7 +100,7 @@ bool CustomMessage::CreateMessage(std::string tableID, uint16_t textID, CustomMe return InsertCustomMessage(tableID, textID, messages); } -std::string CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) { +std::string CustomMessage::RetrieveMessage(GlobalContext* globalCtx, std::string tableID, uint16_t textID) { std::unordered_map::const_iterator result = messageTables.find(tableID); if (result == messageTables.end()) { return ""; @@ -111,6 +111,9 @@ std::string CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) return ""; } CustomMessageEntry messages = message_pair->second; + MessageContext* msgCtx = &globalCtx->msgCtx; + Font* font = &msgCtx->font; + font->charTexBuf[0] = (messages.textBoxType << 4) | messages.textBoxPos; switch (gSaveContext.language) { case LANGUAGE_FRA: return messages.french; diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.h b/soh/soh/Enhancements/custom_message/CustomMessage.h index 66afaf15c..513cdaf60 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.h +++ b/soh/soh/Enhancements/custom_message/CustomMessage.h @@ -1,7 +1,8 @@ #pragma once #include #include -#include "variables.h" +#include "z64.h" +#include #undef MESSAGE_END @@ -15,6 +16,8 @@ #define QM_BLACK 0x47 typedef struct { + TextBoxType textBoxType; + TextBoxPosition textBoxPos; std::string english; std::string german; std::string french; @@ -49,6 +52,6 @@ class CustomMessage { bool CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages); bool CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages); - std::string RetrieveMessage(std::string tableID, uint16_t textID); + std::string RetrieveMessage(GlobalContext* globalCtx, std::string tableID, uint16_t textID); bool AddCustomMessageTable(std::string tableID); }; \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizer.h b/soh/soh/Enhancements/randomizer/randomizer.h index 22047a9d8..5f9f1f1bc 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.h +++ b/soh/soh/Enhancements/randomizer/randomizer.h @@ -4,8 +4,8 @@ #include #include "../../../include/ultra64.h" #include "../../../include/z64item.h" -#include #include +#include class Randomizer { private: @@ -16,7 +16,6 @@ class Randomizer { std::string ganonHintText; std::string ganonText; std::unordered_map randoSettings; - static const std::string customMessageTableID; GetItemID GetItemFromGet(RandomizerGet randoGet, GetItemID ogItemId); GetItemID GetItemFromActor(s16 actorId, s16 actorParams, s16 sceneNum, GetItemID ogItemId); void ParseRandomizerSettingsFile(const char* spoilerFileName); @@ -27,6 +26,8 @@ class Randomizer { Randomizer(); ~Randomizer(); + static const std::string customMessageTableID; + static Sprite* GetSeedTexture(uint8_t index); s16 GetItemModelFromId(s16 itemId); s32 GetItemIDFromGetItemID(s32 getItemId); @@ -43,7 +44,7 @@ class Randomizer { std::string GetHintFromCheck(RandomizerCheck check); GetItemID GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); GetItemID GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); - std::string GetCustomGetItemMessage(GetItemID giid); + //std::string GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid); static void CreateCustomMessages(); }; diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp index 62e213cda..8ac220fca 100644 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp @@ -1,44 +1,52 @@ #include "randomizer.h" #include "soh/Enhancements/custom_message/CustomMessage.h" +#include -#define MESSAGES(eng, ger, fra) {eng, ger, fra} +#define NOGDI +#define WIN32_LEAN_AND_MEAN void Randomizer::CreateCustomMessages() { CustomMessage* customMessage = CustomMessage::Instance; customMessage->AddCustomMessageTable(Randomizer::customMessageTableID); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, - MESSAGES("You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", "", "")); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, - MESSAGES("You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", "", "")); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, - MESSAGES("You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", "", "")); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_FISH, ITEM_FISH, - MESSAGES("You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", "", "")); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_BUGS, ITEM_BUG, - { "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_FAIRY, ITEM_FAIRY, - { "You got a %rFairy in a Bottle%w!&Use it wisely!", "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rFairy in a Bottle%w!&Use it wisely!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_RED_POTION, ITEM_POTION_RED, - { "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_GREEN_POTION, ITEM_POTION_GREEN, - { "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", "", "" }); customMessage->CreateGetItemMessage( Randomizer::customMessageTableID, GI_BOTTLE_WITH_POE, ITEM_POE, - { "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", "", "" }); } -std::string Randomizer::GetCustomGetItemMessage(GetItemID giid) { - if (!gSaveContext.n64ddFlag) { - return "Not Randomized."; - } - - return CustomMessage::Instance->RetrieveMessage(Randomizer::customMessageTableID, giid); -} \ No newline at end of file +//std::string Randomizer::GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid) { +// if (!gSaveContext.n64ddFlag) { +// return "Not Randomized."; +// } +// +// return CustomMessage::Instance->RetrieveMessage(globalCtx, Randomizer::customMessageTableID, giid); +//} \ No newline at end of file diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 309c0a951..c048d3358 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1505,8 +1505,8 @@ extern "C" s32 Randomizer_GetItemIdFromKnownCheck(RandomizerCheck randomizerChec return OTRGlobals::Instance->gRandomizer->GetRandomizedItemIdFromKnownCheck(randomizerCheck, ogId); } -extern "C" int Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize) { - const std::string& getItemText = OTRGlobals::Instance->gRandomizer->GetCustomGetItemMessage(giid); +extern "C" int Randomizer_GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid, char* buffer, const int maxBufferSize) { + const std::string& getItemText = CustomMessage::Instance->RetrieveMessage(globalCtx, Randomizer::customMessageTableID, giid); if (getItemText == "") { return false; } @@ -1523,7 +1523,7 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { if (textId == 0xF8) { font->charTexBuf[0] = 0x23; if (msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( - (GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize)) { + globalCtx, (GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize)) { return true; } else { switch (gSaveContext.language) { @@ -1551,7 +1551,7 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { } else { textId = 0x00B5; } - message = CustomMessage::Instance->RetrieveMessage("BaseGameOverrides", textId); + message = CustomMessage::Instance->RetrieveMessage(globalCtx, "BaseGameOverrides", textId); if (message != "") { return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer(message, buffer, maxBufferSize); } diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index e6ef4bb76..503d3e14b 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -100,6 +100,7 @@ extern "C" void OTRMessage_Init() CustomMessage::Instance->CreateGetItemMessage( customMessageTableID, (GetItemID)0x00B4, ITEM_SKULL_TOKEN, { + TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!\x0E\x3C", "Du erhlst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!\x0E\x3C", "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collect %r\x19\%w symboles en tout!\x0E\x3C" @@ -107,7 +108,9 @@ extern "C" void OTRMessage_Init() ); CustomMessage::Instance->CreateGetItemMessage( customMessageTableID, (GetItemID)0x00B5, ITEM_SKULL_TOKEN, - { "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!", + { + TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!", "Du erhlst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!", "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collect %r\x19\%w symboles en tout!" }); } \ No newline at end of file diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index 196821e9e..e44e5f325 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1709,7 +1709,7 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { msgCtx->msgLength = font->msgLength = Randomizer_CopyHintFromCheck(hintCheck, font->msgBuf, sizeof(font->msgBuf)); } else if (gSaveContext.n64ddFlag && (textId == 0x7040 || textId == 0x7088)) { // rando hints at altar - msgCtx->msgLength = font->msgLength = CopyAltarMessage(font->msgBuf, sizeof(font->msgBuf)); + msgCtx->msgLength = font->msgLength = Randomizer_CopyAltarMessage(font->msgBuf, sizeof(font->msgBuf)); } else if (gSaveContext.n64ddFlag && (textId == 0x10A2 || textId == 0x10DC || textId == 0x10DD)) { msgCtx->msgLength = font->msgLength = CopyScrubMessage(textId, font->msgBuf, sizeof(font->msgBuf)); } else if (gSaveContext.n64ddFlag && textId == 0x70CC) { From b5dc097587dfe3f75362af9cbe6720991f3524d0 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Thu, 21 Jul 2022 13:05:15 -0400 Subject: [PATCH 17/39] Cleanup and move most hint logic to CustomMessage. Haven't removed where rando stores the hints for itself and the ganon and altar hints are still pulled from the randomizer class' local storage, but gossip stone hints are pulled from the custom message table now. --- .../custom_message/CustomMessage.cpp | 28 +++--- .../custom_message/CustomMessage.h | 7 +- .../Enhancements/randomizer/randomizer.cpp | 68 ++++++++++++++- soh/soh/Enhancements/randomizer/randomizer.h | 5 +- soh/soh/OTRGlobals.cpp | 87 ++++++++++++------- soh/soh/OTRGlobals.h | 2 +- soh/soh/z_message_OTR.cpp | 1 - soh/src/code/z_message_PAL.c | 34 +------- 8 files changed, 141 insertions(+), 91 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.cpp b/soh/soh/Enhancements/custom_message/CustomMessage.cpp index 20170a7ba..7f26fb616 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessage.cpp @@ -100,29 +100,27 @@ bool CustomMessage::CreateMessage(std::string tableID, uint16_t textID, CustomMe return InsertCustomMessage(tableID, textID, messages); } -std::string CustomMessage::RetrieveMessage(GlobalContext* globalCtx, std::string tableID, uint16_t textID) { +CustomMessageEntry CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) { std::unordered_map::const_iterator result = messageTables.find(tableID); if (result == messageTables.end()) { - return ""; + return NULL_CUSTOM_MESSAGE; } CustomMessageTable messageTable = result->second; std::unordered_map::const_iterator message_pair = messageTable.find(textID); if (message_pair == messageTable.end()) { - return ""; + return NULL_CUSTOM_MESSAGE; } - CustomMessageEntry messages = message_pair->second; - MessageContext* msgCtx = &globalCtx->msgCtx; - Font* font = &msgCtx->font; - font->charTexBuf[0] = (messages.textBoxType << 4) | messages.textBoxPos; - switch (gSaveContext.language) { - case LANGUAGE_FRA: - return messages.french; - case LANGUAGE_GER: - return messages.german; - case LANGUAGE_ENG: - default: - return messages.english; + CustomMessageEntry message = message_pair->second; + return message; +} + +bool CustomMessage::ClearMessageTable(std::string tableID) { + auto result = messageTables.find(tableID); + if (result == messageTables.end()) { + return false; } + auto& messageTable = result->second; + messageTable.clear(); } bool CustomMessage::AddCustomMessageTable(std::string tableID) { diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.h b/soh/soh/Enhancements/custom_message/CustomMessage.h index 513cdaf60..465d1fafc 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.h +++ b/soh/soh/Enhancements/custom_message/CustomMessage.h @@ -1,7 +1,6 @@ #pragma once #include #include -#include "z64.h" #include #undef MESSAGE_END @@ -23,6 +22,9 @@ typedef struct { std::string french; } CustomMessageEntry; +#define NULL_CUSTOM_MESSAGE \ + { (TextBoxType)(-1), (TextBoxPosition)(-1), "", "", "" } + typedef std::unordered_map CustomMessageTable; class CustomMessage { @@ -52,6 +54,7 @@ class CustomMessage { bool CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages); bool CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages); - std::string RetrieveMessage(GlobalContext* globalCtx, std::string tableID, uint16_t textID); + CustomMessageEntry RetrieveMessage(std::string tableID, uint16_t textID); + bool ClearMessageTable(std::string tableID); bool AddCustomMessageTable(std::string tableID); }; \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 2e47c7c80..77e426baf 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -14,6 +14,7 @@ #include "3drando/rando_main.hpp" #include #include "Lib/ImGui/imgui_internal.h" +#include using json = nlohmann::json; @@ -21,7 +22,8 @@ std::unordered_map gSeedTextures; u8 generated; -const std::string Randomizer::customMessageTableID = "Randomizer"; +const std::string Randomizer::getItemMessageTableID = "Randomizer"; +const std::string Randomizer::hintMessageTableID = "RandomizerHints"; Randomizer::Randomizer() { Sprite bowSprite = { dgFairyBowIconTex, 32, 32, G_IM_FMT_RGBA, G_IM_SIZ_32b, 0 }; @@ -1479,6 +1481,22 @@ void Randomizer::LoadHintLocations(const char* spoilerFileName) { ParseHintLocationsFile(spoilerFileName); } + CustomMessage::Instance->ClearMessageTable(Randomizer::hintMessageTableID); + CustomMessage::Instance->AddCustomMessageTable(Randomizer::hintMessageTableID); + + CustomMessage::Instance->CreateMessage( + Randomizer::hintMessageTableID, 0x7040, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.childAltarText, "", "" }); + CustomMessage::Instance->CreateMessage( + Randomizer::hintMessageTableID, 0x7088, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.adultAltarText, "", "" }); + CustomMessage::Instance->CreateMessage( + Randomizer::hintMessageTableID, 0x70CC, + { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonHintText, "", "" }); + CustomMessage::Instance->CreateMessage( + Randomizer::hintMessageTableID, 0x70CD, + { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonText, "", "" }); + this->childAltarText = gSaveContext.childAltarText; this->adultAltarText = gSaveContext.adultAltarText; this->ganonHintText = gSaveContext.ganonHintText; @@ -1487,6 +1505,8 @@ void Randomizer::LoadHintLocations(const char* spoilerFileName) { for (auto hintLocation : gSaveContext.hintLocations) { if(hintLocation.check == RC_LINKS_POCKET) break; this->hintLocations[hintLocation.check] = hintLocation.hintText; + CustomMessage::Instance->CreateMessage( + Randomizer::hintMessageTableID, hintLocation.check, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, hintLocation.hintText, "", "" }); } } @@ -2409,9 +2429,9 @@ std::string Randomizer::GetGanonHintText() const { return ganonHintText; } -std::string Randomizer::GetHintFromCheck(RandomizerCheck check) { - return this->hintLocations[check]; -} +//CustomMessageEntry Randomizer::GetHintFromCheck(RandomizerCheck check) { +// return CustomMessage::Instance->RetrieveMessage(hintMessageTableID, check); +//} u8 Randomizer::GetRandoSettingValue(RandomizerSettingKey randoSettingKey) { return this->randoSettings[randoSettingKey]; @@ -4748,6 +4768,46 @@ void DrawRandoEditor(bool& open) { }*/ +void Randomizer::CreateCustomMessages() { + CustomMessage* customMessage = CustomMessage::Instance; + customMessage->AddCustomMessageTable(Randomizer::getItemMessageTableID); + customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", "", + "" }); + customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", "", + "" }); + customMessage->CreateGetItemMessage( + Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", "", "" }); + customMessage->CreateGetItemMessage( + Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_FISH, ITEM_FISH, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", "", "" }); + customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_BUGS, ITEM_BUG, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", "", + "" }); + customMessage->CreateGetItemMessage( + Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_FAIRY, ITEM_FAIRY, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rFairy in a Bottle%w!&Use it wisely!", "", "" }); + customMessage->CreateGetItemMessage( + Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_RED_POTION, ITEM_POTION_RED, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", "", "" }); + customMessage->CreateGetItemMessage( + Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_GREEN_POTION, ITEM_POTION_GREEN, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", "", "" }); + customMessage->CreateGetItemMessage( + Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_POE, ITEM_POE, + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, + "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", "", "" }); + } + void InitRando() { SohImGui::AddWindow("Randomizer", "Randomizer Settings", DrawRandoEditor); Randomizer::CreateCustomMessages(); diff --git a/soh/soh/Enhancements/randomizer/randomizer.h b/soh/soh/Enhancements/randomizer/randomizer.h index 5f9f1f1bc..ec27d684d 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.h +++ b/soh/soh/Enhancements/randomizer/randomizer.h @@ -26,7 +26,8 @@ class Randomizer { Randomizer(); ~Randomizer(); - static const std::string customMessageTableID; + static const std::string getItemMessageTableID; + static const std::string hintMessageTableID; static Sprite* GetSeedTexture(uint8_t index); s16 GetItemModelFromId(s16 itemId); @@ -41,7 +42,7 @@ class Randomizer { std::string GetAdultAltarText() const; std::string GetGanonText() const; std::string GetGanonHintText() const; - std::string GetHintFromCheck(RandomizerCheck check); + //CustomMessageEntry GetHintFromCheck(RandomizerCheck check); GetItemID GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); GetItemID GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); //std::string GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid); diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index c048d3358..f570c3b10 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -36,15 +36,14 @@ #include "Enhancements/cosmetics/CosmeticsEditor.h" #include "Enhancements/debugconsole.h" #include "Enhancements/debugger/debugger.h" -#include "Enhancements/randomizer/randomizer.h" #include -#include #include "Enhancements/n64_weird_frame_data.inc" #include "soh/frame_interpolation.h" #include "Utils/BitConverter.h" #include "variables.h" #include "macros.h" #include +#include #ifdef __APPLE__ #include @@ -1490,11 +1489,11 @@ extern "C" int Randomizer_CopyGanonHintText(char* buffer, const int maxBufferSiz return CopyStringToCharBuffer(ganonText, buffer, maxBufferSize); } -extern "C" int Randomizer_CopyHintFromCheck(RandomizerCheck check, char* buffer, const int maxBufferSize) { +extern "C" CustomMessageEntry Randomizer_CopyHintFromCheck(RandomizerCheck check) { // we don't want to make a copy of the std::string returned from GetHintFromCheck // so we're just going to let RVO take care of it - const std::string& hintText = OTRGlobals::Instance->gRandomizer->GetHintFromCheck(check); - return CopyStringToCharBuffer(hintText, buffer, maxBufferSize); + const CustomMessageEntry hintText = CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, check); + return hintText; } extern "C" s32 Randomizer_GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum) { @@ -1505,12 +1504,9 @@ extern "C" s32 Randomizer_GetItemIdFromKnownCheck(RandomizerCheck randomizerChec return OTRGlobals::Instance->gRandomizer->GetRandomizedItemIdFromKnownCheck(randomizerCheck, ogId); } -extern "C" int Randomizer_GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid, char* buffer, const int maxBufferSize) { - const std::string& getItemText = CustomMessage::Instance->RetrieveMessage(globalCtx, Randomizer::customMessageTableID, giid); - if (getItemText == "") { - return false; - } - return CopyStringToCharBuffer(getItemText, buffer, maxBufferSize); +extern "C" CustomMessageEntry Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize) { + const CustomMessageEntry getItemText = CustomMessage::Instance->RetrieveMessage(Randomizer::getItemMessageTableID, giid); + return getItemText; } extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { @@ -1519,42 +1515,67 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { Font* font = &msgCtx->font; char* buffer = font->msgBuf; const int maxBufferSize = sizeof(font->msgBuf); + CustomMessageEntry messageEntry; if (gSaveContext.n64ddFlag) { if (textId == 0xF8) { - font->charTexBuf[0] = 0x23; - if (msgCtx->msgLength = font->msgLength = Randomizer_GetCustomGetItemMessage( - globalCtx, (GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize)) { - return true; - } else { - switch (gSaveContext.language) { - case LANGUAGE_FRA: - return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer( - "Il n'y a pas de message personnalisé pour cet élément.\x02", buffer, maxBufferSize); - case LANGUAGE_GER: - return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer( - "Für diesen Artikel gibt es keine benutzerdefinierte Nachricht.\x02", buffer, - maxBufferSize); - case LANGUAGE_ENG: - default: - return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer( - "There is no custom message for this item.\x02", buffer, maxBufferSize); + messageEntry = + Randomizer_GetCustomGetItemMessage((GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize); + } + if (textId == 0x2053 && Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) != 0 && + (Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) == 1 || + (Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) == 2 && + Player_GetMask(globalCtx) == PLAYER_MASK_TRUTH) || + (Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) == 3 && CHECK_QUEST_ITEM(QUEST_STONE_OF_AGONY)))) { + + s16 actorParams = msgCtx->talkActor->params; + + // if we're in a generic grotto + if (globalCtx->sceneNum == 62 && actorParams == 14360) { + // look for the chest in the actorlist to determine + // which grotto we're in + int numOfActorLists = + sizeof(globalCtx->actorCtx.actorLists) / sizeof(globalCtx->actorCtx.actorLists[0]); + for (int i = 0; i < numOfActorLists; i++) { + if (globalCtx->actorCtx.actorLists[i].length) { + if (globalCtx->actorCtx.actorLists[i].head->id == 10) { + // set the params for the hint check to be negative chest params + actorParams = 0 - globalCtx->actorCtx.actorLists[i].head->params; + } + } } } + + RandomizerCheck hintCheck = + Randomizer_GetCheckFromActor(globalCtx->sceneNum, msgCtx->talkActor->id, actorParams); + + messageEntry = Randomizer_CopyHintFromCheck(hintCheck); } } if (textId == 0x00B4 || textId == 0x00B5) { if (CVar_GetS32("gInjectSkulltulaCount", 0) != 0) { font->charTexBuf[0] = 0x03; - std::string message; if (CVar_GetS32("gSkulltulaFreeze", 0) != 0) { textId = 0x00B4; } else { textId = 0x00B5; } - message = CustomMessage::Instance->RetrieveMessage(globalCtx, "BaseGameOverrides", textId); - if (message != "") { - return msgCtx->msgLength = font->msgLength = CopyStringToCharBuffer(message, buffer, maxBufferSize); - } + messageEntry = CustomMessage::Instance->RetrieveMessage("BaseGameOverrides", textId); + } + } + if (messageEntry.textBoxType != -1) { + font->charTexBuf[0] = (messageEntry.textBoxType << 4) | messageEntry.textBoxPos; + switch (gSaveContext.language) { + case LANGUAGE_FRA: + return msgCtx->msgLength = font->msgLength = + CopyStringToCharBuffer(messageEntry.french, buffer, maxBufferSize); + case LANGUAGE_GER: + return msgCtx->msgLength = font->msgLength = + CopyStringToCharBuffer(messageEntry.german, buffer, maxBufferSize); + + case LANGUAGE_ENG: + default: + return msgCtx->msgLength = font->msgLength = + CopyStringToCharBuffer(messageEntry.english, buffer, maxBufferSize); } } return false; diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 83618f994..4a924ed61 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -9,6 +9,7 @@ #ifdef __cplusplus #include "Enhancements/savestates.h" #include "Enhancements/randomizer/randomizer.h" + class OTRGlobals { public: @@ -87,7 +88,6 @@ void Randomizer_LoadSettings(const char* spoilerFileName); u8 Randomizer_GetSettingValue(RandomizerSettingKey randoSettingKey); RandomizerCheck Randomizer_GetCheckFromActor(s16 actorId, s16 actorParams, s16 sceneNum); int Randomizer_CopyAltarMessage(char* buffer, const int maxBufferSize); -int Randomizer_CopyHintFromCheck(RandomizerCheck check, char* buffer, const int maxBufferSize); int Randomizer_CopyGanonText(char* buffer, const int maxBufferSize); int Randomizer_CopyGanonHintText(char* buffer, const int maxBufferSize); void Randomizer_LoadHintLocations(const char* spoilerFileName); diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index 503d3e14b..c09286fad 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -1,7 +1,6 @@ #include "OTRGlobals.h" #include "ResourceMgr.h" #include "Scene.h" -#include "message_data_static.h" #include "Utils/StringHelper.h" #include "global.h" #include "vt.h" diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index e44e5f325..7a0aed9b2 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1675,39 +1675,7 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { //font->msgLength, __FILE__, __LINE__); } else { Message_FindMessage(globalCtx, textId); - // if we're rando'd and talking to a gossip stone - if (gSaveContext.n64ddFlag && - textId == 0x2053 && - Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) != 0 && - (Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) == 1 || - (Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) == 2 && - Player_GetMask(globalCtx) == PLAYER_MASK_TRUTH) || - (Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) == 3 && - CHECK_QUEST_ITEM(QUEST_STONE_OF_AGONY)))) { - - s16 actorParams = msgCtx->talkActor->params; - - // if we're in a generic grotto - if (globalCtx->sceneNum == 62 && actorParams == 14360) { - // look for the chest in the actorlist to determine - // which grotto we're in - int numOfActorLists = sizeof(globalCtx->actorCtx.actorLists)/sizeof(globalCtx->actorCtx.actorLists[0]); - for(int i = 0; i < numOfActorLists; i++) { - if(globalCtx->actorCtx.actorLists[i].length) { - if(globalCtx->actorCtx.actorLists[i].head->id == 10) { - // set the params for the hint check to be negative chest params - actorParams = 0 - globalCtx->actorCtx.actorLists[i].head->params; - } - } - } - } - - RandomizerCheck hintCheck = Randomizer_GetCheckFromActor(globalCtx->sceneNum, msgCtx->talkActor->id, actorParams); - - // Pass the sizeof the message buffer so we don't hardcode any sizes and can rely on globals. - // If no hint can be found, this just returns 0 size and doesn't modify the buffer, so no worries. - msgCtx->msgLength = font->msgLength = Randomizer_CopyHintFromCheck(hintCheck, font->msgBuf, sizeof(font->msgBuf)); - } else if (gSaveContext.n64ddFlag && (textId == 0x7040 || textId == 0x7088)) { + if (gSaveContext.n64ddFlag && (textId == 0x7040 || textId == 0x7088)) { // rando hints at altar msgCtx->msgLength = font->msgLength = Randomizer_CopyAltarMessage(font->msgBuf, sizeof(font->msgBuf)); } else if (gSaveContext.n64ddFlag && (textId == 0x10A2 || textId == 0x10DC || textId == 0x10DD)) { From 21c585b2cea03e5eaa5331b454fcf50cdacfafac Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Thu, 21 Jul 2022 13:10:04 -0400 Subject: [PATCH 18/39] Removes randomizer_custom_messages, as I relocated its logic elsewhere. --- soh/soh.vcxproj | 1 - .../randomizer/randomizer_custom_messages.cpp | 52 ------------------- 2 files changed, 53 deletions(-) delete mode 100644 soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp diff --git a/soh/soh.vcxproj b/soh/soh.vcxproj index 974fb25c8..1c1f3784a 100644 --- a/soh/soh.vcxproj +++ b/soh/soh.vcxproj @@ -236,7 +236,6 @@ - diff --git a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp b/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp deleted file mode 100644 index 8ac220fca..000000000 --- a/soh/soh/Enhancements/randomizer/randomizer_custom_messages.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "randomizer.h" -#include "soh/Enhancements/custom_message/CustomMessage.h" -#include - -#define NOGDI -#define WIN32_LEAN_AND_MEAN - -void Randomizer::CreateCustomMessages() { - CustomMessage* customMessage = CustomMessage::Instance; - customMessage->AddCustomMessageTable(Randomizer::customMessageTableID); - customMessage->CreateGetItemMessage( - Randomizer::customMessageTableID, GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::customMessageTableID, GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::customMessageTableID, GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::customMessageTableID, GI_BOTTLE_WITH_FISH, ITEM_FISH, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::customMessageTableID, GI_BOTTLE_WITH_BUGS, ITEM_BUG, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::customMessageTableID, GI_BOTTLE_WITH_FAIRY, ITEM_FAIRY, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rFairy in a Bottle%w!&Use it wisely!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::customMessageTableID, GI_BOTTLE_WITH_RED_POTION, ITEM_POTION_RED, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::customMessageTableID, GI_BOTTLE_WITH_GREEN_POTION, ITEM_POTION_GREEN, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::customMessageTableID, GI_BOTTLE_WITH_POE, ITEM_POE, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", "", "" }); -} - -//std::string Randomizer::GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid) { -// if (!gSaveContext.n64ddFlag) { -// return "Not Randomized."; -// } -// -// return CustomMessage::Instance->RetrieveMessage(globalCtx, Randomizer::customMessageTableID, giid); -//} \ No newline at end of file From a21998c489518df35fd919efe21846360e534aca Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 24 Jul 2022 18:47:55 -0400 Subject: [PATCH 19/39] Does some refactoring of rando custom message registration The goal was less verbosity when adding new get-item messages later. --- .../custom_message/CustomMessage.h | 9 ++ .../Enhancements/randomizer/randomizer.cpp | 94 ++++++++++++------- 2 files changed, 67 insertions(+), 36 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.h b/soh/soh/Enhancements/custom_message/CustomMessage.h index 465d1fafc..69ddcbe61 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.h +++ b/soh/soh/Enhancements/custom_message/CustomMessage.h @@ -22,6 +22,15 @@ typedef struct { std::string french; } CustomMessageEntry; +// Message Entry without the text type and position, useful for when +// you need an array of these to loop over for registration +// that will all have the same textbox type and position. +typedef struct { + std::string english; + std::string german; + std::string french; +} CustomMessageMinimal; + #define NULL_CUSTOM_MESSAGE \ { (TextBoxType)(-1), (TextBoxPosition)(-1), "", "", "" } diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 77e426baf..14a729a41 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -4767,46 +4767,68 @@ void DrawRandoEditor(bool& open) { ImGui::End(); }*/ +typedef struct { + GetItemID giid; + ItemID iid; + std::string english; + std::string german; + std::string french; +} GetItemMessage; -void Randomizer::CreateCustomMessages() { - CustomMessage* customMessage = CustomMessage::Instance; - customMessage->AddCustomMessageTable(Randomizer::getItemMessageTableID); +void CreateGetItemMessages(std::vector messageEntries) { + CustomMessage* customMessage = CustomMessage::Instance; + customMessage->AddCustomMessageTable(Randomizer::getItemMessageTableID); + for (GetItemMessage messageEntry : messageEntries) { customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", "", - "" }); - customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", "", - "" }); - customMessage->CreateGetItemMessage( - Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_FISH, ITEM_FISH, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", "", "" }); - customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_BUGS, ITEM_BUG, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", "", - "" }); - customMessage->CreateGetItemMessage( - Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_FAIRY, ITEM_FAIRY, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rFairy in a Bottle%w!&Use it wisely!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_RED_POTION, ITEM_POTION_RED, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_GREEN_POTION, ITEM_POTION_GREEN, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", "", "" }); - customMessage->CreateGetItemMessage( - Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_POE, ITEM_POE, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, - "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", "", "" }); + messageEntry.english, messageEntry.german, + messageEntry.french }); } +} + +#define GIMESSAGE(giid, iid, english, german, french) \ + { giid, iid, english, german, french } + +void Randomizer::CreateCustomMessages() { + const std::vector getItemMessages = { + GIMESSAGE(GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, + "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", + "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", + "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!"), + GIMESSAGE(GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, + "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", + "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", + "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!"), + GIMESSAGE(GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, + "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", + "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", + "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!"), + GIMESSAGE(GI_BOTTLE_WITH_FISH, ITEM_FISH, + "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", + "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", + "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!"), + GIMESSAGE(GI_BOTTLE_WITH_BUGS, ITEM_BUG, + "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", + "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", + "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!"), + GIMESSAGE(GI_BOTTLE_WITH_FAIRY, ITEM_FAIRY, "You got a %rFairy in a Bottle%w!&Use it wisely!", + "You got a %rFairy in a Bottle%w!&Use it wisely!", + "You got a %rFairy in a Bottle%w!&Use it wisely!"), + GIMESSAGE(GI_BOTTLE_WITH_RED_POTION, ITEM_POTION_RED, + "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", + "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", + "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!"), + GIMESSAGE(GI_BOTTLE_WITH_GREEN_POTION, ITEM_POTION_GREEN, + "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", + "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", + "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!"), + GIMESSAGE(GI_BOTTLE_WITH_POE, ITEM_POE, + "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", + "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", + "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this..."), + }; + CreateGetItemMessages(getItemMessages); +} void InitRando() { SohImGui::AddWindow("Randomizer", "Randomizer Settings", DrawRandoEditor); From a33c3d606a906ef4fcc66532ef64758055d54068 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 24 Jul 2022 18:54:05 -0400 Subject: [PATCH 20/39] Fixes minor oversight from previous commit. --- soh/soh/Enhancements/randomizer/randomizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 14a729a41..9a84d80b9 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -4779,7 +4779,7 @@ void CreateGetItemMessages(std::vector messageEntries) { CustomMessage* customMessage = CustomMessage::Instance; customMessage->AddCustomMessageTable(Randomizer::getItemMessageTableID); for (GetItemMessage messageEntry : messageEntries) { - customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, + customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, messageEntry.giid, messageEntry.iid, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, messageEntry.english, messageEntry.german, messageEntry.french }); From 780e9f4669d8d00b10437c36f95487d6f26cfb0f Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 24 Jul 2022 19:18:46 -0400 Subject: [PATCH 21/39] Fixes storage of altar and ganon hints/text. Only one language is stored in gSaveContext at the moment so store the one language in all 3 CustomMessageEntry languages. --- .../Enhancements/randomizer/randomizer.cpp | 67 +++---------------- 1 file changed, 10 insertions(+), 57 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 9a84d80b9..ec5914c07 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -1486,16 +1486,20 @@ void Randomizer::LoadHintLocations(const char* spoilerFileName) { CustomMessage::Instance->CreateMessage( Randomizer::hintMessageTableID, 0x7040, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.childAltarText, "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.childAltarText, + gSaveContext.childAltarText, gSaveContext.childAltarText }); CustomMessage::Instance->CreateMessage( Randomizer::hintMessageTableID, 0x7088, - { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.adultAltarText, "", "" }); + { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.adultAltarText, + gSaveContext.adultAltarText, gSaveContext.adultAltarText }); CustomMessage::Instance->CreateMessage( Randomizer::hintMessageTableID, 0x70CC, - { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonHintText, "", "" }); + { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonHintText, + gSaveContext.ganonHintText, gSaveContext.ganonHintText }); CustomMessage::Instance->CreateMessage( Randomizer::hintMessageTableID, 0x70CD, - { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonText, "", "" }); + { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonText, + gSaveContext.ganonText, gSaveContext.ganonText }); this->childAltarText = gSaveContext.childAltarText; this->adultAltarText = gSaveContext.adultAltarText; @@ -1506,7 +1510,7 @@ void Randomizer::LoadHintLocations(const char* spoilerFileName) { if(hintLocation.check == RC_LINKS_POCKET) break; this->hintLocations[hintLocation.check] = hintLocation.hintText; CustomMessage::Instance->CreateMessage( - Randomizer::hintMessageTableID, hintLocation.check, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, hintLocation.hintText, "", "" }); + Randomizer::hintMessageTableID, hintLocation.check, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, hintLocation.hintText, hintLocation.hintText, hintLocation.hintText }); } } @@ -1818,58 +1822,7 @@ std::string AltarIconString(char iconChar) { std::string FormatJsonHintText(std::string jsonHint) { std::string formattedHintMessage = jsonHint; - char newLine = 0x01; - char playerName = 0x0F; - char nextBox = 0x04; - std::replace(formattedHintMessage.begin(), formattedHintMessage.end(), '&', newLine); - std::replace(formattedHintMessage.begin(), formattedHintMessage.end(), '^', nextBox); - std::replace(formattedHintMessage.begin(), formattedHintMessage.end(), '@', playerName); - - 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'}) { std::string textToReplace = "$"; From 661946b4f53ad6c2abdeeaee4234cfbd1c12e834 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 24 Jul 2022 19:24:24 -0400 Subject: [PATCH 22/39] Pulls altar text from CustomMessageTable instead of gSaveContext. --- soh/soh/OTRGlobals.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index f570c3b10..e749eb286 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1473,10 +1473,9 @@ extern "C" int CopyScrubMessage(u16 scrubTextId, char* buffer, const int maxBuff return CopyStringToCharBuffer(scrubText, buffer, maxBufferSize); } -extern "C" int Randomizer_CopyAltarMessage(char* buffer, const int maxBufferSize) { - const std::string& altarText = (LINK_IS_ADULT) ? OTRGlobals::Instance->gRandomizer->GetAdultAltarText() - : OTRGlobals::Instance->gRandomizer->GetChildAltarText(); - return CopyStringToCharBuffer(altarText, buffer, maxBufferSize); +extern "C" CustomMessageEntry Randomizer_CopyAltarMessage() { + return (LINK_IS_ADULT) ? CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7088) + : CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7040); } extern "C" int Randomizer_CopyGanonText(char* buffer, const int maxBufferSize) { @@ -1520,8 +1519,7 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { if (textId == 0xF8) { messageEntry = Randomizer_GetCustomGetItemMessage((GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize); - } - if (textId == 0x2053 && Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) != 0 && + } else if (textId == 0x2053 && Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) != 0 && (Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) == 1 || (Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) == 2 && Player_GetMask(globalCtx) == PLAYER_MASK_TRUTH) || @@ -1549,6 +1547,9 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { Randomizer_GetCheckFromActor(globalCtx->sceneNum, msgCtx->talkActor->id, actorParams); messageEntry = Randomizer_CopyHintFromCheck(hintCheck); + } else if (textId == 0x7040 || textId == 0x7088) { + // rando hints at altar + messageEntry = Randomizer_CopyAltarMessage(); } } if (textId == 0x00B4 || textId == 0x00B5) { From c1155bb08c46d29fe2917b244ade1b618e19cdaa Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 24 Jul 2022 19:35:24 -0400 Subject: [PATCH 23/39] Cleans up unused z_message_PAL code. --- soh/src/code/z_message_PAL.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index fa26cbad7..e85d4d3ce 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1675,10 +1675,7 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { //font->msgLength, __FILE__, __LINE__); } else { Message_FindMessage(globalCtx, textId); - if (gSaveContext.n64ddFlag && (textId == 0x7040 || textId == 0x7088)) { - // rando hints at altar - msgCtx->msgLength = font->msgLength = Randomizer_CopyAltarMessage(font->msgBuf, sizeof(font->msgBuf)); - } else if (gSaveContext.n64ddFlag && (textId == 0x10A2 || textId == 0x10DC || textId == 0x10DD)) { + if (gSaveContext.n64ddFlag && (textId == 0x10A2 || textId == 0x10DC || textId == 0x10DD)) { msgCtx->msgLength = font->msgLength = CopyScrubMessage(textId, font->msgBuf, sizeof(font->msgBuf)); } else if (gSaveContext.n64ddFlag && textId == 0x70CC) { if (INV_CONTENT(ITEM_ARROW_LIGHT) == ITEM_ARROW_LIGHT) { From 9f2eb466635c155610ef7871b46ec6815402bb39 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 24 Jul 2022 19:43:11 -0400 Subject: [PATCH 24/39] Takes Ganondor's text & hint from CustomMessageTable --- soh/soh/OTRGlobals.cpp | 16 ++++++++++------ soh/src/code/z_message_PAL.c | 6 ------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index e749eb286..658ee9a5a 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1478,14 +1478,12 @@ extern "C" CustomMessageEntry Randomizer_CopyAltarMessage() { : CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7040); } -extern "C" int Randomizer_CopyGanonText(char* buffer, const int maxBufferSize) { - const std::string& ganonText = OTRGlobals::Instance->gRandomizer->GetGanonText(); - return CopyStringToCharBuffer(ganonText, buffer, maxBufferSize); +extern "C" CustomMessageEntry Randomizer_CopyGanonText() { + return CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CD); } -extern "C" int Randomizer_CopyGanonHintText(char* buffer, const int maxBufferSize) { - const std::string& ganonText = OTRGlobals::Instance->gRandomizer->GetGanonHintText(); - return CopyStringToCharBuffer(ganonText, buffer, maxBufferSize); +extern "C" CustomMessageEntry Randomizer_CopyGanonHintText() { + return CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CC); } extern "C" CustomMessageEntry Randomizer_CopyHintFromCheck(RandomizerCheck check) { @@ -1550,6 +1548,12 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { } else if (textId == 0x7040 || textId == 0x7088) { // rando hints at altar messageEntry = Randomizer_CopyAltarMessage(); + } else if (gSaveContext.n64ddFlag && textId == 0x70CC) { + if (INV_CONTENT(ITEM_ARROW_LIGHT) == ITEM_ARROW_LIGHT) { + messageEntry = Randomizer_CopyGanonText(); + } else { + messageEntry = Randomizer_CopyGanonHintText(); + } } } if (textId == 0x00B4 || textId == 0x00B5) { diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index e85d4d3ce..57eafa1d7 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -1677,12 +1677,6 @@ void Message_OpenText(GlobalContext* globalCtx, u16 textId) { 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 if (gSaveContext.n64ddFlag && textId == 0x70CC) { - if (INV_CONTENT(ITEM_ARROW_LIGHT) == ITEM_ARROW_LIGHT) { - msgCtx->msgLength = font->msgLength = Randomizer_CopyGanonText(font->msgBuf, sizeof(font->msgBuf)); - } else { - msgCtx->msgLength = font->msgLength = Randomizer_CopyGanonHintText(font->msgBuf, sizeof(font->msgBuf)); - } } else { msgCtx->msgLength = font->msgLength; char* src = (uintptr_t)font->msgOffset; From cd01e8b7781d1b74ff7a77907666963691006d86 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Mon, 25 Jul 2022 21:31:17 -0400 Subject: [PATCH 25/39] 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]; From 4c9e4b2d842b9e608ba683fb36ddfc74b5b1d2cc Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Mon, 25 Jul 2022 22:04:53 -0400 Subject: [PATCH 26/39] Puts CustomMessage files in filters in Visual Studio --- soh/soh.vcxproj.filters | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/soh/soh.vcxproj.filters b/soh/soh.vcxproj.filters index 5f48ff042..f31a5171c 100644 --- a/soh/soh.vcxproj.filters +++ b/soh/soh.vcxproj.filters @@ -82,6 +82,12 @@ {04fc1c52-49ff-48e2-ae23-2c00867374f8} + + {8f355b3b-15ba-4e0a-be8b-2a6ec0ff4ec7} + + + {34b196e2-95d6-49b1-822d-0297d8114050} + @@ -2373,6 +2379,9 @@ Source Files\src + + Source Files\soh\Enhancements\custom-message + @@ -4061,6 +4070,9 @@ Source Files\src + + Header Files\soh\Enhancements\custom-message + @@ -4073,4 +4085,4 @@ - + \ No newline at end of file From 822476373bb42c5c94eeaaf13178f6bfcb839124 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Mon, 25 Jul 2022 22:33:38 -0400 Subject: [PATCH 27/39] Renames CustomMessage to CustomMessageManager --- soh/soh.vcxproj | 4 +- soh/soh.vcxproj.filters | 4 +- ...omMessage.cpp => CustomMessageManager.cpp} | 38 +++++++++---------- ...CustomMessage.h => CustomMessageManager.h} | 8 ++-- .../Enhancements/randomizer/randomizer.cpp | 20 +++++----- soh/soh/OTRGlobals.cpp | 22 +++++------ soh/soh/z_message_OTR.cpp | 16 ++++---- 7 files changed, 56 insertions(+), 56 deletions(-) rename soh/soh/Enhancements/custom_message/{CustomMessage.cpp => CustomMessageManager.cpp} (77%) rename soh/soh/Enhancements/custom_message/{CustomMessage.h => CustomMessageManager.h} (94%) diff --git a/soh/soh.vcxproj b/soh/soh.vcxproj index 1c1f3784a..27c1571da 100644 --- a/soh/soh.vcxproj +++ b/soh/soh.vcxproj @@ -179,7 +179,7 @@ - + @@ -944,7 +944,7 @@ - + diff --git a/soh/soh.vcxproj.filters b/soh/soh.vcxproj.filters index f31a5171c..ed0a1f200 100644 --- a/soh/soh.vcxproj.filters +++ b/soh/soh.vcxproj.filters @@ -2379,7 +2379,7 @@ Source Files\src - + Source Files\soh\Enhancements\custom-message @@ -4070,7 +4070,7 @@ Source Files\src - + Header Files\soh\Enhancements\custom-message diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.cpp b/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp similarity index 77% rename from soh/soh/Enhancements/custom_message/CustomMessage.cpp rename to soh/soh/Enhancements/custom_message/CustomMessageManager.cpp index 6ea820aa9..4f69102da 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp @@ -1,9 +1,9 @@ -#include "CustomMessage.h" +#include "CustomMessageManager.h" #include using namespace std::literals::string_literals; -CustomMessage::CustomMessage() { +CustomMessageManager::CustomMessageManager() { this->textBoxSpecialCharacters = { { "À", 0x80 }, { "î", 0x81 }, { "Â", 0x82 }, { "Ä", 0x83 }, { "Ç", 0x84 }, { "È", 0x85 }, { "É", 0x86 }, { "Ê", 0x87 }, { "Ë", 0x88 }, { "Ï", 0x89 }, { "Ô", 0x8A }, { "Ö", 0x8B }, { "Ù", 0x8C }, { "Û", 0x8D }, { "Ü", 0x8E }, @@ -15,13 +15,13 @@ CustomMessage::CustomMessage() { { "c", QM_LBLUE }, { "p", QM_PINK }, { "y", QM_YELLOW }, { "B", QM_BLACK } }; } -CustomMessage::~CustomMessage() { +CustomMessageManager::~CustomMessageManager() { this->textBoxSpecialCharacters.clear(); this->colors.clear(); this->messageTables.clear(); } -void CustomMessage::ReplaceSpecialCharacters(std::string& string) { +void CustomMessageManager::ReplaceSpecialCharacters(std::string& string) { // add special characters for (auto specialCharacterPair : this->textBoxSpecialCharacters) { size_t start_pos = 0; @@ -34,7 +34,7 @@ void CustomMessage::ReplaceSpecialCharacters(std::string& string) { } } -void CustomMessage::ReplaceColors(std::string& string) { +void CustomMessageManager::ReplaceColors(std::string& string) { for (auto colorPair : colors) { std::string textToReplace = "%"; textToReplace += colorPair.first; @@ -46,7 +46,7 @@ void CustomMessage::ReplaceColors(std::string& string) { } } -void CustomMessage::FormatCustomMessage(std::string& message, ItemID iid) { +void CustomMessageManager::FormatCustomMessage(std::string& message, ItemID iid) { message.insert(0, ITEM_OBTAINED(iid)); size_t start_pos = 0; std::replace(message.begin(), message.end(), '&', NEWLINE()[0]); @@ -60,7 +60,7 @@ void CustomMessage::FormatCustomMessage(std::string& message, ItemID iid) { message += MESSAGE_END(); } -void CustomMessage::FormatCustomMessage(std::string& message) { +void CustomMessageManager::FormatCustomMessage(std::string& message) { size_t start_pos = 0; std::replace(message.begin(), message.end(), '&', NEWLINE()[0]); std::replace(message.begin(), message.end(), '^', WAIT_FOR_INPUT()[0]); @@ -70,7 +70,7 @@ void CustomMessage::FormatCustomMessage(std::string& message) { message += MESSAGE_END(); } -bool CustomMessage::InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) { +bool CustomMessageManager::InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) { auto result = messageTables.find(tableID); if (result == messageTables.end()) { return false; @@ -82,7 +82,7 @@ bool CustomMessage::InsertCustomMessage(std::string tableID, uint16_t textID, Cu -bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) { +bool CustomMessageManager::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) { FormatCustomMessage(messages.english, iid); FormatCustomMessage(messages.german, iid); FormatCustomMessage(messages.french, iid); @@ -90,14 +90,14 @@ bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, It return InsertCustomMessage(tableID, textID, messages); } -bool CustomMessage::CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) { +bool CustomMessageManager::CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) { FormatCustomMessage(messages.english); FormatCustomMessage(messages.german); FormatCustomMessage(messages.french); return InsertCustomMessage(tableID, textID, messages); } -CustomMessageEntry CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) { +CustomMessageEntry CustomMessageManager::RetrieveMessage(std::string tableID, uint16_t textID) { std::unordered_map::const_iterator result = messageTables.find(tableID); if (result == messageTables.end()) { return NULL_CUSTOM_MESSAGE; @@ -111,7 +111,7 @@ CustomMessageEntry CustomMessage::RetrieveMessage(std::string tableID, uint16_t return message; } -bool CustomMessage::ClearMessageTable(std::string tableID) { +bool CustomMessageManager::ClearMessageTable(std::string tableID) { auto result = messageTables.find(tableID); if (result == messageTables.end()) { return false; @@ -120,31 +120,31 @@ bool CustomMessage::ClearMessageTable(std::string tableID) { messageTable.clear(); } -bool CustomMessage::AddCustomMessageTable(std::string tableID) { +bool CustomMessageManager::AddCustomMessageTable(std::string tableID) { CustomMessageTable newMessageTable; return messageTables.emplace(tableID, newMessageTable).second; } -std::string CustomMessage::MESSAGE_END() { +std::string CustomMessageManager::MESSAGE_END() { return "\x02"s; } -std::string CustomMessage::ITEM_OBTAINED(uint8_t x) { +std::string CustomMessageManager::ITEM_OBTAINED(uint8_t x) { return "\x13"s + char(x); } -std::string CustomMessage::NEWLINE() { +std::string CustomMessageManager::NEWLINE() { return "\x01"s; } -std::string CustomMessage::COLOR(uint8_t x) { +std::string CustomMessageManager::COLOR(uint8_t x) { return "\x05"s + char(x); } -std::string CustomMessage::WAIT_FOR_INPUT() { +std::string CustomMessageManager::WAIT_FOR_INPUT() { return "\x04"s; } -std::string CustomMessage::PLAYER_NAME() { +std::string CustomMessageManager::PLAYER_NAME() { return "\x0F"s; } \ No newline at end of file diff --git a/soh/soh/Enhancements/custom_message/CustomMessage.h b/soh/soh/Enhancements/custom_message/CustomMessageManager.h similarity index 94% rename from soh/soh/Enhancements/custom_message/CustomMessage.h rename to soh/soh/Enhancements/custom_message/CustomMessageManager.h index 69ddcbe61..207d515e3 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessage.h +++ b/soh/soh/Enhancements/custom_message/CustomMessageManager.h @@ -36,7 +36,7 @@ typedef struct { typedef std::unordered_map CustomMessageTable; -class CustomMessage { +class CustomMessageManager { private: std::unordered_map textBoxSpecialCharacters; std::unordered_map colors; @@ -56,10 +56,10 @@ class CustomMessage { std::string PLAYER_NAME(); public: - static CustomMessage* Instance; + static CustomMessageManager* Instance; - CustomMessage(); - ~CustomMessage(); + CustomMessageManager(); + ~CustomMessageManager(); bool CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages); bool CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages); diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 5159de0da..00bcadaf1 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -14,7 +14,7 @@ #include "3drando/rando_main.hpp" #include #include "Lib/ImGui/imgui_internal.h" -#include +#include using json = nlohmann::json; using namespace std::literals::string_literals; @@ -1483,22 +1483,22 @@ void Randomizer::LoadHintLocations(const char* spoilerFileName) { ParseHintLocationsFile(spoilerFileName); } - CustomMessage::Instance->ClearMessageTable(Randomizer::hintMessageTableID); - CustomMessage::Instance->AddCustomMessageTable(Randomizer::hintMessageTableID); + CustomMessageManager::Instance->ClearMessageTable(Randomizer::hintMessageTableID); + CustomMessageManager::Instance->AddCustomMessageTable(Randomizer::hintMessageTableID); - CustomMessage::Instance->CreateMessage( + CustomMessageManager::Instance->CreateMessage( Randomizer::hintMessageTableID, 0x7040, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.childAltarText, gSaveContext.childAltarText, gSaveContext.childAltarText }); - CustomMessage::Instance->CreateMessage( + CustomMessageManager::Instance->CreateMessage( Randomizer::hintMessageTableID, 0x7088, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.adultAltarText, gSaveContext.adultAltarText, gSaveContext.adultAltarText }); - CustomMessage::Instance->CreateMessage( + CustomMessageManager::Instance->CreateMessage( Randomizer::hintMessageTableID, 0x70CC, { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonHintText, gSaveContext.ganonHintText, gSaveContext.ganonHintText }); - CustomMessage::Instance->CreateMessage( + CustomMessageManager::Instance->CreateMessage( Randomizer::hintMessageTableID, 0x70CD, { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonText, gSaveContext.ganonText, gSaveContext.ganonText }); @@ -1511,7 +1511,7 @@ void Randomizer::LoadHintLocations(const char* spoilerFileName) { for (auto hintLocation : gSaveContext.hintLocations) { if(hintLocation.check == RC_LINKS_POCKET) break; this->hintLocations[hintLocation.check] = hintLocation.hintText; - CustomMessage::Instance->CreateMessage( + CustomMessageManager::Instance->CreateMessage( Randomizer::hintMessageTableID, hintLocation.check, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, hintLocation.hintText, hintLocation.hintText, hintLocation.hintText }); } } @@ -4750,7 +4750,7 @@ typedef struct { } GetItemMessage; void CreateGetItemMessages(std::vector messageEntries) { - CustomMessage* customMessage = CustomMessage::Instance; + CustomMessageManager* customMessage = CustomMessageManager::Instance; customMessage->AddCustomMessageTable(Randomizer::getItemMessageTableID); for (GetItemMessage messageEntry : messageEntries) { customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, messageEntry.giid, messageEntry.iid, @@ -4761,7 +4761,7 @@ void CreateGetItemMessages(std::vector messageEntries) { } void CreateScrubMessages() { - CustomMessage* customMessage = CustomMessage::Instance; + CustomMessageManager* customMessage = CustomMessageManager::Instance; customMessage->AddCustomMessageTable(Randomizer::scrubMessageTableID); const std::vector prices = { 10, 40 }; for (u8 price : prices) { diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 03a3eb7f5..c931edbd0 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -43,7 +43,7 @@ #include "variables.h" #include "macros.h" #include -#include +#include #ifdef __APPLE__ #include @@ -59,7 +59,7 @@ OTRGlobals* OTRGlobals::Instance; SaveManager* SaveManager::Instance; -CustomMessage* CustomMessage::Instance; +CustomMessageManager* CustomMessageManager::Instance; OTRGlobals::OTRGlobals() { context = Ship::GlobalCtx2::CreateInstance("Ship of Harkinian"); @@ -114,7 +114,7 @@ extern "C" void InitOTR() { #endif OTRGlobals::Instance = new OTRGlobals(); SaveManager::Instance = new SaveManager(); - CustomMessage::Instance = new CustomMessage(); + CustomMessageManager::Instance = new CustomMessageManager(); auto t = OTRGlobals::Instance->context->GetResourceManager()->LoadFile("version"); if (!t->bHasLoadError) @@ -1420,7 +1420,7 @@ extern "C" CustomMessageEntry Randomizer_CopyScrubMessage(u16 scrubTextId) { price = 40; break; } - return CustomMessage::Instance->RetrieveMessage(Randomizer::scrubMessageTableID, price); + return CustomMessageManager::Instance->RetrieveMessage(Randomizer::scrubMessageTableID, price); } extern "C" int CopyScrubMessage(u16 scrubTextId, char* buffer, const int maxBufferSize) { @@ -1496,22 +1496,22 @@ extern "C" int CopyScrubMessage(u16 scrubTextId, char* buffer, const int maxBuff } extern "C" CustomMessageEntry Randomizer_CopyAltarMessage() { - return (LINK_IS_ADULT) ? CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7088) - : CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7040); + return (LINK_IS_ADULT) ? CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7088) + : CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7040); } extern "C" CustomMessageEntry Randomizer_CopyGanonText() { - return CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CD); + return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CD); } extern "C" CustomMessageEntry Randomizer_CopyGanonHintText() { - return CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CC); + return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CC); } extern "C" CustomMessageEntry Randomizer_CopyHintFromCheck(RandomizerCheck check) { // we don't want to make a copy of the std::string returned from GetHintFromCheck // so we're just going to let RVO take care of it - const CustomMessageEntry hintText = CustomMessage::Instance->RetrieveMessage(Randomizer::hintMessageTableID, check); + const CustomMessageEntry hintText = CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, check); return hintText; } @@ -1524,7 +1524,7 @@ extern "C" s32 Randomizer_GetItemIdFromKnownCheck(RandomizerCheck randomizerChec } extern "C" CustomMessageEntry Randomizer_GetCustomGetItemMessage(GetItemID giid, char* buffer, const int maxBufferSize) { - const CustomMessageEntry getItemText = CustomMessage::Instance->RetrieveMessage(Randomizer::getItemMessageTableID, giid); + const CustomMessageEntry getItemText = CustomMessageManager::Instance->RetrieveMessage(Randomizer::getItemMessageTableID, giid); return getItemText; } @@ -1588,7 +1588,7 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { } else { textId = 0x00B5; } - messageEntry = CustomMessage::Instance->RetrieveMessage("BaseGameOverrides", textId); + messageEntry = CustomMessageManager::Instance->RetrieveMessage("BaseGameOverrides", textId); } } if (messageEntry.textBoxType != -1) { diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index c09286fad..64652189a 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -5,7 +5,7 @@ #include "global.h" #include "vt.h" #include -#include +#include extern "C" MessageTableEntry* sNesMessageEntryTablePtr; extern "C" MessageTableEntry* sGerMessageEntryTablePtr; @@ -95,21 +95,21 @@ extern "C" void OTRMessage_Init() sStaffMessageEntryTablePtr[i].msgSize = file2->messages[i].msg.size(); } - CustomMessage::Instance->AddCustomMessageTable(customMessageTableID); - CustomMessage::Instance->CreateGetItemMessage( + CustomMessageManager::Instance->AddCustomMessageTable(customMessageTableID); + CustomMessageManager::Instance->CreateGetItemMessage( customMessageTableID, (GetItemID)0x00B4, ITEM_SKULL_TOKEN, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!\x0E\x3C", - "Du erhlst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!\x0E\x3C", - "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collect %r\x19\%w symboles en tout!\x0E\x3C" + "Du erhälst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!\x0E\x3C", + "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collecté %r\x19\%w symboles en tout!\x0E\x3C" } ); - CustomMessage::Instance->CreateGetItemMessage( + CustomMessageManager::Instance->CreateGetItemMessage( customMessageTableID, (GetItemID)0x00B5, ITEM_SKULL_TOKEN, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!", - "Du erhlst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!", - "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collect %r\x19\%w symboles en tout!" }); + "Du erhälst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!", + "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collecté %r\x19\%w symboles en tout!" }); } \ No newline at end of file From 59dc52f3940fd236bbd8403f9be6957106f3bd1e Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 26 Jul 2022 18:44:52 -0400 Subject: [PATCH 28/39] Moves the NOGDI define to CustomMessageManager.h --- soh/include/z64.h | 3 --- soh/soh/Enhancements/custom_message/CustomMessageManager.h | 6 ++++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/soh/include/z64.h b/soh/include/z64.h index a16134f08..fdc634e58 100644 --- a/soh/include/z64.h +++ b/soh/include/z64.h @@ -30,9 +30,6 @@ #include "ichain.h" #include "regs.h" -#define NOGDI -#define WIN32_LEAN_AND_MEAN - #if defined(_WIN64) || defined(__x86_64__) || defined(__arm64__) #define _SOH64 #endif diff --git a/soh/soh/Enhancements/custom_message/CustomMessageManager.h b/soh/soh/Enhancements/custom_message/CustomMessageManager.h index 207d515e3..aed3fbf9a 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageManager.h +++ b/soh/soh/Enhancements/custom_message/CustomMessageManager.h @@ -1,6 +1,12 @@ #pragma once #include #include + + +#define NOGDI +#define WIN32_LEAN_AND_MEAN + + #include #undef MESSAGE_END From 0ed8c277e8c24357bf7e26db9b5bf8be049c6ce2 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 26 Jul 2022 19:07:54 -0400 Subject: [PATCH 29/39] Renames some variables for clarity --- .../custom_message/CustomMessageManager.cpp | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp b/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp index 4f69102da..f5c31aa5b 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp @@ -71,43 +71,43 @@ void CustomMessageManager::FormatCustomMessage(std::string& message) { } bool CustomMessageManager::InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) { - auto result = messageTables.find(tableID); - if (result == messageTables.end()) { + auto foundMessageTable = messageTables.find(tableID); + if (foundMessageTable == messageTables.end()) { return false; } - auto& messageTable = result->second; - auto success = messageTable.emplace(textID, messages); - return success.second; + auto& messageTable = foundMessageTable->second; + auto messageInsertResult = messageTable.emplace(textID, messages); + return messageInsertResult.second; } -bool CustomMessageManager::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) { - FormatCustomMessage(messages.english, iid); - FormatCustomMessage(messages.german, iid); - FormatCustomMessage(messages.french, iid); +bool CustomMessageManager::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messageEntry) { + FormatCustomMessage(messageEntry.english, iid); + FormatCustomMessage(messageEntry.german, iid); + FormatCustomMessage(messageEntry.french, iid); const uint16_t textID = giid; - return InsertCustomMessage(tableID, textID, messages); + return InsertCustomMessage(tableID, textID, messageEntry); } -bool CustomMessageManager::CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) { - FormatCustomMessage(messages.english); - FormatCustomMessage(messages.german); - FormatCustomMessage(messages.french); - return InsertCustomMessage(tableID, textID, messages); +bool CustomMessageManager::CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messageEntry) { + FormatCustomMessage(messageEntry.english); + FormatCustomMessage(messageEntry.german); + FormatCustomMessage(messageEntry.french); + return InsertCustomMessage(tableID, textID, messageEntry); } CustomMessageEntry CustomMessageManager::RetrieveMessage(std::string tableID, uint16_t textID) { - std::unordered_map::const_iterator result = messageTables.find(tableID); - if (result == messageTables.end()) { + std::unordered_map::const_iterator foundMessageTable = messageTables.find(tableID); + if (foundMessageTable == messageTables.end()) { return NULL_CUSTOM_MESSAGE; } - CustomMessageTable messageTable = result->second; - std::unordered_map::const_iterator message_pair = messageTable.find(textID); - if (message_pair == messageTable.end()) { + CustomMessageTable messageTable = foundMessageTable->second; + std::unordered_map::const_iterator foundMessage = messageTable.find(textID); + if (foundMessage == messageTable.end()) { return NULL_CUSTOM_MESSAGE; } - CustomMessageEntry message = message_pair->second; + CustomMessageEntry message = foundMessage->second; return message; } From d0968a99c154e1409f80d6428910c28d2ff20af6 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 26 Jul 2022 19:25:17 -0400 Subject: [PATCH 30/39] Removes some unneeded function definitions (some of which were already commented out). --- soh/soh/Enhancements/randomizer/randomizer.h | 2 - soh/soh/OTRGlobals.cpp | 72 -------------------- soh/soh/OTRGlobals.h | 3 - 3 files changed, 77 deletions(-) diff --git a/soh/soh/Enhancements/randomizer/randomizer.h b/soh/soh/Enhancements/randomizer/randomizer.h index a89c1f706..1994cfdc4 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.h +++ b/soh/soh/Enhancements/randomizer/randomizer.h @@ -43,10 +43,8 @@ class Randomizer { std::string GetAdultAltarText() const; std::string GetGanonText() const; std::string GetGanonHintText() const; - //CustomMessageEntry GetHintFromCheck(RandomizerCheck check); GetItemID GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); GetItemID GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); - //std::string GetCustomGetItemMessage(GlobalContext* globalCtx, GetItemID giid); static void CreateCustomMessages(); }; diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index c931edbd0..6d379ef35 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1423,78 +1423,6 @@ extern "C" CustomMessageEntry Randomizer_CopyScrubMessage(u16 scrubTextId) { return CustomMessageManager::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); - int price = 0; - switch (scrubTextId) { - case 0x10A2: - price = 10; - break; - case 0x10DC: - case 0x10DD: - price = 40; - break; - } - switch (language) { - case 0: default: - scrubText += 0x12; // add the sound - scrubText += 0x38; // sound id - scrubText += 0x82; // sound id - scrubText += "All right! You win! In return for"; - scrubText += 0x01; // newline - scrubText += "sparing me, I will sell you a"; - scrubText += 0x01; // newline - scrubText += 0x05; // change the color - scrubText += 0x42; // green - scrubText += "mysterious item"; - scrubText += 0x05; // change the color - scrubText += 0x40; // white - scrubText += "!"; - scrubText += 0x01; // newline - scrubText += 0x05; // change the color - scrubText += 0x41; // red - scrubText += std::to_string(price); - scrubText += price > 1 ? " Rupees" : " Rupee"; - scrubText += 0x05; // change the color - scrubText += 0x40; // white - scrubText += " it is!"; - scrubText += 0x07; // go to a new message - scrubText += 0x10; // message id - scrubText += 0xA3; // message id - break; - case 2: - scrubText += 0x12; // add the sound - scrubText += 0x38; // sound id - scrubText += 0x82; // sound id - scrubText += "J'abandonne! Tu veux bien m'acheter"; - scrubText += 0x01; // newline - scrubText += "un "; - scrubText += 0x05; // change the color - scrubText += 0x42; // green - scrubText += "objet myst\x96rieux"; - //scrubText += "; - scrubText += 0x05; // change the color - scrubText += 0x40; // white - scrubText += "?"; - scrubText += 0x01; // newline - scrubText += "\x84"; - scrubText += "a fera "; - scrubText += 0x05; // change the color - scrubText += 0x41; // red - scrubText += std::to_string(price) + " Rubis"; - scrubText += 0x05; // change the color - scrubText += 0x40; // white - scrubText += "!"; - scrubText += 0x07; // go to a new message - scrubText += 0x10; // message id - scrubText += 0xA3; // message id - break; - } - - return CopyStringToCharBuffer(scrubText, buffer, maxBufferSize); -} - extern "C" CustomMessageEntry Randomizer_CopyAltarMessage() { return (LINK_IS_ADULT) ? CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7088) : CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7040); diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 4a924ed61..76212c676 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -87,9 +87,6 @@ Sprite* GetSeedTexture(uint8_t index); void Randomizer_LoadSettings(const char* spoilerFileName); u8 Randomizer_GetSettingValue(RandomizerSettingKey randoSettingKey); RandomizerCheck Randomizer_GetCheckFromActor(s16 actorId, s16 actorParams, s16 sceneNum); -int Randomizer_CopyAltarMessage(char* buffer, const int maxBufferSize); -int Randomizer_CopyGanonText(char* buffer, const int maxBufferSize); -int Randomizer_CopyGanonHintText(char* buffer, const int maxBufferSize); void Randomizer_LoadHintLocations(const char* spoilerFileName); void Randomizer_LoadItemLocations(const char* spoilerFileName, bool silent); s16 Randomizer_GetItemModelFromId(s16 itemId); From 5a97e9f0dea1faf45504e09330b03a38b7bf61e1 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 26 Jul 2022 20:11:17 -0400 Subject: [PATCH 31/39] Factors away some raw textIDs into an enum with descriptive names. --- soh/soh.vcxproj | 1 + soh/soh.vcxproj.filters | 3 ++ .../custom_message/CustomMessageTypes.h | 14 +++++++++ soh/soh/OTRGlobals.cpp | 31 ++++++++++--------- soh/soh/z_message_OTR.cpp | 5 +-- .../actors/ovl_player_actor/z_player.c | 19 ++++++------ 6 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 soh/soh/Enhancements/custom_message/CustomMessageTypes.h diff --git a/soh/soh.vcxproj b/soh/soh.vcxproj index 27c1571da..12148eae6 100644 --- a/soh/soh.vcxproj +++ b/soh/soh.vcxproj @@ -946,6 +946,7 @@ + diff --git a/soh/soh.vcxproj.filters b/soh/soh.vcxproj.filters index ed0a1f200..554f6a754 100644 --- a/soh/soh.vcxproj.filters +++ b/soh/soh.vcxproj.filters @@ -4073,6 +4073,9 @@ Header Files\soh\Enhancements\custom-message + + Source Files\soh\Enhancements\custom-message + diff --git a/soh/soh/Enhancements/custom_message/CustomMessageTypes.h b/soh/soh/Enhancements/custom_message/CustomMessageTypes.h new file mode 100644 index 000000000..dac9362d9 --- /dev/null +++ b/soh/soh/Enhancements/custom_message/CustomMessageTypes.h @@ -0,0 +1,14 @@ +#pragma once + +typedef enum { + TEXT_GS_NO_FREEZE = 0xB4, + TEXT_GS_FREEZE = 0xB5, + TEXT_RANDOMIZER_GI_ESCAPE_HATCH = 0xF8, + TEXT_SCRUB_POH = 0x10A2, + TEXT_SCRUB_STICK_UPGRADE = 0x10DC, + TEXT_SCRUB_NUT_UPGRADE = 0x10DD, + TEXT_RANDOMIZER_GOSSIP_STONE_HINTS = 0x2053, + TEXT_ALTAR_CHILD = 0x7040, + TEXT_ALTAR_ADULT = 0x7088, + TEXT_GANONDORF = 0x70CC, +} TextIDs; \ No newline at end of file diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 6d379ef35..29c763998 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -56,6 +56,7 @@ #endif #include +#include OTRGlobals* OTRGlobals::Instance; SaveManager* SaveManager::Instance; @@ -1412,11 +1413,11 @@ extern "C" RandomizerCheck Randomizer_GetCheckFromActor(s16 sceneNum, s16 actorI extern "C" CustomMessageEntry Randomizer_CopyScrubMessage(u16 scrubTextId) { int price = 0; switch (scrubTextId) { - case 0x10A2: + case TEXT_SCRUB_POH: price = 10; break; - case 0x10DC: - case 0x10DD: + case TEXT_SCRUB_STICK_UPGRADE: + case TEXT_SCRUB_NUT_UPGRADE: price = 40; break; } @@ -1424,16 +1425,17 @@ extern "C" CustomMessageEntry Randomizer_CopyScrubMessage(u16 scrubTextId) { } extern "C" CustomMessageEntry Randomizer_CopyAltarMessage() { - return (LINK_IS_ADULT) ? CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7088) - : CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x7040); + return (LINK_IS_ADULT) + ? CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, TEXT_ALTAR_ADULT) + : CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, TEXT_ALTAR_CHILD); } extern "C" CustomMessageEntry Randomizer_CopyGanonText() { - return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CD); + return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, TEXT_GANONDORF + 1); } extern "C" CustomMessageEntry Randomizer_CopyGanonHintText() { - return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, 0x70CC); + return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, TEXT_GANONDORF); } extern "C" CustomMessageEntry Randomizer_CopyHintFromCheck(RandomizerCheck check) { @@ -1464,7 +1466,7 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { const int maxBufferSize = sizeof(font->msgBuf); CustomMessageEntry messageEntry; if (gSaveContext.n64ddFlag) { - if (textId == 0xF8) { + if (textId == TEXT_RANDOMIZER_GI_ESCAPE_HATCH) { messageEntry = Randomizer_GetCustomGetItemMessage((GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize); } else if (textId == 0x2053 && Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) != 0 && @@ -1495,26 +1497,25 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { Randomizer_GetCheckFromActor(globalCtx->sceneNum, msgCtx->talkActor->id, actorParams); messageEntry = Randomizer_CopyHintFromCheck(hintCheck); - } else if (textId == 0x7040 || textId == 0x7088) { + } else if (textId == TEXT_ALTAR_CHILD || textId == TEXT_ALTAR_ADULT) { // rando hints at altar messageEntry = Randomizer_CopyAltarMessage(); - } else if (gSaveContext.n64ddFlag && textId == 0x70CC) { + } else if (textId == TEXT_GANONDORF) { if (INV_CONTENT(ITEM_ARROW_LIGHT) == ITEM_ARROW_LIGHT) { messageEntry = Randomizer_CopyGanonText(); } else { messageEntry = Randomizer_CopyGanonHintText(); } - } else if (textId == 0x10A2 || textId == 0x10DC || textId == 0x10DD) { + } else if (textId == TEXT_SCRUB_POH || textId == TEXT_SCRUB_STICK_UPGRADE || textId == TEXT_SCRUB_NUT_UPGRADE) { messageEntry = Randomizer_CopyScrubMessage(textId); } } - if (textId == 0x00B4 || textId == 0x00B5) { + if (textId == TEXT_GS_NO_FREEZE || textId == TEXT_GS_FREEZE) { if (CVar_GetS32("gInjectSkulltulaCount", 0) != 0) { - font->charTexBuf[0] = 0x03; if (CVar_GetS32("gSkulltulaFreeze", 0) != 0) { - textId = 0x00B4; + textId = TEXT_GS_NO_FREEZE; } else { - textId = 0x00B5; + textId = TEXT_GS_FREEZE; } messageEntry = CustomMessageManager::Instance->RetrieveMessage("BaseGameOverrides", textId); } diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index 64652189a..188e569bb 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -6,6 +6,7 @@ #include "vt.h" #include #include +#include extern "C" MessageTableEntry* sNesMessageEntryTablePtr; extern "C" MessageTableEntry* sGerMessageEntryTablePtr; @@ -97,7 +98,7 @@ extern "C" void OTRMessage_Init() CustomMessageManager::Instance->AddCustomMessageTable(customMessageTableID); CustomMessageManager::Instance->CreateGetItemMessage( - customMessageTableID, (GetItemID)0x00B4, ITEM_SKULL_TOKEN, + customMessageTableID, (GetItemID)TEXT_GS_NO_FREEZE, ITEM_SKULL_TOKEN, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!\x0E\x3C", @@ -106,7 +107,7 @@ extern "C" void OTRMessage_Init() } ); CustomMessageManager::Instance->CreateGetItemMessage( - customMessageTableID, (GetItemID)0x00B5, ITEM_SKULL_TOKEN, + customMessageTableID, (GetItemID)TEXT_GS_FREEZE, ITEM_SKULL_TOKEN, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!", diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index ee13e0261..e1e3813f5 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -20,6 +20,7 @@ #include "objects/gameplay_keep/gameplay_keep.h" #include "objects/object_link_child/object_link_child.h" #include "textures/icon_item_24_static/icon_item_24_static.h" +#include "../../../../soh/Enhancements/custom_message/CustomMessageTypes.h" typedef struct { /* 0x00 */ u8 itemId; @@ -652,15 +653,15 @@ static GetItemEntry sGetItemTable[] = { GET_ITEM(ITEM_DOUBLE_MAGIC, OBJECT_GI_MAGICPOT, GID_MAGIC_LARGE, 0xE8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_DOUBLE_DEFENSE, OBJECT_GI_HEARTS, GID_HEART_CONTAINER, 0xE9, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_RED_POTION, OBJECT_GI_LIQUID, GID_POTION_RED, 0xF8, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_GREEN_POTION, OBJECT_GI_LIQUID, GID_POTION_GREEN, 0xF8, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BLUE_POTION, OBJECT_GI_LIQUID, GID_POTION_BLUE, 0xF8, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_FAIRY, OBJECT_GI_BOTTLE, GID_BOTTLE, 0xF8, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_FISH, OBJECT_GI_FISH, GID_FISH, 0xF8, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BLUE_FIRE, OBJECT_GI_FIRE, GID_BLUE_FIRE, 0xF8, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BUGS, OBJECT_GI_INSECT, GID_BUG, 0xF8, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_POE, OBJECT_GI_GHOST, GID_POE, 0xF8, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BIG_POE, OBJECT_GI_GHOST, GID_BIG_POE, 0xF8, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_RED_POTION, OBJECT_GI_LIQUID, GID_POTION_RED, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_GREEN_POTION, OBJECT_GI_LIQUID, GID_POTION_GREEN, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BLUE_POTION, OBJECT_GI_LIQUID, GID_POTION_BLUE, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_FAIRY, OBJECT_GI_BOTTLE, GID_BOTTLE, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_FISH, OBJECT_GI_FISH, GID_FISH, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BLUE_FIRE, OBJECT_GI_FIRE, GID_BLUE_FIRE, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BUGS, OBJECT_GI_INSECT, GID_BUG, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_POE, OBJECT_GI_GHOST, GID_POE, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BIG_POE, OBJECT_GI_GHOST, GID_BIG_POE, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), GET_ITEM_NONE, GET_ITEM_NONE, From e8d2b0cceb651a7874e18f6edd49412a89f7458a Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 26 Jul 2022 20:46:49 -0400 Subject: [PATCH 32/39] Hopefully fixes build errors on Linux-CI. --- .../custom_message/CustomMessageManager.h | 33 +++++++++++++++---- soh/soh/OTRGlobals.cpp | 1 + soh/soh/z_message_OTR.cpp | 1 + 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessageManager.h b/soh/soh/Enhancements/custom_message/CustomMessageManager.h index aed3fbf9a..c08aaf07d 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageManager.h +++ b/soh/soh/Enhancements/custom_message/CustomMessageManager.h @@ -1,13 +1,7 @@ #pragma once #include #include - - -#define NOGDI -#define WIN32_LEAN_AND_MEAN - - -#include +#include "z64item.h" #undef MESSAGE_END @@ -20,6 +14,31 @@ #define QM_YELLOW 0x46 #define QM_BLACK 0x47 +#ifndef MESSAGE_DATA_STATIC_H + +typedef enum { + /* 0 */ TEXTBOX_TYPE_BLACK, + /* 1 */ TEXTBOX_TYPE_WOODEN, + /* 2 */ TEXTBOX_TYPE_BLUE, + /* 3 */ TEXTBOX_TYPE_OCARINA, + /* 4 */ TEXTBOX_TYPE_NONE_BOTTOM, + /* 5 */ TEXTBOX_TYPE_NONE_NO_SHADOW, + /* 11 */ TEXTBOX_TYPE_CREDITS = 11 +} TextBoxType; + +typedef enum { + /* 0 */ TEXTBOX_BG_CROSS +} TextBoxBackground; + +typedef enum { + /* 0 */ TEXTBOX_POS_VARIABLE, + /* 1 */ TEXTBOX_POS_TOP, + /* 2 */ TEXTBOX_POS_MIDDLE, + /* 3 */ TEXTBOX_POS_BOTTOM +} TextBoxPosition; + +#endif + typedef struct { TextBoxType textBoxType; TextBoxPosition textBoxPos; diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 29c763998..aa28b5e98 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -57,6 +57,7 @@ #include #include +#include OTRGlobals* OTRGlobals::Instance; SaveManager* SaveManager::Instance; diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index 188e569bb..f4c836d94 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -5,6 +5,7 @@ #include "global.h" #include "vt.h" #include +#include #include #include From 2f9874c68f2a8e37839be4e382c686a7a56d3136 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Sun, 31 Jul 2022 19:31:22 -0400 Subject: [PATCH 33/39] Cleanup. --- .../custom_message/CustomMessageManager.cpp | 6 +++--- soh/soh/Enhancements/randomizer/randomizer.cpp | 18 +++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp b/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp index f5c31aa5b..e4e190c5c 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp @@ -112,11 +112,11 @@ CustomMessageEntry CustomMessageManager::RetrieveMessage(std::string tableID, ui } bool CustomMessageManager::ClearMessageTable(std::string tableID) { - auto result = messageTables.find(tableID); - if (result == messageTables.end()) { + auto foundMessageTable = messageTables.find(tableID); + if (foundMessageTable == messageTables.end()) { return false; } - auto& messageTable = result->second; + auto& messageTable = foundMessageTable->second; messageTable.clear(); } diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 00bcadaf1..dcfa36675 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -1843,7 +1843,7 @@ std::string FormatJsonHintText(std::string jsonHint) { 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'}) { std::string textToReplace = "$"; @@ -2403,10 +2403,6 @@ std::string Randomizer::GetGanonHintText() const { return ganonHintText; } -//CustomMessageEntry Randomizer::GetHintFromCheck(RandomizerCheck check) { -// return CustomMessage::Instance->RetrieveMessage(hintMessageTableID, check); -//} - u8 Randomizer::GetRandoSettingValue(RandomizerSettingKey randoSettingKey) { return this->randoSettings[randoSettingKey]; } @@ -4750,10 +4746,10 @@ typedef struct { } GetItemMessage; void CreateGetItemMessages(std::vector messageEntries) { - CustomMessageManager* customMessage = CustomMessageManager::Instance; - customMessage->AddCustomMessageTable(Randomizer::getItemMessageTableID); + CustomMessageManager* customMessageManager = CustomMessageManager::Instance; + customMessageManager->AddCustomMessageTable(Randomizer::getItemMessageTableID); for (GetItemMessage messageEntry : messageEntries) { - customMessage->CreateGetItemMessage(Randomizer::getItemMessageTableID, messageEntry.giid, messageEntry.iid, + customMessageManager->CreateGetItemMessage(Randomizer::getItemMessageTableID, messageEntry.giid, messageEntry.iid, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, messageEntry.english, messageEntry.german, messageEntry.french }); @@ -4761,11 +4757,11 @@ void CreateGetItemMessages(std::vector messageEntries) { } void CreateScrubMessages() { - CustomMessageManager* customMessage = CustomMessageManager::Instance; - customMessage->AddCustomMessageTable(Randomizer::scrubMessageTableID); + CustomMessageManager* customMessageManager = CustomMessageManager::Instance; + customMessageManager->AddCustomMessageTable(Randomizer::scrubMessageTableID); const std::vector prices = { 10, 40 }; for (u8 price : prices) { - customMessage->CreateMessage(Randomizer::scrubMessageTableID, price, + customMessageManager->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", From 4d30cc50a1cbde78132f4f79f49cdd2765c818d4 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Mon, 1 Aug 2022 21:21:29 -0400 Subject: [PATCH 34/39] Adds newlines to the ends of some files. --- soh/soh/Enhancements/custom_message/CustomMessageManager.cpp | 2 +- soh/soh/Enhancements/custom_message/CustomMessageManager.h | 2 +- soh/soh/Enhancements/custom_message/CustomMessageTypes.h | 2 +- soh/soh/z_message_OTR.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp b/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp index e4e190c5c..d7dd08991 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp +++ b/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp @@ -147,4 +147,4 @@ std::string CustomMessageManager::WAIT_FOR_INPUT() { std::string CustomMessageManager::PLAYER_NAME() { return "\x0F"s; -} \ No newline at end of file +} diff --git a/soh/soh/Enhancements/custom_message/CustomMessageManager.h b/soh/soh/Enhancements/custom_message/CustomMessageManager.h index c08aaf07d..6156f2ef8 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageManager.h +++ b/soh/soh/Enhancements/custom_message/CustomMessageManager.h @@ -91,4 +91,4 @@ class CustomMessageManager { CustomMessageEntry RetrieveMessage(std::string tableID, uint16_t textID); bool ClearMessageTable(std::string tableID); bool AddCustomMessageTable(std::string tableID); -}; \ No newline at end of file +}; diff --git a/soh/soh/Enhancements/custom_message/CustomMessageTypes.h b/soh/soh/Enhancements/custom_message/CustomMessageTypes.h index dac9362d9..fd065f354 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageTypes.h +++ b/soh/soh/Enhancements/custom_message/CustomMessageTypes.h @@ -11,4 +11,4 @@ typedef enum { TEXT_ALTAR_CHILD = 0x7040, TEXT_ALTAR_ADULT = 0x7088, TEXT_GANONDORF = 0x70CC, -} TextIDs; \ No newline at end of file +} TextIDs; diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index f4c836d94..cdc1c79e8 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -114,4 +114,4 @@ extern "C" void OTRMessage_Init() "You got a %rGold Skulltula Token%w!&You've collected %r\x19%w tokens&in total!", "Du erhälst ein %rGoldene&Skulltula-Symbol%w! Du hast&insgesamt %r\x19%w symbol gesammelt!", "Vous obtenez un %rSymbole de&Skulltula d'or%w! Vous avez&collecté %r\x19\%w symboles en tout!" }); -} \ No newline at end of file +} From eae97cff798dd259eedfc0dbc7cf63e92145037b Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Mon, 1 Aug 2022 21:44:28 -0400 Subject: [PATCH 35/39] Addresses most of bria's comments. --- .../custom_message/CustomMessageTypes.h | 21 ++++++- .../Enhancements/randomizer/randomizer.cpp | 59 ++++++------------- soh/soh/OTRGlobals.cpp | 26 ++++---- .../actors/ovl_player_actor/z_player.c | 18 +++--- 4 files changed, 59 insertions(+), 65 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessageTypes.h b/soh/soh/Enhancements/custom_message/CustomMessageTypes.h index fd065f354..d2f30f123 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageTypes.h +++ b/soh/soh/Enhancements/custom_message/CustomMessageTypes.h @@ -3,7 +3,7 @@ typedef enum { TEXT_GS_NO_FREEZE = 0xB4, TEXT_GS_FREEZE = 0xB5, - TEXT_RANDOMIZER_GI_ESCAPE_HATCH = 0xF8, + TEXT_RANDOMIZER_CUSTOM_ITEM = 0xF8, TEXT_SCRUB_POH = 0x10A2, TEXT_SCRUB_STICK_UPGRADE = 0x10DC, TEXT_SCRUB_NUT_UPGRADE = 0x10DD, @@ -11,4 +11,23 @@ typedef enum { TEXT_ALTAR_CHILD = 0x7040, TEXT_ALTAR_ADULT = 0x7088, TEXT_GANONDORF = 0x70CC, + TEXT_GANONDORF_NOHINT = 0x70CD } TextIDs; + +#ifdef __cplusplus + +typedef struct { + GetItemID giid; + ItemID iid; + std::string english; + std::string german; + std::string french; +} GetItemMessage; + +#define GIMESSAGE(giid, iid, english, german, french) \ + { giid, iid, english, german, french } + +#define GIMESSAGE_UNTRANSLATED(giid, iid, message) \ + { giid, iid, message, message, message } + +#endif diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index dcfa36675..c0077a97e 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -15,6 +15,7 @@ #include #include "Lib/ImGui/imgui_internal.h" #include +#include using json = nlohmann::json; using namespace std::literals::string_literals; @@ -1487,19 +1488,19 @@ void Randomizer::LoadHintLocations(const char* spoilerFileName) { CustomMessageManager::Instance->AddCustomMessageTable(Randomizer::hintMessageTableID); CustomMessageManager::Instance->CreateMessage( - Randomizer::hintMessageTableID, 0x7040, + Randomizer::hintMessageTableID, TEXT_ALTAR_CHILD, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.childAltarText, gSaveContext.childAltarText, gSaveContext.childAltarText }); CustomMessageManager::Instance->CreateMessage( - Randomizer::hintMessageTableID, 0x7088, + Randomizer::hintMessageTableID, TEXT_ALTAR_ADULT, { TEXTBOX_TYPE_BLUE, TEXTBOX_POS_BOTTOM, gSaveContext.adultAltarText, gSaveContext.adultAltarText, gSaveContext.adultAltarText }); CustomMessageManager::Instance->CreateMessage( - Randomizer::hintMessageTableID, 0x70CC, + Randomizer::hintMessageTableID, TEXT_GANONDORF, { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonHintText, gSaveContext.ganonHintText, gSaveContext.ganonHintText }); CustomMessageManager::Instance->CreateMessage( - Randomizer::hintMessageTableID, 0x70CD, + Randomizer::hintMessageTableID, TEXT_GANONDORF_NOHINT, { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, gSaveContext.ganonText, gSaveContext.ganonText, gSaveContext.ganonText }); @@ -4737,14 +4738,6 @@ void DrawRandoEditor(bool& open) { ImGui::End(); }*/ -typedef struct { - GetItemID giid; - ItemID iid; - std::string english; - std::string german; - std::string french; -} GetItemMessage; - void CreateGetItemMessages(std::vector messageEntries) { CustomMessageManager* customMessageManager = CustomMessageManager::Instance; customMessageManager->AddCustomMessageTable(Randomizer::getItemMessageTableID); @@ -4765,6 +4758,7 @@ void CreateScrubMessages() { { 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", + // RANDTODO: Translate the below string to German. "\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" + @@ -4773,45 +4767,26 @@ void CreateScrubMessages() { } } -#define GIMESSAGE(giid, iid, english, german, french) \ - { giid, iid, english, german, french } - void Randomizer::CreateCustomMessages() { + // RANDTODO: Translate into french and german and replace GIMESSAGE_UNTRANSLATED + // with GIMESSAGE(getItemID, itemID, english, german, french). const std::vector getItemMessages = { - GIMESSAGE(GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, - "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", - "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!", + GIMESSAGE_UNTRANSLATED(GI_BOTTLE_WITH_BLUE_FIRE, ITEM_BLUE_FIRE, "You got a %rBottle with Blue &Fire%w! Use it to melt Red Ice!"), - GIMESSAGE(GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, - "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", - "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!", + GIMESSAGE_UNTRANSLATED(GI_BOTTLE_WITH_BIG_POE, ITEM_BIG_POE, "You got a %rBig Poe in a Bottle%w!&Sell it to the Ghost Shop!"), - GIMESSAGE(GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, - "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", - "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!", + GIMESSAGE_UNTRANSLATED(GI_BOTTLE_WITH_BLUE_POTION, ITEM_POTION_BLUE, "You got a %rBottle of Blue Potion%w!&Drink it to replenish your&%ghealth%w and %bmagic%w!"), - GIMESSAGE(GI_BOTTLE_WITH_FISH, ITEM_FISH, - "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", - "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!", + GIMESSAGE_UNTRANSLATED(GI_BOTTLE_WITH_FISH, ITEM_FISH, "You got a %rFish in a Bottle%w!&It looks fresh and delicious!&They say Jabu-Jabu loves them!"), - GIMESSAGE(GI_BOTTLE_WITH_BUGS, ITEM_BUG, - "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", - "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!", + GIMESSAGE_UNTRANSLATED(GI_BOTTLE_WITH_BUGS, ITEM_BUG, "You got a %rBug in a Bottle%w!&They love to burrow in&dirt holes!"), - GIMESSAGE(GI_BOTTLE_WITH_FAIRY, ITEM_FAIRY, "You got a %rFairy in a Bottle%w!&Use it wisely!", - "You got a %rFairy in a Bottle%w!&Use it wisely!", - "You got a %rFairy in a Bottle%w!&Use it wisely!"), - GIMESSAGE(GI_BOTTLE_WITH_RED_POTION, ITEM_POTION_RED, - "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", - "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!", + GIMESSAGE_UNTRANSLATED(GI_BOTTLE_WITH_FAIRY, ITEM_FAIRY, "You got a %rFairy in a Bottle%w!&Use it wisely!"), + GIMESSAGE_UNTRANSLATED(GI_BOTTLE_WITH_RED_POTION, ITEM_POTION_RED, "You got a %rBottle of Red Potion%w!&Drink it to replenish your&%ghealth%w!"), - GIMESSAGE(GI_BOTTLE_WITH_GREEN_POTION, ITEM_POTION_GREEN, - "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", - "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!", + GIMESSAGE_UNTRANSLATED(GI_BOTTLE_WITH_GREEN_POTION, ITEM_POTION_GREEN, "You got a %rBottle of Green Potion%w!&Drink it to replenish your&%bmagic%w!"), - GIMESSAGE(GI_BOTTLE_WITH_POE, ITEM_POE, - "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", - "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this...", + GIMESSAGE_UNTRANSLATED(GI_BOTTLE_WITH_POE, ITEM_POE, "You got a %rPoe in a Bottle%w!&That creepy Ghost Shop might&be interested in this..."), }; CreateGetItemMessages(getItemMessages); diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index aa28b5e98..088e589fa 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1411,7 +1411,7 @@ extern "C" RandomizerCheck Randomizer_GetCheckFromActor(s16 sceneNum, s16 actorI return OTRGlobals::Instance->gRandomizer->GetCheckFromActor(sceneNum, actorId, actorParams); } -extern "C" CustomMessageEntry Randomizer_CopyScrubMessage(u16 scrubTextId) { +extern "C" CustomMessageEntry Randomizer_GetScrubMessage(u16 scrubTextId) { int price = 0; switch (scrubTextId) { case TEXT_SCRUB_POH: @@ -1425,21 +1425,21 @@ extern "C" CustomMessageEntry Randomizer_CopyScrubMessage(u16 scrubTextId) { return CustomMessageManager::Instance->RetrieveMessage(Randomizer::scrubMessageTableID, price); } -extern "C" CustomMessageEntry Randomizer_CopyAltarMessage() { +extern "C" CustomMessageEntry Randomizer_GetAltarMessage() { return (LINK_IS_ADULT) ? CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, TEXT_ALTAR_ADULT) : CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, TEXT_ALTAR_CHILD); } -extern "C" CustomMessageEntry Randomizer_CopyGanonText() { - return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, TEXT_GANONDORF + 1); +extern "C" CustomMessageEntry Randomizer_GetGanonText() { + return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, TEXT_GANONDORF_NOHINT); } -extern "C" CustomMessageEntry Randomizer_CopyGanonHintText() { +extern "C" CustomMessageEntry Randomizer_GetGanonHintText() { return CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, TEXT_GANONDORF); } -extern "C" CustomMessageEntry Randomizer_CopyHintFromCheck(RandomizerCheck check) { +extern "C" CustomMessageEntry Randomizer_GetHintFromCheck(RandomizerCheck check) { // we don't want to make a copy of the std::string returned from GetHintFromCheck // so we're just going to let RVO take care of it const CustomMessageEntry hintText = CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, check); @@ -1467,10 +1467,10 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { const int maxBufferSize = sizeof(font->msgBuf); CustomMessageEntry messageEntry; if (gSaveContext.n64ddFlag) { - if (textId == TEXT_RANDOMIZER_GI_ESCAPE_HATCH) { + if (textId == TEXT_RANDOMIZER_CUSTOM_ITEM) { messageEntry = Randomizer_GetCustomGetItemMessage((GetItemID)GET_PLAYER(globalCtx)->getItemId, buffer, maxBufferSize); - } else if (textId == 0x2053 && Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) != 0 && + } else if (textId == TEXT_RANDOMIZER_GOSSIP_STONE_HINTS && Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) != 0 && (Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) == 1 || (Randomizer_GetSettingValue(RSK_GOSSIP_STONE_HINTS) == 2 && Player_GetMask(globalCtx) == PLAYER_MASK_TRUTH) || @@ -1497,18 +1497,18 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { RandomizerCheck hintCheck = Randomizer_GetCheckFromActor(globalCtx->sceneNum, msgCtx->talkActor->id, actorParams); - messageEntry = Randomizer_CopyHintFromCheck(hintCheck); + messageEntry = Randomizer_GetHintFromCheck(hintCheck); } else if (textId == TEXT_ALTAR_CHILD || textId == TEXT_ALTAR_ADULT) { // rando hints at altar - messageEntry = Randomizer_CopyAltarMessage(); + messageEntry = Randomizer_GetAltarMessage(); } else if (textId == TEXT_GANONDORF) { if (INV_CONTENT(ITEM_ARROW_LIGHT) == ITEM_ARROW_LIGHT) { - messageEntry = Randomizer_CopyGanonText(); + messageEntry = Randomizer_GetGanonText(); } else { - messageEntry = Randomizer_CopyGanonHintText(); + messageEntry = Randomizer_GetGanonHintText(); } } else if (textId == TEXT_SCRUB_POH || textId == TEXT_SCRUB_STICK_UPGRADE || textId == TEXT_SCRUB_NUT_UPGRADE) { - messageEntry = Randomizer_CopyScrubMessage(textId); + messageEntry = Randomizer_GetScrubMessage(textId); } } if (textId == TEXT_GS_NO_FREEZE || textId == TEXT_GS_FREEZE) { diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index e1e3813f5..707851ce3 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -653,15 +653,15 @@ static GetItemEntry sGetItemTable[] = { GET_ITEM(ITEM_DOUBLE_MAGIC, OBJECT_GI_MAGICPOT, GID_MAGIC_LARGE, 0xE8, 0x80, CHEST_ANIM_LONG), GET_ITEM(ITEM_DOUBLE_DEFENSE, OBJECT_GI_HEARTS, GID_HEART_CONTAINER, 0xE9, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_RED_POTION, OBJECT_GI_LIQUID, GID_POTION_RED, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_GREEN_POTION, OBJECT_GI_LIQUID, GID_POTION_GREEN, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BLUE_POTION, OBJECT_GI_LIQUID, GID_POTION_BLUE, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_FAIRY, OBJECT_GI_BOTTLE, GID_BOTTLE, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_FISH, OBJECT_GI_FISH, GID_FISH, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BLUE_FIRE, OBJECT_GI_FIRE, GID_BLUE_FIRE, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BUGS, OBJECT_GI_INSECT, GID_BUG, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_POE, OBJECT_GI_GHOST, GID_POE, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), - GET_ITEM(ITEM_BOTTLE_WITH_BIG_POE, OBJECT_GI_GHOST, GID_BIG_POE, TEXT_RANDOMIZER_GI_ESCAPE_HATCH, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_RED_POTION, OBJECT_GI_LIQUID, GID_POTION_RED, TEXT_RANDOMIZER_CUSTOM_ITEM, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_GREEN_POTION, OBJECT_GI_LIQUID, GID_POTION_GREEN, TEXT_RANDOMIZER_CUSTOM_ITEM, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BLUE_POTION, OBJECT_GI_LIQUID, GID_POTION_BLUE, TEXT_RANDOMIZER_CUSTOM_ITEM, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_FAIRY, OBJECT_GI_BOTTLE, GID_BOTTLE, TEXT_RANDOMIZER_CUSTOM_ITEM, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_FISH, OBJECT_GI_FISH, GID_FISH, TEXT_RANDOMIZER_CUSTOM_ITEM, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BLUE_FIRE, OBJECT_GI_FIRE, GID_BLUE_FIRE, TEXT_RANDOMIZER_CUSTOM_ITEM, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BUGS, OBJECT_GI_INSECT, GID_BUG, TEXT_RANDOMIZER_CUSTOM_ITEM, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_POE, OBJECT_GI_GHOST, GID_POE, TEXT_RANDOMIZER_CUSTOM_ITEM, 0x80, CHEST_ANIM_LONG), + GET_ITEM(ITEM_BOTTLE_WITH_BIG_POE, OBJECT_GI_GHOST, GID_BIG_POE, TEXT_RANDOMIZER_CUSTOM_ITEM, 0x80, CHEST_ANIM_LONG), GET_ITEM_NONE, GET_ITEM_NONE, From 480053dfaab3b374d5d66275fe7d81ba1b9b037e Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Mon, 1 Aug 2022 23:05:29 -0400 Subject: [PATCH 36/39] Exposes FormatCustomMessage and uses it in FormatJsonHintText. --- .../custom_message/CustomMessageManager.h | 4 ++-- .../Enhancements/randomizer/randomizer.cpp | 19 +------------------ 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/soh/soh/Enhancements/custom_message/CustomMessageManager.h b/soh/soh/Enhancements/custom_message/CustomMessageManager.h index 6156f2ef8..35a1d5eb4 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageManager.h +++ b/soh/soh/Enhancements/custom_message/CustomMessageManager.h @@ -69,8 +69,6 @@ class CustomMessageManager { void ReplaceSpecialCharacters(std::string &string); void ReplaceColors(std::string& string); - void FormatCustomMessage(std::string& message, ItemID iid); - void FormatCustomMessage(std::string& message); bool InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages); std::string MESSAGE_END(); @@ -91,4 +89,6 @@ class CustomMessageManager { CustomMessageEntry RetrieveMessage(std::string tableID, uint16_t textID); bool ClearMessageTable(std::string tableID); bool AddCustomMessageTable(std::string tableID); + void FormatCustomMessage(std::string& message, ItemID iid); + void FormatCustomMessage(std::string& message); }; diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index c0077a97e..1163da8b3 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -1826,24 +1826,7 @@ 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(); - } - } + CustomMessageManager::Instance->FormatCustomMessage(formattedHintMessage); // add icons to altar text for (char iconChar : {'0', '1', '2', '3', '4', '5', '6', '7', '8', 'o', 'c', 'i', 'l', 'b', 'L', 'k'}) { From bb8152b3763f1d92319a31c184af865bcb343517 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Mon, 1 Aug 2022 23:16:16 -0400 Subject: [PATCH 37/39] Replaces string literal for BaseGameOverrides with const variable. --- soh/soh/OTRGlobals.cpp | 2 +- soh/soh/OTRGlobals.h | 2 ++ soh/soh/z_message_OTR.cpp | 2 -- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 088e589fa..5662d4895 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1518,7 +1518,7 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { } else { textId = TEXT_GS_FREEZE; } - messageEntry = CustomMessageManager::Instance->RetrieveMessage("BaseGameOverrides", textId); + messageEntry = CustomMessageManager::Instance->RetrieveMessage(customMessageTableID, textId); } } if (messageEntry.textBoxType != -1) { diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 76212c676..4f3b2a7b6 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -10,6 +10,8 @@ #include "Enhancements/savestates.h" #include "Enhancements/randomizer/randomizer.h" +const std::string customMessageTableID = "BaseGameOverrides"; + class OTRGlobals { public: diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index cdc1c79e8..4fd74e497 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -15,8 +15,6 @@ extern "C" MessageTableEntry* sFraMessageEntryTablePtr; extern "C" MessageTableEntry* sStaffMessageEntryTablePtr; //extern "C" MessageTableEntry* _message_0xFFFC_nes; -const std::string customMessageTableID = "BaseGameOverrides"; - MessageTableEntry* OTRMessage_LoadTable(const char* filePath, bool isNES) { auto file = std::static_pointer_cast(OTRGlobals::Instance->context->GetResourceManager()->LoadResource(filePath)); From d80742d882c0f439ccc353056f7b4b462129b958 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Tue, 2 Aug 2022 19:32:59 -0400 Subject: [PATCH 38/39] Adds documentation comments to CustomMessageManager.h --- .../custom_message/CustomMessageManager.h | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/soh/soh/Enhancements/custom_message/CustomMessageManager.h b/soh/soh/Enhancements/custom_message/CustomMessageManager.h index 35a1d5eb4..c5590dc00 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageManager.h +++ b/soh/soh/Enhancements/custom_message/CustomMessageManager.h @@ -84,11 +84,50 @@ class CustomMessageManager { CustomMessageManager(); ~CustomMessageManager(); + /* + Formats the provided Custom Message Entry and inserts it into the table with the provided tableID, + with the provided giid (getItemID) as its key. This function also inserts the icon corresponding to + the provided iid (itemID) at the beginning of each page of the textbox. + */ bool CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages); + + /* + Formats the provided Custom Message Entry and inserts it into the table with the provided tableID, + with the provided textID as its key. + */ bool CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages); + + /* + Retrieves a message from the table with id tableID with the provided textID. + Returns a NULL_CUSTOM_MESSAGE if the message or table does not exist. + */ CustomMessageEntry RetrieveMessage(std::string tableID, uint16_t textID); + + /* + Empties out the message table identified by tableID. + Returns true if successful and false if not (for instance + if a table with the provided tableID does not exist). + */ bool ClearMessageTable(std::string tableID); + + /* + Creates an empty CustomMessageTable accessible at the provided + tableID, returns true if creation was successful and false + if not. + */ bool AddCustomMessageTable(std::string tableID); + + /* + Replaces special characters and certain symbols with control codes + & for newline, ^ for wait-for-input, and @ for the player name, + as well as % for colors (i.e. %r for red and %w for white). + */ void FormatCustomMessage(std::string& message, ItemID iid); + + /* + Replaces special characters and certain symbols with control codes + & for newline, ^ for wait-for-input, and @ for the player name, + as well as % for colors (i.e. %r for red and %w for white). + */ void FormatCustomMessage(std::string& message); }; From e63d84bd7dc57b8d420ae6e548cdc832b746b126 Mon Sep 17 00:00:00 2001 From: Christopher Leggett Date: Mon, 8 Aug 2022 21:14:29 -0400 Subject: [PATCH 39/39] Adapts this branch for cmake building. --- soh/CMakeLists.txt | 15 +++++++++++++++ .../CustomMessageManager.cpp | 0 .../CustomMessageManager.h | 2 +- .../CustomMessageTypes.h | 0 soh/soh/Enhancements/randomizer/randomizer.cpp | 4 ++-- soh/soh/OTRGlobals.cpp | 4 ++-- soh/soh/z_message_OTR.cpp | 4 ++-- .../overlays/actors/ovl_player_actor/z_player.c | 2 +- 8 files changed, 23 insertions(+), 8 deletions(-) rename soh/soh/Enhancements/{custom_message => custom-message}/CustomMessageManager.cpp (100%) rename soh/soh/Enhancements/{custom_message => custom-message}/CustomMessageManager.h (99%) rename soh/soh/Enhancements/{custom_message => custom-message}/CustomMessageTypes.h (100%) diff --git a/soh/CMakeLists.txt b/soh/CMakeLists.txt index 67d5db850..5342374f0 100644 --- a/soh/CMakeLists.txt +++ b/soh/CMakeLists.txt @@ -215,6 +215,13 @@ set(Header_Files__soh__Enhancements__randomizer__3drando ) source_group("Header Files\\soh\\Enhancements\\randomizer\\3drando" FILES ${Header_Files__soh__Enhancements__randomizer__3drando}) +set(Header_Files__soh__Enhancements__custom_message + "soh/Enhancements/custom-message/CustomMessageTypes.h" + "soh/Enhancements/custom-message/CustomMessageManager.h" +) + +source_group("Header Files\\soh\\Enhancements\\custom-message" FILES ${Header_Files__soh__Enhancements__custom_message}) + set(Source_Files__soh "soh/GbiWrap.cpp" "soh/OTRAudio.h" @@ -326,6 +333,12 @@ set(Source_Files__soh__Enhancements__randomizer__3drando__location_access ) source_group("Source Files\\soh\\Enhancements\\randomizer\\3drando\\location_access" FILES ${Source_Files__soh__Enhancements__randomizer__3drando__location_access}) +set(Source_Files__soh__Enhancements__custom_message + "soh/Enhancements/custom-message/CustomMessageManager.cpp" +) + +source_group("Source Files\\soh\\Enhancements\\custom-message" FILES ${Source_Files__soh__Enhancements__custom_message}) + set(Source_Files__src__boot "src/boot/assert.c" "src/boot/boot_main.c" @@ -1534,6 +1547,7 @@ set(ALL_FILES ${Header_Files__soh__Enhancements__debugger} ${Header_Files__soh__Enhancements__randomizer} ${Header_Files__soh__Enhancements__randomizer__3drando} + ${Header_Files__soh__Enhancements__custom_message} ${Source_Files__soh} ${Source_Files__soh__Enhancements} ${Source_Files__soh__Enhancements__cosmetics} @@ -1542,6 +1556,7 @@ set(ALL_FILES ${Source_Files__soh__Enhancements__randomizer__3drando} ${Source_Files__soh__Enhancements__randomizer__3drando__hint_list} ${Source_Files__soh__Enhancements__randomizer__3drando__location_access} + ${Source_Files__soh__Enhancements__custom_message} ${Source_Files__src__boot} ${Source_Files__src__buffers} ${Source_Files__src__code} diff --git a/soh/soh/Enhancements/custom_message/CustomMessageManager.cpp b/soh/soh/Enhancements/custom-message/CustomMessageManager.cpp similarity index 100% rename from soh/soh/Enhancements/custom_message/CustomMessageManager.cpp rename to soh/soh/Enhancements/custom-message/CustomMessageManager.cpp diff --git a/soh/soh/Enhancements/custom_message/CustomMessageManager.h b/soh/soh/Enhancements/custom-message/CustomMessageManager.h similarity index 99% rename from soh/soh/Enhancements/custom_message/CustomMessageManager.h rename to soh/soh/Enhancements/custom-message/CustomMessageManager.h index c5590dc00..0681073b8 100644 --- a/soh/soh/Enhancements/custom_message/CustomMessageManager.h +++ b/soh/soh/Enhancements/custom-message/CustomMessageManager.h @@ -1,7 +1,7 @@ #pragma once #include #include -#include "z64item.h" +#include "../../../include/z64item.h" #undef MESSAGE_END diff --git a/soh/soh/Enhancements/custom_message/CustomMessageTypes.h b/soh/soh/Enhancements/custom-message/CustomMessageTypes.h similarity index 100% rename from soh/soh/Enhancements/custom_message/CustomMessageTypes.h rename to soh/soh/Enhancements/custom-message/CustomMessageTypes.h diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 18e73c230..eaf9f3098 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -13,8 +13,8 @@ #include "3drando/rando_main.hpp" #include #include "Lib/ImGui/imgui_internal.h" -#include -#include +#include +#include using json = nlohmann::json; using namespace std::literals::string_literals; diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 6470a49b3..ba61805f0 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -39,7 +39,7 @@ #include "macros.h" #include #include "Hooks.h" -#include +#include #ifdef __APPLE__ #include @@ -52,7 +52,7 @@ #endif #include -#include +#include #include OTRGlobals* OTRGlobals::Instance; diff --git a/soh/soh/z_message_OTR.cpp b/soh/soh/z_message_OTR.cpp index 4fd74e497..c6be43964 100644 --- a/soh/soh/z_message_OTR.cpp +++ b/soh/soh/z_message_OTR.cpp @@ -6,8 +6,8 @@ #include "vt.h" #include #include -#include -#include +#include +#include extern "C" MessageTableEntry* sNesMessageEntryTablePtr; extern "C" MessageTableEntry* sGerMessageEntryTablePtr; diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index 17b738949..139c8a6e0 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -20,7 +20,7 @@ #include "objects/gameplay_keep/gameplay_keep.h" #include "objects/object_link_child/object_link_child.h" #include "textures/icon_item_24_static/icon_item_24_static.h" -#include "../../../../soh/Enhancements/custom_message/CustomMessageTypes.h" +#include typedef struct { /* 0x00 */ u8 itemId;