From cdc2b11a09d189804095e79bbb85d0954877034d Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Fri, 31 Oct 2014 17:06:42 -0400 Subject: [PATCH 1/5] Add a ConVar class. --- plugins/include/console.inc | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/plugins/include/console.inc b/plugins/include/console.inc index 91c03222..dac7903a 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -438,7 +438,7 @@ native GetCmdArgString(String:buffer[], maxlength); * @return A handle to the newly created convar. If the convar already exists, a handle to it will still be returned. * @error Convar name is blank or is the same as an existing console command. */ -native Handle:CreateConVar(const String:name[], const String:defaultValue[], const String:description[]="", flags=0, bool:hasMin=false, Float:min=0.0, bool:hasMax=false, Float:max=0.0); +native ConVar:CreateConVar(const String:name[], const String:defaultValue[], const String:description[]="", flags=0, bool:hasMin=false, Float:min=0.0, bool:hasMax=false, Float:max=0.0); /** * Searches for a console variable. @@ -446,7 +446,7 @@ native Handle:CreateConVar(const String:name[], const String:defaultValue[], con * @param name Name of convar to find. * @return A handle to the convar if it is found. INVALID_HANDLE otherwise. */ -native Handle:FindConVar(const String:name[]); +native ConVar:FindConVar(const String:name[]); /** * Called when a console variable's value is changed. @@ -969,3 +969,23 @@ forward Action:OnClientSayCommand(client, const String:command[], const String:s * */ forward void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs); + +methodmap ConVar < Handle +{ + public ConVar() = CreateConVar; + public GetBool() = GetConVarBool; + public SetBool() = SetConVarBool; + public GetInt() = GetConVarInt; + public SetInt() = SetConVarInt; + public GetString() = GetConVarString; + public SetString() = SetConVarString; + public GetFloat() = GetConVarFloat; + public SetFloat() = SetConVarFloat; + public GetFlags() = GetConVarFlags; + public SetFlags() = SetConVarFlags; + public GetBounds() = GetConVarBounds; + public SetBounds() = SetConVarBounds; + public GetDefault() = GetConVarDefault; + public GetName() = GetConVarName; + +} \ No newline at end of file From 286d484207a800d17c7e6402d898806cbdbd5197 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Fri, 31 Oct 2014 17:21:37 -0400 Subject: [PATCH 2/5] Rearrange order of methods in methodmap. Add missing Reset method to methodmap. --- plugins/include/console.inc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/plugins/include/console.inc b/plugins/include/console.inc index dac7903a..60272518 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -29,7 +29,7 @@ * * Version: $Id$ */ - + #if defined _console_included #endinput #endif @@ -970,6 +970,7 @@ forward Action:OnClientSayCommand(client, const String:command[], const String:s */ forward void OnClientSayCommand_Post(int client, const char[] command, const char[] sArgs); +// Most of these aren't properties because they're more complex methodmap ConVar < Handle { public ConVar() = CreateConVar; @@ -977,15 +978,15 @@ methodmap ConVar < Handle public SetBool() = SetConVarBool; public GetInt() = GetConVarInt; public SetInt() = SetConVarInt; - public GetString() = GetConVarString; - public SetString() = SetConVarString; public GetFloat() = GetConVarFloat; public SetFloat() = SetConVarFloat; + public GetString() = GetConVarString; + public SetString() = SetConVarString; + public Reset() = ResetConVar; public GetFlags() = GetConVarFlags; public SetFlags() = SetConVarFlags; public GetBounds() = GetConVarBounds; public SetBounds() = SetConVarBounds; public GetDefault() = GetConVarDefault; public GetName() = GetConVarName; - } \ No newline at end of file From 87a21c7ff8e61303a78e7ccc9842a48a2f595eb4 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Wed, 5 Nov 2014 15:26:03 -0500 Subject: [PATCH 3/5] Add HookChange and UnhookChange to ConVar. --- plugins/include/console.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/include/console.inc b/plugins/include/console.inc index 60272518..1f36e24c 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -989,4 +989,6 @@ methodmap ConVar < Handle public SetBounds() = SetConVarBounds; public GetDefault() = GetConVarDefault; public GetName() = GetConVarName; + public HookChange() = HookConVarChange; + public UnhookChange() = UnhookConVarChange; } \ No newline at end of file From 3fff07b33d4eac33981e19a3050548e7ff2c3eb2 Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Wed, 5 Nov 2014 15:50:03 -0500 Subject: [PATCH 4/5] Changed ConVarChanged to take a ConVar variable. Backwards compatible with Handle variables (I tested this to make sure). --- plugins/include/console.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/include/console.inc b/plugins/include/console.inc index 1f36e24c..243da329 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -456,7 +456,7 @@ native ConVar:FindConVar(const String:name[]); * @param newValue String containing the new value of the convar. * @noreturn */ -typedef ConVarChanged = function void (Handle convar, const char[] oldValue, const char[] newValue); +typedef ConVarChanged = function void (ConVar convar, const char[] oldValue, const char[] newValue); /** * Creates a hook for when a console variable's value is changed. From 67f9069382edb3bc010b0b0bcf5829f5db824abd Mon Sep 17 00:00:00 2001 From: Ross Bemrose Date: Wed, 5 Nov 2014 16:34:04 -0500 Subject: [PATCH 5/5] Updated the named with the ones bailopan suggested. --- plugins/include/console.inc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/include/console.inc b/plugins/include/console.inc index 243da329..f1fc2928 100644 --- a/plugins/include/console.inc +++ b/plugins/include/console.inc @@ -982,13 +982,13 @@ methodmap ConVar < Handle public SetFloat() = SetConVarFloat; public GetString() = GetConVarString; public SetString() = SetConVarString; - public Reset() = ResetConVar; + public RestoreDefaultValue() = ResetConVar; public GetFlags() = GetConVarFlags; public SetFlags() = SetConVarFlags; public GetBounds() = GetConVarBounds; public SetBounds() = SetConVarBounds; - public GetDefault() = GetConVarDefault; + public GetDefaultValue() = GetConVarDefault; public GetName() = GetConVarName; - public HookChange() = HookConVarChange; - public UnhookChange() = UnhookConVarChange; + public AddChangeHook() = HookConVarChange; + public RemoveChangeHook() = UnhookConVarChange; } \ No newline at end of file