From f4dfd79e5e6c2a1245888cf0fc3c7c6fa1d84d96 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 10:41:39 +0100 Subject: [PATCH 01/10] reimplement: SHC_3BB0A8C1_0x004F4E00 100.0% Reimplemented BottomLeftTextDisplayState::setBottomLeftTextDisplayText, from gynt's draft (432060404, 35.93%, and c7ba75fa9, 32.7%, in his closed #256; restyled up to cf563c2ba on his fork's archive/UI-MenuViews-development-second-pass and in 10280b161 on reimpl/UI-Core-development), rewritten from the binary: a message type of 0 clears the text and returns, a less important text returns early (the draft's check was empty), the countdown restarts unless the same text is shown again, and a duration of -1 stores 0 and skips timeGetTime. The parameter stays main's int param_4 (the draft used the union); it is compared with and stored as the union's buildingType. The lookup loop's index is set before the message type (declared in the for it measures lower; the numbers are in the PR text), and the sound is s_placement_warning1_wav_005ab8f4 rather than a string literal. reccmp 100.0%. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../setBottomLeftTextDisplayText.cpp | 78 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp diff --git a/src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp b/src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp new file mode 100644 index 0000000000..38a0ee2436 --- /dev/null +++ b/src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp @@ -0,0 +1,78 @@ +#include "../BottomLeftTextDisplayState.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/UI/Enums/TextMessageBLLookupStructTypeEnum.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" + +namespace OpenSHC { +namespace UI { + + using OpenSHC::Commands::MappersEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F4E00 + void BottomLeftTextDisplayState::setBottomLeftTextDisplayText(int messageTypeUnk, int textGroupIndex, + int textNumInGroup, int param_4, int importanceUnk, int displayDurationUnk) + { + if (messageTypeUnk == 0) { + this->currentlyDisplayedTextIsDisplayedUnk = 0; + return; + } + if (this->currentlyDisplayedTextIsDisplayedUnk != 0) { + // a less important text doesn't replace the one shown + if (importanceUnk < this->currentlyDisplayedTextImportanceUnk) { + return; + } + if (textGroupIndex != this->currentlyDisplayedUnkTextGroupIndex_0x4 + || textNumInGroup != this->currentlyDisplayedUnkTextNumInGroup_0x8 + || param_4 != this->currentlyDisplayedUnktextExtraObject.buildingType) { + this->countdown = 0; + } + } else { + this->countdown = 0; + } + this->currentlyDisplayedTextIsDisplayedUnk = messageTypeUnk; + if (textGroupIndex == -1) { + // the text is looked up by the type of message and the object it is about + // the index is set before the type, not in the for (in the for: quick_diff 0.9884 -> 0.9767) + int i = 0; + TextMessageBLLookupStructTypeEnumInt messageType = 0; + if (messageTypeUnk == 2) { + messageType = OpenSHC::UI::Enums::TMBLLSTE_BUILDING_TEXT; + } + for (; DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].messageType != -1; ++i) { + if (messageType == DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].messageType + && param_4 + == DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].associatedType.buildingType) { + this->currentlyDisplayedUnkTextGroupIndex_0x4 + = DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].textGroupIndex; + this->currentlyDisplayedUnkTextNumInGroup_0x8 + = DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].textIndexInGroup; + break; + } + } + } else { + this->currentlyDisplayedUnkTextGroupIndex_0x4 = textGroupIndex; + this->currentlyDisplayedUnkTextNumInGroup_0x8 = textNumInGroup; + // "Not enough workers available to run this building." + if (messageTypeUnk == 1 && textGroupIndex == 77 && textNumInGroup == 1) { + // "placement_warning1.wav" + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_placement_warning1_wav_005ab8f4); + } + } + this->currentlyDisplayedUnktextExtraObject.buildingType = (MappersEnum)param_4; + this->currentlyDisplayedTextImportanceUnk = importanceUnk; + if (displayDurationUnk != -1) { + this->textMessageDurationUnk = displayDurationUnk; + this->textMessageTime = timeGetTime(); + } else { + this->textMessageDurationUnk = 0; + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ed989c9a21..fae2596738 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38643,7 +38643,7 @@ SHC_3BB0A8C1_0x004F4CD0 | 0.0% | Pending SHC_3BB0A8C1_0x004F4D70 | 0.0% | Pending -SHC_3BB0A8C1_0x004F4E00 | 0.0% | Pending +SHC_3BB0A8C1_0x004F4E00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F4EF0 | 0.0% | Pending From bffeb07da6db9592932301a1593a7aa568ae6366 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 10:41:39 +0100 Subject: [PATCH 02/10] header: the slider and scrollbar render functions' last parameter is a BOOLEnum The original pushes it as a 4-byte value: prepareAndRenderMenuItems (0x004F49D0, next commit) keeps the flag in a stack slot (mov dword ptr [esp + 8], 1 at 0x004F4BB4) and pushes it with mov ecx, dword ptr [esp + 8] / push ecx, where a bool parameter makes MSVC compare and setne first. MenuItemRenderFunction_0x20, the same callback in Ghidra's other copy, already has BOOLEnum there. SliderRenderFunction is only used by MenuItemRenderFunctionUnion's slider member, so nothing else changes. With it prepareAndRenderMenuItems is at reccmp 100.0%. Main's six slider render functions take BOOL isDragged (five of them) or BOOLEnum (NewInvasion_RepeatSlider). ScrollbarRenderFunction, the union's scrollbar member, gets the same type: every scrollbar render function on main takes BOOLEnum isDragged. The scrollbar items are drawn through the slider member, and no .cpp uses the scrollbar member. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/Callbacks/ScrollbarRenderFunction.hpp | 5 ++++- src/OpenSHC/UI/Callbacks/SliderRenderFunction.hpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/Callbacks/ScrollbarRenderFunction.hpp b/src/OpenSHC/UI/Callbacks/ScrollbarRenderFunction.hpp index ff195f17e1..cb9820f7cd 100644 --- a/src/OpenSHC/UI/Callbacks/ScrollbarRenderFunction.hpp +++ b/src/OpenSHC/UI/Callbacks/ScrollbarRenderFunction.hpp @@ -8,11 +8,14 @@ #pragma once +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { namespace UI { namespace Callbacks { - typedef void(__cdecl ScrollbarRenderFunction)(int, int, int, int, bool); + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + typedef void(__cdecl ScrollbarRenderFunction)(int, int, int, int, BOOLEnum); } // namespace Callbacks } // namespace UI } // namespace OpenSHC diff --git a/src/OpenSHC/UI/Callbacks/SliderRenderFunction.hpp b/src/OpenSHC/UI/Callbacks/SliderRenderFunction.hpp index 1af4cf7d4a..5bdcf0e98a 100644 --- a/src/OpenSHC/UI/Callbacks/SliderRenderFunction.hpp +++ b/src/OpenSHC/UI/Callbacks/SliderRenderFunction.hpp @@ -8,11 +8,14 @@ #pragma once +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { namespace UI { namespace Callbacks { - typedef void(__cdecl SliderRenderFunction)(int, int, int, int, bool); + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + typedef void(__cdecl SliderRenderFunction)(int, int, int, int, BOOLEnum); } // namespace Callbacks } // namespace UI } // namespace OpenSHC From b73aa3bcc3cebd01c8f6b6fbfe19476789d7db0e Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 10:41:40 +0100 Subject: [PATCH 03/10] reimplement: SHC_3BB0A8C1_0x004F49D0 100.0% Reimplemented MenuItem::prepareAndRenderMenuItems, from gynt's draft (ab38baae5, 59.83%, and 95757c6e9, 59.8%, in his closed #256; restyled up to 71eb42a45 on his fork's archive/UI-MenuViews-development-second-pass and in 10280b161 on reimpl/UI-Core-development), with these changes from the binary. While the build menu slides, an item outside the menu area, or any item between 45 and 55 percent of the slide, returns without being drawn (the draft only zeroed the blend strength there). The slider's clamp is written on its fields, the flag it passes is a BOOLEnum that starts FALSE next to the thumb position (the previous commit makes the callback take it), and the range is written out at each use (a local measures lower; the numbers are in the PR text). The picture's first index is main's GMFirstPictureIndex (the draft's GMTotalPicturesProcessed isn't on main), and the gmDataIndex mask is a named local. reccmp 100.0%. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../UI/MenuItem/prepareAndRenderMenuItems.cpp | 135 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp diff --git a/src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp b/src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp new file mode 100644 index 0000000000..221c40f2a6 --- /dev/null +++ b/src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp @@ -0,0 +1,135 @@ +#include "../MenuItem.func.hpp" + +#include "OpenSHC/UI/Enums/MenuItemRenderFunctionType.hpp" +#include "OpenSHC/UI/Enums/MenuItemType.hpp" + +#include "OpenSHC/Globals/DAT_ButtonBlendStrength.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonH.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_CurrentButtonPictureInGm.hpp" +#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuHandlerState.hpp" +#include "OpenSHC/Globals/DAT_UIButtonDefinedData.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F49D0 + void MenuItem::prepareAndRenderMenuItems() + { + if (this->iconDeactivatedUnk_0x36 != 0) { + return; + } + if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_GM_DATA_IMAGE) { + int const image = GMFirstPictureIndex::instance[DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[this->firstItemTypeData.gmDataIndex] + .gmId_0x0] + + DAT_UIButtonDefinedData::instance.ButtonGmDataArray[this->firstItemTypeData.gmDataIndex] + .pictureInGm_0x4 + - 1; + this->itemWidth = DAT_GMImageHeaders::instance.imh[image].width; + this->itemHeight = DAT_GMImageHeaders::instance.imh[image].height; + } + DAT_ButtonX::instance = this->menuPointer->xPosition - this->menuPointer->currentBuildMenuButtonShiftUnk_0x14 + + this->position.position.x; + DAT_ButtonY::instance = this->menuPointer->yPosition + this->position.position.y; + DAT_ButtonW::instance = this->itemWidth; + DAT_ButtonH::instance = this->itemHeight; + // the index is the low 23 bits, as MIT_MENU_ITEM_TYPE_ID_PARTUnk is of an item type + int const gmDataIndexMask = 0x7fffff; + DAT_CurrentButtonGmDataIndex::instance = this->firstItemTypeData.gmDataIndex & gmDataIndexMask; + DAT_ButtonCurrentlyInteracting::instance = (BOOLEnum)(this->clicked | this->hovering); + DAT_ButtonBlendStrength::instance = 0; + DAT_ButtonUnknownZero::instance = this->unknownZero; + if (DAT_GameCore::instance.hasMenuRenderedUnk) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + } + int const shift = this->menuPointer->currentBuildMenuButtonShiftUnk_0x14; + if (shift != 0) { + // while the build menu slides, items outside its area aren't drawn, and none are around the halfway point + if (this->position.position.x - shift < (int)DAT_MenuHandlerState::instance.const017) { + return; + } + if (this->position.position.x - shift + this->itemWidth > (int)DAT_MenuHandlerState::instance.const516) { + return; + } + int const progress = DAT_MenuHandlerState::instance.buildMenuTransitionProgress_0x38; + if (progress > 45 && progress < 55) { + return; + } + if (progress < 50) { + DAT_ButtonBlendStrength::instance = progress * 32 / 45; + } else { + DAT_ButtonBlendStrength::instance = (100 - progress) * 32 / 45; + } + } + if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_SLIDER_OR_SCROLLBAR) { + if (this->menuPointer->one) { + (*this->menuItemActionHandler.slider)(this->callbackParameter.parameter, 1, + &this->secondItemTypeData.buttonState.someTimestamp_1_0x0, + &this->secondItemTypeData.buttonState.clickTimestamp_0x4, + &this->secondItemTypeData.buttonState.countTo100); + this->secondItemTypeData.buttonState.currentButtonPictureInGm_0xc = -1000; + if (this->secondItemTypeData.buttonState.countTo100 + < this->secondItemTypeData.buttonState.someTimestamp_1_0x0) { + this->secondItemTypeData.buttonState.countTo100 + = this->secondItemTypeData.buttonState.someTimestamp_1_0x0; + } + if (this->secondItemTypeData.buttonState.countTo100 + > this->secondItemTypeData.buttonState.clickTimestamp_0x4) { + this->secondItemTypeData.buttonState.countTo100 + = this->secondItemTypeData.buttonState.clickTimestamp_0x4; + } + } + BOOLEnum isActive = FALSE; + int knobOffset = 0; + int length = this->itemWidth; + if ((this->menuItemType & OpenSHC::UI::Enums::MIT_MENU_ITEM_TYPE_ID_PARTUnk) + == OpenSHC::UI::Enums::MIT_SCROLLBARUnk) { + length = this->itemHeight; + } + int knobLength = length; + // the range is written out at each use, not kept in a local (a local: quick_diff 0.9645 -> 0.8832) + if ((this->secondItemTypeData.buttonState.clickTimestamp_0x4 + - this->secondItemTypeData.buttonState.someTimestamp_1_0x0) + > 0) { + knobLength = length + / ((this->secondItemTypeData.buttonState.clickTimestamp_0x4 + - this->secondItemTypeData.buttonState.someTimestamp_1_0x0) + + 1); + if (knobLength <= this->firstItemTypeData.itemsToSkip) { + knobLength = this->firstItemTypeData.itemsToSkip; + } + knobOffset = (this->secondItemTypeData.buttonState.countTo100 + - this->secondItemTypeData.buttonState.someTimestamp_1_0x0) + * (length - knobLength) + / (this->secondItemTypeData.buttonState.clickTimestamp_0x4 + - this->secondItemTypeData.buttonState.someTimestamp_1_0x0); + } + if (this->secondItemTypeData.buttonState.currentButtonPictureInGm_0xc > -1000) { + isActive = TRUE; + } + (*this->menuItemRenderFunction.slider)(this->callbackParameter.parameter, knobOffset, + this->secondItemTypeData.buttonState.countTo100, knobLength, isActive); + } else if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_SIMPLE_RENDERUnk) { + (*this->menuItemRenderFunction.simple)(this->callbackParameter.parameter); + } else if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_GM_DATA_IMAGE) { + (*this->menuItemRenderFunction.gmDataImage)(this->callbackParameter.parameter); + this->secondItemTypeData.buttonState.currentButtonPictureInGm_0xc = DAT_CurrentButtonPictureInGm::instance; + } + if (this->menuPointer->hoveredItem == this + && DAT_ButtonCurrentlyInteracting::instance != (this->clicked | this->hovering)) { + this->menuPointer->zero = 0; + } + this->unknownZero = DAT_ButtonUnknownZero::instance; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index fae2596738..2c9b9b1945 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38631,7 +38631,7 @@ SHC_3BB0A8C1_0x004F4270 | 0.0% | Pending SHC_3BB0A8C1_0x004F4290 | 0.0% | Pending -SHC_3BB0A8C1_0x004F49D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F49D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F4C30 | 100.0% | Reimplemented From 1befd12edb34a83dcd9ad28e0b413b5f5eee22c6 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 10:41:40 +0100 Subject: [PATCH 04/10] reimplement: SHC_3BB0A8C1_0x004F6280 100.0% Reimplemented Menu::handleMenuItems, from gynt's draft (b7ae11da1, 14.41%, the ActiveMenuTab compare, 7672ad2b5, 14.4%, and 2e7d6fdf5, 19.8%, the infinite loop fixed, in his closed #256; 20.8% in 10280b161 on his fork's reimpl/UI-Core-development), rewritten from the binary as one for-loop over the items up to MIT_LAST_ENTRY with an if/else chain on the item type. The draft's empty ifs are the returns the original has: on the current tab's stop item, on MIT_STOP_HANDLING, during a build-menu slide while handling input, while a modal dialog is open, and when an item's input callback asks to stop. The build-menu shift toggles between 0 and buildMenuItemsLeftShift_0x28, and the switch sends both render passes to prepareAndRenderMenuItems. The item types and flags MenuItemType doesn't name are local constants written as the bits they set, and the sign bit is tested with & (>= 0 measures lower; the numbers are in the PR text). reccmp 100.0%. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/Menu/handleMenuItems.cpp | 106 ++++++++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Menu/handleMenuItems.cpp diff --git a/src/OpenSHC/UI/Menu/handleMenuItems.cpp b/src/OpenSHC/UI/Menu/handleMenuItems.cpp new file mode 100644 index 0000000000..abab9f8403 --- /dev/null +++ b/src/OpenSHC/UI/Menu/handleMenuItems.cpp @@ -0,0 +1,106 @@ +#include "../Menu.func.hpp" + +#include "OpenSHC/UI/MenuItem.func.hpp" +#include "OpenSHC/UI/Enums/MenuItemHandleState.hpp" +#include "OpenSHC/UI/Enums/MenuItemType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuHandlerState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" + +namespace OpenSHC { +namespace UI { + + using namespace OpenSHC::UI::Enums; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F6280 + void Menu::handleMenuItems(MenuItemHandleState funcIndex) + { + // item types without a name yet: two kinds of option group, and flags in the high bits + int const optionGroupType = MIT_START_OF_INTERACTION_GROUPUnk | 1 << 29; + int const optionType = MIT_START_OF_INTERACTION_GROUPUnk | 1 << 28; + int const clickHandlerType = 7; + int const alternativeFlag = 1 << 26; + int const alternativesFlag = 1 << 27; + int const renderSeparatelyFlag = 1 << 23; + this->currentBuildMenuButtonShiftUnk_0x14 = 0; + for (MenuItem* item = this->menuItemArray; item->menuItemType != MIT_LAST_ENTRY; ++item) { + MenuItemTypeInt const type = item->menuItemType; + if (type == MIT_TAB_CONSIDER_ITEM_SKIP_BECAUSE_OTHER_MENU_TAB) { + if (item->callbackParameter.activeMenuTab.tabType != DAT_GameCore::instance.activeMenuTab.tabType + && funcIndex != MIHS_RESET_MENU_ITEM_STATEUnk) { + item += item->firstItemTypeData.itemsToSkip; + } + } else if (type == MIT_TAB_CONSIDER_STOP_BECAUSE_IS_CURRENT_MENU_TAB) { + if (item->callbackParameter.activeMenuTab.tabType == DAT_GameCore::instance.activeMenuTab.tabType + && funcIndex != MIHS_RESET_MENU_ITEM_STATEUnk) { + return; + } + } else if (type == MIT_STOP_HANDLING) { + return; + } else if (type == MIT_ENABLE_OR_WRAP_BUILD_MENU_TRANSITION_OFFSET) { + if (DAT_MenuHandlerState::instance.isBuildMenuTransitioning_0x18 + && funcIndex == MIHS_HANDLE_INPUT_CALLBACKSUnk) { + return; + } + if (this->currentBuildMenuButtonShiftUnk_0x14 != 0) { + this->currentBuildMenuButtonShiftUnk_0x14 = 0; + } else { + this->currentBuildMenuButtonShiftUnk_0x14 + = DAT_MenuHandlerState::instance.buildMenuItemsLeftShift_0x28; + } + } else if (type == MIT_MENU_MODALUnk) { + if (DAT_MenuModalComposition1::instance.activeModalDialogID != MMT_NONE) { + return; + } + } else if (type == optionGroupType) { + for (MenuItem* option = item + item->firstItemTypeData.itemsToSkip + 1; + option->menuItemType == optionType; option += option->firstItemTypeData.itemsToSkip + 1) { + if (option->testNotEqualZero == DAT_GameCore::instance.unknownAlwaysZero01) { + item = option; + break; + } + } + } else if (type == optionType) { + item += item->firstItemTypeData.itemsToSkip; + } else if (type == clickHandlerType) { + DAT_GameCore::instance.menuType7_MenuItemClickHandlerUnk + = (MenuItemActionHandler*)item->menuItemActionHandler.simple; + } else if (type != MIT_START_OF_INTERACTION_GROUPUnk && (type & alternativeFlag) == 0) { + if (type & alternativesFlag) { + for (MenuItem* option = item + 1; option->menuItemType & alternativeFlag; ++option) { + if (option->testNotEqualZero == DAT_GameCore::instance.unknownAlwaysZero01) { + item = option; + break; + } + } + } + // the sign bit tested, not >= 0 (>= 0: quick_diff 0.9191 -> 0.9118) + if ((item->menuItemType & 1 << 31) == 0) { + if ((item->menuItemType & renderSeparatelyFlag) != 0 + && funcIndex == MIHS_PREPARE_AND_RENDER_FOR_FLAG_0X800000 + || (item->menuItemType & renderSeparatelyFlag) == 0 && funcIndex == MIHS_PREPARE_AND_RENDER + || funcIndex == MIHS_HANDLE_INPUT_CALLBACKSUnk || funcIndex == MIHS_RESET_MENU_ITEM_STATEUnk) { + switch (funcIndex) { + case MIHS_HANDLE_INPUT_CALLBACKSUnk: + if (MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::handleMenuElementsCallbacks, item)()) { + return; + } + break; + case MIHS_PREPARE_AND_RENDER: + case MIHS_PREPARE_AND_RENDER_FOR_FLAG_0X800000: + MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::prepareAndRenderMenuItems, item)(); + break; + case MIHS_RESET_MENU_ITEM_STATEUnk: + MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::resetMenuItemStateUnk, item)(); + break; + } + } + } + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2c9b9b1945..2a27ca9405 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38685,7 +38685,7 @@ SHC_3BB0A8C1_0x004F6200 | 0.0% | Pending SHC_3BB0A8C1_0x004F6210 | 0.0% | Pending -SHC_3BB0A8C1_0x004F6280 | 0.0% | Pending +SHC_3BB0A8C1_0x004F6280 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F641D | 0.0% | Pending From 925e2dfb99af44cd1b02caa1152a4c82e5ee0f3c Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 10:41:40 +0100 Subject: [PATCH 05/10] reimplement: SHC_3BB0A8C1_0x004F4100 100.0% Reimplemented Menu::Constructor_Menu, from gynt's draft (8a20e1154, 21.49%, and b357877a0, 21.5%, in his closed #256; restyled up to 71eb42a45 on his fork's archive/UI-MenuViews-development-second-pass and in 10280b161 on reimpl/UI-Core-development), rewritten from the binary as one for-loop over the items: each item gets its menu pointer, its UC index (or -1) and a cleared unknownZero; a tab counts its items up to the next tab, the end or past a stop item; an interaction group hands its callbacks to members that have none, then does the same for each option that follows it and marks itself an option group; and the item before a run of alternatives is flagged as its head. The draft walked the items through a pointer offset by the position field (+4), reached ucIndex_0x4 through a cast, and counted the members with GmDataIndex values; the counts are ints in itemsToSkip here. The flags MenuItemType doesn't name are local constants written as the bits they set, as in handleMenuItems (0x004F6280, previous commit). reccmp 100.0%. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/Menu/Constructor_Menu.cpp | 94 ++++++++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Menu/Constructor_Menu.cpp diff --git a/src/OpenSHC/UI/Menu/Constructor_Menu.cpp b/src/OpenSHC/UI/Menu/Constructor_Menu.cpp new file mode 100644 index 0000000000..4e45bb03e0 --- /dev/null +++ b/src/OpenSHC/UI/Menu/Constructor_Menu.cpp @@ -0,0 +1,94 @@ +#include "../Menu.func.hpp" + +#include "OpenSHC/UI/Enums/MenuItemType.hpp" +#include "OpenSHC/UI/Enums/MenuItemUCMarker.hpp" +#include "OpenSHC/UI/Enums/UserControlID.hpp" + +namespace OpenSHC { +namespace UI { + + using namespace OpenSHC::UI::Enums; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F4100 + Menu* Menu::Constructor_Menu(MenuItem* menuItemArrayAddress) + { + // item types and flags without a name yet, as in handleMenuItems + int const optionGroupFlag = 1 << 29; + int const optionType = MIT_START_OF_INTERACTION_GROUPUnk | 1 << 28; + int const alternativeFlag = 1 << 26; + int const alternativesFlag = 1 << 27; + this->menuItemArray = menuItemArrayAddress; + this->xPosition = 0; + this->yPosition = 0; + this->thousand = 1000; + this->zero = 0; + this->someTimestampUnk = 0; + this->mouseXScreenSpace = -1000; + for (MenuItem* item = menuItemArrayAddress; item->menuItemType != MIT_LAST_ENTRY; ++item) { + item->menuPointer = this; + if (item->position.ucInfo.ucMarker_0x0 == USE_UC_COORDS) { + item->ucID = item->position.ucInfo.ucIndex_0x4; + } else { + item->ucID = -1; + } + item->unknownZero = 0; + if (item->menuItemType == MIT_TAB_CONSIDER_ITEM_SKIP_BECAUSE_OTHER_MENU_TAB) { + // a tab's items reach up to the next tab, the end, or past a stop item + int count = 0; + MenuItem* next; + for (next = item + 1; next->menuItemType != MIT_LAST_ENTRY + && next->menuItemType != MIT_TAB_CONSIDER_ITEM_SKIP_BECAUSE_OTHER_MENU_TAB + && next->menuItemType != MIT_STOP_HANDLING; + ++next) { + ++count; + } + if (next->menuItemType == MIT_STOP_HANDLING) { + ++count; + } + item->firstItemTypeData.itemsToSkip = count; + } else if (item->menuItemType == MIT_START_OF_INTERACTION_GROUPUnk) { + // the group's members take the group's callbacks where they have none + MenuItemActionHandlerUnion actionHandler = item->menuItemActionHandler; + MenuItemRenderFunctionUnion renderFunction = item->menuItemRenderFunction; + MenuItem* member = item + 1; + int count = 0; + for (; member->menuItemType & MIT_PART_OF_INTERACTION_GROUPUnk; ++member) { + if (member->menuItemActionHandler.simple == NULL) { + member->menuItemActionHandler = actionHandler; + } + if (member->menuItemRenderFunction.simple == NULL) { + member->menuItemRenderFunction = renderFunction; + } + ++count; + } + item->firstItemTypeData.itemsToSkip = count; + // options follow, each with members of its own + while (member->menuItemType == optionType) { + item->menuItemType |= optionGroupFlag; + actionHandler = member->menuItemActionHandler; + renderFunction = member->menuItemRenderFunction; + MenuItem* const option = member; + count = 0; + for (++member; member->menuItemType & MIT_PART_OF_INTERACTION_GROUPUnk; ++member) { + if (member->menuItemActionHandler.simple == NULL) { + member->menuItemActionHandler = actionHandler; + } + if (member->menuItemRenderFunction.simple == NULL) { + member->menuItemRenderFunction = renderFunction; + } + ++count; + } + option->firstItemTypeData.itemsToSkip = count; + } + } else if (item->menuItemType & alternativeFlag) { + // the first of a run of alternatives is marked + MenuItem* first; + for (first = item; first->menuItemType & alternativeFlag && first != menuItemArrayAddress; --first) {} + first->menuItemType |= alternativesFlag; + } + } + return this; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2a27ca9405..c001b35ea8 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38621,7 +38621,7 @@ SHC_3BB0A8C1_0x004F4050 | 0.0% | Pending SHC_3BB0A8C1_0x004F4070 | 0.0% | Pending -SHC_3BB0A8C1_0x004F4100 | 0.0% | Pending +SHC_3BB0A8C1_0x004F4100 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F4140 | 0.0% | Pending From 3275d3899b4a9d20d09305624f43abf78a51b154 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 10:41:40 +0100 Subject: [PATCH 06/10] reimplement: SHC_3BB0A8C1_0x004F64A0 100.0% Reimplemented Menu::renderConstructionMenu, from gynt's draft (65e90216a, 63.31%, and 1791e0a55, 62.7%, in his closed #256; 64.0% in 10280b161 on his fork's reimpl/UI-Core-development, names in 7069ca96f), rewritten from the binary. The hovered item's text index is looked up in TextMessageLookupTable, and the message type is one switch: 0 returns, twelve types show the text bottom-left with setBottomLeftTextDisplayText (most of them only with bubble help on) and each clears zero and returns on its own, as the original does (with a break to one shared store: quick_diff 0.9559 -> 0.8475, as 0 no longer gets a register), and every other type shows the tooltip once the mouse has rested on the item for 200 ms. The index is the dword's low word, read whole and masked as handleMenuElementsCallbacks does on gynt's branch (*(int*)&this->textMessageLookupIndex); the ushort field_0x0 loads a word (the numbers are in the PR text). Tab, view and message types are main's enum names where it has them (types 7 to 13 have none), and the tooltip's colour is COL_C2F0EB. reccmp 100.0%. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../UI/Menu/renderConstructionMenu.cpp | 267 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Menu/renderConstructionMenu.cpp diff --git a/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp b/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp new file mode 100644 index 0000000000..7d2a03f96f --- /dev/null +++ b/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp @@ -0,0 +1,267 @@ +#include "../Menu.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/COL_GREYISH_YELLOW.hpp" +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + + using namespace OpenSHC::UI::Enums; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F64A0 + void Menu::renderConstructionMenu() + { + DWORD const now = timeGetTime(); + MenuItem* const item = this->hoveredItem; + // the text's index is the low word of textMessageLookupIndex, read as a dword and masked + // (the ushort field_0x0: quick_diff 0.9559 -> 0.9227) + int const indexMask = 0xffff; + if (item != NULL && (*(int*)&item->textMessageLookupIndex & indexMask) != 0) { + // in the building menus, only these tabs show texts + if (DAT_GameCore::instance.currentMenuViewType != MVT_BUILDING_AND_STATUS_MENU + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_BARRACKS_OR_MPMENU_MODEM + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_MERCENARYPOST + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_TOWER + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_GATEHOUSE + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_ENGINEERSGUILD + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_TUNNELERSGUILD + || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_CATHEDRAL) { + int const index = *(int*)&item->textMessageLookupIndex & indexMask; + switch (DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].messageType) { + case 0: + return; + case TMBLLSTE_BUTTON_TEXT: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case 13: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(13, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case 7: + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(7, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].associatedType.buildingType, + 50, -1); + this->zero = 0; + return; + case TMBLLSTE_BUILDING_TEXT: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(2, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_WALL_TEXT: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(4, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case 9: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(9, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_POPULARITY_HELP_TEXT: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(3, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case TMBLLSTE_UNITS_AND_WEAPONS_TEXT: + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(6, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].associatedType.buildingType, + 50, -1); + this->zero = 0; + return; + case 12: + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(12, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].associatedType.buildingType, + 50, -1); + this->zero = 0; + return; + case 8: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(8, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case 10: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(10, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + case 11: + if (DAT_GameCore::instance.settingBubbleHelp) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(11, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.buildingType, + 50, -1); + } + this->zero = 0; + return; + default: + // the tooltip, once the mouse has rested on the item for 200 ms + if (DAT_MouseState::instance.leftClickState || DAT_MouseState::instance.rightClickState + || DAT_MouseState::instance.midClickState || !DAT_GameCore::instance.settingBubbleHelp) { + break; + } + if (this->zero == 0) { + this->zero = 1; + this->someTimestampUnk = now; + this->mouseXScreenSpace = DAT_MouseState::instance.screenSpaceX; + this->mouseYScreenSpace = DAT_MouseState::instance.screenSpaceY; + return; + } + if (this->zero == 1 && DAT_MouseState::instance.screenSpaceX == this->mouseXScreenSpace + && DAT_MouseState::instance.screenSpaceY == this->mouseYScreenSpace) { + if ((int)(now - this->someTimestampUnk) <= 200) { + return; + } + this->zero = 2; + this->textIndexInGroup + = DAT_RenderingDefinedData::instance + .TextMessageLookupTable[(*(int*)&item->textMessageLookupIndex & indexMask)] + .textIndexInGroup; + this->textGroupIndex + = DAT_RenderingDefinedData::instance + .TextMessageLookupTable[(*(int*)&item->textMessageLookupIndex & indexMask)] + .textGroupIndex; + // "Resume Game" while the game is paused + if (this->textIndexInGroup == 302 && this->textGroupIndex == 8 + && DAT_GameCore::instance.gameSuspended == 1) { + this->textGroupIndex = 74; + this->textIndexInGroup = 10; + } + this->someMenuItemPtr_0x3c = item; + return; + } + if (this->zero == 2 && this->someMenuItemPtr_0x3c == item) { + char* const text = MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)( + (OpenSHC::DE::SHCDE::eTextSections)this->textGroupIndex, this->textIndexInGroup); + int const width = MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::computeTextWidth, DAT_TextManagerObject::ptr)(text, 17); + if (DAT_GameCore::instance.currentMenuViewType != MVT_MISSION_FINISHED_TRANSITION + && DAT_GameCore::instance.currentMenuViewType != MVT_GAME_LOSTUnk) { + this->hoverTextX = DAT_MouseState::instance.screenSpaceX - width / 2 + 8; + this->hoverTextY = DAT_MouseState::instance.screenSpaceY - 68; + } else { + this->hoverTextX = DAT_MouseState::instance.screenSpaceX - width / 2 + 8; + this->hoverTextY = DAT_MouseState::instance.screenSpaceY + 16; + } + if (this->hoverTextY + 23 > DAT_WindowAndDirectDraw::instance.resolutionY) { + this->hoverTextY = DAT_MouseState::instance.screenSpaceY - 23; + } + if (this->hoverTextX + width + 20 > DAT_WindowAndDirectDraw::instance.resolutionX) { + this->hoverTextX = DAT_WindowAndDirectDraw::instance.resolutionX - width - 20; + } + if (this->hoverTextX < 0) { + this->hoverTextX = 0; + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::dimBox, DAT_PencilRenderCore::ptr)( + this->hoverTextX, this->hoverTextY, this->hoverTextX + width + 18, this->hoverTextY + 26); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBorderBox, + DAT_PencilRenderCore::ptr)(this->hoverTextX - 1, this->hoverTextY - 1, + this->hoverTextX + width + 19, this->hoverTextY + 27, + COL_GREYISH_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, + DAT_TextManagerObject::ptr)(text, this->hoverTextX + 11, this->hoverTextY + 3, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 17, FALSE, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + break; + } + } + } + this->zero = 0; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c001b35ea8..08fd667a1d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38699,7 +38699,7 @@ SHC_3BB0A8C1_0x004F6464 | 0.0% | Pending SHC_3BB0A8C1_0x004F6470 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F64A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F64A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F6998 | 0.0% | Pending From e94e6ea726a1ff3c3154817739bf74a4830bb46b Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 18:13:09 +0100 Subject: [PATCH 07/10] header: TextMessageBLLookupStructTypeEnum gets TMBLLSTE_UNKNOWN_0 and 7 to 13 Menu::renderConstructionMenu (0x004F64A0) switches on TextMessageLookupTable[index].messageType with cases for 0 (it returns at once) and for 7 to 13 besides the five named types, and matches at reccmp 100.0 with them; each of the cases for 7 to 13 passes its own number on to setBottomLeftTextDisplayText as its message type. The enum has no names for them, so they get _UNKNOWN_ (TheRedDaemon's ask on #300); setBottomLeftTextDisplayText starts its lookup type at 0. Used in the next commits; code generation is the same. Co-Authored-By: Claude Opus 5.5 --- .../UI/Enums/TextMessageBLLookupStructTypeEnum.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/OpenSHC/UI/Enums/TextMessageBLLookupStructTypeEnum.hpp b/src/OpenSHC/UI/Enums/TextMessageBLLookupStructTypeEnum.hpp index 161f996727..db25730fee 100644 --- a/src/OpenSHC/UI/Enums/TextMessageBLLookupStructTypeEnum.hpp +++ b/src/OpenSHC/UI/Enums/TextMessageBLLookupStructTypeEnum.hpp @@ -13,11 +13,19 @@ namespace UI { namespace Enums { typedef enum TextMessageBLLookupStructTypeEnum { + TMBLLSTE_UNKNOWN_0 = 0, // 0x00000000 TMBLLSTE_BUTTON_TEXT = 2, // 0x00000002 TMBLLSTE_BUILDING_TEXT = 3, // 0x00000003 TMBLLSTE_POPULARITY_HELP_TEXT = 4, // 0x00000004 TMBLLSTE_WALL_TEXT = 5, // 0x00000005 - TMBLLSTE_UNITS_AND_WEAPONS_TEXT = 6 // 0x00000006 + TMBLLSTE_UNITS_AND_WEAPONS_TEXT = 6, // 0x00000006 + TMBLLSTE_UNKNOWN_7 = 7, // 0x00000007 + TMBLLSTE_UNKNOWN_8 = 8, // 0x00000008 + TMBLLSTE_UNKNOWN_9 = 9, // 0x00000009 + TMBLLSTE_UNKNOWN_10 = 10, // 0x0000000A + TMBLLSTE_UNKNOWN_11 = 11, // 0x0000000B + TMBLLSTE_UNKNOWN_12 = 12, // 0x0000000C + TMBLLSTE_UNKNOWN_13 = 13 // 0x0000000D } TextMessageBLLookupStructTypeEnum; From 28ded95db424a8f267650d452fa3fa722594c420 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 18:13:09 +0100 Subject: [PATCH 08/10] header: setBottomLeftTextDisplayText's fourth parameter is associatedTypeUnk BottomLeftTextDisplayState::setBottomLeftTextDisplayText (0x004F4E00) compares its fourth parameter with TextMessageLookupTable[i].associatedType.buildingType and stores it in currentlyDisplayedUnktextExtraObject, so it is the associated type of the text (a building, button or unit type, after TextMessageBLLookupStruct's union); param_4 becomes associatedTypeUnk, as the definition calls it from the next commit on. Only the name changes. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/BottomLeftTextDisplayState.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/BottomLeftTextDisplayState.hpp b/src/OpenSHC/UI/BottomLeftTextDisplayState.hpp index 136c3729b9..d6847a3ba9 100644 --- a/src/OpenSHC/UI/BottomLeftTextDisplayState.hpp +++ b/src/OpenSHC/UI/BottomLeftTextDisplayState.hpp @@ -38,8 +38,8 @@ namespace UI { BottomLeftTextDisplayState() {}; ~BottomLeftTextDisplayState() {}; - void setBottomLeftTextDisplayText(int messageTypeUnk, int textGroupIndex, int textNumInGroup, int param_4, - int importanceUnk, int displayDurationUnk); + void setBottomLeftTextDisplayText(int messageTypeUnk, int textGroupIndex, int textNumInGroup, + int associatedTypeUnk, int importanceUnk, int displayDurationUnk); void hasPassedCountdownOrDuration(); From def0b9995a43a4c5053d5661f20ab250690da9b3 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 18:13:09 +0100 Subject: [PATCH 09/10] UI menu functions: main's slider-state and enum names, flatter handleMenuItems - prepareAndRenderMenuItems' slider branch reads secondItemTypeData.scrollbarOrSliderState (minValue, maxValue, currentValue, dragTiming), main's names for the same four ints, where it read them through buttonState; the GM image line stays on buttonState. isDragged/thumbPos/thumbLength after main's render-function parameters, the set-up call's 1 commented, no (BOOLEnum) cast on clicked | hovering. - renderConstructionMenu: TMBLLSTE_UNKNOWN_0 and 7 to 13 (previous commits) for the case labels, the union's buttonText and unitsAndWeaponsType for those two cases, TEXT_BUBBLE_HELP_TEXT and TEXT_GAME_OPTIONS for 8 and 74, and one line above the switch on why each case stores and returns. - handleMenuItems: the sign bit as hiddenFlag, `continue` for hidden items and for items that aren't handled now (one level of nesting instead of three), parentheses around each && pair, no cast on the click handler, and `alternative` for the loop over alternatives. - Constructor_Menu: the item before a run of alternatives is marked as its head (the old comment had it the other way round), and the unused UserControlID include goes. - setBottomLeftTextDisplayText: associatedTypeUnk (previous commit), TEXT_PANEL_FEEDBACK and BFRE_NOT_ENOUGH_WORKERS for 77 and 1, TMBLLSTE_UNKNOWN_0, and MappersEnum's include and using go (they come with TextMessageBLLookupStructUnion.hpp). - The comments keep only the reasons; the quick_diff numbers go to the PR text. Kept, measured (quick_diff): renderConstructionMenu's second masking of the index and its two hoverTextX stores (reusing index and one store: 0.9559 -> 0.8393 together; each alone in the next commit), Constructor_Menu's while over the options (a for: 0.8787 -> 0.6025), prepareAndRenderMenuItems' isDragged declared early (at its use: 0.9645 -> 0.7980), each with a line in the code. Everything else is quick_diff-identical, and all five functions are reccmp 100.0 in a full build. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../setBottomLeftTextDisplayText.cpp | 20 +++--- src/OpenSHC/UI/Menu/Constructor_Menu.cpp | 11 ++- src/OpenSHC/UI/Menu/handleMenuItems.cpp | 52 +++++++------- .../UI/Menu/renderConstructionMenu.cpp | 34 +++++---- .../UI/MenuItem/prepareAndRenderMenuItems.cpp | 70 ++++++++++--------- 5 files changed, 97 insertions(+), 90 deletions(-) diff --git a/src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp b/src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp index 38a0ee2436..da9dc92ec4 100644 --- a/src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp +++ b/src/OpenSHC/UI/BottomLeftTextDisplayState/setBottomLeftTextDisplayText.cpp @@ -1,7 +1,8 @@ #include "../BottomLeftTextDisplayState.func.hpp" #include "OpenSHC/Audio/SFX/SFXState.func.hpp" -#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/Buildings/BuildingFailReasonEnum.hpp" #include "OpenSHC/UI/Enums/TextMessageBLLookupStructTypeEnum.hpp" #include "OpenSHC/string-literals.hpp" @@ -11,11 +12,9 @@ namespace OpenSHC { namespace UI { - using OpenSHC::Commands::MappersEnum; - // FUNCTION: STRONGHOLDCRUSADER 0x004F4E00 void BottomLeftTextDisplayState::setBottomLeftTextDisplayText(int messageTypeUnk, int textGroupIndex, - int textNumInGroup, int param_4, int importanceUnk, int displayDurationUnk) + int textNumInGroup, int associatedTypeUnk, int importanceUnk, int displayDurationUnk) { if (messageTypeUnk == 0) { this->currentlyDisplayedTextIsDisplayedUnk = 0; @@ -28,7 +27,7 @@ namespace UI { } if (textGroupIndex != this->currentlyDisplayedUnkTextGroupIndex_0x4 || textNumInGroup != this->currentlyDisplayedUnkTextNumInGroup_0x8 - || param_4 != this->currentlyDisplayedUnktextExtraObject.buildingType) { + || associatedTypeUnk != this->currentlyDisplayedUnktextExtraObject.buildingType) { this->countdown = 0; } } else { @@ -37,15 +36,15 @@ namespace UI { this->currentlyDisplayedTextIsDisplayedUnk = messageTypeUnk; if (textGroupIndex == -1) { // the text is looked up by the type of message and the object it is about - // the index is set before the type, not in the for (in the for: quick_diff 0.9884 -> 0.9767) + // the index is declared before messageType: in the for it loses the match int i = 0; - TextMessageBLLookupStructTypeEnumInt messageType = 0; + TextMessageBLLookupStructTypeEnumInt messageType = OpenSHC::UI::Enums::TMBLLSTE_UNKNOWN_0; if (messageTypeUnk == 2) { messageType = OpenSHC::UI::Enums::TMBLLSTE_BUILDING_TEXT; } for (; DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].messageType != -1; ++i) { if (messageType == DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].messageType - && param_4 + && associatedTypeUnk == DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].associatedType.buildingType) { this->currentlyDisplayedUnkTextGroupIndex_0x4 = DAT_RenderingDefinedData::instance.TextMessageLookupTable[i].textGroupIndex; @@ -58,13 +57,14 @@ namespace UI { this->currentlyDisplayedUnkTextGroupIndex_0x4 = textGroupIndex; this->currentlyDisplayedUnkTextNumInGroup_0x8 = textNumInGroup; // "Not enough workers available to run this building." - if (messageTypeUnk == 1 && textGroupIndex == 77 && textNumInGroup == 1) { + if (messageTypeUnk == 1 && textGroupIndex == OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK + && textNumInGroup == OpenSHC::Map::Buildings::BFRE_NOT_ENOUGH_WORKERS) { // "placement_warning1.wav" MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( s_placement_warning1_wav_005ab8f4); } } - this->currentlyDisplayedUnktextExtraObject.buildingType = (MappersEnum)param_4; + this->currentlyDisplayedUnktextExtraObject.buildingType = (MappersEnum)associatedTypeUnk; this->currentlyDisplayedTextImportanceUnk = importanceUnk; if (displayDurationUnk != -1) { this->textMessageDurationUnk = displayDurationUnk; diff --git a/src/OpenSHC/UI/Menu/Constructor_Menu.cpp b/src/OpenSHC/UI/Menu/Constructor_Menu.cpp index 4e45bb03e0..9d30ec925b 100644 --- a/src/OpenSHC/UI/Menu/Constructor_Menu.cpp +++ b/src/OpenSHC/UI/Menu/Constructor_Menu.cpp @@ -2,7 +2,6 @@ #include "OpenSHC/UI/Enums/MenuItemType.hpp" #include "OpenSHC/UI/Enums/MenuItemUCMarker.hpp" -#include "OpenSHC/UI/Enums/UserControlID.hpp" namespace OpenSHC { namespace UI { @@ -62,7 +61,7 @@ namespace UI { ++count; } item->firstItemTypeData.itemsToSkip = count; - // options follow, each with members of its own + // options follow, each with members of its own (a while: a for over the options loses the match) while (member->menuItemType == optionType) { item->menuItemType |= optionGroupFlag; actionHandler = member->menuItemActionHandler; @@ -81,10 +80,10 @@ namespace UI { option->firstItemTypeData.itemsToSkip = count; } } else if (item->menuItemType & alternativeFlag) { - // the first of a run of alternatives is marked - MenuItem* first; - for (first = item; first->menuItemType & alternativeFlag && first != menuItemArrayAddress; --first) {} - first->menuItemType |= alternativesFlag; + // the item before a run of alternatives is marked as its head + MenuItem* head; + for (head = item; head->menuItemType & alternativeFlag && head != menuItemArrayAddress; --head) {} + head->menuItemType |= alternativesFlag; } } return this; diff --git a/src/OpenSHC/UI/Menu/handleMenuItems.cpp b/src/OpenSHC/UI/Menu/handleMenuItems.cpp index abab9f8403..6cd9e8c3f5 100644 --- a/src/OpenSHC/UI/Menu/handleMenuItems.cpp +++ b/src/OpenSHC/UI/Menu/handleMenuItems.cpp @@ -24,6 +24,7 @@ namespace UI { int const alternativeFlag = 1 << 26; int const alternativesFlag = 1 << 27; int const renderSeparatelyFlag = 1 << 23; + int const hiddenFlag = 1 << 31; this->currentBuildMenuButtonShiftUnk_0x14 = 0; for (MenuItem* item = this->menuItemArray; item->menuItemType != MIT_LAST_ENTRY; ++item) { MenuItemTypeInt const type = item->menuItemType; @@ -65,38 +66,39 @@ namespace UI { } else if (type == optionType) { item += item->firstItemTypeData.itemsToSkip; } else if (type == clickHandlerType) { - DAT_GameCore::instance.menuType7_MenuItemClickHandlerUnk - = (MenuItemActionHandler*)item->menuItemActionHandler.simple; + DAT_GameCore::instance.menuType7_MenuItemClickHandlerUnk = item->menuItemActionHandler.simple; } else if (type != MIT_START_OF_INTERACTION_GROUPUnk && (type & alternativeFlag) == 0) { if (type & alternativesFlag) { - for (MenuItem* option = item + 1; option->menuItemType & alternativeFlag; ++option) { - if (option->testNotEqualZero == DAT_GameCore::instance.unknownAlwaysZero01) { - item = option; + for (MenuItem* alternative = item + 1; alternative->menuItemType & alternativeFlag; ++alternative) { + if (alternative->testNotEqualZero == DAT_GameCore::instance.unknownAlwaysZero01) { + item = alternative; break; } } } - // the sign bit tested, not >= 0 (>= 0: quick_diff 0.9191 -> 0.9118) - if ((item->menuItemType & 1 << 31) == 0) { - if ((item->menuItemType & renderSeparatelyFlag) != 0 - && funcIndex == MIHS_PREPARE_AND_RENDER_FOR_FLAG_0X800000 - || (item->menuItemType & renderSeparatelyFlag) == 0 && funcIndex == MIHS_PREPARE_AND_RENDER - || funcIndex == MIHS_HANDLE_INPUT_CALLBACKSUnk || funcIndex == MIHS_RESET_MENU_ITEM_STATEUnk) { - switch (funcIndex) { - case MIHS_HANDLE_INPUT_CALLBACKSUnk: - if (MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::handleMenuElementsCallbacks, item)()) { - return; - } - break; - case MIHS_PREPARE_AND_RENDER: - case MIHS_PREPARE_AND_RENDER_FOR_FLAG_0X800000: - MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::prepareAndRenderMenuItems, item)(); - break; - case MIHS_RESET_MENU_ITEM_STATEUnk: - MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::resetMenuItemStateUnk, item)(); - break; - } + // the sign bit is tested with &, not as >= 0, as the original does + if (item->menuItemType & hiddenFlag) { + continue; + } + if (!(((item->menuItemType & renderSeparatelyFlag) != 0 + && funcIndex == MIHS_PREPARE_AND_RENDER_FOR_FLAG_0X800000) + || ((item->menuItemType & renderSeparatelyFlag) == 0 && funcIndex == MIHS_PREPARE_AND_RENDER) + || funcIndex == MIHS_HANDLE_INPUT_CALLBACKSUnk || funcIndex == MIHS_RESET_MENU_ITEM_STATEUnk)) { + continue; + } + switch (funcIndex) { + case MIHS_HANDLE_INPUT_CALLBACKSUnk: + if (MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::handleMenuElementsCallbacks, item)()) { + return; } + break; + case MIHS_PREPARE_AND_RENDER: + case MIHS_PREPARE_AND_RENDER_FOR_FLAG_0X800000: + MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::prepareAndRenderMenuItems, item)(); + break; + case MIHS_RESET_MENU_ITEM_STATEUnk: + MACRO_CALL_MEMBER(OpenSHC::UI::MenuItem_Func::resetMenuItemStateUnk, item)(); + break; } } } diff --git a/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp b/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp index 7d2a03f96f..edf8d3a678 100644 --- a/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp +++ b/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp @@ -29,8 +29,7 @@ namespace UI { { DWORD const now = timeGetTime(); MenuItem* const item = this->hoveredItem; - // the text's index is the low word of textMessageLookupIndex, read as a dword and masked - // (the ushort field_0x0: quick_diff 0.9559 -> 0.9227) + // the text's index is the low word of textMessageLookupIndex, read as a dword and masked, as the original does int const indexMask = 0xffff; if (item != NULL && (*(int*)&item->textMessageLookupIndex & indexMask) != 0) { // in the building menus, only these tabs show texts @@ -43,8 +42,9 @@ namespace UI { || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_TUNNELERSGUILD || DAT_GameCore::instance.activeMenuTab.tabType == BASMTT_CATHEDRAL) { int const index = *(int*)&item->textMessageLookupIndex & indexMask; + // each case stores and returns on its own: a shared store after a break loses the match switch (DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].messageType) { - case 0: + case TMBLLSTE_UNKNOWN_0: return; case TMBLLSTE_BUTTON_TEXT: if (DAT_GameCore::instance.settingBubbleHelp) { @@ -52,13 +52,12 @@ namespace UI { DAT_BottomLeftTextDisplayState::ptr)(1, DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, - DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] - .associatedType.buildingType, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].associatedType.buttonText, 50, -1); } this->zero = 0; return; - case 13: + case TMBLLSTE_UNKNOWN_13: if (DAT_GameCore::instance.settingBubbleHelp) { MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, DAT_BottomLeftTextDisplayState::ptr)(13, @@ -70,7 +69,7 @@ namespace UI { } this->zero = 0; return; - case 7: + case TMBLLSTE_UNKNOWN_7: MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, DAT_BottomLeftTextDisplayState::ptr)(7, DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, @@ -103,7 +102,7 @@ namespace UI { } this->zero = 0; return; - case 9: + case TMBLLSTE_UNKNOWN_9: if (DAT_GameCore::instance.settingBubbleHelp) { MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, DAT_BottomLeftTextDisplayState::ptr)(9, @@ -132,11 +131,12 @@ namespace UI { DAT_BottomLeftTextDisplayState::ptr)(6, DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textIndexInGroup, - DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].associatedType.buildingType, + DAT_RenderingDefinedData::instance.TextMessageLookupTable[index] + .associatedType.unitsAndWeaponsType, 50, -1); this->zero = 0; return; - case 12: + case TMBLLSTE_UNKNOWN_12: MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, DAT_BottomLeftTextDisplayState::ptr)(12, DAT_RenderingDefinedData::instance.TextMessageLookupTable[index].textGroupIndex, @@ -145,7 +145,7 @@ namespace UI { 50, -1); this->zero = 0; return; - case 8: + case TMBLLSTE_UNKNOWN_8: if (DAT_GameCore::instance.settingBubbleHelp) { MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, DAT_BottomLeftTextDisplayState::ptr)(8, @@ -157,7 +157,7 @@ namespace UI { } this->zero = 0; return; - case 10: + case TMBLLSTE_UNKNOWN_10: if (DAT_GameCore::instance.settingBubbleHelp) { MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, DAT_BottomLeftTextDisplayState::ptr)(10, @@ -169,7 +169,7 @@ namespace UI { } this->zero = 0; return; - case 11: + case TMBLLSTE_UNKNOWN_11: if (DAT_GameCore::instance.settingBubbleHelp) { MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, DAT_BottomLeftTextDisplayState::ptr)(11, @@ -200,6 +200,7 @@ namespace UI { return; } this->zero = 2; + // the index is masked again for these two, as the original does: reusing index loses the match this->textIndexInGroup = DAT_RenderingDefinedData::instance .TextMessageLookupTable[(*(int*)&item->textMessageLookupIndex & indexMask)] @@ -209,9 +210,10 @@ namespace UI { .TextMessageLookupTable[(*(int*)&item->textMessageLookupIndex & indexMask)] .textGroupIndex; // "Resume Game" while the game is paused - if (this->textIndexInGroup == 302 && this->textGroupIndex == 8 + if (this->textIndexInGroup == 302 + && this->textGroupIndex == OpenSHC::DE::SHCDE::TEXT_BUBBLE_HELP_TEXT && DAT_GameCore::instance.gameSuspended == 1) { - this->textGroupIndex = 74; + this->textGroupIndex = OpenSHC::DE::SHCDE::TEXT_GAME_OPTIONS; this->textIndexInGroup = 10; } this->someMenuItemPtr_0x3c = item; @@ -223,6 +225,8 @@ namespace UI { (OpenSHC::DE::SHCDE::eTextSections)this->textGroupIndex, this->textIndexInGroup); int const width = MACRO_CALL_MEMBER( OpenSHC::Text::TextManager_Func::computeTextWidth, DAT_TextManagerObject::ptr)(text, 17); + // hoverTextX is set in both branches, as the original does: one store before the test loses the + // match if (DAT_GameCore::instance.currentMenuViewType != MVT_MISSION_FINISHED_TRANSITION && DAT_GameCore::instance.currentMenuViewType != MVT_GAME_LOSTUnk) { this->hoverTextX = DAT_MouseState::instance.screenSpaceX - width / 2 + 8; diff --git a/src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp b/src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp index 221c40f2a6..860b016332 100644 --- a/src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp +++ b/src/OpenSHC/UI/MenuItem/prepareAndRenderMenuItems.cpp @@ -42,10 +42,10 @@ namespace UI { DAT_ButtonY::instance = this->menuPointer->yPosition + this->position.position.y; DAT_ButtonW::instance = this->itemWidth; DAT_ButtonH::instance = this->itemHeight; - // the index is the low 23 bits, as MIT_MENU_ITEM_TYPE_ID_PARTUnk is of an item type + // the low 23 bits are the index (the same mask as MIT_MENU_ITEM_TYPE_ID_PARTUnk) int const gmDataIndexMask = 0x7fffff; DAT_CurrentButtonGmDataIndex::instance = this->firstItemTypeData.gmDataIndex & gmDataIndexMask; - DAT_ButtonCurrentlyInteracting::instance = (BOOLEnum)(this->clicked | this->hovering); + DAT_ButtonCurrentlyInteracting::instance = this->clicked | this->hovering; DAT_ButtonBlendStrength::instance = 0; DAT_ButtonUnknownZero::instance = this->unknownZero; if (DAT_GameCore::instance.hasMenuRenderedUnk) { @@ -72,52 +72,54 @@ namespace UI { } if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_SLIDER_OR_SCROLLBAR) { if (this->menuPointer->one) { + // 1: set-up: range and position (*this->menuItemActionHandler.slider)(this->callbackParameter.parameter, 1, - &this->secondItemTypeData.buttonState.someTimestamp_1_0x0, - &this->secondItemTypeData.buttonState.clickTimestamp_0x4, - &this->secondItemTypeData.buttonState.countTo100); - this->secondItemTypeData.buttonState.currentButtonPictureInGm_0xc = -1000; - if (this->secondItemTypeData.buttonState.countTo100 - < this->secondItemTypeData.buttonState.someTimestamp_1_0x0) { - this->secondItemTypeData.buttonState.countTo100 - = this->secondItemTypeData.buttonState.someTimestamp_1_0x0; + &this->secondItemTypeData.scrollbarOrSliderState.minValue, + &this->secondItemTypeData.scrollbarOrSliderState.maxValue, + &this->secondItemTypeData.scrollbarOrSliderState.currentValue); + this->secondItemTypeData.scrollbarOrSliderState.dragTiming = -1000; + if (this->secondItemTypeData.scrollbarOrSliderState.currentValue + < this->secondItemTypeData.scrollbarOrSliderState.minValue) { + this->secondItemTypeData.scrollbarOrSliderState.currentValue + = this->secondItemTypeData.scrollbarOrSliderState.minValue; } - if (this->secondItemTypeData.buttonState.countTo100 - > this->secondItemTypeData.buttonState.clickTimestamp_0x4) { - this->secondItemTypeData.buttonState.countTo100 - = this->secondItemTypeData.buttonState.clickTimestamp_0x4; + if (this->secondItemTypeData.scrollbarOrSliderState.currentValue + > this->secondItemTypeData.scrollbarOrSliderState.maxValue) { + this->secondItemTypeData.scrollbarOrSliderState.currentValue + = this->secondItemTypeData.scrollbarOrSliderState.maxValue; } } - BOOLEnum isActive = FALSE; - int knobOffset = 0; + // declared here, before thumbPos and thumbLength: at its first use it loses the match + BOOLEnum isDragged = FALSE; + int thumbPos = 0; int length = this->itemWidth; if ((this->menuItemType & OpenSHC::UI::Enums::MIT_MENU_ITEM_TYPE_ID_PARTUnk) == OpenSHC::UI::Enums::MIT_SCROLLBARUnk) { length = this->itemHeight; } - int knobLength = length; - // the range is written out at each use, not kept in a local (a local: quick_diff 0.9645 -> 0.8832) - if ((this->secondItemTypeData.buttonState.clickTimestamp_0x4 - - this->secondItemTypeData.buttonState.someTimestamp_1_0x0) + int thumbLength = length; + // the range is written out at each use: a local loses the match + if ((this->secondItemTypeData.scrollbarOrSliderState.maxValue + - this->secondItemTypeData.scrollbarOrSliderState.minValue) > 0) { - knobLength = length - / ((this->secondItemTypeData.buttonState.clickTimestamp_0x4 - - this->secondItemTypeData.buttonState.someTimestamp_1_0x0) + thumbLength = length + / ((this->secondItemTypeData.scrollbarOrSliderState.maxValue + - this->secondItemTypeData.scrollbarOrSliderState.minValue) + 1); - if (knobLength <= this->firstItemTypeData.itemsToSkip) { - knobLength = this->firstItemTypeData.itemsToSkip; + if (thumbLength <= this->firstItemTypeData.itemsToSkip) { + thumbLength = this->firstItemTypeData.itemsToSkip; } - knobOffset = (this->secondItemTypeData.buttonState.countTo100 - - this->secondItemTypeData.buttonState.someTimestamp_1_0x0) - * (length - knobLength) - / (this->secondItemTypeData.buttonState.clickTimestamp_0x4 - - this->secondItemTypeData.buttonState.someTimestamp_1_0x0); + thumbPos = (this->secondItemTypeData.scrollbarOrSliderState.currentValue + - this->secondItemTypeData.scrollbarOrSliderState.minValue) + * (length - thumbLength) + / (this->secondItemTypeData.scrollbarOrSliderState.maxValue + - this->secondItemTypeData.scrollbarOrSliderState.minValue); } - if (this->secondItemTypeData.buttonState.currentButtonPictureInGm_0xc > -1000) { - isActive = TRUE; + if (this->secondItemTypeData.scrollbarOrSliderState.dragTiming > -1000) { + isDragged = TRUE; } - (*this->menuItemRenderFunction.slider)(this->callbackParameter.parameter, knobOffset, - this->secondItemTypeData.buttonState.countTo100, knobLength, isActive); + (*this->menuItemRenderFunction.slider)(this->callbackParameter.parameter, thumbPos, + this->secondItemTypeData.scrollbarOrSliderState.currentValue, thumbLength, isDragged); } else if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_SIMPLE_RENDERUnk) { (*this->menuItemRenderFunction.simple)(this->callbackParameter.parameter); } else if (this->menuItemRenderFunctionType == OpenSHC::UI::Enums::MIRFT_GM_DATA_IMAGE) { From f8bc5f05bf622f6c7d3d9dd54aca862505b7ddee Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 18:58:13 +0100 Subject: [PATCH 10/10] UI menu functions: the kept forms give their measurements, one include renderConstructionMenu's second masking of the index and its two hoverTextX stores, and Constructor_Menu's while over the options, say what the cleaner form measures, each alone, in main's one-line form: reusing index 0.9559 -> 0.8883, one hoverTextX store 0.9559 -> 0.9046, a for 0.8787 -> 0.6025. handleMenuItems no longer includes MenuItemHandleState.hpp twice (Menu.func.hpp brings it); quick_diff identical. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/Menu/Constructor_Menu.cpp | 2 +- src/OpenSHC/UI/Menu/handleMenuItems.cpp | 1 - src/OpenSHC/UI/Menu/renderConstructionMenu.cpp | 5 ++--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/OpenSHC/UI/Menu/Constructor_Menu.cpp b/src/OpenSHC/UI/Menu/Constructor_Menu.cpp index 9d30ec925b..ea0a1b248f 100644 --- a/src/OpenSHC/UI/Menu/Constructor_Menu.cpp +++ b/src/OpenSHC/UI/Menu/Constructor_Menu.cpp @@ -61,7 +61,7 @@ namespace UI { ++count; } item->firstItemTypeData.itemsToSkip = count; - // options follow, each with members of its own (a while: a for over the options loses the match) + // options follow, each with members of its own (a for: quick_diff 0.8787 -> 0.6025) while (member->menuItemType == optionType) { item->menuItemType |= optionGroupFlag; actionHandler = member->menuItemActionHandler; diff --git a/src/OpenSHC/UI/Menu/handleMenuItems.cpp b/src/OpenSHC/UI/Menu/handleMenuItems.cpp index 6cd9e8c3f5..31c44f858c 100644 --- a/src/OpenSHC/UI/Menu/handleMenuItems.cpp +++ b/src/OpenSHC/UI/Menu/handleMenuItems.cpp @@ -1,7 +1,6 @@ #include "../Menu.func.hpp" #include "OpenSHC/UI/MenuItem.func.hpp" -#include "OpenSHC/UI/Enums/MenuItemHandleState.hpp" #include "OpenSHC/UI/Enums/MenuItemType.hpp" #include "OpenSHC/UI/Enums/MenuModalType.hpp" diff --git a/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp b/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp index edf8d3a678..8189dab411 100644 --- a/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp +++ b/src/OpenSHC/UI/Menu/renderConstructionMenu.cpp @@ -200,7 +200,7 @@ namespace UI { return; } this->zero = 2; - // the index is masked again for these two, as the original does: reusing index loses the match + // masked again here, as the original does (reusing index: quick_diff 0.9559 -> 0.8883) this->textIndexInGroup = DAT_RenderingDefinedData::instance .TextMessageLookupTable[(*(int*)&item->textMessageLookupIndex & indexMask)] @@ -225,8 +225,7 @@ namespace UI { (OpenSHC::DE::SHCDE::eTextSections)this->textGroupIndex, this->textIndexInGroup); int const width = MACRO_CALL_MEMBER( OpenSHC::Text::TextManager_Func::computeTextWidth, DAT_TextManagerObject::ptr)(text, 17); - // hoverTextX is set in both branches, as the original does: one store before the test loses the - // match + // hoverTextX in both branches (one store before the test: quick_diff 0.9559 -> 0.9046) if (DAT_GameCore::instance.currentMenuViewType != MVT_MISSION_FINISHED_TRANSITION && DAT_GameCore::instance.currentMenuViewType != MVT_GAME_LOSTUnk) { this->hoverTextX = DAT_MouseState::instance.screenSpaceX - width / 2 + 8;