Repository navigation
Map::Floaters: an enum for the flag bits of a floater's variation - #486
Merged
Merged
Conversation
A new enum, Map::Floaters::FloaterVariationFlags, for the low half of Floater::variation. createFloatingLayerElement (0x004E63A0) stores the variation whole, one dword, at 0x004E64BC, and renderMap (0x004E8CF0), and renderUnits for batched tiles, read the bits back: - FVF_FIRST_PASS (0x02) and FVF_SECOND_PASS (0x01): the floater is drawn in the first or the second of the two passes renderMap makes over each row of visible tiles (row loop 0x004E9060 to 0x004EC46D; the tile loops 0x004E90E0 to 0x004EBAA8 and 0x004EBB00 to 0x004EC272; their floater loops test the bit at 0x004E9ED0 and 0x004EC090). - FVF_SET_RENDERED_OWNER (0x04): the rendered owner becomes the current player's slot and the rendered sprite the floater's GM (0x004E9F30, 0x004EC13D). - FVF_RENDERED_OWNER_0 (0x10): the rendered owner is 0 instead; it is read only together with 0x04. - FVF_USE_TOTAL_HEIGHT (0x08): second pass only (0x004EC09B); while TileMapState's setting at 0x01FE7ACC is on and the view is not flat, the floater is raised by getTotalHeightAt(tile, 0) (0x004FFBA0: the tile's height plus that of the building, wall or tree on it) instead of by the offset every other floater gets. - FVF_MASK_IMAGE (0x20): the mask image passed to renderGMWithAlphaMask is the floater's image ID plus the high half, from the same GM (0x004E9F5F, 0x004EC169). Without it, a non-zero high half is the blend strength for renderGMWithBlending, and 0 draws the floater plainly. On a tile with MD_BATCHED_SPRITES (0x004E9EDF, 0x004EC0ED), renderMap hands the floater to scheduleUnitForBatchedRendering with the whole variation instead, and renderUnits (0x004E7810) reads 0x04, 0x10, 0x20 and the high half the same way (0x004E7FC1, 0x004E7FDC). The parameter and the field stay int, since the original passes and stores the value as one dword. The high half stays a number, written value << 16. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The six createFloatingLayerElement calls pass 5, 13 and 29. They are written with FloaterVariationFlags now: FVF_SECOND_PASS | FVF_SET_RENDERED_OWNER (5), with FVF_USE_TOTAL_HEIGHT (13), and with FVF_RENDERED_OWNER_0 as well (29). No other change. Measured: quick_diff gives the same listing as main's text, and a narrow real build on main 48f7e94 (main's /GL list and this file, with the struct resolvers and the files' function resolvers on, sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie) reads 100.0% raw and normalised with no differing line, and every other function reads as in the same build without it. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
approved these changes
Nov 24, 2026
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Nov 24, 2026
sourcehold#486 named the flag bits of a floater's variation, so PlaceUnit's eight createFloatingLayerElement calls now spell them: 13 is `FVF_SECOND_PASS | FVF_SET_RENDERED_OWNER | FVF_USE_TOTAL_HEIGHT` and 29 the same with `FVF_RENDERED_OWNER_0`. The four blended calls keep the blend strength in the high half as the number `(24 << 16)`, as sourcehold#486's text writes it. The quick listing is the same as before (376 instructions). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kotijekriv
added a commit
to kotijekriv/OpenSHC
that referenced
this pull request
Nov 24, 2026
* reimplement: SHC_3BB0A8C1_0x004381D0 100.0% Reimplemented Actions::PlaceUnit, from Gynt's draft on his fork's reimpl/UI-Core-development (10280b1 at 39.4%, from after his closed sourcehold#256, and e584164 at 36.40% before it; sourcehold#256's reimpl/UI-Core has it at 36.4% in a05c452 and 39.0% in 1b11452). The draft has the cases' values (the pictures, the tribe types and the unit types), the calls and their arguments. His 3d17527 on reimpl/UI-MenuItems-development is another line of this file (36.4% there); this text does not build on it. Rewritten against the original instructions are the order and the control flow: - the cases are in the original's jump-table order: 270 to 280, the Arab units 350 to 357, then 281, 282, 284, 283, 285, 286; the Arab ballista case, last in the draft, gets a break, since the catapult case follows it now; - the default case leaves the body graphic unset, as the original does. The original reads it from the stack slot of the siege cost's gold there (`mov edi, [esp + 0x24]` at 0x00438456), so stone and gold are declared in each of the two cost blocks and not once at the top; - the four floating-layer pairs are alternatives that each return (allowed or not, siege tower or not), where the draft ran them one after another, and then went on into the placement, so it paid for and spawned the units while the drag was still going. That is the one behaviour fix against the draft; - the gold check is gold > the player's gold, the flag a dword (BOOLEnum), and the pots loop counts with a signed compare; - `int const tile = ...` stands between `int imageID = 1;` and `BOOLEnum canAfford = TRUE;`. The two share their constant, which then has to live across the tile's computation, where eax, ecx and edx are taken. So it is in edi, and its two stores sink behind the switch's range compare with the tile's store between them, as in the original (`mov edi, 1` at 0x00438223; the stores at 0x00438234, 0x00438238 and 0x0043823C). With both `= 1` on one side of the computation the constant is in eax and is stored before the command is loaded (98.6%). The decompiler's names became tribeType, secondGmID, secondImageID, imageID, blockingLogicMask, canAfford, stone and gold. The blocking masks are written as main's Logic1 flags and the tribe types as AITribeType names (12, the monks', is AITT_HOPS_FARMER_UNK there). The variation of a refused placement is written 29 + (24 << 16) and 13 + (24 << 16): the allowed one's with 24 in the third byte. No line for cmake/compiler-flags-gl.txt, and it must not get one: the file reads 100.0% off the /GL list and 90.0% (normalised 80.9) on it, in the same build otherwise. quick_diff gives the same instructions with and without the bodies of getBuildingCost and processResourceLoss, its two callees on main's list, in the unit. reccmp in a build of main's whole /GL list (the 133 files that exist) and the file, off the list, with every resolver of those files on: 144 functions, average 99.56. PlaceUnit 100.0% raw and normalised, no differing line. The same build without the file has 143 functions, and each of them reads the same. Both builds (off and on the list) had an earlier text of this file: the same statements with the masks and the tribe types as numbers, the flag as an int, the bounds test around the body, and without most comments. quick_diff gives the same 376 instructions, line for line, for that text and for this one. The sources are main's at 3458fea; main's two commits since (02fab42, 812d149) add cmake files only, with the new option off. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> * headers: TileMapState::unitPlacementCount is an int The original uses it as a signed 32-bit count in all six places that touch it. InitializeBasicMap (0x0042F0CD), MenuItemActionHandler_MapEditorProperties_MainButtons (0x0044309F) and MenuItemActionHandler_General_ToolbarButtonPressed (0x00444647) store 1 into it. PlaceUnit passes it to spawnUnitsIntoNewTribe as its int unit count (0x00438659) and loops over it with signed compares: `jle` when it is not above 0 (0x004386A9) and `jl` for the loop bound (0x004386D1). The header had it as undefined4, so PlaceUnit's loop needed an (int) cast (TheRedDaemon's review of sourcehold#458). The two users on main, InitializeBasicMap and ToolbarButtonPressed, compile to the same listing with it (quick_diff, ours against ours). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * PlaceUnit: the map-size constants, no cast on the placement count, the variation's two halves From TheRedDaemon's review of sourcehold#458: - The bounds test and the tile index use Map::MC_MAP_XY_LIMIT_MIN_1 and Map::MC_MAP_XY_LIMIT in place of 399 and 400. - With unitPlacementCount an int (the commit before), the loop drops its (int) cast. - The variation's high half is a blend strength, not a third byte: the comment says so, and the variations are written 13 | (24 << 16) and 29 | (24 << 16). createFloatingLayerElement stores the dword whole (0x004E64BC). renderMap's two floater loops (0x004E9EC0, 0x004EC080) test bits of its low half and take the high half as a signed number (sar 16): with flag 0x20 an offset added to the image ID for renderGMWithAlphaMask, otherwise, when not 0, the blend strength for renderGMWithBlending. The listing is unchanged (quick_diff, ours against ours: the same 376 instructions), and a real build of main's /GL list with this file off the list reads 100.0% raw and normalised. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * style: PlaceUnit starts its unit type at UnitType's UT_INVALID The local unit type started as `(UnitType)-1`; main's UnitType names -1 UT_INVALID, so it is the name now. No other change. Measured: with the precompiled header, quick_diff gives the same listing for the pushed head's text and this one. A narrow real build (main's /GL list and this file, with this PR's header change, the struct resolvers and the file's function resolver on, sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie) reads 100.0% raw and normalised with no differing line, and every other function reads as in the same build without the file. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * PlaceUnit: the floater variations as FloaterVariationFlags names sourcehold#486 named the flag bits of a floater's variation, so PlaceUnit's eight createFloatingLayerElement calls now spell them: 13 is `FVF_SECOND_PASS | FVF_SET_RENDERED_OWNER | FVF_USE_TOTAL_HEIGHT` and 29 the same with `FVF_RENDERED_OWNER_0`. The four blended calls keep the blend strength in the high half as the number `(24 << 16)`, as sourcehold#486's text writes it. The quick listing is the same as before (376 instructions). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
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.
An enum for the flag bits of
Floater::variation, as asked in the #458 review.createFloatingLayerElement's parameter and the field stayint. One caller on main uses the names, with the same listing. One new header, no other header change.The header:
Map::Floaters::FloaterVariationFlagscreateFloatingLayerElement(0x004E63A0) stores the variation whole, one dword, at 0x004E64BC.renderMap(0x004E8CF0), andrenderUnitsfor batched tiles, read the bits back:renderMapdoes with itFVF_FIRST_PASSrenderMapmakes over each row of visible tiles (row loop 0x004E9060 to 0x004EC46D; tile loop 0x004E90E0 to 0x004EBAA8; the floater loop tests the bit at 0x004E9ED0)FVF_SECOND_PASSFVF_SET_RENDERED_OWNERFVF_USE_TOTAL_HEIGHTTileMapState's setting at 0x01FE7ACC is on and the view is not flat, the floater is raised bygetTotalHeightAt(tile, 0)(the tile's height plus that of the building, wall or tree on it) instead of by the offset every other floater getsFVF_RENDERED_OWNER_0FVF_MASK_IMAGErenderGMWithAlphaMaskis the floater's image ID plus the high half, from the same GM (0x004E9F5F, 0x004EC169)Without 0x20, a non-zero high half is the blend strength for
renderGMWithBlending, and 0 draws the floater withrenderGM. The high half stays a number, writtenvalue << 16.On a tile with
MD_BATCHED_SPRITES(0x004E9EDF, 0x004EC0ED),renderMaphands the floater toscheduleUnitForBatchedRenderingwith the whole variation instead, andrenderUnits(0x004E7810) reads 0x04, 0x10, 0x20 and the high half the same way (0x004E7FC1, 0x004E7FDC).Our #458 reply called 0x08 the terrain height. Every floater is already raised by its tile's height; 0x08 uses
getTotalHeightAt's total instead, so the name says that.Why the type stays
int: the original passes the variation as one 32-bit value, for examplepush 0x18001dat 0x00438563 inPlaceUnit, andcreateFloatingLayerElementreads it with onemov edx, [esp + 0x28](0x004E64AC).The header change waits for the Ghidra sync: the header is new under
src/OpenSHC, so main's declaration check fails on it and labels the PR, as with the other header changes. It is written in the generated form, so that the sync can take it in.Callers on main and in #458
calculateHoveredTile(ours, on main): its six calls pass 5, 13 and 29. They areFVF_SECOND_PASS | FVF_SET_RENDERED_OWNER, then withFVF_USE_TOTAL_HEIGHTadded, then withFVF_RENDERED_OWNER_0as well.PlaceUnit(One more UI function at 100%: Actions::PlaceUnit #458):13,29,13 | (24 << 16)and29 | (24 << 16)become the same names, with the same quick listing. That commit goes into whichever of the two PRs lands second.createEntityForAssemblyPointsForActiveTabTypepasses 0xa0022 (FVF_FIRST_PASS | FVF_MASK_IMAGE, mask offset 10) and 0xc0006 (FVF_FIRST_PASS | FVF_SET_RENDERED_OWNER, blend strength 12). It is not changed here.Measured
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), the struct resolvers and the function resolvers enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie.FVF_ADD_TERRAIN_HEIGHTtoFVF_USE_TOTAL_HEIGHT, with the same value), with both resolver sets on and main's own/GLlist, and with 0x004314E0 (theMapEditorLandscaping_GeneralButtonshandler) left out and its resolver off, as in main's baseline, together withrequestGoods(0x004D1F00) andMenuItemActionHandler_Allies_Main(0x004B12D0), which do not compile on 48f7e94 until Reimplement 29 Synchrony and Game functions at 100% #403 renames their twoPlayerDatafields: 0 failed of 2,466 compile steps, 99.59 over 2,482 functions.calculateHoveredTilereads 100.0 raw and normalised there, with no diff entry, and every one of the 2,482 functions reads exactly what it reads in the same build of main (unrounded 99.5915 raw and 99.5570 normalised, 2,365 functions at 100.0 raw, in both). The header adds no code; the six arguments are the same constants./GLlist (the 133 files that exist) andcalculateHoveredTile, on 48f7e94's headers with the new one. The function reads 100.0% raw and normalised with no diff entry, and every other function reads as in the same build without it. quick_diff gives the same listing for main's text and this one (177 instructions).🤖 Generated with Claude Code