Repository navigation
UI: more functions at 100% from our drafts #313, #327 and #328, with two header changes - #417
kotijekriv wants to merge 8 commits into
Conversation
…llocation only (sourcehold#414) WindowAndDirectDraw::reinitWindow, moved out of our draft sourcehold#313 with one comment line added. The draft came from gynt's version on his fork's reimpl/UI-Rendering-development (3768087 at 56.90%, a8b64eb at 56.9%, and 63cc49f of 2026-10-25, his newest commit on the file) and reached 80.4% in 685b039. Register allocation only, per sourcehold#414: reccmp reads 80.4 (normalized 80.5), and the 56 instructions of both sides are the same instructions in the same order with the same memory operands. What differs is which of eax, ecx and edx holds each reload of windowHandle (and the address of the second corner) before it is pushed: eleven lines. if/else, nested and early-return shapes of the two branches all compile to the same code. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
VideoOptions::MenuItemActionHandler_VideoOptions_Main, rewritten from the listing on top of gynt's draft: aae2c08 (57.14%, his fork's development), cd76e7f (57.7%, upstream's reimpl/UI-MenuItems), 8725ec5 (61.5%, his fork's reimpl/UI-MenuItems-development) and 8ca7861 of 2026-10-27, his newest commit on the file (his fork's reimpl/Wilps-2026-10-18: the same code with newer field names). Our mechanical pass b2d7696 in draft sourcehold#328 read 61.5% as well. What the match needed: - case 11 keeps the resolution in a local through the loop and stores it once after it; the draft worked on the field, which stores it in every round; - case 18 reads the new resolution once and calls setExtraActiveModalDialog in every arm of the chain, in the original's order of arms. The draft set two position locals and called once, which shares the pushes. Two neighbouring arms with the same position joined by || read 0.8055 in quick_diff, so each resolution has its arm; - popModalDialog is called at the end of case 18 and in case 17: the compiler shares the one tail jump; - no goto and no position locals are left, and the loop is a for with its exit test in the header (a BOOLEnum that stands in for the original's do-while): the compiler puts the test at the end of the round, where the original has it. Names instead of numbers: CT_WINDOWS_LIKE_CURSOR, CT_ANI_CURSOR and SS_NORMAL. The parameter is button, as in most handlers on main; the buttons have no enum, so each case says what it does. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
SiegeAttackingForceAndStartGoods::MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_Main, rewritten from the listing on top of gynt's draft: ce671d7 and 37bf917 (40.1%, upstream's reimpl/UI-MenuItems), f0479fc, b83dff2 and d7600c8 (44.39% to 52.82%, his fork's reimpl/UI-MenuItems), then 25b481a (54.75%), 9743554 (52.49%) and 6aa5d32 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our mechanical pass 7b18743 and 53bea5f in draft sourcehold#328 read 53.8%. What the match needed: - one if / else-if chain with the draw buffer set back once, at the end. The draft returned from every arm, each with its own store; written once, the compiler copies the store into the arms as the original has it, and esi is pushed before the first branch; - renderGM for a unit's picture is written in both arms that draw one (rows 20 to 29 and 40 to 49). Shared after the chain it reads 0.7479 in quick_diff; - the row is -1 - button (or esi, -1 / sub esi, eax), not -button - 1; - every amount is drawn by a call in each arm of the colour test. One call with the colour as a ?: reads 0.9320 (neg / sbb / and / add for the colour), with a colour local 0.9608. Behaviour: none of the draft's forms differed in what they draw. Readability, all measured equal: rows 20 to 29 read SEC_SiegeInformation[index - 20] and rows 40 to 49 SEC_Section1067.siegeEngineCounts[index - 40] (the draft indexed SEC_StartingResources[index + 5] for both, which is the same address); the picture's height comes from DAT_GMImageHeaders as in TriggerInvasion_Main, not from a cast on PTR_ARRAY_Unknown_UnitGMHeights; index >= 40 && index < 50 for the unsigned range test. reccmp: 99.2% raw. The two lines that differ are the picture table's address 0x00B98782 (imh[first + picture - 1] .height), 14 bytes before DAT_GMImageHeaders: reccmp prints it as a number on the original's side and, on ours, as an offset from whichever variable of our DLL lies there (Instance<int,15544744>+2, DAT_ButtonX's instance). Only the name of the resolved address differs, which the project records as 100% (TriggerInvasion_Main in sourcehold#349 has the same two lines). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The amount the send / request goods dialog works with is compared as a signed value wherever it is read in MenuItemActionHandler_AlliesSendAndRequestGoods_Main (0x004B14C0): - 0x004B15E6: mov ecx, [0x00DF428C] / test ecx, ecx / jle: no amount chosen. An unsigned test would be je; - 0x004B16ED: mov ecx, [0x00DF428C] / cmp eax, ecx / jge against the room getResourceSpace returned; - 0x004B183A: cmp [the player's gold], esi / jge, and 0x004B1863 jl, 0x004B1870 cmp eax, esi / jge, with the amount in esi. As undefined4 (unsigned) each of these needs an (int) cast. Its only user on main, MenuItemActionHandler_Allies_Main (0x004B12D0), assigns to it and stays at 100.0% with the change. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
AlliesSendAndRequestGoods::MenuItemActionHandler_AlliesSendAndRequestGoods_Main, rewritten from the listing on top of gynt's draft: c7cfed8 and 8ee5623 (32.9%, upstream's reimpl/UI-MenuItems), cbc63a3, 17cbc68 and df54f4e (56.22% to 57.83%, his fork's reimpl/UI-MenuItems), 8725ec5 (58.2%) and 0e551f6 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our 1f29978 in draft sourcehold#328 read 60.5%. Behaviour, where the draft differed from the original: - buttons 21 and 50 to 53 return after their one store, and any other button but 100 returns after opening the allies dialog. The draft went on from each of them into button 100's path; - button 102 (cancel) queues its command only when the send dialog is open and DAT_00df4284 is set. The draft queued it always; - when a request fails for want of a building or of room, the original plays at most the one warning that fits the fail state and closes the dialog. The draft played the third warning in every case and, after a missing building, went on to the room test; - a request that is accepted queues the command and closes the dialog; the draft also played the "goods not sent" clip after it; - button 100 does nothing after the request path. The draft fell into the send path. What the match needed: - button 100 holds the whole confirm path and the other buttons' activateModalDialog comes last, which puts the return block where the original has it (with the test turned round it read 0.9305 in quick_diff); - the request path is one if / else-if chain that closes the dialog once at its end, with the five command stores and queueCommand written in both arms that send. The "not enough" arm comes first in the second (accepted first reads 0.9732); - good <= -1, as the original compares with -1 (good < 0 reads 0.9923); - the send path has one local for the resource, one for the type it is stored as, and one for the amount. Uses the header commit before this one (the amount is an int), so no cast on it is left. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
MenuItemActionHandler_General_EventSlider (0x004B9E50) reads the four bytes at 0xA4 as one int, the highest value of the invasion's slider: mov eax, dword ptr [0x01667EEC] at 0x004B9E86 (DAT_MapPropertiesState's invasionEventContent + 0xA4), which it then stores to *maxValue and clamps field_0xa8 with. The header had them as undefined1 padding_0xa4[4], which needs *(int*)&...padding_0xa4[0] to read. Named field_0xa4 like its neighbours field_0xa0 and field_0xa8; the struct's size and layout are unchanged, and nothing on main names the padding. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
General::MenuItemActionHandler_General_EventSlider, from gynt's draft: cbdee60 and 7c31877 (45.3%, upstream's reimpl/UI-MenuItems), d0aa6c7 and 899dcd2 (55.93% and 69.21%, his fork's reimpl/UI-MenuItems), 514b907 (83.26%) and dd1a7c4 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our 2001534 and bddd6be in draft sourcehold#327 read 88.0%. What the match needed, on top of the draft: - the two range tests against the limit compare *currentValue > limit (cmp [ecx], eax / jle); the draft had limit < *currentValue, which swaps the operands; - in the repeat slider's switch, case 7 comes before case 4, as it already did in the months slider's. That alone took it from register names only (0.9322 in quick_diff, the three small blocks of the months slider on rotated registers) to every instruction. Readability, all measured equal: the lists of cases that only break are gone from both switches on the slider; the two step cases use ++ and --, as the invasion slider's do, and no longer the limit's local; no cast on the byte fields, read or written; the parameters are slider and scrollbarEvent, as main's other slider handlers have the second; the amount sliders' cases are written as their event type plus one (the function compares the type with slider - 1). Uses the header commit before this one (the invasion's limit is an int field). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
SinglePlayerMapChoice::MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHands, rewritten from the listing on top of gynt's draft: 582f0a0 and 6918f23 (14.3%, upstream's reimpl/UI-MenuItems), 47663d0 (29.50%, his fork's development), 1ff44c3 to eaf674d (20.55% to 44.64%, his fork's reimpl/UI-MenuItems), b4b1f65 (45.29%) and dd1a7c4 of 2026-11-02, his newest commit on the file (his fork's reimpl/UI-MenuItems-development). Our dcaa477, 53bea5f and 07a33e2 in draft sourcehold#328 read 46.8%. Behaviour: unchanged. The draft cleared DAT_ButtonUnknownZero after the switch for buttons 2 and 65; here each of the two clears it itself, before its call, as the original does. The draft's gotos into a shared text call are gone. What the match needed: - every case breaks to one store of the draw buffer at the end (the compiler copies it into the arms, with pop edi before it, as the original has it); the draft stored and returned in every arm; - each text is drawn by a call of its own in each arm of the colour test, and renderBasicButton is called in each of button 74's three arms and button 77's two; - case 78 is written out with its own store and return: the original's switch has a table entry for it, though it ends in the same block as the default (with a plain break, or left to the default, the range check reads cmp eax, 178 where the original has 179); - the map-index sum in button 65 is DAT_MapSelectionScrollOffset + DAT_MapSelectionRelativeSelected: the other order loads the two fields the other way round (reccmp 99.6%; quick_diff does not see it). Readability, measured equal: X + W / 2 and X + W - 10 for the text positions. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
| @@ -0,0 +1,34 @@ | |||
| #include "../WindowAndDirectDraw.func.hpp" | |||
There was a problem hiding this comment.
Have you checked if the mistmach is related to the type declaration number by adding some dummy enums?
There was a problem hiding this comment.
Good question, I hadn't. I've checked it now: it isn't the declaration count.
I built reinitWindow on its own from this PR's commit (04856c6, both resolver sets on, sourcehold's reccmp with --ignore-security-cookie). Each build had a different number of unused enums (enum DummyEnumN { DUMMY_ENUM_N };) added after the includes. I didn't stop at 1, 2, 4 and 8 but went through every count from 0 to 63, the whole period the symbol numbers cycle through in the compiler's register hash.
- Every count reads the same: 80.4% raw, 80.5% normalised.
- The code is the same in all 64 builds: the reccmp diffs are identical apart from the source line numbers, which move with the added lines.
So the mismatch doesn't depend on the type declaration count.
What is left is register choice only. Both sides have the same 56 instructions in the same order with the same memory operands. Eleven lines differ only in which of eax, ecx and edx loads this->windowHandle before each API call: the SetFocus in the fullscreen branch, and the two ClientToScreen, the UpdateWindow and the SetFocus calls in the windowed branch, where ours is one step off. That's why it is in this PR as 100% under #414 (register allocation only). If you'd rather not count it as 100% while #414 is open, I'll take it out of this PR and put it in the draft PR with its 80.4%.
More UI functions at 100%, with two header commits. All of them come from our drafts #313, #327 and #328, which started from gynt's versions, and most were rewritten from the listing with his draft for the names. Each commit cites the drafts it builds on and credits him as co-author. reinitWindow counts as 100% under the rule gynt set in #414 (a function whose only difference is register allocation); its raw reccmp number and the evidence are below.
WindowAndDirectDraw::reinitWindowVideoOptions::MenuItemActionHandler_VideoOptions_MainSiegeAttackingForceAndStartGoods::MenuItemRenderFunction_SiegeAttackingForceAndStartGoods_MainAlliesSendAndRequestGoods::MenuItemActionHandler_AlliesSendAndRequestGoods_MainGeneral::MenuItemActionHandler_General_EventSliderSinglePlayerMapChoice::MenuItemRenderFunction_SingleplayerMapChoice_ButtonsAndHandsMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie.Allies_Main), with their function resolvers on. All read 100.0% except reinitWindow and SiegeAttackingForce, which are explained below. Main'sMenuItemActionHandler_Allies_Main(0x004B12D0), the other user of the retyped global, stays at 100.0%..cppswitched on. The five functions of the first review round read as above (SiegeAttackingForce 99.2% raw from the address name), and no function on main reads lower; the header commits moved nothing.UI::Menu::handleMenuItemsandConstructor_Menushow the known0x11000000naming artefact in the larger build only (same instructions). MapEditorLandscaping's GeneralButtons handler, which doesn't compile on main since the last sync, was left out (Reimplement 88 Map::TileMapState functions at 100% #366 changes it). After that build, the review fixes (all measured equal) and SingleplayerMapChoice's ButtonsAndHands were measured in a build of the branch's files: all 100.0%.windowHandleand onlea [esi+0xb8](the second corner) before each push: twelve lines. if/else, nested and early-return shapes all compile to the same code. The maintainers haven't settled this on Compiler randomness: adding Enums and Typedefs causes different bytecode because of different code folding #414: gynt set the rule, and TheRedDaemon wrote that he'd accept such functions for now as non-100%. If the status lines should carry the raw number (80.4%) instead, say so and we'll change them.imh[first + picture - 1].height), 14 bytes beforeDAT_GMImageHeaders. reccmp prints it as a number on the original's side and asInstance<int,15544744>+2(DAT_ButtonX + 2) on ours. That is a resolved-address name, as in main'sTriggerInvasion_Main, which has the same two lines.openshc-pr-fixfinds nothing to change, andopenshc-pr-checkgives 0 ERROR.What got them to 100%
What paid most: one if/else-if chain with a single exit, the "other buttons" call last, a block written in each arm that uses it, and the case order inside a switch.
setExtraActiveModalDialogin every arm of its chain, in the original's order, andpopModalDialogis called in cases 17 and 18, so the compiler shares one tail jump. The loop is aforwith its exit test in the header, which puts the test at the end of the round, as in the original.renderGMis written in both arms that draw a unit's picture, each amount is drawn by a call in each arm of its colour test, and the row is-1 - button.activateModalDialogcomes last, which puts the return block where the original has it. The request path is one if/else-if chain that closes the dialog once, with the command stores andqueueCommandwritten in both arms that send, the "not enough" arm first.*currentValue > limit, and in the repeat slider's switch case 7 comes before case 4, as in the months slider's. That one move took it from register names only to every instruction.Behaviour fixed compared with the drafts
DAT_00df4284is set. The draft always queued it;Header changes (a commit each)
DAT_SentOrRequestedGoodsAmountgoes fromundefined4toint(958de6cae). The handler tests it as signed wherever it reads it:test ecx, ecx / jleat 0x004B15E6 (unsigned would beje),cmp eax, ecx / jgeat 0x004B16ED,jgeat 0x004B183A,jlat 0x004B1863 andcmp eax, esi / jgeat 0x004B1870. Asundefined4each needs an(int)cast. Main'sAllies_Mainassigns to it and stays at 100.0%.undefined1 padding_0xa4[4]becomesint field_0xa4(c26ec0906). EventSlider reads it as one dword at 0x004B9E86 (mov eax, dword ptr [0x01667EEC]), the slider's highest value. Size and layout are unchanged, and nothing on main names the padding. The checker's CHECK that a field was "merged into a wider field" is a false positive here.Main's declaration check will fail on this PR and label it until gynt syncs the two changes to main. Then we merge main in, and the check passes.
Kept as they are
resource - 1andgood <= -1in the Allies handler (the original compares with -1;good < 0reads 0.9923 in quick_diff),index - 18in SiegeAttackingForce, and case 7 before case 4 in EventSlider.supportedflag stands in for a do-while: with the test in theforheader the compiler places it where the original has it.SetStorageMarketFailStategetsgoods[0]without +1, as in the original.SEC_Section1067.siegeEngineCounts[index - 40], which runs to [9] on a [6] array: rows 46 to 49 readtunnelersCountand past the struct. The binary does the same, with one base for all rows.What some placeholders hold
DAT_00df4284(0 or 1): set byAllies_Mainwhen the ally asked for a good; the handler's cancel button tells that ally.IngameInvasionEventItemContent::field_0xa4/field_0xa8: the invasion slider's maximum and its amount.MissionAestheticsDefinedData::field_0x345c: the order of the goods list (row to resource type).Proposed, not changed here
DAT_00df4284(0/1),storageMarketFailStatevalues 5 to 10 andSetStorageMarketFailState's states 3 and 4.field_0xa4(the invasion's maximum),field_0xa8(its amount) andfield_0x345c(the order of the goods list).siegeEngineCounts: a union or[7], so rows 40 to 49 don't index past the array.Leaving our drafts
reinitWindow(7d84eb5).EventSlider(d3a52aa).VideoOptions_Main, SiegeAttackingForce's render and the Allies handler (e4dd57d).Each commit removes the
.cppfiles and puts their status lines back to main's.Other PRs
🤖 Generated with Claude Code