From c0681d2be7d64132a93f5251c061875cd7a84206 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 08:19:45 +0100 Subject: [PATCH 1/5] reimplement: SHC_3BB0A8C1_0x00466AB0 100.0% Reimplemented MenuItemRenderFunction_BuildingAndStatusMenu_MercenaryPostPortraits, from gynt's draft on the fork branch reimpl/UI-MenuItems-development (55.6% there; 70.0% as a draft on batch4-development). The parameter is named unitType, as GetUnitRecruitPermission takes it. The button's stateTransitionTimeBaseUnk_0x18 is cleared through the array and the two calls go through a pointer to the button, which gives the original's shared offset (the pointer for the store too: quick_diff 0.8738 -> 0.6400). Like the other getPictureNumberInGm callers it needs /GL (the button pointer stays in ecx across the call), so the file is in cmake/compiler-flags-gl.txt, next to getPictureNumberInGm. Shape: the hovered portrait's 70..76 (Arabian mercenary) test returns through its own copy of the shared tail when unitType is below 70, then tests the upper bound; MSVC merges the copy with the tail. As one range test (`unitType >= UT_A_ARCHER && unitType <= UT_A_FIRETHROWER`) MSVC folds the two signed compares into one unsigned compare: quick_diff 0.8738 -> 0.7122, reccmp 100.0% -> 70.0%. Nested ifs, the reverse order, literals, an enum cast, an index local, `!(a || b)` and `> 69 && < 77` all fold the same way; both bounds returning on their own: 0.7070. The drawing is guarded by DAT_DisableMercPostPortraits rather than returning early, as in EngineerAndMonkPortraits on main (early return: quick_diff 0.8738 -> 0.8350). DAT_ButtonUnknownZero is set to TRUE/FALSE, as a BOOLEnum since a9401a727. Co-Authored-By: Claude Opus 5.5 --- cmake/compiler-flags-gl.txt | 1 + ...ngAndStatusMenu_MercenaryPostPortraits.cpp | 115 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 3 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_MercenaryPostPortraits.cpp diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 9c4ebf2622..d3350045a0 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -99,6 +99,7 @@ src/OpenSHC/Map/Buildings/UpdateGoodBuildingMaypole.cpp src/OpenSHC/Map/Buildings/UpdateBadBuildingDungeon.cpp src/OpenSHC/Map/Buildings/UpdateBadBuildingGallows.cpp src/OpenSHC/Map/Buildings/UpdateBadBuildingBurningStake.cpp +src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_MercenaryPostPortraits.cpp src/OpenSHC/UI/Rendering/ButtonGmData/getPictureNumberInGm.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_EngineerAndMonkPortraits.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_TunnelerPortrait.cpp diff --git a/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_MercenaryPostPortraits.cpp b/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_MercenaryPostPortraits.cpp new file mode 100644 index 0000000000..30209b9c74 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_MercenaryPostPortraits.cpp @@ -0,0 +1,115 @@ +#include "../BuildingAndStatusMenu.func.hpp" + +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/Rendering/ButtonGmData.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/Map/Units/EuroRecruitableState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" + +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonGmDataIndex.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonPictureInGm.hpp" +#include "OpenSHC/Globals/DAT_DisableMercPostPortraits.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UIButtonDefinedData.hpp" +#include "OpenSHC/Globals/INT_00df3350.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + namespace BuildingAndStatusMenu { + + // FUNCTION: STRONGHOLDCRUSADER 0x00466AB0 + void MenuItemRenderFunction_BuildingAndStatusMenu_MercenaryPostPortraits(int unitType, ...) + { + // Outside solitary and single-player skirmish the portraits stay hidden while the no-rush time runs. + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + && DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SKIRMISH_SINGLE_PLAYER + && DAT_GameState::instance.mapAndTime.skirmishNoRushTicks != 0) { + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + DAT_ButtonUnknownZero::instance = FALSE; + // Guarded, not an early return (early return: quick_diff 0.8738 -> 0.8350) + if (DAT_DisableMercPostPortraits::instance) { + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + Map::Units::EuroRecruitableState const permission + = MACRO_CALL(Helpers_Func::GetUnitRecruitPermission)((Map::Units::UnitType)unitType); + if (DAT_ButtonCurrentlyInteracting::instance) { + INT_00df3350::instance = unitType - Map::Units::UT_A_ARCHER; + } + if (permission == Map::Units::ERS_CAN_RECRUITUnk) { + if (DAT_ButtonCurrentlyInteracting::instance) { + // The low bound returns on its own (one range test: quick_diff 0.8738 -> 0.7122) + if (unitType < Map::Units::UT_A_ARCHER) { + DAT_CurrentButtonPictureInGm::instance + = DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .pictureInGm_0x4; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + if (unitType <= Map::Units::UT_A_FIRETHROWER) { + // Store through the array (through the pointer: quick_diff 0.8738 -> 0.6400) + DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .stateTransitionTimeBaseUnk_0x18 = 0; + ButtonGmData* const buttonGmData + = &DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance]; + MACRO_CALL_MEMBER(Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((DE::SHCDE::eGM)buttonGmData->gmId_0x0, + MACRO_CALL_MEMBER(Rendering::ButtonGmData_Func::getPictureNumberInGm, buttonGmData)( + DAT_ButtonCurrentlyInteracting::instance), + DAT_ButtonX::instance, DAT_ButtonY::instance); + } + } else { + DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .stateTransitionTimeBaseUnk_0x18 = 0; + ButtonGmData* const buttonGmData + = &DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance]; + MACRO_CALL_MEMBER(Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((DE::SHCDE::eGM)buttonGmData->gmId_0x0, + MACRO_CALL_MEMBER(Rendering::ButtonGmData_Func::getPictureNumberInGm, buttonGmData)( + FALSE), + DAT_ButtonX::instance, DAT_ButtonY::instance); + } + } else if (permission == Map::Units::ERS_CAN_NOT_RECRUIT + || permission == Map::Units::ERS_UNABLE_MISSING_PEASANTS + || permission == Map::Units::ERS_UNABLE_BECAUSE_MAX_ARMY) { + // A mercenary the player can't hire now is drawn faded and can't be pressed. + ButtonGmData* const buttonGmData + = &DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance]; + DAT_ButtonCurrentlyInteracting::instance = FALSE; + MACRO_CALL_MEMBER(Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)((IO::Graphics::GmID)buttonGmData->gmId_0x0, + MACRO_CALL_MEMBER(Rendering::ButtonGmData_Func::getPictureNumberInGm, buttonGmData)(FALSE) + + 7, + DAT_ButtonX::instance, DAT_ButtonY::instance, 16); + } + DAT_CurrentButtonPictureInGm::instance + = DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .pictureInGm_0x4; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + DAT_ButtonCurrentlyInteracting::instance = FALSE; + } + + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 656f04baca..2b875778e1 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -19981,7 +19981,7 @@ SHC_3BB0A8C1_0x00466920 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00466950 | 0.0% | Pending -SHC_3BB0A8C1_0x00466AB0 | 0.0% | Pending +SHC_3BB0A8C1_0x00466AB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00466C20 | 100.0% | Reimplemented From 923aac06d38463466ed9bc0a7376c74341bd2058 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 08:19:45 +0100 Subject: [PATCH 2/5] reimplement: SHC_3BB0A8C1_0x00466950 100.0% Reimplemented MenuItemActionHandler_BuildingAndStatusMenu_BarrackUnitPortraits, from gynt's draft on the fork branch reimpl/UI-MenuItems (44.1% there; 68.4% as a draft on batch4-development), in the form of the MercenaryPostPortraits render: the European units 22..28, IsEuroUnitRecruitableUnk in place of GetUnitRecruitPermission and the greyed picture through renderGM. Despite the name it draws the barracks portraits. The parameter is named unitType, as in IsEuroUnitRecruitableUnk. It needs /GL like the other getPictureNumberInGm callers, so the file is in cmake/compiler-flags-gl.txt. One behaviour fix: without DAT_EnoughGoldForRequestedUnit the original clears DAT_ButtonCurrentlyInteracting and returns; the draft cleared it and went on to draw the portrait. Shape: as in the MercenaryPostPortraits render, the lower bound of 22..28 returns through its own copy of the shared tail; as one range test MSVC folds it into one unsigned compare: quick_diff 0.8731 -> 0.7449, reccmp 100.0% -> 68.4%. The same guarded draw (early return: 0.8731 -> 0.8325) and the store through the array (through the pointer: 0.8731 -> 0.6425). Co-Authored-By: Claude Opus 5.5 --- cmake/compiler-flags-gl.txt | 1 + ...dingAndStatusMenu_BarrackUnitPortraits.cpp | 114 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemActionHandler_BuildingAndStatusMenu_BarrackUnitPortraits.cpp diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index d3350045a0..ea680bf4b3 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -100,6 +100,7 @@ src/OpenSHC/Map/Buildings/UpdateBadBuildingDungeon.cpp src/OpenSHC/Map/Buildings/UpdateBadBuildingGallows.cpp src/OpenSHC/Map/Buildings/UpdateBadBuildingBurningStake.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_MercenaryPostPortraits.cpp +src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemActionHandler_BuildingAndStatusMenu_BarrackUnitPortraits.cpp src/OpenSHC/UI/Rendering/ButtonGmData/getPictureNumberInGm.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_EngineerAndMonkPortraits.cpp src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAndStatusMenu_TunnelerPortrait.cpp diff --git a/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemActionHandler_BuildingAndStatusMenu_BarrackUnitPortraits.cpp b/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemActionHandler_BuildingAndStatusMenu_BarrackUnitPortraits.cpp new file mode 100644 index 0000000000..dd6e1e4532 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemActionHandler_BuildingAndStatusMenu_BarrackUnitPortraits.cpp @@ -0,0 +1,114 @@ +#include "../BuildingAndStatusMenu.func.hpp" + +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/Rendering/ButtonGmData.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Units/EuroRecruitableState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" + +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonGmDataIndex.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonPictureInGm.hpp" +#include "OpenSHC/Globals/DAT_EnoughGoldForRequestedUnit.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UIButtonDefinedData.hpp" +#include "OpenSHC/Globals/INT_00df3350.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + namespace BuildingAndStatusMenu { + + // FUNCTION: STRONGHOLDCRUSADER 0x00466950 + void MenuItemActionHandler_BuildingAndStatusMenu_BarrackUnitPortraits(int unitType, ...) + { + // Outside solitary and single-player skirmish the portraits stay hidden while the no-rush time runs. + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + && DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SKIRMISH_SINGLE_PLAYER + && DAT_GameState::instance.mapAndTime.skirmishNoRushTicks != 0) { + DAT_ButtonUnknownZero::instance = TRUE; + return; + } + DAT_ButtonUnknownZero::instance = FALSE; + // Guarded, not an early return (early return: quick_diff 0.8731 -> 0.8325) + if (DAT_EnoughGoldForRequestedUnit::instance) { + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + Map::Units::EuroRecruitableState const permission + = MACRO_CALL(Helpers_Func::IsEuroUnitRecruitableUnk)(unitType); + if (DAT_ButtonCurrentlyInteracting::instance) { + INT_00df3350::instance = unitType - Map::Units::UT_E_ARCHER; + } + if (permission == Map::Units::ERS_CAN_RECRUITUnk) { + if (DAT_ButtonCurrentlyInteracting::instance) { + // The low bound returns on its own (one range test: quick_diff 0.8731 -> 0.7449) + if (unitType < Map::Units::UT_E_ARCHER) { + DAT_CurrentButtonPictureInGm::instance + = DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .pictureInGm_0x4; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + if (unitType <= Map::Units::UT_E_KNIGHT) { + // Store through the array (through the pointer: quick_diff 0.8731 -> 0.6425) + DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .stateTransitionTimeBaseUnk_0x18 = 0; + ButtonGmData* const buttonGmData + = &DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance]; + MACRO_CALL_MEMBER(Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((DE::SHCDE::eGM)buttonGmData->gmId_0x0, + MACRO_CALL_MEMBER(Rendering::ButtonGmData_Func::getPictureNumberInGm, buttonGmData)( + DAT_ButtonCurrentlyInteracting::instance), + DAT_ButtonX::instance, DAT_ButtonY::instance); + } + } else { + DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .stateTransitionTimeBaseUnk_0x18 = 0; + ButtonGmData* const buttonGmData + = &DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance]; + MACRO_CALL_MEMBER(Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((DE::SHCDE::eGM)buttonGmData->gmId_0x0, + MACRO_CALL_MEMBER(Rendering::ButtonGmData_Func::getPictureNumberInGm, buttonGmData)( + FALSE), + DAT_ButtonX::instance, DAT_ButtonY::instance); + } + } else if (permission == Map::Units::ERS_CAN_NOT_RECRUIT + || permission == Map::Units::ERS_UNABLE_MISSING_PEASANTS + || permission == Map::Units::ERS_UNABLE_BECAUSE_MAX_ARMY) { + // A unit the player can't recruit now shows its greyed picture and can't be pressed. + ButtonGmData* const buttonGmData + = &DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance]; + DAT_ButtonCurrentlyInteracting::instance = FALSE; + MACRO_CALL_MEMBER(Rendering::TextureRenderCore_Func::renderGM, + DAT_TextureRenderCoreObject::ptr)((DE::SHCDE::eGM)buttonGmData->gmId_0x0, + MACRO_CALL_MEMBER(Rendering::ButtonGmData_Func::getPictureNumberInGm, buttonGmData)(FALSE) + + 7, + DAT_ButtonX::instance, DAT_ButtonY::instance); + } + DAT_CurrentButtonPictureInGm::instance + = DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .pictureInGm_0x4; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + DAT_ButtonCurrentlyInteracting::instance = FALSE; + } + + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2b875778e1..bf62e77d42 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -19979,7 +19979,7 @@ SHC_3BB0A8C1_0x004668F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00466920 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00466950 | 0.0% | Pending +SHC_3BB0A8C1_0x00466950 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00466AB0 | 100.0% | Reimplemented From e16ec30d228dd0f487025e92ba4841caf8258392 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 08:48:32 +0100 Subject: [PATCH 3/5] reimplement: SHC_3BB0A8C1_0x004387D0 100.0% Reimplemented MenuItemActionHandler_BuildMenu_DeleteAction, from 6and8's version on their fork's ci/postmerge (78.7% there; gynt's draft on archive/UI-MenuViews-development-second-pass is at 55.9%). One behaviour fix: without a new click the original goes on (drag-deleting) while the button is held over a wall or moat, and only clears the two flags and returns otherwise (jumps at 0x0043887A and 0x0043888A); the draft returned in both cases. Shape: the player slot read from the field each time (as a local: quick_diff 0.9157 -> 0.8072); the enemy distance in a local before isEnemyTooCloseUnk, in RepairBuildingButton's if/else form (inline in the call: 0.9679 -> 0.9116; the if/else and a ternary local tie); tileX read before tileY (y first: 0.9679 -> 0.9598); and two of the four height sums as terrainOrClimbHeight + buildingHeight, the order the binary loads them in (the draft's order: reccmp 100.0% -> 97.6%). The fail reason is read from the field each time (a local ties). Names for the literals: Game::GM_EDITOR and GM_SIEGE_THAT, Game::GM_SOLITARY, TEXT_MISC2, TEXT_PANEL_FEEDBACK, FX_DEATH_CLUB2 and BFRE_DEFAULT_CANT_PLACE_THAT_THERE (the BuildingFailReasonEnum include leaves the code as it is). Command 97, entity type 30 and fail reason 1000 have no constants in GameCommandType, EntityType and BuildingFailReasonEnum yet, so they stay numbers with main's one-line comment (as in spawnRandomFireEffectOnBuilding). Co-Authored-By: Claude Opus 5.5 --- ...emActionHandler_BuildMenu_DeleteAction.cpp | 195 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemActionHandler_BuildMenu_DeleteAction.cpp diff --git a/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemActionHandler_BuildMenu_DeleteAction.cpp b/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemActionHandler_BuildMenu_DeleteAction.cpp new file mode 100644 index 0000000000..ecf106f854 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/BuildMenu/MenuItemActionHandler_BuildMenu_DeleteAction.cpp @@ -0,0 +1,195 @@ +#include "../BuildMenu.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Entities.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Buildings/BuildingFailReasonEnum.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WallAndPitchState.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + namespace BuildMenu { + + // FUNCTION: STRONGHOLDCRUSADER 0x004387D0 + void MenuItemActionHandler_BuildMenu_DeleteAction(int param_1, ...) + { + if (DAT_GameSynchronyState::instance.syncStatus != 0 + || DAT_GameSynchronyState::instance.saveRelated != 0 + || DAT_TileMapState::instance.currentMapperCommand != OpenSHC::Commands::M_MAPPER_DELETE) { + return; + } + DAT_TileMapState::instance.demolishBlocked = 0; + if (!DAT_ViewportRenderState::instance.viewportState.field_0x0) { + return; + } + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::setupMouseTileXY, DAT_ViewportRenderState::ptr)(); + int const tileX = DAT_ViewportRenderState::instance.viewportState.mouseTileX; + int const tileY = DAT_ViewportRenderState::instance.viewportState.mouseTileY; + DAT_TileMapState::instance.DAT_ClickedTileX = tileX; + DAT_TileMapState::instance.DAT_ClickedTileY = tileY; + if (DAT_GameCore::instance.gameMode_2 != Game::GM_EDITOR + && DAT_GameCore::instance.gameMode_2 != Game::GM_SIEGE_THAT) { + // The cursor shows the delete as blocked with an enemy within 30 (15 outside a solitary game). + // The distance is set before the call (in the call: quick_diff 0.9679 -> 0.9116) + int requiredDistance; + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + requiredDistance = 15; + } else { + requiredDistance = 30; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, + DAT_PathFindingState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, tileX, tileY, requiredDistance)) { + DAT_TileMapState::instance.demolishBlocked = 1; + } + } + // Without a new click, deleting goes on only while the button is held over a wall or moat; otherwise + // both flags are cleared and nothing is deleted. + if (!DAT_MouseState::instance.leftClickStart + && ((!DAT_TileMapState::instance.placementOnWall && !DAT_TileMapState::instance.placementOnMoat) + || !DAT_MouseState::instance.leftClickState)) { + DAT_TileMapState::instance.placementOnWall = 0; + DAT_TileMapState::instance.placementOnMoat = 0; + return; + } + if (DAT_GameCore::instance.solitaryAltUDungeon + && DAT_ViewportRenderState::instance.viewportState.mouseRayUnitID != 0) { + int const unitID = DAT_ViewportRenderState::instance.viewportState.mouseRayUnitID; + if (DAT_UnitsState::instance.units[unitID].health != 0 + && DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_LORD + && !DAT_UnitsState::instance.units[unitID].dying + && DAT_UnitsState::instance.units[unitID].owner + == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { + // Two sums terrain first, the binary's load order (the draft's order: reccmp 100.0% -> 97.6%) + if (DAT_UnitsState::instance.units[unitID].unitType == OpenSHC::Map::Units::UT_E_ENGINEER + && DAT_UnitsState::instance.units[unitID].resourceToDeposit != 0) { + MACRO_CALL(OpenSHC::Map::Entities_Func::IgniteFireAtMiniTile_Convenience)( + DAT_UnitsState::instance.units[unitID].owner, + DAT_UnitsState::instance.units[unitID].microXPosition, + DAT_UnitsState::instance.units[unitID].microYPosition, + DAT_UnitsState::instance.units[unitID].terrainOrClimbHeight + + DAT_UnitsState::instance.units[unitID].buildingHeight - 8, + 5); + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, DAT_UnitsState::instance.units[unitID].owner, 0, + DAT_UnitsState::instance.units[unitID].microXPosition, + DAT_UnitsState::instance.units[unitID].microYPosition, + DAT_UnitsState::instance.units[unitID].buildingHeight + + DAT_UnitsState::instance.units[unitID].terrainOrClimbHeight, + 0, 0, 0, OpenSHC::Map::Entities::EntityTypeInt__ET_EXPLOSION, 0); + } + DAT_UnitsState::instance.units[unitID].dying = 1; + DAT_UnitsState::instance.units[unitID].tunnelerFinishedDigging = 1; + DAT_UnitsState::instance.units[unitID].animationCycleNumber = 0; + DAT_UnitsState::instance.units[unitID].state.generic + = OpenSHC::Map::Units::States::US_STONE_DEATH_01; + // EntityType has no constant for 30. + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, 0, 0, DAT_UnitsState::instance.units[unitID].microXPosition, + DAT_UnitsState::instance.units[unitID].microYPosition, + DAT_UnitsState::instance.units[unitID].buildingHeight + + DAT_UnitsState::instance.units[unitID].terrainOrClimbHeight, + DAT_UnitsState::instance.units[unitID].microXPosition + 1, + DAT_UnitsState::instance.units[unitID].microYPosition + 1, + DAT_UnitsState::instance.units[unitID].terrainOrClimbHeight + + DAT_UnitsState::instance.units[unitID].buildingHeight, + (OpenSHC::Map::Entities::EntityType)30, 0); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + DAT_UnitsState::instance.units[unitID].x, DAT_UnitsState::instance.units[unitID].y, + OpenSHC::DE::SHCDE::FX_DEATH_CLUB2); + return; + } + } + DAT_TileMapState::instance.buildingPlacementFailReason + = Map::Buildings::BFRE_DEFAULT_CANT_PLACE_THAT_THERE; + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::spreadFlagPlacementAlgorithm, + DAT_TileMapState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + DAT_TileMapState::instance.DAT_ClickedTileX, DAT_TileMapState::instance.DAT_ClickedTileY)) { + DAT_WallAndPitchState::instance.countdown = 0; + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 + = DAT_TileMapState::instance.DAT_ClickedTileX; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 + = DAT_TileMapState::instance.DAT_ClickedTileY; + // GameCommandType has no constant for 97. + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)((OpenSHC::Commands::GameCommandType)97); + return; + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::evaluateBuildingPlacementAtCursor, + DAT_TileMapState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + DAT_TileMapState::instance.DAT_ClickedTileX, DAT_TileMapState::instance.DAT_ClickedTileY); + if (DAT_TileMapState::instance.buildingPlacementFail != 0) { + // BuildingFailReasonEnum has no constant for 1000. + if (DAT_TileMapState::instance.buildingPlacementFailReason == 1000) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_MISC2, 2, 0, 100, 6000); + } else if (DAT_TileMapState::instance.buildingPlacementFailReason + != Map::Buildings::BFRE_DEFAULT_CANT_PLACE_THAT_THERE) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, + DAT_TileMapState::instance.buildingPlacementFailReason, 0, 100, 6000); + } + return; + } + DAT_WallAndPitchState::instance.countdown = 0; + int tile; + if (DAT_TileMapState::instance.placementOnMoat) { + tile = DAT_TileMapState::instance.savedCursorTile; + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = -1; + } else { + DAT_GameSynchronyState::instance.DAT_GameCommandParam1 = 50; + if (!DAT_TileMapState::instance.placementOnWall) { + int const targetID = DAT_TileMapState::instance.cursorTargetID; + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = targetID; + if (targetID < 0) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 + = DAT_TileMapState::instance.pitchDitches[-targetID].uid; + } else { + DAT_GameSynchronyState::instance.DAT_GameCommandParam2 + = DAT_BuildingsState::instance.buildings[targetID].uid; + } + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_DESTROY_BUILDING); + return; + } + tile = DAT_ViewportRenderState::instance.viewportState.cursorWallTile; + } + DAT_TileMapState::instance.MiscDisplayLayer[tile] |= 1024; + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = tile; + MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)(OpenSHC::Commands::GCT_DESTROY2Unk); + } + + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bf62e77d42..1df65c8bcc 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -12939,7 +12939,7 @@ SHC_3BB0A8C1_0x004387CE | 0.0% | Pending SHC_3BB0A8C1_0x004387CF | 0.0% | Pending -SHC_3BB0A8C1_0x004387D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004387D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00438B60 | 0.0% | Pending From 8f116ceaf8395e7cc71f190a2d48b20b6f5a9518 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 09:41:43 +0100 Subject: [PATCH 4/5] reimplement: SHC_3BB0A8C1_0x00492080 100.0% Reimplemented MenuItemRenderFunction_GameplayOptions_SpeedSlider, from gynt's draft on the fork branch reimpl/UI-MenuItems (81.4% there; 94.1% as a draft on batch4-development), written as SoundOptions_VolumeSlider and NewInvasion_RepeatSlider (both on main), the same slider with renderNumberToScreen2 for the speed. Shape: the file includes OpenSHC/UI/Enums/MenuItemRenderFunctionType.hpp (MIRFT_SLIDER_OR_SCROLLBAR is this function's render type) although nothing in it uses the enum. Without one more enum declared in the translation unit, MSVC swaps the registers of the thumb's two loads (the button's x and thumbXPos) when the struct resolvers are on: quick_diff 0.9535 -> 0.9070, reccmp 100.0% -> 94.1%. VolumeSlider gets the same from SoundOptions.hpp, which includes SoundMenuClickType.hpp: its source compiled in the SoundOptions namespace matches as it is. MenuModalType, MenuItemType or ScreenResolutionEnum would do the same; BOOLEnum, BGR24 and RGB15 (already declared) do not. Operand order, declaring the button's y first, names and the callee don't change it. isDragged is a BOOLEnum, as in VolumeSlider and RepeatSlider (the same code). Co-Authored-By: Claude Opus 5.5 --- ...erFunction_GameplayOptions_SpeedSlider.cpp | 54 +++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/GameplayOptions/MenuItemRenderFunction_GameplayOptions_SpeedSlider.cpp diff --git a/src/OpenSHC/UI/MenuItems/GameplayOptions/MenuItemRenderFunction_GameplayOptions_SpeedSlider.cpp b/src/OpenSHC/UI/MenuItems/GameplayOptions/MenuItemRenderFunction_GameplayOptions_SpeedSlider.cpp new file mode 100644 index 0000000000..dda3c80daa --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/GameplayOptions/MenuItemRenderFunction_GameplayOptions_SpeedSlider.cpp @@ -0,0 +1,54 @@ +#include "../GameplayOptions.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +// not used: one more enum in this file keeps the thumb's registers (without it: quick_diff 0.9535 -> 0.9070) +#include "OpenSHC/UI/Enums/MenuItemRenderFunctionType.hpp" + +#include "OpenSHC/Globals/AlphaAndButtonSurfaceObj.hpp" +#include "OpenSHC/Globals/COL_DARK_LIME.hpp" +#include "OpenSHC/Globals/COL_GREYISH_YELLOW.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonH.hpp" +#include "OpenSHC/Globals/DAT_ButtonW.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + namespace GameplayOptions { + + // FUNCTION: STRONGHOLDCRUSADER 0x00492080 + void MenuItemRenderFunction_GameplayOptions_SpeedSlider( + int unused, int thumbXPos, int speed, int thumbWidth, BOOLEnum isDragged) + { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + // -1: the plain tiled button (the slider's track) + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(-1, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + // the thumb: x and y before its colour; in the call they lose the match + int const thumbX = thumbXPos + DAT_ButtonX::instance; + int const buttonY = DAT_ButtonY::instance; + ushort color = COL_GREYISH_YELLOW::instance.shortValue; + if (isDragged) { + color = COL_DARK_LIME::instance.shortValue; + } + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::PencilRenderCore_Func::drawColorBox, DAT_PencilRenderCore::ptr)( + thumbX + 1, buttonY + 2, thumbX + thumbWidth - 2, buttonY + DAT_ButtonH::instance - 4, color); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + speed, DAT_ButtonW::instance + DAT_ButtonX::instance + 20, DAT_ButtonY::instance + 7, + OpenSHC::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 1df65c8bcc..e97c8ce043 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23449,7 +23449,7 @@ SHC_3BB0A8C1_0x0049206C | 0.0% | Pending SHC_3BB0A8C1_0x00492070 | 0.0% | Pending -SHC_3BB0A8C1_0x00492080 | 0.0% | Pending +SHC_3BB0A8C1_0x00492080 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00492120 | 0.0% | Pending From 87ed1558af1ecefa8ee07acd3f5c71983bd22c11 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Fri, 6 Nov 2026 09:51:03 +0100 Subject: [PATCH 5/5] reimplement: SHC_3BB0A8C1_0x004BB0D0 100.0% Reimplemented MenuItemRenderFunction_BuildingAvailability_Buttons, from gynt's draft on the fork branch reimpl/UI-MenuItems (60.1% there; 99.3% as a draft on batch4-development), without the gotos. Two behaviour fixes: - both button groups read BuildingAvailabilityStructIndexForNameArray with the button number minus 1000 or 2000, as the action handler does (the draft indexed field1234_0x312c and field1224_0x218c with the bare button number, which lands on the same table); - a row whose mapper has no menu (anything but the fletcher, poleturner, blacksmith and the two barracks, M_MAPPER_* as main's action handler names them) only sets ButtonUnknownZero and returns, as in the original's jump table; the draft went on to RenderScenarioButtonWithText. Shape: the toggle text's number comes from a short local and an if/else, which gives the original's neg/sbb; the text position is worked out in each branch, y then x, as in SaveLoadMap's Buttons render on main, so the last argument's push lands between the halving of the width and the add of DAT_ButtonX as in the binary (worked out once before the test: quick_diff 0.9000 -> 0.8909, reccmp 100.0% -> 99.3%; x then y ties). Also kept, with their numbers: one call per colour, which MSVC merges (one call with a colour local: 0.9000 -> 0.7763 for the toggle text, 0.8018 for the "!"); ButtonUnknownZero set before the switch and cleared in the cases (in a default: arm: 0.9000 -> 0.8869); textID set in each branch (a default overridden: 0.9000 -> 0.8545). The MappersEnum include leaves the code as it is. Co-Authored-By: Claude Opus 5.5 --- ...rFunction_BuildingAvailability_Buttons.cpp | 132 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/BuildingAvailability/MenuItemRenderFunction_BuildingAvailability_Buttons.cpp diff --git a/src/OpenSHC/UI/MenuItems/BuildingAvailability/MenuItemRenderFunction_BuildingAvailability_Buttons.cpp b/src/OpenSHC/UI/MenuItems/BuildingAvailability/MenuItemRenderFunction_BuildingAvailability_Buttons.cpp new file mode 100644 index 0000000000..6ae8177109 --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/BuildingAvailability/MenuItemRenderFunction_BuildingAvailability_Buttons.cpp @@ -0,0 +1,132 @@ +#include "../BuildingAvailability.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/AlphaAndButtonSurface.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/Commands/MappersEnum.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/string-literals.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_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + namespace BuildingAvailability { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BB0D0 + void MenuItemRenderFunction_BuildingAvailability_Buttons(int button, ...) + { + // Buttons from 1000 show whether a row is allowed, from 2000 the row's own menu button. + if (button >= 1000 && button < 2000) { + short const available + = DAT_MapPropertiesState::instance.buildingAvailability + [DAT_MissionAestheticsDefinedData::instance.BuildingAvailabilityStructIndexForNameArray + [DAT_MapPropertiesState::instance.DAT_BuildingAvailabilityScrollbarOffset + button + - 1000]]; + // Set in each branch, for the original's neg/sbb (a default overridden: quick_diff 0.9000 -> + // 0.8545) + int textID; + if (available) { + textID = 172; + } else { + textID = 173; + } + MACRO_CALL_MEMBER(Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + // One call per colour, which MSVC merges (one call with a colour local: quick_diff 0.9000 -> + // 0.7763) The position in each branch (once, before the test: quick_diff 0.9000 -> 0.8909) + if (!DAT_ButtonCurrentlyInteracting::instance) { + int const textY = DAT_ButtonY::instance + 6; + int const textX = 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, textID), + textX, textY, Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, FALSE, 0); + return; + } + int const textY = DAT_ButtonY::instance + 6; + int const textX = 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, textID), + textX, textY, Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, FALSE, 0); + return; + } + if (button >= 2000 && button < 3000) { + // Only the weapon workshops and the two barracks have a menu. + // Set before the switch, cleared in the cases (in a default: arm: quick_diff 0.9000 -> 0.8869) + DAT_ButtonUnknownZero::instance = TRUE; + switch (DAT_MissionAestheticsDefinedData::instance + .BuildingNameRelatedStructArray[DAT_MissionAestheticsDefinedData::instance + .BuildingAvailabilityStructIndexForNameArray + [DAT_MapPropertiesState::instance.DAT_BuildingAvailabilityScrollbarOffset + + button - 2000]] + .field_0x4[0] + .identifier1) { + case Commands::M_MAPPER_FLETCHER: + case Commands::M_MAPPER_POLETURNER: + case Commands::M_MAPPER_BLACKSMITH: + case Commands::M_MAPPER_BARRACKS_EURO: + case Commands::M_MAPPER_BARRACKS_ARAB: + DAT_ButtonUnknownZero::instance = FALSE; + MACRO_CALL_MEMBER(Rendering::AlphaAndButtonSurface_Func::renderBasicButton, + AlphaAndButtonSurfaceObj::ptr)(0, OpenSHC::Rendering::Enums::RT_CONTEXT_BASED); + // One call per colour (one call with a colour local: quick_diff 0.9000 -> 0.8018) + if (!DAT_ButtonCurrentlyInteracting::instance) { + // "!" + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s___005aa7fc, DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, + DAT_ButtonY::instance + 6, Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 19, + FALSE, 0); + } else { + // "!" + MACRO_CALL_MEMBER(Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + s___005aa7fc, DAT_ButtonW::instance / 2 + DAT_ButtonX::instance, + DAT_ButtonY::instance + 6, Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 19, + FALSE, 0); + } + return; + } + return; + } + // -2 and -1 are the scroll buttons. + switch (button) { + case -2: + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER( + Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, DAT_PencilRenderCore::ptr)(1, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + case -1: + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER( + Rendering::PencilRenderCore_Func::renderUpDownButtonUnk, DAT_PencilRenderCore::ptr)(0, 0); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + MACRO_CALL(Rendering_Func::RenderScenarioButtonWithText)(button); + } + + } + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e97c8ce043..dc3de6d1af 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -29121,7 +29121,7 @@ SHC_3BB0A8C1_0x004BB010 | 0.0% | Pending SHC_3BB0A8C1_0x004BB0B0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004BB0D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004BB0D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BB284 | 0.0% | Pending