4330: Try crc for maps if sha256 isn't available (fixes #4327) r=heinrich5991 a=def-

Happens with demos cut from KoG

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
bors[bot] 2021-11-15 19:22:46 +00:00 committed by GitHub
commit 0e64a6ccc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -841,10 +841,10 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
return 0; return 0;
} }
bool CDemoPlayer::ExtractMap(class IStorage *pStorage) unsigned char *CDemoPlayer::GetMapData(class IStorage *pStorage)
{ {
if(!m_MapInfo.m_Size) if(!m_MapInfo.m_Size)
return false; return 0;
long CurSeek = io_tell(m_File); long CurSeek = io_tell(m_File);
@ -853,6 +853,14 @@ bool CDemoPlayer::ExtractMap(class IStorage *pStorage)
unsigned char *pMapData = (unsigned char *)malloc(m_MapInfo.m_Size); unsigned char *pMapData = (unsigned char *)malloc(m_MapInfo.m_Size);
io_read(m_File, pMapData, m_MapInfo.m_Size); io_read(m_File, pMapData, m_MapInfo.m_Size);
io_seek(m_File, CurSeek, IOSEEK_START); io_seek(m_File, CurSeek, IOSEEK_START);
return pMapData;
}
bool CDemoPlayer::ExtractMap(class IStorage *pStorage)
{
unsigned char *pMapData = GetMapData(pStorage);
if(!pMapData)
return false;
// handle sha256 // handle sha256
SHA256_DIGEST Sha256 = SHA256_ZEROED; SHA256_DIGEST Sha256 = SHA256_ZEROED;
@ -1170,7 +1178,11 @@ void CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int
Sha256 = pMapInfo->m_Sha256; Sha256 = pMapInfo->m_Sha256;
} }
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) unsigned char *pMapData = m_pDemoPlayer->GetMapData(m_pStorage);
const int Result = m_pDemoRecorder->Start(m_pStorage, m_pConsole, pDst, m_pNetVersion, pMapInfo->m_aName, &Sha256, pMapInfo->m_Crc, "client", pMapInfo->m_Size, pMapData, NULL, pfnFilter, pUser) == -1;
if(pMapData)
free(pMapData);
if(Result != 0)
return; return;
m_pDemoPlayer->Play(); m_pDemoPlayer->Play();

View file

@ -133,6 +133,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);
unsigned char *GetMapData(class IStorage *pStorage);
bool ExtractMap(class IStorage *pStorage); bool ExtractMap(class IStorage *pStorage);
int Play(); int Play();
void Pause(); void Pause();