Repository navigation
UI: the allies screen's render function at 100% - #447
Open
kotijekriv wants to merge 1 commit into
Open
kotijekriv wants to merge 1 commit into
kotijekriv wants to merge 1 commit into
Conversation
Allies::MenuItemRenderFunction_Allies_Main, rewritten from the original's listing. gynt's draft: 1f983fe at 52.27% ("reordered stores") on his fork's reimpl/UI-MenuItems-development, whose status line records 52.3% (the newest commit on the file there is dd1a7c4, a style commit); his reimpl/UI-MenuItems has 8533b17 at 47.09%, status line 47.1% ("Style pass, asm differs"). Our draft (89a680f, then f8721e5 and 07a33e2; 52.8% in the draft PR sourcehold#328) was his code with a mechanical pass. The function draws the allies screen, one menu item per call, chosen by the item's number: 1 to 6 an ally's portrait with its signs (the resource it asks for, help needed, its orders); 10 the panel, its frame tile by tile and the selected ally's name, request, orders and help text; 200 the help line, whose text items 20 to 22 choose while the mouse is on them; the items above 19 and -1 a plain button; 110 and 111 the selected ally's button, shown while it needs help or has asked you to attack. Without allies every item but -1 is off. Behaviour fixes against the draft, each in the draft's own listing. Most of its ranges were separate ifs without a return, so: - Without allies it set the two flags and went on to draw the item. The original returns (0x004AC7D6). - 110 and 111 ran on after their button into the code for 200 and the rest, which drew the plain button too. The original leaves through the first (a tail jump at 0x004AD0FC). - 200 ran on after the help line, cleared ButtonUnknownZero and drew the plain button. The original returns after the text (0x004AC841). - 7 to 19 other than 10, and 22 while the mouse is on it, drew the panel. The original returns for them (jne at 0x004ACB92 to the return at 0x004ACB89, 0x004AD0AA). - A portrait item past the number of allies cleared ButtonUnknownZero and went on with that index. The original returns (jge at 0x004AC86C). - An unselected ally's portrait returned after its picture when it showed lord icon 0 or 1 or an AI lord, so the signs on it were not drawn. The original goes on to the signs (0x004ACA42 falls into 0x004ACA47). - The selected ally's portrait returned after its frame: no signs either (0x004ACA77 falls into 0x004ACA7C). - The ally's request that you attack: with a player as the target the draft drew the face and its frame, then the target's picture a second time and an AI lord's picture over them. The original returns after the frame (0x004AD012). What decided the match. The counts are differing lines of our own exact listing compare against the original's 702 instructions (operands with the original's addresses and every jump's landing), each with that one thing changed from the final code, which has 0: - The parameter is reused: the portrait steps it to the ally's index, copies that, and then stores the ally's player ID in it; the panel stores the selected ally's player ID in it too. A variable of its own for the player: 281; for the index: 169; for the panel's player: 13. The code reuses `button` for both, as AlliesOrder_Main on main does. - The resource asked for is counted from wood on in a statement of its own (`resource -= RT_WOOD`), in both places. Inside the test: 155 and 123. - The code for the items above 19 stands after the portraits' and the panel's (before them: 62), and the panel's after the portraits' (before them: 577). - The portrait's blend (8 for the unselected ones) by if. As a conditional expression: 88. - An unselected portrait's picture with a call in each arm. Its number in a local and one call: 80. - Smaller: the panel's resource test `< 0` with the "no request" text first (the other way: 8), the player's ID read once into a local (twice: 12), the target picture's x before its y (20), new variables for the last picture's position rather than changing x and y (4), the frame's row number with no first value (7 as its first value: 36), the target's picture called in each arm of its test, in both places (called once before the test: 73 and 41). These gave the same code, and the plainer form stands: 110 and 111 first with a return (the original has their code at the end), their flag by an early return or by if / else, the AI lord's text number's operands in either order, the frame's row number by if / else or by conditional expressions, the range test 0 to 19 as two compares or as one unsigned compare, the step to the index as `button--` or `-= 1`, the frame's middle columns skipped by an else-if or by a nested if, `button` written directly or named through a reference, and 20 to 22 as an else-if chain or as ifs that each return. The text numbers carry their texts from the game's cr.tex (TEXT_ALLIES) as comments. Neither they nor the other comments change the listing: this code compiles to the same instructions, line for line, as the code the narrow build with the callees and the full build measured (0aae52a5f's). Measured in a narrow build on main 3458fea of that code and the eight finished functions it calls, struct resolvers and their resolvers on: renderGM (0x00455300), drawBitmapFace (0x0044CD40), renderGMWithBlending (0x00455390), renderGMWithAlphaMask (0x004557B0), renderFacesSmallUnk (0x0044CE00), isAIPlayer (0x004010B0), RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurrentSurfaceUnk (0x004640D0) and RenderButtonImageWithBlending (0x004641A0), which 110 and 111 tail-call. reccmp 100.0, normalized 100.0, no diff line. The two of them on main's /GL list read lower in that build (RenderCurrentNotActiveButton... 54.8, RenderButtonImageWithBlending 58.3), as their own callees are not in it. With only this file, as committed, in the list, the callees' resolvers off, the function reads 100.0 (100.0 normalized) too. Not run in game. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 21, 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.
One function at 100%, moved out of our open draft #328, from gynt's draft. No header changes. Behaviour fixes against the draft (below).
MenuItems::Allies::MenuItemRenderFunction_Allies_MainOur draft was gynt's code with a mechanical pass; gynt's best, 52.3%, is 1f983fe on his fork's reimpl/UI-MenuItems-development.
Measured
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 (theMapEditorLandscaping_GeneralButtonshandler) is left out and its resolver stays off, as in main's baseline.renderGM(0x00455300),drawBitmapFace(0x0044CD40),renderGMWithBlending(0x00455390),renderGMWithAlphaMask(0x004557B0),renderFacesSmallUnk(0x0044CE00),isAIPlayer(0x004010B0),RenderCurrentNotActiveButtonWithPossibleAlphaTexOnCurrentSurfaceUnk(0x004640D0) andRenderButtonImageWithBlending(0x004641A0), which 110 and 111 tail-call. The function reads 100.0 raw and normalised, with no diff line. The first six stay at 100.0./GLlist, and their own callees are not in the build. In the full build both read 100.0, as on main.tools/). The new function reads 100.0 raw and normalised there too, with no diff entry.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 and UI: the credits scroll's fade and the win/defeat window at 100% #437 describe the same two readings.The behaviour fixes
The function draws the allies screen, one menu item per call: 1 to 6 an ally's portrait with its signs, 10 the panel with the selected ally's state, 200 the help line, 110 and 111 the selected ally's button, the rest plain buttons. Most of the draft's ranges had no
return, so items ran on into the code for others:DAT_ButtonUnknownZeroand drew the plain button. The original returns after the text (0x004AC841).jneat 0x004ACB92 to the return at 0x004ACB89, and 0x004AD0AA).DAT_ButtonUnknownZeroand went on with that index. The original returns (jgeat 0x004AC86C).Each shows in the draft's own listing. Read block by block against the new code, nothing else differs.
What got it to 100%
The function is written from the original's listing now. Our draft read 704 instructions against the original's 702, with 624 lines differing in our compare. What decided the match, each measured with one thing changed (differing lines of that compare; the final code has 0):
buttonfor both, as AlliesOrder_Main on main does. A variable of its own for the player: 281; for the index: 169; for the panel's player: 13.resource -= RT_WOOD), in both places. Inside the test: 155 and 123.if. As a conditional expression: 88.< 0with the "no request" text first (the other way: 8), the player's ID read once into a local (twice: 12), the target picture's x before its y (20), new variables for the last picture's position rather than changing x and y (4), the frame's row number with no first value (7 as its first value: 36), the target's picture called in each arm of its test, in both places where a target is drawn (called once before the test: 73 and 41).These gave the same code, and we took the plainer form: 110 and 111 first with a
return(the original has their code at the end), their flag by an earlyreturnor byif/else, the AI lord's text number's operands in either order, the frame's row number byif/elseor by conditional expressions (main's style bot flags those), the range 0 to 19 as two compares or as one unsigned compare, the step to the index asbutton--or-= 1, the frame's middle columns skipped by an else-if or by a nestedif,buttonwritten directly or named through a reference, and 20 to 22 as an else-if chain or asifs that each return.Things in the file that look odd and are the original's
buttonholds the ally's index and then its player ID. The original keeps both in the parameter's register and stack slot (see above), and the code reusesbuttonfor them, as AlliesOrder_Main on main does.index == DAT_LastTeamMemberIndex): for the plain portrait, for its frame, and for the signs' blend. The original tests it three times too (0x004AC88E, 0x004ACA47, 0x004ACA7E).RT_PITCHbecomesRT_PARTIALPITCH) before the resource's picture and name are chosen, and the numbers count fromRT_WOOD.continuefor the others); the inside is the blended black box drawn after the frame.Header findings (nothing changed here)
DAT_00df42b0is the help sign's blink frame:MenuModalRenderFunction_Alliessteps it between 0 and 1, and this function draws picture 578 or 579 with it.DAT_00df51f4says the help line is shown andDAT_00df51f0is its text number inTEXT_ALLIES(5, 6 or 7: "Set Orders", "Send Goods", "Request Goods"): items 20 to 22 set both while the mouse is on them, item 1 clears the first. Every reference to either in the whole image is in this function (one read and four stores each), andDAT_00df51f4only ever holds 0 or 1, so it can be proposed as aBOOLEnum.PlayerData::isNotNervousByEnemyTroopValue: when it is set, the panel writes text 4 ofTEXT_ALLIES, "Help Needed!" in the game'scr.tex, and the portrait gets the help sign. A lead: the name may say the opposite of what the field means.PlayerData's request fields:requestedGoodsArray1Unk/2Unk(own player's, by the ally's ID): the resource the ally asks for and its amount;requestStateUnk: 0 none, 1 attack, 2 defend;playerID_askerUnk(own player's): the ally that asked you to attack.The checker's 11 CHECKs
DAT_00df51f4(5),DAT_00df51f0(4),DAT_00df42b0(1)int row;with no first value🤖 Generated with Claude Code