diff --git a/configs/addons/RayTrace/gamedata.json b/configs/addons/RayTrace/gamedata.json index c1cffb8..e6a18ac 100644 --- a/configs/addons/RayTrace/gamedata.json +++ b/configs/addons/RayTrace/gamedata.json @@ -27,16 +27,9 @@ "linux": "55 48 89 E5 41 55 49 89 CD 41 54 49 89 FC" } }, - "CBaseModelEntity_SetModel": { - "signatures": { - "library": "server", - "windows": "40 53 48 83 EC ? 48 8B D9 4C 8B C2 48 8B 0D ? ? ? ? 48 8D 54 24 ? 48 8B 01 FF 50 ? 48 8B 44 24 ? 48 8D 54 24 ? 48 8B CB 48 89 44 24 ? E8 ? ? ? ? 48 83 C4 ? 5B C3 CC CC CC CC CC 48 89 5C 24", - "linux": "55 48 89 F2 48 89 E5 53 48 89 FB 48 8D 7D ? 48 83 EC ? 48 8D 05 ? ? ? ? 48 8B 30 48 8B 06 FF 50 ? 48 8B 45 ? 48 8D 75 ? 48 89 DF 48 89 45 ? E8 ? ? ? ? 48 8B 5D ? C9 C3 CC CC CC 55" - } - }, "CNavPhysicsInterface_TraceShape": { "offsets": { - "windows": 1, + "windows": 5, "linux": 5 } }, @@ -52,6 +45,12 @@ "linux": 190 } }, + "CBaseEntity_Teleport":{ + "offsets": { + "windows": 168, + "linux": 167 + } + }, "GameEntitySystem": { "offsets": { "windows": 88, diff --git a/public/CRayTraceInterface.h b/public/CRayTraceInterface.h index 78211c5..b13d246 100644 --- a/public/CRayTraceInterface.h +++ b/public/CRayTraceInterface.h @@ -1,10 +1,7 @@ #pragma once -#include "vector.h" -#include "entityinstance.h" -#include "gametrace.h" -#include "trace.h" -#include "cmodel.h" #include +#include "vector.h" +#include "gametrace.h" #define RAYTRACE_INTERFACE_VERSION "CRayTraceInterface001" @@ -54,24 +51,117 @@ enum class InteractionLayers : uint64_t FUNPLAY_IGNORE_PLAYER = (0x8000000000ull << 1) }; -inline InteractionLayers operator|(InteractionLayers a, InteractionLayers b) +constexpr InteractionLayers operator|(InteractionLayers a, InteractionLayers b) { return static_cast( static_cast(a) | static_cast(b) ); } -inline InteractionLayers& operator|=(InteractionLayers& a, InteractionLayers b) +constexpr InteractionLayers operator&(InteractionLayers a, InteractionLayers b) +{ + return static_cast( + static_cast(a) & static_cast(b) + ); +} + +constexpr InteractionLayers operator~(InteractionLayers a) +{ + return static_cast( + ~static_cast(a) + ); +} + +constexpr InteractionLayers& operator|=(InteractionLayers& a, InteractionLayers b) { a = a | b; return a; } +/// Custom base (0x2C3011, using this as default in my plugins) +constexpr InteractionLayers MASK_SHOT_PHYSICS = + InteractionLayers::Solid | + InteractionLayers::PlayerClip | + InteractionLayers::Window | + InteractionLayers::PassBullets | + InteractionLayers::Player | + InteractionLayers::NPC | + InteractionLayers::Physics_Prop; + +/// Only hitboxes (headshots etc.) +constexpr InteractionLayers MASK_SHOT_HITBOX = + InteractionLayers::Hitboxes | + InteractionLayers::Player | + InteractionLayers::NPC; + +/// Physics + hitboxes (full bullet trace) +constexpr InteractionLayers MASK_SHOT_FULL = + MASK_SHOT_PHYSICS | + InteractionLayers::Hitboxes; + +/// World only (no entities) +constexpr InteractionLayers MASK_WORLD_ONLY = + InteractionLayers::Solid | + InteractionLayers::Window | + InteractionLayers::PassBullets; + +/// Grenade trace +constexpr InteractionLayers MASK_GRENADE = + InteractionLayers::Solid | + InteractionLayers::Window | + InteractionLayers::Physics_Prop | + InteractionLayers::PassBullets; + +/// Brush only +constexpr InteractionLayers MASK_BRUSH_ONLY = + InteractionLayers::Solid | + InteractionLayers::Window; + +/// Movement (player) +constexpr InteractionLayers MASK_PLAYER_MOVE = + InteractionLayers::Solid | + InteractionLayers::Window | + InteractionLayers::PlayerClip | + InteractionLayers::PassBullets; + +/// Movement (NPC) +constexpr InteractionLayers MASK_NPC_MOVE = + InteractionLayers::Solid | + InteractionLayers::Window | + InteractionLayers::NPCClip | + InteractionLayers::PassBullets; + +static_assert( + static_cast(MASK_SHOT_PHYSICS) == 0x2c3011, + "MASK_SHOT_PHYSICS mismatch!" +); + +constexpr InteractionLayers RemovePlayers(InteractionLayers m) +{ + return static_cast( + static_cast(m) & + ~static_cast(InteractionLayers::Player) + ); +} + +constexpr InteractionLayers BuildShotMask(bool includePlayers, bool includeHitboxes) +{ + InteractionLayers m = MASK_SHOT_PHYSICS; + + if (!includePlayers) + m = RemovePlayers(m); + + if (includeHitboxes) + m |= InteractionLayers::Hitboxes; + + return m; +} + struct TraceOptions { - std::optional InteractsWith{static_cast(0x2c3011)}; + std::optional InteractsWith{ MASK_SHOT_PHYSICS }; std::optional InteractsExclude{}; - bool DrawBeam{false}; + bool DrawBeam{ false }; }; struct TraceResult @@ -83,7 +173,8 @@ struct TraceResult Vector Normal{}; }; -class CRayTraceInterface { +class CRayTraceInterface +{ public: virtual ~CRayTraceInterface() = default; @@ -104,4 +195,4 @@ public: const Vector& vecEnd, CTraceFilter& filterInc, Ray_t rayInc) = 0; -}; \ No newline at end of file +}; diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 17ea143..b9b5d31 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -107,7 +107,7 @@ namespace RayTracePlugin void *IPlugin::OnMetamodQuery(const char *iface, int *ret) { if (strcmp(iface, RAYTRACE_INTERFACE_VERSION) == 0) { *ret = META_IFACE_OK; - FP_INFO("CRayTraceInterface001 accessed."); + FP_INFO("{} accessed.", RAYTRACE_INTERFACE_VERSION); return &RayTrace::g_CRayTrace; } diff --git a/src/RayTrace.cpp b/src/RayTrace.cpp index cac567d..103c3f1 100644 --- a/src/RayTrace.cpp +++ b/src/RayTrace.cpp @@ -13,6 +13,8 @@ namespace RayTracePlugin::RayTrace { + CRayTrace g_CRayTrace; + using TraceShapeFn = bool(*)(void* pThis, Ray_t& ray, Vector& start, diff --git a/src/RayTrace.h b/src/RayTrace.h index 7ab9c57..4711001 100644 --- a/src/RayTrace.h +++ b/src/RayTrace.h @@ -17,12 +17,12 @@ namespace RayTracePlugin::RayTrace : CTraceFilter(static_cast(entityToIgnore), entityToIgnore ? entityToIgnore->m_hOwnerEntity.Get() : nullptr, entityToIgnore ? entityToIgnore->m_pCollision()->m_collisionAttribute().m_nHierarchyId() : static_cast(0xFFFFFFFF), - 0x2c3011, + static_cast(MASK_SHOT_PHYSICS), COLLISION_GROUP_DEFAULT, true) { } - CTraceFilterEx() : CTraceFilter(0x2c3011, COLLISION_GROUP_DEFAULT, true) + CTraceFilterEx() : CTraceFilter(static_cast(MASK_SHOT_PHYSICS), COLLISION_GROUP_DEFAULT, true) { } }; @@ -78,5 +78,5 @@ namespace RayTracePlugin::RayTrace } }; - inline CRayTrace g_CRayTrace; + extern CRayTrace g_CRayTrace; } diff --git a/src/listeners/Listeners.cpp b/src/listeners/Listeners.cpp index 1ff6d16..ed2893b 100644 --- a/src/listeners/Listeners.cpp +++ b/src/listeners/Listeners.cpp @@ -44,8 +44,6 @@ namespace RayTracePlugin::Listeners { void SourceHooks::Hook_GameFrame(bool simulating, bool bFirstTick, bool bLastTick) { Tasks::Tick(simulating); - if (!shared::getGlobalVars()) - return; } void SourceHooks::Hook_StartupServer(const GameSessionConfiguration_t& config, diff --git a/src/schema/CBaseModelEntity.h b/src/schema/CBaseModelEntity.h index a9f2a2a..712a718 100644 --- a/src/schema/CBaseModelEntity.h +++ b/src/schema/CBaseModelEntity.h @@ -30,37 +30,6 @@ RayTracePlugin SCHEMA_FIELD(float32, m_flShadowStrength) - void SetModel(const char* model) - { - using SetModel_t = void (*)(CBaseModelEntity*, const char*); - static SetModel_t s_SetModel = nullptr; - - if (!s_SetModel) - { - SetModel_t addr = - DynLibUtils::CModule(shared::g_pServer) - .FindPattern(shared::g_pGameConfig->GetSignature("CBaseModelEntity_SetModel")) - .RCast(); - - if (!addr) return; - s_SetModel = addr; - } - - s_SetModel(this, model); - } - - void SetBodyGroup(std::string name, int value) - { - char bodygroupStr[64]; - g_SMAPI->Format(bodygroupStr, sizeof(bodygroupStr), "%s,%i", name.c_str(), value); - this->AcceptInput( - "SetBodyGroup", - this, - this, - bodygroupStr - ); - } - CUtlSymbolLarge GetModelName() { if (m_CBodyComponent == nullptr) return CUtlSymbolLarge();