diff --git a/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp b/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp new file mode 100644 index 0000000000..b2633a8373 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/SkirmishLeaderboard_DeleteEntry.cpp @@ -0,0 +1,28 @@ +#include "../Skirmish.func.hpp" + +#include "OpenSHC/IO.func.hpp" + +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" + +namespace OpenSHC { +namespace Game { + + /* + Removes the skirmish leaderboard entry at the given index by shifting all later entries down by one, + decrementing the count and saving the table to disk (SkMasters2). + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004D5370 + void Skirmish::SkirmishLeaderboard_DeleteEntry(int index) + { + if (index < 0 || index >= DAT_SkMasters2Data::instance.count) { + return; + } + for (int i = index; i < DAT_SkMasters2Data::instance.count - 1; i++) { + DAT_SkMasters2Data::instance.entries[i] = DAT_SkMasters2Data::instance.entries[i + 1]; + } + DAT_SkMasters2Data::instance.count--; + MACRO_CALL(IO_Func::WriteSkMasters2)(); + } + +} // namespace Game +} // namespace OpenSHC diff --git a/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp b/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp new file mode 100644 index 0000000000..46c0acaf24 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/SkirmishLobbySetupStructure/restoreSkirmishLobbySetup.cpp @@ -0,0 +1,62 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#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 { + + /* + Copies the skirmish lobby settings that were saved in this structure back into the synchrony state and the + game core, then lets the synchrony state reorder the teams and positions. + */ + // FUNCTION: STRONGHOLDCRUSADER 0x00490060 + void SkirmishLobbySetupStructure::restoreSkirmishLobbySetup() + { + DAT_GameSynchronyState::instance.skirmishAutoSaveEveryMinutes = this->mapu4int2; + this->mbr_0x4 = DAT_GameState::instance.mapAndTime.skirmishFogOfWar; + strcpy(DAT_GameSynchronyState::instance.mapName, this->mapName); + for (int i = 0; i < countof(this->currentAIArray); i++) { + DAT_GameSynchronyState::instance.DAT_RoundTableOrderArray[i] = this->roundTableOrderArray[i]; + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[i] = this->playerGroupArray[i]; + DAT_GameSynchronyState::instance.currentAIArray[i] = this->currentAIArray[i]; + DAT_GameSynchronyState::instance.aiVariationArray[i] = this->aiVariationArray[i]; + } + 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; + for (int i = 0; i < countof(this->playerLordTypeArray); i++) { + DAT_GameCore::instance.selectedLordTypes[i] = this->playerLordTypeArray[i]; + } + 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; + DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset = this->mapSelectionScrollOffset; + 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)(); + } + + } // namespace Skirmish +} // namespace Game +} // namespace OpenSHC diff --git a/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp new file mode 100644 index 0000000000..46c828a573 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/Skirmish_PrepareLeaderboardView.cpp @@ -0,0 +1,134 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../Skirmish.func.hpp" + +#include "OpenSHC/Text/TextManager.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Game/Skirmish/Enums/LeaderBoardFilter.hpp" +#include "OpenSHC/Game/Skirmish/Enums/LeaderBoardSortColumn.hpp" + +#include "OpenSHC/Globals/DAT_00ed3124.hpp" +#include "OpenSHC/Globals/DAT_MissionDefinedData.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" +#include "OpenSHC/Globals/DAT_TextManagerObject.hpp" +#include "OpenSHC/Globals/INT_00eb9b60.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 { + + // FUNCTION: STRONGHOLDCRUSADER 0x004D9400 + void Skirmish::Skirmish_PrepareLeaderboardView() + { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + INT_ARRAY_00eb0e48::instance[i] = 1; + } + // custom games have no trail mission (score 0) + if (DAT_00ed3124::instance == Skirmish::Enums::LBF_CRUSADER_TRAIL_ONLY) { + 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 == Skirmish::Enums::LBF_CUSTOM_GAMES_ONLY) { + for (int i = 0; i < DAT_SkMasters2Data::instance.count; i++) { + if (DAT_SkMasters2Data::instance.entries[i].score) { + INT_ARRAY_00eb0e48::instance[i] = 0; + } + } + } + // columns 0 and 1 keep the stored order, forwards or backwards + if (DAT_MissionDefinedData::instance.sortColumn <= Skirmish::Enums::LBSC_UNKNOWN_1) { + INT_00eb9b60::instance = 0; + if (DAT_MissionDefinedData::instance.descending == TRUE) { + 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++; + } + } + } else if (!DAT_MissionDefinedData::instance.descending) { + 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++; + } + } + } + return; + } + if (DAT_MissionDefinedData::instance.sortColumn == Skirmish::Enums::LBSC_DATE) { + INT_00eb9b60::instance = 0; + 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_SkMasters2Data::instance.entries[i].localTimeYear - 2000) * 16 + + DAT_SkMasters2Data::instance.entries[i].localTimeMonth) + * 32 + + DAT_SkMasters2Data::instance.entries[i].localTimeDay; + INT_00eb9b60::instance++; + } + } + 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 == Skirmish::Enums::LBSC_MISSION) { + INT_00eb9b60::instance = 0; + if (DAT_00ed3124::instance == Skirmish::Enums::LBF_CRUSADER_TRAIL_ONLY) { + 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] + = 80 - DAT_SkMasters2Data::instance.entries[i].score; + INT_00eb9b60::instance++; + } + } + } 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 (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 = entry.mapName[0]; + if (first >= 'A' && first <= 'Z') { + first += 'a' - 'A'; + } + byte second = entry.mapName[1]; + if (second >= 'A' && second <= 'Z') { + second += 'a' - 'A'; + } + INT_ARRAY_00ed2be0::instance[INT_00eb9b60::instance] = -1 - first * 256 - second; + INT_ARRAY_00ed27f0::instance[INT_00eb9b60::instance] = i; + INT_00eb9b60::instance++; + } + } + } + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + return; + } + if (DAT_MissionDefinedData::instance.sortColumn == Skirmish::Enums::LBSC_DURATION) { + INT_00eb9b60::instance = 0; + 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_SkMasters2Data::instance.entries[i].gameDurationInMinutes; + INT_00eb9b60::instance++; + } + } + MACRO_CALL(Game::Skirmish_Func::Skirmish_SortAIOpponentOrder)(DAT_MissionDefinedData::instance.descending); + } + } + +} // namespace Game +} // namespace OpenSHC diff --git a/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp b/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp new file mode 100644 index 0000000000..e29ff56924 --- /dev/null +++ b/src/OpenSHC/Game/Skirmish/StoreGameIntoSKMasters.cpp @@ -0,0 +1,52 @@ +#include "../Skirmish.func.hpp" + +#include "OpenSHC/IO.func.hpp" + +#include "OpenSHC/Globals/DAT_SkMasterDataEntry.hpp" +#include "OpenSHC/Globals/DAT_SkMasters2Data.hpp" + +namespace OpenSHC { +namespace Game { + + // FUNCTION: STRONGHOLDCRUSADER 0x004D52A0 + void Skirmish::StoreGameIntoSKMasters(int score) + { + if (!MACRO_CALL(Game::Skirmish_Func::StoreCurrentGameIntoTemporarySKMasterEntry)(score)) { + return; + } + int count = DAT_SkMasters2Data::instance.count; + int insertIndex = -1; + if (count <= 0) { + insertIndex = 0; + } + if (count < countof(DAT_SkMasters2Data::instance.entries)) { + insertIndex = count; + } + if (insertIndex != 0) { + // the table is sorted by score, best first + for (int i = 0; i < count; i++) { + if (DAT_SkMasterDataEntry::instance.skMasterScore + > DAT_SkMasters2Data::instance.entries[i].skMasterScore) { + insertIndex = i; + break; + } + } + if (insertIndex == -1) { + return; + } + } + // shift the later entries down one; the last one falls off a full table + for (; count > insertIndex; count--) { + if (count <= countof(DAT_SkMasters2Data::instance.entries) - 1) { + DAT_SkMasters2Data::instance.entries[count] = DAT_SkMasters2Data::instance.entries[count - 1]; + } + } + DAT_SkMasters2Data::instance.entries[insertIndex] = DAT_SkMasterDataEntry::instance; + if (DAT_SkMasters2Data::instance.count < countof(DAT_SkMasters2Data::instance.entries)) { + DAT_SkMasters2Data::instance.count++; + } + MACRO_CALL(IO_Func::WriteSkMasters2)(); + } + +} // namespace Game +} // namespace OpenSHC diff --git a/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp new file mode 100644 index 0000000000..b09039ee05 --- /dev/null +++ b/src/OpenSHC/Game/Tutorial_IsActionAllowed.cpp @@ -0,0 +1,102 @@ +#include "../Game.func.hpp" + +#include "OpenSHC/Game/Enums/TutorialActionType.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.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_DisableTutorialRestrictions.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TutorialCurrentStep.hpp" + +namespace OpenSHC { + +using WindowsHelper::Enums::BOOLEnum; + +/* + Tells whether the tutorial allows an action at its current step. Everything is allowed when the tutorial + restrictions are off. For the building actions the parameter is a building type, for the rations and taxes actions + the new setting. + */ +// FUNCTION: STRONGHOLDCRUSADER 0x004BD800 +BOOLEnum Game::Tutorial_IsActionAllowed(undefined4 actionType, int actionParam) +{ + if (DAT_DisableTutorialRestrictions::instance) { + return TRUE; + } + switch (actionType) { + case Enums::TAT_SELECT_BUILDING: + if (DAT_TutorialCurrentStep::instance == 2) { + if (DAT_00df5558::instance < 2 && actionParam == Map::Buildings::BT_MANORHOUSE) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 5) { + if (DAT_00df5558::instance == 0 && actionParam == Map::Buildings::BT_GRANARY) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 17) { + if (actionParam == Map::Buildings::BT_WOODCUTTERSHUT && DAT_00df5560::instance == 0) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 21) { + if (actionParam == Map::Buildings::BT_HUNTERSHUT) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 24) { + if (actionParam == Map::Buildings::BT_HOVEL) { + return TRUE; + } + } + return FALSE; + case Enums::TAT_UNKNOWN_2: + if (DAT_TutorialCurrentStep::instance == 2) { + if (DAT_00df5558::instance < 2 && actionParam == Map::Buildings::BT_MANORHOUSE) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 5) { + if (DAT_00df5558::instance == 0 && actionParam == Map::Buildings::BT_GRANARY + && DAT_00df5560::instance == 0) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 17) { + if (actionParam == Map::Buildings::BT_WOODCUTTERSHUT && (int)DAT_00df5590::instance < 4) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 21) { + if (actionParam == Map::Buildings::BT_HUNTERSHUT && (int)DAT_00df5590::instance < 4) { + return TRUE; + } + } else if (DAT_TutorialCurrentStep::instance == 24) { + if (actionParam == Map::Buildings::BT_HOVEL && DAT_00df5560::instance == 0) { + return TRUE; + } + } + return FALSE; + case Enums::TAT_CHANGE_RATIONS: + if (DAT_TutorialCurrentStep::instance != 8) { + return FALSE; + } + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].rationsSetting + == 4 + && actionParam != 4) { + return FALSE; + } + break; + case Enums::TAT_CHANGE_TAXES: + if (DAT_TutorialCurrentStep::instance != 10) { + return FALSE; + } + if (DAT_GameState::instance.playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID].taxesSetting + == 7 + && actionParam != 7) { + return FALSE; + } + break; + } + return TRUE; +} + +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp b/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp new file mode 100644 index 0000000000..8f9a08723c --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/adjustEventMonthAndYearForSection1047.cpp @@ -0,0 +1,40 @@ +#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.militaryCampaignStage = 0; + DAT_GameState::instance.mapAndTime.monthCopy = DAT_GameState::instance.mapAndTime.month; + DAT_GameState::instance.mapAndTime.field3183_0x27dc = 0; + DAT_GameState::instance.mapAndTime.militaryCampaignFlags = 0; + DAT_GameState::instance.mapAndTime.yearCopy = DAT_GameState::instance.mapAndTime.year; + if (DAT_GameCore::instance.missionNumber1to20 == 17) { + DAT_GameState::instance.mapAndTime.yearCopy = DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = DAT_GameState::instance.mapAndTime.month + 1; + } else if (DAT_GameCore::instance.missionNumber1to20 == 18) { + DAT_GameState::instance.mapAndTime.yearCopy = DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = DAT_GameState::instance.mapAndTime.month + 1; + return; + } else if (DAT_GameCore::instance.missionNumber1to20 == 19) { + DAT_GameState::instance.mapAndTime.yearCopy = DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = DAT_GameState::instance.mapAndTime.month + 6; + } else if (DAT_GameCore::instance.missionNumber1to20 == 20) { + DAT_GameState::instance.mapAndTime.yearCopy = DAT_GameState::instance.mapAndTime.year; + DAT_GameState::instance.mapAndTime.monthCopy = DAT_GameState::instance.mapAndTime.month + 3; + } else { + return; + } + if (DAT_GameState::instance.mapAndTime.month >= 12) { + DAT_GameState::instance.mapAndTime.month -= 12; + DAT_GameState::instance.mapAndTime.year++; + } + } + +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp new file mode 100644 index 0000000000..5660d4d238 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/loadMapSiegeHeaderForMissionIndex.cpp @@ -0,0 +1,39 @@ +#include "../MapPropertiesState.func.hpp" + +#include "OpenSHC/Globals/DAT_MissionAestheticsDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + /* + Loads the siege header sections of the map for a 1-based mission number (1-20). The map names are a list of + char* that starts at MissionAestheticsDefinedData.field_0x3c. Does nothing when the number is out of range. + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004C6820 + void MapPropertiesState::loadMapSiegeHeaderForMissionIndex(char* missionNumber) + { + // fixme: the header declares the mission number as char*, it is an int + missionNumber--; + if ((int)missionNumber < 5) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)missionNumber]); + return; + } + if ((int)missionNumber < 10) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)missionNumber]); + return; + } + if ((int)missionNumber < 15) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)missionNumber]); + return; + } + if ((int)missionNumber < 20) { + MACRO_CALL_MEMBER(Map::MapPropertiesState_Func::loadMapSiegeHeaderSections, this)( + (char*)(&DAT_MissionAestheticsDefinedData::instance.field_0x3c)[(int)missionNumber]); + } + } + +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp b/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp new file mode 100644 index 0000000000..674ebf71f8 --- /dev/null +++ b/src/OpenSHC/Map/MapPropertiesState/loadMissionMapAndSetLord.cpp @@ -0,0 +1,37 @@ +#include "../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 of a 1-based mission number (1-20), then sets up the lord for that mission. The map names are a + list of char* that starts at MissionAestheticsDefinedData.field_0x3c. + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004C6880 + void MapPropertiesState::loadMissionMapAndSetLord(int missionNumber) + { + missionNumber--; + 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::Units::UnitsState_Func::setMissionNumberSpecificLord, DAT_UnitsState::ptr)( + missionNumber + 1); + } + +} // namespace Map +} // namespace OpenSHC diff --git a/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp b/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp new file mode 100644 index 0000000000..bb532049c9 --- /dev/null +++ b/src/OpenSHC/Synchrony/LoadSkirmishCampaignData.cpp @@ -0,0 +1,97 @@ +// disable deprecation warnings for strcpy +#pragma warning(disable : 4996) + +#include "../Synchrony.func.hpp" + +#include "OpenSHC/OS.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 Game::CampaignTrailMission; + +// FUNCTION: STRONGHOLDCRUSADER 0x004C6B20 +void Synchrony::LoadSkirmishCampaignData(int missionID) +{ + CampaignTrailMission* mission = &DAT_SkirmishDefinedData::instance.SkirmishTrailMissions[missionID]; + if (DAT_GameCore::instance.currentTrailType == Game::TT_EXTREME) { + mission = &DAT_SkirmishDefinedData::instance.ExtremeTrailMissions[missionID]; + } else if (DAT_GameCore::instance.currentTrailType == Game::TT_WARCHEST) { + mission = &DAT_SkirmishDefinedData::instance.WarchestTrailMissions[missionID]; + } + strcpy(CHAR_ARRAY_00eb0ab0::instance, (char*)mission->mapNameAddress); + MACRO_CALL(OS_Func::_memset)( + DAT_GameSynchronyState::instance.DAT_PlayerNames, 0, sizeof(DAT_GameSynchronyState::instance.DAT_PlayerNames)); + int player = 0; + do { + DAT_GameSynchronyState::instance.currentPlayerFullIDArray[player] = -1; + DAT_GameSynchronyState::instance.currentAIArray[player] = 0; + DAT_GameSynchronyState::instance.aiVariationArray[player] = -1; + player++; + } while (player < countof(DAT_GameSynchronyState::instance.currentAIArray)); + strcpy(DAT_GameSynchronyState::instance.DAT_PlayerNames[1], + MACRO_CALL_MEMBER(Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(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); + // the mission lists the AI of every player after the first, which 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); + } + MACRO_CALL(Synchrony_Func::SetAIPlayerNickNames)(); + for (int i = 0; i < countof(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray) - 1; i++) { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[i + 1] = (&mission->team1)[i]; + if (i >= mission->numberOfPlayers) { + DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[i + 1] = -1; + } + } + // players in a group play as that team; the others each get a team of their own after the highest group + int highestTeam = 0; + int playerID = 1; + do { + char const group = DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[playerID]; + DAT_GameState::instance.mapAndTime.playerGroupArray[playerID] = group; + if (group > 0) { + DAT_GameState::instance.mapAndTime.playerTeams[playerID] = group; + if (group > highestTeam) { + highestTeam = group; + } + } + playerID++; + } while (playerID < countof(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray)); + playerID = 1; + do { + if (DAT_GameSynchronyState::instance.DAT_PlayerGroupArray[playerID] == 0) { + highestTeam++; + DAT_GameState::instance.mapAndTime.playerTeams[playerID] = highestTeam; + } + playerID++; + } while (playerID < countof(DAT_GameSynchronyState::instance.DAT_PlayerGroupArray)); + DAT_GameSynchronyState::instance.skirmishCurrentAdvantageBalance = mission->fairness; + DAT_GameSynchronyState::instance.skirmishGameIntensityType = mission->startLevels; + memset(DAT_GameSynchronyState::instance.playerPositionsArray, -10, + sizeof(DAT_GameSynchronyState::instance.playerPositionsArray)); + // position N of the map goes to the player that lists it + for (int i = 0; i < countof(DAT_GameSynchronyState::instance.playerPositionsArray); i++) { + if ((&mission->position1)[i] != 0) { + DAT_GameSynchronyState::instance.playerPositionsArray[(&mission->position1)[i] - 1] = i; + } + } +} + +} // namespace OpenSHC diff --git a/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp new file mode 100644 index 0000000000..ff26522202 --- /dev/null +++ b/src/OpenSHC/UI/MenuTextInputState/loadOrSaveGame.cpp @@ -0,0 +1,120 @@ +#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/Commands/GameCommandType.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/UI/Enums/MenuModalType.hpp" +#include "OpenSHC/string-macros.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" + +namespace OpenSHC { +namespace UI { + + /* + Opens the load or save dialog: lists the saved games (*.sav, or *.msv in multiplayer), resets the list view and + restores the last selection of that dialog. + */ + // FUNCTION: STRONGHOLDCRUSADER 0x004968A0 + void MenuTextInputState::loadOrSaveGame(int action) + { + if (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + && DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SKIRMISH_SINGLE_PLAYER + && DAT_GameSynchronyState::instance.saveRelated == 1 && action == UI::Enums::MMT_SAVE_MAP) { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::clearAnyOtherModalDialogs, this)(); + return; + } + DAT_MouseState::instance.waitCursorToggle = TRUE; + MACRO_CALL(UI::Helpers_Func::SetCursorDependingOnProgramState)(); + MACRO_CALL(OS_Func::_memset)( + DAT_MinimapViewState::instance.loadedMiniMap, 0, sizeof(DAT_MinimapViewState::instance.loadedMiniMap)); + 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 += S__MSV_005A75D4; + 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; + // fixme: the original writes one entry before index i, so i = 0 writes the field before the array + this->DAT_ArrayOfMapIndices2[i - 1] = 1; + if (action != UI::Enums::MMT_SAVE_MAP) { + DAT_GameSynchronyState::instance.DAT_GameCommandParam0 = i; + MACRO_CALL_MEMBER(Synchrony::GameSynchronyState_Func::queueCommand, DAT_GameSynchronyState::ptr)( + (Commands::GameCommandType)50); + } + } + } else { + std::string savesPath(DAT_ResourceManager::instance.paths_getSavesPath(true)); + savesPath += S__SAV_005A75CC; + 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; + } + } + DAT_MouseState::instance.waitCursorToggle = FALSE; + this->fileListSortOrder = 0; + this->menuLoadGameRelativeSelectionOffset = 0; + if (!this->fileListEntryCount) { + this->menuLoadGameRelativeSelectionIndex = -1; + } else { + this->menuLoadGameRelativeSelectionIndex = 0; + } + this->lastListClickTime = 0; + this->lastClickedListIndex = -1; + this->DAT_ArrayOfMapU3EndInt2 = 0; + this->previewedListIndex = -1; + this->fileListVisibleRowCount = 16; + if (action == UI::Enums::MMT_LOAD_MAP) { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( + UI::Enums::MMT_LOAD_MAP); + this->fileListContext = 1; + // restore where the list was left, unless that is past its end now + if (this->menuLoadGameRelativeSelectionIndex != -1) { + this->menuLoadGameRelativeSelectionIndex = this->savedListSelection1; + this->menuLoadGameRelativeSelectionOffset = this->savedListOffset1; + this->fileListSortOrder = this->savedListSortOrder1; + if (this->menuLoadGameRelativeSelectionOffset + this->menuLoadGameRelativeSelectionIndex + >= this->fileListEntryCount) { + this->menuLoadGameRelativeSelectionIndex = 0; + this->menuLoadGameRelativeSelectionOffset = 0; + } + } + } else { + MACRO_CALL_MEMBER(UI::MenuTextInputState_Func::activateModalDialogAndClearText, this)( + UI::Enums::MMT_SAVE_MAP); + DAT_UserTextHandlerState::instance.allowUserTextInput = FALSE; + 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 = TRUE; + this->fileListContext = 3; + // restore where the list was left, unless that is past its end now + if (this->menuLoadGameRelativeSelectionIndex != -1) { + this->menuLoadGameRelativeSelectionIndex = this->savedListSelection2; + this->menuLoadGameRelativeSelectionOffset = this->savedListOffset2; + this->fileListSortOrder = this->savedListSortOrder2; + if (this->menuLoadGameRelativeSelectionOffset + this->menuLoadGameRelativeSelectionIndex + >= this->fileListEntryCount) { + this->menuLoadGameRelativeSelectionOffset = 0; + this->menuLoadGameRelativeSelectionIndex = 0; + } + } + } + MACRO_CALL(UI::MenuItems::SaveLoadMap_Func::MenuItemActionHandler_SaveLoadMap_TableHeader)( + -1 - this->fileListSortOrder); + } + +} // namespace UI +} // namespace OpenSHC diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index caffa45278..f9c8d1534d 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 | 0.0% | Pending +SHC_3BB0A8C1_0x00490060 | 99.3% | Register allocation 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 | 93.1% | Register allocation 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 | 100.0% | Reimplemented 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 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004BD970 | 0.0% | Pending @@ -34143,13 +34143,13 @@ SHC_3BB0A8C1_0x004C62A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C62C0 | 0.0% | Pending -SHC_3BB0A8C1_0x004C6820 | 0.0% | Pending +SHC_3BB0A8C1_0x004C6820 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004C6880 | 0.0% | Pending +SHC_3BB0A8C1_0x004C6880 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004C68D0 | 0.0% | Pending -SHC_3BB0A8C1_0x004C6B20 | 0.0% | Pending +SHC_3BB0A8C1_0x004C6B20 | 100.0% | Reimplemented 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 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004D5370 | 0.0% | Pending +SHC_3BB0A8C1_0x004D5370 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D53A0 | 0.0% | Pending @@ -36023,7 +36023,7 @@ SHC_3BB0A8C1_0x004D9270 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004D9290 | 100.0% | Reimplemented (counted: only the instance[i - 1] address label differs) -SHC_3BB0A8C1_0x004D9400 | 0.0% | Pending +SHC_3BB0A8C1_0x004D9400 | 100.0% | Reimplemented (counted: only the labels of two array[-1] addresses differ) SHC_3BB0A8C1_0x004D9520 | 0.0% | Pending