Skip to content

Commit

Permalink
Add convar for debugging SetClientClass
Browse files Browse the repository at this point in the history
  • Loading branch information
FortyTwoFortyTwo committed Feb 22, 2024
1 parent 7e116e9 commit 6f2520f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ To download latest build version, select latest package then "Artifacts" section
## ConVars
- `randomizer_version`: Plugin version number, don't touch.
- `randomizer_enabled`: Enable/Disable entire randomizer plugin, another option for load/unload plugins.
- `randomizer_debug`: Enable/Disable debugging infos, not recommended to enable it.
- `randomizer_class`: How should class be randomized.
- `randomizer_weapons`: How should weapons be randomized.
- `randomizer_cosmetics`: How should cosmetics be randomized.
Expand Down
45 changes: 43 additions & 2 deletions scripting/randomizer.sp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#pragma newdecls required

#define PLUGIN_VERSION "1.10.3"
#define PLUGIN_VERSION "1.10.4"
#define PLUGIN_VERSION_REVISION "manual"

#define CONFIG_MAXCHAR 64
Expand Down Expand Up @@ -329,6 +329,7 @@ int g_iOffsetPlayerShared;
int g_iOffsetAlwaysAllow;

ConVar g_cvEnabled;
ConVar g_cvDebug;
ConVar g_cvFixTaunt;
ConVar g_cvDroppedWeapons;
ConVar g_cvHuds;
Expand All @@ -337,6 +338,7 @@ ConVar g_cvRandomize[view_as<int>(RandomizedType_MAX)];
bool g_bClientRefresh[MAXPLAYERS];

TFClassType g_iClientCurrentClass[MAXPLAYERS + 1][4];
FrameIterator g_hClientCurrentClass[MAXPLAYERS + 1][4];
bool g_bFeignDeath[MAXPLAYERS + 1];
int g_iHypeMeterLoaded[MAXPLAYERS + 1] = {INVALID_ENT_REFERENCE, ...};
bool g_bWeaponDecap[MAXPLAYERS + 1];
Expand Down Expand Up @@ -879,10 +881,47 @@ void SetClientClass(int iClient, TFClassType nClass)
ThrowError("Client %d is TFClass_Unknown in SetClientClass", iClient);

TF2_SetPlayerClass(iClient, nClass);

if (g_cvDebug.BoolValue)
g_hClientCurrentClass[iClient][i] = new FrameIterator();

return;
}

ThrowError("Exceeded array limit on storing class");
if (g_cvDebug.BoolValue)
{
LogError("Exceeded array limit on storing class");

for (int i = 0; i < sizeof(g_iClientCurrentClass[]); i++)
{
FrameIterator hIterator = g_hClientCurrentClass[iClient][i];
if (!hIterator)
continue;

hIterator.Reset();
if (!hIterator.Next()) // skip SetClientClass
continue;

LogError("Index %d stack trace: ", i);

int iCounter;

while (hIterator.Next() && hIterator.LineNumber)
{
char sFile[256], sFunction[256];
hIterator.GetFilePath(sFile, sizeof(sFile));
hIterator.GetFunctionName(sFunction, sizeof(sFunction));
LogError(" [%d] Line %d, %s::%s", iCounter, hIterator.LineNumber, sFile, sFunction);

iCounter++;
}
}

}
else
{
ThrowError("Exceeded array limit on storing class, enable randomizer_debug and try again for more infos");
}
}

void SetClientClassOriginal(int iClient)
Expand All @@ -903,6 +942,8 @@ void RevertClientClass(int iClient)

TF2_SetPlayerClass(iClient, g_iClientCurrentClass[iClient][i]);
g_iClientCurrentClass[iClient][i] = TFClass_Unknown;

delete g_hClientCurrentClass[iClient][i];
return;
}

Expand Down
1 change: 1 addition & 0 deletions scripting/randomizer/convar.sp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void ConVar_Init()
g_cvEnabled = CreateConVar("randomizer_enabled", "1", "Enable Randomizer?", _, true, 0.0, true, 1.0);
g_cvEnabled.AddChangeHook(ConVar_EnableChanged);

g_cvDebug = CreateConVar("randomizer_debug", "0", "Enable debugging info, enabling may cause preformance issues.", _, true, 0.0, true, 1.0);
g_cvFixTaunt = CreateConVar("randomizer_fix_taunt", "1", "Fix Taunting?", _, true, 0.0, true, 1.0);
g_cvDroppedWeapons = CreateConVar("randomizer_droppedweapons", "0", "Allow dropped weapons?", _, true, 0.0, true, 1.0);
g_cvHuds = CreateConVar("randomizer_huds", "1", "Hud to use to display weapons. 0 = none, 1 = hud text, 2 = menu.", _, true, 0.0, true, float(HudMode_MAX - 1));
Expand Down

0 comments on commit 6f2520f

Please sign in to comment.