From 1b95cb6fb5d033b5e4e8d05a0b469b18e2600d5c Mon Sep 17 00:00:00 2001 From: Kyle Date: Wed, 31 Mar 2021 11:42:50 +0800 Subject: [PATCH] 1.1, Add new natives, entity types --- .travis.yml | 2 +- TransmitManager.inc | 5 +- extension.cpp | 112 +++++++++++++++++++++++++++++++++----------- extension.h | 2 +- smsdk_config.h | 2 +- 5 files changed, 92 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index c9a04d9..9af2c05 100644 --- a/.travis.yml +++ b/.travis.yml @@ -42,7 +42,7 @@ jobs: before_deploy: - git config --local user.name "Kxnrl" - git config --local user.email "kyle@kxnrl.com" - - export TRAVIS_TAG=release-$TRAVIS_BUILD_NUMBER + - export TRAVIS_TAG=release-$TRAVIS_OS_NAME-$TRAVIS_BUILD_NUMBER - git tag $TRAVIS_TAG deploy: provider: releases diff --git a/TransmitManager.inc b/TransmitManager.inc index e76ba79..f2e7fb2 100644 --- a/TransmitManager.inc +++ b/TransmitManager.inc @@ -6,11 +6,13 @@ native void TransmitManager_AddEntityHooks(int entity); native bool TransmitManager_SetEntityOwner(int entity, int target); 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!_______________________ */ -public Extension __ext_movement = +public Extension __ext_transmit = { name = "TransmitManager", file = "TransmitManager.ext", @@ -25,3 +27,4 @@ public Extension __ext_movement = required = 0, #endif }; + diff --git a/extension.cpp b/extension.cpp index 82570e3..288a90d 100644 --- a/extension.cpp +++ b/extension.cpp @@ -16,25 +16,46 @@ SH_DECL_MANUALHOOK2_void(SetTransmit, 0, 0, 0, CCheckTransmitInfo*, bool); struct HookingEntity { - HookingEntity(CBaseEntity *pEntity) + HookingEntity(CBaseEntity* pEntity) { bRemoveFlags = false; iOwnerEntity = -1; iEntityIndex = gamehelpers->EntityToBCompatRef(pEntity); 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 bCanTransmit[i] = true; } - auto *pName = gamehelpers->GetEntityClassname(pEntity); - if (pName != nullptr && (V_strcmp(pName, "info_particle_system") == 0 || V_strcmp(pName, "light_dynamic") == 0)) + auto* pName = gamehelpers->GetEntityClassname(pEntity); + 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; - auto *edict = gamehelpers->EdictOfIndex(iEntityIndex); + auto* edict = gamehelpers->EdictOfIndex(iEntityIndex); if (edict) { auto flags = edict->m_fStateFlags; @@ -54,7 +75,8 @@ struct HookingEntity bool CanSee(int client) { - if (iEntityIndex == client || iOwnerEntity == client) + // remove self bypass + if (iEntityIndex == client) /*|| iOwnerEntity == client*/ { // self or children return true; @@ -86,7 +108,7 @@ struct HookingEntity private: int SourceHookId; int iEntityIndex; - bool bCanTransmit[SM_MAXPLAYERS]; + bool bCanTransmit[SM_MAXPLAYERS + 1]; int iOwnerEntity; bool bRemoveFlags; }; @@ -95,9 +117,9 @@ HookingEntity* g_Hooked[MAX_EDICTS]; void TransmitManager::Hook_SetTransmit(CCheckTransmitInfo* pInfo, bool bAlways) { - auto *bcref = META_IFACEPTR(CBaseEntity); + auto* bcref = META_IFACEPTR(CBaseEntity); auto entity = gamehelpers->EntityToBCompatRef(bcref); - auto *edict = gamehelpers->EdictOfIndex(entity); + auto* edict = gamehelpers->EdictOfIndex(entity); auto client = gamehelpers->IndexOfEdict(pInfo->m_pClientEnt); if (!IsEntityIndexInRange(entity) || client == entity || !edict || edict->IsFree()) @@ -139,16 +161,16 @@ void TransmitManager::Hook_SetTransmit(CCheckTransmitInfo* pInfo, bool bAlways) 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); SM_GET_IFACE(SDKHOOKS, g_pSDKHooks) - if (!gameconfs->LoadGameConfigFile("sdkhooks.games", &g_pGameConf, error, maxlength)) - { - smutils->Format(error, maxlength, "Failed to load SDKHooks gamedata."); - return false; - } + if (!gameconfs->LoadGameConfigFile("sdkhooks.games", &g_pGameConf, error, maxlength)) + { + smutils->Format(error, maxlength, "Failed to load SDKHooks gamedata."); + return false; + } auto offset = -1; if (!g_pGameConf->GetOffset("SetTransmit", &offset)) @@ -181,7 +203,7 @@ void TransmitManager::NotifyInterfaceDrop(SMInterface* pInterface) bool TransmitManager::QueryRunning(char* error, size_t maxlength) { SM_CHECK_IFACE(SDKHOOKS, g_pSDKHooks) - return true; + return true; } void TransmitManager::SDK_OnUnload() @@ -224,12 +246,12 @@ void TransmitManager::OnEntityDestroyed(CBaseEntity* pEntity) void TransmitManager::OnClientPutInServer(int client) { - auto *pPlayer = playerhelpers->GetGamePlayer(client); + auto* pPlayer = playerhelpers->GetGamePlayer(client); if (!pPlayer || pPlayer->IsSourceTV() || pPlayer->IsReplay()) { return; } - + for (auto i = 1; i < MAX_EDICTS; i++) { if (g_Hooked[i] == nullptr) @@ -297,7 +319,7 @@ void TransmitManager::UnhookEntity(int index) 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 return pContext->ThrowNativeError("Entity %d is out-of-range.", params[1]); @@ -309,24 +331,24 @@ static cell_t Native_SetEntityOwner(IPluginContext* pContext, const cell_t* para 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]); return false; } - + return pContext->ThrowNativeError("Entity %d is not being hook.", params[1]); } 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 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()) { return pContext->ThrowNativeError("Client %d is invalid.", params[2]); @@ -338,24 +360,24 @@ static cell_t Native_SetEntityState(IPluginContext* pContext, const cell_t* para 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]); return false; } - + return pContext->ThrowNativeError("Entity %d is not being hook.", params[1]); } 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 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) { // nuull @@ -367,10 +389,46 @@ static cell_t Native_AddEntityHooks(IPluginContext* pContext, const cell_t* para 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[] = { {"TransmitManager_AddEntityHooks", Native_AddEntityHooks}, {"TransmitManager_SetEntityOwner", Native_SetEntityOwner}, {"TransmitManager_SetEntityState", Native_SetEntityState}, + {"TransmitManager_GetEntityState", Native_GetEntityState}, + {"TransmitManager_IsEntityHooked", Native_IsEntityHooked}, {nullptr, nullptr}, }; diff --git a/extension.h b/extension.h index 4ce371f..4b59ca3 100644 --- a/extension.h +++ b/extension.h @@ -27,6 +27,6 @@ private: 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 diff --git a/smsdk_config.h b/smsdk_config.h index c59949e..27ba6df 100644 --- a/smsdk_config.h +++ b/smsdk_config.h @@ -3,7 +3,7 @@ #define SMEXT_CONF_NAME "Transmit Manager" #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_URL "https://www.kxnrl.com" #define SMEXT_CONF_LOGTAG "TransmitManager"