Engine: Dynamically hook StartFrame for set_lights()
This commit is contained in:
parent
c5f6e26802
commit
c531ad756d
|
@ -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);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -118,7 +118,6 @@ struct PlayerInfo {
|
|||
};
|
||||
|
||||
struct GlobalInfo {
|
||||
float fNextLights;
|
||||
char szLastLights[128];
|
||||
char szRealLights[128];
|
||||
bool bCheckLights;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user