Skip to content

Reimplement 11 Map::Units functions from gynt's units branch (100%) - #390

Merged
gynt merged 19 commits into
sourcehold:mainfrom
kotijekriv:reimpl/units-A-round1-100
Nov 10, 2026
Merged

gynt merged 19 commits into
sourcehold:mainfrom
kotijekriv:reimpl/units-A-round1-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Eleven Map::Units functions at 100%, the first from gynt's units branch reimpl/map-units-updatefunctions (his draft #204), which he offered us on Discord on 2026-11-10. All 11 are his code. Each function is one commit authored by him: his file as on his branch at 48b79a2, with only the renames that main's headers need since his last merge. Our changes are separate commits on top.

Function Address gynt's status
Units::DetachLadderman 0x00530760 100.0%
Units::FindFirstOpponentWithKeep 0x0051BE20 100.0%
Units::IncrementAndOptionalUpdateAVValueRelated 0x00530B40 100.0%
Units::PlayStockpileIsFullWarning 0x00530EB0 100.0%
Units::SetRestingForUnit 0x00549B30 100.0%
Units::SetStateToFreetimeWalking 0x00530CF0 100.0%
Units::ComputeGoodsProduced 0x00530D70 78.0%
Units::PlayArmoryIsFullWarning 0x00530F20 80.4%
Units::WarnIfPlayersGranaryIsFull 0x00530E00 80.4%
Units::UpdateBurningAnimal1 0x005309E0 Pending
Units::UpdateBurningAnimal2 0x00530A90 Pending

The last five read 100% on today's main with his code unchanged. The headers his branch builds against have moved on since his status was written.

Where the code comes from:

Measured on main 847c77b.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), resolvers enabled locally (not committed), and sourcehold's reccmp with --resolve-wrapped-calls --ignore-security-cookie.
  • reccmp: a full build of the branch alone reads all 11 at 100.0% raw and normalized.
  • Style commits: quick_diff output is identical before and after each one, including the last one, which applies a fresh-eyes review: main's form for the three warnings' static guards (!(guard & TRUE), guard |= TRUE), buildingID names, no (short) casts.
  • Checks: openshc-pr-check gives no errors, and status_regression.py finds no score below a known one.
  • Not run in game.

Header changes (each in a commit of its own)

gynt's Ghidra sync 2bd620b brought all four to main. Main (39ed817) is merged in (6662533), so these commits now match main, and the "Declaration/type change validation" check passes. The 11 files' quick_diff output is identical before and after the merge.

Each is kept separate so the header change stands alone. Two of them (the work timers and the void return) don't build on their own; the style commits after them change the code to match.

  • DestinationNeededEnum gets DNE_UNKNOWN_2 (c9bd78b). SetRestingForUnit stores 2 at 0x00549BB7 and 0x00549C09.
  • UnitState gets US_UNKNOWN_121 (24ce8db). It is stored at 0x00530D43 (SetStateToFreetimeWalking) and 0x00530CD2 (ConsiderHavingABreakNowUnk, which comes in a later PR), and it is the resting state.
  • Unit's workTimer, workRelatedA, workRelatedB and workRelatedC become one int workTimers[4] at 0x2E8 (85955cb). IncrementAndOptionalUpdateAVValueRelated indexes it by the unit's working value at 0x00530B5C. No file on main uses the four names, and the struct's layout is unchanged.
  • PlayStockpileIsFullWarning returns void, in Units.hpp and in its resolver's signature (e9cbc59).
    • It was declared uint, but no file on main calls it, and the six callers in the decompilation ignore the result.
    • Its two siblings, PlayArmoryIsFullWarning and WarnIfPlayersGranaryIsFull, are void.
    • What eax holds at its end is only the quotient left over from the last % 5000.
    • Written like its siblings, the body compiles to the same code.

Kept as they are, measured with quick_diff (each has a one-line comment)

Function Kept The other form
ComputeGoodsProduced the divisor in a variable a literal 100: 0.9737 → 0.7561
ComputeGoodsProduced * 100 / 100 without it: 0.9737 → 0.4058
IncrementAndOptionalUpdateAVValueRelated the counter zeroed before the early return after it: 0.9811 → 0.9057

Proposed, not changed here

  • US_UNKNOWN_121 could be named as the resting state.
  • Unit::field_0x2fe is the flag main's CheckUnitProductionPaused (0x00530D50) tests with == 1. SetRestingForUnit sets it to 1 when the unit's resting animation starts, and to 0 when the unit gets up. productionPausedUnk would fit.
  • DAT_UnitHasBecomeIdle is undefined4, but it is only ever stored 1 or tested != 0, so it could be BOOLEnum. So could SetStateToFreetimeWalking's shouldFindNewGoodThing.
  • gynt's branch has more (DestinationNeededEnum)2 and (UnitState)121 uses, in 18 files (for example UpdateAppleFarmer, UpdateArmorer and ConsiderHavingABreakNowUnk). They take the new names in later rounds.
  • SetStateToFreetimeWalking's third parameter is the substate count. It is substateCount in the .cpp and still param_3 in Units.hpp.

Other PRs

🤖 Generated with Claude Code

gynt and others added 18 commits November 10, 2026 07:38
DetachLadderman, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a2 (his draft
sourcehold#204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32f (2026-11-02,
"style(map-units): own-namespace include first, and clang-format"). Taken unchanged (the build fix 43a17df had
nothing to rename here). What main needs on top follows in our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FindFirstOpponentWithKeep, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a2
(his draft sourcehold#204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32f
(2026-11-02, "style(map-units): own-namespace include first, and clang-format"). The build fix 43a17df follows
main's headers: PlayerData::keep becomes buildingEntryInfos[BEIE_KEEP], with BuildingEntryInfoEnum.hpp included;
nothing else changed. What main needs on top follows in our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IncrementAndOptionalUpdateAVValueRelated, gynt's version as it stands on his fork's
reimpl/map-units-updatefunctions at 48b79a2 (his draft sourcehold#204), where its status line reads 100.0% (Reimplemented);
the file was last changed in 974c32f (2026-11-02, "style(map-units): own-namespace include first, and
clang-format"). Taken unchanged (the build fix 43a17df had nothing to rename here). What main needs on top
follows in our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PlayStockpileIsFullWarning, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a2
(his draft sourcehold#204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32f
(2026-11-02, "style(map-units): own-namespace include first, and clang-format"). Taken unchanged (the build fix
43a17df had nothing to rename here). What main needs on top follows in our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SetRestingForUnit, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a2 (his
draft sourcehold#204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32f
(2026-11-02, "style(map-units): own-namespace include first, and clang-format"). The build fix 43a17df follows
main's headers: Unit::field166_0x2fe becomes field_0x2fe; nothing else changed. What main needs on top follows in
our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SetStateToFreetimeWalking, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a2
(his draft sourcehold#204), where its status line reads 100.0% (Reimplemented); the file was last changed in 974c32f
(2026-11-02, "style(map-units): own-namespace include first, and clang-format"). The build fix 43a17df follows
main's headers: Unit::field166_0x2fe becomes field_0x2fe, and the function returns BOOLEnum as main's Units.hpp
declares it (with BOOLEnum.hpp included); nothing else changed. What main needs on top follows in our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ComputeGoodsProduced, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a2 (his
draft sourcehold#204), where its status line reads 78.0% (idiv vs magic division); the file was last changed in c933f79
(2026-11-02, "Adopt the Wilps Map/Units bodies that measure better here (sourcehold#286)"). The body is Wilps's, from
reimpl/Wilps-2026-10-18, which gynt adopted in d914edf and merged in c933f79 (sourcehold#286). Taken unchanged (the build
fix 43a17df had nothing to rename here). With main's headers and both resolver sets on it now reads reccmp
100.0%. What main needs on top follows in our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PlayArmoryIsFullWarning, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a2
(his draft sourcehold#204), where its status line reads 80.4% (loop precheck scheduling); the file was last changed in
c933f79 (2026-11-02, "Adopt the Wilps Map/Units bodies that measure better here (sourcehold#286)"). The body is Wilps's,
from reimpl/Wilps-2026-10-18, which gynt adopted in d914edf and merged in c933f79 (sourcehold#286). Taken unchanged (the
build fix 43a17df had nothing to rename here). With main's headers and both resolver sets on it now reads reccmp
100.0%. What main needs on top follows in our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WarnIfPlayersGranaryIsFull, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a2
(his draft sourcehold#204), where its status line reads 80.4% (loop precheck scheduling); the file was last changed in
c933f79 (2026-11-02, "Adopt the Wilps Map/Units bodies that measure better here (sourcehold#286)"). The body is Wilps's,
from reimpl/Wilps-2026-10-18, which gynt adopted in d914edf and merged in c933f79 (sourcehold#286). Taken unchanged (the
build fix 43a17df had nothing to rename here). With main's headers and both resolver sets on it now reads reccmp
100.0%. What main needs on top follows in our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UpdateBurningAnimal1, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a2 (his
draft sourcehold#204), where its status line reads 0.0% (Pending); the file was last changed in c933f79 (2026-11-02, "Adopt
the Wilps Map/Units bodies that measure better here (sourcehold#286)"). It was first reimplemented in 7abe46b ("reimplement
UpdateBurningAnimal1 100%") and tidied by gynt in bef36eb. Taken unchanged (the build fix 43a17df had nothing
to rename here). With main's headers and both resolver sets on it now reads reccmp 100.0%. What main needs on top
follows in our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
UpdateBurningAnimal2, gynt's version as it stands on his fork's reimpl/map-units-updatefunctions at 48b79a2 (his
draft sourcehold#204), where its status line reads 0.0% (Pending); the file was last changed in c933f79 (2026-11-02, "Adopt
the Wilps Map/Units bodies that measure better here (sourcehold#286)"). It was first reimplemented in c4fba5a ("reimplement
UpdateBurningAnimal2 100%") and tidied by gynt in bef36eb. Taken unchanged (the build fix 43a17df had nothing
to rename here). With main's headers and both resolver sets on it now reads reccmp 100.0%. What main needs on top
follows in our own commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tions


openshc-pr-fix.py's mechanical pass over the eleven files: boost, updateAV and restedEnough are tested for truth
instead of against FALSE, and UpdateBurningAnimal1 and 2 lose their unused using declarations (UnitLogicState,
UnitState). quick_diff is the same for all eleven.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::SetRestingForUnit (0x00549B30) stores 2 in a unit's destinationNeeded twice (mov word ptr [esi + 0x13888C0],
2 at 0x00549BB7 and 0x00549C09: the units array at 0x0138854C plus the field's 0x374), when no building is found
and when the unit has rested enough. The enum has no value between DNE_DESTINATION_NEEDED (1) and
DNE_FLETCHER_SPECIFIC_COUNTDOWN (5); named in the DNE_UNKNOWN_<n> form. Used in place of (DestinationNeededEnum)2;
code generation is the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::SetStateToFreetimeWalking (0x00530CF0) and Units::ConsiderHavingABreakNowUnk (0x00530C40) put a unit into
state 121, the resting state (mov word ptr [ecx + 0x138880C], 0x79 at 0x00530D43 and 0x00530CD2: the units array
at 0x0138854C plus state at 0x2C0). The enum goes from US_STONE_DEATH_03 (116) to US_APPEAR (122); named in the
US_UNKNOWN_<n> form. Used in place of (UnitState)121; code generation is the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Unit::workTimer, workRelatedA, workRelatedB and workRelatedC (+0x2E8 to +0x2F4) are one int[4] indexed by
Unit::working (0 to 3): Units::IncrementAndOptionalUpdateAVValueRelated (0x00530B40) adds 1 to the current one with
add dword ptr [eax*4 + 0x1388834], 1 at 0x00530B5C (eax holding unitID * 292 plus working, in dwords; the units array is
at 0x0138854C), sums all four into av and clears the next one the same way. Nothing on main uses the four names,
and on this branch only that function does. This round's style commit then indexes workTimers there; code
generation is the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…omments


- SetRestingForUnit stores DNE_UNKNOWN_2 and SetStateToFreetimeWalking US_UNKNOWN_121 (header commits) in place of
  the casts; SetRestingForUnit tests hasUnitReachedDestination for truth, and SetStateToFreetimeWalking returns
  FALSE / TRUE and calls its third parameter substateCount (the count of substates it wraps around).
- IncrementAndOptionalUpdateAVValueRelated indexes workTimers (header commit) instead of (&workTimer)[i], with
  countof for the four; its count stays zeroed before the early return (after it: quick_diff 0.9811 -> 0.9057).
- ComputeGoodsProduced keeps its divisor variable (a literal 100: quick_diff 0.9737 -> 0.7561) and its * 100 / 100
  (without: 0.4058), each with a one-line comment, and its plate comment is a // line in the body.
- UpdateBurningAnimal1 and 2 lose the imported plate comment, store US_STATE_2Unk for 2, and name their two locals
  without the leading underscore, the animation bound on the right of the comparison.
- const for the locals assigned once (tile, currentPlayer twice, bonusPercentage, now), and
  PlayStockpileIsFullWarning's comment on its return value says what the code does.
quick_diff is the same for all eleven.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Units::PlayStockpileIsFullWarning (0x00530EB0) was declared to return uint, but nothing uses a result: no file on
main calls it, the six callers in the decompilation throw eax away, and its two siblings, PlayArmoryIsFullWarning and
WarnIfPlayersGranaryIsFull, are void. What eax holds at its end is the quotient of the last % 5000. It is void in
Units.hpp and in its resolver's signature in Units.func.hpp. With the body written like its siblings, quick_diff
output is identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- PlayStockpileIsFullWarning is written like its two siblings: void, an early return, and no quotient kept for eax.
- The three warnings' static guards use main's form (`!(guard & TRUE)`, `guard |= TRUE`), as in
  PlayJokeVideoBasedOnCurrentTimeAndPlayTime, so their BOOLEnum casts, usings and includes go.
- buildingID for the building loops and SetRestingForUnit's building, activeTimerCount for the count of active
  timers, and a truth test for shouldFindNewGoodThing.
- ComputeGoodsProduced drops its (short) casts (the fields are short) and its plate example, and its boost
  comment says every mode but solitary.
- SetRestingForUnit says why idle is tested against target twice.
- IncrementAndOptionalUpdateAVValueRelated loses a comment that repeated what the array says.
- A blank line before the namespaces close in both BurningAnimal files, as in the other nine.

quick_diff output is identical for all 11 files, with -s.

Co-authored-by: Gynt <gynt@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 10, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the declaration/type change This requires changes to the generated/exported types or definitions. label Nov 10, 2026
@gynt
gynt added this pull request to the merge queue Nov 10, 2026
Merged via the queue into sourcehold:main with commit 62ed179 Nov 10, 2026
4 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