From 3a26fe6dd38fcc08fd07e7df845fc0713f53ab88 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 15:11:24 +0100 Subject: [PATCH 01/15] headers: DAT_00b9840c is an int DAT_00b9840c, at 0x00B9840C, was undefined4. MenuItemActionHandler_InGameMenu_ViewToKeeps (0x004335A0) uses it as a signed count of mouse wheel steps within a second: down counts 1, 2 (test ebx, ebx; jge; ... cmp ebx, 2), up counts -1, -2 (test ebx, ebx; jle; sub ebx, 1; cmp ebx, -2). The annotation names the int instance too. No file on main reads it. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Globals/DAT_00b9840c.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Globals/DAT_00b9840c.hpp b/src/OpenSHC/Globals/DAT_00b9840c.hpp index b6f3153120..8cbf3a458a 100644 --- a/src/OpenSHC/Globals/DAT_00b9840c.hpp +++ b/src/OpenSHC/Globals/DAT_00b9840c.hpp @@ -9,11 +9,11 @@ #pragma once // GLOBAL: STRONGHOLDCRUSADER 0x00B9840C -// StructResolver::Instance::instance +// StructResolver::Instance::instance namespace OpenSHC { -MACRO_STRUCT_RESOLVER(undefined4, false, Address::SHC_3BB0A8C1_0x00B9840C) DAT_00b9840c; +MACRO_STRUCT_RESOLVER(int, false, Address::SHC_3BB0A8C1_0x00B9840C) DAT_00b9840c; } // namespace OpenSHC MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00B9840C); From dbb3e8ce89618b4fe2742cee176ec0260a2f1688 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 14:42:29 +0100 Subject: [PATCH 02/15] data: DAT_00b9840c's symbol as an int data.asm names the instance at 0x00B9840C with the int type (H instead of I) in its PUBLIC and EQU lines, as it does for main's other int globals, to go with the header commit before it. Co-Authored-By: Claude Opus 5.5 --- src/symbols/data.asm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/symbols/data.asm b/src/symbols/data.asm index a91cf3c8b0..69feb7e417 100644 --- a/src/symbols/data.asm +++ b/src/symbols/data.asm @@ -1271,7 +1271,7 @@ PUBLIC ?instance@?$Extern@VMenuView@UI@OpenSHC@@$0LJHELM@@StructResolver@@2VMenu PUBLIC ?instance@?$Extern@H$0LJIEAE@@StructResolver@@2HA -PUBLIC ?instance@?$Extern@I$0LJIEAM@@StructResolver@@2IA +PUBLIC ?instance@?$Extern@H$0LJIEAM@@StructResolver@@2HA PUBLIC ?instance@?$Extern@K$0LJIEBA@@StructResolver@@2KA @@ -2958,7 +2958,7 @@ _TEXT SEGMENT ?instance@?$Extern@H$0LJIEAE@@StructResolver@@2HA EQU 00B98404h -?instance@?$Extern@I$0LJIEAM@@StructResolver@@2IA EQU 00B9840Ch +?instance@?$Extern@H$0LJIEAM@@StructResolver@@2HA EQU 00B9840Ch ?instance@?$Extern@K$0LJIEBA@@StructResolver@@2KA EQU 00B98410h From 6ca034fc44234a0049f9ce57a7141b5ec5d3b3f1 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 14:42:29 +0100 Subject: [PATCH 03/15] headers: GameCore::viewedKeepIndex is an int viewedKeepIndex was dword. MenuItemActionHandler_InGameMenu_ViewToKeeps (0x004335A0) views the next keep and wraps the index back to 0 once it passes the number of keeps with a signed compare (add edi, 1; cmp edi, esi; jl). No file on main reads it. 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 a98d1edfc6..85c2d2884c 100644 --- a/src/OpenSHC/Game/GameCore.hpp +++ b/src/OpenSHC/Game/GameCore.hpp @@ -73,7 +73,7 @@ namespace Game { dword field_0x74; // 0x00000074 length: 4 int mapU4Int1; // 0x00000078 length: 4 int mapU4Int1_2; // 0x0000007C length: 4 - dword viewedKeepIndex; // 0x00000080 length: 4 + int viewedKeepIndex; // 0x00000080 length: 4 int battleLevel; // 0x00000084 length: 4 dword cowPoisonTrackerUnk; // 0x00000088 length: 4 int someSoundMatchTime_1; // 0x0000008C length: 4 From 812abf92538ad3f098506a379501ee75e6c667d1 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 14:43:58 +0100 Subject: [PATCH 04/15] reimplement: SHC_3BB0A8C1_0x004AD480 100.0% Reimplemented MenuItemRenderFunction_AlliesOrder_Main draws the allies dialog: the enemies' portraits with an AI's or a human lord's icon or face (buttons 1 to 6, an empty box past the last enemy), the dialog's other buttons, and as item -1 the tooltip the hovered button set, with the player's name for a portrait. Written from the original's instructions, with gynt's drafts (3b1bcad09 on his fork's reimpl/UI-MenuItems-development, 58.50% there, earlier d545ddbdd at 58.00%; 411fb299a at 61.11% and f8e28264e at 60.61% on reimpl/UI-MenuItems) for the reads. Behaviour fix: for a human player the original returns after the name, where the draft went on to draw the AI name text as well. The forms the original needs: button itself becomes the row and then the player, as the original's one register does, and the tooltip's position read x first. Also: decimals for the picture numbers, COL_B8EEFB, TEXT_ALLIES, no gotos or decompiler locals. quick_diff leaves only the colour immediates and ret / ret 0. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...enuItemRenderFunction_AlliesOrder_Main.cpp | 151 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/AlliesOrder/MenuItemRenderFunction_AlliesOrder_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/AlliesOrder/MenuItemRenderFunction_AlliesOrder_Main.cpp b/src/OpenSHC/UI/MenuItems/AlliesOrder/MenuItemRenderFunction_AlliesOrder_Main.cpp new file mode 100644 index 0000000000..f599a1497e --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/AlliesOrder/MenuItemRenderFunction_AlliesOrder_Main.cpp @@ -0,0 +1,151 @@ +#include "../AlliesOrder.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eGM.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" + +#include "OpenSHC/Globals/COL_BLACK.hpp" +#include "OpenSHC/Globals/DAT_00df51f8.hpp" +#include "OpenSHC/Globals/DAT_00df51fc.hpp" +#include "OpenSHC/Globals/DAT_00df5200.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_EnemyArrayIndex.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_RequestedGoodsByWhoArray.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004AD480 + void AlliesOrder::MenuItemRenderFunction_AlliesOrder_Main(int button, ...) + { + if (button == -2) { + MACRO_CALL( + OpenSHC::UI::Rendering_Func::RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurrentSurfaceUnk)(); + return; + } + if (button >= 10) { + // the dialog's other buttons; hovered, 10 and 11 set the tooltip + if (button == 10) { + DAT_00df5200::instance = 0; + } + MACRO_CALL( + OpenSHC::UI::Rendering_Func::RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurrentSurfaceUnk)(); + if (DAT_ButtonCurrentlyInteracting::instance) { + if (button == 10) { + DAT_00df5200::instance = OpenSHC::DE::SHCDE::TEXT_ALLIES; + DAT_00df51fc::instance = 8; + return; + } + if (button == 11) { + DAT_00df5200::instance = OpenSHC::DE::SHCDE::TEXT_ALLIES; + DAT_00df51fc::instance = 9; + return; + } + } + } + // buttons 1 to 6 are the enemies' portraits; the original reuses button for the row and then the player, + // and draws the tooltip when it ends up -1, which button 0 also gives + if (button <= 6 && button != -1) { + --button; + if (button >= DAT_EnemyArrayIndex::instance) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBorderBox, + DAT_PencilRenderCore::ptr)(DAT_ButtonX::instance, DAT_ButtonY::instance, + DAT_ButtonX::instance + 71, DAT_ButtonY::instance + 71, COL_BLACK::instance.shortValue); + } else { + button = DAT_RequestedGoodsByWhoArray::instance[button + 1]; + int ai = 0; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[button] == -1) { + ai = DAT_GameSynchronyState::instance.currentAIArray[button]; + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, button + 546, + DAT_ButtonX::instance, DAT_ButtonY::instance); + if (ai == 0) { + // a human: the lord's icon, or the own face + if (DAT_GameCore::instance.lordIcons[button] == 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 539, + DAT_ButtonX::instance, DAT_ButtonY::instance); + } else if (DAT_GameCore::instance.lordIcons[button] == 1) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 540, + DAT_ButtonX::instance, DAT_ButtonY::instance); + } else if (DAT_TextureRenderCoreObject::instance.bitmapFaceSizes[button + 19] > 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, 541, + DAT_ButtonX::instance, DAT_ButtonY::instance); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::drawBitmapFace, + DAT_TextureRenderCoreObject::ptr)( + button + 19, DAT_ButtonX::instance + 4, DAT_ButtonY::instance + 4); + } + } else { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_INTERFACE_ICONS2, ai + 522, + DAT_ButtonX::instance, DAT_ButtonY::instance); + } + if (DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 514, + DAT_ButtonX::instance - 6, DAT_ButtonY::instance - 6, + OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 513, 0); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithAlphaMask, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 574, + DAT_ButtonX::instance - 10, DAT_ButtonY::instance - 8, + OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 575, 0); + DAT_00df5200::instance = OpenSHC::DE::SHCDE::TEXT_ALLIES; + DAT_00df51fc::instance = 10; + DAT_00df51f8::instance = button; + } + } + } + if (button != -1) { + return; + } + // -1 draws the tooltip set by the hovered button, for a portrait with the player's name + if (DAT_00df5200::instance == 0) { + return; + } + int const x = DAT_ButtonX::instance; + int const y = DAT_ButtonY::instance; + DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME; + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)( + (OpenSHC::DE::SHCDE::eTextSections)DAT_00df5200::instance, DAT_00df51fc::instance), + x, y, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_B8EEFB, 0, 17, FALSE, 0); + if (DAT_00df51fc::instance == 10) { + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[DAT_00df51f8::instance] != -1) { + MACRO_CALL_MEMBER( + OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)( + DAT_GameSynchronyState::instance.DAT_PlayerNames[DAT_00df51f8::instance], x + 5, y, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_B8EEFB, 0, 17, TRUE, 0); + DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + return; + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, + DAT_GameSynchronyState::instance.currentAIArray[DAT_00df51f8::instance] * 8 + + DAT_GameSynchronyState::instance.aiVariationArray[DAT_00df51f8::instance] + 103, + x + 5, y, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_B8EEFB, 0, 17, TRUE); + } + DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ed989c9a21..d889123582 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -25805,7 +25805,7 @@ SHC_3BB0A8C1_0x004AD2B0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004AD2F0 | 0.0% | Pending -SHC_3BB0A8C1_0x004AD480 | 0.0% | Pending +SHC_3BB0A8C1_0x004AD480 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004AD780 | 100.0% | Reimplemented From 279647a39bb26b7694f3ce64ed93daba2986eb20 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 14:43:59 +0100 Subject: [PATCH 05/15] reimplement: SHC_3BB0A8C1_0x004335A0 100.0% Reimplemented MenuItemActionHandler_InGameMenu_ViewToKeeps handles the mouse wheel in game: two steps down within a second view the next keep on the map, two steps up the own keep (scroll event 7 is the wheel turned down, as main's updateMouseStateBasedOnCursorAndTime sets it for a negative delta). Written from the original's instructions, with gynt's draft (209d8e32e on his fork's reimpl/UI-MenuItems-development, 44.28% there; earlier 9707d0c46 at 42.07%) for the reads. Needs the header commits for DAT_00b9840c and GameCore::viewedKeepIndex. The ten keep slots are one plain loop, which MSVC unrolls five wide as the original is (an outer loop in fives with an inner loop up to i + 5 stays a loop: quick_diff 0.5844). Also: countof, BEIE_KEEP for the keep's building entry, decimals, no decompiler locals. quick_diff leaves the timeGetTime import call's form and ret / ret 0. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...emActionHandler_InGameMenu_ViewToKeeps.cpp | 95 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp diff --git a/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp new file mode 100644 index 0000000000..7339543416 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp @@ -0,0 +1,95 @@ +#include "../InGameMenu.func.hpp" + +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_00b9840c.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DWORD_00b98410.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004335A0 + void InGameMenu::MenuItemActionHandler_InGameMenu_ViewToKeeps(int param_1, ...) + { + if (DAT_MenuModalComposition1::instance.activeModalDialogID != OpenSHC::UI::Enums::MMT_NONE) { + return; + } + // two wheel steps within a second count as one move: up views the next keep, down the own keep + DWORD const now = timeGetTime(); + if (now - DWORD_00b98410::instance > 1000) { + DWORD_00b98410::instance = now; + DAT_00b9840c::instance = 0; + } + if (DAT_MouseState::instance.scrollEventData == 7) { + if (DAT_00b9840c::instance < 0) { + DAT_00b9840c::instance = 0; + } + ++DAT_00b9840c::instance; + if (DAT_00b9840c::instance == 2) { + DWORD_00b98410::instance = now; + DAT_00b9840c::instance = 0; + // the keep after the one viewed last, counting the map's keeps from 1 + int keepNumber = 1; + int tileIndex = -1; + for (int i = 0; i < countof(DAT_GameState::instance.mapAndTime.playerKeepTile); ++i) { + if (DAT_GameState::instance.mapAndTime.playerKeepTile[i] > -1) { + if (keepNumber == DAT_GameCore::instance.viewedKeepIndex) { + tileIndex = i; + } + ++keepNumber; + } + } + if (tileIndex == -1) { + int const keep = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id; + if (keep != 0) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[keep].x + 2, + DAT_BuildingsState::instance.buildings[keep].y + 2); + } + } else { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnTile, + DAT_ViewportRenderState::ptr)(DAT_GameState::instance.mapAndTime.playerKeepTile[tileIndex]); + } + ++DAT_GameCore::instance.viewedKeepIndex; + if (DAT_GameCore::instance.viewedKeepIndex >= keepNumber) { + DAT_GameCore::instance.viewedKeepIndex = 0; + } + } + } + if (DAT_MouseState::instance.scrollEventData == 8) { + if (DAT_00b9840c::instance > 0) { + DAT_00b9840c::instance = 0; + } + --DAT_00b9840c::instance; + if (DAT_00b9840c::instance == -2) { + DWORD_00b98410::instance = now; + int const keep + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id; + DAT_00b9840c::instance = 0; + if (keep != 0) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[keep].x + 2, + DAT_BuildingsState::instance.buildings[keep].y + 2); + } + } + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d889123582..0e33ee8d1d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -11101,7 +11101,7 @@ SHC_3BB0A8C1_0x0043355C | 0.0% | Pending SHC_3BB0A8C1_0x00433560 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004335A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004335A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00433630 | 0.0% | Pending From 2175863c3fd8fcc10cc3ebc1607f2939ae77cef0 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 14:43:59 +0100 Subject: [PATCH 06/15] reimplement: SHC_3BB0A8C1_0x0042F940 100.0% Reimplemented MenuItemActionHandler_NewMapMapsize_Buttons makes a new map in the editor: buttons 1 to 4 set the map size (160, 200, 300 or 400), reset the heights, borders, path linkage, wildlife and minimap for it and open the map properties; 7 goes back to the custom scenarios. From gynt's draft (64e69da7c on his fork's reimpl/UI-MenuItems-development, 72.62% there; earlier a3f0f9ced at 55.95%; his fork's reimpl/UI-MenuItems-development measured it again in 8725ec523 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%")). The forms the original needs: button 7 tested and handled first (it lays the 1-4 path out after it), and the switch to the map properties written in both arms of a test of U2_mapType_singleOrMulti == 1, which the original compares there with both arms the same (one call: quick_diff 0.7636 and no cmp). Also: main's field_0x55487c, the map sizes as MapConstants, button and mapSize for the decompiler's names, decimals. quick_diff leaves ret / ret 0 and the jump over the loop's alignment padding, which its npad hides. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...temActionHandler_NewMapMapsize_Buttons.cpp | 103 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/NewMapMapsize/MenuItemActionHandler_NewMapMapsize_Buttons.cpp diff --git a/src/OpenSHC/UI/MenuItems/NewMapMapsize/MenuItemActionHandler_NewMapMapsize_Buttons.cpp b/src/OpenSHC/UI/MenuItems/NewMapMapsize/MenuItemActionHandler_NewMapMapsize_Buttons.cpp new file mode 100644 index 0000000000..00b6407918 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/NewMapMapsize/MenuItemActionHandler_NewMapMapsize_Buttons.cpp @@ -0,0 +1,103 @@ +#include "../NewMapMapsize.func.hpp" + +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/MapLockState.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WildlifeState.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x0042F940 + void NewMapMapsize::MenuItemActionHandler_NewMapMapsize_Buttons(int button, ...) + { + if (DAT_MenuTextInputState::instance.currentModalDialog != OpenSHC::UI::Enums::MMT_NO_MENU) { + return; + } + if (DAT_MenuModalComposition1::instance.activeModalDialogID != OpenSHC::UI::Enums::MMT_NONE) { + return; + } + // buttons 1 to 4 make a new map of that size + int mapSize = OpenSHC::Map::MC_MAP_SIZE_400; + if (button <= 0) { + return; + } + if (button > 4) { + if (button == 7) { + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_CUSTOM_SCENARIOS, 0); + } + return; + } + if (button == 1) { + mapSize = OpenSHC::Map::MC_MAP_SIZE_160; + } else if (button == 2) { + mapSize = OpenSHC::Map::MC_MAP_SIZE_200; + } else if (button == 3) { + mapSize = OpenSHC::Map::MC_MAP_SIZE_300; + } + DAT_TileMapState::instance.mapSize = mapSize; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetHeightAndMapBorders, DAT_TileMapState::ptr)( + mapSize); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkageLayerForEachBuildingAtEachTile, + DAT_PathFindingState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateSeparateAreaTileMap, + DAT_PathFindingState::ptr)(1); + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::updatePathLinkageLayerForAllBuildings, + DAT_BuildingsState::ptr)(); + DAT_TileMapState::instance.forceUpdateMacroLayerFlag = 1; + DAT_TileMapState::instance.field_0x55487c = 200; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::forceFullTileMapRedraw, DAT_TileMapState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::processGameTick, DAT_GameState::ptr)(); + for (int section = 0; section < 40; ++section) { + MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateWildlifeGrid, DAT_WildlifeState::ptr)( + section); + } + MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateWildlife, DAT_WildlifeState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateSection1034Info, DAT_WildlifeState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateNofFpoints, DAT_WildlifeState::ptr)(); + MACRO_CALL_MEMBER( + OpenSHC::UI::MinimapViewState_Func::setTileColorsDependingOnMapSize, DAT_MinimapViewState::ptr)(0, 100); + MACRO_CALL_MEMBER(OpenSHC::UI::MinimapViewState_Func::setMapPropertyDependingOnMapSize, + DAT_MinimapViewState::ptr)(0, 100); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::setViewportBasedOnMapSize, + DAT_ViewportRenderState::ptr)(); + DAT_GameCore::instance.descriptionUseStringTable = 0; + DAT_GameCore::instance.U3_mapLockedState = OpenSHC::Map::MLS_EDITABLE; + DAT_GameCore::instance.temporaryTextBufferOfSize1000[0] = '\0'; + // both arms are the same; the original still compares U2_mapType_singleOrMulti here + if (DAT_GameCore::instance.U2_mapType_singleOrMulti == 1) { + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_MAP_EDITOR_PROPERTIES, 0); + } else { + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_MAP_EDITOR_PROPERTIES, 0); + } + DAT_GameCore::instance.mapLoadedForEditor = 1; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 0e33ee8d1d..925711c219 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -9159,7 +9159,7 @@ SHC_3BB0A8C1_0x0042F7E4 | 0.0% | Pending SHC_3BB0A8C1_0x0042F7F0 | 100.0% | Reimplemented, Security Cookie mismatches -SHC_3BB0A8C1_0x0042F940 | 0.0% | Pending +SHC_3BB0A8C1_0x0042F940 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0042FA10 | 0.0% | Pending From fea87907d67dc0541316d49925465b251d0274f2 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 20:08:38 +0100 Subject: [PATCH 07/15] reimplement: SHC_3BB0A8C1_0x004BAC90 100.0% Reimplemented MenuItemRenderFunction_EditScenario_StartDate draws the scenario editor's text buttons: -5 "Start Date" and -1 "Name" as centred labels, 0 nothing, and any other button its own scenario text, centred unless the button has no width. From gynt's draft (00717e801 on his fork's reimpl/UI-MenuItems, 79.73% there; earlier 20d58490c at 34.23%; his fork's reimpl/UI-MenuItems-development also has it in 8725ec523 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%")). The forms the original needs: the labels' position read y first (x first: quick_diff 0.9306 -> 0.8750), and the other buttons handled in the switch's default, which ends in a break: only then does MSVC share the two text calls' tail as the original does (no break, or the calls after the switch with early returns: 0.8784). Also: a switch for the nested ifs, COL_CCFAFF, TEXT_SCENARIO, decimals, and the texts named from cr.tex (the draft's comment called text 32 "Start Date"). quick_diff leaves only the colour immediates and ret / ret 0. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...mRenderFunction_EditScenario_StartDate.cpp | 63 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/EditScenario/MenuItemRenderFunction_EditScenario_StartDate.cpp diff --git a/src/OpenSHC/UI/MenuItems/EditScenario/MenuItemRenderFunction_EditScenario_StartDate.cpp b/src/OpenSHC/UI/MenuItems/EditScenario/MenuItemRenderFunction_EditScenario_StartDate.cpp new file mode 100644 index 0000000000..523061f37a --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/EditScenario/MenuItemRenderFunction_EditScenario_StartDate.cpp @@ -0,0 +1,63 @@ +#include "../EditScenario.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" + +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + namespace EditScenario { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BAC90 + void MenuItemRenderFunction_EditScenario_StartDate(int button, ...) + { + switch (button) { + case -5: { + // "Start Date"; y read before x as in the original (x first: quick_diff 0.9306 -> 0.8750) + int const labelY = DAT_ButtonY::instance + 6; + int const labelX = DAT_ButtonW::instance / 2 + DAT_ButtonX::instance; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SCENARIO, 39), + labelX, labelY, Text::TTA_CENTER, Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + break; + } + case -1: { + // "Name" + int const labelY = DAT_ButtonY::instance + 6; + int const labelX = DAT_ButtonW::instance / 2 + DAT_ButtonX::instance; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SCENARIO, 32), + labelX, labelY, Text::TTA_CENTER, Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + break; + } + case 0: + break; + default: + // any other button shows its own scenario text, centred unless the button has no width + if (DAT_ButtonW::instance == 0) { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + DE::SHCDE::TEXT_SCENARIO, button, DAT_ButtonX::instance, DAT_ButtonY::instance + 6, + Text::TTA_LEFT, Rendering::Colors::COL_CCFAFF, 18, FALSE); + } else { + MACRO_CALL_MEMBER(Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + DE::SHCDE::TEXT_SCENARIO, button, DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, + DAT_ButtonY::instance + 6, Text::TTA_CENTER, Rendering::Colors::COL_CCFAFF, 18, FALSE); + } + // the two calls share their tail only with this break (without it: quick_diff 0.9306 -> 0.8784) + break; + } + } + + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 925711c219..33f3146d5c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -29095,7 +29095,7 @@ SHC_3BB0A8C1_0x004BA980 | 0.0% | Pending SHC_3BB0A8C1_0x004BAC20 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004BAC90 | 0.0% | Pending +SHC_3BB0A8C1_0x004BAC90 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BAD70 | 0.0% | Pending From b5ba4de9a5df980e67e546f3dec8ca85121593cc Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 20:08:38 +0100 Subject: [PATCH 08/15] reimplement: SHC_3BB0A8C1_0x00492890 100.0% Reimplemented MenuItemActionHandler_SoundOptions_VolumeSlider handles the music, sound effects and speech sliders (0, 1, 2): event 1 sets the range 0 to 100 and reads the stored volume, 2 and 3 hand a changed volume to the slider's sound channels (0; 1, 2 and -1; 3 and 4) and store it, 4 reads the stored volume back. From gynt's draft (aca568dfc on his fork's reimpl/UI-MenuItems, 78.72% there; earlier 385b08745 at 58.06%; his fork's reimpl/UI-MenuItems-development also has it in 8725ec523 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%")). The form the original needs: the read-back written out in both event 1 and event 4, each switch in slider order 0, 1, 2; MSVC then shares their blocks between the two events the way the original does (one read-back after the switch: quick_diff 0.7797; slider 2 before 1 in event 4: 0.8136, as the two copies are then merged whole). Also: main's pendingStreamVolume names, slider and scrollbarEvent for the decompiler's names, no casts. quick_diff leaves only ret / ret 0. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...ctionHandler_SoundOptions_VolumeSlider.cpp | 87 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_VolumeSlider.cpp diff --git a/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_VolumeSlider.cpp b/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_VolumeSlider.cpp new file mode 100644 index 0000000000..3f31504832 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_VolumeSlider.cpp @@ -0,0 +1,87 @@ +#include "../SoundOptions.func.hpp" + +#include "OpenSHC/Audio/mss/SoundSystem.func.hpp" + +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + namespace SoundOptions { + + // FUNCTION: STRONGHOLDCRUSADER 0x00492890 + void MenuItemActionHandler_SoundOptions_VolumeSlider( + int slider, int scrollbarEvent, int* minValue, int* maxValue, int* currentValue) + { + switch (scrollbarEvent) { + case 1: + // the slider's range, then its stored volume + *minValue = 0; + *maxValue = 100; + switch (slider) { + case 0: + *currentValue = DAT_MenuTextInputState::instance.pendingStreamVolume0; + break; + case 1: + *currentValue = DAT_MenuTextInputState::instance.pendingStreamVolume1; + break; + case 2: + *currentValue = DAT_MenuTextInputState::instance.pendingStreamVolume3; + break; + } + return; + case 2: + case 3: + // A new volume goes to the slider's sound channels when it differs from the stored one. + switch (slider) { + case 0: + if (DAT_MenuTextInputState::instance.pendingStreamVolume0 != *currentValue) { + MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::setVolumeUnk, DAT_SoundSystemState::ptr)( + 0, *currentValue); + } + DAT_MenuTextInputState::instance.pendingStreamVolume0 = *currentValue; + return; + case 1: + if (DAT_MenuTextInputState::instance.pendingStreamVolume1 != *currentValue) { + MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::setVolumeUnk, DAT_SoundSystemState::ptr)( + 1, *currentValue); + MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::setVolumeUnk, DAT_SoundSystemState::ptr)( + 2, *currentValue); + MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::setVolumeUnk, DAT_SoundSystemState::ptr)( + -1, *currentValue); + } + DAT_MenuTextInputState::instance.pendingStreamVolume1 = *currentValue; + return; + case 2: + if (DAT_MenuTextInputState::instance.pendingStreamVolume3 != *currentValue) { + MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::setVolumeUnk, DAT_SoundSystemState::ptr)( + 3, *currentValue); + MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::setVolumeUnk, DAT_SoundSystemState::ptr)( + 4, *currentValue); + } + DAT_MenuTextInputState::instance.pendingStreamVolume3 = *currentValue; + return; + } + return; + case 4: + // the stored volume, as event 1 reads it + switch (slider) { + case 0: + *currentValue = DAT_MenuTextInputState::instance.pendingStreamVolume0; + break; + case 1: + *currentValue = DAT_MenuTextInputState::instance.pendingStreamVolume1; + break; + case 2: + *currentValue = DAT_MenuTextInputState::instance.pendingStreamVolume3; + break; + } + return; + } + } + + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 33f3146d5c..a6d2031777 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23489,7 +23489,7 @@ SHC_3BB0A8C1_0x00492660 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00492690 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00492890 | 0.0% | Pending +SHC_3BB0A8C1_0x00492890 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004929B0 | 0.0% | Pending From 9eae62a2a59d075b80bc3c6cfc36c477f09a5d24 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 20:13:34 +0100 Subject: [PATCH 09/15] headers: MapPropertiesState's message library fields are ints field_0x13590 was undefined4 and the 8 bytes after it one padding_0x13594[8]. MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons (0x004BA980) reads field_0x13590 as a signed page number (jge at 0x4BAB00 on the cmp eax, 3 at 0x4BAA15, and cmp eax, 4; jge at 0x4BAB0B) and the padding as two dwords, each compared with a button's offset: 0x13594 at 0x4BA9FD and 0x4BAA2A (cmp reg, dword ptr [0x1666dec]), 0x13598 at 0x4BAA08 (cmp eax, dword ptr [0x1666df0]). So the three are ints, like the page numbers and button offsets they are compared with: field_0x13590, field_0x13594 and field_0x13598. The struct's size is unchanged. No file on main reads them. Co-Authored-By: Claude Opus 5.5 --- src/OpenSHC/Map/MapPropertiesState.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState.hpp b/src/OpenSHC/Map/MapPropertiesState.hpp index 6c1f00e3d6..e386b996ba 100644 --- a/src/OpenSHC/Map/MapPropertiesState.hpp +++ b/src/OpenSHC/Map/MapPropertiesState.hpp @@ -84,8 +84,9 @@ namespace Map { int selectedAbsoluteIndex; // 0x00013584 length: 4 dword selectionTime; // 0x00013588 length: 4 undefined4 value; // 0x0001358C length: 4 - undefined4 field_0x13590; // 0x00013590 length: 4 - undefined1 padding_0x13594[8]; // 0x00013594 length: 8 + int field_0x13590; // 0x00013590 length: 4 + int field_0x13594; // 0x00013594 length: 4 + int field_0x13598; // 0x00013598 length: 4 undefined4 total; // 0x0001359C length: 4 int unknownArray_01[1000]; // 0x000135A0 length: 4000 undefined4 year_copy; // 0x00014540 length: 4 From 4e5029260a4cf4aa68a3c14e40f2f85731435b7b Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 20:14:24 +0100 Subject: [PATCH 10/15] reimplement: SHC_3BB0A8C1_0x004BA980 100.0% Reimplemented MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons draws the buttons of the unused message library: buttons 4 to 8 open its pages "Tutor" to "Characters" (field_0x13590 0 to 4), on "Adviser Prompts" buttons 9 and 10 show "Civil" and "Military", and on "Characters" the faces 1009 to 1012 stand in for buttons 9 to 12, with the face above the name. The open page's button and the entries chosen in field_0x13594 and field_0x13598 are drawn highlighted; buttons a page does not have set DAT_ButtonUnknownZero or are skipped. Written from the original's instructions, with gynt's draft (ef255f4f8 on his fork's reimpl/UI-MenuItems-development, 54.45% there; earlier 9c47863a5 at 30.39%) for the reads. Needs the header commit for the three MapPropertiesState fields. Behaviour fix: off the "Characters" page the original returns after face 1012 as after 1009 to 1011, where the draft fell through, which cleared DAT_ButtonUnknownZero again (pages 0 to 3) or drew the button (pages past 4). The forms the original needs: the highlight test as one condition, from which MSVC lays out the page tests and both copies of the "Civil" / "Military" remap and of the face as the original does, and the plain text as an if/else on the hover state, so that its first arm holds the text call's shared tail (an early return instead: quick_diff 0.9718 -> 0.8870). Also: no gotos or decompiler locals, decimals, COL_CCFAFF and COL_C2F0EB, the texts named from cr.tex. quick_diff leaves only the colour immediates and ret / ret 0. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...ction_UnusedCreateMessageEvent_Buttons.cpp | 126 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons.cpp diff --git a/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons.cpp b/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons.cpp new file mode 100644 index 0000000000..34dc5d2782 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons.cpp @@ -0,0 +1,126 @@ +#include "../Unused.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eGM.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/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BA980 + void Unused::MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons(int button, ...) + { + DAT_ButtonUnknownZero::instance = FALSE; + // The message library: buttons 4 to 8 open its pages, "Tutor" to "Characters". + // On "Characters" the faces 1009 to 1012 stand in for buttons 9 to 12; on the other pages they are off. + if (DAT_MapPropertiesState::instance.field_0x13590 == 4) { + if (button == 9 || button == 10 || button == 11 || button == 12) { + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + } else if (button == 1009 || button == 1010 || button == 1011 || button == 1012) { + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + // the open page's button and the entries chosen on pages 3 and 4 are drawn highlighted + if ((button <= 8 && button - 4 == DAT_MapPropertiesState::instance.field_0x13590) + || (DAT_MapPropertiesState::instance.field_0x13590 == 4 + && (((button <= 12 || button > 1000) + && button - 1009 == DAT_MapPropertiesState::instance.field_0x13594) + || button - 13 == DAT_MapPropertiesState::instance.field_0x13598)) + || (DAT_MapPropertiesState::instance.field_0x13590 == 3 && button <= 12 + && button - 8 == DAT_MapPropertiesState::instance.field_0x13594)) { + // on "Adviser Prompts" buttons 9 and 10 are "Civil" and "Military", 11 and 12 are off + if (DAT_MapPropertiesState::instance.field_0x13590 == 3 && button >= 9) { + if (button == 9) { + button = 24; + } else if (button == 10) { + button = 25; + } else { + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + } + DAT_ButtonCurrentlyInteracting::instance = TRUE; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (DAT_MapPropertiesState::instance.field_0x13590 == 4 + && (button == 1009 || button == 1010 || button == 1011 || button == 1012)) { + // a character's face above its name + button -= 1000; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_ENEMY_FACES, button - 8, + DAT_ButtonW::instance / 2 - 32 + DAT_ButtonX::instance, DAT_ButtonY::instance + 7); + DAT_ButtonY::instance += 72; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, button, DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, + DAT_ButtonY::instance + 6, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, + FALSE); + return; + } + // pages 0 to 2 have no buttons past 8, page 3 none past 12 + if (DAT_MapPropertiesState::instance.field_0x13590 < 3 && button >= 9) { + return; + } + if (DAT_MapPropertiesState::instance.field_0x13590 < 4 && button >= 13) { + return; + } + if (DAT_MapPropertiesState::instance.field_0x13590 == 3 && button >= 9) { + if (button == 9) { + button = 24; + } else if (button == 10) { + button = 25; + } else { + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + } + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (DAT_MapPropertiesState::instance.field_0x13590 == 4 + && (button == 1009 || button == 1010 || button == 1011 || button == 1012)) { + button -= 1000; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::DE::SHCDE::GM_ENEMY_FACES, button - 8, + DAT_ButtonW::instance / 2 - 32 + DAT_ButtonX::instance, DAT_ButtonY::instance + 7); + DAT_ButtonY::instance += 72; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + } + if (!DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, button, DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, + DAT_ButtonY::instance + 6, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, + FALSE); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_SCENARIO, button, DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, + DAT_ButtonY::instance + 6, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, + FALSE); + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a6d2031777..532342ef9e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -29091,7 +29091,7 @@ SHC_3BB0A8C1_0x004BA8B0 | 0.0% | Pending SHC_3BB0A8C1_0x004BA910 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004BA980 | 0.0% | Pending +SHC_3BB0A8C1_0x004BA980 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BAC20 | 100.0% | Reimplemented From 0ce12432ddcc68411294084d92468ab312624a93 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 21:34:23 +0100 Subject: [PATCH 11/15] reimplement: SHC_3BB0A8C1_0x00439160 100.0% Reimplemented MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops draws one portrait of the build menu's selected-troops bar: nothing while no own unit is selected or the slot is empty (-1), otherwise the slot's troop portrait, nudged into place per troop type, with the number of selected units of that type under the button. The Arabian troops (19 on) take their portraits from a second set further along the button table. From gynt's draft (dd1a7c48c on his fork's reimpl/UI-MenuItems-development, 47.7% there after his 8725ec523; earlier 343a1acb9 at 44.53% and 81353103a at 35.71%). The form the original needs: every troop type its own case, with cases 7 and 25 repeating case 2 and case 24 repeating case 20 instead of sharing their labels and no case falling through into the next. MSVC then copies the >= 19 test into every case, shares the identical tails afterwards and builds one dword jump table, as the original does (shared labels and fall-throughs: quick_diff 0.7640, with a byte table in front of the jump table). Also: the cases in order and named after their troops from RenderingDefinedData::SelectionSlotUnitTypes, TRUE and FALSE for DAT_ButtonUnknownZero. quick_diff leaves only the colour immediate, the jump table's label and ret / ret 0. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...tion_BuildMenu_CurrentlySelectedTroops.cpp | 120 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops.cpp diff --git a/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops.cpp b/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops.cpp new file mode 100644 index 0000000000..5ad2682c9f --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops.cpp @@ -0,0 +1,120 @@ +#include "../BuildMenu.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/MenuItems/General.func.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" + +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonGmDataIndex.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + namespace BuildMenu { + + // FUNCTION: STRONGHOLDCRUSADER 0x00439160 + void MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops(int slot, ...) + { + if (DAT_UnitsState::instance.nHasOwnedUnitInSelection == 0) { + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + // an index into RenderingDefinedData::SelectionSlotUnitTypes + int const troopType = DAT_UnitsState::instance.selectionSlots[slot]; + DAT_ButtonUnknownZero::instance = FALSE; + if (troopType == -1) { + DAT_ButtonUnknownZero::instance = TRUE; + DAT_ButtonCurrentlyInteracting::instance = FALSE; + return; + } + // The count goes under the button where it was before the portrait is moved into place. + int const buttonY = DAT_ButtonY::instance; + int const buttonX = DAT_ButtonX::instance; + // no shared labels or fall-throughs, so MSVC copies the >= 19 test into each case as the original + switch (troopType) { + case 0: // archer + DAT_ButtonY::instance -= 14; + break; + case 1: // spearman + DAT_ButtonX::instance -= 3; + break; + case 2: // maceman + DAT_ButtonX::instance += 1; + break; + case 4: // pikeman + DAT_ButtonX::instance += 2; + DAT_ButtonY::instance -= 20; + break; + case 5: // swordsman + DAT_ButtonX::instance += 1; + DAT_ButtonY::instance -= 8; + break; + case 6: // knight + DAT_ButtonY::instance -= 20; + DAT_ButtonX::instance -= 7; + break; + case 7: // engineer + DAT_ButtonX::instance += 1; + break; + case 8: // ladderman + DAT_ButtonY::instance -= 8; + break; + case 9: // tunneler + DAT_ButtonY::instance -= 19; + break; + case 17: // ballista + DAT_ButtonY::instance -= 4; + break; + case 19: // Arabian archer + DAT_ButtonY::instance -= 8; + DAT_ButtonX::instance += 2; + break; + case 20: // slave + DAT_ButtonY::instance -= 9; + DAT_ButtonX::instance += 1; + break; + case 21: // slinger + DAT_ButtonY::instance -= 7; + break; + case 22: // assassin + DAT_ButtonY::instance -= 1; + break; + case 23: // horse archer + DAT_ButtonY::instance -= 13; + DAT_ButtonX::instance -= 6; + break; + case 24: // Arabian swordsman + DAT_ButtonY::instance -= 9; + DAT_ButtonX::instance += 1; + break; + case 25: // fire thrower + DAT_ButtonX::instance += 1; + break; + case 26: // fire ballista + DAT_ButtonX::instance -= 6; + break; + } + // The Arabian troops' portraits (19 on) are a second set further along the button table. + if (troopType >= 19) { + DAT_CurrentButtonGmDataIndex::instance = troopType + 521; + } else { + DAT_CurrentButtonGmDataIndex::instance = troopType + 380; + } + MACRO_CALL(General_Func:: + MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface)(); + MACRO_CALL_MEMBER(Text::TextManager_Func::renderNumber2, DAT_TextManagerObject::ptr)( + DAT_UnitsState::instance.selectionUnitType[troopType], DAT_ButtonW::instance / 2 + buttonX, + buttonY + 83, Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_FFFFFF, 0, 17, FALSE, 0); + } + + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 532342ef9e..d705116c8c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -13301,7 +13301,7 @@ SHC_3BB0A8C1_0x00439150 | 0.0% | Pending SHC_3BB0A8C1_0x00439151 | 0.0% | Pending -SHC_3BB0A8C1_0x00439160 | 0.0% | Pending +SHC_3BB0A8C1_0x00439160 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00439318 | 0.0% | Pending From 8682d0952934e09e66a540807e85feb80a94c08b Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 21:34:24 +0100 Subject: [PATCH 12/15] reimplement: SHC_3BB0A8C1_0x00466320 100.0% Reimplemented MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton draws the repair button of a building's menu: it sets DAT_ButtonUnknownZero for another player's building, is drawn disabled (renderBasicButton's 8, a dimmed button, and a grey "Repair") when the building has no damage to repair or an enemy is within 30 (15 in a multiplayer game), and otherwise drawn live with the hover colour. From gynt's draft (ef06bee7a on his fork's reimpl/UI-MenuItems, 52.48% there; earlier de4fae5d4 at 50.35%; his reimpl/UI-MenuItems-development copy last measured in 8725ec523, then restyled in 50849804c). The forms the original needs: the disabled test kept in a flag that is tested twice, once for the button and once for the text, so that MSVC lays the disabled button out first and folds the second test into both arms (one if/else holding the texts: quick_diff 0.6994; a colour variable: 0.7368), and the text's position read in each of the three text arms (once before them: 0.6623; in the calls: 0.8395). Also: main's sibling handler's names (notDamaged, requiredDistance), unused for the parameter, TRUE and FALSE for DAT_ButtonUnknownZero, COL_7CAAAF, COL_C2F0EB and COL_CCFAFF, decimals. quick_diff leaves only the colour immediates and ret / ret 0. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- ...dingAndStatusMenu_RepairBuildingButton.cpp | 97 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton.cpp diff --git a/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton.cpp b/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton.cpp new file mode 100644 index 0000000000..0bcc6baa0f --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton.cpp @@ -0,0 +1,97 @@ +#include "../BuildingAndStatusMenu.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + namespace BuildingAndStatusMenu { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00466320 + void MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton(int unused, ...) + { + int const buildingID = DAT_BuildingsState::instance.menuSelectedBuildingID; + BOOLEnum notDamaged = FALSE; + DAT_ButtonUnknownZero::instance = FALSE; + if (DAT_BuildingsState::instance.buildings[buildingID].owner + != DAT_GameSynchronyState::instance.currentPlayerSlotID) { + DAT_ButtonUnknownZero::instance = TRUE; + } + if (!MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::updateRepairCostAndReturnIfDamaged, + DAT_BuildingsState::ptr)(buildingID)) { + notDamaged = TRUE; + } + // The button is live when there is damage to repair and no enemy is within 30 (15 in a multiplayer + // game). + int requiredDistance; + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + requiredDistance = 15; + } else { + requiredDistance = 30; + } + // tested twice through a flag, so MSVC lays the disabled arm out first as the original does + BOOLEnum const disabled + = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, + DAT_PathFindingState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].owner, + DAT_BuildingsState::instance.buildings[buildingID].x, + DAT_BuildingsState::instance.buildings[buildingID].y, requiredDistance) + || notDamaged; + if (disabled) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + MACRO_CALL_MEMBER(Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(8, OpenSHC::Rendering::Enums::RT_SCREEN_MENU); + } else { + MACRO_CALL_MEMBER(Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_SCREEN_MENU); + } + // "Repair", with the position read in each arm as the original does + if (disabled) { + int const textX = DAT_ButtonW::instance / 2 + DAT_ButtonX::instance; + int const textY = DAT_ButtonY::instance + 7; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_BUBBLE_HELP_TEXT, 257), + textX, textY, Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_7CAAAF, 18, FALSE, 0); + } else if (!DAT_ButtonCurrentlyInteracting::instance) { + int const textX = DAT_ButtonW::instance / 2 + DAT_ButtonX::instance; + int const textY = DAT_ButtonY::instance + 7; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_BUBBLE_HELP_TEXT, 257), + textX, textY, Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE, 0); + } else { + int const textX = DAT_ButtonW::instance / 2 + DAT_ButtonX::instance; + int const textY = DAT_ButtonY::instance + 7; + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_BUBBLE_HELP_TEXT, 257), + textX, textY, Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, 0); + } + } + + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d705116c8c..8bf3493387 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -19937,7 +19937,7 @@ SHC_3BB0A8C1_0x00466160 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00466260 | 0.0% | Pending -SHC_3BB0A8C1_0x00466320 | 0.0% | Pending +SHC_3BB0A8C1_0x00466320 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00466430 | 0.0% | Pending From 3d0ba0f987c86eba84fd7e2ea9c941deabbb9f0d Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 21:06:15 +0100 Subject: [PATCH 13/15] reimplement: SHC_3BB0A8C1_0x005119D0 100.0% Reimplemented HoveredState::calculateHoveredTile, from gynt's drafts (9dedc438e, 65.8%, in his closed #256; 63e2b092f, 65.83%, on his fork's archive/UI-MenuViews branches; 66.5% in 10280b161 on his fork's reimpl/UI-Core-development), rewritten from the binary as one for-loop over the elements with a switch on the mapper type. The flag's picture and offsets are locals that keep their values from one element to the next, as in the original; the cases are in the original's block order (mangonel, ballista, brazier, flags, heads, siege tents, then building previews) and the orientation cases in the order 0, 4, 2, 6. The draft stepped its element pointer by six elements. In the siege-tent case the tile is stepped (++x / --x) before the picture's x offset is set, as the original's instruction order has it, which gives its register pair (x in ecx, the offset in edx). reccmp 100.0%. Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../UI/HoveredState/calculateHoveredTile.cpp | 151 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/HoveredState/calculateHoveredTile.cpp diff --git a/src/OpenSHC/UI/HoveredState/calculateHoveredTile.cpp b/src/OpenSHC/UI/HoveredState/calculateHoveredTile.cpp new file mode 100644 index 0000000000..614883b628 --- /dev/null +++ b/src/OpenSHC/UI/HoveredState/calculateHoveredTile.cpp @@ -0,0 +1,151 @@ +#include "../HoveredState.func.hpp" + +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace UI { + + using namespace OpenSHC::Commands; + using namespace OpenSHC::IO::Graphics; + + // FUNCTION: STRONGHOLDCRUSADER 0x005119D0 + void HoveredState::calculateHoveredTile() + { + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY) { + return; + } + int imageID = 0; + int flagX = 0; + int flagY = 0; + int const rotation = DAT_TileMapState::instance.uiBuildingRotation; + for (int i = 0; i < countof(this->elements); ++i) { + if (this->elements[i].type == M_MAPPER_NULL) { + continue; + } + switch (this->elements[i].type) { + case M_MAPPER_MANGONEL: + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, + DAT_ViewportRenderState::ptr)(GID_BODY_MANGONEL, 1, 0, 0, + DAT_ViewportRenderState::instance.translationMatrix[this->elements[i].y].addXgetTile + + this->elements[i].x, + 5); + break; + case M_MAPPER_BALLISTA: + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, + DAT_ViewportRenderState::ptr)(GID_BODY_BALLISTA, 1, 0, 0, + DAT_ViewportRenderState::instance.translationMatrix[this->elements[i].y].addXgetTile + + this->elements[i].x, + 5); + break; + case M_MAPPER_BRAZIER: + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, + DAT_ViewportRenderState::ptr)(GID_BODY_BRAZIER, 1, 15, 7, + DAT_ViewportRenderState::instance.translationMatrix[this->elements[i].y].addXgetTile + + this->elements[i].x, + 29); + break; + case M_MAPPER_FLAG_TYPE0: + case M_MAPPER_FLAG_TYPE1: + case M_MAPPER_FLAG_TYPE2: + case M_MAPPER_FLAG_TYPE3: { + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->elements[i].y].addXgetTile + + this->elements[i].x; + switch (this->elements[i].type) { + case M_MAPPER_FLAG_TYPE0: + imageID = 9; + flagX = 15; + flagY = 7; + break; + case M_MAPPER_FLAG_TYPE1: + imageID = 41; + flagX = 15; + flagY = -2; + break; + case M_MAPPER_FLAG_TYPE2: + imageID = 73; + flagX = 6; + flagY = 6; + break; + case M_MAPPER_FLAG_TYPE3: + imageID = 105; + flagX = 6; + flagY = 7; + break; + } + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, + DAT_ViewportRenderState::ptr)(GID_ANIM_FLAGS, imageID, flagX, flagY, tile, 13); + break; + } + case M_MAPPER_HEADS: + imageID = this->elements[i].size + 1; + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, + DAT_ViewportRenderState::ptr)(GID_ANIM_HEADS, imageID, 15, 7, + DAT_ViewportRenderState::instance.translationMatrix[this->elements[i].y].addXgetTile + + this->elements[i].x, + 29); + break; + case M_MAPPER_CATAPULT: + case M_MAPPER_TREBUCHET: + case M_MAPPER_SIEGE_TOWER: + case M_MAPPER_BATTERING_RAM: + case M_MAPPER_PORTABLE_SHIELD: + case M_MAPPER_ARAB_BALLISTA: { + // siege equipment shows its tent on the tile in front, by the map's orientation + int x = this->elements[i].x; + int y = this->elements[i].y; + int imageX = 0; + int imageY = 0; + switch (DAT_TileMapState::instance.mapOrientation) { + case 0: + ++x; + imageX = 13; + ++y; + imageY = 2; + break; + case 4: + --x; + imageX = 13; + imageY = -30; + --y; + break; + case 2: + --x; + imageX = 45; + ++y; + imageY = -14; + break; + case 6: + ++x; + imageX = -19; + imageY = -12; + --y; + break; + } + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, + DAT_ViewportRenderState::ptr)(GID_BODY_TENT, 1, imageX, imageY, + DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x, 5); + break; + } + default: + // any other mapper is a building placement preview, in the element's rotation + DAT_TileMapState::instance.skipPlacementFailChecks = 1; + DAT_TileMapState::instance.uiBuildingRotation = this->elements[i].rotationOrExtraInfo; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setConstructionGFXLayerBasedOnPlacementChecks, + DAT_TileMapState::ptr)(this->elements[i].x, this->elements[i].y, + (MappersEnum)(ushort)this->elements[i].type, this->elements[i].size); + break; + } + } + DAT_TileMapState::instance.uiBuildingRotation = rotation; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 8bf3493387..b884b6ce19 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -44205,7 +44205,7 @@ SHC_3BB0A8C1_0x005119B4 | 0.0% | Pending SHC_3BB0A8C1_0x005119C0 | 0.0% | Pending -SHC_3BB0A8C1_0x005119D0 | 0.0% | Pending +SHC_3BB0A8C1_0x005119D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00511A10 | 0.0% | Pending From c60ed7c1793e7260013ac3c7498cfbdd7e171360 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 9 Nov 2026 22:37:09 +0100 Subject: [PATCH 14/15] UI round: enum names, measured comments, early returns, names after main's siblings - CurrentlySelectedTroops render: the troop type is a UnitSelectionEnumInt with main's USE_* names as the case labels and the Arabian test, slotID as in the sibling handler, and the kept shape's comment gives its measurement. - AlliesOrder render: the TEXT_ALLIES texts in comments ("Clear Orders", "Defend Me", "Attack") and the AI's name; the comment on the row and player is one line. - ViewToKeeps: `unused` for the first parameter, the wheel directions the right way round (7 is the wheel turned down, as main's updateMouseStateBasedOnCursorAndTime sets it for a negative delta), and early returns for the last block. - NewMapMapsize_Buttons: FALSE/TRUE for the two BOOLEnum fields, `row` as main's twin names the wildlife loop, and the two kept shapes say what they measure. - calculateHoveredTile: names qualified instead of two `using namespace` lines, and one line each on the locals kept across the loop and the type passed as a word. - RepairBuildingButton, UnusedCreateMessageEvent_Buttons, SoundOptions_VolumeSlider: the kept shapes give their measurements in main's one-line form; VolumeSlider loses a trailing return. quick_diff output is identical for all nine files. Tried and lost: mapSize set after NewMapMapsize's early returns (0.9704 -> 0.9586), calculateHoveredTile's locals at their first use (0.9690 -> 0.6590). Co-authored-by: Gynt Co-Authored-By: Claude Opus 5.5 --- .../UI/HoveredState/calculateHoveredTile.cpp | 57 +++++++++---------- ...enuItemRenderFunction_AlliesOrder_Main.cpp | 7 ++- ...tion_BuildMenu_CurrentlySelectedTroops.cpp | 50 ++++++++-------- ...dingAndStatusMenu_RepairBuildingButton.cpp | 4 +- ...emActionHandler_InGameMenu_ViewToKeeps.cpp | 42 +++++++------- ...temActionHandler_NewMapMapsize_Buttons.cpp | 13 ++--- ...ctionHandler_SoundOptions_VolumeSlider.cpp | 3 +- ...ction_UnusedCreateMessageEvent_Buttons.cpp | 2 + 8 files changed, 92 insertions(+), 86 deletions(-) diff --git a/src/OpenSHC/UI/HoveredState/calculateHoveredTile.cpp b/src/OpenSHC/UI/HoveredState/calculateHoveredTile.cpp index 614883b628..d2f2251753 100644 --- a/src/OpenSHC/UI/HoveredState/calculateHoveredTile.cpp +++ b/src/OpenSHC/UI/HoveredState/calculateHoveredTile.cpp @@ -13,91 +13,89 @@ namespace OpenSHC { namespace UI { - using namespace OpenSHC::Commands; - using namespace OpenSHC::IO::Graphics; - // FUNCTION: STRONGHOLDCRUSADER 0x005119D0 void HoveredState::calculateHoveredTile() { if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY) { return; } + // kept across the loop, as in the original (declared at first use: quick_diff 0.9690 -> 0.6590) int imageID = 0; int flagX = 0; int flagY = 0; int const rotation = DAT_TileMapState::instance.uiBuildingRotation; for (int i = 0; i < countof(this->elements); ++i) { - if (this->elements[i].type == M_MAPPER_NULL) { + if (this->elements[i].type == Commands::M_MAPPER_NULL) { continue; } switch (this->elements[i].type) { - case M_MAPPER_MANGONEL: + case Commands::M_MAPPER_MANGONEL: MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, - DAT_ViewportRenderState::ptr)(GID_BODY_MANGONEL, 1, 0, 0, + DAT_ViewportRenderState::ptr)(IO::Graphics::GID_BODY_MANGONEL, 1, 0, 0, DAT_ViewportRenderState::instance.translationMatrix[this->elements[i].y].addXgetTile + this->elements[i].x, 5); break; - case M_MAPPER_BALLISTA: + case Commands::M_MAPPER_BALLISTA: MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, - DAT_ViewportRenderState::ptr)(GID_BODY_BALLISTA, 1, 0, 0, + DAT_ViewportRenderState::ptr)(IO::Graphics::GID_BODY_BALLISTA, 1, 0, 0, DAT_ViewportRenderState::instance.translationMatrix[this->elements[i].y].addXgetTile + this->elements[i].x, 5); break; - case M_MAPPER_BRAZIER: + case Commands::M_MAPPER_BRAZIER: MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, - DAT_ViewportRenderState::ptr)(GID_BODY_BRAZIER, 1, 15, 7, + DAT_ViewportRenderState::ptr)(IO::Graphics::GID_BODY_BRAZIER, 1, 15, 7, DAT_ViewportRenderState::instance.translationMatrix[this->elements[i].y].addXgetTile + this->elements[i].x, 29); break; - case M_MAPPER_FLAG_TYPE0: - case M_MAPPER_FLAG_TYPE1: - case M_MAPPER_FLAG_TYPE2: - case M_MAPPER_FLAG_TYPE3: { + case Commands::M_MAPPER_FLAG_TYPE0: + case Commands::M_MAPPER_FLAG_TYPE1: + case Commands::M_MAPPER_FLAG_TYPE2: + case Commands::M_MAPPER_FLAG_TYPE3: { int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->elements[i].y].addXgetTile + this->elements[i].x; switch (this->elements[i].type) { - case M_MAPPER_FLAG_TYPE0: + case Commands::M_MAPPER_FLAG_TYPE0: imageID = 9; flagX = 15; flagY = 7; break; - case M_MAPPER_FLAG_TYPE1: + case Commands::M_MAPPER_FLAG_TYPE1: imageID = 41; flagX = 15; flagY = -2; break; - case M_MAPPER_FLAG_TYPE2: + case Commands::M_MAPPER_FLAG_TYPE2: imageID = 73; flagX = 6; flagY = 6; break; - case M_MAPPER_FLAG_TYPE3: + case Commands::M_MAPPER_FLAG_TYPE3: imageID = 105; flagX = 6; flagY = 7; break; } MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, - DAT_ViewportRenderState::ptr)(GID_ANIM_FLAGS, imageID, flagX, flagY, tile, 13); + DAT_ViewportRenderState::ptr)(IO::Graphics::GID_ANIM_FLAGS, imageID, flagX, flagY, tile, 13); break; } - case M_MAPPER_HEADS: + case Commands::M_MAPPER_HEADS: imageID = this->elements[i].size + 1; MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, - DAT_ViewportRenderState::ptr)(GID_ANIM_HEADS, imageID, 15, 7, + DAT_ViewportRenderState::ptr)(IO::Graphics::GID_ANIM_HEADS, imageID, 15, 7, DAT_ViewportRenderState::instance.translationMatrix[this->elements[i].y].addXgetTile + this->elements[i].x, 29); break; - case M_MAPPER_CATAPULT: - case M_MAPPER_TREBUCHET: - case M_MAPPER_SIEGE_TOWER: - case M_MAPPER_BATTERING_RAM: - case M_MAPPER_PORTABLE_SHIELD: - case M_MAPPER_ARAB_BALLISTA: { + case Commands::M_MAPPER_CATAPULT: + case Commands::M_MAPPER_TREBUCHET: + case Commands::M_MAPPER_SIEGE_TOWER: + case Commands::M_MAPPER_BATTERING_RAM: + case Commands::M_MAPPER_PORTABLE_SHIELD: + case Commands::M_MAPPER_ARAB_BALLISTA: { // siege equipment shows its tent on the tile in front, by the map's orientation int x = this->elements[i].x; int y = this->elements[i].y; @@ -130,7 +128,7 @@ namespace UI { break; } MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, - DAT_ViewportRenderState::ptr)(GID_BODY_TENT, 1, imageX, imageY, + DAT_ViewportRenderState::ptr)(IO::Graphics::GID_BODY_TENT, 1, imageX, imageY, DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x, 5); break; } @@ -138,9 +136,10 @@ namespace UI { // any other mapper is a building placement preview, in the element's rotation DAT_TileMapState::instance.skipPlacementFailChecks = 1; DAT_TileMapState::instance.uiBuildingRotation = this->elements[i].rotationOrExtraInfo; + // the type goes as a word (movzx), though the header's parameter is a MappersEnum MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setConstructionGFXLayerBasedOnPlacementChecks, DAT_TileMapState::ptr)(this->elements[i].x, this->elements[i].y, - (MappersEnum)(ushort)this->elements[i].type, this->elements[i].size); + (Commands::MappersEnum)(ushort)this->elements[i].type, this->elements[i].size); break; } } diff --git a/src/OpenSHC/UI/MenuItems/AlliesOrder/MenuItemRenderFunction_AlliesOrder_Main.cpp b/src/OpenSHC/UI/MenuItems/AlliesOrder/MenuItemRenderFunction_AlliesOrder_Main.cpp index f599a1497e..72ba4ee430 100644 --- a/src/OpenSHC/UI/MenuItems/AlliesOrder/MenuItemRenderFunction_AlliesOrder_Main.cpp +++ b/src/OpenSHC/UI/MenuItems/AlliesOrder/MenuItemRenderFunction_AlliesOrder_Main.cpp @@ -47,19 +47,20 @@ namespace UI { OpenSHC::UI::Rendering_Func::RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurrentSurfaceUnk)(); if (DAT_ButtonCurrentlyInteracting::instance) { if (button == 10) { + // "Clear Orders" DAT_00df5200::instance = OpenSHC::DE::SHCDE::TEXT_ALLIES; DAT_00df51fc::instance = 8; return; } if (button == 11) { + // "Defend Me" DAT_00df5200::instance = OpenSHC::DE::SHCDE::TEXT_ALLIES; DAT_00df51fc::instance = 9; return; } } } - // buttons 1 to 6 are the enemies' portraits; the original reuses button for the row and then the player, - // and draws the tooltip when it ends up -1, which button 0 also gives + // buttons 1 to 6 are the enemies' portraits; button turns into the row, then the player (one register) if (button <= 6 && button != -1) { --button; if (button >= DAT_EnemyArrayIndex::instance) { @@ -107,6 +108,7 @@ namespace UI { DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 574, DAT_ButtonX::instance - 10, DAT_ButtonY::instance - 8, OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 575, 0); + // "Attack" DAT_00df5200::instance = OpenSHC::DE::SHCDE::TEXT_ALLIES; DAT_00df51fc::instance = 10; DAT_00df51f8::instance = button; @@ -137,6 +139,7 @@ namespace UI { DAT_TextManagerObject::instance.textSurfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; return; } + // the AI's name MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText, DAT_TextManagerObject::ptr)( OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, DAT_GameSynchronyState::instance.currentAIArray[DAT_00df51f8::instance] * 8 diff --git a/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops.cpp b/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops.cpp index 5ad2682c9f..817c768cf0 100644 --- a/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops.cpp +++ b/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops.cpp @@ -2,6 +2,8 @@ #include "OpenSHC/Text/TextManager.func.hpp" #include "OpenSHC/UI/MenuItems/General.func.hpp" +#include "OpenSHC/Map/Units/Selection/UnitSelectionEnum.hpp" +#include "OpenSHC/Map/Units/Selection/UnitSelectionEnumInt.hpp" #include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" #include "OpenSHC/Text/TextAlignment.hpp" @@ -20,14 +22,14 @@ namespace UI { namespace BuildMenu { // FUNCTION: STRONGHOLDCRUSADER 0x00439160 - void MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops(int slot, ...) + void MenuItemRenderFunction_BuildMenu_CurrentlySelectedTroops(int slotID, ...) { if (DAT_UnitsState::instance.nHasOwnedUnitInSelection == 0) { DAT_ButtonUnknownZero::instance = TRUE; return; } - // an index into RenderingDefinedData::SelectionSlotUnitTypes - int const troopType = DAT_UnitsState::instance.selectionSlots[slot]; + Map::Units::Selection::UnitSelectionEnumInt const troopType + = DAT_UnitsState::instance.selectionSlots[slotID]; DAT_ButtonUnknownZero::instance = FALSE; if (troopType == -1) { DAT_ButtonUnknownZero::instance = TRUE; @@ -37,72 +39,72 @@ namespace UI { // The count goes under the button where it was before the portrait is moved into place. int const buttonY = DAT_ButtonY::instance; int const buttonX = DAT_ButtonX::instance; - // no shared labels or fall-throughs, so MSVC copies the >= 19 test into each case as the original + // Each troop its own case (shared labels and fall-throughs: quick_diff 0.9457 -> 0.7640) switch (troopType) { - case 0: // archer + case Map::Units::Selection::USE_E_ARCHERS: DAT_ButtonY::instance -= 14; break; - case 1: // spearman + case Map::Units::Selection::USE_E_SPEARMEN: DAT_ButtonX::instance -= 3; break; - case 2: // maceman + case Map::Units::Selection::USE_E_MACEMEN: DAT_ButtonX::instance += 1; break; - case 4: // pikeman + case Map::Units::Selection::USE_E_PIKEMEN: DAT_ButtonX::instance += 2; DAT_ButtonY::instance -= 20; break; - case 5: // swordsman + case Map::Units::Selection::USE_E_SWORDSMEN: DAT_ButtonX::instance += 1; DAT_ButtonY::instance -= 8; break; - case 6: // knight + case Map::Units::Selection::USE_E_KNIGHTS: DAT_ButtonY::instance -= 20; DAT_ButtonX::instance -= 7; break; - case 7: // engineer + case Map::Units::Selection::USE_E_ENGINEERS: DAT_ButtonX::instance += 1; break; - case 8: // ladderman + case Map::Units::Selection::USE_E_LADDERMEN: DAT_ButtonY::instance -= 8; break; - case 9: // tunneler + case Map::Units::Selection::USE_E_TUNNELERS: DAT_ButtonY::instance -= 19; break; - case 17: // ballista + case Map::Units::Selection::USE_E_BALLISTAS: DAT_ButtonY::instance -= 4; break; - case 19: // Arabian archer + case Map::Units::Selection::USE_A_ARAB_ARCHERS: DAT_ButtonY::instance -= 8; DAT_ButtonX::instance += 2; break; - case 20: // slave + case Map::Units::Selection::USE_A_SLAVES: DAT_ButtonY::instance -= 9; DAT_ButtonX::instance += 1; break; - case 21: // slinger + case Map::Units::Selection::USE_A_SLINGERS: DAT_ButtonY::instance -= 7; break; - case 22: // assassin + case Map::Units::Selection::USE_A_ASSASSINS: DAT_ButtonY::instance -= 1; break; - case 23: // horse archer + case Map::Units::Selection::USE_A_HORSE_ARCHERS: DAT_ButtonY::instance -= 13; DAT_ButtonX::instance -= 6; break; - case 24: // Arabian swordsman + case Map::Units::Selection::USE_A_SWORDSMEN: DAT_ButtonY::instance -= 9; DAT_ButtonX::instance += 1; break; - case 25: // fire thrower + case Map::Units::Selection::USE_A_FIRETHROWERS: DAT_ButtonX::instance += 1; break; - case 26: // fire ballista + case Map::Units::Selection::USE_A_FIRE_BALLISTAS: DAT_ButtonX::instance -= 6; break; } - // The Arabian troops' portraits (19 on) are a second set further along the button table. - if (troopType >= 19) { + // The Arabian troops' portraits are a second set further along the button table. + if (troopType >= Map::Units::Selection::USE_A_ARAB_ARCHERS) { DAT_CurrentButtonGmDataIndex::instance = troopType + 521; } else { DAT_CurrentButtonGmDataIndex::instance = troopType + 380; diff --git a/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton.cpp b/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton.cpp index 0bcc6baa0f..f67d4a2533 100644 --- a/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton.cpp +++ b/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_RepairBuildingButton.cpp @@ -51,7 +51,7 @@ namespace UI { } else { requiredDistance = 30; } - // tested twice through a flag, so MSVC lays the disabled arm out first as the original does + // The flag is tested twice (one if/else holding the texts: quick_diff 0.9481 -> 0.6994) BOOLEnum const disabled = MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, DAT_PathFindingState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].owner, @@ -66,7 +66,7 @@ namespace UI { MACRO_CALL_MEMBER(Rendering::AlphaAndButtonSurface_Func::renderBasicButton, AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_SCREEN_MENU); } - // "Repair", with the position read in each arm as the original does + // "Repair"; the position in each arm (once before them: quick_diff 0.9481 -> 0.6623) if (disabled) { int const textX = DAT_ButtonW::instance / 2 + DAT_ButtonX::instance; int const textY = DAT_ButtonY::instance + 7; diff --git a/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp index 7339543416..7f189b7590 100644 --- a/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp +++ b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp @@ -19,12 +19,12 @@ namespace UI { namespace MenuItems { // FUNCTION: STRONGHOLDCRUSADER 0x004335A0 - void InGameMenu::MenuItemActionHandler_InGameMenu_ViewToKeeps(int param_1, ...) + void InGameMenu::MenuItemActionHandler_InGameMenu_ViewToKeeps(int unused, ...) { if (DAT_MenuModalComposition1::instance.activeModalDialogID != OpenSHC::UI::Enums::MMT_NONE) { return; } - // two wheel steps within a second count as one move: up views the next keep, down the own keep + // two wheel steps within a second count as one move: down views the next keep, up the own keep DWORD const now = timeGetTime(); if (now - DWORD_00b98410::instance > 1000) { DWORD_00b98410::instance = now; @@ -69,24 +69,26 @@ namespace UI { } } } - if (DAT_MouseState::instance.scrollEventData == 8) { - if (DAT_00b9840c::instance > 0) { - DAT_00b9840c::instance = 0; - } - --DAT_00b9840c::instance; - if (DAT_00b9840c::instance == -2) { - DWORD_00b98410::instance = now; - int const keep - = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] - .id; - DAT_00b9840c::instance = 0; - if (keep != 0) { - MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, - DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[keep].x + 2, - DAT_BuildingsState::instance.buildings[keep].y + 2); - } - } + if (DAT_MouseState::instance.scrollEventData != 8) { + return; + } + if (DAT_00b9840c::instance > 0) { + DAT_00b9840c::instance = 0; + } + --DAT_00b9840c::instance; + if (DAT_00b9840c::instance != -2) { + return; + } + DWORD_00b98410::instance = now; + int const keep + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id; + DAT_00b9840c::instance = 0; + if (keep != 0) { + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, + DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[keep].x + 2, + DAT_BuildingsState::instance.buildings[keep].y + 2); } } diff --git a/src/OpenSHC/UI/MenuItems/NewMapMapsize/MenuItemActionHandler_NewMapMapsize_Buttons.cpp b/src/OpenSHC/UI/MenuItems/NewMapMapsize/MenuItemActionHandler_NewMapMapsize_Buttons.cpp index 00b6407918..9db6c1176f 100644 --- a/src/OpenSHC/UI/MenuItems/NewMapMapsize/MenuItemActionHandler_NewMapMapsize_Buttons.cpp +++ b/src/OpenSHC/UI/MenuItems/NewMapMapsize/MenuItemActionHandler_NewMapMapsize_Buttons.cpp @@ -37,7 +37,7 @@ namespace UI { if (DAT_MenuModalComposition1::instance.activeModalDialogID != OpenSHC::UI::Enums::MMT_NONE) { return; } - // buttons 1 to 4 make a new map of that size + // buttons 1 to 4 make a map of that size (set after the returns: quick_diff 0.9704 -> 0.9586) int mapSize = OpenSHC::Map::MC_MAP_SIZE_400; if (button <= 0) { return; @@ -71,9 +71,8 @@ namespace UI { DAT_TileMapState::instance.field_0x55487c = 200; MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::forceFullTileMapRedraw, DAT_TileMapState::ptr)(); MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::processGameTick, DAT_GameState::ptr)(); - for (int section = 0; section < 40; ++section) { - MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateWildlifeGrid, DAT_WildlifeState::ptr)( - section); + for (int row = 0; row < 40; ++row) { + MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateWildlifeGrid, DAT_WildlifeState::ptr)(row); } MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateWildlife, DAT_WildlifeState::ptr)(); MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateSection1034Info, DAT_WildlifeState::ptr)(); @@ -84,10 +83,10 @@ namespace UI { DAT_MinimapViewState::ptr)(0, 100); MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::setViewportBasedOnMapSize, DAT_ViewportRenderState::ptr)(); - DAT_GameCore::instance.descriptionUseStringTable = 0; + DAT_GameCore::instance.descriptionUseStringTable = FALSE; DAT_GameCore::instance.U3_mapLockedState = OpenSHC::Map::MLS_EDITABLE; DAT_GameCore::instance.temporaryTextBufferOfSize1000[0] = '\0'; - // both arms are the same; the original still compares U2_mapType_singleOrMulti here + // both arms the same; the original still compares (one call: quick_diff 0.9704 -> 0.7636) if (DAT_GameCore::instance.U2_mapType_singleOrMulti == 1) { MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( OpenSHC::UI::Enums::MVT_MAP_EDITOR_PROPERTIES, 0); @@ -95,7 +94,7 @@ namespace UI { MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( OpenSHC::UI::Enums::MVT_MAP_EDITOR_PROPERTIES, 0); } - DAT_GameCore::instance.mapLoadedForEditor = 1; + DAT_GameCore::instance.mapLoadedForEditor = TRUE; } } diff --git a/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_VolumeSlider.cpp b/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_VolumeSlider.cpp index 3f31504832..4a28b3de00 100644 --- a/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_VolumeSlider.cpp +++ b/src/OpenSHC/UI/MenuItems/SoundOptions/MenuItemActionHandler_SoundOptions_VolumeSlider.cpp @@ -65,7 +65,7 @@ namespace UI { } return; case 4: - // the stored volume, as event 1 reads it + // read back again here (one read-back after the switch: quick_diff 0.9222 -> 0.7797) switch (slider) { case 0: *currentValue = DAT_MenuTextInputState::instance.pendingStreamVolume0; @@ -77,7 +77,6 @@ namespace UI { *currentValue = DAT_MenuTextInputState::instance.pendingStreamVolume3; break; } - return; } } diff --git a/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons.cpp b/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons.cpp index 34dc5d2782..ca235c04b9 100644 --- a/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons.cpp +++ b/src/OpenSHC/UI/MenuItems/Unused/MenuItemRenderFunction_UnusedCreateMessageEvent_Buttons.cpp @@ -86,6 +86,7 @@ namespace UI { if (DAT_MapPropertiesState::instance.field_0x13590 < 4 && button >= 13) { return; } + // the remap again, as the original does it once for the hover test and once for the drawing if (DAT_MapPropertiesState::instance.field_0x13590 == 3 && button >= 9) { if (button == 9) { button = 24; @@ -108,6 +109,7 @@ namespace UI { DAT_ButtonY::instance += 72; DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; } + // An if/else, not an early return (early return: quick_diff 0.9718 -> 0.8870) if (!DAT_ButtonCurrentlyInteracting::instance) { MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( OpenSHC::DE::SHCDE::TEXT_SCENARIO, button, DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, From 887f61473e7d86e1bf910105aaa975a3177a0471 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Tue, 10 Nov 2026 00:43:35 +0100 Subject: [PATCH 15/15] UI-B-round7-100: main's names after its Ghidra sync (TAIT_UNKNOWN, INT_00b9840c) Co-Authored-By: Claude Opus 5.5 --- ...emActionHandler_InGameMenu_ViewToKeeps.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp index 7f189b7590..d5c3499467 100644 --- a/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp +++ b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ViewToKeeps.cpp @@ -4,7 +4,6 @@ #include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" #include "OpenSHC/UI/Enums/MenuModalType.hpp" -#include "OpenSHC/Globals/DAT_00b9840c.hpp" #include "OpenSHC/Globals/DAT_BuildingsState.hpp" #include "OpenSHC/Globals/DAT_GameCore.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" @@ -13,6 +12,7 @@ #include "OpenSHC/Globals/DAT_MouseState.hpp" #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" #include "OpenSHC/Globals/DWORD_00b98410.hpp" +#include "OpenSHC/Globals/INT_00b9840c.hpp" namespace OpenSHC { namespace UI { @@ -28,16 +28,16 @@ namespace UI { DWORD const now = timeGetTime(); if (now - DWORD_00b98410::instance > 1000) { DWORD_00b98410::instance = now; - DAT_00b9840c::instance = 0; + INT_00b9840c::instance = 0; } if (DAT_MouseState::instance.scrollEventData == 7) { - if (DAT_00b9840c::instance < 0) { - DAT_00b9840c::instance = 0; + if (INT_00b9840c::instance < 0) { + INT_00b9840c::instance = 0; } - ++DAT_00b9840c::instance; - if (DAT_00b9840c::instance == 2) { + ++INT_00b9840c::instance; + if (INT_00b9840c::instance == 2) { DWORD_00b98410::instance = now; - DAT_00b9840c::instance = 0; + INT_00b9840c::instance = 0; // the keep after the one viewed last, counting the map's keeps from 1 int keepNumber = 1; int tileIndex = -1; @@ -72,11 +72,11 @@ namespace UI { if (DAT_MouseState::instance.scrollEventData != 8) { return; } - if (DAT_00b9840c::instance > 0) { - DAT_00b9840c::instance = 0; + if (INT_00b9840c::instance > 0) { + INT_00b9840c::instance = 0; } - --DAT_00b9840c::instance; - if (DAT_00b9840c::instance != -2) { + --INT_00b9840c::instance; + if (INT_00b9840c::instance != -2) { return; } DWORD_00b98410::instance = now; @@ -84,7 +84,7 @@ namespace UI { = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] .id; - DAT_00b9840c::instance = 0; + INT_00b9840c::instance = 0; if (keep != 0) { MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::focusOnCoordinate, DAT_ViewportRenderState::ptr)(DAT_BuildingsState::instance.buildings[keep].x + 2,