Expose custom sdktools trace types from hl2sdk (#1822)

* Update trnatives.cpp

* Update sdktools_trace.inc

* Update trnatives.cpp
This commit is contained in:
vanz666 2022-12-02 16:11:05 +03:00 committed by GitHub
parent 3b4a343274
commit 8538233985
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 78 additions and 5 deletions

View File

@ -51,7 +51,7 @@ private:
cell_t m_EntRef = INVALID_EHANDLE_INDEX; cell_t m_EntRef = INVALID_EHANDLE_INDEX;
}; };
class CSMTraceFilter : public CTraceFilter class CSMTraceFilter : public ITraceFilter
{ {
public: public:
bool ShouldHitEntity(IHandleEntity *pEntity, int contentsMask) bool ShouldHitEntity(IHandleEntity *pEntity, int contentsMask)
@ -74,10 +74,19 @@ public:
m_pFunc = pFunc; m_pFunc = pFunc;
m_Data = data; m_Data = data;
} }
virtual TraceType_t GetTraceType() const
{
return m_TraceType;
}
void SetTraceType(TraceType_t traceType)
{
m_TraceType = traceType;
}
private: private:
ExceptionHandler *m_pEh; ExceptionHandler *m_pEh;
IPluginFunction *m_pFunc; IPluginFunction *m_pFunc;
cell_t m_Data; cell_t m_Data;
TraceType_t m_TraceType;
}; };
class CSMTraceEnumerator : public IPartitionEnumerator class CSMTraceEnumerator : public IPartitionEnumerator
@ -458,6 +467,7 @@ static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *param
cell_t *startaddr, *endaddr; cell_t *startaddr, *endaddr;
IPluginFunction *pFunc; IPluginFunction *pFunc;
cell_t data; cell_t data;
TraceType_t traceType;
pFunc = pContext->GetFunctionById(params[5]); pFunc = pContext->GetFunctionById(params[5]);
if (!pFunc) if (!pFunc)
@ -477,6 +487,17 @@ static cell_t smn_TRTraceRayFilter(IPluginContext *pContext, const cell_t *param
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_SMTraceFilter.SetFunctionPtr(&eh, pFunc, data); g_SMTraceFilter.SetFunctionPtr(&eh, pFunc, data);
if (params[0] >= 7)
{
traceType = (TraceType_t)params[7];
}
else
{
traceType = TRACE_EVERYTHING;
}
g_SMTraceFilter.SetTraceType(traceType);
pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[1], &startaddr);
pContext->LocalToPhysAddr(params[2], &endaddr); pContext->LocalToPhysAddr(params[2], &endaddr);
@ -513,6 +534,7 @@ static cell_t smn_TRTraceHullFilter(IPluginContext *pContext, const cell_t *para
cell_t data; cell_t data;
IPluginFunction *pFunc; IPluginFunction *pFunc;
cell_t *startaddr, *endaddr, *mins, *maxs; cell_t *startaddr, *endaddr, *mins, *maxs;
TraceType_t traceType;
pFunc = pContext->GetFunctionById(params[6]); pFunc = pContext->GetFunctionById(params[6]);
if (!pFunc) if (!pFunc)
@ -525,6 +547,17 @@ static cell_t smn_TRTraceHullFilter(IPluginContext *pContext, const cell_t *para
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
g_SMTraceFilter.SetFunctionPtr(&eh, pFunc, data); g_SMTraceFilter.SetFunctionPtr(&eh, pFunc, data);
if (params[0] >= 8)
{
traceType = (TraceType_t)params[8];
}
else
{
traceType = TRACE_EVERYTHING;
}
g_SMTraceFilter.SetTraceType(traceType);
pContext->LocalToPhysAddr(params[1], &startaddr); pContext->LocalToPhysAddr(params[1], &startaddr);
pContext->LocalToPhysAddr(params[2], &endaddr); pContext->LocalToPhysAddr(params[2], &endaddr);
pContext->LocalToPhysAddr(params[3], &mins); pContext->LocalToPhysAddr(params[3], &mins);
@ -750,6 +783,7 @@ static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *par
IPluginFunction *pFunc; IPluginFunction *pFunc;
cell_t *startaddr, *endaddr; cell_t *startaddr, *endaddr;
cell_t data; cell_t data;
TraceType_t traceType;
pFunc = pContext->GetFunctionById(params[5]); pFunc = pContext->GetFunctionById(params[5]);
if (!pFunc) if (!pFunc)
@ -774,6 +808,17 @@ static cell_t smn_TRTraceRayFilterEx(IPluginContext *pContext, const cell_t *par
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
smfilter.SetFunctionPtr(&eh, pFunc, data); smfilter.SetFunctionPtr(&eh, pFunc, data);
if (params[0] >= 7)
{
traceType = (TraceType_t)params[7];
}
else
{
traceType = TRACE_EVERYTHING;
}
smfilter.SetTraceType(traceType);
StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
@ -818,6 +863,7 @@ static cell_t smn_TRTraceHullFilterEx(IPluginContext *pContext, const cell_t *pa
IPluginFunction *pFunc; IPluginFunction *pFunc;
cell_t *startaddr, *endaddr, *mins, *maxs; cell_t *startaddr, *endaddr, *mins, *maxs;
cell_t data; cell_t data;
TraceType_t traceType;
pFunc = pContext->GetFunctionById(params[6]); pFunc = pContext->GetFunctionById(params[6]);
if (!pFunc) if (!pFunc)
@ -837,6 +883,17 @@ static cell_t smn_TRTraceHullFilterEx(IPluginContext *pContext, const cell_t *pa
DetectExceptions eh(pContext); DetectExceptions eh(pContext);
smfilter.SetFunctionPtr(&eh, pFunc, data); smfilter.SetFunctionPtr(&eh, pFunc, data);
if (params[0] >= 8)
{
traceType = (TraceType_t)params[8];
}
else
{
traceType = TRACE_EVERYTHING;
}
smfilter.SetTraceType(traceType);
StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2])); StartVec.Init(sp_ctof(startaddr[0]), sp_ctof(startaddr[1]), sp_ctof(startaddr[2]));
vmins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2])); vmins.Init(sp_ctof(mins[0]), sp_ctof(mins[1]), sp_ctof(mins[2]));

View File

@ -164,6 +164,14 @@ enum RayType
RayType_Infinite /**< The trace ray will go from the start position to infinity using a direction vector. */ RayType_Infinite /**< The trace ray will go from the start position to infinity using a direction vector. */
}; };
enum TraceType
{
TRACE_EVERYTHING = 0,
TRACE_WORLD_ONLY, /**< NOTE: This does *not* test static props!!! */
TRACE_ENTITIES_ONLY, /**< NOTE: This version will *not* test static props */
TRACE_EVERYTHING_FILTER_PROPS /**< NOTE: This version will pass the IHandleEntity for props through the filter, unlike all other filters */
};
typeset TraceEntityFilter typeset TraceEntityFilter
{ {
/** /**
@ -357,13 +365,15 @@ native void TR_EnumerateEntitiesPoint(const float pos[3],
* @param filter Function to use as a filter. * @param filter Function to use as a filter.
* @param data Arbitrary data value to pass through to the filter * @param data Arbitrary data value to pass through to the filter
* function. * function.
* @param traceType Trace type.
*/ */
native void TR_TraceRayFilter(const float pos[3], native void TR_TraceRayFilter(const float pos[3],
const float vec[3], const float vec[3],
int flags, int flags,
RayType rtype, RayType rtype,
TraceEntityFilter filter, TraceEntityFilter filter,
any data=0); any data=0,
TraceType traceType=TRACE_EVERYTHING);
/** /**
* Starts up a new trace hull using a global trace result and a customized * Starts up a new trace hull using a global trace result and a customized
@ -380,6 +390,7 @@ native void TR_TraceRayFilter(const float pos[3],
* @param filter Function to use as a filter. * @param filter Function to use as a filter.
* @param data Arbitrary data value to pass through to the filter * @param data Arbitrary data value to pass through to the filter
* function. * function.
* @param traceType Trace type.
*/ */
native void TR_TraceHullFilter(const float pos[3], native void TR_TraceHullFilter(const float pos[3],
const float vec[3], const float vec[3],
@ -387,7 +398,8 @@ native void TR_TraceHullFilter(const float pos[3],
const float maxs[3], const float maxs[3],
int flags, int flags,
TraceEntityFilter filter, TraceEntityFilter filter,
any data=0); any data=0,
TraceType traceType=TRACE_EVERYTHING);
/** /**
* Clips a ray to a particular entity. * Clips a ray to a particular entity.
@ -478,6 +490,7 @@ native Handle TR_TraceHullEx(const float pos[3],
* @param rtype Method to calculate the ray direction. * @param rtype Method to calculate the ray direction.
* @param filter Function to use as a filter. * @param filter Function to use as a filter.
* @param data Arbitrary data value to pass through to the filter function. * @param data Arbitrary data value to pass through to the filter function.
* @param traceType Trace type.
* @return Ray trace handle, which must be closed via CloseHandle(). * @return Ray trace handle, which must be closed via CloseHandle().
*/ */
native Handle TR_TraceRayFilterEx(const float pos[3], native Handle TR_TraceRayFilterEx(const float pos[3],
@ -485,7 +498,8 @@ native Handle TR_TraceRayFilterEx(const float pos[3],
int flags, int flags,
RayType rtype, RayType rtype,
TraceEntityFilter filter, TraceEntityFilter filter,
any data=0); any data=0,
TraceType traceType=TRACE_EVERYTHING);
/** /**
* Starts up a new trace hull using a new trace result and a customized * Starts up a new trace hull using a new trace result and a customized
@ -501,6 +515,7 @@ native Handle TR_TraceRayFilterEx(const float pos[3],
* @param flags Trace flags. * @param flags Trace flags.
* @param filter Function to use as a filter. * @param filter Function to use as a filter.
* @param data Arbitrary data value to pass through to the filter function. * @param data Arbitrary data value to pass through to the filter function.
* @param traceType Trace type.
* @return Ray trace handle, which must be closed via CloseHandle(). * @return Ray trace handle, which must be closed via CloseHandle().
*/ */
native Handle TR_TraceHullFilterEx(const float pos[3], native Handle TR_TraceHullFilterEx(const float pos[3],
@ -509,7 +524,8 @@ native Handle TR_TraceHullFilterEx(const float pos[3],
const float maxs[3], const float maxs[3],
int flags, int flags,
TraceEntityFilter filter, TraceEntityFilter filter,
any data=0); any data=0,
TraceType traceType=TRACE_EVERYTHING);
/** /**
* Clips a ray to a particular entity. * Clips a ray to a particular entity.