refactor: extract SaveManager, BannedListManager, TerrainFeatureManager, DebugOptions from Game

This commit is contained in:
MatthewBeshay 2026-04-04 17:44:24 +11:00 committed by Tropical
parent 5f64818302
commit 0c7800d28b
11 changed files with 509 additions and 321 deletions

View file

@ -0,0 +1,131 @@
#include "app/common/BannedListManager.h"
#include <cstring>
#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<PBANNEDLISTDATA>;
}
}
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<unsigned int>(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<unsigned int>(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;
}

View file

@ -0,0 +1,46 @@
#pragma once
#include <cstdint>
#include <cstring>
#include <vector>
#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];
};

View file

@ -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

View file

@ -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;
};

View file

@ -149,9 +149,6 @@ Game::Game() {
DebugPrintf("Player at index %d has guest number %d\n", i, DebugPrintf("Player at index %d has guest number %d\n", i,
m_currentSigninInfo[i].dwGuestNumber); m_currentSigninInfo[i].dwGuestNumber);
m_bRead_BannedListA[i] = false;
SetBanListCheck(i, false);
m_uiOpacityCountDown[i] = 0; m_uiOpacityCountDown[i] = 0;
} }
m_eGlobalXuiAction = eAppAction_Idle; m_eGlobalXuiAction = eAppAction_Idle;
@ -164,8 +161,6 @@ Game::Game() {
m_bIntroRunning = false; m_bIntroRunning = false;
m_eGameMode = eMode_Singleplayer; m_eGameMode = eMode_Singleplayer;
m_bLoadSavesFromFolderEnabled = false;
m_bWriteSavesToFolderEnabled = false;
// m_bInterfaceRenderingOff = false; // m_bInterfaceRenderingOff = false;
// m_bHandRenderingOff = false; // m_bHandRenderingOff = false;
m_bTutorialMode = false; m_bTutorialMode = false;
@ -174,18 +169,6 @@ Game::Game() {
m_bChangingSessionType = false; m_bChangingSessionType = false;
m_bReallyChangingSessionType = 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); // memset(m_PreviewBuffer, 0, sizeof(XSOCIAL_PREVIEWIMAGE)*XUSER_MAX_COUNT);
m_xuidNotch = INVALID_XUID; m_xuidNotch = INVALID_XUID;
@ -197,17 +180,12 @@ Game::Game() {
m_pDLCFileBuffer = nullptr; m_pDLCFileBuffer = nullptr;
m_dwDLCFileSize = 0; m_dwDLCFileSize = 0;
m_pBannedListFileBuffer = nullptr;
m_dwBannedListFileSize = 0;
m_bDefaultCapeInstallAttempted = false; m_bDefaultCapeInstallAttempted = false;
m_bDLCInstallProcessCompleted = false; m_bDLCInstallProcessCompleted = false;
m_bDLCInstallPending = false; m_bDLCInstallPending = false;
m_iTotalDLC = 0; m_iTotalDLC = 0;
m_iTotalDLCInstalled = 0; m_iTotalDLCInstalled = 0;
mfTrialPausedTime = 0.0f; mfTrialPausedTime = 0.0f;
m_uiAutosaveTimer = {};
memset(m_pszUniqueMapName, 0, 14);
m_bNewDLCAvailable = false; m_bNewDLCAvailable = false;
m_bSeenNewDLCTip = false; m_bSeenNewDLCTip = false;
@ -226,22 +204,10 @@ Game::Game() {
m_bAllDLCContentRetrieved = true; m_bAllDLCContentRetrieved = true;
m_bAllTMSContentRetrieved = true; m_bAllTMSContentRetrieved = true;
m_bTickTMSDLCFiles = true; m_bTickTMSDLCFiles = true;
m_saveNotificationDepth = 0;
m_dwRequiredTexturePackID = 0; m_dwRequiredTexturePackID = 0;
m_bResetNether = false; 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<PBANNEDLISTDATA>;
}
LocaleAndLanguageInit(); LocaleAndLanguageInit();
} }
@ -4127,16 +4093,15 @@ void Game::NotificationsCallback(void* pParam,
#if defined(_DEBUG_MENUS_ENABLED) #if defined(_DEBUG_MENUS_ENABLED)
bool Game::DebugArtToolsOn() { bool Game::DebugArtToolsOn() {
return DebugSettingsOn() && return m_debugOptions.debugArtToolsOn(
(GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad()) & GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad()));
(1L << eDebugSetting_ArtTools)) != 0;
} }
#endif #endif
void Game::SetDebugSequence(const char* pchSeq) { void Game::SetDebugSequence(const char* pchSeq) {
InputManager.SetDebugSequence(pchSeq, [this]() -> int { InputManager.SetDebugSequence(pchSeq, [this]() -> int {
// printf("sequence matched\n"); // printf("sequence matched\n");
m_bDebugOptions = !m_bDebugOptions; m_debugOptions.setDebugOptions(!m_debugOptions.settingsOn());
for (int i = 0; i < XUSER_MAX_COUNT; i++) { for (int i = 0; i < XUSER_MAX_COUNT; i++) {
if (app.DebugSettingsOn()) { if (app.DebugSettingsOn()) {
@ -5521,43 +5486,6 @@ DLC_INFO* Game::GetDLCInfoForFullOfferID(uint64_t ullOfferID_Full) {
return nullptr; return nullptr;
} }
void Game::lockSaveNotification() {
std::lock_guard<std::mutex> 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<std::mutex> 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) { int Game::RemoteSaveThreadProc(void* lpParameter) {
// The game should be stopped while we are doing this, but the connections // 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<unsigned int>(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<unsigned int>(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 // function to add credits for the DLC packs
void Game::AddCreditText(const wchar_t* lpStr) { void Game::AddCreditText(const wchar_t* lpStr) {
@ -6327,62 +6141,6 @@ unsigned int Game::CreateImageTextData(std::uint8_t* textMetadata,
return iTextMetadataBytes; 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, void Game::UpdatePlayerInfo(std::uint8_t networkSmallId,
int16_t playerColourIndex, int16_t playerColourIndex,
@ -7172,17 +6930,7 @@ int Game::GetDLCInfoTexturesOffersCount() {
// AUTOSAVE // AUTOSAVE
void Game::SetAutosaveTimerTime(void) { void Game::SetAutosaveTimerTime(void) {
int settingValue = GetGameSettings(ProfileManager.GetPrimaryPad(), eGameSetting_Autosave); int settingValue = GetGameSettings(ProfileManager.GetPrimaryPad(), eGameSetting_Autosave);
m_uiAutosaveTimer = m_saveManager.setAutosaveTimerTime(settingValue);
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<std::chrono::seconds>(m_uiAutosaveTimer - time_util::clock::now()).count();
} }
void Game::SetTrialTimerStart(void) { void Game::SetTrialTimerStart(void) {

View file

@ -9,8 +9,12 @@
// using namespace std; // using namespace std;
#include "app/common/BannedListManager.h"
#include "app/common/DebugOptions.h"
#include "app/common/IPlatformGame.h" #include "app/common/IPlatformGame.h"
#include "app/common/App_structs.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/Audio/Consoles_SoundEngine.h"
#include "app/common/DLC/DLCManager.h" #include "app/common/DLC/DLCManager.h"
#include "app/common/GameRules/ConsoleGameRulesConstants.h" #include "app/common/GameRules/ConsoleGameRulesConstants.h"
@ -71,6 +75,10 @@ public:
// storing skin files // storing skin files
std::vector<std::wstring> vSkinNames; std::vector<std::wstring> vSkinNames;
DLCManager m_dlcManager; DLCManager m_dlcManager;
SaveManager m_saveManager;
BannedListManager m_bannedListManager;
TerrainFeatureManager m_terrainFeatureManager;
DebugOptions m_debugOptions;
// storing credits text from the DLC // storing credits text from the DLC
std::vector<std::wstring> m_vCreditText; // hold the credit text lines so std::vector<std::wstring> m_vCreditText; // hold the credit text lines so
@ -242,26 +250,36 @@ public:
// 4J Stu - Functions used for Minecon and other promo work // 4J Stu - Functions used for Minecon and other promo work
bool GetLoadSavesFromFolderEnabled() { bool GetLoadSavesFromFolderEnabled() {
return m_bLoadSavesFromFolderEnabled; return m_debugOptions.getLoadSavesFromFolderEnabled();
} }
void SetLoadSavesFromFolderEnabled(bool bVal) { void SetLoadSavesFromFolderEnabled(bool bVal) {
m_bLoadSavesFromFolderEnabled = bVal; m_debugOptions.setLoadSavesFromFolderEnabled(bVal);
} }
// 4J Stu - Useful for debugging // 4J Stu - Useful for debugging
bool GetWriteSavesToFolderEnabled() { return m_bWriteSavesToFolderEnabled; } bool GetWriteSavesToFolderEnabled() {
void SetWriteSavesToFolderEnabled(bool bVal) { return m_debugOptions.getWriteSavesToFolderEnabled();
m_bWriteSavesToFolderEnabled = bVal; }
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; } bool GetFreezePlayers() { return m_debugOptions.getFreezePlayers(); }
void SetFreezePlayers(bool bVal) { m_bFreezePlayers = bVal; } void SetFreezePlayers(bool bVal) { m_debugOptions.setFreezePlayers(bVal); }
// debug -0 show safe area // debug -0 show safe area
void ShowSafeArea(bool show) {} void ShowSafeArea(bool show) {}
@ -364,7 +382,7 @@ public:
void SetLiveLinkRequired(bool required) { m_bLiveLinkRequired = required; } void SetLiveLinkRequired(bool required) { m_bLiveLinkRequired = required; }
#if defined(_DEBUG_MENUS_ENABLED) #if defined(_DEBUG_MENUS_ENABLED)
bool DebugSettingsOn() { return m_bDebugOptions; } bool DebugSettingsOn() { return m_debugOptions.settingsOn(); }
bool DebugArtToolsOn(); bool DebugArtToolsOn();
#else #else
bool DebugSettingsOn() { return false; } bool DebugSettingsOn() { return false; }
@ -465,13 +483,25 @@ public:
public: public:
// BAN LIST // BAN LIST
void AddLevelToBannedLevelList(int iPad, PlayerUID xuid, char* pszLevelName, void AddLevelToBannedLevelList(int iPad, PlayerUID xuid, char* pszLevelName,
bool bWriteToTMS); bool bWriteToTMS) {
bool IsInBannedLevelList(int iPad, PlayerUID xuid, char* pszLevelName); 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, void RemoveLevelFromBannedLevelList(int iPad, PlayerUID xuid,
char* pszLevelName); char* pszLevelName) {
void InvalidateBannedList(int iPad); m_bannedListManager.removeLevel(iPad, xuid, pszLevelName);
void SetUniqueMapName(char* pszUniqueMapName); }
char* GetUniqueMapName(void); void InvalidateBannedList(int iPad) {
m_bannedListManager.invalidate(iPad);
}
void SetUniqueMapName(char* pszUniqueMapName) {
m_bannedListManager.setUniqueMapName(pszUniqueMapName);
}
char* GetUniqueMapName(void) {
return m_bannedListManager.getUniqueMapName();
}
public: public:
bool GetResourcesLoaded() { return m_bResourcesLoaded; } bool GetResourcesLoaded() { return m_bResourcesLoaded; }
@ -507,8 +537,6 @@ private:
static int TexturePackDialogReturned(void* pParam, int iPad, static int TexturePackDialogReturned(void* pParam, int iPad,
C4JStorage::EMessageResult result); C4JStorage::EMessageResult result);
VBANNEDLIST* m_vBannedListA[XUSER_MAX_COUNT];
void HandleButtonPresses(int iPad); void HandleButtonPresses(int iPad);
bool m_bResourcesLoaded; bool m_bResourcesLoaded;
@ -536,15 +564,7 @@ private:
// gamedefined data per player for settings // gamedefined data per player for settings
GAME_SETTINGS* GameSettingsA[XUSER_MAX_COUNT]; GAME_SETTINGS* GameSettingsA[XUSER_MAX_COUNT];
// For promo work // Debug options now in m_debugOptions
bool m_bLoadSavesFromFolderEnabled;
// For debugging
bool m_bWriteSavesToFolderEnabled;
bool m_bMobsDontAttack;
bool m_bUseDPadForDebug;
bool m_bMobsDontTick;
bool m_bFreezePlayers;
// 4J : WESTY : For taking screen shots. // 4J : WESTY : For taking screen shots.
// bool m_bInterfaceRenderingOff; // bool m_bInterfaceRenderingOff;
@ -604,7 +624,7 @@ private:
void* pParam, int iPad, C4JStorage::EMessageResult result); void* pParam, int iPad, C4JStorage::EMessageResult result);
JoinFromInviteData m_InviteData; JoinFromInviteData m_InviteData;
bool m_bDebugOptions; // toggle debug things on or off // m_bDebugOptions moved to m_debugOptions
// Trial timer // Trial timer
float m_fTrialTimerStart, mfTrialPausedTime; float m_fTrialTimerStart, mfTrialPausedTime;
@ -653,12 +673,17 @@ private:
// XML // XML
public: public:
// Hold a vector of terrain feature positions // Hold a vector of terrain feature positions
void AddTerrainFeaturePosition(_eTerrainFeatureType, int, int); void AddTerrainFeaturePosition(_eTerrainFeatureType eType, int x, int z) {
void ClearTerrainFeaturePosition(); m_terrainFeatureManager.add(eType, x, z);
_eTerrainFeatureType IsTerrainFeature(int x, int z); }
void ClearTerrainFeaturePosition() { m_terrainFeatureManager.clear(); }
_eTerrainFeatureType IsTerrainFeature(int x, int z) {
return m_terrainFeatureManager.isFeature(x, z);
}
bool GetTerrainFeaturePosition(_eTerrainFeatureType eType, int* pX, bool GetTerrainFeaturePosition(_eTerrainFeatureType eType, int* pX,
int* pZ); int* pZ) {
std::vector<FEATURE_DATA*> m_vTerrainFeatures; return m_terrainFeatureManager.getPosition(eType, pX, pZ);
}
static int32_t RegisterMojangData(wchar_t*, PlayerUID, wchar_t*, wchar_t*); static int32_t RegisterMojangData(wchar_t*, PlayerUID, wchar_t*, wchar_t*);
MOJANG_DATA* GetMojangDataForXuid(PlayerUID xuid); MOJANG_DATA* GetMojangDataForXuid(PlayerUID xuid);
@ -729,28 +754,22 @@ public:
// void OverrideFontRenderer(bool set, bool immediate = true); // void OverrideFontRenderer(bool set, bool immediate = true);
// void ToggleFontRenderer() { // void ToggleFontRenderer() {
// OverrideFontRenderer(!m_bFontRendererOverridden,false); } // OverrideFontRenderer(!m_bFontRendererOverridden,false); }
BANNEDLIST BannedListA[XUSER_MAX_COUNT]; BANNEDLIST (&BannedListA)[XUSER_MAX_COUNT] = m_bannedListManager.BannedListA;
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];
public: public:
void SetBanListCheck(int iPad, bool bVal) { m_BanListCheck[iPad] = bVal; } void SetBanListCheck(int iPad, bool bVal) {
bool GetBanListCheck(int iPad) { return m_BanListCheck[iPad]; } m_bannedListManager.setBanListCheck(iPad, bVal);
}
bool GetBanListCheck(int iPad) {
return m_bannedListManager.getBanListCheck(iPad);
}
// AUTOSAVE // AUTOSAVE
public: public:
void SetAutosaveTimerTime(void); void SetAutosaveTimerTime(void);
bool AutosaveDue(void); bool AutosaveDue(void) { return m_saveManager.autosaveDue(); }
int64_t SecondsToAutosave(); int64_t SecondsToAutosave() { return m_saveManager.secondsToAutosave(); }
private: private:
time_util::time_point m_uiAutosaveTimer;
unsigned int m_uiOpacityCountDown[XUSER_MAX_COUNT]; unsigned int m_uiOpacityCountDown[XUSER_MAX_COUNT];
// DLC // DLC
@ -870,12 +889,10 @@ public:
void SetCorruptSaveDeleted(bool bVal) { m_bCorruptSaveDeleted = bVal; } void SetCorruptSaveDeleted(bool bVal) { m_bCorruptSaveDeleted = bVal; }
bool GetCorruptSaveDeleted(void) { return m_bCorruptSaveDeleted; } bool GetCorruptSaveDeleted(void) { return m_bCorruptSaveDeleted; }
void lockSaveNotification(); void lockSaveNotification() { m_saveManager.lock(); }
void unlockSaveNotification(); void unlockSaveNotification() { m_saveManager.unlock(); }
private: private:
std::mutex m_saveNotificationMutex;
int m_saveNotificationDepth;
// Download Status // Download Status
// Request current_download; // Request current_download;
@ -895,8 +912,8 @@ private:
std::uint32_t m_dwAdditionalModelParts[XUSER_MAX_COUNT]; std::uint32_t m_dwAdditionalModelParts[XUSER_MAX_COUNT];
std::uint8_t* m_pBannedListFileBuffer; std::uint8_t*& m_pBannedListFileBuffer = m_bannedListManager.m_pBannedListFileBuffer;
unsigned int m_dwBannedListFileSize; unsigned int& m_dwBannedListFileSize = m_bannedListManager.m_dwBannedListFileSize;
public: public:
unsigned int m_dwDLCFileSize; unsigned int m_dwDLCFileSize;
@ -935,14 +952,13 @@ public:
virtual bool GetTMSDLCInfoRead() { return true; } virtual bool GetTMSDLCInfoRead() { return true; }
virtual bool GetTMSXUIDsFileRead() { 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) { void SetBanListRead(int iPad, bool bVal) {
m_bRead_BannedListA[iPad] = bVal; m_bannedListManager.setBanListRead(iPad, bVal);
}
void ClearBanList(int iPad) {
BannedListA[iPad].pBannedList = nullptr;
BannedListA[iPad].byteCount = 0;
} }
void ClearBanList(int iPad) { m_bannedListManager.clearBanList(iPad); }
std::uint32_t GetRequiredTexturePackID() { std::uint32_t GetRequiredTexturePackID() {
return m_dwRequiredTexturePackID; return m_dwRequiredTexturePackID;

View file

@ -0,0 +1,62 @@
#include "app/common/SaveManager.h"
#include <chrono>
#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<std::chrono::seconds>(
m_uiAutosaveTimer - time_util::clock::now())
.count();
}
void SaveManager::lock() {
std::lock_guard<std::mutex> 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<std::mutex> 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);
}
}
}
}

View file

@ -0,0 +1,23 @@
#pragma once
#include <cstdint>
#include <mutex>
#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;
};

View file

@ -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;
}
}

View file

@ -0,0 +1,19 @@
#pragma once
#include <vector>
#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<FEATURE_DATA*>* features() { return &m_vTerrainFeatures; }
private:
std::vector<FEATURE_DATA*> m_vTerrainFeatures;
};

View file

@ -598,7 +598,7 @@ int main(int argc, const char* argv[]) {
&app.m_dlcManager, &app.m_dlcManager,
&app.m_gameRules, &app.m_gameRules,
&app.vSkinNames, &app.vSkinNames,
&app.m_vTerrainFeatures app.m_terrainFeatureManager.features()
); );
static GameMenuService menuService(app); static GameMenuService menuService(app);
GameServices::initMenuService(&menuService); GameServices::initMenuService(&menuService);