Skip to content

Reimplement 7 UI functions from gynt's drafts, and DAT_ButtonBlendStrength as an int (100%) - #400

Merged
gynt merged 15 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round10-100
Nov 14, 2026
Merged

gynt merged 15 commits into
sourcehold:mainfrom
kotijekriv:reimpl/UI-B-round10-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Seven more UI functions at 100%. Six were written from the original's instructions, with gynt's draft (below 100%) used for the reads. The AlliesOrder handler starts from his draft directly. Each commit cites the drafts it builds on and credits him as co-author. All seven are part of the rest of UI that gynt OK'd on 2026-11-09.

Function Address gynt's best draft
InGameMenu::MenuItemActionHandler_InGameMenu_RightClickMenuAndMaybeResets 0x00438B60 49.12% (b05c784)
AlliesOrder::MenuItemActionHandler_AlliesOrder_Main 0x004B1410 80.00% (36d9d19)
General::MenuItemRenderFunction_General_EventSlider 0x004BA3C0 74.47% (a35032b)
OverlaySlider::MenuItemRenderFunction_OverlaySlider_Slider 0x004AA800 53.63% (71f7285)
TacticalPowerBar::MenuItemRenderFunction_TacticalPowerBar_Main 0x004D9EC0 36.70% (643ea42)
MissionEndscreen::MenuItemRenderFunction_MissionEndscreen_Main 0x004D6D20 43.10% (aa394fe)
TextEditor::MenuItemActionHandler_TextEditor_Scrollbar 0x0045EDF0 43.44% (77036d2)

Measured on main c67521e, with #397's two commits on top (see below).

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), resolvers enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • reccmp: a full build reads all seven at 100.0%.
  • Last commit (2755aa6): it changes only names, comments and two == 0 / != 0 tests that are now truth tests. quick_diff reads the same before and after for all six files it touches: 1.0000 for five of them. The RightClick handler reads 0.9655 both times, because quick_diff prints one global's address operand differently; reccmp reads it 100.0%.
  • Checks: openshc-pr-check gives no errors, and status_regression.py finds no score below a known one.
  • Not run in game.

Behaviour fixed compared with the drafts

  • RightClickMenu: the original tail-calls updateRightDragCameraControl and returns (jmp 0x00470BC0 at 0x00438BC7). The draft went on to clear previewEnabled after it.
  • EventSlider: in the draft, sliders -2 and -1 fell from the inner switch into the next case's event test. They never pass that test, so they were never drawn. The original goes straight to drawing.
  • TacticalPowerBar: once a slot is full, the original draws the bright icon (and the highlight under the mouse) and returns (0x004D9FF5). The draft went on to draw the dimmed icon over it.
  • MissionEndscreen: the draft drew the normal button twice for button -1. It also returned after storing the column under the mouse, where the original goes on to draw that column's header.
  • AlliesOrder: the allies dialog opens again only for button -2 and after button 10's order. The other buttons close it.

Header change (in a commit of its own)

DAT_ButtonBlendStrength is an int (0cab9d6). 90af173 renames its data.asm symbol to the int type to go with it, as dbb3e8c did for DAT_00b9840c in #385.

  • TacticalPowerBar dims its icons during a multiplayer game's no-rush time with 32 - (32 - strength) / 2. The original divides that signed: mov eax, 0x20; sub eax, [0xed31c4]; cdq; sub eax, edx; sar eax, 1 at 0x004D9F5A-0x004D9F68. With undefined4, MSVC emits a shr instead.
  • Every reader passes it on as renderGMWithBlending's blend strength, which is an int.
  • Main's four readers (MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface, MenuItemRenderFunction_MapEditorLandscaping_GeneralButtons, RenderButtonImageWithBlending, RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurrentSurfaceUnk) give identical quick_diff output with it. Its writer, prepareAndRenderMenuItems, stays at 100.0% in a full build.

The declaration check will fail and label this PR until main has the line. Then I'll merge main in.

Built on #397

Main c67521e doesn't compile processMapOrientationChange.cpp after the Ghidra sync, so this branch sits on #397's two commits: e32e2b8 (the MapOrientation cast) and 4cf6926 (the file's own include first). That is the one Map file in this diff. Once #397 is merged, I'll merge main in here and the file drops out of this PR.

Kept as they are, measured with quick_diff

Function Kept The cleaner form
TextEditor Scrollbar the range clamped to 0 a second time after max without it: 0.7126; the original has the second test too (test eax, eax; jge at 0x0045EE81-0x0045EE85)
TextEditor Scrollbar max(range, 0) written out at each use, no local the original works it out again at each use (four times for the down arrow)
TextEditor Scrollbar both arrows as an if/else on an offset local, with one store pair after it the stores in each arm: 0.8702
TacticalPowerBar the button's y and x read into locals first, y before x, before the level; the icon calls read the globals again read inline: 0.8776
TacticalPowerBar the dimmed icon as one call in each branch one call with a blend local: 0.9137
OverlaySlider the title's position in two locals, y first, in both title blocks inline: 0.7039; one title block only: 0.8696
AlliesOrder button 10's own activateModalDialog call, in an if/else with the close-dialog store one shared call: 0.8750
MissionEndscreen the two tab tests in one condition separate blocks: 15 instructions more
MissionEndscreen the -10 and -1 stores as a switch an if/else-if lays them out the other way round
EventSlider, OverlaySlider the thumb's two colours as two drawColorBox calls as in the original, which shares their tail

The kept forms that a reader might tidy away (the second clamp, and the position locals in TacticalPowerBar and OverlaySlider) each have a one-line comment.

Numbers left as numbers:

  • the event slider numbers (-2, -1, 5, 12, 18, 19, 21);
  • the end screen's button IDs (the tabs -100 and -101, -10, -1, and the columns 0 to 15);
  • the power bar's slots 0 to 9 and their icon numbers;
  • the scrollbar events 1 to 7 (main's four sibling scrollbar handlers write them as numbers too).

None of these has an enum on main. The event slider's inner switch uses the ScenarioEventType names.

What some placeholders hold

  • INT_00ec082c: the end screen's selected tab. The GameLost and MissionFinishedTransition prepares set it to 0 or 2. The first tab is drawn pressed for 0 or 2, the second for 1 or 3.
  • DAT_00eb9af8: the end screen's button under the mouse: the column 0 to 15, 16 for button -1, 17 for -10. The same prepares reset it to 0.
  • CHAR_00eb0e44: hides the two tabs while it is set (main's MissionEndscreen action handler tests it the same way).
  • ViewportState::field_0x0: main's name. The right-click handler returns while it is 0, and main's other readers test it by truth too.

Proposed, not changed here

  • MenuModalComposition::textGroup is an int, cast to eTextSections for both of OverlaySlider's title calls. It holds -1 for no title (the >= 0 tests), so I left the type alone.
  • MouseState::previewEnabled is an int. The code here stores only 0 and 1, and main tests it by truth, so it could be a BOOLEnum. Not every writer is reimplemented yet, so this isn't proven.
  • thumbYPos and thumbHeight (the header's names for the slider renders' parameters) are the thumb's x offset and width in these two horizontal sliders: they are added to DAT_ButtonX and compared with DAT_ButtonW.

Other PRs

🤖 Generated with Claude Code

kotijekriv and others added 12 commits November 12, 2026 17:31
Main's Ghidra sync c67521e changed changeMapOrientation's parameter
from int to MapOrientation. processMapOrientationChange passes
DAT_FutureMapOrientation, which is still undefined4, so the file stopped
compiling (C2664). The cast restores it; quick_diff is 1.0000 before the
sync and after the fix.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The button's blend strength at 0x00ED31C4 was undefined4. MenuItemRenderFunction_TacticalPowerBar_Main (0x004D9EC0)
dims its icons during a multiplayer game's no-rush time by 32 - (32 - strength) / 2, and the original divides that
signed (mov eax, 0x20; sub eax, [0xed31c4]; cdq; sub eax, edx; sar eax, 1), where the unsigned field gives shr. Every
reader passes it on as a renderGMWithBlending blend strength, which is an int. The four files on main that read it
(MenuItemRenderFunction_General_RenderCurrentButtonWithPossibleAlphaTexOnScreenMenuSurface,
MenuItemRenderFunction_MapEditorLandscaping_GeneralButtons, RenderButtonImageWithBlending,
RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurrentSurfaceUnk) give the same quick_diff output with it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
data.asm names the instance at 0x00ED31C4 with the int type (H instead of I), as it does for main's other int
globals, to go with the header commit before it. With the old name the original's references to the address show
the unsigned instance in reccmp, and MenuItemRenderFunction_TacticalPowerBar_Main reads 96.4% raw where it is 100.0%
normalized.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_InGameMenu_RightClickMenuAndMaybeResets handles the right mouse button in game: with no right
click started, or a siege tent's battering ram or shield tab open in the build menu, a right drag moves the camera;
otherwise, with no mapper command active, it stores the mouse position and turns the preview on. Written from the
original's instructions, with gynt's draft (b05c784 on his fork's reimpl/UI-MenuItems, 49.12% there, and his batch pass 8725ec5; earlier
357b379 at 35.7%) for the reads. Behaviour fix: the original tail-calls updateRightDragCameraControl and returns,
where the draft went on to clear previewEnabled after it. Also: an early return for a viewport that is not active,
main's names (field_0x0, editorPlacementPlayerID), truth tests on the two BOOL fields, no decompiler comments. The handler's int parameter is unused and keeps the header's name. quick_diff leaves only ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_AlliesOrder_Main sends the order of one of the allies dialog's buttons to the ally shown:
buttons 1 to 6 ask for the goods of the enemy listed there, and only exist up to the number of enemies. Button -2 opens
the allies dialog again; 10 opens it again after its order, the others close it. From gynt's draft (36d9d19 on his
fork's reimpl/UI-MenuItems-development, 80.00% there; earlier 92e7815 at 66.67%) with our earlier behaviour fixes:
the dialog opens again only for -2 and 10. The shape the original needs: -2 opens the dialog and returns at the top,
and 10 has its own activateModalDialog call in an if / else with the close-dialog store (one shared call: quick_diff
0.8750, the store before it). quick_diff leaves only ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_General_EventSlider draws a scenario event's slider: its thumb, in dark lime while it is dragged
and greyish yellow otherwise, and the value beside it, or "-" for slider -2 at 10. Sliders -2 and -1 only show for the
events that last a while (the travelling fair, the plagues and pests, bandits to archers, theft and fire), the others
only for the event one below their number. Written from the original's instructions, with gynt's draft (a35032b on
his fork's reimpl/UI-MenuItems, 74.47% there, and his batch pass 8725ec5; earlier 48ef385 at 60.4%) for the reads. Behaviour fix: in the draft
the -2 and -1 cases fell from the inner switch into the next case's event test, which -2 and -1 never pass, so those
sliders were never drawn; the original goes straight to drawing. The two thumb colours are two drawColorBox calls, as
in the original, which shares their tail. Also: the parameters named slider and value (the outer switch's cases are slider numbers, which have no enum), the inner switch's cases by their ScenarioEventType names,
s___005a2280 for "-", COL_CCFAFF, decimals. quick_diff leaves the jump tables' labels, the colour immediate and ret /
ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_OverlaySlider_Slider draws a modal dialog's slider: a dark box, the slider's title from the
dialog's text group and index, and the thumb in dark lime while it is dragged and greyish yellow otherwise. A thumb as
wide as the slider covers the title, so the title is drawn again over it. Written from the original's instructions,
with gynt's draft (71f7285 on his fork's reimpl/UI-MenuItems-development, 53.63% there; earlier 3144747 at 40.70%)
for the reads. Two forms are kept for the register allocation: the title's position in two locals, y first, in both
title blocks (inline: quick_diff 0.6816, and MSVC then merges the thumb's two drawColorBox calls; one block only:
0.8696), and the thumb's two colours as two calls. Also: the parameters named slider and value as in the event slider (both unused here), COL_C2F0EB and COL_CCFAFF, decimals, no decompiler locals.
quick_diff leaves the colour immediates and ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_TacticalPowerBar_Main draws one slot of the tactical powers bar: a short line, and the power's
icon, bright once the bar's level has filled the slot (636 points a slot) with a highlight while the mouse is over it,
dimmed otherwise. The first time a power is ready the help text is shown. During the no-rush time of a multiplayer game
the icons are dimmed further and never bright. Written from the original's instructions, with gynt's draft (643ea42
on his fork's reimpl/UI-MenuItems, 36.70% there, and his batch pass 8725ec5; earlier 477e2bb at 30.8%) for the reads. Behaviour fix: once the
slot is full the original draws the bright icon and returns; the draft went on to draw the dimmed icon over it. Needs
the header commit before it: the no-rush blend strength is a signed division. The forms the original needs: the
button's y and x read into locals, y first, before the level (inline: quick_diff 0.7919), level >= ... rather than
... <= level, and the dimmed icon as one call in each branch, which MSVC merges at the tail (one call with a blend
local: 0.9137). Also: the parameter named slot; the slot to icon switch (slot numbers, no enum) with the 4 / 8 / 9 case last as in the original, decimals, no
decompiler comments. quick_diff leaves the jump table's label and ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_MissionEndscreen_Main draws the buttons of a skirmish or multiplayer game's end screen: the two
tabs -100 and -101, drawn pressed when they are the one INT_00ec082c selects (0 or 2 for the first, 1 or 3 for the
second); the results table's column headers 0 to 15, the one the table is sorted by drawn pressed, and the column under
the mouse stored in DAT_00eb9af8; and everything else as a normal button. Written from the original's instructions,
with gynt's draft (aa394fe on his fork's reimpl/UI-MenuItems, 43.10% there, and his batch pass 8725ec5; earlier 20d79c5 at 27.27% and 77ed5e0
at 19.9%) for the reads. Behaviour fixes: the draft drew the normal button twice for button -1, and returned after
storing the column under the mouse where the original goes on to draw that column's header. The forms the original
needs: the two tab tests in one condition, so their pressed drawing is one block that MSVC shares with the column
header's (separate blocks: 15 instructions more); the -10 and -1 stores as a switch (an if / else-if lays them out the
other way round). Also: the parameter named buttonID as in the sibling handler, CHAR_00eb0e44 and INT_00ec082c by
main's names, TRUE / FALSE for the BOOL stores, no decompiler locals or gotos. quick_diff leaves only ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_TextEditor_Scrollbar handles the help text's scroll bar: its range is how far the text reaches
past the view (never below 0), its arrows move a twentieth of that, at least one, and the value is the text's scroll
offset. Written from the original's instructions, with gynt's draft (77036d2 on his fork's
reimpl/UI-MenuItems-development, 43.44% there, and his style pass dd1a7c4; earlier c1f0ea6 at 41.63% and 8d5d290
at 22.67%) for the reads. The draft's mask expressions ((x <= 0) - 1 & x) are max(x, 0): the original computes it again
at each use and from the step's division twice, which is how Windows' max macro, already used on main, expands. The
forms the original needs: both arrows as an if / else on an offset local with one store pair after it, which MSVC
copies into each arm (the stores in the arms: quick_diff 0.8702). Also: the parameter named action, decimals.
quick_diff leaves the jump table's label and ret / ret 0.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the fresh-eyes review. quick_diff is unchanged for all six files (1.0000, and the RightClick handler's 0.9655
both before and after, where it prints one global's address operand differently; reccmp reads it 100.0).

- RightClickMenuAndMaybeResets: viewportState.field_0x0 and previewEnabled tested by truth, as main's other readers
  test them; the unused int parameter named unused.
- TextEditor_Scrollbar: the parameters named unused and scrollbarEvent, as main's sibling Scrollbar handlers have
  them.
- Why-comments on the three forms kept for the match, measured again on main c67521e: the scrollbar's second clamp
  after max (without it: 0.7126; the original tests again, test eax, eax; jge at 0x0045EE81), TacticalPowerBar's x
  and y read into locals while the icon calls re-read the globals (inline: 0.8776), and OverlaySlider's title
  position in locals, y first (inline: 0.7039).
- MissionEndscreen's tab comment on one line; EventSlider's "-" comment moved off the macro's argument list, to the
  line above the call.

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 12, 2026
kotijekriv and others added 2 commits November 13, 2026 16:39
Four comments carried quick_diff numbers; the numbers belong in the PR text, so the comments keep only the reason:
the OverlaySlider render's title positions (two), the TacticalPowerBar render's icon positions and the TextEditor
scrollbar handler's second clamp. Comments only, no code change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings in sourcehold#397 (merged as 5ec4011), so this PR no longer shows its
commits, plus sourcehold#290, sourcehold#402 and sourcehold#405.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main's Ghidra sync 1d819b7 has the DAT_ButtonBlendStrength header change
from this PR, so the PR no longer changes a header.

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 13, 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