From e93a720d8f65e7e219fde0b9b59c3c5d718d0a67 Mon Sep 17 00:00:00 2001 From: gymnast86 Date: Sun, 2 Aug 2026 01:37:12 -0700 Subject: [PATCH] update src files with hint stuff --- mods/randomizer/src/messages.cpp | 3 +- mods/randomizer/src/randomizer_context.cpp | 113 +++++++++++++++++++-- mods/randomizer/src/randomizer_context.hpp | 8 +- 3 files changed, 107 insertions(+), 17 deletions(-) diff --git a/mods/randomizer/src/messages.cpp b/mods/randomizer/src/messages.cpp index ce994468d6..6e07013e19 100644 --- a/mods/randomizer/src/messages.cpp +++ b/mods/randomizer/src/messages.cpp @@ -2,6 +2,7 @@ #include "JSystem/JMessage/control.h" #include "d/d_msg_class.h" +#include "d/d_save.h" #include "d/d_com_inf_game.h" #include "randomizer_context.hpp" #include "custom_flow_ids.hpp" @@ -61,7 +62,7 @@ char* GetFormatedTextOverride(u32 key, std::string& text) { } u8 getLanguageForOverride() { - u8 language = randomizer::Text::ENGLISH; + u8 language = dSv_player_config_c::LANGUAGE_ENGLISH; // TODO: add service or something to check game language /*if (dusk::version::isRegionPal()) { diff --git a/mods/randomizer/src/randomizer_context.cpp b/mods/randomizer/src/randomizer_context.cpp index 2267e686bd..fe4442303f 100644 --- a/mods/randomizer/src/randomizer_context.cpp +++ b/mods/randomizer/src/randomizer_context.cpp @@ -1095,6 +1095,21 @@ void parseObjPatchData(stage_tgsc_data_class& object, const YAML::Node& patchNod } } +static std::array CreateAttributeData(const YAML::Node& node, const std::string& name) { + auto attributesStr = node.as(); + auto attributesVec = HexToBytes(attributesStr); + if (attributesVec.size() != 16) { + throw std::runtime_error(fmt::format("Attributes for Text Override {} " + "are the wrong length. (Expected: 16, Actual: {}", name, attributesVec.size())); + } + + std::array attributes{}; + for (size_t i = 0; i < attributesVec.size(); ++i) { + attributes[i + 4] = attributesVec[i]; + } + return attributes; +} + RandomizerContext WriteSeedData(randomizer::logic::world::World* world) { RandomizerContext randoData{}; @@ -1504,6 +1519,92 @@ RandomizerContext WriteSeedData(randomizer::logic::world::World* world) { message->type = 1; message->msg_index = handleCustomMessageID(flowNode["inf index"]); message->next_node_idx = handleCustomFlowID(flowNode["next flow index"]); + + // If a custom message is too long, split it up among additional flow/message nodes + if (message->msg_index >= BASE_CUSTOM_MSG_AND_FLOW_ID) { + auto textName = flowNode["inf index"].as(); + if (world->GetTextDatabase().contains(textName)) { + auto& text = world->GetTextObject(textName); + if (text.IsTooLong()) { + // Get the attributes for the text at this ID. Pretty inefficient since we + // have to loop through every element unfortunately + std::optional> customAttributes{}; + auto textOverrides = LOAD_EMBED_YAML(RANDO_DATA_PATH "text/text_overrides.yaml"); + for (const auto& overrideNode : textOverrides) { + const auto& overrideName = overrideNode["Name"].as(); + if (overrideName == textName && overrideNode["Attributes"]) { + customAttributes = CreateAttributeData(overrideNode["Attributes"], textName); + break; + } + } + + + // Add each split text as a new custom message entry. The original entry + // still exists but has been sliced down to fit properly. + auto extraText = text.SplitToFitTextLimits(); + std::vector newMsgFlows{}; + for (size_t i = 0; i < extraText.size(); i++) { + // Add this custom text to the world + auto extraTextName = textName + std::to_string(i + 1); + world->AddNewText(extraTextName) = extraText[i]; + + // Kinda silly, but means we don't need to create another function + // to handle direct string names. + YAML::Node node{}; + node["name"] = extraTextName; + // Create new Flow and Message Ids for the split text object + auto newCustomFlowIndex = handleCustomFlowID(node["name"]); + auto newCustomMessageIndex = handleCustomMessageID(node["name"]); + + // Create the new flow node. We're storing its own flow index with + // itself for now, but we'll shift it back to the previous node later + mesg_flow_node newMsgFlow{}; + newMsgFlow.type = 1; + newMsgFlow.msg_index = newCustomMessageIndex; + newMsgFlow.next_node_idx = newCustomFlowIndex; + + newMsgFlows.push_back(newMsgFlow); + + //Add the custom text to the rando data + u32 key = (CUSTOM_BMG_GROUP << 16) | newCustomMessageIndex; + for (auto language : randomizer::supportedLanguages) { + std::string newText = extraText[i].mText[language]; + randomizer::applyMessageCodes(newText); + randoData.mTextOverrides[language][key] = newText; + } + + // Add custom attribute data as well if it exists + if (customAttributes.has_value()) { + auto attributes = customAttributes.value(); + + // Set the message id in the attribute data + attributes[4] = newCustomMessageIndex >> 8; + attributes[5] = newCustomMessageIndex & 0xFF; + + randoData.mAttributeOverrides[key] = attributes; + } + } + + // Shift all the next_node_idx fields back a node and set the original + // next node idx as the next node idx for the final of the new flows + auto finalNodeIdx = message->next_node_idx; + message->next_node_idx = newMsgFlows[0].next_node_idx; + for (size_t i = 0; i < newMsgFlows.size(); i++) { + auto& curFlow = newMsgFlows[i]; + auto curFlowIdx = curFlow.next_node_idx; + if (i == newMsgFlows.size() - 1) { + curFlow.next_node_idx = finalNodeIdx; + } else { + curFlow.next_node_idx = newMsgFlows[i + 1].next_node_idx; + } + + // Also Add the new custom flows to our rando data + u32 key = (CUSTOM_BMG_GROUP << 16) | curFlowIdx; + randoData.mFlowPatches[key] = std::bit_cast(curFlow); + } + } + } + } } for (auto index : indices) { u32 key = (groupNo << 16) | index; @@ -1545,17 +1646,7 @@ RandomizerContext WriteSeedData(randomizer::logic::world::World* world) { // If we have custom attributes if (overrideNode["Attributes"]) { - auto attributesStr = overrideNode["Attributes"].as(); - auto attributesVec = HexToBytes(attributesStr); - if (attributesVec.size() != 16) { - throw std::runtime_error(fmt::format("Attributes for Text Override {} " - "are the wrong length. (Expected: 16, Actual: {}", name, attributesVec.size())); - } - - std::array attributes{}; - for (size_t i = 0; i < attributesVec.size(); ++i) { - attributes[i + 4] = attributesVec[i]; - } + auto attributes = CreateAttributeData(overrideNode["Attributes"], name); // Set the message id in the attribute data attributes[4] = messageId >> 8; diff --git a/mods/randomizer/src/randomizer_context.hpp b/mods/randomizer/src/randomizer_context.hpp index fd16f7e60a..46850260b0 100644 --- a/mods/randomizer/src/randomizer_context.hpp +++ b/mods/randomizer/src/randomizer_context.hpp @@ -4,15 +4,13 @@ #include #include -#include +#include #include +#include #include -#include #include +#include #include -#include - -#include "../generator/randomizer.hpp" /* * Class holding all the information necessary for playing