1.1, Add new natives, entity types

This commit is contained in:
Kyle
2021-03-31 11:42:50 +08:00
parent 0fa5a52caf
commit 1b95cb6fb5
5 changed files with 92 additions and 31 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ jobs:
before_deploy: before_deploy:
- git config --local user.name "Kxnrl" - git config --local user.name "Kxnrl"
- git config --local user.email "[email protected]" - git config --local user.email "[email protected]"
- export TRAVIS_TAG=release-$TRAVIS_BUILD_NUMBER - export TRAVIS_TAG=release-$TRAVIS_OS_NAME-$TRAVIS_BUILD_NUMBER
- git tag $TRAVIS_TAG - git tag $TRAVIS_TAG
deploy: deploy:
provider: releases provider: releases
+4 -1
View File
@@ -6,11 +6,13 @@
native void TransmitManager_AddEntityHooks(int entity); native void TransmitManager_AddEntityHooks(int entity);
native bool TransmitManager_SetEntityOwner(int entity, int target); native bool TransmitManager_SetEntityOwner(int entity, int target);
native bool TransmitManager_SetEntityState(int entity, int client, bool can); native bool TransmitManager_SetEntityState(int entity, int client, bool can);
native bool TransmitManager_GetEntityState(int entity, int client);
native bool TransmitManager_IsEntityHooked(int entity);
/** /**
* _________________Do not edit below this line!_______________________ * _________________Do not edit below this line!_______________________
*/ */
public Extension __ext_movement = public Extension __ext_transmit =
{ {
name = "TransmitManager", name = "TransmitManager",
file = "TransmitManager.ext", file = "TransmitManager.ext",
@@ -25,3 +27,4 @@ public Extension __ext_movement =
required = 0, required = 0,
#endif #endif
}; };
+76 -18
View File
@@ -16,25 +16,46 @@ SH_DECL_MANUALHOOK2_void(SetTransmit, 0, 0, 0, CCheckTransmitInfo*, bool);
struct HookingEntity struct HookingEntity
{ {
HookingEntity(CBaseEntity *pEntity) HookingEntity(CBaseEntity* pEntity)
{ {
bRemoveFlags = false; bRemoveFlags = false;
iOwnerEntity = -1; iOwnerEntity = -1;
iEntityIndex = gamehelpers->EntityToBCompatRef(pEntity); iEntityIndex = gamehelpers->EntityToBCompatRef(pEntity);
SourceHookId = SH_ADD_MANUALHOOK(SetTransmit, pEntity, SH_MEMBER(&g_Transmit, &TransmitManager::Hook_SetTransmit), false); SourceHookId = SH_ADD_MANUALHOOK(SetTransmit, pEntity, SH_MEMBER(&g_Transmit, &TransmitManager::Hook_SetTransmit), false);
for (auto i = 1; i < SM_MAXPLAYERS; i++) // for css, gotv is 65
for (auto i = 1; i <= SM_MAXPLAYERS; i++)
{ {
// can see by default // can see by default
bCanTransmit[i] = true; bCanTransmit[i] = true;
} }
auto *pName = gamehelpers->GetEntityClassname(pEntity); auto* pName = gamehelpers->GetEntityClassname(pEntity);
if (pName != nullptr && (V_strcmp(pName, "info_particle_system") == 0 || V_strcmp(pName, "light_dynamic") == 0)) if (pName != nullptr && (
V_strcasecmp(pName, "info_particle_system") == 0 ||
V_strcasecmp(pName, "light_dynamic") == 0 ||
V_strcasecmp(pName, "env_cascade_light") == 0 ||
V_strcasecmp(pName, "env_projectedtexture") == 0 ||
V_strcasecmp(pName, "env_screenoverlay") == 0 ||
V_strcasecmp(pName, "env_fog_controller") == 0 ||
V_strcasecmp(pName, "env_lightglow") == 0 ||
V_strcasecmp(pName, "env_particlesmokegrenade") == 0 ||
V_strcasecmp(pName, "env_global_light") == 0 ||
V_strcasecmp(pName, "env_sun") == 0 ||
V_strcasecmp(pName, "env_sprite") == 0 ||
V_strcasecmp(pName, "point_camera") == 0 ||
V_strcasecmp(pName, "point_viewproxy") == 0 ||
V_strcasecmp(pName, "inferno") == 0 ||
V_strcasecmp(pName, "sunshine_shadow_control") == 0 ||
V_strcasecmp(pName, "cfe_player_decal") == 0 ||
V_strncasecmp(pName, "point_viewcontrol", 17) == 0 ||
V_strncasecmp(pName, "env_fire", 8) == 0 ||
V_strncasecmp(pName, "color_correction", 16) == 0))
{ {
bRemoveFlags = true; bRemoveFlags = true;
auto *edict = gamehelpers->EdictOfIndex(iEntityIndex); auto* edict = gamehelpers->EdictOfIndex(iEntityIndex);
if (edict) if (edict)
{ {
auto flags = edict->m_fStateFlags; auto flags = edict->m_fStateFlags;
@@ -54,7 +75,8 @@ struct HookingEntity
bool CanSee(int client) bool CanSee(int client)
{ {
if (iEntityIndex == client || iOwnerEntity == client) // remove self bypass
if (iEntityIndex == client) /*|| iOwnerEntity == client*/
{ {
// self or children // self or children
return true; return true;
@@ -86,7 +108,7 @@ struct HookingEntity
private: private:
int SourceHookId; int SourceHookId;
int iEntityIndex; int iEntityIndex;
bool bCanTransmit[SM_MAXPLAYERS]; bool bCanTransmit[SM_MAXPLAYERS + 1];
int iOwnerEntity; int iOwnerEntity;
bool bRemoveFlags; bool bRemoveFlags;
}; };
@@ -95,9 +117,9 @@ HookingEntity* g_Hooked[MAX_EDICTS];
void TransmitManager::Hook_SetTransmit(CCheckTransmitInfo* pInfo, bool bAlways) void TransmitManager::Hook_SetTransmit(CCheckTransmitInfo* pInfo, bool bAlways)
{ {
auto *bcref = META_IFACEPTR(CBaseEntity); auto* bcref = META_IFACEPTR(CBaseEntity);
auto entity = gamehelpers->EntityToBCompatRef(bcref); auto entity = gamehelpers->EntityToBCompatRef(bcref);
auto *edict = gamehelpers->EdictOfIndex(entity); auto* edict = gamehelpers->EdictOfIndex(entity);
auto client = gamehelpers->IndexOfEdict(pInfo->m_pClientEnt); auto client = gamehelpers->IndexOfEdict(pInfo->m_pClientEnt);
if (!IsEntityIndexInRange(entity) || client == entity || !edict || edict->IsFree()) if (!IsEntityIndexInRange(entity) || client == entity || !edict || edict->IsFree())
@@ -139,7 +161,7 @@ void TransmitManager::Hook_SetTransmit(CCheckTransmitInfo* pInfo, bool bAlways)
RETURN_META(MRES_IGNORED); RETURN_META(MRES_IGNORED);
} }
bool TransmitManager::SDK_OnLoad(char *error, size_t maxlength, bool late) bool TransmitManager::SDK_OnLoad(char* error, size_t maxlength, bool late)
{ {
sharesys->AddDependency(myself, "sdkhooks.ext", true, true); sharesys->AddDependency(myself, "sdkhooks.ext", true, true);
SM_GET_IFACE(SDKHOOKS, g_pSDKHooks) SM_GET_IFACE(SDKHOOKS, g_pSDKHooks)
@@ -224,7 +246,7 @@ void TransmitManager::OnEntityDestroyed(CBaseEntity* pEntity)
void TransmitManager::OnClientPutInServer(int client) void TransmitManager::OnClientPutInServer(int client)
{ {
auto *pPlayer = playerhelpers->GetGamePlayer(client); auto* pPlayer = playerhelpers->GetGamePlayer(client);
if (!pPlayer || pPlayer->IsSourceTV() || pPlayer->IsReplay()) if (!pPlayer || pPlayer->IsSourceTV() || pPlayer->IsReplay())
{ {
return; return;
@@ -297,7 +319,7 @@ void TransmitManager::UnhookEntity(int index)
static cell_t Native_SetEntityOwner(IPluginContext* pContext, const cell_t* params) static cell_t Native_SetEntityOwner(IPluginContext* pContext, const cell_t* params)
{ {
if (!(params[1] >= 1 && params[1] < MAX_EDICTS)) if (!IsEntityIndexInRange(params[1]))
{ {
// out-of-range // out-of-range
return pContext->ThrowNativeError("Entity %d is out-of-range.", params[1]); return pContext->ThrowNativeError("Entity %d is out-of-range.", params[1]);
@@ -309,7 +331,7 @@ static cell_t Native_SetEntityOwner(IPluginContext* pContext, const cell_t* para
return true; return true;
} }
if (params[1] >= 1 && params[1] < SM_MAXPLAYERS) if (params[1] >= 1 && params[1] < playerhelpers->GetMaxClients())
{ {
smutils->LogError(myself, "Entity %d is not being hook.", params[1]); smutils->LogError(myself, "Entity %d is not being hook.", params[1]);
return false; return false;
@@ -320,13 +342,13 @@ static cell_t Native_SetEntityOwner(IPluginContext* pContext, const cell_t* para
static cell_t Native_SetEntityState(IPluginContext* pContext, const cell_t* params) static cell_t Native_SetEntityState(IPluginContext* pContext, const cell_t* params)
{ {
if (!(params[1] >= 1 && params[1] < MAX_EDICTS)) if (!IsEntityIndexInRange(params[1]))
{ {
// out-of-range // out-of-range
return pContext->ThrowNativeError("Entity %d is out-of-range.", params[1]); return pContext->ThrowNativeError("Entity %d is out-of-range.", params[1]);
} }
auto *pPlayer = playerhelpers->GetGamePlayer(params[2]); auto* pPlayer = playerhelpers->GetGamePlayer(params[2]);
if (!pPlayer || !pPlayer->IsInGame()) if (!pPlayer || !pPlayer->IsInGame())
{ {
return pContext->ThrowNativeError("Client %d is invalid.", params[2]); return pContext->ThrowNativeError("Client %d is invalid.", params[2]);
@@ -338,7 +360,7 @@ static cell_t Native_SetEntityState(IPluginContext* pContext, const cell_t* para
return true; return true;
} }
if (params[1] >= 1 && params[1] < SM_MAXPLAYERS) if (params[1] >= 1 && params[1] < playerhelpers->GetMaxClients())
{ {
smutils->LogError(myself, "Entity %d is not being hook.", params[1]); smutils->LogError(myself, "Entity %d is not being hook.", params[1]);
return false; return false;
@@ -349,13 +371,13 @@ static cell_t Native_SetEntityState(IPluginContext* pContext, const cell_t* para
static cell_t Native_AddEntityHooks(IPluginContext* pContext, const cell_t* params) static cell_t Native_AddEntityHooks(IPluginContext* pContext, const cell_t* params)
{ {
if (!(params[1] >= 1 && params[1] < MAX_EDICTS)) if (!IsEntityIndexInRange(params[1]))
{ {
// out-of-range // out-of-range
return pContext->ThrowNativeError("Entity %d is out-of-range.", params[1]); return pContext->ThrowNativeError("Entity %d is out-of-range.", params[1]);
} }
auto *pEntity = gamehelpers->ReferenceToEntity(params[1]); auto* pEntity = gamehelpers->ReferenceToEntity(params[1]);
if (!pEntity) if (!pEntity)
{ {
// nuull // nuull
@@ -367,10 +389,46 @@ static cell_t Native_AddEntityHooks(IPluginContext* pContext, const cell_t* para
return 0; return 0;
} }
static cell_t Native_GetEntityState(IPluginContext* pContext, const cell_t* params)
{
if (!IsEntityIndexInRange(params[1]))
{
// out-of-range
return pContext->ThrowNativeError("Entity %d is out-of-range.", params[1]);
}
auto* pPlayer = playerhelpers->GetGamePlayer(params[2]);
if (!pPlayer || !pPlayer->IsInGame())
{
return pContext->ThrowNativeError("Client %d is invalid.", params[2]);
}
if (g_Hooked[params[1]] == nullptr)
{
// can see
return true;
}
return g_Hooked[params[1]]->CanSee(params[2]);
}
static cell_t Native_IsEntityHooked(IPluginContext* pContext, const cell_t* params)
{
if (!IsEntityIndexInRange(params[1]))
{
// out-of-range
return pContext->ThrowNativeError("Entity %d is out-of-range.", params[1]);
}
return g_Hooked[params[1]] != nullptr;
}
sp_nativeinfo_t g_Natives[] = sp_nativeinfo_t g_Natives[] =
{ {
{"TransmitManager_AddEntityHooks", Native_AddEntityHooks}, {"TransmitManager_AddEntityHooks", Native_AddEntityHooks},
{"TransmitManager_SetEntityOwner", Native_SetEntityOwner}, {"TransmitManager_SetEntityOwner", Native_SetEntityOwner},
{"TransmitManager_SetEntityState", Native_SetEntityState}, {"TransmitManager_SetEntityState", Native_SetEntityState},
{"TransmitManager_GetEntityState", Native_GetEntityState},
{"TransmitManager_IsEntityHooked", Native_IsEntityHooked},
{nullptr, nullptr}, {nullptr, nullptr},
}; };
+1 -1
View File
@@ -27,6 +27,6 @@ private:
void UnhookEntity(int index); void UnhookEntity(int index);
}; };
inline bool IsEntityIndexInRange(int i) { return i >= 1 && i < 2048; } inline bool IsEntityIndexInRange(int i) { return i >= 1 && i < MAX_EDICTS; }
#endif #endif
+1 -1
View File
@@ -3,7 +3,7 @@
#define SMEXT_CONF_NAME "Transmit Manager" #define SMEXT_CONF_NAME "Transmit Manager"
#define SMEXT_CONF_DESCRIPTION "" #define SMEXT_CONF_DESCRIPTION ""
#define SMEXT_CONF_VERSION "1.0.1" #define SMEXT_CONF_VERSION "1.1"
#define SMEXT_CONF_AUTHOR "Kyle \"Kxnrl\" Frankiss" #define SMEXT_CONF_AUTHOR "Kyle \"Kxnrl\" Frankiss"
#define SMEXT_CONF_URL "https://www.kxnrl.com" #define SMEXT_CONF_URL "https://www.kxnrl.com"
#define SMEXT_CONF_LOGTAG "TransmitManager" #define SMEXT_CONF_LOGTAG "TransmitManager"