Skip to content

Reimplement 8 UI::MenuItems functions at 100% - #349

Merged
gynt merged 20 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-MenuItems-9-100
Nov 7, 2026
Merged

gynt merged 20 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-MenuItems-9-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Eight UI::MenuItems functions at 100%, each with its status line: the invasion trigger screen, the in-game menu's map scrolling, the skirmish type and balance buttons, the rankings screen, the single-player map table and its scrollbar, the "waiting for host" button and the text input display.

Three come from our drafts, which drop them in the same push: TriggerInvasion from #328, Scrolling from #327 and MapTable from #318. The other five continue gynt's drafts on his fork's reimpl/UI-MenuItems (the branch of PR #254). Every commit body says what changed against the draft and why. No header change is left: gynt's Ghidra sync eef6f66 took this PR's five header changes into main, two of them with a different type, which this PR now follows (below), and main is merged in (e5c6b15). Its first two header changes are on main since gynt's sync 8125c61, and main is merged in.

Other PRs: the ready #348 and #352, and the drafts #313, #318, #321, #327 and #328.

Built on top of main (7621d4f) with the bundled MSVC1400-SP1, natively on Windows, against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a). The branch was built clean on its own, with the struct and function resolvers enabled locally (not committed), using sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie. None of it has been run in game.

It went through the same checks as #346: a fresh-eyes review of every file (behaviour checked against the original's disassembly, texts against cr.tex; its points applied and measured), openshc-pr-check with no errors, and status_regression.py, which finds nothing below a known score on main or any fork.

Header changes

Update: all five are on main since eef6f66. Main has DAT_SH1_SiegeAdvancedMode and DAT_StoredGameMode as plain ints rather than the BOOLEnum and GameModeInt below, and this PR follows main: MapTable stores 1, and nothing on the branch uses DAT_StoredGameMode. Every function measures as in the table. The evidence below is kept for the record.

Every user compiles the same (quick_diff before and after: main's RankingGames_Main 0.9506, RankingGames_Prepare 0.9091, CrusadeMapAndEndscreen 0.9464 and TriggerPlaceWallCommand 0.9748, which came in #351; this PR's MapTable 0.9807).

  • DAT_SH1_SiegeAdvancedMode is a BOOLEnum (0bc6102): stores ^1 at 0x0042D81F, 0 at 0x0042D855 / 0x00448DC2 and 1 at 0x00442E66; it's only read with == 0. MapTable stores TRUE (9b3d5a0).
  • DAT_StoredGameMode is a GameModeInt (d4c1b5e): its one store copies GameSynchronyState::currentGameMode (0x004D972A), and its one read copies it back.
  • DAT_SkirmishTrailRelated1 is an int (18f83c2): a count that goes below 0 (stores at 0x004D8D48 / 0x004D8DD5, sub at 0x004D8F3B, clamped with jge at 0x004D8DDB); CrusadeMapAndEndscreen drops its (int) cast (df6428e).
  • MissionDefinedData::descending is a BOOLEnum (b78dc7c): stores 1 at 0x004D995F, and 1 - descending at 0x004D9970 / 0x004D9976.
  • TileMapState::wallDragButtonUp is a BOOLEnum (67b91e0): its one store (0x0043803E) writes a sete (0x00438034).

On main since 8125c61

  • MenuItemActionHandler_InGameMenu_Scrolling() takes no parameters (commit 181b559). The original ends with push 1 / call RecordTutorialPlayerAction / pop ecx (0x00434200-0x00434207) and never reads an argument; it is referenced only by six menu-table dwords (0x005F4B6C, 0x005FA79C, 0x0060613C, 0x0060622C, 0x0060636C, 0x006081BC) and never called directly. Declared (int, ...), MSVC tail-calls through the argument slot instead (mov [esp + 4], 1 / jmp; quick_diff 0.9343 -> 0.9710 with the change). Main declares 16 such handlers (), for example WaitingForHost_ConnectToLobby.
  • SEID_UNKNOWN_0xFE/0xFF/0x100 (254-256) (commit 1572310): SkirmishTypeAndBalance plays them when the balance changes, 256 at either end (buttons 10 and 14), 255 one step from even (11, 13), 254 at even (12). They're pushed at 0x0042A888, 0x0042A8A1 and 0x0042A8B5, and setUpSFXToPlayUnk indexes the 270-entry DAT_SoundStructures2 with them. The names follow the enum's existing SEID_UNKNOWN_0x101, next to main's new 0xFB and 0xFD.

Behaviour compared with the drafts

None of the eight changes behaviour; each does what its draft did and what the original does.

Class Function Address Raw Notes
TriggerInvasion MenuItemRenderFunction_TriggerInvasion_Main 0x004BBF40 100.0% From #328. reccmp 99.2% raw: the only difference is the picture table's address, which reccmp shows as an offset into DAT_GMImageHeaders (as 0x004B92D0 on main).
InGameMenu MenuItemActionHandler_InGameMenu_Scrolling 0x00434120 100.0% From #327; its declaration without parameters is on main since 8125c61.
LobbyMenu MenuItemActionHandler_LobbyMenu_SkirmishTypeAndBalance 0x0042A840 100.0% From gynt's draft; the sound IDs.
RankingGames MenuItemRenderFunction_RankingGames_Main 0x004D99F0 100.0% From gynt's draft. Headers 20-29 sort by columns 1-10; 30 and 31 toggle DAT_00ed3124 to 1 and 2 and back to 0.
SinglePlayerMapChoice MenuItemActionHandler_SingleplayerMapChoice_MapTable 0x00442C30 100.0% From #318. reccmp 98.9% raw: the loop's end, 0x00B95B1C, resolves to the next global in the original and to the array's end in the DLL.
WaitingForHost MenuItemRenderFunction_WaitingForHost_Button 0x0047E420 100.0% From gynt's draft.
SinglePlayerMapChoice MenuItemActionHandler_SingleplayerMapChoice_Scrollbar 0x00442F40 100.0% From gynt's draft; a click on the track pages by 12 of the 13 rows.
General MenuItemRenderFunction_TextInputDisplay 0x0047CCA0 100.0% From gynt's draft.

Kept as they are, and why

Each was measured; a one-line comment in the code says why.

  • TextInputDisplay: the text call in each case, which MSVC merges but for the index (one call after the switch: quick_diff 0.9664 -> 0.9365); == TRUE, since the original compares with 1.
  • WaitingForHost: two calls with the same colour (one call: 0.9375 -> 0.8136; the position inside each arm: 0.5479).
  • MapTable: a flag and break, so the loop's exit jumps past the clearing as the original's does (jg 0x00442DE3 -> 0x00442E64; testing for the end after the loop: 0.9807 -> 0.9753). The siege army's 21 unit counts are read as one array, as the original does (nested [7][3] searches: 0.9807 -> 0.8696), and SEC_SiegeInformation as 20 ints.
  • Scrollbar: the cases in the original's block order 1, 2/3, 4, 7, 5, 6, as in main's LobbyMenu_MapSelectScrollbar.

Proposed, not changed here

  • DAT_SiegeInformationArray is read here as int[21] rather than int[7][3], and SiegeUnitCounts as int[20] (an array view would help). Index 10 is overwritten with 70% of the tunnelers right after the copy. (int[7][3] is right: main's SomeSiegeRelatedCopying indexes it [unit][value]; the flat view here is a code choice.)
  • DAT_00ed3124 -> something like rankingFilterUnk (0, 1, 2); DAT_00ed27a0 -> rankingHoveredHeaderUnk (button 20 clears it, a hovered header 20-31 stores itself).
  • INT_00b95b74 -> mapDescriptionHeight (the height renderMultilineTextUnk mode 1 measures; MapDescriptionScrollbar's maximum is this - 231), and DAT_00b960f4 -> mapDescriptionScrollOffset.
  • DAT_MapMissionType (buttons 66/67/68 set 0/1/2; 2 is siege) needs an enum of its own, since MapType2's numbering differs.
  • RecordTutorialPlayerAction(int action): actions 1 (the view scrolled), 2 (rotation), 3, 4, 5 and 17 could be an enum.
  • GameCore::isNameEntryActive reads inverted (as in Reimplement 5 UI::MenuItems SaveLoadMap and Unused functions at 100% #341 and Reimplement 6 UI::MenuItems text button renders at 100% #345): TextInputDisplay's field 3, the title box, is hidden while it is 1.

gynt's other commits on these functions

Each commit body names the commits it continues. gynt has more on the same functions on his fork, and they are credited here too: his best-scoring commit on the address and his newest one on the file, where the body doesn't name them. Where one of them is at 100%, his version already matched the original, and a fix this text describes for that function was only against the earlier draft it names.

Function Address His other commits
MenuItemRenderFunction_TriggerInvasion_Main 0x004BBF40 0a0a008 (2026-10-10, 97.62%); 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%, 55 of 256")
MenuItemActionHandler_LobbyMenu_SkirmishTypeAndBalance 0x0042A840 4db0cbe (2026-10-09, 81.93%); 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%, 55 of 256")
MenuItemRenderFunction_RankingGames_Main 0x004D99F0 586edf4 (2026-10-08, 96.47%); 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%, 55 of 256")
MenuItemActionHandler_SingleplayerMapChoice_MapTable 0x00442C30 55c2f18 (2026-10-27, 56.6%)
MenuItemRenderFunction_WaitingForHost_Button 0x0047E420 d892ef3 (2026-10-09, 74.07%); 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%, 55 of 256")
MenuItemActionHandler_InGameMenu_Scrolling 0x00434120 441f484 (2026-10-08, 89.87%); 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%, 55 of 256")
MenuItemActionHandler_SingleplayerMapChoice_Scrollbar 0x00442F40 ebdb0a0 (2026-10-10, 77.38%); 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%, 55 of 256")
MenuItemRenderFunction_General_TextInputDisplay 0x0047CCA0 7d9981a (2026-10-11, 73.58%); 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%, 55 of 256")

🤖 Generated with Claude Code

kotijekriv and others added 10 commits November 6, 2026 18:57
Moved here unchanged from the draft sourcehold#328 (reimpl/UI-MenuItems-3-development-2, 13fbfea). It was 100% before the
header sync a9401a7 and 92.3% on sourcehold#328's base 72b2732, where MSVC stopped sharing the tails of its two number
calls. On main 57d3334 it compiles to the original's 100 instructions again, with the shared tail. quick_diff is
left with its own artefacts only: the jump-table spelling, the colour immediates, the picture table's address written
as its base less 14, and ret / ret 0. reccmp: 99.2% raw and 100% normalized, where only the picture table's address
differs (reccmp shows it as an offset into DAT_GMImageHeaders), which the project records as 100%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The original ends with push 1 / call RecordTutorialPlayerAction / pop ecx (0x00434200 to 0x00434207). Declared
(int, ...), our function tail-calls through its own argument slot instead (mov [esp + 4], 1 / jmp), which MSVC can only
do when the function has a named parameter. Only the menu tables refer to it (six dwords, no call), and like
WaitingForHost_ConnectToLobby it never reads an argument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LobbyMenu_SkirmishTypeAndBalance plays them when the balance changes: 256 at either end (buttons 10 and 14), 255 one
step from even (11 and 13) and 254 at even (12); the pushes are at 0x0042A888, 0x0042A8A1 and 0x0042A8B5. The draft
wrote them as (SoundEffectID)0x100 and as SEID_UNIT_DAMAGE3 | SEID_PEOPLE_ARE_COMING_TO_THE_CASTLE (248 | 7) and
SEID_UNIT_DAMAGE3 | SEID_ARROW_KILL (248 | 6).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's fork branch reimpl/UI-MenuItems-100, 97.6% there. On main's headers it compiles to the original's 41
instructions, and quick_diff differs only in its own ret / ret 0. The style pass names the parameter and the button
ranges, and the three sound effects by the names the previous commit adds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's fork branch reimpl/UI-MenuItems-100, 97.6% there. Rewritten without the decompiler's gotos, it keeps
the original's 85 instructions. quick_diff's differences are its own: ret / ret 0, and the tail jump to
MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface at 0x004D9A4F, which our
listing writes as jmp trampoline<4603888> (0x00463FF0) and quick_diff does not count as a function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moved from the draft sourcehold#318 (reimpl/batch2-development 49a51e7), 92.6% there. The search for a siege unit now sets a
flag and leaves the loop, so its exit jumps past the clearing as the original's does (jg at 0x00442DE3 to 0x00442E64)
instead of testing p == end after the loop: quick_diff 0.9753 -> 0.9807. A goto, a flag over the pointer loop and a
flag over an index loop all measure the same; the index loop reads best. What is left is quick_diff's own: the
security cookie, the timeGetTime import call, ret / ret 0, and the 11 bytes of alignment before the copy loop at
0x00442EA5, which the original's assembler wrote as a jmp over the filler. The style pass replaces the pointer loops
with index loops over the 21 counts and returns early for maps that are not sieges.

Clean alone build: reccmp 98.9% raw and 100% normalized. The two raw differences are one address, the end of the
siege search loops (cmp eax, 0x00B95B1C, one past DAT_SiegeInformationArray), which reccmp resolves to the next
global in the original and to our array's end in the DLL; the project records that as 100%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's reimpl/UI-MenuItems (PR sourcehold#254, closed), 74.1% there. The label is drawn in two calls with the same colour,
one per hover state, and the position goes through two locals computed before them: MSVC then merges the two calls but
for the text ID's push (the jne at 0x0047E45D). One call is quick_diff 0.8136, the position inside each arm 0.5479,
this form 0.9375, which leaves only the colour immediate and ret / ret 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Moved from the draft sourcehold#327 (reimpl/UI-MenuItems-3-development c1c152b), 89.9% there. With the header taking no
parameters (previous commit) the closing RecordTutorialPlayerAction(1) is a call again rather than a tail call:
quick_diff 0.9343 -> 0.9710, left with the jump-table spelling and ret / ret 0. The comments now say what -1000 does,
and that the frame-rate formula makes up for only part of the slowdown.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's reimpl/UI-MenuItems (PR sourcehold#254, closed), 77.4% there. The cases now come in the original's order, 1, 2/3, 4,
7, 5, 6, as in LobbyMenu_MapSelectScrollbar on main: the original lays the blocks out in that order (case 7's store at
0x00442FDA sits between case 4 and case 5). quick_diff then differs only in its own jump-table spelling and
ret / ret 0. The style pass names the parameters as the LobbyMenu scrollbar does and writes - 13 and ++ / --.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's reimpl/UI-MenuItems (PR sourcehold#254, closed), 73.6% there, after main's renames (isNameEntryActive). Each case
now computes the text's position, fetches the text and draws it itself: MSVC merges the copies of cases 0 to 3 into
one tail but for the push of the text's index, as the original has push 5 / push 6 / push 7 / push 0 before its
shared tail at 0x0047CDE7; case 4 keeps its own call and the surface reset. With one call after the switch the index
goes through a register (quick_diff 0.9365); this form is 0.9664, which leaves the jump-table spelling, the colour
immediates and ret / ret 0. The cursor's bottom is written DAT_ButtonY + DAT_ButtonH - 4, the order of the original's
lea (0.9030 -> 0.9365 by itself). == TRUE stays: the original compares with 1, and a truthiness test is 0.9365.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… 254-256) into reimpl/UI-MenuItems-9-100

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv and others added 2 commits November 7, 2026 03:24
It was undefined4. Every store is 0 or 1: the toggle xor [0x00B960C8], 1 at 0x0042D81F, 0 at 0x0042D855 (edx, 0 in that
handler) and 0x00448DC2 (ebx), 1 at 0x00442E66; the decompilation agrees (SingleplayerMapChoice's MapTable stores 1,
ButtonsAndHands toggles it and stores 0, SingleplayerMapChoice_Prepare stores 0), and every read compares with 0
(spawnQueuedReinforcementWaves, LaunchSinglePlayerGameUnk). A linear sweep of the exe's code finds every absolute
reference; reads and writes through a pointer to the struct are not covered by that, and the decompilation shows none.
Its one user in the code, this PR's MenuItemActionHandler_SingleplayerMapChoice_MapTable (0x00442C30), stores 1 and
compiles the same (quick_diff 0.9807 before and after); main has none.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv and others added 6 commits November 7, 2026 03:26
It was undefined4. Its one store, at 0x004D972A (MenuView_RankingGames_Prepare), copies
GameSynchronyState.currentGameMode (0x0191DD80, a GameModeInt), and its one read, in
MenuItemActionHandler_RankingGames_Main, copies it back. Both are on main and compile the same; the copy no longer
converts between unsigned and int.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was undefined4. It is a count that can go below 0: MenuView_CrusadeMap_Prepare (0x004D8CB0) stores 3 (0x004D8D48),
decrements it once per mission skipped with the chicken and stores the result (0x004D8DD5), then clamps it at 0 with a
signed test (cmp edx, edi / jge at 0x004D8DDB); 0x004D8F3B subtracts from it in memory. Main's user,
MenuItemRenderFunction_General_CrusadeMapAndEndscreen, tests it with a signed > 0 through an (int) cast, which the next
commit drops; it compiles the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was undefined4. MenuItemActionHandler_RankingGames_Main (0x004D9730) is its only writer: it stores 1 at 0x004D995F
when a new column is picked and 1 - descending at 0x004D9970 / 0x004D9976 when the same column is picked again, so it
only holds 0 and 1. A linear sweep of the exe's code finds every absolute reference; reads and writes through a pointer
to the struct are not covered by that, and the decompilation shows none. The handler is on main and compiles the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was undefined4. Its only store, in MenuItemActionHandler_InGameMenu_TriggerPlaceWallCommand at 0x0043803E, writes the
result of a sete (0x00438034), so it only holds 0 and 1. A linear sweep of the exe's code finds every absolute
reference; reads and writes through a pointer to the struct are not covered by that, and the decompilation shows none.
The handler is on main and compiles the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… no longer needs

DAT_SkirmishTrailRelated1 is an int since the commit before this one, so the signed > 0 test needs no cast. It compiles
the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The global is a BOOLEnum since the header commit before this one. Same code (quick_diff 0.9807 before and after).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The sync types DAT_SH1_SiegeAdvancedMode as int where 0bc6102 had BOOLEnum, and DAT_StoredGameMode as int where
d4c1b5e had GameModeInt: main's headers are taken, and MenuItemActionHandler_SingleplayerMapChoice_MapTable stores 1
instead of TRUE. No file of this branch uses DAT_StoredGameMode. MissionDefinedData and DAT_SkirmishTrailRelated1 are
on main as this branch had them, and TileMapState merges cleanly, so the branch no longer changes any header.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gynt
gynt added this pull request to the merge queue Nov 7, 2026
Merged via the queue into sourcehold:main with commit 7eedad6 Nov 7, 2026
4 checks passed
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