From 63d8daf8b3add04411ba615878998697e52f3f50 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 13:11:10 +0100 Subject: [PATCH 01/11] reimplement: SHC_3BB0A8C1_0x00426D30 100.0% Reimplemented MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect, from gynt's draft on his fork's branch reimpl/UI-MenuItems (43.5% there). A mission not reached yet is an empty cell; the selected one shows its number and name; the others the same in two colours, one call per colour, as in the original (one renderText2 with a colour local, gynt's draft: quick_diff 0.9302 -> 0.6615). DAT_ButtonUnknownZero is set to TRUE/FALSE. Shape: the selected mission's name position as locals, y then x (in the call: quick_diff 0.9302 -> 0.7608; x first: 0.8992); the other missions' number position and value worked out in each branch (once, before the hover test: 0.9302 -> 0.8760; any order of the three ties inside the branches). A comment says what the button holds: minus the mission number, shown as mission - 32 and named by entry mission - 11 of TEXT_MISSION_NAMES. Co-Authored-By: Claude Opus 5.5 --- ...sedEconomicMissionSelect_MissionSelect.cpp | 95 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect.cpp diff --git a/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect.cpp b/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect.cpp new file mode 100644 index 0000000000..dfce8c1197 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect.cpp @@ -0,0 +1,95 @@ +#include "../Unused.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.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/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00426D30 + void Unused::MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect(int button, ...) + { + // nothing while a dialog is open + if (DAT_MenuTextInputState::instance.currentModalDialog != OpenSHC::UI::Enums::MMT_NO_MENU + || DAT_MenuModalComposition1::instance.activeModalDialogID != OpenSHC::UI::Enums::MMT_NONE) { + return; + } + // The button holds minus the mission number: shown as mission - 32, named by entry mission - 11 of + // TEXT_MISSION_NAMES. A mission not reached yet is an empty cell. + if (!DAT_GameCore::instance.unlockAllHistoricalCampaigns + && -button > DAT_GameCore::instance.furthestMission) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawTableCellBackground, + DAT_PencilRenderCore::ptr)(FALSE, button, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawTableCellBackground, + DAT_PencilRenderCore::ptr)(-button == DAT_GameCore::instance.missionNumber1to20, button, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + if (-button == DAT_GameCore::instance.missionNumber1to20) { + // the selected mission: its number and name + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + -32 - button, DAT_ButtonX::instance + 8, DAT_ButtonY::instance + 5, OpenSHC::Text::TTA_LEFT, + OpenSHC::Rendering::Colors::COL_CCFAFF, 19, FALSE, 0); + // y then x for the name (in the call: quick_diff 0.9302 -> 0.7608; x first: 0.8992) + int const nameY = DAT_ButtonY::instance + 5; + int const nameX = DAT_ButtonX::instance + 30; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MISSION_NAMES, -11 - button), + nameX, nameY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, FALSE, 0); + DAT_ButtonUnknownZero::instance = FALSE; + return; + } + // The number's position and value in each branch (once, before the test: quick_diff 0.9302 -> 0.8760) + // and one call per colour (one renderText2 with a colour local: 0.6615) + if (DAT_ButtonCurrentlyInteracting::instance) { + int const numberY = DAT_ButtonY::instance + 5; + int const numberX = DAT_ButtonX::instance + 8; + int const number = -32 - button; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + number, numberX, numberY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, + FALSE, 0); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MISSION_NAMES, -11 - button, DAT_ButtonX::instance + 30, + DAT_ButtonY::instance + 5, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, + FALSE); + } else { + int const numberY = DAT_ButtonY::instance + 5; + int const numberX = DAT_ButtonX::instance + 8; + int const number = -32 - button; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + number, numberX, numberY, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, + FALSE, 0); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MISSION_NAMES, -11 - button, DAT_ButtonX::instance + 30, + DAT_ButtonY::instance + 5, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, + FALSE); + } + DAT_ButtonUnknownZero::instance = FALSE; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d195ecb365..fb79a689fd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -6789,7 +6789,7 @@ SHC_3BB0A8C1_0x00426C50 | 0.0% | Pending SHC_3BB0A8C1_0x00426CA0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00426D30 | 0.0% | Pending +SHC_3BB0A8C1_0x00426D30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00426ED0 | 0.0% | Pending From e663abece7f544dd80b1371ea285d20111a9114a Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 15:56:05 +0100 Subject: [PATCH 02/11] headers: MenuTextInputState's modalDialog_2..6 are one array The five fields after currentModalDialog (+0x60..+0x70) are the stack of dialogs below the current one, and the original moves them as an array: popModalDialog shifts them down one and activateModalDialogAndClearText pushes the current dialog on top, each a loop the compiler unrolled (0x00493900, 0x004916C0). Written as five named fields neither function matches (quick_diff 0.8788 and 0.7742). Now previousModalDialogs[5], most recent first. main's clearModalDialog2to6 is the only .cpp on main that names the fields; the next commit moves it over. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MenuTextInputState.hpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/OpenSHC/UI/MenuTextInputState.hpp b/src/OpenSHC/UI/MenuTextInputState.hpp index 93cc48e476..3959d4f988 100644 --- a/src/OpenSHC/UI/MenuTextInputState.hpp +++ b/src/OpenSHC/UI/MenuTextInputState.hpp @@ -47,11 +47,7 @@ namespace UI { undefined4 DAT_GenieVoiceActiveMenuVar; // 0x00000054 length: 4 undefined4 DAT_MenuOptionsActionParameter; // 0x00000058 length: 4 MenuModalTypeInt currentModalDialog; // 0x0000005C length: 4 - MenuModalTypeInt modalDialog_2; // 0x00000060 length: 4 - MenuModalTypeInt modalDialog_3; // 0x00000064 length: 4 - MenuModalTypeInt modalDialog_4; // 0x00000068 length: 4 - MenuModalTypeInt modalDialog_5; // 0x0000006C length: 4 - MenuModalTypeInt modalDialog_6; // 0x00000070 length: 4 + MenuModalTypeInt previousModalDialogs[5]; // 0x00000060 length: 20 int fileListEntryCount; // 0x00000074 length: 4 undefined4 fileListSortOrder; // 0x00000078 length: 4 int menuLoadGameRelativeSelectionIndex; // 0x0000007C length: 4 From 7f56996d641d43e8a2f3ede2ad5ac450f16cf2bc Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 15:56:05 +0100 Subject: [PATCH 03/11] fix: clearModalDialog2to6 clears previousModalDialogs main's MenuTextInputState::clearModalDialog2to6 (0x00491730) named the five fields the previous commit makes one array. It now clears previousModalDialogs in one loop (countof, to MMT_NO_MENU, which is 0) and compiles to the same code (reccmp 100.0%). Its first include is now the class's .func.hpp, as its siblings have it. Co-Authored-By: Claude Opus 5.5 --- .../UI/MenuTextInputState/clearModalDialog2to6.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OpenSHC/UI/MenuTextInputState/clearModalDialog2to6.cpp b/src/OpenSHC/UI/MenuTextInputState/clearModalDialog2to6.cpp index 6c4ae6b24c..7080d68333 100644 --- a/src/OpenSHC/UI/MenuTextInputState/clearModalDialog2to6.cpp +++ b/src/OpenSHC/UI/MenuTextInputState/clearModalDialog2to6.cpp @@ -1,4 +1,6 @@ -#include "OpenSHC/UI/MenuTextInputState.hpp" +#include "../MenuTextInputState.func.hpp" + +#include "OpenSHC/UI/Enums/MenuModalType.hpp" namespace OpenSHC { @@ -7,11 +9,9 @@ namespace UI { // FUNCTION: STRONGHOLDCRUSADER 0x00491730 void MenuTextInputState::clearModalDialog2to6() { - this->modalDialog_2 = 0; - this->modalDialog_3 = 0; - this->modalDialog_4 = 0; - this->modalDialog_5 = 0; - this->modalDialog_6 = 0; + for (int i = 0; i < countof(this->previousModalDialogs); ++i) { + this->previousModalDialogs[i] = OpenSHC::UI::Enums::MMT_NO_MENU; + } } } From dd1dd8944c0ca75114181480b5398aa8b31574ec Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 15:56:18 +0100 Subject: [PATCH 04/11] reimplement: SHC_3BB0A8C1_0x00493900 100.0% Reimplemented MenuTextInputState::popModalDialog, from our draft on kotijekriv's fork branch reimpl/UI-Core-development (93.9% there, also in #313). The previous dialog comes off the stack, the rest move down one (a loop over previousModalDialogs; written out per element: quick_diff 0.9394 -> 0.8788), and it becomes the current dialog. The save-map dialog gets its file list and text input back; an empty stack clears every other dialog. Guarded, not an early return (an early return for the empty stack: 0.9394 -> 0.8788). resetToTextIndex takes TAIT_TWO__FILTER_A; the last index is countof(previousModalDialogs) - 1. Co-Authored-By: Claude Opus 5.5 --- .../UI/MenuTextInputState/popModalDialog.cpp | 43 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuTextInputState/popModalDialog.cpp diff --git a/src/OpenSHC/UI/MenuTextInputState/popModalDialog.cpp b/src/OpenSHC/UI/MenuTextInputState/popModalDialog.cpp new file mode 100644 index 0000000000..c6a167304c --- /dev/null +++ b/src/OpenSHC/UI/MenuTextInputState/popModalDialog.cpp @@ -0,0 +1,43 @@ +#include "../MenuTextInputState.func.hpp" + +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Text/TextArrayIndexType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x00493900 + void MenuTextInputState::popModalDialog() + { + MenuModalTypeInt const previousDialog = this->previousModalDialogs[0]; + // Pop the stack (written out per element: quick_diff 0.9394 -> 0.8788) + for (int i = 0; i < countof(this->previousModalDialogs) - 1; ++i) { + this->previousModalDialogs[i] = this->previousModalDialogs[i + 1]; + } + this->previousModalDialogs[countof(this->previousModalDialogs) - 1] = OpenSHC::UI::Enums::MMT_NO_MENU; + this->currentModalDialog = previousDialog; + // Guarded, not an early return (an early return for the empty stack: quick_diff 0.9394 -> 0.8788) + if (previousDialog != OpenSHC::UI::Enums::MMT_NO_MENU) { + if (previousDialog == OpenSHC::UI::Enums::MMT_SAVE_MAP) { + this->fileListVisibleRowCount = 16; + DAT_UserTextHandlerState::instance.allowUserTextInput = 0; + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)( + OpenSHC::Text::TAIT_TWO__FILTER_A); + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::moveCursorToEnd, DAT_UserTextHandlerState::ptr)(); + DAT_UserTextHandlerState::instance.allowUserTextInput = 1; + } + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)((MenuModalType)previousDialog, TRUE); + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, this)(); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index fb79a689fd..3ca5befdda 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23645,7 +23645,7 @@ SHC_3BB0A8C1_0x004938F8 | 0.0% | Pending SHC_3BB0A8C1_0x004938FC | 0.0% | Pending -SHC_3BB0A8C1_0x00493900 | 0.0% | Pending +SHC_3BB0A8C1_0x00493900 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00493980 | 100.0% | Reimplemented From eb1d5af5ab2afd54103fd1cdd2339e06185d0141 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 15:56:19 +0100 Subject: [PATCH 05/11] reimplement: SHC_3BB0A8C1_0x004916C0 100.0% Reimplemented MenuTextInputState::activateModalDialogAndClearText, from our draft on kotijekriv's fork branch reimpl/UI-Core-development (90.3% there, also in #313). With no dialog open it saves the text array index and clears the text; a dialog that isn't already current is pushed onto the stack, counting down over previousModalDialogs from countof(previousModalDialogs) - 1 (written out per element: quick_diff 1.0000 -> 0.7742; i != 0 as the bound: 0.5312), and activated. The draft's pointer over ¤tModalDialog is gone, and so is the imported plate comment. The text array index is saved through the global, as the original does (this->: quick_diff 1.0000 -> 0.9355). Co-Authored-By: Claude Opus 5.5 --- .../activateModalDialogAndClearText.cpp | 40 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuTextInputState/activateModalDialogAndClearText.cpp diff --git a/src/OpenSHC/UI/MenuTextInputState/activateModalDialogAndClearText.cpp b/src/OpenSHC/UI/MenuTextInputState/activateModalDialogAndClearText.cpp new file mode 100644 index 0000000000..f1a1699148 --- /dev/null +++ b/src/OpenSHC/UI/MenuTextInputState/activateModalDialogAndClearText.cpp @@ -0,0 +1,40 @@ +#include "../MenuTextInputState.func.hpp" + +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/Text/TextArrayIndexType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x004916C0 + void MenuTextInputState::activateModalDialogAndClearText(MenuModalType dialogID) + { + if (this->currentModalDialog == OpenSHC::UI::Enums::MMT_NO_MENU) { + // Through the global, as the original (this->: quick_diff 1.0000 -> 0.9355) + DAT_MenuTextInputState::instance.DAT_SomeTextArrayIndex = DAT_UserTextHandlerState::instance.textArrayIndex; + DAT_UserTextHandlerState::instance.allowUserTextInput = 1; + if (DAT_UserTextHandlerState::instance.textArrayIndex != OpenSHC::Text::TAIT_ZERO) { + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::clearTextAndCursor, DAT_UserTextHandlerState::ptr)(); + } + } + if (this->currentModalDialog != dialogID) { + // Push the current dialog onto the stack (written out per element: quick_diff 1.0000 -> 0.7742) + for (int i = countof(this->previousModalDialogs) - 1; i > 0; --i) { + this->previousModalDialogs[i] = this->previousModalDialogs[i - 1]; + } + this->previousModalDialogs[0] = this->currentModalDialog; + this->currentModalDialog = dialogID; + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(dialogID, TRUE); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3ca5befdda..59fa895881 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23405,7 +23405,7 @@ SHC_3BB0A8C1_0x004914D0 | 0.0% | Pending SHC_3BB0A8C1_0x00491680 | 0.0% | Pending -SHC_3BB0A8C1_0x004916C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004916C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00491730 | 100.0% | Reimplemented From ad6350e44d68185365893bbf4c874b73d7cc2036 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 15:57:38 +0100 Subject: [PATCH 06/11] reimplement: SHC_3BB0A8C1_0x004B51A0 100.0% Reimplemented MinimapViewState::convertMinimapClickToTileXY, from our draft on kotijekriv's fork branch reimpl/UI-Core-development (87.1% there, also in #313). The mouse position on the minimap becomes a screen point, looked up in the current orientation's screenPointToTileNumber table (80400 entries apart, as main's ViewportBasedTileNumber writes them), and the tile is split into x and y; with clicks disabled both are -1. Orientation 0 sets the offset again, as main's renderPreviewAtMouseLocation does (without that arm: quick_diff 1.0000 -> 0.8714; it was the draft's register swap). Guarded, not an early return (an early return when disabled: 1.0000 -> 0.9000). Computing the offset from the orientation instead: 0.5507. The redundant (short) cast on the short table is gone; 0x191 is 401. The flag is a truthiness test. The Y term and the offset stay up front (Y inline: 1.0000 -> 0.7770; the offset declared at first use: 0.6714); comments say why the +6 / -6 both stay and that the out parameters hold the screen point until the tile is known. Co-Authored-By: Claude Opus 5.5 --- .../convertMinimapClickToTileXY.cpp | 48 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MinimapViewState/convertMinimapClickToTileXY.cpp diff --git a/src/OpenSHC/UI/MinimapViewState/convertMinimapClickToTileXY.cpp b/src/OpenSHC/UI/MinimapViewState/convertMinimapClickToTileXY.cpp new file mode 100644 index 0000000000..87caa224d4 --- /dev/null +++ b/src/OpenSHC/UI/MinimapViewState/convertMinimapClickToTileXY.cpp @@ -0,0 +1,48 @@ +#include "../MinimapViewState.func.hpp" + +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace UI { + + // FUNCTION: STRONGHOLDCRUSADER 0x004B51A0 + void MinimapViewState::convertMinimapClickToTileXY(int* tileX, int* tileY) + { + // Guarded, not an early return (an early return when disabled: quick_diff 1.0000 -> 0.9000) + if (this->minimapClickEnabled) { + // Y and the offset up front (Y inline: quick_diff 1.0000 -> 0.7770; offset at first use: 0.6714) + int const mouseY = DAT_MouseState::instance.screenSpaceY - this->y; + int orientationOffset = 0; + // The original adds 6 here and takes it off again in the index below, so both stay. + *tileX = (((DAT_MouseState::instance.screenSpaceX - this->x) * this->oneOrTwo) / this->widthFactor + 6 + + this->tileOffsetX) + * 32; + int const screenY = ((this->oneOrTwo * mouseY) / this->heightFactor + this->tileOffsetY) * 8; + // The out parameters hold the screen point until the tile is known. + *tileY = screenY; + // Four tables, 80400 entries apart (computed from the orientation: quick_diff 1.0000 -> 0.5507) + if (DAT_TileMapState::instance.mapOrientation == 0) { + // Set again, as in renderPreviewAtMouseLocation (without this arm: quick_diff 1.0000 -> 0.8714) + orientationOffset = 0; + } else if (DAT_TileMapState::instance.mapOrientation == 6) { + orientationOffset = 80400; + } else if (DAT_TileMapState::instance.mapOrientation == 4) { + orientationOffset = 160800; + } else if (DAT_TileMapState::instance.mapOrientation == 2) { + orientationOffset = 241200; + } + int const tile = DAT_ViewportRenderState::instance + .screenPointToTileNumber[*tileX / 32 + screenY / 16 * 401 + orientationOffset - 6]; + int const row = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + *tileY = row; + *tileX = tile - DAT_ViewportRenderState::instance.translationMatrix[row].addXgetTile; + } else { + *tileX = -1; + *tileY = -1; + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 59fa895881..feb411cd96 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -26877,7 +26877,7 @@ SHC_3BB0A8C1_0x004B5100 | 0.0% | Pending SHC_3BB0A8C1_0x004B5110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B51A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004B51A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B5280 | 100.0% | Reimplemented From e66f5b6cea1754fcb9e0857559b185d8f83dadb0 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 15:57:38 +0100 Subject: [PATCH 07/11] reimplement: SHC_3BB0A8C1_0x00493690 100.0% Reimplemented Rendering::RenderLoadAndSaveBar, from our draft on kotijekriv's fork branch reimpl/UI-Rendering-development (85.7% there, also in #313). At most every 30 ms it draws the progress bar, in game on the map surface and flipped, in the menus on the menu surface and blitted. The blit mode is 2 on the siege tent's tower and shield tabs unless the building and status menu is open, else 1: one store of 1 for both paths, as in main's WinMain (there a comma expression, here a siegeTowerOrShieldTab local; an if/else with a store each: quick_diff 0.9459 -> 0.8742, and MSVC then keeps 1 in edi, the draft's blocker). The 30 ms, the per-mille progress (300 pixels wide when full) and the 15-pixel height have a comment each. Co-Authored-By: Claude Opus 5.5 --- .../UI/Rendering/RenderLoadAndSaveBar.cpp | 70 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/Rendering/RenderLoadAndSaveBar.cpp diff --git a/src/OpenSHC/UI/Rendering/RenderLoadAndSaveBar.cpp b/src/OpenSHC/UI/Rendering/RenderLoadAndSaveBar.cpp new file mode 100644 index 0000000000..62488b413c --- /dev/null +++ b/src/OpenSHC/UI/Rendering/RenderLoadAndSaveBar.cpp @@ -0,0 +1,70 @@ +#include "../Rendering.func.hpp" + +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/UI/Rendering/WindowAndDirectDraw.func.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/COL_VERY_SOFT_YELLOW.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" +#include "OpenSHC/Globals/TIME_LoadSaveBar.hpp" + +namespace OpenSHC { +namespace UI { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00493690 + void Rendering::RenderLoadAndSaveBar(int progressValueUnk) + { + DWORD const currentTime = timeGetTime(); + // Redrawn every 30 ms at most + if ((int)(currentTime - TIME_LoadSaveBar::instance) <= 30) { + return; + } + TIME_LoadSaveBar::instance = currentTime; + // The progress is per mille: the bar is 300 pixels wide when full and 15 high + int const barWidth = (progressValueUnk * 300) / 1000; + if (MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::getAreWeInAInGameMenu, DAT_GameCore::ptr)()) { + DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)( + DAT_MenuTextInputState::instance.progressBarX, DAT_MenuTextInputState::instance.progressBarY, + DAT_MenuTextInputState::instance.progressBarX + barWidth, + DAT_MenuTextInputState::instance.progressBarY + 15, COL_VERY_SOFT_YELLOW::instance.shortValue); + // One store of 1 for both paths (as an if/else with a store each: quick_diff 0.9459 -> 0.8742) + BOOLEnum const siegeTowerOrShieldTab + = DAT_GameCore::instance.activeMenuTab.tabType == OpenSHC::UI::Enums::BASMTT_SIEGETENT_SIEGETOWER + || DAT_GameCore::instance.activeMenuTab.tabType == OpenSHC::UI::Enums::BASMTT_SIEGETENT_SHIELD; + if (siegeTowerOrShieldTab) { + DAT_WindowAndDirectDraw::instance.pendingBltMode = 2; + } + if (!siegeTowerOrShieldTab + || DAT_GameCore::instance.currentMenuViewType == OpenSHC::UI::Enums::MVT_BUILDING_AND_STATUS_MENU) { + DAT_WindowAndDirectDraw::instance.pendingBltMode = 1; + } + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::WindowAndDirectDraw_Func::renderBltAndFlip, DAT_WindowAndDirectDraw::ptr)(1); + DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)( + DAT_MenuTextInputState::instance.progressBarX, DAT_MenuTextInputState::instance.progressBarY, + DAT_MenuTextInputState::instance.progressBarX + barWidth, + DAT_MenuTextInputState::instance.progressBarY + 15, COL_VERY_SOFT_YELLOW::instance.shortValue); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::WindowAndDirectDraw_Func::bltScreenMenuSurfaceToScreen, + DAT_WindowAndDirectDraw::ptr)(DAT_MenuTextInputState::instance.progressBarX, + DAT_MenuTextInputState::instance.progressBarY, DAT_MenuTextInputState::instance.progressBarX + 300, + DAT_MenuTextInputState::instance.progressBarY + 15); + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index feb411cd96..8381071c2e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23625,7 +23625,7 @@ SHC_3BB0A8C1_0x004934F0 | 0.0% | Pending SHC_3BB0A8C1_0x00493560 | 0.0% | Pending -SHC_3BB0A8C1_0x00493690 | 0.0% | Pending +SHC_3BB0A8C1_0x00493690 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004937A4 | 0.0% | Pending From 334c1efeb2641f58529840792ba28e74acd63c3e Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 03:36:03 +0100 Subject: [PATCH 08/11] headers: GameCore::unlockAllHistoricalCampaigns is a BOOLEnum Its only stores in the exe are 1 at 0x004B49C8 (ebp, set to 1 at 0x004B4813) and 0 in GameCore's initialiser (mov [eax + 0x58], ecx at 0x0046B21D, ecx zeroed at 0x0046B1F2); its readers compare it with a zero register (0x004269FC, 0x00426D4C). BOOLEnum is a typedef of int, so the size and every access stay the same. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Game/GameCore.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/Game/GameCore.hpp b/src/OpenSHC/Game/GameCore.hpp index 680342d5fc..919ae027e2 100644 --- a/src/OpenSHC/Game/GameCore.hpp +++ b/src/OpenSHC/Game/GameCore.hpp @@ -63,7 +63,7 @@ namespace Game { int missionNumber1to20; // 0x00000040 length: 4 ScenarioProgress scenarioProgress; // 0x00000044 length: 16 int furthestMission; // 0x00000054 length: 4 - dword unlockAllHistoricalCampaigns; // 0x00000058 length: 4 + BOOLEnum unlockAllHistoricalCampaigns; // 0x00000058 length: 4 dword unused1; // 0x0000005C length: 4 dword section1066; // 0x00000060 length: 4 dword gameSuspended; // 0x00000064 length: 4 From 65c084782001e9439c464eca19a793a37672a5a7 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 03:36:04 +0100 Subject: [PATCH 09/11] headers: MinimapViewState::minimapClickEnabled is a BOOLEnum Its only stores in the exe are 1 at 0x00434328 (eax, set to 1 at 0x00434319 on both paths) and 0 at 0x0043432E; no MinimapViewState method writes it through this. BOOLEnum is a typedef of int, so the size and every access stay the same. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MinimapViewState.hpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/OpenSHC/UI/MinimapViewState.hpp b/src/OpenSHC/UI/MinimapViewState.hpp index 24bdbd717a..81241d0261 100644 --- a/src/OpenSHC/UI/MinimapViewState.hpp +++ b/src/OpenSHC/UI/MinimapViewState.hpp @@ -11,10 +11,13 @@ #include "OpenSHC/Map/MapHeaderSection4IntStruct.hpp" #include "WinDef.h" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { namespace UI { + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + using OpenSHC::Map::MapHeaderSection4IntStruct; #pragma pack(push, 1) @@ -37,7 +40,7 @@ namespace UI { int oneOrTwo; // 0x00000030 length: 4 undefined4 field_0x34; // 0x00000034 length: 4 undefined4 field_0x38; // 0x00000038 length: 4 - undefined4 minimapClickEnabled; // 0x0000003C length: 4 + BOOLEnum minimapClickEnabled; // 0x0000003C length: 4 int someMiniMapCounterTill4; // 0x00000040 length: 4 ushort field_0x44[80000]; // 0x00000044 length: 160000 ushort minimapPixelBuffer[80000]; // 0x00027144 length: 160000 From 40bc9bb399d27c4d1ca61e4d80f8a459b9fa5fba Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 04:35:26 +0100 Subject: [PATCH 10/11] headers: clang-format MinimapViewState.hpp cpp-linter checks whole changed files: the BOOLEnum include added in 65c084782 sorts with the project includes. Whitespace and include order only. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MinimapViewState.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/UI/MinimapViewState.hpp b/src/OpenSHC/UI/MinimapViewState.hpp index 81241d0261..d332d87027 100644 --- a/src/OpenSHC/UI/MinimapViewState.hpp +++ b/src/OpenSHC/UI/MinimapViewState.hpp @@ -9,9 +9,9 @@ #pragma once #include "OpenSHC/Map/MapHeaderSection4IntStruct.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "WinDef.h" -#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" namespace OpenSHC { namespace UI { From 222e50ca943aae274dda737016dd1f6829ab6419 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sat, 7 Nov 2026 19:34:20 +0100 Subject: [PATCH 11/11] headers: MinimapViewState as on main again The merge of eef6f667a left the BOOLEnum using-declaration twice: the sync added its own when it took minimapClickEnabled's BOOLEnum from this PR. The header is now the same as main's, so the PR no longer changes it. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/UI/MinimapViewState.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/OpenSHC/UI/MinimapViewState.hpp b/src/OpenSHC/UI/MinimapViewState.hpp index 88882eef0d..289faeba1c 100644 --- a/src/OpenSHC/UI/MinimapViewState.hpp +++ b/src/OpenSHC/UI/MinimapViewState.hpp @@ -16,8 +16,6 @@ namespace OpenSHC { namespace UI { - using OpenSHC::WindowsHelper::Enums::BOOLEnum; - using OpenSHC::Map::MapHeaderSection4IntStruct; using OpenSHC::WindowsHelper::Enums::BOOLEnum;