Fix Music and DLCs Saves

This commit is contained in:
GabsPuNs
2026-03-21 01:43:53 -04:00
parent 6932b8bb91
commit 3f74c89fdf
5 changed files with 22 additions and 98 deletions

View File

@@ -830,29 +830,32 @@ int SoundEngine::GetRandomishTrack(int iStart,int iEnd)
/////////////////////////////////////////////
int SoundEngine::getMusicID(int iDomain)
{
int iRandomVal=0;
Minecraft *pMinecraft=Minecraft::GetInstance();
// Before the game has started?
if(pMinecraft==nullptr)
{
// any track from the overworld
return GetRandomishTrack(m_iStream_Overworld_Min,m_iStream_Overworld_Max);
// return GetRandomishTrack(m_iStream_Overworld_Min,m_iStream_Overworld_Max);
return GetRandomishTrack(m_iStream_Menu_Min, m_iStream_Menu_Max);
}
if(pMinecraft->skins->isUsingDefaultSkin())
{
switch(iDomain)
{
case LevelData::DIMENSION_END:
case eMusicDomain_End:
// the end isn't random - it has different music depending on whether the dragon is alive or not, but we've not added the dead dragon music yet
return m_iStream_End_Min;
case LevelData::DIMENSION_NETHER:
return GetRandomishTrack(m_iStream_Nether_Min,m_iStream_Nether_Max);
//return m_iStream_Nether_Min + random->nextInt(m_iStream_Nether_Max-m_iStream_Nether_Min);
case eMusicDomain_Nether:
return GetRandomishTrack(m_iStream_Nether_Min, m_iStream_Nether_Max);
case eMusicDomain_Creative:
return GetRandomishTrack(m_iStream_Creative_Min, m_iStream_Creative_Max);
case eMusicDomain_Menu:
return GetRandomishTrack(m_iStream_Menu_Min, m_iStream_Menu_Max);
default: //overworld
//return m_iStream_Overworld_Min + random->nextInt(m_iStream_Overworld_Max-m_iStream_Overworld_Min);
return GetRandomishTrack(m_iStream_Overworld_Min,m_iStream_Overworld_Max);
return GetRandomishTrack(m_iStream_Overworld_Min, m_iStream_Overworld_Max);
}
}
else
@@ -860,13 +863,15 @@ int SoundEngine::getMusicID(int iDomain)
// using a texture pack - may have multiple End music tracks
switch(iDomain)
{
case LevelData::DIMENSION_END:
case eMusicDomain_End:
return GetRandomishTrack(m_iStream_End_Min,m_iStream_End_Max);
case LevelData::DIMENSION_NETHER:
//return m_iStream_Nether_Min + random->nextInt(m_iStream_Nether_Max-m_iStream_Nether_Min);
case eMusicDomain_Nether:
return GetRandomishTrack(m_iStream_Nether_Min,m_iStream_Nether_Max);
case eMusicDomain_Creative:
return GetRandomishTrack(m_iStream_Creative_Min, m_iStream_Creative_Max);
case eMusicDomain_Menu:
return GetRandomishTrack(m_iStream_Menu_Min, m_iStream_Menu_Max);
default: //overworld
//return m_iStream_Overworld_Min + random->nextInt(m_iStream_Overworld_Max-m_iStream_Overworld_Min);
return GetRandomishTrack(m_iStream_Overworld_Min,m_iStream_Overworld_Max);
}
}
@@ -1364,7 +1369,7 @@ void SoundEngine::playMusicUpdate()
m_StreamState=eMusicStreamState_Stop; //
// Set the end track
m_musicID = getMusicID(eMusicDomain_Overworld);
pickGameModeMusic(pMinecraft, i);
SetIsPlayingEndMusic(false);
SetIsPlayingNetherMusic(false);
}
@@ -1391,7 +1396,7 @@ void SoundEngine::playMusicUpdate()
{
m_StreamState=eMusicStreamState_Stop; //
// set the Nether track
m_musicID = getMusicID(eMusicDomain_Overworld);
pickGameModeMusic(pMinecraft, i);
SetIsPlayingNetherMusic(false);
SetIsPlayingEndMusic(false);
}

View File

@@ -455,74 +455,6 @@ 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 != nullptr) mountIndex = m_parentDLCPack->GetDLCMountIndex();
@@ -549,7 +481,6 @@ void LevelGenerationOptions::loadBaseSaveData()
setLoadedData();
app.SetAction(ProfileManager.GetPrimaryPad(), eAppAction_ReloadTexturePack);
}
#endif
}
int LevelGenerationOptions::packMounted(LPVOID pParam,int iPad,DWORD dwErr,DWORD dwLicenceMask)

View File

@@ -957,18 +957,13 @@ int CGameNetworkManager::ServerThreadProc( void* lpParameter )
app.SetGameHostOption(eGameHostOption_All,param->settings);
// 4J Stu - If we are loading a DLC save that's separate from the texture pack, load
if (param != nullptr && param->levelGen != nullptr && param->levelGen->isFromDLC())
if( param->levelGen != nullptr && (param->texturePackId == 0 || param->levelGen->getRequiredTexturePackId() != param->texturePackId) )
{
while((Minecraft::GetInstance()->skins->needsUIUpdate() || ui.IsReloadingSkin()))
{
Sleep(1);
}
param->levelGen->loadBaseSaveData();
while (!param->levelGen->hasLoadedData())
{
Sleep(1);
}
}
}

View File

@@ -943,10 +943,7 @@ bool MinecraftServer::loadLevel(LevelStorageSource *storageSource, const wstring
storage = shared_ptr<McRegionLevelStorage>(new McRegionLevelStorage(newFormatSave, File(L"."), name, true));
#else
ConsoleSaveFileOriginal* pSave = new ConsoleSaveFileOriginal(L"");
pSave->ConvertToLocalPlatform();
storage = std::make_shared<McRegionLevelStorage>(pSave, File(L"."), name, true);
storage = std::make_shared<McRegionLevelStorage>(new ConsoleSaveFileOriginal(L""), File(L"."), name, true);
#endif
}

View File

@@ -11,12 +11,8 @@ bool RegionFileCache::useSplitSaves(ESavePlatform platform)
{
case SAVE_FILE_PLATFORM_XBONE:
case SAVE_FILE_PLATFORM_PS4:
return true;
case SAVE_FILE_PLATFORM_WIN64:
{
LevelGenerationOptions* lgo = app.getLevelGenerationOptions();
return (lgo != nullptr && lgo->isFromDLC());
}
return true;
default:
return false;
};