Skip to content

UI: the advanced game options' render function at 100% - #448

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

kotijekriv wants to merge 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round37-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

One function at 100%, moved out of our open draft #328, from gynt's draft. No header changes. Behaviour fixes against the draft (below), one of them an endless loop.

Function Address Before reccmp raw Normalised
MenuItems::General::MenuItemRenderFunction_General_AdvancedGameOptions 0x00428AC0 42.5% (our draft in #328); gynt's best 41.3% 100.0% 100.0%

Our draft was gynt's code with a mechanical pass. gynt's best, 41.32%, is 77fde36 on his fork's reimpl/UI-MenuItems; his reimpl/UI-MenuItems-development records 40.4% (fd61234).

Measured

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie. The struct resolvers and the function resolvers are enabled locally (not committed). In the full build 0x004314E0 (the MapEditorLandscaping_GeneralButtons handler) is left out and its resolver stays off, as in main's baseline.
  • Narrow build: this file (as committed but for comments and one form that compile to the same listing line for line), together with four of main's files it calls, their resolvers on: renderGM (0x00455300), renderBasicButton (0x00463A90), renderNonInteractingButtonBackground (0x004246E0) and MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface (0x00463FF0), which item 103 tail-calls. The function reads 100.0 raw and normalised, with no diff line. The first three stay at 100.0.
    • The last one reads 67.3 in that narrow build. It is on main's /GL list, and its own callee is not in the build. In the full build it reads 100.0, as on main.
    • With only this file, as committed, in the build and the callees' resolvers off, the function reads 100.0 (100.0 normalised) too.
  • Full build: an all-on build of the same code on main 3458fea: 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/). The new function 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).
  • Instructions and jumps: all 961 instructions are the original's, and all 74 local jumps land on the same instruction. We compared them with scripts. The function has no switch table.
  • 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

The function draws the advanced game options of the lobby and the skirmish setup, one menu item per call: a label at the left and the option's value at the right (a text, a number, or a tick picture for the on / off options). Most of the draft's items had no return, so they ran on into the code that draws the other items' label, with their own number as the text's number:

  • 31 (tech level), 36 (win condition), 83 (troops) and -1000 (the Back button) drew a second text after theirs, text 31, 36, 83 or -1000 of TEXT_XPLAY_WAITING_ROOM: "Game: Manor House" at the left of the tech level's row, "Win: Regicide", "Free", and for -1000 a number outside the group. The original returns after each (0x00428C8F, 0x00428CE6, 0x00428D8A, 0x00428E8B).
  • 103 did the same after its button ("Play Options" over the picture button), and with the colour unset. The original leaves through the button's function (a tail jump at 0x00428E97).
  • -11 (no dogs) and -13 (extreme mode) drew that second text after their tick picture. The original returns (0x004290E5, 0x00428FBA).
  • -12 (no rush) drew it after the value text for setting 5. The original returns (0x00429318).
  • 99 (strong walls) never returned. After its picture the draft went back to its own text and picture: an endless loop whenever the item is drawn. The original returns (0x004290E5). gynt's fd61234 and 2c82038 end 99 with the same goto into -11's block and loop too; his 77fde36 has a return in that block's ticked arm, so there 99 loops only with strong walls off, and with them on it returns without the picture, leaving drawBufferChoiceValue at RT_SCREEN_MENU.
  • 100 (alliances) drew both value texts, 101 and then 102, when alliances are off. The original draws one of the two (0x004295D3).

Each of these shows in the draft's own listing. We read the draft against the new code block by block; nothing else differs (the filters, the texts' and pictures' numbers, the positions, the colours and the alpha are the same).

What got it to 100%

The function is written from the original's listing now: the filters, then one block per item, each ending in a return. Our draft read 976 instructions against the original's 961, with 1,074 lines differing in our compare. What decided the match, each measured with one thing changed (differing lines of that compare; the final code has 0):

  • The item blocks in the original's order. 36 before 31: 217; 103 before -1000: 32; 99 before -10: 56; -12 before -10: 486.
  • 83's value text number is held in the parameter: the code stores 84 in button for troops that cost gold, as AlliesOrder_Main on main and UI: the allies screen's render function at 100% #447 do. With a variable of its own: 877; with a call in each arm: 802.
  • The colour is set before the call in the interacting arm and after it in the other (the other way: 342 and 2), and it has no first value: item 103 never sets it (with = 0: 30).
  • The tick pictures with a renderGM call in each arm. One call with a conditional expression: 705.
  • The alpha written out in every call. One local for the items from -10 on: 352.
  • No-rush and auto-save test each value in its own if. As else-if chains: 43 and 27.
  • Smaller: the tech level's text number computed whole before the first call (only / 2 early: 4; in the call: 19), 109's number in a local with one call (a call in each arm: 44; with a first value and the tests rearranged: 14 or 5), 100's alliances as a truth test (== 0 with the arms swapped: 6).

These gave the same code, and we took the plainer form: the modal filter as one else-if (nested ifs tie), the single player filter as one condition, 103's flag in a nested if, 109's number by if / else (the draft added a comparison to 109), and the value's x as W + X - 20 (or W - 20 + X).

Things in the file that look odd and are the original's

  • button holds 83's value text number. The original keeps it in the parameter's register (see above).
  • uint color; with no first value. Item 103 draws its button through another function and never sets it; the original reads the unset stack slot there (0x00428BE7) and does not use it.

Header findings (nothing changed here)

  • GameSynchronyState::skirmishWinCondition, skirmishTroopsCostGold, skirmishStrongWalls, skirmishAlliances, skirmishNoCowThrowing, skirmishNoDogs, skirmishNoRushSetting, skirmishExtremeMode and skirmishExtremeMode2 are undefined4. This function tests seven of them for truth, compares the no-rush setting with 0 to 5 and adds the win condition to a text number. A lead for their types (BOOLEnum for the seven, int for the other two); we did not check the functions that write them.
  • skirmishExtremeMode2 is only ever tested together with skirmishExtremeMode here: item -14's tick is on when both are set.

The checker's 2 CHECKs

What Why it stays
uint color; with no first value needed for the match: with = 0, 30 lines differ
int fogText; with no first value needed for the match: with 95 as its first value and the tests rearranged, 14 or 5 lines differ

🤖 Generated with Claude Code

General::MenuItemRenderFunction_General_AdvancedGameOptions, rewritten from the original's listing. gynt's draft:
fd61234 at 40.37% ("reordered stores") on his fork's reimpl/UI-MenuItems-development, whose status line records
40.4% (the newest commit on the file there is e63ae30, a style commit); his reimpl/UI-MenuItems has 2c82038 at
40.03%, status line 40.0% ("Style pass, asm differs"), after 77fde36 at 41.32%, his highest there. Our draft
(530c671, then 53bea5f and 07a33e2; 42.5% in the draft PR sourcehold#328) was his code with a mechanical pass.

The function draws the advanced game options of the lobby and the skirmish setup, one menu item per call, chosen by
the item's number: a label at the left and the option's value at the right (a text, a number, or a tick picture for
the on / off options). It draws nothing behind the map dialogs, the round table and the lord choices, only the
skirmish options' own items while those are open, and some items only for the host or outside a single player
skirmish.

Behaviour fixes against the draft, each in the draft's own listing. Most of its items had no return, so they ran on
into the code that draws the other items' label, with their own number as the text's number:

- 31 (tech level), 36 (win condition), 83 (troops) and -1000 (the Back button) drew a second text after theirs, text
  number 31, 36, 83 or -1000 of TEXT_XPLAY_WAITING_ROOM. The original returns after each (0x00428C8F, 0x00428CE6,
  0x00428D8A, 0x00428E8B).
- 103 did the same after its button, and with the colour unset. The original leaves through the button's function (a
  tail jump at 0x00428E97).
- -11 (no dogs) and -13 (extreme mode) drew that second text after their tick picture. The original returns
  (0x004290E5, 0x00428FBA).
- -12 (no rush) drew it after the value text for setting 5. The original returns (0x00429318).
- 99 (strong walls) never returned: after its picture the draft went back to its own text and picture, an endless
  loop. The original returns (0x004290E5). gynt's fd61234 and 2c82038 end 99 with the same goto into -11's block
  and loop too; his 77fde36 has a return in that block's ticked arm, so there 99 loops only with strong walls off,
  and with them on it returns without the picture, leaving drawBufferChoiceValue at RT_SCREEN_MENU (2c82038, "bug
  fix", took that return out).
- 100 (alliances) drew both value texts, 101 and then 102, when alliances are off. The original draws one of the two
  (0x004295D3).

What decided the match. The counts are differing lines of our own exact listing compare against the original's 961
instructions (operands with the original's addresses and every jump's landing), each with that one thing changed
from the final code, which has 0:

- The item blocks in the original's order, each ending in a return: 36 before 31: 217; 103 before -1000: 32; 99
  before -10: 56; -12 before -10: 486.
- 83's value text number is held in the parameter: the code stores 84 in `button` for troops that cost gold, as
  AlliesOrder_Main on main does. With a variable of its own: 877; with a call in each arm: 802.
- The colour is set before the call in the interacting arm and after it in the other (the other way: 342 and 2), and
  it has no first value: 103 never sets it (with `= 0`: 30).
- The flag items' tick picture with a renderGM call in each arm. One call with a conditional expression: 705.
- The alpha written out in every call. One local for the items from -10 on: 352.
- No-rush and auto-save test each value in its own if. As else-if chains: 43 and 27.
- Smaller: the tech level's text number computed whole before the first call (only `/ 2` early: 4; in the call: 19),
  109's number in a local with one call (a call in each arm: 44), 100's alliances as a truth test (`== 0` with the
  arms swapped: 6).

These gave the same code, and the plainer form stands: the modal filter as one else-if (nested ifs tie), the single
player filter as one condition, 103's flag in a nested if, 109's number by if / else (where the draft added a
comparison to 109), the value's x as W + X - 20 or W - 20 + X, and 83's number in `button` written directly or named
through a reference.

The text numbers carry their texts from the game's cr.tex (TEXT_XPLAY_WAITING_ROOM, TEXT_SKIRMISH_MISC,
TEXT_GAME_OPTIONS) as comments. Neither they nor the other new comments change the listing: this code compiles to
the same instructions, line for line, as the code the narrow build with the callees and the full build measured.

Measured in a narrow build on main 3458fea of that code and the four finished functions it calls, struct resolvers
and their resolvers on: renderGM (0x00455300), renderBasicButton (0x00463A90), renderNonInteractingButtonBackground
(0x004246E0) and MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface
(0x00463FF0), which 103 tail-calls. reccmp 100.0, normalized 100.0, no diff line. The last of the four is on main's
/GL list and reads 67.3 in that build, as its own callee is not in it. With only this file, as committed, in the
list, the callees' resolvers off, the function reads 100.0 (100.0 normalized) too. Not run in game.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <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