From a4b4b37147adc2970000dd18f5519a2efa61f884 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 11:08:56 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x00447A50 100.0% Reimplemented StatusMenus::RenderStatusMenu_Chimp, from Gynt's draft (67318e1120 at 56.7% on his fork's reimpl/UI-StatusMenus-development). That draft is the decompiler's output and computes what the original computes; no behaviour is changed against it. His earlier copies (47.57% at c8bfbb774e; 49.6% at 9ec9106508, his closed #251) go on after switching back to the build menu for an empty slot; he recovered that return in 109e64fb60 (51.5%, sourcehold's reimpl/UI-StatusMenus), and it is here as in the original (0x00447A84). Rewritten against the original instructions: - the flag for a newly selected unit is cleared in front of the getPeasantGmID call (the original zeroes its register there, 0x00447A8C) and set behind it, as in his 56.7% draft; - the name text is most likely TextManager::renderTextFromTextGroup (0x00424470), inlined. Its body is renderTextToScreen(getTextStringInGroupAtOffset(group, index), x, y, ...), and the original has these two calls in both arms of the ghost test with the outer arguments pushed once in front of the branch (from 0x00447AD2), the lookup's this loaded in front of it too (0x00447AF1) and the first name's index in edx. Written out as the two nested calls the instructions are the same, but the three temporaries get their registers in another order and this cannot be loaded in front of the branch (87.5%). Called through its resolver the function is not inlined in our builds (75.7% with a copy of it in the build, both files on the /GL list; quick_diff 0.8593 with its body in the same unit). So the file has an inline static copy of it, with its name, its parameter types and its body and the text manager global in place of this, as Gynt's draft #373 has copies of ViewportRenderState::xyAreValid in three files; inline, static inline and __forceinline give the same listing; - the current-action call is written at the end of both arms: the original evaluates its coordinates in each arm (0x00447B98, 0x00447BC5) and shares the push of the unit and the call (0x00447BDF). 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), this file and our own copy of TextManager::renderTextFromTextGroup (not part of this commit; this file does not call it), all off the list, with every resolver of those files on: 145 functions, average 99.57. The function 100.0% raw and normalised, no differing line, and the same with both files on the list. The other 143 functions of main's list read the same as without the two files. Both builds had an earlier text of this file (one unused include more, other comments, and other names for the copy and for two locals); quick_diff gives the same 195 instructions, line for line, for that text and for this one. 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 --- .../UI/StatusMenus/RenderStatusMenu_Chimp.cpp | 130 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Chimp.cpp diff --git a/src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Chimp.cpp b/src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Chimp.cpp new file mode 100644 index 0000000000..4197e2bed2 --- /dev/null +++ b/src/OpenSHC/UI/StatusMenus/RenderStatusMenu_Chimp.cpp @@ -0,0 +1,130 @@ +#include "../StatusMenus.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_00b95b6c.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_MenuHandlerState.hpp" +#include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/INT_00b96124.hpp" +#include "OpenSHC/Globals/INT_00b98458.hpp" + +namespace OpenSHC { +namespace UI { + + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // inlined copy of TextManager::renderTextFromTextGroup (0x00424470), which the original has inlined below. + // Called through its resolver it stays a call, with /GL too. + inline static void renderTextFromTextGroup(OpenSHC::DE::SHCDE::eTextSections group, int index, int x, int y, + OpenSHC::Text::TextAlignment alignment, uint color, int fontSize, BOOLEnum keepOffsetX, int blendStrength) + { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(group, index), + x, y, alignment, color, fontSize, keepOffsetX, blendStrength); + } + + // FUNCTION: STRONGHOLDCRUSADER 0x00447A50 + void StatusMenus::RenderStatusMenu_Chimp() + { + int const unitID = DAT_BuildingsState::instance.menuSelectedUnitID; + if (unitID == 0) { + return; + } + int const type = DAT_UnitsState::instance.units[unitID].unitType; + // no unit in that slot any more: back to the build menu + if (type == 0) { + MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + OpenSHC::UI::Enums::MVT_BUILD_MENU, 0); + return; + } + // a newly shown unit (not the one shown last) speaks its comment (below) + BOOLEnum newUnit = FALSE; + // the result is not used: the original makes the call all the same + MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::getPeasantGmID, DAT_UnitsState::ptr)(unitID); + if (unitID != INT_00b96124::instance) { + INT_00b96124::instance = unitID; + newUnit = TRUE; + } + // 1: the unit type's sketch, which the menu's Prepare loads + MACRO_CALL_MEMBER( + OpenSHC::UI::Rendering::TextureRenderCore_Func::renderLoadedGfx, DAT_TextureRenderCoreObject::ptr)( + 1, DAT_MenuHandlerState::instance.x + 14, DAT_MenuHandlerState::instance.y + 489); + // the first name, the surname if it has one, and the unit type (none for the five animals); a ghost has + // its type only. The type is read from the unit again: the original compares it in memory here. + if (DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_GHOST) { + renderTextFromTextGroup(OpenSHC::DE::SHCDE::TEXT_PEASANT_NAMES, + DAT_UnitsState::instance.units[unitID].firstNameIndex, DAT_MenuHandlerState::instance.x + 140, + DAT_MenuHandlerState::instance.y + 481, OpenSHC::Text::TTA_LEFT, 0, 17, FALSE, 0); + char const surnameIndex = DAT_UnitsState::instance.units[unitID].rng1_to_70; + if (surnameIndex != 0) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_PEASANT_SURNAMES, surnameIndex, DAT_MenuHandlerState::instance.x + 145, + DAT_MenuHandlerState::instance.y + 481, OpenSHC::Text::TTA_LEFT, 0, 17, TRUE); + } + if (type != OpenSHC::Map::Units::UT_COW && type != OpenSHC::Map::Units::UT_CHICKEN + && type != OpenSHC::Map::Units::UT_HUNTERDOG && type != OpenSHC::Map::Units::UT_QUARRYOX + && type != OpenSHC::Map::Units::UT_TRADERHORSE) { + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderText2, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_CHIMP_NAMES, type, DAT_MenuHandlerState::instance.x + 160, + DAT_MenuHandlerState::instance.y + 486, OpenSHC::Text::TTA_LEFT, 0, 18, TRUE); + } + // what the unit is doing; written in both arms, as the original evaluates the arguments in each + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderPeasantMenu_CurrentActionUnk)( + unitID, DAT_MenuHandlerState::instance.x + 140, DAT_MenuHandlerState::instance.y + 521); + } else { + renderTextFromTextGroup(OpenSHC::DE::SHCDE::TEXT_CHIMP_NAMES, type, DAT_MenuHandlerState::instance.x + 140, + DAT_MenuHandlerState::instance.y + 481, OpenSHC::Text::TTA_LEFT, 0, 17, FALSE, 0); + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderPeasantMenu_CurrentActionUnk)( + unitID, DAT_MenuHandlerState::instance.x + 140, DAT_MenuHandlerState::instance.y + 521); + } + // the comment, chosen once per selected unit; these types have none + if (type != OpenSHC::Map::Units::UT_LADY && type != OpenSHC::Map::Units::UT_LORD + && type != OpenSHC::Map::Units::UT_COW && type != OpenSHC::Map::Units::UT_CHICKEN + && type != OpenSHC::Map::Units::UT_HUNTERDOG && type != OpenSHC::Map::Units::UT_QUARRYOX + && type != OpenSHC::Map::Units::UT_TRADERHORSE && type != OpenSHC::Map::Units::UT_CAGEDOG + && type != OpenSHC::Map::Units::UT_FIREEATER && type != OpenSHC::Map::Units::UT_JUGGLER + && type != OpenSHC::Map::Units::UT_DRUNK && type != OpenSHC::Map::Units::UT_GHOST + && type != OpenSHC::Map::Units::UT_CHILD) { + int commentID = DAT_00b95b6c::instance; + if (commentID == -1) { + commentID = MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::selectWorkerSpeechOrMoraleStateID, + DAT_UnitsState::ptr)(unitID); + DAT_00b95b6c::instance = commentID; + } + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderMultilineTextUnk, DAT_TextManagerObject::ptr)( + OpenSHC::DE::SHCDE::TEXT_CHIMP_COMMENT, commentID, DAT_MenuHandlerState::instance.x + 140, + DAT_MenuHandlerState::instance.y + 557, 350, 0, 18, 0); + if (newUnit) { + // the tanner, the mother and the brewer have the female voice + if (type == OpenSHC::Map::Units::UT_TANNER || type == OpenSHC::Map::Units::UT_MOTHER + || type == OpenSHC::Map::Units::UT_BREWER) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSpeechSFXFile, DAT_SFXState::ptr)( + DAT_RenderingDefinedData::instance.FemalePeasantSFXNames[commentID]); + } else { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSpeechSFXFile, DAT_SFXState::ptr)( + DAT_RenderingDefinedData::instance.MalePeasantSFXNames[commentID]); + } + INT_00b98458::instance = commentID; + } + } + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..020a665118 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16365,7 +16365,7 @@ SHC_3BB0A8C1_0x00447A48 | 0.0% | Pending SHC_3BB0A8C1_0x00447A4C | 0.0% | Pending -SHC_3BB0A8C1_0x00447A50 | 0.0% | Pending +SHC_3BB0A8C1_0x00447A50 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00447CF0 | 100.0% | Reimplemented