diff --git a/engine/host_saverestore.cpp b/engine/host_saverestore.cpp index 74b66192..3ae1feaa 100644 --- a/engine/host_saverestore.cpp +++ b/engine/host_saverestore.cpp @@ -2128,8 +2128,8 @@ int CSaveRestore::SaveReadNameAndComment( FileHandle_t f, OUT_Z_CAP(nameSize) ch int nNumberOfFields; char *pData; - int nFieldSize; - + short nFieldSize; + pData = pSaveData; // Allocate a table for the strings, and parse the table @@ -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" ) ) diff --git a/game/shared/saverestore.cpp b/game/shared/saverestore.cpp index cc8abfcf..36025baf 100644 --- a/game/shared/saverestore.cpp +++ b/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) // 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; } diff --git a/public/datamap.h b/public/datamap.h index 936f4436..c9d340b4 100644 --- a/public/datamap.h +++ b/public/datamap.h @@ -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 ) @@ -278,7 +278,7 @@ struct typedescription_t // Used to track exclusion of baseclass fields int override_count; - + // Tolerance for field errors for float fields float fieldTolerance; };