Add native `TransmitManager_RemoveEntHooks`
This commit is contained in:
+47
-21
@@ -18,16 +18,16 @@ struct HookingEntity
|
|||||||
{
|
{
|
||||||
HookingEntity(CBaseEntity* pEntity)
|
HookingEntity(CBaseEntity* pEntity)
|
||||||
{
|
{
|
||||||
bRemoveFlags = false;
|
m_bRemoveFlags = false;
|
||||||
iOwnerEntity = -1;
|
m_nOwnerEntity = -1;
|
||||||
iEntityIndex = gamehelpers->EntityToBCompatRef(pEntity);
|
m_iEntityIndex = gamehelpers->EntityToBCompatRef(pEntity);
|
||||||
SourceHookId = SH_ADD_MANUALHOOK(SetTransmit, pEntity, SH_MEMBER(&g_Transmit, &TransmitManager::Hook_SetTransmit), false);
|
m_iHookId = SH_ADD_MANUALHOOK(SetTransmit, pEntity, SH_MEMBER(&g_Transmit, &TransmitManager::Hook_SetTransmit), false);
|
||||||
|
|
||||||
// for css, gotv is 65
|
// for css, gotv is 65
|
||||||
for (auto i = 1; i <= SM_MAXPLAYERS; i++)
|
for (auto i = 1; i <= SM_MAXPLAYERS; i++)
|
||||||
{
|
{
|
||||||
// can see by default
|
// can see by default
|
||||||
bCanTransmit[i] = true;
|
m_bCanTransmit[i] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* pName = gamehelpers->GetEntityClassname(pEntity);
|
auto* pName = gamehelpers->GetEntityClassname(pEntity);
|
||||||
@@ -57,9 +57,9 @@ struct HookingEntity
|
|||||||
V_strncasecmp(pName, "env_fire", 8) == 0 ||
|
V_strncasecmp(pName, "env_fire", 8) == 0 ||
|
||||||
V_strncasecmp(pName, "color_correction", 16) == 0))
|
V_strncasecmp(pName, "color_correction", 16) == 0))
|
||||||
{
|
{
|
||||||
bRemoveFlags = true;
|
m_bRemoveFlags = true;
|
||||||
|
|
||||||
auto* edict = gamehelpers->EdictOfIndex(iEntityIndex);
|
auto* edict = gamehelpers->EdictOfIndex(m_iEntityIndex);
|
||||||
if (edict)
|
if (edict)
|
||||||
{
|
{
|
||||||
auto flags = edict->m_fStateFlags;
|
auto flags = edict->m_fStateFlags;
|
||||||
@@ -70,51 +70,51 @@ struct HookingEntity
|
|||||||
|
|
||||||
~HookingEntity()
|
~HookingEntity()
|
||||||
{
|
{
|
||||||
if (SourceHookId)
|
if (m_iHookId)
|
||||||
{
|
{
|
||||||
SH_REMOVE_HOOK_ID(SourceHookId);
|
SH_REMOVE_HOOK_ID(m_iHookId);
|
||||||
SourceHookId = 0;
|
m_iHookId = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CanSee(int client)
|
bool CanSee(int client)
|
||||||
{
|
{
|
||||||
// remove self bypass
|
// remove self bypass
|
||||||
if (iEntityIndex == client) /*|| iOwnerEntity == client*/
|
if (m_iEntityIndex == client)
|
||||||
{
|
{
|
||||||
// self or children
|
// self or children
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bCanTransmit[client];
|
return m_bCanTransmit[client];
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetSee(int client, bool can)
|
void SetSee(int client, bool can)
|
||||||
{
|
{
|
||||||
bCanTransmit[client] = can;
|
m_bCanTransmit[client] = can;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetOwner()
|
int GetOwner()
|
||||||
{
|
{
|
||||||
return iOwnerEntity;
|
return m_nOwnerEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetOwner(int owner)
|
void SetOwner(int owner)
|
||||||
{
|
{
|
||||||
iOwnerEntity = owner;
|
m_nOwnerEntity = owner;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShouldRemove()
|
bool ShouldRemove()
|
||||||
{
|
{
|
||||||
return bRemoveFlags;
|
return m_bRemoveFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int SourceHookId;
|
int m_iHookId;
|
||||||
int iEntityIndex;
|
int m_iEntityIndex;
|
||||||
bool bCanTransmit[SM_MAXPLAYERS + 1];
|
bool m_bCanTransmit[SM_MAXPLAYERS + 1];
|
||||||
int iOwnerEntity;
|
int m_nOwnerEntity;
|
||||||
bool bRemoveFlags;
|
bool m_bRemoveFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
HookingEntity* g_Hooked[MAX_EDICTS];
|
HookingEntity* g_Hooked[MAX_EDICTS];
|
||||||
@@ -393,6 +393,31 @@ static cell_t Native_AddEntityHooks(IPluginContext* pContext, const cell_t* para
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static cell_t Native_RemoveEntHooks(IPluginContext* pContext, const cell_t* params)
|
||||||
|
{
|
||||||
|
const auto index = params[1];
|
||||||
|
|
||||||
|
if (!IsEntityIndexInRange(index))
|
||||||
|
{
|
||||||
|
// out-of-range
|
||||||
|
return pContext->ThrowNativeError("Entity %d is out-of-range.", index);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* pEntity = gamehelpers->ReferenceToEntity(index);
|
||||||
|
if (!pEntity)
|
||||||
|
{
|
||||||
|
// nuull
|
||||||
|
return pContext->ThrowNativeError("Entity %d is invalid.", index);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_Hooked[index] != nullptr)
|
||||||
|
{
|
||||||
|
delete g_Hooked[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static cell_t Native_GetEntityState(IPluginContext* pContext, const cell_t* params)
|
static cell_t Native_GetEntityState(IPluginContext* pContext, const cell_t* params)
|
||||||
{
|
{
|
||||||
if (!IsEntityIndexInRange(params[1]))
|
if (!IsEntityIndexInRange(params[1]))
|
||||||
@@ -430,6 +455,7 @@ static cell_t Native_IsEntityHooked(IPluginContext* pContext, const cell_t* para
|
|||||||
sp_nativeinfo_t g_Natives[] =
|
sp_nativeinfo_t g_Natives[] =
|
||||||
{
|
{
|
||||||
{"TransmitManager_AddEntityHooks", Native_AddEntityHooks},
|
{"TransmitManager_AddEntityHooks", Native_AddEntityHooks},
|
||||||
|
{"TransmitManager_RemoveEntHooks", Native_RemoveEntHooks},
|
||||||
{"TransmitManager_SetEntityOwner", Native_SetEntityOwner},
|
{"TransmitManager_SetEntityOwner", Native_SetEntityOwner},
|
||||||
{"TransmitManager_SetEntityState", Native_SetEntityState},
|
{"TransmitManager_SetEntityState", Native_SetEntityState},
|
||||||
{"TransmitManager_GetEntityState", Native_GetEntityState},
|
{"TransmitManager_GetEntityState", Native_GetEntityState},
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<ProjectGuid>{B3E797CF-4E77-4C9D-B8A8-7589B6902206}</ProjectGuid>
|
<ProjectGuid>{B3E797CF-4E77-4C9D-B8A8-7589B6902206}</ProjectGuid>
|
||||||
<RootNamespace>TransmitManager</RootNamespace>
|
<RootNamespace>TransmitManager</RootNamespace>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
<ProjectName>TransmitManager</ProjectName>
|
<ProjectName>TransmitManager</ProjectName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
@@ -22,10 +22,10 @@
|
|||||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<PlatformToolset>v142</PlatformToolset>
|
<PlatformToolset>v143</PlatformToolset>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
|||||||
Reference in New Issue
Block a user