Repository navigation
UI: the map editor's properties buttons handler at 100% - #441
Open
kotijekriv wants to merge 3 commits into
Open
kotijekriv wants to merge 3 commits into
kotijekriv wants to merge 3 commits into
Conversation
…takes (int param_1, ...) MenuItemActionHandler_MapEditorProperties_MainButtons (0x00443070) calls the handler at 0x0042EDF0 with one argument and cleans the stack itself (push of the 0 it keeps in ebp, call, add esp, 4, from 0x004436D8). The handler is a menu item's action handler: its address stands in the menu item at 0x005EE8FC, two dwords in front of that item's render function 0x0042EBC0, and nowhere else in the image. So it gets the parameter list that MainButtons' handler and the two render functions of this header have, (int param_1, ...), and not (). Changed: the declaration in MapEditorProperties.hpp and the resolver's type in MapEditorProperties.func.hpp. The definition's signature follows in the next commit; the branch builds from there on. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…finition follows its header The header commit before this one gives the handler at 0x0042EDF0 the parameter list (int param_1, ...). The definition takes (int unused, ...) now. The handler does not read the parameter and is cdecl, so its code is unchanged: reccmp 100.0 (normalized 100.0) as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
MapEditorProperties::MenuItemActionHandler_MapEditorProperties_MainButtons, rewritten from the original's listing. gynt's draft: 39d2799 at 48.43% ("Style pass, asm differs") on his fork's reimpl/UI-MenuItems-development, whose status line records 48.4%; the newest commit on the file there is dd1a7c4. Our draft (59372c9, then d79d89d and 6202bb0; 53.2% in the draft PR sourcehold#328) was his code with a mechanical pass. The function handles the buttons of the map editor's properties view: two early exits while a dialog is open, then one switch over the button's parameter (-6 to 31), dispatched through the byte table at 0x004437B4 and the jump table at 0x00443778. Button 31 starts a game on the edited map and copies the scenario's settings into the game state; that case is two thirds of the function. What decided the match: - The cases stand in the original's order: 2, 3, 4, 5, 6, 31, 9, 25, -1 to -6. The draft had 9 and 25 in front of 31 and the negative ones from -6 to -1. - The seven euro and seven mercenary recruitable values are copied by one loop over the index with both copies in it; the compiler unrolls it completely. Pair by pair is the order that gives the original's registers: the first four euro values end in eax, ecx, edx and esi and stay there for the tests behind the loop, the first two mercenary values go through edx, the third through esi and everything later through edi. A loop for each array gives other registers (quick_diff 0.9900 -> 0.9576). The draft had the twenty short copies in the order of the original's instructions, which the compiler does not keep. - The six weapon flags are copied in front of that loop, in the scenario's order (behind it: 0.9712 -> 0.9262 with the copies written out). - The nine euroRecruitableCopy flags are cleared in front of the loop and set behind it by seven ifs. Cleared behind the loop, the first four copies' stores move in front of the clears (0.9900 -> 0.9800). The draft set them by `= (int)(x != 0)`. - The starting goods are copied by a loop over the 25 entries, which the compiler turns into the original's rep movsd. With memcpy it reads the next statement's value (startGoods[RT_PARTIALPITCH]) from the scenario's array and loads it before the copy, where the original reads the copied entry afterwards (0.9900 -> 0.9875). - The twenty siege unit counts are copied one by one in ascending order; the original's instructions run in threes backwards, which is the compiler's scheduling of exactly that order. - Button 6's tab test is two ifs: the feature tab becomes its multiplayer version on a multiplayer map and the multiplayer version becomes the feature tab on a single-player one. The draft's gotos compile to the same listing (measured on this text). - Button 9 calls the description box's handler with 0, which the two commits before this one allow. Names: the landscaping tab's 237 and 239 are Commands::M_MAPPER_SUB_MODE_FEATURE and M_MAPPER_SUB_MODE_FEATURE_MP, written through buildMenuTab (main's MenuItemActionHandler_MapEditorLandscaping_CategoryButtons does the first half of this swap, on its parameter, with the same names); the build menu's 10 is UI::Enums::BMTT_CASTLE (the draft's BASMTT_HUNTERSHUT has the same value in the other enum of the union); the text index 9 is OpenSHC::Text::TAIT_NINE__FILTER_B as main stores it into the same field; startGoods' entries 7 and 8 are Game::Resources::RT_PITCH and RT_PARTIALPITCH, as main indexes SEC_StartingResources; INT_00b960e4 takes TRUE and FALSE as main writes it. The parameter is called button and the case labels stay numbers, with a comment for each button or pair of buttons, as in main's MenuItemRenderFunction_MapEditorProperties_MainButtons for the same buttons. The description's scroll-down is written flat, as main's SingleplayerMapChoice handler has the same scroll; nested it compiles to the same code. quick_diff ends at 0.9900 with four hunks that are its own printing (three stores into TileMapState fields shown as [G]+G, the operands of rep movsd). Narrow build with those two commits and the two finished callees the function refers to in the sources list, their resolvers on (the description box's handler, and RenderLoadAndSaveBar, whose address it stores): reccmp 100.0, normalized 100.0, and both callees stay at 100.0. Without RenderLoadAndSaveBar's file in the list the stored address shows as a trampoline on our side: one line, 99.8 (95.2 normalized). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <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. One header change:
MenuItemActionHandler_MapEditorProperties_MapDescriptionBoxgets the parameter list(int param_1, ...)(first commit); its definition follows (second commit).MenuItems::MapEditorProperties::MenuItemActionHandler_MapEditorProperties_MainButtonsOur draft was gynt's code with a mechanical pass; gynt's best, 48.4%, is 39d2799 on his fork's reimpl/UI-MenuItems-development.
The header change
For button 9
MainButtonscalls the description box's handler (0x0042EDF0, at 100% on main) with one argument and cleans the stack itself (push ebp; call; add esp, 4from 0x004436D8, with 0 inebp). The header declared the handler with().MapEditorProperties.hppandMapEditorProperties.func.hpp: the declaration and the resolver's type get(int param_1, ...), the list thatMainButtons' handler and the two render functions of this header have. (The two scrollbar functions take five parameters.)(int unused, ...), main's wording for a parameter that is not read. The handler is cdecl, so its code is the same: it stays at 100.0 raw and normalised.Nothing else on main refers to the handler. The first commit does not build alone, because header changes go in a commit of their own.
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).RenderLoadAndSaveBar(whose address the function stores), their resolvers on: 100.0 raw and normalised for all three.RenderLoadAndSaveBar's file in the build the function reads 99.8 (95.2 normalised): the stored address then shows as a trampoline on our side, one line. Measured on this head.tools/). The new function reads 100.0 raw and normalised there too, with no diff entry, and the description box's handler stays at 100.0.(char)casts are gone, our own review renamed two indices and one flag's values, flattened oneifand added comments, and the header commit was split in two. Each gives the same listing, and the narrow build above is of this head.What got it to 100%
The function handles the buttons of the map editor's properties view: one
switchover the button's parameter (-6 to 31). Button 31 starts a game on the edited map and copies the scenario's settings into the game state; that case is two thirds of the function, mostly plain stores.The drafts had the decompiler's shape, with button 31's copies in the order of the original's instructions. Our draft read 411 instructions against the original's 401 (0.5567 in our listing diff). The function is written from the original's listing now. What decided the match:
euroRecruitableCopyflags are cleared in front of the loop and set behind it by sevenifs. Cleared behind the loop, the first four copies' stores move in front of the clears (0.9900 to 0.9800). The draft set them by= (int)(x != 0).rep movsd. Withmemcpyit takes the next statement's value (startGoods[RT_PARTIALPITCH]) from the scenario's array, before the copy; the original reads the copied entry afterwards (0.9900 to 0.9875).Several other choices gave the same listing, and we took the plainer form: two
ifs for button 6's tab in place of the draft's gotos, the scroll-down written flat as main'sSingleplayerMapChoicehandler has it, and the six score additions without a cast.No behaviour differs from our draft, as far as we can tell. The draft called the description box's handler without the argument; the handler does not read it.
Names
Commands::M_MAPPER_SUB_MODE_FEATUREandM_MAPPER_SUB_MODE_FEATURE_MP, written throughbuildMenuTab. Main'sMenuItemActionHandler_MapEditorLandscaping_CategoryButtonsdoes the first half of this swap, on its parameter, with the same names.Game::Resources::RT_PITCHandRT_PARTIALPITCH, as main indexesSEC_StartingResources.UI::Enums::BMTT_CASTLE, as main'shideOrUnhideUIwrites it.OpenSHC::Text::TAIT_NINE__FILTER_B, andINT_00b960e4takes TRUE and FALSE, both as main writes them.button, and the case labels stay numbers, with a comment for each button or pair of buttons. There is no enum for these buttons; main'sMenuItemRenderFunction_MapEditorProperties_MainButtonshandles the same ones the same way.Things in the file that look odd and are the original's
startGoods[RT_PITCH] = startGoods[RT_PARTIALPITCH]; startGoods[RT_PARTIALPITCH] = 0;behind the copy of the starting goods (0x004433CB and 0x004434B6): the scenario keeps this amount underRT_PARTIALPITCH, and the game moves it toRT_PITCH.currentPlayerFullIDArrayentries to -1 in a loop and then entry 1 to 1. The original has eight stores of -1 and one of 1; the compiler drops the loop's store into entry 1.Header findings (nothing changed here)
ActiveMenuTab(the union behindGameCore's...MenuTabToSwitchTofields) has no member for the landscaping menu's values, which areMappersEnum's sub modes (231 to 239). Main writes them throughbuildMenuTab, and so does this file.MenuTextInputState::DAT_SomeTextArrayIndexisundefined4. It holds a text array index: main storesTAIT_NINE__FILTER_BandUserTextHandlerState::textArrayIndexinto it.DAT_00b960f4andINT_00b95b74: the description's arrows moveDAT_00b960f4by 14 between 0 andINT_00b95b74 - 231. A lead: the description's scroll position and its height.AttackInfo::someSinglePlayerScore(byte[50][10]) is indexed by the attack wave here (inv_count), and its columns get the scenario's siege engine counts. A lead: per wave, not a score.The checker's 22 CHECKs
19 are Ghidra's placeholder names (four globals and five
field_0x..fields); one says the header change stays in the PR until main has it; one asks about the resolver's type, which has the form of the header's other(int param_1, ...)resolvers; one notes the numeric case labels (see "Names").🤖 Generated with Claude Code