Engine: Dynamically hook StartFrame for set_lights()

This commit is contained in:
Valentin Grünbacher 2015-05-10 23:21:12 +02:00
parent c5f6e26802
commit c531ad756d
5 changed files with 14 additions and 23 deletions

View File

@ -57,7 +57,6 @@ void OnAmxxAttach()
MF_AddNatives(global_Natives); MF_AddNatives(global_Natives);
memset(glinfo.szLastLights, 0x0, 128); memset(glinfo.szLastLights, 0x0, 128);
memset(glinfo.szRealLights, 0x0, 128); memset(glinfo.szRealLights, 0x0, 128);
glinfo.fNextLights = 0;
glinfo.bCheckLights = false; glinfo.bCheckLights = false;
} }
@ -197,7 +196,6 @@ void ServerDeactivate()
memset(glinfo.szLastLights, 0x0, 128); memset(glinfo.szLastLights, 0x0, 128);
memset(glinfo.szRealLights, 0x0, 128); memset(glinfo.szRealLights, 0x0, 128);
glinfo.bCheckLights = false; glinfo.bCheckLights = false;
glinfo.fNextLights = 0;
// Reset all forwarding function tables (so that forwards won't be called before plugins are initialized) // Reset all forwarding function tables (so that forwards won't be called before plugins are initialized)
g_pFunctionTable->pfnAddToFullPack=NULL; g_pFunctionTable->pfnAddToFullPack=NULL;
@ -226,10 +224,13 @@ void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
void LightStyle(int style, const char *val) { void LightStyle_Post(int style, const char *val) {
if (!style) { if (!style && strcmp(val, glinfo.szRealLights)) {
memset(glinfo.szRealLights, 0x0, 128); 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); RETURN_META(MRES_IGNORED);

View File

@ -493,19 +493,17 @@ static cell AMX_NATIVE_CALL set_lights(AMX *amx, cell *params) {
glinfo.bCheckLights = false; glinfo.bCheckLights = false;
g_pFunctionTable_Post->pfnStartFrame = NULL; g_pFunctionTable_Post->pfnStartFrame = NULL;
memset(glinfo.szLastLights, 0x0, 128); memset(glinfo.szLastLights, 0x0, 128);
(g_engfuncs.pfnLightStyle)(0, glinfo.szRealLights); LIGHT_STYLE(0, glinfo.szRealLights);
return 1; return 1;
} }
g_pFunctionTable_Post->pfnStartFrame = StartFrame_Post;
glinfo.bCheckLights = true; glinfo.bCheckLights = true;
//Reset LastLights //Reset LastLights and store custom lighting
memset(glinfo.szLastLights, 0x0, 128); memset(glinfo.szLastLights, 0x0, 128);
//Store the previous lighting. memcpy(glinfo.szLastLights, szLights, min(iLength, 127));
memcpy(glinfo.szLastLights, szLights, strlen(szLights));
(g_engfuncs.pfnLightStyle)(0, szLights); LIGHT_STYLE(0, szLights);
// These make it so that players/weaponmodels look like whatever the lighting is // 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. // at. otherwise it would color players under the skybox to these values.

View File

@ -118,7 +118,6 @@ struct PlayerInfo {
}; };
struct GlobalInfo { struct GlobalInfo {
float fNextLights;
char szLastLights[128]; char szLastLights[128];
char szRealLights[128]; char szRealLights[128];
bool bCheckLights; bool bCheckLights;

View File

@ -120,15 +120,8 @@ void StartFrame()
void StartFrame_Post() void StartFrame_Post()
{ {
if (glinfo.bCheckLights) g_pFunctionTable_Post->pfnStartFrame = NULL;
{ LIGHT_STYLE(0, glinfo.szLastLights);
if (glinfo.fNextLights < gpGlobals->time)
{
(g_engfuncs.pfnLightStyle)(0, glinfo.szLastLights);
glinfo.fNextLights = gpGlobals->time + 1;
}
}
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }

View File

@ -243,7 +243,7 @@
// #define FN_ServerExecute ServerExecute // #define FN_ServerExecute ServerExecute
// #define FN_engClientCommand engClientCommand // #define FN_engClientCommand engClientCommand
// #define FN_ParticleEffect ParticleEffect // #define FN_ParticleEffect ParticleEffect
#define FN_LightStyle LightStyle // #define FN_LightStyle LightStyle
// #define FN_DecalIndex DecalIndex // #define FN_DecalIndex DecalIndex
// #define FN_PointContents PointContents // #define FN_PointContents PointContents
// #define FN_MessageBegin MessageBegin // #define FN_MessageBegin MessageBegin
@ -389,7 +389,7 @@
// #define FN_ServerExecute_Post ServerExecute_Post // #define FN_ServerExecute_Post ServerExecute_Post
// #define FN_engClientCommand_Post engClientCommand_Post // #define FN_engClientCommand_Post engClientCommand_Post
// #define FN_ParticleEffect_Post ParticleEffect_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_DecalIndex_Post DecalIndex_Post
// #define FN_PointContents_Post PointContents_Post // #define FN_PointContents_Post PointContents_Post
// #define FN_MessageBegin_Post MessageBegin_Post // #define FN_MessageBegin_Post MessageBegin_Post