Repository navigation
Reimplement 5 UI functions from gynt's drafts and #318/#327/#328, with one header commit (100%) - #410
Open
kotijekriv wants to merge 7 commits into
Open
kotijekriv wants to merge 7 commits into
kotijekriv wants to merge 7 commits into
Conversation
sliderMinimum and sliderMaximum were dword. The original treats them as signed: the OverlaySlider handler (0x004AA600) tests `sliderMaximum - sliderMinimum > 200` with jle (0x4aa630, 0x4aa697, 0x4aa7a3) and divides by 5 signed (0x4aa635, 0x4aa6c4). With the fields as int the handler measures 100.0 instead of 57.1 (reccmp, main 1d819b7; the same again on 3416498). The only other users of the two fields, setSliderParameters and setSliderParameters2, only store to them, so they compile the same. sliderValue stays dword: the original only copies it, and the handler compiles to the same code either way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_OverlaySlider_Slider, from our own drafts at 89.8% and 91.5% (local, never pushed), themselves rewritten from gynt's draft (593c4ef at 47.37% on his fork's reimpl/UI-MenuItems-development; his last style pass on the file is f6c6b8b). It needs the slider minimum and maximum as ints (the MenuModalComposition header commit before this one); with them reccmp reads 100.0, normalised 100.0. The fix: case 1 stores the current value once, after the large-range and small-range branches, rather than at the end of each. MSVC then gives the small-range branch the original's scratch registers, and case 2 and 3 follow (the store in each branch measured 91.5). Case 7 tests `*currentValue > *maxValue / 2` for the step of 1, which gives the original's setle. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_HistoricCampaignSelect_Main, from the draft sourcehold#327 (reimpl/UI-MenuItems-3-development, 90d1284 at 98.7%; the file's newest commit on the draft is 446f9fa), itself rewritten from gynt's draft (d07873b at 97.44%, after his 61351fe at 82.1% and 245178b at 94.87%; on his fork's reimpl/UI-MenuItems-development the function is 04f12f8 at 67.10%, his newest reimplement commit on the file is 8725ec5 and his last style pass 5084980). reccmp 100.0, quick_diff 78/78 at 1.0000. The last difference was the getTextStringInGroupAtOffset call loading ecx after both its pushes, where the original loads it between them. The campaign name is drawn by two calls that are the same, one per hover state, each with the position read into `int const textY` then `textX`: MSVC merges them completely and keeps the original's order. It is the same form as in MainMenu's render (0x00424F50), the sibling this function was copied from. The early returns, the branch order, the sound ID SEID_UNKNOWN_0x92 and the campaign names from cr.tex were already in the draft. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemRenderFunction_SaveLoadMap_TableHeader, from gynt's draft (78de101 at 97.44% on his fork's reimpl/UI-MenuItems, after his 0747a3c; on his reimpl/UI-MenuItems-development the file has 2002473, and his newest reimplement commit on it there is 8725ec5; quick_diff 0.9744 on main). reccmp 100.0, quick_diff 39/39 at 1.0000. The draft's only difference was the getTextStringInGroupAtOffset call loading ecx after both its pushes, where the original loads it between them. As in HistoricCampaignSelect's render (0x004255D0, earlier on this branch), the header text is written as two calls that are the same, one per hover state, each with `int const textY` then `textX`: MSVC merges them completely, leaving no branch, and keeps the original's order. Position locals alone measured the same as the draft. The column switch and its text numbers were already gynt's ("Name", "Date" and "Mission" in TEXT_GAME_OPTIONS); the colour is COL_CCFAFF, the font size 18, and the parameter is the column. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_CrusadeMap_Main, rewritten from the binary. It starts from gynt's draft (00e21e3, 59034df and 98dc115 on his fork's reimpl/UI-MenuItems, 33.48% there; 3d6fb54 at 34.80% on his reimpl/UI-MenuItems-development, his newest reimplement commit on the file) and our mechanical pass of it in sourcehold#328 (2d468df, 35.2%). reccmp 100.0 (normalized 100.0), quick_diff 215/215 at 0.9907, the rest being the timeGetTime import call, which reccmp resolves. The buttons are Skip Current Mission (1000), the lord's face for the mission briefing (10), back to the choice of crusade (11), a click on the map (1) and the rankings (99), in the original's block order with early returns. What the match needed: - Skip Current Mission repeats the setStartDateUnk call and everything after it in each trail's branch. MSVC merges the three copies into the first one, as the original has them, and the constant 1 then goes to ebp; one call after the trail branches, or a switch on the trail type, measured 0.9395 and 0.8419. - The click test reads each position as `left = x - 10` and `top = y - 10`, compared with `left + 20` and `top + 20`, which is how the original computes both bounds (0.6075 with x - 10 and x + 10). Fixes against the draft: - The first edition and extreme trails tested the click's y the wrong way round (Ghidra's `y + -clickY >= 10`, that is clickY <= y - 10, where the original tests clickY >= y - 10), so a mission could only be picked by clicking above it. - The warchest and extreme searches went one mission too far (`> 30` and `20 <`), reading one position past the end of the warchest table; the original stops below 30 and 20. Cleanup: a click wrote all three trails' progress back, two of them unchanged; the original stores only the trail being played. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MenuItemActionHandler_General_ToolbarButtonPressed, from gynt's draft (d2993ae, 6e17808, 8a21939 and b984b98 on his fork's reimpl/UI-MenuItems, 65.02% there; a1c4156 at 67.59% and 9dc4216 at 67.74% on his reimpl/UI-MenuItems-development, 9dc4216 being his newest reimplement commit on the file) and our own draft in sourcehold#318 (c00f64a at 71.40% on reimpl/batch2-development), rearranged from the binary. The function leaves sourcehold#318 with this commit. reccmp 100.0 (normalized 100.0). quick_diff reads 0.8939 because it stops the original after the siege-engine case. On main the draft needed only renames to compile: buildingEntryInfos for the eight building references, unitIDSelectedCatapultOrTrebuchet and field_0x30. What the match needed: - The switch cases in the original's block order. The siege engines (with the Arab ballista) and the tunnel are plain cases that break to the code after the switch, and the three stances each make their own call (quick_diff 0.6693 -> 0.7085). - The eight building buttons each move the view to their building in their own copy of that code. MSVC merges the copies into the granary's, where the original has them, followed by the code after the switch (0.7085 -> 0.8915); one shared label puts the block after the last of them instead: reccmp 75.2 (normalized 61.3) against 100.0. - The tunnel button tests for no tunneler first. Fixes against the draft: - With one catapult or trebuchet selected and under 10 stone, the original only plays the lack-of-stone sound; the draft queued the command anyway. - After queueing the command for one engine or for the selection, the original returns; the draft went on to clear the patrol button and mark an engineer as selected. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main's Ghidra sync 1b36c0a has this PR's MenuModalComposition slider types, so the PR no longer changes a header. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Main is merged in now (e086ba7). Its Ghidra sync 1b36c0a has this PR's Because of the symbol-count effect gynt found on #366, we measured again after the merge. This was a full build of main e086ba7 with this PR and #409 merged on it, against a full build of main alone.
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Five more UI functions at 100%, with one header commit:
MenuModalComposition's slider minimum and maximum becomeints, which the OverlaySlider handler needs. All five build on gynt's drafts. Each commit cites the drafts it builds on and credits him as co-author. Three of the five were also in our drafts #318, #327 and #328, which they now leave. All five are part of the rest of UI that gynt OK'd on 2026-11-09.OverlaySlider::MenuItemActionHandler_OverlaySlider_SliderHistoricCampaignSelect::MenuItemRenderFunction_HistoricCampaignSelect_MainSaveLoadMap::MenuItemRenderFunction_SaveLoadMap_TableHeaderCrusadeMap::MenuItemActionHandler_CrusadeMap_MainGeneral::MenuItemActionHandler_General_ToolbarButtonPressedAll five read 100.0%, raw and normalised.
Measured on main 3416498.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp (6f980a441) with--resolve-wrapped-calls --ignore-security-cookie.sliderValueanint). All five read 100.0%, raw and normalised. Of the 2,381 functions measured on main, 2,378 read exactly the same with this branch,setSliderParameters,setSliderParameters2and UnusedWinCondition's Options handler among them. Three move, and none of them because its code changed:UI::Menu::Constructor_Menu(100.0% to 98.4%) andUI::Menu::handleMenuItems(100.0% to 97.9%) compare with the constant0x11000000. With this branch the DLL's layout puts a symbol at that address, so reccmp names the constant after it. It is the same thing Reimplement 5 UI functions from gynt's drafts and #328 (100%) #407 saw the other way round, and neither file changes.openshc-pr-checkgives no errors, andstatus_regression.pyfinds no score below a known one.What got them to 100%
ints (the header commit below), the range test and the divisions by 5 compile signed, as in the original. Case 1 then stores the current value once, after the large-range and small-range branches, rather than at the end of each. MSVC then gives the small-range branch the original's scratch registers, and cases 2 and 3 follow. Case 7 tests*currentValue > *maxValue / 2for the step of 1, which gives the original'ssetle.ecxafter both of its pushes, where the original loads it between them. The campaign name is now drawn by two calls that are the same, one per hover state, each with the position read intotextYthentextX. MSVC merges the two completely, so no branch is left, and keeps the original's order. It is the same form as MainMenu's render (0x00424F50, from Reimplement 5 UI functions from gynt's drafts and #328 (100%) #407), the sibling this function looks copied from.textYthentextX. The column switch and its text numbers were already gynt's.setStartDateUnkcall and everything after it in each trail's branch, and MSVC merges the three copies into the first one, where the original has its code. The click test reads each mission's position asleft = x - 10andtop = y - 10, and compares withleft + 20andtop + 20, which is how the original computes both bounds.buildingEntryInfos,unitIDSelectedCatapultOrTrebuchetandfield_0x30). The cases are in the original's block order. The siege engines (with the Arab ballista) and the tunnel are plain cases that break to the code after the switch, and the three stances each make their own call. The eight building buttons each move the view to their building in their own copy of that code, and MSVC merges the copies into the granary's, where the original has them. The tunnel button tests for no tunneler first.Behaviour fixed compared with the drafts
y + -clickY >= 10isclickY <= y - 10, where the original testsclickY >= y - 10(cmp edi, ecxandjlat 0x4d90d3 and 0x4d9173), so a mission could only be picked by clicking above it.> 30and20 <), which read one position past the end of the warchest table. The original stops below 30 and below 20 (cmp edx, 0x1eat 0x4d9131,cmp edx, 0x14at 0x4d9180).Header change (a commit of its own)
MenuModalComposition::sliderMinimumandsliderMaximumareints (cfc7e1d), notdwords.sliderMaximum - sliderMinimum > 200with a signedjle(0x4aa630, 0x4aa697 and 0x4aa7a3), and divides by 5 signed forrange * 3 / 5(0x4aa635 and 0x4aa6c4).ints the handler reads 100.0% instead of 57.1%, on main 1d819b7 and again on 3416498.setSliderParameters(0x004AA480) andsetSliderParameters2(0x004AA540). They only store to them, so they compile the same. In the full build above they read exactly as on main.sliderValuestays adword. The handler only copies it, and compiles to the same code either way.The declaration check will fail and label this PR until main has these two lines. Then I'll merge main in.
Three functions leave the drafts
General::MenuItemActionHandler_General_ToolbarButtonPressed(0x00444410) leaves Reimplement 6 UI::Helpers and UI::MenuItems functions (not yet 100%) #318.HistoricCampaignSelect::MenuItemRenderFunction_HistoricCampaignSelect_Main(0x004255D0) leaves Reimplement 7 UI::MenuItems functions (draft, below 100%) #327.CrusadeMap::MenuItemActionHandler_CrusadeMap_Main(0x004D8EC0) leaves Reimplement 24 UI::MenuItems functions from gynt's drafts (not yet 100%) #328.Each draft gets one commit that removes the
.cppand puts its status line back to main's (fb28cf0 on #318, 2da7d39 on #327, 3e3b705 on #328). None of the three drafts changes a header, and each still compiles without its function. No other open PR has any of the five.Kept as they are
setStartDateUnkcall and what follows, repeated in each trail's branchleft = x - 10andleft + 20x - 10andx + 10: 0.6075 in quick_diffquick_diff stops the original's ToolbarButtonPressed after the siege-engine case, so it reads 0.8939 for the version at 100.0% in reccmp. Its numbers above compare shapes with each other.
The two-call forms, the repeated code in CrusadeMap and ToolbarButtonPressed, and ToolbarButtonPressed's case order each have a one-line comment in the code that says why. In the OverlaySlider handler's large-range store into the 16-bit
destination2, the operands keep their(short)casts, with a comment: the original does that subtract and add in 16 bits (sub cx, axandadd cx, bxat 0x4aa716 and 0x4aa719).Cleanups from our own review
All of these compile to the same instructions as before (quick_diff's instruction hashes), and the five still read 100.0%:
(short)casts on the stores intodestination2are gone; the parameters areunusedandscrollbarEvent, as in main's other scrollbar handlers; the pointer tests read!= NULL.SetTribesPatrolButtonPressed(FALSE)/(TRUE),getWallTilesThatCanBeBuilt(..., RT_STONE), no(int)on the RNG'sshortcurrentNumber1, and the gate cases' parentheses made explicit.66 * 64pixels and66 * 64 * sizeof(ushort)bytes, and the first edition and warchest bounds arecountof(...) - 1of their position tables.button.TEXT_GAME_OPTIONS).Numbers left as numbers:
caselabels in the OverlaySlider handler (the scrollbar's event codes 1 to 7) and in SaveLoadMap's TableHeader (the table's column, 0 to 2): there is no enum for either on main.-1200months that mark a skipped mission, the258passed tosetSoundWithVariation, whose parameter is a plainintsound number on main, and the extreme trail's 19 and 20: its position table has 30 entries, of which the first 20 are missions, socountofdoesn't fit there.What some placeholders hold
INT_00eb9b48: the crusade map's highlight animation. It is set to 1, with the start time inDWORD_00ed27a8, when the map opens (CrusadeMap's Prepare on main) and when a mission is picked here. gynt's draft of the map's DoEveryFrame runs it in 40 ms steps and sets it back to 0.INT_00b95abc: the last hovered button, as in MainMenu's render (Reimplement 5 UI functions from gynt's drafts and #328 (100%) #407). Here it is the campaign button (0 to 4): the render plays the hover sound only when it changes, and puts it back to -1 when that button is no longer hovered.GameCore::field_0x30: a build-menu tab. ToolbarButtonPressed compares it withactiveMenuTab.tabTypeand copies it intobuildmenuMenuTabToSwitchTo.tabType(bothBuildingsAndStatusMenuTabTypeInt) before it switches to the build menu, and General's Unknown2 handler (0x00434260) sets it.DAT_00b96110: ToolbarButtonPressed sets it to 0 after the tutorial test, before the switch. Nothing else reimplemented uses it.Other PRs
🤖 Generated with Claude Code