Repository navigation
UI: the new event condition dialog's button handler at 100% - #443
Open
kotijekriv wants to merge 2 commits into
Open
kotijekriv wants to merge 2 commits into
kotijekriv wants to merge 2 commits into
Conversation
…int[32][25] MenuItemActionHandler_NewEventCondition_Main (0x004B9620) reads the option lists as dwords in rows of 25: the row is the condition's index times 25 (imul by 0x19 at 0x004B9834 and 0x004B998C), the entries are compared as dwords (cmp dword ptr [edi*4 + 0x00B3BA70], edx at 0x004B9841) and a list ends with -1 (cmp dword ptr [eax], -1 at 0x004B9880). The header had byte[32][100], the same 3,200 bytes. No .cpp on main uses the field. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…code; the folded address before MapPropertiesState is another global's on each side NewEventCondition::MenuItemActionHandler_NewEventCondition_Main, rewritten from the original's listing. gynt's draft is the file on his fork's reimpl/UI-MenuItems-development (first in 4e57118, newest commit on it 5420320); his status line has no number for it. Our draft (f5da902, then 6202bb0; 64.0% in the draft PR sourcehold#328) was his code with a mechanical pass. The function handles the buttons of the new event condition dialog: one switch over the button, dispatched through a compare tree and two pairs of tables (byte table 0x004B9AC0 with jump table 0x004B9AA8 for 19 to 209, byte table 0x004B9B8C with jump table 0x004B9B80 for 5106 to 5209). It works on the selected event's conditions: all-or-any (104), back to the event dialog (37), a condition's row (106 to 125, and 190 to 209 for conditions 20 to 39), the selected condition off (19), its value down and up (1000, 1001), its previous and next option (2000, 2001 and 2002), and a row switched off (5106 to 5125, and 5190 to 5209). The draft reached the conditions by pointer arithmetic on the event's data. The rewrite uses the fields main has for them (scenarioEvents[currentEventID].data.scenario.conditions[...], as main's MenuItemRenderFunction_NewEventCondition_Main does) and one switch. With that, all 283 instructions, every jump's landing and both jump tables are the original's. What it needed, each measured with that one thing changed (reccmp in the narrow build described below; the first four were built on an earlier form of the text with the same listing): - 2001 / 2002 keep the current option in an int local and search the option list with it. Compared from the field again: 91.2% (66.9% normalized). An option of 0 becomes RT_BREAD (10) first: the lists of the four conditions that have one hold ResourceType ids and all start with bread. - 2000's search for the list's last entry is a for loop to 100 that steps back and leaves at the -1. As a counted while loop: 85.0% (65.9%). The 100 is the original's (cmp ecx, 0x64 at 0x004B988B); it is a row's size in bytes, a row has 25 entries. - 37 leaves its search loop by break; with the dialog call and a return inside the loop: 98.0% (79.7%). - A row's enable store goes through the index just stored; through button - 106 again: 96.3% (87.2%). - The search index of 2000 and of 2001 / 2002 is declared before the test of the option kind. Declared at its search loop: 88.2% (70.8%). - The cases stand in the order of the original's code. In ascending order, as far as the two fall-throughs allow: 93.6% (81.3%). The header commit before this one gives the option lists their int[32][25] type; with byte[32][100] the dword compares need casts. One behaviour fix against the draft, with the struct resolvers on. The last case clears conditions[button - 5106].enabled. The draft, like the decompiler's text, wrote that byte through UnitsState (units[2491] plus 995, indexed by the event and the button). With the struct resolvers off that is the same byte; with them on it lies past our own copy of UnitsState, and the condition was never switched off. Recorded as 100% although reccmp shows 99.8% (95.2% normalized): one line differs, and it is the same instruction. Both compilers fold the -5106 * 4 of that last store into its address: mov byte ptr [eax*4 + K], 0 at 0x004B9A9C, where K is MapPropertiesState's instance minus 18937 on both sides (0x0164EE5F = 0x01653858 - 18937 in the original; our listing has the instance's symbol with [eax*4-18937]). K itself lies before the struct, inside UnitsState in the original's layout, and the store never touches it: with the button at 5106 or more it always lands on the condition. So reccmp cannot name K by the struct and names each side by whatever variable covers that address in that image: a plain number against MissionAestheticsDefinedData's instance + 6559 in the narrow build, UnitsState's instance + 2912039 against `cached` + 11 in a full build. The four bytes that are not the address are the same in every build (c6 04 85 .. .. .. .. 00). With MapPropertiesState's struct resolver off, so that the data is the original's by address, all eight bytes are the original's (c6 04 85 5f ee 64 01 00) and reccmp reads 100.0% (100.0% normalized). The line shows with the callees' resolvers on and off alike. Main records the same kind of difference as 100%: 0x0043C6A0 (sourcehold#304) and 0x004DAF50 (sourcehold#323), where a loop's end address resolves to the next global's symbol. Measured in a narrow build on main 3458fea of this file and the four finished functions it refers to, their resolvers on: activateModalDialog (0x004A9ED0), setExtraActiveModalDialog (0x004AA0A0), setSliderParameters2 (0x004AA540) and CaptureCurrentTimeToUnknownTime01 (0x004B9610), whose address it pushes. All four stay at 100.0. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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. One header change:
MissionAestheticsDefinedData::EventConditionOptionValuesbecomesint[32][25](first commit). reccmp shows 99.8% for it, and the code is the original's: the one differing line is the same instruction with its address named differently on the two sides (next section). One behaviour fix against the draft, with the struct resolvers on (below).MenuItems::NewEventCondition::MenuItemActionHandler_NewEventCondition_MainOur draft was gynt's code with a mechanical pass; his file is on his fork's reimpl/UI-MenuItems-development, and his status line has no number for it.
Why reccmp reads 99.8%
conditions[button - 5106].enabled. Both compilers fold the-5106 * 4into the address:mov byte ptr [eax*4 + K], 0at 0x004B9A9C, whereKisMapPropertiesState's instance minus 18,937. In the original that is 0x0164EE5F (the instance is at 0x01653858); our compiler's listing has the instance's symbol with[eax*4-18937].Klies before the struct, so reccmp cannot name it by the struct. In the original's layout it is insideUnitsState, which is where the decompiler's text put the store. The store never touchesKitself: with the button at 5106 or more it always lands on the condition. reccmp names each side by whatever variable coversKin that image. In the narrow build that is a plain number againstMissionAestheticsDefinedData::instance+6559; in the full build it isUnitsState::instance+2912039againstcached+11.c6 04 85 … 00). WithMapPropertiesState's struct resolver off, so that the data is the original's by address, all eight bytes are the original's (c6 04 85 5f ee 64 01 00), and reccmp reads 100.0% raw and normalised.Main records the same kind of difference as 100%: 0x0043C6A0 (#304) and 0x004DAF50 (#323), where a loop's end address resolves to the next global's symbol. No source form changes the line, because the original has the same fold.
The behaviour fix
Cases 5106 to 5125 and 5190 to 5209 clear
conditions[button - 5106].enabled. The draft, like the decompiler's text, wrote that byte throughDAT_UnitsState(units[2491]plus 995, indexed by the event and the button). With the struct resolvers off that is the same byte. With them on it lies past our own copy ofUnitsState, so the condition was never switched off. We found no other difference in behaviour from the draft.The header change
Game/MissionAestheticsDefinedData.hpp:EventConditionOptionValueswasbyte[32][100]and isint[32][25], the same 3,200 bytes. The function reads the option lists as dwords in rows of 25:imulby 0x19 at 0x004B9834 and 0x004B998C);cmp dword ptr [edi*4 + 0x00B3BA70], edxat 0x004B9841);cmp dword ptr [eax], -1at 0x004B9880).No .cpp on main uses the field, and in the full build no function on main moves. With the old type every read needs a cast.
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).activateModalDialog(0x004A9ED0),setExtraActiveModalDialog(0x004AA0A0),setSliderParameters2(0x004AA540) andCaptureCurrentTimeToUnknownTime01(0x004B9610), whose address it pushes. The function reads 99.8 (95.2 normalised), the one line above. The four stay at 100.0 raw and normalised.MapPropertiesState's struct resolver off: 100.0 raw and normalised.tools/). The new function reads 99.8 (95.2) there too, the same one line.whileloops becameforloops, a local was renamed, a 10 becameRT_BREAD, and comments. Each gives the same listing.What got it there
The function handles the buttons of the dialog that sets a scenario event's conditions: all or any of them (104), back to the event's dialog (37), a condition's row on (106 to 125, 190 to 209) and off (5106 to 5125, 5190 to 5209), the selected condition off (19), its value (1000, 1001) and its option (2000, 2001, 2002).
The drafts reached the conditions by pointer arithmetic on the event's data. The function is written from the original's listing now, with the fields main has for the conditions (
scenarioEvents[currentEventID].data.scenario.conditions[…], as main'sMenuItemRenderFunction_NewEventCondition_Maindoes) and oneswitch. What decided the match, each measured with one thing changed (the first four on an earlier form of the text with the same listing):intlocal and search the option list with it. Compared from the field again: 91.2% (66.9% normalised).forloop to 100 that steps back and leaves at the -1. As a countedwhileloop: 85.0% (65.9%).break. With the dialog call and areturninside the loop: 98.0% (79.7%).button - 106again: 96.3% (87.2%).Two choices gave the same listing, and we took the plainer form:
forfor the two option searches, andSECI_AUTO_STOPandcountoffor the numbers 0 and 40.Things in the file that look odd and are the original's
cmp ecx, 0x64at 0x004B988B): it is a row's size in bytes; a row has 25 entries.RT_BREAD(10) before they search (mov byte ptr [eax], 0xaat 0x004B9978): bread is the first entry of every goods list. 2000 does not.Header findings (nothing else changed here)
field_0x30c4[25], right after the table, has the shape of one more row.MapPropertiesState::invasionTroopIndexis the selected condition's index in this dialog, here and in main's render function for it. A lead for a wider name.EventConditionParamKindis 0, 1 or 2: no option, a list of goods (ResourceTypeids), one of five opponents (field_0x170[5], as main's render function for this dialog reads it). A lead for an enum.setSliderParameters2declares itsdestinationasdword, and it is ashort*. This function passes(dword)&…value, and main'ssetSliderParameters2.cppcasts it straight back toshort*. Retyping the parameter would drop both casts. Not done here, because it would change main's .cpp too.The checker's 5 CHECKs
forloops without their counter in the loop header🤖 Generated with Claude Code