From 4a6617c3d6a6dcc31584c949ba40ce07cbf6a389 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 22:34:11 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x0048F590 100.0% Reimplemented MenuItemActionHandler_Chat_MostButtons, the chat dialog's buttons: a negative button sends the message to that one player only, 31 to everyone, 32 to nobody, 35 to the own team. 33 sends the message and closes the dialog, as 34 does without sending; a message that is empty or only spaces is neither sent nor closes it. 69 opens the allies dialog. The sender always gets the message too. Written from the original's instructions, with gynt's draft beside it for the reads: his best is 59.60% (ab1c46e59f on his fork's reimpl/UI-MenuItems), the newest 6aa5d327b8 on reimpl/UI-MenuItems-development. Behaviour against the draft, in every version: case 33's space-skipping loop. In ab1c46e59f, 8725ec5232 and 6aa5d327b8 the loop returns after its first pass, so a message that starts with a space and is longer than one character returns at once: it is not sent, the dialog stays open, and the sender's flag is not set. In 51c5f22c5 to 637c6b0cb and a4de844ef (the 42.2% file, #254's), e1c66a1321, 8c21931533, 9205629df0 and 8ca78619cd it has no return, so a message of spaces only is sent and the dialog closes. The original sends only a message with a character other than a space, and sets the sender's flag either way. The receiver flags are written TRUE / FALSE (they hold only 0 or 1). What the match needed: one counter for all the loops (a counter per loop swaps the text scan's address registers); the negative button's arm without a return of its own, ending in the sender's store behind the switch as the cases do (with a return there the constant 1 is built from the 0 register); its index written as `buttonID < 0 ? -buttonID : buttonID` (a plain -buttonID is folded into the address); the cases in the original's order (35 before 33). Measured in a narrow build of this file on main 0e4a83b5d with both resolver sets on: 100.0% raw and normalised. Not run in game. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...MenuItemActionHandler_Chat_MostButtons.cpp | 109 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/Chat/MenuItemActionHandler_Chat_MostButtons.cpp diff --git a/src/OpenSHC/UI/MenuItems/Chat/MenuItemActionHandler_Chat_MostButtons.cpp b/src/OpenSHC/UI/MenuItems/Chat/MenuItemActionHandler_Chat_MostButtons.cpp new file mode 100644 index 0000000000..b70eb61cb5 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/Chat/MenuItemActionHandler_Chat_MostButtons.cpp @@ -0,0 +1,109 @@ +#include "../Chat.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + namespace Chat { + + // FUNCTION: STRONGHOLDCRUSADER 0x0048F590 + void MenuItemActionHandler_Chat_MostButtons(int buttonID, ...) + { + // one counter for all the loops (a counter per loop swaps the text scan's address registers) + int i; + // the player buttons (-1 to -8) address the next message to that one player only + // both arms end in the sender's store below (a return in this arm builds the 1 from the 0 register) + if (buttonID < 0) { + for (i = 0; i < countof(DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray); ++i) { + DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray[i] = FALSE; + } + // the conditional, not -buttonID or abs() (both lose the match: -buttonID folds into the address) + DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray[buttonID < 0 ? -buttonID : buttonID] + = TRUE; + } else { + switch (buttonID) { + case 31: + // everyone + for (i = 0; i < countof(DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray); ++i) { + DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray[i] = TRUE; + } + break; + case 32: + // nobody but the sender (no button of the chat menu passes 32) + for (i = 0; i < countof(DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray); ++i) { + DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray[i] = FALSE; + } + break; + case 35: { + // the own team (before 33 as in the original; in number order the match is lost) + int const team = DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID]; + for (i = 0; i < countof(DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray); ++i) { + DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray[i] = FALSE; + } + // the players' slots, 1 to 8 + for (i = 1; i < countof(DAT_GameState::instance.mapAndTime.playerTeams); ++i) { + if (DAT_GameState::instance.mapAndTime.playerTeams[i] == team) { + DAT_GameSynchronyState::instance.DAT_ChatMessageReceiverArray[i] = TRUE; + } + } + break; + } + case 33: { + // send, unless the message is empty or only spaces + char* const text = MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::getCurrentText, DAT_UserTextHandlerState::ptr)(); + int const length = strlen(text); + for (i = 0; i < length; ++i) { + if (text[i] != ' ') { + // 0: the typed text (the taunt buttons store the taunt's number, 1 to 20) + DAT_GameSynchronyState::instance.DAT_ChatTauntOrMessage = 0; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_TAUNT_OR_CHAT); + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_NONE, FALSE); + break; + } + } + break; + } + case 34: + // close the dialog without sending + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_NONE, FALSE); + break; + case 69: + // the allies dialog + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_ALLIES, FALSE); + if (DAT_GameCore::instance.genieVoiceActive) { + // "Genie_11.wav": "Your allies" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + SFX_YourAllies); + } + break; + } + } + // the sender always gets the message too + DAT_GameSynchronyState::instance + .DAT_ChatMessageReceiverArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] = TRUE; + } + + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e8a6864d03..3c3871f6ff 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23263,7 +23263,7 @@ SHC_3BB0A8C1_0x0048F440 | 0.0% | Pending SHC_3BB0A8C1_0x0048F4C0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0048F590 | 0.0% | Pending +SHC_3BB0A8C1_0x0048F590 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048F800 | 0.0% | Pending