Skip to content

Reimplement 5 UI menu dialog, minimap and progress bar functions at 100% - #348

Merged
gynt merged 14 commits into
sourcehold:mainfrom
kotijekriv:reimpl/batch15-100
Nov 7, 2026
Merged

gynt merged 14 commits into
sourcehold:mainfrom
kotijekriv:reimpl/batch15-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Five UI functions at 100%, each with its status line: the menu dialog stack's push and pop (activateModalDialogAndClearText, popModalDialog), the minimap click (convertMinimapClickToTileXY), the load/save progress bar (RenderLoadAndSaveBar) and an old menu's mission select render.

Four come from our draft #313, which drops them in the same push; the mission select continues gynt's draft on his fork. 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 two header changes (below) into main, and main is merged in (614ef85). Its first header change, the array, is on main since gynt's sync 8125c61 (below), and main is merged in. That sync leaves main's own clearModalDialog2to6.cpp naming modalDialog_2..6, so it no longer compiles; this PR's fe606002c moves it to the array, so merging this mends main.

Other PRs: the ready #349 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 and measured 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; its points applied and measured), openshc-pr-check, and status_regression.py, which finds nothing below a known score on main or any fork.

Header changes

Update: both are on main since eef6f66. 222e50c drops the BOOLEnum using-declaration that the merge left twice in MinimapViewState.hpp, so the header is the same as main's. Main's own clearModalDialog2to6.cpp still doesn't compile there until this PR lands (fe606002c below); the other files the sync broke are in #368.

  • GameCore::unlockAllHistoricalCampaigns is a BOOLEnum (334c1ef): its only stores in the exe are 1 (0x004B49C8, from a register set to 1 before) and 0 (GameCore's initialiser, 0x0046B21D); its readers compare it with 0.
  • MinimapViewState::minimapClickEnabled is a BOOLEnum (65c0847): its only stores are 1 at 0x00434328 (the register is 1 on both paths into it) and 0 at 0x0043432E, and none of MinimapViewState's own methods writes it.

All six of main's users of the two fields still measure 100.0%.

On main since 8125c61: MenuTextInputState's modalDialog_2..6 are one array

modalDialog_2..6 (+0x60..+0x70) become MenuModalTypeInt previousModalDialogs[5]: the dialogs below currentModalDialog, most recent first (commit b93f85653). All four functions that touch them treat them as one run:

  • push, 0x004916C0: [70h]<-[6Ch], [6Ch]<-[68h], [68h]<-[64h], [64h]<-[60h], [60h]<-[5Ch], then [5Ch]<-dialogID;
  • pop, 0x00493900: [60h..6Ch]<-[64h..70h], then [70h]<-0;
  • clear, 0x00491730: zeroes [60h..70h];
  • the constructor, 0x00491680: zeroes [5Ch], then [60h..70h] in order.

Written as loops over the array, the push and the pop match; written as five named fields they don't (quick_diff 0.7742 and 0.8788; the #313 drafts reached reccmp 90.3% and 93.9%). currentModalDialog stays a field of its own: 17 files on main name it, and neither loop's range includes it. Layout: 0x60 + 20 = 0x74 = fileListEntryCount, and the size assert is unchanged.

Main's only user is clearModalDialog2to6, moved to a countof loop over the array in the next commit (fe606002c, same code, still 100%). b93f85653 alone doesn't build because of that; they're kept apart so the header is in a commit of its own.

Off main, these drafts name the old fields and need the same move when they land: Constructor_MenuTextInputState.cpp, activateModalDialogAndClearText.cpp and popModalDialog.cpp on sourcehold's reimpl/UI-Core and on gynt's development, reimpl/UI-Core-development, reimpl/UI-MenuItems-development, reimpl/UI-Rendering-development and reimpl/UI-MenuItems-100 (6and8's reimpl/UI-Core too). This PR replaces the activate and pop drafts; the constructor's five MMT_NO_MENU stores become a loop over previousModalDialogs.

Behaviour fixed compared with gynt's drafts

His drafts of three of these (on development, reimpl/UI-Core-development and reimpl/UI-Rendering-development) lose a return the original has; our #313 drafts had them, and here each is a guarded if/else:

  • popModalDialog: after reactivating the previous dialog it fell into clearAnyOtherModalDialogs and closed it again; the original returns (pop esi; ret at 0x00493969).
  • convertMinimapClickToTileXY: the computed tile was always overwritten with -1/-1; the original returns (ret 8 at 0x004B525D).
  • RenderLoadAndSaveBar: in game it also drew the bar on the menu surface and blitted it after the flip; the original returns (ret at 0x0049375A).
Class Function Address Raw Notes
MenuTextInputState activateModalDialogAndClearText 0x004916C0 100.0% From #313 (90.3%).
MenuTextInputState popModalDialog 0x00493900 100.0% From #313 (93.9%); the return fix above.
MinimapViewState convertMinimapClickToTileXY 0x004B51A0 100.0% From #313 (87.1%); the return fix above.
Rendering RenderLoadAndSaveBar 0x00493690 100.0% From #313 (85.7%); the return fix above.
Unused MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect 0x00426D30 100.0% From gynt's draft (81.4%).

Kept as they are, and why

All five are reccmp 100%. quick_diff compiles without LTCG, so some kept forms read below 1.0 there (0x00426D30 0.9302, 0x00493900 0.9394, 0x00493690 0.9459); the numbers below are from that baseline. A one-line comment in the code says why.

  • activateModalDialogAndClearText: DAT_SomeTextArrayIndex is written through the global, as the exe writes the absolute address (this->: 1.0000 -> 0.9355); the push as a loop (written out: 0.7742).
  • popModalDialog: the pop as a loop (written out: 0.9394 -> 0.8788); guarded, not an early return for the empty stack (0.8788).
  • convertMinimapClickToTileXY: guarded, not an early return when disabled (1.0000 -> 0.9000); the orientation if-chain (the offset computed from the orientation: 0.5507), with an arm for orientation 0, as main's renderPreviewAtMouseLocation has (without it: 0.8714, the draft's register swap).
  • RenderLoadAndSaveBar: one store of 1 through a siegeTowerOrShieldTab local, as main's WinMain has one store (there a comma expression); an if/else with a store each measures 0.9459 -> 0.8742, because MSVC then keeps 1 in edi, which held the draft at 85.7%.
  • The mission select: the name's position as locals, y then x (in the call: 0.9302 -> 0.7608; x first: 0.8992); the number's position and value in each branch (once, before the test: 0.8760).

Proposed, not changed here

  • MenuTextInputState::clearModalDialog2to6 -> clearPreviousModalDialogs, now that the fields are an array.
  • MinimapViewState::convertMinimapClickToTileXY(int* param_1, int* param_2) -> (int* tileX, int* tileY); the .cpp already uses those names.
  • Rendering::RenderLoadAndSaveBar(int progressValueUnk) -> progressPerMille: callers pass size * 1000 / total (writeMapOrSaveFile, readMapOrSavFile) or 50.
  • UserTextHandler::allowUserTextInput may be a BOOLEnum too, but it has more than 20 stores, many of them from registers we haven't all traced to 0 or 1 yet, so it isn't changed here.
  • WindowAndDirectDraw::pendingBltMode holds 1 or 2 (here and in WinMain); an enum could name the two values.

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_UnusedEconomicMissionSelect_MissionSelect 0x00426D30 ba84163 (2026-10-10, 43.51%); 8725ec5 (2026-10-25, "UI-MenuItems average 73.57% -> 75.19%, 55 of 256")
popModalDialog 0x00493900 4c98c03 (2026-10-03, 32.4%); 10280b1 (2026-10-25, "UI-Core average 56.85% -> 63.78%, 10 of 57 at 10")
activateModalDialogAndClearText 0x004916C0 a7a173d (2026-10-03, 58.1%); 10280b1 (2026-10-25, "UI-Core average 56.85% -> 63.78%, 10 of 57 at 10")
convertMinimapClickToTileXY 0x004B51A0 be3fc9e (2026-10-03, 72.86%); 10280b1 (2026-10-25, "UI-Core average 56.85% -> 63.78%, 10 of 57 at 10")
RenderLoadAndSaveBar 0x00493690 9c107ef (2026-10-01, 66.21%); 63cc49f (2026-10-25, "UI-Rendering average 51.16% -> 56.41%, 20 of 106")

🤖 Generated with Claude Code

kotijekriv and others added 7 commits November 6, 2026 18:41
MenuItemRenderFunction_UnusedEconomicMissionSelect_MissionSelect, from gynt's draft on his fork's branch
reimpl/UI-MenuItems (43.5% there). A mission not reached yet is an empty cell; the selected one shows its number
and name; the others the same in two colours, one call per colour, as in the original (one renderText2
with a colour local, gynt's draft: quick_diff 0.9302 -> 0.6615). DAT_ButtonUnknownZero is set to
TRUE/FALSE.
Shape: the selected mission's name position as locals, y then x (in the call: quick_diff 0.9302 -> 0.7608; x first:
0.8992); the other missions' number position and value worked out in each branch (once, before the hover test:
0.9302 -> 0.8760; any order of the three ties inside the branches). A comment says what the button holds: minus
the mission number, shown as mission - 32 and named by entry mission - 11 of TEXT_MISSION_NAMES.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The five fields after currentModalDialog (+0x60..+0x70) are the stack of dialogs below the current one, and the
original moves them as an array: popModalDialog shifts them down one and activateModalDialogAndClearText pushes
the current dialog on top, each a loop the compiler unrolled (0x00493900, 0x004916C0). Written as five named
fields neither function matches (quick_diff 0.8788 and 0.7742). Now previousModalDialogs[5], most recent first.
main's clearModalDialog2to6 is the only .cpp on main that names the fields; the next commit moves it over.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main's MenuTextInputState::clearModalDialog2to6 (0x00491730) named the five fields the previous commit makes one
array. It now clears previousModalDialogs in one loop (countof, to MMT_NO_MENU, which is 0) and compiles to the same
code (reccmp 100.0%). Its first include is now the class's .func.hpp, as its siblings have it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuTextInputState::popModalDialog, from our draft on kotijekriv's fork branch reimpl/UI-Core-development (93.9% there,
also in sourcehold#313). The previous dialog comes off the stack, the rest move down one (a loop over previousModalDialogs;
written out per element: quick_diff 0.9394 -> 0.8788), and it becomes the current dialog. The save-map dialog
gets its file list and text input back; an empty stack clears every other dialog. Guarded, not an early return (an
early return for the empty stack: 0.9394 -> 0.8788). resetToTextIndex takes TAIT_TWO__FILTER_A; the
last index is countof(previousModalDialogs) - 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuTextInputState::activateModalDialogAndClearText, from our draft on kotijekriv's fork branch
reimpl/UI-Core-development (90.3% there, also in sourcehold#313). With no dialog open it saves the text array index and
clears the text; a dialog that isn't already current is pushed onto the stack, counting down over
previousModalDialogs from countof(previousModalDialogs) - 1 (written out per element: quick_diff 1.0000 -> 0.7742; i != 0 as the bound: 0.5312), and
activated. The draft's pointer over &currentModalDialog is gone, and so is the imported plate comment. The text array index is
saved through the global, as the original does (this->: quick_diff 1.0000 -> 0.9355).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MinimapViewState::convertMinimapClickToTileXY, from our draft on kotijekriv's fork branch reimpl/UI-Core-development
(87.1% there, also in sourcehold#313). The mouse position on the minimap becomes a screen point, looked up in the current
orientation's screenPointToTileNumber table (80400 entries apart, as main's ViewportBasedTileNumber writes them),
and the tile is split into x and y; with clicks disabled both are -1. Orientation 0 sets the offset again, as main's
renderPreviewAtMouseLocation does (without that arm: quick_diff 1.0000 -> 0.8714; it was the draft's register
swap). Guarded, not an early return (an early return when disabled: 1.0000 -> 0.9000). Computing the offset from the
orientation instead: 0.5507. The redundant (short) cast on the short table is gone; 0x191 is 401. The flag is a truthiness test.
The Y term and the offset stay up front (Y inline: 1.0000 -> 0.7770; the offset declared at first use: 0.6714);
comments say why the +6 / -6 both stay and that the out parameters hold the screen point until the tile is known.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rendering::RenderLoadAndSaveBar, from our draft on kotijekriv's fork branch reimpl/UI-Rendering-development (85.7% there,
also in sourcehold#313). At most every 30 ms it draws the progress bar, in game on the map surface and flipped, in the menus
on the menu surface and blitted. The blit mode is 2 on the siege tent's tower and shield tabs unless the building
and status menu is open, else 1: one store of 1 for both paths, as in main's WinMain (there a comma expression, here
a siegeTowerOrShieldTab local; an if/else with a store each: quick_diff 0.9459 -> 0.8742, and MSVC then keeps 1 in
edi, the draft's blocker). The 30 ms, the per-mille progress (300 pixels wide when full) and the 15-pixel height
have a comment each.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nto reimpl/batch15-100

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv and others added 3 commits November 7, 2026 03:36
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its only stores in the exe are 1 at 0x004B49C8 (ebp, set to 1 at 0x004B4813) and 0 in GameCore's initialiser
(mov [eax + 0x58], ecx at 0x0046B21D, ecx zeroed at 0x0046B1F2); its readers compare it with a zero register
(0x004269FC, 0x00426D4C). BOOLEnum is a typedef of int, so the size and every access stay the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Its only stores in the exe are 1 at 0x00434328 (eax, set to 1 at 0x00434319 on both paths) and 0 at 0x0043432E;
no MinimapViewState method writes it through this. BOOLEnum is a typedef of int, so the size and every access stay
the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 7, 2026
cpp-linter checks whole changed files: the BOOLEnum include added in 65c0847 sorts with the project includes.
Whitespace and include order only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv and others added 2 commits November 7, 2026 17:53
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The merge of eef6f66 left the BOOLEnum using-declaration twice: the sync added its own when it took
minimapClickEnabled's BOOLEnum from this PR. The header is now the same as main's, so the PR no longer
changes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 7, 2026
@gynt
gynt added this pull request to the merge queue Nov 7, 2026
Merged via the queue into sourcehold:main with commit 2de2ada 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