Skip to content

Commit

Permalink
Improve Teleport Function (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarukon committed Jun 27, 2024
1 parent 9c5468e commit a87bd25
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions managed/CounterStrikeSharp.API/Core/Model/CBaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ namespace CounterStrikeSharp.API.Core;
public partial class CBaseEntity
{
/// <exception cref="InvalidOperationException">Entity is not valid</exception>
/// <exception cref="ArgumentNullException">No valid argument</exception>
public void Teleport(Vector? position = null, QAngle? angles = null, Vector? velocity = null)
{
Guard.IsValidEntity(this);

position ??= AbsOrigin!;
angles ??= AbsRotation!;
velocity ??= AbsVelocity;

VirtualFunction.CreateVoid<IntPtr, IntPtr, IntPtr, IntPtr>(Handle, GameData.GetOffset("CBaseEntity_Teleport"))(
Handle, position.Handle, angles.Handle, velocity.Handle);

if (position == null && angles == null && velocity == null)
throw new ArgumentNullException("No valid argument");

nint _position = position?.Handle ?? 0;
nint _angles = angles?.Handle ?? 0;
nint _velocity = velocity?.Handle ?? 0;

VirtualFunction.CreateVoid<IntPtr, IntPtr, IntPtr, IntPtr>(Handle, GameData.GetOffset("CBaseEntity_Teleport"))(Handle, _position, _angles, _velocity);
}

/// <exception cref="InvalidOperationException">Entity is not valid</exception>
Expand Down Expand Up @@ -45,4 +48,4 @@ public void DispatchSpawn()

return (T)Activator.CreateInstance(typeof(T), Marshal.ReadIntPtr(SubclassID.Handle + 4));
}
}
}

0 comments on commit a87bd25

Please sign in to comment.