From 9fc48caee57410d4408919e964ff839da129369d Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 12:59:47 +0100 Subject: [PATCH 1/2] reimplement: SHC_3BB0A8C1_0x004285F0 100.0% Reimplemented LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapDesc, from Gynt's draft (de3ed4fd0b at 56.20% on his fork's reimpl/UI-MenuItems; 26.1% at 9745a3f66f on his closed #254's reimpl/UI-MenuItems, 54.84% at 3df20401ef on his fork's reimpl/UI-MenuItems-development). The drafts are the decompiler's output. One behaviour fix against them: behind a description from the string table they go on and draw the map's own description text as well, where the original leaves with a tail jump to setScreenMenuSurfaceHeightRangeToResolution (0x00428965); here the function ends there too. Their map index [offset + selected - 1] is this text's [offset + selected]: in main's header the array begins one element earlier. Rewritten against the original instructions: - the box and its seven lines are a __forceinline function with the four edges as parameters, in the order (bottom, top, left, right). The original stores the right edge and the box's right edge (right - 20) where they are defined and reads them back (0x0042861F, 0x00428626, 0x00428646), keeps left - 1 in the second slot and recomputes right + 1 per line; written in the function with locals, the second value stays in a register and nothing is stored. The parameter order decides the edges' registers (top ebx, bottom ebp); four other orders differ. Plain inline is not expanded for this body (209 instructions against 288), off the /GL list and on it (39.9% in a build with the file on the list); Gynt's draft #396 makes FunctionResolver.h's get() functions __forceinline for the same reason; - the lookup of the title and the title's draw are written in both arms of the host test: the original pushes the lookup's arguments in each arm (0x004287AB, 0x004287B3) and shares everything from the call on (0x004287BD). With the title's draw in both arms too, the compiler joins the tails itself and the scratch registers and x's register (edi) are the original's; - the title's x is written out as x - 100 at its four uses (as a local: quick_diff 0.7552); - the lookup's out-parameter is declared in each arm of the host test: at the function's scope its address stays live to the end, the frame gets a third slot and the last call is no longer a tail jump (284 instructions). No line for cmake/compiler-flags-gl.txt: the file reads 100.0% off the /GL list, and 100.0% on it too. reccmp in a build of main's whole /GL list (the 133 files that exist), this file and setScreenMenuSurfaceHeightRangeToResolution.cpp (on main at 100%, not on the list; the function's tail jumps go to it), all off the list, with every resolver of those files on: 145 functions, average 99.57. The function 100.0% raw and normalised, no differing line. With the file on the list the same: 100.0% raw and normalised, no differing line. The other 143 functions of main's list read the same as without the two files. Without the callee's file in the build reccmp has no name for the target of the tail jump at 0x00428903 and reads 99.7% raw, 100.0% normalised. The builds had an earlier text of this file (other comments, another name for the helper, right - 20 written out in the lines, the out-parameter in a block around both arms); quick_diff gives the same 288 instructions, line for line, for both texts. 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 --- ...nuItemRenderFunction_LobbyMenu_MapDesc.cpp | 147 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapDesc.cpp diff --git a/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapDesc.cpp b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapDesc.cpp new file mode 100644 index 0000000000..b2c6348ec4 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapDesc.cpp @@ -0,0 +1,147 @@ +#include "../LobbyMenu.func.hpp" + +#include "OpenSHC/Global.func.hpp" +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/COL_VERY_SOFT_YELLOW.hpp" +#include "OpenSHC/Globals/DAT_00b960f4.hpp" +#include "OpenSHC/Globals/DAT_ButtonBackgroundBlendStrength.hpp" +#include "OpenSHC/Globals/DAT_ButtonH.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // The box, its outline and the scroll bar's column: inlined in the original, with the four edges as parameters + // in this order. Plain `inline` is not expanded for this body; written into the function the match is lost. + __forceinline static void drawDescriptionFrame(int bottom, int top, int left, int right) + { + // the box ends where the scroll bar's column begins; a local, so that it is stored where it is defined, + // as the original stores it + int const boxRight = right - 20; + // written the long way round, as the original computes them (for the texts it is the strength itself) + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, DAT_PencilRenderCore::ptr)( + left, top, boxRight, bottom, (DAT_ButtonBackgroundBlendStrength::instance - 32) * 16 / 32 + 32); + // the lines only once the menu is fully blended in: the outline, then the column and its two button squares + if (DAT_ButtonBackgroundBlendStrength::instance == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + left - 1, top - 1, right + 1, top - 1, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + left - 1, bottom + 1, right + 1, bottom + 1, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + left - 1, top, left - 1, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + right + 1, top, right + 1, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + boxRight, top, boxRight, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + boxRight, top + 20, right, top + 20, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + boxRight, bottom - 20, right, bottom - 20, COL_VERY_SOFT_YELLOW::instance.shortValue); + } + } + + // FUNCTION: STRONGHOLDCRUSADER 0x004285F0 + void LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapDesc(int buttonID, ...) + { + if (MACRO_CALL(OpenSHC::UI::Helpers_Func::AModalDialogIsActiveButIsNotQuitting)()) { + return; + } + int const x = DAT_ButtonX::instance; + int const y = DAT_ButtonY::instance; + drawDescriptionFrame(DAT_ButtonH::instance + y + 122, y + 3, x - 110, DAT_ButtonW::instance + x + 101); + if (DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber == 0 + || DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected == -1) { + return; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::setScreenMenuSurfaceHeightRange, + DAT_TextureRenderCoreObject::ptr)(y + 7, DAT_ButtonH::instance + y + 121); + // the host shows the selected map, a guest the map the host chose. The lookup and the title are written in + // both arms, and the title's x at each use: written once, or x - 100 in a local, the match is lost + if (DAT_GameSynchronyState::instance.isHost) { + // the lookup's second result, which is not used. Declared in each arm: at function scope its address + // stays live to the end and the last call is no longer a tail jump; with a value it gets a store + int descriptionGroup; + // the file name and the title are locals: written into the calls that use them, the match is lost + char* const fileName + = MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex, + DAT_ResourceManager::ptr)(DAT_MenuTextInputState::instance + .DAT_ArrayOfMapIndices[DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected]); + char* const title + = MACRO_CALL(OpenSHC::Global_Func::GetStringBasedOnHardcodedMaps)(fileName, &descriptionGroup); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + title, x - 100, y - DAT_00b960f4::instance - 8, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_C2F0EB, 19, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } else { + int descriptionGroup; + char* const title = MACRO_CALL(OpenSHC::Global_Func::GetStringBasedOnHardcodedMaps)( + DAT_GameSynchronyState::instance.mapName, &descriptionGroup); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + title, x - 100, y - DAT_00b960f4::instance - 8, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_C2F0EB, 19, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + // "-" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s___005a2280, x - 94, y - DAT_00b960f4::instance - 8, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_C2F0EB, 19, TRUE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + // "Unbalanced" (412) or "Balanced" (411) + if (DAT_GameCore::instance.savedMapBalance != 0) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, 412, x - 88, y - DAT_00b960f4::instance - 8, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, TRUE, + (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, 411, x - 88, y - DAT_00b960f4::instance - 8, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, TRUE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + // the description: the map's own text, or one from the string table + if (!DAT_GameCore::instance.mapDescUseStringTable) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderMultilineText5Unk, DAT_TextManagerObject::ptr)( + DAT_GameCore::instance.mapDescription, x - 100, y - DAT_00b960f4::instance + 11, + DAT_ButtonW::instance + 170, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::setScreenMenuSurfaceHeightRangeToResolution, + DAT_TextureRenderCoreObject::ptr)(); + return; + } + if (DAT_GameCore::instance.mapDescUseStringTableIndex != 0) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderMultilineTextUnk, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MAP_NAMES, DAT_GameCore::instance.mapDescUseStringTableIndex, x - 100, + y - DAT_00b960f4::instance + 11, DAT_ButtonW::instance + 170, + OpenSHC::Rendering::Colors::COL_C2F0EB, 19, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::setScreenMenuSurfaceHeightRangeToResolution, + DAT_TextureRenderCoreObject::ptr)(); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..6293ebd9a3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -6869,7 +6869,7 @@ SHC_3BB0A8C1_0x00428590 | 0.0% | Pending SHC_3BB0A8C1_0x004285C0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004285F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004285F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00428980 | 100.0% | Reimplemented From b6f03c1c2b7f5d420c8a7386375bb939cda17844 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 16:40:36 +0100 Subject: [PATCH 2/2] reimplement: SHC_3BB0A8C1_0x004285F0 the frame written into the function, no __forceinline helper LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapDesc (0x004285F0), after review: the box, its outline and the scroll bar's column are written into the function in a scope of their own, with the four edges as int const locals, in place of the __forceinline helper drawDescriptionFrame. The edges are declared right, left, top, bottom, the reverse of the helper's parameters (bottom, top, left, right): in the parameters' order the edges' registers differ (quick_diff 0.9306, the same 288 instructions); in the reverse order the listing is the original's (1.0000). The braces do not change the listing; they keep the four names to the frame. The box's right edge is written out as right - 20 (the helper needed it in a local; here it gives the same listing). The same instructions as the helper form. The function is from Gynt's draft (de3ed4fd0b at 56.20%; his newest, 3df20401ef, at 54.84%), as the first commit says; this one changes only how the frame is written. reccmp, the same narrow builds as before (main's /GL list, this file and setScreenMenuSurfaceHeightRangeToResolution.cpp): 145 functions, average 99.57; the function 100.0% raw and normalised, no differing line, off the /GL list and on it (that build had the box's right edge in a local; quick_diff gives the same 288 instructions); this text itself, off the list: the same. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 Co-Authored-By: Claude Opus 5.5 --- ...nuItemRenderFunction_LobbyMenu_MapDesc.cpp | 67 ++++++++++--------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapDesc.cpp b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapDesc.cpp index b2c6348ec4..3be4a492dc 100644 --- a/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapDesc.cpp +++ b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_MapDesc.cpp @@ -30,36 +30,6 @@ namespace OpenSHC { namespace UI { namespace MenuItems { - // The box, its outline and the scroll bar's column: inlined in the original, with the four edges as parameters - // in this order. Plain `inline` is not expanded for this body; written into the function the match is lost. - __forceinline static void drawDescriptionFrame(int bottom, int top, int left, int right) - { - // the box ends where the scroll bar's column begins; a local, so that it is stored where it is defined, - // as the original stores it - int const boxRight = right - 20; - // written the long way round, as the original computes them (for the texts it is the strength itself) - MACRO_CALL_MEMBER( - OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, DAT_PencilRenderCore::ptr)( - left, top, boxRight, bottom, (DAT_ButtonBackgroundBlendStrength::instance - 32) * 16 / 32 + 32); - // the lines only once the menu is fully blended in: the outline, then the column and its two button squares - if (DAT_ButtonBackgroundBlendStrength::instance == 0) { - MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - left - 1, top - 1, right + 1, top - 1, COL_VERY_SOFT_YELLOW::instance.shortValue); - MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - left - 1, bottom + 1, right + 1, bottom + 1, COL_VERY_SOFT_YELLOW::instance.shortValue); - MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - left - 1, top, left - 1, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); - MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - right + 1, top, right + 1, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); - MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - boxRight, top, boxRight, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); - MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - boxRight, top + 20, right, top + 20, COL_VERY_SOFT_YELLOW::instance.shortValue); - MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( - boxRight, bottom - 20, right, bottom - 20, COL_VERY_SOFT_YELLOW::instance.shortValue); - } - } - // FUNCTION: STRONGHOLDCRUSADER 0x004285F0 void LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapDesc(int buttonID, ...) { @@ -68,7 +38,42 @@ namespace UI { } int const x = DAT_ButtonX::instance; int const y = DAT_ButtonY::instance; - drawDescriptionFrame(DAT_ButtonH::instance + y + 122, y + 3, x - 110, DAT_ButtonW::instance + x + 101); + // the box, its outline and the scroll bar's column. The edges are declared right, left, top, bottom: in the + // order bottom, top, left, right, their registers differ from the original's + { + int const right = DAT_ButtonW::instance + x + 101; + int const left = x - 110; + int const top = y + 3; + int const bottom = DAT_ButtonH::instance + y + 122; + // written the long way round, as the original computes them (for the texts it is the strength itself) + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBlendedBlackBox, DAT_PencilRenderCore::ptr)( + left, top, right - 20, bottom, (DAT_ButtonBackgroundBlendStrength::instance - 32) * 16 / 32 + 32); + // the lines only once the menu is fully blended in: the outline, then the column and its two squares + if (DAT_ButtonBackgroundBlendStrength::instance == 0) { + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + left - 1, top - 1, right + 1, top - 1, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + left - 1, bottom + 1, right + 1, bottom + 1, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + left - 1, top, left - 1, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + right + 1, top, right + 1, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + right - 20, top, right - 20, bottom, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + right - 20, top + 20, right, top + 20, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawLine, DAT_PencilRenderCore::ptr)( + right - 20, bottom - 20, right, bottom - 20, COL_VERY_SOFT_YELLOW::instance.shortValue); + } + } if (DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber == 0 || DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected == -1) { return;