From 2cb31db94d375e9937760fd74e10831631ca74c2 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 22 Jun 2009 16:10:40 +0200 Subject: [PATCH 1/4] Fixed logic bug in class flag filtering. --- src/zr/playerclasses/filtertools.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zr/playerclasses/filtertools.inc b/src/zr/playerclasses/filtertools.inc index 23083bd..cd57dcf 100644 --- a/src/zr/playerclasses/filtertools.inc +++ b/src/zr/playerclasses/filtertools.inc @@ -492,7 +492,7 @@ stock bool:ClassFlagFilterMatch(index, require, deny, cachetype) } // Match deny filter. - if (deny == 0 || ~flags & deny) + if (deny == 0 || !(flags & deny)) { // No denied flags are set. denypassed = true; From a0d8209c6aa3fa73675dedc47d6e1d3b5ee457d3 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 22 Jun 2009 16:29:13 +0200 Subject: [PATCH 2/4] Minior fixes in class system. --- src/zr/cvars.inc | 2 +- src/zr/playerclasses/classevents.inc | 8 ++++---- src/zr/playerclasses/filtertools.inc | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index f7d9032..b547009 100644 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -238,7 +238,7 @@ CvarsCreate() g_hCvarsList[CVAR_CLASSES_DEFAULT_ADMIN] = CreateConVar("zr_classes_default_admin", "random", "Admin class assigned to admins on connect. [\"random\" = Random admin class | \"\" = Class config default]"); // Menu - g_hCvarsList[CVAR_CLASSES_MENU_AUTOCLOSE] = CreateConVar("zr_classes_menu_autoclose", "0", "Automatically close class selection menu."); + g_hCvarsList[CVAR_CLASSES_MENU_AUTOCLOSE] = CreateConVar("zr_classes_menu_autoclose", "0", "Automatically close class selection menu after selecting a class."); // Overlays g_hCvarsList[CVAR_CLASSES_OVERLAY_TOGGLE] = CreateConVar("zr_classes_overlay_toggle", "1", "Allow players to toggle class overlay."); diff --git a/src/zr/playerclasses/classevents.inc b/src/zr/playerclasses/classevents.inc index 43f60bf..99e7304 100644 --- a/src/zr/playerclasses/classevents.inc +++ b/src/zr/playerclasses/classevents.inc @@ -172,9 +172,9 @@ ClassOnClientInfected(client, bool:motherzombie = false) // Check if it's a mother zombie. if (motherzombie) { - // Set negative admin flag if client is admin, so it's removed in - // special class flags. - isadmin = ZRIsClientAdmin(client) ? -ZR_CLASS_FLAG_ADMIN_ONLY : 0; + // Set admin flag if client is admin, so it's removed in special class + // flags. + isadmin = ZRIsClientAdmin(client) ? ZR_CLASS_FLAG_ADMIN_ONLY : 0; // Get default mother zombie setting. GetConVarString(g_hCvarsList[CVAR_CLASSES_DEFAULT_M_ZOMB], motherzombiesetting, sizeof(motherzombiesetting)); @@ -186,7 +186,7 @@ ClassOnClientInfected(client, bool:motherzombie = false) else if (StrEqual(motherzombiesetting, "random", false)) { // Get random regular zombie class. Remove admin flag if admin. - motherindex = ClassGetRandomClass(ZR_CLASS_TEAM_ZOMBIES, _, _, ZR_CLASS_SPECIALFLAGS + isadmin); + motherindex = ClassGetRandomClass(ZR_CLASS_TEAM_ZOMBIES, _, _, ZR_CLASS_SPECIALFLAGS - isadmin); } else if (StrEqual(motherzombiesetting, "motherzombies", false)) { diff --git a/src/zr/playerclasses/filtertools.inc b/src/zr/playerclasses/filtertools.inc index cd57dcf..51a4d0c 100644 --- a/src/zr/playerclasses/filtertools.inc +++ b/src/zr/playerclasses/filtertools.inc @@ -909,7 +909,7 @@ stock ClassGetDefaultSpawnClass(teamid, cachetype = ZR_CLASS_CACHE_MODIFIED) // The class index is invalid or the team IDs didn't match. // Because it's user input, we'll fall back to the first class // in the specified team, and log a warning. - classindex = ClassGetFirstClass(teamid, _, _, cachetype); + classindex = ClassGetFirstClass(teamid, _, _, ZR_CLASS_SPECIALFLAGS, cachetype); LogEvent(false, LogType_Error, LOG_CORE_EVENTS, LogModule_Playerclasses, "Default Spawn Class", "Warning: Failed to set \"%s\" as default spawn class for team %d. The class doesn't exist or the team IDs doesn't match. Falling back to the first class in the team.", classname, teamid); From 1cc0fc4dda3406a71913736a744610f85253516a Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 22 Jun 2009 17:01:26 +0200 Subject: [PATCH 3/4] Fixed original models not restored when using zr_human on a player. --- src/zr/playerclasses/apply.inc | 15 +++++++++++++-- src/zr/playerclasses/classevents.inc | 12 +++++++++--- src/zr/playerclasses/playerclasses.inc | 6 ++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/zr/playerclasses/apply.inc b/src/zr/playerclasses/apply.inc index cc845d8..625da0e 100644 --- a/src/zr/playerclasses/apply.inc +++ b/src/zr/playerclasses/apply.inc @@ -101,8 +101,19 @@ bool:ClassApplyModel(client, classindex, cachetype = ZR_CLASS_CACHE_PLAYER) // Check if the user specified no change. else if (strcmp(modelpath, "default", false) == 0) { - // Don't change the model. - return true; + // Get current model. + GetClientModel(client, modelpath, sizeof(modelpath)); + + // Restore original model if not already set. + if (!StrEqual(ClassOriginalPlayerModel[client], modelpath)) + { + strcopy(modelpath, sizeof(modelpath), ClassOriginalPlayerModel[client]); + } + else + { + // Wanted model is already set, don't change. + return true; + } } SetEntityModel(client, modelpath); diff --git a/src/zr/playerclasses/classevents.inc b/src/zr/playerclasses/classevents.inc index 99e7304..9c5f4d6 100644 --- a/src/zr/playerclasses/classevents.inc +++ b/src/zr/playerclasses/classevents.inc @@ -69,6 +69,10 @@ ClassOnClientDisconnect(client) */ ClassOnClientSpawn(client) { + decl String:originalmodel[PLATFORM_MAX_PATH]; + decl String:steamid[16]; + decl String:classname[64]; + // Check if the player is alive. if (!IsPlayerAlive(client)) { @@ -85,10 +89,12 @@ ClassOnClientSpawn(client) // Reset attributes by triggering death event. ClassOnClientDeath(client); + // Cache original player model. + GetClientModel(client, originalmodel, sizeof(originalmodel)); + strcopy(ClassOriginalPlayerModel[client], PLATFORM_MAX_PATH, originalmodel); + + // Get random class setting. new bool:randomclass = GetConVarBool(g_hCvarsList[CVAR_CLASSES_RANDOM]); - - decl String:steamid[16]; - decl String:classname[64]; // Assign random classes if enabled. Always do it for bots. GetClientAuthString(client, steamid, sizeof(steamid)); diff --git a/src/zr/playerclasses/playerclasses.inc b/src/zr/playerclasses/playerclasses.inc index 8e76e5f..e06a73c 100644 --- a/src/zr/playerclasses/playerclasses.inc +++ b/src/zr/playerclasses/playerclasses.inc @@ -366,6 +366,12 @@ new bool:ClassPlayerAdminMode[MAXPLAYERS + 1]; */ new ClassPlayerNextAdminClass[MAXPLAYERS + 1]; +/** + * Cache for storing original model path before applying custom models. Used + * when restoring to old model. + */ +new String:ClassOriginalPlayerModel[MAXPLAYERS + 1][PLATFORM_MAX_PATH]; + #include "zr/playerclasses/filtertools" #include "zr/playerclasses/attributes" #include "zr/playerclasses/apply" From 723038052e38830131a17425e1603d951ec08603 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 22 Jun 2009 18:11:31 +0200 Subject: [PATCH 4/4] Fixed potential memory leak in class system. --- src/zr/playerclasses/classmenus.inc | 3 +++ src/zr/playerclasses/filtertools.inc | 9 ++++++++- src/zr/playerclasses/playerclasses.inc | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/zr/playerclasses/classmenus.inc b/src/zr/playerclasses/classmenus.inc index f9ed80d..18130ff 100644 --- a/src/zr/playerclasses/classmenus.inc +++ b/src/zr/playerclasses/classmenus.inc @@ -231,6 +231,9 @@ ClassMenuSelect(client, teamid) } } + // Destroy array. + CloseHandle(classarray); + SetMenuExitBackButton(menu, true); DisplayMenu(menu, client, MENU_TIME_FOREVER); } diff --git a/src/zr/playerclasses/filtertools.inc b/src/zr/playerclasses/filtertools.inc index 51a4d0c..aa86c85 100644 --- a/src/zr/playerclasses/filtertools.inc +++ b/src/zr/playerclasses/filtertools.inc @@ -693,6 +693,7 @@ stock ClassGetRandomClass(teamfilter = -1, bool:ignoreEnabled = false, requirefl new Handle:classarray; new arraycount; new randnum; + new buffer; classarray = CreateArray(); @@ -704,11 +705,14 @@ stock ClassGetRandomClass(teamfilter = -1, bool:ignoreEnabled = false, requirefl randnum = GetRandomInt(0, arraycount - 1); // Return the value at the random index. - return GetArrayCell(classarray, randnum); + buffer = GetArrayCell(classarray, randnum); + CloseHandle(classarray); + return buffer; } else { // Failed to get a random class. + CloseHandle(classarray); return -1; } } @@ -808,6 +812,7 @@ stock ClassGetDefaultClass(teamid, bool:ignoreEnabled = false, requireflags = 0, if (!ClassAddToArray(classarray, teamid, ignoreEnabled, requireflags, denyflags, cachetype)) { // Failed to get classes. + CloseHandle(classarray); return -1; } @@ -822,10 +827,12 @@ stock ClassGetDefaultClass(teamid, bool:ignoreEnabled = false, requireflags = 0, if (ClassGetTeamDefault(classindex, cachetype)) { // Default class found. + CloseHandle(classarray); return classindex; } } + CloseHandle(classarray); return -1; } diff --git a/src/zr/playerclasses/playerclasses.inc b/src/zr/playerclasses/playerclasses.inc index e06a73c..c8734b1 100644 --- a/src/zr/playerclasses/playerclasses.inc +++ b/src/zr/playerclasses/playerclasses.inc @@ -544,6 +544,9 @@ ClassLoad(bool:keepMultipliers = false) ConfigSetConfigReloadFunc(File_Classes, GetFunctionByName(GetMyHandle(), "ClassOnConfigReload")); // ConfigSetConfigHandle(File_Classes, INVALID_HANDLE); ConfigSetConfigPath(File_Classes, pathclasses); + + // Remove key/value cache. + CloseHandle(kvClassData); } /**