Browse Source

saveload fix

ToGLES3
nillerusr 3 years ago
parent
commit
1f3436945f
  1. 16
      engine/host_saverestore.cpp
  2. 14
      game/shared/saverestore.cpp
  3. 6
      public/datamap.h

16
engine/host_saverestore.cpp

@ -2128,7 +2128,7 @@ int CSaveRestore::SaveReadNameAndComment( FileHandle_t f, OUT_Z_CAP(nameSize) ch
int nNumberOfFields; int nNumberOfFields;
char *pData; char *pData;
int nFieldSize; short nFieldSize;
pData = pSaveData; pData = pSaveData;
@ -2148,9 +2148,12 @@ int CSaveRestore::SaveReadNameAndComment( FileHandle_t f, OUT_Z_CAP(nameSize) ch
pTokenList = NULL; pTokenList = NULL;
// short, short (size, index of field name) // short, short (size, index of field name)
nFieldSize = *(short *)pData;
Q_memcpy( &nFieldSize, pData, sizeof(short) );
pData += sizeof(short); pData += sizeof(short);
pFieldName = pTokenList[ *(short *)pData ]; short index = 0;
Q_memcpy( &index, pData, sizeof(short) );
pFieldName = pTokenList[index];
if ( !pFieldName || Q_stricmp( pFieldName, "GameHeader" ) ) if ( !pFieldName || Q_stricmp( pFieldName, "GameHeader" ) )
{ {
@ -2161,7 +2164,7 @@ int CSaveRestore::SaveReadNameAndComment( FileHandle_t f, OUT_Z_CAP(nameSize) ch
// int (fieldcount) // int (fieldcount)
pData += sizeof(short); pData += sizeof(short);
nNumberOfFields = *(int*)pData; Q_memcpy( &nNumberOfFields, pData, sizeof(int) );
pData += nFieldSize; pData += nFieldSize;
// Each field is a short (size), short (index of name), binary string of "size" bytes (data) // Each field is a short (size), short (index of name), binary string of "size" bytes (data)
@ -2172,10 +2175,11 @@ int CSaveRestore::SaveReadNameAndComment( FileHandle_t f, OUT_Z_CAP(nameSize) ch
// szName // szName
// Actual Data // Actual Data
nFieldSize = *(short *)pData; Q_memcpy( &nFieldSize, pData, sizeof(short) );
pData += sizeof(short); pData += sizeof(short);
pFieldName = pTokenList[ *(short *)pData ]; Q_memcpy( &index, pData, sizeof(short) );
pFieldName = pTokenList[index];
pData += sizeof(short); pData += sizeof(short);
if ( !Q_stricmp( pFieldName, "comment" ) ) if ( !Q_stricmp( pFieldName, "comment" ) )

14
game/shared/saverestore.cpp

@ -152,7 +152,7 @@ const char *UTIL_FunctionToName( datamap_t *pMap, inputfunc_t *function )
// This is used to save/restore function pointers (convert text back to pointer) // This is used to save/restore function pointers (convert text back to pointer)
// Input : *pName - name of the member function // Input : *pName - name of the member function
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inputfunc_t *UTIL_FunctionFromName( datamap_t *pMap, const char *pName ) inputfunc_t UTIL_FunctionFromName( datamap_t *pMap, const char *pName )
{ {
while ( pMap ) while ( pMap )
{ {
@ -170,7 +170,7 @@ inputfunc_t *UTIL_FunctionFromName( datamap_t *pMap, const char *pName )
{ {
if ( FStrEq( pName, pMap->dataDesc[i].fieldName ) ) if ( FStrEq( pName, pMap->dataDesc[i].fieldName ) )
{ {
return EXTRACT_INPUTFUNC_FUNCTIONPTR(pMap->dataDesc[i].inputFunc); return pMap->dataDesc[i].inputFunc;
} }
} }
} }
@ -2240,8 +2240,14 @@ int CRestore::ReadFunction( datamap_t *pMap, inputfunc_t **pValue, int count, in
if ( *pszFunctionName == 0 ) if ( *pszFunctionName == 0 )
*pValue = NULL; *pValue = NULL;
else else
*pValue = UTIL_FunctionFromName( pMap, pszFunctionName ); {
inputfunc_t func = UTIL_FunctionFromName( pMap, pszFunctionName );
#ifdef GNUC
Q_memcpy( (void*)pValue, &func, sizeof(void*)*2 );
#else
Q_memcpy( (void*)pValue, &func, sizeof(void*) );
#endif
}
return 0; return 0;
} }

6
public/datamap.h

@ -113,9 +113,9 @@ DECLARE_FIELD_SIZE( FIELD_SOUNDNAME, sizeof(int))
DECLARE_FIELD_SIZE( FIELD_INPUT, sizeof(int)) DECLARE_FIELD_SIZE( FIELD_INPUT, sizeof(int))
#ifdef POSIX #ifdef POSIX
// pointer to members under gnuc are 8bytes if you have a virtual func // pointer to members under gnuc are 8bytes if you have a virtual func
DECLARE_FIELD_SIZE( FIELD_FUNCTION, sizeof(uint64)) DECLARE_FIELD_SIZE( FIELD_FUNCTION, 2 * sizeof(void *))
#else #else
DECLARE_FIELD_SIZE( FIELD_FUNCTION, sizeof(int *)) DECLARE_FIELD_SIZE( FIELD_FUNCTION, sizeof(void *))
#endif #endif
DECLARE_FIELD_SIZE( FIELD_VMATRIX, 16 * sizeof(float)) DECLARE_FIELD_SIZE( FIELD_VMATRIX, 16 * sizeof(float))
DECLARE_FIELD_SIZE( FIELD_VMATRIX_WORLDSPACE, 16 * sizeof(float)) DECLARE_FIELD_SIZE( FIELD_VMATRIX_WORLDSPACE, 16 * sizeof(float))
@ -202,7 +202,7 @@ extern ISaveRestoreOps *eventFuncs;
#define DEFINE_OUTPUT( name, outputname ) { FIELD_CUSTOM, #name, { _offsetof(classNameTypedef, name), 0 }, 1, FTYPEDESC_OUTPUT | FTYPEDESC_SAVE | FTYPEDESC_KEY, outputname, eventFuncs } #define DEFINE_OUTPUT( name, outputname ) { FIELD_CUSTOM, #name, { _offsetof(classNameTypedef, name), 0 }, 1, FTYPEDESC_OUTPUT | FTYPEDESC_SAVE | FTYPEDESC_KEY, outputname, eventFuncs }
// replaces EXPORT table for portability and non-DLL based systems (xbox) // replaces EXPORT table for portability and non-DLL based systems (xbox)
#define DEFINE_FUNCTION_RAW( function, func_type ) { FIELD_VOID, nameHolder.GenerateName(#function), { NULL, NULL }, 1, FTYPEDESC_FUNCTIONTABLE, NULL, NULL, (inputfunc_t)((func_type)(&classNameTypedef::function)) } #define DEFINE_FUNCTION_RAW( function, func_type ) { FIELD_VOID, nameHolder.GenerateName(#function), { NULL, NULL }, 1, FTYPEDESC_FUNCTIONTABLE, NULL, NULL, (inputfunc_t)(&classNameTypedef::function) }
#define DEFINE_FUNCTION( function ) DEFINE_FUNCTION_RAW( function, inputfunc_t ) #define DEFINE_FUNCTION( function ) DEFINE_FUNCTION_RAW( function, inputfunc_t )

Loading…
Cancel
Save