Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion Game.Client/C_BaseAnimating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,45 @@ public void RemoveBaseAnimatingInterpolatedVars() {
RemoveVar(this, DA_Cycle, false);
}

public bool ComputeHitboxSurroundingBox(out Vector3 vecWorldMins, out Vector3 vecWorldMaxs) => throw new NotImplementedException();
memhandle_t HitboxBoneCacheHandle;

public BoneCache GetBoneCache(StudioHdr? studioHdr) {
int boneMask = Studio.BONE_USED_BY_HITBOX;
BoneCache cache = Studio.GetBoneCache(HitboxBoneCacheHandle);
if (!cache.IsNull()) {
if (cache.IsValid(gpGlobals.CurTime, 0.0))
return cache;

if ((cache.BoneMask & boneMask) != boneMask) {
Studio.DestroyBoneCache(HitboxBoneCacheHandle);
HitboxBoneCacheHandle = 0;
cache = default;
}
}

studioHdr ??= GetModelPtr();
Assert(studioHdr != null);

PushAllowBoneAccess(true, false, (BoneAccessTag)"GetBoneCache");
SetupBones(null, -1, boneMask, gpGlobals.CurTime);
PopAllowBoneAccess((BoneAccessTag)"GetBoneCache");

if (!cache.IsNull())
cache.UpdateBones(CachedBoneData.AsSpan(), studioHdr!.NumBones(), gpGlobals.CurTime);
else {
BoneCacheParams parms = new();
parms.StudioHdr = studioHdr!;
parms.BoneToWorld = CachedBoneData.AsSpan();
parms.CurTime = gpGlobals.CurTime;
parms.BoneMask = boneMask;

HitboxBoneCacheHandle = Studio.CreateBoneCache(in parms);
cache = Studio.GetBoneCache(HitboxBoneCacheHandle);
}

Assert(!cache.IsNull());
return cache;
}

public override bool GetSoundSpatialization(ref SpatializationInfo info) {
using (AutoAllowBoneAccess boneaccess = new(true, false)) {
Expand Down Expand Up @@ -951,6 +989,9 @@ private static void RecvProxy_Sequence(ref readonly RecvProxyData data, object i
InvalidateBoneCache();
BoneMergeCache = null;

Studio.DestroyBoneCache(HitboxBoneCacheHandle);
HitboxBoneCacheHandle = 0;

if (CachedBoneData.Count != hdr.NumBones()) {
CachedBoneData.SetSize(hdr.NumBones());
for (i = 0; i < hdr.NumBones(); i++)
Expand Down
2 changes: 0 additions & 2 deletions Game.Server/BaseAnimating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ public void ResetSequence(int sequence) {
ResetSequenceInfo();
}

public bool ComputeHitboxSurroundingBox(out Vector3 vecWorldMins, out Vector3 vecWorldMaxs) => throw new NotImplementedException();

public const int NUM_POSEPAREMETERS = 24;
public const int NUM_BONECTRLS = 4;

Expand Down
44 changes: 41 additions & 3 deletions Game.Server/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Source.Common.Engine;
using Source.Common.Formats.BSP;
using Source.Common.Game.Server;
using Source.Common.Hashing;
using Source.Common.Mathematics;
using Source.Common.Physics;
using Source.Engine;
Expand Down Expand Up @@ -1468,11 +1469,48 @@ public override void PhysicsSimulate() {
pi.NumCmds = commandsToRun;
}
}
else if (GetTimeSinceLastUserCommand() > 3.0f /*sv_player_usercommand_timeout.GetFloat()*/)
RunNullCommand();

gpGlobals.CurTime = savetime;
gpGlobals.FrameTime = saveframetime;

if (GetTimeSinceLastUserCommand() >= UserCommandTimeout)
RunLastCommand();
}

const float UserCommandTimeout = 0.5f;

private void RunLastCommand() {
UserCmd cmd = LastCmd;
cmd.CommandNumber++;
cmd.TickCount++;
cmd.Forced = true;
cmd.RandomSeed = (int)(MD5Value.PseudoRandom((uint)cmd.CommandNumber) & 0x7fffffff);
cmd.MouseDeltaX = 0;
cmd.MouseDeltaY = 0;
cmd.Impulse = 0;
cmd.WeaponSelect = 0;
cmd.ScrollWheelSpeed = 0;

TimeUnit_t oldFrameTime = gpGlobals.FrameTime;
TimeUnit_t oldCurTime = gpGlobals.CurTime;

MoveHelperServer.s_MoveHelperServer.SetHost(this);
PlayerRunCommand(cmd, MoveHelperServer.s_MoveHelperServer);

if (VecPlayerSimInfo.Count > 0) {
PlayerSimInfo pi = VecPlayerSimInfo[VecPlayerSimInfo.Count - 1];
pi.Time = Platform.Time;
pi.AbsOrigin = GetAbsOrigin();
pi.GameSimulationTime = gpGlobals.CurTime;
pi.NumCmds = 1;
}

MoveHelperServer.s_MoveHelperServer.SetHost(null);

LastCmd = cmd;

gpGlobals.FrameTime = oldFrameTime;
gpGlobals.CurTime = oldCurTime;
}

private void RunNullCommand() {
Expand Down Expand Up @@ -1553,7 +1591,7 @@ public virtual void PlayerRunCommand(UserCmd userCmd, IMoveHelper s_MoveHelperSe

public bool IsPredictingWeapons() => false; // todo

TimeUnit_t GetTimeSinceLastUserCommand() => /*(!IsConnected() || IsFakeClient() || IsBot()) ? 0.0f :*/ gpGlobals.CurTime - LastUserCommandTime;
TimeUnit_t GetTimeSinceLastUserCommand() => (!IsConnected() || IsFakeClient() || IsBot()) ? 0.0f : gpGlobals.CurTime - LastUserCommandTime;

public virtual void SetupVisibility(BaseEntity? viewEntity, byte[] pvs, int pvssize) {
if (viewEntity != null)
Expand Down
55 changes: 55 additions & 0 deletions Game.Shared/BaseAnimatingShared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Source.Common.Mathematics;

using System.Numerics;
using System.Runtime.CompilerServices;

#if CLIENT_DLL
namespace Game.Client
Expand Down Expand Up @@ -339,6 +340,60 @@ public void CalculateIKLocks(TimeUnit_t currentTime) {
partition.SuppressLists(curSuppressed, true);
}
#endif

public bool ComputeHitboxSurroundingBox(out Vector3 vecWorldMins, out Vector3 vecWorldMaxs) {
vecWorldMins = default;
vecWorldMaxs = default;

#if CLIENT_DLL
if (IsDynamicModelLoading())
return false;
#endif

StudioHdr? studioHdr = GetModelPtr();
if (studioHdr == null)
return false;

if (HitboxSet < 0 || HitboxSet >= studioHdr.NumHitboxSets()) {
Warning($"[UH-OH!] Invalid HitboxSet {HitboxSet} of {studioHdr.NumHitboxSets()} on model {studioHdr.Name()}.\n");
return false;
}

MStudioHitboxSet set = studioHdr.HitboxSet(HitboxSet);
if (set.NumHitboxes == 0)
return false;

#if CLIENT_DLL
BoneCache cache = GetBoneCache(studioHdr);
#else
BoneCache cache = GetBoneCache();
#endif
if (cache.IsNull())
return false;

vecWorldMins = new(float.MaxValue);
vecWorldMaxs = new(-float.MaxValue);

#if !CLIENT_DLL
float modelScale = GetModelScale();
#endif
for (int i = 0; i < set.NumHitboxes; i++) {
MStudioBBox box = set.Hitbox(i);
ref Matrix3x4 matrix = ref cache.GetCachedBone(box.Bone);
if (Unsafe.IsNullRef(ref matrix))
continue;

#if CLIENT_DLL
MathLib.TransformAABB(in matrix, box.BBMin, box.BBMax, out Vector3 boxAbsMins, out Vector3 boxAbsMaxs);
#else
MathLib.TransformAABB(in matrix, box.BBMin * modelScale, box.BBMax * modelScale, out Vector3 boxAbsMins, out Vector3 boxAbsMaxs);
#endif
vecWorldMins = Vector3.Min(vecWorldMins, boxAbsMins);
vecWorldMaxs = Vector3.Max(vecWorldMaxs, boxAbsMaxs);
}

return true;
}
}
}
#endif
9 changes: 9 additions & 0 deletions Source.Common/Hashing/MD5Value.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommunityToolkit.HighPerformance;

using System.Buffers.Binary;
using System.Runtime.InteropServices;

using FIELD_W_TYPE = System.UInt32;
Expand Down Expand Up @@ -40,6 +41,14 @@ public static STRUCT_TYPE Compute(ReadOnlySpan<byte> data) {
return FromBytes(hash);
}

public static uint PseudoRandom(uint seed) {
Span<byte> data = stackalloc byte[sizeof(uint)];
BinaryPrimitives.WriteUInt32LittleEndian(data, seed);
Span<byte> hash = stackalloc byte[SIZE_BYTES];
HASH_ALGORITHM.HashData(data, hash);
return BinaryPrimitives.ReadUInt32LittleEndian(hash[6..]);
}

public readonly override string ToString() {
Span<char> chars = stackalloc char[SIZE_HEX_CHARACTERS];
ToString(chars);
Expand Down
22 changes: 22 additions & 0 deletions Source.Engine/Client/ClientState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,28 @@ public void SetModel(int tableIndex) {
p.SetModel(null);
}

protected override bool ProcessFixAngle(SVC_FixAngle msg) {
if (msg.Angle.X > 180)
msg.Angle.X -= 360;
if (msg.Angle.Y > 180)
msg.Angle.Y -= 360;
if (msg.Angle.Z > 180)
msg.Angle.Z -= 360;

if (msg.Relative) {
AddAngleTotal += msg.Angle.Y;

AddAngle.Add(new() {
Total = AddAngleTotal,
StartTime = LastServerTickTime
});
}
else
ViewAngles = msg.Angle;

return true;
}

protected override bool ProcessCrosshairAngle(SVC_CrosshairAngle msg) {
g_ClientDLL!.SetCrosshairAngle(msg.Angle);
return true;
Expand Down
Loading