Skip to content

Reimplement 5 UI::MenuItems editor and building menu renders at 100% - #346

Merged
gynt merged 5 commits into
sourcehold:mainfrom
kotijekriv:reimpl/batch13-100
Nov 6, 2026
Merged

gynt merged 5 commits into
sourcehold:mainfrom
kotijekriv:reimpl/batch13-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Five UI::MenuItems render functions at 100%, each with its status line: the weapon-disabling screen and two scenario editor controls (the up/down buttons and the start month), the outpost's unit buttons and the rows of the building availability table.

All five continue gynt's drafts on his fork (reimpl/UI-MenuItems and -development). Every commit body says what changed against the draft and why. No header changes.

Other PRs: the ready #342, #343 (the fix for main's 15 files), #344 and #345, and the drafts #313, #318, #321, #327 and #328.

Built on top of main (57d3334) with the bundled MSVC1400-SP1, natively on Windows, against the Steam Stronghold 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 #344: a fresh-eyes review of every file (behaviour checked against the original's disassembly, texts against cr.tex; its points applied and measured), openshc-pr-check, and status_regression.py, which finds nothing below a known score on main or any fork.

Behaviour fixed compared with the draft

  • EditScenario UpDownButtons: the draft had no return after the text and no else for the arrows. Buttons from 0 up now draw their text and return, where the draft also drew the down arrow (renderUpDownButtonUnk(1, 0)) after it; -1 now draws only the up arrow, where the draft drew both; other negatives (-2) draw the down arrow.

The other four do what their drafts did, which matches the original.

Class Function Address Raw Notes
DisableWeapon MenuItemRenderFunction_DisableWeapon_Main 0x004BB7B0 100.0% Finished from gynt's draft (the Ghidra output with gotos); the shape rebuilt. The menu has buttons 0-5 and -3 only, so 6 and 7 of the original's 0..7 range never occur.
EditScenario MenuItemRenderFunction_EditScenario_UpDownButtons 0x004B9060 100.0% Finished from gynt's draft; the arrow fix above. It also draws the scenario editor's text buttons (0 and up, TEXT_SCENARIO[button]).
EditScenario MenuItemRenderFunction_EditScenario_StartDateMonth 0x004BAC20 100.0% Finished from gynt's draft.
BuildingAndStatusMenu MenuItemRenderFunction_BuildingAndStatusMenu_OutpostUnitSelection 0x00466620 100.0% Finished from gynt's draft. The parameter is bitIndex, as main's handler for the same buttons (0x00466710) names it.
BuildingAvailability MenuItemRenderFunction_BuildingAvailability_TableRows 0x004BB3E0 100.0% Finished from gynt's draft (63.5% there).

Kept as they are, and why

Each was measured; a one-line comment in the code says why. Most of these are the per-branch shape: MSVC hoists or merges the code each branch writes out the way the original has it.

  • DisableWeapon:
    • the range test stays (uint)button <= 7, the original's unsigned compare (button >= 0 && button <= 7, < 8, !(button < 0 || button > 7) and 0 <= button all measure reccmp 100.0% -> 90.0%: MSVC then merges one of the returns);
    • a guarded if, not an early return (early return: quick_diff 0.8889 -> 0.8673);
    • iconOffsetY declared before the test, because the Exit block reuses its zero (inside the if: 0.8889 -> 0.7273);
    • the default: break; (without it: 0.8889 -> 0.8673);
    • each weapon case breaks to the icon (the return first: 0.8889 -> 0.7527);
    • the Exit text's position in each branch, y then x, as SaveLoadMap's Buttons render on main (once, before the test: 0.8889 -> 0.8788, reccmp 100.0% -> 99.1%);
    • one call per colour (a colour local: 0.8889 -> 0.7839).
  • UpDownButtons: the position in each branch, y then x (once, before the test: 0.9231 -> 0.9038, reccmp 100.0% -> 98.1%); one call per colour pair (colour locals: 0.9231 -> 0.5455; two ternaries: 0.5766).
  • StartDateMonth: the position and the month's text number in each branch, y, x, then the month (once, before the test: 0.9062 -> 0.8438, reccmp 100.0% -> 93.8%; the month first: 0.6970; in the call: 0.6857); one call per colour (a colour local: 0.9062 -> 0.5373).
  • OutpostUnitSelection: the pressed test and the button draw in each branch, as the binary has them twice (once, before the hover test: 0.9206 -> 0.5854); the position in each branch, y then x (in the calls: 0.9206 -> 0.8730, reccmp 100.0% -> 95.2%); one call per colour pair (colour locals: 0.9206 -> 0.4615).
  • TableRows: one call per colour (a colour local or a ternary: 0.9048 -> 0.5882); y, x, then the name's text number in each branch (the position once: 0.7857; x first: 0.8095; the name once, before the test: 0.7381, reccmp 100.0% -> 81.0%; the name first: 0.7045; in the call: 0.5208).

Proposed, not changed here

  • Building::outpostRelatedUnk1 (a short) is the outpost's selected-units mask: bit i is unit i of TEXT_IN_OUTPOST, the action handler 0x00466710 toggles it, and 0x00466620 shows the button pressed while the bit is set. Something like outpostSelectedUnitsMask?
  • PencilRenderCore::renderUpDownButtonUnk(int isDownButtonUnk, ...): confirmed, 0 is the up arrow (it scrolls up in 0x004B9020 and SaveLoadMap) and 1 the down arrow, so the first parameter could be BOOLEnum isDownButton.
  • MenuItemRenderFunction_EditScenario_UpDownButtons also draws the editor's text buttons, so the name is narrower than what it does.
  • TEXT_IN_OUTPOST (group 64): [0] "OutPost", [1-8] the European units, [9] "OutPost Arab", [10-17] the Arabian units. That's where the 9 and the + 1 in OutpostUnitSelection come from.

🤖 Generated with Claude Code

kotijekriv and others added 5 commits November 6, 2026 12:25
MenuItemRenderFunction_DisableWeapon_Main, rebuilt from the original; gynt's draft on the fork branch
reimpl/UI-MenuItems-development (59.1% there) is Ghidra's output with gotos and behaves the same. Buttons 0 to 7
draw their button and, for weapons 0 to 5 only while they cannot be made, the disabled icon (GID_INTERFACE_ICONS_2,
picture 45); button 1 moves down a pixel while hovered with its icon held in place. -3 is "Exit". The menu only has
buttons 0 to 5 and -3, so 6 and 7 of the original's 0..7 range never occur.
Shape: each weapon case breaks to the icon when its Producible flag (only ever 0 or 1) is clear and returns
otherwise (the return first: quick_diff 0.8889 -> 0.7527), with an explicit `default: break;` (without it: 0.8673);
one unsigned test for 0..7 (`button >= 0 && button <= 7`, `< 8`, `!(x < 0 || x > 7)` or `0 <= x`: 0.8673, reccmp
100.0% -> 90.0%) guarding the weapon block rather than an early return (0.8673), with iconOffsetY zeroed before it,
as the Exit block reuses that zero (inside the if: 0.7273); the X shift after the switch as `if (button != 0)`; the
Exit text's position worked out in each branch, y then x, as in SaveLoadMap's Buttons render on main (once, before
the test: 0.8889 -> 0.8788); one call per colour (one call with a colour local: 0.8889 -> 0.7839).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_EditScenario_UpDownButtons, rebuilt from the original; gynt's draft on the fork branch
reimpl/UI-MenuItems (66.7% there, the same on -development and -100) had no return after the text and no else for
the arrows. Fixed against the draft (the code follows the original):
- buttons from 0 up draw their scenario text and return; the draft then drew the down arrow
  (renderUpDownButtonUnk(1, 0)) as well;
- -1 draws only the up arrow (0) and the other negative buttons the down arrow (1); the draft drew both for -1.
The colours are COL_00A2FF on COL_003E66, or COL_FFFFFF on COL_000000 while hovered.
Shape: the text position worked out in each branch, y then x (once, before the test: quick_diff 0.9231 -> 0.9038);
one call per colour pair (one call with colour locals: 0.9231 -> 0.5455; with two ternaries: 0.5766).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_EditScenario_StartDateMonth, from gynt's draft on the fork branch reimpl/UI-MenuItems (59.4%
there), in main's namespace form with the ColorsEnum names. TEXT_MONTHS 12 to 23 are the full month names.
Shape: the position and the month's text number worked out in each branch, y, x, then the month (once, before the
test: quick_diff 0.9062 -> 0.8438; month first: 0.6970; between y and x: 0.7576; the month in the call: 0.6857);
one call per colour (one call with a colour local: 0.9062 -> 0.5373; the draft's ternary compiles branch-free).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_BuildingAndStatusMenu_OutpostUnitSelection, from gynt's draft on the fork branch
reimpl/UI-MenuItems (76.8% there), in main's namespace form: the parameter named bitIndex, as main's action handler
for the same buttons (0x00466710) names it; the unit bit as a plain shift; the text number as the outpost's text
offset + 1 + bitIndex (TEXT_IN_OUTPOST: each outpost's title, then its units, the Arabian ones from 9); the pressed
state as an if/else per arm; and the colours by their ColorsEnum names: COL_C2F0EB on COL_003E66, COL_CCFAFF on
COL_000000 while hovered.
Shape: the pressed test and the draw in each branch, as the binary has them twice (once, before the hover test:
quick_diff 0.9206 -> 0.5854); the text position worked out in each branch, y then x (in the calls: 0.9206 ->
0.8730); one call per colour pair (one call with colour locals: 0.9206 -> 0.4615). quick_diff still shows `test
eax, edx` where the binary has `test edx, eax`; reccmp, which compares the linked code, has no difference there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_BuildingAvailability_TableRows, from gynt's draft on the fork branch
reimpl/UI-MenuItems-development (63.5% there), in main's namespace form with the colours by their ColorsEnum names
(COL_CCFAFF hovered, COL_7F7F7F for a building that is not available, COL_C2F0EB otherwise); the availability flag
(only ever 0 or 1) is tested for truth, and buildingIndex is the row's index into the building tables.
Shape: one call per colour, which MSVC merges after the colour push as the binary does (one call with a colour
local, or a ternary in the call, compiles branch-free: quick_diff 0.9048 -> 0.5882); the text position and the name
number worked out in each branch, y, x, then the name (the position once, before the test: 0.7857; x first: 0.8095;
the name once, before the test: 0.7381; the name first: 0.7045; the name in the call: 0.5208).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gynt
gynt added this pull request to the merge queue Nov 6, 2026
Merged via the queue into sourcehold:main with commit 576d3c2 Nov 6, 2026
5 checks passed
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.

2 participants