Engine: Detour LightStyle to catch all calls, restores set_lights() functionality
This commit is contained in:
parent
8b6d85eb78
commit
7059f5b3b9
|
@ -14,6 +14,9 @@ binary.sources = [
|
|||
'entity.cpp',
|
||||
'globals.cpp',
|
||||
'forwards.cpp',
|
||||
'../../public/memtools/MemoryUtils.cpp',
|
||||
'../../public/memtools/CDetour/detours.cpp',
|
||||
'../../public/memtools/CDetour/asm/asm.c',
|
||||
]
|
||||
|
||||
if builder.target_platform == 'windows':
|
||||
|
|
|
@ -30,7 +30,7 @@ CPP_OSX = clang
|
|||
|
||||
LINK =
|
||||
|
||||
INCLUDE = -I. -I$(PUBLIC_ROOT) -I$(PUBLIC_ROOT)/sdk -I$(PUBLIC_ROOT)/amtl \
|
||||
INCLUDE = -I. -I$(PUBLIC_ROOT) -I$(PUBLIC_ROOT)/sdk -I$(PUBLIC_ROOT)/memtools -I$(PUBLIC_ROOT)/memtools/CDetour -I$(PUBLIC_ROOT)/memtools/CDetour/asm -I$(PUBLIC_ROOT)/amtl \
|
||||
-I$(HLSDK) -I$(HLSDK)/public -I$(HLSDK)/common -I$(HLSDK)/dlls -I$(HLSDK)/engine -I$(HLSDK)/game_shared -I$(HLSDK)/pm_shared\
|
||||
-I$(MM_ROOT)
|
||||
|
||||
|
@ -108,6 +108,9 @@ $(BIN_DIR)/%.o: %.cpp
|
|||
all:
|
||||
mkdir -p $(BIN_DIR)
|
||||
ln -sf $(PUBLIC_ROOT)/sdk/amxxmodule.cpp
|
||||
ln -sf $(PUBLIC_ROOT)/memtools/MemoryUtils.cpp
|
||||
ln -sf $(PUBLIC_ROOT)/memtools/CDetour/detours.cpp
|
||||
ln -sf $(PUBLIC_ROOT)/memtools/CDetour/asm/asm.c
|
||||
$(MAKE) -f $(MAKEFILE_NAME) $(PROJECT)
|
||||
|
||||
$(PROJECT): $(OBJ_BIN)
|
||||
|
|
|
@ -14,6 +14,10 @@
|
|||
#include "engine.h"
|
||||
|
||||
BOOL CheckForPublic(const char *publicname);
|
||||
void CreateDetours();
|
||||
void DestroyDetours();
|
||||
|
||||
CDetour *LightStyleDetour = NULL;
|
||||
|
||||
edict_t *g_player_edicts[33];
|
||||
|
||||
|
@ -58,6 +62,13 @@ void OnAmxxAttach()
|
|||
memset(glinfo.szLastLights, 0x0, 128);
|
||||
memset(glinfo.szRealLights, 0x0, 128);
|
||||
glinfo.bCheckLights = false;
|
||||
|
||||
CreateDetours();
|
||||
}
|
||||
|
||||
void OnAmxxDetach()
|
||||
{
|
||||
DestroyDetours();
|
||||
}
|
||||
|
||||
void OnPluginsLoaded()
|
||||
|
@ -209,7 +220,6 @@ void ServerDeactivate()
|
|||
g_pFunctionTable->pfnThink=NULL; // "pfn_think", "register_think"
|
||||
g_pFunctionTable->pfnStartFrame=NULL; // "server_frame","ServerFrame"
|
||||
g_pFunctionTable->pfnTouch=NULL; // "pfn_touch","vexd_pfntouch"
|
||||
g_pFunctionTable_Post->pfnStartFrame = NULL; // "set_lights"
|
||||
|
||||
ClearHooks();
|
||||
|
||||
|
@ -224,15 +234,27 @@ void ServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
|
|||
RETURN_META(MRES_IGNORED);
|
||||
}
|
||||
|
||||
void LightStyle_Post(int style, const char *val) {
|
||||
DETOUR_DECL_STATIC2(LightStyle, void, int, style, const char *, val) // void (*pfnLightStyle) (int style, const char* val);
|
||||
{
|
||||
DETOUR_STATIC_CALL(LightStyle)(style, val);
|
||||
|
||||
if (!style && strcmp(val, glinfo.szRealLights)) {
|
||||
memset(glinfo.szRealLights, 0x0, 128);
|
||||
memcpy(glinfo.szRealLights, val, min(strlen(val), 127));
|
||||
memcpy(glinfo.szRealLights, val, ke::Min(strlen(val), (size_t)127));
|
||||
}
|
||||
|
||||
if (glinfo.bCheckLights && strcmp(val, glinfo.szLastLights))
|
||||
g_pFunctionTable_Post->pfnStartFrame = StartFrame_Post;
|
||||
}
|
||||
|
||||
void StartFrame_Post()
|
||||
{
|
||||
g_pFunctionTable_Post->pfnStartFrame = NULL;
|
||||
|
||||
LightStyleDetour->DisableDetour();
|
||||
LIGHT_STYLE(0, glinfo.szLastLights);
|
||||
LightStyleDetour->EnableDetour();
|
||||
|
||||
RETURN_META(MRES_IGNORED);
|
||||
}
|
||||
|
||||
|
@ -256,3 +278,13 @@ BOOL CheckForPublic(const char *publicname)
|
|||
|
||||
return FALSE; // no public found in any loaded script
|
||||
}
|
||||
|
||||
void CreateDetours()
|
||||
{
|
||||
LightStyleDetour = DETOUR_CREATE_STATIC_FIXED(LightStyle, (void*)(g_engfuncs.pfnLightStyle));
|
||||
}
|
||||
|
||||
void DestroyDetours()
|
||||
{
|
||||
LightStyleDetour->Destroy();
|
||||
}
|
|
@ -300,8 +300,9 @@ static cell AMX_NATIVE_CALL trace_normal(AMX *amx, cell *params)
|
|||
static cell AMX_NATIVE_CALL trace_line(AMX *amx, cell *params)
|
||||
{
|
||||
int iEnt = params[1];
|
||||
if (iEnt != -1)
|
||||
if (iEnt != -1) {
|
||||
CHECK_ENTITY(iEnt);
|
||||
}
|
||||
|
||||
cell *cStart = MF_GetAmxAddr(amx, params[2]);
|
||||
cell *cEnd = MF_GetAmxAddr(amx, params[3]);
|
||||
|
@ -370,8 +371,9 @@ static cell AMX_NATIVE_CALL get_info_keybuffer(AMX *amx, cell *params)
|
|||
{
|
||||
int iEnt = params[1];
|
||||
|
||||
if (iEnt != -1)
|
||||
if (iEnt != -1) {
|
||||
CHECK_ENTITY(iEnt);
|
||||
}
|
||||
|
||||
char *info = GETINFOKEYBUFFER((iEnt == -1) ? NULL : INDEXENT2(iEnt));
|
||||
|
||||
|
@ -546,7 +548,6 @@ static cell AMX_NATIVE_CALL set_lights(AMX *amx, cell *params) {
|
|||
|
||||
if (FStrEq(szLights, "#OFF")) {
|
||||
glinfo.bCheckLights = false;
|
||||
g_pFunctionTable_Post->pfnStartFrame = NULL;
|
||||
memset(glinfo.szLastLights, 0x0, 128);
|
||||
LIGHT_STYLE(0, glinfo.szRealLights);
|
||||
return 1;
|
||||
|
@ -556,9 +557,11 @@ static cell AMX_NATIVE_CALL set_lights(AMX *amx, cell *params) {
|
|||
|
||||
//Reset LastLights and store custom lighting
|
||||
memset(glinfo.szLastLights, 0x0, 128);
|
||||
memcpy(glinfo.szLastLights, szLights, min(iLength, 127));
|
||||
memcpy(glinfo.szLastLights, szLights, ke::Min(iLength, 127));
|
||||
|
||||
LightStyleDetour->DisableDetour();
|
||||
LIGHT_STYLE(0, szLights);
|
||||
LightStyleDetour->EnableDetour();
|
||||
|
||||
// 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.
|
||||
|
@ -573,8 +576,9 @@ static cell AMX_NATIVE_CALL set_lights(AMX *amx, cell *params) {
|
|||
static cell AMX_NATIVE_CALL trace_hull(AMX *amx,cell *params)
|
||||
{
|
||||
int iEnt = params[3];
|
||||
if (iEnt > 0)
|
||||
if (iEnt > 0) {
|
||||
CHECK_ENTITY(iEnt);
|
||||
}
|
||||
|
||||
int iResult=0;
|
||||
Vector vStart;
|
||||
|
@ -950,8 +954,9 @@ static cell AMX_NATIVE_CALL trace_forward(AMX *amx, cell *params)
|
|||
cell *cAngles = MF_GetAmxAddr(amx, params[2]);
|
||||
REAL fGive = amx_ctof(params[3]);
|
||||
int iIgnoreEnt = params[4];
|
||||
if (iIgnoreEnt != -1)
|
||||
if (iIgnoreEnt != -1) {
|
||||
CHECK_ENTITY(iIgnoreEnt);
|
||||
}
|
||||
|
||||
cell *hitX = MF_GetAmxAddr(amx, params[5]);
|
||||
cell *hitY = MF_GetAmxAddr(amx, params[6]);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "entity_state.h"
|
||||
#include <am-vector.h>
|
||||
#include <am-string.h>
|
||||
#include "CDetour/detours.h"
|
||||
|
||||
extern DLL_FUNCTIONS *g_pFunctionTable;
|
||||
extern DLL_FUNCTIONS *g_pFunctionTable_Post;
|
||||
|
@ -47,6 +48,8 @@ extern int DispatchUseForward;
|
|||
extern int VexdTouchForward;
|
||||
extern int VexdServerForward;
|
||||
|
||||
extern CDetour *LightStyleDetour;
|
||||
|
||||
#define AMS_OFFSET 0.01
|
||||
|
||||
#define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
|
||||
|
|
|
@ -118,13 +118,6 @@ void StartFrame()
|
|||
RETURN_META(MRES_IGNORED);
|
||||
}
|
||||
|
||||
void StartFrame_Post()
|
||||
{
|
||||
g_pFunctionTable_Post->pfnStartFrame = NULL;
|
||||
LIGHT_STYLE(0, glinfo.szLastLights);
|
||||
RETURN_META(MRES_IGNORED);
|
||||
}
|
||||
|
||||
void CmdStart(const edict_t *player, const struct usercmd_s *_cmd, unsigned int random_seed)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\;..\..\..\public;..\..\..\public\sdk; ..\..\..\public\amtl\include;..\..\third_party;..\..\third_party\hashing;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\;..\..\..\public;..\..\..\public\memtools;..\..\..\public\sdk;..\..\..\public\amtl\include;..\..\third_party;..\..\third_party\hashing;$(METAMOD)\metamod;$(HLSDK)\common;$(HLSDK)\engine;$(HLSDK)\dlls;$(HLSDK)\pm_shared;$(HLSDK)\public;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;ENGINE_EXPORTS;HAVE_STDINT_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
|
@ -98,6 +98,9 @@
|
|||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\public\memtools\CDetour\asm\asm.c" />
|
||||
<ClCompile Include="..\..\..\public\memtools\CDetour\detours.cpp" />
|
||||
<ClCompile Include="..\..\..\public\memtools\MemoryUtils.cpp" />
|
||||
<ClCompile Include="..\amxxapi.cpp" />
|
||||
<ClCompile Include="..\engine.cpp" />
|
||||
<ClCompile Include="..\entity.cpp" />
|
||||
|
@ -106,6 +109,10 @@
|
|||
<ClCompile Include="..\..\..\public\sdk\amxxmodule.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\public\memtools\CDetour\asm\asm.h" />
|
||||
<ClInclude Include="..\..\..\public\memtools\CDetour\detourhelpers.h" />
|
||||
<ClInclude Include="..\..\..\public\memtools\CDetour\detours.h" />
|
||||
<ClInclude Include="..\..\..\public\memtools\MemoryUtils.h" />
|
||||
<ClInclude Include="..\engine.h" />
|
||||
<ClInclude Include="..\entity.h" />
|
||||
<ClInclude Include="..\gpglobals.h" />
|
||||
|
|
|
@ -18,6 +18,15 @@
|
|||
<Filter Include="Pawn Includes">
|
||||
<UniqueIdentifier>{e7f2c5c2-cba9-4712-a576-ceb676c94b36}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Memtools">
|
||||
<UniqueIdentifier>{ca6abf66-eee2-4d06-813e-792d82d6e846}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Memtools\CDetour">
|
||||
<UniqueIdentifier>{59354b8c-0925-4d8b-bb2b-684f6638de6b}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Memtools\CDetour\asm">
|
||||
<UniqueIdentifier>{6c2c3c74-4dc3-45bf-b3a5-6224971eee69}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\amxxapi.cpp">
|
||||
|
@ -38,6 +47,15 @@
|
|||
<ClCompile Include="..\..\..\public\sdk\amxxmodule.cpp">
|
||||
<Filter>Module SDK\SDK Base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\public\memtools\MemoryUtils.cpp">
|
||||
<Filter>Memtools</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\public\memtools\CDetour\detours.cpp">
|
||||
<Filter>Memtools\CDetour</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\public\memtools\CDetour\asm\asm.c">
|
||||
<Filter>Memtools\CDetour\asm</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\engine.h">
|
||||
|
@ -55,6 +73,18 @@
|
|||
<ClInclude Include="..\..\..\public\sdk\amxxmodule.h">
|
||||
<Filter>Module SDK\SDK Base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\public\memtools\MemoryUtils.h">
|
||||
<Filter>Memtools</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\public\memtools\CDetour\detourhelpers.h">
|
||||
<Filter>Memtools\CDetour</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\public\memtools\CDetour\detours.h">
|
||||
<Filter>Memtools\CDetour</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\public\memtools\CDetour\asm\asm.h">
|
||||
<Filter>Memtools\CDetour\asm</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\..\plugins\include\engine.inc">
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9b1cb728c931c0b42a23b96a3c0909470769a72f
|
||||
Subproject commit 1bb5196ce39ff3ed59445e51f9223734d4bcf886
|
Loading…
Reference in New Issue
Block a user