Skip to content

Reimplement 5 UI functions from gynt's drafts and #328 (100%) - #407

Merged
gynt merged 5 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round12-100
Nov 14, 2026
Merged

gynt merged 5 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round12-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Five more UI functions at 100%, with no header changes. Three of them are rewrites of gynt's drafts, with his draft used for the reads. The other two come from our draft #328, which started from his versions too. 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 Before After
ChooseNetworkServiceProvider::MenuItemActionHandler_ChooseNetworkServiceProvider_Buttons 0x004909E0 our draft #328, 79.4% (306a61a); gynt's 76.2% (8725ec5; 72.84% at 1674e0f) 100.0% (see below)
SinglePlayerMapChoice::MenuItemActionHandler_SingleplayerMapChoice_ButtonsAndHands 0x0042D640 our draft #328, 75.1% (031cb7d); gynt's 72.67% (f3cef40) 100.0% (see below)
MainMenu::MenuItemRenderFunction_MainMenu_Main 0x00424F50 gynt's draft 81.39% (f2e9ae2) 100.0%
OnlineVoteQuitAndQuitGame::MenuItemActionHandler_OnlineVoteQuitAndQuitGame_Main 0x00495860 gynt's draft 80.93% (9d44bf4) 100.0% (see below)
LobbyMenu::MenuItemRenderFunction_LobbyMenu_MapSelectHeader 0x00427740 gynt's draft 74.80% (305b2b1; 73.2% at 8725ec5) 100.0%

All five read 100.0%, raw and normalised, in the full build described below. Built with only this round's five files, three of them read just under 100% raw and 100.0% normalised: ChooseNetworkServiceProvider's Buttons 99.2%, SingleplayerMapChoice's ButtonsAndHands 99.7% and OnlineVoteQuit 98.2%. In each the only difference is the target of a tail jump that goes through a resolver, so they are 100% either way by the call-target rule. In the first and the last that is resetMouseState2 (0x004689D0), which is on main with its resolver off. ChooseNetworkServiceProvider's Buttons jumps to it three times, and reccmp reads two of ours as different targets.

Measured.

  • 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, before the last small fixes and the rebase: all 2,351 source files of main 1d819b7 with this branch merged in, against a full build of main alone as the baseline (2,346 files). All five read 100.0% raw. Of the 2,364 functions measured on main, 2,362 read exactly the same with this branch and none read lower. Two read higher, UI::Menu::Constructor_Menu (98.4% to 100.0%) and UI::Menu::handleMenuItems (97.9% to 100.0%), and that is reccmp, not the code: both compare with the constant 0x11000000, and in main's DLL a symbol happens to sit at that address, so reccmp names the constant after it. With this branch the DLL's layout moves and the constant reads as a constant again. Neither file changes.

  • Since then: the branch now sits on main 72c6a2e, which has Reimplement 7 UI functions from gynt's drafts, and DAT_ButtonBlendStrength as an int (100%) #400 and Reimplement 5 UI functions from gynt's drafts and #327/#328, with three header commits (100%) #406; the rebase changed none of the five files. The branch also changed in small ways:

    • ChooseNetworkServiceProvider's two join-case flags are BOOLEnum, and its index wrap, shift loop and last slot use countof(ipRelatedArray), as its two search loops already did. Both compile to the same code.
    • Each of the four switches has a one-line comment saying its cases are in the original's block order. SingleplayerMapChoice's cases 67 and 76 are labelled with their mission types, and MapSelectHeader's three text numbers have their strings as comments ("Bl", "No" and "Name", texts 410, 61 and 62 of TEXT_XPLAY_WAITING_ROOM).
    • MapSelectHeader's fade local is now blendStrength, and the comments on the kept shapes say why each shape stays.
    • A duplicate using and some stray blank lines are gone.

    All five were measured again after these changes, with only this branch's five files built, and read as above.

  • Checks: openshc-pr-check gives no errors.

  • Not run in game.

What got them to 100%

  • ChooseNetworkServiceProvider Buttons: the join case is written without the draft's gotos and hand-unrolled string loops. The typed address is stored only when it isn't empty (strlen(...) != 0), isn't already in the list (a found flag over the four entries), in the first empty slot (a stored flag, then strcpy), or else at the end after the list moves up one. MSVC threads both flags away and inlines strlen and strcpy into the original's loops, including its sub eax, edx length tests, which the draft's pointer compare didn't give. The host case copies the player name with strcpy too.
  • SingleplayerMapChoice ButtonsAndHands: one switch, which MSVC splits the original's way: -1100, -1000 and -101 compared one by one, and -100 to 77 through the jump table. The cases are in the original's block order (2, -101, 65, 66, 67, 68, 76, 69, 74, 77, -10, -11, -100). The back button's two menu views are two calls that MSVC merges. The start-game test reads the scroll offset through DAT_GameSynchronyState::ptr and the relative selection through instance: MSVC then loads the relative selection first, as the original does. A comment in the code says why.
  • MainMenu render: the draft's gotos are one if/else. A button that isn't hovered and isn't one of 5 to 9 draws its button and goes straight to its text; every other button runs the button-5 hover sound, the GM index choice, the draw and the hover tracking. Each text with a hovered and a not-hovered state is drawn by two calls that are the same, one per state, with the position read into textY then textX in each. MSVC keeps the two calls apart and merges only what they share, as the original does. The not-hovered call comes first.
  • OnlineVoteQuit handler: one switch over the five buttons, with resetMouseState2 once after it. Button 2 repeats button 1's code for the case where nobody else is in the game, written after button 1, so MSVC merges the two into the original's jump. The two loops over player slots 1 to 8 compile to the same code as the eight lines written out.
  • MapSelectHeader render: one text call per hover state rather than a colour ternary. The fade and y are read into locals before the branch, and x into a local inside each branch, so the text offset keeps the original's register. The text number and offset are set before the dialog tests; set after them, the two swap registers.

Behaviour fixed compared with the drafts

  • SingleplayerMapChoice ButtonsAndHands:
    • "Start game" (button 65, or -1100) sets the difficulty to 1 for mission types 0 and 3 and then still launches the game, as the original does (0x0042D71D falls into 0x0042D727). The draft returned there without launching.
    • "Start game" returns when the scroll offset plus the relative selection is negative, as the original does (js at 0x0042D709). The draft's test was the wrong way round: it launched only when that sum was below -1.
    • The map description's scroll down (-101) adds 14 and clamps at the limit, and does nothing when it's already there. The draft always set the offset to the limit.
    • The draft's extra DAT_StopHandlingMenuItems stores are gone. The original stores it once, at the top.
  • MainMenu render: with the GM-index flag set, buttons 1, 2, 3 and 9 now go on to draw the button and its text after choosing GM index 353, as the original does. The draft returned there.
  • OnlineVoteQuit handler: button 2 now does what the original does in both of its cases. With nobody else in the game it ends the game at once (its count test jumps into button 1's code), and after starting a vote it stops there. In both cases the draft fell through into button 4 and sent a "no" vote.
  • Enum values: the draft or'ed two unrelated enum values that happen to add up to the right number in three places. These are now SEID_UNKNOWN_0xFB and SEID_UNKNOWN_0x92 (MainMenu's sounds) and GCT_UNKNOWN_91 (the vote command). The code is the same.

Two functions leave #328

  • ChooseNetworkServiceProvider::MenuItemActionHandler_ChooseNetworkServiceProvider_Buttons (0x004909E0)
  • SinglePlayerMapChoice::MenuItemActionHandler_SingleplayerMapChoice_ButtonsAndHands (0x0042D640)

#328 gets one commit that removes both .cpp files and puts their status lines back to main's (b379b2c). #328 still compiles without them. No other open draft of ours has any of the five.

Kept as they are, measured with quick_diff

Function Kept The cleaner form
SingleplayerMapChoice ButtonsAndHands the scroll offset read through ptr, the relative selection through instance both through instance in either order, a local, or 0 >: all 99.1% in reccmp
MainMenu render two identical text calls per hover state, the not-hovered one first one shared call: 0.9154; only the button text split: 0.9938
MainMenu render the position read into textY then textX before each of the four text calls (eight locals) the position written inline in each call: 0.8478
OnlineVoteQuit handler button 2 repeating button 1's code after it button 2 falling into a following button 1: 0.8922
MapSelectHeader render one text call per hover state a colour ternary: 0.8661
MapSelectHeader render x read into a local inside each branch one x local before the branch: 0.8254
MapSelectHeader render the text number and offset set before the dialog tests set after them: the two swap registers
MapSelectHeader render the fade written as the original computes it, (strength - 32) * 32 / 32 + 32 it comes back to the blend strength itself, but the original does the sum, so it stays (with a comment)

Most of these have a one-line comment in the code that says why.

Numbers left as numbers:

  • The case labels in the OnlineVoteQuit and SingleplayerMapChoice handlers and in MapSelectHeader: they are the menu's button numbers and MapSelectHeader's table column, with no enum on main.
  • SingleplayerMapChoice's DAT_MapMissionType values (0 to 3): the global is an undefined4 with no enum.

What some placeholders hold

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 5 commits November 14, 2026 01:37
MenuItemActionHandler_ChooseNetworkServiceProvider_Buttons, from the draft sourcehold#328 (reimpl/UI-MenuItems-3-development-2,
306a61a, 79.4%), itself gynt's draft (1674e0f, 72.84%; his newest reimplementation commit on the file is
8725ec5, his last style pass dd1a7c4). gynt's: the switch over the actions, the scroll and host cases and the
session handling. The join case is rewritten without the decompiler's gotos and hand-unrolled string loops: the typed
address is stored only when it is not empty (`strlen(...) != 0`), not already listed (a found flag over the four
entries), in the first empty slot (a stored flag, `strlen(...) == 0`, then strcpy), or else after shifting the list
up. MSVC threads both flags away and inlines strlen and strcpy into the original's loops, including its `sub eax,
edx` length tests that the draft's pointer compare did not give. The host case copies the player name with strcpy.

reccmp 99.2, normalised 100.0: the only differences are tail-jump targets to resetMouseState2 (0x004689D0, on
main with its resolver off), so 100% by the call-target rule. The original jumps to it three times (0x00490C73,
0x00490D4A, 0x00490D81); reccmp reads two of ours as different targets. quick_diff 0.9850; its other hunk is
the original's `npad` jump before the shift loop. The parameter is action, the session result is tested inline,
the index step is a plain increment, the two flags are BOOLEnum and the array bounds are written with countof (all
measured identical).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From sourcehold#328 (reimpl/UI-MenuItems-3-development-2, 031cb7d, 75.1%), itself gynt's draft (f3cef40, 72.67%;
his last style pass dd1a7c4). Rewritten from the original's asm as one switch: MSVC splits it the original's way,
-1100, -1000 and -101 compared one by one and -100..77 through the jump table, with the cases in the original's
block order (2, -101, 65, 66, 67, 68, 76, 69, 74, 77, -10, -11, -100). No gotos; the back button's two menu views
are two calls MSVC merges.

Behaviour fixes against the binary:
- start game (65 / -1100) sets the difficulty to 1 for mission types 0 and 3 and then still launches the game
  (0x0042D71D falls into 0x0042D727); the draft returned without launching;
- the description's scroll down (-101) adds 14 and clamps to the limit, returning when already there; the draft
  always overwrote the offset with the limit;
- the start game guard returns when the scroll offset plus the relative selection is negative (`js` at
  0x0042D709); the draft's guard was inverted;
- the draft's extra DAT_StopHandlingMenuItems stores are gone (the original stores it once, at the top).

reccmp 99.7, normalised 100.0: the only difference is a tail jump's target through a resolver, so 100% by the
call-target rule. The start-game test reads the scroll offset through DAT_GameSynchronyState::ptr and the relative
selection through instance: MSVC then loads the relative selection first, as the original does (the same fields
both through instance, in either order, a local or `0 >`, all kept the opposite load order, 99.1). A comment says
why. quick_diff 134/134 (its other hunks are the timeGetTime import and resolver tail calls).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_MainMenu_Main, rewritten without gotos from the original's code, with gynt's draft
(f2e9ae2 at 81.39% on his fork's reimpl/UI-MenuItems-development; his last style pass on the file is dd1a7c4;
quick_diff 0.9159 on main) for the reads. reccmp 100.0, quick_diff 162/162 at 1.0000.

The decompiler's gotos are one if/else: a button that is not hovered and is not one of 5-9 draws its button and goes
straight to the text, and every other button runs the button-5 hover sound, the GM index choice, the draw and the
hover tracking. Each text that has a hovered and a not-hovered state is drawn by two calls that are the same, one per
state, with the position read into `int const textY` then `textX` in each: MSVC keeps the two calls apart and merges
only what they share, as in the original (one shared call: 0.9154; the button text alone split: 0.9938). The
not-hovered call comes first.

Behaviour fix: with the GM-index flag set, buttons 1, 2, 3 and 9 now go on to draw the button and its text after
choosing GM index 353, as the original does; the draft returned there. The sound IDs are SEID_UNKNOWN_0xFB and
SEID_UNKNOWN_0x92 (the draft or'ed two unrelated enum values that add up to them), the Multiplayer test compares with
DD7_LOADED, and the colours are COL_7F7F7F and COL_C2F0EB.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_OnlineVoteQuitAndQuitGame_Main, rewritten without gotos from the original's code, with gynt's
draft for the reads (9d44bf4 at 80.93%, after his 85b6360, 2490ef5 and f03fca7; the file's newest commit on
his fork's reimpl/UI-MenuItems-development is 8725ec5; quick_diff 0.8768 on main). The fields, the vote counting
and the five buttons' actions were already his. reccmp 98.2, normalised 100.0: the only differences are the
resetMouseState2 tail jumps, which go through its resolver. quick_diff 102/102 at 0.9608, for the same reason and the
timeGetTime import call.

One switch over the five buttons, every path ending in resetMouseState2. Button 1 ends the game. Button 2 counts
the occupied player slots and starts a quit vote when someone else is there, with the empty slots and the asking
player's own as yes votes. Buttons 4 and 5 send a no or a yes, and button 3 closes the dialog. The two loops over
slots 1-8 compile to the same code as the eight lines written out.

Behaviour fix: button 2 now does what the original does in both of its cases. With nobody else in the game it ends
the game at once (the count test jumps into button 1's code), and after starting a vote it stops there. The draft
fell through into button 4 in both cases and sent a no vote. Button 2 repeats button 1's code for the first case,
written after button 1, so that MSVC merges the two as in the original (button 2 falling into a following button 1
put the blocks in the other order: 0.8922). The vote command is GCT_UNKNOWN_91 (the draft or'ed two unrelated enum
values that add up to it).

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_LobbyMenu_MapSelectHeader, rewritten from the original's code with gynt's draft for the reads
(305b2b1 at 74.80% on his fork's reimpl/UI-MenuItems; on reimpl/UI-MenuItems-development his newest reimplement
commit on the file is 8725ec5 and the newest commit 5084980; quick_diff 0.8160 on main). The columns' text
numbers and offsets were already his. reccmp 100.0, quick_diff 63/63 at 1.0000.

The header cell picks its text and x offset per column, draws the cell background and its title, brighter while
hovered. Forms that match, measured with quick_diff:
- one call per hover state rather than a colour ternary (the ternary compiles branch-free: 0.8661);
- the fade and y read into locals before the branch, and x read into a local in each branch. The offset then keeps
  the original's register, where one x local before the branch swaps the offset and the text index (0.8254);
- the text index and offset initialised before the dialog tests (after them, the two swap registers).

The fade keeps the original's (strength - 32) * 32 / 32 + 32, with a comment that it comes back to the strength
itself. The parameter is the column, the early returns replace the draft's nested condition, and the colours are
COL_C2F0EB and COL_CCFAFF.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gynt
gynt added this pull request to the merge queue Nov 14, 2026
Merged via the queue into sourcehold:main with commit 3416498 Nov 14, 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