Repository navigation
UI: the credits scroll's fade and the win/defeat window at 100% - #437
Open
kotijekriv wants to merge 2 commits into
Open
kotijekriv wants to merge 2 commits into
kotijekriv wants to merge 2 commits into
Conversation
CreditsScroll::MenuModalRenderFunction_CreditsScroll, rewritten from the original's listing. gynt's drafts: a4ce8c2 at 37.8% on sourcehold's reimpl/UI-MenuModals and 934219c at 40.84% ("allocator only") on his fork's reimpl/UI-MenuModals-development; the newest commit on the file, 1eaeddd, is on his fork's reimpl/UI-MenuItems-development. Our draft be9edd1 (41.0%, in the draft PR sourcehold#360) was his code, not reworked. The drafts had the decompiler's text: 21 counters in locals, each stepped by hand, and all of it twice. The listing shows what they are. The scroll fades to black towards its top and bottom edge over 30 rows of four pixels, each row over its 20 leftmost columns, and the blend of column c in row r is (r - 30) * (c + 1) / 20 + 32. Written that way, with the row as the only variable, the compiler makes the same counters by itself, down to the one it does not make: column 3's product 4 * (r - 30) comes from the row's y, which also steps by four (mov edx, [esp + 0x60]; lea ecx, [edx + esi] at 0x004AACAA). Three things the match needs: - Each column is its own call. As a loop over the columns the compiler keeps the loop (102 instructions against 709), so the 20 calls are written out. - The first column is 32 - (30 - r) / 20, not (r - 30) / 20 + 32. The original keeps 30 - r as a counter of its own for it (0x004AAC27, used at 0x004AAC38) and leaves the loop by the second column's counter (0x004AAFD5). With the first column in the others' form the compiler has no such counter and ends the loop by counting down (700 instructions). - One row variable for both loops. The original has both loops' row counter in [esp + 0x10]; with a counter of its own in each loop, the second loop's 20 counters land one slot off (reccmp 91.4%). Measured: quick_diff 1.0000 with 709 instructions on both sides, also with the stack slots kept; reccmp 100.0% (normalized 100.0%) alone, data resolvers and its own resolver on. Not run in game. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
DisplayElements::RenderInGameWinDefeatWindowDisplayElement, rewritten from the original's listing. gynt's drafts are on his fork's reimpl/UI-DisplayElements-pr-development: 3c85538 at 65.16%, 7648a6d at 76.62% and 7a4656b at 80.97%, which the branch's status line records as 81.0% (158fe8d at 87.80% was reverted in 94926b6; ff0d33f is the newest commit on the file there). Our draft d0fbcd5 (82.0%, in the draft PR sourcehold#360) was his code. The drafts walked three pointers through the players' arrays and kept the window's y in a second variable, as the decompiler shows it. Written with the arrays indexed by the player and the y parameter itself counted on, the compiler makes the same three pointers, and four differences go: - The window's y. posY += -28 - height / 2, with posY used from there on, gives the original's mov edx, -28; sub edx, eax; add esi, edx (0x004AFC25). With the sum in a variable of its own the compiler folded it into two subtractions, in every form. - The loop over the players ends at the array's length, player < countof(playerIsAlive), which is 9 (the jl at 0x004AFD7D, behind a compare with the array's end, 0x0117EF52). - The count of the players alive is a loop as well; the compiler unrolls it into the original's eight tests. - "Wins" behind each name: its colour and its x are locals in front of the call, the colour first. The original loads the colour and works out x where the call's pushes begin (0x004AFCE1 to 0x004AFCF8). Written in the call, x was finished behind the pushes and in another register. The security cookie: the original has one, and an 8-byte frame (the cookie and the players' pointer), so its source had a buffer whose address was taken. Nothing reads it, so `char unused[8]; char* unusedPointer = unused;` is a guess at its type and length. An unused array alone gets no cookie. gynt's 7a4656b found the cookie first, with a ushort[3] whose address went into the loop's pointer; our draft d0fbcd5 had made that a short[3]. Measured: quick_diff 0.9893 with 187 instructions on both sides (what differs is how the two listings print the cookie's address and an import call); reccmp 100.0% (normalized 100.0%) alone, data resolvers and its own resolver on. Not run in game. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 19, 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.
Two render functions at 100%, moved out of our open draft #360, both from gynt's drafts. No header changes.
MenuModals::CreditsScroll::MenuModalRenderFunction_CreditsScrollDisplayElements::RenderInGameWinDefeatWindowDisplayElementMeasured.
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/). Both functions read 100.0 raw and normalised, with no diff entry.Global::Init::Constructor_MenuModal_CreditsScroll(0x0059BDA0, 93.8 / 92.3 before) andGlobal::Init::CreateInGameWinDefeatWindowDisplayElement(0x0059C540, 88.9 / 88.9 before).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. UI: three more functions at 100%: the building menu's DoInitial, the credits' prepare and activateModalDialog2 #435's text describes the same thing for its build.openshc-pr-checkgives 0 ERROR and 5 CHECK (below).openshc-pr-fixfinds nothing to change.What got them to 100%
Both drafts still had the decompiler's text: counters stepped by hand and pointers walking arrays. Tuning that text had stopped paying. Both functions are now written from the original's listing, with the loop variable as the only variable, and the compiler makes the counters and the pointers itself.
The credits scroll's fade (0x004AAB50)
The scroll fades to black towards its top and its bottom edge, over 30 rows of four pixels, and each row over its 20 leftmost columns. The draft had 21 counters in locals for that, each stepped by hand, and all of it twice.
(r - 30) * (c + 1) / 20 + 32. Written that way, the compiler makes the same counters, down to the one it does not make: column 3's product4 * (r - 30)comes from the row's y, which also steps by four (mov edx, [esp + 0x60]; lea ecx, [edx + esi]at 0x004AACAA).32 - (30 - r) / 20. The original keeps30 - ras a counter of its own for it (0x004AAC27, used at 0x004AAC38) and leaves the loop by the second column's counter (0x004AAFD5). With the first column in the others' form, the compiler has no such counter and ends the loop by counting down (700 instructions).[esp + 0x10]. With a counter of its own in each loop, the second loop's 20 counters land one slot off (91.4%).The win/defeat window (0x004AFB30)
The draft walked three pointers through the players' arrays and kept the window's y in a second variable.
posY += -28 - height / 2, withposYused from there on, gives the original'smov edx, -28; sub edx, eax; add esi, edx(0x004AFC25). With the sum in a variable of its own the compiler folded it into two subtractions, in every form tried.countof(playerIsAlive), which is 9 (thejlat 0x004AFD7D follows a compare with the array's end, 0x0117EF52).constlocals in front of the call, the colour first. The original loads the colour and works out x where the call's pushes begin (0x004AFCE1 to 0x004AFCF8). Written in the call, x was finished behind the pushes and in another register.char unused[8]; char* unusedPointer = unused;is a guess at its type and length, and the comment in the file says so. An unused array alone gets no cookie. gynt's 7a4656b found the cookie first, with aushort[3]whose address went into the loop's pointer; our draft d0fbcd5 had made that ashort[3].No behaviour differs from the drafts, as far as we can tell: they computed the same values the decompiler's way.
The checker's 5 CHECKs
All five are in the credits scroll's file.
int row;declared without a value, and the twoforloops without their counter in the header (3 CHECKs)int rowin eachforthe second loop's counters land one slot off and the match drops to 91.4%. The comment above the declaration says so🤖 Generated with Claude Code