From f9fabb0343cdfb0ea46ce2dff7886256ffee4892 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 14:47:00 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x00433370 100.0% Reimplemented InGameMenu::MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange, rewritten against the original instructions from Gynt's draft (d5895e2c4c at 29.4%, the file's newest commit on his fork's reimpl/UI-MenuItems; before it 24.6% at 668d05f689, 26.74% at cee8a6a83c and 35.68% at 1831d1480a; 29.1% at 8725ec5232 on his reimpl/UI-MenuItems-development; the 24.6% text, as cf563c2ba6, on 20 of his other branches). The rewrite was first in our draft #328 (85.2% at ecef1ca639, 93.3% at b730ba65bd). One thing in the behaviour differs from his newest copies, as the original has it: the frame's copy (scribeAnimationFrameCopy) gets the frame after a step of phase 0 or 2, where his 29% texts (from 65a026cbb1 on) compare and store a local that those steps do not update (the original: 0x0043352B and 0x00433545 with the stepped value). The returns he got right himself: his 24.6% text has empty bodies for the three returns (0x00433378, 0x00433381, 0x004333AF), which he restored in cee8a6a83c (the 60 ms one) and 1831d1480a (the game modes); cee8a6a83c also returned behind every step and at a sequence's end, which he took out in 65a026cbb1 ("switch was unreachable"), as the original has it (0x00433485, 0x0043348A, 0x0043352B). Here the returns are the original's. The 93.3% text had the original's 129 instructions with one difference: the zero the compiler keeps in a register was in ebp, where the original has ebx (0x0043338F), and ebx was unused. Here: - the phase is the global itself at each use, not a local that is loaded from it and stored back. A local is one more candidate for a register and took one in front of the zero; with the global the compiler keeps the phase in edi itself (0x004333B5, 0x00433472) and the zero gets ebx; - the frame is written the same way (a local for it gives the same listing); - each entry of a setting's sequence is read into a local and tested (the 93.3% text read the table twice, which this form no longer needs); - the phase switch's cases are in the order 0, 1, 2, as the animation runs (the same listing). No line for cmake/compiler-flags-gl.txt: the file reads 100.0% off the /GL list, and 100.0% on it too. reccmp in a build of main's whole /GL list (the 133 files that exist) and this file, off the list, with every resolver of those files on: 144 functions, average 99.56. The function 100.0% raw and normalised, no differing line, and the same with the file on the list. The other 143 functions of main's list read the same as without the file. The sources are main's at 3458fea34; main's two commits since (02fab423c, 812d149696) add cmake files only, with the new option off. Co-authored-by: Gynt Co-Authored-By: Claude Fable 5.2 Co-Authored-By: Claude Opus 5.5 --- ...nGameMenu_ProcessScribeAnimationChange.cpp | 114 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange.cpp diff --git a/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange.cpp b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange.cpp new file mode 100644 index 0000000000..3f8a972bbd --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/InGameMenu/MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange.cpp @@ -0,0 +1,114 @@ +#include "../InGameMenu.func.hpp" + +#include "OpenSHC/Game/GameMode2.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x00433370 + void InGameMenu::MenuItemActionHandler_InGameMenu_ProcessScribeAnimationChange(int unused, ...) + { + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_EDITOR + || DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT) { + return; + } + int const slot = DAT_GameSynchronyState::instance.currentPlayerSlotID; + // while a tax setting is animated: one step every 60 milliseconds + if (DAT_GameCore::instance.taxesSettingUnk != 0) { + DWORD const now = timeGetTime(); + if ((int)(now - DAT_GameCore::instance.taxestimeUnk) < 60) { + return; + } + DAT_GameCore::instance.taxestimeUnk = now; + // the phase is read from the global at each use: kept in a local, it takes the register the original + // keeps the zero in + switch (DAT_GameCore::instance.scribeAnimationPhase) { + case 0: + // to frame 6 first, then phase 1 + if (DAT_GameCore::instance.scribeAnimationFrame < 6) { + ++DAT_GameCore::instance.scribeAnimationFrame; + } else if (DAT_GameCore::instance.scribeAnimationFrame > 6) { + --DAT_GameCore::instance.scribeAnimationFrame; + } else { + DAT_GameCore::instance.scribeAnimationPhase = 1; + } + break; + case 1: + // the next entry of the setting's sequence (below) + ++DAT_GameCore::instance.scribeAnimationFrame2; + break; + case 2: { + // back to the frame that shows the popularity; there the animation ends + int const target = (100 - DAT_GameState::instance.playerDataArray[slot].popularity / 100) / 10 + 1; + // a frame of a sequence (12 and up; the popularity's are 1 to 11): to frame 6 first + if (DAT_GameCore::instance.scribeAnimationFrame > 11) { + DAT_GameCore::instance.scribeAnimationFrame = 6; + } else if (DAT_GameCore::instance.scribeAnimationFrame > target) { + --DAT_GameCore::instance.scribeAnimationFrame; + } else if (DAT_GameCore::instance.scribeAnimationFrame < target) { + ++DAT_GameCore::instance.scribeAnimationFrame; + } else { + DAT_GameCore::instance.taxesSettingUnk = 0; + } + break; + } + } + } + // no setting: the frame that shows the popularity. Settings 1 to 3 in phase 1: the frame from the setting's + // sequence, which a 0 ends. + switch (DAT_GameCore::instance.taxesSettingUnk) { + case 0: + DAT_GameCore::instance.scribeAnimationFrame + = (100 - DAT_GameState::instance.playerDataArray[slot].popularity / 100) / 10 + 1; + break; + case 1: + if (DAT_GameCore::instance.scribeAnimationPhase == 1) { + int const entry = DAT_RenderingDefinedData::instance + .ScribeAnimationFrames1[DAT_GameCore::instance.scribeAnimationFrame2]; + if (entry != 0) { + DAT_GameCore::instance.scribeAnimationFrame = entry; + } else { + DAT_GameCore::instance.taxesSettingUnk = 0; + } + } + break; + case 2: + if (DAT_GameCore::instance.scribeAnimationPhase == 1) { + int const entry = DAT_RenderingDefinedData::instance + .ScribeAnimationFrames2[DAT_GameCore::instance.scribeAnimationFrame2]; + if (entry != 0) { + DAT_GameCore::instance.scribeAnimationFrame = entry; + } else { + DAT_GameCore::instance.taxesSettingUnk = 0; + } + } + break; + case 3: + if (DAT_GameCore::instance.scribeAnimationPhase == 1) { + int const entry = DAT_RenderingDefinedData::instance + .ScribeAnimationFrames3[DAT_GameCore::instance.scribeAnimationFrame2]; + if (entry != 0) { + DAT_GameCore::instance.scribeAnimationFrame = entry; + } else { + DAT_GameCore::instance.taxesSettingUnk = 0; + } + } + break; + } + // the frame changed, or the month did + if (DAT_GameCore::instance.scribeAnimationFrameCopy != DAT_GameCore::instance.scribeAnimationFrame + || DAT_GameState::instance.mapAndTime.monthChanged != 0) { + DAT_GameCore::instance.countdown = 1; + DAT_GameCore::instance.scribeAnimationFrameCopy = DAT_GameCore::instance.scribeAnimationFrame; + } + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..8e85285cdf 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -11089,7 +11089,7 @@ SHC_3BB0A8C1_0x00433230 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00433260 | 0.0% | Pending -SHC_3BB0A8C1_0x00433370 | 0.0% | Pending +SHC_3BB0A8C1_0x00433370 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00433550 | 0.0% | Pending