From 7b58b39568eb60970eeaeb33bf09e644d1640834 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 13:56:17 +0100 Subject: [PATCH 01/60] Copy 16 functions from gynt's catch-all branches to reimpl/mission-skirmish-flow Their best match lives only on gynt's catch-all branches, which are ~2080 cpp files ahead of their merge base and 412 commits behind main. The cpp files are copied unchanged, without the headers of those branches: - gynt/reimpl/UI-Core-development@10280b161 (1) - gynt/reimpl/UI-DisplayElements-pr-development@fbc092e15 (15) Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Audio/SFX/ComputePlayerRanking.cpp | 77 + .../Game/Skirmish/SetupSkirmishMode.cpp | 160 + .../SkirmishLeaderboard_DeleteEntry.cpp | 46 + .../restoreSkirmishLobbySetup.cpp | 98 + .../Skirmish_PrepareLeaderboardView.cpp | 219 ++ .../Game/Skirmish/StoreGameIntoSKMasters.cpp | 86 + src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp | 118 + .../adjustEventMonthAndYearForSection1047.cpp | 39 + .../computeMissionCompletionScore.cpp | 327 ++ .../Map/MapPropertiesState/loadMap.cpp | 273 ++ .../loadMapSiegeHeaderForMissionIndex.cpp | 39 + .../loadMissionMapAndSetLord.cpp | 42 + .../processSingleplayerEvents.cpp | 2704 +++++++++++++++++ .../spawnInvasionEventAttackWave.cpp | 241 ++ .../Synchrony/LoadSkirmishCampaignData.cpp | 135 + .../UI/MenuTextInputState/loadOrSaveGame.cpp | 125 + 16 files changed, 4729 insertions(+) create mode 100644 src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp create mode 100644 src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp create mode 100644 src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp create mode 100644 src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp create mode 100644 src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp create mode 100644 src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp create mode 100644 src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp create mode 100644 src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp create mode 100644 src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp create mode 100644 src/OpenSHC/Map/MapPropertiesState/loadMap.cpp create mode 100644 src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp create mode 100644 src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp create mode 100644 src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp create mode 100644 src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp create mode 100644 src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp create mode 100644 src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp diff --git a/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp b/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp new file mode 100644 index 0000000000..8b4afa3a5b --- /dev/null +++ b/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp @@ -0,0 +1,77 @@ +#include "../../Audio.func.hpp" + +#include "OpenSHC/Audio/SFX.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Audio { + + /* + variable _playerPointsArray made by gynt decompilerscript: committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x0044B680 + int SFX::ComputePlayerRanking(int playerID) + { + int _playerID; + int _highestPointsUnk; + undefined4 _deadPlayerList[10]; + int _playerPointsArray[9][2]; + _playerPointsArray[0][0] = 0; + _playerPointsArray[1][0] = 0; + _playerPointsArray[2][0] = 0; + _playerPointsArray[3][0] = 0; + _playerPointsArray[4][0] = 0; + _playerPointsArray[5][0] = 0; + _playerPointsArray[6][0] = 0; + _playerPointsArray[7][0] = 0; + _playerPointsArray[8][0] = 0; + int _arrayIndex = 0; + for (_playerID = 1; _playerID < 9; _playerID++) { + if (DAT_GameSynchronyState::instance.finalResults.active[_playerID] != 0) { + _playerPointsArray[_arrayIndex][0] = _playerID; + int _isAlive = MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::getAliveLordForPlayer, DAT_UnitsState::ptr)(_playerID); + if (!_isAlive) { + if (_playerID == playerID) { + return 0; + } + _deadPlayerList[_playerID] = 1; + _playerPointsArray[_arrayIndex][1] = 0; + } else { + int _playerPoints = MACRO_CALL(Audio::SFX_Func::ComputePlayerPoints1)(_playerID); + _playerPointsArray[_arrayIndex][1] = _playerPoints; + } + _arrayIndex = _arrayIndex + 1; + } + } + int _index = 0; + if (0 < _arrayIndex) { + do { + int _highestPointsIndex = -1; + int _index2 = 0; + do { + if ((_playerPointsArray[_index2][0] != 0) + && ((_highestPointsIndex == -1 || (_highestPointsUnk < _playerPointsArray[_index2][1])))) { + _highestPointsUnk = _playerPointsArray[_index2][1]; + _highestPointsIndex = _index2; + } + _index2 = _index2 + 1; + } while (_index2 < _arrayIndex); + if (_highestPointsIndex < 0) { + return 0; + } + if (_playerPointsArray[_highestPointsIndex][0] == playerID) { + return _index + 1; + } + _index = _index + 1; + _playerPointsArray[_highestPointsIndex][0] = 0; + } while (_index < _arrayIndex); + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp new file mode 100644 index 0000000000..f5c1ba66d1 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp @@ -0,0 +1,160 @@ +#include "../../Game.func.hpp" +#include "../Skirmish.func.hpp" + +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/Actions.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/TrailType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_SkirmishDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { +namespace Game { + + using Commands::GameCommandType; + using Game::GameMode; + using Game::GameMode2; + using Game::TrailType; + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004C68D0 + void Skirmish::SetupSkirmishMode(int skirmishTrailMission) + { + char cVar1; + int* piVar2; + char* pcVar3; + int iVar4; + int iVar5; + char (*pacVar6)[250]; + CampaignTrailMission* pCVar7; + dword _startDateInMonths; + pCVar7 = DAT_SkirmishDefinedData::instance.SkirmishTrailMissions + skirmishTrailMission; + if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { + pCVar7 = DAT_SkirmishDefinedData::instance.ExtremeTrailMissions + skirmishTrailMission; + } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { + pCVar7 = DAT_SkirmishDefinedData::instance.WarchestTrailMissions + skirmishTrailMission; + } + MACRO_CALL_MEMBER( + Synchrony::GameSynchronyState_Func::setupSkirmishLobby, DAT_GameSynchronyState::ptr)(); + DAT_GameSynchronyState::instance.isHost = TRUE; + DAT_GameSynchronyState::instance.currentGameMode = Game::GM_SKIRMISH_SINGLE_PLAYER; + DAT_GameSynchronyState::instance.DPLAYX_ReceivedPlayerID = 1; + DAT_GameCore::instance.gameMode_2 = Game::GM_SKIRMISH_AND_MULTIPLAYER; + MACRO_CALL(OS_Func::_memset)( + DAT_GameSynchronyState::instance.DAT_PlayerNames, 0, (size_t)((int)(2250))); + piVar2 = DAT_GameSynchronyState::instance.currentAIArray; + do { + piVar2[-0x1b] = -1; + *piVar2 = 0; + piVar2[9] = -1; + piVar2 = piVar2 + 1; + } while ((int)piVar2 < 0x191dea0); + pcVar3 = MACRO_CALL_MEMBER( + Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0); + pacVar6 = DAT_GameSynchronyState::instance.DAT_PlayerNames + 1; + do { + cVar1 = *pcVar3; + (*pacVar6)[0] = cVar1; + pcVar3 = pcVar3 + 1; + pacVar6 = (char (*)[250])(*pacVar6 + 1); + } while (cVar1 != '\0'); + MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + Commands::GCT_ASK_FOR_SLOT_ASSIGNMENT); + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[0] = 1; + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[1] = 1; + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[2] = 1; + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[3] = 1; + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[4] = 1; + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[5] = 1; + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[6] = 1; + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[7] = 1; + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[8] = 1; + DAT_GameSynchronyState::instance.skirmishRelated1 = -1; + DAT_GameCore::instance.mapU4Int0 = 0; + if (1 < pCVar7->numberOfPlayers) { + piVar2 = &pCVar7->player2AI; + iVar4 = 1; + do { + iVar5 = iVar4 + 1; + DAT_GameSynchronyState::instance.currentAIArray[iVar4 + 1] = *piVar2; + MACRO_CALL(Synchrony_Func::ResetAiVariationArrayValue)(iVar5); + piVar2 = piVar2 + 1; + iVar4 = iVar5; + } while (iVar5 < pCVar7->numberOfPlayers); + } + DAT_GameSynchronyState::instance.playerPositionsArray[0] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[1] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[2] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[3] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[4] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[5] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[6] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[7] = -10; + iVar4 = 0; + piVar2 = &pCVar7->position1; + do { + if (*piVar2 != 0) { + DAT_GameSynchronyState::instance.playerPositionsArray[*piVar2 - 1] = (char)iVar4; + } + iVar4 = iVar4 + 1; + piVar2 = piVar2 + 1; + } while (iVar4 < 8); + iVar4 = pCVar7->numberOfPlayers; + iVar5 = 0; + piVar2 = &pCVar7->team1; + do { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5 + 1] = (byte)*piVar2; + if (iVar4 <= iVar5) { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5 + 1] = 0xff; + } + iVar5 = iVar5 + 1; + piVar2 = piVar2 + 1; + } while (iVar5 < 8); + pcVar3 = (char *)(pCVar7->mapNameAddress); + iVar4 = 0x1a22f9c - (int)pcVar3; + do { + cVar1 = *pcVar3; + pcVar3[iVar4] = cVar1; + pcVar3 = pcVar3 + 1; + } while (cVar1 != '\0'); + DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance = pCVar7->fairness; + DAT_GameSynchronyState::instance.skirmishGameIntensityType = pCVar7->startLevels; + piVar2 = &pCVar7->aiv1; + DAT_GameCore::instance.isSkirmishTrail = TRUE; + if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { + DAT_GameCore::instance.extremeTrailProgress = skirmishTrailMission; + MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)piVar2); + _startDateInMonths + = DAT_GameCore::instance.extremeTrailStartDatesInMonths[DAT_GameCore::instance.extremeTrailProgress]; + DAT_GameCore::instance.extremeTrailStartDateMonths = _startDateInMonths; + } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { + DAT_GameCore::instance.warchestTrailProgress = skirmishTrailMission; + MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)piVar2); + _startDateInMonths + = DAT_GameCore::instance.warchestTrailStartDatesInMonths[DAT_GameCore::instance.warchestTrailProgress]; + DAT_GameCore::instance.warchestTrailStartDateMonths = _startDateInMonths; + } else { + DAT_GameCore::instance.skirmishTrailProgress = skirmishTrailMission; + MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)piVar2); + _startDateInMonths + = DAT_GameCore::instance.skirmishTrailStartDateInMonths[DAT_GameCore::instance.skirmishTrailProgress]; + DAT_GameCore::instance.skirmishTrailStartDateMonths = _startDateInMonths; + } + DAT_GameState::instance.mapAndTime.year = (int)_startDateInMonths / 0xc; + DAT_GameState::instance.mapAndTime.month = (int)_startDateInMonths % 0xc; + DAT_GameSynchronyState::instance.finalResults.yearStart = (int)_startDateInMonths / 0xc; + DAT_GameSynchronyState::instance.finalResults.monthStart = (int)_startDateInMonths % 0xc; + } + +} +} diff --git a/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp b/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp new file mode 100644 index 0000000000..44d6704073 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp @@ -0,0 +1,46 @@ +#include "../../Game.func.hpp" +#include "../Skirmish.func.hpp" + +#include "OpenSHC/IO.func.hpp" + +#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp" + +namespace OpenSHC { +namespace Game { + + /* + This removes the skirmish leaderboard entry at a given index by shifting all subsequent entries down by one, + decrementing the count, and saving to disk. It's the delete operation for the SkMasters2 high score / results + table — likely called when the player deletes a saved skirmish result from the UI. decompilerscript: + committed: 2025-01-30 21:57:43.216000 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004D5370 + void Skirmish::SkirmishLeaderboard_DeleteEntry(int index) + { + SkMasterDataEntry* pSVar1; + int iVar2; + SkMasterDataEntry* pSVar3; + SkMasterDataEntry* pSVar4; + if ((-1 < index) && (index < DAT_SkMasters2Data_Count::instance)) { + if (index < DAT_SkMasters2Data_Count::instance + -1) { + pSVar1 = DAT_SkMasters2DataArray::instance + index; + do { + pSVar3 = pSVar1 + 1; + pSVar4 = pSVar1; + for (iVar2 = 0x2fc; iVar2 != 0; iVar2 = iVar2 + -1) { + pSVar4->score = pSVar3->score; + pSVar3 = (SkMasterDataEntry*)pSVar3->mapName; + pSVar4 = (SkMasterDataEntry*)pSVar4->mapName; + } + index = index + 1; + pSVar1 = pSVar1 + 1; + } while (index < DAT_SkMasters2Data_Count::instance + -1); + } + DAT_SkMasters2Data_Count::instance = DAT_SkMasters2Data_Count::instance + -1; + MACRO_CALL(IO_Func::WriteSkMasters2)(); + } + } + +} +} diff --git a/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp b/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp new file mode 100644 index 0000000000..5973d3aed5 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp @@ -0,0 +1,98 @@ +#include "../../../Game.func.hpp" +#include "../SkirmishLobbySetupStructure.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/INT_00b960b0.hpp" + +namespace OpenSHC { +namespace Game { + namespace Skirmish { + + // FUNCTION: STRONGHOLDCRUSADER 0x00490060 + void SkirmishLobbySetupStructure::restoreSkirmishLobbySetup() + { + char cVar1; + char* pcVar2; + DAT_GameSynchronyState::instance.skirmishAutoSaveEveryMinutes = this->mapu4int2; + pcVar2 = this->mapName; + this->mbr_0x4 = DAT_GameState::instance.mapAndTime.skirmishFogOfWar; + do { + cVar1 = *pcVar2; + pcVar2[0xc2ee7c] = cVar1; + pcVar2 = pcVar2 + 1; + } while (cVar1 != '\0'); + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[0] = this->roundTableOrderArray[0]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[0] = this->playerGroupArray[0]; + DAT_GameSynchronyState::instance.currentAIArray[0] = this->currentAIArray[0]; + DAT_GameSynchronyState::instance.aiVariationArray[0] = this->aiVariationArray[0]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[1] = this->roundTableOrderArray[1]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[1] = this->playerGroupArray[1]; + DAT_GameSynchronyState::instance.currentAIArray[1] = this->currentAIArray[1]; + DAT_GameSynchronyState::instance.aiVariationArray[1] = this->aiVariationArray[1]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[2] = this->roundTableOrderArray[2]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[2] = this->playerGroupArray[2]; + DAT_GameSynchronyState::instance.currentAIArray[2] = this->currentAIArray[2]; + DAT_GameSynchronyState::instance.aiVariationArray[2] = this->aiVariationArray[2]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[3] = this->roundTableOrderArray[3]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[3] = this->playerGroupArray[3]; + DAT_GameSynchronyState::instance.currentAIArray[3] = this->currentAIArray[3]; + DAT_GameSynchronyState::instance.aiVariationArray[3] = this->aiVariationArray[3]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[4] = this->roundTableOrderArray[4]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[4] = this->playerGroupArray[4]; + DAT_GameSynchronyState::instance.currentAIArray[4] = this->currentAIArray[4]; + DAT_GameSynchronyState::instance.aiVariationArray[4] = this->aiVariationArray[4]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[5] = this->roundTableOrderArray[5]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[5] = this->playerGroupArray[5]; + DAT_GameSynchronyState::instance.currentAIArray[5] = this->currentAIArray[5]; + DAT_GameSynchronyState::instance.aiVariationArray[5] = this->aiVariationArray[5]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[6] = this->roundTableOrderArray[6]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[6] = this->playerGroupArray[6]; + DAT_GameSynchronyState::instance.currentAIArray[6] = this->currentAIArray[6]; + DAT_GameSynchronyState::instance.aiVariationArray[6] = this->aiVariationArray[6]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[7] = this->roundTableOrderArray[7]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[7] = this->playerGroupArray[7]; + DAT_GameSynchronyState::instance.currentAIArray[7] = this->currentAIArray[7]; + DAT_GameSynchronyState::instance.aiVariationArray[7] = this->aiVariationArray[7]; + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[8] = this->roundTableOrderArray[8]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[8] = this->playerGroupArray[8]; + DAT_GameSynchronyState::instance.currentAIArray[8] = this->currentAIArray[8]; + DAT_GameSynchronyState::instance.aiVariationArray[8] = this->aiVariationArray[8]; + DAT_GameSynchronyState::instance.playerPositionsArray[0] = this->slot1Position; + DAT_GameSynchronyState::instance.playerPositionsArray[1] = this->slot2Position; + DAT_GameSynchronyState::instance.playerPositionsArray[2] = this->slot3Position; + DAT_GameSynchronyState::instance.playerPositionsArray[3] = this->slot4Position; + DAT_GameSynchronyState::instance.playerPositionsArray[4] = this->slot5Position; + DAT_GameSynchronyState::instance.playerPositionsArray[5] = this->slot6Position; + DAT_GameSynchronyState::instance.playerPositionsArray[6] = this->slot7Position; + DAT_GameSynchronyState::instance.playerPositionsArray[7] = this->slot8Position; + DAT_GameSynchronyState::instance.currentPlayerSlotID = this->currentPlayerSlotID; + DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance = this->currentAdvantageBalance; + DAT_GameSynchronyState::instance.skirmishGameIntensityType = this->currentAdvantageGroup; + DAT_GameSynchronyState::instance.skirmishTechLevel = this->mbr_0x80; + DAT_GameCore::instance.selectedLordTypes[0] = this->playerLordTypeArray[0]; + DAT_GameCore::instance.selectedLordTypes[1] = this->playerLordTypeArray[1]; + DAT_GameCore::instance.selectedLordTypes[2] = this->playerLordTypeArray[2]; + DAT_GameCore::instance.selectedLordTypes[3] = this->playerLordTypeArray[3]; + DAT_GameCore::instance.selectedLordTypes[4] = this->playerLordTypeArray[4]; + DAT_GameCore::instance.selectedLordTypes[5] = this->playerLordTypeArray[5]; + DAT_GameCore::instance.selectedLordTypes[6] = this->playerLordTypeArray[6]; + DAT_GameCore::instance.selectedLordTypes[7] = this->playerLordTypeArray[7]; + DAT_GameCore::instance.selectedLordTypes[8] = this->playerLordTypeArray[8]; + DAT_GameCore::instance.field152_0x2340 = this->mbr_0xf0; + DAT_GameCore::instance.selectedLordTypeUnk = this->selectedLordType; + DAT_GameSynchronyState::instance.skirmishDefaultPopularity = this->popularity; + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected = this->mapSelectionRelativeSelected; + DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset = this->mapSelectionScrollOffset; + INT_00b960b0::instance = this->mapSelectionScrollOffset + this->mapSelectionRelativeSelected; + DAT_GameSynchronyState::instance.lobbyMapSortOrder = this->mbr_0xfc; + MACRO_CALL_MEMBER( + Synchrony::GameSynchronyState_Func::reorderTeamsAndPositions, DAT_GameSynchronyState::ptr)(); + } + + } +} +} diff --git a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp new file mode 100644 index 0000000000..35136f3b38 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp @@ -0,0 +1,219 @@ +#include "../../Game.func.hpp" + +#include "OpenSHC/Game/Skirmish.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" + +#include "OpenSHC/Globals/DAT_00eb9b60.hpp" +#include "OpenSHC/Globals/DAT_00ed3124.hpp" +#include "OpenSHC/Globals/DAT_MissionDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/INT_00eb0e44.hpp" +#include "OpenSHC/Globals/INT_00ed2bdc.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00eb0e48.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00eb96d8.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00ed27f0.hpp" +#include "OpenSHC/Globals/INT_ARRAY_00ed2be0.hpp" + +namespace OpenSHC { +namespace Game { + + using DE::SHCDE::eTextSections; + + // FUNCTION: STRONGHOLDCRUSADER 0x004D9400 + void Skirmish::Skirmish_PrepareLeaderboardView() + { + char cVar1; + int iVar2; + byte bVar3; + int _index; + SkMasterDataEntry* puVar7; + char* pcVar4; + int _index2; + SkMasterDataEntry* _pSkMasters_01; + SkMasterDataEntry* _pSkMasters_02; + int* piVar5; + byte bVar6; + int iVar7; + SkMasterDataEntry* pSVar8; + char* pcVar9; + int _count; + uint _month; + uint _year; + _count = DAT_SkMasters2Data_Count::instance; + /* + Phase 1: Initialize visibility filter + */ + if (0 < DAT_SkMasters2Data_Count::instance) { + piVar5 = INT_ARRAY_00eb0e48::instance; + for (_index2 = DAT_SkMasters2Data_Count::instance; _index2 != 0; _index2 = _index2 + -1) { + *piVar5 = 1; + piVar5 = piVar5 + 1; + } + } + iVar7 = DAT_00ed3124::instance; + if (DAT_00ed3124::instance == 1) { + _index = 0; + if (0 < _count) { + _pSkMasters_01 = DAT_SkMasters2DataArray::instance; + do { + if (!_pSkMasters_01->score) { + INT_ARRAY_00eb0e48::instance[_index] = 0; + } + _index = _index + 1; + _pSkMasters_01 = _pSkMasters_01 + 1; + } while (_index < _count); + } + } else if ((DAT_00ed3124::instance == 2) && (_index = 0, 0 < _count)) { + _pSkMasters_02 = DAT_SkMasters2DataArray::instance; + do { + if (_pSkMasters_02->score) { + INT_ARRAY_00eb0e48::instance[_index] = 0; + } + _index = _index + 1; + _pSkMasters_02 = _pSkMasters_02 + 1; + } while (_index < _count); + } + /* + Phase 2: Sort column dispatch + */ + if (DAT_MissionDefinedData::instance.sortColumn < 2) { + iVar7 = 0; + DAT_00eb9b60::instance = 0; + if (DAT_MissionDefinedData::instance.descending == 1) { + _index = 0; + if (0 < _count) { + do { + if (INT_ARRAY_00eb0e48::instance[_index] != 0) { + INT_ARRAY_00eb96d8::instance[iVar7] = _index; + iVar7 = iVar7 + 1; + } + _index = _index + 1; + } while (_index < _count); + DAT_00eb9b60::instance = iVar7; + } + } else if ((!DAT_MissionDefinedData::instance.descending) && (0 < _count)) { + piVar5 = INT_00eb0e44::ptr + _count; + _index = _count; + do { + _index = _index + -1; + if (*piVar5 != 0) { + INT_ARRAY_00eb96d8::instance[iVar7] = _index; + iVar7 = iVar7 + 1; + } + piVar5 = piVar5 + -1; + _count = _count + -1; + } while (_count); + DAT_00eb9b60::instance = iVar7; + } + } else { + if (DAT_MissionDefinedData::instance.sortColumn == 4) { + _index = 0; + iVar7 = 0; + DAT_00eb9b60::instance = 0; + if (0 < _count) { + puVar7 = DAT_SkMasters2DataArray::ptr[0]; + do { + if (INT_ARRAY_00eb0e48::instance[iVar7] != 0) { + _year = puVar7->localTimeYear; + _month = puVar7->localTimeMonth; + INT_ARRAY_00ed27f0::instance[_index] = iVar7; + _index = _index + 1; + (INT_00ed2bdc::ptr)[_index] + = ((_year - 2000) * 0x10 + _month) * 0x20 + puVar7->localTimeDay; + } + iVar7 = iVar7 + 1; + puVar7 = puVar7 + 0x2fc; + DAT_00eb9b60::instance = _index; + } while (iVar7 < _count); + } + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + } + if (DAT_MissionDefinedData::instance.sortColumn == 2) { + _index = 0; + DAT_00eb9b60::instance = 0; + if (iVar7 == 1) { + iVar7 = 0; + if (0 < _count) { + pSVar8 = DAT_SkMasters2DataArray::instance; + do { + if (INT_ARRAY_00eb0e48::instance[iVar7] != 0) { + iVar2 = pSVar8->score; + INT_ARRAY_00ed27f0::instance[_index] = iVar7; + INT_ARRAY_00ed2be0::instance[_index] = 0x50 - iVar2; + _index = _index + 1; + } + iVar7 = iVar7 + 1; + pSVar8 = pSVar8 + 1; + } while (iVar7 < _count); + DAT_00eb9b60::instance = _index; + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + } + } else { + iVar7 = 0; + if (0 < _count) { + pSVar8 = DAT_SkMasters2DataArray::instance; + do { + if (INT_ARRAY_00eb0e48::instance[iVar7] != 0) { + if (pSVar8->score) { + pcVar4 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)( + DE::SHCDE::TEXT_TRAIL_NAMES_CRU, pSVar8->score); + pcVar9 = pSVar8->mapName; + do { + cVar1 = *pcVar4; + *pcVar9 = cVar1; + pcVar4 = pcVar4 + 1; + pcVar9 = pcVar9 + 1; + _index = DAT_00eb9b60::instance; + _count = DAT_SkMasters2Data_Count::instance; + } while (cVar1 != '\0'); + } + bVar6 = pSVar8->mapName[0]; + if ((byte)(bVar6 + 0xbf) < 0x1a) { + bVar6 = bVar6 + 0x20; + } + bVar3 = pSVar8->mapName[1]; + if ((byte)(bVar3 + 0xbf) < 0x1a) { + bVar3 = bVar3 + 0x20; + } + INT_ARRAY_00ed2be0::instance[_index] = ((uint)bVar6 * -0x100 + -1) - (uint)bVar3; + INT_ARRAY_00ed27f0::instance[_index] = iVar7; + _index = _index + 1; + DAT_00eb9b60::instance = _index; + } + iVar7 = iVar7 + 1; + pSVar8 = pSVar8 + 1; + } while (iVar7 < _count); + } + } + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + } + if (DAT_MissionDefinedData::instance.sortColumn == 3) { + _index = 0; + iVar7 = 0; + DAT_00eb9b60::instance = 0; + if (0 < _count) { + piVar5 = &DAT_SkMasters2DataArray::instance[0].gameDurationInMinutes; + do { + if (INT_ARRAY_00eb0e48::instance[iVar7] != 0) { + iVar2 = *piVar5; + INT_ARRAY_00ed27f0::instance[_index] = iVar7; + INT_ARRAY_00ed2be0::instance[_index] = -1 - iVar2; + _index = _index + 1; + } + iVar7 = iVar7 + 1; + piVar5 = piVar5 + 0x2fc; + DAT_00eb9b60::instance = _index; + } while (iVar7 < _count); + } + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + } + } + } + +} +} diff --git a/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp b/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp new file mode 100644 index 0000000000..d45eb6d60f --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp @@ -0,0 +1,86 @@ +#include "../../Game.func.hpp" + +#include "OpenSHC/Game/Skirmish.func.hpp" +#include "OpenSHC/IO.func.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_SkMasterDataEntry.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp" + +namespace OpenSHC { +namespace Game { + + using WindowsHelper::Enums::BOOLEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x004D52A0 + void Skirmish::StoreGameIntoSKMasters(int score) + { + BOOLEnum BVar1; + int iVar2; + int iVar3; + int* piVar4; + SkMasterDataEntry* pSVar5; + int iVar6; + SkMasterDataEntry* _ptrSrc; + SkMasterDataEntry* _ptrDst; + int _count; + SkMasterDataEntry* _ptrDst2; + SkMasterDataEntry* _ptrSrc2; + BVar1 = MACRO_CALL(Game::Skirmish_Func::StoreCurrentGameIntoTemporarySKMasterEntry)(score); + if (!BVar1) {} + _count = -1; + if (DAT_SkMasters2Data_Count::instance < 1) { + _count = 0; + } + if (DAT_SkMasters2Data_Count::instance < 250) { + _count = DAT_SkMasters2Data_Count::instance; + } + iVar6 = _count; + if (_count) { + iVar2 = 0; + if (0 < DAT_SkMasters2Data_Count::instance) { + piVar4 = &DAT_SkMasters2DataArray::instance[0].skMasterScore; + do { + iVar6 = iVar2; + if (*piVar4 < DAT_SkMasterDataEntry::instance.skMasterScore) + break; + iVar2 = iVar2 + 1; + piVar4 = piVar4 + 764; + iVar6 = _count; + } while (iVar2 < DAT_SkMasters2Data_Count::instance); + } + if (iVar6 == -1) {} + } + if (iVar6 < DAT_SkMasters2Data_Count::instance) { + pSVar5 = DAT_SkMasters2DataArray::instance + DAT_SkMasters2Data_Count::instance; + iVar2 = DAT_SkMasters2Data_Count::instance; + do { + if (iVar2 < 249) { + _ptrSrc = pSVar5 + -1; + _ptrDst = pSVar5; + for (iVar3 = 764; iVar3 != 0; iVar3 = iVar3 + -1) { + _ptrDst->score = _ptrSrc->score; + _ptrSrc = (SkMasterDataEntry*)_ptrSrc->mapName; + _ptrDst = (SkMasterDataEntry*)_ptrDst->mapName; + } + } + iVar2 = iVar2 + -1; + pSVar5 = pSVar5 + -1; + } while (iVar6 < iVar2); + } + _ptrSrc2 = DAT_SkMasterDataEntry::ptr; + _ptrDst2 = DAT_SkMasters2DataArray::instance + iVar6; + for (iVar2 = 764; iVar2 != 0; iVar2 = iVar2 + -1) { + _ptrDst2->score = _ptrSrc2->score; + _ptrSrc2 = (SkMasterDataEntry*)_ptrSrc2->mapName; + _ptrDst2 = (SkMasterDataEntry*)_ptrDst2->mapName; + } + if (DAT_SkMasters2Data_Count::instance < 250) { + DAT_SkMasters2Data_Count::instance = DAT_SkMasters2Data_Count::instance + 1; + } + MACRO_CALL(IO_Func::WriteSkMasters2)(); + } + +} +} diff --git a/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp new file mode 100644 index 0000000000..841ab3836b --- /dev/null +++ b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp @@ -0,0 +1,118 @@ +#include "../Game.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_00df5558.hpp" +#include "OpenSHC/Globals/DAT_00df5560.hpp" +#include "OpenSHC/Globals/DAT_00df5590.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TutorialCurrentStep.hpp" +#include "OpenSHC/Globals/INT_DisableTutorialRestrictions.hpp" + +namespace OpenSHC { + +using WindowsHelper::Enums::BOOLEnum; + +// FUNCTION: STRONGHOLDCRUSADER 0x004BD800 +BOOLEnum Game::Tutorial_IsActionAllowed(undefined4 actionType, int actionParam) +{ + int iVar1; + bool bVar2; + if (INT_DisableTutorialRestrictions::instance) { + return TRUE; + } + switch (actionType) { + case 1: + if (DAT_TutorialCurrentStep::instance == 2) { + if (1 < DAT_00df5558::instance) { + return FALSE; + } + bVar2 = actionParam == 0x28; + } else if (DAT_TutorialCurrentStep::instance == 5) { + if (DAT_00df5558::instance) { + return FALSE; + } + bVar2 = actionParam == 0x13; + } else if (DAT_TutorialCurrentStep::instance == 0x11) { + if (actionParam != 3) { + return FALSE; + } + bVar2 = DAT_00df5560::instance == 0; + } else { + if (DAT_TutorialCurrentStep::instance != 0x15) { + if (DAT_TutorialCurrentStep::instance != 0x18) { + return FALSE; + } + if (actionParam != 1) { + return FALSE; + } + return TRUE; + } + bVar2 = actionParam == 7; + } + if (bVar2) { + return TRUE; + } + return FALSE; + case 2: + if (DAT_TutorialCurrentStep::instance == 2) { + if ((DAT_00df5558::instance < 2) && (actionParam == 0x28)) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 5) { + if (((!DAT_00df5558::instance) && (actionParam == 0x13)) && (!DAT_00df5560::instance)) { + return TRUE; + } + } else { + if (DAT_TutorialCurrentStep::instance == 0x11) { + bVar2 = actionParam == 3; + } else { + if (DAT_TutorialCurrentStep::instance != 0x15) { + if (DAT_TutorialCurrentStep::instance != 0x18) { + return FALSE; + } + if (actionParam != 1) { + return FALSE; + } + if (DAT_00df5560::instance) { + return FALSE; + } + return TRUE; + } + bVar2 = actionParam == 7; + } + if ((bVar2) && (DAT_00df5590::instance < 4)) { + return TRUE; + } + } + return FALSE; + case 3: + if (DAT_TutorialCurrentStep::instance != 8) { + return FALSE; + } + iVar1 = 4; + bVar2 = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .rationsSetting + == 4; + break; + case 4: + if (DAT_TutorialCurrentStep::instance != 10) { + return FALSE; + } + iVar1 = 7; + bVar2 + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].taxesSetting + == 7; + break; + default: + goto switchD_004bd819_caseD_4; + } + if ((bVar2) && (actionParam != iVar1)) { + return FALSE; + } +switchD_004bd819_caseD_4: + return TRUE; +} + +} diff --git a/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp b/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp new file mode 100644 index 0000000000..a38df47e80 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp @@ -0,0 +1,39 @@ +#include "../../Map.func.hpp" +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004BC110 + void MapPropertiesState::adjustEventMonthAndYearForSection1047() + { + DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month; + DAT_GameState::instance.mapAndTime.militaryCampaignStage = 0; + DAT_GameState::instance.mapAndTime.field3183_0x27dc = 0; + DAT_GameState::instance.mapAndTime.militaryCampaignFlags = 0; + DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; + if (DAT_GameCore::instance.missionNumber1to20 == 17) { + DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month + 1; + } else if (DAT_GameCore::instance.missionNumber1to20 == 18) { + DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month + 1; + } else if (DAT_GameCore::instance.missionNumber1to20 == 19) { + DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month + 6; + } else { + if (DAT_GameCore::instance.missionNumber1to20 != 20) { + DAT_GameState::instance.mapAndTime.militaryCampaignStage = 0; + DAT_GameState::instance.mapAndTime.militaryCampaignFlags = 0; + DAT_GameState::instance.mapAndTime.field3183_0x27dc = 0; + } + DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month + 3; + } + if (12 < DAT_GameState::instance.mapAndTime.month) { + DAT_GameState::instance.mapAndTime.month = DAT_GameState::instance.mapAndTime.month - 12; + DAT_GameState::instance.mapAndTime.year = DAT_GameState::instance.mapAndTime.year + 1; + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp new file mode 100644 index 0000000000..f3804bc1cc --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp @@ -0,0 +1,327 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode2; + using Map::Units::UnitLogicState; + + // FUNCTION: STRONGHOLDCRUSADER 0x004BDE40 + void MapPropertiesState::computeMissionCompletionScore() + { + bool bVar1; + int* piVar2; + int iVar3; + uint uVar4; + int iVar5; + int iVar6; + char* pcVar7; + short* psVar8; + int local_8; + int local_4; + local_4 = 0; + local_8 = 0; + this->missionScore = 0xffffffff; + this->objectiveGoodsCount = 0; + iVar5 = 0; + if (0 < this->eventsCount) { + pcVar7 = (char*)((int)&this->scenarioEvents[0].data + 0xf); + iVar6 = 1; + do { + if (*(int*)(pcVar7 + -0x17) != 3) + goto LAB_004be33e; + if (((*(int*)(pcVar7 + -0xb) == 1) || (*(int*)(pcVar7 + -0xb) == 0x1b)) && (*pcVar7 != '\0')) { + local_4 = *(int*)(pcVar7 + -0x1f); + local_8 = *(int*)(pcVar7 + -0x1b); + } + if ((*(int*)(pcVar7 + -0xb) != 0) && (*(int*)(pcVar7 + -0xb) != 0x1a)) + goto LAB_004be33e; + if (iVar6 < this->eventsCount) { + piVar2 = (int*)(pcVar7 + 0xd9); + iVar5 = iVar6; + do { + if ((piVar2[-3] == 3) && ((*piVar2 == 0 || (*piVar2 == 0x1a)))) + goto LAB_004be33e; + iVar5 = iVar5 + 1; + piVar2 = piVar2 + 0x39; + } while (iVar5 < this->eventsCount); + } + if (pcVar7[0x18] == '\0') + goto LAB_004bdfd7; + this->objectiveGoodsType[this->objectiveGoodsCount] = (int)pcVar7[0x17]; + iVar5 = this->objectiveGoodsCount; + iVar3 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)*(short*)(pcVar7 + 0x15)); + this->objectiveGoodsSurplus[iVar5] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[this->objectiveGoodsType[iVar5]] + - iVar3; + switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { + case 2: + case 10: + case 0xb: + case 0xc: + case 0xd: + iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; + goto LAB_004bdfb7; + default: + iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + LAB_004bdfb7: + this->objectiveGoodsScore[this->objectiveGoodsCount] = iVar5; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x14; + break; + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x32; + } + if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + LAB_004bdfd7: + if (pcVar7[0x44] == '\0') + goto LAB_004be0ae; + this->objectiveGoodsType[this->objectiveGoodsCount] = (int)pcVar7[0x43]; + iVar5 = this->objectiveGoodsCount; + iVar3 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)*(short*)(pcVar7 + 0x41)); + this->objectiveGoodsSurplus[iVar5] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[this->objectiveGoodsType[iVar5]] + - iVar3; + switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { + case 2: + case 10: + case 0xb: + case 0xc: + case 0xd: + iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; + goto LAB_004be08e; + default: + iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + LAB_004be08e: + this->objectiveGoodsScore[this->objectiveGoodsCount] = iVar5; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x14; + break; + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x32; + } + if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + LAB_004be0ae: + if (pcVar7[0x14] == '\0') + goto LAB_004be185; + this->objectiveGoodsType[this->objectiveGoodsCount] = (int)pcVar7[0x13]; + iVar5 = this->objectiveGoodsCount; + iVar3 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)*(short*)(pcVar7 + 0x11)); + this->objectiveGoodsSurplus[iVar5] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[this->objectiveGoodsType[iVar5]] + - iVar3; + switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { + case 2: + case 10: + case 0xb: + case 0xc: + case 0xd: + iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; + goto LAB_004be165; + default: + iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + LAB_004be165: + this->objectiveGoodsScore[this->objectiveGoodsCount] = iVar5; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x14; + break; + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x32; + } + if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + LAB_004be185: + if (pcVar7[0x1c] == '\0') + goto LAB_004be25c; + this->objectiveGoodsType[this->objectiveGoodsCount] = (int)pcVar7[0x1b]; + iVar5 = this->objectiveGoodsCount; + iVar3 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)*(short*)(pcVar7 + 0x19)); + this->objectiveGoodsSurplus[iVar5] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[this->objectiveGoodsType[iVar5]] + - iVar3; + switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { + case 2: + case 10: + case 0xb: + case 0xc: + case 0xd: + iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; + goto LAB_004be23c; + default: + iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + LAB_004be23c: + this->objectiveGoodsScore[this->objectiveGoodsCount] = iVar5; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x14; + break; + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x32; + } + if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + LAB_004be25c: + if (pcVar7[0x10] != '\0') { + this->objectiveGoodsType[this->objectiveGoodsCount] = 0xf; + iVar5 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, + this)((int)*(short*)(pcVar7 + 0xd)); + this->objectiveGoodsSurplus[this->objectiveGoodsCount] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[0xf] + - iVar5; + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount]; + if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + } + if (pcVar7[4] != '\0') { + this->objectiveGoodsType[this->objectiveGoodsCount] = -1; + iVar5 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, + this)((int)*(short*)(pcVar7 + 1)); + this->objectiveGoodsSurplus[this->objectiveGoodsCount] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentPopulation + - iVar5; + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount]; + if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; + } + } + LAB_004be33e: + pcVar7 = pcVar7 + 0xe4; + bVar1 = iVar6 < this->eventsCount; + iVar5 = local_8; + iVar6 = iVar6 + 1; + } while (bVar1); + } + iVar6 = 0; + this->monthsRemaining = 0; + this->timeBonusScore = 0; + if (iVar5) { + uVar4 = ((iVar5 - DAT_GameState::instance.mapAndTime.year) * 0xc - DAT_GameState::instance.mapAndTime.month) + + local_4; + this->monthsRemaining = uVar4 & ((int)uVar4 < 1) - 1; + this->timeBonusScore = this->monthsRemaining * 100; + } + this->missionScore = DAT_MissionAestheticsDefinedData::instance + .MissionScoreByDifficulty[DAT_GameState::instance.mapAndTime.difficulty] + + this->timeBonusScore; + iVar5 = 0; + if (0 < this->objectiveGoodsCount) { + piVar2 = this->objectiveGoodsScore; + do { + this->missionScore = this->missionScore + *piVar2; + iVar5 = iVar5 + 1; + piVar2 = piVar2 + 1; + } while (iVar5 < this->objectiveGoodsCount); + } + this->troopSurvivalScore = 0; + if ((DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) + || ((DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk + && ((int)this->SEC_U3_MapType2_1 < 2)))) { + psVar8 = &DAT_UnitsState::instance.units[1].owner; + iVar5 = DAT_GameSynchronyState::instance.currentPlayerSlotID; + do { + if (((psVar8[-5] != Map::Units::ULS_INVISIBLE) && (*psVar8 == iVar5)) + && (psVar8[0x107] != 0)) { + iVar5 = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, + DAT_TroopValueState::ptr)((Map::Units::UnitType)((int)psVar8[-4])); + iVar6 = iVar6 + iVar5; + iVar5 = DAT_GameSynchronyState::instance.currentPlayerSlotID; + } + psVar8 = psVar8 + 0x248; + } while ((int)psVar8 < 0x1651422); + iVar5 = DAT_GameState::instance.playerDataArray[iVar5].weightedLosses; + iVar6 = iVar5 + iVar6; + if (iVar6) { + this->troopLossPercent = (iVar5 * 100) / iVar6; + this->troopSurvivalScore = (100 - this->troopLossPercent) * 100; + this->missionScore = this->missionScore + this->troopSurvivalScore; + } + } + if (DAT_GameCore::instance.mapU4Int1) { + iVar5 = 0; + psVar8 = &DAT_UnitsState::instance.units[1].owner; + do { + if (((psVar8[-5] != Map::Units::ULS_INVISIBLE) && (*psVar8 == 1)) && (psVar8[0x107] != 0)) { + iVar6 = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, + DAT_TroopValueState::ptr)((Map::Units::UnitType)((int)psVar8[-4])); + iVar5 = iVar5 + iVar6; + } + psVar8 = psVar8 + 0x248; + } while ((int)psVar8 < 0x1651422); + this->enemyTroopValueLost = DAT_GameState::instance.playerDataArray[2].weightedLosses; + this->enemyTroopValueTotal = DAT_GameState::instance.playerDataArray[2].weightedLosses + iVar5; + this->enemyTroopValueSurviving = iVar5; + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp new file mode 100644 index 0000000000..8a0b04ed0f --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp @@ -0,0 +1,273 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/AI/AICState.func.hpp" +#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/IO/FilePackager.func.hpp" +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Rendering/Bink/AIMessageQueue.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/IO/FileResourceType.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_AICState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MapDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_VideoBikQueue.hpp" +#include "OpenSHC/Globals/FilePackagerObj.hpp" +#include "OpenSHC/Globals/MSVC_SecurityCookie.hpp" +#include "OpenSHC/Globals/TIME_ReceivedMessage_2.hpp" +#include "OpenSHC/Game/GameMode2Int.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" + +namespace OpenSHC { +namespace Map { + + using Game::GameMode2; + using IO::FileResourceType; + using Map::Units::UnitLogicState; + using Map::Units::UnitType; + using WindowsHelper::Enums::BOOLEnum; + using Game::GameMode2Int; + using Map::Units::UnitTypeShort; + + // FUNCTION: STRONGHOLDCRUSADER 0x004C62C0 + void MapPropertiesState::loadMap(char* mapName) + { + char cVar1; + GameMode2Int GVar2; + UnitTypeShort* pUVar3; + int* piVar4; + SiegeUnitCounts* pSVar5; + int iVar6; + int* piVar7; + SiegeUnitCounts* pSVar8; + int* pIVar9; + int local_34; + int local_30; + int local_2c; + int local_28; + int local_24; + int local_20; + int local_1c; + int local_18; + int local_14; + int local_10; + int local_c; + int local_8; + uint local_4; + GVar2 = DAT_GameCore::instance.gameMode_2; + iVar6 = DAT_GameCore::instance.missionNumber1to20; + local_4 = MSVC_SecurityCookie::instance ^ (uint)&local_34; + local_14 = DAT_GameSynchronyState::instance.currentPlayerSlotID; + local_30 = DAT_GameState::instance.mapAndTime.difficulty; + local_10 = DAT_GameCore::instance.xbowProducible_logic; + local_18 = DAT_GameCore::instance.swordProducible_logic; + local_28 = DAT_GameCore::instance.pikeProducible_logic; + local_20 = DAT_GameCore::instance.bowProducible_logic; + local_24 = (int)DAT_GameState::instance.mapAndTime.unitJesterRelated; + local_2c = DAT_GameCore::instance.maceProducible_logic; + local_34 = DAT_GameCore::instance.spearProducible_logic; + local_1c = (int)DAT_GameState::instance.mapAndTime.unitLadyRelated; + local_c = DAT_GameState::instance.mapAndTime.field43_0xf0; + local_8 = DAT_GameState::instance.mapAndTime.field44_0xf4; + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::resetTeams, DAT_GameState::ptr)(); + MACRO_CALL_MEMBER(Map::TileMapState_Func::setupAllMapSections, DAT_TileMapState::ptr)(); + MACRO_CALL_MEMBER(IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( + IO::FRT_MAPS, (char const*)((int)(mapName))); + MACRO_CALL_MEMBER(IO::FilePackager_Func::readMapOrSavFile, FilePackagerObj::ptr)( + DAT_MapDefinedData::instance.MapSectionAddressArray); + MACRO_CALL_MEMBER( + Audio::MSS::SoundSystem_Func::mapLoadingAndLaunchGameRelated1, DAT_SoundSystemState::ptr)(); + DAT_GameState::instance.mapAndTime.difficulty = local_30; + DAT_GameCore::instance.xbowProducible_logic = local_10; + DAT_GameCore::instance.pikeProducible_logic = local_28; + DAT_GameCore::instance.swordProducible_logic = local_18; + DAT_GameCore::instance.bowProducible_logic = local_20; + DAT_GameCore::instance.mapTimeInTicks = 1; + DAT_GameCore::instance.section1127 = 1; + DAT_GameCore::instance.spearProducible_logic = local_34; + DAT_GameCore::instance.maceProducible_logic = local_2c; + DAT_GameCore::instance.missionNumber1to20 = iVar6; + DAT_GameCore::instance.gameMode_2 = GVar2; + if (iVar6 == 1) { + iVar6 = 8; + pUVar3 = &DAT_UnitsState::instance.units[1].unitType; + do { + if (((pUVar3[-1] != Map::Units::ULS_INVISIBLE) + && (*pUVar3 == Map::Units::UT_E_ARCHER)) + && (pUVar3[4] == 1)) { + iVar6 = iVar6 + -1; + *(int*)(pUVar3 + -0x3f) = 3; + if (!iVar6) + break; + } + pUVar3 = pUVar3 + 0x248; + } while ((int)pUVar3 < 0x165141a); + } + DAT_GameState::instance.mapAndTime.unitLadyRelated = (short)local_1c; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[0] = -1; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[1] = -1; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[2] = -1; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[3] = -1; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[4] = -1; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[5] = -1; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[6] = -1; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[7] = -1; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[8] = -1; + DAT_GameState::instance.mapAndTime.unitJesterRelated = (short)local_24; + DAT_GameSynchronyState::instance.currentPlayerSlotID = local_14; + DAT_GameState::instance.mapAndTime.field44_0xf4 = local_8; + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[local_14] = 1; + DAT_GameState::instance.mapAndTime.field43_0xf0 = local_c; + DAT_GameState::instance.playerDataArray[1].tacticalPowersBarLevel = 0; + DAT_GameState::instance.playerDataArray[2].tacticalPowersBarLevel = 0; + DAT_GameState::instance.playerDataArray[3].tacticalPowersBarLevel = 0; + DAT_GameState::instance.playerDataArray[4].tacticalPowersBarLevel = 0; + DAT_GameState::instance.playerDataArray[5].tacticalPowersBarLevel = 0; + DAT_GameState::instance.playerDataArray[6].tacticalPowersBarLevel = 0; + DAT_GameState::instance.playerDataArray[7].tacticalPowersBarLevel = 0; + DAT_GameState::instance.playerDataArray[8].tacticalPowersBarLevel = 0; + DAT_GameCore::instance.isTimeHalted = FALSE; + DAT_GameCore::instance.section1095 = 0; + iVar6 = (int)this - (int)mapName; + do { + cVar1 = *mapName; + mapName[iVar6] = cVar1; + mapName = mapName + 1; + } while (cVar1 != '\0'); + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { + MACRO_CALL_MEMBER( + Game::GameCore_Func::removeJesterAndLadyUnitsInCertainMissions, DAT_GameCore::ptr)(); + } else if (DAT_GameCore::instance.gameMode_2 == Game::GM_ECONOMIC_CAMPAIGN_SH1) { + MACRO_CALL_MEMBER(Game::GameCore_Func::removeLadyAndJester, DAT_GameCore::ptr)(); + } + pIVar9 = this->SEC_EventsExtra[0].conditionIsTrue; + for (iVar6 = 8000; iVar6 != 0; iVar6 = iVar6 + -1) { + *pIVar9 = 0; + pIVar9 = pIVar9 + 1; + } + DAT_GameState::instance.mapAndTime.month = this->SEC_StartingMonth; + DAT_GameState::instance.mapAndTime.year = this->SEC_StartingYear; + if (DAT_GameCore::instance.missionNumber1to20 - 4294967280 < 5) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::adjustEventMonthAndYearForSection1047, this)(); + } + if ((DAT_GameState::instance.mapAndTime.month == this->SEC_StartingMonth) + && (DAT_GameState::instance.mapAndTime.year == this->SEC_StartingYear)) { + piVar4 = DAT_GameState::instance.mapAndTime.startGoods; + piVar7 = this->SEC_StartingResources; + do { + *piVar4 = *piVar7; + piVar4 = piVar4 + 1; + piVar7 = piVar7 + 1; + } while ((int)piVar4 < 0x117ce50); + DAT_GameState::instance.mapAndTime.startGoods[7] = DAT_GameState::instance.mapAndTime.startGoods[8]; + DAT_GameState::instance.mapAndTime.startGoods[8] = 0; + pSVar5 = &DAT_GameState::instance.mapAndTime.siegeInformation; + pSVar8 = &this->SEC_SiegeInformation; + do { + pSVar5->archers = pSVar8->archers; + pSVar5 = (SiegeUnitCounts*)&pSVar5->crossbowmen; + pSVar8 = (SiegeUnitCounts*)&pSVar8->crossbowmen; + } while ((int)pSVar5 < 0x117cea0); + DAT_GameState::instance.mapAndTime.startingPopularity = this->SEC_StartingPopularity * 10; + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::setMonthAndYear, DAT_GameState::ptr)( + this->SEC_StartingMonth, this->SEC_StartingYear); + } + this->SEC_Section1080 = 0; + this->SEC_Section1081 = 0; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::countDeerEfficiently, DAT_TribesState::ptr)(); + MACRO_CALL_MEMBER(Map::TileMapState_Func::prepareMap, DAT_TileMapState::ptr)(); + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::clearEnemyRelatedStructures, DAT_GameState::ptr)(); + DAT_UnitsState::instance.lastSelectedUnitID = 0; + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::clearSelectionCountsAndPlayerIDs, DAT_UnitsState::ptr)(); + DAT_GameState::instance.mapAndTime.euroRecruitable[4] + = (int)this->barracksRecruitability.recruitability.macemen; + DAT_GameState::instance.mapAndTime.euroRecruitable[5] + = (int)this->barracksRecruitability.recruitability.swordsmen; + DAT_GameState::instance.mapAndTime.euroRecruitable[6] + = (int)this->barracksRecruitability.recruitability.knights; + DAT_GameState::instance.mapAndTime.mercRecruitable[0] = (int)this->SEC_MercRecruitable[0]; + DAT_GameState::instance.mapAndTime.euroRecruitable[0] + = (int)this->barracksRecruitability.recruitability.archers; + DAT_GameState::instance.mapAndTime.euroRecruitable[1] + = (int)this->barracksRecruitability.recruitability.crossbowmen; + DAT_GameState::instance.mapAndTime.euroRecruitable[2] + = (int)this->barracksRecruitability.recruitability.spearmen; + DAT_GameState::instance.mapAndTime.euroRecruitable[3] + = (int)this->barracksRecruitability.recruitability.pikemen; + DAT_GameState::instance.mapAndTime.mercRecruitable[1] = (int)this->SEC_MercRecruitable[1]; + DAT_GameState::instance.mapAndTime.mercRecruitable[2] = (int)this->SEC_MercRecruitable[2]; + DAT_GameState::instance.mapAndTime.mercRecruitable[3] = (int)this->SEC_MercRecruitable[3]; + DAT_GameState::instance.mapAndTime.mercRecruitable[4] = (int)this->SEC_MercRecruitable[4]; + DAT_GameState::instance.mapAndTime.mercRecruitable[5] = (int)this->SEC_MercRecruitable[5]; + DAT_GameState::instance.mapAndTime.mercRecruitable[6] = (int)this->SEC_MercRecruitable[6]; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_0 + = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[0] != 0); + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_a + = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[1] != 0); + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_b + = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[1] != 0); + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_2 + = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[2] != 0); + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b + = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[3] != 0); + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_b + = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[3] != 0); + if (DAT_GameState::instance.mapAndTime.euroRecruitable[4] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_a = 1; + } + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_4 + = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[4] != 0); + if (DAT_GameState::instance.mapAndTime.euroRecruitable[5] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b = 1; + } + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_a + = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[5] != 0); + if (DAT_GameState::instance.mapAndTime.euroRecruitable[6] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_a = 1; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b = 1; + } + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_c + = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[6] != 0); + DAT_GameState::instance.mapAndTime.countUpTo201 = 0; + DAT_GameState::instance.mapAndTime.cathedralRelated1 = 0; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::importTradingCosts, this)(); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::clearAttackInfo, DAT_TroopValueState::ptr)(); + MACRO_CALL_MEMBER(AI::AICState_Func::recomputeAIZonerLayer, DAT_AICState::ptr)(); + MACRO_CALL_MEMBER( + Map::TileMapState_Func::setSignpostDistanceForCampaignMission, DAT_TileMapState::ptr)(); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playNextStoredBinkVideo, DAT_VideoBikQueue::ptr)(); + DAT_GameCore::instance.xbowProducible_logic = (int)this->SEC_XbowProducible_save; + DAT_GameCore::instance.bowProducible_logic = (int)this->SEC_BowProducible_save; + DAT_GameCore::instance.pikeProducible_logic = (int)this->SEC_PikeProducible_save; + DAT_GameCore::instance.spearProducible_logic = (int)this->SEC_SpearProducible_save; + DAT_GameCore::instance.swordProducible_logic = (int)this->SEC_SwordProducible_save; + DAT_GameCore::instance.maceProducible_logic = (int)this->SEC_MaceProducible_save; + DAT_GameCore::instance.timeSum_2 = timeGetTime(); + DAT_GameCore::instance.gameDuration = 0; + TIME_ReceivedMessage_2::instance = 0; + ; + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp new file mode 100644 index 0000000000..484a15172d --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp @@ -0,0 +1,39 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + /* + Looks up the map filename for mission index param_1 (1-based, range 1-20) from + MissionAestheticsDefinedData.field15_0x3c and calls loadMapSiegeHeaderSections. Covers all four groups of 5 + missions (1-5, 6-10, 11-15, 16-20). Does nothing if param_1 is out of range. renamed by: Claude Sonnet 4.6 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004C6820 + void MapPropertiesState::loadMapSiegeHeaderForMissionIndex(char* param_1) + { + char* pcVar1; + pcVar1 = param_1 + -1; + if ((int)pcVar1 < 5) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field15_0x3c)[(int)pcVar1]); + } + if ((int)pcVar1 < 10) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field15_0x3c)[(int)pcVar1]); + } + if ((int)pcVar1 < 0xf) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field15_0x3c)[(int)pcVar1]); + } + if ((int)pcVar1 < 20) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field15_0x3c)[(int)pcVar1]); + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp new file mode 100644 index 0000000000..0c5090855c --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp @@ -0,0 +1,42 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" + +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" + +namespace OpenSHC { +namespace Map { + + /* + Loads the map file for the given mission number (1-based) from MissionAestheticsDefinedData.field14_0x38, then + calls UnitsState::setMissionNumberSpecificLord to configure the lord unit for that mission. Covers missions + 1-20. renamed by: Claude Sonnet 4.6 + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004C6880 + void MapPropertiesState::loadMissionMapAndSetLord(int missionNumber) + { + int iVar1; + char** mapName; + iVar1 = missionNumber + -1; + if (iVar1 < 5) { + LAB_004c688d: + mapName = (&DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName)[missionNumber]; + } else { + if (9 < iVar1) { + if (iVar1 < 0xf) + goto LAB_004c688d; + if (0x13 < iVar1) + goto LAB_004c68b3; + } + mapName = (&DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName)[missionNumber]; + } + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)((char*)mapName); + LAB_004c68b3: + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::setMissionNumberSpecificLord, DAT_UnitsState::ptr)( + missionNumber); + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp new file mode 100644 index 0000000000..9b66e888e0 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -0,0 +1,2704 @@ +#include "../../Map.func.hpp" + +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Game/GameCore.func.hpp" +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Input/MouseState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/MapPropertiesState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Rendering/Bink/AIMessageQueue.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/UI/DisplayElements.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/MenuItems/General.func.hpp" +#include "OpenSHC/UI/MenuModalComposition.func.hpp" +#include "OpenSHC/UI/MenuTextInputState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Audio/SFX/SoundEffectID.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/MapType2.hpp" +#include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/UI/Enums/BuildMenuTabType.hpp" +#include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" +#include "OpenSHC/UI/Enums/DisplayElementID.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/UI/Enums/MenuViewType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BinkControlState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition2.hpp" +#include "OpenSHC/Globals/DAT_MenuModalComposition3.hpp" +#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_VideoBikQueue.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" +#include "OpenSHC/Game/ScenarioEvents/ScenarioEventCondition.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" +#include "OpenSHC/Map/Units/UnitTypeInt.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" + +namespace OpenSHC { +namespace Map { + + using Audio::SFX::SoundEffectID; + using Commands::MappersEnum; + using DE::SHCDE::eTextSections; + using Game::GameMode; + using Game::GameMode2; + using Map::MapType2; + using Map::Buildings::BuildingLogicalState; + using Map::Buildings::BuildingType; + using Map::Units::UnitLogicState; + using Map::Units::UnitType; + using Map::Units::Instructions::UnitMatchSpeedEnum; + using UI::Enums::BuildingsAndStatusMenuTabType; + using UI::Enums::BuildMenuTabType; + using UI::Enums::DisplayElementID; + using UI::Enums::MenuModalType; + using UI::Enums::MenuViewType; + using WindowsHelper::Enums::BOOLEnum; + using Game::ScenarioEvents::ScenarioEventCondition; + using Map::Buildings::BuildingTypeShort; + using Map::Units::UnitTypeInt; + using Map::Units::UnitTypeShort; + + // FUNCTION: STRONGHOLDCRUSADER 0x004C31A0 + void MapPropertiesState::processSingleplayerEvents() + { + int iVar1; + byte(*pabVar2)[10]; + byte* pbVar3; + byte bVar4; + byte bVar5; + UnitTypeShort UVar6; + short sVar7; + short sVar8; + BuildingTypeShort BVar9; + char* pcVar10; + BOOLEnum BVar11; + UnitTypeShort* pUVar12; + BuildingTypeShort* pBVar13; + dword tribeID; + dword dVar14; + ScenarioEventCondition* pSVar15; + int _invasionAmplifier; + InGameEventUnionVersion* pIVar16; + char cVar17; + int iVar18; + uint uVar19; + int _unitSpawnTotalAdjustment; + int iVar20; + int numInGroup; + InGameEventUnionVersion* psVar21; + int _unitAIBehaviourTypeUnk; + int iVar21; + int iVar22; + uint y1; + UnitTypeInt _unitType; + bool bVar23; + bool bVar24; + char* pcVar25; + char* pcVar26; + char* pcVar27; + int local_a0; + int _eventIndex; + int _subIndex; + int _spawnUnitCount; + int local_88; + int local_80; + uint uStack_7c; + uint uStack_78; + int _previousScenarioEventIndex; + int local_70[10]; + int local_48[18]; + int _amplifiedUnitTotalForUnitType; + int _crusaderOrArabian; + int _repeatMonths; + int _conditionOffset; + int _counter; + int _scenarioEventType; + int _eventType; + int* _pConditionIsMet; + local_88 = 0; + local_70[9] = DAT_GameState::instance.mapAndTime.signpostsMapEdgeDataCounter; + _previousScenarioEventIndex = -1; + if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { + if ((DAT_GameCore::instance.gameMode_2 != Game::GM_EDITOR) + && (DAT_GameCore::instance.gameMode_2 != Game::GM_SIEGE_THAT)) { + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CRUSADER_TUTORIAL) { + MACRO_CALL(UI::Helpers_Func::UpdateTutorialStepAndProgress)(); + } + if (DAT_GameCore::instance.section1095 != 1) { + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 0) { + if ((this->SEC_Section1081) && (0 < this->SEC_Section1080)) { + this->SEC_Section1080 = this->SEC_Section1080 + -1; + } + if (DAT_GameState::instance.mapAndTime.startOfDay) { + if (DAT_GameCore::instance.unknownAlwaysZero) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated = 1; + DAT_GameCore::instance.unknownAlwaysZero = 0; + DAT_GameState::instance.mapAndTime.unknownCountdown01 = 10; + } + _pConditionIsMet = DAT_GameState::instance.mapAndTime.scenarioEventTimers; + do { + if ((*_pConditionIsMet != 0) + && (iVar18 = *_pConditionIsMet + 1, *_pConditionIsMet = iVar18, 0x4b0 < iVar18)) { + *_pConditionIsMet = 0; + } + _pConditionIsMet = _pConditionIsMet + 1; + } while ((int)_pConditionIsMet < 0x117ee60); + local_48[0] = -1; + local_48[1] = 0xffffffff; + local_48[2] = 0xffffffff; + local_48[3] = 0xffffffff; + local_48[4] = 0xffffffff; + local_48[5] = 0xffffffff; + local_48[6] = 0xffffffff; + local_48[7] = 0xffffffff; + local_48[8] = 0xffffffff; + local_80 = DAT_TroopValueState::instance.attackInfo.inv_count; + local_70[0] = 0; + local_48[9] = 0; + local_70[1] = 0; + local_48[10] = 0; + local_70[2] = 0; + local_48[0xb] = 0; + local_70[3] = 0; + local_48[0xc] = 0; + local_70[4] = 0; + local_48[0xd] = 0; + local_70[5] = 0; + local_48[0xe] = 0; + local_70[6] = 0; + local_48[0xf] = 0; + local_70[7] = 0; + local_48[0x10] = 0; + local_70[8] = 0; + local_48[0x11] = 0; + if ((((DAT_GameState::instance.mapAndTime.month == this->SEC_StartingMonth) + && (DAT_GameState::instance.mapAndTime.year == this->SEC_StartingYear + 1)) + && (DAT_GameState::instance.gameTicksLoadBalancer == 1)) + && ((!DAT_GameState::instance.mapAndTime.week + && (bVar23 = false, 0 < this->eventsCount)))) { + _pConditionIsMet = &this->scenarioEvents[0].data.scenario.ScenarioEventType; + iVar18 = this->eventsCount; + do { + if ((_pConditionIsMet[-3] == 3) && (*_pConditionIsMet == 0x1e)) { + bVar23 = true; + } + _pConditionIsMet = _pConditionIsMet + 0x39; + iVar18 = iVar18 + -1; + } while (iVar18); + if (bVar23) { + /* + if a fire warning event + */ + iVar18 = 0; + if (0 < DAT_BuildingsState::instance.maxBuildingsCount) { + pBVar13 = &DAT_BuildingsState::instance.buildings[0].buildingType; + do { + if (((pBVar13[-1] != ((BuildingLogicalState)0)) + && ((short)pBVar13[2] + == DAT_GameSynchronyState::instance.currentPlayerSlotID)) + && ((*pBVar13 == Map::Buildings::BT_WELL + || (*pBVar13 == Map::Buildings::BT_WATERPOT)))) + goto LAB_004c3637; + iVar18 = iVar18 + 1; + pBVar13 = pBVar13 + 0x196; + } while (iVar18 < DAT_BuildingsState::instance.maxBuildingsCount); + } + pcVar27 = "general_message3.wav"; + pcVar25 = "ap_civil12.bik"; + /* + "there are no wells in the castle my liege. should a fire break out, we are int + great danger." added by script: "There are no wells in the castle my Liege. + Should a fire break out we would be in great danger." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x12); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); + } + } + LAB_004c3637: + _eventIndex = 0; + if (0 < this->eventsCount) { + do { + iVar18 = this->scenarioEvents[_eventIndex].header.year; + if ((DAT_GameState::instance.mapAndTime.year < iVar18) + || ((DAT_GameState::instance.mapAndTime.year == iVar18 + && (DAT_GameState::instance.mapAndTime.month + < this->scenarioEvents[_eventIndex].header.month)))) + break; + /* + "next Event" + */ + if (this->scenarioEvents[_eventIndex].header.done != 0) + goto LAB_004c5f28; + _eventType = this->scenarioEvents[_eventIndex].header.tl_type; + if (_eventType == 1) { + /* + Invasion + */ + DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 0; + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .aiControlStatusRelated = -200; + /* + invasion. ? + */ + iVar18 + = local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian]; + if (local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian] + == -1) { + DAT_TroopValueState::instance.attackInfo.inv_count + = DAT_TroopValueState::instance.attackInfo.inv_count + 1; + if (0x31 < DAT_TroopValueState::instance.attackInfo.inv_count) { + DAT_TroopValueState::instance.attackInfo.inv_count = 1; + } + MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::initializeAttackWaveSlot, + DAT_TroopValueState::ptr)( + DAT_TroopValueState::instance.attackInfo.inv_count, + this->scenarioEvents[_eventIndex].data.invasion.messageMonth); + local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian] + = DAT_TroopValueState::instance.attackInfo.inv_count; + local_80 = DAT_TroopValueState::instance.attackInfo.inv_count; + iVar18 = DAT_TroopValueState::instance.attackInfo.inv_count; + } + DAT_TroopValueState::instance.attackInfo.inv_count = iVar18; + DAT_TroopValueState::instance.attackInfo + .attackWavePlayerIDArray[DAT_TroopValueState::instance.attackInfo.inv_count] + = *(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x74) + 2; + _subIndex = 0; + do { + /* + if invasion.units[index] == 0 then index += 1 (break when not index < + 0x19) + */ + iVar18 = *( + int*)((int)&this->scenarioEvents[_eventIndex].data + _subIndex * 4 + 4); + if (!iVar18) + goto LAB_004c5db4; + _unitAIBehaviourTypeUnk = 0; + _unitType = ((UnitType)0); + _unitSpawnTotalAdjustment = 0; + switch (_subIndex) { + case 0: + _unitAIBehaviourTypeUnk = 3; + _unitType = Map::Units::UT_E_ARCHER; + break; + case 1: + _unitAIBehaviourTypeUnk = 7; + _unitType = Map::Units::UT_E_XBOW; + break; + case 2: + _unitAIBehaviourTypeUnk = 5; + _unitType = Map::Units::UT_E_SPEAR; + break; + case 3: + _unitAIBehaviourTypeUnk = 6; + _unitType = Map::Units::UT_E_PIKE; + break; + case 4: + _unitAIBehaviourTypeUnk = 9; + _unitType = Map::Units::UT_E_MACE; + break; + case 5: + _unitAIBehaviourTypeUnk = 8; + _unitType = Map::Units::UT_E_SWORD; + break; + case 6: + _unitAIBehaviourTypeUnk = 10; + _unitType = Map::Units::UT_E_KNIGHT; + _unitSpawnTotalAdjustment = 10; + goto switchD_004c5b0c_default; + case 7: + _unitAIBehaviourTypeUnk = 4; + _unitType = Map::Units::UT_E_LADDER; + break; + case 8: + _unitAIBehaviourTypeUnk = 0xb; + _unitType = Map::Units::UT_E_ENGINEER; + break; + case 9: + _unitAIBehaviourTypeUnk = 0x16; + _unitType = Map::Units::UT_S_CATAPULT; + break; + case 10: + _unitAIBehaviourTypeUnk = 0x17; + _unitType = Map::Units::UT_S_TREBUCHET; + break; + case 0xb: + _unitAIBehaviourTypeUnk = 0x13; + _unitType = Map::Units::UT_S_BATTERINGRAM; + break; + case 0xc: + _unitAIBehaviourTypeUnk = 0x14; + _unitType = Map::Units::UT_S_TOWER; + break; + case 0xd: + _unitAIBehaviourTypeUnk = 0x15; + _unitType = Map::Units::UT_S_SHIELD; + break; + case 0xe: + _unitAIBehaviourTypeUnk = 0xc; + _unitType = Map::Units::UT_E_MONK; + break; + case 0xf: + _unitAIBehaviourTypeUnk = 2; + _unitType = Map::Units::UT_TUNNELER; + break; + case 0x10: + _unitAIBehaviourTypeUnk = 0x19; + _unitType = Map::Units::UT_A_ARCHER; + break; + case 0x11: + _unitAIBehaviourTypeUnk = 0x1a; + _unitType = Map::Units::UT_A_SLAVE; + _unitSpawnTotalAdjustment = 0x14; + goto switchD_004c5b0c_default; + case 0x12: + _unitAIBehaviourTypeUnk = 0x1b; + _unitType = Map::Units::UT_A_SLINGER; + _unitSpawnTotalAdjustment = 0x14; + goto switchD_004c5b0c_default; + case 0x13: + _unitAIBehaviourTypeUnk = 0x1c; + _unitType = Map::Units::UT_A_ASSASSIN; + _unitSpawnTotalAdjustment = 2; + goto switchD_004c5b0c_default; + case 0x14: + _unitAIBehaviourTypeUnk = 0x1d; + _unitType = Map::Units::UT_A_HARCHER; + break; + case 0x15: + _unitAIBehaviourTypeUnk = 0x1e; + _unitType = Map::Units::UT_A_SWORDSMAN; + _unitSpawnTotalAdjustment = 8; + goto switchD_004c5b0c_default; + case 0x16: + _unitAIBehaviourTypeUnk = 0x1f; + _unitType = Map::Units::UT_A_FIRETHROWER; + _unitSpawnTotalAdjustment = 4; + goto switchD_004c5b0c_default; + case 0x17: + _unitAIBehaviourTypeUnk = 0x18; + _unitType = Map::Units::UT_S_FBALLISTA; + break; + default: + goto switchD_004c5b0c_default; + } + _unitSpawnTotalAdjustment = 10; + switchD_004c5b0c_default: + _invasionAmplifier = 100; + if (!DAT_GameState::instance.mapAndTime.difficulty) { + _invasionAmplifier = 50; + } else if (DAT_GameState::instance.mapAndTime.difficulty == 2) { + _invasionAmplifier = 140; + } else if (DAT_GameState::instance.mapAndTime.difficulty == 3) { + _invasionAmplifier = 200; + } + _amplifiedUnitTotalForUnitType = (_invasionAmplifier * iVar18) / 100; + cVar17 = (char)_amplifiedUnitTotalForUnitType; + if (_unitAIBehaviourTypeUnk == 0x16) { + pabVar2 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + + DAT_TroopValueState::instance.attackInfo.inv_count; + (*pabVar2)[0] = (*pabVar2)[0] + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x17) { + pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count] + + 1; + *pbVar3 = *pbVar3 + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x13) { + pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count] + + 2; + *pbVar3 = *pbVar3 + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x14) { + pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count] + + 3; + *pbVar3 = *pbVar3 + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x15) { + pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count] + + 4; + *pbVar3 = *pbVar3 + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x18) { + pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count] + + 8; + *pbVar3 = *pbVar3 + cVar17; + } else { + _spawnUnitCount = _amplifiedUnitTotalForUnitType + / (_amplifiedUnitTotalForUnitType / _unitSpawnTotalAdjustment + 1); + while (0 < _amplifiedUnitTotalForUnitType) { + if (_amplifiedUnitTotalForUnitType < _spawnUnitCount) { + _spawnUnitCount = _amplifiedUnitTotalForUnitType; + } + iVar18 = this->scenarioEvents[_eventIndex] + .data.invasion.crusaderArabian; + iVar22 = local_48[iVar18 + 9]; + local_48[iVar18 + 9] = iVar22 + 1; + iVar21 = (&DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray)[DAT_TroopValueState::instance + .attackInfo.inv_count]; + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, + DAT_TribesState::ptr)(iVar22, _unitAIBehaviourTypeUnk, + DAT_GameState::instance.mapAndTime + .signpostsMapEdge[iVar21][local_88] + .x, + DAT_GameState::instance.mapAndTime + .signpostsMapEdge[iVar21][local_88] + .y, + iVar18 + 2, (UnitType)((int)(_unitType)), ((UnitType)0), + _spawnUnitCount, 0); + local_88 = local_88 + 1; + _amplifiedUnitTotalForUnitType + = _amplifiedUnitTotalForUnitType - _spawnUnitCount; + if (local_70[9] <= local_88) { + local_88 = 0; + } + } + } + LAB_004c5db4: + _subIndex = _subIndex + 1; + } while (_subIndex < 0x19); + iVar18 = (&DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray) + [DAT_TroopValueState::instance.attackInfo.inv_count]; + MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, + DAT_MinimapViewState::ptr)( + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); + DAT_TroopValueState::instance.attackInfo.inv_count = local_80; + if ((!DAT_GameCore::instance.section1076) + && (_crusaderOrArabian + = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian, + local_70[_crusaderOrArabian] == 0)) { + local_70[_crusaderOrArabian] = 1; + if (!_crusaderOrArabian) { + pcVar25 = "infidel_attack.wav"; + pcVar10 = "sultan_nervous.bik"; + LAB_004c5e44: + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)("", pcVar10, pcVar25); + } else if (_crusaderOrArabian == 1) { + pcVar25 = "arabian_attack.wav"; + pcVar10 = "good_soldier_nervous.bik"; + goto LAB_004c5e44; + } + if ((DAT_GameCore::instance.currentMenuViewType + == UI::Enums::MVT_BUILD_MENU) + && ((DAT_GameCore::instance.activeMenuTab.tabType + == UI::Enums::BASMTT_SIEGETENT_SIEGETOWER + || (DAT_GameCore::instance.activeMenuTab.tabType + == UI::Enums::BASMTT_SIEGETENT_SHIELD)))) { + MACRO_CALL_MEMBER(Game::GameCore_Func::swapBuildMenuTab, + DAT_GameCore::ptr)(); + if (DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_SIEGETOWER) { + if (DAT_GameCore::instance.currentMenuViewType + == UI::Enums::MVT_BUILD_MENU) { + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + = UI::Enums::BASMTT_HUNTERSHUT; + } else if (DAT_GameCore::instance.currentMenuViewType + == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + DAT_GameCore::instance.landscapingmenuMenuTabToSwitchTo = 0xe7; + } + } + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, + DAT_GameCore::ptr)((UI::Enums::MenuViewType)DAT_GameCore::instance.currentMenuViewType, 0); + } + } + _repeatMonths = this->scenarioEvents[_eventIndex].data.invasion.repeatMonths; + if (!_repeatMonths) { + this->scenarioEvents[_eventIndex].header.done = 1; + } else { + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + _repeatMonths / 0xc; + iVar18 = this->scenarioEvents[_eventIndex].header.year; + this->scenarioEvents[_eventIndex].header.month + = this->scenarioEvents[_eventIndex].header.month + _repeatMonths % 0xc; + iVar22 = this->scenarioEvents[_eventIndex].header.month; + this->scenarioEvents[_eventIndex].header.pre_done = 0; + if (0xb < iVar22) { + this->scenarioEvents[_eventIndex].header.month = iVar22 + -0xc; + this->scenarioEvents[_eventIndex].header.year = iVar18 + 1; + } + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + } + goto LAB_004c5f28; + } + if (_eventType == 2) { + this->scenarioEvents[_eventIndex].header.done = 1; + goto LAB_004c5f28; + } + if (_eventType != 3) + goto LAB_004c5f28; + iVar18 = this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType; + if ((!iVar18) || (iVar18 == 0x1a)) { + if (_previousScenarioEventIndex != -1) { + this->scenarioEvents[_previousScenarioEventIndex].header.done = 1; + } + _previousScenarioEventIndex = _eventIndex; + } + local_a0 = 0; + /* + this is from invasion event code, ignore the meaning here + */ + _spawnUnitCount = 0; + for (_subIndex = 0; _subIndex < 40; _subIndex++) { + _conditionOffset = _subIndex * 4; + _counter = _spawnUnitCount; + /* + this condition is empty? then move to next condition + */ + if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + _subIndex * 4 + 0xf) + == '\0') + goto switchD_004c3756_caseD_18; + _counter = _spawnUnitCount + 1; + /* + Extra event info at: 0x0165f028 + */ + _pConditionIsMet + = &this->SEC_EventsExtra[_eventIndex].conditionIsTrue[_subIndex]; + *_pConditionIsMet = 0; + switch (_subIndex) { + case 0: + local_a0 = _counter; + break; + case 1: + iVar22 = MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, + this)((int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[1] + .value); + iVar18 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentPopulation; + bVar24 = (iVar18 < iVar22); + bVar23 = iVar18 - iVar22 < 0; + goto LAB_004c3fc7; + case 2: + iVar18 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .lordKilledByPlayerID; + if (!iVar18) + break; + cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data + + _conditionOffset + 0xe); + if (((cVar17 != '\0') && (iVar18 != 10)) && (cVar17 + 1 != iVar18)) + goto LAB_004c37cd; + goto LAB_004c3fcd; + case 3: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .playerRelatedFlag + != 0) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + break; + } + goto LAB_004c37cd; + case 4: + iVar22 = MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, + this)((int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[4] + .value); + iVar18 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xf]; + bVar24 = (iVar18 < iVar22); + bVar23 = iVar18 - iVar22 < 0; + goto LAB_004c3fc7; + case 5: + iVar18 = MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, + this)((int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[5] + .value); + cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data + + _conditionOffset + 0xe); + if (cVar17 == '\0') { + iVar22 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[10] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xb] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xc] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xd]; + bVar24 = (iVar22 < iVar18); + bVar23 = iVar22 - iVar18 < 0; + } else { + LAB_004c38d2: + iVar22 = (int)cVar17; + if (iVar22 == 8) { + iVar22 = 7; + } + iVar22 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[iVar22]; + bVar24 = (iVar22 < iVar18); + bVar23 = iVar22 - iVar18 < 0; + } + goto LAB_004c3fc7; + case 6: + case 0x11: + iVar18 = MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, + this)((int)*(short*)((int)&this->scenarioEvents[_eventIndex].data + + _subIndex * 4 + 0xc)); + cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data + + _conditionOffset + 0xe); + if (cVar17 != '\0') + goto LAB_004c38d2; + iVar22 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x11] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x12] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x13] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x14] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x15] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x16] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x17] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x18]; + bVar24 = (iVar22 < iVar18); + bVar23 = iVar22 - iVar18 < 0; + goto LAB_004c3fc7; + case 7: + iVar18 = MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, + this)((int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[7] + .value); + cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data + + _conditionOffset + 0xe); + if (cVar17 != '\0') + goto LAB_004c38d2; + iVar22 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xe] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[2] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[3] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[4] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[6] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[7] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[9]; + bVar24 = (iVar22 < iVar18); + bVar23 = iVar22 - iVar18 < 0; + LAB_004c3fc7: + if (bVar24 == bVar23) { + LAB_004c3fcd: + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + LAB_004c37cd: + *_pConditionIsMet = 0; + } + break; + case 8: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .totalEnemyUnitsCount + == 0) { + _scenarioEventType + = this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType; + if (((_scenarioEventType == 0x1a) || (!_scenarioEventType)) + || (_scenarioEventType == 0x17)) { + iVar18 = _eventIndex + 1; + if (iVar18 < this->eventsCount) { + pSVar15 = this->scenarioEvents[_eventIndex + 1] + .data.scenario.conditions + + 0x19; + do { + if (((*(const int*)&pSVar15[-0x1e] == 1) + && (*(const int*)pSVar15 == 0)) + && (pSVar15[-0x1d].value == 0)) + goto switchD_004c3756_caseD_18; + iVar18 = iVar18 + 1; + pSVar15 = pSVar15 + 0x39; + } while (iVar18 < this->eventsCount); + } + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + } + break; + case 9: + BVar11 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::checkKeepEnclosed, + DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + if (!BVar11) + goto LAB_004c37cd; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + break; + case 10: + iVar18 = 0; + if (DAT_UnitsState::instance.maxUnitCount < 2) + goto LAB_004c3fcd; + pUVar12 = &DAT_UnitsState::instance.units[1].unitType; + iVar22 = DAT_UnitsState::instance.maxUnitCount - 1; + do { + if ((pUVar12[-1] == Map::Units::ULS_NORMAL) + && (*pUVar12 == Map::Units::UT_LIONSHWOLF)) { + iVar18 = iVar18 + 1; + } + pUVar12 = pUVar12 + 0x248; + iVar22 = iVar22 + -1; + } while (iVar22); + if (iVar18) + goto LAB_004c37cd; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + break; + case 0xb: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .totalEnemyUnitsCount + == 0) + goto LAB_004c37cd; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + break; + case 0xc: + iVar18 = 0; + if (DAT_UnitsState::instance.maxUnitCount < 2) + goto LAB_004c3fcd; + pUVar12 = &DAT_UnitsState::instance.units[1].unitType; + iVar22 = DAT_UnitsState::instance.maxUnitCount - 1; + do { + if (((((pUVar12[-1] == Map::Units::ULS_NORMAL) + && ((short)pUVar12[4] + == DAT_GameSynchronyState::instance.currentPlayerSlotID)) + && (*(byte*)(pUVar12 + 0x14f) == 0)) + && (((((pUVar12[0x165] == 0 + && (UVar6 = *pUVar12, + UVar6 != Map::Units::UT_E_LADDER)) + && ((UVar6 != Map::Units::UT_E_ENGINEER + || (pUVar12[0x17d] != 0)))) + && ((UVar6 != Map::Units::UT_S_TOWER + && (UVar6 + != Map::Units::UT_S_BATTERINGRAM)))) + && (UVar6 != Map::Units::UT_S_SHIELD)))) + && ((((UVar6 != Map::Units::UT_S_MANGONEL + && (UVar6 != Map::Units::UT_S_BALLISTA)) + && (UVar6 != Map::Units::UT_S_CATAPULT)) + && ((UVar6 != Map::Units::UT_S_FBALLISTA + && (UVar6 != Map::Units::UT_S_TREBUCHET)))))) { + iVar18 = iVar18 + 1; + } + pUVar12 = pUVar12 + 0x248; + iVar22 = iVar22 + -1; + } while (iVar22); + if (iVar18) + goto LAB_004c37cd; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + break; + case 0xd: + cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data + + _conditionOffset + 0xe); + if (cVar17 == '\0') { + if ((int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0xd] + .value + <= DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[0] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[1] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[2] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[3] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[4] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[5] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[6] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[7] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[8]) { + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[0] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[1] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[2] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[3] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[4] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[5] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[6] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[7] = 0; + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[8] = 0; + this->SEC_EventsExtra[_eventIndex].conditionIsTrue[13] = 1; + local_a0 = local_a0 + 1; + } + } else if (((byte)(cVar17 - 1U) < 4) + && ((int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0xd] + .value + <= DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + -8])) { + DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + -8] = 0; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0xe: + cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data + + _conditionOffset + 0xe); + if (cVar17 == '\0') { + if ((int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0xe] + .value + <= DAT_GameState::instance.mapAndTime.emenyHitArray[0] + + DAT_GameState::instance.mapAndTime.emenyHitArray[1] + + DAT_GameState::instance.mapAndTime.emenyHitArray[2] + + DAT_GameState::instance.mapAndTime.emenyHitArray[3] + + DAT_GameState::instance.mapAndTime.emenyHitArray[4] + + DAT_GameState::instance.mapAndTime.emenyHitArray[5] + + DAT_GameState::instance.mapAndTime.emenyHitArray[6] + + DAT_GameState::instance.mapAndTime.emenyHitArray[7] + + DAT_GameState::instance.mapAndTime.emenyHitArray[8]) { + DAT_GameState::instance.mapAndTime.emenyHitArray[0] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[1] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[2] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[3] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[4] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[5] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[6] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[7] = 0; + DAT_GameState::instance.mapAndTime.emenyHitArray[8] = 0; + this->SEC_EventsExtra[_eventIndex].conditionIsTrue[14] = 1; + local_a0 = local_a0 + 1; + } + } else if (((byte)(cVar17 - 1U) < 4) + && ((int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0xe] + .value + <= DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + 1])) { + DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + 1] = 0; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0xf: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .totalEnemyUnitsCount + == 0) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + if (((DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) + || (this->SEC_U3_MapType2_1 != Map::MT_SIEGE)) + || ((DAT_GameSynchronyState::instance.currentPlayerSlotID != 1 + || (BVar11 = MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::isAttackWaveComplete, + DAT_TroopValueState::ptr)(), + !BVar11)))) + goto LAB_004c37cd; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0x10: + if (DAT_GameState::instance.mapAndTime.cathedralRelated1 == 1) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0x12: + if (DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) { + iVar18 = 0; + if (DAT_BuildingsState::instance.maxBuildingsCount < 2) + goto LAB_004c37cd; + pBVar13 = &DAT_BuildingsState::instance.buildings[1].buildingType; + iVar22 = DAT_BuildingsState::instance.maxBuildingsCount + -1; + do { + if (((pBVar13[-1] != ((BuildingLogicalState)0)) + && (*pBVar13 == Map::Buildings::BT_DAIRYFARM)) + && (pBVar13[0x65] == 0)) { + iVar18 = iVar18 + 1; + } + pBVar13 = pBVar13 + 0x196; + iVar22 = iVar22 + -1; + } while (iVar22); + bVar24 = (iVar18 < 4); + bVar23 = iVar18 + -4 < 0; + goto LAB_004c3fc7; + } + break; + case 0x13: + if (DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) { + iVar18 = 0; + if (DAT_BuildingsState::instance.maxBuildingsCount < 2) + goto LAB_004c37cd; + pBVar13 = &DAT_BuildingsState::instance.buildings[1].buildingType; + iVar22 = DAT_BuildingsState::instance.maxBuildingsCount + -1; + do { + if ((((pBVar13[-1] != ((BuildingLogicalState)0)) + && (*pBVar13 == Map::Buildings::BT_INN)) + && (pBVar13[0x65] == 0)) + && (0 < (short)pBVar13[0xef])) { + iVar18 = iVar18 + 1; + } + pBVar13 = pBVar13 + 0x196; + iVar22 = iVar22 + -1; + } while (iVar22); + bVar24 = (iVar18 < 2); + bVar23 = iVar18 + -2 < 0; + goto LAB_004c3fc7; + } + break; + case 0x14: + sVar7 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .previousBlessedPeoplePercentage; + sVar8 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0x14] + .value; + bVar24 = (sVar7 < sVar8); + bVar23 = (short)(sVar7 - sVar8) < 0; + goto LAB_004c3deb; + case 0x15: + iVar18 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::computeAleCoverage, + DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + iVar22 = (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0x15] + .value; + bVar24 = (iVar18 < iVar22); + bVar23 = iVar18 - iVar22 < 0; + goto LAB_004c3deb; + case 0x16: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .fearFactorLevel + <= -(int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0x16] + .value) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0x17: + iVar22 = (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0x17] + .value; + iVar18 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .fearFactorLevel; + bVar24 = (iVar18 < iVar22); + bVar23 = iVar18 - iVar22 < 0; + LAB_004c3deb: + if (bVar24 == bVar23) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0x27: + if (local_a0 == _spawnUnitCount) { + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_TIME_UNTIL_VICTORY, 1); + if (!this->SEC_Section1081) { + this->SEC_Section1080 + = *(short*)((int)&this->scenarioEvents[_eventIndex].data + 0xa8) + * 800; + this->SEC_Section1090 = this->SEC_Section1080; + } + this->SEC_Section1081 = 1; + if (this->SEC_Section1080 < 1) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + } else { + if (this->SEC_Section1081) { + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_TIME_UNTIL_VICTORY, 0); + } + this->SEC_Section1081 = 0; + } + } + switchD_004c3756_caseD_18: + _spawnUnitCount = _counter; + } + if (((*(short*)((int)&this->scenarioEvents[_eventIndex].data + 8) != 0) + || (!local_a0)) + && (local_a0 < _spawnUnitCount)) + goto LAB_004c5f28; + iVar18 = this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType; + this->scenarioEvents[_eventIndex].header.done = 1; + DAT_GameState::instance.mapAndTime.scenarioEventTimers[iVar18] = 1; + iVar18 = DAT_GameSynchronyState::instance.currentPlayerSlotID; + switch (this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType) { + case 0: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 0) { + iVar18 = _eventIndex + 1; + if (iVar18 < this->eventsCount) { + _pConditionIsMet = &this->scenarioEvents[_eventIndex + 1] + .data.scenario.ScenarioEventType; + do { + if (((_pConditionIsMet[-3] == 3) + && (((*_pConditionIsMet == 0 || (*_pConditionIsMet == 0x1a)) + && (_pConditionIsMet[-4] + <= DAT_GameState::instance.mapAndTime.year)))) + && ((DAT_GameState::instance.mapAndTime.year + != _pConditionIsMet[-4] + || (_pConditionIsMet[-5] + < DAT_GameState::instance.mapAndTime.month)))) + goto switchD_004c382e_caseD_2; + iVar18 = iVar18 + 1; + _pConditionIsMet = _pConditionIsMet + 0x39; + } while (iVar18 < this->eventsCount); + } + if (((DAT_GameCore::instance.gameMode_2 + == Game::GM_CAMPAIGN_MISSION) + || (DAT_GameCore::instance.gameMode_2 + == Game::GM_ECONOMIC_CAMPAIGN_SH1)) + || (DAT_GameCore::instance.gameMode_2 + == Game::GM_BUILDERUnk)) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .playerDeathRelated = 1; + DAT_GameState::instance.mapAndTime.unknownCountdown01 = 0xf0; + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 1); + if ((DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_BATTERINGRAM) + || (DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_SHIELD)) { + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.buildMenuTab + = DAT_GameCore::instance.tabTypeSiegeSubset; + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, + DAT_GameCore::ptr)(UI::Enums::MVT_BUILD_MENU, 0); + } + DAT_TileMapState::instance.currentMapperCommand + = Commands::M_MAPPER_NULL; + if (0 < DAT_UnitsState::instance.totalUnitsInSelection) { + MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, + DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::queueEscapeCommand, + DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER( + Input::MouseState_Func::resetMouseCursorState, + DAT_MouseState::ptr)(); + } + if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x13) + == '\0') { + if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x1f) + == '\0') { + if ((((*(char*)((int)&this->scenarioEvents[_eventIndex].data + + 0x23) + == '\0') + && (*(char*)((int)&this->scenarioEvents[_eventIndex] + .data + + 0x27) + == '\0')) + && (*(char*)((int)&this->scenarioEvents[_eventIndex] + .data + + 0x2b) + == '\0')) + && (*(char*)((int)&this->scenarioEvents[_eventIndex].data + + 0x53) + == '\0')) { + this->field133_0x145d8 = 1; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, + this)(); + } else { + this->field133_0x145d8 = 3; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, + this)(); + } + } else { + this->field133_0x145d8 = 2; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, + this)(); + } + } else { + this->field133_0x145d8 = 1; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, + this)(); + } + break; + } + } + goto switchD_004c382e_caseD_2; + case 1: + if ((DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .playerDeathRelated + == 0) + && (( + (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION + || (DAT_GameCore::instance.gameMode_2 + == Game::GM_ECONOMIC_CAMPAIGN_SH1)) + || (DAT_GameCore::instance.gameMode_2 + == Game::GM_BUILDERUnk)))) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated = 2; + MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::setAIControlStatusTo100000, + DAT_UnitsState::ptr)(); + DAT_GameState::instance.mapAndTime.unknownCountdown01 = 0xf0; + if ((DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) + && (this->SEC_U3_MapType2_1 == Map::MT_SIEGE)) { + DAT_GameState::instance.mapAndTime.unknownCountdown01 = 0x280; + } + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 2); + if ((DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_BATTERINGRAM) + || (DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_SHIELD)) { + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.buildMenuTab + = DAT_GameCore::instance.tabTypeSiegeSubset; + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, + DAT_GameCore::ptr)(UI::Enums::MVT_BUILD_MENU, 0); + } + DAT_TileMapState::instance.currentMapperCommand + = Commands::M_MAPPER_NULL; + if (0 < DAT_UnitsState::instance.totalUnitsInSelection) { + MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, + DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::queueEscapeCommand, + DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER( + Input::MouseState_Func::resetMouseCursorState, + DAT_MouseState::ptr)(); + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + } + } + default: + goto switchD_004c382e_caseD_2; + case 3: + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::flagTribesOfType, + DAT_TribesState::ptr)(0xe); + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 4: + iVar18 = this->scenarioEvents[_eventIndex].data.scenario.actionData; + if (!iVar18) { + iVar18 = 1; + } + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::consumeFlaggedTribesOfType, + DAT_TribesState::ptr)(0xe, iVar18); + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 5: + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, + DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + (int)((int)(SEC_RNG::instance.currentNumber2 % 9)), + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.xEntry + * 8, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.yEntry + * 8, + (int)((int)(( + uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.tileEntry])), + Map::Units::UT_JUGGLER); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, + DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + (SEC_RNG::instance.currentNumber2 >> 3) % 9, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.xEntry + * 8, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.yEntry + * 8, + (UnitType)((int)(( + uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.tileEntry])), + Map::Units::UT_JUGGLER); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, + DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + (SEC_RNG::instance.currentNumber2 >> 6) % 9, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.xEntry + * 8, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.yEntry + * 8, + (UnitType)((int)(( + uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.tileEntry])), + Map::Units::UT_JUGGLER); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, + DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + (SEC_RNG::instance.currentNumber2 >> 9) % 9, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.xEntry + * 8, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.yEntry + * 8, + (UnitType)((int)(( + uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.tileEntry])), + Map::Units::UT_FIREEATER); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, + DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + (SEC_RNG::instance.currentNumber2 >> 0xc) % 9, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.xEntry + * 8, + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.yEntry + * 8, + (UnitType)((int)(( + uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .campground.tileEntry])), + Map::Units::UT_FIREEATER); + pcVar25 = "Random_Events1.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent1VideoName; + /* + "a travelling fair has come to town my lord" added by script: "A ‘Travelling + Fair’ has come to town, my Lord." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 1); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (0xb < iVar18) { + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + } + LAB_004c4621: + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 6: + DAT_GameCore::instance.isTimeHalted = TRUE; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 7: + DAT_GameCore::instance.isTimeHalted = FALSE; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 8: + MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::switchPlayerOwnership, + DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID); + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func:: + setupBarracksCampgroundPositions, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func:: + setupMercenaryPostCampgroundPositions, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::triggerStoneTowerDeathForPlayer, + DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID); + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::countPlayerResources, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + = UI::Enums::BASMTT_HUNTERSHUT; + DAT_GameCore::instance.secondaryActiveMenuTabToSwitchTo.tabType + = UI::Enums::BASMTT_HUNTERSHUT; + DAT_GameCore::instance.tabTypeSiegeSubset = UI::Enums::BMTT_CASTLE; + if (((DAT_GameCore::instance.currentMenuViewType + == UI::Enums::MVT_BUILD_MENU) + && ((DAT_GameCore::instance.activeMenuTab.tabType + != UI::Enums::BASMTT_STOCKS + || (MACRO_CALL_MEMBER( + Game::GameCore_Func::switchToMenuView, + DAT_GameCore::ptr)(UI::Enums::MVT_BUILD_MENU, 0), + DAT_GameCore::instance.currentMenuViewType + == UI::Enums::MVT_BUILD_MENU)))) + && ((DAT_GameCore::instance.activeMenuTab.tabType + == UI::Enums::BASMTT_SIEGETENT_BATTERINGRAM + || (DAT_GameCore::instance.activeMenuTab.tabType + == UI::Enums::BASMTT_SIEGETENT_SHIELD)))) { + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + = UI::Enums::BASMTT_SIEGETENT_BATTERINGRAM; + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, + DAT_GameCore::ptr)(UI::Enums::MVT_BUILD_MENU, 0); + } + iVar22 = DAT_GameSynchronyState::instance.currentPlayerSlotID; + iVar18 + = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .lordID; + if ((!iVar18) + || (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .lordUID + == DAT_UnitsState::instance.units[iVar18].uid)) + goto switchD_004c382e_caseD_2; + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .lordID = 0; + DAT_GameState::instance.playerDataArray[iVar22].lordUID = 0; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 9: + DAT_GameCore::instance.xbowProducible_logic = 1; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0xb: + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .someCount48 = 0x18; + iVar22 = DAT_GameState::instance.playerDataArray[iVar18].popularity; + if (6000 < iVar22) { + DAT_GameState::instance.playerDataArray[iVar18].popularity + = (iVar22 + -6000) / 2 + 6000; + } + MACRO_CALL_MEMBER(Game::GameStateStructures_Func:: + spawnPoisonCloudsAtRandomStorageOrArmyBuilding, + DAT_GameState::ptr)( + iVar18, this->scenarioEvents[_eventIndex].data.scenario.actionData); + pcVar25 = "Random_Events2.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent2VideoName; + /* + added by script: "Plague has descended on our castle your lordship." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 2); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0xc: + iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_WHEATFARM); + if (iVar18) { + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::harmWheatFarmsOfPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + pcVar25 = "Random_Events3.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent3VideoName; + /* + added by script: "A pestilence is devastating our wheat crops, Sire." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 3); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0xd: + iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_HOPFARM); + if (iVar18) { + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::harmHopFarmsOfPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + pcVar25 = "Random_Events4.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent4VideoName; + /* + added by script: "Our hops plants are overrun with hop weevil, the crop is + ruined, My Liege." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 4); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0xe: + iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_APPLEFARM); + if (iVar18) { + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func:: + harmAppleFarmTreesOfPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + pcVar27 = "Random_Events5.wav"; + pcVar25 = ""; + /* + added by script: "Our apple orchards are barren, my lord. The people + suspect witchcraft." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 5); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)("", + (char*)((int)(DAT_MissionAestheticsDefinedData::instance.RandomEvent5VideoName)), + ""); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0xf: + MACRO_CALL_MEMBER(Map::LandscapeState_Func::killEveryFifthTree, + DAT_LandscapeState::ptr)(); + pcVar25 = "Random_Events6.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent6VideoName; + /* + added by script: "Sire, woodcutters report that the recent drought has killed + off many trees." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 6); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0x10: + iVar18 = MACRO_CALL_MEMBER(Map::Units::TribesState_Func:: + hasAvailableSpawnSlotForWildlifeOrMercs, + DAT_TribesState::ptr)(); + if ((iVar18) + && ((iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_HOPFARM), + iVar18 != 0 + || (iVar18 = MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func:: + findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_WHEATFARM), + iVar18 != 0)))) { + DAT_GameState::instance.mapAndTime.eventCountdownRabbitInfestation = 1200; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func:: + spawnWildlifeOrMercAtAvailableSlot, + DAT_TribesState::ptr)(); + MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, + DAT_MinimapViewState::ptr)(DAT_TribesState::instance.unknownX_01, + DAT_TribesState::instance.unknownY_01); + pcVar25 = "Random_Events7.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent7VideoName; + /* + added by script: "Rabbits are breeding at an alarming rate Liege. Our + crops are threatened." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 7); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0x11: + iVar18 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::findRecentOrSignpostSpawnLocation, + DAT_TribesState::ptr)(&uStack_78, &uStack_7c); + if ((iVar18) + && (BVar11 + = MACRO_CALL_MEMBER(Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(uStack_78, uStack_7c), + iVar18 = DAT_GameSynchronyState::instance.currentPlayerSlotID, + BVar11)) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .someCount49 = 0xc; + iVar22 = DAT_GameState::instance.playerDataArray[iVar18].popularity; + if (6000 < iVar22) { + DAT_GameState::instance.playerDataArray[iVar18].popularity + = (iVar22 + -6000) / 2 + 6000; + } + iVar18 = 0; + if (0 < this->scenarioEvents[_eventIndex].data.scenario.actionData) { + do { + MACRO_CALL_MEMBER(Map::Units::TribesState_Func:: + findRecentOrSignpostSpawnLocation, + DAT_TribesState::ptr)(&uStack_78, &uStack_7c); + dVar14 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::createAnimal, + DAT_TribesState::ptr)(Commands::M_MAPPER_LION, + uStack_78, uStack_7c, + (int)((int)((uint) + * (byte*)(DAT_ViewportRenderState::instance + .translationMatrix[uStack_7c] + .addXgetTile + + 0x1d32c38 + uStack_78)))); + MACRO_CALL_MEMBER( + UI::MinimapViewState_Func::setSpawnMoment, + DAT_MinimapViewState::ptr)(uStack_78, (int)((int)(uStack_7c))); + iVar18 = iVar18 + 1; + DAT_TribesState::instance.tribes[dVar14].unknownBool02 = 0; + DAT_TribesState::instance.tribes[dVar14].unknownBool01 = 1; + } while (iVar18 + < this->scenarioEvents[_eventIndex].data.scenario.actionData); + } + pcVar27 = ""; + pcVar25 = ""; + /* + added by script: "I have alarming reports that lions are abroad in the + land. People are scared my Lord." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 8); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0x12: + BVar11 + = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::hasAnySignpost, + DAT_GameState::ptr)(); + if (BVar11) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .someCount50 = 0x10; + DAT_TroopValueState::instance.attackInfo.inv_count + = DAT_TroopValueState::instance.attackInfo.inv_count + 1; + if (0x31 < DAT_TroopValueState::instance.attackInfo.inv_count) { + DAT_TroopValueState::instance.attackInfo.inv_count = 1; + } + MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::initializeAttackWaveSlot, + DAT_TroopValueState::ptr)( + DAT_TroopValueState::instance.attackInfo.inv_count, 0); + DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray + [DAT_TroopValueState::instance.attackInfo.inv_count] = 8; + iVar18 = MACRO_CALL_MEMBER(Game::GameStateStructures_Func:: + pickRandomAccessibleSignpostEntry, + DAT_GameState::ptr)(); + dVar14 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::createTribeWithSpawnedUnit, + DAT_TribesState::ptr)(0, 9, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y, 8, + Map::Units::UT_E_MACE, + this->scenarioEvents[_eventIndex].data.scenario.actionData + 1); + MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, + DAT_MinimapViewState::ptr)( + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); + iVar18 = 0; + if (0 < DAT_TribesState::instance.tribes[dVar14].size) { + do { + iVar22 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getUnitIDForIndexInTribe, + DAT_TribesState::ptr)(dVar14, iVar18); + sVar7 = DAT_TribesState::instance.tribes[dVar14].size; + iVar18 = iVar18 + 1; + DAT_UnitsState::instance.units[iVar22].calculatedOwnerPlayerIndex + = 5; + DAT_UnitsState::instance.units[iVar22].logicalState + = Map::Units::ULS_NORMAL; + } while (iVar18 < sVar7); + } + pcVar25 = "Random_Events9.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent9VideoName; + /* + added by script: "Bandits are operating near the castle Lordship." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 9); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0x13: + iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findBuildingOfTypeForPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_DAIRYFARM); + if (iVar18) { + MACRO_CALL_MEMBER( + Map::Units::UnitsState_Func::setRandomNumberOnCows, + DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::setDairyFarmCheeseCounter, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + pcVar27 = "Random_Events10.wav"; + pcVar25 = ""; + /* + added by script: "Our cows have been struck down by a strange malady, my + lord." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 10); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)("", + (char*)((int)(DAT_MissionAestheticsDefinedData::instance.RandomEvent10VideoName)), + ""); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0x14: + BVar11 + = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::hasAnySignpost, + DAT_GameState::ptr)(); + if (BVar11) { + iVar18 = MACRO_CALL_MEMBER(Game::GameStateStructures_Func:: + pickRandomAccessibleSignpostEntry, + DAT_GameState::ptr)(); + iVar22 = 0; + dVar14 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::createTribeWithSpawnedUnit, + DAT_TribesState::ptr)(0, 3, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y, + (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), + Map::Units::UT_E_ARCHER, + this->scenarioEvents[_eventIndex].data.scenario.actionData); + tribeID = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::createTribeWithSpawnedUnit, + DAT_TribesState::ptr)(0, 0xc, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y, + (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), + Map::Units::UT_E_MONK, 1); + MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, + DAT_MinimapViewState::ptr)( + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); + DAT_TribesState::instance.tribes[dVar14].pendingScatterMove = 0; + DAT_TribesState::instance.tribes[tribeID].pendingScatterMove = 0; + if (0 < DAT_TribesState::instance.tribes[dVar14].size) { + do { + iVar18 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getUnitIDForIndexInTribe, + DAT_TribesState::ptr)(dVar14, iVar22); + sVar7 = DAT_TribesState::instance.tribes[dVar14].size; + iVar22 = iVar22 + 1; + DAT_UnitsState::instance.units[iVar18].calculatedOwnerPlayerIndex + = 8; + DAT_UnitsState::instance.units[iVar18].logicalState + = Map::Units::ULS_NORMAL; + } while (iVar22 < sVar7); + } + iVar18 = 0; + if (0 < DAT_TribesState::instance.tribes[tribeID].size) { + do { + iVar22 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getUnitIDForIndexInTribe, + DAT_TribesState::ptr)(tribeID, iVar18); + DAT_UnitsState::instance.units[iVar22].calculatedOwnerPlayerIndex + = 8; + DAT_UnitsState::instance.units[iVar22].logicalState + = Map::Units::ULS_NORMAL; + iVar18 = iVar18 + 1; + } while (iVar18 < DAT_TribesState::instance.tribes[tribeID].size); + } + iVar18 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .keep.id; + if (0 < iVar18) { + BVar9 = DAT_BuildingsState::instance.buildings[iVar18].buildingType; + uVar19 = 0; + y1 = 0; + if (BVar9 == Map::Buildings::BT_MANORHOUSE) { + uVar19 + = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].x + + 3; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].y + + 8; + } else if (BVar9 == Map::Buildings::BT_STONEKEEP) { + uVar19 + = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].x + + 3; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].y + + 3; + } else if (BVar9 == Map::Buildings::BT_STRONGHOLD) { + uVar19 + = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].x + + 3; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].y + + 3; + } else if (BVar9 == Map::Buildings::BT_KEEPFOUR) { + uVar19 + = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].x + + 4; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].y + + 4; + } else if (BVar9 == Map::Buildings::BT_KEEPFIVE) { + uVar19 + = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].x + + 5; + y1 = (int)(short)DAT_BuildingsState::instance.buildings[iVar18].y + + 5; + } + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::giveTribeMoveInstruction, + DAT_TribesState::ptr)(dVar14, uVar19, y1, 0, 0, + Map::Units::Instructions::UMSE_0); + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::giveTribeMoveInstruction, + DAT_TribesState::ptr)(tribeID, uVar19, y1, 0, 0, + Map::Units::Instructions::UMSE_0); + } + pcVar25 = "Random_Events11.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent11VideoName; + /* + added by script: "Some outlaws from the woods have returned to our cause, + my lord." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xb); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0x15: + DAT_GameState::instance.mapAndTime.unitLadyRelated = 1; + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .someCount52 = 0xc; + if (10000 < DAT_GameState::instance.playerDataArray[iVar18].popularity) { + DAT_GameState::instance.playerDataArray[iVar18].popularity = 10000; + } + pcVar25 = "Random_Events12.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent12VideoName; + /* + added by script: "The people rejoice at your forthcoming marriage, Sire." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xc); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, + DAT_SFXState::ptr)(Audio::SFX::SEID_CHAPEL_BELL); + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x16: + DAT_GameState::instance.mapAndTime.unitJesterRelated = 1; + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .someCount53 = 0x30; + if (10000 < DAT_GameState::instance.playerDataArray[iVar18].popularity) { + DAT_GameState::instance.playerDataArray[iVar18].popularity = 10000; + } + pcVar25 = "Random_Events13.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent13VideoName; + /* + added by script: "A Jester has arrived at the castle Liege. I have taken the + liberty of offering him employment." + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xd); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x17: + if (((DAT_GameCore::instance.gameMode_2 != Game::GM_CAMPAIGN_MISSION) + && (this->scenarioEvents[_eventIndex].header.year == 0x43d)) + && (this->scenarioEvents[_eventIndex].header.month == 0xb)) { + dVar14 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::createTribeWithSpawnedUnit, + DAT_TribesState::ptr)(0, 3, 0x85, 0x116, + (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), + Map::Units::UT_E_ARCHER, 0x14); + sVar7 = DAT_TribesState::instance.tribes[dVar14].size; + DAT_TribesState::instance.tribes[dVar14].pendingScatterMove = 3; + if (0 < sVar7) { + iVar18 = 0; + do { + iVar22 = iVar18 + 1; + iVar18 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getUnitIDForIndexInTribe, + DAT_TribesState::ptr)(dVar14, iVar18); + sVar7 = DAT_TribesState::instance.tribes[dVar14].size; + DAT_UnitsState::instance.units[iVar18].calculatedOwnerPlayerIndex + = 6; + iVar18 = iVar22; + } while (iVar22 < sVar7); + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + } + } + goto switchD_004c382e_caseD_2; + case 0x18: + DAT_GameCore::instance.section1076 = 0; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x19: + DAT_GameCore::instance.section1076 = 1; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x1a: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 0) { + iVar18 = _eventIndex + 1; + if (iVar18 < this->eventsCount) { + _pConditionIsMet = &this->scenarioEvents[_eventIndex + 1] + .data.scenario.ScenarioEventType; + do { + if ((_pConditionIsMet[-3] == 3) + && ((((*_pConditionIsMet == 0 || (*_pConditionIsMet == 0x1a)) + && (_pConditionIsMet[-4] + <= DAT_GameState::instance.mapAndTime.year)) + && ((DAT_GameState::instance.mapAndTime.year + != _pConditionIsMet[-4] + || (_pConditionIsMet[-5] + < DAT_GameState::instance.mapAndTime.month)))))) + goto switchD_004c382e_caseD_2; + iVar18 = iVar18 + 1; + _pConditionIsMet = _pConditionIsMet + 0x39; + } while (iVar18 < this->eventsCount); + } + this->scenarioEvents[_eventIndex].header.done = 0; + this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType = 0; + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year; + LAB_004c4072: + iVar18 = DAT_GameState::instance.mapAndTime.month; + iVar22 = DAT_GameState::instance.mapAndTime.month + 1; + this->scenarioEvents[_eventIndex].header.month = iVar22; + if (0xb < iVar22) { + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xb; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + } + } + goto switchD_004c382e_caseD_2; + case 0x1b: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 0) { + this->scenarioEvents[_eventIndex].header.done = 0; + this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType = 1; + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year; + goto LAB_004c4072; + } + goto switchD_004c382e_caseD_2; + case 0x1c: + iVar18 = 0; + if (0 < this->eventsCount) { + pSVar15 = this->scenarioEvents[0].data.scenario.conditions + 0x19; + do { + if ((*(const int*)&pSVar15[-0x1e] == 1) + && (*(const int*)pSVar15 != 0)) { + pSVar15->value = 0; + pSVar15->subType = 0; + pSVar15->enabled = 0; + pSVar15[-0x1d].value = 1; + pSVar15[-0xffffffff0000001f].value = 0x49d; + pSVar15[-0xffffffff0000001f].subType = 0; + pSVar15[-0xffffffff0000001f].enabled = 0; + } + iVar18 = iVar18 + 1; + pSVar15 = pSVar15 + 0x39; + } while (iVar18 < this->eventsCount); + } + switchD_004c382e_caseD_2: + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x1d: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .totalFood + != 0) { + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func:: + applyFoodLossPercentageToPlayer, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + this->scenarioEvents[_eventIndex].data.scenario.actionData); + pcVar10 = "general_message3.wav"; + if (this->scenarioEvents[_eventIndex].data.scenario.actionData == 100) { + iVar18 = 0x10; + } else { + iVar18 = 0xe; + } + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent14VideoName; + /* + added by script: "Thieves have stolen some food from our granary." + */ + pcVar25 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar25, pcVar26, pcVar10); + } + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + break; + case 0x1e: + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .someCount51 = 8; + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::spreadFireRandomlyToBuildings, + DAT_BuildingsState::ptr)( + iVar18, this->scenarioEvents[_eventIndex].data.scenario.actionData); + iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findFirstBuildingOfType, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_WELL); + if (!iVar18) { + iVar18 = MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findFirstBuildingOfType, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_WATERPOT); + if (!iVar18) { + iVar18 = 0x11; + } else { + iVar18 = 0xf; + } + } else { + iVar18 = 0xf; + } + pcVar25 = "general_warning16.wav"; + pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName; + /* + added by script: "There is fire in the castle and we have not built any wells + my Liege!" + */ + pcVar10 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; + if ((!bVar4) + || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, + bVar5 == 1)) + goto switchD_004c382e_caseD_2; + if (bVar5 != 10) { + this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; + } + uVar19 = (uint)bVar4; + this->scenarioEvents[_eventIndex].header.done = 0; + if (3 < uVar19) { + uVar19 + = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + } + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; + iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + + ((int)uVar19 / 0xc) * -0xc; + this->scenarioEvents[_eventIndex].header.month = iVar18; + if (iVar18 < 0xc) + goto LAB_004c4621; + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + } + LAB_004c5f28: + _eventIndex = _eventIndex + 1; + } while (_eventIndex < this->eventsCount); + } + iVar18 = DAT_GameState::instance.mapAndTime.month + 3; + local_88 = DAT_GameState::instance.mapAndTime.year; + if (0xb < iVar18) { + iVar18 = DAT_GameState::instance.mapAndTime.month + -9; + local_88 = DAT_GameState::instance.mapAndTime.year + 1; + } + local_70[0] = 0; + local_70[1] = 0; + local_70[2] = 0; + local_70[3] = 0; + local_70[4] = 0; + local_70[5] = 0; + local_70[6] = 0; + local_70[7] = 0; + local_70[8] = 0; + _eventIndex = 0; + if (0 < this->eventsCount) { + psVar21 = &this->scenarioEvents[0]; + do { + if ((((local_88 == psVar21->header.year) && (iVar18 == psVar21->header.month)) + && ((!psVar21->header.pre_done + && ((iVar22 = psVar21->header.tl_type, psVar21->header.pre_done = 1, + iVar22 == 1 + && (DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 1, + DAT_GameCore::instance.section1076 == 0)))))) + && (iVar22 = (psVar21->data).invasion.crusaderArabian, local_70[iVar22] == 0)) { + iVar20 = 0; + iVar1 = iVar22 * 4; + numInGroup = iVar1 + 1; + iVar21 = 5; + _pConditionIsMet = (psVar21->data).invasion.unitCountsPerUnitType + 3; + do { + iVar20 = iVar20 + _pConditionIsMet[-3] + _pConditionIsMet[-2] + + _pConditionIsMet[-1] + _pConditionIsMet[1] + *_pConditionIsMet; + iVar21 = iVar21 + -1; + _pConditionIsMet = _pConditionIsMet + 5; + } while (iVar21); + if (0x18 < iVar20) { + if (iVar20 < 0x4b) { + numInGroup = iVar1 + 2; + } else if (iVar20 < 0x96) { + numInGroup = iVar1 + 3; + } else { + numInGroup = iVar1 + 4; + } + } + local_70[iVar22] = 1; + if (!iVar22) { + pcVar26 = (&DAT_MissionAestheticsDefinedData::instance + .field59_0xec)[numInGroup]; + pcVar10 = "good_arab_nervous.bik"; + } else { + if (iVar22 != 1) + goto LAB_004c609a; + pcVar26 = (&DAT_MissionAestheticsDefinedData::instance + .field59_0xec)[numInGroup]; + pcVar10 = "good_soldier_nervous.bik"; + } + pcVar25 = MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)( + DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar25, pcVar10, pcVar26); + } + LAB_004c609a: + _eventIndex = _eventIndex + 1; + psVar21 = psVar21 + 0x72; + } while (_eventIndex < this->eventsCount); + } + if ((DAT_GameState::instance.gameTicksLoadBalancer == 0x97) + && (DAT_GameState::instance.mapAndTime.week == 3)) { + iVar22 = DAT_GameState::instance.mapAndTime.month + 1; + iVar18 = DAT_GameState::instance.mapAndTime.year; + if (0xb < iVar22) { + iVar22 = DAT_GameState::instance.mapAndTime.month + -0xb; + iVar18 = DAT_GameState::instance.mapAndTime.year + 1; + } + iVar21 = 0; + if (0 < this->eventsCount) { + pIVar16 = this->scenarioEvents; + do { + if (((iVar18 == (pIVar16->header).year) && (iVar22 == (pIVar16->header).month)) + && ((pIVar16->header).tl_type == 1)) { + DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown = 40; + } + iVar21 = iVar21 + 1; + pIVar16 = pIVar16 + 1; + } while (iVar21 < this->eventsCount); + } + } + } + } else { + if ((DAT_BinkControlState::instance.binkObjPtrArray[1] == (HBINK)0x0) + && (!DAT_VideoBikQueue::instance.storedMessages_0x924)) { + DAT_GameState::instance.mapAndTime.unknownCountdown01 + = DAT_GameState::instance.mapAndTime.unknownCountdown01 + -1; + } + if (!DAT_GameState::instance.mapAndTime.unknownCountdown01) { + DAT_VideoBikQueue::instance.storedMessages_0x924 = 0; + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(UI::Enums::MMT_NONE, FALSE); + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition2::ptr)(UI::Enums::MMT_NONE, FALSE); + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition3::ptr)(UI::Enums::MMT_NONE, FALSE); + DAT_MenuTextInputState::instance.DAT_SomeTextArrayIndex = 9; + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, + DAT_MenuTextInputState::ptr)(); + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + MACRO_CALL_MEMBER( + Game::GameCore_Func::incrementMissionProgress, DAT_GameCore::ptr)(); + DAT_GameCore::instance.section1066 = 2; + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, + DAT_GameCore::ptr)(UI::Enums::MVT_GAME_LOSTUnk, 0); + DAT_GameCore::instance.section1066 = 0; + } + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + } + if (DAT_GameCore::instance.gameMode_2 != Game::GM_ECONOMIC_CAMPAIGN_SH1) { + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { + if (DAT_GameCore::instance.field24_0x6c) { + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; + MACRO_CALL(UI::MenuItems::General_Func:: + MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(0x16); + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + if ((int)this->SEC_U3_MapType2_1 < 2) { + MACRO_CALL_MEMBER( + Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); + } else { + DAT_GameCore::instance.section1095 = 1; + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 0x2f; + MACRO_CALL_MEMBER( + UI::MenuTextInputState_Func::activateModalDialogAndClearText, + DAT_MenuTextInputState::ptr)(UI::Enums::MMT_QUIT_DIALOG); + } + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, + DAT_GameCore::ptr)(UI::Enums::MVT_GAME_LOSTUnk, 0); + } + DAT_GameCore::instance.section1066 = 2; + } + MACRO_CALL(UI::DisplayElements_Func:: + CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + MACRO_CALL_MEMBER(Game::GameCore_Func::incrementMission, DAT_GameCore::ptr)(); + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); + } + MACRO_CALL( + UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + MACRO_CALL( + UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + } + } + } + } + } else if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::updateMilitaryCampaignMissionState, this)(); + } + } + +} +} diff --git a/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp b/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp new file mode 100644 index 0000000000..82cec09f34 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp @@ -0,0 +1,241 @@ +#include "../../Map.func.hpp" +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" +#include "OpenSHC/Rendering/Bink/AIMessageQueue.func.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" + +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_TribesState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_VideoBikQueue.hpp" +#include "OpenSHC/Map/Units/UnitTypeInt.hpp" + +namespace OpenSHC { +namespace Map { + + using Map::Units::UnitType; + using Map::Units::UnitTypeInt; + + /* + WARNING (jumptable): Heritage AFTER dead removal. Revisit: 0x01667ebc + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004C13F0 + void MapPropertiesState::spawnInvasionEventAttackWave() + { + byte(*pabVar1)[10]; + byte* pbVar2; + int iVar3; + char cVar4; + int _sliderValue; + int _unitCount; + int _unitTypeOther; + UnitTypeInt _unitType; + char* eventVideoBik; + char* eventWavFile; + int local_10; + int local_c; + int _sliderIndex; + DAT_TroopValueState::instance.attackInfo.inv_count = DAT_TroopValueState::instance.attackInfo.inv_count + 1; + local_c = 0; + local_10 = 0; + if (0x31 < DAT_TroopValueState::instance.attackInfo.inv_count) { + DAT_TroopValueState::instance.attackInfo.inv_count = 1; + } + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackWaveSlot, + DAT_TroopValueState::ptr)(DAT_TroopValueState::instance.attackInfo.inv_count, 0); + DAT_TroopValueState::instance.attackInfo + .attackWavePlayerIDArray[DAT_TroopValueState::instance.attackInfo.inv_count] + = (char)this->invasionEventContent.crusaderArabian + 2; + _sliderIndex = 0; + do { + _sliderValue = this->invasionEventContent.unitCountsPerUnitType[_sliderIndex]; + if (!_sliderValue) + goto LAB_004c16b3; + _unitTypeOther = 0; + _unitType = ((UnitType)0); + iVar3 = 0; + switch (_sliderIndex) { + case 0: + _unitTypeOther = 3; + _unitType = Map::Units::UT_E_ARCHER; + break; + case 1: + _unitTypeOther = 7; + _unitType = Map::Units::UT_E_XBOW; + break; + case 2: + _unitTypeOther = 5; + _unitType = Map::Units::UT_E_SPEAR; + break; + case 3: + _unitTypeOther = 6; + _unitType = Map::Units::UT_E_PIKE; + break; + case 4: + _unitTypeOther = 9; + _unitType = Map::Units::UT_E_MACE; + break; + case 5: + _unitTypeOther = 8; + _unitType = Map::Units::UT_E_SWORD; + break; + case 6: + _unitTypeOther = 10; + _unitType = Map::Units::UT_E_KNIGHT; + iVar3 = 10; + goto switchD_004c146e_caseD_18; + case 7: + _unitTypeOther = 4; + _unitType = Map::Units::UT_E_LADDER; + break; + case 8: + _unitTypeOther = 0xb; + _unitType = Map::Units::UT_E_ENGINEER; + break; + case 9: + _unitTypeOther = 0x16; + _unitType = Map::Units::UT_S_CATAPULT; + break; + case 10: + _unitTypeOther = 0x17; + _unitType = Map::Units::UT_S_TREBUCHET; + break; + case 0xb: + _unitTypeOther = 0x13; + _unitType = Map::Units::UT_S_BATTERINGRAM; + break; + case 0xc: + _unitTypeOther = 0x14; + _unitType = Map::Units::UT_S_TOWER; + break; + case 0xd: + _unitTypeOther = 0x15; + _unitType = Map::Units::UT_S_SHIELD; + break; + case 0xe: + _unitTypeOther = 0xc; + _unitType = Map::Units::UT_E_MONK; + break; + case 0xf: + _unitTypeOther = 2; + _unitType = Map::Units::UT_TUNNELER; + break; + case 0x10: + _unitTypeOther = 0x19; + _unitType = Map::Units::UT_A_ARCHER; + break; + case 0x11: + _unitTypeOther = 0x1a; + _unitType = Map::Units::UT_A_SLAVE; + break; + case 0x12: + _unitTypeOther = 0x1b; + _unitType = Map::Units::UT_A_SLINGER; + break; + case 0x13: + _unitTypeOther = 0x1c; + _unitType = Map::Units::UT_A_ASSASSIN; + break; + case 0x14: + _unitTypeOther = 0x1d; + _unitType = Map::Units::UT_A_HARCHER; + break; + case 0x15: + _unitTypeOther = 0x1e; + _unitType = Map::Units::UT_A_SWORDSMAN; + break; + case 0x16: + _unitTypeOther = 0x1f; + _unitType = Map::Units::UT_A_FIRETHROWER; + break; + case 0x17: + _unitTypeOther = 0x18; + _unitType = Map::Units::UT_S_FBALLISTA; + break; + default: + goto switchD_004c146e_caseD_18; + } + /* + if a siege engine... + */ + iVar3 = 10; + switchD_004c146e_caseD_18: + cVar4 = (char)_sliderValue; + if (_unitTypeOther == 0x16) { + pabVar1 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + + DAT_TroopValueState::instance.attackInfo.inv_count; + (*pabVar1)[0] = (*pabVar1)[0] + cVar4; + } else if (_unitTypeOther == 0x17) { + pbVar2 = DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count] + + 1; + *pbVar2 = *pbVar2 + cVar4; + } else if (_unitTypeOther == 0x13) { + pbVar2 = DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count] + + 2; + *pbVar2 = *pbVar2 + cVar4; + } else if (_unitTypeOther == 0x14) { + pbVar2 = DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count] + + 3; + *pbVar2 = *pbVar2 + cVar4; + } else if (_unitTypeOther == 0x15) { + pbVar2 = DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count] + + 4; + *pbVar2 = *pbVar2 + cVar4; + } else if (_unitTypeOther == 0x18) { + pbVar2 = DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count] + + 8; + *pbVar2 = *pbVar2 + cVar4; + } else { + /* + if not a siege engine... + */ + _unitCount = _sliderValue / (_sliderValue / iVar3 + 1); + while (0 < _sliderValue) { + if (_sliderValue < _unitCount) { + _unitCount = _sliderValue; + } + iVar3 = (&DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray)[DAT_TroopValueState::instance.attackInfo.inv_count]; + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, DAT_TribesState::ptr)(local_c, + _unitTypeOther, DAT_GameState::instance.mapAndTime.signpostsMapEdge[iVar3][local_10].x, + DAT_GameState::instance.mapAndTime.signpostsMapEdge[iVar3][local_10].y, + this->invasionEventContent.crusaderArabian + 2, (UnitType)((int)(_unitType)), ((UnitType)0), + _unitCount, 0); + local_c = local_c + 1; + local_10 = local_10 + 1; + _sliderValue = _sliderValue - _unitCount; + if (DAT_GameState::instance.mapAndTime.signpostsMapEdgeDataCounter <= local_10) { + local_10 = 0; + } + } + } + LAB_004c16b3: + _sliderIndex = _sliderIndex + 1; + if (0x18 < _sliderIndex) { + if (!this->invasionEventContent.crusaderArabian) { + eventWavFile = "infidel_attack.wav"; + eventVideoBik = "sultan_nervous.bik"; + } else { + if (this->invasionEventContent.crusaderArabian != 1) { + this->eventsCount = 0; + } + eventWavFile = "arabian_attack.wav"; + eventVideoBik = "good_soldier_nervous.bik"; + } + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)("", eventVideoBik, eventWavFile); + this->eventsCount = 0; + } + } while (true); + } + +} +} diff --git a/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp b/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp new file mode 100644 index 0000000000..bee9caf210 --- /dev/null +++ b/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp @@ -0,0 +1,135 @@ +#include "../Synchrony.func.hpp" + +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/CampaignTrailMission.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/TrailType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/CHAR_ARRAY_00eb0ab0.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_SkirmishDefinedData.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" + +namespace OpenSHC { + +using Commands::GameCommandType; +using Game::CampaignTrailMission; +using Game::GameMode; +using Game::TrailType; +using WindowsHelper::Enums::BOOLEnum; + +// FUNCTION: STRONGHOLDCRUSADER 0x004C6B20 +void Synchrony::LoadSkirmishCampaignData(int missionID) +{ + char cVar1; + char* pcVar3; + int* piVar4; + int iVar5; + int iVar6; + int iVar7; + char (*pacVar8)[250]; + CampaignTrailMission* pCVar9; + pCVar9 = DAT_SkirmishDefinedData::instance.SkirmishTrailMissions + missionID; + if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { + pCVar9 = DAT_SkirmishDefinedData::instance.ExtremeTrailMissions + missionID; + } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { + pCVar9 = DAT_SkirmishDefinedData::instance.WarchestTrailMissions + missionID; + } + pcVar3 = (char*)(pCVar9->mapNameAddress); + iVar7 = (int)CHAR_ARRAY_00eb0ab0::instance - (int)pcVar3; + do { + cVar1 = *pcVar3; + pcVar3[iVar7] = cVar1; + pcVar3 = pcVar3 + 1; + } while (cVar1 != '\0'); + MACRO_CALL(OS_Func::_memset)(DAT_GameSynchronyState::instance.DAT_PlayerNames, 0, 0x8ca); + piVar4 = DAT_GameSynchronyState::instance.currentAIArray; + do { + piVar4[-0x1b] = -1; + *piVar4 = 0; + piVar4[9] = -1; + piVar4 = piVar4 + 1; + } while ((int)piVar4 < 0x191dea0); + pcVar3 = MACRO_CALL_MEMBER(Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0); + pacVar8 = DAT_GameSynchronyState::instance.DAT_PlayerNames + 1; + do { + cVar1 = *pcVar3; + (*pacVar8)[0] = cVar1; + pcVar3 = pcVar3 + 1; + pacVar8 = (char (*)[250])(*pacVar8 + 1); + } while (cVar1 != '\0'); + DAT_GameSynchronyState::instance.isHost = TRUE; + DAT_GameSynchronyState::instance.currentGameMode = Game::GM_SKIRMISH_SINGLE_PLAYER; + MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + Commands::GCT_ASK_FOR_SLOT_ASSIGNMENT); + if (1 < pCVar9->numberOfPlayers) { + piVar4 = &pCVar9->player2AI; + iVar7 = 1; + do { + iVar5 = iVar7 + 1; + DAT_GameSynchronyState::instance.currentAIArray[iVar7 + 1] = *piVar4; + MACRO_CALL(Synchrony_Func::ResetAiVariationArrayValue)(iVar5); + piVar4 = piVar4 + 1; + iVar7 = iVar5; + } while (iVar5 < pCVar9->numberOfPlayers); + } + MACRO_CALL(Synchrony_Func::SetAIPlayerNickNames)(); + iVar7 = pCVar9->numberOfPlayers; + iVar5 = 0; + piVar4 = &pCVar9->team1; + do { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5 + 1] = (byte)*piVar4; + if (iVar5 >= iVar7) { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5 + 1] = 0xff; + } + iVar5 = iVar5 + 1; + piVar4 = piVar4 + 1; + } while (iVar5 < 8); + iVar7 = 0; + iVar5 = 1; + do { + byte bVar2 = DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5]; + iVar6 = (int)(char)bVar2; + DAT_GameState::instance.mapAndTime.playerGroupArray[iVar5] = iVar6; + if (('\0' < (char)bVar2) && (DAT_GameState::instance.mapAndTime.playerTeams[iVar5] = iVar6, iVar6 > iVar7)) { + iVar7 = iVar6; + } + iVar5 = iVar5 + 1; + } while (iVar5 < 9); + iVar5 = 1; + do { + if (DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5] == 0) { + iVar7 = iVar7 + 1; + DAT_GameState::instance.mapAndTime.playerTeams[iVar5] = iVar7; + } + iVar5 = iVar5 + 1; + } while (iVar5 < 9); + DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance = pCVar9->fairness; + DAT_GameSynchronyState::instance.skirmishGameIntensityType = pCVar9->startLevels; + DAT_GameSynchronyState::instance.playerPositionsArray[0] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[1] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[2] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[3] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[4] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[5] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[6] = -10; + DAT_GameSynchronyState::instance.playerPositionsArray[7] = -10; + piVar4 = &pCVar9->position1; + iVar7 = 0; + do { + if (*piVar4 != 0) { + DAT_GameSynchronyState::instance.playerPositionsArray[*piVar4 - 1] = (char)iVar7; + } + iVar7 = iVar7 + 1; + piVar4 = piVar4 + 1; + } while (iVar7 < 8); +} + +} diff --git a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp new file mode 100644 index 0000000000..e4cc5b22b2 --- /dev/null +++ b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp @@ -0,0 +1,125 @@ +#include "../MenuTextInputState.func.hpp" + +#include "OpenSHC/IO/ResourceManager.func.hpp" +#include "OpenSHC/OS.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/MenuItems/SaveLoadMap.func.hpp" +#include "OpenSHC/UI/MenuTextInputState.func.hpp" +#include "OpenSHC/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_MouseState.hpp" +#include "OpenSHC/Globals/DAT_ResourceManager.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" +#include "OpenSHC/Globals/INT_00b95b64.hpp" +#include "OpenSHC/Globals/MSVC_SecurityCookie.hpp" + +namespace OpenSHC { +namespace UI { + + using Commands::GameCommandType; + using Game::GameMode; + using UI::Enums::MenuModalType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004968A0 + void MenuTextInputState::loadOrSaveGame(int action) + { + int iVar1; + int iVar2; + int* puVar5; + int iVar6; + if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY + || DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SKIRMISH_SINGLE_PLAYER + || DAT_GameSynchronyState::instance.saveRelated != 1 || action != 10) { + DAT_MouseState::instance.waitCursorToggle = 1; + MACRO_CALL(UI::Helpers_Func::SetCursorDependingOnProgramState)(); + MACRO_CALL(OS_Func::_memset)(DAT_MinimapViewState::instance.loadedMiniMap, 0, 80000); + INT_00b95b64::instance = 1; + if ((DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) + || (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SKIRMISH_SINGLE_PLAYER)) { + std::string _savesPath + = MACRO_CALL_MEMBER(IO::ResourceManager_Func::paths_getSavesPath, DAT_ResourceManager::ptr)(true); + _savesPath.append("*.sav", 5); + MACRO_CALL_MEMBER(IO::ResourceManager_Func::discoverMapFiles, DAT_ResourceManager::ptr)( + _savesPath.c_str()); + this->fileListEntryCount = DAT_ResourceManager::instance.mapFileCounter; + for (int _mapIndex = 0; _mapIndex < DAT_ResourceManager::instance.mapFileCounter; _mapIndex++) { + (&this->DAT_MapSelectionPreloadMapIndexMapping)[_mapIndex] = _mapIndex; + } + } else { + std::string _savesPath + = MACRO_CALL_MEMBER(IO::ResourceManager_Func::paths_getSavesPath, DAT_ResourceManager::ptr)(true); + _savesPath.append("*.msv", 5); + MACRO_CALL_MEMBER(IO::ResourceManager_Func::discoverMapFiles, DAT_ResourceManager::ptr)( + _savesPath.c_str()); + this->fileListEntryCount = DAT_ResourceManager::instance.mapFileCounter; + iVar6 = 0; + if (0 < DAT_ResourceManager::instance.mapFileCounter) { + puVar5 = this->DAT_ArrayOfMapIndices + 499; + do { + puVar5[-500] = iVar6; + *puVar5 = 1; + if (action != 10) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = iVar6; + MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, + DAT_GameSynchronyState::ptr)((Commands::GameCommandType)(Commands::GCT_LOAD_MAP_HEADER + | Commands::GCT_MULTIPLAYER_INITIATE_ANNOUNCE_HOST)); + } + iVar6 = iVar6 + 1; + puVar5 = puVar5 + 1; + } while (iVar6 < DAT_ResourceManager::instance.mapFileCounter); + } + } + DAT_MouseState::instance.waitCursorToggle = 0; + this->fileListSortOrder = 0; + this->DAT_MenuLoadGameRelativeSelectionOffset = 0; + if (!this->fileListEntryCount) { + this->DAT_MenuLoadGameRelativeSelectionIndex = -1; + } else { + this->DAT_MenuLoadGameRelativeSelectionIndex = 0; + } + this->lastListClickTime = 0; + this->lastClickedListIndex = 0xffffffff; + this->field49_0xac = 0; + this->previewedListIndex = 0xffffffff; + this->fileListVisibleRowCount = 0x10; + if (action == 9) { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( + UI::Enums::MMT_LOAD_MAP); + this->fileListContext = 1; + iVar6 = this->savedListOffset1; + iVar1 = this->savedListSelection1; + iVar2 = this->savedListSortOrder1; + } else { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( + UI::Enums::MMT_SAVE_MAP); + DAT_UserTextHandlerState::instance.allowUserTextInput = 0; + MACRO_CALL_MEMBER(Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)(2); + MACRO_CALL_MEMBER(Text::UserTextHandler_Func::moveCursorToEnd, DAT_UserTextHandlerState::ptr)(); + DAT_UserTextHandlerState::instance.allowUserTextInput = 1; + this->fileListContext = 3; + iVar6 = this->savedListOffset2; + iVar1 = this->savedListSelection2; + iVar2 = this->savedListSortOrder2; + } + if ((this->DAT_MenuLoadGameRelativeSelectionIndex != -1) + && (this->fileListSortOrder = iVar2, this->DAT_MenuLoadGameRelativeSelectionIndex = iVar1, + this->DAT_MenuLoadGameRelativeSelectionOffset = iVar6, iVar6 + iVar1 >= this->fileListEntryCount)) { + this->DAT_MenuLoadGameRelativeSelectionIndex = 0; + this->DAT_MenuLoadGameRelativeSelectionOffset = 0; + } + MACRO_CALL(UI::MenuItems::SaveLoadMap_Func::MenuItemActionHandler_SaveLoadMap_TableHeader)( + -1 - this->fileListSortOrder); + } else { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, this)(); + }; + return; + } + +} +} From 0a8b2c764ab69de96691bbd9004df0c803cea16f Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 14:38:01 +0100 Subject: [PATCH 02/60] Fix compile errors against main's headers Renamed fields, globals and resolvers by address, enum-typed arguments, array fields indexed directly, clang-format. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Game/Skirmish/SetupSkirmishMode.cpp | 15 +- .../restoreSkirmishLobbySetup.cpp | 2 +- .../Skirmish_PrepareLeaderboardView.cpp | 45 +- src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp | 4 +- .../computeMissionCompletionScore.cpp | 14 +- .../Map/MapPropertiesState/loadMap.cpp | 30 +- .../loadMapSiegeHeaderForMissionIndex.cpp | 8 +- .../loadMissionMapAndSetLord.cpp | 4 +- .../processSingleplayerEvents.cpp | 564 ++++++++---------- .../spawnInvasionEventAttackWave.cpp | 19 +- .../UI/MenuTextInputState/loadOrSaveGame.cpp | 20 +- 11 files changed, 330 insertions(+), 395 deletions(-) diff --git a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp index f5c1ba66d1..7f59cdebdf 100644 --- a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp +++ b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp @@ -44,14 +44,12 @@ namespace Game { } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { pCVar7 = DAT_SkirmishDefinedData::instance.WarchestTrailMissions + skirmishTrailMission; } - MACRO_CALL_MEMBER( - Synchrony::GameSynchronyState_Func::setupSkirmishLobby, DAT_GameSynchronyState::ptr)(); + MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::setupSkirmishLobby, DAT_GameSynchronyState::ptr)(); DAT_GameSynchronyState::instance.isHost = TRUE; DAT_GameSynchronyState::instance.currentGameMode = Game::GM_SKIRMISH_SINGLE_PLAYER; DAT_GameSynchronyState::instance.DPLAYX_ReceivedPlayerID = 1; DAT_GameCore::instance.gameMode_2 = Game::GM_SKIRMISH_AND_MULTIPLAYER; - MACRO_CALL(OS_Func::_memset)( - DAT_GameSynchronyState::instance.DAT_PlayerNames, 0, (size_t)((int)(2250))); + MACRO_CALL(OS_Func::_memset)(DAT_GameSynchronyState::instance.DAT_PlayerNames, 0, (size_t)((int)(2250))); piVar2 = DAT_GameSynchronyState::instance.currentAIArray; do { piVar2[-0x1b] = -1; @@ -59,8 +57,7 @@ namespace Game { piVar2[9] = -1; piVar2 = piVar2 + 1; } while ((int)piVar2 < 0x191dea0); - pcVar3 = MACRO_CALL_MEMBER( - Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0); + pcVar3 = MACRO_CALL_MEMBER(Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0); pacVar6 = DAT_GameSynchronyState::instance.DAT_PlayerNames + 1; do { cVar1 = *pcVar3; @@ -120,7 +117,7 @@ namespace Game { iVar5 = iVar5 + 1; piVar2 = piVar2 + 1; } while (iVar5 < 8); - pcVar3 = (char *)(pCVar7->mapNameAddress); + pcVar3 = (char*)(pCVar7->mapNameAddress); iVar4 = 0x1a22f9c - (int)pcVar3; do { cVar1 = *pcVar3; @@ -152,8 +149,8 @@ namespace Game { } DAT_GameState::instance.mapAndTime.year = (int)_startDateInMonths / 0xc; DAT_GameState::instance.mapAndTime.month = (int)_startDateInMonths % 0xc; - DAT_GameSynchronyState::instance.finalResults.yearStart = (int)_startDateInMonths / 0xc; - DAT_GameSynchronyState::instance.finalResults.monthStart = (int)_startDateInMonths % 0xc; + DAT_GameSynchronyState::instance.finalResults.tail.tail1.yearStart = (int)_startDateInMonths / 0xc; + DAT_GameSynchronyState::instance.finalResults.tail.tail1.monthStart = (int)_startDateInMonths % 0xc; } } diff --git a/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp b/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp index 5973d3aed5..2e5b9a8334 100644 --- a/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp +++ b/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp @@ -82,7 +82,7 @@ namespace Game { DAT_GameCore::instance.selectedLordTypes[6] = this->playerLordTypeArray[6]; DAT_GameCore::instance.selectedLordTypes[7] = this->playerLordTypeArray[7]; DAT_GameCore::instance.selectedLordTypes[8] = this->playerLordTypeArray[8]; - DAT_GameCore::instance.field152_0x2340 = this->mbr_0xf0; + DAT_GameCore::instance.field_0x2340 = this->mbr_0xf0; DAT_GameCore::instance.selectedLordTypeUnk = this->selectedLordType; DAT_GameSynchronyState::instance.skirmishDefaultPopularity = this->popularity; DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected = this->mapSelectionRelativeSelected; diff --git a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp index 35136f3b38..9df1760c68 100644 --- a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp +++ b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp @@ -4,13 +4,12 @@ #include "OpenSHC/Text/TextManager.func.hpp" #include "OpenSHC/DE/SHCDE/eTextSections.hpp" -#include "OpenSHC/Globals/DAT_00eb9b60.hpp" #include "OpenSHC/Globals/DAT_00ed3124.hpp" #include "OpenSHC/Globals/DAT_MissionDefinedData.hpp" #include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" #include "OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp" #include "OpenSHC/Globals/DAT_TextManagerObject.hpp" -#include "OpenSHC/Globals/INT_00eb0e44.hpp" +#include "OpenSHC/Globals/INT_00eb9b60.hpp" #include "OpenSHC/Globals/INT_00ed2bdc.hpp" #include "OpenSHC/Globals/INT_ARRAY_00eb0e48.hpp" #include "OpenSHC/Globals/INT_ARRAY_00eb96d8.hpp" @@ -81,7 +80,7 @@ namespace Game { */ if (DAT_MissionDefinedData::instance.sortColumn < 2) { iVar7 = 0; - DAT_00eb9b60::instance = 0; + INT_00eb9b60::instance = 0; if (DAT_MissionDefinedData::instance.descending == 1) { _index = 0; if (0 < _count) { @@ -92,10 +91,10 @@ namespace Game { } _index = _index + 1; } while (_index < _count); - DAT_00eb9b60::instance = iVar7; + INT_00eb9b60::instance = iVar7; } } else if ((!DAT_MissionDefinedData::instance.descending) && (0 < _count)) { - piVar5 = INT_00eb0e44::ptr + _count; + piVar5 = &INT_ARRAY_00eb0e48::instance[_count - 1]; _index = _count; do { _index = _index + -1; @@ -106,13 +105,13 @@ namespace Game { piVar5 = piVar5 + -1; _count = _count + -1; } while (_count); - DAT_00eb9b60::instance = iVar7; + INT_00eb9b60::instance = iVar7; } } else { if (DAT_MissionDefinedData::instance.sortColumn == 4) { _index = 0; iVar7 = 0; - DAT_00eb9b60::instance = 0; + INT_00eb9b60::instance = 0; if (0 < _count) { puVar7 = DAT_SkMasters2DataArray::ptr[0]; do { @@ -126,14 +125,15 @@ namespace Game { } iVar7 = iVar7 + 1; puVar7 = puVar7 + 0x2fc; - DAT_00eb9b60::instance = _index; + INT_00eb9b60::instance = _index; } while (iVar7 < _count); } - MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)( + DAT_MissionDefinedData::instance.descending); } if (DAT_MissionDefinedData::instance.sortColumn == 2) { _index = 0; - DAT_00eb9b60::instance = 0; + INT_00eb9b60::instance = 0; if (iVar7 == 1) { iVar7 = 0; if (0 < _count) { @@ -148,8 +148,9 @@ namespace Game { iVar7 = iVar7 + 1; pSVar8 = pSVar8 + 1; } while (iVar7 < _count); - DAT_00eb9b60::instance = _index; - MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + INT_00eb9b60::instance = _index; + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)( + DAT_MissionDefinedData::instance.descending); } } else { iVar7 = 0; @@ -158,17 +159,15 @@ namespace Game { do { if (INT_ARRAY_00eb0e48::instance[iVar7] != 0) { if (pSVar8->score) { - pcVar4 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)( - DE::SHCDE::TEXT_TRAIL_NAMES_CRU, pSVar8->score); + pcVar4 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_TRAIL_NAMES_CRU, pSVar8->score); pcVar9 = pSVar8->mapName; do { cVar1 = *pcVar4; *pcVar9 = cVar1; pcVar4 = pcVar4 + 1; pcVar9 = pcVar9 + 1; - _index = DAT_00eb9b60::instance; + _index = INT_00eb9b60::instance; _count = DAT_SkMasters2Data_Count::instance; } while (cVar1 != '\0'); } @@ -183,19 +182,20 @@ namespace Game { INT_ARRAY_00ed2be0::instance[_index] = ((uint)bVar6 * -0x100 + -1) - (uint)bVar3; INT_ARRAY_00ed27f0::instance[_index] = iVar7; _index = _index + 1; - DAT_00eb9b60::instance = _index; + INT_00eb9b60::instance = _index; } iVar7 = iVar7 + 1; pSVar8 = pSVar8 + 1; } while (iVar7 < _count); } } - MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)( + DAT_MissionDefinedData::instance.descending); } if (DAT_MissionDefinedData::instance.sortColumn == 3) { _index = 0; iVar7 = 0; - DAT_00eb9b60::instance = 0; + INT_00eb9b60::instance = 0; if (0 < _count) { piVar5 = &DAT_SkMasters2DataArray::instance[0].gameDurationInMinutes; do { @@ -207,10 +207,11 @@ namespace Game { } iVar7 = iVar7 + 1; piVar5 = piVar5 + 0x2fc; - DAT_00eb9b60::instance = _index; + INT_00eb9b60::instance = _index; } while (iVar7 < _count); } - MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)( + DAT_MissionDefinedData::instance.descending); } } } diff --git a/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp index 841ab3836b..4e45d6f41a 100644 --- a/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp +++ b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp @@ -5,10 +5,10 @@ #include "OpenSHC/Globals/DAT_00df5558.hpp" #include "OpenSHC/Globals/DAT_00df5560.hpp" #include "OpenSHC/Globals/DAT_00df5590.hpp" +#include "OpenSHC/Globals/DAT_DisableTutorialRestrictions.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" #include "OpenSHC/Globals/DAT_TutorialCurrentStep.hpp" -#include "OpenSHC/Globals/INT_DisableTutorialRestrictions.hpp" namespace OpenSHC { @@ -19,7 +19,7 @@ BOOLEnum Game::Tutorial_IsActionAllowed(undefined4 actionType, int actionParam) { int iVar1; bool bVar2; - if (INT_DisableTutorialRestrictions::instance) { + if (DAT_DisableTutorialRestrictions::instance) { return TRUE; } switch (actionType) { diff --git a/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp index f3804bc1cc..70c7107f49 100644 --- a/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp @@ -228,8 +228,8 @@ namespace Map { LAB_004be25c: if (pcVar7[0x10] != '\0') { this->objectiveGoodsType[this->objectiveGoodsCount] = 0xf; - iVar5 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, - this)((int)*(short*)(pcVar7 + 0xd)); + iVar5 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)*(short*)(pcVar7 + 0xd)); this->objectiveGoodsSurplus[this->objectiveGoodsCount] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .currentResources[0xf] @@ -242,8 +242,8 @@ namespace Map { } if (pcVar7[4] != '\0') { this->objectiveGoodsType[this->objectiveGoodsCount] = -1; - iVar5 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, - this)((int)*(short*)(pcVar7 + 1)); + iVar5 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)*(short*)(pcVar7 + 1)); this->objectiveGoodsSurplus[this->objectiveGoodsCount] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .currentPopulation @@ -284,13 +284,11 @@ namespace Map { } this->troopSurvivalScore = 0; if ((DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) - || ((DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk - && ((int)this->SEC_U3_MapType2_1 < 2)))) { + || ((DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk && ((int)this->SEC_U3_MapType2_1 < 2)))) { psVar8 = &DAT_UnitsState::instance.units[1].owner; iVar5 = DAT_GameSynchronyState::instance.currentPlayerSlotID; do { - if (((psVar8[-5] != Map::Units::ULS_INVISIBLE) && (*psVar8 == iVar5)) - && (psVar8[0x107] != 0)) { + if (((psVar8[-5] != Map::Units::ULS_INVISIBLE) && (*psVar8 == iVar5)) && (psVar8[0x107] != 0)) { iVar5 = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, DAT_TroopValueState::ptr)((Map::Units::UnitType)((int)psVar8[-4])); iVar6 = iVar6 + iVar5; diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp index 8a0b04ed0f..a3e8dc8673 100644 --- a/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp @@ -12,10 +12,13 @@ #include "OpenSHC/Map/Units/TroopValueState.func.hpp" #include "OpenSHC/Map/Units/UnitsState.func.hpp" #include "OpenSHC/Rendering/Bink/AIMessageQueue.func.hpp" +#include "OpenSHC/AI/Siege/SiegeUnitCounts.hpp" #include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/GameMode2Int.hpp" #include "OpenSHC/IO/FileResourceType.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_AICState.hpp" @@ -33,19 +36,18 @@ #include "OpenSHC/Globals/FilePackagerObj.hpp" #include "OpenSHC/Globals/MSVC_SecurityCookie.hpp" #include "OpenSHC/Globals/TIME_ReceivedMessage_2.hpp" -#include "OpenSHC/Game/GameMode2Int.hpp" -#include "OpenSHC/Map/Units/UnitTypeShort.hpp" namespace OpenSHC { namespace Map { + using AI::Siege::SiegeUnitCounts; using Game::GameMode2; + using Game::GameMode2Int; using IO::FileResourceType; using Map::Units::UnitLogicState; using Map::Units::UnitType; - using WindowsHelper::Enums::BOOLEnum; - using Game::GameMode2Int; using Map::Units::UnitTypeShort; + using WindowsHelper::Enums::BOOLEnum; // FUNCTION: STRONGHOLDCRUSADER 0x004C62C0 void MapPropertiesState::loadMap(char* mapName) @@ -93,8 +95,7 @@ namespace Map { IO::FRT_MAPS, (char const*)((int)(mapName))); MACRO_CALL_MEMBER(IO::FilePackager_Func::readMapOrSavFile, FilePackagerObj::ptr)( DAT_MapDefinedData::instance.MapSectionAddressArray); - MACRO_CALL_MEMBER( - Audio::MSS::SoundSystem_Func::mapLoadingAndLaunchGameRelated1, DAT_SoundSystemState::ptr)(); + MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::mapLoadingAndLaunchGameRelated1, DAT_SoundSystemState::ptr)(); DAT_GameState::instance.mapAndTime.difficulty = local_30; DAT_GameCore::instance.xbowProducible_logic = local_10; DAT_GameCore::instance.pikeProducible_logic = local_28; @@ -110,8 +111,7 @@ namespace Map { iVar6 = 8; pUVar3 = &DAT_UnitsState::instance.units[1].unitType; do { - if (((pUVar3[-1] != Map::Units::ULS_INVISIBLE) - && (*pUVar3 == Map::Units::UT_E_ARCHER)) + if (((pUVar3[-1] != Map::Units::ULS_INVISIBLE) && (*pUVar3 == Map::Units::UT_E_ARCHER)) && (pUVar3[4] == 1)) { iVar6 = iVar6 + -1; *(int*)(pUVar3 + -0x3f) = 3; @@ -153,8 +153,7 @@ namespace Map { mapName = mapName + 1; } while (cVar1 != '\0'); if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { - MACRO_CALL_MEMBER( - Game::GameCore_Func::removeJesterAndLadyUnitsInCertainMissions, DAT_GameCore::ptr)(); + MACRO_CALL_MEMBER(Game::GameCore_Func::removeJesterAndLadyUnitsInCertainMissions, DAT_GameCore::ptr)(); } else if (DAT_GameCore::instance.gameMode_2 == Game::GM_ECONOMIC_CAMPAIGN_SH1) { MACRO_CALL_MEMBER(Game::GameCore_Func::removeLadyAndJester, DAT_GameCore::ptr)(); } @@ -180,7 +179,7 @@ namespace Map { DAT_GameState::instance.mapAndTime.startGoods[7] = DAT_GameState::instance.mapAndTime.startGoods[8]; DAT_GameState::instance.mapAndTime.startGoods[8] = 0; pSVar5 = &DAT_GameState::instance.mapAndTime.siegeInformation; - pSVar8 = &this->SEC_SiegeInformation; + pSVar8 = (SiegeUnitCounts*)this->SEC_SiegeInformation; do { pSVar5->archers = pSVar8->archers; pSVar5 = (SiegeUnitCounts*)&pSVar5->crossbowmen; @@ -197,8 +196,7 @@ namespace Map { MACRO_CALL_MEMBER(Game::GameStateStructures_Func::clearEnemyRelatedStructures, DAT_GameState::ptr)(); DAT_UnitsState::instance.lastSelectedUnitID = 0; MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, DAT_UnitsState::ptr)(); - MACRO_CALL_MEMBER( - Map::Units::UnitsState_Func::clearSelectionCountsAndPlayerIDs, DAT_UnitsState::ptr)(); + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::clearSelectionCountsAndPlayerIDs, DAT_UnitsState::ptr)(); DAT_GameState::instance.mapAndTime.euroRecruitable[4] = (int)this->barracksRecruitability.recruitability.macemen; DAT_GameState::instance.mapAndTime.euroRecruitable[5] @@ -253,10 +251,8 @@ namespace Map { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::importTradingCosts, this)(); MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::clearAttackInfo, DAT_TroopValueState::ptr)(); MACRO_CALL_MEMBER(AI::AICState_Func::recomputeAIZonerLayer, DAT_AICState::ptr)(); - MACRO_CALL_MEMBER( - Map::TileMapState_Func::setSignpostDistanceForCampaignMission, DAT_TileMapState::ptr)(); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playNextStoredBinkVideo, DAT_VideoBikQueue::ptr)(); + MACRO_CALL_MEMBER(Map::TileMapState_Func::setSignpostDistanceForCampaignMission, DAT_TileMapState::ptr)(); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playNextStoredBinkVideo, DAT_VideoBikQueue::ptr)(); DAT_GameCore::instance.xbowProducible_logic = (int)this->SEC_XbowProducible_save; DAT_GameCore::instance.bowProducible_logic = (int)this->SEC_BowProducible_save; DAT_GameCore::instance.pikeProducible_logic = (int)this->SEC_PikeProducible_save; diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp index 484a15172d..85a6ce68a3 100644 --- a/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp @@ -19,19 +19,19 @@ namespace Map { pcVar1 = param_1 + -1; if ((int)pcVar1 < 5) { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( - (char*)(&DAT_MissionAestheticsDefinedData::instance.field15_0x3c)[(int)pcVar1]); + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)pcVar1]); } if ((int)pcVar1 < 10) { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( - (char*)(&DAT_MissionAestheticsDefinedData::instance.field15_0x3c)[(int)pcVar1]); + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)pcVar1]); } if ((int)pcVar1 < 0xf) { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( - (char*)(&DAT_MissionAestheticsDefinedData::instance.field15_0x3c)[(int)pcVar1]); + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)pcVar1]); } if ((int)pcVar1 < 20) { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( - (char*)(&DAT_MissionAestheticsDefinedData::instance.field15_0x3c)[(int)pcVar1]); + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)pcVar1]); } } diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp index 0c5090855c..d9b45f589e 100644 --- a/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp @@ -18,7 +18,7 @@ namespace Map { void MapPropertiesState::loadMissionMapAndSetLord(int missionNumber) { int iVar1; - char** mapName; + char* mapName; iVar1 = missionNumber + -1; if (iVar1 < 5) { LAB_004c688d: @@ -32,7 +32,7 @@ namespace Map { } mapName = (&DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName)[missionNumber]; } - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)((char*)mapName); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)(mapName); LAB_004c68b3: MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::setMissionNumberSpecificLord, DAT_UnitsState::ptr)( missionNumber); diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 9b66e888e0..9f0ec19504 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -24,12 +24,17 @@ #include "OpenSHC/DE/SHCDE/eTextSections.hpp" #include "OpenSHC/Game/GameMode.hpp" #include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Game/ScenarioEvents/ScenarioEventCondition.hpp" #include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" #include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" #include "OpenSHC/Map/MapType2.hpp" #include "OpenSHC/Map/Units/Instructions/UnitMatchSpeedEnum.hpp" #include "OpenSHC/Map/Units/UnitLogicState.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeInt.hpp" +#include "OpenSHC/Map/Units/UnitTypeShort.hpp" #include "OpenSHC/UI/Enums/BuildMenuTabType.hpp" #include "OpenSHC/UI/Enums/BuildingsAndStatusMenuTabType.hpp" #include "OpenSHC/UI/Enums/DisplayElementID.hpp" @@ -59,10 +64,6 @@ #include "OpenSHC/Globals/DAT_VideoBikQueue.hpp" #include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" #include "OpenSHC/Globals/SEC_RNG.hpp" -#include "OpenSHC/Game/ScenarioEvents/ScenarioEventCondition.hpp" -#include "OpenSHC/Map/Buildings/BuildingTypeShort.hpp" -#include "OpenSHC/Map/Units/UnitTypeInt.hpp" -#include "OpenSHC/Map/Units/UnitTypeShort.hpp" namespace OpenSHC { namespace Map { @@ -72,11 +73,15 @@ namespace Map { using DE::SHCDE::eTextSections; using Game::GameMode; using Game::GameMode2; + using Game::ScenarioEvents::ScenarioEventCondition; using Map::MapType2; using Map::Buildings::BuildingLogicalState; using Map::Buildings::BuildingType; + using Map::Buildings::BuildingTypeShort; using Map::Units::UnitLogicState; using Map::Units::UnitType; + using Map::Units::UnitTypeInt; + using Map::Units::UnitTypeShort; using Map::Units::Instructions::UnitMatchSpeedEnum; using UI::Enums::BuildingsAndStatusMenuTabType; using UI::Enums::BuildMenuTabType; @@ -84,10 +89,6 @@ namespace Map { using UI::Enums::MenuModalType; using UI::Enums::MenuViewType; using WindowsHelper::Enums::BOOLEnum; - using Game::ScenarioEvents::ScenarioEventCondition; - using Map::Buildings::BuildingTypeShort; - using Map::Units::UnitTypeInt; - using Map::Units::UnitTypeShort; // FUNCTION: STRONGHOLDCRUSADER 0x004C31A0 void MapPropertiesState::processSingleplayerEvents() @@ -245,8 +246,7 @@ namespace Map { great danger." added by script: "There are no wells in the castle my Liege. Should a fire break out we would be in great danger." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, + pcVar10 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x12); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); @@ -473,9 +473,10 @@ namespace Map { .data.invasion.crusaderArabian; iVar22 = local_48[iVar18 + 9]; local_48[iVar18 + 9] = iVar22 + 1; - iVar21 = (&DAT_TroopValueState::instance.attackInfo - .unknownSignpostRelatedArray)[DAT_TroopValueState::instance - .attackInfo.inv_count]; + iVar21 + = DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray[DAT_TroopValueState::instance + .attackInfo.inv_count]; MACRO_CALL_MEMBER( Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, DAT_TribesState::ptr)(iVar22, _unitAIBehaviourTypeUnk, @@ -498,10 +499,10 @@ namespace Map { LAB_004c5db4: _subIndex = _subIndex + 1; } while (_subIndex < 0x19); - iVar18 = (&DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray) - [DAT_TroopValueState::instance.attackInfo.inv_count]; - MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, - DAT_MinimapViewState::ptr)( + iVar18 = DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray + [DAT_TroopValueState::instance.attackInfo.inv_count]; + MACRO_CALL_MEMBER( + UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)( DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); DAT_TroopValueState::instance.attackInfo.inv_count = local_80; @@ -528,8 +529,8 @@ namespace Map { == UI::Enums::BASMTT_SIEGETENT_SIEGETOWER || (DAT_GameCore::instance.activeMenuTab.tabType == UI::Enums::BASMTT_SIEGETENT_SHIELD)))) { - MACRO_CALL_MEMBER(Game::GameCore_Func::swapBuildMenuTab, - DAT_GameCore::ptr)(); + MACRO_CALL_MEMBER( + Game::GameCore_Func::swapBuildMenuTab, DAT_GameCore::ptr)(); if (DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType == UI::Enums::BASMTT_SIEGETENT_SIEGETOWER) { if (DAT_GameCore::instance.currentMenuViewType @@ -538,11 +539,14 @@ namespace Map { = UI::Enums::BASMTT_HUNTERSHUT; } else if (DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { - DAT_GameCore::instance.landscapingmenuMenuTabToSwitchTo = 0xe7; + DAT_GameCore::instance.landscapingmenuMenuTabToSwitchTo + .buildMenuTab = 0xe7; } } - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, - DAT_GameCore::ptr)((UI::Enums::MenuViewType)DAT_GameCore::instance.currentMenuViewType, 0); + MACRO_CALL_MEMBER( + Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + (UI::Enums::MenuViewType)DAT_GameCore::instance.currentMenuViewType, + 0); } } _repeatMonths = this->scenarioEvents[_eventIndex].data.invasion.repeatMonths; @@ -560,8 +564,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar22 + -0xc; this->scenarioEvents[_eventIndex].header.year = iVar18 + 1; } - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; } goto LAB_004c5f28; @@ -606,8 +609,8 @@ namespace Map { break; case 1: iVar22 = MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::getDifficultyMultipliedValue, - this)((int)this->scenarioEvents[_eventIndex] + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[1] .value); iVar18 = DAT_GameState::instance @@ -642,8 +645,8 @@ namespace Map { goto LAB_004c37cd; case 4: iVar22 = MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::getDifficultyMultipliedValue, - this)((int)this->scenarioEvents[_eventIndex] + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[4] .value); iVar18 = DAT_GameState::instance @@ -655,8 +658,8 @@ namespace Map { goto LAB_004c3fc7; case 5: iVar18 = MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::getDifficultyMultipliedValue, - this)((int)this->scenarioEvents[_eventIndex] + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[5] .value); cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data @@ -697,9 +700,9 @@ namespace Map { case 6: case 0x11: iVar18 = MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::getDifficultyMultipliedValue, - this)((int)*(short*)((int)&this->scenarioEvents[_eventIndex].data - + _subIndex * 4 + 0xc)); + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)*(short*)((int)&this->scenarioEvents[_eventIndex].data + + _subIndex * 4 + 0xc)); cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data + _conditionOffset + 0xe); if (cVar17 != '\0') @@ -741,8 +744,8 @@ namespace Map { goto LAB_004c3fc7; case 7: iVar18 = MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::getDifficultyMultipliedValue, - this)((int)this->scenarioEvents[_eventIndex] + Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[7] .value); cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data @@ -805,8 +808,8 @@ namespace Map { .data.scenario.conditions + 0x19; do { - if (((*(const int*)&pSVar15[-0x1e] == 1) - && (*(const int*)pSVar15 == 0)) + if (((*(int const*)&pSVar15[-0x1e] == 1) + && (*(int const*)pSVar15 == 0)) && (pSVar15[-0x1d].value == 0)) goto switchD_004c3756_caseD_18; iVar18 = iVar18 + 1; @@ -823,8 +826,7 @@ namespace Map { break; case 9: BVar11 = MACRO_CALL_MEMBER( - Game::GameStateStructures_Func::checkKeepEnclosed, - DAT_GameState::ptr)( + Game::GameStateStructures_Func::checkKeepEnclosed, DAT_GameState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); if (!BVar11) goto LAB_004c37cd; @@ -877,8 +879,7 @@ namespace Map { && ((UVar6 != Map::Units::UT_E_ENGINEER || (pUVar12[0x17d] != 0)))) && ((UVar6 != Map::Units::UT_S_TOWER - && (UVar6 - != Map::Units::UT_S_BATTERINGRAM)))) + && (UVar6 != Map::Units::UT_S_BATTERINGRAM)))) && (UVar6 != Map::Units::UT_S_SHIELD)))) && ((((UVar6 != Map::Units::UT_S_MANGONEL && (UVar6 != Map::Units::UT_S_BALLISTA)) @@ -910,7 +911,8 @@ namespace Map { + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[5] + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[6] + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[7] - + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[8]) { + + DAT_GameState::instance.mapAndTime + .hitsDealtToPlayerArray[8]) { DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[0] = 0; DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[1] = 0; DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[2] = 0; @@ -1054,8 +1056,7 @@ namespace Map { goto LAB_004c3deb; case 0x15: iVar18 = MACRO_CALL_MEMBER( - Game::GameStateStructures_Func::computeAleCoverage, - DAT_GameState::ptr)( + Game::GameStateStructures_Func::computeAleCoverage, DAT_GameState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); iVar22 = (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[0x15] @@ -1151,12 +1152,10 @@ namespace Map { _pConditionIsMet = _pConditionIsMet + 0x39; } while (iVar18 < this->eventsCount); } - if (((DAT_GameCore::instance.gameMode_2 - == Game::GM_CAMPAIGN_MISSION) + if (((DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) || (DAT_GameCore::instance.gameMode_2 == Game::GM_ECONOMIC_CAMPAIGN_SH1)) - || (DAT_GameCore::instance.gameMode_2 - == Game::GM_BUILDERUnk)) { + || (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk)) { DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] @@ -1180,11 +1179,9 @@ namespace Map { MACRO_CALL_MEMBER( Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, DAT_UnitsState::ptr)(); - MACRO_CALL_MEMBER( - Map::Units::UnitsState_Func::queueEscapeCommand, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::queueEscapeCommand, DAT_UnitsState::ptr)(); - MACRO_CALL_MEMBER( - Input::MouseState_Func::resetMouseCursorState, + MACRO_CALL_MEMBER(Input::MouseState_Func::resetMouseCursorState, DAT_MouseState::ptr)(); } if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x13) @@ -1207,25 +1204,21 @@ namespace Map { == '\0')) { this->field133_0x145d8 = 1; MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, - this)(); + Map::MapPropertiesState_Func::sortEventsByDate, this)(); } else { this->field133_0x145d8 = 3; MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, - this)(); + Map::MapPropertiesState_Func::sortEventsByDate, this)(); } } else { this->field133_0x145d8 = 2; MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, - this)(); + Map::MapPropertiesState_Func::sortEventsByDate, this)(); } } else { this->field133_0x145d8 = 1; MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, - this)(); + Map::MapPropertiesState_Func::sortEventsByDate, this)(); } break; } @@ -1237,17 +1230,14 @@ namespace Map { .currentPlayerSlotID] .playerDeathRelated == 0) - && (( - (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION - || (DAT_GameCore::instance.gameMode_2 - == Game::GM_ECONOMIC_CAMPAIGN_SH1)) - || (DAT_GameCore::instance.gameMode_2 - == Game::GM_BUILDERUnk)))) { + && (((DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION + || (DAT_GameCore::instance.gameMode_2 + == Game::GM_ECONOMIC_CAMPAIGN_SH1)) + || (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk)))) { DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .playerDeathRelated = 2; - MACRO_CALL_MEMBER( - Map::Units::UnitsState_Func::setAIControlStatusTo100000, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::setAIControlStatusTo100000, DAT_UnitsState::ptr)(); DAT_GameState::instance.mapAndTime.unknownCountdown01 = 0xf0; if ((DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) @@ -1266,17 +1256,13 @@ namespace Map { MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)(UI::Enums::MVT_BUILD_MENU, 0); } - DAT_TileMapState::instance.currentMapperCommand - = Commands::M_MAPPER_NULL; + DAT_TileMapState::instance.currentMapperCommand = Commands::M_MAPPER_NULL; if (0 < DAT_UnitsState::instance.totalUnitsInSelection) { - MACRO_CALL_MEMBER( - Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, DAT_UnitsState::ptr)(); - MACRO_CALL_MEMBER( - Map::Units::UnitsState_Func::queueEscapeCommand, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::queueEscapeCommand, DAT_UnitsState::ptr)(); - MACRO_CALL_MEMBER( - Input::MouseState_Func::resetMouseCursorState, + MACRO_CALL_MEMBER(Input::MouseState_Func::resetMouseCursorState, DAT_MouseState::ptr)(); MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::sortEventsByDate, this)(); @@ -1286,117 +1272,129 @@ namespace Map { default: goto switchD_004c382e_caseD_2; case 3: - MACRO_CALL_MEMBER(Map::Units::TribesState_Func::flagTribesOfType, - DAT_TribesState::ptr)(0xe); MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + Map::Units::TribesState_Func::flagTribesOfType, DAT_TribesState::ptr)(0xe); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 4: iVar18 = this->scenarioEvents[_eventIndex].data.scenario.actionData; if (!iVar18) { iVar18 = 1; } - MACRO_CALL_MEMBER( - Map::Units::TribesState_Func::consumeFlaggedTribesOfType, + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::consumeFlaggedTribesOfType, DAT_TribesState::ptr)(0xe, iVar18); - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 5: - MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, - DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, (int)((int)(SEC_RNG::instance.currentNumber2 % 9)), DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.xEntry + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry * 8, DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.yEntry + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry * 8, (int)((int)(( uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.tileEntry])), + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry])), Map::Units::UT_JUGGLER); - MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, - DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, (SEC_RNG::instance.currentNumber2 >> 3) % 9, DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.xEntry + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry * 8, DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.yEntry + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry * 8, (UnitType)((int)(( uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.tileEntry])), + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry])), Map::Units::UT_JUGGLER); - MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, - DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, (SEC_RNG::instance.currentNumber2 >> 6) % 9, DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.xEntry + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry * 8, DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.yEntry + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry * 8, (UnitType)((int)(( uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.tileEntry])), + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry])), Map::Units::UT_JUGGLER); - MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, - DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, (SEC_RNG::instance.currentNumber2 >> 9) % 9, DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.xEntry + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry * 8, DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.yEntry + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry * 8, (UnitType)((int)(( uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.tileEntry])), + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry])), Map::Units::UT_FIREEATER); - MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, - DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::spawnUnit, DAT_UnitsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, (SEC_RNG::instance.currentNumber2 >> 0xc) % 9, DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.xEntry + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .xEntry * 8, DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.yEntry + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .yEntry * 8, (UnitType)((int)(( uint)DAT_TileMapState::instance.HeightLayer[DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .campground.tileEntry])), + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] + .tileEntry])), Map::Units::UT_FIREEATER); pcVar25 = "Random_Events1.wav"; pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent1VideoName; @@ -1404,11 +1402,10 @@ namespace Map { "a travelling fair has come to town my lord" added by script: "A ‘Travelling Fair’ has come to town, my Lord." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 1); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + pcVar10 + = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 1); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -1435,37 +1432,31 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; } LAB_004c4621: - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 6: DAT_GameCore::instance.isTimeHalted = TRUE; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 7: DAT_GameCore::instance.isTimeHalted = FALSE; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 8: - MACRO_CALL_MEMBER( - Game::GameStateStructures_Func::switchPlayerOwnership, + MACRO_CALL_MEMBER(Game::GameStateStructures_Func::switchPlayerOwnership, DAT_GameState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID); - MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func:: - setupBarracksCampgroundPositions, + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::setupBarracksCampgroundPositions, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); - MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func:: - setupMercenaryPostCampgroundPositions, + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::setupMercenaryPostCampgroundPositions, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); - MACRO_CALL_MEMBER( - Map::Units::UnitsState_Func::triggerStoneTowerDeathForPlayer, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::triggerStoneTowerDeathForPlayer, DAT_UnitsState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID); - MACRO_CALL_MEMBER( - Map::Buildings::BuildingsState_Func::countPlayerResources, + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::countPlayerResources, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType @@ -1473,12 +1464,10 @@ namespace Map { DAT_GameCore::instance.secondaryActiveMenuTabToSwitchTo.tabType = UI::Enums::BASMTT_HUNTERSHUT; DAT_GameCore::instance.tabTypeSiegeSubset = UI::Enums::BMTT_CASTLE; - if (((DAT_GameCore::instance.currentMenuViewType - == UI::Enums::MVT_BUILD_MENU) + if (((DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_BUILD_MENU) && ((DAT_GameCore::instance.activeMenuTab.tabType != UI::Enums::BASMTT_STOCKS - || (MACRO_CALL_MEMBER( - Game::GameCore_Func::switchToMenuView, + || (MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)(UI::Enums::MVT_BUILD_MENU, 0), DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_BUILD_MENU)))) @@ -1488,8 +1477,8 @@ namespace Map { == UI::Enums::BASMTT_SIEGETENT_SHIELD)))) { DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType = UI::Enums::BASMTT_SIEGETENT_BATTERINGRAM; - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, - DAT_GameCore::ptr)(UI::Enums::MVT_BUILD_MENU, 0); + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_BUILD_MENU, 0); } iVar22 = DAT_GameSynchronyState::instance.currentPlayerSlotID; iVar18 @@ -1507,18 +1496,16 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .lordID = 0; DAT_GameState::instance.playerDataArray[iVar22].lordUID = 0; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 9: DAT_GameCore::instance.xbowProducible_logic = 1; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0xb: DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .someCount48 = 0x18; + .eventPlagueCountdown = 0x18; iVar22 = DAT_GameState::instance.playerDataArray[iVar18].popularity; if (6000 < iVar22) { DAT_GameState::instance.playerDataArray[iVar18].popularity @@ -1533,11 +1520,10 @@ namespace Map { /* added by script: "Plague has descended on our castle your lordship." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 2); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + pcVar10 + = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 2); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -1563,8 +1549,7 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0xc: @@ -1586,8 +1571,7 @@ namespace Map { pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 3); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; @@ -1614,8 +1598,7 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0xd: @@ -1625,8 +1608,7 @@ namespace Map { DAT_GameSynchronyState::instance.currentPlayerSlotID, Map::Buildings::BT_HOPFARM); if (iVar18) { - MACRO_CALL_MEMBER( - Map::Buildings::BuildingsState_Func::harmHopFarmsOfPlayer, + MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::harmHopFarmsOfPlayer, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); pcVar25 = "Random_Events4.wav"; @@ -1638,8 +1620,7 @@ namespace Map { pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 4); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; @@ -1666,8 +1647,7 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0xe: @@ -1677,8 +1657,8 @@ namespace Map { DAT_GameSynchronyState::instance.currentPlayerSlotID, Map::Buildings::BT_APPLEFARM); if (iVar18) { - MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func:: - harmAppleFarmTreesOfPlayer, + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::harmAppleFarmTreesOfPlayer, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); pcVar27 = "Random_Events5.wav"; @@ -1690,13 +1670,12 @@ namespace Map { pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 5); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)("", - (char*)((int)(DAT_MissionAestheticsDefinedData::instance.RandomEvent5VideoName)), + (char*)((int)(DAT_MissionAestheticsDefinedData::instance + .RandomEvent5VideoName)), ""); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; @@ -1723,12 +1702,11 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0xf: - MACRO_CALL_MEMBER(Map::LandscapeState_Func::killEveryFifthTree, + MACRO_CALL_MEMBER(Map::LandscapeState_Func::ageFourFifthsOfGrowingTrees, DAT_LandscapeState::ptr)(); pcVar25 = "Random_Events6.wav"; pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent6VideoName; @@ -1736,11 +1714,10 @@ namespace Map { added by script: "Sire, woodcutters report that the recent drought has killed off many trees." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 6); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + pcVar10 + = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 6); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -1766,13 +1743,12 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0x10: - iVar18 = MACRO_CALL_MEMBER(Map::Units::TribesState_Func:: - hasAvailableSpawnSlotForWildlifeOrMercs, + iVar18 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::hasAvailableSpawnSlotForWildlifeOrMercs, DAT_TribesState::ptr)(); if ((iVar18) && ((iVar18 = MACRO_CALL_MEMBER( @@ -1788,8 +1764,8 @@ namespace Map { Map::Buildings::BT_WHEATFARM), iVar18 != 0)))) { DAT_GameState::instance.mapAndTime.eventCountdownRabbitInfestation = 1200; - MACRO_CALL_MEMBER(Map::Units::TribesState_Func:: - spawnWildlifeOrMercAtAvailableSlot, + MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::spawnRabbitAtFirstFreeSpawnPoint, DAT_TribesState::ptr)(); MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)(DAT_TribesState::instance.unknownX_01, @@ -1803,8 +1779,7 @@ namespace Map { pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 7); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; @@ -1831,8 +1806,7 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0x11: @@ -1847,7 +1821,7 @@ namespace Map { BVar11)) { DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .someCount49 = 0xc; + .eventLionsCountdown = 0xc; iVar22 = DAT_GameState::instance.playerDataArray[iVar18].popularity; if (6000 < iVar22) { DAT_GameState::instance.playerDataArray[iVar18].popularity @@ -1856,20 +1830,19 @@ namespace Map { iVar18 = 0; if (0 < this->scenarioEvents[_eventIndex].data.scenario.actionData) { do { - MACRO_CALL_MEMBER(Map::Units::TribesState_Func:: - findRecentOrSignpostSpawnLocation, - DAT_TribesState::ptr)(&uStack_78, &uStack_7c); - dVar14 = MACRO_CALL_MEMBER( - Map::Units::TribesState_Func::createAnimal, - DAT_TribesState::ptr)(Commands::M_MAPPER_LION, - uStack_78, uStack_7c, - (int)((int)((uint) - * (byte*)(DAT_ViewportRenderState::instance - .translationMatrix[uStack_7c] - .addXgetTile - + 0x1d32c38 + uStack_78)))); MACRO_CALL_MEMBER( - UI::MinimapViewState_Func::setSpawnMoment, + Map::Units::TribesState_Func::findRecentOrSignpostSpawnLocation, + DAT_TribesState::ptr)(&uStack_78, &uStack_7c); + dVar14 + = MACRO_CALL_MEMBER(Map::Units::TribesState_Func::createAnimal, + DAT_TribesState::ptr)(Commands::M_MAPPER_LION, uStack_78, + uStack_7c, + (int)((int)((uint) + * (byte*)(DAT_ViewportRenderState::instance + .translationMatrix[uStack_7c] + .addXgetTile + + 0x1d32c38 + uStack_78)))); + MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)(uStack_78, (int)((int)(uStack_7c))); iVar18 = iVar18 + 1; DAT_TribesState::instance.tribes[dVar14].unknownBool02 = 0; @@ -1886,8 +1859,7 @@ namespace Map { pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 8); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; @@ -1914,18 +1886,16 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0x12: - BVar11 - = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::hasAnySignpost, - DAT_GameState::ptr)(); + BVar11 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::hasAnySignpost, DAT_GameState::ptr)(); if (BVar11) { DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .someCount50 = 0x10; + .eventBanditsCountdown = 0x10; DAT_TroopValueState::instance.attackInfo.inv_count = DAT_TroopValueState::instance.attackInfo.inv_count + 1; if (0x31 < DAT_TroopValueState::instance.attackInfo.inv_count) { @@ -1937,18 +1907,18 @@ namespace Map { DAT_TroopValueState::instance.attackInfo.inv_count, 0); DAT_TroopValueState::instance.attackInfo.attackWavePlayerIDArray [DAT_TroopValueState::instance.attackInfo.inv_count] = 8; - iVar18 = MACRO_CALL_MEMBER(Game::GameStateStructures_Func:: - pickRandomAccessibleSignpostEntry, + iVar18 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::pickRandomAccessibleSignpostEntry, DAT_GameState::ptr)(); dVar14 = MACRO_CALL_MEMBER( Map::Units::TribesState_Func::createTribeWithSpawnedUnit, - DAT_TribesState::ptr)(0, 9, + DAT_TribesState::ptr)(0, OpenSHC::AI::Tribes::AITT_MACEMEN, DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y, 8, Map::Units::UT_E_MACE, this->scenarioEvents[_eventIndex].data.scenario.actionData + 1); - MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, - DAT_MinimapViewState::ptr)( + MACRO_CALL_MEMBER( + UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)( DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); iVar18 = 0; @@ -1973,8 +1943,7 @@ namespace Map { pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 9); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; @@ -2001,8 +1970,7 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0x13: @@ -2012,8 +1980,7 @@ namespace Map { DAT_GameSynchronyState::instance.currentPlayerSlotID, Map::Buildings::BT_DAIRYFARM); if (iVar18) { - MACRO_CALL_MEMBER( - Map::Units::UnitsState_Func::setRandomNumberOnCows, + MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::setRandomNumberOnCows, DAT_UnitsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); MACRO_CALL_MEMBER( @@ -2029,13 +1996,12 @@ namespace Map { pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 10); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)("", - (char*)((int)(DAT_MissionAestheticsDefinedData::instance.RandomEvent10VideoName)), + (char*)((int)(DAT_MissionAestheticsDefinedData::instance + .RandomEvent10VideoName)), ""); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; @@ -2062,22 +2028,20 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0x14: - BVar11 - = MACRO_CALL_MEMBER(Game::GameStateStructures_Func::hasAnySignpost, - DAT_GameState::ptr)(); + BVar11 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::hasAnySignpost, DAT_GameState::ptr)(); if (BVar11) { - iVar18 = MACRO_CALL_MEMBER(Game::GameStateStructures_Func:: - pickRandomAccessibleSignpostEntry, + iVar18 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::pickRandomAccessibleSignpostEntry, DAT_GameState::ptr)(); iVar22 = 0; dVar14 = MACRO_CALL_MEMBER( Map::Units::TribesState_Func::createTribeWithSpawnedUnit, - DAT_TribesState::ptr)(0, 3, + DAT_TribesState::ptr)(0, OpenSHC::AI::Tribes::AITT_ARCHERS, DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y, (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), @@ -2085,13 +2049,13 @@ namespace Map { this->scenarioEvents[_eventIndex].data.scenario.actionData); tribeID = MACRO_CALL_MEMBER( Map::Units::TribesState_Func::createTribeWithSpawnedUnit, - DAT_TribesState::ptr)(0, 0xc, + DAT_TribesState::ptr)(0, OpenSHC::AI::Tribes::AITT_HOPS_FARMER_UNK, DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y, (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), Map::Units::UT_E_MONK, 1); - MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, - DAT_MinimapViewState::ptr)( + MACRO_CALL_MEMBER( + UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)( DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); DAT_TribesState::instance.tribes[dVar14].pendingScatterMove = 0; @@ -2125,7 +2089,8 @@ namespace Map { iVar18 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .keep.id; + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id; if (0 < iVar18) { BVar9 = DAT_BuildingsState::instance.buildings[iVar18].buildingType; uVar19 = 0; @@ -2163,12 +2128,12 @@ namespace Map { } MACRO_CALL_MEMBER( Map::Units::TribesState_Func::giveTribeMoveInstruction, - DAT_TribesState::ptr)(dVar14, uVar19, y1, 0, 0, - Map::Units::Instructions::UMSE_0); + DAT_TribesState::ptr)( + dVar14, uVar19, y1, 0, 0, Map::Units::Instructions::UMSE_0); MACRO_CALL_MEMBER( Map::Units::TribesState_Func::giveTribeMoveInstruction, - DAT_TribesState::ptr)(tribeID, uVar19, y1, 0, 0, - Map::Units::Instructions::UMSE_0); + DAT_TribesState::ptr)( + tribeID, uVar19, y1, 0, 0, Map::Units::Instructions::UMSE_0); } pcVar25 = "Random_Events11.wav"; pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent11VideoName; @@ -2179,8 +2144,7 @@ namespace Map { pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xb); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; @@ -2207,15 +2171,14 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0x15: DAT_GameState::instance.mapAndTime.unitLadyRelated = 1; DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .someCount52 = 0xc; + .eventMarriageCountdown = 0xc; if (10000 < DAT_GameState::instance.playerDataArray[iVar18].popularity) { DAT_GameState::instance.playerDataArray[iVar18].popularity = 10000; } @@ -2224,22 +2187,20 @@ namespace Map { /* added by script: "The people rejoice at your forthcoming marriage, Sire." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xc); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + pcVar10 + = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xc); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, DAT_SFXState::ptr)(Audio::SFX::SEID_CHAPEL_BELL); - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x16: DAT_GameState::instance.mapAndTime.unitJesterRelated = 1; DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .someCount53 = 0x30; + .eventJesterCountdown = 0x30; if (10000 < DAT_GameState::instance.playerDataArray[iVar18].popularity) { DAT_GameState::instance.playerDataArray[iVar18].popularity = 10000; } @@ -2249,14 +2210,12 @@ namespace Map { added by script: "A Jester has arrived at the castle Liege. I have taken the liberty of offering him employment." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xd); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + pcVar10 + = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xd); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x17: if (((DAT_GameCore::instance.gameMode_2 != Game::GM_CAMPAIGN_MISSION) @@ -2264,7 +2223,7 @@ namespace Map { && (this->scenarioEvents[_eventIndex].header.month == 0xb)) { dVar14 = MACRO_CALL_MEMBER( Map::Units::TribesState_Func::createTribeWithSpawnedUnit, - DAT_TribesState::ptr)(0, 3, 0x85, 0x116, + DAT_TribesState::ptr)(0, OpenSHC::AI::Tribes::AITT_ARCHERS, 0x85, 0x116, (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), Map::Units::UT_E_ARCHER, 0x14); sVar7 = DAT_TribesState::instance.tribes[dVar14].size; @@ -2289,13 +2248,11 @@ namespace Map { goto switchD_004c382e_caseD_2; case 0x18: DAT_GameCore::instance.section1076 = 0; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x19: DAT_GameCore::instance.section1076 = 1; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x1a: if (DAT_GameState::instance @@ -2355,8 +2312,8 @@ namespace Map { if (0 < this->eventsCount) { pSVar15 = this->scenarioEvents[0].data.scenario.conditions + 0x19; do { - if ((*(const int*)&pSVar15[-0x1e] == 1) - && (*(const int*)pSVar15 != 0)) { + if ((*(int const*)&pSVar15[-0x1e] == 1) + && (*(int const*)pSVar15 != 0)) { pSVar15->value = 0; pSVar15->subType = 0; pSVar15->enabled = 0; @@ -2370,16 +2327,15 @@ namespace Map { } while (iVar18 < this->eventsCount); } switchD_004c382e_caseD_2: - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x1d: if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .totalFood != 0) { - MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func:: - applyFoodLossPercentageToPlayer, + MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::applyFoodLossPercentageToPlayer, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID, this->scenarioEvents[_eventIndex].data.scenario.actionData); @@ -2396,8 +2352,7 @@ namespace Map { pcVar25 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar25, pcVar26, pcVar10); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; @@ -2424,14 +2379,13 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; case 0x1e: DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .someCount51 = 8; + .eventFireCountdown = 8; MACRO_CALL_MEMBER( Map::Buildings::BuildingsState_Func::spreadFireRandomlyToBuildings, DAT_BuildingsState::ptr)( @@ -2461,11 +2415,10 @@ namespace Map { added by script: "There is fire in the castle and we have not built any wells my Liege!" */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + pcVar10 + = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -2491,8 +2444,7 @@ namespace Map { _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; *_pConditionIsMet = *_pConditionIsMet + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; } LAB_004c5f28: @@ -2547,22 +2499,20 @@ namespace Map { } local_70[iVar22] = 1; if (!iVar22) { - pcVar26 = (&DAT_MissionAestheticsDefinedData::instance - .field59_0xec)[numInGroup]; + pcVar26 + = (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]; pcVar10 = "good_arab_nervous.bik"; } else { if (iVar22 != 1) goto LAB_004c609a; - pcVar26 = (&DAT_MissionAestheticsDefinedData::instance - .field59_0xec)[numInGroup]; + pcVar26 + = (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]; pcVar10 = "good_soldier_nervous.bik"; } - pcVar25 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)( - DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup); - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + pcVar25 + = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)(pcVar25, pcVar10, pcVar26); } LAB_004c609a: @@ -2607,8 +2557,8 @@ namespace Map { MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, DAT_MenuModalComposition3::ptr)(UI::Enums::MMT_NONE, FALSE); DAT_MenuTextInputState::instance.DAT_SomeTextArrayIndex = 9; - MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, - DAT_MenuTextInputState::ptr)(); + MACRO_CALL_MEMBER( + UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, DAT_MenuTextInputState::ptr)(); if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] @@ -2622,25 +2572,23 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .playerDeathRelated == 2) { - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, - DAT_GameCore::ptr)(UI::Enums::MVT_GAME_LOSTUnk, 0); + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); DAT_GameCore::instance.section1066 = 0; } - MACRO_CALL(UI::DisplayElements_Func:: - CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - MACRO_CALL(UI::DisplayElements_Func:: - CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); } if (DAT_GameCore::instance.gameMode_2 != Game::GM_ECONOMIC_CAMPAIGN_SH1) { if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { - if (DAT_GameCore::instance.field24_0x6c) { + if (DAT_GameCore::instance.field_0x6c) { DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; MACRO_CALL(UI::MenuItems::General_Func:: MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(0x16); - MACRO_CALL(UI::DisplayElements_Func:: - CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + MACRO_CALL( + UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); } if (DAT_GameState::instance @@ -2648,8 +2596,7 @@ namespace Map { .playerDeathRelated == 1) { if ((int)this->SEC_U3_MapType2_1 < 2) { - MACRO_CALL_MEMBER( - Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); } else { DAT_GameCore::instance.section1095 = 1; @@ -2663,13 +2610,12 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .playerDeathRelated == 2) { - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, - DAT_GameCore::ptr)(UI::Enums::MVT_GAME_LOSTUnk, 0); + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); } DAT_GameCore::instance.section1066 = 2; } - MACRO_CALL(UI::DisplayElements_Func:: - CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); } if (DAT_GameState::instance @@ -2685,11 +2631,9 @@ namespace Map { MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( UI::Enums::MVT_GAME_LOSTUnk, 0); } - MACRO_CALL( - UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - MACRO_CALL( - UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); } } diff --git a/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp b/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp index 82cec09f34..c5efcc49c4 100644 --- a/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp @@ -5,12 +5,12 @@ #include "OpenSHC/Map/Units/TroopValueState.func.hpp" #include "OpenSHC/Rendering/Bink/AIMessageQueue.func.hpp" #include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Units/UnitTypeInt.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_TribesState.hpp" #include "OpenSHC/Globals/DAT_TroopValueState.hpp" #include "OpenSHC/Globals/DAT_VideoBikQueue.hpp" -#include "OpenSHC/Map/Units/UnitTypeInt.hpp" namespace OpenSHC { namespace Map { @@ -43,8 +43,8 @@ namespace Map { if (0x31 < DAT_TroopValueState::instance.attackInfo.inv_count) { DAT_TroopValueState::instance.attackInfo.inv_count = 1; } - MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackWaveSlot, - DAT_TroopValueState::ptr)(DAT_TroopValueState::instance.attackInfo.inv_count, 0); + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackWaveSlot, DAT_TroopValueState::ptr)( + DAT_TroopValueState::instance.attackInfo.inv_count, 0); DAT_TroopValueState::instance.attackInfo .attackWavePlayerIDArray[DAT_TroopValueState::instance.attackInfo.inv_count] = (char)this->invasionEventContent.crusaderArabian + 2; @@ -201,11 +201,10 @@ namespace Map { if (_sliderValue < _unitCount) { _unitCount = _sliderValue; } - iVar3 = (&DAT_TroopValueState::instance.attackInfo - .unknownSignpostRelatedArray)[DAT_TroopValueState::instance.attackInfo.inv_count]; - MACRO_CALL_MEMBER( - Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, DAT_TribesState::ptr)(local_c, - _unitTypeOther, DAT_GameState::instance.mapAndTime.signpostsMapEdge[iVar3][local_10].x, + iVar3 = DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray[DAT_TroopValueState::instance.attackInfo.inv_count]; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, DAT_TribesState::ptr)( + local_c, _unitTypeOther, DAT_GameState::instance.mapAndTime.signpostsMapEdge[iVar3][local_10].x, DAT_GameState::instance.mapAndTime.signpostsMapEdge[iVar3][local_10].y, this->invasionEventContent.crusaderArabian + 2, (UnitType)((int)(_unitType)), ((UnitType)0), _unitCount, 0); @@ -230,8 +229,8 @@ namespace Map { eventWavFile = "arabian_attack.wav"; eventVideoBik = "good_soldier_nervous.bik"; } - MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)("", eventVideoBik, eventWavFile); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( + "", eventVideoBik, eventWavFile); this->eventsCount = 0; } } while (true); diff --git a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp index e4cc5b22b2..fdfc4b3fd1 100644 --- a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp +++ b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp @@ -49,7 +49,7 @@ namespace UI { _savesPath.c_str()); this->fileListEntryCount = DAT_ResourceManager::instance.mapFileCounter; for (int _mapIndex = 0; _mapIndex < DAT_ResourceManager::instance.mapFileCounter; _mapIndex++) { - (&this->DAT_MapSelectionPreloadMapIndexMapping)[_mapIndex] = _mapIndex; + this->DAT_ArrayOfMapIndices[_mapIndex] = _mapIndex; } } else { std::string _savesPath @@ -77,15 +77,15 @@ namespace UI { } DAT_MouseState::instance.waitCursorToggle = 0; this->fileListSortOrder = 0; - this->DAT_MenuLoadGameRelativeSelectionOffset = 0; + this->menuLoadGameRelativeSelectionOffset = 0; if (!this->fileListEntryCount) { - this->DAT_MenuLoadGameRelativeSelectionIndex = -1; + this->menuLoadGameRelativeSelectionIndex = -1; } else { - this->DAT_MenuLoadGameRelativeSelectionIndex = 0; + this->menuLoadGameRelativeSelectionIndex = 0; } this->lastListClickTime = 0; this->lastClickedListIndex = 0xffffffff; - this->field49_0xac = 0; + this->DAT_ArrayOfMapU3EndInt2 = 0; this->previewedListIndex = 0xffffffff; this->fileListVisibleRowCount = 0x10; if (action == 9) { @@ -107,11 +107,11 @@ namespace UI { iVar1 = this->savedListSelection2; iVar2 = this->savedListSortOrder2; } - if ((this->DAT_MenuLoadGameRelativeSelectionIndex != -1) - && (this->fileListSortOrder = iVar2, this->DAT_MenuLoadGameRelativeSelectionIndex = iVar1, - this->DAT_MenuLoadGameRelativeSelectionOffset = iVar6, iVar6 + iVar1 >= this->fileListEntryCount)) { - this->DAT_MenuLoadGameRelativeSelectionIndex = 0; - this->DAT_MenuLoadGameRelativeSelectionOffset = 0; + if ((this->menuLoadGameRelativeSelectionIndex != -1) + && (this->fileListSortOrder = iVar2, this->menuLoadGameRelativeSelectionIndex = iVar1, + this->menuLoadGameRelativeSelectionOffset = iVar6, iVar6 + iVar1 >= this->fileListEntryCount)) { + this->menuLoadGameRelativeSelectionIndex = 0; + this->menuLoadGameRelativeSelectionOffset = 0; } MACRO_CALL(UI::MenuItems::SaveLoadMap_Func::MenuItemActionHandler_SaveLoadMap_TableHeader)( -1 - this->fileListSortOrder); From cdefcdb1f80e28dd10a649e7d66856ce965ab8c9 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 14:38:02 +0100 Subject: [PATCH 03/60] reimplement: status of 16 ported functions SHC_3BB0A8C1_0x0044B680 48.7% ComputePlayerRanking SHC_3BB0A8C1_0x00490060 94.4% restoreSkirmishLobbySetup SHC_3BB0A8C1_0x004968A0 55.6% loadOrSaveGame SHC_3BB0A8C1_0x004BC110 28.9% adjustEventMonthAndYearForSection1047 SHC_3BB0A8C1_0x004BD800 32.9% Tutorial_IsActionAllowed SHC_3BB0A8C1_0x004BDE40 62.4% computeMissionCompletionScore SHC_3BB0A8C1_0x004C13F0 48.1% spawnInvasionEventAttackWave SHC_3BB0A8C1_0x004C31A0 26.9% processSingleplayerEvents SHC_3BB0A8C1_0x004C62C0 43.3% loadMap SHC_3BB0A8C1_0x004C6820 3.7% loadMapSiegeHeaderForMissionIndex SHC_3BB0A8C1_0x004C6880 26.3% loadMissionMapAndSetLord SHC_3BB0A8C1_0x004C68D0 44.8% SetupSkirmishMode SHC_3BB0A8C1_0x004C6B20 92.4% LoadSkirmishCampaignData SHC_3BB0A8C1_0x004D52A0 17.0% StoreGameIntoSKMasters SHC_3BB0A8C1_0x004D5370 16.4% SkirmishLeaderboard_DeleteEntry SHC_3BB0A8C1_0x004D9400 42.6% Skirmish_PrepareLeaderboardView Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- status/addresses-SHC-3BB0A8C1.txt | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 81b4e6a71e..5ab7583bb5 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16863,7 +16863,7 @@ SHC_3BB0A8C1_0x0044B673 | 0.0% | Pending SHC_3BB0A8C1_0x0044B674 | 0.0% | Pending -SHC_3BB0A8C1_0x0044B680 | 0.0% | Pending +SHC_3BB0A8C1_0x0044B680 | 48.7% | Ported from gynt, asm differs SHC_3BB0A8C1_0x0044B760 | 100.0% | Reimplemented @@ -23369,7 +23369,7 @@ SHC_3BB0A8C1_0x0048FCB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048FFD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00490060 | 0.0% | Pending +SHC_3BB0A8C1_0x00490060 | 94.4% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00490080 | 0.0% | Pending @@ -24233,7 +24233,7 @@ SHC_3BB0A8C1_0x00495A30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00496400 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004968A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004968A0 | 55.6% | Ported from gynt, asm differs SHC_3BB0A8C1_0x00496B80 | 100.0% | Reimplemented @@ -29881,7 +29881,7 @@ SHC_3BB0A8C1_0x004BC100 | 0.0% | Pending SHC_3BB0A8C1_0x004BC104 | 0.0% | Pending -SHC_3BB0A8C1_0x004BC110 | 0.0% | Pending +SHC_3BB0A8C1_0x004BC110 | 28.9% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004BC1C0 | 100.0% | Pending @@ -30243,7 +30243,7 @@ SHC_3BB0A8C1_0x004BD7F0 | 0.0% | Pending SHC_3BB0A8C1_0x004BD7F4 | 0.0% | Pending -SHC_3BB0A8C1_0x004BD800 | 0.0% | Pending +SHC_3BB0A8C1_0x004BD800 | 32.9% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004BD970 | 0.0% | Pending @@ -30257,7 +30257,7 @@ SHC_3BB0A8C1_0x004BD980 | 0.0% | Pending SHC_3BB0A8C1_0x004BDA80 | 0.0% | Pending -SHC_3BB0A8C1_0x004BDE40 | 0.0% | Pending +SHC_3BB0A8C1_0x004BDE40 | 62.4% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004BDE80 | 0.0% | Pending @@ -33195,7 +33195,7 @@ SHC_3BB0A8C1_0x004C1370 | 0.0% | Pending SHC_3BB0A8C1_0x004C1390 | 0.0% | Pending -SHC_3BB0A8C1_0x004C13F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004C13F0 | 48.1% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004C1708 | 0.0% | Pending @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004C31A0 | 26.9% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending @@ -34141,15 +34141,15 @@ SHC_3BB0A8C1_0x004C6298 | 0.0% | Pending SHC_3BB0A8C1_0x004C62A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C62C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004C62C0 | 43.3% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x004C6820 | 0.0% | Pending +SHC_3BB0A8C1_0x004C6820 | 3.7% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x004C6880 | 0.0% | Pending +SHC_3BB0A8C1_0x004C6880 | 26.3% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x004C68D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004C68D0 | 44.8% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x004C6B20 | 0.0% | Pending +SHC_3BB0A8C1_0x004C6B20 | 92.4% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004C6B90 | 0.0% | Pending @@ -35565,9 +35565,9 @@ SHC_3BB0A8C1_0x004D5010 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D5180 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004D52A0 | 0.0% | Pending +SHC_3BB0A8C1_0x004D52A0 | 17.0% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x004D5370 | 0.0% | Pending +SHC_3BB0A8C1_0x004D5370 | 16.4% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004D53A0 | 0.0% | Pending @@ -36023,7 +36023,7 @@ SHC_3BB0A8C1_0x004D9270 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D9290 | 100.0% | Reimplemented (counted: only memset/_stricmp call labels and the instance[i - 1] address label differ) -SHC_3BB0A8C1_0x004D9400 | 0.0% | Pending +SHC_3BB0A8C1_0x004D9400 | 42.6% | Ported from gynt, asm differs SHC_3BB0A8C1_0x004D9520 | 0.0% | Pending From d2d7831b964c3a2237212f106ece1b4502dc6003 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 20:51:53 +0100 Subject: [PATCH 04/60] Mission/skirmish flow: 3 functions to 100%, 3 more improved - loadMissionMapAndSetLord 26.3 -> 100: the parameter itself is decremented and passed back as missionNumber + 1; four else-if arms load the map. - LoadSkirmishCampaignData 92.4 -> 100: memset for the player positions, indexed AI loop. - loadMapSiegeHeaderForMissionIndex 3.7 -> 100 (call targets only): the original returns after the first matching bound; ours called the loader up to four times. The header types the index as char*. - restoreSkirmishLobbySetup 94.4 -> 99.3: strcpy for the map name, the selection sum read back from the stored globals. Left: [eax+esi] operand order. - StoreGameIntoSKMasters 17.0 -> 87.4: control flow rebuilt from the original. Left: the original re-reads the count after each struct copy, which happens when count and entries are one struct (version, count, entries are adjacent). - adjustEventMonthAndYearForSection1047 28.9 -> 74.7: every arm re-stores yearCopy, mission 18 returns without the month check, the test is month >= 12. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../restoreSkirmishLobbySetup.cpp | 12 +-- .../Game/Skirmish/StoreGameIntoSKMasters.cpp | 77 ++++++------------- .../adjustEventMonthAndYearForSection1047.cpp | 22 +++--- .../loadMapSiegeHeaderForMissionIndex.cpp | 22 +++--- .../loadMissionMapAndSetLord.cpp | 31 ++++---- .../Synchrony/LoadSkirmishCampaignData.cpp | 23 ++---- status/addresses-SHC-3BB0A8C1.txt | 12 +-- 7 files changed, 75 insertions(+), 124 deletions(-) diff --git a/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp b/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp index 2e5b9a8334..d60116df65 100644 --- a/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp +++ b/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp @@ -15,16 +15,9 @@ namespace Game { // FUNCTION: STRONGHOLDCRUSADER 0x00490060 void SkirmishLobbySetupStructure::restoreSkirmishLobbySetup() { - char cVar1; - char* pcVar2; DAT_GameSynchronyState::instance.skirmishAutoSaveEveryMinutes = this->mapu4int2; - pcVar2 = this->mapName; this->mbr_0x4 = DAT_GameState::instance.mapAndTime.skirmishFogOfWar; - do { - cVar1 = *pcVar2; - pcVar2[0xc2ee7c] = cVar1; - pcVar2 = pcVar2 + 1; - } while (cVar1 != '\0'); + strcpy(DAT_GameSynchronyState::instance.mapName, this->mapName); DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[0] = this->roundTableOrderArray[0]; DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[0] = this->playerGroupArray[0]; DAT_GameSynchronyState::instance.currentAIArray[0] = this->currentAIArray[0]; @@ -87,8 +80,9 @@ namespace Game { DAT_GameSynchronyState::instance.skirmishDefaultPopularity = this->popularity; DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected = this->mapSelectionRelativeSelected; DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset = this->mapSelectionScrollOffset; - INT_00b960b0::instance = this->mapSelectionScrollOffset + this->mapSelectionRelativeSelected; DAT_GameSynchronyState::instance.lobbyMapSortOrder = this->mbr_0xfc; + INT_00b960b0::instance = DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset + + DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected; MACRO_CALL_MEMBER( Synchrony::GameSynchronyState_Func::reorderTeamsAndPositions, DAT_GameSynchronyState::ptr)(); } diff --git a/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp b/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp index d45eb6d60f..37c17b8fc5 100644 --- a/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp +++ b/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp @@ -16,66 +16,35 @@ namespace Game { // FUNCTION: STRONGHOLDCRUSADER 0x004D52A0 void Skirmish::StoreGameIntoSKMasters(int score) { - BOOLEnum BVar1; - int iVar2; - int iVar3; - int* piVar4; - SkMasterDataEntry* pSVar5; - int iVar6; - SkMasterDataEntry* _ptrSrc; - SkMasterDataEntry* _ptrDst; - int _count; - SkMasterDataEntry* _ptrDst2; - SkMasterDataEntry* _ptrSrc2; - BVar1 = MACRO_CALL(Game::Skirmish_Func::StoreCurrentGameIntoTemporarySKMasterEntry)(score); - if (!BVar1) {} - _count = -1; - if (DAT_SkMasters2Data_Count::instance < 1) { - _count = 0; + if (!MACRO_CALL(Game::Skirmish_Func::StoreCurrentGameIntoTemporarySKMasterEntry)(score)) { + return; } - if (DAT_SkMasters2Data_Count::instance < 250) { - _count = DAT_SkMasters2Data_Count::instance; + int count = DAT_SkMasters2Data_Count::instance; + int insertIndex = -1; + if (count <= 0) { + insertIndex = 0; } - iVar6 = _count; - if (_count) { - iVar2 = 0; - if (0 < DAT_SkMasters2Data_Count::instance) { - piVar4 = &DAT_SkMasters2DataArray::instance[0].skMasterScore; - do { - iVar6 = iVar2; - if (*piVar4 < DAT_SkMasterDataEntry::instance.skMasterScore) - break; - iVar2 = iVar2 + 1; - piVar4 = piVar4 + 764; - iVar6 = _count; - } while (iVar2 < DAT_SkMasters2Data_Count::instance); - } - if (iVar6 == -1) {} + if (count < 250) { + insertIndex = count; } - if (iVar6 < DAT_SkMasters2Data_Count::instance) { - pSVar5 = DAT_SkMasters2DataArray::instance + DAT_SkMasters2Data_Count::instance; - iVar2 = DAT_SkMasters2Data_Count::instance; - do { - if (iVar2 < 249) { - _ptrSrc = pSVar5 + -1; - _ptrDst = pSVar5; - for (iVar3 = 764; iVar3 != 0; iVar3 = iVar3 + -1) { - _ptrDst->score = _ptrSrc->score; - _ptrSrc = (SkMasterDataEntry*)_ptrSrc->mapName; - _ptrDst = (SkMasterDataEntry*)_ptrDst->mapName; - } + if (insertIndex != 0) { + for (int i = 0; i < count; i++) { + if (DAT_SkMasterDataEntry::instance.skMasterScore + > DAT_SkMasters2DataArray::instance[i].skMasterScore) { + insertIndex = i; + break; } - iVar2 = iVar2 + -1; - pSVar5 = pSVar5 + -1; - } while (iVar6 < iVar2); + } + if (insertIndex == -1) { + return; + } } - _ptrSrc2 = DAT_SkMasterDataEntry::ptr; - _ptrDst2 = DAT_SkMasters2DataArray::instance + iVar6; - for (iVar2 = 764; iVar2 != 0; iVar2 = iVar2 + -1) { - _ptrDst2->score = _ptrSrc2->score; - _ptrSrc2 = (SkMasterDataEntry*)_ptrSrc2->mapName; - _ptrDst2 = (SkMasterDataEntry*)_ptrDst2->mapName; + for (; count > insertIndex; count--) { + if (count <= 249) { + DAT_SkMasters2DataArray::instance[count] = DAT_SkMasters2DataArray::instance[count - 1]; + } } + DAT_SkMasters2DataArray::instance[insertIndex] = DAT_SkMasterDataEntry::instance; if (DAT_SkMasters2Data_Count::instance < 250) { DAT_SkMasters2Data_Count::instance = DAT_SkMasters2Data_Count::instance + 1; } diff --git a/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp b/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp index a38df47e80..ffb88e7682 100644 --- a/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp @@ -16,20 +16,22 @@ namespace Map { DAT_GameState::instance.mapAndTime.militaryCampaignFlags = 0; DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; if (DAT_GameCore::instance.missionNumber1to20 == 17) { - DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month + 1; + DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = (short)(DAT_GameState::instance.mapAndTime.month + 1); } else if (DAT_GameCore::instance.missionNumber1to20 == 18) { - DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month + 1; + DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = (short)(DAT_GameState::instance.mapAndTime.month + 1); + return; } else if (DAT_GameCore::instance.missionNumber1to20 == 19) { - DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month + 6; + DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = (short)(DAT_GameState::instance.mapAndTime.month + 6); + } else if (DAT_GameCore::instance.missionNumber1to20 == 20) { + DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = (short)(DAT_GameState::instance.mapAndTime.month + 3); } else { - if (DAT_GameCore::instance.missionNumber1to20 != 20) { - DAT_GameState::instance.mapAndTime.militaryCampaignStage = 0; - DAT_GameState::instance.mapAndTime.militaryCampaignFlags = 0; - DAT_GameState::instance.mapAndTime.field3183_0x27dc = 0; - } - DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month + 3; + return; } - if (12 < DAT_GameState::instance.mapAndTime.month) { + if (DAT_GameState::instance.mapAndTime.month >= 12) { DAT_GameState::instance.mapAndTime.month = DAT_GameState::instance.mapAndTime.month - 12; DAT_GameState::instance.mapAndTime.year = DAT_GameState::instance.mapAndTime.year + 1; } diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp index 85a6ce68a3..fbbb0c20c4 100644 --- a/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp @@ -15,23 +15,25 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004C6820 void MapPropertiesState::loadMapSiegeHeaderForMissionIndex(char* param_1) { - char* pcVar1; - pcVar1 = param_1 + -1; - if ((int)pcVar1 < 5) { + param_1 = param_1 - 1; + if ((int)param_1 < 5) { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( - (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)pcVar1]); + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)param_1]); + return; } - if ((int)pcVar1 < 10) { + if ((int)param_1 < 10) { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( - (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)pcVar1]); + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)param_1]); + return; } - if ((int)pcVar1 < 0xf) { + if ((int)param_1 < 15) { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( - (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)pcVar1]); + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)param_1]); + return; } - if ((int)pcVar1 < 20) { + if ((int)param_1 < 20) { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( - (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)pcVar1]); + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)param_1]); } } diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp index d9b45f589e..9761c048c8 100644 --- a/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp @@ -17,25 +17,22 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004C6880 void MapPropertiesState::loadMissionMapAndSetLord(int missionNumber) { - int iVar1; - char* mapName; - iVar1 = missionNumber + -1; - if (iVar1 < 5) { - LAB_004c688d: - mapName = (&DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName)[missionNumber]; - } else { - if (9 < iVar1) { - if (iVar1 < 0xf) - goto LAB_004c688d; - if (0x13 < iVar1) - goto LAB_004c68b3; - } - mapName = (&DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName)[missionNumber]; + missionNumber = missionNumber - 1; + if (missionNumber < 5) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[missionNumber]); + } else if (missionNumber < 10) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[missionNumber]); + } else if (missionNumber < 15) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[missionNumber]); + } else if (missionNumber < 20) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[missionNumber]); } - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMap, this)(mapName); - LAB_004c68b3: MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::setMissionNumberSpecificLord, DAT_UnitsState::ptr)( - missionNumber); + missionNumber + 1); } } diff --git a/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp b/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp index bee9caf210..f2fc6c7f94 100644 --- a/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp +++ b/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp @@ -69,16 +69,9 @@ void Synchrony::LoadSkirmishCampaignData(int missionID) DAT_GameSynchronyState::instance.currentGameMode = Game::GM_SKIRMISH_SINGLE_PLAYER; MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( Commands::GCT_ASK_FOR_SLOT_ASSIGNMENT); - if (1 < pCVar9->numberOfPlayers) { - piVar4 = &pCVar9->player2AI; - iVar7 = 1; - do { - iVar5 = iVar7 + 1; - DAT_GameSynchronyState::instance.currentAIArray[iVar7 + 1] = *piVar4; - MACRO_CALL(Synchrony_Func::ResetAiVariationArrayValue)(iVar5); - piVar4 = piVar4 + 1; - iVar7 = iVar5; - } while (iVar5 < pCVar9->numberOfPlayers); + for (int i = 1; i < pCVar9->numberOfPlayers; i++) { + DAT_GameSynchronyState::instance.currentAIArray[i + 1] = (&pCVar9->player1AI)[i]; + MACRO_CALL(Synchrony_Func::ResetAiVariationArrayValue)(i + 1); } MACRO_CALL(Synchrony_Func::SetAIPlayerNickNames)(); iVar7 = pCVar9->numberOfPlayers; @@ -113,14 +106,8 @@ void Synchrony::LoadSkirmishCampaignData(int missionID) } while (iVar5 < 9); DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance = pCVar9->fairness; DAT_GameSynchronyState::instance.skirmishGameIntensityType = pCVar9->startLevels; - DAT_GameSynchronyState::instance.playerPositionsArray[0] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[1] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[2] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[3] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[4] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[5] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[6] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[7] = -10; + memset(DAT_GameSynchronyState::instance.playerPositionsArray, -10, + sizeof(DAT_GameSynchronyState::instance.playerPositionsArray)); piVar4 = &pCVar9->position1; iVar7 = 0; do { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5ab7583bb5..4ba9a2a1c7 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -23369,7 +23369,7 @@ SHC_3BB0A8C1_0x0048FCB0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0048FFD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00490060 | 94.4% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x00490060 | 99.3% | Base/index operand order SHC_3BB0A8C1_0x00490080 | 0.0% | Pending @@ -29881,7 +29881,7 @@ SHC_3BB0A8C1_0x004BC100 | 0.0% | Pending SHC_3BB0A8C1_0x004BC104 | 0.0% | Pending -SHC_3BB0A8C1_0x004BC110 | 28.9% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004BC110 | 74.7% | Shared tail in wrong arm SHC_3BB0A8C1_0x004BC1C0 | 100.0% | Pending @@ -34143,13 +34143,13 @@ SHC_3BB0A8C1_0x004C62A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C62C0 | 43.3% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x004C6820 | 3.7% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004C6820 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C6880 | 26.3% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004C6880 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C68D0 | 44.8% | Ported from gynt, asm differs -SHC_3BB0A8C1_0x004C6B20 | 92.4% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004C6B20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C6B90 | 0.0% | Pending @@ -35565,7 +35565,7 @@ SHC_3BB0A8C1_0x004D5010 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D5180 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004D52A0 | 17.0% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004D52A0 | 87.4% | Count/entries struct aliasing SHC_3BB0A8C1_0x004D5370 | 16.4% | Ported from gynt, asm differs From a1e177b072aebf3f9dd112b750b5a476ca0d6749 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 28 Nov 2026 21:03:44 +0100 Subject: [PATCH 05/60] Mission/skirmish flow: Tutorial_IsActionAllowed 32.9 -> 92.3, two more improved - Tutorial_IsActionAllowed: rebuilt from the original jump table. The step arms fall through to one shared return FALSE (an `if (c) return TRUE; return FALSE;` per arm becomes sete), and DAT_00df5590 is compared signed. Left: cases 3 and 4 keep their shared tail in the other arm. - ComputePlayerRanking 48.7 -> 53.8: the points table has 10 rows and the dead list 10 slots, as the original zeroes them. Left: playerID kept in ebp. - SetupSkirmishMode 44.8 -> 47.6: memset for the positions, indexed AI loop and a signed start date, as in LoadSkirmishCampaignData. Left: the original divides by 12 with idiv and keeps 1 and -1 in callee-saved registers. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Audio/SFX/ComputePlayerRanking.cpp | 84 +++++++--------- .../Game/Skirmish/SetupSkirmishMode.cpp | 47 ++++----- src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp | 96 +++++++------------ status/addresses-SHC-3BB0A8C1.txt | 6 +- 4 files changed, 90 insertions(+), 143 deletions(-) diff --git a/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp b/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp index 8b4afa3a5b..a90a2b38cd 100644 --- a/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp +++ b/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp @@ -15,60 +15,44 @@ namespace Audio { // FUNCTION: STRONGHOLDCRUSADER 0x0044B680 int SFX::ComputePlayerRanking(int playerID) { - int _playerID; - int _highestPointsUnk; - undefined4 _deadPlayerList[10]; - int _playerPointsArray[9][2]; - _playerPointsArray[0][0] = 0; - _playerPointsArray[1][0] = 0; - _playerPointsArray[2][0] = 0; - _playerPointsArray[3][0] = 0; - _playerPointsArray[4][0] = 0; - _playerPointsArray[5][0] = 0; - _playerPointsArray[6][0] = 0; - _playerPointsArray[7][0] = 0; - _playerPointsArray[8][0] = 0; - int _arrayIndex = 0; - for (_playerID = 1; _playerID < 9; _playerID++) { - if (DAT_GameSynchronyState::instance.finalResults.active[_playerID] != 0) { - _playerPointsArray[_arrayIndex][0] = _playerID; - int _isAlive = MACRO_CALL_MEMBER( - Map::Units::UnitsState_Func::getAliveLordForPlayer, DAT_UnitsState::ptr)(_playerID); - if (!_isAlive) { - if (_playerID == playerID) { - return 0; - } - _deadPlayerList[_playerID] = 1; - _playerPointsArray[_arrayIndex][1] = 0; - } else { - int _playerPoints = MACRO_CALL(Audio::SFX_Func::ComputePlayerPoints1)(_playerID); - _playerPointsArray[_arrayIndex][1] = _playerPoints; - } - _arrayIndex = _arrayIndex + 1; - } + int deadPlayers[10]; + int playerPoints[10][2]; + for (int i = 0; i < 10; i++) { + playerPoints[i][0] = 0; } - int _index = 0; - if (0 < _arrayIndex) { - do { - int _highestPointsIndex = -1; - int _index2 = 0; - do { - if ((_playerPointsArray[_index2][0] != 0) - && ((_highestPointsIndex == -1 || (_highestPointsUnk < _playerPointsArray[_index2][1])))) { - _highestPointsUnk = _playerPointsArray[_index2][1]; - _highestPointsIndex = _index2; - } - _index2 = _index2 + 1; - } while (_index2 < _arrayIndex); - if (_highestPointsIndex < 0) { + int count = 0; + for (int player = 1; player < 9; player++) { + if (DAT_GameSynchronyState::instance.finalResults.active[player] == 0) { + continue; + } + playerPoints[count][0] = player; + if (!MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::getAliveLordForPlayer, DAT_UnitsState::ptr)(player)) { + if (player == playerID) { return 0; } - if (_playerPointsArray[_highestPointsIndex][0] == playerID) { - return _index + 1; + deadPlayers[player] = 1; + playerPoints[count][1] = 0; + } else { + playerPoints[count][1] = MACRO_CALL(Audio::SFX_Func::ComputePlayerPoints1)(player); + } + count = count + 1; + } + int highestPoints; + for (int rank = 0; rank < count; rank++) { + int highestIndex = -1; + for (int i = 0; i < count; i++) { + if (playerPoints[i][0] != 0 && (highestIndex == -1 || playerPoints[i][1] > highestPoints)) { + highestPoints = playerPoints[i][1]; + highestIndex = i; } - _index = _index + 1; - _playerPointsArray[_highestPointsIndex][0] = 0; - } while (_index < _arrayIndex); + } + if (highestIndex < 0) { + return 0; + } + if (playerPoints[highestIndex][0] == playerID) { + return rank + 1; + } + playerPoints[highestIndex][0] = 0; } return 0; } diff --git a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp index 7f59cdebdf..1afefa6fb4 100644 --- a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp +++ b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp @@ -37,7 +37,7 @@ namespace Game { int iVar5; char (*pacVar6)[250]; CampaignTrailMission* pCVar7; - dword _startDateInMonths; + int startDateInMonths; pCVar7 = DAT_SkirmishDefinedData::instance.SkirmishTrailMissions + skirmishTrailMission; if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { pCVar7 = DAT_SkirmishDefinedData::instance.ExtremeTrailMissions + skirmishTrailMission; @@ -78,25 +78,12 @@ namespace Game { DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[8] = 1; DAT_GameSynchronyState::instance.skirmishRelated1 = -1; DAT_GameCore::instance.mapU4Int0 = 0; - if (1 < pCVar7->numberOfPlayers) { - piVar2 = &pCVar7->player2AI; - iVar4 = 1; - do { - iVar5 = iVar4 + 1; - DAT_GameSynchronyState::instance.currentAIArray[iVar4 + 1] = *piVar2; - MACRO_CALL(Synchrony_Func::ResetAiVariationArrayValue)(iVar5); - piVar2 = piVar2 + 1; - iVar4 = iVar5; - } while (iVar5 < pCVar7->numberOfPlayers); + for (int i = 1; i < pCVar7->numberOfPlayers; i++) { + DAT_GameSynchronyState::instance.currentAIArray[i + 1] = (&pCVar7->player1AI)[i]; + MACRO_CALL(Synchrony_Func::ResetAiVariationArrayValue)(i + 1); } - DAT_GameSynchronyState::instance.playerPositionsArray[0] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[1] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[2] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[3] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[4] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[5] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[6] = -10; - DAT_GameSynchronyState::instance.playerPositionsArray[7] = -10; + memset(DAT_GameSynchronyState::instance.playerPositionsArray, -10, + sizeof(DAT_GameSynchronyState::instance.playerPositionsArray)); iVar4 = 0; piVar2 = &pCVar7->position1; do { @@ -111,7 +98,7 @@ namespace Game { piVar2 = &pCVar7->team1; do { DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5 + 1] = (byte)*piVar2; - if (iVar4 <= iVar5) { + if (iVar5 >= iVar4) { DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5 + 1] = 0xff; } iVar5 = iVar5 + 1; @@ -131,26 +118,26 @@ namespace Game { if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { DAT_GameCore::instance.extremeTrailProgress = skirmishTrailMission; MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)piVar2); - _startDateInMonths + startDateInMonths = DAT_GameCore::instance.extremeTrailStartDatesInMonths[DAT_GameCore::instance.extremeTrailProgress]; - DAT_GameCore::instance.extremeTrailStartDateMonths = _startDateInMonths; + DAT_GameCore::instance.extremeTrailStartDateMonths = startDateInMonths; } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { DAT_GameCore::instance.warchestTrailProgress = skirmishTrailMission; MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)piVar2); - _startDateInMonths + startDateInMonths = DAT_GameCore::instance.warchestTrailStartDatesInMonths[DAT_GameCore::instance.warchestTrailProgress]; - DAT_GameCore::instance.warchestTrailStartDateMonths = _startDateInMonths; + DAT_GameCore::instance.warchestTrailStartDateMonths = startDateInMonths; } else { DAT_GameCore::instance.skirmishTrailProgress = skirmishTrailMission; MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)piVar2); - _startDateInMonths + startDateInMonths = DAT_GameCore::instance.skirmishTrailStartDateInMonths[DAT_GameCore::instance.skirmishTrailProgress]; - DAT_GameCore::instance.skirmishTrailStartDateMonths = _startDateInMonths; + DAT_GameCore::instance.skirmishTrailStartDateMonths = startDateInMonths; } - DAT_GameState::instance.mapAndTime.year = (int)_startDateInMonths / 0xc; - DAT_GameState::instance.mapAndTime.month = (int)_startDateInMonths % 0xc; - DAT_GameSynchronyState::instance.finalResults.tail.tail1.yearStart = (int)_startDateInMonths / 0xc; - DAT_GameSynchronyState::instance.finalResults.tail.tail1.monthStart = (int)_startDateInMonths % 0xc; + DAT_GameState::instance.mapAndTime.year = startDateInMonths / 0xc; + DAT_GameState::instance.mapAndTime.month = startDateInMonths % 0xc; + DAT_GameSynchronyState::instance.finalResults.tail.tail1.yearStart = startDateInMonths / 0xc; + DAT_GameSynchronyState::instance.finalResults.tail.tail1.monthStart = startDateInMonths % 0xc; } } diff --git a/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp index 4e45d6f41a..4fe451dbbd 100644 --- a/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp +++ b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp @@ -17,72 +17,52 @@ using WindowsHelper::Enums::BOOLEnum; // FUNCTION: STRONGHOLDCRUSADER 0x004BD800 BOOLEnum Game::Tutorial_IsActionAllowed(undefined4 actionType, int actionParam) { - int iVar1; - bool bVar2; if (DAT_DisableTutorialRestrictions::instance) { return TRUE; } switch (actionType) { case 1: if (DAT_TutorialCurrentStep::instance == 2) { - if (1 < DAT_00df5558::instance) { - return FALSE; + if (DAT_00df5558::instance < 2 && actionParam == 40) { + return TRUE; } - bVar2 = actionParam == 0x28; } else if (DAT_TutorialCurrentStep::instance == 5) { - if (DAT_00df5558::instance) { - return FALSE; + if (DAT_00df5558::instance == 0 && actionParam == 19) { + return TRUE; } - bVar2 = actionParam == 0x13; - } else if (DAT_TutorialCurrentStep::instance == 0x11) { - if (actionParam != 3) { - return FALSE; + } else if (DAT_TutorialCurrentStep::instance == 17) { + if (actionParam == 3 && DAT_00df5560::instance == 0) { + return TRUE; } - bVar2 = DAT_00df5560::instance == 0; - } else { - if (DAT_TutorialCurrentStep::instance != 0x15) { - if (DAT_TutorialCurrentStep::instance != 0x18) { - return FALSE; - } - if (actionParam != 1) { - return FALSE; - } + } else if (DAT_TutorialCurrentStep::instance == 21) { + if (actionParam == 7) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 24) { + if (actionParam == 1) { return TRUE; } - bVar2 = actionParam == 7; - } - if (bVar2) { - return TRUE; } return FALSE; case 2: if (DAT_TutorialCurrentStep::instance == 2) { - if ((DAT_00df5558::instance < 2) && (actionParam == 0x28)) { + if (DAT_00df5558::instance < 2 && actionParam == 40) { return TRUE; } } else if (DAT_TutorialCurrentStep::instance == 5) { - if (((!DAT_00df5558::instance) && (actionParam == 0x13)) && (!DAT_00df5560::instance)) { + if (DAT_00df5558::instance == 0 && actionParam == 19 && DAT_00df5560::instance == 0) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 17) { + if (actionParam == 3 && (int)DAT_00df5590::instance < 4) { return TRUE; } - } else { - if (DAT_TutorialCurrentStep::instance == 0x11) { - bVar2 = actionParam == 3; - } else { - if (DAT_TutorialCurrentStep::instance != 0x15) { - if (DAT_TutorialCurrentStep::instance != 0x18) { - return FALSE; - } - if (actionParam != 1) { - return FALSE; - } - if (DAT_00df5560::instance) { - return FALSE; - } - return TRUE; - } - bVar2 = actionParam == 7; + } else if (DAT_TutorialCurrentStep::instance == 21) { + if (actionParam == 7 && (int)DAT_00df5590::instance < 4) { + return TRUE; } - if ((bVar2) && (DAT_00df5590::instance < 4)) { + } else if (DAT_TutorialCurrentStep::instance == 24) { + if (actionParam == 1 && DAT_00df5560::instance == 0) { return TRUE; } } @@ -91,27 +71,23 @@ BOOLEnum Game::Tutorial_IsActionAllowed(undefined4 actionType, int actionParam) if (DAT_TutorialCurrentStep::instance != 8) { return FALSE; } - iVar1 = 4; - bVar2 = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .rationsSetting - == 4; - break; + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].rationsSetting + == 4 + && actionParam != 4) { + return FALSE; + } + return TRUE; case 4: if (DAT_TutorialCurrentStep::instance != 10) { return FALSE; } - iVar1 = 7; - bVar2 - = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].taxesSetting - == 7; - break; - default: - goto switchD_004bd819_caseD_4; - } - if ((bVar2) && (actionParam != iVar1)) { - return FALSE; + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].taxesSetting + == 7 + && actionParam != 7) { + return FALSE; + } + return TRUE; } -switchD_004bd819_caseD_4: return TRUE; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 4ba9a2a1c7..7d39736fa8 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16863,7 +16863,7 @@ SHC_3BB0A8C1_0x0044B673 | 0.0% | Pending SHC_3BB0A8C1_0x0044B674 | 0.0% | Pending -SHC_3BB0A8C1_0x0044B680 | 48.7% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x0044B680 | 53.8% | Register allocation SHC_3BB0A8C1_0x0044B760 | 100.0% | Reimplemented @@ -30243,7 +30243,7 @@ SHC_3BB0A8C1_0x004BD7F0 | 0.0% | Pending SHC_3BB0A8C1_0x004BD7F4 | 0.0% | Pending -SHC_3BB0A8C1_0x004BD800 | 32.9% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004BD800 | 92.3% | Shared tail in wrong arm SHC_3BB0A8C1_0x004BD970 | 0.0% | Pending @@ -34147,7 +34147,7 @@ SHC_3BB0A8C1_0x004C6820 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C6880 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C68D0 | 44.8% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004C68D0 | 47.6% | idiv by 12, register allocation SHC_3BB0A8C1_0x004C6B20 | 100.0% | Reimplemented From beec747e565c7163fdbe69a7d207bccb37ea9027 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 04:21:32 +0100 Subject: [PATCH 06/60] Skirmish: DeleteEntry moves entries up by struct assignment 16.4 -> 34.5. The original copies each entry with rep movsd, which is a struct assignment, not the decompiler's dword loop. The original re-reads the entry count after every copy. The count (0xdf624c) sits directly before the array (0xdf6250), so the original most likely declared both as one struct, where a store into an entry may alias the count. With two separate globals MSVC hoists the count and counts the loop down instead. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../SkirmishLeaderboard_DeleteEntry.cpp | 25 +++++-------------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp b/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp index 44d6704073..a3262bf113 100644 --- a/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp +++ b/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp @@ -18,26 +18,13 @@ namespace Game { // FUNCTION: STRONGHOLDCRUSADER 0x004D5370 void Skirmish::SkirmishLeaderboard_DeleteEntry(int index) { - SkMasterDataEntry* pSVar1; - int iVar2; - SkMasterDataEntry* pSVar3; - SkMasterDataEntry* pSVar4; - if ((-1 < index) && (index < DAT_SkMasters2Data_Count::instance)) { - if (index < DAT_SkMasters2Data_Count::instance + -1) { - pSVar1 = DAT_SkMasters2DataArray::instance + index; - do { - pSVar3 = pSVar1 + 1; - pSVar4 = pSVar1; - for (iVar2 = 0x2fc; iVar2 != 0; iVar2 = iVar2 + -1) { - pSVar4->score = pSVar3->score; - pSVar3 = (SkMasterDataEntry*)pSVar3->mapName; - pSVar4 = (SkMasterDataEntry*)pSVar4->mapName; - } - index = index + 1; - pSVar1 = pSVar1 + 1; - } while (index < DAT_SkMasters2Data_Count::instance + -1); + if (index >= 0 && index < DAT_SkMasters2Data_Count::instance) { + // close the gap by moving every later entry up one + for (int i = index; i < DAT_SkMasters2Data_Count::instance - 1; i++) { + SkMasterDataEntry& entry = DAT_SkMasters2DataArray::instance[i]; + entry = DAT_SkMasters2DataArray::instance[i + 1]; } - DAT_SkMasters2Data_Count::instance = DAT_SkMasters2Data_Count::instance + -1; + DAT_SkMasters2Data_Count::instance = DAT_SkMasters2Data_Count::instance - 1; MACRO_CALL(IO_Func::WriteSkMasters2)(); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7d39736fa8..38a9cc7059 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -35567,7 +35567,7 @@ SHC_3BB0A8C1_0x004D5180 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D52A0 | 87.4% | Count/entries struct aliasing -SHC_3BB0A8C1_0x004D5370 | 16.4% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004D5370 | 34.5% | count and entries are one struct in the original SHC_3BB0A8C1_0x004D53A0 | 0.0% | Pending From cf8dccfd567626ccfe2b063563e88a9cf771c656 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 04:31:36 +0100 Subject: [PATCH 07/60] UI: loadOrSaveGame fixes the map index off-by-one 55.6 -> 62.9, plus a behaviour fix. - The original writes DAT_ArrayOfMapIndices[i] = i and DAT_ArrayOfMapIndices2[i - 1] = 1 (esi + 0x880 + 4i and esi + 0x1050 + 4i). The ported code wrote both one entry low, so every multiplayer save shifted by one and entry 0 was never written. Indices2 is indexed by the 1-based map number, as everywhere else. - paths_getSavesPath is called directly, as paths.cpp already notes: the resolver call cannot use return value optimisation. Each arm otherwise copied a temporary string, which doubled the frame (0x74 against the original's 0x3c). - The dialog-clear case returns early, and the multiplayer (.msv) arm comes first, as in the original. What is left is register roles: the original keeps 1 in edi and the string's small-buffer limit 0x10 in ebp. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../UI/MenuTextInputState/loadOrSaveGame.cpp | 162 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 78 insertions(+), 86 deletions(-) diff --git a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp index fdfc4b3fd1..1344dbdedf 100644 --- a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp +++ b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp @@ -29,97 +29,89 @@ namespace UI { // FUNCTION: STRONGHOLDCRUSADER 0x004968A0 void MenuTextInputState::loadOrSaveGame(int action) { - int iVar1; - int iVar2; - int* puVar5; - int iVar6; - if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY - || DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SKIRMISH_SINGLE_PLAYER - || DAT_GameSynchronyState::instance.saveRelated != 1 || action != 10) { - DAT_MouseState::instance.waitCursorToggle = 1; - MACRO_CALL(UI::Helpers_Func::SetCursorDependingOnProgramState)(); - MACRO_CALL(OS_Func::_memset)(DAT_MinimapViewState::instance.loadedMiniMap, 0, 80000); - INT_00b95b64::instance = 1; - if ((DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) - || (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SKIRMISH_SINGLE_PLAYER)) { - std::string _savesPath - = MACRO_CALL_MEMBER(IO::ResourceManager_Func::paths_getSavesPath, DAT_ResourceManager::ptr)(true); - _savesPath.append("*.sav", 5); - MACRO_CALL_MEMBER(IO::ResourceManager_Func::discoverMapFiles, DAT_ResourceManager::ptr)( - _savesPath.c_str()); - this->fileListEntryCount = DAT_ResourceManager::instance.mapFileCounter; - for (int _mapIndex = 0; _mapIndex < DAT_ResourceManager::instance.mapFileCounter; _mapIndex++) { - this->DAT_ArrayOfMapIndices[_mapIndex] = _mapIndex; - } - } else { - std::string _savesPath - = MACRO_CALL_MEMBER(IO::ResourceManager_Func::paths_getSavesPath, DAT_ResourceManager::ptr)(true); - _savesPath.append("*.msv", 5); - MACRO_CALL_MEMBER(IO::ResourceManager_Func::discoverMapFiles, DAT_ResourceManager::ptr)( - _savesPath.c_str()); - this->fileListEntryCount = DAT_ResourceManager::instance.mapFileCounter; - iVar6 = 0; - if (0 < DAT_ResourceManager::instance.mapFileCounter) { - puVar5 = this->DAT_ArrayOfMapIndices + 499; - do { - puVar5[-500] = iVar6; - *puVar5 = 1; - if (action != 10) { - DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = iVar6; - MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, - DAT_GameSynchronyState::ptr)((Commands::GameCommandType)(Commands::GCT_LOAD_MAP_HEADER - | Commands::GCT_MULTIPLAYER_INITIATE_ANNOUNCE_HOST)); - } - iVar6 = iVar6 + 1; - puVar5 = puVar5 + 1; - } while (iVar6 < DAT_ResourceManager::instance.mapFileCounter); + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + && DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SKIRMISH_SINGLE_PLAYER + && DAT_GameSynchronyState::instance.saveRelated == 1 && action == 10) { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, this)(); + return; + } + DAT_MouseState::instance.waitCursorToggle = 1; + MACRO_CALL(UI::Helpers_Func::SetCursorDependingOnProgramState)(); + MACRO_CALL(OS_Func::_memset)(DAT_MinimapViewState::instance.loadedMiniMap, 0, 80000); + INT_00b95b64::instance = 1; + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + && DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SKIRMISH_SINGLE_PLAYER) { + std::string savesPath(DAT_ResourceManager::instance.paths_getSavesPath(true)); + savesPath.append("*.msv", 5); + MACRO_CALL_MEMBER(IO::ResourceManager_Func::discoverMapFiles, DAT_ResourceManager::ptr)(savesPath.c_str()); + this->fileListEntryCount = DAT_ResourceManager::instance.mapFileCounter; + for (int i = 0; i < DAT_ResourceManager::instance.mapFileCounter; i++) { + this->DAT_ArrayOfMapIndices[i] = i; + // indexed by map number, which counts from 1 + this->DAT_ArrayOfMapIndices2[i - 1] = 1; + if (action != 10) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = i; + MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + (Commands::GameCommandType)(Commands::GCT_LOAD_MAP_HEADER + | Commands::GCT_MULTIPLAYER_INITIATE_ANNOUNCE_HOST)); } } - DAT_MouseState::instance.waitCursorToggle = 0; - this->fileListSortOrder = 0; - this->menuLoadGameRelativeSelectionOffset = 0; - if (!this->fileListEntryCount) { - this->menuLoadGameRelativeSelectionIndex = -1; - } else { - this->menuLoadGameRelativeSelectionIndex = 0; - } - this->lastListClickTime = 0; - this->lastClickedListIndex = 0xffffffff; - this->DAT_ArrayOfMapU3EndInt2 = 0; - this->previewedListIndex = 0xffffffff; - this->fileListVisibleRowCount = 0x10; - if (action == 9) { - MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( - UI::Enums::MMT_LOAD_MAP); - this->fileListContext = 1; - iVar6 = this->savedListOffset1; - iVar1 = this->savedListSelection1; - iVar2 = this->savedListSortOrder1; - } else { - MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( - UI::Enums::MMT_SAVE_MAP); - DAT_UserTextHandlerState::instance.allowUserTextInput = 0; - MACRO_CALL_MEMBER(Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)(2); - MACRO_CALL_MEMBER(Text::UserTextHandler_Func::moveCursorToEnd, DAT_UserTextHandlerState::ptr)(); - DAT_UserTextHandlerState::instance.allowUserTextInput = 1; - this->fileListContext = 3; - iVar6 = this->savedListOffset2; - iVar1 = this->savedListSelection2; - iVar2 = this->savedListSortOrder2; + } else { + std::string savesPath(DAT_ResourceManager::instance.paths_getSavesPath(true)); + savesPath.append("*.sav", 5); + MACRO_CALL_MEMBER(IO::ResourceManager_Func::discoverMapFiles, DAT_ResourceManager::ptr)(savesPath.c_str()); + this->fileListEntryCount = DAT_ResourceManager::instance.mapFileCounter; + for (int i = 0; i < DAT_ResourceManager::instance.mapFileCounter; i++) { + this->DAT_ArrayOfMapIndices[i] = i; } - if ((this->menuLoadGameRelativeSelectionIndex != -1) - && (this->fileListSortOrder = iVar2, this->menuLoadGameRelativeSelectionIndex = iVar1, - this->menuLoadGameRelativeSelectionOffset = iVar6, iVar6 + iVar1 >= this->fileListEntryCount)) { + } + DAT_MouseState::instance.waitCursorToggle = 0; + this->fileListSortOrder = 0; + this->menuLoadGameRelativeSelectionOffset = 0; + if (!this->fileListEntryCount) { + this->menuLoadGameRelativeSelectionIndex = -1; + } else { + this->menuLoadGameRelativeSelectionIndex = 0; + } + this->lastListClickTime = 0; + this->lastClickedListIndex = 0xffffffff; + this->DAT_ArrayOfMapU3EndInt2 = 0; + this->previewedListIndex = 0xffffffff; + this->fileListVisibleRowCount = 0x10; + int offset; + int selection; + int sortOrder; + if (action == 9) { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( + UI::Enums::MMT_LOAD_MAP); + this->fileListContext = 1; + offset = this->savedListOffset1; + selection = this->savedListSelection1; + sortOrder = this->savedListSortOrder1; + } else { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( + UI::Enums::MMT_SAVE_MAP); + DAT_UserTextHandlerState::instance.allowUserTextInput = 0; + MACRO_CALL_MEMBER(Text::UserTextHandler_Func::resetToTextIndex, DAT_UserTextHandlerState::ptr)(2); + MACRO_CALL_MEMBER(Text::UserTextHandler_Func::moveCursorToEnd, DAT_UserTextHandlerState::ptr)(); + DAT_UserTextHandlerState::instance.allowUserTextInput = 1; + this->fileListContext = 3; + offset = this->savedListOffset2; + selection = this->savedListSelection2; + sortOrder = this->savedListSortOrder2; + } + // restore where the list was left, unless that is past its end now + if (this->menuLoadGameRelativeSelectionIndex != -1) { + this->fileListSortOrder = sortOrder; + this->menuLoadGameRelativeSelectionIndex = selection; + this->menuLoadGameRelativeSelectionOffset = offset; + if (offset + selection >= this->fileListEntryCount) { this->menuLoadGameRelativeSelectionIndex = 0; this->menuLoadGameRelativeSelectionOffset = 0; } - MACRO_CALL(UI::MenuItems::SaveLoadMap_Func::MenuItemActionHandler_SaveLoadMap_TableHeader)( - -1 - this->fileListSortOrder); - } else { - MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, this)(); - }; - return; + } + MACRO_CALL(UI::MenuItems::SaveLoadMap_Func::MenuItemActionHandler_SaveLoadMap_TableHeader)( + -1 - this->fileListSortOrder); } - } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 38a9cc7059..dd8fea695b 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -24233,7 +24233,7 @@ SHC_3BB0A8C1_0x00495A30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00496400 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004968A0 | 55.6% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004968A0 | 62.9% | register roles for the 1 and 0x10 constants SHC_3BB0A8C1_0x00496B80 | 100.0% | Reimplemented From 4cd90bdd6f5ec5a9c0ee94860a3246fa318adbb6 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 04:35:07 +0100 Subject: [PATCH 08/60] Skirmish: rewrite PrepareLeaderboardView from the original 42.6 -> 86.1, plus a behaviour fix. - The mission column sorted twice for filter 1 with entries present. The decompiler duplicated the sort call into the loop's guard, but the original reaches one sort call from both sides. - Every arm counts in INT_00eb9b60 and reads the entry count from its global, which is why the original reloads both after the name lookup call. - The sort-column arms return one by one, and the stored-order arm tests `<= 1`. - The backwards walk keeps a separate trip counter, as the original's `sub esi, 1; jne` does. - The date key goes to INT_ARRAY_00ed2be0[n]; the decompiler addressed it as INT_00ed2bdc[n + 1]. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Skirmish_PrepareLeaderboardView.cpp | 259 ++++++------------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 88 insertions(+), 173 deletions(-) diff --git a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp index 9df1760c68..e03c96d8a4 100644 --- a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp +++ b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp @@ -24,197 +24,112 @@ namespace Game { // FUNCTION: STRONGHOLDCRUSADER 0x004D9400 void Skirmish::Skirmish_PrepareLeaderboardView() { - char cVar1; - int iVar2; - byte bVar3; - int _index; - SkMasterDataEntry* puVar7; - char* pcVar4; - int _index2; - SkMasterDataEntry* _pSkMasters_01; - SkMasterDataEntry* _pSkMasters_02; - int* piVar5; - byte bVar6; - int iVar7; - SkMasterDataEntry* pSVar8; - char* pcVar9; - int _count; - uint _month; - uint _year; - _count = DAT_SkMasters2Data_Count::instance; - /* - Phase 1: Initialize visibility filter - */ - if (0 < DAT_SkMasters2Data_Count::instance) { - piVar5 = INT_ARRAY_00eb0e48::instance; - for (_index2 = DAT_SkMasters2Data_Count::instance; _index2 != 0; _index2 = _index2 + -1) { - *piVar5 = 1; - piVar5 = piVar5 + 1; - } + for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + INT_ARRAY_00eb0e48::instance[i] = 1; } - iVar7 = DAT_00ed3124::instance; + // filter 1 hides the custom maps (no trail mission score), filter 2 the trail missions if (DAT_00ed3124::instance == 1) { - _index = 0; - if (0 < _count) { - _pSkMasters_01 = DAT_SkMasters2DataArray::instance; - do { - if (!_pSkMasters_01->score) { - INT_ARRAY_00eb0e48::instance[_index] = 0; - } - _index = _index + 1; - _pSkMasters_01 = _pSkMasters_01 + 1; - } while (_index < _count); + for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + if (!DAT_SkMasters2DataArray::instance[i].score) { + INT_ARRAY_00eb0e48::instance[i] = 0; + } } - } else if ((DAT_00ed3124::instance == 2) && (_index = 0, 0 < _count)) { - _pSkMasters_02 = DAT_SkMasters2DataArray::instance; - do { - if (_pSkMasters_02->score) { - INT_ARRAY_00eb0e48::instance[_index] = 0; + } else if (DAT_00ed3124::instance == 2) { + for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + if (DAT_SkMasters2DataArray::instance[i].score) { + INT_ARRAY_00eb0e48::instance[i] = 0; } - _index = _index + 1; - _pSkMasters_02 = _pSkMasters_02 + 1; - } while (_index < _count); + } } - /* - Phase 2: Sort column dispatch - */ - if (DAT_MissionDefinedData::instance.sortColumn < 2) { - iVar7 = 0; + // columns 0 and 1 keep the stored order, forwards or backwards + if (DAT_MissionDefinedData::instance.sortColumn <= 1) { INT_00eb9b60::instance = 0; if (DAT_MissionDefinedData::instance.descending == 1) { - _index = 0; - if (0 < _count) { - do { - if (INT_ARRAY_00eb0e48::instance[_index] != 0) { - INT_ARRAY_00eb96d8::instance[iVar7] = _index; - iVar7 = iVar7 + 1; - } - _index = _index + 1; - } while (_index < _count); - INT_00eb9b60::instance = iVar7; + for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + INT_ARRAY_00eb96d8::instance[INT_00eb9b60::instance] = i; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; + } } - } else if ((!DAT_MissionDefinedData::instance.descending) && (0 < _count)) { - piVar5 = &INT_ARRAY_00eb0e48::instance[_count - 1]; - _index = _count; - do { - _index = _index + -1; - if (*piVar5 != 0) { - INT_ARRAY_00eb96d8::instance[iVar7] = _index; - iVar7 = iVar7 + 1; + } else if (!DAT_MissionDefinedData::instance.descending) { + for (int left = DAT_SkMasters2Data_Count::instance, i = DAT_SkMasters2Data_Count::instance - 1; + left != 0; left--, i--) { + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + INT_ARRAY_00eb96d8::instance[INT_00eb9b60::instance] = i; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } - piVar5 = piVar5 + -1; - _count = _count + -1; - } while (_count); - INT_00eb9b60::instance = iVar7; + } } - } else { - if (DAT_MissionDefinedData::instance.sortColumn == 4) { - _index = 0; - iVar7 = 0; - INT_00eb9b60::instance = 0; - if (0 < _count) { - puVar7 = DAT_SkMasters2DataArray::ptr[0]; - do { - if (INT_ARRAY_00eb0e48::instance[iVar7] != 0) { - _year = puVar7->localTimeYear; - _month = puVar7->localTimeMonth; - INT_ARRAY_00ed27f0::instance[_index] = iVar7; - _index = _index + 1; - (INT_00ed2bdc::ptr)[_index] - = ((_year - 2000) * 0x10 + _month) * 0x20 + puVar7->localTimeDay; - } - iVar7 = iVar7 + 1; - puVar7 = puVar7 + 0x2fc; - INT_00eb9b60::instance = _index; - } while (iVar7 < _count); + return; + } + // date + if (DAT_MissionDefinedData::instance.sortColumn == 4) { + INT_00eb9b60::instance = 0; + for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; + INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] + = ((DAT_SkMasters2DataArray::instance[i].localTimeYear - 2000) * 16 + + DAT_SkMasters2DataArray::instance[i].localTimeMonth) + * 32 + + DAT_SkMasters2DataArray::instance[i].localTimeDay; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } - MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)( - DAT_MissionDefinedData::instance.descending); } - if (DAT_MissionDefinedData::instance.sortColumn == 2) { - _index = 0; - INT_00eb9b60::instance = 0; - if (iVar7 == 1) { - iVar7 = 0; - if (0 < _count) { - pSVar8 = DAT_SkMasters2DataArray::instance; - do { - if (INT_ARRAY_00eb0e48::instance[iVar7] != 0) { - iVar2 = pSVar8->score; - INT_ARRAY_00ed27f0::instance[_index] = iVar7; - INT_ARRAY_00ed2be0::instance[_index] = 0x50 - iVar2; - _index = _index + 1; - } - iVar7 = iVar7 + 1; - pSVar8 = pSVar8 + 1; - } while (iVar7 < _count); - INT_00eb9b60::instance = _index; - MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)( - DAT_MissionDefinedData::instance.descending); + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + return; + } + // mission: trail missions by score, custom maps by the first two letters of their name + if (DAT_MissionDefinedData::instance.sortColumn == 2) { + INT_00eb9b60::instance = 0; + if (DAT_00ed3124::instance == 1) { + for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; + INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] + = 0x50 - DAT_SkMasters2DataArray::instance[i].score; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } - } else { - iVar7 = 0; - if (0 < _count) { - pSVar8 = DAT_SkMasters2DataArray::instance; - do { - if (INT_ARRAY_00eb0e48::instance[iVar7] != 0) { - if (pSVar8->score) { - pcVar4 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_TRAIL_NAMES_CRU, pSVar8->score); - pcVar9 = pSVar8->mapName; - do { - cVar1 = *pcVar4; - *pcVar9 = cVar1; - pcVar4 = pcVar4 + 1; - pcVar9 = pcVar9 + 1; - _index = INT_00eb9b60::instance; - _count = DAT_SkMasters2Data_Count::instance; - } while (cVar1 != '\0'); - } - bVar6 = pSVar8->mapName[0]; - if ((byte)(bVar6 + 0xbf) < 0x1a) { - bVar6 = bVar6 + 0x20; - } - bVar3 = pSVar8->mapName[1]; - if ((byte)(bVar3 + 0xbf) < 0x1a) { - bVar3 = bVar3 + 0x20; - } - INT_ARRAY_00ed2be0::instance[_index] = ((uint)bVar6 * -0x100 + -1) - (uint)bVar3; - INT_ARRAY_00ed27f0::instance[_index] = iVar7; - _index = _index + 1; - INT_00eb9b60::instance = _index; - } - iVar7 = iVar7 + 1; - pSVar8 = pSVar8 + 1; - } while (iVar7 < _count); + } + } else { + for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + if (DAT_SkMasters2DataArray::instance[i].score) { + strcpy(DAT_SkMasters2DataArray::instance[i].mapName, + MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)( + DE::SHCDE::TEXT_TRAIL_NAMES_CRU, DAT_SkMasters2DataArray::instance[i].score)); + } + byte first = DAT_SkMasters2DataArray::instance[i].mapName[0]; + if (first >= 'A' && first <= 'Z') { + first = first + 0x20; + } + byte second = DAT_SkMasters2DataArray::instance[i].mapName[1]; + if (second >= 'A' && second <= 'Z') { + second = second + 0x20; + } + INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] = -1 - first * 0x100 - second; + INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } } - MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)( - DAT_MissionDefinedData::instance.descending); } - if (DAT_MissionDefinedData::instance.sortColumn == 3) { - _index = 0; - iVar7 = 0; - INT_00eb9b60::instance = 0; - if (0 < _count) { - piVar5 = &DAT_SkMasters2DataArray::instance[0].gameDurationInMinutes; - do { - if (INT_ARRAY_00eb0e48::instance[iVar7] != 0) { - iVar2 = *piVar5; - INT_ARRAY_00ed27f0::instance[_index] = iVar7; - INT_ARRAY_00ed2be0::instance[_index] = -1 - iVar2; - _index = _index + 1; - } - iVar7 = iVar7 + 1; - piVar5 = piVar5 + 0x2fc; - INT_00eb9b60::instance = _index; - } while (iVar7 < _count); + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + return; + } + // duration + if (DAT_MissionDefinedData::instance.sortColumn == 3) { + INT_00eb9b60::instance = 0; + for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + if (INT_ARRAY_00eb0e48::instance[i] != 0) { + INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; + INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] + = -1 - DAT_SkMasters2DataArray::instance[i].gameDurationInMinutes; + INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } - MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)( - DAT_MissionDefinedData::instance.descending); } + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); } } - } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index dd8fea695b..c6289efaf0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -36023,7 +36023,7 @@ SHC_3BB0A8C1_0x004D9270 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D9290 | 100.0% | Reimplemented (counted: only memset/_stricmp call labels and the instance[i - 1] address label differ) -SHC_3BB0A8C1_0x004D9400 | 42.6% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004D9400 | 86.1% | register assignment SHC_3BB0A8C1_0x004D9520 | 0.0% | Pending From 4d5c166f988fbdb0a99acc0c6e41e60484f1a215 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 04:42:53 +0100 Subject: [PATCH 09/60] Map: spawnInvasionEventAttackWave returns after the last slider 47.0 -> 47.7, plus a behaviour fix. - The ported loop was `do { } while (true)` with no exit: after slider 24 it played the video and then carried on reading past the slider array forever. The original leaves the loop at slider 25 and plays the video once. - Slider 24 reads invasionPoint (25 sliders over 24 counts), as the original does. - The video choice is a switch on crusaderArabian. The original resets eventsCount once, after it. What is left is block layout. Our compiler threads each switch arm straight past the siege-engine compare chain, while the original jumps every arm to one shared `divisor = 10` block ahead of the chain. Declaring the locals outside the loop, wrapping the body instead of using continue, separate ifs and += all compiled the same. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../spawnInvasionEventAttackWave.cpp | 284 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 135 insertions(+), 151 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp b/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp index c5efcc49c4..16d4fa3b59 100644 --- a/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp @@ -24,23 +24,10 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004C13F0 void MapPropertiesState::spawnInvasionEventAttackWave() { - byte(*pabVar1)[10]; - byte* pbVar2; - int iVar3; - char cVar4; - int _sliderValue; - int _unitCount; - int _unitTypeOther; - UnitTypeInt _unitType; - char* eventVideoBik; - char* eventWavFile; - int local_10; - int local_c; - int _sliderIndex; DAT_TroopValueState::instance.attackInfo.inv_count = DAT_TroopValueState::instance.attackInfo.inv_count + 1; - local_c = 0; - local_10 = 0; - if (0x31 < DAT_TroopValueState::instance.attackInfo.inv_count) { + int tribe = 0; + int edge = 0; + if (DAT_TroopValueState::instance.attackInfo.inv_count >= 50) { DAT_TroopValueState::instance.attackInfo.inv_count = 1; } MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackWaveSlot, DAT_TroopValueState::ptr)( @@ -48,193 +35,190 @@ namespace Map { DAT_TroopValueState::instance.attackInfo .attackWavePlayerIDArray[DAT_TroopValueState::instance.attackInfo.inv_count] = (char)this->invasionEventContent.crusaderArabian + 2; - _sliderIndex = 0; - do { - _sliderValue = this->invasionEventContent.unitCountsPerUnitType[_sliderIndex]; - if (!_sliderValue) - goto LAB_004c16b3; - _unitTypeOther = 0; - _unitType = ((UnitType)0); - iVar3 = 0; - switch (_sliderIndex) { + // 25 sliders over 24 counts: the last one reads invasionPoint, as in the original + for (int slider = 0; slider < 25; slider++) { + int count = this->invasionEventContent.unitCountsPerUnitType[slider]; + if (!count) { + continue; + } + int troopType = 0; + UnitTypeInt unitType = 0; + int divisor = 0; + switch (slider) { case 0: - _unitTypeOther = 3; - _unitType = Map::Units::UT_E_ARCHER; + troopType = 3; + unitType = Map::Units::UT_E_ARCHER; + divisor = 10; break; case 1: - _unitTypeOther = 7; - _unitType = Map::Units::UT_E_XBOW; + troopType = 7; + unitType = Map::Units::UT_E_XBOW; + divisor = 10; break; case 2: - _unitTypeOther = 5; - _unitType = Map::Units::UT_E_SPEAR; + troopType = 5; + unitType = Map::Units::UT_E_SPEAR; + divisor = 10; break; case 3: - _unitTypeOther = 6; - _unitType = Map::Units::UT_E_PIKE; + troopType = 6; + unitType = Map::Units::UT_E_PIKE; + divisor = 10; break; case 4: - _unitTypeOther = 9; - _unitType = Map::Units::UT_E_MACE; + troopType = 9; + unitType = Map::Units::UT_E_MACE; + divisor = 10; break; case 5: - _unitTypeOther = 8; - _unitType = Map::Units::UT_E_SWORD; + troopType = 8; + unitType = Map::Units::UT_E_SWORD; + divisor = 10; break; case 6: - _unitTypeOther = 10; - _unitType = Map::Units::UT_E_KNIGHT; - iVar3 = 10; - goto switchD_004c146e_caseD_18; + troopType = 10; + unitType = Map::Units::UT_E_KNIGHT; + divisor = 10; + break; case 7: - _unitTypeOther = 4; - _unitType = Map::Units::UT_E_LADDER; + troopType = 4; + unitType = Map::Units::UT_E_LADDER; + divisor = 10; break; case 8: - _unitTypeOther = 0xb; - _unitType = Map::Units::UT_E_ENGINEER; + troopType = 0xb; + unitType = Map::Units::UT_E_ENGINEER; + divisor = 10; break; case 9: - _unitTypeOther = 0x16; - _unitType = Map::Units::UT_S_CATAPULT; + troopType = 0x16; + unitType = Map::Units::UT_S_CATAPULT; + divisor = 10; break; case 10: - _unitTypeOther = 0x17; - _unitType = Map::Units::UT_S_TREBUCHET; + troopType = 0x17; + unitType = Map::Units::UT_S_TREBUCHET; + divisor = 10; break; case 0xb: - _unitTypeOther = 0x13; - _unitType = Map::Units::UT_S_BATTERINGRAM; + troopType = 0x13; + unitType = Map::Units::UT_S_BATTERINGRAM; + divisor = 10; break; case 0xc: - _unitTypeOther = 0x14; - _unitType = Map::Units::UT_S_TOWER; + troopType = 0x14; + unitType = Map::Units::UT_S_TOWER; + divisor = 10; break; case 0xd: - _unitTypeOther = 0x15; - _unitType = Map::Units::UT_S_SHIELD; + troopType = 0x15; + unitType = Map::Units::UT_S_SHIELD; + divisor = 10; break; case 0xe: - _unitTypeOther = 0xc; - _unitType = Map::Units::UT_E_MONK; + troopType = 0xc; + unitType = Map::Units::UT_E_MONK; + divisor = 10; break; case 0xf: - _unitTypeOther = 2; - _unitType = Map::Units::UT_TUNNELER; + troopType = 2; + unitType = Map::Units::UT_TUNNELER; + divisor = 10; break; case 0x10: - _unitTypeOther = 0x19; - _unitType = Map::Units::UT_A_ARCHER; + troopType = 0x19; + unitType = Map::Units::UT_A_ARCHER; + divisor = 10; break; case 0x11: - _unitTypeOther = 0x1a; - _unitType = Map::Units::UT_A_SLAVE; + troopType = 0x1a; + unitType = Map::Units::UT_A_SLAVE; + divisor = 10; break; case 0x12: - _unitTypeOther = 0x1b; - _unitType = Map::Units::UT_A_SLINGER; + troopType = 0x1b; + unitType = Map::Units::UT_A_SLINGER; + divisor = 10; break; case 0x13: - _unitTypeOther = 0x1c; - _unitType = Map::Units::UT_A_ASSASSIN; + troopType = 0x1c; + unitType = Map::Units::UT_A_ASSASSIN; + divisor = 10; break; case 0x14: - _unitTypeOther = 0x1d; - _unitType = Map::Units::UT_A_HARCHER; + troopType = 0x1d; + unitType = Map::Units::UT_A_HARCHER; + divisor = 10; break; case 0x15: - _unitTypeOther = 0x1e; - _unitType = Map::Units::UT_A_SWORDSMAN; + troopType = 0x1e; + unitType = Map::Units::UT_A_SWORDSMAN; + divisor = 10; break; case 0x16: - _unitTypeOther = 0x1f; - _unitType = Map::Units::UT_A_FIRETHROWER; + troopType = 0x1f; + unitType = Map::Units::UT_A_FIRETHROWER; + divisor = 10; break; case 0x17: - _unitTypeOther = 0x18; - _unitType = Map::Units::UT_S_FBALLISTA; + troopType = 0x18; + unitType = Map::Units::UT_S_FBALLISTA; + divisor = 10; break; - default: - goto switchD_004c146e_caseD_18; } - /* - if a siege engine... - */ - iVar3 = 10; - switchD_004c146e_caseD_18: - cVar4 = (char)_sliderValue; - if (_unitTypeOther == 0x16) { - pabVar1 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - + DAT_TroopValueState::instance.attackInfo.inv_count; - (*pabVar1)[0] = (*pabVar1)[0] + cVar4; - } else if (_unitTypeOther == 0x17) { - pbVar2 = DAT_TroopValueState::instance.attackInfo - .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count] - + 1; - *pbVar2 = *pbVar2 + cVar4; - } else if (_unitTypeOther == 0x13) { - pbVar2 = DAT_TroopValueState::instance.attackInfo - .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count] - + 2; - *pbVar2 = *pbVar2 + cVar4; - } else if (_unitTypeOther == 0x14) { - pbVar2 = DAT_TroopValueState::instance.attackInfo - .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count] - + 3; - *pbVar2 = *pbVar2 + cVar4; - } else if (_unitTypeOther == 0x15) { - pbVar2 = DAT_TroopValueState::instance.attackInfo - .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count] - + 4; - *pbVar2 = *pbVar2 + cVar4; - } else if (_unitTypeOther == 0x18) { - pbVar2 = DAT_TroopValueState::instance.attackInfo - .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count] - + 8; - *pbVar2 = *pbVar2 + cVar4; + // siege engines are only counted + if (troopType == 0x16) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][0] += count; + } else if (troopType == 0x17) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][1] += count; + } else if (troopType == 0x13) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][2] += count; + } else if (troopType == 0x14) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][3] += count; + } else if (troopType == 0x15) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][4] += count; + } else if (troopType == 0x18) { + DAT_TroopValueState::instance.attackInfo + .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][8] += count; } else { - /* - if not a siege engine... - */ - _unitCount = _sliderValue / (_sliderValue / iVar3 + 1); - while (0 < _sliderValue) { - if (_sliderValue < _unitCount) { - _unitCount = _sliderValue; + // split the troops into groups of about a tenth, one per map edge signpost in turn + int perTribe = count / (count / divisor + 1); + while (count > 0) { + if (perTribe > count) { + perTribe = count; } - iVar3 = DAT_TroopValueState::instance.attackInfo - .unknownSignpostRelatedArray[DAT_TroopValueState::instance.attackInfo.inv_count]; - MACRO_CALL_MEMBER(Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, DAT_TribesState::ptr)( - local_c, _unitTypeOther, DAT_GameState::instance.mapAndTime.signpostsMapEdge[iVar3][local_10].x, - DAT_GameState::instance.mapAndTime.signpostsMapEdge[iVar3][local_10].y, - this->invasionEventContent.crusaderArabian + 2, (UnitType)((int)(_unitType)), ((UnitType)0), - _unitCount, 0); - local_c = local_c + 1; - local_10 = local_10 + 1; - _sliderValue = _sliderValue - _unitCount; - if (DAT_GameState::instance.mapAndTime.signpostsMapEdgeDataCounter <= local_10) { - local_10 = 0; - } - } - } - LAB_004c16b3: - _sliderIndex = _sliderIndex + 1; - if (0x18 < _sliderIndex) { - if (!this->invasionEventContent.crusaderArabian) { - eventWavFile = "infidel_attack.wav"; - eventVideoBik = "sultan_nervous.bik"; - } else { - if (this->invasionEventContent.crusaderArabian != 1) { - this->eventsCount = 0; + int const signpost + = DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray[DAT_TroopValueState::instance.attackInfo.inv_count]; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, DAT_TribesState::ptr)(tribe, + troopType, DAT_GameState::instance.mapAndTime.signpostsMapEdge[signpost][edge].x, + DAT_GameState::instance.mapAndTime.signpostsMapEdge[signpost][edge].y, + this->invasionEventContent.crusaderArabian + 2, (UnitType)unitType, (UnitType)0, perTribe, 0); + tribe = tribe + 1; + edge = edge + 1; + count = count - perTribe; + if (edge >= DAT_GameState::instance.mapAndTime.signpostsMapEdgeDataCounter) { + edge = 0; } - eventWavFile = "arabian_attack.wav"; - eventVideoBik = "good_soldier_nervous.bik"; } - MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( - "", eventVideoBik, eventWavFile); - this->eventsCount = 0; } - } while (true); + } + switch (this->invasionEventContent.crusaderArabian) { + case 0: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( + "", "sultan_nervous.bik", "infidel_attack.wav"); + break; + case 1: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( + "", "good_soldier_nervous.bik", "arabian_attack.wav"); + break; + } + this->eventsCount = 0; } - } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c6289efaf0..3479807788 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33195,7 +33195,7 @@ SHC_3BB0A8C1_0x004C1370 | 0.0% | Pending SHC_3BB0A8C1_0x004C1390 | 0.0% | Pending -SHC_3BB0A8C1_0x004C13F0 | 48.1% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004C13F0 | 47.7% | our compiler threads the switch arms past the siege compare chain SHC_3BB0A8C1_0x004C1708 | 0.0% | Pending From a8d97ee98887d338d2097ada3ee1b67a4ae44e98 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 05:18:13 +0100 Subject: [PATCH 10/60] Map: rewrite loadMap from the original 43.3 -> 77.6, plus a behaviour fix. - Ghidra's `missionNumber1to20 - 4294967280 < 5` is an unsigned literal, so it computed x + 16 and missions 16-20 never called adjustEventMonthAndYearForSection1047. The original tests `x - 16 <= 4`. - The original has a /GS cookie. The two mapAndTime fields at 0xf0/0xf4, saved side by side right under it, are kept as an 8-byte char buffer, which gives the cookie and the 0x34 frame. - The events-extra zeroing is a for loop (rep stosd); memset of 32000 bytes became a call. - The mission 1 unit loop names each field through units[i]; a Unit& reference unrolled it three times. - Recruitability and producibility are read from the global DAT_MapPropertiesState instance, as the original does. - The euroRecruitableCopy flags are all zeroed, then set per recruitable unit, matching the original's stores. - The restore order of sword/pike and jester/lady puts every saved value in the original's stack slot. Load scheduling in the prologue is what is left. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/MapPropertiesState/loadMap.cpp | 260 ++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 112 insertions(+), 150 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp index a3e8dc8673..367d7354d5 100644 --- a/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp @@ -26,6 +26,7 @@ #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" #include "OpenSHC/Globals/DAT_MapDefinedData.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" #include "OpenSHC/Globals/DAT_ResourceManager.hpp" #include "OpenSHC/Globals/DAT_SoundSystemState.hpp" #include "OpenSHC/Globals/DAT_TileMapState.hpp" @@ -34,7 +35,6 @@ #include "OpenSHC/Globals/DAT_UnitsState.hpp" #include "OpenSHC/Globals/DAT_VideoBikQueue.hpp" #include "OpenSHC/Globals/FilePackagerObj.hpp" -#include "OpenSHC/Globals/MSVC_SecurityCookie.hpp" #include "OpenSHC/Globals/TIME_ReceivedMessage_2.hpp" namespace OpenSHC { @@ -52,200 +52,163 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004C62C0 void MapPropertiesState::loadMap(char* mapName) { - char cVar1; - GameMode2Int GVar2; - UnitTypeShort* pUVar3; - int* piVar4; - SiegeUnitCounts* pSVar5; - int iVar6; - int* piVar7; - SiegeUnitCounts* pSVar8; - int* pIVar9; - int local_34; - int local_30; - int local_2c; - int local_28; - int local_24; - int local_20; - int local_1c; - int local_18; - int local_14; - int local_10; - int local_c; - int local_8; - uint local_4; - GVar2 = DAT_GameCore::instance.gameMode_2; - iVar6 = DAT_GameCore::instance.missionNumber1to20; - local_4 = MSVC_SecurityCookie::instance ^ (uint)&local_34; - local_14 = DAT_GameSynchronyState::instance.currentPlayerSlotID; - local_30 = DAT_GameState::instance.mapAndTime.difficulty; - local_10 = DAT_GameCore::instance.xbowProducible_logic; - local_18 = DAT_GameCore::instance.swordProducible_logic; - local_28 = DAT_GameCore::instance.pikeProducible_logic; - local_20 = DAT_GameCore::instance.bowProducible_logic; - local_24 = (int)DAT_GameState::instance.mapAndTime.unitJesterRelated; - local_2c = DAT_GameCore::instance.maceProducible_logic; - local_34 = DAT_GameCore::instance.spearProducible_logic; - local_1c = (int)DAT_GameState::instance.mapAndTime.unitLadyRelated; - local_c = DAT_GameState::instance.mapAndTime.field43_0xf0; - local_8 = DAT_GameState::instance.mapAndTime.field44_0xf4; + // reading the map overwrites these, so they are kept across it + GameMode2Int const gameMode = DAT_GameCore::instance.gameMode_2; + int const missionNumber = DAT_GameCore::instance.missionNumber1to20; + int const playerSlotID = DAT_GameSynchronyState::instance.currentPlayerSlotID; + int const difficulty = DAT_GameState::instance.mapAndTime.difficulty; + int const xbowProducible = DAT_GameCore::instance.xbowProducible_logic; + int const swordProducible = DAT_GameCore::instance.swordProducible_logic; + int const pikeProducible = DAT_GameCore::instance.pikeProducible_logic; + int const bowProducible = DAT_GameCore::instance.bowProducible_logic; + int const jester = DAT_GameState::instance.mapAndTime.unitJesterRelated; + int const maceProducible = DAT_GameCore::instance.maceProducible_logic; + int const spearProducible = DAT_GameCore::instance.spearProducible_logic; + int const lady = DAT_GameState::instance.mapAndTime.unitLadyRelated; + // a byte buffer: the original has a security cookie, and these two sit right under it + char savedFields[8]; + memcpy(savedFields, &DAT_GameState::instance.mapAndTime.field43_0xf0, sizeof(savedFields)); MACRO_CALL_MEMBER(Game::GameStateStructures_Func::resetTeams, DAT_GameState::ptr)(); MACRO_CALL_MEMBER(Map::TileMapState_Func::setupAllMapSections, DAT_TileMapState::ptr)(); MACRO_CALL_MEMBER(IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)( - IO::FRT_MAPS, (char const*)((int)(mapName))); + IO::FRT_MAPS, mapName); MACRO_CALL_MEMBER(IO::FilePackager_Func::readMapOrSavFile, FilePackagerObj::ptr)( DAT_MapDefinedData::instance.MapSectionAddressArray); MACRO_CALL_MEMBER(Audio::MSS::SoundSystem_Func::mapLoadingAndLaunchGameRelated1, DAT_SoundSystemState::ptr)(); - DAT_GameState::instance.mapAndTime.difficulty = local_30; - DAT_GameCore::instance.xbowProducible_logic = local_10; - DAT_GameCore::instance.pikeProducible_logic = local_28; - DAT_GameCore::instance.swordProducible_logic = local_18; - DAT_GameCore::instance.bowProducible_logic = local_20; + DAT_GameState::instance.mapAndTime.difficulty = difficulty; + DAT_GameCore::instance.xbowProducible_logic = xbowProducible; + DAT_GameCore::instance.swordProducible_logic = swordProducible; + DAT_GameCore::instance.pikeProducible_logic = pikeProducible; + DAT_GameCore::instance.bowProducible_logic = bowProducible; DAT_GameCore::instance.mapTimeInTicks = 1; DAT_GameCore::instance.section1127 = 1; - DAT_GameCore::instance.spearProducible_logic = local_34; - DAT_GameCore::instance.maceProducible_logic = local_2c; - DAT_GameCore::instance.missionNumber1to20 = iVar6; - DAT_GameCore::instance.gameMode_2 = GVar2; - if (iVar6 == 1) { - iVar6 = 8; - pUVar3 = &DAT_UnitsState::instance.units[1].unitType; - do { - if (((pUVar3[-1] != Map::Units::ULS_INVISIBLE) && (*pUVar3 == Map::Units::UT_E_ARCHER)) - && (pUVar3[4] == 1)) { - iVar6 = iVar6 + -1; - *(int*)(pUVar3 + -0x3f) = 3; - if (!iVar6) + DAT_GameCore::instance.spearProducible_logic = spearProducible; + DAT_GameCore::instance.maceProducible_logic = maceProducible; + DAT_GameCore::instance.missionNumber1to20 = missionNumber; + DAT_GameCore::instance.gameMode_2 = gameMode; + if (missionNumber == 1) { + // the first mission hands up to eight of the player's archers to player 3 + int left = 8; + for (int i = 1; i < 2500; i++) { + if (DAT_UnitsState::instance.units[i].logicalState != Map::Units::ULS_INVISIBLE + && DAT_UnitsState::instance.units[i].unitType == Map::Units::UT_E_ARCHER + && DAT_UnitsState::instance.units[i].owner == 1) { + left = left - 1; + DAT_UnitsState::instance.units[i].calculatedOwnerPlayerIndex = 3; + if (left == 0) { break; + } } - pUVar3 = pUVar3 + 0x248; - } while ((int)pUVar3 < 0x165141a); + } + } + DAT_GameState::instance.mapAndTime.unitLadyRelated = (short)lady; + for (int i = 0; i < 9; i++) { + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[i] = -1; + } + DAT_GameState::instance.mapAndTime.unitJesterRelated = (short)jester; + DAT_GameSynchronyState::instance.currentPlayerSlotID = playerSlotID; + memcpy(&DAT_GameState::instance.mapAndTime.field43_0xf0, savedFields, sizeof(savedFields)); + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerSlotID] = 1; + for (int i = 1; i < 9; i++) { + DAT_GameState::instance.playerDataArray[i].tacticalPowersBarLevel = 0; } - DAT_GameState::instance.mapAndTime.unitLadyRelated = (short)local_1c; - DAT_GameSynchronyState::instance.currentPlayerFullIDArray[0] = -1; - DAT_GameSynchronyState::instance.currentPlayerFullIDArray[1] = -1; - DAT_GameSynchronyState::instance.currentPlayerFullIDArray[2] = -1; - DAT_GameSynchronyState::instance.currentPlayerFullIDArray[3] = -1; - DAT_GameSynchronyState::instance.currentPlayerFullIDArray[4] = -1; - DAT_GameSynchronyState::instance.currentPlayerFullIDArray[5] = -1; - DAT_GameSynchronyState::instance.currentPlayerFullIDArray[6] = -1; - DAT_GameSynchronyState::instance.currentPlayerFullIDArray[7] = -1; - DAT_GameSynchronyState::instance.currentPlayerFullIDArray[8] = -1; - DAT_GameState::instance.mapAndTime.unitJesterRelated = (short)local_24; - DAT_GameSynchronyState::instance.currentPlayerSlotID = local_14; - DAT_GameState::instance.mapAndTime.field44_0xf4 = local_8; - DAT_GameSynchronyState::instance.currentPlayerFullIDArray[local_14] = 1; - DAT_GameState::instance.mapAndTime.field43_0xf0 = local_c; - DAT_GameState::instance.playerDataArray[1].tacticalPowersBarLevel = 0; - DAT_GameState::instance.playerDataArray[2].tacticalPowersBarLevel = 0; - DAT_GameState::instance.playerDataArray[3].tacticalPowersBarLevel = 0; - DAT_GameState::instance.playerDataArray[4].tacticalPowersBarLevel = 0; - DAT_GameState::instance.playerDataArray[5].tacticalPowersBarLevel = 0; - DAT_GameState::instance.playerDataArray[6].tacticalPowersBarLevel = 0; - DAT_GameState::instance.playerDataArray[7].tacticalPowersBarLevel = 0; - DAT_GameState::instance.playerDataArray[8].tacticalPowersBarLevel = 0; DAT_GameCore::instance.isTimeHalted = FALSE; DAT_GameCore::instance.section1095 = 0; - iVar6 = (int)this - (int)mapName; - do { - cVar1 = *mapName; - mapName[iVar6] = cVar1; - mapName = mapName + 1; - } while (cVar1 != '\0'); + strcpy((char*)this->SEC_Section1089, mapName); if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { MACRO_CALL_MEMBER(Game::GameCore_Func::removeJesterAndLadyUnitsInCertainMissions, DAT_GameCore::ptr)(); } else if (DAT_GameCore::instance.gameMode_2 == Game::GM_ECONOMIC_CAMPAIGN_SH1) { MACRO_CALL_MEMBER(Game::GameCore_Func::removeLadyAndJester, DAT_GameCore::ptr)(); } - pIVar9 = this->SEC_EventsExtra[0].conditionIsTrue; - for (iVar6 = 8000; iVar6 != 0; iVar6 = iVar6 + -1) { - *pIVar9 = 0; - pIVar9 = pIVar9 + 1; + int* const eventsExtra = (int*)this->SEC_EventsExtra; + for (int i = 0; i < 8000; i++) { + eventsExtra[i] = 0; } DAT_GameState::instance.mapAndTime.month = this->SEC_StartingMonth; DAT_GameState::instance.mapAndTime.year = this->SEC_StartingYear; - if (DAT_GameCore::instance.missionNumber1to20 - 4294967280 < 5) { + if (DAT_GameCore::instance.missionNumber1to20 >= 16 && DAT_GameCore::instance.missionNumber1to20 <= 20) { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::adjustEventMonthAndYearForSection1047, this)(); } - if ((DAT_GameState::instance.mapAndTime.month == this->SEC_StartingMonth) - && (DAT_GameState::instance.mapAndTime.year == this->SEC_StartingYear)) { - piVar4 = DAT_GameState::instance.mapAndTime.startGoods; - piVar7 = this->SEC_StartingResources; - do { - *piVar4 = *piVar7; - piVar4 = piVar4 + 1; - piVar7 = piVar7 + 1; - } while ((int)piVar4 < 0x117ce50); + // the start goods only apply when the events left the start date alone + if (DAT_GameState::instance.mapAndTime.month == this->SEC_StartingMonth + && DAT_GameState::instance.mapAndTime.year == this->SEC_StartingYear) { + for (int i = 0; i < 25; i++) { + DAT_GameState::instance.mapAndTime.startGoods[i] = this->SEC_StartingResources[i]; + } DAT_GameState::instance.mapAndTime.startGoods[7] = DAT_GameState::instance.mapAndTime.startGoods[8]; DAT_GameState::instance.mapAndTime.startGoods[8] = 0; - pSVar5 = &DAT_GameState::instance.mapAndTime.siegeInformation; - pSVar8 = (SiegeUnitCounts*)this->SEC_SiegeInformation; - do { - pSVar5->archers = pSVar8->archers; - pSVar5 = (SiegeUnitCounts*)&pSVar5->crossbowmen; - pSVar8 = (SiegeUnitCounts*)&pSVar8->crossbowmen; - } while ((int)pSVar5 < 0x117cea0); + int* const siegeInformation = (int*)&DAT_GameState::instance.mapAndTime.siegeInformation; + for (int i = 0; i < 20; i++) { + siegeInformation[i] = this->SEC_SiegeInformation[i]; + } DAT_GameState::instance.mapAndTime.startingPopularity = this->SEC_StartingPopularity * 10; MACRO_CALL_MEMBER(Game::GameStateStructures_Func::setMonthAndYear, DAT_GameState::ptr)( this->SEC_StartingMonth, this->SEC_StartingYear); } this->SEC_Section1080 = 0; - this->SEC_Section1081 = 0; + this->SEC_Section1081 = FALSE; MACRO_CALL_MEMBER(Map::Units::TribesState_Func::countDeerEfficiently, DAT_TribesState::ptr)(); MACRO_CALL_MEMBER(Map::TileMapState_Func::prepareMap, DAT_TileMapState::ptr)(); MACRO_CALL_MEMBER(Game::GameStateStructures_Func::clearEnemyRelatedStructures, DAT_GameState::ptr)(); DAT_UnitsState::instance.lastSelectedUnitID = 0; MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::deselectAllUnitsOneByOne, DAT_UnitsState::ptr)(); MACRO_CALL_MEMBER(Map::Units::UnitsState_Func::clearSelectionCountsAndPlayerIDs, DAT_UnitsState::ptr)(); + // the original reads the global instance here rather than this DAT_GameState::instance.mapAndTime.euroRecruitable[4] - = (int)this->barracksRecruitability.recruitability.macemen; + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.macemen; DAT_GameState::instance.mapAndTime.euroRecruitable[5] - = (int)this->barracksRecruitability.recruitability.swordsmen; + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.swordsmen; DAT_GameState::instance.mapAndTime.euroRecruitable[6] - = (int)this->barracksRecruitability.recruitability.knights; - DAT_GameState::instance.mapAndTime.mercRecruitable[0] = (int)this->SEC_MercRecruitable[0]; + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.knights; + DAT_GameState::instance.mapAndTime.mercRecruitable[0] = DAT_MapPropertiesState::instance.SEC_MercRecruitable[0]; DAT_GameState::instance.mapAndTime.euroRecruitable[0] - = (int)this->barracksRecruitability.recruitability.archers; + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.archers; DAT_GameState::instance.mapAndTime.euroRecruitable[1] - = (int)this->barracksRecruitability.recruitability.crossbowmen; + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.crossbowmen; DAT_GameState::instance.mapAndTime.euroRecruitable[2] - = (int)this->barracksRecruitability.recruitability.spearmen; + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.spearmen; DAT_GameState::instance.mapAndTime.euroRecruitable[3] - = (int)this->barracksRecruitability.recruitability.pikemen; - DAT_GameState::instance.mapAndTime.mercRecruitable[1] = (int)this->SEC_MercRecruitable[1]; - DAT_GameState::instance.mapAndTime.mercRecruitable[2] = (int)this->SEC_MercRecruitable[2]; - DAT_GameState::instance.mapAndTime.mercRecruitable[3] = (int)this->SEC_MercRecruitable[3]; - DAT_GameState::instance.mapAndTime.mercRecruitable[4] = (int)this->SEC_MercRecruitable[4]; - DAT_GameState::instance.mapAndTime.mercRecruitable[5] = (int)this->SEC_MercRecruitable[5]; - DAT_GameState::instance.mapAndTime.mercRecruitable[6] = (int)this->SEC_MercRecruitable[6]; - DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_0 - = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[0] != 0); - DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_a - = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[1] != 0); - DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_b - = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[1] != 0); - DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_2 - = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[2] != 0); - DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b - = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[3] != 0); - DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_b - = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[3] != 0); + = DAT_MapPropertiesState::instance.barracksRecruitability.recruitability.pikemen; + for (int i = 1; i < 7; i++) { + DAT_GameState::instance.mapAndTime.mercRecruitable[i] + = DAT_MapPropertiesState::instance.SEC_MercRecruitable[i]; + } + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_0 = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_b = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_2 = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_b = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_4 = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_a = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_a = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b = 0; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_c = 0; + if (DAT_GameState::instance.mapAndTime.euroRecruitable[0] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_0 = 1; + } + if (DAT_GameState::instance.mapAndTime.euroRecruitable[1] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_b = 1; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_a = 1; + } + if (DAT_GameState::instance.mapAndTime.euroRecruitable[2] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_2 = 1; + } + if (DAT_GameState::instance.mapAndTime.euroRecruitable[3] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_b = 1; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b = 1; + } if (DAT_GameState::instance.mapAndTime.euroRecruitable[4] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_4 = 1; DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_1_a = 1; } - DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_4 - = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[4] != 0); if (DAT_GameState::instance.mapAndTime.euroRecruitable[5] != 0) { + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_a = 1; DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b = 1; } - DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_a - = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[5] != 0); if (DAT_GameState::instance.mapAndTime.euroRecruitable[6] != 0) { DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_a = 1; DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_3_a_and_6_b = 1; + DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_c = 1; } - DAT_GameState::instance.mapAndTime.euroRecruitableCopy_index_6_c - = (int)(DAT_GameState::instance.mapAndTime.euroRecruitable[6] != 0); DAT_GameState::instance.mapAndTime.countUpTo201 = 0; DAT_GameState::instance.mapAndTime.cathedralRelated1 = 0; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::importTradingCosts, this)(); @@ -253,16 +216,15 @@ namespace Map { MACRO_CALL_MEMBER(AI::AICState_Func::recomputeAIZonerLayer, DAT_AICState::ptr)(); MACRO_CALL_MEMBER(Map::TileMapState_Func::setSignpostDistanceForCampaignMission, DAT_TileMapState::ptr)(); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playNextStoredBinkVideo, DAT_VideoBikQueue::ptr)(); - DAT_GameCore::instance.xbowProducible_logic = (int)this->SEC_XbowProducible_save; - DAT_GameCore::instance.bowProducible_logic = (int)this->SEC_BowProducible_save; - DAT_GameCore::instance.pikeProducible_logic = (int)this->SEC_PikeProducible_save; - DAT_GameCore::instance.spearProducible_logic = (int)this->SEC_SpearProducible_save; - DAT_GameCore::instance.swordProducible_logic = (int)this->SEC_SwordProducible_save; - DAT_GameCore::instance.maceProducible_logic = (int)this->SEC_MaceProducible_save; + DAT_GameCore::instance.xbowProducible_logic = DAT_MapPropertiesState::instance.SEC_XbowProducible_save; + DAT_GameCore::instance.bowProducible_logic = DAT_MapPropertiesState::instance.SEC_BowProducible_save; + DAT_GameCore::instance.pikeProducible_logic = DAT_MapPropertiesState::instance.SEC_PikeProducible_save; + DAT_GameCore::instance.spearProducible_logic = DAT_MapPropertiesState::instance.SEC_SpearProducible_save; + DAT_GameCore::instance.swordProducible_logic = DAT_MapPropertiesState::instance.SEC_SwordProducible_save; + DAT_GameCore::instance.maceProducible_logic = DAT_MapPropertiesState::instance.SEC_MaceProducible_save; DAT_GameCore::instance.timeSum_2 = timeGetTime(); DAT_GameCore::instance.gameDuration = 0; TIME_ReceivedMessage_2::instance = 0; - ; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3479807788..dd5a7ddbe3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -34141,7 +34141,7 @@ SHC_3BB0A8C1_0x004C6298 | 0.0% | Pending SHC_3BB0A8C1_0x004C62A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C62C0 | 43.3% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004C62C0 | 77.6% | load scheduling in the save/restore prologue SHC_3BB0A8C1_0x004C6820 | 100.0% | Reimplemented From e04e90ea916314359f52cb3315927c14ac5f7cac Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 05:18:13 +0100 Subject: [PATCH 11/60] Map: rewrite computeMissionCompletionScore from the original 62.4 -> 71.6. The goto chains become a loop over the events: - A timed goal sets the deadline. - Only the last win condition counts: a later one supersedes it. - Each goal condition adds an objective: four goods conditions (6, 17, 5, 7) with the per-good switch, then gold and population. - The Builder-mode test reads SEC_U3_MapType2_1 from the global instance, as the original does. - The unit loops index units[i] directly. What is left: - The event loop's base pointer is anchored at conditions[0].enabled in the original and at ScenarioEventType in ours. - The *5 goods arm shares the default arm's store in the original. A goto into the default arm reproduced that in quick_diff, but reccmp measured it lower (70.7), so it is not used. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../computeMissionCompletionScore.cpp | 390 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 185 insertions(+), 207 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp index 70c7107f49..4fb5a2765f 100644 --- a/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp @@ -8,6 +8,7 @@ #include "OpenSHC/Globals/DAT_GameCore.hpp" #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" #include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" #include "OpenSHC/Globals/DAT_TroopValueState.hpp" #include "OpenSHC/Globals/DAT_UnitsState.hpp" @@ -21,69 +22,52 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004BDE40 void MapPropertiesState::computeMissionCompletionScore() { - bool bVar1; - int* piVar2; - int iVar3; - uint uVar4; - int iVar5; - int iVar6; - char* pcVar7; - short* psVar8; - int local_8; - int local_4; - local_4 = 0; - local_8 = 0; + int deadlineMonth = 0; + int deadlineYear = 0; this->missionScore = 0xffffffff; this->objectiveGoodsCount = 0; - iVar5 = 0; - if (0 < this->eventsCount) { - pcVar7 = (char*)((int)&this->scenarioEvents[0].data + 0xf); - iVar6 = 1; - do { - if (*(int*)(pcVar7 + -0x17) != 3) - goto LAB_004be33e; - if (((*(int*)(pcVar7 + -0xb) == 1) || (*(int*)(pcVar7 + -0xb) == 0x1b)) && (*pcVar7 != '\0')) { - local_4 = *(int*)(pcVar7 + -0x1f); - local_8 = *(int*)(pcVar7 + -0x1b); - } - if ((*(int*)(pcVar7 + -0xb) != 0) && (*(int*)(pcVar7 + -0xb) != 0x1a)) - goto LAB_004be33e; - if (iVar6 < this->eventsCount) { - piVar2 = (int*)(pcVar7 + 0xd9); - iVar5 = iVar6; - do { - if ((piVar2[-3] == 3) && ((*piVar2 == 0 || (*piVar2 == 0x1a)))) - goto LAB_004be33e; - iVar5 = iVar5 + 1; - piVar2 = piVar2 + 0x39; - } while (iVar5 < this->eventsCount); + for (int i = 0; i < this->eventsCount; i++) { + InGameEventUnionVersion const& event = this->scenarioEvents[i]; + // a goal with a time limit sets the deadline + if (event.header.tl_type == 3 + && (event.data.scenario.ScenarioEventType == 1 || event.data.scenario.ScenarioEventType == 0x1b) + && event.data.scenario.conditions[0].enabled) { + deadlineMonth = event.header.month; + deadlineYear = event.header.year; + } + if (event.header.tl_type != 3 + || (event.data.scenario.ScenarioEventType != 0 && event.data.scenario.ScenarioEventType != 0x1a)) { + continue; + } + // only the last win condition counts + bool superseded = false; + for (int later = i + 1; later < this->eventsCount; later++) { + if (this->scenarioEvents[later].header.tl_type == 3 + && (this->scenarioEvents[later].data.scenario.ScenarioEventType == 0 + || this->scenarioEvents[later].data.scenario.ScenarioEventType == 0x1a)) { + superseded = true; + break; } - if (pcVar7[0x18] == '\0') - goto LAB_004bdfd7; - this->objectiveGoodsType[this->objectiveGoodsCount] = (int)pcVar7[0x17]; - iVar5 = this->objectiveGoodsCount; - iVar3 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - (int)*(short*)(pcVar7 + 0x15)); - this->objectiveGoodsSurplus[iVar5] + } + if (superseded) { + continue; + } + if (event.data.scenario.conditions[6].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] = event.data.scenario.conditions[6].subType; + int const index = this->objectiveGoodsCount; + this->objectiveGoodsSurplus[index] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .currentResources[this->objectiveGoodsType[iVar5]] - - iVar3; + .currentResources[this->objectiveGoodsType[index]] + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + event.data.scenario.conditions[6].value); switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { case 2: case 10: - case 0xb: - case 0xc: - case 0xd: - iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; - goto LAB_004bdfb7; - default: - iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; - LAB_004bdfb7: - this->objectiveGoodsScore[this->objectiveGoodsCount] = iVar5; - break; - case 6: + case 11: + case 12: + case 13: this->objectiveGoodsScore[this->objectiveGoodsCount] - = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x14; + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; break; case 0x11: case 0x12: @@ -94,38 +78,37 @@ namespace Map { case 0x17: case 0x18: this->objectiveGoodsScore[this->objectiveGoodsCount] - = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x32; + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 50; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 20; + break; + default: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + break; } - if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } - LAB_004bdfd7: - if (pcVar7[0x44] == '\0') - goto LAB_004be0ae; - this->objectiveGoodsType[this->objectiveGoodsCount] = (int)pcVar7[0x43]; - iVar5 = this->objectiveGoodsCount; - iVar3 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - (int)*(short*)(pcVar7 + 0x41)); - this->objectiveGoodsSurplus[iVar5] + } + if (event.data.scenario.conditions[17].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] = event.data.scenario.conditions[17].subType; + int const index = this->objectiveGoodsCount; + this->objectiveGoodsSurplus[index] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .currentResources[this->objectiveGoodsType[iVar5]] - - iVar3; + .currentResources[this->objectiveGoodsType[index]] + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + event.data.scenario.conditions[17].value); switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { case 2: case 10: - case 0xb: - case 0xc: - case 0xd: - iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; - goto LAB_004be08e; - default: - iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; - LAB_004be08e: - this->objectiveGoodsScore[this->objectiveGoodsCount] = iVar5; - break; - case 6: + case 11: + case 12: + case 13: this->objectiveGoodsScore[this->objectiveGoodsCount] - = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x14; + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; break; case 0x11: case 0x12: @@ -136,38 +119,37 @@ namespace Map { case 0x17: case 0x18: this->objectiveGoodsScore[this->objectiveGoodsCount] - = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x32; + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 50; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 20; + break; + default: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + break; } - if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } - LAB_004be0ae: - if (pcVar7[0x14] == '\0') - goto LAB_004be185; - this->objectiveGoodsType[this->objectiveGoodsCount] = (int)pcVar7[0x13]; - iVar5 = this->objectiveGoodsCount; - iVar3 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - (int)*(short*)(pcVar7 + 0x11)); - this->objectiveGoodsSurplus[iVar5] + } + if (event.data.scenario.conditions[5].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] = event.data.scenario.conditions[5].subType; + int const index = this->objectiveGoodsCount; + this->objectiveGoodsSurplus[index] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .currentResources[this->objectiveGoodsType[iVar5]] - - iVar3; + .currentResources[this->objectiveGoodsType[index]] + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + event.data.scenario.conditions[5].value); switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { case 2: case 10: - case 0xb: - case 0xc: - case 0xd: - iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; - goto LAB_004be165; - default: - iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; - LAB_004be165: - this->objectiveGoodsScore[this->objectiveGoodsCount] = iVar5; - break; - case 6: + case 11: + case 12: + case 13: this->objectiveGoodsScore[this->objectiveGoodsCount] - = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x14; + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; break; case 0x11: case 0x12: @@ -178,38 +160,37 @@ namespace Map { case 0x17: case 0x18: this->objectiveGoodsScore[this->objectiveGoodsCount] - = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x32; + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 50; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 20; + break; + default: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + break; } - if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } - LAB_004be185: - if (pcVar7[0x1c] == '\0') - goto LAB_004be25c; - this->objectiveGoodsType[this->objectiveGoodsCount] = (int)pcVar7[0x1b]; - iVar5 = this->objectiveGoodsCount; - iVar3 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - (int)*(short*)(pcVar7 + 0x19)); - this->objectiveGoodsSurplus[iVar5] + } + if (event.data.scenario.conditions[7].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] = event.data.scenario.conditions[7].subType; + int const index = this->objectiveGoodsCount; + this->objectiveGoodsSurplus[index] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .currentResources[this->objectiveGoodsType[iVar5]] - - iVar3; + .currentResources[this->objectiveGoodsType[index]] + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + event.data.scenario.conditions[7].value); switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { case 2: case 10: - case 0xb: - case 0xc: - case 0xd: - iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; - goto LAB_004be23c; - default: - iVar5 = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; - LAB_004be23c: - this->objectiveGoodsScore[this->objectiveGoodsCount] = iVar5; - break; - case 6: + case 11: + case 12: + case 13: this->objectiveGoodsScore[this->objectiveGoodsCount] - = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x14; + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 5; break; case 0x11: case 0x12: @@ -220,106 +201,103 @@ namespace Map { case 0x17: case 0x18: this->objectiveGoodsScore[this->objectiveGoodsCount] - = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 0x32; + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 50; + break; + case 6: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 20; + break; + default: + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount] * 10; + break; } - if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } - LAB_004be25c: - if (pcVar7[0x10] != '\0') { - this->objectiveGoodsType[this->objectiveGoodsCount] = 0xf; - iVar5 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - (int)*(short*)(pcVar7 + 0xd)); - this->objectiveGoodsSurplus[this->objectiveGoodsCount] - = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .currentResources[0xf] - - iVar5; - this->objectiveGoodsScore[this->objectiveGoodsCount] - = this->objectiveGoodsSurplus[this->objectiveGoodsCount]; - if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { - this->objectiveGoodsCount = this->objectiveGoodsCount + 1; - } + } + if (event.data.scenario.conditions[4].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] = 0xf; + this->objectiveGoodsSurplus[this->objectiveGoodsCount] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentResources[0xf] + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + event.data.scenario.conditions[4].value); + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount]; + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } - if (pcVar7[4] != '\0') { - this->objectiveGoodsType[this->objectiveGoodsCount] = -1; - iVar5 = MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - (int)*(short*)(pcVar7 + 1)); - this->objectiveGoodsSurplus[this->objectiveGoodsCount] - = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .currentPopulation - - iVar5; - this->objectiveGoodsScore[this->objectiveGoodsCount] - = this->objectiveGoodsSurplus[this->objectiveGoodsCount]; - if (0 < this->objectiveGoodsSurplus[this->objectiveGoodsCount]) { - this->objectiveGoodsCount = this->objectiveGoodsCount + 1; - } + } + if (event.data.scenario.conditions[1].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] = -1; + this->objectiveGoodsSurplus[this->objectiveGoodsCount] + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .currentPopulation + - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( + event.data.scenario.conditions[1].value); + this->objectiveGoodsScore[this->objectiveGoodsCount] + = this->objectiveGoodsSurplus[this->objectiveGoodsCount]; + if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { + this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } - LAB_004be33e: - pcVar7 = pcVar7 + 0xe4; - bVar1 = iVar6 < this->eventsCount; - iVar5 = local_8; - iVar6 = iVar6 + 1; - } while (bVar1); + } } - iVar6 = 0; this->monthsRemaining = 0; this->timeBonusScore = 0; - if (iVar5) { - uVar4 = ((iVar5 - DAT_GameState::instance.mapAndTime.year) * 0xc - DAT_GameState::instance.mapAndTime.month) - + local_4; - this->monthsRemaining = uVar4 & ((int)uVar4 < 1) - 1; + if (deadlineYear != 0) { + int const months = (deadlineYear - DAT_GameState::instance.mapAndTime.year) * 12 + - DAT_GameState::instance.mapAndTime.month + deadlineMonth; + this->monthsRemaining = months > 0 ? months : 0; this->timeBonusScore = this->monthsRemaining * 100; } - this->missionScore = DAT_MissionAestheticsDefinedData::instance - .MissionScoreByDifficulty[DAT_GameState::instance.mapAndTime.difficulty] - + this->timeBonusScore; - iVar5 = 0; - if (0 < this->objectiveGoodsCount) { - piVar2 = this->objectiveGoodsScore; - do { - this->missionScore = this->missionScore + *piVar2; - iVar5 = iVar5 + 1; - piVar2 = piVar2 + 1; - } while (iVar5 < this->objectiveGoodsCount); + this->missionScore = this->timeBonusScore; + this->missionScore = this->missionScore + + DAT_MissionAestheticsDefinedData::instance + .MissionScoreByDifficulty[DAT_GameState::instance.mapAndTime.difficulty]; + for (int i = 0; i < this->objectiveGoodsCount; i++) { + this->missionScore = this->missionScore + this->objectiveGoodsScore[i]; } this->troopSurvivalScore = 0; - if ((DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) - || ((DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk && ((int)this->SEC_U3_MapType2_1 < 2)))) { - psVar8 = &DAT_UnitsState::instance.units[1].owner; - iVar5 = DAT_GameSynchronyState::instance.currentPlayerSlotID; - do { - if (((psVar8[-5] != Map::Units::ULS_INVISIBLE) && (*psVar8 == iVar5)) && (psVar8[0x107] != 0)) { - iVar5 = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, - DAT_TroopValueState::ptr)((Map::Units::UnitType)((int)psVar8[-4])); - iVar6 = iVar6 + iVar5; - iVar5 = DAT_GameSynchronyState::instance.currentPlayerSlotID; + // the original reads the global instance here rather than this + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION + || (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk + && (int)DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 < 2)) { + int surviving = 0; + for (int i = 1; i < 2500; i++) { + if (DAT_UnitsState::instance.units[i].logicalState != Map::Units::ULS_INVISIBLE + && DAT_UnitsState::instance.units[i].owner == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_UnitsState::instance.units[i].isSelectable_OR_matchTime != 0) { + surviving = surviving + + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, + DAT_TroopValueState::ptr)((Map::Units::UnitType)DAT_UnitsState::instance.units[i].unitType); } - psVar8 = psVar8 + 0x248; - } while ((int)psVar8 < 0x1651422); - iVar5 = DAT_GameState::instance.playerDataArray[iVar5].weightedLosses; - iVar6 = iVar5 + iVar6; - if (iVar6) { - this->troopLossPercent = (iVar5 * 100) / iVar6; + } + int const lost + = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .weightedLosses; + int const total = lost + surviving; + if (total != 0) { + this->troopLossPercent = lost * 100 / total; this->troopSurvivalScore = (100 - this->troopLossPercent) * 100; this->missionScore = this->missionScore + this->troopSurvivalScore; } } if (DAT_GameCore::instance.mapU4Int1) { - iVar5 = 0; - psVar8 = &DAT_UnitsState::instance.units[1].owner; - do { - if (((psVar8[-5] != Map::Units::ULS_INVISIBLE) && (*psVar8 == 1)) && (psVar8[0x107] != 0)) { - iVar6 = MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, - DAT_TroopValueState::ptr)((Map::Units::UnitType)((int)psVar8[-4])); - iVar5 = iVar5 + iVar6; + int surviving = 0; + for (int i = 1; i < 2500; i++) { + if (DAT_UnitsState::instance.units[i].logicalState != Map::Units::ULS_INVISIBLE + && DAT_UnitsState::instance.units[i].owner == 1 + && DAT_UnitsState::instance.units[i].isSelectable_OR_matchTime != 0) { + surviving = surviving + + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::getValueOfTroopType, + DAT_TroopValueState::ptr)((Map::Units::UnitType)DAT_UnitsState::instance.units[i].unitType); } - psVar8 = psVar8 + 0x248; - } while ((int)psVar8 < 0x1651422); + } + this->enemyTroopValueSurviving = surviving; this->enemyTroopValueLost = DAT_GameState::instance.playerDataArray[2].weightedLosses; - this->enemyTroopValueTotal = DAT_GameState::instance.playerDataArray[2].weightedLosses + iVar5; - this->enemyTroopValueSurviving = iVar5; + this->enemyTroopValueTotal = DAT_GameState::instance.playerDataArray[2].weightedLosses + surviving; } } - } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index dd5a7ddbe3..075acb7f93 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -30257,7 +30257,7 @@ SHC_3BB0A8C1_0x004BD980 | 0.0% | Pending SHC_3BB0A8C1_0x004BDA80 | 0.0% | Pending -SHC_3BB0A8C1_0x004BDE40 | 62.4% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004BDE40 | 71.6% | event base pointer anchor, *5 arm shares the default store SHC_3BB0A8C1_0x004BDE80 | 0.0% | Pending From b843d69ad94f4dce76c0bff056aaa8e5c21ceeb1 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 05:20:01 +0100 Subject: [PATCH 12/60] Skirmish: rewrite SetupSkirmishMode without decompiler artefacts 47.6 -> 51.9. - Pointer walks become indexed loops, and memset, strcpy and the struct fields are named. - The per-player reset loop is bounded with `!=`: a `< 9` bound unrolls it into 27 stores, while the original keeps it a loop. What is left is register choice. The original keeps -1 in ebx for the loop, skirmishRelated1 and the team fill, keeps the mission pointer in esi, and pushes ebp only around the AI loop. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Game/Skirmish/SetupSkirmishMode.cpp | 112 ++++++------------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 40 insertions(+), 74 deletions(-) diff --git a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp index 1afefa6fb4..0a54ead43c 100644 --- a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp +++ b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp @@ -30,114 +30,80 @@ namespace Game { // FUNCTION: STRONGHOLDCRUSADER 0x004C68D0 void Skirmish::SetupSkirmishMode(int skirmishTrailMission) { - char cVar1; - int* piVar2; - char* pcVar3; - int iVar4; - int iVar5; - char (*pacVar6)[250]; - CampaignTrailMission* pCVar7; - int startDateInMonths; - pCVar7 = DAT_SkirmishDefinedData::instance.SkirmishTrailMissions + skirmishTrailMission; + CampaignTrailMission* mission = &DAT_SkirmishDefinedData::instance.SkirmishTrailMissions[skirmishTrailMission]; if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { - pCVar7 = DAT_SkirmishDefinedData::instance.ExtremeTrailMissions + skirmishTrailMission; + mission = &DAT_SkirmishDefinedData::instance.ExtremeTrailMissions[skirmishTrailMission]; } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { - pCVar7 = DAT_SkirmishDefinedData::instance.WarchestTrailMissions + skirmishTrailMission; + mission = &DAT_SkirmishDefinedData::instance.WarchestTrailMissions[skirmishTrailMission]; } MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::setupSkirmishLobby, DAT_GameSynchronyState::ptr)(); DAT_GameSynchronyState::instance.isHost = TRUE; DAT_GameSynchronyState::instance.currentGameMode = Game::GM_SKIRMISH_SINGLE_PLAYER; DAT_GameSynchronyState::instance.DPLAYX_ReceivedPlayerID = 1; DAT_GameCore::instance.gameMode_2 = Game::GM_SKIRMISH_AND_MULTIPLAYER; - MACRO_CALL(OS_Func::_memset)(DAT_GameSynchronyState::instance.DAT_PlayerNames, 0, (size_t)((int)(2250))); - piVar2 = DAT_GameSynchronyState::instance.currentAIArray; - do { - piVar2[-0x1b] = -1; - *piVar2 = 0; - piVar2[9] = -1; - piVar2 = piVar2 + 1; - } while ((int)piVar2 < 0x191dea0); - pcVar3 = MACRO_CALL_MEMBER(Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0); - pacVar6 = DAT_GameSynchronyState::instance.DAT_PlayerNames + 1; - do { - cVar1 = *pcVar3; - (*pacVar6)[0] = cVar1; - pcVar3 = pcVar3 + 1; - pacVar6 = (char (*)[250])(*pacVar6 + 1); - } while (cVar1 != '\0'); + memset(DAT_GameSynchronyState::instance.DAT_PlayerNames, 0, + sizeof(DAT_GameSynchronyState::instance.DAT_PlayerNames)); + for (int i = 0; i != 9; i++) { + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[i] = -1; + DAT_GameSynchronyState::instance.currentAIArray[i] = 0; + DAT_GameSynchronyState::instance.aiVariationArray[i] = -1; + } + strcpy(DAT_GameSynchronyState::instance.DAT_PlayerNames[1], + MACRO_CALL_MEMBER(Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0)); MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( Commands::GCT_ASK_FOR_SLOT_ASSIGNMENT); - DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[0] = 1; - DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[1] = 1; - DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[2] = 1; - DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[3] = 1; - DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[4] = 1; - DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[5] = 1; - DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[6] = 1; - DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[7] = 1; - DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[8] = 1; + for (int i = 0; i < 9; i++) { + DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[i] = 1; + } DAT_GameSynchronyState::instance.skirmishRelated1 = -1; DAT_GameCore::instance.mapU4Int0 = 0; - for (int i = 1; i < pCVar7->numberOfPlayers; i++) { - DAT_GameSynchronyState::instance.currentAIArray[i + 1] = (&pCVar7->player1AI)[i]; + // the trail mission lists the AI of each player in turn; player 1 is the human + for (int i = 1; i < mission->numberOfPlayers; i++) { + DAT_GameSynchronyState::instance.currentAIArray[i + 1] = (&mission->player1AI)[i]; MACRO_CALL(Synchrony_Func::ResetAiVariationArrayValue)(i + 1); } memset(DAT_GameSynchronyState::instance.playerPositionsArray, -10, sizeof(DAT_GameSynchronyState::instance.playerPositionsArray)); - iVar4 = 0; - piVar2 = &pCVar7->position1; - do { - if (*piVar2 != 0) { - DAT_GameSynchronyState::instance.playerPositionsArray[*piVar2 - 1] = (char)iVar4; + for (int i = 0; i < 8; i++) { + if ((&mission->position1)[i] != 0) { + DAT_GameSynchronyState::instance.playerPositionsArray[(&mission->position1)[i] - 1] = (char)i; } - iVar4 = iVar4 + 1; - piVar2 = piVar2 + 1; - } while (iVar4 < 8); - iVar4 = pCVar7->numberOfPlayers; - iVar5 = 0; - piVar2 = &pCVar7->team1; - do { - DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5 + 1] = (byte)*piVar2; - if (iVar5 >= iVar4) { - DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[iVar5 + 1] = 0xff; + } + int const players = mission->numberOfPlayers; + for (int i = 0; i < 8; i++) { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[i + 1] = (char)(&mission->team1)[i]; + if (i >= players) { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[i + 1] = -1; } - iVar5 = iVar5 + 1; - piVar2 = piVar2 + 1; - } while (iVar5 < 8); - pcVar3 = (char*)(pCVar7->mapNameAddress); - iVar4 = 0x1a22f9c - (int)pcVar3; - do { - cVar1 = *pcVar3; - pcVar3[iVar4] = cVar1; - pcVar3 = pcVar3 + 1; - } while (cVar1 != '\0'); - DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance = pCVar7->fairness; - DAT_GameSynchronyState::instance.skirmishGameIntensityType = pCVar7->startLevels; - piVar2 = &pCVar7->aiv1; + } + strcpy(DAT_GameSynchronyState::instance.mapName, (char*)mission->mapNameAddress); + DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance = mission->fairness; + DAT_GameSynchronyState::instance.skirmishGameIntensityType = mission->startLevels; DAT_GameCore::instance.isSkirmishTrail = TRUE; + int startDateInMonths; if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { DAT_GameCore::instance.extremeTrailProgress = skirmishTrailMission; - MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)piVar2); + MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)&mission->aiv1); startDateInMonths = DAT_GameCore::instance.extremeTrailStartDatesInMonths[DAT_GameCore::instance.extremeTrailProgress]; DAT_GameCore::instance.extremeTrailStartDateMonths = startDateInMonths; } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { DAT_GameCore::instance.warchestTrailProgress = skirmishTrailMission; - MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)piVar2); + MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)&mission->aiv1); startDateInMonths = DAT_GameCore::instance.warchestTrailStartDatesInMonths[DAT_GameCore::instance.warchestTrailProgress]; DAT_GameCore::instance.warchestTrailStartDateMonths = startDateInMonths; } else { DAT_GameCore::instance.skirmishTrailProgress = skirmishTrailMission; - MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)piVar2); + MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)&mission->aiv1); startDateInMonths = DAT_GameCore::instance.skirmishTrailStartDateInMonths[DAT_GameCore::instance.skirmishTrailProgress]; DAT_GameCore::instance.skirmishTrailStartDateMonths = startDateInMonths; } - DAT_GameState::instance.mapAndTime.year = startDateInMonths / 0xc; - DAT_GameState::instance.mapAndTime.month = startDateInMonths % 0xc; - DAT_GameSynchronyState::instance.finalResults.tail.tail1.yearStart = startDateInMonths / 0xc; - DAT_GameSynchronyState::instance.finalResults.tail.tail1.monthStart = startDateInMonths % 0xc; + DAT_GameState::instance.mapAndTime.year = startDateInMonths / 12; + DAT_GameState::instance.mapAndTime.month = startDateInMonths % 12; + DAT_GameSynchronyState::instance.finalResults.tail.tail1.yearStart = startDateInMonths / 12; + DAT_GameSynchronyState::instance.finalResults.tail.tail1.monthStart = startDateInMonths % 12; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 075acb7f93..0f7a41f25f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -34147,7 +34147,7 @@ SHC_3BB0A8C1_0x004C6820 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C6880 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C68D0 | 47.6% | idiv by 12, register allocation +SHC_3BB0A8C1_0x004C68D0 | 51.9% | register choice, -1 not hoisted into ebx SHC_3BB0A8C1_0x004C6B20 | 100.0% | Reimplemented From 65d93eeeec504cc44c682c902476b60e17ac33ac Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 05:24:38 +0100 Subject: [PATCH 13/60] Map: adjustEventMonthAndYearForSection1047 to 100% 74.7 -> 100. Moving militaryCampaignStage = 0 to the top lets the compiler schedule the month read, the zero and the mission test as the original does. Found by trying all 120 orders of the five opening stores. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../adjustEventMonthAndYearForSection1047.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp b/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp index ffb88e7682..1dfaddd6b9 100644 --- a/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp @@ -10,8 +10,8 @@ namespace Map { // FUNCTION: STRONGHOLDCRUSADER 0x004BC110 void MapPropertiesState::adjustEventMonthAndYearForSection1047() { - DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month; DAT_GameState::instance.mapAndTime.militaryCampaignStage = 0; + DAT_GameState::instance.mapAndTime.monthCopy = (short)DAT_GameState::instance.mapAndTime.month; DAT_GameState::instance.mapAndTime.field3183_0x27dc = 0; DAT_GameState::instance.mapAndTime.militaryCampaignFlags = 0; DAT_GameState::instance.mapAndTime.yearCopy = (short)DAT_GameState::instance.mapAndTime.year; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 0f7a41f25f..1169b083a0 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -29881,7 +29881,7 @@ SHC_3BB0A8C1_0x004BC100 | 0.0% | Pending SHC_3BB0A8C1_0x004BC104 | 0.0% | Pending -SHC_3BB0A8C1_0x004BC110 | 74.7% | Shared tail in wrong arm +SHC_3BB0A8C1_0x004BC110 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BC1C0 | 100.0% | Pending From 7e91f91457f1cac1d8e38b642c2d660e1b29d8c5 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 12:13:29 +0100 Subject: [PATCH 14/60] Map: spawnInvasionEventAttackWave siege types as a switch The siege engines were tested with an else-if chain, which our compiler jump-threads from the slider switch arms straight to each add. A switch on troopType keeps the arms going through the shared tail as the original does; it now lowers to a jump table where the original has compares, which is what is left. 47.7% -> 91.0%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../spawnInvasionEventAttackWave.cpp | 22 +++++++++++++------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp b/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp index 16d4fa3b59..b6aaef5369 100644 --- a/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/spawnInvasionEventAttackWave.cpp @@ -167,25 +167,32 @@ namespace Map { break; } // siege engines are only counted - if (troopType == 0x16) { + switch (troopType) { + case 0x16: DAT_TroopValueState::instance.attackInfo .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][0] += count; - } else if (troopType == 0x17) { + break; + case 0x17: DAT_TroopValueState::instance.attackInfo .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][1] += count; - } else if (troopType == 0x13) { + break; + case 0x13: DAT_TroopValueState::instance.attackInfo .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][2] += count; - } else if (troopType == 0x14) { + break; + case 0x14: DAT_TroopValueState::instance.attackInfo .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][3] += count; - } else if (troopType == 0x15) { + break; + case 0x15: DAT_TroopValueState::instance.attackInfo .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][4] += count; - } else if (troopType == 0x18) { + break; + case 0x18: DAT_TroopValueState::instance.attackInfo .someSinglePlayerScore[DAT_TroopValueState::instance.attackInfo.inv_count][8] += count; - } else { + break; + default: // split the troops into groups of about a tenth, one per map edge signpost in turn int perTribe = count / (count / divisor + 1); while (count > 0) { @@ -206,6 +213,7 @@ namespace Map { edge = 0; } } + break; } } switch (this->invasionEventContent.crusaderArabian) { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1169b083a0..9c38d0c0ab 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33195,7 +33195,7 @@ SHC_3BB0A8C1_0x004C1370 | 0.0% | Pending SHC_3BB0A8C1_0x004C1390 | 0.0% | Pending -SHC_3BB0A8C1_0x004C13F0 | 47.7% | our compiler threads the switch arms past the siege compare chain +SHC_3BB0A8C1_0x004C13F0 | 91.0% | siege switch is a jump table, the original compares (if-chain gets jump-threaded) SHC_3BB0A8C1_0x004C1708 | 0.0% | Pending From 6306a530f30ff00aed249e5087402c9d81bf4886 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 12:34:04 +0100 Subject: [PATCH 15/60] Map: processSingleplayerEvents control flow from the original - The event type is a switch laid out case 3, case 2, case 1 as the original; the invasion arm was tested first. - The repeat offset is `rng % (months / 4)` with a signed divide as the original's cdq/and 3/sar 2; the unsigned `>> 2` was both wrong for the signed short RNG and the reason our compiler merged the repeat blocks. - Return early outside solitary games so the campaign update is a tail jump, and scope the spawn-location out-params to the lion case: an address-taken function-scope local disabled every tail call. - The playerDeathRelated != 0 (win/lose) arm comes first, as laid out. 26.9% -> 47.4%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 1250 ++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 615 insertions(+), 637 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 9f0ec19504..b5cb9ae89a 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -134,8 +134,6 @@ namespace Map { int _spawnUnitCount; int local_88; int local_80; - uint uStack_7c; - uint uStack_78; int _previousScenarioEventIndex; int local_70[10]; int local_48[18]; @@ -150,431 +148,224 @@ namespace Map { local_88 = 0; local_70[9] = DAT_GameState::instance.mapAndTime.signpostsMapEdgeDataCounter; _previousScenarioEventIndex = -1; - if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) { - if ((DAT_GameCore::instance.gameMode_2 != Game::GM_EDITOR) - && (DAT_GameCore::instance.gameMode_2 != Game::GM_SIEGE_THAT)) { - if (DAT_GameCore::instance.gameMode_2 == Game::GM_CRUSADER_TUTORIAL) { - MACRO_CALL(UI::Helpers_Func::UpdateTutorialStepAndProgress)(); - } - if (DAT_GameCore::instance.section1095 != 1) { - if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 0) { - if ((this->SEC_Section1081) && (0 < this->SEC_Section1080)) { - this->SEC_Section1080 = this->SEC_Section1080 + -1; - } - if (DAT_GameState::instance.mapAndTime.startOfDay) { - if (DAT_GameCore::instance.unknownAlwaysZero) { - DAT_GameState::instance + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY) { + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::updateMilitaryCampaignMissionState, this)(); + } + return; + } + + if ((DAT_GameCore::instance.gameMode_2 != Game::GM_EDITOR) + && (DAT_GameCore::instance.gameMode_2 != Game::GM_SIEGE_THAT)) { + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CRUSADER_TUTORIAL) { + MACRO_CALL(UI::Helpers_Func::UpdateTutorialStepAndProgress)(); + } + if (DAT_GameCore::instance.section1095 != 1) { + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + != 0) { + if ((DAT_BinkControlState::instance.binkObjPtrArray[1] == (HBINK)0x0) + && (!DAT_VideoBikQueue::instance.storedMessages_0x924)) { + DAT_GameState::instance.mapAndTime.unknownCountdown01 + = DAT_GameState::instance.mapAndTime.unknownCountdown01 + -1; + } + if (!DAT_GameState::instance.mapAndTime.unknownCountdown01) { + DAT_VideoBikQueue::instance.storedMessages_0x924 = 0; + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(UI::Enums::MMT_NONE, FALSE); + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition2::ptr)(UI::Enums::MMT_NONE, FALSE); + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition3::ptr)(UI::Enums::MMT_NONE, FALSE); + DAT_MenuTextInputState::instance.DAT_SomeTextArrayIndex = 9; + MACRO_CALL_MEMBER( + UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, DAT_MenuTextInputState::ptr)(); + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { + if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated = 1; - DAT_GameCore::instance.unknownAlwaysZero = 0; - DAT_GameState::instance.mapAndTime.unknownCountdown01 = 10; + .playerDeathRelated + == 1) { + MACRO_CALL_MEMBER(Game::GameCore_Func::incrementMissionProgress, DAT_GameCore::ptr)(); + DAT_GameCore::instance.section1066 = 2; } - _pConditionIsMet = DAT_GameState::instance.mapAndTime.scenarioEventTimers; - do { - if ((*_pConditionIsMet != 0) - && (iVar18 = *_pConditionIsMet + 1, *_pConditionIsMet = iVar18, 0x4b0 < iVar18)) { - *_pConditionIsMet = 0; + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); + DAT_GameCore::instance.section1066 = 0; + } + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + } + if (DAT_GameCore::instance.gameMode_2 != Game::GM_ECONOMIC_CAMPAIGN_SH1) { + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { + if (DAT_GameCore::instance.field_0x6c) { + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; + MACRO_CALL(UI::MenuItems::General_Func:: + MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(0x16); + MACRO_CALL( + UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); } - _pConditionIsMet = _pConditionIsMet + 1; - } while ((int)_pConditionIsMet < 0x117ee60); - local_48[0] = -1; - local_48[1] = 0xffffffff; - local_48[2] = 0xffffffff; - local_48[3] = 0xffffffff; - local_48[4] = 0xffffffff; - local_48[5] = 0xffffffff; - local_48[6] = 0xffffffff; - local_48[7] = 0xffffffff; - local_48[8] = 0xffffffff; - local_80 = DAT_TroopValueState::instance.attackInfo.inv_count; - local_70[0] = 0; - local_48[9] = 0; - local_70[1] = 0; - local_48[10] = 0; - local_70[2] = 0; - local_48[0xb] = 0; - local_70[3] = 0; - local_48[0xc] = 0; - local_70[4] = 0; - local_48[0xd] = 0; - local_70[5] = 0; - local_48[0xe] = 0; - local_70[6] = 0; - local_48[0xf] = 0; - local_70[7] = 0; - local_48[0x10] = 0; - local_70[8] = 0; - local_48[0x11] = 0; - if ((((DAT_GameState::instance.mapAndTime.month == this->SEC_StartingMonth) - && (DAT_GameState::instance.mapAndTime.year == this->SEC_StartingYear + 1)) - && (DAT_GameState::instance.gameTicksLoadBalancer == 1)) - && ((!DAT_GameState::instance.mapAndTime.week - && (bVar23 = false, 0 < this->eventsCount)))) { - _pConditionIsMet = &this->scenarioEvents[0].data.scenario.ScenarioEventType; - iVar18 = this->eventsCount; - do { - if ((_pConditionIsMet[-3] == 3) && (*_pConditionIsMet == 0x1e)) { - bVar23 = true; - } - _pConditionIsMet = _pConditionIsMet + 0x39; - iVar18 = iVar18 + -1; - } while (iVar18); - if (bVar23) { - /* - if a fire warning event - */ - iVar18 = 0; - if (0 < DAT_BuildingsState::instance.maxBuildingsCount) { - pBVar13 = &DAT_BuildingsState::instance.buildings[0].buildingType; - do { - if (((pBVar13[-1] != ((BuildingLogicalState)0)) - && ((short)pBVar13[2] - == DAT_GameSynchronyState::instance.currentPlayerSlotID)) - && ((*pBVar13 == Map::Buildings::BT_WELL - || (*pBVar13 == Map::Buildings::BT_WATERPOT)))) - goto LAB_004c3637; - iVar18 = iVar18 + 1; - pBVar13 = pBVar13 + 0x196; - } while (iVar18 < DAT_BuildingsState::instance.maxBuildingsCount); + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + if ((int)this->SEC_U3_MapType2_1 < 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); + } else { + DAT_GameCore::instance.section1095 = 1; + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 0x2f; + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, + DAT_MenuTextInputState::ptr)(UI::Enums::MMT_QUIT_DIALOG); } - pcVar27 = "general_message3.wav"; - pcVar25 = "ap_civil12.bik"; - /* - "there are no wells in the castle my liege. should a fire break out, we are int - great danger." added by script: "There are no wells in the castle my Liege. - Should a fire break out we would be in great danger." - */ - pcVar10 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x12); - MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); + } + DAT_GameCore::instance.section1066 = 2; } - LAB_004c3637: - _eventIndex = 0; - if (0 < this->eventsCount) { - do { - iVar18 = this->scenarioEvents[_eventIndex].header.year; - if ((DAT_GameState::instance.mapAndTime.year < iVar18) - || ((DAT_GameState::instance.mapAndTime.year == iVar18 - && (DAT_GameState::instance.mapAndTime.month - < this->scenarioEvents[_eventIndex].header.month)))) - break; - /* - "next Event" - */ - if (this->scenarioEvents[_eventIndex].header.done != 0) - goto LAB_004c5f28; - _eventType = this->scenarioEvents[_eventIndex].header.tl_type; - if (_eventType == 1) { - /* - Invasion - */ - DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 0; - DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .aiControlStatusRelated = -200; - /* - invasion. ? - */ - iVar18 - = local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian]; - if (local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian] - == -1) { - DAT_TroopValueState::instance.attackInfo.inv_count - = DAT_TroopValueState::instance.attackInfo.inv_count + 1; - if (0x31 < DAT_TroopValueState::instance.attackInfo.inv_count) { - DAT_TroopValueState::instance.attackInfo.inv_count = 1; - } - MACRO_CALL_MEMBER( - Map::Units::TroopValueState_Func::initializeAttackWaveSlot, - DAT_TroopValueState::ptr)( - DAT_TroopValueState::instance.attackInfo.inv_count, - this->scenarioEvents[_eventIndex].data.invasion.messageMonth); - local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian] - = DAT_TroopValueState::instance.attackInfo.inv_count; - local_80 = DAT_TroopValueState::instance.attackInfo.inv_count; - iVar18 = DAT_TroopValueState::instance.attackInfo.inv_count; - } - DAT_TroopValueState::instance.attackInfo.inv_count = iVar18; - DAT_TroopValueState::instance.attackInfo - .attackWavePlayerIDArray[DAT_TroopValueState::instance.attackInfo.inv_count] - = *(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x74) + 2; - _subIndex = 0; - do { - /* - if invasion.units[index] == 0 then index += 1 (break when not index < - 0x19) - */ - iVar18 = *( - int*)((int)&this->scenarioEvents[_eventIndex].data + _subIndex * 4 + 4); - if (!iVar18) - goto LAB_004c5db4; - _unitAIBehaviourTypeUnk = 0; - _unitType = ((UnitType)0); - _unitSpawnTotalAdjustment = 0; - switch (_subIndex) { - case 0: - _unitAIBehaviourTypeUnk = 3; - _unitType = Map::Units::UT_E_ARCHER; - break; - case 1: - _unitAIBehaviourTypeUnk = 7; - _unitType = Map::Units::UT_E_XBOW; - break; - case 2: - _unitAIBehaviourTypeUnk = 5; - _unitType = Map::Units::UT_E_SPEAR; - break; - case 3: - _unitAIBehaviourTypeUnk = 6; - _unitType = Map::Units::UT_E_PIKE; - break; - case 4: - _unitAIBehaviourTypeUnk = 9; - _unitType = Map::Units::UT_E_MACE; - break; - case 5: - _unitAIBehaviourTypeUnk = 8; - _unitType = Map::Units::UT_E_SWORD; - break; - case 6: - _unitAIBehaviourTypeUnk = 10; - _unitType = Map::Units::UT_E_KNIGHT; - _unitSpawnTotalAdjustment = 10; - goto switchD_004c5b0c_default; - case 7: - _unitAIBehaviourTypeUnk = 4; - _unitType = Map::Units::UT_E_LADDER; - break; - case 8: - _unitAIBehaviourTypeUnk = 0xb; - _unitType = Map::Units::UT_E_ENGINEER; - break; - case 9: - _unitAIBehaviourTypeUnk = 0x16; - _unitType = Map::Units::UT_S_CATAPULT; - break; - case 10: - _unitAIBehaviourTypeUnk = 0x17; - _unitType = Map::Units::UT_S_TREBUCHET; - break; - case 0xb: - _unitAIBehaviourTypeUnk = 0x13; - _unitType = Map::Units::UT_S_BATTERINGRAM; - break; - case 0xc: - _unitAIBehaviourTypeUnk = 0x14; - _unitType = Map::Units::UT_S_TOWER; - break; - case 0xd: - _unitAIBehaviourTypeUnk = 0x15; - _unitType = Map::Units::UT_S_SHIELD; - break; - case 0xe: - _unitAIBehaviourTypeUnk = 0xc; - _unitType = Map::Units::UT_E_MONK; - break; - case 0xf: - _unitAIBehaviourTypeUnk = 2; - _unitType = Map::Units::UT_TUNNELER; - break; - case 0x10: - _unitAIBehaviourTypeUnk = 0x19; - _unitType = Map::Units::UT_A_ARCHER; - break; - case 0x11: - _unitAIBehaviourTypeUnk = 0x1a; - _unitType = Map::Units::UT_A_SLAVE; - _unitSpawnTotalAdjustment = 0x14; - goto switchD_004c5b0c_default; - case 0x12: - _unitAIBehaviourTypeUnk = 0x1b; - _unitType = Map::Units::UT_A_SLINGER; - _unitSpawnTotalAdjustment = 0x14; - goto switchD_004c5b0c_default; - case 0x13: - _unitAIBehaviourTypeUnk = 0x1c; - _unitType = Map::Units::UT_A_ASSASSIN; - _unitSpawnTotalAdjustment = 2; - goto switchD_004c5b0c_default; - case 0x14: - _unitAIBehaviourTypeUnk = 0x1d; - _unitType = Map::Units::UT_A_HARCHER; - break; - case 0x15: - _unitAIBehaviourTypeUnk = 0x1e; - _unitType = Map::Units::UT_A_SWORDSMAN; - _unitSpawnTotalAdjustment = 8; - goto switchD_004c5b0c_default; - case 0x16: - _unitAIBehaviourTypeUnk = 0x1f; - _unitType = Map::Units::UT_A_FIRETHROWER; - _unitSpawnTotalAdjustment = 4; - goto switchD_004c5b0c_default; - case 0x17: - _unitAIBehaviourTypeUnk = 0x18; - _unitType = Map::Units::UT_S_FBALLISTA; - break; - default: - goto switchD_004c5b0c_default; - } - _unitSpawnTotalAdjustment = 10; - switchD_004c5b0c_default: - _invasionAmplifier = 100; - if (!DAT_GameState::instance.mapAndTime.difficulty) { - _invasionAmplifier = 50; - } else if (DAT_GameState::instance.mapAndTime.difficulty == 2) { - _invasionAmplifier = 140; - } else if (DAT_GameState::instance.mapAndTime.difficulty == 3) { - _invasionAmplifier = 200; - } - _amplifiedUnitTotalForUnitType = (_invasionAmplifier * iVar18) / 100; - cVar17 = (char)_amplifiedUnitTotalForUnitType; - if (_unitAIBehaviourTypeUnk == 0x16) { - pabVar2 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - + DAT_TroopValueState::instance.attackInfo.inv_count; - (*pabVar2)[0] = (*pabVar2)[0] + cVar17; - } else if (_unitAIBehaviourTypeUnk == 0x17) { - pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - [DAT_TroopValueState::instance.attackInfo.inv_count] - + 1; - *pbVar3 = *pbVar3 + cVar17; - } else if (_unitAIBehaviourTypeUnk == 0x13) { - pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - [DAT_TroopValueState::instance.attackInfo.inv_count] - + 2; - *pbVar3 = *pbVar3 + cVar17; - } else if (_unitAIBehaviourTypeUnk == 0x14) { - pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - [DAT_TroopValueState::instance.attackInfo.inv_count] - + 3; - *pbVar3 = *pbVar3 + cVar17; - } else if (_unitAIBehaviourTypeUnk == 0x15) { - pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - [DAT_TroopValueState::instance.attackInfo.inv_count] - + 4; - *pbVar3 = *pbVar3 + cVar17; - } else if (_unitAIBehaviourTypeUnk == 0x18) { - pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - [DAT_TroopValueState::instance.attackInfo.inv_count] - + 8; - *pbVar3 = *pbVar3 + cVar17; - } else { - _spawnUnitCount = _amplifiedUnitTotalForUnitType - / (_amplifiedUnitTotalForUnitType / _unitSpawnTotalAdjustment + 1); - while (0 < _amplifiedUnitTotalForUnitType) { - if (_amplifiedUnitTotalForUnitType < _spawnUnitCount) { - _spawnUnitCount = _amplifiedUnitTotalForUnitType; - } - iVar18 = this->scenarioEvents[_eventIndex] - .data.invasion.crusaderArabian; - iVar22 = local_48[iVar18 + 9]; - local_48[iVar18 + 9] = iVar22 + 1; - iVar21 - = DAT_TroopValueState::instance.attackInfo - .unknownSignpostRelatedArray[DAT_TroopValueState::instance - .attackInfo.inv_count]; - MACRO_CALL_MEMBER( - Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, - DAT_TribesState::ptr)(iVar22, _unitAIBehaviourTypeUnk, - DAT_GameState::instance.mapAndTime - .signpostsMapEdge[iVar21][local_88] - .x, - DAT_GameState::instance.mapAndTime - .signpostsMapEdge[iVar21][local_88] - .y, - iVar18 + 2, (UnitType)((int)(_unitType)), ((UnitType)0), - _spawnUnitCount, 0); - local_88 = local_88 + 1; - _amplifiedUnitTotalForUnitType - = _amplifiedUnitTotalForUnitType - _spawnUnitCount; - if (local_70[9] <= local_88) { - local_88 = 0; - } - } - } - LAB_004c5db4: - _subIndex = _subIndex + 1; - } while (_subIndex < 0x19); - iVar18 = DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray - [DAT_TroopValueState::instance.attackInfo.inv_count]; - MACRO_CALL_MEMBER( - UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)( - DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, - DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); - DAT_TroopValueState::instance.attackInfo.inv_count = local_80; - if ((!DAT_GameCore::instance.section1076) - && (_crusaderOrArabian - = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian, - local_70[_crusaderOrArabian] == 0)) { - local_70[_crusaderOrArabian] = 1; - if (!_crusaderOrArabian) { - pcVar25 = "infidel_attack.wav"; - pcVar10 = "sultan_nervous.bik"; - LAB_004c5e44: - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)("", pcVar10, pcVar25); - } else if (_crusaderOrArabian == 1) { - pcVar25 = "arabian_attack.wav"; - pcVar10 = "good_soldier_nervous.bik"; - goto LAB_004c5e44; - } - if ((DAT_GameCore::instance.currentMenuViewType - == UI::Enums::MVT_BUILD_MENU) - && ((DAT_GameCore::instance.activeMenuTab.tabType - == UI::Enums::BASMTT_SIEGETENT_SIEGETOWER - || (DAT_GameCore::instance.activeMenuTab.tabType - == UI::Enums::BASMTT_SIEGETENT_SHIELD)))) { - MACRO_CALL_MEMBER( - Game::GameCore_Func::swapBuildMenuTab, DAT_GameCore::ptr)(); - if (DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType - == UI::Enums::BASMTT_SIEGETENT_SIEGETOWER) { - if (DAT_GameCore::instance.currentMenuViewType - == UI::Enums::MVT_BUILD_MENU) { - DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType - = UI::Enums::BASMTT_HUNTERSHUT; - } else if (DAT_GameCore::instance.currentMenuViewType - == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { - DAT_GameCore::instance.landscapingmenuMenuTabToSwitchTo - .buildMenuTab = 0xe7; - } - } - MACRO_CALL_MEMBER( - Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - (UI::Enums::MenuViewType)DAT_GameCore::instance.currentMenuViewType, - 0); - } - } - _repeatMonths = this->scenarioEvents[_eventIndex].data.invasion.repeatMonths; - if (!_repeatMonths) { - this->scenarioEvents[_eventIndex].header.done = 1; - } else { - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + _repeatMonths / 0xc; - iVar18 = this->scenarioEvents[_eventIndex].header.year; - this->scenarioEvents[_eventIndex].header.month - = this->scenarioEvents[_eventIndex].header.month + _repeatMonths % 0xc; - iVar22 = this->scenarioEvents[_eventIndex].header.month; - this->scenarioEvents[_eventIndex].header.pre_done = 0; - if (0xb < iVar22) { - this->scenarioEvents[_eventIndex].header.month = iVar22 + -0xc; - this->scenarioEvents[_eventIndex].header.year = iVar18 + 1; - } - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); - _eventIndex = _eventIndex + -1; - } - goto LAB_004c5f28; - } - if (_eventType == 2) { - this->scenarioEvents[_eventIndex].header.done = 1; - goto LAB_004c5f28; - } - if (_eventType != 3) - goto LAB_004c5f28; + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + MACRO_CALL_MEMBER(Game::GameCore_Func::incrementMission, DAT_GameCore::ptr)(); + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); + } + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + } + } else { + if ((this->SEC_Section1081) && (0 < this->SEC_Section1080)) { + this->SEC_Section1080 = this->SEC_Section1080 + -1; + } + if (DAT_GameState::instance.mapAndTime.startOfDay) { + if (DAT_GameCore::instance.unknownAlwaysZero) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated = 1; + DAT_GameCore::instance.unknownAlwaysZero = 0; + DAT_GameState::instance.mapAndTime.unknownCountdown01 = 10; + } + _pConditionIsMet = DAT_GameState::instance.mapAndTime.scenarioEventTimers; + do { + if ((*_pConditionIsMet != 0) + && (iVar18 = *_pConditionIsMet + 1, *_pConditionIsMet = iVar18, 0x4b0 < iVar18)) { + *_pConditionIsMet = 0; + } + _pConditionIsMet = _pConditionIsMet + 1; + } while ((int)_pConditionIsMet < 0x117ee60); + local_48[0] = -1; + local_48[1] = 0xffffffff; + local_48[2] = 0xffffffff; + local_48[3] = 0xffffffff; + local_48[4] = 0xffffffff; + local_48[5] = 0xffffffff; + local_48[6] = 0xffffffff; + local_48[7] = 0xffffffff; + local_48[8] = 0xffffffff; + local_80 = DAT_TroopValueState::instance.attackInfo.inv_count; + local_70[0] = 0; + local_48[9] = 0; + local_70[1] = 0; + local_48[10] = 0; + local_70[2] = 0; + local_48[0xb] = 0; + local_70[3] = 0; + local_48[0xc] = 0; + local_70[4] = 0; + local_48[0xd] = 0; + local_70[5] = 0; + local_48[0xe] = 0; + local_70[6] = 0; + local_48[0xf] = 0; + local_70[7] = 0; + local_48[0x10] = 0; + local_70[8] = 0; + local_48[0x11] = 0; + if ((((DAT_GameState::instance.mapAndTime.month == this->SEC_StartingMonth) + && (DAT_GameState::instance.mapAndTime.year == this->SEC_StartingYear + 1)) + && (DAT_GameState::instance.gameTicksLoadBalancer == 1)) + && (( + !DAT_GameState::instance.mapAndTime.week && (bVar23 = false, 0 < this->eventsCount)))) { + _pConditionIsMet = &this->scenarioEvents[0].data.scenario.ScenarioEventType; + iVar18 = this->eventsCount; + do { + if ((_pConditionIsMet[-3] == 3) && (*_pConditionIsMet == 0x1e)) { + bVar23 = true; + } + _pConditionIsMet = _pConditionIsMet + 0x39; + iVar18 = iVar18 + -1; + } while (iVar18); + if (bVar23) { + /* + if a fire warning event + */ + iVar18 = 0; + if (0 < DAT_BuildingsState::instance.maxBuildingsCount) { + pBVar13 = &DAT_BuildingsState::instance.buildings[0].buildingType; + do { + if (((pBVar13[-1] != ((BuildingLogicalState)0)) + && ((short)pBVar13[2] + == DAT_GameSynchronyState::instance.currentPlayerSlotID)) + && ((*pBVar13 == Map::Buildings::BT_WELL + || (*pBVar13 == Map::Buildings::BT_WATERPOT)))) + goto LAB_004c3637; + iVar18 = iVar18 + 1; + pBVar13 = pBVar13 + 0x196; + } while (iVar18 < DAT_BuildingsState::instance.maxBuildingsCount); + } + pcVar27 = "general_message3.wav"; + pcVar25 = "ap_civil12.bik"; + /* + "there are no wells in the castle my liege. should a fire break out, we are int + great danger." added by script: "There are no wells in the castle my Liege. + Should a fire break out we would be in great danger." + */ + pcVar10 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x12); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); + } + } + LAB_004c3637: + _eventIndex = 0; + if (0 < this->eventsCount) { + do { + iVar18 = this->scenarioEvents[_eventIndex].header.year; + if ((DAT_GameState::instance.mapAndTime.year < iVar18) + || ((DAT_GameState::instance.mapAndTime.year == iVar18 + && (DAT_GameState::instance.mapAndTime.month + < this->scenarioEvents[_eventIndex].header.month)))) + break; + /* + "next Event" + */ + if (this->scenarioEvents[_eventIndex].header.done != 0) + goto LAB_004c5f28; + _eventType = this->scenarioEvents[_eventIndex].header.tl_type; + switch (_eventType) { + case 3: iVar18 = this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType; if ((!iVar18) || (iVar18 == 0x1a)) { if (_previousScenarioEventIndex != -1) { @@ -1399,8 +1190,8 @@ namespace Map { pcVar25 = "Random_Events1.wav"; pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent1VideoName; /* - "a travelling fair has come to town my lord" added by script: "A ‘Travelling - Fair’ has come to town, my Lord." + "a travelling fair has come to town my lord" added by script: "A + ‘Travelling Fair’ has come to town, my Lord." */ pcVar10 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, @@ -1418,8 +1209,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -1536,8 +1326,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -1585,8 +1374,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -1614,8 +1402,8 @@ namespace Map { pcVar25 = "Random_Events4.wav"; pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent4VideoName; /* - added by script: "Our hops plants are overrun with hop weevil, the crop is - ruined, My Liege." + added by script: "Our hops plants are overrun with hop weevil, the + crop is ruined, My Liege." */ pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, @@ -1634,8 +1422,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -1689,8 +1476,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -1711,8 +1497,8 @@ namespace Map { pcVar25 = "Random_Events6.wav"; pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent6VideoName; /* - added by script: "Sire, woodcutters report that the recent drought has killed - off many trees." + added by script: "Sire, woodcutters report that the recent drought has + killed off many trees." */ pcVar10 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, @@ -1730,8 +1516,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -1793,8 +1578,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -1809,7 +1593,9 @@ namespace Map { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; - case 0x11: + case 0x11: { + uint uStack_7c; + uint uStack_78; iVar18 = MACRO_CALL_MEMBER( Map::Units::TribesState_Func::findRecentOrSignpostSpawnLocation, DAT_TribesState::ptr)(&uStack_78, &uStack_7c); @@ -1873,8 +1659,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -1889,6 +1674,7 @@ namespace Map { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; break; + } case 0x12: BVar11 = MACRO_CALL_MEMBER( Game::GameStateStructures_Func::hasAnySignpost, DAT_GameState::ptr)(); @@ -1957,8 +1743,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -1990,8 +1775,8 @@ namespace Map { pcVar27 = "Random_Events10.wav"; pcVar25 = ""; /* - added by script: "Our cows have been struck down by a strange malady, my - lord." + added by script: "Our cows have been struck down by a strange malady, + my lord." */ pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, @@ -2015,8 +1800,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -2138,8 +1922,8 @@ namespace Map { pcVar25 = "Random_Events11.wav"; pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent11VideoName; /* - added by script: "Some outlaws from the woods have returned to our cause, - my lord." + added by script: "Some outlaws from the woods have returned to our + cause, my lord." */ pcVar10 = MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, @@ -2158,8 +1942,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -2207,8 +1990,8 @@ namespace Map { pcVar25 = "Random_Events13.wav"; pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent13VideoName; /* - added by script: "A Jester has arrived at the castle Liege. I have taken the - liberty of offering him employment." + added by script: "A Jester has arrived at the castle Liege. I have taken + the liberty of offering him employment." */ pcVar10 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, @@ -2366,8 +2149,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -2412,8 +2194,8 @@ namespace Map { pcVar25 = "general_warning16.wav"; pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName; /* - added by script: "There is fire in the castle and we have not built any wells - my Liege!" + added by script: "There is fire in the castle and we have not built any + wells my Liege!" */ pcVar10 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, @@ -2431,8 +2213,7 @@ namespace Map { uVar19 = (uint)bVar4; this->scenarioEvents[_eventIndex].header.done = 0; if (3 < uVar19) { - uVar19 - = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 >> 2); + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; @@ -2447,200 +2228,397 @@ namespace Map { MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; } - LAB_004c5f28: - _eventIndex = _eventIndex + 1; - } while (_eventIndex < this->eventsCount); - } - iVar18 = DAT_GameState::instance.mapAndTime.month + 3; - local_88 = DAT_GameState::instance.mapAndTime.year; - if (0xb < iVar18) { - iVar18 = DAT_GameState::instance.mapAndTime.month + -9; - local_88 = DAT_GameState::instance.mapAndTime.year + 1; - } - local_70[0] = 0; - local_70[1] = 0; - local_70[2] = 0; - local_70[3] = 0; - local_70[4] = 0; - local_70[5] = 0; - local_70[6] = 0; - local_70[7] = 0; - local_70[8] = 0; - _eventIndex = 0; - if (0 < this->eventsCount) { - psVar21 = &this->scenarioEvents[0]; - do { - if ((((local_88 == psVar21->header.year) && (iVar18 == psVar21->header.month)) - && ((!psVar21->header.pre_done - && ((iVar22 = psVar21->header.tl_type, psVar21->header.pre_done = 1, - iVar22 == 1 - && (DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 1, - DAT_GameCore::instance.section1076 == 0)))))) - && (iVar22 = (psVar21->data).invasion.crusaderArabian, local_70[iVar22] == 0)) { - iVar20 = 0; - iVar1 = iVar22 * 4; - numInGroup = iVar1 + 1; - iVar21 = 5; - _pConditionIsMet = (psVar21->data).invasion.unitCountsPerUnitType + 3; - do { - iVar20 = iVar20 + _pConditionIsMet[-3] + _pConditionIsMet[-2] - + _pConditionIsMet[-1] + _pConditionIsMet[1] + *_pConditionIsMet; - iVar21 = iVar21 + -1; - _pConditionIsMet = _pConditionIsMet + 5; - } while (iVar21); - if (0x18 < iVar20) { - if (iVar20 < 0x4b) { - numInGroup = iVar1 + 2; - } else if (iVar20 < 0x96) { - numInGroup = iVar1 + 3; - } else { - numInGroup = iVar1 + 4; - } + break; + case 2: + this->scenarioEvents[_eventIndex].header.done = 1; + break; + case 1: + /* + Invasion + */ + DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 0; + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .aiControlStatusRelated = -200; + /* + invasion. ? + */ + iVar18 = local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian]; + if (local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian] + == -1) { + DAT_TroopValueState::instance.attackInfo.inv_count + = DAT_TroopValueState::instance.attackInfo.inv_count + 1; + if (0x31 < DAT_TroopValueState::instance.attackInfo.inv_count) { + DAT_TroopValueState::instance.attackInfo.inv_count = 1; + } + MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackWaveSlot, + DAT_TroopValueState::ptr)( + DAT_TroopValueState::instance.attackInfo.inv_count, + this->scenarioEvents[_eventIndex].data.invasion.messageMonth); + local_48[this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian] + = DAT_TroopValueState::instance.attackInfo.inv_count; + local_80 = DAT_TroopValueState::instance.attackInfo.inv_count; + iVar18 = DAT_TroopValueState::instance.attackInfo.inv_count; + } + DAT_TroopValueState::instance.attackInfo.inv_count = iVar18; + DAT_TroopValueState::instance.attackInfo + .attackWavePlayerIDArray[DAT_TroopValueState::instance.attackInfo.inv_count] + = *(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x74) + 2; + _subIndex = 0; + do { + /* + if invasion.units[index] == 0 then index += 1 (break when not index < + 0x19) + */ + iVar18 + = *(int*)((int)&this->scenarioEvents[_eventIndex].data + _subIndex * 4 + 4); + if (!iVar18) + goto LAB_004c5db4; + _unitAIBehaviourTypeUnk = 0; + _unitType = ((UnitType)0); + _unitSpawnTotalAdjustment = 0; + switch (_subIndex) { + case 0: + _unitAIBehaviourTypeUnk = 3; + _unitType = Map::Units::UT_E_ARCHER; + break; + case 1: + _unitAIBehaviourTypeUnk = 7; + _unitType = Map::Units::UT_E_XBOW; + break; + case 2: + _unitAIBehaviourTypeUnk = 5; + _unitType = Map::Units::UT_E_SPEAR; + break; + case 3: + _unitAIBehaviourTypeUnk = 6; + _unitType = Map::Units::UT_E_PIKE; + break; + case 4: + _unitAIBehaviourTypeUnk = 9; + _unitType = Map::Units::UT_E_MACE; + break; + case 5: + _unitAIBehaviourTypeUnk = 8; + _unitType = Map::Units::UT_E_SWORD; + break; + case 6: + _unitAIBehaviourTypeUnk = 10; + _unitType = Map::Units::UT_E_KNIGHT; + _unitSpawnTotalAdjustment = 10; + goto switchD_004c5b0c_default; + case 7: + _unitAIBehaviourTypeUnk = 4; + _unitType = Map::Units::UT_E_LADDER; + break; + case 8: + _unitAIBehaviourTypeUnk = 0xb; + _unitType = Map::Units::UT_E_ENGINEER; + break; + case 9: + _unitAIBehaviourTypeUnk = 0x16; + _unitType = Map::Units::UT_S_CATAPULT; + break; + case 10: + _unitAIBehaviourTypeUnk = 0x17; + _unitType = Map::Units::UT_S_TREBUCHET; + break; + case 0xb: + _unitAIBehaviourTypeUnk = 0x13; + _unitType = Map::Units::UT_S_BATTERINGRAM; + break; + case 0xc: + _unitAIBehaviourTypeUnk = 0x14; + _unitType = Map::Units::UT_S_TOWER; + break; + case 0xd: + _unitAIBehaviourTypeUnk = 0x15; + _unitType = Map::Units::UT_S_SHIELD; + break; + case 0xe: + _unitAIBehaviourTypeUnk = 0xc; + _unitType = Map::Units::UT_E_MONK; + break; + case 0xf: + _unitAIBehaviourTypeUnk = 2; + _unitType = Map::Units::UT_TUNNELER; + break; + case 0x10: + _unitAIBehaviourTypeUnk = 0x19; + _unitType = Map::Units::UT_A_ARCHER; + break; + case 0x11: + _unitAIBehaviourTypeUnk = 0x1a; + _unitType = Map::Units::UT_A_SLAVE; + _unitSpawnTotalAdjustment = 0x14; + goto switchD_004c5b0c_default; + case 0x12: + _unitAIBehaviourTypeUnk = 0x1b; + _unitType = Map::Units::UT_A_SLINGER; + _unitSpawnTotalAdjustment = 0x14; + goto switchD_004c5b0c_default; + case 0x13: + _unitAIBehaviourTypeUnk = 0x1c; + _unitType = Map::Units::UT_A_ASSASSIN; + _unitSpawnTotalAdjustment = 2; + goto switchD_004c5b0c_default; + case 0x14: + _unitAIBehaviourTypeUnk = 0x1d; + _unitType = Map::Units::UT_A_HARCHER; + break; + case 0x15: + _unitAIBehaviourTypeUnk = 0x1e; + _unitType = Map::Units::UT_A_SWORDSMAN; + _unitSpawnTotalAdjustment = 8; + goto switchD_004c5b0c_default; + case 0x16: + _unitAIBehaviourTypeUnk = 0x1f; + _unitType = Map::Units::UT_A_FIRETHROWER; + _unitSpawnTotalAdjustment = 4; + goto switchD_004c5b0c_default; + case 0x17: + _unitAIBehaviourTypeUnk = 0x18; + _unitType = Map::Units::UT_S_FBALLISTA; + break; + default: + goto switchD_004c5b0c_default; + } + _unitSpawnTotalAdjustment = 10; + switchD_004c5b0c_default: + _invasionAmplifier = 100; + if (!DAT_GameState::instance.mapAndTime.difficulty) { + _invasionAmplifier = 50; + } else if (DAT_GameState::instance.mapAndTime.difficulty == 2) { + _invasionAmplifier = 140; + } else if (DAT_GameState::instance.mapAndTime.difficulty == 3) { + _invasionAmplifier = 200; } - local_70[iVar22] = 1; - if (!iVar22) { - pcVar26 - = (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]; - pcVar10 = "good_arab_nervous.bik"; + _amplifiedUnitTotalForUnitType = (_invasionAmplifier * iVar18) / 100; + cVar17 = (char)_amplifiedUnitTotalForUnitType; + if (_unitAIBehaviourTypeUnk == 0x16) { + pabVar2 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + + DAT_TroopValueState::instance.attackInfo.inv_count; + (*pabVar2)[0] = (*pabVar2)[0] + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x17) { + pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count] + + 1; + *pbVar3 = *pbVar3 + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x13) { + pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count] + + 2; + *pbVar3 = *pbVar3 + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x14) { + pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count] + + 3; + *pbVar3 = *pbVar3 + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x15) { + pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count] + + 4; + *pbVar3 = *pbVar3 + cVar17; + } else if (_unitAIBehaviourTypeUnk == 0x18) { + pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count] + + 8; + *pbVar3 = *pbVar3 + cVar17; } else { - if (iVar22 != 1) - goto LAB_004c609a; - pcVar26 - = (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]; + _spawnUnitCount = _amplifiedUnitTotalForUnitType + / (_amplifiedUnitTotalForUnitType / _unitSpawnTotalAdjustment + 1); + while (0 < _amplifiedUnitTotalForUnitType) { + if (_amplifiedUnitTotalForUnitType < _spawnUnitCount) { + _spawnUnitCount = _amplifiedUnitTotalForUnitType; + } + iVar18 + = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian; + iVar22 = local_48[iVar18 + 9]; + local_48[iVar18 + 9] = iVar22 + 1; + iVar21 = DAT_TroopValueState::instance.attackInfo + .unknownSignpostRelatedArray[DAT_TroopValueState::instance + .attackInfo.inv_count]; + MACRO_CALL_MEMBER(Map::Units::TribesState_Func::spawnUnitsIntoNewTribe, + DAT_TribesState::ptr)(iVar22, _unitAIBehaviourTypeUnk, + DAT_GameState::instance.mapAndTime + .signpostsMapEdge[iVar21][local_88] + .x, + DAT_GameState::instance.mapAndTime + .signpostsMapEdge[iVar21][local_88] + .y, + iVar18 + 2, (UnitType)((int)(_unitType)), ((UnitType)0), + _spawnUnitCount, 0); + local_88 = local_88 + 1; + _amplifiedUnitTotalForUnitType + = _amplifiedUnitTotalForUnitType - _spawnUnitCount; + if (local_70[9] <= local_88) { + local_88 = 0; + } + } + } + LAB_004c5db4: + _subIndex = _subIndex + 1; + } while (_subIndex < 0x19); + iVar18 = DAT_TroopValueState::instance.attackInfo.unknownSignpostRelatedArray + [DAT_TroopValueState::instance.attackInfo.inv_count]; + MACRO_CALL_MEMBER( + UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)( + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].x, + DAT_GameState::instance.mapAndTime.signpostEntryData[iVar18].y); + DAT_TroopValueState::instance.attackInfo.inv_count = local_80; + if ((!DAT_GameCore::instance.section1076) + && (_crusaderOrArabian + = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian, + local_70[_crusaderOrArabian] == 0)) { + local_70[_crusaderOrArabian] = 1; + if (!_crusaderOrArabian) { + pcVar25 = "infidel_attack.wav"; + pcVar10 = "sultan_nervous.bik"; + LAB_004c5e44: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)("", pcVar10, pcVar25); + } else if (_crusaderOrArabian == 1) { + pcVar25 = "arabian_attack.wav"; pcVar10 = "good_soldier_nervous.bik"; + goto LAB_004c5e44; + } + if ((DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_BUILD_MENU) + && ((DAT_GameCore::instance.activeMenuTab.tabType + == UI::Enums::BASMTT_SIEGETENT_SIEGETOWER + || (DAT_GameCore::instance.activeMenuTab.tabType + == UI::Enums::BASMTT_SIEGETENT_SHIELD)))) { + MACRO_CALL_MEMBER( + Game::GameCore_Func::swapBuildMenuTab, DAT_GameCore::ptr)(); + if (DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + == UI::Enums::BASMTT_SIEGETENT_SIEGETOWER) { + if (DAT_GameCore::instance.currentMenuViewType + == UI::Enums::MVT_BUILD_MENU) { + DAT_GameCore::instance.buildmenuMenuTabToSwitchTo.tabType + = UI::Enums::BASMTT_HUNTERSHUT; + } else if (DAT_GameCore::instance.currentMenuViewType + == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) { + DAT_GameCore::instance.landscapingmenuMenuTabToSwitchTo.buildMenuTab + = 0xe7; + } + } + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + (UI::Enums::MenuViewType)DAT_GameCore::instance.currentMenuViewType, 0); } - pcVar25 - = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup); - MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar25, pcVar10, pcVar26); } - LAB_004c609a: - _eventIndex = _eventIndex + 1; - psVar21 = psVar21 + 0x72; - } while (_eventIndex < this->eventsCount); - } - if ((DAT_GameState::instance.gameTicksLoadBalancer == 0x97) - && (DAT_GameState::instance.mapAndTime.week == 3)) { - iVar22 = DAT_GameState::instance.mapAndTime.month + 1; - iVar18 = DAT_GameState::instance.mapAndTime.year; - if (0xb < iVar22) { - iVar22 = DAT_GameState::instance.mapAndTime.month + -0xb; - iVar18 = DAT_GameState::instance.mapAndTime.year + 1; - } - iVar21 = 0; - if (0 < this->eventsCount) { - pIVar16 = this->scenarioEvents; - do { - if (((iVar18 == (pIVar16->header).year) && (iVar22 == (pIVar16->header).month)) - && ((pIVar16->header).tl_type == 1)) { - DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown = 40; + _repeatMonths = this->scenarioEvents[_eventIndex].data.invasion.repeatMonths; + if (!_repeatMonths) { + this->scenarioEvents[_eventIndex].header.done = 1; + } else { + _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; + *_pConditionIsMet = *_pConditionIsMet + _repeatMonths / 0xc; + iVar18 = this->scenarioEvents[_eventIndex].header.year; + this->scenarioEvents[_eventIndex].header.month + = this->scenarioEvents[_eventIndex].header.month + _repeatMonths % 0xc; + iVar22 = this->scenarioEvents[_eventIndex].header.month; + this->scenarioEvents[_eventIndex].header.pre_done = 0; + if (0xb < iVar22) { + this->scenarioEvents[_eventIndex].header.month = iVar22 + -0xc; + this->scenarioEvents[_eventIndex].header.year = iVar18 + 1; } - iVar21 = iVar21 + 1; - pIVar16 = pIVar16 + 1; - } while (iVar21 < this->eventsCount); + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + _eventIndex = _eventIndex + -1; + } + break; } - } + LAB_004c5f28: + _eventIndex = _eventIndex + 1; + } while (_eventIndex < this->eventsCount); } - } else { - if ((DAT_BinkControlState::instance.binkObjPtrArray[1] == (HBINK)0x0) - && (!DAT_VideoBikQueue::instance.storedMessages_0x924)) { - DAT_GameState::instance.mapAndTime.unknownCountdown01 - = DAT_GameState::instance.mapAndTime.unknownCountdown01 + -1; + iVar18 = DAT_GameState::instance.mapAndTime.month + 3; + local_88 = DAT_GameState::instance.mapAndTime.year; + if (0xb < iVar18) { + iVar18 = DAT_GameState::instance.mapAndTime.month + -9; + local_88 = DAT_GameState::instance.mapAndTime.year + 1; } - if (!DAT_GameState::instance.mapAndTime.unknownCountdown01) { - DAT_VideoBikQueue::instance.storedMessages_0x924 = 0; - MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, - DAT_MenuModalComposition1::ptr)(UI::Enums::MMT_NONE, FALSE); - MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, - DAT_MenuModalComposition2::ptr)(UI::Enums::MMT_NONE, FALSE); - MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, - DAT_MenuModalComposition3::ptr)(UI::Enums::MMT_NONE, FALSE); - DAT_MenuTextInputState::instance.DAT_SomeTextArrayIndex = 9; - MACRO_CALL_MEMBER( - UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, DAT_MenuTextInputState::ptr)(); - if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 1) { - MACRO_CALL_MEMBER( - Game::GameCore_Func::incrementMissionProgress, DAT_GameCore::ptr)(); - DAT_GameCore::instance.section1066 = 2; - } - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 2) { - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - UI::Enums::MVT_GAME_LOSTUnk, 0); - DAT_GameCore::instance.section1066 = 0; - } - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - } - if (DAT_GameCore::instance.gameMode_2 != Game::GM_ECONOMIC_CAMPAIGN_SH1) { - if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { - if (DAT_GameCore::instance.field_0x6c) { - DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; - MACRO_CALL(UI::MenuItems::General_Func:: - MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(0x16); - MACRO_CALL( - UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - } - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 1) { - if ((int)this->SEC_U3_MapType2_1 < 2) { - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); + local_70[0] = 0; + local_70[1] = 0; + local_70[2] = 0; + local_70[3] = 0; + local_70[4] = 0; + local_70[5] = 0; + local_70[6] = 0; + local_70[7] = 0; + local_70[8] = 0; + _eventIndex = 0; + if (0 < this->eventsCount) { + psVar21 = &this->scenarioEvents[0]; + do { + if ((((local_88 == psVar21->header.year) && (iVar18 == psVar21->header.month)) + && ((!psVar21->header.pre_done + && ((iVar22 = psVar21->header.tl_type, psVar21->header.pre_done = 1, + iVar22 == 1 + && (DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 1, + DAT_GameCore::instance.section1076 == 0)))))) + && (iVar22 = (psVar21->data).invasion.crusaderArabian, local_70[iVar22] == 0)) { + iVar20 = 0; + iVar1 = iVar22 * 4; + numInGroup = iVar1 + 1; + iVar21 = 5; + _pConditionIsMet = (psVar21->data).invasion.unitCountsPerUnitType + 3; + do { + iVar20 = iVar20 + _pConditionIsMet[-3] + _pConditionIsMet[-2] + + _pConditionIsMet[-1] + _pConditionIsMet[1] + *_pConditionIsMet; + iVar21 = iVar21 + -1; + _pConditionIsMet = _pConditionIsMet + 5; + } while (iVar21); + if (0x18 < iVar20) { + if (iVar20 < 0x4b) { + numInGroup = iVar1 + 2; + } else if (iVar20 < 0x96) { + numInGroup = iVar1 + 3; } else { - DAT_GameCore::instance.section1095 = 1; - DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 0x2f; - MACRO_CALL_MEMBER( - UI::MenuTextInputState_Func::activateModalDialogAndClearText, - DAT_MenuTextInputState::ptr)(UI::Enums::MMT_QUIT_DIALOG); + numInGroup = iVar1 + 4; } } - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 2) { - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - UI::Enums::MVT_GAME_LOSTUnk, 0); + local_70[iVar22] = 1; + if (!iVar22) { + pcVar26 = (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]; + pcVar10 = "good_arab_nervous.bik"; + } else { + if (iVar22 != 1) + goto LAB_004c609a; + pcVar26 = (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]; + pcVar10 = "good_soldier_nervous.bik"; } - DAT_GameCore::instance.section1066 = 2; + pcVar25 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup); + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)(pcVar25, pcVar10, pcVar26); } - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - } - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 1) { - MACRO_CALL_MEMBER(Game::GameCore_Func::incrementMission, DAT_GameCore::ptr)(); + LAB_004c609a: + _eventIndex = _eventIndex + 1; + psVar21 = psVar21 + 0x72; + } while (_eventIndex < this->eventsCount); + } + if ((DAT_GameState::instance.gameTicksLoadBalancer == 0x97) + && (DAT_GameState::instance.mapAndTime.week == 3)) { + iVar22 = DAT_GameState::instance.mapAndTime.month + 1; + iVar18 = DAT_GameState::instance.mapAndTime.year; + if (0xb < iVar22) { + iVar22 = DAT_GameState::instance.mapAndTime.month + -0xb; + iVar18 = DAT_GameState::instance.mapAndTime.year + 1; } - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 2) { - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - UI::Enums::MVT_GAME_LOSTUnk, 0); + iVar21 = 0; + if (0 < this->eventsCount) { + pIVar16 = this->scenarioEvents; + do { + if (((iVar18 == (pIVar16->header).year) && (iVar22 == (pIVar16->header).month)) + && ((pIVar16->header).tl_type == 1)) { + DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown = 40; + } + iVar21 = iVar21 + 1; + pIVar16 = pIVar16 + 1; + } while (iVar21 < this->eventsCount); } - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); } } } } - } else if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::updateMilitaryCampaignMissionState, this)(); } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 9c38d0c0ab..0dba7d7a7a 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 26.9% | Ported from gynt, asm differs +SHC_3BB0A8C1_0x004C31A0 | 47.4% | structure partly restored; condition/action case layout and frame (0x9c vs 0xa0) left SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 773e4615379e1b0993b311bd9a44554cb940ecd8 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 12:49:54 +0100 Subject: [PATCH 16/60] Map: processSingleplayerEvents win/lose block returns per game mode The original returns after the campaign-mission arm, after the economic-campaign arm and after the builder arm's multiplayer branch. Ghidra's version fell through, so a won campaign mission also ran incrementMission and redrew the banner twice more. Rewritten from the asm; SEC_U3_MapType2_1 is read through the global as the original does. The condition switch cases are in the original's jump-table target order. 47.4% -> 49.0%. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 305 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 157 insertions(+), 150 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index b5cb9ae89a..2097a3491f 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -48,6 +48,7 @@ #include "OpenSHC/Globals/DAT_GameState.hpp" #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" #include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.hpp" #include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" #include "OpenSHC/Globals/DAT_MenuModalComposition2.hpp" #include "OpenSHC/Globals/DAT_MenuModalComposition3.hpp" @@ -164,79 +165,47 @@ namespace Map { if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .playerDeathRelated != 0) { - if ((DAT_BinkControlState::instance.binkObjPtrArray[1] == (HBINK)0x0) - && (!DAT_VideoBikQueue::instance.storedMessages_0x924)) { + if (DAT_BinkControlState::instance.binkObjPtrArray[1] == (HBINK)0x0 + && !DAT_VideoBikQueue::instance.storedMessages_0x924) { DAT_GameState::instance.mapAndTime.unknownCountdown01 - = DAT_GameState::instance.mapAndTime.unknownCountdown01 + -1; + = DAT_GameState::instance.mapAndTime.unknownCountdown01 - 1; } - if (!DAT_GameState::instance.mapAndTime.unknownCountdown01) { - DAT_VideoBikQueue::instance.storedMessages_0x924 = 0; - MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, - DAT_MenuModalComposition1::ptr)(UI::Enums::MMT_NONE, FALSE); - MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, - DAT_MenuModalComposition2::ptr)(UI::Enums::MMT_NONE, FALSE); - MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, - DAT_MenuModalComposition3::ptr)(UI::Enums::MMT_NONE, FALSE); - DAT_MenuTextInputState::instance.DAT_SomeTextArrayIndex = 9; - MACRO_CALL_MEMBER( - UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, DAT_MenuTextInputState::ptr)(); - if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 1) { - MACRO_CALL_MEMBER(Game::GameCore_Func::incrementMissionProgress, DAT_GameCore::ptr)(); - DAT_GameCore::instance.section1066 = 2; - } - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 2) { - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - UI::Enums::MVT_GAME_LOSTUnk, 0); - DAT_GameCore::instance.section1066 = 0; - } - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + if (DAT_GameState::instance.mapAndTime.unknownCountdown01 != 0) { + return; + } + DAT_VideoBikQueue::instance.storedMessages_0x924 = 0; + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition1::ptr)(UI::Enums::MMT_NONE, FALSE); + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition2::ptr)(UI::Enums::MMT_NONE, FALSE); + MACRO_CALL_MEMBER(UI::MenuModalComposition_Func::activateModalDialog, + DAT_MenuModalComposition3::ptr)(UI::Enums::MMT_NONE, FALSE); + DAT_MenuTextInputState::instance.DAT_SomeTextArrayIndex = 9; + MACRO_CALL_MEMBER( + UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, DAT_MenuTextInputState::ptr)(); + if (DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) { + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + MACRO_CALL_MEMBER(Game::GameCore_Func::incrementMissionProgress, DAT_GameCore::ptr)(); + DAT_GameCore::instance.section1066 = 2; } - if (DAT_GameCore::instance.gameMode_2 != Game::GM_ECONOMIC_CAMPAIGN_SH1) { - if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { - if (DAT_GameCore::instance.field_0x6c) { - DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; - MACRO_CALL(UI::MenuItems::General_Func:: - MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(0x16); - MACRO_CALL( - UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - } - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 1) { - if ((int)this->SEC_U3_MapType2_1 < 2) { - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); - } else { - DAT_GameCore::instance.section1095 = 1; - DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 0x2f; - MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, - DAT_MenuTextInputState::ptr)(UI::Enums::MMT_QUIT_DIALOG); - } - } - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 2) { - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - UI::Enums::MVT_GAME_LOSTUnk, 0); - } - DAT_GameCore::instance.section1066 = 2; - } - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); + DAT_GameCore::instance.section1066 = 0; } + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + return; + } + if (DAT_GameCore::instance.gameMode_2 == Game::GM_ECONOMIC_CAMPAIGN_SH1) { if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .playerDeathRelated @@ -254,7 +223,43 @@ namespace Map { UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + return; } + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { + if (DAT_GameCore::instance.field_0x6c) { + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; + MACRO_CALL(UI::MenuItems::General_Func:: + MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(0x16); + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + return; + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + if ((int)DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 < 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); + } else { + DAT_GameCore::instance.section1095 = 1; + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 0x2f; + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, + DAT_MenuTextInputState::ptr)(UI::Enums::MMT_QUIT_DIALOG); + } + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_GAME_LOSTUnk, 0); + } + DAT_GameCore::instance.section1066 = 2; + } + MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( + UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); + return; } else { if ((this->SEC_Section1081) && (0 < this->SEC_Section1080)) { this->SEC_Section1080 = this->SEC_Section1080 + -1; @@ -583,6 +588,27 @@ namespace Map { *_pConditionIsMet = 0; } break; + case 0xf: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .totalEnemyUnitsCount + == 0) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + if (((DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) + || (this->SEC_U3_MapType2_1 != Map::MT_SIEGE)) + || ((DAT_GameSynchronyState::instance.currentPlayerSlotID != 1 + || (BVar11 = MACRO_CALL_MEMBER( + Map::Units::TroopValueState_Func::isAttackWaveComplete, + DAT_TroopValueState::ptr)(), + !BVar11)))) + goto LAB_004c37cd; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; case 8: if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -764,76 +790,6 @@ namespace Map { local_a0 = local_a0 + 1; } break; - case 0xf: - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .totalEnemyUnitsCount - == 0) { - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; - } else { - if (((DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) - || (this->SEC_U3_MapType2_1 != Map::MT_SIEGE)) - || ((DAT_GameSynchronyState::instance.currentPlayerSlotID != 1 - || (BVar11 = MACRO_CALL_MEMBER( - Map::Units::TroopValueState_Func::isAttackWaveComplete, - DAT_TroopValueState::ptr)(), - !BVar11)))) - goto LAB_004c37cd; - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; - } - break; - case 0x10: - if (DAT_GameState::instance.mapAndTime.cathedralRelated1 == 1) { - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; - } - break; - case 0x12: - if (DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) { - iVar18 = 0; - if (DAT_BuildingsState::instance.maxBuildingsCount < 2) - goto LAB_004c37cd; - pBVar13 = &DAT_BuildingsState::instance.buildings[1].buildingType; - iVar22 = DAT_BuildingsState::instance.maxBuildingsCount + -1; - do { - if (((pBVar13[-1] != ((BuildingLogicalState)0)) - && (*pBVar13 == Map::Buildings::BT_DAIRYFARM)) - && (pBVar13[0x65] == 0)) { - iVar18 = iVar18 + 1; - } - pBVar13 = pBVar13 + 0x196; - iVar22 = iVar22 + -1; - } while (iVar22); - bVar24 = (iVar18 < 4); - bVar23 = iVar18 + -4 < 0; - goto LAB_004c3fc7; - } - break; - case 0x13: - if (DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) { - iVar18 = 0; - if (DAT_BuildingsState::instance.maxBuildingsCount < 2) - goto LAB_004c37cd; - pBVar13 = &DAT_BuildingsState::instance.buildings[1].buildingType; - iVar22 = DAT_BuildingsState::instance.maxBuildingsCount + -1; - do { - if ((((pBVar13[-1] != ((BuildingLogicalState)0)) - && (*pBVar13 == Map::Buildings::BT_INN)) - && (pBVar13[0x65] == 0)) - && (0 < (short)pBVar13[0xef])) { - iVar18 = iVar18 + 1; - } - pBVar13 = pBVar13 + 0x196; - iVar22 = iVar22 + -1; - } while (iVar22); - bVar24 = (iVar18 < 2); - bVar23 = iVar18 + -2 < 0; - goto LAB_004c3fc7; - } - break; case 0x14: sVar7 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -845,16 +801,6 @@ namespace Map { bVar24 = (sVar7 < sVar8); bVar23 = (short)(sVar7 - sVar8) < 0; goto LAB_004c3deb; - case 0x15: - iVar18 = MACRO_CALL_MEMBER( - Game::GameStateStructures_Func::computeAleCoverage, DAT_GameState::ptr)( - DAT_GameSynchronyState::instance.currentPlayerSlotID); - iVar22 = (int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0x15] - .value; - bVar24 = (iVar18 < iVar22); - bVar23 = iVar18 - iVar22 < 0; - goto LAB_004c3deb; case 0x16: if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -883,6 +829,16 @@ namespace Map { local_a0 = local_a0 + 1; } break; + case 0x15: + iVar18 = MACRO_CALL_MEMBER( + Game::GameStateStructures_Func::computeAleCoverage, DAT_GameState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID); + iVar22 = (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0x15] + .value; + bVar24 = (iVar18 < iVar22); + bVar23 = iVar18 - iVar22 < 0; + goto LAB_004c3deb; case 0x27: if (local_a0 == _spawnUnitCount) { MACRO_CALL(UI::DisplayElements_Func:: @@ -907,6 +863,56 @@ namespace Map { } this->SEC_Section1081 = 0; } + break; + case 0x10: + if (DAT_GameState::instance.mapAndTime.cathedralRelated1 == 1) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; + case 0x12: + if (DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) { + iVar18 = 0; + if (DAT_BuildingsState::instance.maxBuildingsCount < 2) + goto LAB_004c37cd; + pBVar13 = &DAT_BuildingsState::instance.buildings[1].buildingType; + iVar22 = DAT_BuildingsState::instance.maxBuildingsCount + -1; + do { + if (((pBVar13[-1] != ((BuildingLogicalState)0)) + && (*pBVar13 == Map::Buildings::BT_DAIRYFARM)) + && (pBVar13[0x65] == 0)) { + iVar18 = iVar18 + 1; + } + pBVar13 = pBVar13 + 0x196; + iVar22 = iVar22 + -1; + } while (iVar22); + bVar24 = (iVar18 < 4); + bVar23 = iVar18 + -4 < 0; + goto LAB_004c3fc7; + } + break; + case 0x13: + if (DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) { + iVar18 = 0; + if (DAT_BuildingsState::instance.maxBuildingsCount < 2) + goto LAB_004c37cd; + pBVar13 = &DAT_BuildingsState::instance.buildings[1].buildingType; + iVar22 = DAT_BuildingsState::instance.maxBuildingsCount + -1; + do { + if ((((pBVar13[-1] != ((BuildingLogicalState)0)) + && (*pBVar13 == Map::Buildings::BT_INN)) + && (pBVar13[0x65] == 0)) + && (0 < (short)pBVar13[0xef])) { + iVar18 = iVar18 + 1; + } + pBVar13 = pBVar13 + 0x196; + iVar22 = iVar22 + -1; + } while (iVar22); + bVar24 = (iVar18 < 2); + bVar23 = iVar18 + -2 < 0; + goto LAB_004c3fc7; + } + break; } switchD_004c3756_caseD_18: _spawnUnitCount = _counter; @@ -1060,6 +1066,7 @@ namespace Map { break; } } + goto switchD_004c382e_caseD_2; default: goto switchD_004c382e_caseD_2; case 3: diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 0dba7d7a7a..7e72609601 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 47.4% | structure partly restored; condition/action case layout and frame (0x9c vs 0xa0) left +SHC_3BB0A8C1_0x004C31A0 | 49.0% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 794ddc655df2f9c67d22e15e4308db4b784b7b6e Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 15:50:43 +0100 Subject: [PATCH 17/60] Map: processSingleplayerEvents zero tests in the original's arm order The hit-count conditions test the player byte for non-zero first, and the sortEventsByDate block is a flat chain in the order the original tests it. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 94 +++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 46 insertions(+), 50 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 2097a3491f..1fb7e8362e 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -716,7 +716,18 @@ namespace Map { case 0xd: cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data + _conditionOffset + 0xe); - if (cVar17 == '\0') { + if (cVar17 != '\0') { + if (((byte)(cVar17 - 1U) < 4) + && ((int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0xd] + .value + <= DAT_GameState::instance.mapAndTime + .emenyHitArray[cVar17 + -8])) { + DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + -8] = 0; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + } else { if ((int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[0xd] .value @@ -742,20 +753,23 @@ namespace Map { this->SEC_EventsExtra[_eventIndex].conditionIsTrue[13] = 1; local_a0 = local_a0 + 1; } - } else if (((byte)(cVar17 - 1U) < 4) - && ((int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0xd] - .value - <= DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + -8])) { - DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + -8] = 0; - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; } break; case 0xe: cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data + _conditionOffset + 0xe); - if (cVar17 == '\0') { + if (cVar17 != '\0') { + if (((byte)(cVar17 - 1U) < 4) + && ((int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0xe] + .value + <= DAT_GameState::instance.mapAndTime + .emenyHitArray[cVar17 + 1])) { + DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + 1] = 0; + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + } else { if ((int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[0xe] .value @@ -780,14 +794,6 @@ namespace Map { this->SEC_EventsExtra[_eventIndex].conditionIsTrue[14] = 1; local_a0 = local_a0 + 1; } - } else if (((byte)(cVar17 - 1U) < 4) - && ((int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0xe] - .value - <= DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + 1])) { - DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + 1] = 0; - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; } break; case 0x14: @@ -982,40 +988,30 @@ namespace Map { DAT_MouseState::ptr)(); } if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x13) - == '\0') { - if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x1f) - == '\0') { - if ((((*(char*)((int)&this->scenarioEvents[_eventIndex].data - + 0x23) - == '\0') - && (*(char*)((int)&this->scenarioEvents[_eventIndex] - .data - + 0x27) - == '\0')) - && (*(char*)((int)&this->scenarioEvents[_eventIndex] - .data - + 0x2b) - == '\0')) - && (*(char*)((int)&this->scenarioEvents[_eventIndex].data - + 0x53) - == '\0')) { - this->field133_0x145d8 = 1; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); - } else { - this->field133_0x145d8 = 3; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); - } - } else { - this->field133_0x145d8 = 2; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); - } - } else { + != 0) { + this->field133_0x145d8 = 1; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + } else if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x1f) + != 0) { + this->field133_0x145d8 = 2; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + } else if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x23) + == 0 + && *(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x27) + == 0 + && *(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x2b) + == 0 + && *(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x53) + == 0) { this->field133_0x145d8 = 1; MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::sortEventsByDate, this)(); + } else { + this->field133_0x145d8 = 3; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); } break; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7e72609601..1eee277e02 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 49.0% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp +SHC_3BB0A8C1_0x004C31A0 | 49.2% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 90e5a18669658b257e274d3f7a5ebdbdf42dd8d1 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 16:00:58 +0100 Subject: [PATCH 18/60] Map: processSingleplayerEvents event videos as nested calls The original evaluates playEventVideoBik(getText(..), video, wav) as one call; Ghidra's pcVar locals for its arguments are gone, and the fire warning tests for a well before a water pot as the original does. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 183 ++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 82 insertions(+), 103 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 1fb7e8362e..fc86c5beab 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -340,17 +340,16 @@ namespace Map { pBVar13 = pBVar13 + 0x196; } while (iVar18 < DAT_BuildingsState::instance.maxBuildingsCount); } - pcVar27 = "general_message3.wav"; - pcVar25 = "ap_civil12.bik"; /* "there are no wells in the castle my liege. should a fire break out, we are int great danger." added by script: "There are no wells in the castle my Liege. Should a fire break out we would be in great danger." */ - pcVar10 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x12); - MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x12), + "ap_civil12.bik", "general_message3.wav"); } } LAB_004c3637: @@ -1190,17 +1189,16 @@ namespace Map { .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_CAMPGROUND] .tileEntry])), Map::Units::UT_FIREEATER); - pcVar25 = "Random_Events1.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent1VideoName; /* "a travelling fair has come to town my lord" added by script: "A ‘Travelling Fair’ has come to town, my Lord." */ - pcVar10 - = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 1); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 1), + DAT_MissionAestheticsDefinedData::instance.RandomEvent1VideoName, + "Random_Events1.wav"); bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, @@ -1308,16 +1306,15 @@ namespace Map { spawnPoisonCloudsAtRandomStorageOrArmyBuilding, DAT_GameState::ptr)( iVar18, this->scenarioEvents[_eventIndex].data.scenario.actionData); - pcVar25 = "Random_Events2.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent2VideoName; /* added by script: "Plague has descended on our castle your lordship." */ - pcVar10 - = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 2); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 2), + DAT_MissionAestheticsDefinedData::instance.RandomEvent2VideoName, + "Random_Events2.wav"); bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, @@ -1355,16 +1352,15 @@ namespace Map { Map::Buildings::BuildingsState_Func::harmWheatFarmsOfPlayer, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); - pcVar25 = "Random_Events3.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent3VideoName; /* added by script: "A pestilence is devastating our wheat crops, Sire." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 3); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 3), + DAT_MissionAestheticsDefinedData::instance.RandomEvent3VideoName, + "Random_Events3.wav"); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -1402,17 +1398,16 @@ namespace Map { MACRO_CALL_MEMBER(Map::Buildings::BuildingsState_Func::harmHopFarmsOfPlayer, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); - pcVar25 = "Random_Events4.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent4VideoName; /* added by script: "Our hops plants are overrun with hop weevil, the crop is ruined, My Liege." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 4); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 4), + DAT_MissionAestheticsDefinedData::instance.RandomEvent4VideoName, + "Random_Events4.wav"); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -1451,17 +1446,15 @@ namespace Map { Map::Buildings::BuildingsState_Func::harmAppleFarmTreesOfPlayer, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); - pcVar27 = "Random_Events5.wav"; - pcVar25 = ""; /* added by script: "Our apple orchards are barren, my lord. The people suspect witchcraft." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 5); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 5), + "", "Random_Events5.wav"); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)("", (char*)((int)(DAT_MissionAestheticsDefinedData::instance @@ -1497,17 +1490,16 @@ namespace Map { case 0xf: MACRO_CALL_MEMBER(Map::LandscapeState_Func::ageFourFifthsOfGrowingTrees, DAT_LandscapeState::ptr)(); - pcVar25 = "Random_Events6.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent6VideoName; /* added by script: "Sire, woodcutters report that the recent drought has killed off many trees." */ - pcVar10 - = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 6); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 6), + DAT_MissionAestheticsDefinedData::instance.RandomEvent6VideoName, + "Random_Events6.wav"); bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, @@ -1558,17 +1550,16 @@ namespace Map { MACRO_CALL_MEMBER(UI::MinimapViewState_Func::setSpawnMoment, DAT_MinimapViewState::ptr)(DAT_TribesState::instance.unknownX_01, DAT_TribesState::instance.unknownY_01); - pcVar25 = "Random_Events7.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent7VideoName; /* added by script: "Rabbits are breeding at an alarming rate Liege. Our crops are threatened." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 7); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 7), + DAT_MissionAestheticsDefinedData::instance.RandomEvent7VideoName, + "Random_Events7.wav"); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -1639,17 +1630,15 @@ namespace Map { } while (iVar18 < this->scenarioEvents[_eventIndex].data.scenario.actionData); } - pcVar27 = ""; - pcVar25 = ""; /* added by script: "I have alarming reports that lions are abroad in the land. People are scared my Lord." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 8); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 8), + "", ""); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -1724,16 +1713,15 @@ namespace Map { = Map::Units::ULS_NORMAL; } while (iVar18 < sVar7); } - pcVar25 = "Random_Events9.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent9VideoName; /* added by script: "Bandits are operating near the castle Lordship." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 9); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 9), + DAT_MissionAestheticsDefinedData::instance.RandomEvent9VideoName, + "Random_Events9.wav"); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -1775,17 +1763,15 @@ namespace Map { Map::Buildings::BuildingsState_Func::setDairyFarmCheeseCounter, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); - pcVar27 = "Random_Events10.wav"; - pcVar25 = ""; /* added by script: "Our cows have been struck down by a strange malady, my lord." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 10); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar25, pcVar27); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 10), + "", "Random_Events10.wav"); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)("", (char*)((int)(DAT_MissionAestheticsDefinedData::instance @@ -1922,17 +1908,16 @@ namespace Map { DAT_TribesState::ptr)( tribeID, uVar19, y1, 0, 0, Map::Units::Instructions::UMSE_0); } - pcVar25 = "Random_Events11.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent11VideoName; /* added by script: "Some outlaws from the woods have returned to our cause, my lord." */ - pcVar10 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xb); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xb), + DAT_MissionAestheticsDefinedData::instance.RandomEvent11VideoName, + "Random_Events11.wav"); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -1968,16 +1953,15 @@ namespace Map { if (10000 < DAT_GameState::instance.playerDataArray[iVar18].popularity) { DAT_GameState::instance.playerDataArray[iVar18].popularity = 10000; } - pcVar25 = "Random_Events12.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent12VideoName; /* added by script: "The people rejoice at your forthcoming marriage, Sire." */ - pcVar10 - = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xc); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xc), + DAT_MissionAestheticsDefinedData::instance.RandomEvent12VideoName, + "Random_Events12.wav"); MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::setUpSFXToPlayUnk, DAT_SFXState::ptr)(Audio::SFX::SEID_CHAPEL_BELL); MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); @@ -1990,17 +1974,16 @@ namespace Map { if (10000 < DAT_GameState::instance.playerDataArray[iVar18].popularity) { DAT_GameState::instance.playerDataArray[iVar18].popularity = 10000; } - pcVar25 = "Random_Events13.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent13VideoName; /* added by script: "A Jester has arrived at the castle Liege. I have taken the liberty of offering him employment." */ - pcVar10 - = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xd); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xd), + DAT_MissionAestheticsDefinedData::instance.RandomEvent13VideoName, + "Random_Events13.wav"); MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x17: @@ -2180,31 +2163,27 @@ namespace Map { DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID, Map::Buildings::BT_WELL); - if (!iVar18) { - iVar18 = MACRO_CALL_MEMBER( - Map::Buildings::BuildingsState_Func::findFirstBuildingOfType, - DAT_BuildingsState::ptr)( - DAT_GameSynchronyState::instance.currentPlayerSlotID, - Map::Buildings::BT_WATERPOT); - if (!iVar18) { - iVar18 = 0x11; - } else { - iVar18 = 0xf; - } - } else { + if (iVar18) { + iVar18 = 0xf; + } else if (MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findFirstBuildingOfType, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_WATERPOT)) { iVar18 = 0xf; + } else { + iVar18 = 0x11; } - pcVar25 = "general_warning16.wav"; - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName; /* added by script: "There is fire in the castle and we have not built any wells my Liege!" */ - pcVar10 - = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar10, pcVar26, pcVar25); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18), + DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName, + "general_warning16.wav"); bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1eee277e02..3bc183393e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 49.2% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp +SHC_3BB0A8C1_0x004C31A0 | 50.2% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 18b9b6c4743a72b6da5f4173545554eb53fc6592 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 16:10:02 +0100 Subject: [PATCH 19/60] Map: processSingleplayerEvents per-arm sands-of-time video call Each crusader/arabian arm makes its own playEventVideoBik call as the original does, and the stolen-food video is a nested call as well; the pcVar locals left without a use are removed. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 37 +++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index fc86c5beab..0a7d61bc0a 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -127,8 +127,6 @@ namespace Map { bool bVar23; bool bVar24; char* pcVar25; - char* pcVar26; - char* pcVar27; int local_a0; int _eventIndex; int _subIndex; @@ -2108,21 +2106,20 @@ namespace Map { DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID, this->scenarioEvents[_eventIndex].data.scenario.actionData); - pcVar10 = "general_message3.wav"; if (this->scenarioEvents[_eventIndex].data.scenario.actionData == 100) { iVar18 = 0x10; } else { iVar18 = 0xe; } - pcVar26 = DAT_MissionAestheticsDefinedData::instance.RandomEvent14VideoName; /* added by script: "Thieves have stolen some food from our granary." */ - pcVar25 = MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18); MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar25, pcVar26, pcVar10); + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18), + DAT_MissionAestheticsDefinedData::instance.RandomEvent14VideoName, + "general_message3.wav"); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -2559,18 +2556,20 @@ namespace Map { } local_70[iVar22] = 1; if (!iVar22) { - pcVar26 = (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]; - pcVar10 = "good_arab_nervous.bik"; - } else { - if (iVar22 != 1) - goto LAB_004c609a; - pcVar26 = (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]; - pcVar10 = "good_soldier_nervous.bik"; + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), + "good_arab_nervous.bik", + (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); + } else if (iVar22 == 1) { + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), + "good_soldier_nervous.bik", + (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); } - pcVar25 = MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup); - MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)(pcVar25, pcVar10, pcVar26); } LAB_004c609a: _eventIndex = _eventIndex + 1; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3bc183393e..143fdc67a1 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 50.2% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp +SHC_3BB0A8C1_0x004C31A0 | 50.4% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 0549275b73ba21ea8e3fb09b57e239cb2d0c34a0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 16:18:27 +0100 Subject: [PATCH 20/60] Map: processSingleplayerEvents indexed scans for a pending invasion The two scans for a later invasion that is already due index the event array as the original does (imul by the event size) and name the header fields instead of walking Ghidra's int pointer. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 60 ++++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 0a7d61bc0a..ffc2ae2496 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -934,23 +934,19 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .playerDeathRelated == 0) { - iVar18 = _eventIndex + 1; - if (iVar18 < this->eventsCount) { - _pConditionIsMet = &this->scenarioEvents[_eventIndex + 1] - .data.scenario.ScenarioEventType; - do { - if (((_pConditionIsMet[-3] == 3) - && (((*_pConditionIsMet == 0 || (*_pConditionIsMet == 0x1a)) - && (_pConditionIsMet[-4] - <= DAT_GameState::instance.mapAndTime.year)))) - && ((DAT_GameState::instance.mapAndTime.year - != _pConditionIsMet[-4] - || (_pConditionIsMet[-5] - < DAT_GameState::instance.mapAndTime.month)))) - goto switchD_004c382e_caseD_2; - iVar18 = iVar18 + 1; - _pConditionIsMet = _pConditionIsMet + 0x39; - } while (iVar18 < this->eventsCount); + for (iVar18 = _eventIndex + 1; iVar18 < this->eventsCount; iVar18++) { + if (this->scenarioEvents[iVar18].header.tl_type == 3 + && (this->scenarioEvents[iVar18].data.scenario.ScenarioEventType + == 0 + || this->scenarioEvents[iVar18].data.scenario.ScenarioEventType + == 0x1a) + && this->scenarioEvents[iVar18].header.year + <= DAT_GameState::instance.mapAndTime.year + && (DAT_GameState::instance.mapAndTime.year + != this->scenarioEvents[iVar18].header.year + || this->scenarioEvents[iVar18].header.month + < DAT_GameState::instance.mapAndTime.month)) + goto switchD_004c382e_caseD_2; } if (((DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) || (DAT_GameCore::instance.gameMode_2 @@ -2026,23 +2022,19 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .playerDeathRelated == 0) { - iVar18 = _eventIndex + 1; - if (iVar18 < this->eventsCount) { - _pConditionIsMet = &this->scenarioEvents[_eventIndex + 1] - .data.scenario.ScenarioEventType; - do { - if ((_pConditionIsMet[-3] == 3) - && ((((*_pConditionIsMet == 0 || (*_pConditionIsMet == 0x1a)) - && (_pConditionIsMet[-4] - <= DAT_GameState::instance.mapAndTime.year)) - && ((DAT_GameState::instance.mapAndTime.year - != _pConditionIsMet[-4] - || (_pConditionIsMet[-5] - < DAT_GameState::instance.mapAndTime.month)))))) - goto switchD_004c382e_caseD_2; - iVar18 = iVar18 + 1; - _pConditionIsMet = _pConditionIsMet + 0x39; - } while (iVar18 < this->eventsCount); + for (iVar18 = _eventIndex + 1; iVar18 < this->eventsCount; iVar18++) { + if (this->scenarioEvents[iVar18].header.tl_type == 3 + && (this->scenarioEvents[iVar18].data.scenario.ScenarioEventType + == 0 + || this->scenarioEvents[iVar18].data.scenario.ScenarioEventType + == 0x1a) + && this->scenarioEvents[iVar18].header.year + <= DAT_GameState::instance.mapAndTime.year + && (DAT_GameState::instance.mapAndTime.year + != this->scenarioEvents[iVar18].header.year + || this->scenarioEvents[iVar18].header.month + < DAT_GameState::instance.mapAndTime.month)) + goto switchD_004c382e_caseD_2; } this->scenarioEvents[_eventIndex].header.done = 0; this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType = 0; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 143fdc67a1..652d08a4db 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 50.4% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp +SHC_3BB0A8C1_0x004C31A0 | 50.7% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 73d1200219ce326441d39e397849acc9bc1f4b02 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 17:20:21 +0100 Subject: [PATCH 21/60] Skirmish: Skirmish_PrepareLeaderboardView descending loop runs on i >= 0 The original reads the filter flag through the counter (arr[left - 1], walked by pointer) and stores the index, guarded by a signed i >= 0. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp | 6 +++--- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp index e03c96d8a4..5381b6a638 100644 --- a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp +++ b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp @@ -52,9 +52,9 @@ namespace Game { } } } else if (!DAT_MissionDefinedData::instance.descending) { - for (int left = DAT_SkMasters2Data_Count::instance, i = DAT_SkMasters2Data_Count::instance - 1; - left != 0; left--, i--) { - if (INT_ARRAY_00eb0e48::instance[i] != 0) { + for (int left = DAT_SkMasters2Data_Count::instance, i = DAT_SkMasters2Data_Count::instance - 1; i >= 0; + left--, i--) { + if (INT_ARRAY_00eb0e48::instance[left - 1] != 0) { INT_ARRAY_00eb96d8::instance[INT_00eb9b60::instance] = i; INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 652d08a4db..0193823ca5 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -36023,7 +36023,7 @@ SHC_3BB0A8C1_0x004D9270 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D9290 | 100.0% | Reimplemented (counted: only memset/_stricmp call labels and the instance[i - 1] address label differ) -SHC_3BB0A8C1_0x004D9400 | 86.1% | register assignment +SHC_3BB0A8C1_0x004D9400 | 89.1% | descending loop ends on the counter (jne) in the original, ours on i (jge) SHC_3BB0A8C1_0x004D9520 | 0.0% | Pending From f8e617c5111b099de37e6678d34d979ea5de4a90 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 17:53:46 +0100 Subject: [PATCH 22/60] Map: processSingleplayerEvents reads each condition through one reference The condition's enabled, subType and value bytes come from a ScenarioEventCondition reference instead of raw offsets into the event data, and the case-2 lord-killed test falls into the shared not-met store the way the original lays it out before the loop latch. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 49 ++++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index ffc2ae2496..0051fe1264 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -139,7 +139,6 @@ namespace Map { int _amplifiedUnitTotalForUnitType; int _crusaderOrArabian; int _repeatMonths; - int _conditionOffset; int _counter; int _scenarioEventType; int _eventType; @@ -381,13 +380,13 @@ namespace Map { */ _spawnUnitCount = 0; for (_subIndex = 0; _subIndex < 40; _subIndex++) { - _conditionOffset = _subIndex * 4; + Game::ScenarioEvents::ScenarioEventCondition const& condition + = this->scenarioEvents[_eventIndex].data.scenario.conditions[_subIndex]; _counter = _spawnUnitCount; /* this condition is empty? then move to next condition */ - if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + _subIndex * 4 + 0xf) - == '\0') + if (condition.enabled == 0) goto switchD_004c3756_caseD_18; _counter = _spawnUnitCount + 1; /* @@ -420,11 +419,12 @@ namespace Map { .lordKilledByPlayerID; if (!iVar18) break; - cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data - + _conditionOffset + 0xe); - if (((cVar17 != '\0') && (iVar18 != 10)) && (cVar17 + 1 != iVar18)) - goto LAB_004c37cd; - goto LAB_004c3fcd; + cVar17 = condition.subType; + if (cVar17 == '\0' || iVar18 == 10 || cVar17 + 1 == iVar18) + goto LAB_004c3fcd; + LAB_004c37cd: + *_pConditionIsMet = 0; + break; case 3: if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -455,8 +455,7 @@ namespace Map { (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[5] .value); - cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data - + _conditionOffset + 0xe); + cVar17 = condition.subType; if (cVar17 == '\0') { iVar22 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -494,10 +493,8 @@ namespace Map { case 0x11: iVar18 = MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - (int)*(short*)((int)&this->scenarioEvents[_eventIndex].data - + _subIndex * 4 + 0xc)); - cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data - + _conditionOffset + 0xe); + condition.value); + cVar17 = condition.subType; if (cVar17 != '\0') goto LAB_004c38d2; iVar22 = DAT_GameState::instance @@ -541,8 +538,7 @@ namespace Map { (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[7] .value); - cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data - + _conditionOffset + 0xe); + cVar17 = condition.subType; if (cVar17 != '\0') goto LAB_004c38d2; iVar22 = DAT_GameState::instance @@ -576,14 +572,11 @@ namespace Map { bVar24 = (iVar22 < iVar18); bVar23 = iVar22 - iVar18 < 0; LAB_004c3fc7: - if (bVar24 == bVar23) { - LAB_004c3fcd: - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; - } else { - LAB_004c37cd: - *_pConditionIsMet = 0; - } + if (bVar24 != bVar23) + goto LAB_004c37cd; + LAB_004c3fcd: + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; break; case 0xf: if (DAT_GameState::instance @@ -711,8 +704,7 @@ namespace Map { local_a0 = local_a0 + 1; break; case 0xd: - cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data - + _conditionOffset + 0xe); + cVar17 = condition.subType; if (cVar17 != '\0') { if (((byte)(cVar17 - 1U) < 4) && ((int)this->scenarioEvents[_eventIndex] @@ -753,8 +745,7 @@ namespace Map { } break; case 0xe: - cVar17 = *(char*)((int)&this->scenarioEvents[_eventIndex].data - + _conditionOffset + 0xe); + cVar17 = condition.subType; if (cVar17 != '\0') { if (((byte)(cVar17 - 1U) < 4) && ((int)this->scenarioEvents[_eventIndex] diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 0193823ca5..6274b6576d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 50.7% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp +SHC_3BB0A8C1_0x004C31A0 | 51.8% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 0f2441a8faab2d81c51958162f685394125a272f Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 18:04:33 +0100 Subject: [PATCH 23/60] Map: processSingleplayerEvents threshold tests as plain comparisons Ghidra's bVar24/bVar23 sign-flag pairs become `if (a >= b)` with the met and not-met stores in each case, and the dead jump into the shared flag test goes away. The original compiles each to a cmp feeding one shared jl, which this now reaches more often. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 103 ++++++++++++------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 68 insertions(+), 37 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 0051fe1264..fa640c4d50 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -125,7 +125,6 @@ namespace Map { uint y1; UnitTypeInt _unitType; bool bVar23; - bool bVar24; char* pcVar25; int local_a0; int _eventIndex; @@ -409,9 +408,13 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] .currentPopulation; - bVar24 = (iVar18 < iVar22); - bVar23 = iVar18 - iVar22 < 0; - goto LAB_004c3fc7; + if (iVar18 >= iVar22) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; case 2: iVar18 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -446,9 +449,13 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] .currentResources[0xf]; - bVar24 = (iVar18 < iVar22); - bVar23 = iVar18 - iVar22 < 0; - goto LAB_004c3fc7; + if (iVar18 >= iVar22) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; case 5: iVar18 = MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( @@ -473,8 +480,13 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] .currentResources[0xd]; - bVar24 = (iVar22 < iVar18); - bVar23 = iVar22 - iVar18 < 0; + if (iVar22 >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; } else { LAB_004c38d2: iVar22 = (int)cVar17; @@ -485,10 +497,14 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] .currentResources[iVar22]; - bVar24 = (iVar22 < iVar18); - bVar23 = iVar22 - iVar18 < 0; + if (iVar22 >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; } - goto LAB_004c3fc7; case 6: case 0x11: iVar18 = MACRO_CALL_MEMBER( @@ -529,9 +545,13 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] .currentResources[0x18]; - bVar24 = (iVar22 < iVar18); - bVar23 = iVar22 - iVar18 < 0; - goto LAB_004c3fc7; + if (iVar22 >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; case 7: iVar18 = MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( @@ -569,11 +589,13 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] .currentResources[9]; - bVar24 = (iVar22 < iVar18); - bVar23 = iVar22 - iVar18 < 0; - LAB_004c3fc7: - if (bVar24 != bVar23) - goto LAB_004c37cd; + if (iVar22 >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; LAB_004c3fcd: *_pConditionIsMet = 1; local_a0 = local_a0 + 1; @@ -792,9 +814,11 @@ namespace Map { sVar8 = this->scenarioEvents[_eventIndex] .data.scenario.conditions[0x14] .value; - bVar24 = (sVar7 < sVar8); - bVar23 = (short)(sVar7 - sVar8) < 0; - goto LAB_004c3deb; + if (sVar7 >= sVar8) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; case 0x16: if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -815,10 +839,7 @@ namespace Map { .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] .fearFactorLevel; - bVar24 = (iVar18 < iVar22); - bVar23 = iVar18 - iVar22 < 0; - LAB_004c3deb: - if (bVar24 == bVar23) { + if (iVar18 >= iVar22) { *_pConditionIsMet = 1; local_a0 = local_a0 + 1; } @@ -830,9 +851,11 @@ namespace Map { iVar22 = (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[0x15] .value; - bVar24 = (iVar18 < iVar22); - bVar23 = iVar18 - iVar22 < 0; - goto LAB_004c3deb; + if (iVar18 >= iVar22) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } + break; case 0x27: if (local_a0 == _spawnUnitCount) { MACRO_CALL(UI::DisplayElements_Func:: @@ -880,9 +903,13 @@ namespace Map { pBVar13 = pBVar13 + 0x196; iVar22 = iVar22 + -1; } while (iVar22); - bVar24 = (iVar18 < 4); - bVar23 = iVar18 + -4 < 0; - goto LAB_004c3fc7; + if (iVar18 >= 4) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; } break; case 0x13: @@ -902,9 +929,13 @@ namespace Map { pBVar13 = pBVar13 + 0x196; iVar22 = iVar22 + -1; } while (iVar22); - bVar24 = (iVar18 < 2); - bVar23 = iVar18 + -2 < 0; - goto LAB_004c3fc7; + if (iVar18 >= 2) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } + break; } break; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6274b6576d..174ebc7d39 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 51.8% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp +SHC_3BB0A8C1_0x004C31A0 | 52.0% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 434758fe6e695856829b428610c3ac912ca82eee Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 18:50:01 +0100 Subject: [PATCH 24/60] Map: processSingleplayerEvents bumps the event year as a field update The decompiler routed every year increment through the reused condition-flag pointer; write it as a direct field update instead. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 60 +++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index fa640c4d50..9889d4a9fc 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -1234,8 +1234,8 @@ namespace Map { + ((int)uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (0xb < iVar18) { - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; } LAB_004c4621: @@ -1351,8 +1351,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1398,8 +1398,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1445,8 +1445,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1497,8 +1497,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1536,8 +1536,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1597,8 +1597,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1676,8 +1676,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1759,8 +1759,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1814,8 +1814,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1955,8 +1955,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -2067,8 +2067,8 @@ namespace Map { iVar22 = DAT_GameState::instance.mapAndTime.month + 1; this->scenarioEvents[_eventIndex].header.month = iVar22; if (0xb < iVar22) { - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xb; MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::sortEventsByDate, this)(); @@ -2155,8 +2155,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -2215,8 +2215,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + 1; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -2502,8 +2502,8 @@ namespace Map { if (!_repeatMonths) { this->scenarioEvents[_eventIndex].header.done = 1; } else { - _pConditionIsMet = &this->scenarioEvents[_eventIndex].header.year; - *_pConditionIsMet = *_pConditionIsMet + _repeatMonths / 0xc; + this->scenarioEvents[_eventIndex].header.year + = this->scenarioEvents[_eventIndex].header.year + _repeatMonths / 0xc; iVar18 = this->scenarioEvents[_eventIndex].header.year; this->scenarioEvents[_eventIndex].header.month = this->scenarioEvents[_eventIndex].header.month + _repeatMonths % 0xc; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 174ebc7d39..3df24c3465 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 52.0% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp +SHC_3BB0A8C1_0x004C31A0 | 52.4% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 2b29afe0e9811ca600682ab27b766884c02f8a45 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 19:00:35 +0100 Subject: [PATCH 25/60] types: SkMasters2 version, count and entries as one SkMasters2Data global 0x00DF6248..0x00EB0AB0 is one block in the original: the float version, the entry count and the 250 SkMasterDataEntry records. As three separate globals the compiler knows a copied entry cannot overwrite the count and keeps it in a register; the original re-reads it after every struct copy, which is what it does for a variable index into one object. The three resolvers become DAT_SkMasters2Data (IO::SkMasters2Data) and every user moves to its fields. Matches with the new layout: SkirmishLeaderboard_DeleteEntry 34.5 -> 100, StoreGameIntoSKMasters 87.4 -> 100; readSkMasters2, WriteSkMasters2, Skirmish_SortAIOpponentOrder and MenuItemActionHandler_RankingGames_Main still differ only in labels. The Ghidra project still has the three separate labels, so the next header import will regenerate them unless the struct is applied there. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../SkirmishLeaderboard_DeleteEntry.cpp | 12 +++-- .../Skirmish_PrepareLeaderboardView.cpp | 45 +++++++++---------- .../Skirmish/Skirmish_SortAIOpponentOrder.cpp | 6 +-- .../Game/Skirmish/StoreGameIntoSKMasters.cpp | 15 +++---- src/OpenSHC/Globals/DAT_SkMasters2Data.hpp | 23 ++++++++++ .../Globals/DAT_SkMasters2DataArray.hpp | 23 ---------- .../Globals/DAT_SkMasters2Data_Count.hpp | 19 -------- .../Globals/DAT_SkMasters2Data_Version.hpp | 19 -------- src/OpenSHC/IO/SkMasters2Data.hpp | 29 ++++++++++++ src/OpenSHC/IO/WriteSkMasters2.cpp | 14 +++--- src/OpenSHC/IO/readSkMasters2.cpp | 12 +++-- ...enuItemActionHandler_RankingGames_Main.cpp | 10 ++--- 12 files changed, 105 insertions(+), 122 deletions(-) create mode 100644 src/OpenSHC/Globals/DAT_SkMasters2Data.hpp delete mode 100644 src/OpenSHC/Globals/DAT_SkMasters2DataArray.hpp delete mode 100644 src/OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp delete mode 100644 src/OpenSHC/Globals/DAT_SkMasters2Data_Version.hpp create mode 100644 src/OpenSHC/IO/SkMasters2Data.hpp diff --git a/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp b/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp index a3262bf113..e25512f7f9 100644 --- a/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp +++ b/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp @@ -3,8 +3,7 @@ #include "OpenSHC/IO.func.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" namespace OpenSHC { namespace Game { @@ -18,13 +17,12 @@ namespace Game { // FUNCTION: STRONGHOLDCRUSADER 0x004D5370 void Skirmish::SkirmishLeaderboard_DeleteEntry(int index) { - if (index >= 0 && index < DAT_SkMasters2Data_Count::instance) { + if (index >= 0 && index < DAT_SkMasters2Data::instance.count) { // close the gap by moving every later entry up one - for (int i = index; i < DAT_SkMasters2Data_Count::instance - 1; i++) { - SkMasterDataEntry& entry = DAT_SkMasters2DataArray::instance[i]; - entry = DAT_SkMasters2DataArray::instance[i + 1]; + for (int i = index; i < DAT_SkMasters2Data::instance.count - 1; i++) { + DAT_SkMasters2Data::instance.entries[i] = DAT_SkMasters2Data::instance.entries[i + 1]; } - DAT_SkMasters2Data_Count::instance = DAT_SkMasters2Data_Count::instance - 1; + DAT_SkMasters2Data::instance.count = DAT_SkMasters2Data::instance.count - 1; MACRO_CALL(IO_Func::WriteSkMasters2)(); } } diff --git a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp index 5381b6a638..ff9dcc6089 100644 --- a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp +++ b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp @@ -6,8 +6,7 @@ #include "OpenSHC/Globals/DAT_00ed3124.hpp" #include "OpenSHC/Globals/DAT_MissionDefinedData.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" #include "OpenSHC/Globals/DAT_TextManagerObject.hpp" #include "OpenSHC/Globals/INT_00eb9b60.hpp" #include "OpenSHC/Globals/INT_00ed2bdc.hpp" @@ -24,19 +23,19 @@ namespace Game { // FUNCTION: STRONGHOLDCRUSADER 0x004D9400 void Skirmish::Skirmish_PrepareLeaderboardView() { - for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { INT_ARRAY_00eb0e48::instance[i] = 1; } // filter 1 hides the custom maps (no trail mission score), filter 2 the trail missions if (DAT_00ed3124::instance == 1) { - for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { - if (!DAT_SkMasters2DataArray::instance[i].score) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + if (!DAT_SkMasters2Data::instance.entries[i].score) { INT_ARRAY_00eb0e48::instance[i] = 0; } } } else if (DAT_00ed3124::instance == 2) { - for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { - if (DAT_SkMasters2DataArray::instance[i].score) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + if (DAT_SkMasters2Data::instance.entries[i].score) { INT_ARRAY_00eb0e48::instance[i] = 0; } } @@ -45,14 +44,14 @@ namespace Game { if (DAT_MissionDefinedData::instance.sortColumn <= 1) { INT_00eb9b60::instance = 0; if (DAT_MissionDefinedData::instance.descending == 1) { - for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { if (INT_ARRAY_00eb0e48::instance[i] != 0) { INT_ARRAY_00eb96d8::instance[INT_00eb9b60::instance] = i; INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } } } else if (!DAT_MissionDefinedData::instance.descending) { - for (int left = DAT_SkMasters2Data_Count::instance, i = DAT_SkMasters2Data_Count::instance - 1; i >= 0; + for (int left = DAT_SkMasters2Data::instance.count, i = DAT_SkMasters2Data::instance.count - 1; i >= 0; left--, i--) { if (INT_ARRAY_00eb0e48::instance[left - 1] != 0) { INT_ARRAY_00eb96d8::instance[INT_00eb9b60::instance] = i; @@ -65,14 +64,14 @@ namespace Game { // date if (DAT_MissionDefinedData::instance.sortColumn == 4) { INT_00eb9b60::instance = 0; - for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { if (INT_ARRAY_00eb0e48::instance[i] != 0) { INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] - = ((DAT_SkMasters2DataArray::instance[i].localTimeYear - 2000) * 16 - + DAT_SkMasters2DataArray::instance[i].localTimeMonth) + = ((DAT_SkMasters2Data::instance.entries[i].localTimeYear - 2000) * 16 + + DAT_SkMasters2Data::instance.entries[i].localTimeMonth) * 32 - + DAT_SkMasters2DataArray::instance[i].localTimeDay; + + DAT_SkMasters2Data::instance.entries[i].localTimeDay; INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } } @@ -83,28 +82,28 @@ namespace Game { if (DAT_MissionDefinedData::instance.sortColumn == 2) { INT_00eb9b60::instance = 0; if (DAT_00ed3124::instance == 1) { - for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { if (INT_ARRAY_00eb0e48::instance[i] != 0) { INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] - = 0x50 - DAT_SkMasters2DataArray::instance[i].score; + = 0x50 - DAT_SkMasters2Data::instance.entries[i].score; INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } } } else { - for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { if (INT_ARRAY_00eb0e48::instance[i] != 0) { - if (DAT_SkMasters2DataArray::instance[i].score) { - strcpy(DAT_SkMasters2DataArray::instance[i].mapName, + if (DAT_SkMasters2Data::instance.entries[i].score) { + strcpy(DAT_SkMasters2Data::instance.entries[i].mapName, MACRO_CALL_MEMBER( Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)( - DE::SHCDE::TEXT_TRAIL_NAMES_CRU, DAT_SkMasters2DataArray::instance[i].score)); + DE::SHCDE::TEXT_TRAIL_NAMES_CRU, DAT_SkMasters2Data::instance.entries[i].score)); } - byte first = DAT_SkMasters2DataArray::instance[i].mapName[0]; + byte first = DAT_SkMasters2Data::instance.entries[i].mapName[0]; if (first >= 'A' && first <= 'Z') { first = first + 0x20; } - byte second = DAT_SkMasters2DataArray::instance[i].mapName[1]; + byte second = DAT_SkMasters2Data::instance.entries[i].mapName[1]; if (second >= 'A' && second <= 'Z') { second = second + 0x20; } @@ -120,11 +119,11 @@ namespace Game { // duration if (DAT_MissionDefinedData::instance.sortColumn == 3) { INT_00eb9b60::instance = 0; - for (int i = 0; i < DAT_SkMasters2Data_Count::instance; i++) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { if (INT_ARRAY_00eb0e48::instance[i] != 0) { INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] - = -1 - DAT_SkMasters2DataArray::instance[i].gameDurationInMinutes; + = -1 - DAT_SkMasters2Data::instance.entries[i].gameDurationInMinutes; INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } } diff --git a/src/OpenSHC/Game/Skirmish/Skirmish_SortAIOpponentOrder.cpp b/src/OpenSHC/Game/Skirmish/Skirmish_SortAIOpponentOrder.cpp index b017ae141d..c6adb4d040 100644 --- a/src/OpenSHC/Game/Skirmish/Skirmish_SortAIOpponentOrder.cpp +++ b/src/OpenSHC/Game/Skirmish/Skirmish_SortAIOpponentOrder.cpp @@ -2,7 +2,7 @@ #include "OpenSHC/Globals/DAT_00ed3124.hpp" #include "OpenSHC/Globals/DAT_MissionDefinedData.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" #include "OpenSHC/Globals/INT_00eb9b60.hpp" #include "OpenSHC/Globals/INT_ARRAY_00eb96d8.hpp" #include "OpenSHC/Globals/INT_ARRAY_00ed27f0.hpp" @@ -39,9 +39,9 @@ namespace Game { int swaps = 0; for (int i = 1; i < (int)INT_00eb9b60::instance; ++i) { OpenSHC::IO::SkMasterDataEntry* const a - = &DAT_SkMasters2DataArray::instance[INT_ARRAY_00eb96d8::instance[i - 1]]; + = &DAT_SkMasters2Data::instance.entries[INT_ARRAY_00eb96d8::instance[i - 1]]; OpenSHC::IO::SkMasterDataEntry* const b - = &DAT_SkMasters2DataArray::instance[INT_ARRAY_00eb96d8::instance[i]]; + = &DAT_SkMasters2Data::instance.entries[INT_ARRAY_00eb96d8::instance[i]]; if (_stricmp(a->mapName, b->mapName) > 0) { int const swap = INT_ARRAY_00eb96d8::instance[i]; INT_ARRAY_00eb96d8::instance[i] = INT_ARRAY_00eb96d8::instance[i - 1]; diff --git a/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp b/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp index 37c17b8fc5..b06dfd56fe 100644 --- a/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp +++ b/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp @@ -5,8 +5,7 @@ #include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" #include "OpenSHC/Globals/DAT_SkMasterDataEntry.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" namespace OpenSHC { namespace Game { @@ -19,7 +18,7 @@ namespace Game { if (!MACRO_CALL(Game::Skirmish_Func::StoreCurrentGameIntoTemporarySKMasterEntry)(score)) { return; } - int count = DAT_SkMasters2Data_Count::instance; + int count = DAT_SkMasters2Data::instance.count; int insertIndex = -1; if (count <= 0) { insertIndex = 0; @@ -30,7 +29,7 @@ namespace Game { if (insertIndex != 0) { for (int i = 0; i < count; i++) { if (DAT_SkMasterDataEntry::instance.skMasterScore - > DAT_SkMasters2DataArray::instance[i].skMasterScore) { + > DAT_SkMasters2Data::instance.entries[i].skMasterScore) { insertIndex = i; break; } @@ -41,12 +40,12 @@ namespace Game { } for (; count > insertIndex; count--) { if (count <= 249) { - DAT_SkMasters2DataArray::instance[count] = DAT_SkMasters2DataArray::instance[count - 1]; + DAT_SkMasters2Data::instance.entries[count] = DAT_SkMasters2Data::instance.entries[count - 1]; } } - DAT_SkMasters2DataArray::instance[insertIndex] = DAT_SkMasterDataEntry::instance; - if (DAT_SkMasters2Data_Count::instance < 250) { - DAT_SkMasters2Data_Count::instance = DAT_SkMasters2Data_Count::instance + 1; + DAT_SkMasters2Data::instance.entries[insertIndex] = DAT_SkMasterDataEntry::instance; + if (DAT_SkMasters2Data::instance.count < 250) { + DAT_SkMasters2Data::instance.count = DAT_SkMasters2Data::instance.count + 1; } MACRO_CALL(IO_Func::WriteSkMasters2)(); } diff --git a/src/OpenSHC/Globals/DAT_SkMasters2Data.hpp b/src/OpenSHC/Globals/DAT_SkMasters2Data.hpp new file mode 100644 index 0000000000..babeb81759 --- /dev/null +++ b/src/OpenSHC/Globals/DAT_SkMasters2Data.hpp @@ -0,0 +1,23 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Globals/DAT_SkMasters2Data.hpp' +*/ + +#pragma once + +#include "OpenSHC/IO/SkMasters2Data.hpp" + +// GLOBAL: STRONGHOLDCRUSADER 0x00DF6248 +// StructResolver::Instance::instance + +namespace OpenSHC { + +using OpenSHC::IO::SkMasters2Data; + +MACRO_STRUCT_RESOLVER(SkMasters2Data, false, Address::SHC_3BB0A8C1_0x00DF6248) DAT_SkMasters2Data; +} // namespace OpenSHC + +MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00DF6248); diff --git a/src/OpenSHC/Globals/DAT_SkMasters2DataArray.hpp b/src/OpenSHC/Globals/DAT_SkMasters2DataArray.hpp deleted file mode 100644 index 68e614c4fe..0000000000 --- a/src/OpenSHC/Globals/DAT_SkMasters2DataArray.hpp +++ /dev/null @@ -1,23 +0,0 @@ -/** - THIS FILE IS AUTO GENERATED - Communicate changes to the dev team (e.g. via a Pull Request). - Changes get lost otherwise. - - path: 'OpenSHC/Globals/DAT_SkMasters2DataArray.hpp' -*/ - -#pragma once - -#include "OpenSHC/IO/SkMasterDataEntry.hpp" - -// GLOBAL: STRONGHOLDCRUSADER 0x00DF6250 -// StructResolver::Instance::instance - -namespace OpenSHC { - -using OpenSHC::IO::SkMasterDataEntry; - -MACRO_STRUCT_RESOLVER(SkMasterDataEntry[250], false, Address::SHC_3BB0A8C1_0x00DF6250) DAT_SkMasters2DataArray; -} // namespace OpenSHC - -MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00DF6250); diff --git a/src/OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp b/src/OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp deleted file mode 100644 index 0b78178c47..0000000000 --- a/src/OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/** - THIS FILE IS AUTO GENERATED - Communicate changes to the dev team (e.g. via a Pull Request). - Changes get lost otherwise. - - path: 'OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp' -*/ - -#pragma once - -// GLOBAL: STRONGHOLDCRUSADER 0x00DF624C -// StructResolver::Instance::instance - -namespace OpenSHC { - -MACRO_STRUCT_RESOLVER(int, false, Address::SHC_3BB0A8C1_0x00DF624C) DAT_SkMasters2Data_Count; -} // namespace OpenSHC - -MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00DF624C); diff --git a/src/OpenSHC/Globals/DAT_SkMasters2Data_Version.hpp b/src/OpenSHC/Globals/DAT_SkMasters2Data_Version.hpp deleted file mode 100644 index 7d03a88cfe..0000000000 --- a/src/OpenSHC/Globals/DAT_SkMasters2Data_Version.hpp +++ /dev/null @@ -1,19 +0,0 @@ -/** - THIS FILE IS AUTO GENERATED - Communicate changes to the dev team (e.g. via a Pull Request). - Changes get lost otherwise. - - path: 'OpenSHC/Globals/DAT_SkMasters2Data_Version.hpp' -*/ - -#pragma once - -// GLOBAL: STRONGHOLDCRUSADER 0x00DF6248 -// StructResolver::Instance::instance - -namespace OpenSHC { - -MACRO_STRUCT_RESOLVER(float, false, Address::SHC_3BB0A8C1_0x00DF6248) DAT_SkMasters2Data_Version; -} // namespace OpenSHC - -MACRO_STRUCT_INSTANCE(Address::SHC_3BB0A8C1_0x00DF6248); diff --git a/src/OpenSHC/IO/SkMasters2Data.hpp b/src/OpenSHC/IO/SkMasters2Data.hpp new file mode 100644 index 0000000000..18722a6445 --- /dev/null +++ b/src/OpenSHC/IO/SkMasters2Data.hpp @@ -0,0 +1,29 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/IO/SkMasters2Data.hpp' +*/ + +#pragma once + +#include "OpenSHC/IO/SkMasterDataEntry.hpp" + +namespace OpenSHC { +namespace IO { + +#pragma pack(push, 1) + // SIZE: 0x000BA868 + typedef struct SkMasters2Data { + + float version; // 0x00000000 length: 4 + int count; // 0x00000004 length: 4 + SkMasterDataEntry entries[250]; // 0x00000008 length: 764000 + + } SkMasters2Data; +#pragma pack(pop) + + static_assert_cpp98_obj(sizeof(SkMasters2Data) == 764008, SkMasters2Data); +} // namespace IO +} // namespace OpenSHC diff --git a/src/OpenSHC/IO/WriteSkMasters2.cpp b/src/OpenSHC/IO/WriteSkMasters2.cpp index 74fe85b12d..ca20ccd377 100644 --- a/src/OpenSHC/IO/WriteSkMasters2.cpp +++ b/src/OpenSHC/IO/WriteSkMasters2.cpp @@ -8,16 +8,14 @@ #include "OpenSHC/string-literals.hpp" #include "OpenSHC/Globals/DAT_ResourceManager.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2Data_Version.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" namespace OpenSHC { // FUNCTION: STRONGHOLDCRUSADER 0x004D5180 void IO::WriteSkMasters2() { - if (DAT_SkMasters2Data_Count::instance < 1) { + if (DAT_SkMasters2Data::instance.count < 1) { return; } @@ -32,11 +30,11 @@ void IO::WriteSkMasters2() } MACRO_CALL(OpenSHC::OS_Func::_fwrite)( - DAT_SkMasters2Data_Version::ptr, sizeof(DAT_SkMasters2Data_Version::instance), 1, _File); + &DAT_SkMasters2Data::instance.version, sizeof(DAT_SkMasters2Data::instance.version), 1, _File); MACRO_CALL(OpenSHC::OS_Func::_fwrite)( - DAT_SkMasters2Data_Count::ptr, sizeof(DAT_SkMasters2Data_Count::instance), 1, _File); - MACRO_CALL(OpenSHC::OS_Func::_fwrite)(DAT_SkMasters2DataArray::instance, - sizeof(DAT_SkMasters2DataArray::instance[0]), DAT_SkMasters2Data_Count::instance, _File); + &DAT_SkMasters2Data::instance.count, sizeof(DAT_SkMasters2Data::instance.count), 1, _File); + MACRO_CALL(OpenSHC::OS_Func::_fwrite)(DAT_SkMasters2Data::instance.entries, + sizeof(DAT_SkMasters2Data::instance.entries[0]), DAT_SkMasters2Data::instance.count, _File); MACRO_CALL(OpenSHC::OS_Func::_fclose)(_File); } diff --git a/src/OpenSHC/IO/readSkMasters2.cpp b/src/OpenSHC/IO/readSkMasters2.cpp index df25bfca1d..c91b975a05 100644 --- a/src/OpenSHC/IO/readSkMasters2.cpp +++ b/src/OpenSHC/IO/readSkMasters2.cpp @@ -8,17 +8,15 @@ #include "OpenSHC/string-literals.hpp" #include "OpenSHC/Globals/DAT_ResourceManager.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2Data_Count.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2Data_Version.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" namespace OpenSHC { // FUNCTION: STRONGHOLDCRUSADER 0x004D5010 void IO::ReadSkMasters2() { - DAT_SkMasters2Data_Version::instance = 3.0; - DAT_SkMasters2Data_Count::instance = 0; + DAT_SkMasters2Data::instance.version = 3.0; + DAT_SkMasters2Data::instance.count = 0; char path[1000]; // NOTE: Direct use to support copy elision @@ -44,9 +42,9 @@ void IO::ReadSkMasters2() return; } - DAT_SkMasters2Data_Count::instance = _count; + DAT_SkMasters2Data::instance.count = _count; MACRO_CALL(OpenSHC::OS_Func::_fread)( - DAT_SkMasters2DataArray::instance, sizeof(DAT_SkMasters2DataArray::instance[0]), _count, file); + DAT_SkMasters2Data::instance.entries, sizeof(DAT_SkMasters2Data::instance.entries[0]), _count, file); MACRO_CALL(OpenSHC::OS_Func::_fclose)(file); } diff --git a/src/OpenSHC/UI/MenuItems/RankingGames/MenuItemActionHandler_RankingGames_Main.cpp b/src/OpenSHC/UI/MenuItems/RankingGames/MenuItemActionHandler_RankingGames_Main.cpp index 8f3d1ff79c..68b50d337c 100644 --- a/src/OpenSHC/UI/MenuItems/RankingGames/MenuItemActionHandler_RankingGames_Main.cpp +++ b/src/OpenSHC/UI/MenuItems/RankingGames/MenuItemActionHandler_RankingGames_Main.cpp @@ -20,7 +20,7 @@ #include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" #include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp" #include "OpenSHC/Globals/DAT_MissionDefinedData.hpp" -#include "OpenSHC/Globals/DAT_SkMasters2DataArray.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" #include "OpenSHC/Globals/DAT_StoredGameMode.hpp" #include "OpenSHC/Globals/INT_00eb9b60.hpp" #include "OpenSHC/Globals/INT_00ed3120.hpp" @@ -49,20 +49,20 @@ namespace UI { // buttons 0 to 7 are the rows: a row shows that game's end screen if (button < 8 && INT_00ed3120::instance + button < INT_00eb9b60::instance) { int const game = INT_ARRAY_00eb96d8::instance[INT_00ed3120::instance + button]; - DAT_GameSynchronyState::instance.finalResults = DAT_SkMasters2DataArray::instance[game].results; + DAT_GameSynchronyState::instance.finalResults = DAT_SkMasters2Data::instance.entries[game].results; DAT_GameCore::instance.gameMode_2 = OpenSHC::Game::GM_SKIRMISH_AND_MULTIPLAYER; DAT_GameSynchronyState::instance.currentGameMode = OpenSHC::Game::GM_SKIRMISH_END_OF_GAME_SINGLE_PLAYER; - if (DAT_SkMasters2DataArray::instance[game].aliveArray[1] != 0) { + if (DAT_SkMasters2Data::instance.entries[game].aliveArray[1] != 0) { // "win_screen_crusader.tgx" strcpy(CHAR_ARRAY_00eb9ac8::instance, S_WIN_SCREEN_CRUSADER_TGX_005AB024); - if (DAT_SkMasters2DataArray::instance[game].lordType != 0) { + if (DAT_SkMasters2Data::instance.entries[game].lordType != 0) { // "win_screen_arab.tgx" strcpy(CHAR_ARRAY_00eb9ac8::instance, S_WIN_SCREEN_ARAB_TGX_005AB010); } } else { // "lose_screen_crusader.tgx" strcpy(CHAR_ARRAY_00eb9ac8::instance, S_LOSE_SCREEN_CRUSADER_TGX_005AAFF4); - if (DAT_SkMasters2DataArray::instance[game].lordType != 0) { + if (DAT_SkMasters2Data::instance.entries[game].lordType != 0) { // "lose_screen_arab.tgx" strcpy(CHAR_ARRAY_00eb9ac8::instance, S_LOSE_SCREEN_ARAB_TGX_005AAFDC); } From 090e95592002c55b6cce7b1bd7b005a33b8b494d Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 19:00:52 +0100 Subject: [PATCH 26/60] Skirmish: leaderboard delete and store match with the SkMasters2Data global Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- status/addresses-SHC-3BB0A8C1.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3df24c3465..7ce906dd1d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -35565,9 +35565,9 @@ SHC_3BB0A8C1_0x004D5010 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D5180 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004D52A0 | 87.4% | Count/entries struct aliasing +SHC_3BB0A8C1_0x004D52A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004D5370 | 34.5% | count and entries are one struct in the original +SHC_3BB0A8C1_0x004D5370 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D53A0 | 0.0% | Pending From 37d62413d9199d31c8301ac05cf4731d1455b34f Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 19:15:25 +0100 Subject: [PATCH 27/60] Map: processSingleplayerEvents bound tests with the literals the asm uses The month rollover and the invasion counter wrap test `>= 12` and `>= 50` (cmp 0xc / 0x32; jl), not Ghidra's `0xb <` and `0x31 <`. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 14 +++++++------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 9889d4a9fc..3be0f752a4 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -1233,7 +1233,7 @@ namespace Map { iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month + ((int)uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; - if (0xb < iVar18) { + if (iVar18 >= 12) { this->scenarioEvents[_eventIndex].header.year = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; @@ -1692,7 +1692,7 @@ namespace Map { .eventBanditsCountdown = 0x10; DAT_TroopValueState::instance.attackInfo.inv_count = DAT_TroopValueState::instance.attackInfo.inv_count + 1; - if (0x31 < DAT_TroopValueState::instance.attackInfo.inv_count) { + if (DAT_TroopValueState::instance.attackInfo.inv_count >= 50) { DAT_TroopValueState::instance.attackInfo.inv_count = 1; } MACRO_CALL_MEMBER( @@ -2066,7 +2066,7 @@ namespace Map { iVar18 = DAT_GameState::instance.mapAndTime.month; iVar22 = DAT_GameState::instance.mapAndTime.month + 1; this->scenarioEvents[_eventIndex].header.month = iVar22; - if (0xb < iVar22) { + if (iVar22 >= 12) { this->scenarioEvents[_eventIndex].header.year = this->scenarioEvents[_eventIndex].header.year + 1; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xb; @@ -2241,7 +2241,7 @@ namespace Map { == -1) { DAT_TroopValueState::instance.attackInfo.inv_count = DAT_TroopValueState::instance.attackInfo.inv_count + 1; - if (0x31 < DAT_TroopValueState::instance.attackInfo.inv_count) { + if (DAT_TroopValueState::instance.attackInfo.inv_count >= 50) { DAT_TroopValueState::instance.attackInfo.inv_count = 1; } MACRO_CALL_MEMBER(Map::Units::TroopValueState_Func::initializeAttackWaveSlot, @@ -2509,7 +2509,7 @@ namespace Map { = this->scenarioEvents[_eventIndex].header.month + _repeatMonths % 0xc; iVar22 = this->scenarioEvents[_eventIndex].header.month; this->scenarioEvents[_eventIndex].header.pre_done = 0; - if (0xb < iVar22) { + if (iVar22 >= 12) { this->scenarioEvents[_eventIndex].header.month = iVar22 + -0xc; this->scenarioEvents[_eventIndex].header.year = iVar18 + 1; } @@ -2524,7 +2524,7 @@ namespace Map { } iVar18 = DAT_GameState::instance.mapAndTime.month + 3; local_88 = DAT_GameState::instance.mapAndTime.year; - if (0xb < iVar18) { + if (iVar18 >= 12) { iVar18 = DAT_GameState::instance.mapAndTime.month + -9; local_88 = DAT_GameState::instance.mapAndTime.year + 1; } @@ -2594,7 +2594,7 @@ namespace Map { && (DAT_GameState::instance.mapAndTime.week == 3)) { iVar22 = DAT_GameState::instance.mapAndTime.month + 1; iVar18 = DAT_GameState::instance.mapAndTime.year; - if (0xb < iVar22) { + if (iVar22 >= 12) { iVar22 = DAT_GameState::instance.mapAndTime.month + -0xb; iVar18 = DAT_GameState::instance.mapAndTime.year + 1; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 7ce906dd1d..4a3bf4527e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 52.4% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp +SHC_3BB0A8C1_0x004C31A0 | 52.6% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From be7d70c1c27ee27d2160214b2bd2919e2d1e90cb Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 19:40:21 +0100 Subject: [PATCH 28/60] Map: processSingleplayerEvents clears the win type before choosing it The original stores 0 to field133_0x145d8 before testing which goal conditions are set, and compares the pending-invasion month as `month > event.month`. Restoring the store keeps the two `= 1` arms apart as in the original (the polarity flip at 0x4c41cc is gone); the match is unchanged to one decimal. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/MapPropertiesState/processSingleplayerEvents.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 3be0f752a4..f5f4ced93a 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -966,8 +966,8 @@ namespace Map { <= DAT_GameState::instance.mapAndTime.year && (DAT_GameState::instance.mapAndTime.year != this->scenarioEvents[iVar18].header.year - || this->scenarioEvents[iVar18].header.month - < DAT_GameState::instance.mapAndTime.month)) + || DAT_GameState::instance.mapAndTime.month + > this->scenarioEvents[iVar18].header.month)) goto switchD_004c382e_caseD_2; } if (((DAT_GameCore::instance.gameMode_2 == Game::GM_CAMPAIGN_MISSION) @@ -1002,6 +1002,7 @@ namespace Map { MACRO_CALL_MEMBER(Input::MouseState_Func::resetMouseCursorState, DAT_MouseState::ptr)(); } + this->field133_0x145d8 = 0; if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x13) != 0) { this->field133_0x145d8 = 1; @@ -2054,8 +2055,8 @@ namespace Map { <= DAT_GameState::instance.mapAndTime.year && (DAT_GameState::instance.mapAndTime.year != this->scenarioEvents[iVar18].header.year - || this->scenarioEvents[iVar18].header.month - < DAT_GameState::instance.mapAndTime.month)) + || DAT_GameState::instance.mapAndTime.month + > this->scenarioEvents[iVar18].header.month)) goto switchD_004c382e_caseD_2; } this->scenarioEvents[_eventIndex].header.done = 0; From 369631274e8ddc0e7c0d355bfe4cfe0c8a3696c0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 19:50:23 +0100 Subject: [PATCH 29/60] Map: processSingleplayerEvents year rollovers as year++ Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 42 +++++++------------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index f5f4ced93a..d35dd98c09 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -1235,8 +1235,7 @@ namespace Map { + ((int)uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 >= 12) { - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; } LAB_004c4621: @@ -1352,8 +1351,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1399,8 +1397,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1446,8 +1443,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1498,8 +1494,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1537,8 +1532,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1598,8 +1592,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1677,8 +1670,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1760,8 +1752,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1815,8 +1806,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -1956,8 +1946,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -2068,8 +2057,7 @@ namespace Map { iVar22 = DAT_GameState::instance.mapAndTime.month + 1; this->scenarioEvents[_eventIndex].header.month = iVar22; if (iVar22 >= 12) { - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xb; MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::sortEventsByDate, this)(); @@ -2156,8 +2144,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; @@ -2216,8 +2203,7 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; - this->scenarioEvents[_eventIndex].header.year - = this->scenarioEvents[_eventIndex].header.year + 1; + this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 4a3bf4527e..101d68d6ac 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 52.6% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), action-case order measured worse in reccmp +SHC_3BB0A8C1_0x004C31A0 | 52.7% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), year += 1 kept in a register where the original adds an immediate SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 9d66ced66bfca6ae9df7536ece8b88a6e8131174 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 20:01:18 +0100 Subject: [PATCH 30/60] Map: processSingleplayerEvents mode arms share the final banner call The original never merges the stack cleanup of the two banner calls and keeps a separate epilogue copy per game mode: each arm makes one call and then joins a common `call; return`, which MSVC duplicates into its predecessors. Writing the modes as an else-if chain ending in that shared call reproduces it, and the builder arm's early exit becomes an else. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 56 ++++++++----------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index d35dd98c09..f8531791a3 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -197,11 +197,7 @@ namespace Map { } MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - return; - } - if (DAT_GameCore::instance.gameMode_2 == Game::GM_ECONOMIC_CAMPAIGN_SH1) { + } else if (DAT_GameCore::instance.gameMode_2 == Game::GM_ECONOMIC_CAMPAIGN_SH1) { if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .playerDeathRelated @@ -217,41 +213,35 @@ namespace Map { } MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - return; - } - if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { + } else if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { if (DAT_GameCore::instance.field_0x6c) { DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 7; MACRO_CALL(UI::MenuItems::General_Func:: MenuItemActionHandler_General_LaunchOrQuitMultiplayerGameUnk)(0x16); - MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( - UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); - return; - } - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 1) { - if ((int)DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 < 2) { + } else { + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 1) { + if ((int)DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 < 2) { + MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( + UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); + } else { + DAT_GameCore::instance.section1095 = 1; + DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 0x2f; + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, + DAT_MenuTextInputState::ptr)(UI::Enums::MMT_QUIT_DIALOG); + } + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 2) { MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0); - } else { - DAT_GameCore::instance.section1095 = 1; - DAT_MenuTextInputState::instance.DAT_MenuOptionsActionParameter = 0x2f; - MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, - DAT_MenuTextInputState::ptr)(UI::Enums::MMT_QUIT_DIALOG); + UI::Enums::MVT_GAME_LOSTUnk, 0); } + DAT_GameCore::instance.section1066 = 2; } - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 2) { - MACRO_CALL_MEMBER(Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)( - UI::Enums::MVT_GAME_LOSTUnk, 0); - } - DAT_GameCore::instance.section1066 = 2; } MACRO_CALL(UI::DisplayElements_Func::CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_MISSION_WIN_DEFEAT_BANNER, 0); diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 101d68d6ac..a38fd118fd 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 52.7% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), year += 1 kept in a register where the original adds an immediate +SHC_3BB0A8C1_0x004C31A0 | 53.5% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), one fewer epilogue copy SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From b443bad1c270d582d2e8b08595a7f0dc3b75a0d4 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 20:03:06 +0100 Subject: [PATCH 31/60] Map: processSingleplayerEvents returns after the forced player loss When unknownAlwaysZero is set the original marks the player dead, clears the flag, sets the countdown and returns (0x4c3491). The reimplementation fell through into the timer update and the day's event processing. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/MapPropertiesState/processSingleplayerEvents.cpp | 1 + status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index f8531791a3..5fde74c7aa 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -257,6 +257,7 @@ namespace Map { .playerDeathRelated = 1; DAT_GameCore::instance.unknownAlwaysZero = 0; DAT_GameState::instance.mapAndTime.unknownCountdown01 = 10; + return; } _pConditionIsMet = DAT_GameState::instance.mapAndTime.scenarioEventTimers; do { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index a38fd118fd..6ab7cfe7db 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 53.5% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short), one fewer epilogue copy +SHC_3BB0A8C1_0x004C31A0 | 54.3% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short) SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 7a40807abf1c118eda3043df74679e8700271b18 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 20:11:44 +0100 Subject: [PATCH 32/60] Map: processSingleplayerEvents next-month rollover from month + 1 The original keeps only the incremented month and subtracts 12 from it (add eax, -0xc), rather than holding the old month and subtracting 11. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/MapPropertiesState/processSingleplayerEvents.cpp | 3 +-- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 5fde74c7aa..c04720e457 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -2044,12 +2044,11 @@ namespace Map { this->scenarioEvents[_eventIndex].header.year = DAT_GameState::instance.mapAndTime.year; LAB_004c4072: - iVar18 = DAT_GameState::instance.mapAndTime.month; iVar22 = DAT_GameState::instance.mapAndTime.month + 1; this->scenarioEvents[_eventIndex].header.month = iVar22; if (iVar22 >= 12) { this->scenarioEvents[_eventIndex].header.year++; - this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xb; + this->scenarioEvents[_eventIndex].header.month = iVar22 - 12; MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6ab7cfe7db..57d7fd819c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 54.3% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short) +SHC_3BB0A8C1_0x004C31A0 | 54.7% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short) SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 90bfe5aacf202209d69b39ccf29461270c2b98b0 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 20:45:52 +0100 Subject: [PATCH 33/60] Map: processSingleplayerEvents repeat delay as a signed int The original tests the repeat delay with `cmp ecx, 4; jl` (signed `>= 4`) at all 13 rescheduling sites; the decompiler's uint and `3 < x` compiled to unsigned `jbe`. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 158 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 80 insertions(+), 80 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index c04720e457..cc25364cf2 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -114,7 +114,7 @@ namespace Map { InGameEventUnionVersion* pIVar16; char cVar17; int iVar18; - uint uVar19; + int uVar19; int _unitSpawnTotalAdjustment; int iVar20; int numInGroup; @@ -1215,15 +1215,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 >= 12) { this->scenarioEvents[_eventIndex].header.year++; @@ -1330,15 +1330,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -1376,15 +1376,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -1422,15 +1422,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -1473,15 +1473,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -1511,15 +1511,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -1571,15 +1571,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -1649,15 +1649,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -1731,15 +1731,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -1785,15 +1785,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -1925,15 +1925,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -2122,15 +2122,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; @@ -2181,15 +2181,15 @@ namespace Map { if (bVar5 != 10) { this->scenarioEvents[_eventIndex].data.scenario.repeatMonths = bVar5 - 1; } - uVar19 = (uint)bVar4; + uVar19 = bVar4; this->scenarioEvents[_eventIndex].header.done = 0; - if (3 < uVar19) { - uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % ((int)uVar19 / 4); + if (uVar19 >= 4) { + uVar19 = uVar19 + (int)SEC_RNG::instance.currentNumber2 % (uVar19 / 4); } this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year + (int)uVar19 / 0xc; - iVar18 = uVar19 + DAT_GameState::instance.mapAndTime.month - + ((int)uVar19 / 0xc) * -0xc; + = DAT_GameState::instance.mapAndTime.year + uVar19 / 0xc; + iVar18 + = uVar19 + DAT_GameState::instance.mapAndTime.month + (uVar19 / 0xc) * -0xc; this->scenarioEvents[_eventIndex].header.month = iVar18; if (iVar18 < 0xc) goto LAB_004c4621; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 57d7fd819c..d5ded9b95c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 54.7% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short) +SHC_3BB0A8C1_0x004C31A0 | 55.5% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short) SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From c8063201e68c3dae5d2b3bcd0f2c53d113dcee61 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 20:52:22 +0100 Subject: [PATCH 34/60] Map: processSingleplayerEvents hit-counter cases name the arrays they read Case 0xd's per-subtype counter is hitsDealtToPlayerArray[subType + 1] (0x117c838 + 4 * subType), not emenyHitArray[subType - 8]: same address, the array the sum below it reads. The subtype bound is `<= 3` as the asm tests it (cmp cl, 3; ja). Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Map/MapPropertiesState/processSingleplayerEvents.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index cc25364cf2..a626f386de 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -719,13 +719,14 @@ namespace Map { case 0xd: cVar17 = condition.subType; if (cVar17 != '\0') { - if (((byte)(cVar17 - 1U) < 4) + if (((byte)(cVar17 - 1U) <= 3) && ((int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[0xd] .value <= DAT_GameState::instance.mapAndTime - .emenyHitArray[cVar17 + -8])) { - DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + -8] = 0; + .hitsDealtToPlayerArray[cVar17 + 1])) { + DAT_GameState::instance.mapAndTime + .hitsDealtToPlayerArray[cVar17 + 1] = 0; *_pConditionIsMet = 1; local_a0 = local_a0 + 1; } @@ -760,7 +761,7 @@ namespace Map { case 0xe: cVar17 = condition.subType; if (cVar17 != '\0') { - if (((byte)(cVar17 - 1U) < 4) + if (((byte)(cVar17 - 1U) <= 3) && ((int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[0xe] .value From 799c3886e383a9e756eb167dd08fa1300c3470ae Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 20:55:01 +0100 Subject: [PATCH 35/60] UI: loadOrSaveGame restores the saved list position in each arm The original tests the selection index and loads the load- or save-list fields inside each modal arm, then cross-jumps into shared stores. With the restore written once after the arms, MSVC loaded both field sets into locals ahead of the test and the 1/0x10 constants took different registers. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../UI/MenuTextInputState/loadOrSaveGame.cpp | 37 ++++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp index 1344dbdedf..4f8eec3afa 100644 --- a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp +++ b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp @@ -78,16 +78,20 @@ namespace UI { this->DAT_ArrayOfMapU3EndInt2 = 0; this->previewedListIndex = 0xffffffff; this->fileListVisibleRowCount = 0x10; - int offset; - int selection; - int sortOrder; if (action == 9) { MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( UI::Enums::MMT_LOAD_MAP); this->fileListContext = 1; - offset = this->savedListOffset1; - selection = this->savedListSelection1; - sortOrder = this->savedListSortOrder1; + // restore where the list was left, unless that is past its end now + if (this->menuLoadGameRelativeSelectionIndex != -1) { + this->fileListSortOrder = this->savedListSortOrder1; + this->menuLoadGameRelativeSelectionIndex = this->savedListSelection1; + this->menuLoadGameRelativeSelectionOffset = this->savedListOffset1; + if (this->savedListOffset1 + this->savedListSelection1 >= this->fileListEntryCount) { + this->menuLoadGameRelativeSelectionIndex = 0; + this->menuLoadGameRelativeSelectionOffset = 0; + } + } } else { MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( UI::Enums::MMT_SAVE_MAP); @@ -96,18 +100,15 @@ namespace UI { MACRO_CALL_MEMBER(Text::UserTextHandler_Func::moveCursorToEnd, DAT_UserTextHandlerState::ptr)(); DAT_UserTextHandlerState::instance.allowUserTextInput = 1; this->fileListContext = 3; - offset = this->savedListOffset2; - selection = this->savedListSelection2; - sortOrder = this->savedListSortOrder2; - } - // restore where the list was left, unless that is past its end now - if (this->menuLoadGameRelativeSelectionIndex != -1) { - this->fileListSortOrder = sortOrder; - this->menuLoadGameRelativeSelectionIndex = selection; - this->menuLoadGameRelativeSelectionOffset = offset; - if (offset + selection >= this->fileListEntryCount) { - this->menuLoadGameRelativeSelectionIndex = 0; - this->menuLoadGameRelativeSelectionOffset = 0; + // restore where the list was left, unless that is past its end now + if (this->menuLoadGameRelativeSelectionIndex != -1) { + this->fileListSortOrder = this->savedListSortOrder2; + this->menuLoadGameRelativeSelectionIndex = this->savedListSelection2; + this->menuLoadGameRelativeSelectionOffset = this->savedListOffset2; + if (this->savedListOffset2 + this->savedListSelection2 >= this->fileListEntryCount) { + this->menuLoadGameRelativeSelectionIndex = 0; + this->menuLoadGameRelativeSelectionOffset = 0; + } } } MACRO_CALL(UI::MenuItems::SaveLoadMap_Func::MenuItemActionHandler_SaveLoadMap_TableHeader)( diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d5ded9b95c..207e2a20ef 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -24233,7 +24233,7 @@ SHC_3BB0A8C1_0x00495A30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00496400 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004968A0 | 62.9% | register roles for the 1 and 0x10 constants +SHC_3BB0A8C1_0x004968A0 | 87.8% | register roles for the 1 and 0x10 constants SHC_3BB0A8C1_0x00496B80 | 100.0% | Reimplemented From 52b3b3e288d48a1358f1c106f09de0db6b40b5c2 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 20:57:06 +0100 Subject: [PATCH 36/60] UI: loadOrSaveGame restore stores index, offset, sort order Stored in that order and checked against the fields just written, the saved-position restore shares the original's cross-jump tail. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp | 10 ++++++---- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp index 4f8eec3afa..3c8c1f12fa 100644 --- a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp +++ b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp @@ -84,10 +84,11 @@ namespace UI { this->fileListContext = 1; // restore where the list was left, unless that is past its end now if (this->menuLoadGameRelativeSelectionIndex != -1) { - this->fileListSortOrder = this->savedListSortOrder1; this->menuLoadGameRelativeSelectionIndex = this->savedListSelection1; this->menuLoadGameRelativeSelectionOffset = this->savedListOffset1; - if (this->savedListOffset1 + this->savedListSelection1 >= this->fileListEntryCount) { + this->fileListSortOrder = this->savedListSortOrder1; + if (this->menuLoadGameRelativeSelectionOffset + this->menuLoadGameRelativeSelectionIndex + >= this->fileListEntryCount) { this->menuLoadGameRelativeSelectionIndex = 0; this->menuLoadGameRelativeSelectionOffset = 0; } @@ -102,10 +103,11 @@ namespace UI { this->fileListContext = 3; // restore where the list was left, unless that is past its end now if (this->menuLoadGameRelativeSelectionIndex != -1) { - this->fileListSortOrder = this->savedListSortOrder2; this->menuLoadGameRelativeSelectionIndex = this->savedListSelection2; this->menuLoadGameRelativeSelectionOffset = this->savedListOffset2; - if (this->savedListOffset2 + this->savedListSelection2 >= this->fileListEntryCount) { + this->fileListSortOrder = this->savedListSortOrder2; + if (this->menuLoadGameRelativeSelectionOffset + this->menuLoadGameRelativeSelectionIndex + >= this->fileListEntryCount) { this->menuLoadGameRelativeSelectionIndex = 0; this->menuLoadGameRelativeSelectionOffset = 0; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 207e2a20ef..3998ec4ea3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -24233,7 +24233,7 @@ SHC_3BB0A8C1_0x00495A30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00496400 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004968A0 | 87.8% | register roles for the 1 and 0x10 constants +SHC_3BB0A8C1_0x004968A0 | 92.6% | 0x10 held in ebp by the original for the string capacity tests SHC_3BB0A8C1_0x00496B80 | 100.0% | Reimplemented From 1fafad13b3de0785af5fd1ff29b628793ef9f53e Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 23:26:38 +0100 Subject: [PATCH 37/60] MapPropertiesState: computeMissionCompletionScore indexes the event array directly Reading scenarioEvents[i] at each use instead of through a const reference makes the compiler anchor its loop pointer on conditions[0].enabled, as the original does, so every event field offset now matches. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../computeMissionCompletionScore.cpp | 53 ++++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp index 4fb5a2765f..6f07017786 100644 --- a/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp @@ -27,16 +27,17 @@ namespace Map { this->missionScore = 0xffffffff; this->objectiveGoodsCount = 0; for (int i = 0; i < this->eventsCount; i++) { - InGameEventUnionVersion const& event = this->scenarioEvents[i]; // a goal with a time limit sets the deadline - if (event.header.tl_type == 3 - && (event.data.scenario.ScenarioEventType == 1 || event.data.scenario.ScenarioEventType == 0x1b) - && event.data.scenario.conditions[0].enabled) { - deadlineMonth = event.header.month; - deadlineYear = event.header.year; + if (this->scenarioEvents[i].header.tl_type == 3 + && (this->scenarioEvents[i].data.scenario.ScenarioEventType == 1 + || this->scenarioEvents[i].data.scenario.ScenarioEventType == 0x1b) + && this->scenarioEvents[i].data.scenario.conditions[0].enabled) { + deadlineMonth = this->scenarioEvents[i].header.month; + deadlineYear = this->scenarioEvents[i].header.year; } - if (event.header.tl_type != 3 - || (event.data.scenario.ScenarioEventType != 0 && event.data.scenario.ScenarioEventType != 0x1a)) { + if (this->scenarioEvents[i].header.tl_type != 3 + || (this->scenarioEvents[i].data.scenario.ScenarioEventType != 0 + && this->scenarioEvents[i].data.scenario.ScenarioEventType != 0x1a)) { continue; } // only the last win condition counts @@ -52,14 +53,15 @@ namespace Map { if (superseded) { continue; } - if (event.data.scenario.conditions[6].enabled) { - this->objectiveGoodsType[this->objectiveGoodsCount] = event.data.scenario.conditions[6].subType; + if (this->scenarioEvents[i].data.scenario.conditions[6].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] + = this->scenarioEvents[i].data.scenario.conditions[6].subType; int const index = this->objectiveGoodsCount; this->objectiveGoodsSurplus[index] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .currentResources[this->objectiveGoodsType[index]] - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - event.data.scenario.conditions[6].value); + this->scenarioEvents[i].data.scenario.conditions[6].value); switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { case 2: case 10: @@ -93,14 +95,15 @@ namespace Map { this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } } - if (event.data.scenario.conditions[17].enabled) { - this->objectiveGoodsType[this->objectiveGoodsCount] = event.data.scenario.conditions[17].subType; + if (this->scenarioEvents[i].data.scenario.conditions[17].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] + = this->scenarioEvents[i].data.scenario.conditions[17].subType; int const index = this->objectiveGoodsCount; this->objectiveGoodsSurplus[index] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .currentResources[this->objectiveGoodsType[index]] - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - event.data.scenario.conditions[17].value); + this->scenarioEvents[i].data.scenario.conditions[17].value); switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { case 2: case 10: @@ -134,14 +137,15 @@ namespace Map { this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } } - if (event.data.scenario.conditions[5].enabled) { - this->objectiveGoodsType[this->objectiveGoodsCount] = event.data.scenario.conditions[5].subType; + if (this->scenarioEvents[i].data.scenario.conditions[5].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] + = this->scenarioEvents[i].data.scenario.conditions[5].subType; int const index = this->objectiveGoodsCount; this->objectiveGoodsSurplus[index] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .currentResources[this->objectiveGoodsType[index]] - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - event.data.scenario.conditions[5].value); + this->scenarioEvents[i].data.scenario.conditions[5].value); switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { case 2: case 10: @@ -175,14 +179,15 @@ namespace Map { this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } } - if (event.data.scenario.conditions[7].enabled) { - this->objectiveGoodsType[this->objectiveGoodsCount] = event.data.scenario.conditions[7].subType; + if (this->scenarioEvents[i].data.scenario.conditions[7].enabled) { + this->objectiveGoodsType[this->objectiveGoodsCount] + = this->scenarioEvents[i].data.scenario.conditions[7].subType; int const index = this->objectiveGoodsCount; this->objectiveGoodsSurplus[index] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .currentResources[this->objectiveGoodsType[index]] - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - event.data.scenario.conditions[7].value); + this->scenarioEvents[i].data.scenario.conditions[7].value); switch (this->objectiveGoodsType[this->objectiveGoodsCount]) { case 2: case 10: @@ -216,26 +221,26 @@ namespace Map { this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } } - if (event.data.scenario.conditions[4].enabled) { + if (this->scenarioEvents[i].data.scenario.conditions[4].enabled) { this->objectiveGoodsType[this->objectiveGoodsCount] = 0xf; this->objectiveGoodsSurplus[this->objectiveGoodsCount] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .currentResources[0xf] - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - event.data.scenario.conditions[4].value); + this->scenarioEvents[i].data.scenario.conditions[4].value); this->objectiveGoodsScore[this->objectiveGoodsCount] = this->objectiveGoodsSurplus[this->objectiveGoodsCount]; if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { this->objectiveGoodsCount = this->objectiveGoodsCount + 1; } } - if (event.data.scenario.conditions[1].enabled) { + if (this->scenarioEvents[i].data.scenario.conditions[1].enabled) { this->objectiveGoodsType[this->objectiveGoodsCount] = -1; this->objectiveGoodsSurplus[this->objectiveGoodsCount] = DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .currentPopulation - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - event.data.scenario.conditions[1].value); + this->scenarioEvents[i].data.scenario.conditions[1].value); this->objectiveGoodsScore[this->objectiveGoodsCount] = this->objectiveGoodsSurplus[this->objectiveGoodsCount]; if (this->objectiveGoodsSurplus[this->objectiveGoodsCount] > 0) { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 3998ec4ea3..45beea528d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -30257,7 +30257,7 @@ SHC_3BB0A8C1_0x004BD980 | 0.0% | Pending SHC_3BB0A8C1_0x004BDA80 | 0.0% | Pending -SHC_3BB0A8C1_0x004BDE40 | 71.6% | event base pointer anchor, *5 arm shares the default store +SHC_3BB0A8C1_0x004BDE40 | 86.7% | *5 arm shares the default store, register naming SHC_3BB0A8C1_0x004BDE80 | 0.0% | Pending From 9cf7f3e3869c5faaa9a793f3f16d72bfaeab91e3 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sun, 29 Nov 2026 23:31:45 +0100 Subject: [PATCH 38/60] MapPropertiesState: processSingleplayerEvents indexes the condition directly Same lever as computeMissionCompletionScore: no const reference to the condition, so the array access is re-evaluated at each use. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 35 +++++++++++++------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index a626f386de..986761b102 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -370,13 +370,14 @@ namespace Map { */ _spawnUnitCount = 0; for (_subIndex = 0; _subIndex < 40; _subIndex++) { - Game::ScenarioEvents::ScenarioEventCondition const& condition - = this->scenarioEvents[_eventIndex].data.scenario.conditions[_subIndex]; _counter = _spawnUnitCount; /* this condition is empty? then move to next condition */ - if (condition.enabled == 0) + if (this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .enabled + == 0) goto switchD_004c3756_caseD_18; _counter = _spawnUnitCount + 1; /* @@ -413,7 +414,9 @@ namespace Map { .lordKilledByPlayerID; if (!iVar18) break; - cVar17 = condition.subType; + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; if (cVar17 == '\0' || iVar18 == 10 || cVar17 + 1 == iVar18) goto LAB_004c3fcd; LAB_004c37cd: @@ -453,7 +456,9 @@ namespace Map { (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[5] .value); - cVar17 = condition.subType; + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; if (cVar17 == '\0') { iVar22 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -500,8 +505,12 @@ namespace Map { case 0x11: iVar18 = MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - condition.value); - cVar17 = condition.subType; + this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value); + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; if (cVar17 != '\0') goto LAB_004c38d2; iVar22 = DAT_GameState::instance @@ -549,7 +558,9 @@ namespace Map { (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[7] .value); - cVar17 = condition.subType; + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; if (cVar17 != '\0') goto LAB_004c38d2; iVar22 = DAT_GameState::instance @@ -717,7 +728,9 @@ namespace Map { local_a0 = local_a0 + 1; break; case 0xd: - cVar17 = condition.subType; + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; if (cVar17 != '\0') { if (((byte)(cVar17 - 1U) <= 3) && ((int)this->scenarioEvents[_eventIndex] @@ -759,7 +772,9 @@ namespace Map { } break; case 0xe: - cVar17 = condition.subType; + cVar17 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .subType; if (cVar17 != '\0') { if (((byte)(cVar17 - 1U) <= 3) && ((int)this->scenarioEvents[_eventIndex] diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 45beea528d..ab10073601 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 55.5% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short) +SHC_3BB0A8C1_0x004C31A0 | 55.9% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short) SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 6019f29e7a096533874aed709e10db6782985ded Mon Sep 17 00:00:00 2001 From: Gynt Date: Mon, 30 Nov 2026 00:27:28 +0100 Subject: [PATCH 39/60] Skirmish: Skirmish_PrepareLeaderboardView counts the descending pass up The original guards on count <= 0 and ends the backwards copy on a counter reaching zero, which is how MSVC compiles an upward loop whose counter the body never reads. Counting k up and deriving i = count - 1 - k reproduces the loop instruction for instruction. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp | 6 +++--- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp index ff9dcc6089..4b7f25ff62 100644 --- a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp +++ b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp @@ -51,9 +51,9 @@ namespace Game { } } } else if (!DAT_MissionDefinedData::instance.descending) { - for (int left = DAT_SkMasters2Data::instance.count, i = DAT_SkMasters2Data::instance.count - 1; i >= 0; - left--, i--) { - if (INT_ARRAY_00eb0e48::instance[left - 1] != 0) { + for (int k = 0; k < DAT_SkMasters2Data::instance.count; k++) { + int const i = DAT_SkMasters2Data::instance.count - 1 - k; + if (INT_ARRAY_00eb0e48::instance[i] != 0) { INT_ARRAY_00eb96d8::instance[INT_00eb9b60::instance] = i; INT_00eb9b60::instance = INT_00eb9b60::instance + 1; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index ab10073601..bd5b1b87fa 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -36023,7 +36023,7 @@ SHC_3BB0A8C1_0x004D9270 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D9290 | 100.0% | Reimplemented (counted: only memset/_stricmp call labels and the instance[i - 1] address label differ) -SHC_3BB0A8C1_0x004D9400 | 89.1% | descending loop ends on the counter (jne) in the original, ours on i (jge) +SHC_3BB0A8C1_0x004D9400 | 93.2% | name loop pointer anchored on mapName, the original on the entry SHC_3BB0A8C1_0x004D9520 | 0.0% | Pending From f12724114132eead6ee28b7f4b5c13fa3d12b08a Mon Sep 17 00:00:00 2001 From: Gynt Date: Mon, 30 Nov 2026 00:52:49 +0100 Subject: [PATCH 40/60] MapPropertiesState: processSingleplayerEvents sums the invasion's unit counts in a loop The decompiler's five-wide pointer walk over unitCountsPerUnitType is a plain 25-element loop that MSVC unrolls by five, and the threshold is the >= 25 the original tests with jl. Match unchanged, normalized +0.1. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../processSingleplayerEvents.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 986761b102..519f350ea2 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -2544,15 +2544,10 @@ namespace Map { iVar20 = 0; iVar1 = iVar22 * 4; numInGroup = iVar1 + 1; - iVar21 = 5; - _pConditionIsMet = (psVar21->data).invasion.unitCountsPerUnitType + 3; - do { - iVar20 = iVar20 + _pConditionIsMet[-3] + _pConditionIsMet[-2] - + _pConditionIsMet[-1] + _pConditionIsMet[1] + *_pConditionIsMet; - iVar21 = iVar21 + -1; - _pConditionIsMet = _pConditionIsMet + 5; - } while (iVar21); - if (0x18 < iVar20) { + for (int k = 0; k < 25; k++) { + iVar20 = iVar20 + (psVar21->data).invasion.unitCountsPerUnitType[k]; + } + if (iVar20 >= 0x19) { if (iVar20 < 0x4b) { numInGroup = iVar1 + 2; } else if (iVar20 < 0x96) { From 97a345fc4579a84ad8d41d757b81a6bc5d951229 Mon Sep 17 00:00:00 2001 From: Gynt Date: Mon, 30 Nov 2026 01:07:17 +0100 Subject: [PATCH 41/60] Skirmish: Skirmish_PrepareLeaderboardView binds the entry for the name sort A reference to entries[i] at loop scope makes the compiler base its pointer on the entry, as the original does, instead of on mapName. reccmp 99.1, normalized 100: the only differences left are the labels of two array[-1] addresses, which resolve to the neighbouring globals. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXNCM9MzSpvzeakUrQ --- .../Skirmish/Skirmish_PrepareLeaderboardView.cpp | 14 +++++++------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp index 4b7f25ff62..a8f1a1b9b6 100644 --- a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp +++ b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp @@ -92,18 +92,18 @@ namespace Game { } } else { for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + OpenSHC::IO::SkMasterDataEntry& entry = DAT_SkMasters2Data::instance.entries[i]; if (INT_ARRAY_00eb0e48::instance[i] != 0) { - if (DAT_SkMasters2Data::instance.entries[i].score) { - strcpy(DAT_SkMasters2Data::instance.entries[i].mapName, - MACRO_CALL_MEMBER( - Text::TextManager_Func::getTextStringInGroupAtOffset, DAT_TextManagerObject::ptr)( - DE::SHCDE::TEXT_TRAIL_NAMES_CRU, DAT_SkMasters2Data::instance.entries[i].score)); + if (entry.score) { + strcpy(entry.mapName, + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_TRAIL_NAMES_CRU, entry.score)); } - byte first = DAT_SkMasters2Data::instance.entries[i].mapName[0]; + byte first = entry.mapName[0]; if (first >= 'A' && first <= 'Z') { first = first + 0x20; } - byte second = DAT_SkMasters2Data::instance.entries[i].mapName[1]; + byte second = entry.mapName[1]; if (second >= 'A' && second <= 'Z') { second = second + 0x20; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bd5b1b87fa..2c8667baf4 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -36023,7 +36023,7 @@ SHC_3BB0A8C1_0x004D9270 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D9290 | 100.0% | Reimplemented (counted: only memset/_stricmp call labels and the instance[i - 1] address label differ) -SHC_3BB0A8C1_0x004D9400 | 93.2% | name loop pointer anchored on mapName, the original on the entry +SHC_3BB0A8C1_0x004D9400 | 100.0% | Reimplemented (counted: only the labels of two array[-1] addresses differ) SHC_3BB0A8C1_0x004D9520 | 0.0% | Pending From e3487d09b16e3065f8f565cf8243672207dee102 Mon Sep 17 00:00:00 2001 From: Gynt Date: Wed, 2 Dec 2026 16:41:16 +0100 Subject: [PATCH 42/60] fix(MapPropertiesState): follow main's PlayerData rename aiControlStatusRelated -> aiHoldBackTicks After the merge of origin/main all 7 functions at 100% stay 100% (normalized), and the partial ones keep their match. Co-Authored-By: Claude Opus 5.5 (1M context) --- .../Map/MapPropertiesState/processSingleplayerEvents.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 519f350ea2..e8ee121843 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -2225,7 +2225,7 @@ namespace Map { DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 0; DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .aiControlStatusRelated = -200; + .aiHoldBackTicks = -200; /* invasion. ? */ From 49c7abbb298a40fb131045f9e3836278d3f51570 Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 3 Dec 2026 22:58:41 +0100 Subject: [PATCH 43/60] reimplement: SHC_3BB0A8C1_0x004BD800 100.00% Reimplemented Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp | 4 ++-- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp index 4fe451dbbd..7ef67b72a7 100644 --- a/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp +++ b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp @@ -76,7 +76,7 @@ BOOLEnum Game::Tutorial_IsActionAllowed(undefined4 actionType, int actionParam) && actionParam != 4) { return FALSE; } - return TRUE; + break; case 4: if (DAT_TutorialCurrentStep::instance != 10) { return FALSE; @@ -86,7 +86,7 @@ BOOLEnum Game::Tutorial_IsActionAllowed(undefined4 actionType, int actionParam) && actionParam != 7) { return FALSE; } - return TRUE; + break; } return TRUE; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2552bbb196..1d5737cc57 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -30243,7 +30243,7 @@ SHC_3BB0A8C1_0x004BD7F0 | 0.0% | Pending SHC_3BB0A8C1_0x004BD7F4 | 0.0% | Pending -SHC_3BB0A8C1_0x004BD800 | 92.3% | Shared tail in wrong arm +SHC_3BB0A8C1_0x004BD800 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BD970 | 0.0% | Pending From 169a4e6f5b070c7cdfd0a6635660639e4d39a292 Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 3 Dec 2026 23:09:24 +0100 Subject: [PATCH 44/60] reimplement: SHC_3BB0A8C1_0x004968A0 93.09% 0x10 not kept in ebp (alloc) Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp | 2 +- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp index 3c8c1f12fa..b0569fc322 100644 --- a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp +++ b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp @@ -108,8 +108,8 @@ namespace UI { this->fileListSortOrder = this->savedListSortOrder2; if (this->menuLoadGameRelativeSelectionOffset + this->menuLoadGameRelativeSelectionIndex >= this->fileListEntryCount) { - this->menuLoadGameRelativeSelectionIndex = 0; this->menuLoadGameRelativeSelectionOffset = 0; + this->menuLoadGameRelativeSelectionIndex = 0; } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 1d5737cc57..b9e97eff6c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -24233,7 +24233,7 @@ SHC_3BB0A8C1_0x00495A30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00496400 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004968A0 | 92.6% | 0x10 held in ebp by the original for the string capacity tests +SHC_3BB0A8C1_0x004968A0 | 93.1% | 0x10 not kept in ebp (alloc) SHC_3BB0A8C1_0x00496B80 | 100.0% | Reimplemented From fe61ad2fc775b4cc8d061fbee55366db78f132c5 Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 3 Dec 2026 23:13:11 +0100 Subject: [PATCH 45/60] reimplement: SHC_3BB0A8C1_0x004BDE40 88.67% *5 arm store not merged (regs) Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/MapPropertiesState/computeMissionCompletionScore.cpp | 5 +++-- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp index 6f07017786..ff1e0d14df 100644 --- a/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/computeMissionCompletionScore.cpp @@ -300,8 +300,9 @@ namespace Map { } } this->enemyTroopValueSurviving = surviving; - this->enemyTroopValueLost = DAT_GameState::instance.playerDataArray[2].weightedLosses; - this->enemyTroopValueTotal = DAT_GameState::instance.playerDataArray[2].weightedLosses + surviving; + int const lost = DAT_GameState::instance.playerDataArray[2].weightedLosses; + this->enemyTroopValueLost = lost; + this->enemyTroopValueTotal = lost + surviving; } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b9e97eff6c..706c0e7a92 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -30257,7 +30257,7 @@ SHC_3BB0A8C1_0x004BD980 | 0.0% | Pending SHC_3BB0A8C1_0x004BDA80 | 0.0% | Pending -SHC_3BB0A8C1_0x004BDE40 | 86.7% | *5 arm shares the default store, register naming +SHC_3BB0A8C1_0x004BDE40 | 88.7% | *5 arm store not merged (regs) SHC_3BB0A8C1_0x004BDE80 | 0.0% | Pending From 2e3b879b00b0a4f24569608009aba338bca66905 Mon Sep 17 00:00:00 2001 From: Gynt Date: Thu, 3 Dec 2026 23:58:51 +0100 Subject: [PATCH 46/60] reimplement: SHC_3BB0A8C1_0x0044B680 90.12% rank/best swap edx-esi (alloc) Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp | 5 +++-- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp b/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp index a90a2b38cd..da7297061f 100644 --- a/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp +++ b/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp @@ -49,10 +49,11 @@ namespace Audio { if (highestIndex < 0) { return 0; } - if (playerPoints[highestIndex][0] == playerID) { + int const id = playerPoints[highestIndex][0]; + playerPoints[highestIndex][0] = 0; + if (id == playerID) { return rank + 1; } - playerPoints[highestIndex][0] = 0; } return 0; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 706c0e7a92..f29c0160b3 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16863,7 +16863,7 @@ SHC_3BB0A8C1_0x0044B673 | 0.0% | Pending SHC_3BB0A8C1_0x0044B674 | 0.0% | Pending -SHC_3BB0A8C1_0x0044B680 | 53.8% | Register allocation +SHC_3BB0A8C1_0x0044B680 | 90.1% | rank/best swap edx-esi (alloc) SHC_3BB0A8C1_0x0044B760 | 100.0% | Reimplemented From 8fbebe330bcff71973818507591a1e0e6703ba32 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 09:42:39 +0100 Subject: [PATCH 47/60] reimplement: SHC_3BB0A8C1_0x004C31A0 62.16% this/zero regs swapped, frame Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../processSingleplayerEvents.cpp | 28 +++++++++---------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index e8ee121843..aebb172c2c 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -394,7 +394,7 @@ namespace Map { iVar22 = MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( (int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[1] + .data.scenario.conditions[_subIndex] .value); iVar18 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -437,7 +437,7 @@ namespace Map { iVar22 = MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( (int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[4] + .data.scenario.conditions[_subIndex] .value); iVar18 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -454,7 +454,7 @@ namespace Map { iVar18 = MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( (int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[5] + .data.scenario.conditions[_subIndex] .value); cVar17 = this->scenarioEvents[_eventIndex] .data.scenario.conditions[_subIndex] @@ -556,7 +556,7 @@ namespace Map { iVar18 = MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( (int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[7] + .data.scenario.conditions[_subIndex] .value); cVar17 = this->scenarioEvents[_eventIndex] .data.scenario.conditions[_subIndex] @@ -734,7 +734,7 @@ namespace Map { if (cVar17 != '\0') { if (((byte)(cVar17 - 1U) <= 3) && ((int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0xd] + .data.scenario.conditions[_subIndex] .value <= DAT_GameState::instance.mapAndTime .hitsDealtToPlayerArray[cVar17 + 1])) { @@ -745,7 +745,7 @@ namespace Map { } } else { if ((int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0xd] + .data.scenario.conditions[_subIndex] .value <= DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[0] + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[1] @@ -766,7 +766,7 @@ namespace Map { DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[6] = 0; DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[7] = 0; DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[8] = 0; - this->SEC_EventsExtra[_eventIndex].conditionIsTrue[13] = 1; + this->SEC_EventsExtra[_eventIndex].conditionIsTrue[_subIndex] = 1; local_a0 = local_a0 + 1; } } @@ -778,7 +778,7 @@ namespace Map { if (cVar17 != '\0') { if (((byte)(cVar17 - 1U) <= 3) && ((int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0xe] + .data.scenario.conditions[_subIndex] .value <= DAT_GameState::instance.mapAndTime .emenyHitArray[cVar17 + 1])) { @@ -788,7 +788,7 @@ namespace Map { } } else { if ((int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0xe] + .data.scenario.conditions[_subIndex] .value <= DAT_GameState::instance.mapAndTime.emenyHitArray[0] + DAT_GameState::instance.mapAndTime.emenyHitArray[1] @@ -808,7 +808,7 @@ namespace Map { DAT_GameState::instance.mapAndTime.emenyHitArray[6] = 0; DAT_GameState::instance.mapAndTime.emenyHitArray[7] = 0; DAT_GameState::instance.mapAndTime.emenyHitArray[8] = 0; - this->SEC_EventsExtra[_eventIndex].conditionIsTrue[14] = 1; + this->SEC_EventsExtra[_eventIndex].conditionIsTrue[_subIndex] = 1; local_a0 = local_a0 + 1; } } @@ -819,7 +819,7 @@ namespace Map { .currentPlayerSlotID] .previousBlessedPeoplePercentage; sVar8 = this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0x14] + .data.scenario.conditions[_subIndex] .value; if (sVar7 >= sVar8) { *_pConditionIsMet = 1; @@ -832,7 +832,7 @@ namespace Map { .currentPlayerSlotID] .fearFactorLevel <= -(int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0x16] + .data.scenario.conditions[_subIndex] .value) { *_pConditionIsMet = 1; local_a0 = local_a0 + 1; @@ -840,7 +840,7 @@ namespace Map { break; case 0x17: iVar22 = (int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0x17] + .data.scenario.conditions[_subIndex] .value; iVar18 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -856,7 +856,7 @@ namespace Map { Game::GameStateStructures_Func::computeAleCoverage, DAT_GameState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID); iVar22 = (int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[0x15] + .data.scenario.conditions[_subIndex] .value; if (iVar18 >= iVar22) { *_pConditionIsMet = 1; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index f29c0160b3..d333d32004 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 55.9% | structure restored; frame 0x9c vs 0xa0 (one scalar spill short) +SHC_3BB0A8C1_0x004C31A0 | 62.2% | this/zero regs swapped, frame SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 98f66cc3a0916facfc7f793c350b7fa8cf6ae939 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 09:57:06 +0100 Subject: [PATCH 48/60] reimplement: SHC_3BB0A8C1_0x004C31A0 62.67% case 0x1c block placed late; r Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/MapPropertiesState/processSingleplayerEvents.cpp | 8 ++------ status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index aebb172c2c..f6a7efe93c 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -2090,13 +2090,9 @@ namespace Map { do { if ((*(int const*)&pSVar15[-0x1e] == 1) && (*(int const*)pSVar15 != 0)) { - pSVar15->value = 0; - pSVar15->subType = 0; - pSVar15->enabled = 0; + *(int*)pSVar15 = 0; pSVar15[-0x1d].value = 1; - pSVar15[-0xffffffff0000001f].value = 0x49d; - pSVar15[-0xffffffff0000001f].subType = 0; - pSVar15[-0xffffffff0000001f].enabled = 0; + *(int*)&pSVar15[-0x1f] = 0x49d; } iVar18 = iVar18 + 1; pSVar15 = pSVar15 + 0x39; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index d333d32004..059324eacf 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 62.2% | this/zero regs swapped, frame +SHC_3BB0A8C1_0x004C31A0 | 62.7% | case 0x1c block placed late; r SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 8bdbfa0751faf046089cb0efd9dd5b8554bf1f33 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 10:05:52 +0100 Subject: [PATCH 49/60] reimplement: SHC_3BB0A8C1_0x004C31A0 63.89% regs and case layout in condit Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../processSingleplayerEvents.cpp | 208 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 105 insertions(+), 105 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index f6a7efe93c..2f12c489b7 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -958,6 +958,41 @@ namespace Map { DAT_GameState::instance.mapAndTime.scenarioEventTimers[iVar18] = 1; iVar18 = DAT_GameSynchronyState::instance.currentPlayerSlotID; switch (this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType) { + case 0x1a: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 0) { + for (iVar18 = _eventIndex + 1; iVar18 < this->eventsCount; iVar18++) { + if (this->scenarioEvents[iVar18].header.tl_type == 3 + && (this->scenarioEvents[iVar18].data.scenario.ScenarioEventType + == 0 + || this->scenarioEvents[iVar18].data.scenario.ScenarioEventType + == 0x1a) + && this->scenarioEvents[iVar18].header.year + <= DAT_GameState::instance.mapAndTime.year + && (DAT_GameState::instance.mapAndTime.year + != this->scenarioEvents[iVar18].header.year + || DAT_GameState::instance.mapAndTime.month + > this->scenarioEvents[iVar18].header.month)) + goto switchD_004c382e_caseD_2; + } + this->scenarioEvents[_eventIndex].header.done = 0; + this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType = 0; + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year; + LAB_004c4072: + iVar22 = DAT_GameState::instance.mapAndTime.month + 1; + this->scenarioEvents[_eventIndex].header.month = iVar22; + if (iVar22 >= 12) { + this->scenarioEvents[_eventIndex].header.year++; + this->scenarioEvents[_eventIndex].header.month = iVar22 - 12; + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + } + } + goto switchD_004c382e_caseD_2; case 0: if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] @@ -1040,6 +1075,18 @@ namespace Map { } } goto switchD_004c382e_caseD_2; + case 0x1b: + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .playerDeathRelated + == 0) { + this->scenarioEvents[_eventIndex].header.done = 0; + this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType = 1; + this->scenarioEvents[_eventIndex].header.year + = DAT_GameState::instance.mapAndTime.year; + goto LAB_004c4072; + } + goto switchD_004c382e_caseD_2; case 1: if ((DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance @@ -1086,8 +1133,6 @@ namespace Map { } } goto switchD_004c382e_caseD_2; - default: - goto switchD_004c382e_caseD_2; case 3: MACRO_CALL_MEMBER( Map::Units::TribesState_Func::flagTribesOfType, DAT_TribesState::ptr)(0xe); @@ -1999,108 +2044,6 @@ namespace Map { "Random_Events13.wav"); MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; - case 0x17: - if (((DAT_GameCore::instance.gameMode_2 != Game::GM_CAMPAIGN_MISSION) - && (this->scenarioEvents[_eventIndex].header.year == 0x43d)) - && (this->scenarioEvents[_eventIndex].header.month == 0xb)) { - dVar14 = MACRO_CALL_MEMBER( - Map::Units::TribesState_Func::createTribeWithSpawnedUnit, - DAT_TribesState::ptr)(0, OpenSHC::AI::Tribes::AITT_ARCHERS, 0x85, 0x116, - (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), - Map::Units::UT_E_ARCHER, 0x14); - sVar7 = DAT_TribesState::instance.tribes[dVar14].size; - DAT_TribesState::instance.tribes[dVar14].pendingScatterMove = 3; - if (0 < sVar7) { - iVar18 = 0; - do { - iVar22 = iVar18 + 1; - iVar18 = MACRO_CALL_MEMBER( - Map::Units::TribesState_Func::getUnitIDForIndexInTribe, - DAT_TribesState::ptr)(dVar14, iVar18); - sVar7 = DAT_TribesState::instance.tribes[dVar14].size; - DAT_UnitsState::instance.units[iVar18].calculatedOwnerPlayerIndex - = 6; - iVar18 = iVar22; - } while (iVar22 < sVar7); - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); - break; - } - } - goto switchD_004c382e_caseD_2; - case 0x18: - DAT_GameCore::instance.section1076 = 0; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); - break; - case 0x19: - DAT_GameCore::instance.section1076 = 1; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); - break; - case 0x1a: - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 0) { - for (iVar18 = _eventIndex + 1; iVar18 < this->eventsCount; iVar18++) { - if (this->scenarioEvents[iVar18].header.tl_type == 3 - && (this->scenarioEvents[iVar18].data.scenario.ScenarioEventType - == 0 - || this->scenarioEvents[iVar18].data.scenario.ScenarioEventType - == 0x1a) - && this->scenarioEvents[iVar18].header.year - <= DAT_GameState::instance.mapAndTime.year - && (DAT_GameState::instance.mapAndTime.year - != this->scenarioEvents[iVar18].header.year - || DAT_GameState::instance.mapAndTime.month - > this->scenarioEvents[iVar18].header.month)) - goto switchD_004c382e_caseD_2; - } - this->scenarioEvents[_eventIndex].header.done = 0; - this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType = 0; - this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year; - LAB_004c4072: - iVar22 = DAT_GameState::instance.mapAndTime.month + 1; - this->scenarioEvents[_eventIndex].header.month = iVar22; - if (iVar22 >= 12) { - this->scenarioEvents[_eventIndex].header.year++; - this->scenarioEvents[_eventIndex].header.month = iVar22 - 12; - MACRO_CALL_MEMBER( - Map::MapPropertiesState_Func::sortEventsByDate, this)(); - break; - } - } - goto switchD_004c382e_caseD_2; - case 0x1b: - if (DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] - .playerDeathRelated - == 0) { - this->scenarioEvents[_eventIndex].header.done = 0; - this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType = 1; - this->scenarioEvents[_eventIndex].header.year - = DAT_GameState::instance.mapAndTime.year; - goto LAB_004c4072; - } - goto switchD_004c382e_caseD_2; - case 0x1c: - iVar18 = 0; - if (0 < this->eventsCount) { - pSVar15 = this->scenarioEvents[0].data.scenario.conditions + 0x19; - do { - if ((*(int const*)&pSVar15[-0x1e] == 1) - && (*(int const*)pSVar15 != 0)) { - *(int*)pSVar15 = 0; - pSVar15[-0x1d].value = 1; - *(int*)&pSVar15[-0x1f] = 0x49d; - } - iVar18 = iVar18 + 1; - pSVar15 = pSVar15 + 0x39; - } while (iVar18 < this->eventsCount); - } - switchD_004c382e_caseD_2: - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); - break; case 0x1d: if (DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] @@ -2209,6 +2152,63 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + break; + case 0x17: + if (((DAT_GameCore::instance.gameMode_2 != Game::GM_CAMPAIGN_MISSION) + && (this->scenarioEvents[_eventIndex].header.year == 0x43d)) + && (this->scenarioEvents[_eventIndex].header.month == 0xb)) { + dVar14 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::createTribeWithSpawnedUnit, + DAT_TribesState::ptr)(0, OpenSHC::AI::Tribes::AITT_ARCHERS, 0x85, 0x116, + (int)((int)(DAT_GameSynchronyState::instance.currentPlayerSlotID)), + Map::Units::UT_E_ARCHER, 0x14); + sVar7 = DAT_TribesState::instance.tribes[dVar14].size; + DAT_TribesState::instance.tribes[dVar14].pendingScatterMove = 3; + if (0 < sVar7) { + iVar18 = 0; + do { + iVar22 = iVar18 + 1; + iVar18 = MACRO_CALL_MEMBER( + Map::Units::TribesState_Func::getUnitIDForIndexInTribe, + DAT_TribesState::ptr)(dVar14, iVar18); + sVar7 = DAT_TribesState::instance.tribes[dVar14].size; + DAT_UnitsState::instance.units[iVar18].calculatedOwnerPlayerIndex + = 6; + iVar18 = iVar22; + } while (iVar22 < sVar7); + MACRO_CALL_MEMBER( + Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + } + } + goto switchD_004c382e_caseD_2; + case 0x19: + DAT_GameCore::instance.section1076 = 1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x18: + DAT_GameCore::instance.section1076 = 0; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; + case 0x1c: + iVar18 = 0; + if (0 < this->eventsCount) { + pSVar15 = this->scenarioEvents[0].data.scenario.conditions + 0x19; + do { + if ((*(int const*)&pSVar15[-0x1e] == 1) + && (*(int const*)pSVar15 != 0)) { + *(int*)pSVar15 = 0; + pSVar15[-0x1d].value = 1; + *(int*)&pSVar15[-0x1f] = 0x49d; + } + iVar18 = iVar18 + 1; + pSVar15 = pSVar15 + 0x39; + } while (iVar18 < this->eventsCount); + } + default: + switchD_004c382e_caseD_2: + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); + break; } break; case 2: diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 059324eacf..54d328d518 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 62.7% | case 0x1c block placed late; r +SHC_3BB0A8C1_0x004C31A0 | 63.9% | regs and case layout in condit SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From f0257cfc33a0d5b2ed194b1fc95a366a9e897bcf Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 11:17:19 +0100 Subject: [PATCH 50/60] reimplement: SHC_3BB0A8C1_0x004C68D0 72.49% mission/one regs swapped, star Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Game/Skirmish/SetupSkirmishMode.cpp | 23 +++++++++++-------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp index 0a54ead43c..a5b018e5dd 100644 --- a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp +++ b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp @@ -43,34 +43,36 @@ namespace Game { DAT_GameCore::instance.gameMode_2 = Game::GM_SKIRMISH_AND_MULTIPLAYER; memset(DAT_GameSynchronyState::instance.DAT_PlayerNames, 0, sizeof(DAT_GameSynchronyState::instance.DAT_PlayerNames)); - for (int i = 0; i != 9; i++) { + int i = 0; + do { DAT_GameSynchronyState::instance.currentPlayerFullIDArray[i] = -1; DAT_GameSynchronyState::instance.currentAIArray[i] = 0; DAT_GameSynchronyState::instance.aiVariationArray[i] = -1; - } + i++; + } while (i < 9); strcpy(DAT_GameSynchronyState::instance.DAT_PlayerNames[1], MACRO_CALL_MEMBER(Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0)); MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( Commands::GCT_ASK_FOR_SLOT_ASSIGNMENT); - for (int i = 0; i < 9; i++) { + for (i = 0; i < 9; i++) { DAT_GameSynchronyState::instance.DAT_PlayerSlotArraySomeValue[i] = 1; } DAT_GameSynchronyState::instance.skirmishRelated1 = -1; DAT_GameCore::instance.mapU4Int0 = 0; // the trail mission lists the AI of each player in turn; player 1 is the human - for (int i = 1; i < mission->numberOfPlayers; i++) { + for (i = 1; i < mission->numberOfPlayers; i++) { DAT_GameSynchronyState::instance.currentAIArray[i + 1] = (&mission->player1AI)[i]; MACRO_CALL(Synchrony_Func::ResetAiVariationArrayValue)(i + 1); } memset(DAT_GameSynchronyState::instance.playerPositionsArray, -10, sizeof(DAT_GameSynchronyState::instance.playerPositionsArray)); - for (int i = 0; i < 8; i++) { + for (i = 0; i < 8; i++) { if ((&mission->position1)[i] != 0) { DAT_GameSynchronyState::instance.playerPositionsArray[(&mission->position1)[i] - 1] = (char)i; } } int const players = mission->numberOfPlayers; - for (int i = 0; i < 8; i++) { + for (i = 0; i < 8; i++) { DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[i + 1] = (char)(&mission->team1)[i]; if (i >= players) { DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[i + 1] = -1; @@ -81,6 +83,7 @@ namespace Game { DAT_GameSynchronyState::instance.skirmishGameIntensityType = mission->startLevels; DAT_GameCore::instance.isSkirmishTrail = TRUE; int startDateInMonths; + int monthsPerYear = 12; if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { DAT_GameCore::instance.extremeTrailProgress = skirmishTrailMission; MACRO_CALL(UI::Actions_Func::LaunchSkirmishGame)((int)&mission->aiv1); @@ -100,10 +103,10 @@ namespace Game { = DAT_GameCore::instance.skirmishTrailStartDateInMonths[DAT_GameCore::instance.skirmishTrailProgress]; DAT_GameCore::instance.skirmishTrailStartDateMonths = startDateInMonths; } - DAT_GameState::instance.mapAndTime.year = startDateInMonths / 12; - DAT_GameState::instance.mapAndTime.month = startDateInMonths % 12; - DAT_GameSynchronyState::instance.finalResults.tail.tail1.yearStart = startDateInMonths / 12; - DAT_GameSynchronyState::instance.finalResults.tail.tail1.monthStart = startDateInMonths % 12; + DAT_GameState::instance.mapAndTime.year = startDateInMonths / monthsPerYear; + DAT_GameState::instance.mapAndTime.month = startDateInMonths % monthsPerYear; + DAT_GameSynchronyState::instance.finalResults.tail.tail1.yearStart = startDateInMonths / monthsPerYear; + DAT_GameSynchronyState::instance.finalResults.tail.tail1.monthStart = startDateInMonths % monthsPerYear; } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 54d328d518..bffa706477 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -34147,7 +34147,7 @@ SHC_3BB0A8C1_0x004C6820 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C6880 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C68D0 | 51.9% | register choice, -1 not hoisted into ebx +SHC_3BB0A8C1_0x004C68D0 | 72.5% | mission/one regs swapped, star SHC_3BB0A8C1_0x004C6B20 | 100.0% | Reimplemented From c5a4170334fe0dbcbaa45140c7ef707dcc9f0c15 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 13:59:16 +0100 Subject: [PATCH 51/60] reimplement: SHC_3BB0A8C1_0x004C62C0 78.99% equal-weight slot tie order Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Map/MapPropertiesState/loadMap.cpp | 4 ++-- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp index 367d7354d5..d01f93c98d 100644 --- a/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/loadMap.cpp @@ -55,15 +55,15 @@ namespace Map { // reading the map overwrites these, so they are kept across it GameMode2Int const gameMode = DAT_GameCore::instance.gameMode_2; int const missionNumber = DAT_GameCore::instance.missionNumber1to20; - int const playerSlotID = DAT_GameSynchronyState::instance.currentPlayerSlotID; int const difficulty = DAT_GameState::instance.mapAndTime.difficulty; + int const playerSlotID = DAT_GameSynchronyState::instance.currentPlayerSlotID; int const xbowProducible = DAT_GameCore::instance.xbowProducible_logic; int const swordProducible = DAT_GameCore::instance.swordProducible_logic; int const pikeProducible = DAT_GameCore::instance.pikeProducible_logic; int const bowProducible = DAT_GameCore::instance.bowProducible_logic; - int const jester = DAT_GameState::instance.mapAndTime.unitJesterRelated; int const maceProducible = DAT_GameCore::instance.maceProducible_logic; int const spearProducible = DAT_GameCore::instance.spearProducible_logic; + int const jester = DAT_GameState::instance.mapAndTime.unitJesterRelated; int const lady = DAT_GameState::instance.mapAndTime.unitLadyRelated; // a byte buffer: the original has a security cookie, and these two sit right under it char savedFields[8]; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index bffa706477..964c744058 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -34141,7 +34141,7 @@ SHC_3BB0A8C1_0x004C6298 | 0.0% | Pending SHC_3BB0A8C1_0x004C62A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C62C0 | 77.6% | load scheduling in the save/restore prologue +SHC_3BB0A8C1_0x004C62C0 | 79.0% | equal-weight slot tie order SHC_3BB0A8C1_0x004C6820 | 100.0% | Reimplemented From e8c467f24ed2212c3f200e63b20845f38ec2eb57 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 14:02:51 +0100 Subject: [PATCH 52/60] reimplement: SHC_3BB0A8C1_0x0044B680 98.14% id load folded into cmp Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp | 3 ++- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp b/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp index da7297061f..15ab6aca73 100644 --- a/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp +++ b/src/OpenSHC/Audio/SFX/ComputePlayerRanking.cpp @@ -50,10 +50,11 @@ namespace Audio { return 0; } int const id = playerPoints[highestIndex][0]; - playerPoints[highestIndex][0] = 0; if (id == playerID) { + playerPoints[highestIndex][0] = 0; return rank + 1; } + playerPoints[highestIndex][0] = 0; } return 0; } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 964c744058..5dcd3ed014 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -16863,7 +16863,7 @@ SHC_3BB0A8C1_0x0044B673 | 0.0% | Pending SHC_3BB0A8C1_0x0044B674 | 0.0% | Pending -SHC_3BB0A8C1_0x0044B680 | 90.1% | rank/best swap edx-esi (alloc) +SHC_3BB0A8C1_0x0044B680 | 98.1% | id load folded into cmp SHC_3BB0A8C1_0x0044B760 | 100.0% | Reimplemented From fe3b7793f4fdcd579550deb30ada01b741c112b4 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 14:12:35 +0100 Subject: [PATCH 53/60] reimplement: SHC_3BB0A8C1_0x004C68D0 82.58% mission defs in head; idiv reg Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp | 4 +++- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp index a5b018e5dd..c7ce6d5704 100644 --- a/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp +++ b/src/OpenSHC/Game/Skirmish/SetupSkirmishMode.cpp @@ -30,11 +30,13 @@ namespace Game { // FUNCTION: STRONGHOLDCRUSADER 0x004C68D0 void Skirmish::SetupSkirmishMode(int skirmishTrailMission) { - CampaignTrailMission* mission = &DAT_SkirmishDefinedData::instance.SkirmishTrailMissions[skirmishTrailMission]; + CampaignTrailMission* mission; if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { mission = &DAT_SkirmishDefinedData::instance.ExtremeTrailMissions[skirmishTrailMission]; } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { mission = &DAT_SkirmishDefinedData::instance.WarchestTrailMissions[skirmishTrailMission]; + } else { + mission = &DAT_SkirmishDefinedData::instance.SkirmishTrailMissions[skirmishTrailMission]; } MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::setupSkirmishLobby, DAT_GameSynchronyState::ptr)(); DAT_GameSynchronyState::instance.isHost = TRUE; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 5dcd3ed014..2a69d7994d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -34147,7 +34147,7 @@ SHC_3BB0A8C1_0x004C6820 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C6880 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C68D0 | 72.5% | mission/one regs swapped, star +SHC_3BB0A8C1_0x004C68D0 | 82.6% | mission defs in head; idiv reg SHC_3BB0A8C1_0x004C6B20 | 100.0% | Reimplemented From 8f97c77deb25b0feb3e1848bda8ada983e9f4418 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 14:19:01 +0100 Subject: [PATCH 54/60] reimplement: SHC_3BB0A8C1_0x004C31A0 63.95% fire flag int; this spilled, f Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../Map/MapPropertiesState/processSingleplayerEvents.cpp | 7 +++---- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 2f12c489b7..2d4fc6d683 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -124,7 +124,7 @@ namespace Map { int iVar22; uint y1; UnitTypeInt _unitType; - bool bVar23; + int bVar23; char* pcVar25; int local_a0; int _eventIndex; @@ -298,13 +298,12 @@ namespace Map { if ((((DAT_GameState::instance.mapAndTime.month == this->SEC_StartingMonth) && (DAT_GameState::instance.mapAndTime.year == this->SEC_StartingYear + 1)) && (DAT_GameState::instance.gameTicksLoadBalancer == 1)) - && (( - !DAT_GameState::instance.mapAndTime.week && (bVar23 = false, 0 < this->eventsCount)))) { + && ((!DAT_GameState::instance.mapAndTime.week && (bVar23 = 0, 0 < this->eventsCount)))) { _pConditionIsMet = &this->scenarioEvents[0].data.scenario.ScenarioEventType; iVar18 = this->eventsCount; do { if ((_pConditionIsMet[-3] == 3) && (*_pConditionIsMet == 0x1e)) { - bVar23 = true; + bVar23 = 1; } _pConditionIsMet = _pConditionIsMet + 0x39; iVar18 = iVar18 + -1; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 2a69d7994d..3f9ed6471d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 63.9% | regs and case layout in condit +SHC_3BB0A8C1_0x004C31A0 | 64.0% | fire flag int; this spilled, f SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From fba895f373b66b70761d56e47974ef741a052ecb Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 21:56:56 +0100 Subject: [PATCH 55/60] reimplement: SHC_3BB0A8C1_0x004C31A0 64.47% invasion and condition structure Structural pass on processSingleplayerEvents (arm order already matched the original in all three jump tables, so the work is inside the arms): - condition loop counts conditions before the switch; the 0x27 arm compares against count - 1, the decompiler's double counter is gone - condition 8 scans later invasion events by index instead of a raw pointer - conditions 5, 6/0x11, 7 each carry their own subType branch; MSVC tail-merges them into the copy in case 5 like the original - map type read through the global instance where the original does - invasion: difficulty and crusader/arabian dispatch are switches, the score bytes are added in place, spawn clamp compares in the original's order - the three-months-ahead warning loop walks scenarioEvents by index; the old pointer stepped 0x72 events at a time instead of one (behaviour fix) Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../processSingleplayerEvents.cpp | 422 ++++++++++-------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 231 insertions(+), 193 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 2d4fc6d683..c181ad69c3 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -367,9 +367,8 @@ namespace Map { /* this is from invasion event code, ignore the meaning here */ - _spawnUnitCount = 0; + _counter = 0; for (_subIndex = 0; _subIndex < 40; _subIndex++) { - _counter = _spawnUnitCount; /* this condition is empty? then move to next condition */ @@ -377,8 +376,8 @@ namespace Map { .data.scenario.conditions[_subIndex] .enabled == 0) - goto switchD_004c3756_caseD_18; - _counter = _spawnUnitCount + 1; + continue; + _counter = _counter + 1; /* Extra event info at: 0x0165f028 */ @@ -458,7 +457,7 @@ namespace Map { cVar17 = this->scenarioEvents[_eventIndex] .data.scenario.conditions[_subIndex] .subType; - if (cVar17 == '\0') { + if (cVar17 == 0) { iVar22 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] @@ -481,74 +480,87 @@ namespace Map { } else { *_pConditionIsMet = 0; } - break; } else { - LAB_004c38d2: iVar22 = (int)cVar17; if (iVar22 == 8) { iVar22 = 7; } - iVar22 = DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[iVar22]; - if (iVar22 >= iVar18) { + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[iVar22] + >= iVar18) { *_pConditionIsMet = 1; local_a0 = local_a0 + 1; } else { *_pConditionIsMet = 0; } - break; } + break; case 6: case 0x11: iVar18 = MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::getDifficultyMultipliedValue, this)( - this->scenarioEvents[_eventIndex] + (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[_subIndex] .value); cVar17 = this->scenarioEvents[_eventIndex] .data.scenario.conditions[_subIndex] .subType; - if (cVar17 != '\0') - goto LAB_004c38d2; - iVar22 = DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[0x11] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[0x12] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[0x13] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[0x14] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[0x15] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[0x16] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[0x17] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[0x18]; - if (iVar22 >= iVar18) { - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; + if (cVar17 == 0) { + iVar22 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x11] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x12] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x13] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x14] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x15] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x16] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x17] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0x18]; + if (iVar22 >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } } else { - *_pConditionIsMet = 0; + iVar22 = (int)cVar17; + if (iVar22 == 8) { + iVar22 = 7; + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[iVar22] + >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } } break; case 7: @@ -560,41 +572,56 @@ namespace Map { cVar17 = this->scenarioEvents[_eventIndex] .data.scenario.conditions[_subIndex] .subType; - if (cVar17 != '\0') - goto LAB_004c38d2; - iVar22 = DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[0xe] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[2] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[3] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[4] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[6] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[7] - + DAT_GameState::instance - .playerDataArray[DAT_GameSynchronyState::instance - .currentPlayerSlotID] - .currentResources[9]; - if (iVar22 >= iVar18) { - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; + if (cVar17 == 0) { + iVar22 = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[0xe] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[2] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[3] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[4] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[6] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[7] + + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[9]; + if (iVar22 >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } } else { - *_pConditionIsMet = 0; + iVar22 = (int)cVar17; + if (iVar22 == 8) { + iVar22 = 7; + } + if (DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance + .currentPlayerSlotID] + .currentResources[iVar22] + >= iVar18) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } } break; LAB_004c3fcd: @@ -611,7 +638,8 @@ namespace Map { local_a0 = local_a0 + 1; } else { if (((DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) - || (this->SEC_U3_MapType2_1 != Map::MT_SIEGE)) + || (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 + != Map::MT_SIEGE)) || ((DAT_GameSynchronyState::instance.currentPlayerSlotID != 1 || (BVar11 = MACRO_CALL_MEMBER( Map::Units::TroopValueState_Func::isAttackWaveComplete, @@ -632,19 +660,13 @@ namespace Map { = this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType; if (((_scenarioEventType == 0x1a) || (!_scenarioEventType)) || (_scenarioEventType == 0x17)) { - iVar18 = _eventIndex + 1; - if (iVar18 < this->eventsCount) { - pSVar15 = this->scenarioEvents[_eventIndex + 1] - .data.scenario.conditions - + 0x19; - do { - if (((*(int const*)&pSVar15[-0x1e] == 1) - && (*(int const*)pSVar15 == 0)) - && (pSVar15[-0x1d].value == 0)) - goto switchD_004c3756_caseD_18; - iVar18 = iVar18 + 1; - pSVar15 = pSVar15 + 0x39; - } while (iVar18 < this->eventsCount); + for (iVar18 = _eventIndex + 1; iVar18 < this->eventsCount; + iVar18++) { + if (this->scenarioEvents[iVar18].header.tl_type == 1 + && this->scenarioEvents[iVar18].data.invasion.repeatMonths + == 0 + && this->scenarioEvents[iVar18].header.done == 0) + goto switchD_004c3756_caseD_18; } *_pConditionIsMet = 1; local_a0 = local_a0 + 1; @@ -863,7 +885,7 @@ namespace Map { } break; case 0x27: - if (local_a0 == _spawnUnitCount) { + if (local_a0 == _counter - 1) { MACRO_CALL(UI::DisplayElements_Func:: CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_TIME_UNTIL_VICTORY, 1); @@ -945,12 +967,11 @@ namespace Map { } break; } - switchD_004c3756_caseD_18: - _spawnUnitCount = _counter; + switchD_004c3756_caseD_18:; } if (((*(short*)((int)&this->scenarioEvents[_eventIndex].data + 8) != 0) || (!local_a0)) - && (local_a0 < _spawnUnitCount)) + && (local_a0 < _counter)) goto LAB_004c5f28; iVar18 = this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType; this->scenarioEvents[_eventIndex].header.done = 1; @@ -1103,7 +1124,8 @@ namespace Map { DAT_UnitsState::ptr)(); DAT_GameState::instance.mapAndTime.unknownCountdown01 = 0xf0; if ((DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) - && (this->SEC_U3_MapType2_1 == Map::MT_SIEGE)) { + && (DAT_MapPropertiesState::instance.SEC_U3_MapType2_1 + == Map::MT_SIEGE)) { DAT_GameState::instance.mapAndTime.unknownCountdown01 = 0x280; } MACRO_CALL(UI::DisplayElements_Func:: @@ -2367,49 +2389,60 @@ namespace Map { _unitSpawnTotalAdjustment = 10; switchD_004c5b0c_default: _invasionAmplifier = 100; - if (!DAT_GameState::instance.mapAndTime.difficulty) { + switch (DAT_GameState::instance.mapAndTime.difficulty) { + case 0: _invasionAmplifier = 50; - } else if (DAT_GameState::instance.mapAndTime.difficulty == 2) { + break; + case 2: _invasionAmplifier = 140; - } else if (DAT_GameState::instance.mapAndTime.difficulty == 3) { + break; + case 3: _invasionAmplifier = 200; + break; } _amplifiedUnitTotalForUnitType = (_invasionAmplifier * iVar18) / 100; cVar17 = (char)_amplifiedUnitTotalForUnitType; if (_unitAIBehaviourTypeUnk == 0x16) { - pabVar2 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - + DAT_TroopValueState::instance.attackInfo.inv_count; - (*pabVar2)[0] = (*pabVar2)[0] + cVar17; + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][0] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][0] + + cVar17; } else if (_unitAIBehaviourTypeUnk == 0x17) { - pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - [DAT_TroopValueState::instance.attackInfo.inv_count] - + 1; - *pbVar3 = *pbVar3 + cVar17; + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][1] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][1] + + cVar17; } else if (_unitAIBehaviourTypeUnk == 0x13) { - pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - [DAT_TroopValueState::instance.attackInfo.inv_count] - + 2; - *pbVar3 = *pbVar3 + cVar17; + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][2] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][2] + + cVar17; } else if (_unitAIBehaviourTypeUnk == 0x14) { - pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - [DAT_TroopValueState::instance.attackInfo.inv_count] - + 3; - *pbVar3 = *pbVar3 + cVar17; + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][3] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][3] + + cVar17; } else if (_unitAIBehaviourTypeUnk == 0x15) { - pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - [DAT_TroopValueState::instance.attackInfo.inv_count] - + 4; - *pbVar3 = *pbVar3 + cVar17; + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][4] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][4] + + cVar17; } else if (_unitAIBehaviourTypeUnk == 0x18) { - pbVar3 = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore - [DAT_TroopValueState::instance.attackInfo.inv_count] - + 8; - *pbVar3 = *pbVar3 + cVar17; + DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][8] + = DAT_TroopValueState::instance.attackInfo.someSinglePlayerScore + [DAT_TroopValueState::instance.attackInfo.inv_count][8] + + cVar17; } else { _spawnUnitCount = _amplifiedUnitTotalForUnitType / (_amplifiedUnitTotalForUnitType / _unitSpawnTotalAdjustment + 1); while (0 < _amplifiedUnitTotalForUnitType) { - if (_amplifiedUnitTotalForUnitType < _spawnUnitCount) { + if (_spawnUnitCount > _amplifiedUnitTotalForUnitType) { _spawnUnitCount = _amplifiedUnitTotalForUnitType; } iVar18 @@ -2452,16 +2485,16 @@ namespace Map { = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian, local_70[_crusaderOrArabian] == 0)) { local_70[_crusaderOrArabian] = 1; - if (!_crusaderOrArabian) { - pcVar25 = "infidel_attack.wav"; - pcVar10 = "sultan_nervous.bik"; - LAB_004c5e44: + switch (_crusaderOrArabian) { + case 0: MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)("", pcVar10, pcVar25); - } else if (_crusaderOrArabian == 1) { - pcVar25 = "arabian_attack.wav"; - pcVar10 = "good_soldier_nervous.bik"; - goto LAB_004c5e44; + DAT_VideoBikQueue::ptr)("", "sultan_nervous.bik", "infidel_attack.wav"); + break; + case 1: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + "", "good_soldier_nervous.bik", "arabian_attack.wav"); + break; } if ((DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_BUILD_MENU) && ((DAT_GameCore::instance.activeMenuTab.tabType @@ -2510,11 +2543,11 @@ namespace Map { _eventIndex = _eventIndex + 1; } while (_eventIndex < this->eventsCount); } - iVar18 = DAT_GameState::instance.mapAndTime.month + 3; local_88 = DAT_GameState::instance.mapAndTime.year; + iVar18 = DAT_GameState::instance.mapAndTime.month + 3; if (iVar18 >= 12) { - iVar18 = DAT_GameState::instance.mapAndTime.month + -9; - local_88 = DAT_GameState::instance.mapAndTime.year + 1; + iVar18 = iVar18 - 12; + local_88 = local_88 + 1; } local_70[0] = 0; local_70[1] = 0; @@ -2525,61 +2558,66 @@ namespace Map { local_70[6] = 0; local_70[7] = 0; local_70[8] = 0; - _eventIndex = 0; - if (0 < this->eventsCount) { - psVar21 = &this->scenarioEvents[0]; - do { - if ((((local_88 == psVar21->header.year) && (iVar18 == psVar21->header.month)) - && ((!psVar21->header.pre_done - && ((iVar22 = psVar21->header.tl_type, psVar21->header.pre_done = 1, - iVar22 == 1 - && (DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 1, - DAT_GameCore::instance.section1076 == 0)))))) - && (iVar22 = (psVar21->data).invasion.crusaderArabian, local_70[iVar22] == 0)) { - iVar20 = 0; - iVar1 = iVar22 * 4; - numInGroup = iVar1 + 1; - for (int k = 0; k < 25; k++) { - iVar20 = iVar20 + (psVar21->data).invasion.unitCountsPerUnitType[k]; - } - if (iVar20 >= 0x19) { - if (iVar20 < 0x4b) { - numInGroup = iVar1 + 2; - } else if (iVar20 < 0x96) { - numInGroup = iVar1 + 3; - } else { - numInGroup = iVar1 + 4; - } - } - local_70[iVar22] = 1; - if (!iVar22) { - MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)( - MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), - "good_arab_nervous.bik", - (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); - } else if (iVar22 == 1) { - MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)( - MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), - "good_soldier_nervous.bik", - (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); - } + for (_eventIndex = 0; _eventIndex < this->eventsCount; _eventIndex++) { + if (local_88 != this->scenarioEvents[_eventIndex].header.year + || iVar18 != this->scenarioEvents[_eventIndex].header.month + || this->scenarioEvents[_eventIndex].header.pre_done != 0) { + continue; + } + this->scenarioEvents[_eventIndex].header.pre_done = 1; + if (this->scenarioEvents[_eventIndex].header.tl_type != 1) { + continue; + } + DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 1; + if (DAT_GameCore::instance.section1076 != 0) { + continue; + } + iVar22 = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian; + if (local_70[iVar22] != 0) { + continue; + } + iVar20 = 0; + numInGroup = iVar22 * 4 + 1; + for (int k = 0; k < 25; k++) { + iVar20 + = iVar20 + this->scenarioEvents[_eventIndex].data.invasion.unitCountsPerUnitType[k]; + } + if (iVar20 >= 25) { + if (iVar20 < 75) { + numInGroup = numInGroup + 1; + } else if (iVar20 < 150) { + numInGroup = numInGroup + 2; + } else { + numInGroup = numInGroup + 3; } - LAB_004c609a: - _eventIndex = _eventIndex + 1; - psVar21 = psVar21 + 0x72; - } while (_eventIndex < this->eventsCount); + } + local_70[iVar22] = 1; + switch (iVar22) { + case 0: + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), + "good_arab_nervous.bik", + (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); + break; + case 1: + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), + "good_soldier_nervous.bik", + (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); + break; + } } if ((DAT_GameState::instance.gameTicksLoadBalancer == 0x97) && (DAT_GameState::instance.mapAndTime.week == 3)) { iVar22 = DAT_GameState::instance.mapAndTime.month + 1; iVar18 = DAT_GameState::instance.mapAndTime.year; if (iVar22 >= 12) { - iVar22 = DAT_GameState::instance.mapAndTime.month + -0xb; - iVar18 = DAT_GameState::instance.mapAndTime.year + 1; + iVar22 = iVar22 - 12; + iVar18 = iVar18 + 1; } iVar21 = 0; if (0 < this->eventsCount) { diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index c9691e8368..fd5a0e0e5f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 64.0% | fire flag int; this spilled, f +SHC_3BB0A8C1_0x004C31A0 | 64.5% | this vs numMet reg; tail merge SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 0cd606abcd69501c2f6988facfe1438bb9762766 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 22:32:34 +0100 Subject: [PATCH 56/60] reimplement: SHC_3BB0A8C1_0x004C31A0 65.90% per-branch video calls, index loops - actions 0x1d/0x1e call playEventVideoBik in each branch instead of picking the text id first; the original has separate pushes per branch that MSVC only produces from duplicated calls (tail-merged at the shared call) - spreadFireRandomlyToBuildings takes the player slot explicitly instead of a stale iVar18 holding the same value - conditions 0xc, 0x12, 0x13 count units/buildings with index loops over the named fields instead of pointer walks with raw offsets - condition 0x27 tests the remaining time as <= 0 - repeat tail decrements the event index before sorting, as the original does Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../processSingleplayerEvents.cpp | 245 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 129 insertions(+), 118 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index c181ad69c3..05bd5fa807 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -716,37 +716,37 @@ namespace Map { break; case 0xc: iVar18 = 0; - if (DAT_UnitsState::instance.maxUnitCount < 2) - goto LAB_004c3fcd; - pUVar12 = &DAT_UnitsState::instance.units[1].unitType; - iVar22 = DAT_UnitsState::instance.maxUnitCount - 1; - do { - if (((((pUVar12[-1] == Map::Units::ULS_NORMAL) - && ((short)pUVar12[4] - == DAT_GameSynchronyState::instance.currentPlayerSlotID)) - && (*(byte*)(pUVar12 + 0x14f) == 0)) - && (((((pUVar12[0x165] == 0 - && (UVar6 = *pUVar12, - UVar6 != Map::Units::UT_E_LADDER)) - && ((UVar6 != Map::Units::UT_E_ENGINEER - || (pUVar12[0x17d] != 0)))) - && ((UVar6 != Map::Units::UT_S_TOWER - && (UVar6 != Map::Units::UT_S_BATTERINGRAM)))) - && (UVar6 != Map::Units::UT_S_SHIELD)))) - && ((((UVar6 != Map::Units::UT_S_MANGONEL - && (UVar6 != Map::Units::UT_S_BALLISTA)) - && (UVar6 != Map::Units::UT_S_CATAPULT)) - && ((UVar6 != Map::Units::UT_S_FBALLISTA - && (UVar6 != Map::Units::UT_S_TREBUCHET)))))) { - iVar18 = iVar18 + 1; + for (iVar22 = 1; iVar22 < DAT_UnitsState::instance.maxUnitCount; iVar22++) { + if (DAT_UnitsState::instance.units[iVar22].logicalState + == Map::Units::ULS_NORMAL + && DAT_UnitsState::instance.units[iVar22].owner + == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_UnitsState::instance.units[iVar22].isStalked == 0 + && DAT_UnitsState::instance.units[iVar22].unknownTestAgainst0_2 + == 0) { + UVar6 = DAT_UnitsState::instance.units[iVar22].unitType; + if (UVar6 != Map::Units::UT_E_LADDER + && (UVar6 != Map::Units::UT_E_ENGINEER + || DAT_UnitsState::instance.units[iVar22].resourceToDeposit + != 0) + && UVar6 != Map::Units::UT_S_TOWER + && UVar6 != Map::Units::UT_S_BATTERINGRAM + && UVar6 != Map::Units::UT_S_SHIELD + && UVar6 != Map::Units::UT_S_MANGONEL + && UVar6 != Map::Units::UT_S_BALLISTA + && UVar6 != Map::Units::UT_S_CATAPULT + && UVar6 != Map::Units::UT_S_FBALLISTA + && UVar6 != Map::Units::UT_S_TREBUCHET) { + iVar18 = iVar18 + 1; + } } - pUVar12 = pUVar12 + 0x248; - iVar22 = iVar22 + -1; - } while (iVar22); - if (iVar18) - goto LAB_004c37cd; - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; + } + if (iVar18 == 0) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } break; case 0xd: cVar17 = this->scenarioEvents[_eventIndex] @@ -896,7 +896,7 @@ namespace Map { this->SEC_Section1090 = this->SEC_Section1080; } this->SEC_Section1081 = 1; - if (this->SEC_Section1080 < 1) { + if (this->SEC_Section1080 <= 0) { *_pConditionIsMet = 1; local_a0 = local_a0 + 1; } @@ -916,55 +916,53 @@ namespace Map { } break; case 0x12: - if (DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) { - iVar18 = 0; - if (DAT_BuildingsState::instance.maxBuildingsCount < 2) - goto LAB_004c37cd; - pBVar13 = &DAT_BuildingsState::instance.buildings[1].buildingType; - iVar22 = DAT_BuildingsState::instance.maxBuildingsCount + -1; - do { - if (((pBVar13[-1] != ((BuildingLogicalState)0)) - && (*pBVar13 == Map::Buildings::BT_DAIRYFARM)) - && (pBVar13[0x65] == 0)) { - iVar18 = iVar18 + 1; - } - pBVar13 = pBVar13 + 0x196; - iVar22 = iVar22 + -1; - } while (iVar22); - if (iVar18 >= 4) { - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; - } else { - *_pConditionIsMet = 0; - } + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { break; } + iVar18 = 0; + for (iVar22 = 1; iVar22 < DAT_BuildingsState::instance.maxBuildingsCount; + iVar22++) { + if (DAT_BuildingsState::instance.buildings[iVar22].logicalState != 0 + && DAT_BuildingsState::instance.buildings[iVar22].buildingType + == Map::Buildings::BT_DAIRYFARM + && DAT_BuildingsState::instance.buildings[iVar22] + .currentlyNeededEmployeeCount + == 0) { + iVar18 = iVar18 + 1; + } + } + if (iVar18 >= 4) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } break; case 0x13: - if (DAT_GameCore::instance.gameMode_2 != Game::GM_BUILDERUnk) { - iVar18 = 0; - if (DAT_BuildingsState::instance.maxBuildingsCount < 2) - goto LAB_004c37cd; - pBVar13 = &DAT_BuildingsState::instance.buildings[1].buildingType; - iVar22 = DAT_BuildingsState::instance.maxBuildingsCount + -1; - do { - if ((((pBVar13[-1] != ((BuildingLogicalState)0)) - && (*pBVar13 == Map::Buildings::BT_INN)) - && (pBVar13[0x65] == 0)) - && (0 < (short)pBVar13[0xef])) { - iVar18 = iVar18 + 1; - } - pBVar13 = pBVar13 + 0x196; - iVar22 = iVar22 + -1; - } while (iVar22); - if (iVar18 >= 2) { - *_pConditionIsMet = 1; - local_a0 = local_a0 + 1; - } else { - *_pConditionIsMet = 0; - } + if (DAT_GameCore::instance.gameMode_2 == Game::GM_BUILDERUnk) { break; } + iVar18 = 0; + for (iVar22 = 1; iVar22 < DAT_BuildingsState::instance.maxBuildingsCount; + iVar22++) { + if (DAT_BuildingsState::instance.buildings[iVar22].logicalState != 0 + && DAT_BuildingsState::instance.buildings[iVar22].buildingType + == Map::Buildings::BT_INN + && DAT_BuildingsState::instance.buildings[iVar22] + .currentlyNeededEmployeeCount + == 0 + && DAT_BuildingsState::instance.buildings[iVar22] + .flagonsOfAleOrCheeseOrReleaseDogs + > 0) { + iVar18 = iVar18 + 1; + } + } + if (iVar18 >= 2) { + *_pConditionIsMet = 1; + local_a0 = local_a0 + 1; + } else { + *_pConditionIsMet = 0; + } break; } switchD_004c3756_caseD_18:; @@ -1312,8 +1310,8 @@ namespace Map { this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; } LAB_004c4621: - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 6: DAT_GameCore::instance.isTimeHalted = TRUE; @@ -1426,8 +1424,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0xc: iVar18 = MACRO_CALL_MEMBER( @@ -1472,8 +1470,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0xd: iVar18 = MACRO_CALL_MEMBER( @@ -1518,8 +1516,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0xe: iVar18 = MACRO_CALL_MEMBER( @@ -1569,8 +1567,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0xf: MACRO_CALL_MEMBER(Map::LandscapeState_Func::ageFourFifthsOfGrowingTrees, @@ -1607,8 +1605,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x10: iVar18 = MACRO_CALL_MEMBER( @@ -1667,8 +1665,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x11: { uint uStack_7c; @@ -1745,8 +1743,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; } case 0x12: @@ -1827,8 +1825,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x13: iVar18 = MACRO_CALL_MEMBER( @@ -1881,8 +1879,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x14: BVar11 = MACRO_CALL_MEMBER( @@ -2021,8 +2019,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x15: DAT_GameState::instance.mapAndTime.unitLadyRelated = 1; @@ -2075,20 +2073,26 @@ namespace Map { DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID, this->scenarioEvents[_eventIndex].data.scenario.actionData); + /* added by script: "Thieves have stolen some food from our granary." */ if (this->scenarioEvents[_eventIndex].data.scenario.actionData == 100) { - iVar18 = 0x10; + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x10), + DAT_MissionAestheticsDefinedData::instance.RandomEvent14VideoName, + "general_message3.wav"); } else { - iVar18 = 0xe; + MACRO_CALL_MEMBER( + Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER( + Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xe), + DAT_MissionAestheticsDefinedData::instance.RandomEvent14VideoName, + "general_message3.wav"); } - /* - added by script: "Thieves have stolen some food from our granary." - */ - MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)( - MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18), - DAT_MissionAestheticsDefinedData::instance.RandomEvent14VideoName, - "general_message3.wav"); } bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) @@ -2112,8 +2116,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x1e: DAT_GameState::instance @@ -2122,33 +2126,40 @@ namespace Map { MACRO_CALL_MEMBER( Map::Buildings::BuildingsState_Func::spreadFireRandomlyToBuildings, DAT_BuildingsState::ptr)( - iVar18, this->scenarioEvents[_eventIndex].data.scenario.actionData); - iVar18 = MACRO_CALL_MEMBER( - Map::Buildings::BuildingsState_Func::findFirstBuildingOfType, - DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID, - Map::Buildings::BT_WELL); - if (iVar18) { - iVar18 = 0xf; + this->scenarioEvents[_eventIndex].data.scenario.actionData); + /* added by script: "There is fire in the castle and we have not built any wells + * my Liege!" */ + if (MACRO_CALL_MEMBER( + Map::Buildings::BuildingsState_Func::findFirstBuildingOfType, + DAT_BuildingsState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, + Map::Buildings::BT_WELL)) { + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xf), + DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName, + "general_warning16.wav"); } else if (MACRO_CALL_MEMBER( Map::Buildings::BuildingsState_Func::findFirstBuildingOfType, DAT_BuildingsState::ptr)( DAT_GameSynchronyState::instance.currentPlayerSlotID, Map::Buildings::BT_WATERPOT)) { - iVar18 = 0xf; + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0xf), + DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName, + "general_warning16.wav"); } else { - iVar18 = 0x11; + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, 0x11), + DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName, + "general_warning16.wav"); } - /* - added by script: "There is fire in the castle and we have not built any - wells my Liege!" - */ - MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, - DAT_VideoBikQueue::ptr)( - MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_ACTION, iVar18), - DAT_MissionAestheticsDefinedData::instance.RandomEvent15VideoName, - "general_warning16.wav"); bVar4 = this->scenarioEvents[_eventIndex].data.scenario.repeat; if ((!bVar4) || (bVar5 = this->scenarioEvents[_eventIndex].data.scenario.repeatMonths, @@ -2171,8 +2182,8 @@ namespace Map { goto LAB_004c4621; this->scenarioEvents[_eventIndex].header.year++; this->scenarioEvents[_eventIndex].header.month = iVar18 + -0xc; - MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); _eventIndex = _eventIndex + -1; + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::sortEventsByDate, this)(); break; case 0x17: if (((DAT_GameCore::instance.gameMode_2 != Game::GM_CAMPAIGN_MISSION) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index fd5a0e0e5f..178280087e 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 64.5% | this vs numMet reg; tail merge +SHC_3BB0A8C1_0x004C31A0 | 65.9% | this vs numMet reg; tail merge SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 50a200c64cd36f94edc03bd4629a3a1faaba6c9f Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 23:16:03 +0100 Subject: [PATCH 57/60] reimplement: SHC_3BB0A8C1_0x004C31A0 66.72% sum order, compare direction, switches - resource and hit-count sums are written highest index first; MSVC evaluates the chain from the right, so this gives the original's load order - conditions 0xd/0xe compare the hit count against the target (count >= value) like the original's cmp [hits], value; jl - the three-months-ahead warning loop and the next-month countdown loop dispatch on tl_type with a switch: the original tests it with sub reg,1; jne and reuses the zero, which a plain == 1 test does not give - invasion signpost index wraps with local_88 >= count Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../processSingleplayerEvents.cpp | 192 +++++++++--------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 98 insertions(+), 96 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 05bd5fa807..293cb7744a 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -461,19 +461,19 @@ namespace Map { iVar22 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[10] + .currentResources[0xd] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0xb] + .currentResources[0xc] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0xc] + .currentResources[0xb] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0xd]; + .currentResources[10]; if (iVar22 >= iVar18) { *_pConditionIsMet = 1; local_a0 = local_a0 + 1; @@ -511,35 +511,35 @@ namespace Map { iVar22 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0x11] + .currentResources[0x18] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0x12] + .currentResources[0x17] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0x13] + .currentResources[0x16] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0x14] + .currentResources[0x15] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0x15] + .currentResources[0x14] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0x16] + .currentResources[0x13] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0x17] + .currentResources[0x12] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0x18]; + .currentResources[0x11]; if (iVar22 >= iVar18) { *_pConditionIsMet = 1; local_a0 = local_a0 + 1; @@ -576,15 +576,15 @@ namespace Map { iVar22 = DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[0xe] + .currentResources[9] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[2] + .currentResources[7] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[3] + .currentResources[6] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] @@ -592,15 +592,15 @@ namespace Map { + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[6] + .currentResources[3] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[7] + .currentResources[2] + DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance .currentPlayerSlotID] - .currentResources[9]; + .currentResources[0xe]; if (iVar22 >= iVar18) { *_pConditionIsMet = 1; local_a0 = local_a0 + 1; @@ -754,30 +754,29 @@ namespace Map { .subType; if (cVar17 != '\0') { if (((byte)(cVar17 - 1U) <= 3) - && ((int)this->scenarioEvents[_eventIndex] + && (DAT_GameState::instance.mapAndTime + .hitsDealtToPlayerArray[cVar17 + 1] + >= (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[_subIndex] - .value - <= DAT_GameState::instance.mapAndTime - .hitsDealtToPlayerArray[cVar17 + 1])) { + .value)) { DAT_GameState::instance.mapAndTime .hitsDealtToPlayerArray[cVar17 + 1] = 0; *_pConditionIsMet = 1; local_a0 = local_a0 + 1; } } else { - if ((int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[_subIndex] - .value - <= DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[0] - + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[1] - + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[2] - + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[3] - + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[4] - + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[5] - + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[6] + if (DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[8] + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[7] - + DAT_GameState::instance.mapAndTime - .hitsDealtToPlayerArray[8]) { + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[6] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[5] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[4] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[3] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[2] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[1] + + DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[0] + >= (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value) { DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[0] = 0; DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[1] = 0; DAT_GameState::instance.mapAndTime.hitsDealtToPlayerArray[2] = 0; @@ -798,28 +797,27 @@ namespace Map { .subType; if (cVar17 != '\0') { if (((byte)(cVar17 - 1U) <= 3) - && ((int)this->scenarioEvents[_eventIndex] + && (DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + 1] + >= (int)this->scenarioEvents[_eventIndex] .data.scenario.conditions[_subIndex] - .value - <= DAT_GameState::instance.mapAndTime - .emenyHitArray[cVar17 + 1])) { + .value)) { DAT_GameState::instance.mapAndTime.emenyHitArray[cVar17 + 1] = 0; *_pConditionIsMet = 1; local_a0 = local_a0 + 1; } } else { - if ((int)this->scenarioEvents[_eventIndex] - .data.scenario.conditions[_subIndex] - .value - <= DAT_GameState::instance.mapAndTime.emenyHitArray[0] - + DAT_GameState::instance.mapAndTime.emenyHitArray[1] - + DAT_GameState::instance.mapAndTime.emenyHitArray[2] - + DAT_GameState::instance.mapAndTime.emenyHitArray[3] - + DAT_GameState::instance.mapAndTime.emenyHitArray[4] - + DAT_GameState::instance.mapAndTime.emenyHitArray[5] - + DAT_GameState::instance.mapAndTime.emenyHitArray[6] + if (DAT_GameState::instance.mapAndTime.emenyHitArray[8] + DAT_GameState::instance.mapAndTime.emenyHitArray[7] - + DAT_GameState::instance.mapAndTime.emenyHitArray[8]) { + + DAT_GameState::instance.mapAndTime.emenyHitArray[6] + + DAT_GameState::instance.mapAndTime.emenyHitArray[5] + + DAT_GameState::instance.mapAndTime.emenyHitArray[4] + + DAT_GameState::instance.mapAndTime.emenyHitArray[3] + + DAT_GameState::instance.mapAndTime.emenyHitArray[2] + + DAT_GameState::instance.mapAndTime.emenyHitArray[1] + + DAT_GameState::instance.mapAndTime.emenyHitArray[0] + >= (int)this->scenarioEvents[_eventIndex] + .data.scenario.conditions[_subIndex] + .value) { DAT_GameState::instance.mapAndTime.emenyHitArray[0] = 0; DAT_GameState::instance.mapAndTime.emenyHitArray[1] = 0; DAT_GameState::instance.mapAndTime.emenyHitArray[2] = 0; @@ -2476,7 +2474,7 @@ namespace Map { local_88 = local_88 + 1; _amplifiedUnitTotalForUnitType = _amplifiedUnitTotalForUnitType - _spawnUnitCount; - if (local_70[9] <= local_88) { + if (local_88 >= local_70[9]) { local_88 = 0; } } @@ -2576,49 +2574,50 @@ namespace Map { continue; } this->scenarioEvents[_eventIndex].header.pre_done = 1; - if (this->scenarioEvents[_eventIndex].header.tl_type != 1) { - continue; - } - DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 1; - if (DAT_GameCore::instance.section1076 != 0) { - continue; - } - iVar22 = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian; - if (local_70[iVar22] != 0) { - continue; - } - iVar20 = 0; - numInGroup = iVar22 * 4 + 1; - for (int k = 0; k < 25; k++) { - iVar20 - = iVar20 + this->scenarioEvents[_eventIndex].data.invasion.unitCountsPerUnitType[k]; - } - if (iVar20 >= 25) { - if (iVar20 < 75) { - numInGroup = numInGroup + 1; - } else if (iVar20 < 150) { - numInGroup = numInGroup + 2; - } else { - numInGroup = numInGroup + 3; - } - } - local_70[iVar22] = 1; - switch (iVar22) { - case 0: - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( - MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), - "good_arab_nervous.bik", - (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); - break; + switch (this->scenarioEvents[_eventIndex].header.tl_type) { case 1: - MACRO_CALL_MEMBER( - Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, DAT_VideoBikQueue::ptr)( - MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, - DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), - "good_soldier_nervous.bik", - (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); + DAT_GameState::instance.mapAndTime.field3171_0x27a8 = 1; + if (DAT_GameCore::instance.section1076 != 0) { + continue; + } + iVar22 = this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian; + if (local_70[iVar22] != 0) { + continue; + } + iVar20 = 0; + numInGroup = iVar22 * 4 + 1; + for (int k = 0; k < 25; k++) { + iVar20 = iVar20 + + this->scenarioEvents[_eventIndex].data.invasion.unitCountsPerUnitType[k]; + } + if (iVar20 >= 25) { + if (iVar20 < 75) { + numInGroup = numInGroup + 1; + } else if (iVar20 < 150) { + numInGroup = numInGroup + 2; + } else { + numInGroup = numInGroup + 3; + } + } + local_70[iVar22] = 1; + switch (iVar22) { + case 0: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), + "good_arab_nervous.bik", + (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); + break; + case 1: + MACRO_CALL_MEMBER(Rendering::Bink::AIMessageQueue_Func::playEventVideoBik, + DAT_VideoBikQueue::ptr)( + MACRO_CALL_MEMBER(Text::TextManager_Func::getTextStringInGroupAtOffset, + DAT_TextManagerObject::ptr)(DE::SHCDE::TEXT_SANDS_OF_TIME, numInGroup), + "good_soldier_nervous.bik", + (&DAT_MissionAestheticsDefinedData::instance.field_0xec)[numInGroup]); + break; + } break; } } @@ -2634,9 +2633,12 @@ namespace Map { if (0 < this->eventsCount) { pIVar16 = this->scenarioEvents; do { - if (((iVar18 == (pIVar16->header).year) && (iVar22 == (pIVar16->header).month)) - && ((pIVar16->header).tl_type == 1)) { - DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown = 40; + if (iVar18 == (pIVar16->header).year && iVar22 == (pIVar16->header).month) { + switch ((pIVar16->header).tl_type) { + case 1: + DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown = 40; + break; + } } iVar21 = iVar21 + 1; pIVar16 = pIVar16 + 1; diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 178280087e..6b9e005b38 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 65.9% | this vs numMet reg; tail merge +SHC_3BB0A8C1_0x004C31A0 | 66.7% | this vs numMet reg alloc SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From 5c7245b0eb13afa0953cbc5806a195042b012133 Mon Sep 17 00:00:00 2001 From: Gynt Date: Fri, 4 Dec 2026 23:56:39 +0100 Subject: [PATCH 58/60] reimplement: SHC_3BB0A8C1_0x004C31A0 67.53% drop stale slot temp, named fields - the action switch no longer preloads the player slot into iVar18; actions 0xb, 0x15, 0x16 read currentPlayerSlotID themselves, which is what the original does (every arm reloads it) - raw data+offset casts replaced with the fields they hit: conditions[0x27].value, allOrAnyCondition, conditions[n].enabled, invasion.crusaderArabian, invasion.unitCountsPerUnitType[] - action 0x1c (cancel repeating invasions) and the well/waterpot check walk by index over named fields instead of offset pointers; the 0x1c loop keeps the do/while shape, which compiles identically to the original Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- .../processSingleplayerEvents.cpp | 119 ++++++++++-------- status/addresses-SHC-3BB0A8C1.txt | 2 +- 2 files changed, 67 insertions(+), 54 deletions(-) diff --git a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp index 293cb7744a..e534fc3da7 100644 --- a/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp +++ b/src/OpenSHC/Map/MapPropertiesState/processSingleplayerEvents.cpp @@ -312,19 +312,15 @@ namespace Map { /* if a fire warning event */ - iVar18 = 0; - if (0 < DAT_BuildingsState::instance.maxBuildingsCount) { - pBVar13 = &DAT_BuildingsState::instance.buildings[0].buildingType; - do { - if (((pBVar13[-1] != ((BuildingLogicalState)0)) - && ((short)pBVar13[2] - == DAT_GameSynchronyState::instance.currentPlayerSlotID)) - && ((*pBVar13 == Map::Buildings::BT_WELL - || (*pBVar13 == Map::Buildings::BT_WATERPOT)))) - goto LAB_004c3637; - iVar18 = iVar18 + 1; - pBVar13 = pBVar13 + 0x196; - } while (iVar18 < DAT_BuildingsState::instance.maxBuildingsCount); + for (iVar18 = 0; iVar18 < DAT_BuildingsState::instance.maxBuildingsCount; iVar18++) { + if (DAT_BuildingsState::instance.buildings[iVar18].logicalState != 0 + && DAT_BuildingsState::instance.buildings[iVar18].owner + == DAT_GameSynchronyState::instance.currentPlayerSlotID + && (DAT_BuildingsState::instance.buildings[iVar18].buildingType + == Map::Buildings::BT_WELL + || DAT_BuildingsState::instance.buildings[iVar18].buildingType + == Map::Buildings::BT_WATERPOT)) + goto LAB_004c3637; } /* "there are no wells in the castle my liege. should a fire break out, we are int @@ -888,8 +884,9 @@ namespace Map { CheckDisplayElementByIDAndSetForUnlimitedDisplay)( UI::Enums::DEID_TIME_UNTIL_VICTORY, 1); if (!this->SEC_Section1081) { - this->SEC_Section1080 - = *(short*)((int)&this->scenarioEvents[_eventIndex].data + 0xa8) + this->SEC_Section1080 = this->scenarioEvents[_eventIndex] + .data.scenario.conditions[0x27] + .value * 800; this->SEC_Section1090 = this->SEC_Section1080; } @@ -965,14 +962,13 @@ namespace Map { } switchD_004c3756_caseD_18:; } - if (((*(short*)((int)&this->scenarioEvents[_eventIndex].data + 8) != 0) + if (((this->scenarioEvents[_eventIndex].data.scenario.allOrAnyCondition != 0) || (!local_a0)) && (local_a0 < _counter)) goto LAB_004c5f28; iVar18 = this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType; this->scenarioEvents[_eventIndex].header.done = 1; DAT_GameState::instance.mapAndTime.scenarioEventTimers[iVar18] = 1; - iVar18 = DAT_GameSynchronyState::instance.currentPlayerSlotID; switch (this->scenarioEvents[_eventIndex].data.scenario.ScenarioEventType) { case 0x1a: if (DAT_GameState::instance @@ -1061,23 +1057,35 @@ namespace Map { DAT_MouseState::ptr)(); } this->field133_0x145d8 = 0; - if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x13) + if (this->scenarioEvents[_eventIndex] + .data.scenario.conditions[1] + .enabled != 0) { this->field133_0x145d8 = 1; MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::sortEventsByDate, this)(); - } else if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x1f) + } else if (this->scenarioEvents[_eventIndex] + .data.scenario.conditions[4] + .enabled != 0) { this->field133_0x145d8 = 2; MACRO_CALL_MEMBER( Map::MapPropertiesState_Func::sortEventsByDate, this)(); - } else if (*(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x23) + } else if (this->scenarioEvents[_eventIndex] + .data.scenario.conditions[5] + .enabled == 0 - && *(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x27) + && this->scenarioEvents[_eventIndex] + .data.scenario.conditions[6] + .enabled == 0 - && *(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x2b) + && this->scenarioEvents[_eventIndex] + .data.scenario.conditions[7] + .enabled == 0 - && *(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x53) + && this->scenarioEvents[_eventIndex] + .data.scenario.conditions[17] + .enabled == 0) { this->field133_0x145d8 = 1; MACRO_CALL_MEMBER( @@ -1382,10 +1390,14 @@ namespace Map { DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .eventPlagueCountdown = 0x18; - iVar22 = DAT_GameState::instance.playerDataArray[iVar18].popularity; + iVar22 + = DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity; if (6000 < iVar22) { - DAT_GameState::instance.playerDataArray[iVar18].popularity - = (iVar22 + -6000) / 2 + 6000; + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity = (iVar22 + -6000) / 2 + 6000; } MACRO_CALL_MEMBER(Game::GameStateStructures_Func:: spawnPoisonCloudsAtRandomStorageOrArmyBuilding, @@ -2025,8 +2037,12 @@ namespace Map { DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .eventMarriageCountdown = 0xc; - if (10000 < DAT_GameState::instance.playerDataArray[iVar18].popularity) { - DAT_GameState::instance.playerDataArray[iVar18].popularity = 10000; + if (10000 < DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity = 10000; } /* added by script: "The people rejoice at your forthcoming marriage, Sire." @@ -2046,8 +2062,12 @@ namespace Map { DAT_GameState::instance .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] .eventJesterCountdown = 0x30; - if (10000 < DAT_GameState::instance.playerDataArray[iVar18].popularity) { - DAT_GameState::instance.playerDataArray[iVar18].popularity = 10000; + if (10000 < DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity) { + DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .popularity = 10000; } /* added by script: "A Jester has arrived at the castle Liege. I have taken @@ -2223,16 +2243,14 @@ namespace Map { case 0x1c: iVar18 = 0; if (0 < this->eventsCount) { - pSVar15 = this->scenarioEvents[0].data.scenario.conditions + 0x19; do { - if ((*(int const*)&pSVar15[-0x1e] == 1) - && (*(int const*)pSVar15 != 0)) { - *(int*)pSVar15 = 0; - pSVar15[-0x1d].value = 1; - *(int*)&pSVar15[-0x1f] = 0x49d; + if (this->scenarioEvents[iVar18].header.tl_type == 1 + && this->scenarioEvents[iVar18].data.invasion.repeatMonths != 0) { + this->scenarioEvents[iVar18].data.invasion.repeatMonths = 0; + this->scenarioEvents[iVar18].header.done = 1; + this->scenarioEvents[iVar18].header.year = 1181; } iVar18 = iVar18 + 1; - pSVar15 = pSVar15 + 0x39; } while (iVar18 < this->eventsCount); } default: @@ -2275,15 +2293,15 @@ namespace Map { DAT_TroopValueState::instance.attackInfo.inv_count = iVar18; DAT_TroopValueState::instance.attackInfo .attackWavePlayerIDArray[DAT_TroopValueState::instance.attackInfo.inv_count] - = *(char*)((int)&this->scenarioEvents[_eventIndex].data + 0x74) + 2; + = (char)this->scenarioEvents[_eventIndex].data.invasion.crusaderArabian + 2; _subIndex = 0; do { /* if invasion.units[index] == 0 then index += 1 (break when not index < 0x19) */ - iVar18 - = *(int*)((int)&this->scenarioEvents[_eventIndex].data + _subIndex * 4 + 4); + iVar18 = this->scenarioEvents[_eventIndex] + .data.invasion.unitCountsPerUnitType[_subIndex]; if (!iVar18) goto LAB_004c5db4; _unitAIBehaviourTypeUnk = 0; @@ -2629,20 +2647,15 @@ namespace Map { iVar22 = iVar22 - 12; iVar18 = iVar18 + 1; } - iVar21 = 0; - if (0 < this->eventsCount) { - pIVar16 = this->scenarioEvents; - do { - if (iVar18 == (pIVar16->header).year && iVar22 == (pIVar16->header).month) { - switch ((pIVar16->header).tl_type) { - case 1: - DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown = 40; - break; - } + for (iVar21 = 0; iVar21 < this->eventsCount; iVar21++) { + if (iVar18 == this->scenarioEvents[iVar21].header.year + && iVar22 == this->scenarioEvents[iVar21].header.month) { + switch (this->scenarioEvents[iVar21].header.tl_type) { + case 1: + DAT_GameState::instance.mapAndTime.gameEventRelatedCountdown = 40; + break; } - iVar21 = iVar21 + 1; - pIVar16 = pIVar16 + 1; - } while (iVar21 < this->eventsCount); + } } } } diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 6b9e005b38..95e645b535 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 66.7% | this vs numMet reg alloc +SHC_3BB0A8C1_0x004C31A0 | 67.5% | this vs numMet reg alloc SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From ba5bd563abfdb5f139c1897b800f0c83ed5f6592 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 10:27:45 +0100 Subject: [PATCH 59/60] status: SHC_3BB0A8C1_0x004C31A0 67.5%, tail call already matches Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- status/addresses-SHC-3BB0A8C1.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index eeb29513bc..8427b2d524 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -33901,7 +33901,7 @@ SHC_3BB0A8C1_0x004C2280 | 100.0% | Reimplemented (counted: only the resetMouseCu SHC_3BB0A8C1_0x004C3110 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C31A0 | 67.5% | this vs numMet reg alloc +SHC_3BB0A8C1_0x004C31A0 | 67.5% | this vs numMet reg alloc: the original keeps this in ebx and zero in edi, ours swaps them; our frame is 0x98 against the original's 0xa0 and the body is 0x91 bytes shorter. The tail call to updateMilitaryCampaignMissionState (jmp 0x004C2280) is already emitted, so the address-taken-locals tail-call fix does not apply SHC_3BB0A8C1_0x004C35B0 | 0.0% | Pending From b5acb5104ea4d98cc0da611007ed9f70eea00dc7 Mon Sep 17 00:00:00 2001 From: Gynt Date: Sat, 5 Dec 2026 10:31:34 +0100 Subject: [PATCH 60/60] status: SetupSkirmishMode measures 83.2 after merging main; precise remarks Measured with a full build and reccmp, both resolver sets on. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XmXCmXCVBvESeaU1djQFjp --- status/addresses-SHC-3BB0A8C1.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index eeb29513bc..e3226b572f 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -30257,7 +30257,7 @@ SHC_3BB0A8C1_0x004BD980 | 0.0% | Pending SHC_3BB0A8C1_0x004BDA80 | 0.0% | Pending -SHC_3BB0A8C1_0x004BDE40 | 88.7% | *5 arm store not merged (regs) +SHC_3BB0A8C1_0x004BDE40 | 88.7% | goods-score switches: the *5 arm shares the default's store in the original, ours shares the *50 one (temp registers alternate); no case order changes it SHC_3BB0A8C1_0x004BDE80 | 0.0% | Pending @@ -34147,7 +34147,7 @@ SHC_3BB0A8C1_0x004C6820 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C6880 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C68D0 | 82.6% | mission defs in head; idiv reg +SHC_3BB0A8C1_0x004C68D0 | 83.2% | the original picks the mission in one register per arm (default first); written that way, mission and the constant 1 swap esi/edi; idiv divisor in esi SHC_3BB0A8C1_0x004C6B20 | 100.0% | Reimplemented