Skip to content

UpdateUnitLossSpeechFeedback at 100%: two sums the original's way - #482

Merged
gynt merged 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/units-D-unitloss-100
Nov 24, 2026
Merged

gynt merged 1 commit into
sourcehold:mainfrom
kotijekriv:reimpl/units-D-unitloss-100

Conversation

@kotijekriv

@kotijekriv kotijekriv commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

UpdateUnitLossSpeechFeedback is TheRedDaemon's reimplementation on main (#148, where he left the rest of the match open). This changes two sums in it, turns its text annotations into // lines and adds three comments; no header changes. The commit credits him as co-author.

Function Address Before After
Audio::SFX::UpdateUnitLossSpeechFeedback 0x0044B840 84.0% (status), 84.4% / 63.8% in a full build of main 100.0%: 99.6% raw; normalised 100.0% in our narrow builds, 95.2% in a full build (one data name, see below)

What changed. Two sums written the way the original adds them; nothing else in the function's code:

  • The destroyed-buildings history at the end is summed, cleared and shifted with three loops (sum, reset, shift). The original keeps [0] in ecx, [1] in edi, [2] in esi, [3] in edx and the zero in ebx (0x0044BBF0 .. 0x0044BC08). Written out as statements, the same values get the next registers in turn. A comment says why the reset stops at [3]: the shift right after gives [4] the zero from [3].
  • The enemies' total over the past nine rounds (the second RelativeValueForGenie argument) is written out and grouped, (T[1] + T[2] + T[3]) + (T[9] + T[8]) + (T[7] + T[6]) + (T[4] + T[5]): that is what gives the original's additions, [4] + [5], [6] .. [9], then [3], [2] and [1] (0x0044BA10 .. 0x0044BA5E). As a loop, like the player's total next to it, it starts with [3] + [4]. The comment above it says so.
  • For the record: the rest already compiles to the original's code once the call to RelativeValueForGenie (0x0044AAB0, same file, 100%) goes to its definition here, as it does whenever the file is built. The original keeps three history values in registers across the first call (0x0044B9F4) and adds them into the second sums.

What is left (one line, not code). The per-enemy loop ends with cmp ecx, <end> (0x0044BBB8), where <end> is 392 bytes past the start of Dat_UnitValueLossesHistoryPerEnemyPlayer, beyond its end. Both sides compare with that same place. reccmp names it after what lies there in each binary: DAT_SFXAmbientEventCountersRescaled[8] in the original, and in ours whatever our DLL happens to place there. In our narrow builds that was a data proxy (DAT_TotalUnitValueLossesEnemyHistory[8]), so both sides were names and normalised read 100.0. In a full build no symbol of our DLL lies there and our side is a bare address, which the normaliser does not equate with a name: 95.2 normalised. Either way it is the layout of the DLL's data, not this function's code, so the status line records 100.0% as main does for a loop-end data name (#304, #323, #405).

Measured.

  • Setup: the bundled MSVC1400-SP1 against the Steam Stronghold Crusader.exe (3bb0a8c1…5387ac5a), both resolver sets 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 two comments and the status line), with both resolver sets on and main's own /GL list (this file is not on it), and with 0x004314E0 (the MapEditorLandscaping_GeneralButtons handler) left out and its resolver off, as in main's baseline: 0 failed, 99.58 over 2,441 functions. UpdateUnitLossSpeechFeedback reads 99.6% raw there (84.4% in the same build of main) with the one diff line above, and 95.2% normalised (63.8% on main): in this build's data layout no symbol of our DLL lies at the loop's end address, so our side reads as the bare address 0x12D83008 where the original's reads as DAT_SFXAmbientEventCountersRescaled[8], and reccmp's normaliser does not equate the two; the instruction is the same. Its callee UpdateUnitLossSpeechFeedback_RelativeValueForGenie reads 100.0 as before. 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, and in this 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.5835 raw and 99.5601 normalised, 2,323 functions at 100.0 raw; with the two 0x11000000 readings at 100.0, 99.5850 and 99.5656, 2,325; main 0e4a83b alone: 99.5788 and 99.5528 over 2,441, 2,325 at 100.0.
  • Our own narrower run: real builds of our units stack's head (Reimplement 47 UnitsState functions at 100% and restyle 28 more #378 and the units on it; every header this file includes is the same there as on main 0e4a83b), with this file in the build list and off /GL, as on main: 99.6% raw and 100.0% normalised, the one diff line above, RelativeValueForGenie 100.0%; none of the other 350 functions reads differently from the build with only the first change (97.0% / 85.2% there), and that build changed no function against the same build without this file.
  • With main 45767c4 merged in: the same source reads 95.6% raw (79.3% normalised). Besides the loop-end line above, the enemies' total over the past nine rounds (the second RelativeValueForGenie argument) is built in edx where the original builds it in ecx: the registers tie in the allocator, and main's changes since 0e4a83b moved the tie the other way, the same as for LaunchSinglePlayerGameUnk on main. The source is unchanged.
  • Not run in game.

Checks: openshc-pr-check gives 0 ERROR and 1 CHECK: the reset loop's bound 4 is not the array's length on purpose (it clears [0] .. [3] of the five entries; [4] gets [3] from the shift right after), and the comment above the loop says so. clang-format 23.1.3 changes nothing.

Other PRs

No open PR touches the file or its status line. The commit merges with every open PR exactly as main does: git merge-tree against the heads of all 100 open PRs gives no conflict that main does not already have.

🤖 Generated with Claude Code

…code

Audio::SFX::UpdateUnitLossSpeechFeedback, TheRedDaemon's text on main (his commits cdb11e1 to 6aa57e7 at 84%
and fd55ea8's type change, then Gynt's style passes cadac92 and e218f79), with two sums written the
original's way. It reads 99.6 raw and is recorded as 100.0, as main does for a function whose only diff is a
data name: the one line left is a name, not code (see the end). The rest of the function is his.

1. The five-entry history of destroyed buildings at the function's end is summed, cleared and shifted with three
   loops: the sum (`i < countof(...)`) behind the `[0] > 1` test, the reset of [0] .. [3] and the shift
   (`for (i = 4; i > 0; --i)`). The original keeps [0] in ecx, [1] in edi, [2] in esi, [3] in edx and the zero in
   ebx (0x0044BBF0 .. 0x0044BC08) and sums [1] + [2], [3], [4], [0] (0x0044BC4B .. 0x0044BC56). With the
   statements written out the compiler hands the same values the next registers in turn ([0] in eax, the zero in
   edi, the sum in ebx).
2. The enemies' total over the nine past rounds (the second RelativeValueForGenie call's argument) is written
   out, grouped as (T[1] + T[2] + T[3]) + (T[9] + T[8]) + (T[7] + T[6]) + (T[4] + T[5]): that gives the original's
   additions, [4] + [5], [6] .. [9], then [3] and the two values kept in registers, [2] and [1] (0x0044BA10 ..
   0x0044BA5E). As a loop, like the player's total next to it (which already gives the original's [3] + [4] ..
   [9], [2], [1]), it starts with [3] + [4].
3. Nothing else needed changing: the rest already compiles to the original's code once the call to the helper
   RelativeValueForGenie (0x0044AAB0, in this file, 100.0) goes to its definition here, as it does whenever the
   file is in the build. The original keeps three history values in edi, ebx and ebp across the first call
   (0x0044B9F4) and adds them into the second sums (0x0044BA4E, 0x0044BA5C, 0x0044BA5E).
4. The `/* "..." */` text annotations as `// "..."` lines (SG 19), and two comments: why the reset stops at
   [3] and why the enemies' total is written out rather than a loop.

Measured with real builds of a local branch made of sourcehold#378 and our open Map::Units PRs on it (every header this file
includes is the same there as on main 0e4a83b), its build list plus this file, BUILD_OK each, the file off the
/GL list as on main. With item 1 only: 97.0 / 85.2, and no other function reads differently from the same build
without this file. This text: 99.6 raw / 100.0 normalised, RelativeValueForGenie 100.0 / 100.0, and no other
function reads differently from the item-1 build. The one diff line left is the per-enemy loop's end compare
(0x0044BBB8): both sides compare with the same place, 392 bytes past the start of
Dat_UnitValueLossesHistoryPerEnemyPlayer (beyond its end), and reccmp names it after the array that follows the
history in each binary: DAT_SFXAmbientEventCountersRescaled[8] in the original, the data proxy our DLL has there
(DAT_TotalUnitValueLossesEnemyHistory[8] in this build). That is the layout of the DLL's data, not this function's
code. (The original's side has a name only when the build list holds a file that includes
DAT_SFXAmbientEventCountersRescaled, such as updateAmbientSoundStream.cpp; the last build did, the item-1 build did
not.) In an all-on build of main with the same code no symbol of our DLL lies at that place, so our side reads as
a bare address there: 99.6 raw and 95.2 normalised (84.4 / 63.8 on main), the instruction the same. No other
function's code reads differently there; two of main's read lower only because reccmp prints the constant
0x11000000 as a symbol in that layout, as sourcehold#466 describes.

Co-authored-by: TheRedDaemon <66257843+TheRedDaemon@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 aeaabd0 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