mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
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:
commit
811ddb3283
|
@ -3420,10 +3420,12 @@ const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
|
|||
// load map
|
||||
Crc = m_DemoPlayer.GetMapInfo()->m_Crc;
|
||||
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)
|
||||
{
|
||||
m_DemoPlayer.ExtractMap(Storage());
|
||||
if(!m_DemoPlayer.ExtractMap(Storage()))
|
||||
return pError;
|
||||
|
||||
Sha = m_DemoPlayer.GetMapInfo()->m_Sha256;
|
||||
pError = LoadMapSearch(m_DemoPlayer.Info()->m_Header.m_aMapName, &Sha, Crc);
|
||||
if(pError)
|
||||
|
|
|
@ -791,10 +791,10 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
|||
return 0;
|
||||
}
|
||||
|
||||
void CDemoPlayer::ExtractMap(class IStorage *pStorage)
|
||||
bool CDemoPlayer::ExtractMap(class IStorage *pStorage)
|
||||
{
|
||||
if(!m_MapInfo.m_Size)
|
||||
return;
|
||||
return false;
|
||||
|
||||
long CurSeek = io_tell(m_File);
|
||||
|
||||
|
@ -821,11 +821,16 @@ void CDemoPlayer::ExtractMap(class IStorage *pStorage)
|
|||
|
||||
// save map
|
||||
IOHANDLE MapFile = pStorage->OpenFile(aMapFilename, IOFLAG_WRITE, IStorage::TYPE_SAVE);
|
||||
if(!MapFile)
|
||||
return false;
|
||||
|
||||
io_write(MapFile, pMapData, m_MapInfo.m_Size);
|
||||
io_close(MapFile);
|
||||
|
||||
// free data
|
||||
free(pMapData);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
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));
|
||||
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)
|
||||
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
|
||||
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]);
|
||||
|
||||
|
@ -1057,17 +1076,20 @@ void CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int
|
|||
return;
|
||||
|
||||
const CMapInfo *pMapInfo = m_pDemoPlayer->GetMapInfo();
|
||||
SHA256_DIGEST Fake;
|
||||
for(unsigned i = 0; i < sizeof(Fake.data); i++)
|
||||
const CDemoPlayer::CPlaybackInfo *pInfo = m_pDemoPlayer->Info();
|
||||
|
||||
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;
|
||||
|
||||
|
||||
m_pDemoPlayer->Play();
|
||||
const CDemoPlayer::CPlaybackInfo *pInfo = m_pDemoPlayer->Info();
|
||||
|
||||
while (m_pDemoPlayer->IsPlaying() && !m_Stop) {
|
||||
m_pDemoPlayer->Update(false);
|
||||
|
|
|
@ -121,7 +121,7 @@ public:
|
|||
void SetListener(IListener *pListener);
|
||||
|
||||
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();
|
||||
void Pause();
|
||||
void Unpause();
|
||||
|
|
Loading…
Reference in a new issue