@@ -152,28 +152,35 @@ class Text
152152 return result;
153153 }
154154
155- static bool CanTextInThisSlotBeAddedToBrief (const char * slot )
155+ static bool CanThisTextBeAddedToBrief (const char * text )
156156 {
157- // content dedup: exits early if another entry already holds the same text.
158- for (size_t i = 0 ; i < BriefSize; i++)
157+ if (!CTheScripts::bAddNextMessageToPreviousBriefs) return false ;
158+
159+ for (const auto & brief : CMessages::PreviousBriefs)
159160 {
160- const auto pText = CMessages::PreviousBriefs[i].m_pText ;
161- if (pText == nullptr ) break ; // end of used entries
162- if (pText == slot) continue ; // stale self-reference, skip to avoid a false positive duplicate
163- if (strcmp (pText, slot) == 0 ) return false ; // content duplicate, exit
161+ const auto briefText = brief.m_pText ;
162+ if (briefText && strcmp (briefText, text) == 0 ) return false ;
164163 }
164+ return true ;
165+ }
166+
167+ static char * PrepareThisTextForBrief (const char * text)
168+ {
169+ briefIdx = (briefIdx + 1 ) % BriefSize;
170+ char * msgSlot = briefs[briefIdx];
165171
166- // stale pointer eviction: prevents the game's pointer-based dedup from rejecting the insertion
167- for (size_t i = 0 ; i < BriefSize; i++)
172+ for (auto & brief : CMessages::PreviousBriefs)
168173 {
169- auto & pText = CMessages::PreviousBriefs[i].m_pText ;
170- if (pText == slot)
171- {
172- pText = nullptr ;
173- break ;
174- }
174+ // stale pointer eviction: prevents the game's pointer-based brief dedup from rejecting the insertion
175+ const auto briefText = brief.m_pText ;
176+ if (briefText == msgSlot) brief.m_pText = nullptr ;
175177 }
176- return true ;
178+
179+ // put the message into a free slot in the static buffer to get a persistent pointer
180+ const auto msgSlotSize = sizeof (briefs[briefIdx]);
181+ strncpy_s (msgSlot, msgSlotSize, text, msgSlotSize - 1 );
182+
183+ return msgSlot;
177184 }
178185
179186 static void PrintHelp (CLEO::CRunningScript* thread, const char * text)
@@ -182,17 +189,9 @@ class Text
182189
183190 if (IsLegacyScript (thread)) return ;
184191
185- if (CTheScripts::bAddNextMessageToPreviousBriefs )
192+ if (CanThisTextBeAddedToBrief (text) )
186193 {
187- briefIdx = (briefIdx + 1 ) % BriefSize;
188- auto & briefSlot = briefs[briefIdx];
189-
190- strncpy_s (briefSlot, text, sizeof (briefSlot) - 1 );
191-
192- if (CanTextInThisSlotBeAddedToBrief (briefSlot))
193- {
194- CMessages::AddToPreviousBriefArray (briefSlot, -1 , -1 , -1 , -1 , -1 , -1 , 0 );
195- }
194+ CMessages::AddToPreviousBriefArray (PrepareThisTextForBrief (text), -1 , -1 , -1 , -1 , -1 , -1 , 0 );
196195 }
197196
198197 CTheScripts::bAddNextMessageToPreviousBriefs = true ;
@@ -201,10 +200,10 @@ class Text
201200 static void AddToMessageQueue (CLEO::CRunningScript* pScript, const char * text, int time, bool now)
202201 {
203202 /*
204- CLEO 4: always show messages, no brief change, no subtitle suppression (~z~)
205- CLEO 5: show messages conditionally based on user preference, update brief
203+ CLEO 4: show subtitle ~z~ regarless of "Show Subtitles"; no brief update ever
204+ CLEO 5: show subtitle ~z~ only if "Show Subtitles" is ON; update brief if needed
206205
207- Both: if message queue is full, don't show the message, unless it's a NOW message.
206+ Both: Queue messages; if the queue is full, skip the next message, unless it's a NOW message.
208207 */
209208
210209 const auto isLegacy = IsLegacyScript (pScript);
@@ -231,15 +230,20 @@ class Text
231230
232231 if (display)
233232 {
234- // put the message into a free slot in our static buffer to get a persistent pointer
235- queueIdx = (queueIdx + 1 ) % MessageQueueSize;
236- auto & messageSlot = messageQueue[queueIdx];
237- strncpy_s (messageSlot, text, sizeof (messageSlot) - 1 );
233+ // put the message into a free slot in the static buffer to get a persistent pointer
234+ queueIdx = (queueIdx + 1 ) % MessageQueueSize;
235+ char * messageSlot = messageQueue[queueIdx];
236+ const auto bufSize = sizeof (messageQueue[queueIdx]);
237+ strncpy_s (messageSlot, bufSize, text, bufSize - 1 );
238238
239239 // check game brief and decide whether this message can be added to it.
240240 // Note: legacy scripts never modify the game brief.
241- const auto addToBrief = !isLegacy && CTheScripts::bAddNextMessageToPreviousBriefs &&
242- CanTextInThisSlotBeAddedToBrief (messageSlot);
241+ const auto addToBrief = !isLegacy && CanThisTextBeAddedToBrief (text);
242+
243+ if (addToBrief)
244+ {
245+ messageSlot = PrepareThisTextForBrief (text);
246+ }
243247
244248 if (now)
245249 {
0 commit comments