mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Add SHA to demos. Bump Demo Version
This commit is contained in:
parent
b2cefb20ed
commit
7cdd050fee
|
@ -3421,10 +3421,12 @@ const char *CClient::DemoPlayer_Play(const char *pFilename, int StorageType)
|
|||
|
||||
// load map
|
||||
Crc = m_DemoPlayer.GetMapInfo()->m_Crc;
|
||||
pError = LoadMapSearch(m_DemoPlayer.Info()->m_Header.m_aMapName, 0, Crc);
|
||||
SHA256_DIGEST Sha = m_DemoPlayer.GetMapInfo()->m_Sha256;
|
||||
pError = LoadMapSearch(m_DemoPlayer.Info()->m_Header.m_aMapName, &Sha, Crc);
|
||||
if(pError)
|
||||
{
|
||||
SHA256_DIGEST Sha = m_DemoPlayer.ExtractMap(Storage());
|
||||
m_DemoPlayer.ExtractMap(Storage());
|
||||
Sha = m_DemoPlayer.GetMapInfo()->m_Sha256;
|
||||
pError = LoadMapSearch(m_DemoPlayer.Info()->m_Header.m_aMapName, &Sha, Crc);
|
||||
if(pError)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#ifndef ENGINE_DEMO_H
|
||||
#define ENGINE_DEMO_H
|
||||
|
||||
#include <base/hash.h>
|
||||
#include "kernel.h"
|
||||
|
||||
enum
|
||||
|
@ -33,6 +34,14 @@ struct CTimelineMarkers
|
|||
char m_aTimelineMarkers[MAX_TIMELINE_MARKERS][4];
|
||||
};
|
||||
|
||||
struct CMapInfo
|
||||
{
|
||||
char m_aName[128];
|
||||
SHA256_DIGEST m_Sha256;
|
||||
int m_Crc;
|
||||
int m_Size;
|
||||
};
|
||||
|
||||
class IDemoPlayer : public IInterface
|
||||
{
|
||||
MACRO_INTERFACE("demoplayer", 0)
|
||||
|
@ -69,7 +78,7 @@ public:
|
|||
virtual bool IsPlaying() const = 0;
|
||||
virtual const CInfo *BaseInfo() const = 0;
|
||||
virtual void GetDemoName(char *pBuffer, int BufferSize) const = 0;
|
||||
virtual bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers) const = 0;
|
||||
virtual bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers, CMapInfo *pMapInfo) const = 0;
|
||||
virtual int GetDemoType() const = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -15,8 +15,9 @@
|
|||
#include "snapshot.h"
|
||||
|
||||
static const unsigned char gs_aHeaderMarker[7] = {'T', 'W', 'D', 'E', 'M', 'O', 0};
|
||||
static const unsigned char gs_ActVersion = 5;
|
||||
static const unsigned char gs_ActVersion = 6;
|
||||
static const unsigned char gs_OldVersion = 3;
|
||||
static const unsigned char gs_SHAVersion = 6;
|
||||
static const unsigned char gs_VersionTickCompression = 5; // demo files with this version or higher will use `CHUNKTICKFLAG_TICK_COMPRESSED`
|
||||
static const int gs_LengthOffset = 152;
|
||||
static const int gs_NumMarkersOffset = 176;
|
||||
|
@ -120,6 +121,7 @@ int CDemoRecorder::Start(class IStorage *pStorage, class IConsole *pConsole, con
|
|||
str_timestamp(Header.m_aTimestamp, sizeof(Header.m_aTimestamp));
|
||||
io_write(DemoFile, &Header, sizeof(Header));
|
||||
io_write(DemoFile, &TimelineMarkers, sizeof(TimelineMarkers)); // fill this on stop
|
||||
io_write(DemoFile, &Sha256, sizeof(SHA256_DIGEST));
|
||||
|
||||
if(m_NoMapData)
|
||||
{
|
||||
|
@ -717,6 +719,10 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
|||
else if(m_Info.m_Header.m_Version > gs_OldVersion)
|
||||
io_read(m_File, &m_Info.m_TimelineMarkers, sizeof(m_Info.m_TimelineMarkers));
|
||||
|
||||
SHA256_DIGEST Sha = {};
|
||||
if(m_Info.m_Header.m_Version >= gs_SHAVersion)
|
||||
io_read(m_File, &Sha, sizeof(SHA256_DIGEST)); // need a safe read
|
||||
|
||||
// get demo type
|
||||
if(!str_comp(m_Info.m_Header.m_aType, "client"))
|
||||
m_DemoType = DEMOTYPE_CLIENT;
|
||||
|
@ -738,10 +744,10 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
|||
|
||||
// store map information
|
||||
m_MapInfo.m_Crc = Crc;
|
||||
m_MapInfo.m_Sha256 = Sha;
|
||||
m_MapInfo.m_Size = MapSize;
|
||||
str_copy(m_MapInfo.m_aName, m_Info.m_Header.m_aMapName, sizeof(m_MapInfo.m_aName));
|
||||
|
||||
|
||||
if(m_Info.m_Header.m_Version > gs_OldVersion)
|
||||
{
|
||||
// get timeline markers
|
||||
|
@ -767,10 +773,10 @@ int CDemoPlayer::Load(class IStorage *pStorage, class IConsole *pConsole, const
|
|||
return 0;
|
||||
}
|
||||
|
||||
SHA256_DIGEST CDemoPlayer::ExtractMap(class IStorage *pStorage)
|
||||
void CDemoPlayer::ExtractMap(class IStorage *pStorage)
|
||||
{
|
||||
if(!m_MapInfo.m_Size)
|
||||
return {};
|
||||
return;
|
||||
|
||||
long CurSeek = io_tell(m_File);
|
||||
|
||||
|
@ -780,8 +786,17 @@ SHA256_DIGEST CDemoPlayer::ExtractMap(class IStorage *pStorage)
|
|||
io_read(m_File, pMapData, m_MapInfo.m_Size);
|
||||
io_seek(m_File, CurSeek, IOSEEK_START);
|
||||
|
||||
// calculate sha, should probably add to demo header
|
||||
SHA256_DIGEST Sha = sha256(pMapData, m_MapInfo.m_Size);
|
||||
// handle sha256
|
||||
SHA256_DIGEST Sha = {};
|
||||
if(m_Info.m_Header.m_Version >= gs_SHAVersion)
|
||||
Sha = m_MapInfo.m_Sha256;
|
||||
else
|
||||
{
|
||||
Sha = sha256(pMapData, m_MapInfo.m_Size);
|
||||
m_MapInfo.m_Sha256 = Sha;
|
||||
}
|
||||
|
||||
// construct name
|
||||
char aSha[SHA256_MAXSTRSIZE], aMapFilename[128];
|
||||
sha256_str(Sha, aSha, sizeof(aSha));
|
||||
str_format(aMapFilename, sizeof(aMapFilename), "downloadedmaps/%s_%08x_%s.map", m_Info.m_Header.m_aMapName, m_MapInfo.m_Crc, aSha);
|
||||
|
@ -793,8 +808,6 @@ SHA256_DIGEST CDemoPlayer::ExtractMap(class IStorage *pStorage)
|
|||
|
||||
// free data
|
||||
free(pMapData);
|
||||
|
||||
return Sha;
|
||||
}
|
||||
|
||||
int CDemoPlayer::NextFrame()
|
||||
|
@ -964,9 +977,9 @@ void CDemoPlayer::GetDemoName(char *pBuffer, int BufferSize) const
|
|||
str_copy(pBuffer, pExtractedName, Length);
|
||||
}
|
||||
|
||||
bool CDemoPlayer::GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers) const
|
||||
bool CDemoPlayer::GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers, CMapInfo *pMapInfo) const
|
||||
{
|
||||
if(!pDemoHeader || !pTimelineMarkers)
|
||||
if(!pDemoHeader || !pTimelineMarkers || !pMapInfo)
|
||||
return false;
|
||||
|
||||
mem_zero(pDemoHeader, sizeof(CDemoHeader));
|
||||
|
@ -978,6 +991,17 @@ bool CDemoPlayer::GetDemoInfo(class IStorage *pStorage, const char *pFilename, i
|
|||
|
||||
io_read(File, pDemoHeader, sizeof(CDemoHeader));
|
||||
io_read(File, pTimelineMarkers, sizeof(CTimelineMarkers));
|
||||
|
||||
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]);
|
||||
|
||||
if(pDemoHeader->m_Version >= gs_SHAVersion)
|
||||
io_read(File, &pMapInfo->m_Sha256, SHA256_DIGEST_LENGTH);
|
||||
else
|
||||
pMapInfo->m_Sha256 = {};
|
||||
|
||||
pMapInfo->m_Size = (pDemoHeader->m_aMapSize[0]<<24) | (pDemoHeader->m_aMapSize[1]<<16) | (pDemoHeader->m_aMapSize[2]<<8) | (pDemoHeader->m_aMapSize[3]);
|
||||
|
||||
io_close(File);
|
||||
return !(mem_comp(pDemoHeader->m_aMarker, gs_aHeaderMarker, sizeof(gs_aHeaderMarker)) || pDemoHeader->m_Version < gs_OldVersion);
|
||||
}
|
||||
|
@ -1014,7 +1038,7 @@ void CDemoEditor::Slice(const char *pDemo, const char *pDst, int StartTick, int
|
|||
if (m_pDemoPlayer->Load(m_pStorage, m_pConsole, pDemo, IStorage::TYPE_ALL) == -1)
|
||||
return;
|
||||
|
||||
const CDemoPlayer::CMapInfo *pMapInfo = m_pDemoPlayer->GetMapInfo();
|
||||
const CMapInfo *pMapInfo = m_pDemoPlayer->GetMapInfo();
|
||||
SHA256_DIGEST Fake;
|
||||
for(unsigned i = 0; i < sizeof(Fake.data); i++)
|
||||
{
|
||||
|
|
|
@ -78,14 +78,6 @@ public:
|
|||
float m_TickTime;
|
||||
};
|
||||
|
||||
struct CMapInfo
|
||||
{
|
||||
char m_aName[128];
|
||||
SHA256_DIGEST m_Sha256;
|
||||
int m_Crc;
|
||||
int m_Size;
|
||||
};
|
||||
|
||||
private:
|
||||
IListener *m_pListener;
|
||||
|
||||
|
@ -129,7 +121,7 @@ public:
|
|||
void SetListener(IListener *pListener);
|
||||
|
||||
int Load(class IStorage *pStorage, class IConsole *pConsole, const char *pFilename, int StorageType);
|
||||
SHA256_DIGEST ExtractMap(class IStorage *pStorage);
|
||||
void ExtractMap(class IStorage *pStorage);
|
||||
int Play();
|
||||
void Pause();
|
||||
void Unpause();
|
||||
|
@ -141,7 +133,7 @@ public:
|
|||
int SetPos(int WantedTick);
|
||||
const CInfo *BaseInfo() const { return &m_Info.m_Info; }
|
||||
void GetDemoName(char *pBuffer, int BufferSize) const;
|
||||
bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers) const;
|
||||
bool GetDemoInfo(class IStorage *pStorage, const char *pFilename, int StorageType, CDemoHeader *pDemoHeader, CTimelineMarkers *pTimelineMarkers, CMapInfo *pMapInfo) const;
|
||||
const char *GetDemoFileName() { return m_aFilename; };
|
||||
int GetDemoType() const;
|
||||
|
||||
|
|
|
@ -174,6 +174,7 @@ class CMenus : public CComponent
|
|||
bool m_Valid;
|
||||
CDemoHeader m_Info;
|
||||
CTimelineMarkers m_TimelineMarkers;
|
||||
CMapInfo m_MapInfo;
|
||||
|
||||
int NumMarkers() const
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <base/tl/string.h>
|
||||
|
||||
#include <base/math.h>
|
||||
#include <base/hash.h>
|
||||
|
||||
#include <engine/demo.h>
|
||||
#include <engine/keys.h>
|
||||
|
@ -805,7 +806,7 @@ bool CMenus::FetchHeader(CDemoItem &Item)
|
|||
{
|
||||
char aBuffer[512];
|
||||
str_format(aBuffer, sizeof(aBuffer), "%s/%s", m_aCurrentDemoFolder, Item.m_aFilename);
|
||||
Item.m_Valid = DemoPlayer()->GetDemoInfo(Storage(), aBuffer, Item.m_StorageType, &Item.m_Info, &Item.m_TimelineMarkers);
|
||||
Item.m_Valid = DemoPlayer()->GetDemoInfo(Storage(), aBuffer, Item.m_StorageType, &Item.m_Info, &Item.m_TimelineMarkers, &Item.m_MapInfo);
|
||||
Item.m_InfosLoaded = true;
|
||||
}
|
||||
return Item.m_Valid;
|
||||
|
@ -930,13 +931,18 @@ void CMenus::RenderDemoList(CUIRect MainView)
|
|||
Labels.HSplitTop(20.0f, &Left, &Labels);
|
||||
Left.VSplitLeft(150.0f, &Left, &Right);
|
||||
UI()->DoLabelScaled(&Left, Localize("Crc:"), 14.0f, -1);
|
||||
unsigned Crc = (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[0]<<24) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[1]<<16) |
|
||||
(m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[2]<<8) | (m_lDemos[m_DemolistSelectedIndex].m_Info.m_aMapCrc[3]);
|
||||
str_format(aBuf, sizeof(aBuf), "%08x", Crc);
|
||||
str_format(aBuf, sizeof(aBuf), "%08x", m_lDemos[m_DemolistSelectedIndex].m_MapInfo.m_Crc);
|
||||
UI()->DoLabelScaled(&Right, aBuf, 14.0f, -1);
|
||||
Labels.HSplitTop(5.0f, 0, &Labels);
|
||||
Labels.HSplitTop(20.0f, &Left, &Labels);
|
||||
Left.VSplitLeft(150.0f, &Left, &Right);
|
||||
UI()->DoLabelScaled(&Left, Localize("SHA256:"), 14.0f, -1);
|
||||
char aSha[SHA256_MAXSTRSIZE];
|
||||
sha256_str(m_lDemos[m_DemolistSelectedIndex].m_MapInfo.m_Sha256, aSha, sizeof(aSha)/2);
|
||||
UI()->DoLabelScaled(&Right, aSha, 14.0f, -1);
|
||||
Labels.HSplitTop(5.0f, 0, &Labels);
|
||||
Labels.HSplitTop(20.0f, &Left, &Labels);
|
||||
Left.VSplitLeft(150.0f, &Left, &Right);
|
||||
UI()->DoLabelScaled(&Left, Localize("Netversion:"), 14.0f, -1);
|
||||
UI()->DoLabelScaled(&Right, m_lDemos[m_DemolistSelectedIndex].m_Info.m_aNetversion, 14.0f, -1);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue