- Removed GetConVarMin/Max() and replaced them with GetConVarBounds()
- Added SetConVarBounds() to set convar constraints after convar has already been created --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40720
This commit is contained in:
parent
523e3d042d
commit
41e473a60c
@ -200,8 +200,14 @@ protected:
|
||||
static IConCommandBaseAccessor *s_pAccessor;
|
||||
|
||||
public: // Hackalicous
|
||||
int GetFlags() { return m_nFlags; }
|
||||
void SetFlags(int flags) { m_nFlags = flags; }
|
||||
inline int GetFlags()
|
||||
{
|
||||
return m_nFlags;
|
||||
}
|
||||
inline void SetFlags(int flags)
|
||||
{
|
||||
m_nFlags = flags;
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -246,7 +252,10 @@ private:
|
||||
FnCommandCompletionCallback m_fnCompletionCallback;
|
||||
bool m_bHasCompletionCallback;
|
||||
public: // Hackalicous
|
||||
FnCommandCallback GetCallback() { return m_fnCommandCallback; }
|
||||
inline FnCommandCallback GetCallback()
|
||||
{
|
||||
return m_fnCommandCallback;
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -360,7 +369,20 @@ private:
|
||||
// Call this function when ConVar changes
|
||||
FnChangeCallback m_fnChangeCallback;
|
||||
public: // Hackalicous
|
||||
FnChangeCallback GetCallback() { return m_fnChangeCallback; }
|
||||
inline FnChangeCallback GetCallback()
|
||||
{
|
||||
return m_fnChangeCallback;
|
||||
}
|
||||
inline void SetMin(bool set, float min)
|
||||
{
|
||||
m_bHasMin = set;
|
||||
m_fMinVal = min;
|
||||
}
|
||||
inline void SetMax(bool set, float max)
|
||||
{
|
||||
m_bHasMax = set;
|
||||
m_fMaxVal = max;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -22,6 +22,12 @@
|
||||
#include "sm_stringutil.h"
|
||||
#include "PlayerManager.h"
|
||||
|
||||
enum ConVarBounds
|
||||
{
|
||||
ConVarBound_Upper = 0,
|
||||
ConVarBound_Lower
|
||||
};
|
||||
|
||||
static cell_t sm_CreateConVar(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
char *name, *defaultVal, *helpText;
|
||||
@ -261,7 +267,7 @@ static cell_t sm_SetConVarFlags(IPluginContext *pContext, const cell_t *params)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t sm_GetConVarMin(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t sm_GetConVarBounds(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError err;
|
||||
@ -274,18 +280,28 @@ static cell_t sm_GetConVarMin(IPluginContext *pContext, const cell_t *params)
|
||||
}
|
||||
|
||||
cell_t *addr;
|
||||
bool hasMin;
|
||||
float min;
|
||||
bool hasBound;
|
||||
float bound;
|
||||
|
||||
pContext->LocalToPhysAddr(params[2], &addr);
|
||||
switch (params[2])
|
||||
{
|
||||
case ConVarBound_Upper:
|
||||
hasBound = pConVar->GetMax(bound);
|
||||
break;
|
||||
case ConVarBound_Lower:
|
||||
hasBound = pConVar->GetMin(bound);
|
||||
break;
|
||||
default:
|
||||
return pContext->ThrowNativeError("Invalid ConVarBounds value %d");
|
||||
}
|
||||
|
||||
pContext->LocalToPhysAddr(params[3], &addr);
|
||||
*addr = sp_ftoc(bound);
|
||||
|
||||
hasMin = pConVar->GetMin(min);
|
||||
*addr = sp_ftoc(min);
|
||||
|
||||
return hasMin;
|
||||
return hasBound;
|
||||
}
|
||||
|
||||
static cell_t sm_GetConVarMax(IPluginContext *pContext, const cell_t *params)
|
||||
static cell_t sm_SetConVarBounds(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||
HandleError err;
|
||||
@ -297,16 +313,19 @@ static cell_t sm_GetConVarMax(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
|
||||
}
|
||||
|
||||
cell_t *addr;
|
||||
bool hasMax;
|
||||
float max;
|
||||
switch (params[2])
|
||||
{
|
||||
case ConVarBound_Upper:
|
||||
pConVar->SetMax(params[3] ? true : false, sp_ctof(params[4]));
|
||||
break;
|
||||
case ConVarBound_Lower:
|
||||
pConVar->SetMin(params[3] ? true : false, sp_ctof(params[4]));
|
||||
break;
|
||||
default:
|
||||
return pContext->ThrowNativeError("Invalid ConVarBounds value %d");
|
||||
}
|
||||
|
||||
pContext->LocalToPhysAddr(params[2], &addr);
|
||||
|
||||
hasMax = pConVar->GetMax(max);
|
||||
*addr = sp_ftoc(max);
|
||||
|
||||
return hasMax;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static cell_t sm_GetConVarName(IPluginContext *pContext, const cell_t *params)
|
||||
@ -630,8 +649,8 @@ REGISTER_NATIVES(consoleNatives)
|
||||
{"GetConVarFlags", sm_GetConVarFlags},
|
||||
{"SetConVarFlags", sm_SetConVarFlags},
|
||||
{"GetConVarName", sm_GetConVarName},
|
||||
{"GetConVarMin", sm_GetConVarMin},
|
||||
{"GetConVarMax", sm_GetConVarMax},
|
||||
{"GetConVarBounds", sm_GetConVarBounds},
|
||||
{"SetConVarBounds", sm_SetConVarBounds},
|
||||
{"ResetConVar", sm_ResetConVar},
|
||||
{"QueryClientConVar", sm_QueryClientConVar},
|
||||
{"RegServerCmd", sm_RegServerCmd},
|
||||
|
@ -18,6 +18,15 @@
|
||||
#endif
|
||||
#define _console_included
|
||||
|
||||
/**
|
||||
* Console variable bound values used with Get/SetConVarBounds()
|
||||
*/
|
||||
enum ConVarBounds
|
||||
{
|
||||
ConVarBound_Upper = 0,
|
||||
ConVarBound_Lower
|
||||
};
|
||||
|
||||
/**
|
||||
* Console variable query helper values.
|
||||
*/
|
||||
@ -378,6 +387,29 @@ native GetConVarFlags(Handle:convar);
|
||||
*/
|
||||
native SetConVarFlags(Handle:convar, flags);
|
||||
|
||||
/**
|
||||
* Retrieves the specified bound of a console variable.
|
||||
*
|
||||
* @param convar Handle to the convar.
|
||||
* @param type Type of bound to retrieve, ConVarBound_Lower or ConVarBound_Upper.
|
||||
* @param value By-reference cell to store the specified floating point bound value.
|
||||
* @return True if the convar has the specified bound set, false otherwise.
|
||||
* @error Invalid or corrupt Handle.
|
||||
*/
|
||||
native bool:GetConVarBounds(Handle:convar, ConVarBounds:type, &Float:value);
|
||||
|
||||
/**
|
||||
* Sets the specified bound of a console variable.
|
||||
*
|
||||
* @param convar Handle to the convar.
|
||||
* @param type Type of bound to set, ConVarBound_Lower or ConVarBound_Upper
|
||||
* @param set If set to true, convar will use specified bound. If false, bound will be removed.
|
||||
* @param value Floating point value to use as the specified bound.
|
||||
* @noreturn
|
||||
* @error Invalid or corrupt Handle.
|
||||
*/
|
||||
native SetConVarBounds(Handle:convar, ConVarBounds:type, bool:set, Float:value=0.0);
|
||||
|
||||
/**
|
||||
* Retrieves the name of a console variable.
|
||||
*
|
||||
@ -389,26 +421,6 @@ native SetConVarFlags(Handle:convar, flags);
|
||||
*/
|
||||
native GetConVarName(Handle:convar, const String:name[], maxlength);
|
||||
|
||||
/**
|
||||
* Retrieves the minimum floating point value that a console variable can contain.
|
||||
*
|
||||
* @param convar Handle to the convar.
|
||||
* @param min By-reference cell to store the minimum floating point value.
|
||||
* @return True if the convar has a minimum value set, false otherwise.
|
||||
* @error Invalid or corrupt Handle.
|
||||
*/
|
||||
native bool:GetConVarMin(Handle:convar, &Float:min);
|
||||
|
||||
/**
|
||||
* Retrieves the maximum floating point value that a console variable can contain.
|
||||
*
|
||||
* @param convar Handle to the convar.
|
||||
* @param min By-reference cell to store the maximum floating point value.
|
||||
* @return True if the convar has a maximum value set, false otherwise.
|
||||
* @error Invalid or corrupt Handle.
|
||||
*/
|
||||
native bool:GetConVarMax(Handle:convar, &Float:max);
|
||||
|
||||
/**
|
||||
* Resets the console variable to its default value.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user