From 8b032c5c9edf63fb68413874e388b74e80c5ee26 Mon Sep 17 00:00:00 2001 From: BotoX Date: Tue, 2 May 2017 23:54:15 +0200 Subject: [PATCH] GlowColors: Restore glowcolor when map resets to 255 255 255 or sets normal rendermode. --- GlowColors/scripting/GlowColors.sp | 122 ++++++++++++++++++++++++++--- 1 file changed, 109 insertions(+), 13 deletions(-) diff --git a/GlowColors/scripting/GlowColors.sp b/GlowColors/scripting/GlowColors.sp index 280b52a7..ecb5c870 100644 --- a/GlowColors/scripting/GlowColors.sp +++ b/GlowColors/scripting/GlowColors.sp @@ -6,6 +6,7 @@ #include #include #include +#include #undef REQUIRE_PLUGIN #include #define REQUIRE_PLUGIN @@ -15,10 +16,13 @@ public Plugin myinfo = name = "GlowColors", author = "BotoX", description = "Change your clients colors.", - version = "1.1", + version = "1.2", url = "" } +// bool CBaseEntity::AcceptInput( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID ) +Handle g_hAcceptInput; + Menu g_GlowColorsMenu; Handle g_hClientCookie = INVALID_HANDLE; @@ -31,6 +35,23 @@ float g_aRainbowFrequency[MAXPLAYERS + 1]; public void OnPluginStart() { + Handle hGameConf = LoadGameConfigFile("sdktools.games"); + if(hGameConf == INVALID_HANDLE) + { + SetFailState("Couldn't load sdktools game config!"); + return; + } + + int Offset = GameConfGetOffset(hGameConf, "AcceptInput"); + g_hAcceptInput = DHookCreate(Offset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity, AcceptInput); + DHookAddParam(g_hAcceptInput, HookParamType_CharPtr); + DHookAddParam(g_hAcceptInput, HookParamType_CBaseEntity); + DHookAddParam(g_hAcceptInput, HookParamType_CBaseEntity); + DHookAddParam(g_hAcceptInput, HookParamType_Object, 20, DHookPass_ByVal|DHookPass_ODTOR|DHookPass_OCTOR|DHookPass_OASSIGNOP); //varaint_t is a union of 12 (float[3]) plus two int type params 12 + 8 = 20 + DHookAddParam(g_hAcceptInput, HookParamType_Int); + + CloseHandle(hGameConf); + g_hClientCookie = RegClientCookie("glowcolor", "", CookieAccess_Protected); g_Regex_RGB = CompileRegex("^(([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])\\s+){2}([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$"); @@ -53,14 +74,21 @@ public void OnPluginStart() g_Cvar_MinBrightness = CreateConVar("sm_glowcolor_minbrightness", "100", "Lowest brightness value for glowcolor.", 0, true, 0.0, true, 255.0); + AutoExecConfig(true, "plugin.GlowColors"); + LoadConfig(); for(int client = 1; client <= MaxClients; client++) { - if(IsClientInGame(client) && !IsFakeClient(client) && AreClientCookiesCached(client)) + if(IsClientInGame(client)) { - OnClientCookiesCached(client); - ApplyGlowColor(client); + OnClientPutInServer(client); + + if(!IsFakeClient(client) && AreClientCookiesCached(client)) + { + OnClientCookiesCached(client); + ApplyGlowColor(client); + } } } } @@ -119,12 +147,14 @@ void LoadConfig() while(Config.GotoNextKey(false)); } -public void OnClientConnected(int client) +public void OnClientPutInServer(int client) { g_aGlowColor[client][0] = 255; g_aGlowColor[client][1] = 255; g_aGlowColor[client][2] = 255; g_aRainbowFrequency[client] = 0.0; + + DHookEntity(g_hAcceptInput, false, client); } public void OnClientCookiesCached(int client) @@ -198,6 +228,80 @@ public void OnPostThinkPost(int client) ToolsSetEntityColor(client, Red, Green, Blue); } +// bool CBaseEntity::AcceptInput( const char *szInputName, CBaseEntity *pActivator, CBaseEntity *pCaller, variant_t Value, int outputID ) +public MRESReturn AcceptInput(int pThis, Handle hReturn, Handle hParams) +{ + // Should not happen? + if(DHookIsNullParam(hParams, 2)) + { + LogError("AcceptInput pActivator = NULL"); + return MRES_Ignored; + } + int client = DHookGetParam(hParams, 2); + + char szInputName[32]; + DHookGetParamString(hParams, 1, szInputName, sizeof(szInputName)); + + if(!StrEqual(szInputName, "addoutput", false)) + return MRES_Ignored; + + char sValue[128]; + DHookGetParamObjectPtrString(hParams, 4, 0, ObjectValueType_String, sValue, sizeof(sValue)); + int iValueLen = strlen(sValue); + + int aArgs[4] = {0, ...}; + int iArgs = 0; + bool bFound = false; + + for(int i = 0; i < iValueLen; i++) + { + if(sValue[i] == ' ') + { + if(bFound) + { + sValue[i] = '\0'; + bFound = false; + + if(iArgs > sizeof(aArgs)) + break; + } + continue; + } + + if(!bFound) + { + aArgs[iArgs++] = i; + bFound = true; + } + } + + if(strncmp(sValue[aArgs[0]], "rendercolor", 11, false) == 0) + { + int aColor[3]; + aColor[0] = StringToInt(sValue[aArgs[1]]) & 0xFF; + aColor[1] = StringToInt(sValue[aArgs[2]]) & 0xFF; + aColor[2] = StringToInt(sValue[aArgs[3]]) & 0xFF; + + if(aColor[0] == 255 && aColor[1] == 255 && aColor[2] == 255) + { + ApplyGlowColor(client); + DHookSetReturn(hReturn, true); + return MRES_Supercede; + } + } + else if(StrEqual(sValue[aArgs[0]], "rendermode", false)) + { + int renderMode = StringToInt(sValue[aArgs[1]]) & 0xFF; + if(renderMode == 0) + { + ApplyGlowColor(client); + return MRES_Ignored; + } + } + + return MRES_Ignored; +} + public Action Command_GlowColors(int client, int args) { if(args < 1) @@ -324,14 +428,6 @@ public void Event_ApplyGlowColor(Event event, const char[] name, bool dontBroadc return; RequestFrame(view_as(ApplyGlowColor), client); - CreateTimer(5.0, Timer_ApplyGlowColor, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE); -} - -public Action Timer_ApplyGlowColor(Handle timer, int serial) -{ - int client = GetClientFromSerial(serial); - if(client) - ApplyGlowColor(client); } public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn)