- 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;
|
static IConCommandBaseAccessor *s_pAccessor;
|
||||||
|
|
||||||
public: // Hackalicous
|
public: // Hackalicous
|
||||||
int GetFlags() { return m_nFlags; }
|
inline int GetFlags()
|
||||||
void SetFlags(int flags) { m_nFlags = flags; }
|
{
|
||||||
|
return m_nFlags;
|
||||||
|
}
|
||||||
|
inline void SetFlags(int flags)
|
||||||
|
{
|
||||||
|
m_nFlags = flags;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -246,7 +252,10 @@ private:
|
|||||||
FnCommandCompletionCallback m_fnCompletionCallback;
|
FnCommandCompletionCallback m_fnCompletionCallback;
|
||||||
bool m_bHasCompletionCallback;
|
bool m_bHasCompletionCallback;
|
||||||
public: // Hackalicous
|
public: // Hackalicous
|
||||||
FnCommandCallback GetCallback() { return m_fnCommandCallback; }
|
inline FnCommandCallback GetCallback()
|
||||||
|
{
|
||||||
|
return m_fnCommandCallback;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -360,7 +369,20 @@ private:
|
|||||||
// Call this function when ConVar changes
|
// Call this function when ConVar changes
|
||||||
FnChangeCallback m_fnChangeCallback;
|
FnChangeCallback m_fnChangeCallback;
|
||||||
public: // Hackalicous
|
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 "sm_stringutil.h"
|
||||||
#include "PlayerManager.h"
|
#include "PlayerManager.h"
|
||||||
|
|
||||||
|
enum ConVarBounds
|
||||||
|
{
|
||||||
|
ConVarBound_Upper = 0,
|
||||||
|
ConVarBound_Lower
|
||||||
|
};
|
||||||
|
|
||||||
static cell_t sm_CreateConVar(IPluginContext *pContext, const cell_t *params)
|
static cell_t sm_CreateConVar(IPluginContext *pContext, const cell_t *params)
|
||||||
{
|
{
|
||||||
char *name, *defaultVal, *helpText;
|
char *name, *defaultVal, *helpText;
|
||||||
@ -261,7 +267,7 @@ static cell_t sm_SetConVarFlags(IPluginContext *pContext, const cell_t *params)
|
|||||||
return 1;
|
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]);
|
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||||
HandleError err;
|
HandleError err;
|
||||||
@ -274,18 +280,28 @@ static cell_t sm_GetConVarMin(IPluginContext *pContext, const cell_t *params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cell_t *addr;
|
cell_t *addr;
|
||||||
bool hasMin;
|
bool hasBound;
|
||||||
float min;
|
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);
|
return hasBound;
|
||||||
*addr = sp_ftoc(min);
|
|
||||||
|
|
||||||
return hasMin;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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]);
|
Handle_t hndl = static_cast<Handle_t>(params[1]);
|
||||||
HandleError err;
|
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);
|
return pContext->ThrowNativeError("Invalid convar handle %x (error %d)", hndl, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
cell_t *addr;
|
switch (params[2])
|
||||||
bool hasMax;
|
{
|
||||||
float max;
|
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);
|
return 1;
|
||||||
|
|
||||||
hasMax = pConVar->GetMax(max);
|
|
||||||
*addr = sp_ftoc(max);
|
|
||||||
|
|
||||||
return hasMax;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static cell_t sm_GetConVarName(IPluginContext *pContext, const cell_t *params)
|
static cell_t sm_GetConVarName(IPluginContext *pContext, const cell_t *params)
|
||||||
@ -630,8 +649,8 @@ REGISTER_NATIVES(consoleNatives)
|
|||||||
{"GetConVarFlags", sm_GetConVarFlags},
|
{"GetConVarFlags", sm_GetConVarFlags},
|
||||||
{"SetConVarFlags", sm_SetConVarFlags},
|
{"SetConVarFlags", sm_SetConVarFlags},
|
||||||
{"GetConVarName", sm_GetConVarName},
|
{"GetConVarName", sm_GetConVarName},
|
||||||
{"GetConVarMin", sm_GetConVarMin},
|
{"GetConVarBounds", sm_GetConVarBounds},
|
||||||
{"GetConVarMax", sm_GetConVarMax},
|
{"SetConVarBounds", sm_SetConVarBounds},
|
||||||
{"ResetConVar", sm_ResetConVar},
|
{"ResetConVar", sm_ResetConVar},
|
||||||
{"QueryClientConVar", sm_QueryClientConVar},
|
{"QueryClientConVar", sm_QueryClientConVar},
|
||||||
{"RegServerCmd", sm_RegServerCmd},
|
{"RegServerCmd", sm_RegServerCmd},
|
||||||
|
@ -18,6 +18,15 @@
|
|||||||
#endif
|
#endif
|
||||||
#define _console_included
|
#define _console_included
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Console variable bound values used with Get/SetConVarBounds()
|
||||||
|
*/
|
||||||
|
enum ConVarBounds
|
||||||
|
{
|
||||||
|
ConVarBound_Upper = 0,
|
||||||
|
ConVarBound_Lower
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Console variable query helper values.
|
* Console variable query helper values.
|
||||||
*/
|
*/
|
||||||
@ -378,6 +387,29 @@ native GetConVarFlags(Handle:convar);
|
|||||||
*/
|
*/
|
||||||
native SetConVarFlags(Handle:convar, flags);
|
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.
|
* Retrieves the name of a console variable.
|
||||||
*
|
*
|
||||||
@ -389,26 +421,6 @@ native SetConVarFlags(Handle:convar, flags);
|
|||||||
*/
|
*/
|
||||||
native GetConVarName(Handle:convar, const String:name[], maxlength);
|
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.
|
* Resets the console variable to its default value.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user