Skip to content

One more UI::MenuItems function at 100%: LobbyMenu NonBoxedButtons - #459

Open
kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-nonboxedbuttons-100
Open

kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-nonboxedbuttons-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

One more function at 100%, with no header changes and no line for cmake/compiler-flags-gl.txt. Six behaviour fixes against gynt's best draft (below). LobbyMenu::MenuItemRenderFunction_LobbyMenu_NonBoxedButtons draws the lobby's buttons that have no box: the scroll buttons of the chat, the map list and the map description, the host's Load and Launch Game buttons, Main Menu, Ready (a picture button, and a Ready text button), the host's Send Map, Skirmish Masters and the keeps on the map preview. It is from gynt's draft on his fork's reimpl/UI-MenuItems-development, and the commit credits him as co-author.

Function Address Before After
LobbyMenu::MenuItemRenderFunction_LobbyMenu_NonBoxedButtons 0x0042AE90 gynt's draft 76.48% (2dedc17; 53.37% at a87bbb9, 53.81% at a349a0e, 59.30% at eb99046) 100.0%, off the /GL list and on it

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 with --resolve-wrapped-calls --ignore-security-cookie.
  • Full build: an all-on build of this branch on main 812d149, with main's own /GL list and with 0x004314E0 (the MapEditorLandscaping_GeneralButtons handler) left out and its resolver off, as in main's baseline: 0 failed of 2,424 compile steps, 99.58 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files under tools/, and cmake: optional wrapper units built from function-visibility.txt #399 and cmake: function-visibility.txt, which callers must see which callees' bodies #398 add the optional function-visibility units, off by default). MenuItemRenderFunction_LobbyMenu_NonBoxedButtons reads 100.0 raw and normalised there too, with no diff entry. Every main function reads exactly what it read before (unrounded 99.5761 against 99.5759 raw, 99.5494 against 99.5492 normalised; 2,323 against 2,322 functions at 100.0 raw).
  • Our own narrower run: the 133 files of main's /GL list that exist on main, and the file, off the list: 144 functions, average 99.56. The function reads 100.0% raw and normalised, with no diff entries; the switch's jump table and its index bytes are part of that. The same build without the file has 143 functions, and each of them reads the same. That build, and the one with the file on the list (below), had the file before its comments, clang-format and the flag's BOOLEnum type. quick_diff gives the same 383 instructions, line for line, for that text and for this one. The sources were main's at 3458fea; main's two commits since (02fab42, 812d149) add cmake files only, with the new option off.
  • Instructions: the original's 383 (385 with its two fillers, nop at 0x0042B15F and mov edi, edi at 0x0042B362), in its order; reccmp's diff for the function is empty. The case labels pair with the original's jump table (12 entries) and index table (205 bytes), case for case.
  • Please measure with both resolver switches on (the Globals and the function resolvers), as our numbers are.
  • Checks: our local style checker gives 0 ERROR and 2 CHECK (below); our local fixer finds nothing to change.
  • Not run in game.

The behaviour fixes

gynt's 2dedc17 ("control flow from the asm") already restores the returns of the modal-dialog block, of button 1's two draws and of the buttons 3, 4 and 105. These are the ones left, each against dd1a7c4:

  • Load (1) for a guest: the original marks the button (DAT_ButtonUnknownZero) and returns (cmp [isHost], ebp; je at 0x0042AFBF). The draft set the mark and went on. It drew the host's Load button for guests too: dimmed, and lit once everyone was ready. On the dimmed path it also cleared the mark again behind the switch.
  • Ready (-20) in a single-player skirmish: the original marks it and returns (0x0042B0FC). The draft cleared the mark again on the next line and drew the button.
  • Send Map (105): the original marks it and returns in four cases (0x0042B266, 0x0042B273, 0x0042B28F, 0x0042B29B): when the player is not the host, when no map is selected, when the map's entry is not zero, and when a map file is being received. In all four the draft only set the mark, and drew the button and its text anyway. With no map selected it also read the map list at a negative index.
  • Skirmish Masters (413) outside a single-player skirmish: the original marks it and returns (0x0042B333 into 0x0042B335). The draft drew it in the multiplayer lobby and cleared the mark behind the switch. The click handler (0x00442640) has no test of its own for 413.
  • The keep under the mouse (-200): the original stores the first keep whose box holds the mouse, and returns (0x0042B23B, 0x0042B24F). The draft went on and kept the last one. The two differ only where two keeps' boxes overlap.
  • No stores behind the switch: the original's shared exit (0x0042B248) only returns. The draft set drawBufferChoiceValue to RT_SCREEN_MENU and cleared the mark there. After button 1's dimmed draw and after 413's draw, that undid the RT_MAP_GAME which RenderCurrentButtonToScreenMenuWithBlendingUnk leaves behind.

Not a fix: the draft's - 1 in the map index of the buttons 4 and 105. main's header has since moved DAT_ArrayOfMapIndices from 0x884 to 0x880 (it is now 501 entries long), so the same address is now written [offset + selection].

Read case by case against the jump table, the draft's values are the original's: the conditions, the call arguments, the colours and the keep boxes (572 / 595, 3 / 35).

What got it to 100%

The draft has the buttons' conditions, the calls and their arguments, and most of the original's returns (see above). The control flow is rewritten against the original instructions, in two steps on our dev branch (not public): 91.2%, then 100.0%.

  • One switch, with the cases in the order of the original's code (the scroll cases aside, see below). The jump table covers -200 to 4; 105 and 413 are tested in front of it, which is how the compiler lowers such a switch.
  • The flag for "every human player is ready" is declared in front of the switch, not in its two cases. The original keeps its 1 in edi through the whole switch and pushes it for TTA_CENTER and for the down buttons.
  • The six scroll buttons are six cases with a call each, in the order -10, -1, -11, -2, -100, -101 (91.2% to 100.0%, together with the next point). Each call reads the blend strength into one temporary, and the compiler hands those out eax, ecx, edx in turn, block after block, as far as we can tell. After that it joins the cases whose code came out the same: -100 into the call of -1, and -11 with -101. That is what the original shows: its jump table sends -100 into the middle of the block of -1, behind that block's mode check (0x0042AF64), and its four remaining blocks read the blend into ecx, edx, ecx and eax (0x0042AF41, 0x0042AF64, 0x0042AF87, 0x0042AF9D). Only this order, or the same with -11 and -101 swapped (the same code), gives those four registers; written as the original's four blocks, the turns are off by one from the third block on, and with them every temporary in the cases behind it.
  • The texts of the buttons 3 and 105 are two calls each, one per colour. One call with the colour chosen in it compiles without a branch (neg / sbb); the original branches. Once the scroll cases are as above, button 3's two calls get the original's registers by themselves (y in edx and in eax, 0x0042B0B4 and 0x0042B0E4), and the compiler shares only the pushes before and after the colour (alpha, FALSE and 18 in front, and the tail from x on, 0x0042B0C4), as the original does.

quick_diff reads 1.0000: 383 instructions against 383.

No line for cmake/compiler-flags-gl.txt

  • The file reads 100.0% off the /GL list, and 100.0% on it too (the same build with the line added). So it needs no line.
  • quick_diff gives the same instructions with and without its callees' bodies in the unit. It needs no line in cmake/function-visibility.txt (cmake: function-visibility.txt, which callers must see which callees' bodies #398) either: the manifest lists RenderCurrentButtonToScreenMenuWithBlendingUnk only as the caller of getPictureNumberInGm.

Kept as they are

  • The order of the six scroll cases looks arbitrary and is not: see above. A comment in the code says why they are six, and that -11 and -101 may swap.
  • Two calls for one text (buttons 3 and 105): a comment says why.
  • The mark is cleared again in -20 and in 413, although it is cleared in front of the switch: the original stores it again in both places (mov [0x00ED31CC], ebp at 0x0042B109 and 0x0042B32D). A comment says so.
  • The 14 case labels are numbers (one CHECK): buttonID is the menu item's plain number, and no enum on main names these buttons. Each case has a comment that says what the button is, from the texts of the lobby's group (1 "Load", 2 "Main Menu", 3 "Ready", 4 "Launch Game", 105 "Send Map", 413 "Skirmish Masters") and from the click handler of our UI: three more functions at 100%: the lobby's start button, the save list's header and the mission rows #423 (0x00442640).
  • INT_00b95950 (one CHECK): a placeholder name; what it holds is below.

What some placeholders hold

  • INT_00b95950: the keep under the mouse on the map preview, set by button -200. The minimap (General_MenuMiniMap, on main) draws that keep highlighted and sets it back to -1 after each draw. gynt's reimpl/Wilps-2026-10-18 has it as DAT_LobbyMinimapHoveredKeepIndex, a name for Ghidra's side.
  • DAT_ButtonUnknownZero: a mark set for a button that is not drawn or not live in the current state; cleared in front of the switch.
  • GameSynchronyState::DAT_PlayerSlotArraySomeValue: zero for a player who is not ready (buttons 1, 4 and -20 read it so).
  • GameSynchronyState::unknownMapRelatedReceivedDataArray: indexed by the selected map; button 4 is dimmed while the entry is zero or less, and button 105 is only drawn while it is zero. The Launch Game handler (0x00442640, UI: three more functions at 100%: the lobby's start button, the save list's header and the mission rows #423) starts the game only when the entry is above zero.

Other PRs

  • gynt's reimplement OpenSHC::UI::MenuItems (256 functions, 27 at 100%) #254 (closed 2026-10-03; sourcehold's reimpl/UI-MenuItems) has it at 42.1% (a23ac01), and his fork's UI branches carry older copies (43.1% on most, 52.0% on reimpl/UI-MenuItems, 76.5% on reimpl/UI-MenuItems-development). No open PR has this function or its status line.
  • The status file's entries 0x0042B364 to 0x0042B460 (Pending) are this function's jump table (12 entries, 0x0042B364 to 0x0042B390) and its 205 index bytes (0x0042B394 to 0x0042B460), not functions; this PR leaves them as they are.

🤖 Generated with Claude Code

LobbyMenu::MenuItemRenderFunction_LobbyMenu_NonBoxedButtons, from Gynt's draft on his fork's
reimpl/UI-MenuItems-development (a87bbb9 at 53.37%, a349a0e at 53.81%, eb99046 at 59.30%, 2dedc17 at
76.48%, dd1a7c4 style). The draft has the buttons' conditions, the calls and their arguments.
Behaviour fixes against dd1a7c4, whose 2dedc17 had restored most returns: Load (1) is not drawn for a guest,
Ready (-20) is not drawn in a single-player skirmish, Send Map (105) is not drawn unless it can be used, and
Skirmish Masters (413) is not drawn outside a single-player skirmish. Each marks the button and returns, as the
original does. The keep under the mouse is the first match (-200). There are no draw-buffer or mark stores behind
the switch, which the original does not have.
Rewritten against the original instructions is the control flow: one switch with the cases in the order of the
original's code, the scroll cases aside (its jump table covers -200 to 4; 105 and 413 are tested in front of it,
as the compiler lowers such a switch). The forms that matter:
- the flag for every human player being ready is declared in front of the switch, not in its two cases: the
  original keeps its 1 in edi through the whole switch and pushes it for TTA_CENTER and for the down buttons;
- the six scroll buttons are six cases with a call each, in the order -10, -1, -11, -2, -100, -101. The compiler
  gives the calls' one temporary eax, ecx and edx in turn and then joins the cases whose code came out the same:
  -100 into -1's call and -11 with -101. That is the original: its jump table sends -100 into the middle of -1's
  block (0x0042AF64), and its four blocks read the blend into ecx, edx, ecx and eax (0x0042AF41 to 0x0042AF9D).
  Written as the four blocks the original ends with, the turns are off by one from the third block on; -11 and
  -101 may swap (the same code), and no other order of the six was compiled;
- the texts of the buttons 3 and 105 are two calls each, one per colour. One call with the colour chosen in it
  compiles without a branch (neg / sbb). With the scroll cases as above the two calls of button 3 get the
  original's registers (y in edx and in eax, 0x0042B0B4 and 0x0042B0E4) and share only the pushes before and
  after the colour.
The buttons' names in the comments are from the lobby's text group and from the click handler (0x00442640).

No line for cmake/compiler-flags-gl.txt: the file reads 100.0% off the /GL list, and 100.0% on it too.
quick_diff gives the same instructions with and without its callees' bodies in the unit.

reccmp in a build of main's whole /GL list (the 133 files that exist) and the file, off the list, with every
resolver of those files on: 144 functions, average 99.56. NonBoxedButtons 100.0% raw and normalised, no differing
line, the jump table and its index bytes included. The same build without the file has 143 functions, and each of
them reads the same. Both builds (off and on the list) had this file before its comments, clang-format and the
flag's BOOLEnum type. quick_diff gives the same 383 instructions, line for line, for that text and for this one.
The sources are main's at 3458fea; main's two commits since (02fab42, 812d149) add cmake files only, with
the new option off.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

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