Fix small bug with demos that don't include a map

This commit is contained in:
Learath 2019-12-18 13:51:08 +01:00
parent 71857fdb80
commit 65ec25a8a1
3 changed files with 12 additions and 5 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()

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();