Skip to content

One more UI::MenuModals function at 100%: ProgressBarBox - #467

Merged
TheRedDaemon merged 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-progressbarbox-100
Nov 22, 2026
Merged

TheRedDaemon merged 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-A-progressbarbox-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

One more function at 100%, moved out of our open draft #360, with no header changes and no line for cmake/compiler-flags-gl.txt. No behaviour change against gynt's 96.3% draft, which has an else that his older copies miss (below). ProgressBarBox::MenuModalRenderFunction_ProgressBarBox draws the box of the load and save progress bar: its title, in a smaller font for English and American, and the bar's background, a very soft yellow box or a dimmed one. It keeps the bar's place for RenderLoadAndSaveBar, which draws the progress. It is from gynt's draft on his fork's reimpl/UI-MenuModals-development, and the commit credits him as co-author.

Function Address Before After
ProgressBarBox::MenuModalRenderFunction_ProgressBarBox 0x00493560 96.3% in the draft PR (f860f20, gynt's code with the fixer's rewrites); gynt's draft 96.3% (217700a; earlier 45.2% at 266d7a5, 48.6% at 6987e8c, 85.97% at 85a110f) 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 the previous cut of this branch on main 812d149 (the same code: the cut since writes one local, the bar's bottom, into its two uses and changes comments, and compiles to the same listing; the function is not on the /GL list), 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). MenuModalRenderFunction_ProgressBarBox reads 100.0 raw and normalised there too, with no diff entry. One function on main reads higher: Global::Init::Constructor_MenuModal_ProgressBarBox (0x0059B6E0) goes from 93.8 to 100.0 (92.3 to 100.0 normalised), because the address it stores is now this function and no longer the resolver's trampoline; its code is unchanged. Every other main function reads exactly what it read before (unrounded 99.5786 against 99.5759 raw, 99.5526 against 99.5492 normalised; 2,324 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 this file, off the list: 144 functions, average 99.56. The function reads 100.0% raw and normalised, with no diff entries, 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 an earlier text of this file (one unused include more, and the bar's bottom in a local); quick_diff gives the same 109 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 109, 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 1 CHECK (the local top, declared without a value; below); our local fixer finds nothing to change.
  • Not run in game.

Against the draft

gynt's 96.3% draft (217700a, on his fork's reimpl/UI-MenuModals-development) computes what the original computes, and nothing in its control flow or its values is changed here: the same two tests, the same text, boxes and stores. What differs is where two values are kept: top holds y, and y holds the bar's x, which his draft keeps in height. Neither parameter is read again behind the last store. The casts on the text's number and on the box's colour are dropped (the same listing).

His earlier copies draw the filled box and then the dimmed box over it: their second test has no else, so the dimmed arm runs in every case. These are the 45.2% text of #252 (266d7a5), the 42.5% text (a461509) that 20 of his other branches carry (his style passes on top), 48.6% at 6987e8c, and the copy on reimpl/Wilps-2026-10-18 (8ca7861). He put the else in himself in 85a110f (85.97%, "one extra stack slot"), as the original has it (it returns at 0x00493642), and came to 96.3% in 217700a ("spill slot differs"). Both steps are his, and both are here.

What got it to 100%

gynt's draft has the original's 109 instructions already. Four of them use another stack slot (96.3%), and that is all this PR changes.

  • The original keeps the bar's x in the second parameter's slot. It computes the bar's x (0x0049360F), stores it into the slot y came in (0x00493620) in front of the draw, and reads it back from there for progressBarX (0x0049362F); the other arm does the same (0x0049364E, 0x0049365E, 0x0049366D). gynt's draft assigns the value to height, the fourth parameter, which the function does not use otherwise: the same instructions with the fourth slot.
  • Assigned to y as the draft assigns it to height, the value stays in y's register: y is in edi for the whole function, and the compiler puts the new value there too (105 instructions against 109). An own local gets a new stack slot (112 instructions), and with the expression written out at both uses the compiler saves it in a new slot as well (112).
  • So y is read through a copy, and the copy is made in each arm of the language test. The original loads the second parameter in each arm (0x00493572, 0x004935A2). With a local top that is assigned from y there, top gets edi, y itself is not kept in a register, and its new value lives in its own slot: 109 instructions against 109.
    • top cannot be declared with y as its value (int top = y; or int const top = y;): then y is loaded at the function's start, in front of the language test, and the match is lost (107 instructions).
    • The unused height as the copy (height = y; in each arm) gives the same listing as top. But height would then hold the box's top (barY = height + 65), and the function already has one parameter, y, that holds something else; a local says what it holds.
    • The assignment has to come behind barY, as the draft has it: in front of it, or with barY written out at its two uses, the compiler takes a new stack slot (112 instructions). The bar's bottom, used once, is written out in the call: as a local it gives the same listing.

quick_diff reads 1.0000: 109 instructions against 109.

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

Kept as they are

  • int top; is declared without a value (the checker's note) and assigned in both arms of the language test: see above. A comment in the code says why.
  • The bar's x is assigned to y: a local of its own gets a new stack slot (112 instructions), and y without the copy keeps it in a register (105); see above. A comment says so at both assignments.
  • The title's draw is written out in both arms (font size 16 for English and American, 18 otherwise): the original pushes the draw's arguments in each arm (0x00493572 to 0x0049359F, and 0x004935A2 to 0x004935CE) and shares the two calls (from 0x004935CF).
  • The bar's four values are computed in both arms of the second test: the original computes them in each arm (from 0x004935FD and from 0x00493643).
  • The numbers (positions, the bar's width 300, the font sizes) are plain numbers.

What some placeholders hold (nothing changed here)

  • MenuTextInputState::DAT_MenuOptionsActionParameter: the number of the title's text in the game options' text group, which has "Load" and "Save". It is undefined4 in the header; the exe refers to it in 35 places.
  • GameSynchronyState::saveRelated: not zero for the filled box; undefined4, 17 references in the exe.
  • MenuTextInputState::progressBarX and progressBarY: the bar's place. RenderLoadAndSaveBar (0x00493690, on main) draws the progress there.

Other PRs

🤖 Generated with Claude Code

ProgressBarBox::MenuModalRenderFunction_ProgressBarBox, moved out of our draft sourcehold#360 (f860f20, Gynt's code with
the fixer's rewrites), from Gynt's draft (217700a at 96.33% on his fork's reimpl/UI-MenuModals-development,
"spill slot differs"). That draft computes what the original computes; no behaviour is changed against it. His
earlier copies (45.2% at 266d7a5, in his closed sourcehold#252; 48.6% at 6987e8c) have no else on the second test and
dim the filled box; he put the else in in 85a110f (85.97%), as the original has it (it returns at 0x00493642),
and it is here.
His draft has the original's 109 instructions; four of them use another stack slot. The original keeps the bar's x
in the second parameter's slot: computed at 0x0049360F, stored there in front of the draw (0x00493620) and read
back for progressBarX (0x0049362F; 0x0049364E, 0x0049365E and 0x0049366D in the other arm). The draft assigns the
value to height, the unused fourth parameter, and gets the fourth slot. Here:
- the bar's x is assigned to y. On its own that keeps the value in y's register (105 instructions), an own local
  gets a new stack slot (112 instructions), and so does the expression written out at both uses (112);
- so y is read through a local, top, that is assigned from y in each arm of the language test, where the original
  loads the second parameter (0x00493572, 0x004935A2). Then top gets y's register (edi), y is not kept in a
  register, and its new value lives in its own slot: 109 instructions against 109. Declared with y as its value
  (int top = y; or int const top = y;), top is loaded at the function's start and the match is lost (107
  instructions); the unused height as the copy gives the same listing as top;
- the bar's bottom is written out in the two calls (as a local, the same listing), and the casts on the text's
  number and on the box's colour are dropped (the same listing).

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 other 143 functions of main's list read the same as without the
file. Both builds had an earlier text of this file (one unused include more, and the bar's bottom in a local);
quick_diff gives the same 109 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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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