Skip to content

Instantly share code, notes, and snippets.

@sigsegv-mvm
Created September 7, 2015 20:54
Show Gist options
  • Save sigsegv-mvm/17fb93f3bcea0cea5a4f to your computer and use it in GitHub Desktop.
Save sigsegv-mvm/17fb93f3bcea0cea5a4f to your computer and use it in GitHub Desktop.
ClientCommandKeyValues dumper
#include <sourcemod>
#include <tf2>
#include <clients>
#include <keyvalues>
#include <tf2>
#include <tf2_stocks>
#include <sdktools>
#include <sdkhooks>
public OnPluginStart()
{
PrintToServer("[dumpclientcmdkv] plugin started")
}
void dump_kv(KeyValues kv, int level = 0)
{
do {
decl String:sec[256] = "";
if (!kv.GetSectionName(sec, 256)) {
continue;
}
decl String:indent[256] = "";
for (new i = 0; i < level; ++i) {
StrCat(indent, 256, " ");
}
if (kv.GetDataType(NULL_STRING) == KvData_None &&
strcmp(sec, "") != 0) {
PrintToServer("%s+ %s", indent, sec);
}
if (kv.GotoFirstSubKey(false)) {
dump_kv(kv, level + 1);
kv.GoBack();
} else {
switch (kv.GetDataType(NULL_STRING)) {
case KvData_None: {
//PrintToServer("%s- None", indent);
}
case KvData_String: {
decl String:val[256] = "";
kv.GetString(NULL_STRING, val, 256);
PrintToServer("%s- String %s: '%s'", indent, sec, val);
}
case KvData_Int: {
PrintToServer("%s- Int %s: %d", indent, sec, kv.GetNum(NULL_STRING));
}
case KvData_Float: {
PrintToServer("%s- Float %s: %f", indent, sec, kv.GetFloat(NULL_STRING));
}
case KvData_Ptr: {
PrintToServer("%s- Ptr %s: %x", indent, sec, kv.GetNum(NULL_STRING));
}
case KvData_WString: {
PrintToServer("%s- WString %s: ???", indent, sec);
}
case KvData_Color: {
PrintToServer("%s- Color %s: ???", indent, sec);
}
case KvData_UInt64: {
decl val[2];
kv.GetUInt64(NULL_STRING, val);
PrintToServer("%s- UInt64 %s: %x %x", indent, sec, val[0], val[1]);
}
default: {
PrintToServer("%s- ??? %s: ???", indent, sec);
}
}
}
} while (kv.GotoNextKey(false));
}
public Action OnClientCommandKeyValues(int client, KeyValues kv)
{
decl String:name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
PrintToServer("[%8.3f] %s (#%d): ClientCmd", GetGameTime(), name, client);
dump_kv(kv);
decl String:cmd[256] = "";
kv.GetSectionName(cmd, 256);
/*if (strcmp(cmd, "mvm_upgrade", false) == 0) {
kv.ExportToFile("clientcmdkv.txt");
}*/
/* allow the command to be sent */
return Plugin_Continue;
}
public void OnClientCommandKeyValues_Post(int client, KeyValues kv)
{
return;
decl String:name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
PrintToServer("[%8.3f] %s (#%d): ClientCmd_Post", GetGameTime(), name, client);
dump_kv(kv);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment