From 7639c0f2ede3c2b17f16ba24b004fef3d21e89e8 Mon Sep 17 00:00:00 2001 From: aMannus Date: Fri, 19 Aug 2022 14:41:20 +0200 Subject: [PATCH] Moved code to randomizer.cpp, fixes special chars --- soh/include/message_data_static.h | 22 +------ soh/include/message_data_textbox_types.h | 25 ++++++++ .../custom-message/CustomMessageManager.h | 26 +------- .../Enhancements/randomizer/randomizer.cpp | 64 ++++++++++++++++--- soh/soh/Enhancements/randomizer/randomizer.h | 3 + soh/soh/OTRGlobals.cpp | 52 +-------------- 6 files changed, 89 insertions(+), 103 deletions(-) create mode 100644 soh/include/message_data_textbox_types.h diff --git a/soh/include/message_data_static.h b/soh/include/message_data_static.h index c286771aa..0821f1093 100644 --- a/soh/include/message_data_static.h +++ b/soh/include/message_data_static.h @@ -3,32 +3,12 @@ #include "global.h" #include "message_data_fmt.h" +#include "message_data_textbox_types.h" #ifdef __cplusplus extern "C" { #endif -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; - typedef struct { u16 textId; u8 typePos; diff --git a/soh/include/message_data_textbox_types.h b/soh/include/message_data_textbox_types.h new file mode 100644 index 000000000..2567617e9 --- /dev/null +++ b/soh/include/message_data_textbox_types.h @@ -0,0 +1,25 @@ +#ifndef MESSAGE_DATA_TEXTBOX_TYPES_H +#define MESSAGE_DATA_TEXTBOX_TYPES_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 \ 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 0681073b8..2764e97c8 100644 --- a/soh/soh/Enhancements/custom-message/CustomMessageManager.h +++ b/soh/soh/Enhancements/custom-message/CustomMessageManager.h @@ -2,6 +2,7 @@ #include #include #include "../../../include/z64item.h" +#include "../../../include/message_data_textbox_types.h" #undef MESSAGE_END @@ -14,31 +15,6 @@ #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/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 3cae6f9b8..47caa943a 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -14,7 +14,6 @@ #include "3drando/rando_main.hpp" #include #include "Lib/ImGui/imgui_internal.h" -#include #include using json = nlohmann::json; @@ -4629,27 +4628,76 @@ void CreateRupeeMessages() { for (u8 rupee : rupees) { switch (rupee) { case TEXT_BLUE_RUPEE: - rupeeText = "\x05\x03 5 %RUPEE% \x05\x00"; + rupeeText = "\x05\x03 5 %RUPEE%\x05\x00"; break; case TEXT_RED_RUPEE: - rupeeText = "\x05\x01 20 %RUPEE% \x05\x00"; + rupeeText = "\x05\x01 20 %RUPEE%\x05\x00"; break; case TEXT_PURPLE_RUPEE: - rupeeText = "\x05\x05 50 %RUPEE% \x05\x00"; + rupeeText = "\x05\x05 50 %RUPEE%\x05\x00"; break; case TEXT_HUGE_RUPEE: - rupeeText = "\x05\x06 200 %RUPEE% \x05\x00"; + rupeeText = "\x05\x06 200 %RUPEE%\x05\x00"; break; } customMessageManager->CreateMessage(Randomizer::rupeeMessageTableID, rupee, { TEXTBOX_TYPE_BLACK, TEXTBOX_POS_BOTTOM, - "You found" + rupeeText + "!", - "Du hast" + rupeeText + " gefunden!", - "Vous obtenez" + rupeeText + "!" + "You found" + rupeeText + " !", + "Du hast" + rupeeText + " gefunden!", + "Vous obtenez" + rupeeText + " !" }); } } +std::string Randomizer::Randomizer_InsertRupeeName(std::string message, int language) { + const char* englishRupeeNames[40] = { + "Rupees", "Bitcoin", "Bananas", "Cornflakes", "Gummybears", "Floopies", "Dollars", "Lemmings", + "Emeralds", "Bucks", "Rubles", "Diamonds", "Moons", "Stars", "Mana", "Doll Hairs", + "Dogecoin", "Mushrooms", "Experience", "Friends", "Coins", "Rings", "Gil", "Pokédollars", + "Bells", "Orbs", "Bottle Caps", "Simoleons", "Pokémon", "Toys", "Smackaroos", "Zorkmids", + "Zenny", "Bones", "Souls", "Studs", "Munny", "Rubies", "Gald", "Gold" + }; + const char* germanRupeeNames[1] = { "Rubine" }; + const char* frenchRupeeNames[36] = { + "Rubis", "Bitcoin", "Bananes", "Euros", "Dollars", "Émeraudes", "Joyaux", "Diamants", + "Balles", "Pokémon", "Pièces", "Lunes", "Étoiles", "Dogecoin", "Anneaux", "Radis", + "Pokédollars", "Zennies", "Pépètes", "Mailles", "Éthers", "Clochettes", "Capsules", "Gils", + "Champignons", "Blés", "Halos", "Munnies", "Orens", "Florens", "Crédits", "Galds", + "Bling", "Orbes", "Baguettes", "Croissants" + }; + int randomIndex; + std::string replaceWith; + switch (language) { + case LANGUAGE_ENG: + randomIndex = rand() % (sizeof(englishRupeeNames) / sizeof(englishRupeeNames[0])); + replaceWith = englishRupeeNames[randomIndex]; + break; + case LANGUAGE_GER: + randomIndex = rand() % (sizeof(germanRupeeNames) / sizeof(germanRupeeNames[0])); + replaceWith = germanRupeeNames[randomIndex]; + break; + case LANGUAGE_FRA: + randomIndex = rand() % (sizeof(frenchRupeeNames) / sizeof(frenchRupeeNames[0])); + replaceWith = frenchRupeeNames[randomIndex]; + break; + } + std::string replaceString = "%RUPEE%"; + size_t pos = message.find(replaceString); + size_t len = replaceString.length(); + message.replace(pos, len, replaceWith); + CustomMessageManager::Instance->FormatCustomMessage(message); + return message; +} + +CustomMessageEntry Randomizer::Randomizer_GetRupeeMessage(u16 rupeeTextId) { + CustomMessageEntry messageEntry = + CustomMessageManager::Instance->RetrieveMessage(Randomizer::rupeeMessageTableID, rupeeTextId); + messageEntry.english = Randomizer::Randomizer_InsertRupeeName(messageEntry.english, LANGUAGE_ENG); + messageEntry.german = Randomizer::Randomizer_InsertRupeeName(messageEntry.german, LANGUAGE_GER); + messageEntry.french = Randomizer::Randomizer_InsertRupeeName(messageEntry.french, LANGUAGE_FRA); + return messageEntry; +} + void Randomizer::CreateCustomMessages() { // RANDTODO: Translate into french and german and replace GIMESSAGE_UNTRANSLATED // with GIMESSAGE(getItemID, itemID, english, german, french). diff --git a/soh/soh/Enhancements/randomizer/randomizer.h b/soh/soh/Enhancements/randomizer/randomizer.h index 88c4f0296..9ec983e14 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.h +++ b/soh/soh/Enhancements/randomizer/randomizer.h @@ -6,6 +6,7 @@ #include "../../../include/z64item.h" #include #include +#include class Randomizer { private: @@ -47,6 +48,8 @@ class Randomizer { GetItemID GetRandomizedItemIdFromKnownCheck(RandomizerCheck randomizerCheck, GetItemID ogId); GetItemID GetRandomizedItemId(GetItemID ogId, s16 actorId, s16 actorParams, s16 sceneNum); static void CreateCustomMessages(); + std::string Randomizer_InsertRupeeName(std::string message, int language); + CustomMessageEntry Randomizer_GetRupeeMessage(u16 rupeeTextId); }; #ifdef __cplusplus diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 1df80f38e..2a5180dce 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -33,6 +33,7 @@ #include "Enhancements/cosmetics/CosmeticsEditor.h" #include "Enhancements/debugconsole.h" #include "Enhancements/debugger/debugger.h" +#include #include #include "Enhancements/n64_weird_frame_data.inc" #include "soh/frame_interpolation.h" @@ -1447,54 +1448,6 @@ extern "C" CustomMessageEntry Randomizer_GetScrubMessage(u16 scrubTextId) { return CustomMessageManager::Instance->RetrieveMessage(Randomizer::scrubMessageTableID, price); } -extern "C" std::string Randomizer_InsertRupeeName(std::string message, int language) { - const char* englishRupeeNames[40] = { - "Rupees", "Bitcoin", "Bananas", "Cornflakes", "Gummybears", "Floopies", "Dollars", "Lemmings", "Emeralds", "Bucks", - "Rubles", "Diamonds", "Moons", "Stars", "Mana", "Doll Hairs", "Dogecoin", "Mushrooms", "Experience", "Friends", - "Coins", "Rings", "Gil", "Pokédollars", "Bells", "Orbs", "Bottle Caps", "Simoleons", "Pokémon", "Toys", - "Smackaroos", "Zorkmids", "Zenny", "Bones", "Souls", "Studs", "Munny", "Rubies", "Gald", "Gold" - }; - const char* germanRupeeNames[1] = { - "Rubine" - }; - const char* frenchRupeeNames[36] = { - "Rubis", "Bitcoin", "Bananes", "Euros", "Dollars", "Émeraudes", "Joyaux", - "Diamants", "Balles", "Pokémon", "Pièces", "Lunes", "Étoiles", "Dogecoin", "Anneaux", "Radis", "Pokédollars", - "Zennies", "Pépètes", "Mailles", "Éthers", "Clochettes", "Capsules", "Gils", "Champignons", "Blés", "Halos", - "Munnies", "Orens", "Florens", "Crédits", "Galds", "Bling", "Orbes", "Baguettes", "Croissants" - }; - int randomIndex; - std::string replaceWith; - switch (language) { - case LANGUAGE_ENG: - randomIndex = rand() % (sizeof(englishRupeeNames) / sizeof(englishRupeeNames[0])); - replaceWith = englishRupeeNames[randomIndex]; - break; - case LANGUAGE_GER: - randomIndex = rand() % (sizeof(germanRupeeNames) / sizeof(germanRupeeNames[0])); - replaceWith = germanRupeeNames[randomIndex]; - break; - case LANGUAGE_FRA: - randomIndex = rand() % (sizeof(frenchRupeeNames) / sizeof(frenchRupeeNames[0])); - replaceWith = frenchRupeeNames[randomIndex]; - break; - } - std::string replaceString = "%RUPEE%"; - size_t pos = message.find(replaceString); - size_t len = replaceString.length(); - message.replace(pos, len, replaceWith); - CustomMessageManager::Instance->FormatCustomMessage(message); - return message; -} - -extern "C" CustomMessageEntry Randomizer_GetRupeeMessage(u16 rupeeTextId) { - CustomMessageEntry messageEntry = CustomMessageManager::Instance->RetrieveMessage(Randomizer::rupeeMessageTableID, rupeeTextId); - messageEntry.english = Randomizer_InsertRupeeName(messageEntry.english, LANGUAGE_ENG); - messageEntry.german = Randomizer_InsertRupeeName(messageEntry.german, LANGUAGE_GER); - messageEntry.french = Randomizer_InsertRupeeName(messageEntry.french, LANGUAGE_FRA); - return messageEntry; -} - extern "C" CustomMessageEntry Randomizer_GetAltarMessage() { return (LINK_IS_ADULT) ? CustomMessageManager::Instance->RetrieveMessage(Randomizer::hintMessageTableID, TEXT_ALTAR_ADULT) @@ -1591,7 +1544,8 @@ extern "C" int CustomMessage_RetrieveIfExists(GlobalContext* globalCtx) { } else if (!CVar_GetS32("gRandoDisableRandomRupeeNames", 0) && (textId == TEXT_BLUE_RUPEE || textId == TEXT_RED_RUPEE || textId == TEXT_PURPLE_RUPEE || textId == TEXT_HUGE_RUPEE)) { - messageEntry = Randomizer_GetRupeeMessage(textId); + Randomizer randomizerInstance; + messageEntry = randomizerInstance.Randomizer_GetRupeeMessage(textId); } } if (textId == TEXT_GS_NO_FREEZE || textId == TEXT_GS_FREEZE) {