diff --git a/targets/app/common/BannedListManager.cpp b/targets/app/common/BannedListManager.cpp new file mode 100644 index 000000000..d7171781c --- /dev/null +++ b/targets/app/common/BannedListManager.cpp @@ -0,0 +1,131 @@ +#include "app/common/BannedListManager.h" + +#include + +#include "platform/XboxStubs.h" + +BannedListManager::BannedListManager() { + m_pBannedListFileBuffer = nullptr; + m_dwBannedListFileSize = 0; + std::memset(m_pszUniqueMapName, 0, 14); + + for (int i = 0; i < XUSER_MAX_COUNT; i++) { + m_bRead_BannedListA[i] = false; + m_BanListCheck[i] = false; + m_vBannedListA[i] = new std::vector; + } +} + +void BannedListManager::invalidate(int iPad) { + if (m_bRead_BannedListA[iPad] == true) { + m_bRead_BannedListA[iPad] = false; + setBanListCheck(iPad, false); + m_vBannedListA[iPad]->clear(); + + if (BannedListA[iPad].pBannedList) { + delete[] BannedListA[iPad].pBannedList; + BannedListA[iPad].pBannedList = nullptr; + } + } +} + +void BannedListManager::addLevel(int iPad, PlayerUID xuid, + char* pszLevelName, bool bWriteToTMS) { + // we will have retrieved the banned level list from TMS, so add this one to + // it and write it back to TMS + + BANNEDLISTDATA* pBannedListData = new BANNEDLISTDATA; + memset(pBannedListData, 0, sizeof(BANNEDLISTDATA)); + + memcpy(&pBannedListData->xuid, &xuid, sizeof(PlayerUID)); + strcpy(pBannedListData->pszLevelName, pszLevelName); + m_vBannedListA[iPad]->push_back(pBannedListData); + + if (bWriteToTMS) { + const std::size_t bannedListCount = m_vBannedListA[iPad]->size(); + const unsigned int dataBytes = + static_cast(sizeof(BANNEDLISTDATA) * bannedListCount); + PBANNEDLISTDATA pBannedList = new BANNEDLISTDATA[bannedListCount]; + int iCount = 0; + for (auto it = m_vBannedListA[iPad]->begin(); + it != m_vBannedListA[iPad]->end(); ++it) { + PBANNEDLISTDATA pData = *it; + memcpy(&pBannedList[iCount++], pData, sizeof(BANNEDLISTDATA)); + } + + // 4J-PB - write to TMS++ now + + // bool + // bRes=StorageManager.WriteTMSFile(iPad,C4JStorage::eGlobalStorage_TitleUser,L"BannedList",(std::uint8_t*)pBannedList, + // dwDataBytes); + + delete[] pBannedList; + } + // update telemetry too +} + +bool BannedListManager::isInList(int iPad, PlayerUID xuid, + char* pszLevelName) { + for (auto it = m_vBannedListA[iPad]->begin(); + it != m_vBannedListA[iPad]->end(); ++it) { + PBANNEDLISTDATA pData = *it; + if (IsEqualXUID(pData->xuid, xuid) && + (strcmp(pData->pszLevelName, pszLevelName) == 0)) { + return true; + } + } + + return false; +} + +void BannedListManager::removeLevel(int iPad, PlayerUID xuid, + char* pszLevelName) { + // bool bFound=false; + // bool bRes; + + // we will have retrieved the banned level list from TMS, so remove this one + // from it and write it back to TMS + for (auto it = m_vBannedListA[iPad]->begin(); + it != m_vBannedListA[iPad]->end();) { + PBANNEDLISTDATA pBannedListData = *it; + + if (pBannedListData != nullptr) { + if (IsEqualXUID(pBannedListData->xuid, xuid) && + (strcmp(pBannedListData->pszLevelName, pszLevelName) == 0)) { + // match found, so remove this entry + it = m_vBannedListA[iPad]->erase(it); + } else { + ++it; + } + } else { + ++it; + } + } + + const std::size_t bannedListCount = m_vBannedListA[iPad]->size(); + const unsigned int dataBytes = + static_cast(sizeof(BANNEDLISTDATA) * bannedListCount); + if (dataBytes == 0) { + // wipe the file + } else { + PBANNEDLISTDATA pBannedList = + (BANNEDLISTDATA*)(new std::uint8_t[dataBytes]); + + for (std::size_t i = 0; i < bannedListCount; ++i) { + PBANNEDLISTDATA pBannedListData = m_vBannedListA[iPad]->at(i); + + memcpy(&pBannedList[i], pBannedListData, sizeof(BANNEDLISTDATA)); + } + delete[] pBannedList; + } + + // update telemetry too +} + +void BannedListManager::setUniqueMapName(char* pszUniqueMapName) { + memcpy(m_pszUniqueMapName, pszUniqueMapName, 14); +} + +char* BannedListManager::getUniqueMapName() { + return m_pszUniqueMapName; +} diff --git a/targets/app/common/BannedListManager.h b/targets/app/common/BannedListManager.h new file mode 100644 index 000000000..23d2028b6 --- /dev/null +++ b/targets/app/common/BannedListManager.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include + +#include "app/common/App_structs.h" +#include "platform/XboxStubs.h" + +class BannedListManager { +public: + BannedListManager(); + + void invalidate(int iPad); + void addLevel(int iPad, PlayerUID xuid, char* pszLevelName, + bool bWriteToTMS); + bool isInList(int iPad, PlayerUID xuid, char* pszLevelName); + void removeLevel(int iPad, PlayerUID xuid, char* pszLevelName); + + void setUniqueMapName(char* pszUniqueMapName); + char* getUniqueMapName(); + + void setBanListCheck(int iPad, bool bVal) { m_BanListCheck[iPad] = bVal; } + bool getBanListCheck(int iPad) const { return m_BanListCheck[iPad]; } + + bool getBanListRead(int iPad) const { return m_bRead_BannedListA[iPad]; } + void setBanListRead(int iPad, bool bVal) { + m_bRead_BannedListA[iPad] = bVal; + } + + void clearBanList(int iPad) { + BannedListA[iPad].pBannedList = nullptr; + BannedListA[iPad].byteCount = 0; + } + + BANNEDLIST BannedListA[XUSER_MAX_COUNT]; + + std::uint8_t* m_pBannedListFileBuffer; + unsigned int m_dwBannedListFileSize; + +private: + VBANNEDLIST* m_vBannedListA[XUSER_MAX_COUNT]; + bool m_bRead_BannedListA[XUSER_MAX_COUNT]; + char m_pszUniqueMapName[14]; + bool m_BanListCheck[XUSER_MAX_COUNT]; +}; diff --git a/targets/app/common/DebugOptions.cpp b/targets/app/common/DebugOptions.cpp new file mode 100644 index 000000000..b8a7bd099 --- /dev/null +++ b/targets/app/common/DebugOptions.cpp @@ -0,0 +1,33 @@ +#include "app/common/DebugOptions.h" + +DebugOptions::DebugOptions() { +#if defined(_DEBUG_MENUS_ENABLED) +#if defined(_CONTENT_PACKAGE) + m_bDebugOptions = + false; // make them off by default in a content package build +#else + m_bDebugOptions = true; +#endif +#else + m_bDebugOptions = false; +#endif + + m_bLoadSavesFromFolderEnabled = false; + m_bWriteSavesToFolderEnabled = false; + m_bMobsDontAttack = false; + m_bMobsDontTick = false; + m_bFreezePlayers = false; + +#if defined(_CONTENT_PACAKGE) + m_bUseDPadForDebug = false; +#else + m_bUseDPadForDebug = true; +#endif +} + +#if defined(_DEBUG_MENUS_ENABLED) +bool DebugOptions::debugArtToolsOn(unsigned int debugMask) { + return settingsOn() && + (debugMask & (1L << eDebugSetting_ArtTools)) != 0; +} +#endif diff --git a/targets/app/common/DebugOptions.h b/targets/app/common/DebugOptions.h new file mode 100644 index 000000000..de437d650 --- /dev/null +++ b/targets/app/common/DebugOptions.h @@ -0,0 +1,52 @@ +#pragma once + +#include "app/common/Console_Debug_enum.h" + +class DebugOptions { +public: + DebugOptions(); + + bool settingsOn() const { return m_bDebugOptions; } + void setDebugOptions(bool bVal) { m_bDebugOptions = bVal; } + + bool getLoadSavesFromFolderEnabled() const { + return m_bLoadSavesFromFolderEnabled; + } + void setLoadSavesFromFolderEnabled(bool bVal) { + m_bLoadSavesFromFolderEnabled = bVal; + } + + bool getWriteSavesToFolderEnabled() const { + return m_bWriteSavesToFolderEnabled; + } + void setWriteSavesToFolderEnabled(bool bVal) { + m_bWriteSavesToFolderEnabled = bVal; + } + + bool getMobsDontAttack() const { return m_bMobsDontAttack; } + void setMobsDontAttack(bool bVal) { m_bMobsDontAttack = bVal; } + + bool getUseDPadForDebug() const { return m_bUseDPadForDebug; } + void setUseDPadForDebug(bool bVal) { m_bUseDPadForDebug = bVal; } + + bool getMobsDontTick() const { return m_bMobsDontTick; } + void setMobsDontTick(bool bVal) { m_bMobsDontTick = bVal; } + + bool getFreezePlayers() const { return m_bFreezePlayers; } + void setFreezePlayers(bool bVal) { m_bFreezePlayers = bVal; } + +#if defined(_DEBUG_MENUS_ENABLED) + bool debugArtToolsOn(unsigned int debugMask); +#else + bool debugArtToolsOn(unsigned int) { return false; } +#endif + +private: + bool m_bDebugOptions; + bool m_bLoadSavesFromFolderEnabled; + bool m_bWriteSavesToFolderEnabled; + bool m_bMobsDontAttack; + bool m_bUseDPadForDebug; + bool m_bMobsDontTick; + bool m_bFreezePlayers; +}; diff --git a/targets/app/common/Game.cpp b/targets/app/common/Game.cpp index e479d3944..9fb367847 100644 --- a/targets/app/common/Game.cpp +++ b/targets/app/common/Game.cpp @@ -149,9 +149,6 @@ Game::Game() { DebugPrintf("Player at index %d has guest number %d\n", i, m_currentSigninInfo[i].dwGuestNumber); - m_bRead_BannedListA[i] = false; - SetBanListCheck(i, false); - m_uiOpacityCountDown[i] = 0; } m_eGlobalXuiAction = eAppAction_Idle; @@ -164,8 +161,6 @@ Game::Game() { m_bIntroRunning = false; m_eGameMode = eMode_Singleplayer; - m_bLoadSavesFromFolderEnabled = false; - m_bWriteSavesToFolderEnabled = false; // m_bInterfaceRenderingOff = false; // m_bHandRenderingOff = false; m_bTutorialMode = false; @@ -174,18 +169,6 @@ Game::Game() { m_bChangingSessionType = false; m_bReallyChangingSessionType = false; -#if defined(_DEBUG_MENUS_ENABLED) - -#if defined(_CONTENT_PACKAGE) - m_bDebugOptions = - false; // make them off by default in a content package build -#else - m_bDebugOptions = true; -#endif -#else - m_bDebugOptions = false; -#endif - // memset(m_PreviewBuffer, 0, sizeof(XSOCIAL_PREVIEWIMAGE)*XUSER_MAX_COUNT); m_xuidNotch = INVALID_XUID; @@ -197,17 +180,12 @@ Game::Game() { m_pDLCFileBuffer = nullptr; m_dwDLCFileSize = 0; - m_pBannedListFileBuffer = nullptr; - m_dwBannedListFileSize = 0; - m_bDefaultCapeInstallAttempted = false; m_bDLCInstallProcessCompleted = false; m_bDLCInstallPending = false; m_iTotalDLC = 0; m_iTotalDLCInstalled = 0; mfTrialPausedTime = 0.0f; - m_uiAutosaveTimer = {}; - memset(m_pszUniqueMapName, 0, 14); m_bNewDLCAvailable = false; m_bSeenNewDLCTip = false; @@ -226,22 +204,10 @@ Game::Game() { m_bAllDLCContentRetrieved = true; m_bAllTMSContentRetrieved = true; m_bTickTMSDLCFiles = true; - m_saveNotificationDepth = 0; - m_dwRequiredTexturePackID = 0; m_bResetNether = false; -#if defined(_CONTENT_PACAKGE) - m_bUseDPadForDebug = false; -#else - m_bUseDPadForDebug = true; -#endif - - for (int i = 0; i < XUSER_MAX_COUNT; i++) { - m_vBannedListA[i] = new std::vector; - } - LocaleAndLanguageInit(); } @@ -4127,16 +4093,15 @@ void Game::NotificationsCallback(void* pParam, #if defined(_DEBUG_MENUS_ENABLED) bool Game::DebugArtToolsOn() { - return DebugSettingsOn() && - (GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad()) & - (1L << eDebugSetting_ArtTools)) != 0; + return m_debugOptions.debugArtToolsOn( + GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad())); } #endif void Game::SetDebugSequence(const char* pchSeq) { InputManager.SetDebugSequence(pchSeq, [this]() -> int { // printf("sequence matched\n"); - m_bDebugOptions = !m_bDebugOptions; + m_debugOptions.setDebugOptions(!m_debugOptions.settingsOn()); for (int i = 0; i < XUSER_MAX_COUNT; i++) { if (app.DebugSettingsOn()) { @@ -5521,43 +5486,6 @@ DLC_INFO* Game::GetDLCInfoForFullOfferID(uint64_t ullOfferID_Full) { return nullptr; } -void Game::lockSaveNotification() { - std::lock_guard lock(m_saveNotificationMutex); - if (m_saveNotificationDepth++ == 0) { - if (g_NetworkManager - .IsInSession()) // this can be triggered from the front end if - // we're downloading a save - { - MinecraftServer::getInstance()->broadcastStartSavingPacket(); - - if (g_NetworkManager.IsLocalGame() && - g_NetworkManager.GetPlayerCount() == 1) { - app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), - eXuiServerAction_PauseServer, - (void*)true); - } - } - } -} - -void Game::unlockSaveNotification() { - std::lock_guard lock(m_saveNotificationMutex); - if (--m_saveNotificationDepth == 0) { - if (g_NetworkManager - .IsInSession()) // this can be triggered from the front end if - // we're downloading a save - { - MinecraftServer::getInstance()->broadcastStopSavingPacket(); - - if (g_NetworkManager.IsLocalGame() && - g_NetworkManager.GetPlayerCount() == 1) { - app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), - eXuiServerAction_PauseServer, - (void*)false); - } - } - } -} int Game::RemoteSaveThreadProc(void* lpParameter) { // The game should be stopped while we are doing this, but the connections @@ -5644,120 +5572,6 @@ void Game::SetSpecialTutorialCompletionFlag(int iPad, int index) { } } -// BANNED LIST FUNCTIONS - -void Game::SetUniqueMapName(char* pszUniqueMapName) { - memcpy(m_pszUniqueMapName, pszUniqueMapName, 14); -} - -char* Game::GetUniqueMapName(void) { return m_pszUniqueMapName; } - -void Game::InvalidateBannedList(int iPad) { - if (m_bRead_BannedListA[iPad] == true) { - m_bRead_BannedListA[iPad] = false; - SetBanListCheck(iPad, false); - m_vBannedListA[iPad]->clear(); - - if (BannedListA[iPad].pBannedList) { - delete[] BannedListA[iPad].pBannedList; - BannedListA[iPad].pBannedList = nullptr; - } - } -} - -void Game::AddLevelToBannedLevelList(int iPad, PlayerUID xuid, - char* pszLevelName, - bool bWriteToTMS) { - // we will have retrieved the banned level list from TMS, so add this one to - // it and write it back to TMS - - BANNEDLISTDATA* pBannedListData = new BANNEDLISTDATA; - memset(pBannedListData, 0, sizeof(BANNEDLISTDATA)); - - memcpy(&pBannedListData->xuid, &xuid, sizeof(PlayerUID)); - strcpy(pBannedListData->pszLevelName, pszLevelName); - m_vBannedListA[iPad]->push_back(pBannedListData); - - if (bWriteToTMS) { - const std::size_t bannedListCount = m_vBannedListA[iPad]->size(); - const unsigned int dataBytes = - static_cast(sizeof(BANNEDLISTDATA) * bannedListCount); - PBANNEDLISTDATA pBannedList = new BANNEDLISTDATA[bannedListCount]; - int iCount = 0; - for (auto it = m_vBannedListA[iPad]->begin(); - it != m_vBannedListA[iPad]->end(); ++it) { - PBANNEDLISTDATA pData = *it; - memcpy(&pBannedList[iCount++], pData, sizeof(BANNEDLISTDATA)); - } - - // 4J-PB - write to TMS++ now - - // bool - // bRes=StorageManager.WriteTMSFile(iPad,C4JStorage::eGlobalStorage_TitleUser,L"BannedList",(std::uint8_t*)pBannedList, - // dwDataBytes); - - delete[] pBannedList; - } - // update telemetry too -} - -bool Game::IsInBannedLevelList(int iPad, PlayerUID xuid, - char* pszLevelName) { - for (auto it = m_vBannedListA[iPad]->begin(); - it != m_vBannedListA[iPad]->end(); ++it) { - PBANNEDLISTDATA pData = *it; - if (IsEqualXUID(pData->xuid, xuid) && - (strcmp(pData->pszLevelName, pszLevelName) == 0)) { - return true; - } - } - - return false; -} - -void Game::RemoveLevelFromBannedLevelList(int iPad, PlayerUID xuid, - char* pszLevelName) { - // bool bFound=false; - // bool bRes; - - // we will have retrieved the banned level list from TMS, so remove this one - // from it and write it back to TMS - for (auto it = m_vBannedListA[iPad]->begin(); - it != m_vBannedListA[iPad]->end();) { - PBANNEDLISTDATA pBannedListData = *it; - - if (pBannedListData != nullptr) { - if (IsEqualXUID(pBannedListData->xuid, xuid) && - (strcmp(pBannedListData->pszLevelName, pszLevelName) == 0)) { - // match found, so remove this entry - it = m_vBannedListA[iPad]->erase(it); - } else { - ++it; - } - } else { - ++it; - } - } - - const std::size_t bannedListCount = m_vBannedListA[iPad]->size(); - const unsigned int dataBytes = - static_cast(sizeof(BANNEDLISTDATA) * bannedListCount); - if (dataBytes == 0) { - // wipe the file - } else { - PBANNEDLISTDATA pBannedList = - (BANNEDLISTDATA*)(new std::uint8_t[dataBytes]); - - for (std::size_t i = 0; i < bannedListCount; ++i) { - PBANNEDLISTDATA pBannedListData = m_vBannedListA[iPad]->at(i); - - memcpy(&pBannedList[i], pBannedListData, sizeof(BANNEDLISTDATA)); - } - delete[] pBannedList; - } - - // update telemetry too -} // function to add credits for the DLC packs void Game::AddCreditText(const wchar_t* lpStr) { @@ -6327,62 +6141,6 @@ unsigned int Game::CreateImageTextData(std::uint8_t* textMetadata, return iTextMetadataBytes; } -void Game::AddTerrainFeaturePosition(_eTerrainFeatureType eFeatureType, - int x, int z) { - // check we don't already have this in - for (auto it = m_vTerrainFeatures.begin(); it < m_vTerrainFeatures.end(); - ++it) { - FEATURE_DATA* pFeatureData = *it; - - if ((pFeatureData->eTerrainFeature == eFeatureType) && - (pFeatureData->x == x) && (pFeatureData->z == z)) - return; - } - - FEATURE_DATA* pFeatureData = new FEATURE_DATA; - pFeatureData->eTerrainFeature = eFeatureType; - pFeatureData->x = x; - pFeatureData->z = z; - - m_vTerrainFeatures.push_back(pFeatureData); -} - -_eTerrainFeatureType Game::IsTerrainFeature(int x, int z) { - for (auto it = m_vTerrainFeatures.begin(); it < m_vTerrainFeatures.end(); - ++it) { - FEATURE_DATA* pFeatureData = *it; - - if ((pFeatureData->x == x) && (pFeatureData->z == z)) - return pFeatureData->eTerrainFeature; - } - - return eTerrainFeature_None; -} - -bool Game::GetTerrainFeaturePosition(_eTerrainFeatureType eType, - int* pX, int* pZ) { - for (auto it = m_vTerrainFeatures.begin(); it < m_vTerrainFeatures.end(); - ++it) { - FEATURE_DATA* pFeatureData = *it; - - if (pFeatureData->eTerrainFeature == eType) { - *pX = pFeatureData->x; - *pZ = pFeatureData->z; - return true; - } - } - - return false; -} - -void Game::ClearTerrainFeaturePosition() { - FEATURE_DATA* pFeatureData; - while (m_vTerrainFeatures.size() > 0) { - pFeatureData = m_vTerrainFeatures.back(); - m_vTerrainFeatures.pop_back(); - delete pFeatureData; - } -} void Game::UpdatePlayerInfo(std::uint8_t networkSmallId, int16_t playerColourIndex, @@ -7172,17 +6930,7 @@ int Game::GetDLCInfoTexturesOffersCount() { // AUTOSAVE void Game::SetAutosaveTimerTime(void) { int settingValue = GetGameSettings(ProfileManager.GetPrimaryPad(), eGameSetting_Autosave); - m_uiAutosaveTimer = - time_util::clock::now() + - std::chrono::minutes(settingValue * 15); -} // value x 15 to get mins - -bool Game::AutosaveDue(void) { - return (time_util::clock::now() > m_uiAutosaveTimer); -} - -int64_t Game::SecondsToAutosave() { - return std::chrono::duration_cast(m_uiAutosaveTimer - time_util::clock::now()).count(); + m_saveManager.setAutosaveTimerTime(settingValue); } void Game::SetTrialTimerStart(void) { diff --git a/targets/app/common/Game.h b/targets/app/common/Game.h index d0aaad5c0..3aadae8c0 100644 --- a/targets/app/common/Game.h +++ b/targets/app/common/Game.h @@ -9,8 +9,12 @@ // using namespace std; +#include "app/common/BannedListManager.h" +#include "app/common/DebugOptions.h" #include "app/common/IPlatformGame.h" #include "app/common/App_structs.h" +#include "app/common/SaveManager.h" +#include "app/common/TerrainFeatureManager.h" #include "app/common/Audio/Consoles_SoundEngine.h" #include "app/common/DLC/DLCManager.h" #include "app/common/GameRules/ConsoleGameRulesConstants.h" @@ -71,6 +75,10 @@ public: // storing skin files std::vector vSkinNames; DLCManager m_dlcManager; + SaveManager m_saveManager; + BannedListManager m_bannedListManager; + TerrainFeatureManager m_terrainFeatureManager; + DebugOptions m_debugOptions; // storing credits text from the DLC std::vector m_vCreditText; // hold the credit text lines so @@ -242,26 +250,36 @@ public: // 4J Stu - Functions used for Minecon and other promo work bool GetLoadSavesFromFolderEnabled() { - return m_bLoadSavesFromFolderEnabled; + return m_debugOptions.getLoadSavesFromFolderEnabled(); } void SetLoadSavesFromFolderEnabled(bool bVal) { - m_bLoadSavesFromFolderEnabled = bVal; + m_debugOptions.setLoadSavesFromFolderEnabled(bVal); } // 4J Stu - Useful for debugging - bool GetWriteSavesToFolderEnabled() { return m_bWriteSavesToFolderEnabled; } - void SetWriteSavesToFolderEnabled(bool bVal) { - m_bWriteSavesToFolderEnabled = bVal; + bool GetWriteSavesToFolderEnabled() { + return m_debugOptions.getWriteSavesToFolderEnabled(); + } + void SetWriteSavesToFolderEnabled(bool bVal) { + m_debugOptions.setWriteSavesToFolderEnabled(bVal); + } + bool GetMobsDontAttackEnabled() { + return m_debugOptions.getMobsDontAttack(); + } + void SetMobsDontAttackEnabled(bool bVal) { + m_debugOptions.setMobsDontAttack(bVal); + } + bool GetUseDPadForDebug() { return m_debugOptions.getUseDPadForDebug(); } + void SetUseDPadForDebug(bool bVal) { + m_debugOptions.setUseDPadForDebug(bVal); + } + bool GetMobsDontTickEnabled() { return m_debugOptions.getMobsDontTick(); } + void SetMobsDontTickEnabled(bool bVal) { + m_debugOptions.setMobsDontTick(bVal); } - bool GetMobsDontAttackEnabled() { return m_bMobsDontAttack; } - void SetMobsDontAttackEnabled(bool bVal) { m_bMobsDontAttack = bVal; } - bool GetUseDPadForDebug() { return m_bUseDPadForDebug; } - void SetUseDPadForDebug(bool bVal) { m_bUseDPadForDebug = bVal; } - bool GetMobsDontTickEnabled() { return m_bMobsDontTick; } - void SetMobsDontTickEnabled(bool bVal) { m_bMobsDontTick = bVal; } - bool GetFreezePlayers() { return m_bFreezePlayers; } - void SetFreezePlayers(bool bVal) { m_bFreezePlayers = bVal; } + bool GetFreezePlayers() { return m_debugOptions.getFreezePlayers(); } + void SetFreezePlayers(bool bVal) { m_debugOptions.setFreezePlayers(bVal); } // debug -0 show safe area void ShowSafeArea(bool show) {} @@ -364,7 +382,7 @@ public: void SetLiveLinkRequired(bool required) { m_bLiveLinkRequired = required; } #if defined(_DEBUG_MENUS_ENABLED) - bool DebugSettingsOn() { return m_bDebugOptions; } + bool DebugSettingsOn() { return m_debugOptions.settingsOn(); } bool DebugArtToolsOn(); #else bool DebugSettingsOn() { return false; } @@ -465,13 +483,25 @@ public: public: // BAN LIST void AddLevelToBannedLevelList(int iPad, PlayerUID xuid, char* pszLevelName, - bool bWriteToTMS); - bool IsInBannedLevelList(int iPad, PlayerUID xuid, char* pszLevelName); + bool bWriteToTMS) { + m_bannedListManager.addLevel(iPad, xuid, pszLevelName, bWriteToTMS); + } + bool IsInBannedLevelList(int iPad, PlayerUID xuid, char* pszLevelName) { + return m_bannedListManager.isInList(iPad, xuid, pszLevelName); + } void RemoveLevelFromBannedLevelList(int iPad, PlayerUID xuid, - char* pszLevelName); - void InvalidateBannedList(int iPad); - void SetUniqueMapName(char* pszUniqueMapName); - char* GetUniqueMapName(void); + char* pszLevelName) { + m_bannedListManager.removeLevel(iPad, xuid, pszLevelName); + } + void InvalidateBannedList(int iPad) { + m_bannedListManager.invalidate(iPad); + } + void SetUniqueMapName(char* pszUniqueMapName) { + m_bannedListManager.setUniqueMapName(pszUniqueMapName); + } + char* GetUniqueMapName(void) { + return m_bannedListManager.getUniqueMapName(); + } public: bool GetResourcesLoaded() { return m_bResourcesLoaded; } @@ -507,8 +537,6 @@ private: static int TexturePackDialogReturned(void* pParam, int iPad, C4JStorage::EMessageResult result); - VBANNEDLIST* m_vBannedListA[XUSER_MAX_COUNT]; - void HandleButtonPresses(int iPad); bool m_bResourcesLoaded; @@ -536,15 +564,7 @@ private: // gamedefined data per player for settings GAME_SETTINGS* GameSettingsA[XUSER_MAX_COUNT]; - // For promo work - bool m_bLoadSavesFromFolderEnabled; - - // For debugging - bool m_bWriteSavesToFolderEnabled; - bool m_bMobsDontAttack; - bool m_bUseDPadForDebug; - bool m_bMobsDontTick; - bool m_bFreezePlayers; + // Debug options now in m_debugOptions // 4J : WESTY : For taking screen shots. // bool m_bInterfaceRenderingOff; @@ -604,7 +624,7 @@ private: void* pParam, int iPad, C4JStorage::EMessageResult result); JoinFromInviteData m_InviteData; - bool m_bDebugOptions; // toggle debug things on or off + // m_bDebugOptions moved to m_debugOptions // Trial timer float m_fTrialTimerStart, mfTrialPausedTime; @@ -653,12 +673,17 @@ private: // XML public: // Hold a vector of terrain feature positions - void AddTerrainFeaturePosition(_eTerrainFeatureType, int, int); - void ClearTerrainFeaturePosition(); - _eTerrainFeatureType IsTerrainFeature(int x, int z); + void AddTerrainFeaturePosition(_eTerrainFeatureType eType, int x, int z) { + m_terrainFeatureManager.add(eType, x, z); + } + void ClearTerrainFeaturePosition() { m_terrainFeatureManager.clear(); } + _eTerrainFeatureType IsTerrainFeature(int x, int z) { + return m_terrainFeatureManager.isFeature(x, z); + } bool GetTerrainFeaturePosition(_eTerrainFeatureType eType, int* pX, - int* pZ); - std::vector m_vTerrainFeatures; + int* pZ) { + return m_terrainFeatureManager.getPosition(eType, pX, pZ); + } static int32_t RegisterMojangData(wchar_t*, PlayerUID, wchar_t*, wchar_t*); MOJANG_DATA* GetMojangDataForXuid(PlayerUID xuid); @@ -729,28 +754,22 @@ public: // void OverrideFontRenderer(bool set, bool immediate = true); // void ToggleFontRenderer() { // OverrideFontRenderer(!m_bFontRendererOverridden,false); } - BANNEDLIST BannedListA[XUSER_MAX_COUNT]; - -private: - // XUI_FontRenderer *m_fontRenderer; - // bool m_bFontRendererOverridden; - // bool m_bOverrideFontRenderer; - - bool m_bRead_BannedListA[XUSER_MAX_COUNT]; - char m_pszUniqueMapName[14]; - bool m_BanListCheck[XUSER_MAX_COUNT]; + BANNEDLIST (&BannedListA)[XUSER_MAX_COUNT] = m_bannedListManager.BannedListA; public: - void SetBanListCheck(int iPad, bool bVal) { m_BanListCheck[iPad] = bVal; } - bool GetBanListCheck(int iPad) { return m_BanListCheck[iPad]; } + void SetBanListCheck(int iPad, bool bVal) { + m_bannedListManager.setBanListCheck(iPad, bVal); + } + bool GetBanListCheck(int iPad) { + return m_bannedListManager.getBanListCheck(iPad); + } // AUTOSAVE public: void SetAutosaveTimerTime(void); - bool AutosaveDue(void); - int64_t SecondsToAutosave(); + bool AutosaveDue(void) { return m_saveManager.autosaveDue(); } + int64_t SecondsToAutosave() { return m_saveManager.secondsToAutosave(); } private: - time_util::time_point m_uiAutosaveTimer; unsigned int m_uiOpacityCountDown[XUSER_MAX_COUNT]; // DLC @@ -870,12 +889,10 @@ public: void SetCorruptSaveDeleted(bool bVal) { m_bCorruptSaveDeleted = bVal; } bool GetCorruptSaveDeleted(void) { return m_bCorruptSaveDeleted; } - void lockSaveNotification(); - void unlockSaveNotification(); + void lockSaveNotification() { m_saveManager.lock(); } + void unlockSaveNotification() { m_saveManager.unlock(); } private: - std::mutex m_saveNotificationMutex; - int m_saveNotificationDepth; // Download Status // Request current_download; @@ -895,8 +912,8 @@ private: std::uint32_t m_dwAdditionalModelParts[XUSER_MAX_COUNT]; - std::uint8_t* m_pBannedListFileBuffer; - unsigned int m_dwBannedListFileSize; + std::uint8_t*& m_pBannedListFileBuffer = m_bannedListManager.m_pBannedListFileBuffer; + unsigned int& m_dwBannedListFileSize = m_bannedListManager.m_dwBannedListFileSize; public: unsigned int m_dwDLCFileSize; @@ -935,14 +952,13 @@ public: virtual bool GetTMSDLCInfoRead() { return true; } virtual bool GetTMSXUIDsFileRead() { return true; } - bool GetBanListRead(int iPad) { return m_bRead_BannedListA[iPad]; } + bool GetBanListRead(int iPad) { + return m_bannedListManager.getBanListRead(iPad); + } void SetBanListRead(int iPad, bool bVal) { - m_bRead_BannedListA[iPad] = bVal; - } - void ClearBanList(int iPad) { - BannedListA[iPad].pBannedList = nullptr; - BannedListA[iPad].byteCount = 0; + m_bannedListManager.setBanListRead(iPad, bVal); } + void ClearBanList(int iPad) { m_bannedListManager.clearBanList(iPad); } std::uint32_t GetRequiredTexturePackID() { return m_dwRequiredTexturePackID; diff --git a/targets/app/common/SaveManager.cpp b/targets/app/common/SaveManager.cpp new file mode 100644 index 000000000..cc8cf5c73 --- /dev/null +++ b/targets/app/common/SaveManager.cpp @@ -0,0 +1,62 @@ +#include "app/common/SaveManager.h" + +#include + +#include "app/common/Game.h" +#include "app/common/Network/GameNetworkManager.h" +#include "minecraft/server/MinecraftServer.h" +#include "platform/sdl2/Profile.h" + +void SaveManager::setAutosaveTimerTime(int settingValue) { + m_uiAutosaveTimer = + time_util::clock::now() + + std::chrono::minutes(settingValue * 15); +} + +bool SaveManager::autosaveDue() const { + return (time_util::clock::now() > m_uiAutosaveTimer); +} + +int64_t SaveManager::secondsToAutosave() const { + return std::chrono::duration_cast( + m_uiAutosaveTimer - time_util::clock::now()) + .count(); +} + +void SaveManager::lock() { + std::lock_guard lock(m_saveNotificationMutex); + if (m_saveNotificationDepth++ == 0) { + if (g_NetworkManager + .IsInSession()) // this can be triggered from the front end if + // we're downloading a save + { + MinecraftServer::getInstance()->broadcastStartSavingPacket(); + + if (g_NetworkManager.IsLocalGame() && + g_NetworkManager.GetPlayerCount() == 1) { + app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), + eXuiServerAction_PauseServer, + (void*)true); + } + } + } +} + +void SaveManager::unlock() { + std::lock_guard lock(m_saveNotificationMutex); + if (--m_saveNotificationDepth == 0) { + if (g_NetworkManager + .IsInSession()) // this can be triggered from the front end if + // we're downloading a save + { + MinecraftServer::getInstance()->broadcastStopSavingPacket(); + + if (g_NetworkManager.IsLocalGame() && + g_NetworkManager.GetPlayerCount() == 1) { + app.SetXuiServerAction(ProfileManager.GetPrimaryPad(), + eXuiServerAction_PauseServer, + (void*)false); + } + } + } +} diff --git a/targets/app/common/SaveManager.h b/targets/app/common/SaveManager.h new file mode 100644 index 000000000..a5159e8ce --- /dev/null +++ b/targets/app/common/SaveManager.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +#include "util/Timer.h" + +class SaveManager { +public: + SaveManager() : m_uiAutosaveTimer{}, m_saveNotificationDepth(0) {} + + void setAutosaveTimerTime(int settingValue); + bool autosaveDue() const; + int64_t secondsToAutosave() const; + + void lock(); + void unlock(); + +private: + time_util::time_point m_uiAutosaveTimer; + std::mutex m_saveNotificationMutex; + int m_saveNotificationDepth; +}; diff --git a/targets/app/common/TerrainFeatureManager.cpp b/targets/app/common/TerrainFeatureManager.cpp new file mode 100644 index 000000000..e6a38ecb2 --- /dev/null +++ b/targets/app/common/TerrainFeatureManager.cpp @@ -0,0 +1,58 @@ +#include "app/common/TerrainFeatureManager.h" + +void TerrainFeatureManager::add(_eTerrainFeatureType eFeatureType, int x, + int z) { + // check we don't already have this in + for (auto it = m_vTerrainFeatures.begin(); it < m_vTerrainFeatures.end(); + ++it) { + FEATURE_DATA* pFeatureData = *it; + + if ((pFeatureData->eTerrainFeature == eFeatureType) && + (pFeatureData->x == x) && (pFeatureData->z == z)) + return; + } + + FEATURE_DATA* pFeatureData = new FEATURE_DATA; + pFeatureData->eTerrainFeature = eFeatureType; + pFeatureData->x = x; + pFeatureData->z = z; + + m_vTerrainFeatures.push_back(pFeatureData); +} + +_eTerrainFeatureType TerrainFeatureManager::isFeature(int x, int z) const { + for (auto it = m_vTerrainFeatures.begin(); it < m_vTerrainFeatures.end(); + ++it) { + FEATURE_DATA* pFeatureData = *it; + + if ((pFeatureData->x == x) && (pFeatureData->z == z)) + return pFeatureData->eTerrainFeature; + } + + return eTerrainFeature_None; +} + +bool TerrainFeatureManager::getPosition(_eTerrainFeatureType eType, int* pX, + int* pZ) const { + for (auto it = m_vTerrainFeatures.begin(); it < m_vTerrainFeatures.end(); + ++it) { + FEATURE_DATA* pFeatureData = *it; + + if (pFeatureData->eTerrainFeature == eType) { + *pX = pFeatureData->x; + *pZ = pFeatureData->z; + return true; + } + } + + return false; +} + +void TerrainFeatureManager::clear() { + FEATURE_DATA* pFeatureData; + while (m_vTerrainFeatures.size() > 0) { + pFeatureData = m_vTerrainFeatures.back(); + m_vTerrainFeatures.pop_back(); + delete pFeatureData; + } +} diff --git a/targets/app/common/TerrainFeatureManager.h b/targets/app/common/TerrainFeatureManager.h new file mode 100644 index 000000000..58fa3647d --- /dev/null +++ b/targets/app/common/TerrainFeatureManager.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include "app/common/App_enums.h" +#include "app/common/App_structs.h" + +class TerrainFeatureManager { +public: + void add(_eTerrainFeatureType eFeatureType, int x, int z); + void clear(); + _eTerrainFeatureType isFeature(int x, int z) const; + bool getPosition(_eTerrainFeatureType eType, int* pX, int* pZ) const; + + std::vector* features() { return &m_vTerrainFeatures; } + +private: + std::vector m_vTerrainFeatures; +}; diff --git a/targets/app/linux/Linux_Minecraft.cpp b/targets/app/linux/Linux_Minecraft.cpp index d04f53533..e2ccc11d2 100644 --- a/targets/app/linux/Linux_Minecraft.cpp +++ b/targets/app/linux/Linux_Minecraft.cpp @@ -598,7 +598,7 @@ int main(int argc, const char* argv[]) { &app.m_dlcManager, &app.m_gameRules, &app.vSkinNames, - &app.m_vTerrainFeatures + app.m_terrainFeatureManager.features() ); static GameMenuService menuService(app); GameServices::initMenuService(&menuService);