Skip to content

UI: three more functions at 100%: the lobby's start button, the save list's header and the mission rows - #423

Open
kotijekriv wants to merge 3 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round17-100
Open

kotijekriv wants to merge 3 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round17-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Three more UI functions at 100%, with no header changes. The lobby's start button comes from our draft #327, and the other two are rewritten from the binary with gynt's drafts for the names.

Function Address Before reccmp raw Normalised
LobbyMenu::MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick 0x00442640 our draft #327 (cb601a0, 1918de9): 90.7% in #327's status line, 90.3% built on main's code; gynt's 80.71% (35aef55; newest on the file dd1a7c4) 100.0 100.0
SaveLoadMap::MenuItemActionHandler_SaveLoadMap_TableHeader 0x00492DE0 gynt's 49.40% (21d4dcf; newest on the file 8725ec5, 49.4%) 100.0 100.0
HistoricMissionSelect::MenuItemRenderFunction_HistoricMissionSelect_MissionRows 0x004269E0 gynt's 44.53% (626fd68) 100.0 100.0

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 3458fea: 0 failed, 99.58 over 2,442 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files under tools/). All three functions read 100.0 raw and normalised, and no function on main moved.
  • The build's commit: it ran on 540974152. The head differs from it by one comment in MissionRows and in commit messages, and MissionRows compiles to the same instructions.
  • Checks: openshc-pr-fix finds nothing to change, and openshc-pr-check gives 0 ERROR and 26 CHECK, all explained below.
  • Not run in game.

What got them to 100%

  • Lobby start button (the Reimplement 2 UI::MenuItems functions (draft, below 100%) #327 draft reads 90.3% built on main's code, 90.7% in Reimplement 2 UI::MenuItems functions (draft, below 100%) #327's status line; now 100%):
    • Case 4 sets the draw buffer back once, after the if / else that launches the game, because the original pops three registers before that store in the skirmish arm.
    • The two keep-position loops read keepPositions[position].x where they use it, with no local.
    • Case 105's map index goes through a local declared before the switch. Of the 32 combinations of how the three sums are written, only this one and its twin with case 105's operands swapped match. A local declared in case 105 swaps case 4's two loads.
  • SaveLoadMap table header:
    • The order is stored in each arm, and previewedListIndex = -1 is written once after the if / else. MSVC copies that store into both arms after the last pop, as the original has it.
    • The swap reads the moved element into a local inside the if.
    • fileListEntryCount is read in the loop condition, because the original reloads it after each swap's stores.
  • MissionRows:
    • The number and the name are written in each of the three arms, so MSVC hoists their common pushes and shares the tail.
    • The number's position is written out in each arm.
    • In the selected arm, the name's position and index go into locals before the nested call, in the order the original loads them.

Behaviour compared with the drafts

  • Lobby start button: load game (1) and start game (4) return as soon as an occupied slot isn't ready, where gynt's draft only left the loop and carried on. For the host, dropping a keep position (-201) ends with INT_00b95960 = -1 on every path, and stops when no position is under the mouse.
  • MissionRows: a mission not reached yet is drawn as a greyed cell and the function returns (0x00426A53). The draft went on and drew the number and the name over it.
  • SaveLoadMap table header: the behaviour is the draft's. Its DAT_ArrayOfMapIndices[i - 1] was right on gynt's branch, where the array is declared at offset 0x884. Main's sync 12854bc moved the declared start to 0x880, so the index here is [i].

What the placeholders hold

These are read from how the code uses them. Ghidra has no better names, so the names are unchanged.

  • DAT_00b960dc: the lobby's fade. It is non-zero while the menu fades in or out, and the handler ignores clicks while it is non-zero.
  • DAT_00b960f4: the map description's scroll offset.
  • INT_00b95b74: probably the description text's height, since the scroll limit is this value minus 114.
  • INT_00b95960: the player position being dragged onto another keep, or -1 when nothing is being dragged.
  • INT_00b95f64: the keep slot that position was picked up from.
  • DAT_00b96100: probably the number of missions in the list, since a row shows mission DAT_00b96100 - row - 1.
  • DAT_00b95b2c: the selected campaign, which indexes the four progress counters in ScenarioProgress.
  • MenuTextInputState::field_0x9c: set to 1 before the lobby opens the load dialog. I don't know what it means.

The checker's 26 CHECKs

Count Where Finding Why it stays
7 Lobby :201, :202, :203, :209, :210, :211, :212 placeholder DAT_00b960f4 explained above
3 Lobby :236, :246, :271 placeholder INT_00b95960 explained above
3 Lobby :237, :262, :263 placeholder INT_00b95f64 explained above
1 Lobby :41 placeholder DAT_00b960dc explained above
1 Lobby :77 placeholder field_0x9c explained above
1 Lobby :208 placeholder INT_00b95b74 explained above
1 Lobby :50 15 numeric case labels these are the buttons' action numbers, and no enum exists for them; most cases carry a comment
1 TableHeader :17 6 numeric case labels the header's arrows and columns, and no enum exists for them
5 MissionRows :35, :50, :61, :71, :79 placeholder DAT_00b96100 explained above
1 MissionRows :36 placeholder DAT_00b95b2c explained above
1 MissionRows :35 cast on a global DAT_00b96100 is an undefined4 and the original's compare is signed; see the proposal below
1 MissionRows :53 comment about matching the one line that says why the calls are written in each arm

Proposed, not changed here

Neither of the first two has been measured.

  • ScenarioProgress: MissionRows :36 reads (&DAT_GameCore::instance.scenarioProgress.progressCallToArms)[DAT_00b95b2c::instance], indexing the four campaign counters from the first one. They could be one array of four ints, which would make this a plain index.
  • DAT_00b96100 as an int: this would remove the (int) cast at MissionRows :35.
  • loadOrSaveGame(int): the options click handler passes it 9 for Load (0x00496C85) and 10 for Save (0x00496CFA), which are MMT_LOAD_MAP and MMT_SAVE_MAP. Its parameter is probably a MenuModalType, and the lobby's 9 is probably MMT_LOAD_MAP.

One function leaves #327

The lobby's start button moves here from the draft #327. 942d855 on #327 takes it out of that draft.

🤖 Generated with Claude Code

kotijekriv and others added 3 commits November 18, 2026 17:34
LobbyMenu::MenuItemActionHandler_LobbyMenu_LobbyscreenStartButtonClick, from gynt's draft (c0a2f52 at 40.85% on his
fork's development; c88d7a2 at 40.8% on upstream's reimpl/UI-MenuItems; f53ef94 to d81f02f, 54.93% to 69.03%,
his fork's reimpl/UI-MenuItems; a4fb7c2 of 2026-10-28 on his fork's reimpl/Wilps-2026-10-18; 99cb905 at 80.53%,
35aef55 at 80.71% and dd1a7c4 of 2026-11-02, his newest commit on the file, on his fork's
reimpl/UI-MenuItems-development) and our cb601a0 and 1918de9 in draft sourcehold#327 (90.7%).

90.3% -> 100.0% on main 3458fea:
- case 4 sets the draw buffer back once, after the if / else that launches the game: the original pops three
  registers before that store in the skirmish arm (pop esi / pop ebp / pop ebx / mov / pop edi / ret);
- the two keep-position loops read keepPositions[position].x where they use it, with no local, which gives
  lea ebp, [eax + edi + 572] with x as the base (a local gave [edi + eax + 572]);
- the map index. Case 4 writes its two sums as DAT_MapSelectionScrollOffset + DAT_MapSelectionRelativeSelected, and
  case 105 takes its index through a local that is declared before the switch. That gives both cases the
  original's two loads and add (0x0044284E: edx, eax, add eax, edx; 0x00442AD8: ecx, edx, add edx, ecx). The three
  sums are coupled: of 32 combinations (each case's sum written out, as a block-scope local or as this local, in
  both operand orders) only this one and its twin with case 105's operands swapped match. A block-scope local in
  case 105 swaps case 4's loads, which is why the declaration stands before the switch, with one comment line. The local starts at 0, which nothing
  reads: declared without a value, style rule 24 asks for it in case 105, and the code is the same either way.

quick_diff reads 0.9956: its two lines are a tail jump it prints as a label and the jmp over the first loop's
alignment padding; it cannot see the load order, since it prints both fields as [G].

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>
SaveLoadMap::MenuItemActionHandler_SaveLoadMap_TableHeader, rewritten from the binary with gynt's draft for the names
(f788afb at 17.2% on upstream's reimpl/UI-MenuItems; 54e57c4 and 21d4dcf at 47.81% and 49.40% on his fork's
reimpl/UI-MenuItems; 8725ec5 at 49.4% on his reimpl/UI-MenuItems-development, his newest reimplement commit on the
file). reccmp 100.0 (normalized 100.0) on
main 3458fea with the data and its own function resolver on; the draft reads 47.8 there.

The array index changed with the header. gynt's draft uses DAT_ArrayOfMapIndices[i - 1] and [i], which was right on his
branch, where the array is declared at offset 0x884. Main's sync 12854bc (2026-11-04) moved the declared start to
0x880, so the original's 0x01126E28 and 0x01126E2C are [i] and [i + 1] here.

- The order store is in each arm and previewedListIndex = -1 is written once after the if / else. MSVC copies that store into both arms, after the last pop, as the original has it; only the order store sits
  between the pops. Written in each arm, it keeps -1 in ebx and pushes
  ebx at the top, and the first sort's two loops lose their alignment padding.
- The swap reads the moved element into a local inside the if. With both elements in locals before the test they
  land in each other's registers.
- fileListEntryCount is read in the loop condition: the original reloads it after each swap's stores.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HistoricMissionSelect::MenuItemRenderFunction_HistoricMissionSelect_MissionRows, rewritten from the binary with gynt's
draft for the names (298b3af at 20.6% on upstream's reimpl/UI-MenuItems; 633d784 at 41.41% on his fork's
reimpl/UI-MenuItems; 626fd68 at 44.53% on his reimpl/UI-MenuItems-development, his newest reimplement commit on the
file). reccmp 100.0 (normalized 100.0) on main 3458fea with the data and its own function resolver on; the draft
reads 45.3 there.

Behaviour: a mission not reached yet is drawn as a greyed cell and the function returns (0x00426A53). The draft went
on and drew the number and the name over it.

- The number and the name are written in each of the three arms, and DAT_ButtonUnknownZero = FALSE once after them:
  MSVC hoists the arms' common pushes and shares the tail, as the original has it.
- The number's position is written out in each arm; with locals for it the two loads come in the other order.
- In the selected arm the name's position and index are read into locals before the nested call, Y, X, then the
  index, which gives the original's registers for that call.
- The locked test compares (int)(DAT_00b96100 - row - 1): the global is an undefined4, and the original's jle is signed.

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