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
5 changes: 5 additions & 0 deletions Game.Client/CDLL_Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public static void PrecacheOther(ReadOnlySpan<char> classname) {
entity.Release();
}

public static void Remove(C_BaseEntity? entity) {
if (entity != null && !entity.IsMarkedForDeletion())
ClientThinkList().AddToDeleteList(entity.GetClientHandle());
}

}
public static partial class Util_Globals
{
Expand Down
7 changes: 7 additions & 0 deletions Game.Client/C_BaseAnimating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public static void PushAllowBoneAccess(bool allowForNormalModels, bool allowForV
}
}

public int GetNumBodyGroups() => Animation.GetNumBodyGroups(GetModelPtr());

public void SetBodygroup(int group, int value) {
Animation.SetBodygroup(GetModelPtr(), ref Body, group, value);
}
Expand Down Expand Up @@ -1158,6 +1160,11 @@ public void AddToClientSideAnimationList() {
UpdateRelevantInterpolatedVars();
}

public override void Term() {
RemoveFromClientSideAnimationList(true);
base.Term();
}

public void RemoveFromClientSideAnimationList(bool beingDestroyed = false) {
if (INVALID_CLIENTSIDEANIMATION_LIST_HANDLE == ClientSideAnimationListHandle)
return;
Expand Down
3 changes: 3 additions & 0 deletions Game.Client/C_BaseCombatWeapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public partial class C_BaseCombatWeapon : C_BaseAnimating
{
public override bool IsBaseCombatWeapon() => true;
public override GarrysMod.LuaClass Lua_GetLuaClass() => GarrysMod.LuaEntity.LC_Weapon;
public bool Dropped;
public virtual bool WasDropped() => Dropped;
public virtual void SetDropped() => Dropped = true;
public virtual void DrawHUD() { }
public virtual void DrawHUDBackground() { }
public override bool IsWeapon() => true;
Expand Down
229 changes: 215 additions & 14 deletions Game.Client/C_BaseEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ public static class BaseEntityConsts
public const int MULTIPLAYER_BACKUP = 90;
}

public enum CollideType
{
ShouldNotCollide = 0,
ShouldCollide,
ShouldRespond
}

public enum InterpolateResult
{
Stop = 0,
Expand Down Expand Up @@ -183,6 +190,10 @@ public partial class C_BaseEntity : IClientEntity
public virtual bool IsBaseCombatWeapon() => false;
public virtual bool IsCombatItem() => false;

public void SetClassname(ReadOnlySpan<char> classname) {
// todo
}

static readonly char[] GetClassname__outstr = new char[256];
public ReadOnlySpan<char> GetClassname() {
GetClassname__outstr[0] = '\0';
Expand Down Expand Up @@ -554,7 +565,7 @@ protected static void RecvProxy_SimulationTime(ref readonly RecvProxyData data,
RecvPropInt(FIELD.OF(nameof(CollisionGroup))),
RecvPropFloat(FIELD.OF(nameof(Elasticity))),
RecvPropFloat(FIELD.OF(nameof(ShadowCastDistance))),
RecvPropEHandle(FIELD.OF(nameof(OwnerEntity))),
RecvPropEHandle(FIELD.OF(nameof(OwnerEntity)), RecvProxy_OwnerEntity),
RecvPropEHandle(FIELD.OF(nameof(EffectEntity))),
RecvPropInt(FIELD.OF(nameof(NetworkMoveParent)), 0, RecvProxy_IntToMoveParent),
RecvPropInt(FIELD.OF(nameof(ParentAttachment))),
Expand Down Expand Up @@ -586,9 +597,9 @@ protected static void RecvProxy_SimulationTime(ref readonly RecvProxyData data,
RecvPropBool(FIELD.OF(nameof(OnFire))),
RecvPropFloat(FIELD.OF(nameof(CreationTime))),

RecvPropFloat(FIELD.OF_VECTORELEM(nameof(Velocity), 0)),
RecvPropFloat(FIELD.OF_VECTORELEM(nameof(Velocity), 1)),
RecvPropFloat(FIELD.OF_VECTORELEM(nameof(Velocity), 2)),
RecvPropFloat(FIELD.OF_VECTORELEM(nameof(Velocity), 0), 0, RecvProxy_LocalVelocityX),
RecvPropFloat(FIELD.OF_VECTORELEM(nameof(Velocity), 1), 0, RecvProxy_LocalVelocityY),
RecvPropFloat(FIELD.OF_VECTORELEM(nameof(Velocity), 2), 0, RecvProxy_LocalVelocityZ),

// NW2 table
RecvPropGModTable(FIELD.OF(nameof(GMOD_DataTable))),
Expand All @@ -610,6 +621,50 @@ protected static void RecvProxy_SimulationTime(ref readonly RecvProxyData data,
RecvPropInt(FIELD.OF(nameof(MapCreatedID))),
]);

private static void RecvProxy_OwnerEntity(ref readonly RecvProxyData data, object instance, IFieldAccessor field) {
RecvProxy_IntToEHandle(in data, instance, field);
((C_BaseEntity)instance).OnOwnerChanged();
}

public virtual void OnOwnerChanged() { }

private static void RecvProxy_LocalVelocityX(ref readonly RecvProxyData data, object instance, IFieldAccessor field) {
C_BaseEntity ent = (C_BaseEntity)instance;
float newVelX = data.Value.Float;
Vector3 velocity = ent.GetLocalVelocity();
if (velocity.X != newVelX) {
velocity.X = newVelX;
ent.SetLocalVelocity(velocity);
}
}

private static void RecvProxy_LocalVelocityY(ref readonly RecvProxyData data, object instance, IFieldAccessor field) {
C_BaseEntity ent = (C_BaseEntity)instance;
float newVelY = data.Value.Float;
Vector3 velocity = ent.GetLocalVelocity();
if (velocity.Y != newVelY) {
velocity.Y = newVelY;
ent.SetLocalVelocity(velocity);
}
}

private static void RecvProxy_LocalVelocityZ(ref readonly RecvProxyData data, object instance, IFieldAccessor field) {
C_BaseEntity ent = (C_BaseEntity)instance;
float newVelZ = data.Value.Float;
Vector3 velocity = ent.GetLocalVelocity();
if (velocity.Z != newVelZ) {
velocity.Z = newVelZ;
ent.SetLocalVelocity(velocity);
}
}

public void SetLocalVelocity(in Vector3 velocity) {
if (Velocity != velocity) {
InvalidatePhysicsRecursive(InvalidatePhysicsBits.VelocityChanged);
Velocity = velocity;
}
}

private static void RecvProxy_MoveCollide(ref readonly RecvProxyData data, object instance, IFieldAccessor field) {
((C_BaseEntity)instance).SetMoveCollide((MoveCollide)data.Value.Int);
}
Expand Down Expand Up @@ -876,7 +931,7 @@ public static bool FClassnameIs(C_BaseEntity? entity, ReadOnlySpan<char> classna
return 0 == strcmp(entity.GetClassname(), classname);
}

public void SetParent(C_BaseEntity parentEntity, int parentAttachment = 0) {
public void SetParent(C_BaseEntity? parentEntity, int parentAttachment = 0) {
EHANDLE newParentHandle = default;
newParentHandle.Set(parentEntity);
if (newParentHandle.Index == MoveParent.Index)
Expand Down Expand Up @@ -1090,8 +1145,13 @@ public void SetModelPointer(Model? model) {
}
void SetModelIndex(int index) {
ModelIndex = index;
#if GMOD_DLL
if (index != -1)
SetModelPointer(modelinfo.GetModel(ModelIndex));
#else
Model? model = modelinfo.GetModel(ModelIndex);
SetModelPointer(model);
#endif
}
public void SetModelByIndex(int modelIndex) {
SetModelIndex(modelIndex);
Expand Down Expand Up @@ -1846,14 +1906,12 @@ public virtual RenderGroup GetRenderGroup() {
if (RenderMode == (int)Source.RenderMode.None)
return RenderGroup.OpaqueEntity;

// todo
// int tempComputeFrame = FXComputeFrame;
// FXComputeFrame = gpGlobals.FrameCount;
long tempComputeFrame = FXComputeFrame;
FXComputeFrame = gpGlobals.FrameCount;

int fxBlend = GetFxBlend();

// todo
// FXComputeFrame = tempComputeFrame;
FXComputeFrame = tempComputeFrame;

if (fxBlend == 0)
return RenderGroup.OpaqueEntity;
Expand Down Expand Up @@ -2027,7 +2085,31 @@ private TimeUnit_t GetLastChangeTime(LatchFlags flags) {
return gpGlobals.CurTime;
}

private void CreateShadow() {
public static bool AllowPrecache;
public static bool IsPrecacheAllowed() => AllowPrecache;
public static void SetAllowPrecache(bool allow) => AllowPrecache = allow;

public void SetBlocksLOS(bool blocksLOS) {
if (blocksLOS)
RemoveEFlags(EFL.DontBlockLOS);
else
AddEFlags(EFL.DontBlockLOS);
}

public virtual CollideType GetCollideType() => CollideType.ShouldNotCollide;

public void UpdatePartitionListEntry() {
PartitionListMask list = PartitionListMask.ClientNonStaticEdicts;
CollideType shouldCollide = GetCollideType();
if (shouldCollide == CollideType.ShouldCollide)
list |= PartitionListMask.ClientSolidEdicts;
else if (shouldCollide == CollideType.ShouldRespond)
list |= PartitionListMask.ClientResponsiveEdicts;

partition.RemoveAndInsert((int)(PartitionListMask.ClientSolidEdicts | PartitionListMask.ClientResponsiveEdicts | PartitionListMask.ClientNonStaticEdicts), (int)list, CollisionProp().GetPartitionHandle());
}

public void CreateShadow() {
ShadowType shadowType = ShadowCastType();
if (shadowType == ShadowType.None)
DestroyShadow();
Expand Down Expand Up @@ -2066,7 +2148,7 @@ public virtual void SpawnClientEntity() { }
public virtual void Precache() { }

public PredictionContext? PredictionContext;
bool Dormant;
public bool Dormant;
bool Predictable;
bool DormantPredictable;
long IncomingPacketEntityBecameDormant;
Expand Down Expand Up @@ -2379,8 +2461,10 @@ private void RemoveAllDecals() {

}

public bool DestroyedOnRecreateEntities;
public void SetDestroyedOnRecreateEntities() {

// ParticleProp().StopEmission(null, false);
DestroyedOnRecreateEntities = true;
}

public virtual ICollideable GetCollideable() => Collision;
Expand All @@ -2407,8 +2491,125 @@ public void OnDataUnchangedInPVS() {
return null;
}

long FXComputeFrame = -1;

public virtual byte GetClientSideFade() => 255;

public virtual void ComputeFxBlend() {
// todo
if (FXComputeFrame == gpGlobals.FrameCount)
return;

int blend = 0;
float offset = EntIndex() * 363.0f;

switch ((RenderFx)RenderFX) {
case RenderFx.PulseSlowWide:
blend = (int)(ColorRender.A + 64 * MathF.Sin((float)gpGlobals.CurTime * 2 + offset));
break;
case RenderFx.PulseFastWide:
blend = (int)(ColorRender.A + 64 * MathF.Sin((float)gpGlobals.CurTime * 8 + offset));
break;
case RenderFx.PulseFastWider:
blend = (int)(255 * MathF.Abs(MathF.Sin((float)gpGlobals.CurTime * 12 + offset)));
break;
case RenderFx.PulseSlow:
blend = (int)(ColorRender.A + 16 * MathF.Sin((float)gpGlobals.CurTime * 2 + offset));
break;
case RenderFx.PulseFast:
blend = (int)(ColorRender.A + 16 * MathF.Sin((float)gpGlobals.CurTime * 8 + offset));
break;
case RenderFx.FadeSlow:
if (ColorRender.A > 0)
SetRenderColorA((byte)(ColorRender.A - 1));
else
SetRenderColorA(0);
blend = ColorRender.A;
break;
case RenderFx.FadeFast:
if (ColorRender.A > 3)
SetRenderColorA((byte)(ColorRender.A - 4));
else
SetRenderColorA(0);
blend = ColorRender.A;
break;
case RenderFx.SolidSlow:
if (ColorRender.A < 255)
SetRenderColorA((byte)(ColorRender.A + 1));
else
SetRenderColorA(255);
blend = ColorRender.A;
break;
case RenderFx.SolidFast:
if (ColorRender.A < 252)
SetRenderColorA((byte)(ColorRender.A + 4));
else
SetRenderColorA(255);
blend = ColorRender.A;
break;
case RenderFx.StrobeSlow:
blend = (int)(20 * MathF.Sin((float)gpGlobals.CurTime * 4 + offset));
blend = blend < 0 ? 0 : ColorRender.A;
break;
case RenderFx.StrobeFast:
blend = (int)(20 * MathF.Sin((float)gpGlobals.CurTime * 16 + offset));
blend = blend < 0 ? 0 : ColorRender.A;
break;
case RenderFx.StrobeFaster:
blend = (int)(20 * MathF.Sin((float)gpGlobals.CurTime * 36 + offset));
blend = blend < 0 ? 0 : ColorRender.A;
break;
case RenderFx.FlickerSlow:
blend = (int)(20 * (MathF.Sin((float)gpGlobals.CurTime * 2) + MathF.Sin((float)gpGlobals.CurTime * 17 + offset)));
blend = blend < 0 ? 0 : ColorRender.A;
break;
case RenderFx.FlickerFast:
blend = (int)(20 * (MathF.Sin((float)gpGlobals.CurTime * 16) + MathF.Sin((float)gpGlobals.CurTime * 23 + offset)));
blend = blend < 0 ? 0 : ColorRender.A;
break;
case RenderFx.Hologram:
case RenderFx.Distort: {
Vector3 tmp = GetAbsOrigin() - ViewAccessors.CurrentViewOrigin();
float dist = MathLib.DotProduct(tmp, ViewAccessors.CurrentViewForward());
if ((RenderFx)RenderFX == RenderFx.Distort)
dist = 1;
if (dist <= 0)
blend = 0;
else {
SetRenderColorA(180);
if (dist <= 100)
blend = ColorRender.A;
else
blend = (int)((1.0 - (dist - 100) * (1.0 / 400.0)) * ColorRender.A);
blend += random.RandomInt(-32, 31);
}
}
break;
default:
if (RenderMode == (int)Source.RenderMode.Normal)
blend = 255;
else
blend = ColorRender.A;
break;
}

blend = Math.Clamp(blend, 0, 255);

byte fadeAlpha = GetClientSideFade();
if (fadeAlpha != 255) {
float flBlend = blend / 255.0f;
float flFade = fadeAlpha / 255.0f;
blend = (int)(flBlend * flFade * 255.0f + 0.5f);
blend = Math.Clamp(blend, 0, 255);
}

RenderFXBlend = (byte)blend;
FXComputeFrame = gpGlobals.FrameCount;

if (renderHandle != INVALID_CLIENT_RENDER_HANDLE)
clientLeafSystem.SetRenderGroup(renderHandle, GetRenderGroup());

if (ShadowHandle != CLIENTSHADOW_INVALID_HANDLE)
g_ClientShadowMgr.SetFalloffBias(ShadowHandle, (byte)(255 - RenderFXBlend));
}

public virtual object GetDataTableBasePtr() {
Expand Down
17 changes: 17 additions & 0 deletions Game.Client/C_BasePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ public bool GetSteamID(out CSteamID id) {
}
return false;
}
PlayerInfo NetworkIDInfo;
InlineArray33<char> NetworkIDString;
public ReadOnlySpan<char> GetNetworkIDString() {
if (engine.GetPlayerInfo(EntIndex(), out NetworkIDInfo)) {
if (NetworkIDInfo.FakePlayer)
return "BOT";
uint friendsID = NetworkIDInfo.FriendsID;
if (friendsID != 0)
sprintf(NetworkIDString, "STEAM_0:%u:%u").U(friendsID & 1).U(friendsID >> 1);
else
for (int i = 0; i < 33; i++)
NetworkIDString[i] = (char)NetworkIDInfo.GUID[i];
return ((ReadOnlySpan<char>)NetworkIDString).SliceNullTerminatedString();
}
return "NULL";
}
public bool IsHLTV() => IsLocalPlayer() && engine.IsHLTV();
public bool IsBot() => false; // TODO, gmod
public static bool ShouldDrawLocalPlayer() {
Expand Down Expand Up @@ -325,6 +341,7 @@ public virtual void PreThink() {
public bool IsInAVehicle() => Vehicle.Get() != null;
#if GMOD_DLL
public virtual bool RestrictPlayerPitch() => false;
public virtual bool CanAttack() => true;
#endif
public virtual void SetAnimation(PlayerAnim playerAnim) { } // todo

Expand Down
Loading
Loading