From ab83c7628f2f1bb1d8842cfee839338a8ccc86d9 Mon Sep 17 00:00:00 2001 From: robojumper Date: Sat, 22 Nov 2025 22:24:38 +0100 Subject: [PATCH] Use a common constant for msg window character buffer size --- include/d/d_textwindow_unk.h | 8 +++++--- include/d/lyt/msg_window/d_lyt_msg_window_sword.h | 4 ++-- include/d/lyt/msg_window/d_lyt_simple_window.h | 4 ++-- src/d/d_textwindow_unk.cpp | 4 ++-- src/d/lyt/msg_window/d_lyt_msg_window_sword.cpp | 14 +++++++------- src/d/lyt/msg_window/d_lyt_simple_window.cpp | 9 ++++----- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/include/d/d_textwindow_unk.h b/include/d/d_textwindow_unk.h index a599b2d0..f98aec26 100644 --- a/include/d/d_textwindow_unk.h +++ b/include/d/d_textwindow_unk.h @@ -30,6 +30,8 @@ struct dLytMsgWindowCharData { // one by one in the text boxes class TextWindowUnk { public: + static const int BUF_SIZE = 1023; + TextWindowUnk(dTagProcessor_c *tagProcessor); virtual ~TextWindowUnk() {} @@ -55,8 +57,8 @@ public: private: /* 0x0004 */ dTagProcessor_c *mpTagProcessor; - /* 0x0008 */ wchar_t mRawTextBuffer[1023]; - /* 0x0806 */ wchar_t mProcessedTextBuffer[1023]; + /* 0x0008 */ wchar_t mRawTextBuffer[BUF_SIZE]; + /* 0x0806 */ wchar_t mProcessedTextBuffer[BUF_SIZE]; /* 0x1004 */ wchar_t mUnkBuffer[511]; // ??? /* 0x1402 */ SizedString<64> field_0x1402; /* 0x1442 */ u8 _0x1442[0x144C - 0x1442]; @@ -90,7 +92,7 @@ public: } private: - dLytMsgWindowCharData mData[1023]; + dLytMsgWindowCharData mData[TextWindowUnk::BUF_SIZE]; }; #endif diff --git a/include/d/lyt/msg_window/d_lyt_msg_window_sword.h b/include/d/lyt/msg_window/d_lyt_msg_window_sword.h index ae9a40b8..82e649f5 100644 --- a/include/d/lyt/msg_window/d_lyt_msg_window_sword.h +++ b/include/d/lyt/msg_window/d_lyt_msg_window_sword.h @@ -76,8 +76,8 @@ private: /* 0x05F8 */ dLytCommonABtn_c mBtn; - /* 0x07A8 */ dLytMsgWindowCharData mCharacterData[1023]; - /* 0x5794 */ wchar_t mTextBuf[1023]; + /* 0x07A8 */ dLytMsgWindowCharData mCharacterData[TextWindowUnk::BUF_SIZE]; + /* 0x5794 */ wchar_t mTextBuf[TextWindowUnk::BUF_SIZE]; /* 0x5F94 */ dLytTextSword mSwordText; /* 0x607C */ dLytTextSword::ESwordType mSwordType; diff --git a/include/d/lyt/msg_window/d_lyt_simple_window.h b/include/d/lyt/msg_window/d_lyt_simple_window.h index fe3a402d..83f8e8b1 100644 --- a/include/d/lyt/msg_window/d_lyt_simple_window.h +++ b/include/d/lyt/msg_window/d_lyt_simple_window.h @@ -110,8 +110,8 @@ private: /* 0x01D8 */ dTextBox_c *mpTextboxes[2]; /* 0x01E0 */ nw4r::lyt::Pane *mpPanes[3]; /* 0x01F4 */ dTagProcessor_c *mpTagProcessor; - /* 0x01F8 */ dLytMsgWindowCharData mCharData[1023]; // TODO - how large is this really? - /* 0x51DC */ wchar_t mTextBuf[1023]; + /* 0x01F8 */ dLytMsgWindowCharData mCharData[TextWindowUnk::BUF_SIZE]; + /* 0x51DC */ wchar_t mTextBuf[TextWindowUnk::BUF_SIZE]; /* 0x59DC */ dLytTextSword mSwordText; /* 0x5AC4 */ s32 mSwordType; /* 0x5AC8 */ u8 field_0x5AC8; diff --git a/src/d/d_textwindow_unk.cpp b/src/d/d_textwindow_unk.cpp index 22782a5d..063df1b9 100644 --- a/src/d/d_textwindow_unk.cpp +++ b/src/d/d_textwindow_unk.cpp @@ -70,14 +70,14 @@ bool TextWindowUnk::checkEndReached() const { } void MsgWindowBlurRelated::build() { - for (int i = 0; i < 1023; i++) { + for (int i = 0; i < TextWindowUnk::BUF_SIZE; i++) { mData[i].reset(); } } void MsgWindowBlurRelated::drawTextBlur(dLytTextLight *thing, mVec2_c size, u8 alpha) { s8 t = -1; - for (int i = 0; i < 1023; i++) { + for (int i = 0; i < TextWindowUnk::BUF_SIZE; i++) { if (mData[i].displayTimerMaybe >= 0) { if (t == -1) { mData[i].displayTimerMaybe++; diff --git a/src/d/lyt/msg_window/d_lyt_msg_window_sword.cpp b/src/d/lyt/msg_window/d_lyt_msg_window_sword.cpp index 27e725f8..16426fc2 100644 --- a/src/d/lyt/msg_window/d_lyt_msg_window_sword.cpp +++ b/src/d/lyt/msg_window/d_lyt_msg_window_sword.cpp @@ -4,6 +4,7 @@ #include "d/d_gfx.h" #include "d/d_tag_processor.h" #include "d/d_lyt_hio.h" +#include "d/d_textwindow_unk.h" #include "d/lyt/d2d.h" #include "d/lyt/d_textbox.h" #include "m/m_vec.h" @@ -96,7 +97,7 @@ bool dLytMsgWindowSword_c::build(d2d::ResAccIf_c *resAcc1, d2d::ResAccIf_c *resA mSwordText.build(resAcc, mSwordType); - for (int i = 0; i < 1023; i++) { + for (int i = 0; i < TextWindowUnk::BUF_SIZE; i++) { mCharacterData[i].reset(); mTextBuf[i] = L'\0'; } @@ -265,7 +266,7 @@ bool dLytMsgWindowSword_c::execute() { void dLytMsgWindowSword_c::draw() { mLyt.draw(); - for (int i = 0; i < 1023; i++) { + for (int i = 0; i < TextWindowUnk::BUF_SIZE; i++) { if (mCharacterData[i].displayTimerMaybe >= 0) { if (!mHasDrawnThisTick) { mCharacterData[i].displayTimerMaybe += 1; @@ -313,15 +314,14 @@ bool dLytMsgWindowSword_c::isDoneClosing() const { } bool dLytMsgWindowSword_c::setText(const wchar_t *text) { - int foundIdx = 1023; - for (int i = 0; i < 1023; i++) { + int foundIdx = TextWindowUnk::BUF_SIZE; + for (int i = 0; i < TextWindowUnk::BUF_SIZE; i++) { if (mCharacterData[i].displayTimerMaybe >= 0 && foundIdx > mCharacterData[i].field_0x0C) { foundIdx = mCharacterData[i].field_0x0C; } } - // How is text bounds-checked here???? - for (int i = 0; i < 1023; i++) { + for (int i = 0; i < TextWindowUnk::BUF_SIZE; i++) { if (i < foundIdx) { mTextBuf[i] = text[i]; } else { @@ -333,5 +333,5 @@ bool dLytMsgWindowSword_c::setText(const wchar_t *text) { mpTextboxes[1]->SetTagProcessor(mpTagProcessor); mpTextboxes[0]->setTextWithTextProcessor(mTextBuf, mpTagProcessor, 0); mpTextboxes[1]->setTextWithTextProcessor(mTextBuf, mpTagProcessor, 0); - return foundIdx == 1023; + return foundIdx == TextWindowUnk::BUF_SIZE; } diff --git a/src/d/lyt/msg_window/d_lyt_simple_window.cpp b/src/d/lyt/msg_window/d_lyt_simple_window.cpp index 67cb522c..9991aae7 100644 --- a/src/d/lyt/msg_window/d_lyt_simple_window.cpp +++ b/src/d/lyt/msg_window/d_lyt_simple_window.cpp @@ -280,7 +280,7 @@ bool dLytSimpleWindowSword_c::build(d2d::ResAccIf_c *resAcc, dTagProcessor_c *ta mpTextboxes[1]->setIsShadow(1); mpTagProcessor = tagProcessor; - for (int i = 0; i < (int)ARRAY_LENGTH(mCharData); i++) { + for (int i = 0; i < TextWindowUnk::BUF_SIZE; i++) { mCharData[i].reset(); mTextBuf[i] = L'\0'; } @@ -373,15 +373,14 @@ bool dLytSimpleWindowSword_c::isOut() { } bool dLytSimpleWindowSword_c::setText(const wchar_t *text) { - int foundIdx = ARRAY_LENGTH(mCharData); - for (int i = 0; i < (int)ARRAY_LENGTH(mCharData); i++) { + int foundIdx = TextWindowUnk::BUF_SIZE; + for (int i = 0; i < TextWindowUnk::BUF_SIZE; i++) { if (mCharData[i].displayTimerMaybe >= 0 && foundIdx > mCharData[i].field_0x0C) { foundIdx = mCharData[i].field_0x0C; } } - // How is text bounds-checked here???? - for (int i = 0; i < (int)ARRAY_LENGTH(mCharData); i++) { + for (int i = 0; i < TextWindowUnk::BUF_SIZE; i++) { if (i < foundIdx) { mTextBuf[i] = text[i]; } else {