From ff1813ba017387dcb0f24e781a89af088c5d2aa1 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 20 Nov 2026 04:46:21 +0100 Subject: [PATCH 1/4] reimplement: SHC_3BB0A8C1_0x004D8250 100.0% Reimplemented ScenarioDescription::MenuItemRenderFunction_ScenarioDescription_Main, from gynt's draft (38ce29778 at 28.99% on his fork's development; his newest commit on the file is e63ae309a on reimpl/UI-MenuItems-development) by way of my draft in the open draft PR (a8b32250f, 95.0%, "block order of the last tests"). reccmp 100.0 (normalized 100.0) on main 3458fea34 with the data on. The last difference was which copy of the `button == 13` test and the economic-mode tests the compiler keeps. The original has them once, behind the else arm's `button == 12` test (0x004D8543), and the other arm jumps there. My draft wrote the whole test in each arm as one condition, and MSVC then kept the earlier arm's copy and dropped the re-tests of 12 and 13 that the original makes. Written as the original has it, the arms only do their own tests and fall out, and the economic-mode test stands once behind both: the later copy survives and the re-tests stay. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ...enderFunction_ScenarioDescription_Main.cpp | 184 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/ScenarioDescription/MenuItemRenderFunction_ScenarioDescription_Main.cpp diff --git a/src/OpenSHC/UI/MenuItems/ScenarioDescription/MenuItemRenderFunction_ScenarioDescription_Main.cpp b/src/OpenSHC/UI/MenuItems/ScenarioDescription/MenuItemRenderFunction_ScenarioDescription_Main.cpp new file mode 100644 index 0000000000..3932a8d95a --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/ScenarioDescription/MenuItemRenderFunction_ScenarioDescription_Main.cpp @@ -0,0 +1,184 @@ +#include "../ScenarioDescription.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/MenuItems/General.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/GameMode2.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_00ed2798.hpp" +#include "OpenSHC/Globals/DAT_ARRAY_00ed26d0.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_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_StopHandlingMenuItems.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/INT_00ed27bc.hpp" +#include "OpenSHC/Globals/INT_00ed27c4.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x004D8250 + void ScenarioDescription::MenuItemRenderFunction_ScenarioDescription_Main(int button, ...) + { + DAT_ButtonUnknownZero::instance = TRUE; + DAT_StopHandlingMenuItems::instance = 0; + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_BUILDERUnk && button != 10 && button != 12 + && button != 13 && button != -3 && button != -4 && button != -1) { + return; + } + if (INT_00ed27bc::instance == 1 && button != 12) { + return; + } + // -1: the difficulty and its setting, in a campaign mission after the third or an economic one + if (button == -1) { + if (DAT_00ed2798::instance != 0 && DAT_00ed2798::instance != 1) { + return; + } + if ((DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_CAMPAIGN_MISSION + || DAT_GameCore::instance.missionNumber1to20 <= 3) + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_ECONOMIC_CAMPAIGN_SH1 + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_BUILDERUnk) { + return; + } + if (DAT_GameCore::instance.mapU4Int1) { + return; + } + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_BUILDERUnk) { + return; + } + if (DAT_GameCore::instance.gameSuspended == 1) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + } + DAT_ButtonUnknownZero::instance = FALSE; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + // a call for each colour: the original pushes the colour inside each arm + if (DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MAINOPTIONS, 24, DAT_ButtonX::instance + 10, DAT_ButtonY::instance + 8, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MAINOPTIONS, 24, DAT_ButtonX::instance + 10, DAT_ButtonY::instance + 8, + OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_C2F0EB, 18, FALSE); + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MAINOPTIONS, DAT_GameState::instance.mapAndTime.difficulty + 19, + DAT_ButtonX::instance + DAT_ButtonW::instance - 10, DAT_ButtonY::instance + 8, + OpenSHC::Text::TTA_RIGHT, OpenSHC::Rendering::Colors::COL_00FF00, 18, FALSE); + return; + } + // -2 to -4: three text buttons + if (button == -2) { + if (DAT_00ed2798::instance) { + return; + } + if (DAT_ARRAY_00ed26d0::instance[0].y == 0) { + return; + } + if (INT_00ed27bc::instance) { + return; + } + DAT_ButtonUnknownZero::instance = FALSE; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MISSION_BUTTONS, 10, DAT_ButtonX::instance + DAT_ButtonW::instance / 2, + DAT_ButtonY::instance + 8, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, + 18, FALSE); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MISSION_BUTTONS, 10, DAT_ButtonX::instance + DAT_ButtonW::instance / 2, + DAT_ButtonY::instance + 8, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, + 18, FALSE); + } + return; + } + if (button == -3) { + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_BUILDERUnk) { + return; + } + if (DAT_GameCore::instance.gameSuspended != 1) { + return; + } + DAT_ButtonUnknownZero::instance = FALSE; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MISSION_BUTTONS, 11, DAT_ButtonX::instance + DAT_ButtonW::instance / 2, + DAT_ButtonY::instance + 8, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, + 18, FALSE); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MISSION_BUTTONS, 11, DAT_ButtonX::instance + DAT_ButtonW::instance / 2, + DAT_ButtonY::instance + 8, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, + 18, FALSE); + } + return; + } + if (button == -4) { + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_BUILDERUnk) { + return; + } + if (INT_00ed27c4::instance <= 1) { + return; + } + DAT_ButtonUnknownZero::instance = FALSE; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + if (DAT_ButtonCurrentlyInteracting::instance) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MAPEDIT, 10, DAT_ButtonX::instance + DAT_ButtonW::instance / 2, + DAT_ButtonY::instance + 8, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, + 18, FALSE); + } else { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_MAPEDIT, 10, DAT_ButtonX::instance + DAT_ButtonW::instance / 2, + DAT_ButtonY::instance + 8, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, + 18, FALSE); + } + return; + } + // the other buttons are drawn as they are, but for the ones the game mode hides + if ((DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_CAMPAIGN_MISSION + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_ECONOMIC_CAMPAIGN_SH1) + || INT_00ed27bc::instance == 1) { + if (button == 11) { + return; + } + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_BUILDERUnk + && DAT_GameCore::instance.gameSuspended == 1) { + if (button == 12) { + return; + } + } else if (button == 13) { + return; + } + } else if (button == 12 || button == 13) { + return; + } + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_ECONOMIC_CAMPAIGN_SH1 + && (button == 12 || button == 13)) { + return; + } + DAT_ButtonUnknownZero::instance = FALSE; + MACRO_CALL(OpenSHC::UI::MenuItems::General_Func:: + MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface)(); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..9a3ae0569d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -35925,7 +35925,7 @@ SHC_3BB0A8C1_0x004D8228 | 0.0% | Pending SHC_3BB0A8C1_0x004D822C | 0.0% | Pending -SHC_3BB0A8C1_0x004D8250 | 0.0% | Pending +SHC_3BB0A8C1_0x004D8250 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D839E | 0.0% | Pending From 6b3c69846a22733677a098509f44e86e61a587af Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 20 Nov 2026 05:05:20 +0100 Subject: [PATCH 2/4] reimplement: SHC_3BB0A8C1_0x00434350 100.0% Reimplemented InGameMenu::MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection, from gynt's drafts (b62cbe642 at 67.13% on his fork's reimpl/UI-MenuItems-development is his newest scored one; 8ca78619c on reimpl/Wilps-2026-10-18 is the newest commit on the file) by way of my draft in the open draft PR (f1f198c0e, 90.6%, "block placement at the end"). reccmp 100.0 (normalized 100.0) on main 3458fea34 with the data on. Two changes took it from 90.6 to 100: - The left-click arm with a mapper command. The original tests the command in line (0x00434699) and has the arm's code, which ends in returns, behind the function's last return (0x004347BE). `else if (command != NULL) { ... }` moved the test out of line with the code. Written as `else if (command == NULL) { } else { ... }` the code is an else arm that returns, which MSVC lays out behind the next return, and the test stays where it is. That alone gave 99.7: the plain returns then share the earlier return block, as in the original. - The second selectUnitAndOpenStatusMenu call, for the unit that was under the mouse before. The original tests the first call's result with `test eax, eax` and the second's with `cmp eax, ebp` (ebp holds zero), so the second result went through a variable: `BOOLEnum selectedLast = FALSE; if (...) selectedLast = call; if (selectedLast) return;`. One variable for both calls turns the first test into a `cmp` too. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- ...PeasantBuildAndRightClickMenuSelection.cpp | 299 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 300 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection.cpp diff --git a/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection.cpp b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection.cpp new file mode 100644 index 0000000000..b6db963567 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection.cpp @@ -0,0 +1,299 @@ +#include "../InGameMenu.func.hpp" + +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Input/MouseState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/DisplayElements.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/UI/Enums/BuildMenuTabType.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/DisplayElementID.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/DAT_00b960f8.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_MapPropertiesState.hpp" +#include "OpenSHC/Globals/DAT_ModifierKeyState.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UIDragDropDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" +#include "OpenSHC/Globals/INT_00b960f0.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00434350 + void InGameMenu::MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection(int unused, ...) + { + if (DAT_GameSynchronyState::instance.syncStatus != 0) { + return; + } + if (DAT_GameSynchronyState::instance.saveRelated != 0) { + return; + } + // in a multiplayer game, command 117 goes out every 1.5 seconds with a counter, until that reaches 66 + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY + && DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER + && DAT_00b960f8::instance != 66) { + if (INT_00b960f0::instance == 0) { + INT_00b960f0::instance = timeGetTime() + 20000; + } else { + DWORD const now = timeGetTime(); + if ((int)(now - INT_00b960f0::instance) > 1500) { + INT_00b960f0::instance = now; + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = DAT_00b960f8::instance; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 + = DAT_GameSynchronyState::instance.currentPlayerSlotID; + MACRO_CALL_MEMBER( + OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + OpenSHC::Commands::GCT_UPDATE_LOBBY_FACE_BITMAPSPECIALTRANSMITLOGIC); + DAT_00b960f8::instance++; + } + } + } + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_EDITOR + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_SIEGE_THAT + && (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_BUILDERUnk + || DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 != OpenSHC::Map::MT_SIEGE) + && DAT_GameCore::instance.currentMenuViewType == OpenSHC::UI::Enums::MVT_BUILD_MENU) { + if (MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::getArmySize, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID) + == 0) { + if (DAT_GameCore::instance.activeMenuTab.buildMenuTab == OpenSHC::UI::Enums::BMTT_CASTLE_KEEPS) { + if (DAT_GameCore::instance.menuSwitchDelay == -1) { + if (MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::singlePlayerHasKeepAndGranaryCheck, + DAT_GameState::ptr)() + != 1) { + MACRO_CALL(OpenSHC::UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO, 1); + DAT_UIDragDropDefinedData::instance.MenuView_TriggerInitial = TRUE; + } else { + MACRO_CALL(OpenSHC::UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO, 0); + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.buildMenuTab + = OpenSHC::UI::Enums::BMTT_CASTLE; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_BUILD_MENU, 0); + } + } else { + DAT_UIDragDropDefinedData::instance.MenuView_TriggerInitial = TRUE; + MACRO_CALL( + OpenSHC::UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO, 0); + } + } else if (DAT_GameCore::instance.activeMenuTab.buildMenuTab + == OpenSHC::UI::Enums::BMTT_UNKNOWN_49) { + MACRO_CALL(OpenSHC::UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO, 2); + DAT_UIDragDropDefinedData::instance.MenuView_TriggerInitial = TRUE; + } else { + DAT_UIDragDropDefinedData::instance.MenuView_TriggerInitial = TRUE; + MACRO_CALL(OpenSHC::UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO, 0); + } + } else if (DAT_GameCore::instance.activeMenuTab.buildMenuTab == OpenSHC::UI::Enums::BMTT_UNKNOWN_49) { + MACRO_CALL(OpenSHC::UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO, 2); + DAT_UIDragDropDefinedData::instance.MenuView_TriggerInitial = TRUE; + } + } + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_EDITOR) { + // a call in each arm with its own constant: the original pushes the constant inside the arm + if (DAT_UnitsState::instance.unitCount >= 2300) { + MACRO_CALL(OpenSHC::UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_PEOPLE_LEFT_TO_PLACE, 1); + } else { + MACRO_CALL(OpenSHC::UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + OpenSHC::UI::Enums::DEID_PEOPLE_LEFT_TO_PLACE, 0); + } + } + // the mouse's view events; each is recorded for the tutorial + if (DAT_MouseState::instance.mouseBasedEvent == 1) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::triggerLoweredView, DAT_TileMapState::ptr)(3); + DAT_GameCore::instance.field_0x15c = 1; + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CRUSADER_TUTORIAL) { + MACRO_CALL(OpenSHC::UI::Helpers_Func::RecordTutorialPlayerAction)(4); + } + } else if ((!DAT_MouseState::instance.rightClickState || DAT_MouseState::instance.mouseBasedEvent == 2) + && (DAT_ModifierKeyState::instance.ctrl == 0 || DAT_ModifierKeyState::instance.downArrow == 0) + && DAT_ModifierKeyState::instance.v == 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::triggerLoweredView, DAT_TileMapState::ptr)(4); + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CRUSADER_TUTORIAL) { + MACRO_CALL(OpenSHC::UI::Helpers_Func::RecordTutorialPlayerAction)(5); + } + } else if (DAT_MouseState::instance.mouseBasedEvent == 3) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMapRotation, DAT_TileMapState::ptr)( + DAT_MouseState::instance.mapOrientationCopy3); + DAT_GameCore::instance.field_0x15c = 1; + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CRUSADER_TUTORIAL) { + MACRO_CALL(OpenSHC::UI::Helpers_Func::RecordTutorialPlayerAction)(2); + } + } else if (DAT_MouseState::instance.mouseBasedEvent == 4) { + DAT_MouseState::instance.field_0x198 = 2; + // a call in each arm here too, each pushing its own argument as the original does + if (DAT_ViewportRenderState::instance.viewportState.isZoomedOutUnk) { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::resetupViewport, DAT_ViewportRenderState::ptr)(0); + } else { + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::resetupViewport, DAT_ViewportRenderState::ptr)(1); + } + DAT_WindowAndDirectDraw::instance.unk_resetViewportRelated = 2; + DAT_UIDragDropDefinedData::instance.MenuView_TriggerInitial = TRUE; + DAT_GameCore::instance.field_0x15c = 1; + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CRUSADER_TUTORIAL) { + MACRO_CALL(OpenSHC::UI::Helpers_Func::RecordTutorialPlayerAction)(3); + } + } else if (DAT_MouseState::instance.mouseBasedEvent == 5) { + DAT_MouseState::instance.field_0x19c = 2; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::toggleFlatView, DAT_TileMapState::ptr)( + DAT_TileMapState::instance.flatViewToggleValue1 ^ 1); + DAT_GameCore::instance.field_0x15c = 1; + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CRUSADER_TUTORIAL) { + MACRO_CALL(OpenSHC::UI::Helpers_Func::RecordTutorialPlayerAction)(17); + } + } + // the mouse is not over the map + if (DAT_ViewportRenderState::instance.viewportState.field_0x0 == 0) { + if (DAT_MouseState::instance.rightClickStart) { + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_NULL; + DAT_GameCore::instance.field_0x15c = 0; + } + MACRO_CALL_MEMBER(OpenSHC::Input::MouseState_Func::storeXYAndResetMouseState, DAT_MouseState::ptr)(); + return; + } + if (DAT_MouseState::instance.rightClickStart) { + if (DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_MOAT) { + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_NULL; + } + DAT_GameCore::instance.field_0x15c = 0; + return; + } + if (DAT_MouseState::instance.rightClickStop + && DAT_TileMapState::instance.currentMapperCommand == OpenSHC::Commands::M_MAPPER_MOAT + && DAT_GameCore::instance.field_0x15c == 0) { + DAT_TileMapState::instance.currentMapperCommand = OpenSHC::Commands::M_MAPPER_NULL; + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::noop1, DAT_TileMapState::ptr)( + DAT_ViewportRenderState::instance.viewportState.mouseFlatTile); + if (!DAT_MouseState::instance.leftClickState) { + if (DAT_UnitsState::instance.unitCountOfSelection[DAT_GameSynchronyState::instance.currentPlayerSlotID] + <= 0) { + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::processBuildingClickBonus, + AlphaAndButtonSurfaceObj::ptr)( + DAT_ViewportRenderState::instance.viewportState.mouseRayBuildingID); + } + if (!DAT_MouseState::instance.draggingStopped) { + return; + } + if (DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_NULL) { + return; + } + } else if (DAT_TileMapState::instance.currentMapperCommand == OpenSHC::Commands::M_MAPPER_NULL) { + // no mapper command: the click is handled below (an else-if on the command loses the match) + } else { + if (!DAT_MouseState::instance.leftClickStart + && DAT_ViewportRenderState::instance.viewportState.previousMouseTile + == DAT_ViewportRenderState::instance.viewportState.mouseFlatTile) { + return; + } + DAT_ViewportRenderState::instance.viewportState.previousMouseTile + = DAT_ViewportRenderState::instance.viewportState.mouseFlatTile; + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::setupMouseTileXY, DAT_ViewportRenderState::ptr)(); + return; + } + if (DAT_UnitsState::instance.unitCountOfSelection[DAT_GameSynchronyState::instance.currentPlayerSlotID] + > 0) { + return; + } + if (DAT_UnitsState::instance.totalUnitsInSelection > 0) { + return; + } + // nothing selected: a click selects the unit or opens the building under the mouse, or the stockpile + // menu when the tile has the stockpile flag and belongs to the player + DWORD const clickTime = timeGetTime(); + if (!DAT_MouseState::instance.draggingStopped) { + return; + } + if (DAT_MouseState::instance.selectionBoxState != 0) { + return; + } + if (DAT_MouseState::instance.savedSelectionBoxState != 0) { + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::selectUnitAndOpenStatusMenu, + AlphaAndButtonSurfaceObj::ptr)(DAT_ViewportRenderState::instance.viewportState.mouseRayUnitID)) { + return; + } + // within 200 ms, the unit that was under the mouse before counts too (the result in a local: tested + // on the call, the match is lost) + BOOLEnum selectedLast = FALSE; + if ((int)(clickTime - DAT_ViewportRenderState::instance.viewportState.field_0x34) < 200) { + selectedLast = MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::selectUnitAndOpenStatusMenu, + AlphaAndButtonSurfaceObj::ptr)(DAT_ViewportRenderState::instance.viewportState.mouseRayLastUnitID); + } + if (selectedLast) { + return; + } + if (MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::openBuildingStatusMenuForBuildingID, + AlphaAndButtonSurfaceObj::ptr)( + DAT_ViewportRenderState::instance.viewportState.mouseRayBuildingID)) { + return; + } + if ((DAT_TileMapState::instance + .LogicLayer[DAT_ViewportRenderState::instance.viewportState.mouseAtomRefFloorTile] + & 2) + == 0) { + return; + } + if ((DAT_TileMapState::instance + .WallOwnerLayer[DAT_ViewportRenderState::instance.viewportState.mouseAtomRefFloorTile] + & 7) + + 1 + != DAT_GameSynchronyState::instance.currentPlayerSlotID) { + return; + } + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_STOCKPILE] + .id + == 0) { + return; + } + DAT_GameCore::instance.buildingandstatusmenuMenuTabToSwitchTo = OpenSHC::UI::Enums::BASMTT_STOCKPILE; + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_BUILDING_AND_STATUS_MENU, 0); + DAT_BuildingsState::instance.newSelectedUnitID = 0; + DAT_BuildingsState::instance.newSelectedBuildingID + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_STOCKPILE] + .id; + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 9a3ae0569d..bc7650db8e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -11145,7 +11145,7 @@ SHC_3BB0A8C1_0x00434300 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00434340 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00434350 | 0.0% | Pending +SHC_3BB0A8C1_0x00434350 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004347F0 | 100.0% | Reimplemented From fc31bc6821bf2577ab50f9d962dda752f81b03f1 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 20 Nov 2026 05:17:38 +0100 Subject: [PATCH 3/4] reimplement: SHC_3BB0A8C1_0x00440560 100.0% Reimplemented GameStartEnterName::MenuView_GameStartEnterName_Prepare, from gynt's draft (ac762234d1 at 82.52% on his fork's reimpl/UI-MenuViews-development) by way of my draft in the open draft PR (c5b5fe6c3, 98.2%, "stack slots of the name buffer and the cookie"). reccmp 100.0 (normalized 100.0) on main 3458fea34 with the data on. The last difference was the frame: the name buffer sat at [esp + 0xc] where the original has it at [esp + 0x10], under the same cookie. Two things in the draft cancelled out in the frame's size but not in its layout: - the name buffer is 250 bytes, not 256 (250 is also the size of the game's player name entries); - the length test is strlen, with which MSVC's frame is four bytes larger. The draft had a hand-written loop instead, because with the 256-byte buffer strlen made the frame four bytes too large. With both, the frame is 0x10c bytes with the buffer four bytes up, as in the original. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 --- .../MenuView_GameStartEnterName_Prepare.cpp | 104 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuViews/GameStartEnterName/MenuView_GameStartEnterName_Prepare.cpp diff --git a/src/OpenSHC/UI/MenuViews/GameStartEnterName/MenuView_GameStartEnterName_Prepare.cpp b/src/OpenSHC/UI/MenuViews/GameStartEnterName/MenuView_GameStartEnterName_Prepare.cpp new file mode 100644 index 0000000000..823ce98253 --- /dev/null +++ b/src/OpenSHC/UI/MenuViews/GameStartEnterName/MenuView_GameStartEnterName_Prepare.cpp @@ -0,0 +1,104 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../GameStartEnterName.func.hpp" + +#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/UI/MenuViews/MainMenu.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/Audio/SFX/SpeechEffectID.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Text/TextArrayIndexType.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuView_TriggerPrepare.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" +#include "OpenSHC/Globals/DAT_SpeechDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UIDragDropDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuViews { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x00440560 + void GameStartEnterName::MenuView_GameStartEnterName_Prepare() + { + // the original reads the local time and drops it + __time64_t now; + MACRO_CALL(OpenSHC::OS_Func::__time64)(&now); + MACRO_CALL(OpenSHC::OS_Func::_localtime)(&now); + // the lord's name, spoken when the game has a recording of it, otherwise the start-game line + char lordName[250]; + strcpy(lordName, + MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0)); + BOOLEnum named = FALSE; + for (int lord = 0; lord < countof(DAT_SpeechDefinedData::instance.LordNameToCall); ++lord) { + if (MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::isLordNameCallable, DAT_LowLevelMemory::ptr)( + lordName, DAT_SpeechDefinedData::instance.LordNameToCall[lord].name)) { + MACRO_CALL_MEMBER(OpenSHC::Audio::MSS::SoundSystem_Func::playSoundOnStream3Unk, + DAT_SoundSystemState::ptr)(DAT_SpeechDefinedData::instance.LordNameToCall[lord].source, 1); + named = TRUE; + break; + } + } + if (!named) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSpeechSFX, DAT_SFXState::ptr)( + OpenSHC::Audio::SFX::SEID_GENERAL_STARTGAME); + } + // a name already entered: straight on to the main menu + if (strlen(MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0)) + != 0) { + DAT_GameCore::instance.isNameEntryActive = TRUE; + DAT_GameCore::instance.nameEntryStartTime = timeGetTime(); + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_MAIN_MENU, 0); + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::processMenuViewSwitch, DAT_GameCore::ptr)(); + MACRO_CALL(OpenSHC::UI::MenuViews::MainMenu_Func::MenuView_MainMenu_Prepare)(); + MACRO_CALL(OpenSHC::UI::MenuViews::MainMenu_Func::MenuView_MainMenu_DoInitial)(); + MACRO_CALL(OpenSHC::UI::MenuViews::MainMenu_Func::MenuView_MainMenu_DoEveryFrame)(); + DAT_UIDragDropDefinedData::instance.MenuView_TriggerInitial = FALSE; + DAT_MenuView_TriggerPrepare::instance = FALSE; + return; + } + // otherwise the name entry dialog, filled in with "Lord Crusader" + DAT_TextureRenderCoreObject::instance.totalLoadedGfx = 0; + // "frontend_combat3.tgx" + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::loadGfxFile, + DAT_TextureRenderCoreObject::ptr)(s_frontend_combat3_tgx_005a2134); + MACRO_CALL(OpenSHC::UI::Helpers_Func::LoadTGX_shc_back)(); + DAT_GameCore::instance.isNameEntryActive = FALSE; + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)( + OpenSHC::Text::TAIT_ZERO); + // "Lord Crusader" + MACRO_CALL_MEMBER(OpenSHC::Text::UserTextHandler_Func::copyIntoTextArray, DAT_UserTextHandlerState::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_GAME_OPTIONS, 48)); + MACRO_CALL_MEMBER(OpenSHC::UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(OpenSHC::UI::Enums::MMT_ENTER_TITLE_ON_GAME_START, FALSE); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bc7650db8e..2e8d773ee2 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -13641,7 +13641,7 @@ SHC_3BB0A8C1_0x00440420 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00440430 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00440560 | 0.0% | Pending +SHC_3BB0A8C1_0x00440560 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00440600 | 0.0% | Pending From 733d5cfe10b02839f951936b2db3b714208581fd Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 20 Nov 2026 07:39:05 +0100 Subject: [PATCH 4/4] style: say which else-if loses the match in the click handler The empty arm for "no mapper command" in MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection (0x00434350) is what keeps the command test in line. Its comment said "an else-if on the command loses the match", which reads oddly on an arm that is itself an else-if on the command. It now names the form that loses the match: `else if (command != M_MAPPER_NULL) { ... }` without the empty arm. Comment only: reccmp still reads 100.0 (normalized 100.0). Co-Authored-By: Claude Fable 5.2 --- ...ndler_InGameMenu_PeasantBuildAndRightClickMenuSelection.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection.cpp b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection.cpp index b6db963567..1e7196b11d 100644 --- a/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection.cpp +++ b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_PeasantBuildAndRightClickMenuSelection.cpp @@ -212,7 +212,8 @@ namespace UI { return; } } else if (DAT_TileMapState::instance.currentMapperCommand == OpenSHC::Commands::M_MAPPER_NULL) { - // no mapper command: the click is handled below (an else-if on the command loses the match) + // no mapper command: the click is handled below. This arm stays empty on purpose: written as + // `else if (command != M_MAPPER_NULL) { ... }` without it, the match is lost } else { if (!DAT_MouseState::instance.leftClickStart && DAT_ViewportRenderState::instance.viewportState.previousMouseTile