saveload fix

This commit is contained in:
nillerusr 2022-01-09 19:59:13 +03:00
parent 1d8149a3b3
commit 1f3436945f
3 changed files with 25 additions and 15 deletions

View File

@ -2128,7 +2128,7 @@ int CSaveRestore::SaveReadNameAndComment( FileHandle_t f, OUT_Z_CAP(nameSize) ch
int nNumberOfFields;
char *pData;
int nFieldSize;
short nFieldSize;
pData = pSaveData;
@ -2148,9 +2148,12 @@ int CSaveRestore::SaveReadNameAndComment( FileHandle_t f, OUT_Z_CAP(nameSize) ch
pTokenList = NULL;
// short, short (size, index of field name)
nFieldSize = *(short *)pData;
Q_memcpy( &nFieldSize, 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" ) )
{
@ -2161,7 +2164,7 @@ int CSaveRestore::SaveReadNameAndComment( FileHandle_t f, OUT_Z_CAP(nameSize) ch
// int (fieldcount)
pData += sizeof(short);
nNumberOfFields = *(int*)pData;
Q_memcpy( &nNumberOfFields, pData, sizeof(int) );
pData += nFieldSize;
// 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
// Actual Data
nFieldSize = *(short *)pData;
Q_memcpy( &nFieldSize, pData, sizeof(short) );
pData += sizeof(short);
pFieldName = pTokenList[ *(short *)pData ];
Q_memcpy( &index, pData, sizeof(short) );
pFieldName = pTokenList[index];
pData += sizeof(short);
if ( !Q_stricmp( pFieldName, "comment" ) )

View File

@ -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)
// 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 )
{
@ -170,7 +170,7 @@ inputfunc_t *UTIL_FunctionFromName( datamap_t *pMap, const char *pName )
{
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 )
*pValue = NULL;
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;
}

View File

@ -113,9 +113,9 @@ DECLARE_FIELD_SIZE( FIELD_SOUNDNAME, sizeof(int))
DECLARE_FIELD_SIZE( FIELD_INPUT, sizeof(int))
#ifdef POSIX
// 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
DECLARE_FIELD_SIZE( FIELD_FUNCTION, sizeof(int *))
DECLARE_FIELD_SIZE( FIELD_FUNCTION, sizeof(void *))
#endif
DECLARE_FIELD_SIZE( FIELD_VMATRIX, 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 }
// 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 )