aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/Common/GameRules/LevelGenerationOptions.cpp
diff options
context:
space:
mode:
authorqwasdrizzel <145519042+qwasdrizzel@users.noreply.github.com>2026-03-16 21:44:26 -0500
committerGitHub <noreply@github.com>2026-03-16 21:44:26 -0500
commitce739f6045ec72127491286ea3f3f21e537c1b55 (patch)
treef33bd42a47c1b4a7b2153a7fb77127ee3b407db9 /Minecraft.Client/Common/GameRules/LevelGenerationOptions.cpp
parent255a18fe8e9b57377975f82e2b227afe2a12eda0 (diff)
parent5a59f5d146b43811dde6a5a0245ee9875d7b5cd1 (diff)
Merge branch 'smartcmd:main' into main
Diffstat (limited to 'Minecraft.Client/Common/GameRules/LevelGenerationOptions.cpp')
-rw-r--r--Minecraft.Client/Common/GameRules/LevelGenerationOptions.cpp141
1 files changed, 105 insertions, 36 deletions
diff --git a/Minecraft.Client/Common/GameRules/LevelGenerationOptions.cpp b/Minecraft.Client/Common/GameRules/LevelGenerationOptions.cpp
index e49ee293..2af1826c 100644
--- a/Minecraft.Client/Common/GameRules/LevelGenerationOptions.cpp
+++ b/Minecraft.Client/Common/GameRules/LevelGenerationOptions.cpp
@@ -44,8 +44,8 @@ bool JustGrSource::ready() { return true; }
LevelGenerationOptions::LevelGenerationOptions(DLCPack *parentPack)
{
- m_spawnPos = NULL;
- m_stringTable = NULL;
+ m_spawnPos = nullptr;
+ m_stringTable = nullptr;
m_hasLoadedData = false;
@@ -56,7 +56,7 @@ LevelGenerationOptions::LevelGenerationOptions(DLCPack *parentPack)
m_minY = INT_MAX;
m_bRequiresGameRules = false;
- m_pbBaseSaveData = NULL;
+ m_pbBaseSaveData = nullptr;
m_dwBaseSaveSize = 0;
m_parentDLCPack = parentPack;
@@ -66,7 +66,7 @@ LevelGenerationOptions::LevelGenerationOptions(DLCPack *parentPack)
LevelGenerationOptions::~LevelGenerationOptions()
{
clearSchematics();
- if(m_spawnPos != NULL) delete m_spawnPos;
+ if(m_spawnPos != nullptr) delete m_spawnPos;
for (auto& it : m_schematicRules )
{
delete it;
@@ -141,26 +141,26 @@ void LevelGenerationOptions::getChildren(vector<GameRuleDefinition *> *children)
GameRuleDefinition *LevelGenerationOptions::addChild(ConsoleGameRules::EGameRuleType ruleType)
{
- GameRuleDefinition *rule = NULL;
+ GameRuleDefinition *rule = nullptr;
if(ruleType == ConsoleGameRules::eGameRuleType_ApplySchematic)
{
rule = new ApplySchematicRuleDefinition(this);
- m_schematicRules.push_back((ApplySchematicRuleDefinition *)rule);
+ m_schematicRules.push_back(static_cast<ApplySchematicRuleDefinition *>(rule));
}
else if(ruleType == ConsoleGameRules::eGameRuleType_GenerateStructure)
{
rule = new ConsoleGenerateStructure();
- m_structureRules.push_back((ConsoleGenerateStructure *)rule);
+ m_structureRules.push_back(static_cast<ConsoleGenerateStructure *>(rule));
}
else if(ruleType == ConsoleGameRules::eGameRuleType_BiomeOverride)
{
rule = new BiomeOverride();
- m_biomeOverrides.push_back((BiomeOverride *)rule);
+ m_biomeOverrides.push_back(static_cast<BiomeOverride *>(rule));
}
else if(ruleType == ConsoleGameRules::eGameRuleType_StartFeature)
{
rule = new StartFeature();
- m_features.push_back((StartFeature *)rule);
+ m_features.push_back(static_cast<StartFeature *>(rule));
}
else
{
@@ -175,26 +175,26 @@ void LevelGenerationOptions::addAttribute(const wstring &attributeName, const ws
{
if(attributeName.compare(L"seed") == 0)
{
- m_seed = _fromString<__int64>(attributeValue);
+ m_seed = _fromString<int64_t>(attributeValue);
app.DebugPrintf("LevelGenerationOptions: Adding parameter m_seed=%I64d\n",m_seed);
}
else if(attributeName.compare(L"spawnX") == 0)
{
- if(m_spawnPos == NULL) m_spawnPos = new Pos();
+ if(m_spawnPos == nullptr) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue);
m_spawnPos->x = value;
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnX=%d\n",value);
}
else if(attributeName.compare(L"spawnY") == 0)
{
- if(m_spawnPos == NULL) m_spawnPos = new Pos();
+ if(m_spawnPos == nullptr) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue);
m_spawnPos->y = value;
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnY=%d\n",value);
}
else if(attributeName.compare(L"spawnZ") == 0)
{
- if(m_spawnPos == NULL) m_spawnPos = new Pos();
+ if(m_spawnPos == nullptr) m_spawnPos = new Pos();
int value = _fromString<int>(attributeValue);
m_spawnPos->z = value;
app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnZ=%d\n",value);
@@ -268,7 +268,7 @@ void LevelGenerationOptions::processSchematics(LevelChunk *chunk)
if (structureStart->getBoundingBox()->intersects(cx, cz, cx + 15, cz + 15))
{
BoundingBox *bb = new BoundingBox(cx, cz, cx + 15, cz + 15);
- structureStart->postProcess(chunk->level, NULL, bb);
+ structureStart->postProcess(chunk->level, nullptr, bb);
delete bb;
}
}
@@ -353,7 +353,7 @@ ConsoleSchematicFile *LevelGenerationOptions::loadSchematicFile(const wstring &f
return it->second;
}
- ConsoleSchematicFile *schematic = NULL;
+ ConsoleSchematicFile *schematic = nullptr;
byteArray data(pbData,dwLen);
ByteArrayInputStream bais(data);
DataInputStream dis(&bais);
@@ -366,7 +366,7 @@ ConsoleSchematicFile *LevelGenerationOptions::loadSchematicFile(const wstring &f
ConsoleSchematicFile *LevelGenerationOptions::getSchematicFile(const wstring &filename)
{
- ConsoleSchematicFile *schematic = NULL;
+ ConsoleSchematicFile *schematic = nullptr;
// If we have already loaded this, just return
auto it = m_schematics.find(filename);
if(it != m_schematics.end())
@@ -399,7 +399,7 @@ void LevelGenerationOptions::loadStringTable(StringTable *table)
LPCWSTR LevelGenerationOptions::getString(const wstring &key)
{
- if(m_stringTable == NULL)
+ if(m_stringTable == nullptr)
{
return L"";
}
@@ -455,8 +455,76 @@ unordered_map<wstring, ConsoleSchematicFile *> *LevelGenerationOptions::getUnfin
void LevelGenerationOptions::loadBaseSaveData()
{
+#ifdef _WINDOWS64
+
+ int gameRulesCount = m_parentDLCPack ? m_parentDLCPack->getDLCItemsCount(DLCManager::e_DLCType_GameRulesHeader) : 0;
+
+ wstring baseSave = getBaseSavePath();
+ wstring packName = baseSave.substr(0, baseSave.find(L'.'));
+
+ for (int i = 0; i < gameRulesCount; ++i)
+ {
+ DLCGameRulesHeader* dlcFile = static_cast<DLCGameRulesHeader*>(m_parentDLCPack->getFile(DLCManager::e_DLCType_GameRulesHeader, i));
+
+ if (!dlcFile->getGrfPath().empty())
+ {
+ File grf(L"Windows64Media\\DLC\\" + packName + L"\\Data\\" + dlcFile->getGrfPath());
+
+ if (grf.exists())
+ {
+ wstring path = grf.getPath();
+ HANDLE fileHandle = CreateFileW(path.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
+
+ if (fileHandle != INVALID_HANDLE_VALUE)
+ {
+ DWORD dwFileSize = grf.length();
+ DWORD bytesRead;
+ PBYTE pbData = new BYTE[dwFileSize];
+ BOOL bSuccess = ReadFile(fileHandle, pbData, dwFileSize, &bytesRead, nullptr);
+ CloseHandle(fileHandle);
+
+ if (bSuccess)
+ {
+ dlcFile->setGrfData(pbData, dwFileSize, m_stringTable);
+ app.m_gameRules.setLevelGenerationOptions(dlcFile->lgo);
+ }
+ delete[] pbData;
+ }
+ }
+ }
+ }
+
+ if (requiresBaseSave() && !getBaseSavePath().empty())
+ {
+ File save(L"Windows64Media\\DLC\\" + packName + L"\\Data\\" + baseSave);
+
+ if (save.exists())
+ {
+ wstring path = save.getPath();
+ HANDLE fileHandle = CreateFileW(path.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, nullptr);
+
+ if (fileHandle != INVALID_HANDLE_VALUE)
+ {
+ DWORD dwFileSize = GetFileSize(fileHandle, nullptr);
+ DWORD bytesRead;
+ PBYTE pbData = new BYTE[dwFileSize];
+ BOOL bSuccess = ReadFile(fileHandle, pbData, dwFileSize, &bytesRead, nullptr);
+ CloseHandle(fileHandle);
+
+ if (bSuccess)
+ setBaseSaveData(pbData, dwFileSize);
+ else
+ delete[] pbData;
+ }
+ }
+ }
+
+ setLoadedData();
+ app.SetAction(ProfileManager.GetPrimaryPad(), eAppAction_ReloadTexturePack);
+
+#else
int mountIndex = -1;
- if(m_parentDLCPack != NULL) mountIndex = m_parentDLCPack->GetDLCMountIndex();
+ if(m_parentDLCPack != nullptr) mountIndex = m_parentDLCPack->GetDLCMountIndex();
if(mountIndex > -1)
{
@@ -481,11 +549,12 @@ void LevelGenerationOptions::loadBaseSaveData()
setLoadedData();
app.SetAction(ProfileManager.GetPrimaryPad(), eAppAction_ReloadTexturePack);
}
+#endif
}
int LevelGenerationOptions::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD dwLicenceMask)
{
- LevelGenerationOptions *lgo = (LevelGenerationOptions *)pParam;
+ LevelGenerationOptions *lgo = static_cast<LevelGenerationOptions *>(pParam);
lgo->m_bLoadingData = false;
if(dwErr!=ERROR_SUCCESS)
{
@@ -499,7 +568,7 @@ int LevelGenerationOptions::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD
int gameRulesCount = lgo->m_parentDLCPack->getDLCItemsCount(DLCManager::e_DLCType_GameRulesHeader);
for(int i = 0; i < gameRulesCount; ++i)
{
- DLCGameRulesHeader *dlcFile = (DLCGameRulesHeader *) lgo->m_parentDLCPack->getFile(DLCManager::e_DLCType_GameRulesHeader, i);
+ DLCGameRulesHeader *dlcFile = static_cast<DLCGameRulesHeader *>(lgo->m_parentDLCPack->getFile(DLCManager::e_DLCType_GameRulesHeader, i));
if (!dlcFile->getGrfPath().empty())
{
@@ -513,10 +582,10 @@ int LevelGenerationOptions::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD
pchFilename, // file name
GENERIC_READ, // access mode
0, // share mode // TODO 4J Stu - Will we need to share file? Probably not but...
- NULL, // Unused
+ nullptr, // Unused
OPEN_EXISTING , // how to create // TODO 4J Stu - Assuming that the file already exists if we are opening to read from it
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
- NULL // Unsupported
+ nullptr // Unsupported
);
#else
const char *pchFilename=wstringtofilename(grf.getPath());
@@ -524,10 +593,10 @@ int LevelGenerationOptions::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD
pchFilename, // file name
GENERIC_READ, // access mode
0, // share mode // TODO 4J Stu - Will we need to share file? Probably not but...
- NULL, // Unused
+ nullptr, // Unused
OPEN_EXISTING , // how to create // TODO 4J Stu - Assuming that the file already exists if we are opening to read from it
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
- NULL // Unsupported
+ nullptr // Unsupported
);
#endif
@@ -536,7 +605,7 @@ int LevelGenerationOptions::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD
DWORD dwFileSize = grf.length();
DWORD bytesRead;
PBYTE pbData = (PBYTE) new BYTE[dwFileSize];
- BOOL bSuccess = ReadFile(fileHandle,pbData,dwFileSize,&bytesRead,NULL);
+ BOOL bSuccess = ReadFile(fileHandle,pbData,dwFileSize,&bytesRead,nullptr);
if(bSuccess==FALSE)
{
app.FatalLoadError();
@@ -565,10 +634,10 @@ int LevelGenerationOptions::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD
pchFilename, // file name
GENERIC_READ, // access mode
0, // share mode // TODO 4J Stu - Will we need to share file? Probably not but...
- NULL, // Unused
+ nullptr, // Unused
OPEN_EXISTING , // how to create // TODO 4J Stu - Assuming that the file already exists if we are opening to read from it
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
- NULL // Unsupported
+ nullptr // Unsupported
);
#else
const char *pchFilename=wstringtofilename(save.getPath());
@@ -576,18 +645,18 @@ int LevelGenerationOptions::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD
pchFilename, // file name
GENERIC_READ, // access mode
0, // share mode // TODO 4J Stu - Will we need to share file? Probably not but...
- NULL, // Unused
+ nullptr, // Unused
OPEN_EXISTING , // how to create // TODO 4J Stu - Assuming that the file already exists if we are opening to read from it
FILE_FLAG_SEQUENTIAL_SCAN, // file attributes
- NULL // Unsupported
+ nullptr // Unsupported
);
#endif
if( fileHandle != INVALID_HANDLE_VALUE )
{
- DWORD bytesRead,dwFileSize = GetFileSize(fileHandle,NULL);
+ DWORD bytesRead,dwFileSize = GetFileSize(fileHandle,nullptr);
PBYTE pbData = (PBYTE) new BYTE[dwFileSize];
- BOOL bSuccess = ReadFile(fileHandle,pbData,dwFileSize,&bytesRead,NULL);
+ BOOL bSuccess = ReadFile(fileHandle,pbData,dwFileSize,&bytesRead,nullptr);
if(bSuccess==FALSE)
{
app.FatalLoadError();
@@ -624,8 +693,8 @@ void LevelGenerationOptions::reset_start()
void LevelGenerationOptions::reset_finish()
{
- //if (m_spawnPos) { delete m_spawnPos; m_spawnPos = NULL; }
- //if (m_stringTable) { delete m_stringTable; m_stringTable = NULL; }
+ //if (m_spawnPos) { delete m_spawnPos; m_spawnPos = nullptr; }
+ //if (m_stringTable) { delete m_stringTable; m_stringTable = nullptr; }
if (isFromDLC())
{
@@ -694,13 +763,13 @@ bool LevelGenerationOptions::ready() { return info()->ready(); }
void LevelGenerationOptions::setBaseSaveData(PBYTE pbData, DWORD dwSize) { m_pbBaseSaveData = pbData; m_dwBaseSaveSize = dwSize; }
PBYTE LevelGenerationOptions::getBaseSaveData(DWORD &size) { size = m_dwBaseSaveSize; return m_pbBaseSaveData; }
-bool LevelGenerationOptions::hasBaseSaveData() { return m_dwBaseSaveSize > 0 && m_pbBaseSaveData != NULL; }
-void LevelGenerationOptions::deleteBaseSaveData() { if(m_pbBaseSaveData) delete m_pbBaseSaveData; m_pbBaseSaveData = NULL; m_dwBaseSaveSize = 0; }
+bool LevelGenerationOptions::hasBaseSaveData() { return m_dwBaseSaveSize > 0 && m_pbBaseSaveData != nullptr; }
+void LevelGenerationOptions::deleteBaseSaveData() { if(m_pbBaseSaveData) delete m_pbBaseSaveData; m_pbBaseSaveData = nullptr; m_dwBaseSaveSize = 0; }
bool LevelGenerationOptions::hasLoadedData() { return m_hasLoadedData; }
void LevelGenerationOptions::setLoadedData() { m_hasLoadedData = true; }
-__int64 LevelGenerationOptions::getLevelSeed() { return m_seed; }
+int64_t LevelGenerationOptions::getLevelSeed() { return m_seed; }
int LevelGenerationOptions::getLevelHasBeenInCreative() { return m_bHasBeenInCreative; }
Pos *LevelGenerationOptions::getSpawnPos() { return m_spawnPos; }
bool LevelGenerationOptions::getuseFlatWorld() { return m_useFlatWorld; }