Skip to content

Map::Units: two TribesState functions back to 100%, predatorNearby tested for non-zero - #483

Merged
gynt merged 2 commits into
sourcehold:mainfrom
kotijekriv:reimpl/main-A-round3-100
Nov 24, 2026
Merged

gynt merged 2 commits into
sourcehold:mainfrom
kotijekriv:reimpl/main-A-round3-100

Conversation

@kotijekriv

Copy link
Copy Markdown
Contributor

Two of gynt's TribesState functions from #277 read below 100% in a full build of main (with #478's four unrelated fixes on top) with every resolver on, although their status lines say 100%. In both, one conditional jump differs (ja where the original has jne), and the change is the same one-line test. No header change, no line for cmake/compiler-flags-gl.txt, and the status lines stay as they are (100.0%).

Function Address Reimplemented by Full build of main (raw / normalised) Now
TribesState::trySpawnAdditionalWildlifeForTribe 0x005260B0 gynt (#277) 98.7% / 95.2% 100.0% / 100.0%
TribesState::updateAnimalHerdBehaviorState 0x00523590 gynt (#277) 98.0% / 95.2% 100.0% / 100.0%

Both commits credit gynt as co-author.

predatorNearby tested for non-zero

  • The original tests the tribe's predatorNearby against 0 with jne in both: cmp word ptr [eax + ecx + 0x2a0], 0 at 0x005260D3 with jne at 0x005260E0, and cmp word ptr [eax + 0x2a0], 0 at 0x005235AA with jne at 0x005235B6.
  • The field is a counter, not a flag: in the Reimpl/TribesState methods that are 100% #277 review TheRedDaemon asked whether this is a boolean check. gynt found that it is set to 1 when the herd is scared, counted up every tick, and cleared after 800 ticks, so it holds 0..800. He offered to rename it (predatorScareTimer) or to put the explicit != 0 back, and then wrote the two tests as > 0 (374411d, 2026-11-09). On the ushort field, > 0 compiles to ja, and that one jump is each function's whole difference. His explicit tests against 0 before that read 100%: != 0 in trySpawnAdditionalWildlifeForTribe (7a1d6aa), and == 0 in updateAnimalHerdBehaviorState's first version (7a1d6aa), then != 0 (1d394e6). Between those and > 0, 5524e2a had made both tests bare truth tests.
  • Here both tests are != 0, the other form gynt offered: on an unsigned counter it gives the same answer as > 0 for every value. It is the test the original makes (whether a scare is running, not how far along it is), and it stays an explicit comparison, as the style guide's rule 5 keeps for counters, so it does not read as a flag. Each has a one-line comment saying so, so that it isn't changed back to > 0 or to a bare truth test.
  • The rename is not in this PR: TheRedDaemon agreed to renaming the field, and that rename hasn't been done yet. predatorNearby keeps its name here, because renaming it is a Tribe.hpp change that also touches UpdateDeer.cpp and the drafts in Reimpl/TribesState development #279. It changes no code, so we can add it here as a header commit (predatorScareTimer, as gynt suggested) if you would like it now, or leave it for the Ghidra sync.

Style fixes in the touched files

  • updateAnimalHerdBehaviorState's unit loop is a for, as the style guide asks. Its index still steps in the body, right after the call, as the original's add esi, 1 at 0x005235D4 does; stepped in the loop's header, the match is lost. A one-line comment says so.
  • The two x = x + 1 steps are ++x (the style guide's rule 29; prefix, as everywhere on main; the same listing).
  • field_0x288 keeps its placeholder name: it counts the ticks towards spawnIntervalTicks and is cleared when they are reached. Naming it is a header change, so it is left for the Ghidra sync.

Measured

  • Setup: the bundled MSVC1400-SP1 against the Steam 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.
  • Full build: an all-on build of the previous cut of this branch on main 0e4a83b (the same code: this cut changes only the comment above each test), with both resolver sets on and main's own /GL list (neither file is on it), and with 0x004314E0 (the MapEditorLandscaping_GeneralButtons handler) left out and its resolver off, as in main's baseline: 0 failed of 2,425 compile steps, 99.58 over 2,441 functions. trySpawnAdditionalWildlifeForTribe and updateAnimalHerdBehaviorState read 100.0 raw and normalised there, with no diff entry (98.7 and 98.0, both 95.2 normalised, in the same build of main). Two main functions read lower, and it is how reccmp prints a constant, not their code: Menu::handleMenuItems (0x004F6280) reads 97.9 (91.4 normalised) and Menu::Constructor_Menu (0x004F4100) 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, five compares in all; in this build's layout a symbol of our DLL lies at exactly that address, so reccmp prints the constant as that symbol's name on our side, and the instructions are the same on both sides (UI: the single-player game launch at 100% #466 describes the same two readings). Every other function reads exactly what it read before; against main's own build (made at f489b72, 2,439 functions) the only other changes are main's since then (One more UI::MenuModals function at 100%: ProgressBarBox #467's MenuModalRenderFunction_ProgressBarBox and its constructor, UI: the single-player game launch at 100% #466's LaunchSinglePlayerGameUnk) (unrounded 99.5787 raw and 99.5512 normalised, 2,325 functions at 100.0 raw; with those two at 100.0, 99.5802 and 99.5567, 2,327; main 0e4a83b alone: 99.5788 and 99.5528 over 2,441, 2,325 at 100.0).
  • Our narrower run: main's /GL list (the 133 files that exist) and the two files in this PR's texts (built before the last change to the two predatorNearby comments, which leaves the listing the same), with their resolvers on: each of the two reads 100.0% raw and normalised with no diff entry, and every other function reads as in the same build without them.
  • Checks: our local style checker gives 0 ERROR and 1 CHECK (the placeholder name field_0x288, below). Our local fixer finds nothing to change.
  • Not run in game.

Looked at in the same pass, nothing to change in the source

Other functions on main that read below 100% only because reccmp names an operand on one side and not the other (the instructions and addresses agree):

  • moveTribeToNearbyClearTile (98.4%): the loop's end address (the table's end + 4) is named cached+4 on our side and not named on the original's. Both loops anchor the pointer on XYPair::y and run 0x140 bytes, so main's status remark ("anchors on XYPair::x") describes an earlier version; gynt's Reimpl/TribesState methods that are 100% #277 note on the end address's encoding is the current reading. We left the line alone, since Reimpl/TribesState development #279 changes the lines next to it; happy to correct it here if you prefer.
  • TicksSinceCounterStart (88.7%): the performance counter's address, which reccmp does not pair although it prints the same name on both sides, and the float constants.
  • RenderHistoryBookEdgeUnk (85.7%): the float constants and _ftol2_sse.
  • initializeDirectDraw (99.2%), createDirectPlayInterfaceModem (98.7%) and createWindow (98.4%): the DirectDraw and DirectPlay import thunks and the callbacks' trampolines.
  • RenderActiveCreditsElements (95.0%): _ftol2_sse, the float constants and the loop's end address.
  • PlayJokeVideoBasedOnCurrentTimeAndPlayTime (91.3%): the 26 operands into FLAG_JokeAIMessageArray, not named on the original's side.

🤖 Generated with Claude Code

kotijekriv and others added 2 commits November 23, 2026 09:06
…again

The original tests the tribe's predatorNearby with `cmp word ptr [eax + ecx + 0x2a0], 0` and `jne` (0x005260D3,
0x005260E0). gynt's first version had `!= 0` and read 100%. 374411d (2026-11-09) wrote `> 0`, because the field
is not a flag: it counts the ticks since the herd was scared. On the ushort, `> 0` compiles to `ja`, the function's
one differing instruction in a full build (98.7% raw, 95.2% normalised). `!= 0` is the same test on a ushort and
gives the original's `jne`; a one-line comment says why.

The tick counter's `field_0x288 = field_0x288 + 1` is `++field_0x288`, as the style fixer writes it (the same
listing). No other change.

Measured: a real build (main's /GL list and the two files of this branch, 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, 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>
The original tests the tribe's predatorNearby with `cmp word ptr [eax + 0x2a0], 0` and `jne` (0x005235AA,
0x005235B6). gynt's first version had `== 0` (then `!= 0`) and read 100%. 374411d (2026-11-09) wrote `> 0`,
because the field is not a flag: it counts the ticks since the herd was scared. On the ushort, `> 0` compiles to
`ja`, the function's one differing instruction in a full build (98.0% raw, 95.2% normalised). `!= 0` is the same
test on a ushort and gives the original's `jne`; a one-line comment says why.

The unit loop is a `for` now, as the style guide asks. Its index still steps in the body, right after the call, as
the original's `add esi, 1` at 0x005235D4 does (stepped in the loop's header, the match is lost), and it is written
`++unitSelectionIndex`, as the style fixer writes it. No other change.

Measured: a real build (main's /GL list and the two files of this branch, 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, 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>
@gynt
gynt added this pull request to the merge queue Nov 24, 2026
Merged via the queue into sourcehold:main with commit 96e44c9 Nov 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants