Skip to content

Commit

Permalink
server: nodes: added check for platform hash in .nod cache files
Browse files Browse the repository at this point in the history
  • Loading branch information
SNMetamorph committed Mar 10, 2024
1 parent 9156c98 commit 15f3571
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
35 changes: 32 additions & 3 deletions server/nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#include "extdll.h"
#include "util.h"
#include "cbase.h"
#include "virtualfs.h"
#include "virtualfs.h"
#include "monsters.h"
#include "nodes.h"
#include "animation.h"
#include "func_door.h"
#include "crclib.h"
#include "build_info.h"

#define HULL_STEP_SIZE 16// how far the test hull moves on each step
#define NODE_HEIGHT 8 // how high to lift nodes off the ground after we drop them all (make stair/ramp mapping easier)
Expand Down Expand Up @@ -463,6 +465,15 @@ int CGraph::NodeType( const CBaseEntity *pEntity )
return bits_NODE_LAND;
}

uint32_t CGraph::GetPlatformHash()
{
uint32_t hash;
CRC32_Init(&hash);
CRC32_ProcessBuffer(&hash, BuildInfo::GetArchitecture(), strlen(BuildInfo::GetArchitecture()));
CRC32_ProcessBuffer(&hash, BuildInfo::GetPlatform(), strlen(BuildInfo::GetPlatform()));
hash = CRC32_Final(hash);
return hash;
}

// Sum up graph weights on the path from iStart to iDest to determine path length
float CGraph::PathLength( int iStart, int iDest, int iHull, int afCapMask )
Expand Down Expand Up @@ -2317,11 +2328,26 @@ int CGraph :: FLoadGraph ( char *szMapName )
memcpy(&iVersion, pMemFile, sizeof(int));
pMemFile += sizeof(int);

if ( iVersion != GRAPH_VERSION )
// Read the platform hash
//
length -= sizeof(uint32_t);
if (length < 0) goto ShortFile;
uint32_t platformHash = *(reinterpret_cast<uint32_t*>(pMemFile));
pMemFile += sizeof(uint32_t);

if (iVersion != GRAPH_VERSION)
{
// This file was written by a different build of the dll!
//
ALERT(at_aiconsole, "**ERROR** Graph version is %d, expected %d\n", iVersion, GRAPH_VERSION);
goto ShortFile;
}

if (platformHash != GetPlatformHash())
{
// This file was written by a different build of the dll!
//
ALERT ( at_aiconsole, "**ERROR** Graph version is %d, expected %d\n",iVersion, GRAPH_VERSION );
ALERT(at_aiconsole, "**ERROR** Graph platform hash mismatch\n");
goto ShortFile;
}

Expand Down Expand Up @@ -2478,6 +2504,9 @@ int CGraph :: FSaveGraph ( char *szMapName )
// write the version
file.Write( &iVersion, sizeof( int ));

// write platform hash
file.Write( GetPlatformHash() );

// write the CGraph class
file.Write( this, sizeof( CGraph ));

Expand Down
3 changes: 2 additions & 1 deletion server/nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ typedef struct
//=========================================================
// CGraph
//=========================================================
#define GRAPH_VERSION (int)16// !!!increment this whever graph/node/link classes change, to obsolesce older disk files.
#define GRAPH_VERSION (int)17// !!!increment this whever graph/node/link classes change, to obsolesce older disk files.
class CGraph
{
public:
Expand Down Expand Up @@ -207,6 +207,7 @@ class CGraph
return 0;
}

static uint32_t GetPlatformHash();

inline CNode &Node( int i )
{
Expand Down

0 comments on commit 15f3571

Please sign in to comment.