update: add Ray/Hull Trace API (INavPhysicsInterface)#1331
Conversation
|
I think this looks passable to me. It is a bit annoying with the opaque pointers to the structs we don't have definitions for, but it is better than nothing since CS#1.0 native struct support is terrible. I'll probably write some integration/game tests for this to try it out which may take me some time. |
| public CEntityInstance HitEntity() => new(m_pEnt); | ||
|
|
||
| /// <summary>Native <c>CHitBox*</c> — opaque pointer.</summary> | ||
| public nint Hitbox() => m_pHitbox; |
There was a problem hiding this comment.
It might be worth considering naming these something else, like HitboxPtr, just in case we do ever add the proper struct types for these later down the line and then we would have to make a breaking change to the existing property. Don't know what your thoughts are on that?
There was a problem hiding this comment.
I thought about naming them the way they those members are named as we could use NativeObject and construct them in same way as CEntityInstance wrapper is. So naming would be ideal, otherwise it can be changed right away.
Thanks, yeah I didn't imlement them as we can use NativeObject or raw unsafe / marshal passing, also I had idea of having raytrace logic in core so we can just bump SDK and its fixed right away, |
Adds a complete ray and hull trace system to CounterStrikeSharp, exposing CS2's
CNavPhysicsInterfacevtable to C# plugins.What changed
C++ (
src/)src/core/cs2_sdk/interfaces/navphysicsinterface.h/.cpp— adapts the existingINavPhysicsInterfacestatic wrapper to use CSSharp's ownmodules::server->FindVirtualTable()instead of Source2Toolkit'sDynLibUtilssrc/scripting/natives/natives_raytrace.cpp/.yaml— 6 new natives:TRACE_SHAPE/TRACE_END_SHAPE/TRACE_HULL_SHAPE— write into a caller-providedCSSTraceResultbuffer (no heap allocation on C++ side)POINT_CONTENTS— contents bitmask at world positionCHECK_AREA_OVERLAPPING_ENTITY— nav area vs entity AABB overlapGET_ENTITY_WORLD_SPACE_AABB— world-space AABB of an entityCTraceFilteris constructed with the entity's owner handle and hierarchy ID (read via schema with static caching), matchingCTraceFilterExbehaviour from Source2ToolkitC# (
managed/)Modules/Utils/Trace.csTraceOptions—InteractsAs,InteractsWith,InteractsExcludeTraceResult—[StructLayout(Sequential, Pack=1)]unmanaged struct, stack-allocated by eachTrace.*method and returned by value; zero heap allocation, zero native calls for field accessTracestatic class —TraceShape,TraceEndShape,TraceHullShape,PointContents,CheckAreaOverlappingEntity,GetEntityWorldSpaceAABBModules/Utils/ContentsMask.cs—ContentsandMaskstatic classes with allCONTENTS_*andMASK_*constants frombspflags.h/const.hasconst ulongUsage
Notes
gamedata.jsonhas no new entries required — vtable is found by RTTI name ("CNavPhysicsInterface")CSSTraceResultlayout is#pragma pack(1)and must stay in sync withTraceResult's[StructLayout(Sequential, Pack=1)]CTransform/RnCollisionAttr_tare intentionally not exposed on the C# side; opaque pointers (nint) are available viaBody(),Shape(),Surface(),Hitbox()for interop