From b4ff106eb3db8883f4fbd006cddf4bf27030f12f Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Mon, 23 Nov 2026 08:20:58 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x0044B840 100.0% Reimplemented, identical code Audio::SFX::UpdateUnitLossSpeechFeedback, TheRedDaemon's text on main (his commits cdb11e1a29 to 6aa57e7a16 at 84% and fd55ea89c3's type change, then Gynt's style passes cadac925ba and e218f79878), 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 #378 and our open Map::Units PRs on it (every header this file includes is the same there as on main 0e4a83b5d2), 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 #466 describes. Co-authored-by: TheRedDaemon <66257843+TheRedDaemon@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- .../SFX/UpdateUnitLossSpeechFeedback.cpp | 72 +++++++++++-------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/src/OpenSHC/Audio/SFX/UpdateUnitLossSpeechFeedback.cpp b/src/OpenSHC/Audio/SFX/UpdateUnitLossSpeechFeedback.cpp index 2b27f7203f..34ef2a0e0f 100644 --- a/src/OpenSHC/Audio/SFX/UpdateUnitLossSpeechFeedback.cpp +++ b/src/OpenSHC/Audio/SFX/UpdateUnitLossSpeechFeedback.cpp @@ -71,17 +71,26 @@ namespace Audio { smallPlayerUnitLossesSum, smallTotalEnemyUnitLossesSum); int playerUnitLossesSum = 0; - int totalEnemyUnitLossesSum = 0; for (int i = 1; i < 10; ++i) { playerUnitLossesSum += DAT_CurrentPlayerUnitLossesHistory::instance[i]; - totalEnemyUnitLossesSum += DAT_TotalUnitValueLossesEnemyHistory::instance[i]; } + // grouped so the additions run in the original's order, [4] + [5], [6] .. [9], [3], [2], [1]; + // as a loop like the player's sum above, they start with [3] + [4] + int totalEnemyUnitLossesSum = (DAT_TotalUnitValueLossesEnemyHistory::instance[1] + + DAT_TotalUnitValueLossesEnemyHistory::instance[2] + + DAT_TotalUnitValueLossesEnemyHistory::instance[3]) + + (DAT_TotalUnitValueLossesEnemyHistory::instance[9] + + DAT_TotalUnitValueLossesEnemyHistory::instance[8]) + + (DAT_TotalUnitValueLossesEnemyHistory::instance[7] + + DAT_TotalUnitValueLossesEnemyHistory::instance[6]) + + (DAT_TotalUnitValueLossesEnemyHistory::instance[4] + + DAT_TotalUnitValueLossesEnemyHistory::instance[5]); int _relative2 = MACRO_CALL(SFX_Func::UpdateUnitLossSpeechFeedback_RelativeValueForGenie)( playerUnitLossesSum, totalEnemyUnitLossesSum); if (_relative1 == 0 && _relative2 == 0) { if (DAT_GameCore::instance.genieVoiceActive) { - /* "A Valliant Effort" */ + // "A Valliant Effort" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_29_wav_005a4ecc); } DAT_GL_Counter::instance = 0; @@ -90,25 +99,25 @@ namespace Audio { _relative1 = (_relative2 + _relative1) / 2; if (DAT_GameCore::instance.genieVoiceActive) { if (_relative1 == 1) { - /* "Majestic" */ + // "Majestic" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_30_wav_005a4ebc); } else if (_relative1 == 2) { - /* "Excellent" */ + // "Excellent" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_31_wav_005a4eac); } else if (_relative1 == 3) { - /* "Impressive" */ + // "Impressive" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_32_wav_005a4e9c); } else if (_relative1 == 4) { - /* "Glorious" */ + // "Glorious" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_34_wav_005a4e8c); } else if (_relative1 == 5) { - /* "For the crown" */ + // "For the crown" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_37_wav_005a4e7c); } else if (_relative1 == 6) { - /* "Heroic" */ + // "Heroic" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_38_wav_005a4e6c); } else if (_relative1 >= 7) { - /* "It's a Rout" */ + // "It's a Rout" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_39_wav_005a4e5c); } } @@ -118,16 +127,16 @@ namespace Audio { int averageRelativeValue = (_relative2 + _relative1) / 2; if (DAT_GameCore::instance.genieVoiceActive) { if (averageRelativeValue == -1) { - /* "Vanquished" */ + // "Vanquished" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_42_wav_005a4e4c); } else if (averageRelativeValue == -2) { - /* "Crest falling" */ + // "Crest falling" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_43_wav_005a4e3c); } } if (averageRelativeValue <= -3) { if (DAT_GameCore::instance.genieVoiceActive) { - /* "Humiliated" */ + // "Humiliated" MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_44_wav_005a4e2c); } int playerId = -1; @@ -157,25 +166,26 @@ namespace Audio { for (int i = 0; i < 9; ++i) { DAT_UnitValueLossesPerEnemyPlayer::instance[i] = 0; } - if (DAT_DestroyedBuildingsCountHistory::instance[0] > 1 - && DAT_DestroyedBuildingsCountHistory::instance[4] + DAT_DestroyedBuildingsCountHistory::instance[3] - + DAT_DestroyedBuildingsCountHistory::instance[2] - + DAT_DestroyedBuildingsCountHistory::instance[1] - + DAT_DestroyedBuildingsCountHistory::instance[0] - > 5) { - if (DAT_GameCore::instance.genieVoiceActive) { - /* "Where is your Castle" */ - MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_41_wav_005a4e1c); - } - DAT_DestroyedBuildingsCountHistory::instance[0] = 0; - DAT_DestroyedBuildingsCountHistory::instance[1] = 0; - DAT_DestroyedBuildingsCountHistory::instance[2] = 0; - DAT_DestroyedBuildingsCountHistory::instance[3] = 0; + // the sum, the reset and the shift as loops: written out, the compiler gives them other registers + if (DAT_DestroyedBuildingsCountHistory::instance[0] > 1) { + int destroyedSum = 0; + for (int i = 0; i < countof(DAT_DestroyedBuildingsCountHistory::instance); ++i) { + destroyedSum += DAT_DestroyedBuildingsCountHistory::instance[i]; + } + if (destroyedSum > 5) { + if (DAT_GameCore::instance.genieVoiceActive) { + // "Where is your Castle" + MACRO_CALL_MEMBER(SFXState_Func::playWAVSFX, DAT_SFXState::ptr)(s_Genie_41_wav_005a4e1c); + } + // all but the last entry: the shift below gives [4] the zero from [3] + for (int i = 0; i < 4; ++i) { + DAT_DestroyedBuildingsCountHistory::instance[i] = 0; + } + } + } + for (int i = 4; i > 0; --i) { + DAT_DestroyedBuildingsCountHistory::instance[i] = DAT_DestroyedBuildingsCountHistory::instance[i - 1]; } - DAT_DestroyedBuildingsCountHistory::instance[4] = DAT_DestroyedBuildingsCountHistory::instance[3]; - DAT_DestroyedBuildingsCountHistory::instance[3] = DAT_DestroyedBuildingsCountHistory::instance[2]; - DAT_DestroyedBuildingsCountHistory::instance[2] = DAT_DestroyedBuildingsCountHistory::instance[1]; - DAT_DestroyedBuildingsCountHistory::instance[1] = DAT_DestroyedBuildingsCountHistory::instance[0]; DAT_DestroyedBuildingsCountHistory::instance[0] = 0; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index e8a6864d03..9e04d8e0ed 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16871,7 +16871,7 @@ SHC_3BB0A8C1_0x0044B7D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0044B800 | 0.0% | Pending -SHC_3BB0A8C1_0x0044B840 | 84.0% | Reimplemented, but heavy register mismatch. Logic seems sound, though. +SHC_3BB0A8C1_0x0044B840 | 100.0% | Reimplemented, identical code; the loop-end compare (past the per-enemy history) is the next global's symbol in the original, unnamed or another global in ours SHC_3BB0A8C1_0x0044B890 | 0.0% | Pending