Skip to content

One more UI::MenuItems function at 100%: LobbyMenu SkirmishTypeAndBalance - #462

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

kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-skirmish-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. No change of control flow against the drafts, and one changed test (below). LobbyMenu::MenuItemRenderFunction_LobbyMenu_SkirmishTypeAndBalance draws the skirmish settings of the lobby: the three game type buttons ("Normal Game", "Crusader Game", "Deathmatch Game"), the chosen one pressed; the balance bar with its marker; and the panel with the game type's name, "Human Advantage" or "Computer Advantage" beside an uneven balance, and each side's starting gold. 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_SkirmishTypeAndBalance 0x0042A480 gynt's draft 75.21% (5f8890a; 41.8% at f45fb61, 50.17% at ed70d66, 63.07% at 04a1f23) 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_SkirmishTypeAndBalance 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 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 as committed but for its comments (two worded differently, the others not yet written); quick_diff gives the same 296 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 296, in its order; reccmp's diff for the function is empty. The function has no switch table.
  • 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 3 CHECK (below); our local fixer finds nothing to change.
  • Not run in game.

Against the drafts

Read against the original, gynt's drafts have its control flow: the same stores in the same order in front of the buttons, the same draws per button, and the unpressed draw after the pressed one only when the game type changed during it. Two tests differ in some of them:

  • The trail test. The original multiplies the starting gold by 3 when gameMode_2 is skirmish, isSkirmishTrail is 1 and the trail is the extreme one (cmp [isSkirmishTrail], ebp at 0x0042A6D4, where ebp holds 1). His 75.21% text (5f8890a, "truth test, not == TRUE"; the same test at the branch's head 405b988, after his style passes dd1a7c4 and 5084980) tests isSkirmishTrail != FALSE. That commit took his status line from 61.7% (8725ec5) to 75.21%: as far as we can tell, with == TRUE the 0 and the 1 trade registers through the function (see "What got it to 100%"). All his other copies have == TRUE. The two differ only if the flag holds a value other than 0 and 1. Here it is == TRUE again, and the store in both arms of the retest (below) gives the two their registers back.
  • The balance tests. The original compares the balance with 3 signed (jge at 0x0042A5E6, jle at 0x0042A634). skirmishCurrentAdvantageBalance is undefined4 (unsigned) in the header, and the copies at 41.8% and 50.17% and the one on his reimpl/Wilps-2026-10-18 (8ca7861) compare it as it is; his 63.07% and 75.21% texts have the (int) cast, as this one has. The two differ only for a balance of 2^31 or more.

Everything else in the drafts computes the original's values: the positions, pictures, colours and font sizes, and the gold. His 75.21% text reads the gold as field451_0x53bb4[(balance + type * 5) * 2 + 12] and + 13; on main the same two addresses are StartGoldPerFairnessLevel[type - 1][balance - 1][0] and [1].

What got it to 100%

The drafts are the decompiler's output: one nested condition with assignments inside it for the stores in front, and the buttons nested in each other. The function is rewritten against the original instructions, in three steps on our dev branch (not public): 95.4% (read with the file on the /GL list; quick_diff, which compiles it off the list, gave 0.9730), then 99.3% and 100.0% off the list.

  • Returns per button, and a flag for the three AI setup dialogs, as MapSelectTable on main has it (0x0042B4C0): DAT_ButtonUnknownZero ends up set for a guest, and for the host while the round table or one of the two AI lord selects is open; otherwise it is cleared. A guest's DAT_ButtonCurrentlyInteracting is cleared too.
  • The arguments of the panel's first text are locals, in the order they are pushed (quick_diff 0.9730 to 0.9932; 99.3% in the build): the blend, y, x, then the game type's index. The original holds all four at once (eax, ecx, edx and esi, from 0x0042A580). Written into the nested call, the type was loaded first and eax reused.
  • In the pressed draw, the draw target is set back in both arms of the test that follows it (99.3% to 100.0%, together with == TRUE above). The original keeps 0 and 1 in ebx and ebp through the whole function (0x0042A49D, 0x0042A495). With the trail test as == TRUE and the target set back once, in front of the test, the compiler gives the two each other's register, and every line that uses them differs (quick_diff 0.9054; the instructions are otherwise the same 296). With the trail test as a truth test the registers are right, and the test itself is the two lines that are left (99.3%). The original reads the game type again behind the pressed draw and has both stores between that compare and its branch (0x0042A807 to 0x0042A819). Written as if (still this type) { target back; return; } target back;, the compiler joins the two stores in front of the branch itself, which gives the same instructions as one store there, and the registers are the original's. As far as we can tell, it chooses the two registers while the stores are still in the arms. Measured besides: the picture store in both arms too gives the same listing, and so do the arms the other way round; without the return in the arm, with the old second if, it is 297 instructions. The drafts already have the test with the store in its arm (the decompiler shows it there), and one more store in front of it.
  • The gold is StartGoldPerFairnessLevel[type - 1][balance - 1][0] and [1], times a multiplier that starts at 1 and becomes 3 (see above).

quick_diff reads 1.0000: 296 instructions against 296.

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

Kept as they are

  • Four locals in front of the panel's first text (the blend, y, x and the type's index), each used once: the original holds all four at once; written into the call, the type is loaded first (see above). A comment in the code says so.
  • The draw target is set back twice in the pressed draw. A comment in the code says that once, in front of the test, loses the match.
  • isSkirmishTrail == TRUE (one CHECK): the original compares the flag with 1, and a comment says so.
  • The two (int) casts on the balance (two CHECKs): the field is undefined4 in the header (see the header finding below); retyping it is left out so this PR stays header-free.
  • The blend, (strength - 32) * 32 / 32 + 32, is written out at nine of the ten draws (the first text has it in a local, see above): the original computes it at each one. A comment in the code says that it comes back to the blend strength itself.
  • Two tests for the balance, < 3 and > 3, not an else: the original reads the balance again behind the "Human Advantage" text (0x0042A62E).
  • buttonID < 20 && buttonID >= 10 in this order: the original tests 20 first (0x0042A4D3).
  • buttonID and its values are plain numbers: it is the menu item's number, and no enum on main names these buttons. Each block has a comment that says what it draws, with the texts' names from the game type group (0 to 2 "Normal Game", "Crusader Game", "Deathmatch Game"; 3 "Human Advantage"; 4 "Computer Advantage").

Header finding (nothing changed here)

  • GameSynchronyState::skirmishCurrentAdvantageBalance is undefined4, but the original uses it as int (jge at 0x0042A5E6, jle at 0x0042A634). As int, the two casts here would go. Its other users on main do not depend on the sign: GameStateStructures::calculateTaxIncomeForPlayer compares it with 1, 2, 4 and 5, and the click handler (0x0042A840) stores button - 9 for the buttons from 10 on, so it runs from 1. 3 is the even balance; below 3 favours the human side and above 3 the computer side. The gold table bears that out: the normal game's pairs are 8000 / 2000, 4000 / 2000, 2000 / 2000, 2000 / 4000 and 2000 / 8000.

What some placeholders hold

  • DAT_ButtonUnknownZero: set here for a button that is not live in the current state (an AI setup dialog is open, or the player is a guest). gynt's reimpl/Wilps-2026-10-18 has it as DAT_ButtonDisabled.

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 41.8% (f45fb61), and his fork's UI branches carry later copies: 50.17% on most (ed70d66, with his style pass 637c6b0; the status line reads 50.2%), 63.07% on reimpl/UI-MenuItems (04a1f23), 75.21% on reimpl/UI-MenuItems-development (5f8890a, with his style passes dd1a7c4 and 5084980 on top), and a copy with other global names and a 0.0% status line on reimpl/Wilps-2026-10-18 (8ca7861). No open PR has this function or its status line. A branch that holds this file will have an add/add conflict on it and a different status line at 0x0042A480, and can take main's version once this lands.

🤖 Generated with Claude Code

LobbyMenu::MenuItemRenderFunction_LobbyMenu_SkirmishTypeAndBalance, from Gynt's draft (5f8890a at 75.21% on his
fork's reimpl/UI-MenuItems-development; 41.8% at f45fb61 on his closed sourcehold#254's reimpl/UI-MenuItems, 50.17% at
ed70d66 and 63.07% at 04a1f23 on his fork). The drafts are the decompiler's output and have the original's
control flow. One test is changed against the 75.21% text: the trail test is isSkirmishTrail == TRUE again, as the
original compares the flag with 1 (0x0042A6D4) and as his other copies have it (his 75.21% commit had changed it to
a truth test for the match; the store in both arms below makes == TRUE match).
Rewritten against the original instructions:
- returns per button, and a flag for the three AI setup dialogs in front, as MapSelectTable has it;
- the arguments of the panel's first text (blend, y, x, the game type's index) are locals in the order they are
  pushed: the original holds all four at once (from 0x0042A580); written into the nested call, the type was
  loaded first (quick_diff 0.9730 to 0.9932);
- in the pressed draw the draw target is set back in both arms of the test that follows it. The original keeps 0
  and 1 in ebx and ebp through the function. With the target set back once, in front of the test, and the trail
  test as == TRUE, the two get each other's register and every line that uses them differs; with a truth test
  the registers are right and the test's two lines are left (99.3%). Set back in both arms, the compiler joins
  the two stores in front of the branch itself (0x0042A813, the same instructions as one store there), and the
  registers are the original's. As far as we can tell, it chooses them while the stores are still in the arms;
- the gold is StartGoldPerFairnessLevel[type - 1][balance - 1][0] and [1] (the 75.21% text's
  field451_0x53bb4[(balance + type * 5) * 2 + 12] and + 13, the same addresses), times 3 on the extreme trail;
- (int)skirmishCurrentAdvantageBalance: the original compares it signed (the field is undefined4 in the header).

No line for cmake/compiler-flags-gl.txt: the file reads 100.0% off the /GL list, and 100.0% on it too.

reccmp in a build of main's whole /GL list (the 133 files that exist) and this file, off the list, with every
resolver of those files on: 144 functions, average 99.56. The function 100.0% raw and normalised, no differing
line, and the same with the file on the list. The same build without the file has 143 functions, and each of them
reads the same. Both builds had the file as committed but for its comments (two worded differently, the others not
yet written); quick_diff gives the same 296 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