Skip to content

Reimplement 6 UI::MenuItems text button renders at 100% - #345

Merged
gynt merged 6 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-MenuItems-8-100
Nov 6, 2026
Merged

gynt merged 6 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-MenuItems-8-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Six UI::MenuItems render functions at 100%, each with its status line: the buttons of the troop-disabling screens (European and Arabian), the tutorial box, the title entry at the game's start, the map transfer screen and the old menus' title buttons.

Five of them were in our draft #327, which drops them in the same push; UnusedSetName_ButtonsUnk continues gynt's draft on his fork. All six had one blocker left, the first push 0 scheduled late; computing the text position inside each path fixed it. 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 #346, 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 clean 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 with no errors, main's style_lint.py with nothing to report, and status_regression.py, which finds nothing below a known score on main or any fork.

Behaviour compared with the drafts

None of the six changes behaviour; each does what its draft did and what the original does.

  • DisableEuroTroops: the draft's SEC_MercRecruitable[param_1 + -7] is the same address as barracksRecruitability.array.barracksRecruitability[troopIndex]; the branch names it the way main's handler for the same screen does, without the negative index.
  • UnusedSetName_ButtonsUnk: gynt's draft stored DAT_ButtonUnknownZero = 1 only on the hidden path, behind a goto; the branch stores it before the tests, as the original does (0x0042675D). The final value is the same on every path.
Class Function Address Raw Notes
Unused MenuItemRenderFunction_UnusedSetName_ButtonsUnk 0x00426750 100.0% From gynt's draft. "OK" (8) is hidden while a title is set, "Change Your Title, Lord?" (25) while one is typed in.
DisableEuroTroops MenuItemRenderFunction_DisableEuroTroops_Main 0x004BB570 100.0% From #327 (98.4%). The spearmen's button is drawn 8 pixels further left.
DisableArabTroops MenuItemRenderFunction_DisableArabTroops_Main 0x004BB680 100.0% From #327 (98.2%).
TutorialBox MenuItemRenderFunction_TutorialBox_Main 0x004BD0F0 100.0% From #327 (97.9%). "Continue", "Exit" and "Skip".
EnterTitleOnGameStart MenuItemRenderFunction_EnterTitleOnGameStart_Button 0x00491C50 100.0% From #327 (97.7%). Its one caller passes 302, "Start Game".
SendReceiveMap MenuItemRenderFunction_SendReceiveMap_Main 0x004AC440 100.0% From #327 (97.3%). "Send" (68) is hidden while a map is being transferred.

Kept as they are, and why

Each was measured; a one-line comment in the code says why.

  • The position in each path, which MSVC hoists the way the original does (the position computed once above the if: DisableArab 98.2%, DisableEuro 98.4%, EnterTitle 97.7%, SendReceiveMap 97.3%, TutorialBox 97.9%, UnusedSetName 97.7%). The textX/textY locals stay too: the position written straight into each call measures DisableArab 68.4%, DisableEuro 73.0%, EnterTitle 58.1%, SendReceiveMap 59.0%, TutorialBox 71.2%, UnusedSetName 65.2%.
  • UnusedSetName: one call per path (a ternary colour: quick_diff 0.6966); == TRUE, since the original tests for 1 and then for 0, and every other reader of the field compares it with 1 (a truthiness test: 100.0% -> 85.4%).
  • TutorialBox: >> 1, because the original halves without the sign fix-up (/ 2: 100.0% -> 93.9%).
  • DisableEuro and DisableArab: troopIndex >= 0 && troopIndex <= 7 follows the original's ja 7, which lets 7 through, one past both 7-entry arrays (barracksRecruitability[7] is SEC_MercRecruitable[0], SEC_MercRecruitable[7] is SEC_XbowProducible_save). Both menus only pass 0-6 and -3, so it never happens. DisableEuro restores DAT_ButtonX for the spearmen only on the disabled path, as the original does (0x004BB594 returns before the add).

Proposed, not changed here

  • Commands::M_MAPPER_BARRACKS_EURO (86) and M_MAPPER_BARRACKS_ARAB (87) have their names swapped (also in Reimplement 5 UI::MenuItems building menu and options functions at 100% #344): convertBuildingTypeToCommandBuildingType maps BT_MERCENARYPOST to 86, and the original's BuildingAvailability jump table sends 86 to modal 0x75 (MMT_DISABLE_ARAB_TROOPS), whose menu items are this PR's DisableArab handler and render; 87 goes to 0x73 and the barracks. The MMT names, the menu names and this PR's names are right. aiPlaceAIVBuilding and shouldNotBuild... use both mapper names, so they are worth a look.
  • GameCore::isNameEntryActive reads inverted (as in Reimplement 5 UI::MenuItems SaveLoadMap and Unused functions at 100% #341): it is 1 when a title already exists (GameStartEnterName_Prepare stores 1 for a non-empty name), and the text box and "OK" are hidden then. Something like isTitleSet?
  • The tutorial globals: DAT_00df5540 is the step transition (0 none, 1 fade in, 2 fade out, from InitTutorialStepTransition), DAT_00df5558 the step's current action, DAT_00df555c the step's action count (TutorialStepActionCount[step]), and DAT_00df5560 whether the player has done what the action asks (only ever 0 or 1, a BOOLEnum candidate).
  • DAT_ButtonUnknownZero is 1 for a button that is hidden (here) or greyed out (NetworkSessions "Host"/"Join" without a modem): something like DAT_ButtonInactiveUnk?

🤖 Generated with Claude Code

kotijekriv and others added 6 commits November 6, 2026 12:40
Finished from gynt's draft on his fork (reimpl/UI-MenuItems, 84.8%), which no longer compiled on main: the GameCore
field at 0x118 is isNameEntryActive there now. The original stores DAT_ButtonUnknownZero = 1 before it tests anything,
returns on the hidden button (8, "OK", while a title is set, and 25, "Change Your Title, Lord?", while one is typed
in; isNameEntryActive is 1 when a title is already set, so its name reads the other way round) and stores 0 otherwise,
so the source does the same, without the decompiler's goto. Each path makes its own call and computes the text
position itself: the compiler merges the two calls into the original's one (a ternary colour compiles branch-free
instead: quick_diff 0.6966) and hoists the identical position above the branch the way the original does, which puts
the first push 0 where the original has it. The position computed once above the `if` measured 97.7%, as it did in
GameOptionsTextButton (0x004934F0); a comment says so. quick_diff 0.8478 (the renamed draft, 48 instructions against
44) -> 44/44 with only quick_diff's own artefacts left: the two colour immediates, which it prints as globals on the
original's side, and ret / ret 0. `== TRUE` stays: the original tests for 1 and then for 0 (a truthiness test: 100.0%
-> 85.4%), and every other reader of the field compares it with 1; a comment says so. DAT_ButtonUnknownZero takes TRUE
and FALSE (a BOOLEnum on main). The parameter is button, as the menu's handler calls it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (98.4%, the same code). The draft read SEC_MercRecruitable[troopIndex - 7], a negative
index; the address is barracksRecruitability.array.barracksRecruitability[troopIndex], as the handler for the same
screen reads it. Early returns, `troopIndex >= 0 && troopIndex <= 7` instead of the unsigned cast, COL_CCFAFF, no
casts. The text position is computed in each path: the compiler hoists the identical computation above the branch the
way the original does, which schedules the first push 0 where the original has it. Computed once above the `if`, as on
the draft, it measured 98.4%; a comment says so. Moved here from the draft sourcehold#327 (reimpl/UI-MenuItems-3-development,
8f88cf1). quick_diff is left with its own artefacts only: the two colour immediates, which it prints as globals on
the original's side, and ret / ret 0. The parameter is troopIndex, as the handler for the same screen calls it. A
comment says index 2 is the spearmen, whose button is drawn 8 pixels further left. The flag is tested for truthiness
(it is only ever 0 or 1; the same code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (98.2%, the same code), the same way as the euro troops render: early returns, both bounds
spelled out, COL_CCFAFF, no casts. The text position is computed in each path: the compiler hoists the identical
computation above the branch the way the original does, which schedules the first push 0 where the original has it.
Computed once above the `if`, as on the draft, it measured 98.2%; a comment says so. Moved here from the draft sourcehold#327
(reimpl/UI-MenuItems-3-development, 4581585). quick_diff is left with its own artefacts only: the two colour
immediates, which it prints as globals on the original's side, and ret / ret 0. The parameter is troopIndex, as the
handler for the same screen calls it. The flag is tested for truthiness (it is only ever 0 or 1; the same code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (97.9%, the same code): early returns, the button texts from cr.tex ("Continue", "Exit",
"Skip"), no casts (the counters it compares, DAT_00df5558 and DAT_00df555c, are ints on main), COL_CCFAFF. The text
position is computed in each path: the compiler hoists the identical computation above the branch the way the original
does, which schedules the first push 0 where the original has it. Computed once above the `if`, as on the draft, it
measured 97.9%; a comment says so. Moved here from the draft sourcehold#327 (reimpl/UI-MenuItems-3-development, 36d0a96).
quick_diff is left with its own artefacts only: the two colour immediates, which it prints as globals on the
original's side, and ret / ret 0. The parameter is button, as the handler for the same box calls it. `>> 1` stays: the
original halves without the sign fix-up (`/ 2`: 100.0% -> 93.9%), as its comment says. DAT_00df5560 is tested for
truthiness, as main's handler for the same box does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (97.7%, the same code): no TextAlignment local, an early return, COL_CCFAFF, no casts. The
text position is computed in each path: the compiler hoists the identical computation above the branch the way the
original does, which schedules the first push 0 where the original has it. Computed once above the `if`, as on the
draft, it measured 97.7%; a comment says so. Moved here from the draft sourcehold#327 (reimpl/UI-MenuItems-3-development,
8d25a1f). quick_diff is left with its own artefacts only: the two colour immediates, which it prints as globals on
the original's side, and ret / ret 0. The parameter is textIndex: it is only the text's index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewritten from gynt's draft (97.3%, the same code): early returns, COL_CCFAFF, decimal numbers, no casts. The text
position is computed in each path: the compiler hoists the identical computation above the branch the way the original
does, which schedules the first push 0 where the original has it. Computed once above the `if`, as on the draft, it
measured 97.3%; a comment says so. Moved here from the draft sourcehold#327 (reimpl/UI-MenuItems-3-development, 197b9d4).
quick_diff is left with its own artefacts only: the two colour immediates, which it prints as globals on the
original's side, and ret / ret 0. The parameter is buttonID: the button's ID, which is also its text's index. A
comment says what 68 is: "Send", hidden while a map is being transferred.

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 5b4dbdd 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