diff --git a/public/CRayTraceInterface.h b/public/CRayTraceInterface.h index 61c8e02..83fa242 100644 --- a/public/CRayTraceInterface.h +++ b/public/CRayTraceInterface.h @@ -144,11 +144,15 @@ struct TraceOptions struct TraceResult { - Vector EndPos; + float EndPosX; + float EndPosY; + float EndPosZ; CEntityInstance* HitEntity; float Fraction; int AllSolid; - Vector Normal; + float NormalX; + float NormalY; + float NormalZ; }; class CRayTraceInterface diff --git a/public/Example.cs b/public/Example.cs index 5e72e2a..43edaf0 100644 --- a/public/Example.cs +++ b/public/Example.cs @@ -87,24 +87,24 @@ namespace RayTrace } } - [StructLayout(LayoutKind.Explicit, Size = 44)] - public struct TraceResult - { - [FieldOffset(0)] public float EndPosX; - [FieldOffset(4)] public float EndPosY; - [FieldOffset(8)] public float EndPosZ; - [FieldOffset(16)] public nint HitEntity; - [FieldOffset(24)] public float Fraction; - [FieldOffset(28)] public int AllSolid; - [FieldOffset(32)] public float NormalX; - [FieldOffset(36)] public float NormalY; - [FieldOffset(40)] public float NormalZ; + [StructLayout(LayoutKind.Explicit, Size = 48)] + public struct TraceResult + { + [FieldOffset(0)] public float EndPosX; + [FieldOffset(4)] public float EndPosY; + [FieldOffset(8)] public float EndPosZ; + [FieldOffset(16)] public nint HitEntity; + [FieldOffset(24)] public float Fraction; + [FieldOffset(28)] public int AllSolid; + [FieldOffset(32)] public float NormalX; + [FieldOffset(36)] public float NormalY; + [FieldOffset(40)] public float NormalZ; - public Vector3 EndPos => new(EndPosX, EndPosY, EndPosZ); - public Vector3 Normal => new(NormalX, NormalY, NormalZ); - public bool DidHit => Fraction < 1.0f; - public bool IsAllSolid => AllSolid != 0; - } + public Vector3 EndPos => new(EndPosX, EndPosY, EndPosZ); + public Vector3 Normal => new(NormalX, NormalY, NormalZ); + public bool DidHit => Fraction < 1.0f; + public bool IsAllSolid => AllSolid != 0; + } #endregion public static class CRayTrace diff --git a/src/RayTrace.cpp b/src/RayTrace.cpp index 865bf0a..1ff2944 100644 --- a/src/RayTrace.cpp +++ b/src/RayTrace.cpp @@ -61,7 +61,10 @@ namespace RayTracePlugin::RayTrace CTraceFilter& filterInc, Ray_t rayInc) { - if (!s_TraceShape) return std::nullopt; + if (!s_TraceShape) { + FP_ERROR("CNavPhysicsInterface::TraceShape is not bound!"); + return std::nullopt; + } CGameTrace tr{}; Vector startCopy = start; @@ -70,11 +73,15 @@ namespace RayTracePlugin::RayTrace &filterInc, &tr); TraceResult r{}; - r.EndPos = tr.m_vEndPos; + r.EndPosX = tr.m_vEndPos.x; + r.EndPosY = tr.m_vEndPos.y; + r.EndPosZ = tr.m_vEndPos.z; r.HitEntity = tr.m_pEnt; r.Fraction = tr.m_flFraction; r.AllSolid = tr.m_bStartInSolid; - r.Normal = tr.m_vHitNormal; + r.NormalX = tr.m_vHitNormal.x; + r.NormalY = tr.m_vHitNormal.y; + r.NormalZ = tr.m_vHitNormal.z; return r; } @@ -117,7 +124,7 @@ namespace RayTracePlugin::RayTrace if (opts && opts->DrawBeam) { Color col = res.has_value() ? colors::Red().ToValveColor() : colors::Green().ToValveColor(); - DrawBeam(origin, res ? res->EndPos : endOrigin, col); + DrawBeam(origin, res ? Vector(res->EndPosX, res->EndPosY, res->EndPosZ) : endOrigin, col); } return res; @@ -153,7 +160,7 @@ namespace RayTracePlugin::RayTrace if (opts && opts->DrawBeam) { Color col = res.has_value() ? colors::Red().ToValveColor() : colors::Green().ToValveColor(); - DrawBeam(origin, res ? res->EndPos : endOrigin, col); + DrawBeam(origin, res ? Vector(res->EndPosX, res->EndPosY, res->EndPosZ) : endOrigin, col); } return res; @@ -186,7 +193,7 @@ namespace RayTracePlugin::RayTrace if (opts && opts->DrawBeam) { Color col = res.has_value() ? colors::Red().ToValveColor() : colors::Green().ToValveColor(); - DrawBeam(vecStart, res ? res->EndPos : vecEnd, col); + DrawBeam(vecStart, res ? Vector(res->EndPosX, res->EndPosY, res->EndPosZ) : vecEnd, col); } return res;