From 11a581061fa5de3e0fa63b6ca31d357708d45ca4 Mon Sep 17 00:00:00 2001 From: Philippe Symons Date: Tue, 22 Sep 2026 17:10:20 +0200 Subject: [PATCH] Fix first_time text entries in payload (untested) first_time entries would be longer, therefore the reference pointers inside the payload would shift. To avoid that, we now reserve space for the longest entry, knowing that the texts will get stripped after the payloads have been generated. Doing so ensures that the text offsets remain constant, no matter if we're dealing with the first_time or othertimes payload. This also means we need to take that reservation into account on the PTGB rom side of things of course. To do so, I created a pair array indicating the first time entries and there non-first_time counterparts. We'll determine which entry is the longest and ensure we use that length for the offset of the next entry. --- include/mystery_gift_injector.h | 2 +- source/mystery_gift_injector.cpp | 122 ++++++++++++------ source/script_array.cpp | 23 +++- .../include/mystery_gift_builder.h | 3 +- tools/gba-payload-generator/src/main.cpp | 2 +- .../src/mystery_gift_builder.cpp | 49 ++++--- 6 files changed, 142 insertions(+), 59 deletions(-) diff --git a/include/mystery_gift_injector.h b/include/mystery_gift_injector.h index b57c576..4d83c50 100644 --- a/include/mystery_gift_injector.h +++ b/include/mystery_gift_injector.h @@ -4,6 +4,6 @@ #include "PokeBox.h" #include "pokemon_data.h" -bool inject_mystery(PokeBox* box); +bool inject_mystery(PokeBox* box, bool isFirstTime); #endif \ No newline at end of file diff --git a/source/mystery_gift_injector.cpp b/source/mystery_gift_injector.cpp index a04fa6a..73ad41d 100644 --- a/source/mystery_gift_injector.cpp +++ b/source/mystery_gift_injector.cpp @@ -117,6 +117,12 @@ static constexpr PatchFileTableEntry patchFileTable[] = { PACK_PATCH_KEY(MAP_LEAFGREEN, MAP_SPANISH, VERS_1_0), (u8)Script_patchesFiles::SCRIPT_LEAFGREEN_SPANISH_1_0 } }; +static constexpr std::pair firstTimeTextEntryPairs[] = { + {RSEFRLG_dia_textIAm_first_rs, RSEFRLG_dia_textIAm_second_rs}, + {RSEFRLG_dia_textIAm_first_frlge, RSEFRLG_dia_textIAm_second_frlge}, + {RSEFRLG_dia_textYouMustBe_first, RSEFRLG_dia_textYouMustBe_second} +}; + // This will need to be modified for the JP releases static constexpr u8 em_wonder_card[0x14E] = { 0x08, 0x6E, 0x00, 0x00, 0xBA, 0xB4, 0xBE, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0xCA, 0xCC, 0xC9, 0xC0, 0xBF, 0xCD, 0xCD, 0xC9, 0xCC, 0x00, 0xC0, 0xBF, 0xC8, 0xC8, 0xBF, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0x00, 0xBD, 0xD9, 0xE6, 0xE8, 0xDD, 0xDA, 0xDD, 0xD7, 0xD5, 0xE8, 0xD9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xDD, 0xE7, 0xDD, 0xE8, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xDC, 0xE3, 0xE9, 0xE7, 0xD9, 0x00, 0xE7, 0xE3, 0xE9, 0xE8, 0xDC, 0xD9, 0xD5, 0xE7, 0xE8, 0x00, 0xE3, 0xDA, 0x00, 0xE8, 0xDC, 0xD9, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xBD, 0xBF, 0xC8, 0xCE, 0xBF, 0xCC, 0x00, 0xDD, 0xE2, 0x00, 0xCD, 0xE3, 0xE3, 0xE8, 0xE3, 0xE4, 0xE3, 0xE0, 0xDD, 0xE7, 0x00, 0xBD, 0xDD, 0xE8, 0xED, 0x00, 0xE8, 0xE3, 0x00, 0xE6, 0xD9, 0xD7, 0xDD, 0xD9, 0xEA, 0xD9, 0x00, 0x00, 0x00, 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBE, 0xE3, 0x00, 0xE2, 0xE3, 0xE8, 0x00, 0xE8, 0xE3, 0xE7, 0xE7, 0x00, 0xE8, 0xDC, 0xDD, 0xE7, 0x00, 0xBF, 0xEC, 0xD7, 0xDC, 0xD5, 0xE2, 0xDB, 0xD9, 0x00, 0xBD, 0xD5, 0xE6, 0xD8, 0x00, 0xD6, 0xD9, 0xDA, 0xE3, 0xE6, 0xD9, 0x00, 0x00, 0x00, 0xE6, 0xD9, 0xD7, 0xD9, 0xDD, 0xEA, 0xDD, 0xE2, 0xDB, 0x00, 0xED, 0xE3, 0xE9, 0xE6, 0x00, 0xE8, 0xE6, 0xD5, 0xE2, 0xE7, 0xDA, 0xD9, 0xE6, 0xD9, 0xD8, 0x00, 0xCA, 0xC9, 0xC5, 0x1B, 0xC7, 0xC9, 0xC8, 0xAB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; @@ -184,22 +190,18 @@ static Language convertLangCodeIntoLanguage(int32_t langCode) } /** - * @brief This function injects a text entry generated by text_helper into the provided buffer. - * NOTE: bufferPos should point to the exact location at which the text entry should be injected. - * NOTE: this code originated from text_var::insert_text() and has been adapted for use in this context. + * @brief This one loads the specified textEntry index into a newly malloc'ed outBuffer. + * It removes the colored text from the text entry if necessary and stores the actual buffer depth into outBufferDepth * - * @param charset a charset buffer to use hen injecting the text entry. It's used to detect colored text and remove it if necessary. - * @param bufferPos an offset into the buffer where the text entry should be injected. - * @param textReader a FileContainerReader instance used to read the text entry. - * @param entryIndex the index of the text entry to inject. - * @return u32 the number of bytes injected into the buffer. + * WARNING: the caller becomes owner of the outBuffer pointer. Make sure to free() it! */ -static u32 __attribute__((noinline)) injectTextEntryIntoBuffer(const u16 *charset, u8 *buffer, u32 bufferSize, u32 bufferPos, FileContainerReader &textReader, u32 entryIndex) +static void loadProcessedTextEntry(const u16 *charset, FileContainerReader &textReader, u16 entryIndex, u8 *&outBuffer, u32 &outBufferDepth) { const u8 *curText = textReader.getPointerToFileInDecompressionBuffer(entryIndex); - u8 *curBuffer = buffer + bufferPos; - u8 *tempBuffer = (u8*)malloc(textReader.getFileSize(entryIndex)); - u32 bufferDepth = 0; + u8 *curBuffer; + + outBuffer = (u8*)malloc(textReader.getFileSize(entryIndex)); + curBuffer = outBuffer; // Process the text entry and copy it into a temporary buffer, removing any colored text if necessary. while((*curText) != 0xFF) @@ -213,19 +215,76 @@ static u32 __attribute__((noinline)) injectTextEntryIntoBuffer(const u16 *charse } } - *(tempBuffer + bufferDepth) = *curText; - ++bufferDepth; + *(curBuffer) = *curText; + ++curBuffer; ++curText; } - *(tempBuffer + bufferDepth) = 0xFF; // End string - ++bufferDepth; + *(curBuffer) = 0xFF; // End string + ++curBuffer; + outBufferDepth = curBuffer - outBuffer; +} + +/** + * @brief This function injects a text entry generated by text_helper into the provided buffer. + * NOTE: bufferPos should point to the exact location at which the text entry should be injected. + * NOTE: this code originated from text_var::insert_text() and has been adapted for use in this context. + * + * @param charset a charset buffer to use hen injecting the text entry. It's used to detect colored text and remove it if necessary. + * @param bufferPos an offset into the buffer where the text entry should be injected. + * @param textReader a FileContainerReader instance used to read the text entry. + * @param entryIndex the index of the text entry to inject. + * @return u32 the number of bytes injected into the buffer. + */ +static u32 __attribute__((noinline)) injectTextEntryIntoBuffer(const u16 *charset, u8 *buffer, u32 bufferSize, u32 bufferPos, FileContainerReader &textReader, u16 entryIndex, bool isFirstTime) +{ + u8 *curBuffer = buffer + bufferPos; + u8 *tempBuffer; + u32 bufferDepth; + u16 selectedEntryIndex; + u16 otherEntryIndex; + u32 otherBufferDepth; + + // if this is a first_time related text, determine which entry to inject first. + selectedEntryIndex = entryIndex; + otherEntryIndex = UINT16_MAX; + for(u32 i = 0; i < sizeof(firstTimeTextEntryPairs) / sizeof(firstTimeTextEntryPairs[0]); ++i) + { + if(entryIndex == firstTimeTextEntryPairs[i].first) + { + if(isFirstTime) + { + otherEntryIndex = firstTimeTextEntryPairs[i].second; + } + else + { + selectedEntryIndex = firstTimeTextEntryPairs[i].second; + otherEntryIndex = entryIndex; + } + } + } + + loadProcessedTextEntry(charset, textReader, selectedEntryIndex, tempBuffer, bufferDepth); // Move the existing buffer content to make room for the new text entry memmove(curBuffer + bufferDepth, curBuffer, bufferSize - bufferPos - bufferDepth); // now copy the processed text into the buffer at the current position memcpy(curBuffer, tempBuffer, bufferDepth); free(tempBuffer); + // mystery_gift_builder in gba-payload-generator reserves space for the largest entry of the first_time/second_time pair. + // this is done to make sure the pointer references within the payload remain the same, no matter which one we inject. + // however, we need to take this into account, so we inject the next entry at the right offset as well, taking that reservation + // of space into account. + if(otherEntryIndex != UINT32_MAX) + { + loadProcessedTextEntry(charset, textReader, otherEntryIndex, tempBuffer, otherBufferDepth); + free(tempBuffer); + if(bufferDepth < otherBufferDepth) + { + bufferDepth = otherBufferDepth; + } + } + return bufferDepth; } @@ -236,7 +295,7 @@ static u32 __attribute__((noinline)) injectTextEntryIntoBuffer(const u16 *charse * * But in order to use the payload, we actually need to reinsert those at runtime. */ -static void __attribute__((noinline)) reinjectMysteryGiftPayloadTexts(u8 *section30Buffer, u8 *mgScriptBuffer) +static void __attribute__((noinline)) reinjectMysteryGiftPayloadTexts(u8 *section30Buffer, u8 *mgScriptBuffer, bool isFirstTime) { u8 decompressionBuffer[4096]; u16 gen3Charset[256]; @@ -245,21 +304,9 @@ static void __attribute__((noinline)) reinjectMysteryGiftPayloadTexts(u8 *sectio std::array section30TextSequence; std::array scriptTextSequence; u8 textGreetEntryIndex; - u8 youMustBeEntryIndex; u8 iAmEntryIndex; u32 section30Offset; u32 mgScriptOffset; - bool firstTime = true; - - // This determines if the event has been done before - for (unsigned i = 1; i <= 251; i++) - { - if (is_caught(i)) - { - firstTime = false; - break; - } - } FileContainerReader textReader(RSEFRLG_chunklist, sizeof(RSEFRLG_chunklist) / sizeof(RSEFRLG_chunklist[0]), sizeof(decompressionBuffer)); textReader.init(decompressionBuffer, sizeof(decompressionBuffer)); @@ -279,38 +326,37 @@ static void __attribute__((noinline)) reinjectMysteryGiftPayloadTexts(u8 *sectio case SAPPHIRE_ID: mgScriptOffset = 0x268; textGreetEntryIndex = RSEFRLG_dia_textGreet_rse; - iAmEntryIndex = (firstTime) ? RSEFRLG_dia_textIAm_first_rs : RSEFRLG_dia_textIAm_second_rs; + iAmEntryIndex = RSEFRLG_dia_textIAm_first_rs; section30TextSequence = { RSEFRLG_dia_textThank_rs, RSEFRLG_dia_textPCFull_rs, RSEFRLG_dia_textWeHere_rs, RSEFRLG_dia_textPCConvo_rs, RSEFRLG_dia_textPCThanks_rs, RSEFRLG_dia_textLookerFull_rs, RSEFRLG_dia_textMoveBox_rs, RSEFRLG_dia_textRecieved_rs }; break; case FIRERED_ID: case LEAFGREEN_ID: mgScriptOffset = 0x278; textGreetEntryIndex = RSEFRLG_dia_textGreet_frlg; - iAmEntryIndex = (firstTime) ? RSEFRLG_dia_textIAm_first_frlge : RSEFRLG_dia_textIAm_second_frlge; + iAmEntryIndex = RSEFRLG_dia_textIAm_first_frlge; section30TextSequence = { RSEFRLG_dia_textThank_frlge, RSEFRLG_dia_textPCFull_frlge, RSEFRLG_dia_textWeHere_frlg, RSEFRLG_dia_textPCConvo_frlge, RSEFRLG_dia_textPCThanks_frlge, RSEFRLG_dia_textLookerFull_frlge, RSEFRLG_dia_textMoveBox_frlg, RSEFRLG_dia_textRecieved_frlge }; break; default: mgScriptOffset = 0x298; textGreetEntryIndex = RSEFRLG_dia_textGreet_rse; - iAmEntryIndex = (firstTime) ? RSEFRLG_dia_textIAm_first_frlge : RSEFRLG_dia_textIAm_second_frlge; + iAmEntryIndex = RSEFRLG_dia_textIAm_first_frlge; section30TextSequence = { RSEFRLG_dia_textThank_frlge, RSEFRLG_dia_textPCFull_frlge, RSEFRLG_dia_textWeHere_e, RSEFRLG_dia_textPCConvo_frlge, RSEFRLG_dia_textPCThanks_frlge, RSEFRLG_dia_textLookerFull_frlge, RSEFRLG_dia_textMoveBox_e, RSEFRLG_dia_textRecieved_frlge }; break; } - youMustBeEntryIndex = (firstTime) ? RSEFRLG_dia_textYouMustBe_first : RSEFRLG_dia_textYouMustBe_second; - scriptTextSequence = {textGreetEntryIndex, youMustBeEntryIndex, iAmEntryIndex }; + scriptTextSequence = {textGreetEntryIndex, RSEFRLG_dia_textYouMustBe_first, iAmEntryIndex }; load_localized_charset(gen3Charset, 3, convertLangCodeIntoLanguage(curr_GBA_rom.language)); for(unsigned i=0; i < 8; ++i) { - bytesInjected = injectTextEntryIntoBuffer(gen3Charset, section30Buffer, 4096, section30Offset, textReader, section30TextSequence[i]); + bytesInjected = injectTextEntryIntoBuffer(gen3Charset, section30Buffer, 0x1000, section30Offset, textReader, section30TextSequence[i], isFirstTime); section30Offset += bytesInjected; } for(unsigned i=0; i < 3; ++i) { - bytesInjected = injectTextEntryIntoBuffer(gen3Charset, mgScriptBuffer, MG_SCRIPT_SIZE, mgScriptOffset, textReader, scriptTextSequence[i]); + bytesInjected = injectTextEntryIntoBuffer(gen3Charset, mgScriptBuffer, MG_SCRIPT_SIZE, mgScriptOffset, textReader, scriptTextSequence[i], isFirstTime); mgScriptOffset += bytesInjected; } } @@ -521,13 +567,13 @@ static void __attribute__((noinline)) reconstructPregeneratedPayloads(u8* sectio } -bool inject_mystery(PokeBox* box) +bool inject_mystery(PokeBox* box, bool isFirstTime) { u32 checksum; u8 script_buffer[MG_SCRIPT_SIZE]; reconstructPregeneratedPayloads(global_memory_buffer, script_buffer); - reinjectMysteryGiftPayloadTexts(global_memory_buffer, script_buffer); + reinjectMysteryGiftPayloadTexts(global_memory_buffer, script_buffer, isFirstTime); // One thing our pregeneration process obviously leaves out is the pokemon data. // so let's add that in now. diff --git a/source/script_array.cpp b/source/script_array.cpp index f4ae1ec..10daf05 100644 --- a/source/script_array.cpp +++ b/source/script_array.cpp @@ -487,6 +487,22 @@ const script_obj_params event_script_params[SCRIPT_SIZE] = { {}, // COND_CHECK_MISSINGNO }; +static bool isFirstTime() +{ + bool firstTime = true; + + // This determines if the event has been done before + for (unsigned i = 1; i <= 251; i++) + { + if (is_caught(i)) + { + firstTime = false; + break; + } + } + return firstTime; +} + static void __attribute__((noinline)) convertPokeBox() { PokemonTables tables; @@ -694,9 +710,14 @@ bool run_conditional(int index) return true; case CMD_IMPORT_POKEMON: + { + // we need to determine firstTime BEFORE calling convertPokeBox() + // because convertPokeBox will call set_caught() + const bool firstTime = isFirstTime(); convertPokeBox(); - inject_mystery(&box); + inject_mystery(&box, firstTime); return true; + } case CMD_BACK_TO_MENU: set_text_exit(); REG_BG1HOFS = 0; diff --git a/tools/gba-payload-generator/include/mystery_gift_builder.h b/tools/gba-payload-generator/include/mystery_gift_builder.h index f428746..29d2cd9 100644 --- a/tools/gba-payload-generator/include/mystery_gift_builder.h +++ b/tools/gba-payload-generator/include/mystery_gift_builder.h @@ -249,7 +249,6 @@ #define CPU_SET_16BIT 0x00000000 #define CPU_SET_32BIT 0x04000000 -class PokeBox; class UncompressedFileContainerReader; class mystery_gift_script @@ -294,7 +293,7 @@ public: * You're in control! */ mystery_gift_script(u8 *save_section_30_buffer, u8 *mg_script_buffer); - void build_script(UncompressedFileContainerReader &text_table_reader, const struct ROM_DATA& curr_GBA_rom, const uint16_t *gen3_charset, PokeBox *box, bool first_time); + void build_script(UncompressedFileContainerReader &text_table_reader, const struct ROM_DATA& curr_GBA_rom, const uint16_t *gen3_charset); /** * @brief This function removes the inserted textbox_var texts again from the payloads. diff --git a/tools/gba-payload-generator/src/main.cpp b/tools/gba-payload-generator/src/main.cpp index 37d10ec..d381814 100644 --- a/tools/gba-payload-generator/src/main.cpp +++ b/tools/gba-payload-generator/src/main.cpp @@ -168,7 +168,7 @@ static void generatePayloadsForLanguage(const char* outputPath, char languageCod generateOutputPath(outputPathBuffer, outputPath, "section30", gbaRomDataArray + i); printf("[gba-payload-generator]: Generating payload: %s\n", outputPathBuffer); - builder.build_script(rsefrlgTableReader, gbaRomDataArray[i], gen3CharsetEng, nullptr, true); + builder.build_script(rsefrlgTableReader, gbaRomDataArray[i], gen3CharsetEng); // strip the injected texts again for compression sake. // doing it this way preserves the pointers (because the text had been temporarily injected) diff --git a/tools/gba-payload-generator/src/mystery_gift_builder.cpp b/tools/gba-payload-generator/src/mystery_gift_builder.cpp index d33cc14..c6fdc69 100644 --- a/tools/gba-payload-generator/src/mystery_gift_builder.cpp +++ b/tools/gba-payload-generator/src/mystery_gift_builder.cpp @@ -82,6 +82,34 @@ static const char* getGameName(u32 gamecode) } } +/** + * @brief This function determines the longest of 2 text entries and sets that one to the textbox_var. + * + * The reason we do this is to make the references to the textbox_vars consistently pointing + * to the same addresses, even if certain entries have different lengths based on some game context. + * (tbh this is about the first_time-based text entries) + * + * This may look strange, but this ties together with our approach to strip the actual texts in the strip_injected_texts() function + * and inject them back into the payload at runtime. + * + * If this strip_injected_texts() function wasn't called, doing this wouldn't make any sense. + * + */ +static void setLongestTextEntryOnTextBoxVar(textbox_var &textVar, UncompressedFileContainerReader &textReader, uint32_t firstEntryIndex, uint32_t secondEntryIndex) +{ + uint32_t selectedEntryIndex; + + if(textReader.getFileSize(firstEntryIndex) > textReader.getFileSize(secondEntryIndex)) + { + selectedEntryIndex = firstEntryIndex; + } + else + { + selectedEntryIndex = secondEntryIndex; + } + textVar.set_text(textReader.getPointerToFile(selectedEntryIndex)); +} + mystery_gift_script::mystery_gift_script(u8 *save_section_30_buffer, u8 *mg_script_buffer) : curr_mg_index(NPC_LOCATION_OFFSET) , curr_section30_index(0) @@ -94,7 +122,7 @@ mystery_gift_script::mystery_gift_script(u8 *save_section_30_buffer, u8 *mg_scri { } -void mystery_gift_script::build_script(UncompressedFileContainerReader &text_table_reader, const struct ROM_DATA& curr_GBA_rom, const uint16_t *gen3_charset, PokeBox *box, bool first_time) +void mystery_gift_script::build_script(UncompressedFileContainerReader &text_table_reader, const struct ROM_DATA& curr_GBA_rom, const uint16_t *gen3_charset) { std::vector mg_variable_list; std::vector sec30_variable_list; @@ -342,23 +370,12 @@ void mystery_gift_script::build_script(UncompressedFileContainerReader &text_tab switch (curr_GBA_rom.gamecode) { case RUBY_ID: - textGreet.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textGreet_rse)); - textMoveBox.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textMoveBox_rs)); - textWeHere.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textWeHere_rs)); - textReceived.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textRecieved_rs)); - textIAm.set_text(text_table_reader.getPointerToFile(first_time ? RSEFRLG_dia_textIAm_first_rs : RSEFRLG_dia_textIAm_second_rs)); - textPCConvo.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textPCConvo_rs)); // ȼDon’t worry ƲÀ,Ňyou won’t have to do a thing!"); - textPCThanks.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textPCThanks_rs)); - textThank.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textThank_rs)); - textPCFull.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textPCFull_rs)); - textLookerFull.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textLookerFull_rs)); - break; case SAPPHIRE_ID: textGreet.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textGreet_rse)); textMoveBox.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textMoveBox_rs)); textWeHere.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textWeHere_rs)); textReceived.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textRecieved_rs)); - textIAm.set_text(text_table_reader.getPointerToFile(first_time ? RSEFRLG_dia_textIAm_first_rs : RSEFRLG_dia_textIAm_second_rs)); + setLongestTextEntryOnTextBoxVar(textIAm, text_table_reader, RSEFRLG_dia_textIAm_first_rs, RSEFRLG_dia_textIAm_second_rs); textPCConvo.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textPCConvo_rs)); // ȼDon’t worry ƲÀ,Ňyou won’t have to do a thing!"); textPCThanks.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textPCThanks_rs)); textThank.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textThank_rs)); @@ -371,7 +388,7 @@ void mystery_gift_script::build_script(UncompressedFileContainerReader &text_tab textMoveBox.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textMoveBox_frlg)); textWeHere.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textWeHere_frlg)); textReceived.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textRecieved_frlge)); - textIAm.set_text(text_table_reader.getPointerToFile(first_time ? RSEFRLG_dia_textIAm_first_frlge : RSEFRLG_dia_textIAm_second_frlge)); + setLongestTextEntryOnTextBoxVar(textIAm, text_table_reader, RSEFRLG_dia_textIAm_first_frlge, RSEFRLG_dia_textIAm_second_frlge); textPCConvo.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textPCConvo_frlge)); // ȼDon’t worry ƲÀ,Ňyou won’t have to do a thing!"); textPCThanks.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textPCThanks_frlge)); textThank.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textThank_frlge)); @@ -383,7 +400,7 @@ void mystery_gift_script::build_script(UncompressedFileContainerReader &text_tab textMoveBox.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textMoveBox_e)); textWeHere.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textWeHere_e)); textReceived.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textRecieved_frlge)); - textIAm.set_text(text_table_reader.getPointerToFile(first_time ? RSEFRLG_dia_textIAm_first_frlge : RSEFRLG_dia_textIAm_second_frlge)); + setLongestTextEntryOnTextBoxVar(textIAm, text_table_reader, RSEFRLG_dia_textIAm_first_frlge, RSEFRLG_dia_textIAm_second_frlge); textPCConvo.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textPCConvo_frlge)); // ȼDon’t worry ƲÀ,Ňyou won’t have to do a thing!"); textPCThanks.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textPCThanks_frlge)); textThank.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textThank_frlge)); @@ -391,7 +408,7 @@ void mystery_gift_script::build_script(UncompressedFileContainerReader &text_tab textLookerFull.set_text(text_table_reader.getPointerToFile(RSEFRLG_dia_textLookerFull_frlge)); break; } - textYouMustBe.set_text(text_table_reader.getPointerToFile(first_time ? RSEFRLG_dia_textYouMustBe_first : RSEFRLG_dia_textYouMustBe_second)); + setLongestTextEntryOnTextBoxVar(textYouMustBe, text_table_reader, RSEFRLG_dia_textYouMustBe_first, RSEFRLG_dia_textYouMustBe_second); textThank.insert_text(gen3_charset, save_section_30, is_hoenn_game); textPCFull.insert_text(gen3_charset, save_section_30, is_hoenn_game);