Repository navigation
Map::Units::UpdateLion at 100% - #425
Open
kotijekriv wants to merge 3 commits into
Open
kotijekriv wants to merge 3 commits into
kotijekriv wants to merge 3 commits into
Conversation
…_208 Units::UpdateLion (0x0056B0E0) tests its state against these numbers: cmp dx, 208 at 0x0056B24A, 207 at 0x0056B28A and 206 at 0x0056B68F. The values already in the enum do not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::UpdateLion, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (974c32f, after e3fc5d9 at 59.36%), through an earlier version on our dev branch at 87.9%. Kept forms, each with quick_diff of the form without it (the /GL callees in the unit; the final form reads 0.9939, all of it quick_diff's view of the two timeGetTime calls): - the first state reads the slot into a local behind setUnitFacingDirectionTowardsTarget and again behind each findClosestAnimalStoreResult (without those three reads 0.9479, through the global throughout 0.9817); - state 205 sets a frame local in each arm, stores it once and tests the local (through the field 0.9837); - the chase state keeps the target in a short with an int copy for the index (one int 0.9888) and stores destinationNeeded through the slot ahead of that read (through unitID 0.9919). compiler-flags-gl.txt gets UpdateLion.cpp. The callees it needs visible are on the list already: checkIfCitizenUnitIsAliveBasedOnState (quick_diff without it 0.8409) and hasUnitReachedDestination (0.9591). With no callee bodies at all, i.e. off the list, 0.8396. reccmp in a build of main's whole /GL list with every resolver of those files on: UpdateLion 100.0%. Every other function in that build reads the same as in the same build of main (3458fea). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 19, 2026
tryAttackUnitID returns BOOLEnum, and the lion's test was `== 0`; TheRedDaemon's review on sourcehold#300 asks for a BOOLEnum result to be tested by truthiness, so it is `!tryAttackUnitID(...)` 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 round's files of several of our PRs, with the struct resolvers and those files' function resolvers on, sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie) reads 100.0% raw and normalised with no differing line for each function this commit touches, and every other function reads as in the same build without them. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <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 more function at 100%:
Units::UpdateLion(0x0056B0E0), from gynt's units branchreimpl/map-units-updatefunctions(his draft #204). The commit credits him as co-author. As it stands it adds three newUnitStatevalues, so the declaration check will fail until those values are on main (see below). There is also a question below about doing without them./GLlist/GLlist/GLlistgynt's numbers are as he recorded them; we did not measure his commits again. The 100.0% was measured on a commit with the same tree as 94377f0 (tree 100067d7b); only the commit message differs.
Measured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie./GLlist that exist on main, plusUpdateLion.cpp.UpdateLionreads 100.0% raw and normalised, with no diff entries. The average is 99.56 over 144 functions. The same list on main (3458fea) gives 99.56 over 143, and every function in both builds reads the same.updateBuildingPlacementRotationPreview46.2%,playUnitSelectSpeech94.1%,InitBlendFilterArraysUnk97.9%,lightUpBuilding99.3% andUpdateFireBallistaBuilding99.6%. That run does not build every file, and we did not look further into them.openshc-pr-fixfinds nothing to change, andopenshc-pr-checkgives 0 ERROR and 19 CHECK (all explained below).What got it to 100%
Which statements read the unit through
DAT_CurrentUnitSlotID::instanceand which through the copy taken at the top was settled by measuring. That and the/GLline took the earlier version from 80.0% to 87.9%. Four shapes did the rest. Each quick_diff number below is the final file with that one shape undone; the final file reads 0.9939, and reccmp reads 100.0%. The 0.9939 is quick_diff's view of the twotimeGetTimecalls.setUnitFacingDirectionTowardsTarget(0x0056B185) and again behindfindClosestAnimalStoreResult(0x0056B21C). The code has a localslotfor this, read again behind each of the three searches. The compiler merges the three calls into the one the original has. Without those three reads: 0.9479, 488 instructions against 491. Through the global throughout: 0.9817.frame, which is stored once and then tested, as at 0x0056B631. Through the field: 0.9837.shortwith anintcopy for the index. The original tests the 16-bit value, then sign-extends it ahead of the branch (the block at 0x0056B2BB). Oneint: 0.9888, 490 instructions.destinationNeededis stored through the slot. This keeps the store ahead of the target's read, as at 0x0056B2BB. ThroughunitID: 0.9919.Header change: three new
UnitStatevaluesCommit a6603f8 adds
US_UNKNOWN_206,US_UNKNOWN_207andUS_UNKNOWN_208tosrc/OpenSHC/Map/Units/States/UnitState.hpp, next to the existingUS_UNKNOWN_205andUS_UNKNOWN_209. No existing value changes.UpdateLionUS_UNKNOWN_20866 81 FA D0 00cmp dx, 0xD0movementRelatedreaches 8US_UNKNOWN_20766 81 FA CF 00cmp dx, 0xCFUS_UNKNOWN_20666 81 FA CE 00cmp dx, 0xCEThe declaration check will fail on this PR until main has these values.
check-declaration-changes.ymlfails any PR that changes a.hor.hppfile undersrc/OpenSHC, labels itdeclaration/type change, and the merge queue rejects it too. The header is generated, so the values need to come in through main. Once they are there we will merge main in and this commit drops out.Question for the maintainers: the three enumerators now, or casts until the Ghidra sync?
The three enumerators move one function on main through the TU symbol count (the effect found on #366). In the full build,
GameStateStructures::migrateGameStateForMapVersion(0x0045C1C0) reads 99.8 / 95.5 in place of 100.0 / 100.0. Its source does not change and it is not on the/GLlist. One load,mov si, word ptr [GameStateStructures + 337108](source line 135), sits at a different place.To check this, we compiled that one file on this branch and compared the instruction streams:
UnitState.hppUS_UNKNOWN_206to208typedef shortlines after the first includeUnitsState.func.hppincludeSo three extra symbols anywhere after the includes give exactly this branch's code. The move depends only on how many symbols there are, not on what they are called. The same function moved to 99.8 with the two
Addressenumerators on #420, and it will move the same way when these three values reach main through a Ghidra sync.The alternative, measured:
UpdateLioncompares with(OpenSHC::Map::Units::States::UnitState)208,207and206, on main's headers, with no header commit./GLlist that exist on main, plusUpdateLion.cppandmigrateGameStateForMapVersion.cpp, both resolver sets on),UpdateLionreads 100.0 raw and normalised, and so doesmigrateGameStateForMapVersion.Which do you prefer? One option is the three enumerators now, with
migrateGameStateForMapVersionat 99.8 until it is matched again. The other is the three casts until a Ghidra sync brings the values, which leaves every function on main as it is. Switching this PR to the casts is one commit.Line added to
cmake/compiler-flags-gl.txtUpdateLion.cpp. quick_diff reads 0.9939 with its callees visible and 0.8396 with none of them, which is the same as being off the list.checkIfCitizenUnitIsAliveBasedOnState(0.8409 without it) andhasUnitReachedDestination(0.9591 without it).makeUnitStopWalkingByClearingPathProgressStateandresumeMovementIfNoAttackTargetare on the list as well and make no difference here (0.9939 without either).The 19 CHECKs
UpdateLion.cpp(char)castbyte, and the original reads them signed. FordisappearFadeAlphaCountdownit compares with a signed jump:cmp al, bl; jleat 0x0056B113 (line 31) andcmp al, 0x20; jleat 0x0056B821 (line 368), each after amov alof the byte. Each frame-table read is amovsx: 0x0056B89A (line 97), 0x0056B413 (198), 0x0056B579 (249), 0x0056B61B (277), 0x0056B62A (280), 0x0056B6C1 (313) and 0x0056B762 (337)int frame;)What some placeholders hold
These are only what
UpdateLionshows.MapAndTimeState::field3170_0x27a4: incremented once at the top of everyUpdateLion.Unit::field_0x3c2: cleared in states 204 and 205.AnimationFrameData.field_0x6d14: the frames for substate 100 of the moving state.AnimationFrameData.field_0x703c: the melee attack frames.AnimationFrameData.field_0x6ec4: the frames of state 204.AnimationFrameData.field_0x6ca4and.field_0x6cec: the frames of state 205, whenseatedis 0 and when it is not.Proposed, not changed here
charfor byte fields read as signed:Unit::disappearFadeAlphaCountdownand theAnimationFrameDataframe tables, as on Five more functions at 100%: InGameMenu MainButtons, Roundtable handler, BuySell, UpdateGhost and UpdateHopsFarmer #416 and Three more Map::Units functions at 100%: UpdateOx, ConsiderHavingABreakNowUnk and UpdateMinerIronFetcher #421. Aschar, the nine casts above could go.Other PRs
Checked with trial merges against each PR's head on 2026-11-19.
UpdateLion.cppand its status line: gynt's Reimpl/map units updatefunctions #204 holds his draft of this file, so the two conflict there. They also get a new conflict instatus/addresses-SHC-3BB0A8C1.txtatSHC_3BB0A8C1_0x0056B0E0, his 59.4% against this PR's 100.0%. Reimpl/map units updatefunctions #204 already conflicts with main elsewhere in that file. Once this lands, his branch can take main's version of both.UnitState.hpp: Reimplement 17 navigation and map-property functions #293 also adds values at the end of this enum. It merges cleanly with this branch in that file, and both sets of values are kept.cmake/compiler-flags-gl.txt: the new line goes one above the end of the list, betweenUpdateInnkeeper.cppandUpdateMerchant.cpp.🤖 Generated with Claude Code