Skip to content

Reimplement 5 UI::MenuItems functions at 100% - #351

Merged
gynt merged 5 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-MenuItems-10-100
Nov 6, 2026
Merged

gynt merged 5 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-MenuItems-10-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Five UI::MenuItems functions at 100%, each with its status line: the greatest lord table's header render, the crusade map's skip button caption, the in-game wall placement command, a button render on the screen menu surface, and the rankings screen's buttons.

All five continue gynt's drafts on his fork: four from reimpl/UI-MenuItems (the branch of PR #254), the rankings handler from reimpl/UI-MenuItems-development. Every commit body says what changed against the draft and why. No header change. One file is added to cmake/compiler-flags-gl.txt (below).

Other PRs: the ready #342, #348, #349 and #350 (a fix for main), and the drafts #313, #318, #321, #327 and #328.

Built on top of main (da1fef5) 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 #349: 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.

Behaviour fixed compared with the drafts

  • GreatestLord render (0x004AE720): the original returns after drawing the sorted column's header (ret at 0x004AE7B6). The draft went on to RenderButtonImageWithBlending and drew the default picture over it.
  • TriggerPlaceWallCommand (0x00437ED0): the original returns after drawing the wall preview until the drag stops (ret at 0x0043805E). The draft went on, so during a drag it could queue GCT_PLACE_WALL, and show the fail-reason text, every frame.
  • The other three behave exactly as their drafts did; only their form changed.
Class Function Address Raw Notes
GreatestLord MenuItemRenderFunction_GreatestLord_Main 0x004AE720 100.0% The return fix above.
General MenuItemRenderFunction_General_CrusadeMapAndEndscreen 0x004D8DF0 100.0% "Skip Current Mission" / "No Chickens Left" (cr.tex group 256, texts 0 and 1).
InGameMenu MenuItemActionHandler_InGameMenu_TriggerPlaceWallCommand 0x00437ED0 100.0% The return fix above.
General MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface 0x00463FF0 100.0% Built with /GL.
RankingGames MenuItemActionHandler_RankingGames_Main 0x004D9730 100.0%

Kept as they are, and why

Each was measured; a one-line comment in the code says why where the shape isn't obvious. quick_diff compiles without LTCG, so its baselines here read below 1.0.

  • RenderCurrentButton… and /GL: after call 0x004630B0 (getPictureNumberInGm) the original reads through the preserved ecx (mov ecx, [ecx] at 0x00464040), which needs /GL; the callee's file is already in the list and at 100%. Each use indexes ButtonGmDataArray afresh, as the original forms the address in each path (lea ecx at 0x00464028 and 0x00464081); a ButtonGmData* local, as in RenderButtonImageWithBlending, moves it ahead of the branch (70.7%).
  • CrusadeMapAndEndscreen: the caption in one call per text, which MSVC merges but for the index (an index local: quick_diff 0.9464 -> 0.8468); its position y then x, before the test (x first: 0.8750); the hover flag cleared, then set when hovered (a copy of DAT_ButtonCurrentlyInteracting: 0.8000). (int)DAT_SkirmishTrailRelated1, because the header has undefined4 and the original compares it signed (jle at 0x004D8E8E).
  • TriggerPlaceWallCommand:
    • (ushort)currentMapperCommand in both calls: the original passes the mapper's low word, zero-extended (movzx at 0x00437FD8 and 0x00438019), to an undefined4 command parameter.
    • The six command parameters are set in address order, which MSVC compiles to the original's store order (from 0x0043809B); the draft's copy of the compiled order came out in address order (93.3%).
    • getWallTilesThatCanBeBuilt(..., Resources::RT_STONE) for every wall tool, the wooden wall included: the original pushes 4 at 0x00437FB7.
  • RankingGames_Main: button 11 is an if/else of the two switchToMenuView calls and one store of the stored game mode (two separate returns: quick_diff 0.9506 -> 0.8519); 1 - descending (!descending: 0.9354); the clamp written twice, as the original has it twice (0x004D9981, 0x004D99D2); the results copied with one struct assignment (rep movsd of 0x1DE dwords at 0x004D97B6) and the picture names with plain strcpy, which MSVC inlines as the original does.

Proposed, not changed here

  • DAT_00ed3124 is the rankings filter: 0 "All Games", 1 "Crusader Trail Only", 2 "Custom Games Only" (cr.tex group 255, texts 7-9); an enum would name them. INT_00ed3120 is the rankings list's first shown row and INT_00eb9b60 the number of games in it (counted in Skirmish_PrepareLeaderboardView, 0x004D9400). Main's SetActiveCreditsSequenceIndex (0x004D9270) sets the filter and resets the first row (see Fix SetActiveCreditsSequenceIndex after the INT_00ed3120 rename #350).
  • DAT_00ed2788: the game record the delete dialog removes (read at 0x004D9D67, passed to 0x004D5370). DAT_CurrentMenuID_3: the menu the rankings were opened from (stored at 0x0046B6E6 / 0x0046B700). DAT_StoredGameMode: undefined4 -> GameModeInt (MenuView_RankingGames_Prepare saves currentGameMode into it; button 11 restores it).
  • INT_00ed2bdc: "skip button hovered", a BOOLEnum (three stores in the exe, all 0 or 1).
  • DAT_SkirmishTrailRelated1 (0x00ED27C0): the crusade trail's chickens (skips) left, an int: set to 3 at 0x004D8D48, lowered and clamped at 0 in 0x004D8CB0, lowered again at 0x004D8F3B, always compared signed. As an int it would drop the cast above.
  • BOOLEnum candidates (only 0/1 stored, tested by truthiness): MissionDefinedData::descending, TileMapState::wallDragButtonUp (sete at 0x00438034), and GameCore::skipStoreSKMasters (a byte; about 30 stores, all 0/1).
  • MouseState::field_0x1dc is a mouse mode: -1, 0-5, or 1000 here (a switch at 0x004EC5D6 has a case for 1000), so an enum candidate.
  • TileMapState::validateWallBuildPath / renderWallDragPreview: the last parameter is undefined4 command, but every caller passes the mapper's low word; it may be a 16-bit type.

🤖 Generated with Claude Code

kotijekriv and others added 5 commits November 6, 2026 21:37
From gynt's reimpl/UI-MenuItems (PR sourcehold#254, closed), 62.9% there. Behaviour fix: the original returns after drawing the
sorted column's header (ret at 0x004AE7B6); the draft went on to RenderButtonImageWithBlending and drew the default
picture over it. The position goes straight into the renderGM call, as the original pushes it before calling
getPictureNumberInGm. quick_diff leaves only ret / ret 0; reccmp 100% in a trial build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's reimpl/UI-MenuItems (PR sourcehold#254, closed), 64.3% there. The hover caption is drawn in two calls, "Skip Current
Mission" while skips are left and "No Chickens Left" otherwise (cr.tex section 256, texts 0 and 1), which MSVC merges
but for the text index, as the original's push 0 at 0x004D8E90 and push 1 at 0x004D8EA8; the draft's (count < 1)
index compiled to a setl. The caption's position is computed before the test, y first. DAT_SkirmishTrailRelated1 is
declared unsigned and the original compares it signed (jle at 0x004D8E8E), hence the (int). reccmp 100% in a trial
build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's reimpl/UI-MenuItems (PR sourcehold#254, closed), 70.3% there, after main's renames (field_0x0, wallDragButtonUp,
field_0x1dc). Behaviour fix: the original returns after drawing the wall preview while the drag goes on (ret at
0x0043805E), so the wall is only placed once the drag has stopped; the draft went on and could queue GCT_PLACE_WALL
during the drag. The arms of three ifs now come in the original's order: the click first, the flat view's
setupMouseTileXY2 first, the illegal build first. The six command parameters are set in address order, which MSVC
compiles to the original's store order (Param1, Param0, Param2, Param4, Param3, Param5 from 0x0043809B on); the draft
had copied that compiled order, and written so ours came out in address order (reccmp 93.3%). quick_diff
0.8186 -> 0.9748, which leaves only ret / ret 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's reimpl/UI-MenuItems (PR sourcehold#254, closed), 53.0% there. Built with /GL (added to cmake/compiler-flags-gl.txt):
the original keeps the button's address in ecx across getPictureNumberInGm (0x004630B0, 100% and already in the list)
and reads the GM ID through it afterwards (mov ecx, [ecx] at 0x00464040). Each use indexes the array afresh: the
original computes the byte offset once and forms the address in each path (lea ecx at 0x00464028 and 0x00464081),
where a pointer local moved it ahead of the branch (70.7% with /GL). reccmp 100% in a clean alone build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From gynt's fork branch reimpl/UI-MenuItems-development, 54.6% there. The game's results are copied with one struct
assignment (rep movsd of 0x1DE dwords at 0x004D97B6) and the end-screen picture names with plain strcpy calls from the
S_* literals, which MSVC inlines as the original does (six dword moves, five dword moves, rep movsd plus movsb, and five
dwords and a byte); the draft had a hand-written loop and a memcpy with a masked byte. Button 11 is an if/else of the
two switchToMenuView calls followed by one store of the stored game mode, which MSVC duplicates into both paths with the
original's registers (two separate returns: quick_diff 0.9506 -> 0.8519). The scroll offset and the game count are
main's INT_00ed3120 and INT_00eb9b60, declared int since 7621d4f. quick_diff then leaves only its spelling of rep
movsd and ret / ret 0.

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