In case it helps I'm appending my Callback functionality, the reason it's so hairy is due to changes since the corruption started happening, I've been trying my hardest to avoid any situation where a ConVar may be created in my callback but to no avail...
PHP Code:
char sTmp[100];
char sNewVarName[100];
char sPrefix[8];
// Create string name of the alternate cvar.
if ( lZombieVar == CVAR_ORIGINAL )
{
Q_strncpy( sPrefix, "zm_", sizeof( sPrefix ) );
Q_StrRight( sName, Q_strlen( sName ) - 7, sTmp, 100 );
}
else // CVAR_SHORT
{
Q_strncpy( sPrefix, "zombie_", sizeof( sPrefix ) );
Q_StrRight( sName, Q_strlen( sName ) - 3, sTmp, 100 );
}
Q_snprintf( sNewVarName, sizeof( sNewVarName ), "%s%s", sPrefix, sTmp );
// Get reference to ConVars.
ConVarRef cRef = ConVarRef( sName );
ConVarRef cNewRef = ConVarRef( sNewVarName );
// Set alternate cvar values.
cNewRef.m_pConVarState->m_fValue = cRef.m_pConVarState->GetFloat();
cNewRef.m_pConVarState->m_nValue = cRef.m_pConVarState->GetInt();
// Set string value...
char sString[5120] = "";
Q_strncpy(sString, (char*)cRef.m_pConVarState->GetString(), 5120 );
if ( Q_strlen( sString ) > 0 )
{
// Only set this pointer to a value value if the string exists, otherwise maybe it's what's causing the issue as the issue is happening during deleting of this string! Maybe it's because this isn't a string pointer and is being destroyed at the end of my function?? I'm afraid to use SetValue in case it fires the cvar again but this can be hacked.
Q_strncpy( cNewRef.m_pConVarState->m_pszString, sString, Q_strlen( sString ) + 1 );
}
// If it was the short version we want to fire anything that happens during the firing of the long version, I'm still not 100% sure if we need this, the code above (which isn't in this post) could be amended instead.
if ( lZombieVar == CVAR_SHORT )
{
char sCommand[1024];
if ( Q_strlen(sNewVarName) == 0 || Q_strlen(sString) == 0 )
{
Assert( false ); // Should never happen but...
}
Q_snprintf( sCommand, sizeof( sCommand ), "%s \"%s\"\n", sNewVarName, sString ); // Create command.
m_Engine->ServerCommand( sCommand ); // Could be tidied but useful for now.
}
__________________