Repository navigation
One more Map::Units function at 100%: UpdateAssassin, with Unit::field_0x41a as a short - #450
Open
kotijekriv wants to merge 2 commits into
Open
kotijekriv wants to merge 2 commits into
kotijekriv wants to merge 2 commits into
Conversation
It was `undefined2`. Units::UpdateAssassin (0x005744D0) compares it signed in two places, `cmp ax, bx; jle` at 0x00574F12 and `cmp cx, bx; jle` at 0x005750C2 (ebx is 0), each followed by `add ..., -2` and the store back. No other function on main names the field. The only other code that touches it is 0x004E2630 (`movsx` at 0x004E2691), not on main; gynt's sourcehold#241 has it as renderAssassinClimbingOverlay and makes the same change to this line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::UpdateAssassin, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (7e9039d at 44.69%, after 7ffb455 at 44.69% and 982d7f0 at 39.56%), through versions on our dev branch from 82.5% to 97.0%. The forms that matter: - the melee and wall-attack states have UpdateKnight's shapes: the unit is read through the slot global with no local copy of the unit ID, and the attacked unit's ID is read once into a local in front of playHurtSFXForUnit, its type once into an int behind it; - `building` is declared with its value at the wall attack's tile check (`int building = BuildingLayer[...]`), so no path reads it unassigned; without that assignment the function gets 4 bytes of frame the original does not have; - the fade countdown is decremented as a signed char (`--(char&)...`); - of the wall attack's three give-up places the first and the third only set the state and fall to the case's end, and the second, the AI's give-up on a wall, is the then-arm of its test with the return in the else-arm. The compiler keeps a block with its own copy of the case's end at the first place and jumps into it from the second, as the original does (9 bytes); - the idle state's end in its plain form: `if (dig or fill moat) { idle = 1; } if (idle == 0) { return; } animationCycleNumber = 0;`. The original sets the idle flag behind the two compares and jumps over the flag test (`cmp ax, 6; je; cmp ax, 7; jne; mov [idle], ecx; jmp` from 0x00575506); with the return in an else-if the function is four instructions longer; - field_0x41a is compared as the short it now is in Unit.hpp (the commit before this one), without a cast. The rope chain ends in an else-if / else, no else stands behind a return, and two comments give the why of the then-arm and of the signed decrement; the code is the same (quick_diff, 1058 instructions, line for line). Numbers and pointer arithmetic that have names in main's headers are written with those names, as in UpdateKnight. The states 104 and 105 have no name in UnitState yet and keep their casts. compiler-flags-gl.txt gets UpdateAssassin.cpp. No other line is needed: of its callees, hasUnitReachedDestination and resumeMovementIfNoAttackTarget are on main's list already, and the function reads 100.0% with the list as it is. reccmp in a build of main's whole /GL list (the 133 files that exist) and this file, with the header commit and every resolver of those files on: UpdateAssassin 100.0% raw and normalised, no differing line. Each of the 143 functions of main's list reads the same as in the same build of main (3458fea) without the header commit and the file. 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 more function at 100%, with one header change in a commit of its own:
Unit::field_0x41abecomes ashort.Units::UpdateAssassinis from gynt's units branchreimpl/map-units-updatefunctions(his draft #204), and its commit credits him as co-author. It sharesUpdateKnight's wall attack (#444).Units::UpdateAssassin/GLMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie.MapEditorLandscaping_GeneralButtonshandler) left out and its resolver off, as in main's baseline: 0 failed of 2,424 compile steps, 99.57 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files undertools/).UpdateAssassinreads 100.0 raw and normalised there too, with no diff entry. No.cppon main usesUnit::field_0x41a, and the header change moves no function. Two functions on main read lower, and it is how reccmp prints a constant, not their code:Menu::handleMenuItems(0x004F6280) reads 97.9 (91.4 normalised) andMenu::Constructor_Menu(0x004F4100) reads 98.4 (95.2), both 100.0 before. Their only differing lines are five compares with the constant 0x11000000, which reccmp prints on our side as the name of a symbol of our DLL that lies at exactly that address in this build's layout; 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. Unrounded the average is 99.5746 against 99.5759 for main; with those two at 100.0 it would be 99.5761. Every other main function reads exactly what it read before./GLlist that exist on main, andUpdateAssassin.cpp, with the header commit: 144 functions, average 99.56.UpdateAssassinreads 100.0% raw and normalised, with no diff entries. The same build of main without the header commit and the file has 143 functions, and each of them reads the same in both.openshc-pr-fixfinds nothing to change, andopenshc-pr-checkgives 0 ERROR and 79 CHECK (explained below).The header commit:
Unit::field_0x41ais ashortIt was
undefined2.UpdateAssassincompares it signed in two places:cmp ax, bx; jleat 0x00574F12 andcmp cx, bx; jleat 0x005750C2 (ebxholds 0), each followed byadd …, -2and the store back. With the field asshortthe two(short)casts our dev version needed are gone. The only other code that touches it is 0x004E2630 (movsxat 0x004E2691), not on main; gynt's #241 has it asrenderAssassinClimbingOverlayand makes the same change to this line, so the two hunks merge cleanly. No other function on main names the field, so the commit cannot change any other function; in our narrower run each of main's 143 functions reads the same with and without it.The declaration check will fail and label this PR until main has this line. Then we merge main in, and the check passes.
What got it to 100%
Every number here is with the file on the
/GLlist (below). On our dev branch (not public) it went from 82.5% to 97.0%, mostly with the formsUpdateKnighthas: the unit read throughDAT_CurrentUnitSlotID::instancewith no local copy of the slot, and the attacked unit's ID and type each read once into a local for the clash sound. Four more things were needed; the third is the same as in the melee units next to it.buildingis declared with its value at the wall attack's tile check (int building = BuildingLayer[…]), in front of the idle test, so no path reads it unassigned. The other melee units keep 4 bytes of frame forbuilding; the assassin's original has none, and ours had them until the variable got its value there (91.2% to 97.0%, together with the next point).--(char&)…disappearFadeAlphaCountdown): in that form the compiler keeps -1 in a register across the decrement, as the original does (asx--;quick_diff reads 0.9872, 1,057 instructions, against 0.9924). A comment in the code says so.moveUnitToBehaviorTargetfails, where an AI player gives up on a wall, and where it gives up on a gate or tower. In the original the first and the third are each a state store with a copy of the case's end behind it, and the second is ajmpinto the first one's block. With the first two written out (state = …; animationCycleNumber = 0; return;) the shared block computes the unit's offset once, 9 bytes short. With the first only setting the state and the second asif (!setDestinationNearTargetedBuilding(…)) { state = …; } else { return; }the compiler keeps a block with its own copy of the end at the first place and jumps into it from the second (quick_diff with the/GLcallees in the unit 0.9886 to 0.9915). A comment in the code says why.if (dig or fill) { idle = 1; } if (idle == 0) { return; } animationCycleNumber = 0;. The original sets the flag behind the two compares and jumps over the flag test (cmp ax, 6; je; cmp ax, 7; jne; mov [idle], ecx; jmpfrom 0x00575506). Our dev version had an if / else-if / else chain there, left by an earlier search, which laid the store out behind the test; with thereturnin an else-if the function is four instructions longer (0.9896 against 0.9943).0xffffagainst-0x1twice, the import oftimeGetTime, one mask, and the tile-cost table's address in two operands.Lines added to
cmake/compiler-flags-gl.txtUpdateAssassin.cpp. No callee needs a line:hasUnitReachedDestinationandresumeMovementIfNoAttackTarget, which it calls, are on main's list already, and with main's list as it is the function compiles to the same code as with every finished callee of our dev list visible.Kept as they are
int damage;without a value (thedeclared without a valueCHECK): each arm of the wall test assigns it.(char)casts: 14 frame-table reads intoanimationFrame, four tests ofdisappearFadeAlphaCountdown, two ofengineerManningSiegeStateRef_checkTypeand one ofownerOfAssassinScaledObject. The headers have these asbyte, and the original reads them signed (see the proposal below). The--(char&)decrement belongs with them.(int)(mapTimeInTicks + slot) % 40: the original divides signed (cdqat 0x00574678,idivat 0x0057467E).units[slot].ownerread again in four places thoughowneris a local: the argument ofprocessDamageToBuildingThunk,attacker, and twice in the wall-scaled warning. The original reads the field again there (movsxat 0x00574AD8, 0x00574B8C, 0x00574DC0 and 0x00574E0B), thoughebpstill holds it.UnitState: 105 twice and 104 once. 105 isUS_RALLYINGin gynt's Reimplement 17 navigation and map-property functions #293, and those two casts go when that lands; 104 has no name in any open PR. State 108 uses main'sUS_UNKNOWN_108.similar blocksCHECKs): the thresholds 70, 100, 130, 160, 190 and 210 pickimageIDUnk7 down to 2, else 1. The original has the chain of compares; as a for loop over the thresholds the function comes out 139 instructions shorter (quick_diff 0.8862 against 0.9924), which the comment in the code says in short.Unitfields of the next section): below.What some placeholders hold
Unit::field_0x413: 1 while the assassin is on the rope (throwing the hook, climbing up, climbing down), 0 again when the climb ends.Unit::field_0x418: how far up the rope the unit is. Climbing up it counts up with the animation until it reachesassassinHeightDifference - 35; climbing down it starts atassassinHeightDifferenceand falls by 4 per update until it is 30 or less;US_DEATH_01takes 8 off per update,US_DEATH_03and the stone deaths set it to 0, and starting to climb down leaves it alone; everywhere else it is 0.Unit::field_0x41a: set to 32 when a climb starts and when it ends, and taken down by 2 per update while it is above 0 inUS_ASSASSIN_CLIMBING_UP(0x00574F0B) andUS_ASSASSIN_CLIMBING_DOWN(0x005750BB). 0x004E2630 reads it for the climbing overlay. This is the field the header commit types.Unit::field_0x2ac: 10 while the unit stands idle, as in the other melee units.DWORD_00ee1064: thetimeGetTime()of the last wall-scaled warning ("General_Warning18"), which it limits to one per 30 s. Only this function uses it (0x00574DE6, 0x00574E3C).Frames_Shared_UnitClimbingUp:.field_0x2c94is the table of melee and of the wall attack;.field_0x2dac,.field_0x2df4and.field_0x2e4care the three tables of throwing the hook;.field_0x2ed8is climbing up and.field_0x2eb0starting to climb down;.field_0x93cis the table ofUS_DEATH_01andUS_DEATH_03,.field_0x8e4that of the three stone deaths (114 to 116 share one case).Proposed, not changed here
charfor byte fields read as signed:Unit::disappearFadeAlphaCountdown,Unit::engineerManningSiegeStateRef_checkType,Unit::ownerOfAssassinScaledObjectand the AnimationFrameData frame 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. Ascharthe(char)and(char&)casts above could go.UnitState(US_UNKNOWN_104), in a header commit of its own. 105 isUS_RALLYINGin gynt's Reimplement 17 navigation and map-property functions #293; a second definition here would break the build.Other PRs
UpdateAssassin.cpptoo: an add/add conflict on that file, and the status line at 0x005744D0 differs (100.0% here against his 44.7%). Once this lands, his branch can take main's version of it.cmake/compiler-flags-gl.txt. The conflict is line-level only: whichever lands second needs a trivial merge that keeps the lines of both. Map::Units::UpdateLion at 100% #425 merges cleanly, and cmake: optional wrapper units built from function-visibility.txt #399 doesn't touch the list.Unit.hpp(identical hunks), and Reimplement 17 navigation and map-property functions #293 names state 105US_RALLYING.UpdateAssassin's callees on the/GLlist, and the original reloads the slot behind four of them (0x00574981, 0x00575341, 0x00574B29, 0x005748F3). We have not measured this function with Reimplement 47 UnitsState functions at 100% and restyle 28 more #378 in the tree.🤖 Generated with Claude Code