From b635af5212ef0075adc923b5da2ebb68616ef2a3 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 04:06:40 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x0042AE90 100.0% Reimplemented LobbyMenu::MenuItemRenderFunction_LobbyMenu_NonBoxedButtons, from Gynt's draft on his fork's reimpl/UI-MenuItems-development (a87bbb929d at 53.37%, a349a0e37f at 53.81%, eb99046ac0 at 59.30%, 2dedc176f9 at 76.48%, dd1a7c48c7 style). The draft has the buttons' conditions, the calls and their arguments. Behaviour fixes against dd1a7c48c7, whose 2dedc176f9 had restored most returns: Load (1) is not drawn for a guest, Ready (-20) is not drawn in a single-player skirmish, Send Map (105) is not drawn unless it can be used, and Skirmish Masters (413) is not drawn outside a single-player skirmish. Each marks the button and returns, as the original does. The keep under the mouse is the first match (-200). There are no draw-buffer or mark stores behind the switch, which the original does not have. Rewritten against the original instructions is the control flow: one switch with the cases in the order of the original's code, the scroll cases aside (its jump table covers -200 to 4; 105 and 413 are tested in front of it, as the compiler lowers such a switch). The forms that matter: - the flag for every human player being ready is declared in front of the switch, not in its two cases: the original keeps its 1 in edi through the whole switch and pushes it for TTA_CENTER and for the down buttons; - the six scroll buttons are six cases with a call each, in the order -10, -1, -11, -2, -100, -101. The compiler gives the calls' one temporary eax, ecx and edx in turn and then joins the cases whose code came out the same: -100 into -1's call and -11 with -101. That is the original: its jump table sends -100 into the middle of -1's block (0x0042AF64), and its four blocks read the blend into ecx, edx, ecx and eax (0x0042AF41 to 0x0042AF9D). Written as the four blocks the original ends with, the turns are off by one from the third block on; -11 and -101 may swap (the same code), and no other order of the six was compiled; - the texts of the buttons 3 and 105 are two calls each, one per colour. One call with the colour chosen in it compiles without a branch (neg / sbb). With the scroll cases as above the two calls of button 3 get the original's registers (y in edx and in eax, 0x0042B0B4 and 0x0042B0E4) and share only the pushes before and after the colour. The buttons' names in the comments are from the lobby's text group and from the click handler (0x00442640). No line for cmake/compiler-flags-gl.txt: the file reads 100.0% off the /GL list, and 100.0% on it too. quick_diff gives the same instructions with and without its callees' bodies in the unit. reccmp in a build of main's whole /GL list (the 133 files that exist) and the file, off the list, with every resolver of those files on: 144 functions, average 99.56. NonBoxedButtons 100.0% raw and normalised, no differing line, the jump table and its index bytes included. The same build without the file has 143 functions, and each of them reads the same. Both builds (off and on the list) had this file before its comments, clang-format and the flag's BOOLEnum type. quick_diff gives the same 383 instructions, line for line, for that text and for this one. The sources are main's at 3458fea34; main's two commits since (02fab423c, 812d149696) add cmake files only, with the new option off. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ...nderFunction_LobbyMenu_NonBoxedButtons.cpp | 287 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 288 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_NonBoxedButtons.cpp diff --git a/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_NonBoxedButtons.cpp b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_NonBoxedButtons.cpp new file mode 100644 index 0000000000..2d672fd375 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_NonBoxedButtons.cpp @@ -0,0 +1,287 @@ +#include "../LobbyMenu.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/DAT_ButtonBackgroundBlendStrength.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonGmDataIndex.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" +#include "OpenSHC/Globals/INT_00b95950.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x0042AE90 + void LobbyMenu::MenuItemRenderFunction_LobbyMenu_NonBoxedButtons(int buttonID, ...) + { + if (MACRO_CALL(OpenSHC::UI::Helpers_Func::AModalDialogIsActiveButIsNotQuitting)()) { + return; + } + // while the round table or an AI lord select is open, only some buttons stay live + if (DAT_MenuModalComposition1::instance.activeModalDialogID == OpenSHC::UI::Enums::MMT_ROUNDTABLE) { + if (buttonID != 2 && buttonID != 3 && buttonID != -20 && buttonID != -1 && buttonID != -2) { + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + } else if (DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_BASIC_AI_LORD_SELECT + || DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_EXTENDED_AI_LORD_SELECT) { + if (buttonID != 2 && buttonID != -20 && buttonID != -1 && buttonID != -2 && buttonID != -200 + && buttonID != -201) { + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + // every human player in the lobby is ready (buttons 1 and 4); declared in those cases the match is lost + BOOLEnum allReady = TRUE; + DAT_ButtonUnknownZero::instance = FALSE; + switch (buttonID) { + // the scroll buttons (up, down): -1 / -2 the chat, -10 / -11 the map list, -100 / -101 the map description + // six cases in this order (-11 and -101 may swap): the compiler joins them itself; joined here, no match + case -10: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, + DAT_PencilRenderCore::ptr)(0, DAT_ButtonBackgroundBlendStrength::instance); + break; + case -1: + // the chat's scroll buttons are not drawn in a single-player skirmish + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + break; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, + DAT_PencilRenderCore::ptr)(0, DAT_ButtonBackgroundBlendStrength::instance); + break; + case -11: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, + DAT_PencilRenderCore::ptr)(1, DAT_ButtonBackgroundBlendStrength::instance); + break; + case -2: + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + break; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, + DAT_PencilRenderCore::ptr)(1, DAT_ButtonBackgroundBlendStrength::instance); + break; + case -100: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, + DAT_PencilRenderCore::ptr)(0, DAT_ButtonBackgroundBlendStrength::instance); + break; + case -101: + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, + DAT_PencilRenderCore::ptr)(1, DAT_ButtonBackgroundBlendStrength::instance); + break; + // 1: the host's Load button, lit once every human player is ready and checkPlayerSetValid gives 2 or more + case 1: { + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + break; + } + if (!DAT_GameSynchronyState::instance.isHost) { + DAT_ButtonUnknownZero::instance = TRUE; + break; + } + for (int i = 1; i < countof(DAT_GameSynchronyState::instance.currentPlayerFullIDArray); ++i) { + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[i] != -1 + && DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[i] == 0) { + allReady = FALSE; + break; + } + } + if (MACRO_CALL_MEMBER( + OpenSHC::Synchrony::GameSynchronyState_Func::checkPlayerSetValid, DAT_GameSynchronyState::ptr)() + >= 2 + && allReady) { + // the fade written the long way round, for the match; it comes back to the blend strength itself + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderCurrentButtonToScreenMenuWithBlendingUnk)( + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } else { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderCurrentButtonToScreenMenuWithBlendingUnk)( + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 16 / 32 + 32); + } + break; + } + // 2: Main Menu (leave the lobby), always lit + case 2: + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderCurrentButtonToScreenMenuWithBlendingUnk)( + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + break; + // 3: a Ready text button (its click toggles ready, as -20's does); the text is lighter while it is + // interacted with + case 3: + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + break; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)( + DAT_ButtonBackgroundBlendStrength::instance, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + // two calls: one call with the colour chosen in it compiles without the branch + // "Ready" (the button's own number, 3) + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, buttonID, + DAT_ButtonW::instance / 2 + DAT_ButtonX::instance - 10, DAT_ButtonY::instance + 6, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, buttonID, + DAT_ButtonW::instance / 2 + DAT_ButtonX::instance - 10, DAT_ButtonY::instance + 6, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + break; + // -20: the Ready picture button + case -20: + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + DAT_ButtonUnknownZero::instance = TRUE; + break; + } + // cleared again, as the original does + DAT_ButtonUnknownZero::instance = FALSE; + if (DAT_GameSynchronyState::instance.DAT_TwoIfNotHost != 2) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + } + // a player who is not ready yet gets the next picture + if (DAT_GameSynchronyState::instance + .DAT_PlayerSlotArraySomeValue[DAT_GameSynchronyState::instance.currentPlayerSlotID] + == 0) { + ++DAT_CurrentButtonGmDataIndex::instance; + } + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderCurrentButtonToScreenMenuWithBlendingUnk)( + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + break; + // 4: the host's Launch Game button, lit once every human player is ready, checkPlayerSetValid gives 2 or + // more and the selected map's entry is above zero + case 4: { + if (!DAT_GameSynchronyState::instance.isHost) { + DAT_ButtonUnknownZero::instance = TRUE; + break; + } + for (int i = 1; i < countof(DAT_GameSynchronyState::instance.currentPlayerFullIDArray); ++i) { + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[i] != -1 + && DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[i] == 0) { + allReady = FALSE; + break; + } + } + if (MACRO_CALL_MEMBER( + OpenSHC::Synchrony::GameSynchronyState_Func::checkPlayerSetValid, DAT_GameSynchronyState::ptr)() + < 2) { + allReady = FALSE; + } + int strength = 32; + if (!allReady + || DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected + + DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + < 0 + || DAT_GameSynchronyState::instance + .unknownMapRelatedReceivedDataArray[DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected]] + <= 0) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + strength = 16; + } + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderCurrentButtonToScreenMenuWithBlendingUnk)( + 32 - (32 - DAT_ButtonBackgroundBlendStrength::instance) * strength / 32); + break; + } + // -200: the keeps on the map preview; the one under the mouse is remembered + case -200: + for (int i = 0; i < countof(DAT_GameCore::instance.keepPositions); ++i) { + if (DAT_GameCore::instance.keepPositions[i].x >= 0 + && DAT_MouseState::instance.screenSpaceX >= DAT_GameCore::instance.keepPositions[i].x + + DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + 572 + && DAT_MouseState::instance.screenSpaceX <= DAT_GameCore::instance.keepPositions[i].x + + DAT_WindowAndDirectDraw::instance.mainMenuBorderWidth + 595 + && DAT_MouseState::instance.screenSpaceY >= DAT_GameCore::instance.keepPositions[i].y + + DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight + 3 + && DAT_MouseState::instance.screenSpaceY <= DAT_GameCore::instance.keepPositions[i].y + + DAT_WindowAndDirectDraw::instance.mainMenuBorderHeight + 35) { + INT_00b95950::instance = i; + return; + } + } + break; + // 105: the host's Send Map button, drawn only while the selected map's entry is zero and no map file is + // being received + case 105: + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + break; + } + if (!DAT_GameSynchronyState::instance.isHost + || DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected < 0 + || DAT_GameSynchronyState::instance + .unknownMapRelatedReceivedDataArray[DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected]] + != 0 + || DAT_GameSynchronyState::instance.DAT_MapFileReceivingState != 0) { + DAT_ButtonUnknownZero::instance = TRUE; + break; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)( + DAT_ButtonBackgroundBlendStrength::instance, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + // two calls, as for button 3 + // "Send Map" + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, 105, + DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, DAT_ButtonY::instance + 6, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, 105, + DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, DAT_ButtonY::instance + 6, + OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + break; + // 413: Skirmish Masters (the rankings), shown only in a single-player skirmish + case 413: + // cleared again, as the original does + DAT_ButtonUnknownZero::instance = FALSE; + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + DAT_ButtonUnknownZero::instance = TRUE; + break; + } + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderCurrentButtonToScreenMenuWithBlendingUnk)( + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + break; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..f4fbd548b0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -6981,7 +6981,7 @@ SHC_3BB0A8C1_0x0042AC70 | 0.0% | Pending SHC_3BB0A8C1_0x0042AC90 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x0042AE90 | 0.0% | Pending +SHC_3BB0A8C1_0x0042AE90 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0042B364 | 0.0% | Pending