Merge pull request #2008 from Learath2/dd_pr_demohotfix

Fix (not) small bug with demos that don't include a map
This commit is contained in:
Dennis Felsing 2019-12-22 22:38:22 +01:00 committed by GitHub
commit 811ddb3283
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 13 deletions

View file

@ -3420,10 +3420,12 @@ const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
// load map // load map
Crc = m_DemoPlayer.GetMapInfo()->m_Crc; Crc = m_DemoPlayer.GetMapInfo()->m_Crc;
SHA256_DIGEST Sha = m_DemoPlayer.GetMapInfo()->m_Sha256; SHA256_DIGEST Sha = m_DemoPlayer.GetMapInfo()->m_Sha256;
pError = LoadMapSearch(m_DemoPlayer.Info()->m_Header.m_aMapName, &Sha, Crc); pError = LoadMapSearch(m_DemoPlayer.Info()->m_Header.m_aMapName, Sha != SHA256_ZEROED ? &Sha : nullptr, Crc);
if(pError) if(pError)
{ {
m_DemoPlayer.ExtractMap(Storage()); if(!m_DemoPlayer.ExtractMap(Storage()))
return pError;
Sha = m_DemoPlayer.GetMapInfo()->m_Sha256; Sha = m_DemoPlayer.GetMapInfo()->m_Sha256;
pError = LoadMapSearch(m_DemoPlayer.Info()->m_Header.m_aMapName, &Sha, Crc); pError = LoadMapSearch(m_DemoPlayer.Info()->m_Header.m_aMapName, &Sha, Crc);
if(pError) if(pError)

View file

@ -791,10 +791,10 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
return 0; return 0;
} }
void CDemoPlayer::ExtractMap(class IStorage *pStorage) bool CDemoPlayer::ExtractMap(class IStorage *pStorage)
{ {
if(!m_MapInfo.m_Size) if(!m_MapInfo.m_Size)
return; return false;
long CurSeek = io_tell(m_File); long CurSeek = io_tell(m_File);
@ -821,11 +821,16 @@ void CDemoPlayer::ExtractMap(class IStorage *pStorage)
// save map // save map
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE); IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
if(!MapFile)
return false;
io_write(MapFile, pMapData, m_MapInfo.m_Size); io_write(MapFile, pMapData, m_MapInfo.m_Size);
io_close(MapFile); io_close(MapFile);
// free data // free data
free(pMapData); free(pMapData);
return true;
} }
int CDemoPlayer::NextFrame() int CDemoPlayer::NextFrame()
@ -1013,10 +1018,24 @@ bool CDemoPlayer::GetDemoInfo(class IStorage *pStorage, const char *pFilename, i
str_copy(pMapInfo->m_aName, pDemoHeader->m_aMapName, sizeof(pMapInfo->m_aName)); str_copy(pMapInfo->m_aName, pDemoHeader->m_aMapName, sizeof(pMapInfo->m_aName));
pMapInfo->m_Crc = (pDemoHeader->m_aMapCrc[0]<<24) | (pDemoHeader->m_aMapCrc[1]<<16) | (pDemoHeader->m_aMapCrc[2]<<8) | (pDemoHeader->m_aMapCrc[3]); pMapInfo->m_Crc = (pDemoHeader->m_aMapCrc[0]<<24) | (pDemoHeader->m_aMapCrc[1]<<16) | (pDemoHeader->m_aMapCrc[2]<<8) | (pDemoHeader->m_aMapCrc[3]);
SHA256_DIGEST Sha256 = SHA256_ZEROED;
if(pDemoHeader->m_Version >= gs_Sha256Version) if(pDemoHeader->m_Version >= gs_Sha256Version)
io_read(File, &pMapInfo->m_Sha256, SHA256_DIGEST_LENGTH); {
CUuid ExtensionUuid = {};
io_read(File, &ExtensionUuid.m_aData, sizeof(ExtensionUuid.m_aData));
if(ExtensionUuid == SHA256_EXTENSION)
{
io_read(File, &Sha256, sizeof(SHA256_DIGEST)); // need a safe read
}
else else
pMapInfo->m_Sha256 = SHA256_ZEROED; {
// This hopes whatever happened during the version increment didn't add something here
dbg_msg("demo", "demo version incremented, but not by ddnet");
io_seek(File, -(int)sizeof(ExtensionUuid.m_aData), IOSEEK_CUR);
}
}
pMapInfo->m_Sha256 = Sha256;
pMapInfo->m_Size = (pDemoHeader->m_aMapSize[0]<<24) | (pDemoHeader->m_aMapSize[1]<<16) | (pDemoHeader->m_aMapSize[2]<<8) | (pDemoHeader->m_aMapSize[3]); pMapInfo->m_Size = (pDemoHeader->m_aMapSize[0]<<24) | (pDemoHeader->m_aMapSize[1]<<16) | (pDemoHeader->m_aMapSize[2]<<8) | (pDemoHeader->m_aMapSize[3]);
@ -1057,17 +1076,20 @@ void CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int
return; return;
const CMapInfo *pMapInfo = m_pDemoPlayer->GetMapInfo(); const CMapInfo *pMapInfo = m_pDemoPlayer->GetMapInfo();
SHA256_DIGEST Fake; const CDemoPlayer::CPlaybackInfo *pInfo = m_pDemoPlayer->Info();
for(unsigned i = 0; i < sizeof(Fake.data); i++)
SHA256_DIGEST Sha256 = pMapInfo->m_Sha256;
if(pInfo->m_Header.m_Version < gs_Sha256Version)
{ {
Fake.data[i] = 0xff; if(m_pDemoPlayer->ExtractMap(m_pStorage))
Sha256 = pMapInfo->m_Sha256;
} }
if (m_pDemoRecorder->Start(m_pStorage, m_pConsole, pDst, m_pNetVersion, pMapInfo->m_aName, Fake, pMapInfo->m_Crc, "client", pMapInfo->m_Size, NULL, NULL, pfnFilter, pUser) == -1)
if (m_pDemoRecorder->Start(m_pStorage, m_pConsole, pDst, m_pNetVersion, pMapInfo->m_aName, Sha256, pMapInfo->m_Crc, "client", pMapInfo->m_Size, NULL, NULL, pfnFilter, pUser) == -1)
return; return;
m_pDemoPlayer->Play(); m_pDemoPlayer->Play();
const CDemoPlayer::CPlaybackInfo *pInfo = m_pDemoPlayer->Info();
while (m_pDemoPlayer->IsPlaying() && !m_Stop) { while (m_pDemoPlayer->IsPlaying() && !m_Stop) {
m_pDemoPlayer->Update(false); m_pDemoPlayer->Update(false);

View file

@ -121,7 +121,7 @@ public:
void SetListener(IListener *pListener); void SetListener(IListener *pListener);
int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType); int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType);
void ExtractMap(class IStorage *pStorage); bool ExtractMap(class IStorage *pStorage);
int Play(); int Play();
void Pause(); void Pause();
void Unpause(); void Unpause();