From 6b6753ec1b5aa18cb75c102eb326a266c4221f2d Mon Sep 17 00:00:00 2001 From: jenz Date: Thu, 6 Jun 2024 12:41:07 +0200 Subject: [PATCH] initial release to log anything happening to givenamedItem --- .../gamedata/track_give_named_item.css.txt | 14 ++++ .../scripting/track_give_named_item.sp | 64 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 track_give_named_item/gamedata/track_give_named_item.css.txt create mode 100644 track_give_named_item/scripting/track_give_named_item.sp diff --git a/track_give_named_item/gamedata/track_give_named_item.css.txt b/track_give_named_item/gamedata/track_give_named_item.css.txt new file mode 100644 index 00000000..1f8a77b5 --- /dev/null +++ b/track_give_named_item/gamedata/track_give_named_item.css.txt @@ -0,0 +1,14 @@ +"Games" +{ + "cstrike" + { + "Signatures" + { + "CCSPlayer::GiveNamedItem" + { + "library" "server" + "linux" "@_ZN9CCSPlayer13GiveNamedItemEPKci" + } + } + } +} diff --git a/track_give_named_item/scripting/track_give_named_item.sp b/track_give_named_item/scripting/track_give_named_item.sp new file mode 100644 index 00000000..9bec25fd --- /dev/null +++ b/track_give_named_item/scripting/track_give_named_item.sp @@ -0,0 +1,64 @@ +#pragma semicolon 1 +#define PLUGIN_AUTHOR "jenz" +#define PLUGIN_VERSION "1.0" +#include +#include +#include + +Handle hGiveNamedItem; + +//the trololo guy is actively checking all plugins running. he should not be aware that we got somehwere. + +public Plugin myinfo = +{ + name = "it does what it does", + author = PLUGIN_AUTHOR, + description = "yeah", + version = PLUGIN_VERSION, + url = "www.unloze.com" +}; + +public void OnPluginStart() +{ + Handle conf = LoadGameConfigFile("track_give_named_item.css"); + if (conf == INVALID_HANDLE) + SetFailState("Failed to load gamedata track_give_named_item.css"); + + hGiveNamedItem = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_CBaseEntity, ThisPointer_CBaseEntity); + if (!hGiveNamedItem) + SetFailState("Failed to setup detour for CCSPlayer::GiveNamedItem"); + + if (!DHookSetFromConf(hGiveNamedItem, conf, SDKConf_Signature, "CCSPlayer::GiveNamedItem")) + SetFailState("Failed to load CCSPlayer::GiveNamedItem signature from gamedata"); + + //function CCSPlayer::GiveNamedItem has two params. + DHookAddParam(hGiveNamedItem, HookParamType_CharPtr); + DHookAddParam(hGiveNamedItem, HookParamType_Int); + + if (!DHookEnableDetour(hGiveNamedItem, false, track_give_named_item)) + SetFailState("Failed to detour CCSPlayer::GiveNamedItem"); + + delete conf; +} + +public MRESReturn track_give_named_item(int pThis, Handle hReturn, Handle hParams) +{ + char pszName[512]; + DHookGetParamString(hParams, 1, pszName, sizeof(pszName)); + + int iSubType = DHookGetParam(hParams, 2); + + LogToFile("addons/sourcemod/logs/GiveNamedItemDebug.txt", "pszName: %s iSubType: %i", pszName, iSubType); + if (IsValidClient(pThis)) + { + LogToFile("addons/sourcemod/logs/GiveNamedItemDebug.txt", "Client: %L\n\n", pThis); + } + return MRES_Ignored; +} + +stock bool IsValidClient(int client) +{ + if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client)) + return true; + return false; +}