Skip to content

Reimplement 5 UI functions from gynt's drafts (100%) - #386

Merged
gynt merged 9 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round9-100
Nov 10, 2026
Merged

gynt merged 9 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round9-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Five more UI functions at 100%: four from gynt's drafts (below 100%), and one new function that one of them tail-calls. Each commit cites the drafts it builds on and credits him as co-author. All five are part of the rest of UI that gynt OK'd on 2026-11-09.

Function Address gynt's best draft
MenuItemActionHandler_MainMenu_Main 0x004251A0 71.7%
Helpers::InitTutorialState (new) 0x004BC6F0 none
MenuItemActionHandler_SingleplayerMapChoice_MapTableHeader 0x00449290 64.5%
MenuItemRenderFunction_LobbyMenu_ChatBox 0x0042AC90 54.5%
MenuItemRenderFunction_LobbyMenu_MapSelectTable 0x0042B4C0 56.4%

Measured on today's main (b6d9688).

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), resolvers enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • reccmp: a full build reads all five at 100.0%.
  • Last commit: it changes only comments, names and a bool to BOOLEnum. quick_diff output is identical for every file it touches.
  • Checks: openshc-pr-check gives no errors, and status_regression.py finds no score below a known one.
  • Not run in game.

Behaviour fixed compared with the drafts

  • LobbyMenu MapSelectTable draws the map's name once, with one text call per path, each followed by a return:

    • at 0x0042B737: x + 44, width 150, both moved by the first icon's 20 when it shows;
    • at 0x0042B7A4: x + 24, width 170.

    When the second icon showed, gynt's draft fell through and drew the name twice.

  • MainMenu's tutorial button tail-calls InitTutorialState (jmp 0x004BC6F0 at 0x00425458) instead of carrying its body inlined.

Header change (in a commit of its own)

gynt's Ghidra sync 2bd620b brought this line to main. Main (39ed817) is merged in (60802f9), so the commit now matches main, and the "Declaration/type change validation" check passes. The five files' quick_diff output is identical before and after the merge.

Helpers::InitTutorialState() is declared, with its resolver off (7d987ae).

  • Main declares nothing at 0x004BC6F0, and Ghidra has no name for it; the name is a proposal.
  • It reads no arguments: it calls InitTutorialStepTransition(1), then resets the tutorial state at 0xDF554C-0xDF5564 and 0xDF556C.
  • Its only reference is MainMenu's tail jump, so it is void __cdecl().

Kept as they are, measured with quick_diff (each has a one-line comment)

Function Kept The cleaner form
MainMenu the view switch and colour reset written out in cases 3 and 4 one copy after the switch: 0.9500 → 0.7756
MapTableHeader a guarded do-while for the name copy a for or a while loop: 0.9738 → 0.9283
MapTableHeader the sort reads the previous entry first the current entry first: 0.8151, against 0.9358 for the kept order when measured
ChatBox nested ifs in the original's block order early returns: 0.9671 → 0.6184
ChatBox the blend strength read again after the calls the blend local: 0.9671 → 0.8803
MapSelectTable the AI-setup flag written without it: 0.9781 → 0.9607
MapSelectTable descriptionGroup declared once for both calls at each call: 0.9781 → 0.9649
MapSelectTable the file name in a local as an argument: 0.9781 → 0.9518
InitTutorialState the stores as the original orders them start + 1, step + 2: 0.4091

The style-lint bot will post on the do-while; its comment gives the numbers above.

Other notes:

  • MapTableHeader reads DAT_ArrayOfMapIndices2[i - 1], as main's three other users do. At i = 0 that is the address the original reads (0x011275F8), which suggests the header's array starts 4 bytes earlier than declared. It could be fixed in the header; the code is left as main's users have it.
  • The '\0' in MainMenu stores into the char[1001] file name (rule 26).
  • MainMenu's buttons stay numbers: main has no enum for them, and each case has a comment.
  • The placeholders (DAT_00df55xx, INT_00df55xx, DAT_00b960dc, INT_00b95b64, INT_00b95954) have no Ghidra names yet; main's siblings use the same ones.

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 7 commits November 10, 2026 00:28
0x004BC6F0 is in the address list as a function but no header declares it, so its one caller, the main menu's
tutorial button (MenuItemActionHandler_MainMenu_Main, 0x004251A0, tail jump at 0x00425458), could only inline it.
It reads no arguments and ends in a tail jump to ResetTutorialActionTrackers (0x004BC6C0), so it is
void __cdecl(): it calls InitTutorialStepTransition(1), resets the tutorial state at 0xDF554C-0xDF5564 and 0xDF556C and fills
INT_ARRAY_00df5598 with each step's start. It sits among the other tutorial helpers in UI/Helpers, so it goes there,
after ResetTutorialActionTrackers. The name is a proposal: Ghidra has none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
InitTutorialState starts the tutorial's step tracking: InitTutorialStepTransition(1), the first step's action
count into DAT_00df555c, the restriction flag and current step cleared, the fixed values 32 and 36, and for each of
the 32 steps where it starts in INT_ARRAY_00df5598, two past the previous start plus the previous step's action
count, then ResetTutorialActionTrackers. Needs the header commit that declares it. Written from the original's
instructions; gynt's draft of the main menu's handler (c9bfdf1, 8725ec5 on his fork) had the same body inlined
there, which is where the reads come from. The form the original needs: the running start incremented before its
store and the step's count added after it (the store as start + 1 and the step as + 2: quick_diff 0.4091, a
different register for the zero). Also: countof for the 32 steps. quick_diff leaves only the tail call's form.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_MainMenu_Main handles the main menu's buttons: 1 the historical campaigns, 2 the crusades, 3
the castle builder, 4 multiplayer (only once DirectDraw is loaded), 5 quit, 6 the tutorial, 7 the credits, 8 the
options, 9 the custom scenarios. From gynt's draft (c9bfdf1 on his fork's reimpl/UI-MenuItems-development, 67.12%
there; his batch pass 8725ec5 left its status line at 71.7%). Needs the header commit that declares InitTutorialState: the tutorial button
ends in a tail call to it, where the draft had its body inlined. The form the original needs: the menu switch and
the player colour reset written out in both case 3 and case 4, each returning, so that MSVC jumps from case 3 into
case 4's copy as the original does (one copy after the switch on a view variable: quick_diff 0.7756, with ebx
zeroed before the dispatch). Also: the colour reset as a countof loop (MSVC unrolls it into the original's
nine copies), s_Crusader_tutorial_map_005a1ff8 for the string macro, DD7_LOADED for 1792 without the cast,
INT_00b95954, button for param_1, no unused usings or includes. quick_diff leaves the jump table's symbol,
ret / ret 0 and the tail call's form.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_SingleplayerMapChoice_MapTableHeader sorts the map list when a column header is clicked: 0
copies the order kept in DAT_ArrayOfMapIndices2, backwards after the first click (fileListSortOrder 0 / 1), 1 bubble
sorts by the file times (2 / 3), 2 by arrayOfMapEndInt2 (lobbyMapSortOrder 5 / 6); then the map table is refreshed
and lastClickedListIndex cleared. Written from the original's instructions, with gynt's draft (755f040 on his
fork's reimpl/UI-MenuItems, 64.54% there; then his batch pass 8725ec5) for the reads. No header change: main's
arrayOfMapEndInt2[500] at 0xB0 is the array the draft indexed through DAT_ArrayOfMapU3EndInt2, and
DAT_ArrayOfMapIndices2 is read with - 1, as its three other users on main do. The forms the original needs: the next
entry read before the current one in the sort loops (the other order swaps eax and ecx: quick_diff 0.8151 ->
0.9358), and the forward copy as a guarded do-while (as a for loop MSVC makes it rep movsd). Also: no decompiler
locals, the sort passes as for loops on the swap count, column for param_1. quick_diff leaves ret / ret 0 and the
jumps over the loops' alignment
padding, which their npad hides.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LobbyMenu::MenuItemRenderFunction_LobbyMenu_ChatBox, from gynt's draft (557a0e2, 54.49%, on his fork's
reimpl/UI-MenuItems; 53.8% in 8725ec5 on reimpl/UI-MenuItems-development), rewritten from the binary. Button -3
draws the chat messages, -2 the line being typed with its cursor, -1 the player's own name and the others the
waiting room's texts. The branches are nested in the original's block order (early returns for -3 and -2 measure
lower), and the waiting room's text comes before the -1 name, as the original lays them out. The y position is
written in both calls, so MSVC shares their pushes as the original does, and the -2 branch reads the blend strength
again after its calls. reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapSelectTable, from gynt's draft (5467a25, 56.44%, on his fork's
reimpl/UI-MenuItems-development), rewritten from the binary. The draft drew the map's name twice when the second
icon shows; the original draws it once, beside that icon (150 wide) or 20 pixels further left (170 wide), both less the first icon's
20 when it shows (iconsWidth). The file
name is fetched into a local before the text call, as the original's call order has it (as an argument,
&descriptionGroup is pushed first), and DAT_ButtonUnknownZero is set from a flag for the round table and the two AI
lord selects (a guest stores TRUE, then FALSE), which gives the original's shared store. reccmp 100.0%.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ings

- LobbyMenu MapSelectTable: the AI-setup flag is a BOOLEnum, and the file and map names are loadedName and mapName,
  as main's SingleplayerMapChoice_MapTable names them. The three kept shapes give their measurements: no flag
  0.9607, descriptionGroup at each call 0.9649, the file name as an argument 0.9518 (against 0.9781).
- LobbyMenu ChatBox: the nesting (early returns 0.6184) and the blend strength read again (the blend local 0.8803,
  against 0.9671) in main's one-line form.
- SingleplayerMapChoice MapTableHeader: the do-while gives its measurement (a for or a while loop: 0.9283, against
  0.9738), and the name sort's comment no longer explains the - 1.
- MainMenu: the shared tail's comment in main's form (one copy after the switch: 0.7756, against 0.9500).
quick_diff output is identical for all four files.

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 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Style guide reading (advisory, posted once)

1 possible deviation(s) from REIMPLEMENTATION_STYLE_GUIDE.md across 1 of the 5 reimplemented .cpp file(s) in this PR.

The match comes first. Where the ugly form is what matched, it stays -- that is the guide's own overriding rule, and rule 21 asks for a one-line comment saying what was measured so the next reader does not retry it. This report is posted once, when the PR opens, and is not repeated on later pushes.

rule what it asks hits
9 Prefer for over while/do 1
Where

Rule 9 — Prefer for over while/do

  • src/OpenSHC/UI/MenuItems/SinglePlayerMapChoice/MenuItemActionHandler_SingleplayerMapChoice_MapTableHeader.cpp:31 — do-loop; the guide asks for a for

Main's Ghidra sync 6c1e0bd brought this branch's header changes; main's versions are kept.

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