Fix C# traceresult
This commit is contained in:
parent
5146e4cc88
commit
131186e1e1
1 changed files with 308 additions and 305 deletions
|
|
@ -11,8 +11,9 @@ namespace RayTraceAPI
|
|||
{
|
||||
#region Native Structs (matching C++ layout exactly)
|
||||
[Flags]
|
||||
public enum InteractionLayers : ulong
|
||||
public enum InteractionLayers: ulong
|
||||
{
|
||||
None = 0,
|
||||
Solid = 0x1,
|
||||
Hitboxes = 0x2,
|
||||
Trigger = 0x4,
|
||||
|
|
@ -79,8 +80,7 @@ namespace RayTraceAPI
|
|||
DrawBeam = 0;
|
||||
}
|
||||
|
||||
public TraceOptions(InteractionLayers interactsAs, InteractionLayers interactsWith,
|
||||
InteractionLayers interactsExclude = 0, bool drawBeam = false)
|
||||
public TraceOptions(InteractionLayers interactsAs, InteractionLayers interactsWith, InteractionLayers interactsExclude = 0, bool drawBeam = false)
|
||||
{
|
||||
InteractsAs = (ulong)interactsAs;
|
||||
InteractsWith = (ulong)interactsWith;
|
||||
|
|
@ -114,10 +114,8 @@ namespace RayTraceAPI
|
|||
[FieldOffset(12)] public uint BaseNameHash;
|
||||
[FieldOffset(16)] public int ListIndex;
|
||||
[FieldOffset(20)] public int BaseListIndex;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)] [FieldOffset(24)]
|
||||
public bool Hidden;
|
||||
|
||||
[MarshalAs(UnmanagedType.I1)]
|
||||
[FieldOffset(24)] public bool Hidden;
|
||||
[FieldOffset(32)] public CUtlString Description;
|
||||
[FieldOffset(40)] public CPhysSurfacePropertiesPhysicsTrace Physics;
|
||||
[FieldOffset(80)] public CPhysSurfacePropertiesSoundNamesTrace AudioSounds;
|
||||
|
|
@ -314,39 +312,52 @@ namespace RayTraceAPI
|
|||
}
|
||||
|
||||
[StructLayout(LayoutKind.Explicit, Size = 208)]
|
||||
public struct TraceResult
|
||||
public unsafe struct TraceResult
|
||||
{
|
||||
// Start position
|
||||
[FieldOffset(0)] public float StartPosX;
|
||||
[FieldOffset(4)] public float StartPosY;
|
||||
[FieldOffset(8)] public float StartPosZ;
|
||||
|
||||
// End position
|
||||
[FieldOffset(12)] public float EndPosX;
|
||||
[FieldOffset(16)] public float EndPosY;
|
||||
[FieldOffset(20)] public float EndPosZ;
|
||||
|
||||
// Hit point
|
||||
[FieldOffset(24)] public float HitPointX;
|
||||
[FieldOffset(28)] public float HitPointY;
|
||||
[FieldOffset(32)] public float HitPointZ;
|
||||
|
||||
// Hit normal
|
||||
[FieldOffset(36)] public float NormalX;
|
||||
[FieldOffset(40)] public float NormalY;
|
||||
[FieldOffset(44)] public float NormalZ;
|
||||
|
||||
// Fraction & hit offset
|
||||
[FieldOffset(48)] public float Fraction;
|
||||
[FieldOffset(52)] public float HitOffset;
|
||||
|
||||
// Hit triangle / hitbox
|
||||
[FieldOffset(56)] public int TriangleIndex;
|
||||
[FieldOffset(60)] public int HitboxBoneIndex;
|
||||
|
||||
// Flags/metadata are 32-bit values in native trace result
|
||||
[FieldOffset(64)] public InteractionLayers Contents;
|
||||
[FieldOffset(68)] public RayType_t RayType;
|
||||
[FieldOffset(72)] public int AllSolid;
|
||||
[FieldOffset(76)] public int ExactHitPoint;
|
||||
|
||||
// Raw pointers (8 bytes each on x64)
|
||||
[FieldOffset(80)] public nint HitEntityHandle;
|
||||
[FieldOffset(88)] public nint HitboxHandle;
|
||||
[FieldOffset(96)] public nint SurfacePropsHandle;
|
||||
[FieldOffset(104)] public nint BodyHandle;
|
||||
[FieldOffset(112)] public nint ShapeHandle;
|
||||
|
||||
[FieldOffset(128)] public CTransform BodyTransform;
|
||||
[FieldOffset(160)] public RnCollisionAttr_t ShapeAttributes;
|
||||
|
||||
// Helper properties for vectors
|
||||
public Vector3 StartPos => new(StartPosX, StartPosY, StartPosZ);
|
||||
public Vector3 EndPos => new(EndPosX, EndPosY, EndPosZ);
|
||||
public Vector3 HitPoint => new(HitPointX, HitPointY, HitPointZ);
|
||||
|
|
@ -355,17 +366,9 @@ namespace RayTraceAPI
|
|||
public bool DidHit => Fraction < 1.0f;
|
||||
public bool IsAllSolid => AllSolid != 0;
|
||||
public bool HasExactHit => ExactHitPoint != 0;
|
||||
|
||||
public CEntityInstance? HitEntity
|
||||
=> HitEntityHandle == 0 ? null : new CEntityInstance(HitEntityHandle);
|
||||
|
||||
public CHitBox Hitbox
|
||||
=> HitboxHandle == 0 ? default : Marshal.PtrToStructure<CHitBox>(HitboxHandle);
|
||||
|
||||
public CPhysSurfacePropertiesTrace SurfaceProps
|
||||
=> SurfacePropsHandle == 0
|
||||
? default
|
||||
: Marshal.PtrToStructure<CPhysSurfacePropertiesTrace>(SurfacePropsHandle);
|
||||
public CPhysSurfacePropertiesTrace SurfaceProps => SurfacePropsHandle == 0 ? default : Marshal.PtrToStructure<CPhysSurfacePropertiesTrace>(SurfacePropsHandle);
|
||||
public CHitBox Hitbox => HitboxHandle == 0 ? default : Marshal.PtrToStructure<CHitBox>(HitboxHandle);
|
||||
public CEntityInstance? HitEntity => HitEntityHandle == 0 ? null : new CEntityInstance(HitEntityHandle);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue