From c531ad756d70338cc2bc8bb2952e37392eb187a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Gr=C3=BCnbacher?= Date: Sun, 10 May 2015 23:21:12 +0200 Subject: [PATCH] Engine: Dynamically hook StartFrame for set_lights() --- modules/engine/amxxapi.cpp | 11 ++++++----- modules/engine/engine.cpp | 10 ++++------ modules/engine/engine.h | 1 - modules/engine/forwards.cpp | 11 ++--------- modules/engine/moduleconfig.h | 4 ++-- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/modules/engine/amxxapi.cpp b/modules/engine/amxxapi.cpp index b21ab8cf..259978e2 100644 --- a/modules/engine/amxxapi.cpp +++ b/modules/engine/amxxapi.cpp @@ -57,7 +57,6 @@ void OnAmxxAttach() MF_AddNatives(global_Natives); memset(glinfo.szLastLights, 0x0, 128); memset(glinfo.szRealLights, 0x0, 128); - glinfo.fNextLights = 0; glinfo.bCheckLights = false; } @@ -197,7 +196,6 @@ void ServerDeactivate() memset(glinfo.szLastLights, 0x0, 128); memset(glinfo.szRealLights, 0x0, 128); glinfo.bCheckLights = false; - glinfo.fNextLights = 0; // Reset all forwarding function tables (so that forwards won't be called before plugins are initialized) g_pFunctionTable->pfnAddToFullPack=NULL; @@ -226,10 +224,13 @@ void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax) RETURN_META(MRES_IGNORED); } -void LightStyle(int style, const char *val) { - if (!style) { +void LightStyle_Post(int style, const char *val) { + if (!style && strcmp(val, glinfo.szRealLights)) { memset(glinfo.szRealLights, 0x0, 128); - memcpy(glinfo.szRealLights, val, strlen(val)); + memcpy(glinfo.szRealLights, val, min(strlen(val), 127)); + + if (glinfo.bCheckLights && strcmp(val, glinfo.szLastLights)) + g_pFunctionTable_Post->pfnStartFrame = StartFrame_Post; } RETURN_META(MRES_IGNORED); diff --git a/modules/engine/engine.cpp b/modules/engine/engine.cpp index 042dfa8e..8c8b6f34 100644 --- a/modules/engine/engine.cpp +++ b/modules/engine/engine.cpp @@ -493,19 +493,17 @@ static cell AMX_NATIVE_CALL set_lights(AMX *amx, cell *params) { glinfo.bCheckLights = false; g_pFunctionTable_Post->pfnStartFrame = NULL; memset(glinfo.szLastLights, 0x0, 128); - (g_engfuncs.pfnLightStyle)(0, glinfo.szRealLights); + LIGHT_STYLE(0, glinfo.szRealLights); return 1; } - g_pFunctionTable_Post->pfnStartFrame = StartFrame_Post; glinfo.bCheckLights = true; - //Reset LastLights + //Reset LastLights and store custom lighting memset(glinfo.szLastLights, 0x0, 128); - //Store the previous lighting. - memcpy(glinfo.szLastLights, szLights, strlen(szLights)); + memcpy(glinfo.szLastLights, szLights, min(iLength, 127)); - (g_engfuncs.pfnLightStyle)(0, szLights); + LIGHT_STYLE(0, szLights); // These make it so that players/weaponmodels look like whatever the lighting is // at. otherwise it would color players under the skybox to these values. diff --git a/modules/engine/engine.h b/modules/engine/engine.h index d0415445..2ea243d8 100644 --- a/modules/engine/engine.h +++ b/modules/engine/engine.h @@ -118,7 +118,6 @@ struct PlayerInfo { }; struct GlobalInfo { - float fNextLights; char szLastLights[128]; char szRealLights[128]; bool bCheckLights; diff --git a/modules/engine/forwards.cpp b/modules/engine/forwards.cpp index a5b6c22c..34faf6c4 100644 --- a/modules/engine/forwards.cpp +++ b/modules/engine/forwards.cpp @@ -120,15 +120,8 @@ void StartFrame() void StartFrame_Post() { - if (glinfo.bCheckLights) - { - if (glinfo.fNextLights < gpGlobals->time) - { - (g_engfuncs.pfnLightStyle)(0, glinfo.szLastLights); - glinfo.fNextLights = gpGlobals->time + 1; - } - } - + g_pFunctionTable_Post->pfnStartFrame = NULL; + LIGHT_STYLE(0, glinfo.szLastLights); RETURN_META(MRES_IGNORED); } diff --git a/modules/engine/moduleconfig.h b/modules/engine/moduleconfig.h index 827f3234..72e5796f 100644 --- a/modules/engine/moduleconfig.h +++ b/modules/engine/moduleconfig.h @@ -243,7 +243,7 @@ // #define FN_ServerExecute ServerExecute // #define FN_engClientCommand engClientCommand // #define FN_ParticleEffect ParticleEffect -#define FN_LightStyle LightStyle +// #define FN_LightStyle LightStyle // #define FN_DecalIndex DecalIndex // #define FN_PointContents PointContents // #define FN_MessageBegin MessageBegin @@ -389,7 +389,7 @@ // #define FN_ServerExecute_Post ServerExecute_Post // #define FN_engClientCommand_Post engClientCommand_Post // #define FN_ParticleEffect_Post ParticleEffect_Post -// #define FN_LightStyle_Post LightStyle_Post +#define FN_LightStyle_Post LightStyle_Post // #define FN_DecalIndex_Post DecalIndex_Post // #define FN_PointContents_Post PointContents_Post // #define FN_MessageBegin_Post MessageBegin_Post