Repository navigation
Reimplement 5 UI::MenuItems building menu and options functions at 100% - #344
Merged
Merged
Conversation
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 a9401a7. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
This was referenced Nov 6, 2026
gynt
approved these changes
Nov 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Five UI::MenuItems functions at 100%, each with its status line: the barracks' and the mercenary post's unit portraits, the build menu's delete tool, the game speed slider and the buttons of the building availability editor.
All five continue drafts on gynt's and 6and8's forks (
reimpl/UI-MenuItemsand-development, at 68-99% there). Every commit body says what changed against the draft and why. No header changes.Other PRs: the ready #342 and #343 (the fix for main's 15 files), and the drafts #313, #318, #321, #327 and #328.
Built on top of
main(d972299, and it merges cleanly into 57d3334) with the bundled MSVC1400-SP1, natively on Windows, against the SteamStronghold Crusader.exe(3bb0a8c1…5387ac5a). The branch was built and measured on its own, with the struct and function resolvers enabled locally (not committed), using sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. None of it has been run in game.It went through the same checks as #342: the points from the earlier reviews, a fresh-eyes review of every file (the behaviour fixes checked against the original's disassembly; its 22 points applied and measured),
openshc-pr-checkwith no errors, andstatus_regression.py, which finds nothing below a known score on main or any fork.Behaviour fixed compared with the drafts
Read from the original's asm; the commit bodies give the details.
DAT_EnoughGoldForRequestedUnitis not set, it clearsDAT_ButtonCurrentlyInteractingand returns. The draft cleared it and went on to draw the portrait.BuildingAvailabilityStructIndexForNameArraywith the button number less 1000 or 2000, as the action handler does (the draft usedfield1234_0x312c/field1224_0x218cwith the bare number, which reaches the same table). A row whose mapper has no menu (anything but the fletcher, poleturner, blacksmith and the two barracks) only setsButtonUnknownZeroand returns; the draft went on toRenderScenarioButtonWithText.MenuItemRenderFunction_BuildingAndStatusMenu_MercenaryPostPortraitsMenuItemActionHandler_BuildingAndStatusMenu_BarrackUnitPortraitsMenuItemActionHandler_BuildMenu_DeleteActionMenuItemRenderFunction_GameplayOptions_SpeedSliderMenuItemRenderFunction_BuildingAvailability_ButtonsKept as they are, and why
Each was measured; a one-line comment in the code says why.
!(a || b)and> 69 && < 77fold the same way;ifinstead of an early return, as in EngineerAndMonkPortraits on main (early return: 0.8738 -> 0.8350 and 0.8731 -> 0.8325);isEnemyTooCloseUnk, as in RepairBuildingButton (in the call: 0.9679 -> 0.9116; a ternary local ties);currentPlayerSlotIDread from the field each time (as a local: 0.9157 -> 0.8072);tileXread beforetileY(y first: 0.9679 -> 0.9598);OpenSHC/UI/Enums/MenuItemRenderFunctionType.hpp, which its code doesn't use. With the struct resolvers on and no other enum declared in the file, MSVC swaps the registers of the thumb's two loads (DAT_ButtonXandthumbXPos): quick_diff 0.9535 -> 0.9070, reccmp 100.0% -> 94.1%. VolumeSlider on main gets the same fromSoundOptions.hpp, which includesSoundMenuClickType.hpp, and matches as written. MenuModalType, MenuItemType or ScreenResolutionEnum work too; BOOLEnum (a typedef), BGR24 and RGB15 don't, and operand order, names and the callee make no difference. We picked the render-type enum because this is a slider render. If you'd rather not have the include, the function goes in at 94.1%.ButtonUnknownZeroset before the switch (in adefault:arm: 0.9000 -> 0.8869).GCT_UNKNOWN_97(next to GCT_UNKNOWN_98),ET_UNKNOWN_30(also spawned by spawnEraserTileEffect, spawnCrowForBuilding and spawnProjectileImpactDebris) andBFRE_UNKNOWN_1000. DeleteAction'sDAT_GameCommandParam1values 50 and -1 have no name yet.Proposed, not changed here
INT_00df3350is the index of the hovered unit in the barracks or mercenary post menu (0..6, fromunitType - UT_E_ARCHERor- UT_A_ARCHER), -1 when none (Unknown_Min1); BarracksWeaponAvailability readsEuroUnitResourceCosts[it]. Something likeINT_HoveredRecruitIndex?ViewportState::field_0x0is tested before everysetupMouseTileXY(DeleteAction, HandleWallTerrainMouseDrag, renderPreviewAtMouseLocation, ReturnToBuildMenu, viewportAndScrollingRelated). It reads as "the mouse is over the map view"; aBOOLEnumif every store is 0/1.BuildingNameRelatedStruct::field_0x4[3]:[0].identifier1is the row's mapper (both BuildingAvailability Buttons functions switch on it withM_MAPPER_*).DAT_DisableMercPostPortraits/Helpers::DisableMercPostPortraits()read the wrong way round: the merc post draws its portraits only while the global is non-zero, and DisableMercPostPortraits() sets it to 1.M_MAPPER_BARRACKS_EURO(86) andM_MAPPER_BARRACKS_ARAB(87) inMappersEnumhave their names swapped: 86 is the mercenary post (BT_MERCENARYPOSTmaps to 86), and the original's jump table sends 86 to modal 0x75, the Arab troops' dialog (handler and render useSEC_MercRecruitable). TheMMT_DISABLE_*names and the menu names are right. This PR uses the enum's names as they are.TileMapState::demolishBlocked,placementOnWallandplacementOnMoatonly ever hold 0 or 1 and read as flags:BOOLEnumcandidates (nowundefined4).🤖 Generated with Claude Code