Repository navigation
UI: three more functions at 100%: the building menu's DoInitial, the credits' prepare and activateModalDialog2 - #435
Open
kotijekriv wants to merge 3 commits into
Open
kotijekriv wants to merge 3 commits into
kotijekriv wants to merge 3 commits into
Conversation
BuildingAndStatusMenu::MenuView_BuildingAndStatusMenu_DoInitial, from gynt's draft on his fork's reimpl/UI-MenuViews-development (his newest scored commit on the file is 24a37e8 at 96.23%; the newest commit on the file, e9bc49c, is on his reimpl/UI-MenuItems-development), through our draft bef74ae (96.3%, in the draft PR sourcehold#356), which restored the y store at 640x480. Two differences were left, and both come from one thing: a store that both arms of an if / else share was written once behind the arms. The compiler merges the arms' identical ends, so the instructions come out the same either way, but what it decides before that merge does not: - DAT_MenuHandlerState::instance.y at the function's start. Written in each arm, ebp is saved behind the merged store and the load of the tab type (push ebp at 0x004398FF), as in the original. Written once behind the arms, ebp is saved in front of the store. - drawBufferChoiceValue = RT_MAP_GAME at the end of the 1024x768 and the 1024x600 blocks. The function stores 99 sixteen times, so the compiler holds 99 in ecx (lea ecx, [ebx + 99] at 0x00439986). The original uses that register only up to the first call and stores the immediate in every later block. Written once behind the arms, our compiler loaded 99 into ecx again at each block's end (13 times). Written in each arm of those two blocks, it does not. Measured: quick_diff 1.0000 with 1069 instructions on both sides; reccmp 100.0% (normalized 100.0%) alone, data resolvers and its own resolver on. Not run in game. Tried on the way, all without effect on the 99: where the 99 stores sit in the first two blocks, a local for the 99, the second store reading the index back, and the four callees in the same translation unit (quick_diff 0.7860). The text against the draft: pendingMenuRedraw is a BOOLEnum, so it is tested by truthiness and stored FALSE; in the first two blocks, where each arm is now complete by itself, leftGfx is declared in the arm with its value. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Credits::MenuView_Credits_Prepare, from gynt's draft on his fork's reimpl/UI-MenuViews-development (his scored commit on the file is 458bcd5 at 80.00%, and the branch's status line records 82.1% since 71e725a; the newest commit on the file, 0295332, is on his reimpl/UI-MenuItems-development), through our draft 3480be0 (82.1%, his code in main's style, in the draft PR sourcehold#356). One change: each arm of the test empties the list of loaded pictures itself (totalLoadedGfx = 0), where the draft had one store in front of the test. The original keeps 0 in edi for the whole function (xor edi, edi at 0x004261E2, six uses) and saves esi and edi at the start. With one store our compiler used the immediate 0 everywhere and saved esi only in front of its first use. With the store in each arm it keeps 0 in edi, and the two stores still come out as one, between the compare and the jump (0x004261EA), where the single store stood too. Presumably the compiler counts the uses of 0 before it merges the two stores. Measured: reccmp 100.0% (normalized 100.0%) alone, data resolvers and its own resolver on. Not run in game. The text against the draft: the string pointers have their texts as comments. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
MenuModalComposition::activateModalDialog2, from gynt's drafts: 06829d8 at 53.6% on sourcehold's reimpl/UI-Core; b1c48ad at 50.64% and 10280b1, whose status line records 53.7%, on his fork's reimpl/UI-Core-development; the newest commit on the file, 1eaeddd, is on his reimpl/UI-MenuItems-development. Through our draft 950e83e (82.7%, in the draft PR sourcehold#313). What was left: our compiler kept a zero in esi for the whole function (xor esi, esi at the start and again behind the copy of the modal), where the original compares with and stores the immediate 0 and saves esi only around that copy. The last block decided it. It had the result of getAreWeInAInGameMenu and the dialog's x and y in locals in front of the test. Now the call is tested directly and each arm has its own x and y. The original loads y and x between the call's test and the jump (0x004B29F2 to 0x004B29FA), which is where the compiler puts loads that both arms start with, and tests the result with test eax, eax. With that form no zero register is left. Checked against the binary: the function returns when the next stored AI lord message starts playing (jne at 0x004B2854), and in game it blits only the map surface's rectangle (the two blits are the arms of one test, each followed by its own end, 0x004B2A2A and 0x004B2A4D). All four of gynt's versions of the file (06829d8, 8ca7861, 10280b1, 1eaeddd) go on from the in-game blit to the menu surface's blit, and 10280b1 and 1eaeddd have an empty if where the first return is. Our draft 950e83e had both right already. Measured: quick_diff 0.9895 with 191 instructions on both sides (what differs is how the two listings print a rep movsd and an import call); reccmp 100.0% (normalized 100.0%) alone, data resolvers and its own resolver on. Not run in game. The text against the draft: the unused BOOLEnum using and include are gone; the border style masks are written in decimal, (32 | 512) for the two tiled styles and 1024, as the bits have no names yet; the imported note on the copy is gone, as in main's activateModalDialog. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 20, 2026
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.
Three UI functions at 100%, moved out of our open drafts #356 (two) and #313 (one), all from gynt's drafts. No header changes.
BuildingAndStatusMenu::MenuView_BuildingAndStatusMenu_DoInitialCredits::MenuView_Credits_PrepareMenuModalComposition::activateModalDialog2Measured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie. The struct resolvers and the function resolvers are enabled locally (not committed); in the full build 0x004314E0 (MapEditorLandscaping_GeneralButtonshandler) is left out and its resolver stays off, as in main's baseline.tools/). All three functions read 100.0 raw and normalised, with no diff entry.Constructor_MenuView_BuildingAndStatusMenu(0x0059A430) from 70.0 to 80.0 andConstructor_MenuView_Credits(0x0059A7F0) from 80.0 to 90.0. Each pushes the address of one of the functions here, which now resolves to the reimplementation.Menu::handleMenuItems(0x004F6280) reads 97.9 (91.4 normalised) andMenu::Constructor_Menu(0x004F4100) reads 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, five compares in all. In this build's layout a symbol of our DLL lies at exactly the address 0x11000000, so reccmp prints the constant as that symbol's name on our side. The instructions are the same on both sides. In an all-on build with only the first two functions, where no symbol lies at that address, both read 100.0.openshc-pr-checkgives 0 ERROR and 18 CHECK (below).openshc-pr-fixfinds nothing to change.What got them to 100%
All three had the same kind of gap: the instructions were right, but a constant sat in a register on one side and was an immediate on the other. In all three the answer was where a statement that both arms of an
if/elseshare is written.MSVC merges identical code at the start or the end of two arms into one copy, so the instructions come out the same whether the source has the statement once outside the arms or once in each arm. What differs is what the compiler decides before that merge: how often a constant is used, which decides whether it gets a register, and where the registers are saved.
MenuView_BuildingAndStatusMenu_DoInitial
ecx(lea ecx, [ebx + 99]at 0x00439986). The original uses that register only up to the first call and stores the immediate in every later block. Ours loaded 99 intoecxagain at the end of each block, 13 times.drawBufferChoiceValue = RT_MAP_GAME) stood once behind the two arms. Written in each arm, the 13 reloads are gone.ebp.DAT_MenuHandlerState::instance.ystood once behind the firstif/else. Written in each arm,ebpis saved behind the merged store and the load of the tab type (0x004398FF), as in the original, and not in front of the store.MenuView_Credits_Prepare
edifor the whole function (xor edi, ediat 0x004261E2, six uses) and savesesiandediat the start. Ours used the immediate 0 everywhere.totalLoadedGfx = 0stood once in front of the test. Written in each arm it is one more use of 0, and the compiler keeps 0 inedi. The two stores still come out as one, between the compare and the jump (0x004261EA).activateModalDialog2
esifor the whole function, where the original compares with and stores the immediate 0 and savesesionly around the copy of the modal.getAreWeInAInGameMenuand the dialog's x and y in locals in front of the test. Now the call is tested directly and each arm has its own x and y. The original loads y and x between the call's test and the jump (0x004B29F2 to 0x004B29FA), where the compiler puts loads that both arms start with.This may help with other functions whose only gap is a constant's register or the place of a
push.Behaviour fixed compared with gynt's drafts
These fixes were made in the draft PRs and checked against the binary. They are listed here because the drafts' texts no longer carry these functions.
DAT_MenuHandlerState::instance.y. The original stores it for both branches (the shared store at 0x004398F5). His e9bc49c sets it in front of the test, so it does not have this.jneat 0x004B2854 to the function's end). Two of gynt's versions, 10280b1 and 1eaeddd, have an emptyifwhere that return is; 06829d8 and 8ca7861 have the return.Style changes against the drafts
(32 | 512)for the two tiled styles and1024, because the bits have no names yet. Main'sactivateModalDialogstill has them as0x220and0x400. The imported note on the copy of the modal is gone, as in main'sactivateModalDialog.pendingMenuRedrawis aBOOLEnum, so it is tested by truthiness and storedFALSE. In the first two blocksleftGfxis declared in each arm with its value.The checker's 18 CHECKs
int leftGfx;declared without a value, in the twelve later resolution blocks of DoInitialINT_00b95954INT_00b960d0,INT_00b960d4LoadTGX_shc_back, one after itDAT_00b95b3c,DAT_00b95b70,DAT_00b9610c🤖 Generated with Claude Code