Skip to content

Reimplement 5 UI functions from gynt's drafts and #318/#327/#328, with one header commit (100%) - #410

Open
kotijekriv wants to merge 7 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round13-100
Open

kotijekriv wants to merge 7 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round13-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Five more UI functions at 100%, with one header commit: MenuModalComposition's slider minimum and maximum become ints, which the OverlaySlider handler needs. All five build on gynt's drafts. Each commit cites the drafts it builds on and credits him as co-author. Three of the five were also in our drafts #318, #327 and #328, which they now leave. All five are part of the rest of UI that gynt OK'd on 2026-11-09.

Function Address Before After
OverlaySlider::MenuItemActionHandler_OverlaySlider_Slider 0x004AA600 gynt's draft 47.37% (593c4ef); this branch's code reads 57.1% without the header commit 100.0% (1566007, with cfc7e1d)
HistoricCampaignSelect::MenuItemRenderFunction_HistoricCampaignSelect_Main 0x004255D0 our draft #327, 98.7% (90d1284); gynt's 97.44% (d07873b) 100.0% (b607ec8)
SaveLoadMap::MenuItemRenderFunction_SaveLoadMap_TableHeader 0x00492FD0 gynt's draft 97.44% (78de101) 100.0% (133c2c2)
CrusadeMap::MenuItemActionHandler_CrusadeMap_Main 0x004D8EC0 our draft #328, 35.2% (2d468df); gynt's 34.80% (3d6fb54) 100.0% (cf7b873)
General::MenuItemActionHandler_General_ToolbarButtonPressed 0x00444410 our draft #318, 71.40% (c00f64a); gynt's 67.74% (9dc4216) 100.0% (b1710db)

All five read 100.0%, raw and normalised.

Measured on main 3416498.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp (6f980a441) with --resolve-wrapped-calls --ignore-security-cookie.
  • Full build: all 2,363 source files of main 3416498 as the baseline, against the same with this branch (2,368 files). This build was made just before our own last review pass (branch tip cf5bc84c0, whose header commit also made sliderValue an int). All five read 100.0%, raw and normalised. Of the 2,381 functions measured on main, 2,378 read exactly the same with this branch, setSliderParameters, setSliderParameters2 and UnusedWinCondition's Options handler among them. Three move, and none of them because its code changed:
    • UI::Menu::Constructor_Menu (100.0% to 98.4%) and UI::Menu::handleMenuItems (100.0% to 97.9%) compare with the constant 0x11000000. With this branch the DLL's layout puts a symbol at that address, so reccmp names the constant after it. It is the same thing Reimplement 5 UI functions from gynt's drafts and #328 (100%) #407 saw the other way round, and neither file changes.
    • InGameMenu's MainButtons handler (0x00444B80) reads 100.0% raw instead of 99.77%. It tail-jumps to ToolbarButtonPressed, whose resolver is now on, so the jump target matches. Normalised it reads 100.0% either way.
  • After the review pass: the changes it made are listed under "Cleanups from our own review" below. All five were measured again in one build of the five: 100.0% raw and normalised each, with no compiler warnings.
  • Checks: openshc-pr-check gives no errors, and status_regression.py finds no score below a known one.
  • Not run in game.

What got them to 100%

  • OverlaySlider handler: with the slider's minimum and maximum as ints (the header commit below), the range test and the divisions by 5 compile signed, as in the original. Case 1 then stores the current value once, after the large-range and small-range branches, rather than at the end of each. MSVC then gives the small-range branch the original's scratch registers, and cases 2 and 3 follow. Case 7 tests *currentValue > *maxValue / 2 for the step of 1, which gives the original's setle.
  • HistoricCampaignSelect render: the last difference was the text call loading ecx after both of its pushes, where the original loads it between them. The campaign name is now drawn by two calls that are the same, one per hover state, each with the position read into textY then textX. MSVC merges the two completely, so no branch is left, and keeps the original's order. It is the same form as MainMenu's render (0x00424F50, from Reimplement 5 UI functions from gynt's drafts and #328 (100%) #407), the sibling this function looks copied from.
  • SaveLoadMap TableHeader render: the same difference and the same fix: the header text is two identical calls, one per hover state, each with textY then textX. The column switch and its text numbers were already gynt's.
  • CrusadeMap Main handler: rewritten from the binary, with the buttons in the original's block order and early returns. The buttons are Skip Current Mission (1000), the lord's face for the mission briefing (10), back to the choice of crusade (11), a click on the map (1) and the rankings (99). Skip Current Mission repeats the setStartDateUnk call and everything after it in each trail's branch, and MSVC merges the three copies into the first one, where the original has its code. The click test reads each mission's position as left = x - 10 and top = y - 10, and compares with left + 20 and top + 20, which is how the original computes both bounds.
  • ToolbarButtonPressed handler: on main the draft needed only renames to compile (buildingEntryInfos, unitIDSelectedCatapultOrTrebuchet and field_0x30). The cases are in the original's block order. The siege engines (with the Arab ballista) and the tunnel are plain cases that break to the code after the switch, and the three stances each make their own call. The eight building buttons each move the view to their building in their own copy of that code, and MSVC merges the copies into the granary's, where the original has them. The tunnel button tests for no tunneler first.

Behaviour fixed compared with the drafts

  • CrusadeMap Main handler (the draft in Reimplement 24 UI::MenuItems functions from gynt's drafts (not yet 100%) #328 had the same two, and the same cleanup):
    • The first edition and extreme trails tested the click's y the wrong way round. Ghidra's y + -clickY >= 10 is clickY <= y - 10, where the original tests clickY >= y - 10 (cmp edi, ecx and jl at 0x4d90d3 and 0x4d9173), so a mission could only be picked by clicking above it.
    • The warchest and extreme searches went one mission too far (> 30 and 20 <), which read one position past the end of the warchest table. The original stops below 30 and below 20 (cmp edx, 0x1e at 0x4d9131, cmp edx, 0x14 at 0x4d9180).
    • A cleanup rather than a fix: a click wrote all three trails' progress back, two of them unchanged. The original stores only the trail being played (one store per trail, at 0x4d90ea, 0x4d913b and 0x4d918a).
  • ToolbarButtonPressed handler, Engineer Build (the draft in Reimplement 6 UI::Helpers and UI::MenuItems functions (not yet 100%) #318 had the same two):
    • With one catapult or trebuchet selected and under 10 stone, the original only plays the lack-of-stone sound and returns (the test at 0x444990, the sound at 0x4449a1, the return at 0x4449aa). The draft queued the command anyway.
    • After queueing the command for one engine or for the selection, the original returns (0x4449cd and 0x4449f3). The draft went on to clear the patrol button and mark an engineer as selected.

Header change (a commit of its own)

MenuModalComposition::sliderMinimum and sliderMaximum are ints (cfc7e1d), not dwords.

  • The OverlaySlider handler (0x004AA600) tests sliderMaximum - sliderMinimum > 200 with a signed jle (0x4aa630, 0x4aa697 and 0x4aa7a3), and divides by 5 signed for range * 3 / 5 (0x4aa635 and 0x4aa6c4).
  • With the two fields as ints the handler reads 100.0% instead of 57.1%, on main 1d819b7 and again on 3416498.
  • On main the only other users of the two fields are setSliderParameters (0x004AA480) and setSliderParameters2 (0x004AA540). They only store to them, so they compile the same. In the full build above they read exactly as on main.
  • sliderValue stays a dword. The handler only copies it, and compiles to the same code either way.

The declaration check will fail and label this PR until main has these two lines. Then I'll merge main in.

Three functions leave the drafts

Each draft gets one commit that removes the .cpp and puts its status line back to main's (fb28cf0 on #318, 2da7d39 on #327, 3e3b705 on #328). None of the three drafts changes a header, and each still compiles without its function. No other open PR has any of the five.

Kept as they are

Function Kept The cleaner form
OverlaySlider handler case 1 storing the current value once, after both range branches the store at the end of each branch: 91.5% in reccmp
HistoricCampaignSelect render two identical text calls, one per hover state one call: 98.7% in reccmp (#327's version)
SaveLoadMap TableHeader render two identical text calls, one per hover state one call: 97.44% in reccmp (gynt's version); position locals alone measured the same
CrusadeMap Main handler Skip Current Mission's setStartDateUnk call and what follows, repeated in each trail's branch one call after the trail branches: 0.9395 in quick_diff; a switch on the trail type: 0.8419
CrusadeMap Main handler the click bounds as left = x - 10 and left + 20 x - 10 and x + 10: 0.6075 in quick_diff
ToolbarButtonPressed handler each stance making its own call one shared call: 0.6693 against 0.7085 in quick_diff
ToolbarButtonPressed handler each of the eight building buttons with its own copy of the focus-on-building code one shared label, as the draft had it: 0.7085 against 0.8915 in quick_diff, and 75.2% in reccmp (61.3% normalised) against 100.0%

quick_diff stops the original's ToolbarButtonPressed after the siege-engine case, so it reads 0.8939 for the version at 100.0% in reccmp. Its numbers above compare shapes with each other.

The two-call forms, the repeated code in CrusadeMap and ToolbarButtonPressed, and ToolbarButtonPressed's case order each have a one-line comment in the code that says why. In the OverlaySlider handler's large-range store into the 16-bit destination2, the operands keep their (short) casts, with a comment: the original does that subtract and add in 16 bits (sub cx, ax and add cx, bx at 0x4aa716 and 0x4aa719).

Cleanups from our own review

All of these compile to the same instructions as before (quick_diff's instruction hashes), and the five still read 100.0%:

  • OverlaySlider handler: the three narrowing (short) casts on the stores into destination2 are gone; the parameters are unused and scrollbarEvent, as in main's other scrollbar handlers; the pointer tests read != NULL.
  • ToolbarButtonPressed handler: SetTribesPatrolButtonPressed(FALSE)/(TRUE), getWallTilesThatCanBeBuilt(..., RT_STONE), no (int) on the RNG's short currentNumber1, and the gate cases' parentheses made explicit.
  • CrusadeMap Main handler: the face copy is 66 * 64 pixels and 66 * 64 * sizeof(ushort) bytes, and the first edition and warchest bounds are countof(...) - 1 of their position tables.
  • HistoricCampaignSelect render: the parameter is button.
  • SaveLoadMap TableHeader render: the column texts are in comments ("Name", "Date" and "Mission", from TEXT_GAME_OPTIONS).

Numbers left as numbers:

  • The case labels in the OverlaySlider handler (the scrollbar's event codes 1 to 7) and in SaveLoadMap's TableHeader (the table's column, 0 to 2): there is no enum for either on main.
  • CrusadeMap's button numbers (1000, 10, 11, 1 and 99), the -1200 months that mark a skipped mission, the 258 passed to setSoundWithVariation, whose parameter is a plain int sound number on main, and the extreme trail's 19 and 20: its position table has 30 entries, of which the first 20 are missions, so countof doesn't fit there.

What some placeholders hold

  • INT_00eb9b48: the crusade map's highlight animation. It is set to 1, with the start time in DWORD_00ed27a8, when the map opens (CrusadeMap's Prepare on main) and when a mission is picked here. gynt's draft of the map's DoEveryFrame runs it in 40 ms steps and sets it back to 0.
  • INT_00b95abc: the last hovered button, as in MainMenu's render (Reimplement 5 UI functions from gynt's drafts and #328 (100%) #407). Here it is the campaign button (0 to 4): the render plays the hover sound only when it changes, and puts it back to -1 when that button is no longer hovered.
  • GameCore::field_0x30: a build-menu tab. ToolbarButtonPressed compares it with activeMenuTab.tabType and copies it into buildmenuMenuTabToSwitchTo.tabType (both BuildingsAndStatusMenuTabTypeInt) before it switches to the build menu, and General's Unknown2 handler (0x00434260) sets it.
  • DAT_00b96110: ToolbarButtonPressed sets it to 0 after the tutorial test, before the switch. Nothing else reimplemented uses it.

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 6 commits November 14, 2026 13:30
sliderMinimum and sliderMaximum were dword. The original treats them as signed: the OverlaySlider handler
(0x004AA600) tests `sliderMaximum - sliderMinimum > 200` with jle (0x4aa630, 0x4aa697, 0x4aa7a3) and divides by 5
signed (0x4aa635, 0x4aa6c4). With the fields as int the handler measures 100.0 instead of 57.1 (reccmp, main
1d819b7; the same again on 3416498). The only other users of the two fields, setSliderParameters and
setSliderParameters2, only store to them, so they compile the same.

sliderValue stays dword: the original only copies it, and the handler compiles to the same code either way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_OverlaySlider_Slider, from our own drafts at 89.8% and 91.5% (local, never pushed), themselves
rewritten from gynt's draft (593c4ef at 47.37% on his fork's reimpl/UI-MenuItems-development; his last style pass
on the file is f6c6b8b). It needs the slider minimum and maximum as ints (the MenuModalComposition header commit
before this one); with them reccmp reads 100.0, normalised 100.0.

The fix: case 1 stores the current value once, after the large-range and small-range branches, rather than at the
end of each. MSVC then gives the small-range branch the original's scratch registers, and case 2 and 3 follow
(the store in each branch measured 91.5). Case 7 tests `*currentValue > *maxValue / 2` for the step of 1, which
gives the original's setle.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_HistoricCampaignSelect_Main, from the draft sourcehold#327 (reimpl/UI-MenuItems-3-development,
90d1284 at 98.7%; the file's newest commit on the draft is 446f9fa), itself rewritten from gynt's draft
(d07873b at 97.44%, after his 61351fe at 82.1% and 245178b at 94.87%; on his fork's
reimpl/UI-MenuItems-development the function is 04f12f8 at 67.10%, his newest reimplement commit on the file is
8725ec5 and his last style pass 5084980). reccmp 100.0, quick_diff 78/78 at 1.0000.

The last difference was the getTextStringInGroupAtOffset call loading ecx after both its pushes, where the original
loads it between them. The campaign name is drawn by two calls that are the same, one per hover state, each with the
position read into `int const textY` then `textX`: MSVC merges them completely and keeps the original's order. It is
the same form as in MainMenu's render (0x00424F50), the sibling this function was copied from. The early returns,
the branch order, the sound ID SEID_UNKNOWN_0x92 and the campaign names from cr.tex were already in the draft.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_SaveLoadMap_TableHeader, from gynt's draft (78de101 at 97.44% on his fork's
reimpl/UI-MenuItems, after his 0747a3c; on his reimpl/UI-MenuItems-development the file has 2002473, and his
newest reimplement commit on it there is 8725ec5; quick_diff 0.9744 on main). reccmp 100.0, quick_diff 39/39 at
1.0000.

The draft's only difference was the getTextStringInGroupAtOffset call loading ecx after both its pushes, where the
original loads it between them. As in HistoricCampaignSelect's render (0x004255D0, earlier on this branch), the header
text is written as two calls that are the same, one per hover state, each with `int const textY` then `textX`: MSVC
merges them completely, leaving no branch, and keeps the original's order. Position locals alone measured the same as
the draft. The column switch and its text numbers were already gynt's ("Name", "Date" and "Mission" in
TEXT_GAME_OPTIONS); the colour is COL_CCFAFF, the font size 18, and the parameter is the column.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_CrusadeMap_Main, rewritten from the binary. It starts from gynt's draft (00e21e3, 59034df
and 98dc115 on his fork's reimpl/UI-MenuItems, 33.48% there; 3d6fb54 at 34.80% on his
reimpl/UI-MenuItems-development, his newest reimplement commit on the file) and our mechanical pass of it in sourcehold#328
(2d468df, 35.2%). reccmp 100.0 (normalized 100.0), quick_diff 215/215 at 0.9907, the rest being the timeGetTime
import call, which reccmp resolves.

The buttons are Skip Current Mission (1000), the lord's face for the mission briefing (10), back to the choice of
crusade (11), a click on the map (1) and the rankings (99), in the original's block order with early returns. What the
match needed:
- Skip Current Mission repeats the setStartDateUnk call and everything after it in each trail's branch. MSVC merges the
  three copies into the first one, as the original has them, and the constant 1 then goes to ebp; one call after the
  trail branches, or a switch on the trail type, measured 0.9395 and 0.8419.
- The click test reads each position as `left = x - 10` and `top = y - 10`, compared with `left + 20` and `top + 20`,
  which is how the original computes both bounds (0.6075 with x - 10 and x + 10).

Fixes against the draft:
- The first edition and extreme trails tested the click's y the wrong way round (Ghidra's `y + -clickY >= 10`, that
  is clickY <= y - 10, where the original tests clickY >= y - 10), so a mission could only be picked by clicking above
  it.
- The warchest and extreme searches went one mission too far (`> 30` and `20 <`), reading one position past the end
  of the warchest table; the original stops below 30 and 20.

Cleanup: a click wrote all three trails' progress back, two of them unchanged; the original stores only the trail
being played.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_General_ToolbarButtonPressed, from gynt's draft (d2993ae, 6e17808, 8a21939 and b984b98
on his fork's reimpl/UI-MenuItems, 65.02% there; a1c4156 at 67.59% and 9dc4216 at 67.74% on his
reimpl/UI-MenuItems-development, 9dc4216 being his newest reimplement commit on the file) and our own draft in sourcehold#318
(c00f64a at 71.40% on reimpl/batch2-development), rearranged from the binary. The function leaves sourcehold#318 with this
commit. reccmp 100.0 (normalized 100.0). quick_diff reads 0.8939 because it stops the original after the siege-engine
case.

On main the draft needed only renames to compile: buildingEntryInfos for the eight building references,
unitIDSelectedCatapultOrTrebuchet and field_0x30. What the match needed:
- The switch cases in the original's block order. The siege engines (with the Arab ballista) and the tunnel are plain
  cases that break to the code after the switch, and the three stances each make their own call (quick_diff
  0.6693 -> 0.7085).
- The eight building buttons each move the view to their building in their own copy of that code. MSVC merges the
  copies into the granary's, where the original has them, followed by the code after the switch (0.7085 -> 0.8915);
  one shared label puts the block after the last of them instead: reccmp 75.2 (normalized 61.3) against 100.0.
- The tunnel button tests for no tunneler first.

Fixes against the draft:
- With one catapult or trebuchet selected and under 10 stone, the original only plays the lack-of-stone sound; the
  draft queued the command anyway.
- After queueing the command for one engine or for the selection, the original returns; the draft went on to clear
  the patrol button and mark an engineer as selected.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 14, 2026
Main's Ghidra sync 1b36c0a has this PR's MenuModalComposition slider
types, so the PR no longer changes a header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 17, 2026
@kotijekriv

Copy link
Copy Markdown
Contributor Author

Main is merged in now (e086ba7). Its Ghidra sync 1b36c0a has this PR's MenuModalComposition slider types, so the PR no longer changes a header and the declaration check passes.

Because of the symbol-count effect gynt found on #366, we measured again after the merge. This was a full build of main e086ba7 with this PR and #409 merged on it, against a full build of main alone.

  • All five functions here read 100.0%, raw and normalised.
  • No function on main reads lower than in the baseline.
  • One reads higher: InGameMenu's MainButtons action handler (0x00444B80), 99.8% to 100.0%. It calls ToolbarButtonPressed, which this PR reimplements.

MapEditorLandscaping's GeneralButtons action handler (0x004314E0) doesn't compile on main since the sync retyped editorRockType and rockOrientation. #366 changes that file, so it was left out of both builds.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant