From 5ae53478ef828f4a3a52eeaccce5692f6fccbb50 Mon Sep 17 00:00:00 2001 From: kotijekriv Date: Sun, 22 Nov 2026 09:21:23 +0100 Subject: [PATCH] reimplement: SHC_3BB0A8C1_0x0042A480 100.0% Reimplemented LobbyMenu::MenuItemRenderFunction_LobbyMenu_SkirmishTypeAndBalance, from Gynt's draft (5f8890aec7 at 75.21% on his fork's reimpl/UI-MenuItems-development; 41.8% at f45fb619bf on his closed #254's reimpl/UI-MenuItems, 50.17% at ed70d66816 and 63.07% at 04a1f23b9e on his fork). The drafts are the decompiler's output and have the original's control flow. One test is changed against the 75.21% text: the trail test is isSkirmishTrail == TRUE again, as the original compares the flag with 1 (0x0042A6D4) and as his other copies have it (his 75.21% commit had changed it to a truth test for the match; the store in both arms below makes == TRUE match). Rewritten against the original instructions: - returns per button, and a flag for the three AI setup dialogs in front, as MapSelectTable has it; - the arguments of the panel's first text (blend, y, x, the game type's index) are locals in the order they are pushed: the original holds all four at once (from 0x0042A580); written into the nested call, the type was loaded first (quick_diff 0.9730 to 0.9932); - in the pressed draw the draw target is set back in both arms of the test that follows it. The original keeps 0 and 1 in ebx and ebp through the function. With the target set back once, in front of the test, and the trail test as == TRUE, the two get each other's register and every line that uses them differs; with a truth test the registers are right and the test's two lines are left (99.3%). Set back in both arms, the compiler joins the two stores in front of the branch itself (0x0042A813, the same instructions as one store there), and the registers are the original's. As far as we can tell, it chooses them while the stores are still in the arms; - the gold is StartGoldPerFairnessLevel[type - 1][balance - 1][0] and [1] (the 75.21% text's field451_0x53bb4[(balance + type * 5) * 2 + 12] and + 13, the same addresses), times 3 on the extreme trail; - (int)skirmishCurrentAdvantageBalance: the original compares it signed (the field is undefined4 in the header). 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 same build without the file has 143 functions, and each of them reads the same. Both builds had the file as committed but for its comments (two worded differently, the others not yet written); quick_diff gives the same 296 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 --- ...ction_LobbyMenu_SkirmishTypeAndBalance.cpp | 169 ++++++++++++++++++ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 170 insertions(+), 1 deletion(-) create mode 100644 src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_SkirmishTypeAndBalance.cpp diff --git a/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_SkirmishTypeAndBalance.cpp b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_SkirmishTypeAndBalance.cpp new file mode 100644 index 0000000000..143a9a3cef --- /dev/null +++ b/src/OpenSHC/UI/MenuItems/LobbyMenu/MenuItemRenderFunction_LobbyMenu_SkirmishTypeAndBalance.cpp @@ -0,0 +1,169 @@ +#include "../LobbyMenu.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/Rendering.func.hpp" +#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/TrailType.hpp" +#include "OpenSHC/IO/Graphics/GmID.hpp" +#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp" +#include "OpenSHC/Rendering/Enums/RenderTarget.hpp" +#include "OpenSHC/Text/TextAlignment.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_ButtonBackgroundBlendStrength.hpp" +#include "OpenSHC/Globals/DAT_ButtonCurrentlyInteracting.hpp" +#include "OpenSHC/Globals/DAT_ButtonUnknownZero.hpp" +#include "OpenSHC/Globals/DAT_ButtonX.hpp" +#include "OpenSHC/Globals/DAT_ButtonY.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonGmDataIndex.hpp" +#include "OpenSHC/Globals/DAT_CurrentButtonPictureInGm.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp" +#include "OpenSHC/Globals/DAT_UIButtonDefinedData.hpp" + +namespace OpenSHC { +namespace UI { + namespace MenuItems { + + // FUNCTION: STRONGHOLDCRUSADER 0x0042A480 + void LobbyMenu::MenuItemRenderFunction_LobbyMenu_SkirmishTypeAndBalance(int buttonID, ...) + { + if (MACRO_CALL(OpenSHC::UI::Helpers_Func::AModalDialogIsActiveButIsNotQuitting)()) { + return; + } + // DAT_ButtonUnknownZero is set for the host while one of three AI setup dialogs is open, and for a guest + BOOLEnum const aiSetupOpen + = DAT_MenuModalComposition1::instance.activeModalDialogID == OpenSHC::UI::Enums::MMT_ROUNDTABLE + || DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_BASIC_AI_LORD_SELECT + || DAT_MenuModalComposition1::instance.activeModalDialogID + == OpenSHC::UI::Enums::MMT_EXTENDED_AI_LORD_SELECT; + if (aiSetupOpen) { + DAT_ButtonUnknownZero::instance = TRUE; + } + if (!aiSetupOpen || !DAT_GameSynchronyState::instance.isHost) { + DAT_ButtonUnknownZero::instance = FALSE; + if (!DAT_GameSynchronyState::instance.isHost) { + DAT_ButtonCurrentlyInteracting::instance = FALSE; + DAT_ButtonUnknownZero::instance = TRUE; + } + } + // the balance buttons (10 on) draw nothing; button 4 draws the bar + if (buttonID < 20 && buttonID >= 10) { + return; + } + // the fade is written the long way round, as the original computes it; it comes back to the blend strength + // 4: the balance bar and its marker + if (buttonID == 4) { + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 674, + DAT_ButtonX::instance, DAT_ButtonY::instance, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, + DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance + 674, + DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance * 70 - 50 + DAT_ButtonX::instance, + DAT_ButtonY::instance, (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + // 20: the game type, who the balance favours, and each side's starting gold + if (buttonID == 20) { + // the arguments in locals, in the order they are pushed (written into the call, the match is lost) + int const blend = (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32; + int const y = DAT_ButtonY::instance + 1; + int const x = DAT_ButtonX::instance + 180; + int const index = DAT_GameSynchronyState::instance.skirmishGameIntensityType - 1; + // "Normal Game", "Crusader Game" or "Deathmatch Game" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_GAME_TYPE, index), + x, y, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, 17, FALSE, blend); + if ((int)DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance < 3) { + // "Human Advantage" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_GAME_TYPE, 3, DAT_ButtonX::instance + 180, + DAT_ButtonY::instance + 26, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, + 19, FALSE, (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + if ((int)DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance > 3) { + // "Computer Advantage" + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextFromTextGroup, + DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_GAME_TYPE, 4, DAT_ButtonX::instance + 180, + DAT_ButtonY::instance + 26, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_CCFAFF, + 19, FALSE, (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)(OpenSHC::IO::Graphics::GID_INTERFACE_ICONS_2, 730, + DAT_ButtonX::instance + 165, DAT_ButtonY::instance + 41, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + // the extreme trail's skirmishes start with three times the gold; the original compares the flag with 1 + int goldMultiplier = 1; + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SKIRMISH_AND_MULTIPLAYER + && DAT_GameCore::instance.isSkirmishTrail == TRUE + && DAT_GameCore::instance.currentTrailType == OpenSHC::Game::TT_EXTREME) { + goldMultiplier = 3; + } + // the human side's starting gold, then the computer side's + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_RenderingDefinedData::instance + .StartGoldPerFairnessLevel[DAT_GameSynchronyState::instance.skirmishGameIntensityType + - 1][DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance - 1][0] + * goldMultiplier, + DAT_ButtonX::instance + 110, DAT_ButtonY::instance + 48, OpenSHC::Text::TTA_CENTER, + OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumberToScreen2, DAT_TextManagerObject::ptr)( + DAT_RenderingDefinedData::instance + .StartGoldPerFairnessLevel[DAT_GameSynchronyState::instance.skirmishGameIntensityType + - 1][DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance - 1][1] + * goldMultiplier, + DAT_ButtonX::instance + 250, DAT_ButtonY::instance + 48, OpenSHC::Text::TTA_CENTER, + OpenSHC::Rendering::Colors::COL_CCFAFF, 18, FALSE, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + return; + } + if (buttonID > 3) { + return; + } + // 1 to 3: the game types, the chosen one drawn pressed + if (buttonID == DAT_GameSynchronyState::instance.skirmishGameIntensityType) { + int const picture + = DAT_UIButtonDefinedData::instance.ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .pictureInGm_0x4 + + 1; + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_SCREEN_MENU; + MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, + DAT_TextureRenderCoreObject::ptr)((OpenSHC::IO::Graphics::GmID)DAT_UIButtonDefinedData::instance + .ButtonGmDataArray[DAT_CurrentButtonGmDataIndex::instance] + .gmId_0x0, + picture, DAT_ButtonX::instance, DAT_ButtonY::instance, + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + DAT_CurrentButtonPictureInGm::instance = picture; + // the original reads the type again behind the draw. The draw target goes back in both arms: set back + // once, in front of this test, the match is lost + if (buttonID == DAT_GameSynchronyState::instance.skirmishGameIntensityType) { + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue + = OpenSHC::Rendering::Enums::RT_MAP_GAME; + return; + } + DAT_TextureRenderCoreObject::instance.drawBufferChoiceValue = OpenSHC::Rendering::Enums::RT_MAP_GAME; + } + // not the chosen type, or no longer after the draw: the plain button + MACRO_CALL(OpenSHC::UI::Rendering_Func::RenderCurrentButtonToScreenMenuWithBlendingUnk)( + (DAT_ButtonBackgroundBlendStrength::instance - 32) * 32 / 32 + 32); + } + + } +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b62540e14f..2cb9660dd0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -6935,7 +6935,7 @@ SHC_3BB0A8C1_0x0042A470 | 0.0% | Pending SHC_3BB0A8C1_0x0042A474 | 0.0% | Pending -SHC_3BB0A8C1_0x0042A480 | 0.0% | Pending +SHC_3BB0A8C1_0x0042A480 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0042A840 | 100.0% | Reimplemented