From f8c9008cc63b80af222064386c93e98eecc16b6c Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Tue, 17 Nov 2026 03:16:52 +0000 Subject: [PATCH 1/9] Fix some missing overrides --- Game.Client/C_BaseAnimating.cs | 6 +++--- Game.Client/HL2/HudBattery.cs | 2 +- Game.Client/HL2/HudHealth.cs | 2 +- Game.Client/HL2/HudSuitPower.cs | 2 +- Game.Server/HL2/HL2_Player.cs | 4 +--- Game.Server/HL2MP/HL2MP_Player.cs | 6 ++---- Game.Server/NavMesh/NavEntities.cs | 20 +++++++++++++++++--- Game.Server/NavMesh/NavMesh.cs | 2 +- Game.Server/Player.cs | 3 --- Game.Server/SoundEnt.cs | 10 ++++++++-- Game.Shared/GameRules.cs | 2 +- Source.Engine/EngineRecvTable.cs | 3 +-- Source.GUI.Controls/Frame.cs | 2 +- Source.GUI.Controls/HTML.cs | 2 +- Source.GUI.Controls/PropertySheet.cs | 4 ++-- Source.GUI.Controls/TreeView.cs | 2 +- 16 files changed, 42 insertions(+), 30 deletions(-) diff --git a/Game.Client/C_BaseAnimating.cs b/Game.Client/C_BaseAnimating.cs index 2d92fe250..9f65a45b8 100644 --- a/Game.Client/C_BaseAnimating.cs +++ b/Game.Client/C_BaseAnimating.cs @@ -1640,8 +1640,8 @@ public void InvalidateMdlCache() { public bool IsModelScaled() => ModelScale > 1.0f + FLT_EPSILON || ModelScale < 1.0f - FLT_EPSILON; public float GetModelScale() => ModelScale; - public int GetBody() => Body; - public int GetSkin() => Skin; + public override int GetBody() => Body; + public override int GetSkin() => Skin; public int InternalDrawModel(StudioFlags flags) { var model = GetModel(); @@ -1768,7 +1768,7 @@ public int LookupBone(ReadOnlySpan name) { return BoneSetup.Studio_BoneIndexByName(GetModelPtr(), name); } - public int LookupAttachment(ReadOnlySpan attachmentName) { + public override int LookupAttachment(ReadOnlySpan attachmentName) { StudioHdr? hdr = GetModelPtr(); if (hdr == null) return -1; diff --git a/Game.Client/HL2/HudBattery.cs b/Game.Client/HL2/HudBattery.cs index 9adb616ae..b8e1aaa0c 100644 --- a/Game.Client/HL2/HudBattery.cs +++ b/Game.Client/HL2/HudBattery.cs @@ -45,7 +45,7 @@ public void VidInit() { Reset(); } - public void Reset() { + public override void Reset() { ReadOnlySpan tempString = Localize.Find("#Valve_Hud_SUIT"); if (!tempString.IsEmpty) diff --git a/Game.Client/HL2/HudHealth.cs b/Game.Client/HL2/HudHealth.cs index f2a223c7a..3402e2f0c 100644 --- a/Game.Client/HL2/HudHealth.cs +++ b/Game.Client/HL2/HudHealth.cs @@ -36,7 +36,7 @@ public void Init() { public void VidInit() { Reset(); } - public void Reset() { + public override void Reset() { Health = -1; #if !GMOD_DLL BitsDamage = 0; diff --git a/Game.Client/HL2/HudSuitPower.cs b/Game.Client/HL2/HudSuitPower.cs index 58b7a3eac..f559e72a2 100644 --- a/Game.Client/HL2/HudSuitPower.cs +++ b/Game.Client/HL2/HudSuitPower.cs @@ -36,7 +36,7 @@ public HudSuitPower(string? panelName) : base("HudSuitPower", panelName) { ((IHudElement)this).SetHiddenBits(HideHudBits.Health | HideHudBits.NeedSuit | HideHudBits.PlayerDead); } - public void Init() { + public override void Init() { SuitPower = SUIT_POWER_INIT; SuitPowerLow = -1; ActiveSuitDevices = 0; diff --git a/Game.Server/HL2/HL2_Player.cs b/Game.Server/HL2/HL2_Player.cs index 5a8bd41e8..7f433c534 100644 --- a/Game.Server/HL2/HL2_Player.cs +++ b/Game.Server/HL2/HL2_Player.cs @@ -323,9 +323,7 @@ bool ApplyBattery(float powerMultiplier) { throw new NotImplementedException(); } - int FlashlightIsOn() { - throw new NotImplementedException(); - } + public override bool FlashlightIsOn() => IsEffectActive(EntityEffects.DimLight); void FlashlightTurnOn() { } diff --git a/Game.Server/HL2MP/HL2MP_Player.cs b/Game.Server/HL2MP/HL2MP_Player.cs index 97291477d..ddde4e154 100644 --- a/Game.Server/HL2MP/HL2MP_Player.cs +++ b/Game.Server/HL2MP/HL2MP_Player.cs @@ -606,9 +606,7 @@ bool BecomeRagdollOnClient(Vector3 force) { void CreateRagdollEntity() { } - int FlashlightIsOn() { - throw new NotImplementedException(); - } + public override bool FlashlightIsOn() => IsEffectActive(EntityEffects.DimLight); void FlashlightTurnOn() { } @@ -752,7 +750,7 @@ void State_Enter_ACTIVE() { } void State_PreThink_ACTIVE() { } - bool CanHearAndReadChatFrom(BasePlayer player) => player != null; + public override bool CanHearAndReadChatFrom(BasePlayer player) => player != null; } [LinkEntityToClass("hl2mp_ragdoll")] diff --git a/Game.Server/NavMesh/NavEntities.cs b/Game.Server/NavMesh/NavEntities.cs index 1075709ae..954970619 100644 --- a/Game.Server/NavMesh/NavEntities.cs +++ b/Game.Server/NavMesh/NavEntities.cs @@ -1,5 +1,6 @@ using Game.Shared; using Source.Common; +using Source.Common.Engine; using System.Numerics; @@ -42,11 +43,24 @@ public partial class FuncNavObstruction : BaseEntity, INavAvoidanceObstacle public bool Disabled; - int DrawDebugTextOverlays() { - throw new NotImplementedException(); + public override int DrawDebugTextOverlays() { + int offset = base.DrawDebugTextOverlays(); + + if ((DebugOverlays & DebugOverlayBits.Text) != 0) { + if (CanObstructNavAreas()) + EntityText(offset++, "Obstructing nav", (float)IVDebugOverlay.NDEBUG_PERSIST_TILL_NEXT_SERVER); + else + EntityText(offset++, "Not obstructing nav", (float)IVDebugOverlay.NDEBUG_PERSIST_TILL_NEXT_SERVER); + } + + return offset; } - void UpdateOnRemove() { } + public override void UpdateOnRemove() { + NavMesh.Instance!.UnregisterAvoidanceObstacle(this); + + base.UpdateOnRemove(); + } public override void Spawn() { SetMoveType(Source.MoveType.None); diff --git a/Game.Server/NavMesh/NavMesh.cs b/Game.Server/NavMesh/NavMesh.cs index 8c6a0f98f..ae18e8a34 100644 --- a/Game.Server/NavMesh/NavMesh.cs +++ b/Game.Server/NavMesh/NavMesh.cs @@ -835,7 +835,7 @@ public void RegisterAvoidanceObstacle(INavAvoidanceObstacle obstruction) { AvoidanceObstacles.Add(obstruction); } - void UnregisterAvoidanceObstacle(INavAvoidanceObstacle obstruction) => AvoidanceObstacles.Remove(obstruction); + public void UnregisterAvoidanceObstacle(INavAvoidanceObstacle obstruction) => AvoidanceObstacles.Remove(obstruction); public List GetObstructions() => AvoidanceObstacles; diff --git a/Game.Server/Player.cs b/Game.Server/Player.cs index 7714fd1b2..e636c7997 100644 --- a/Game.Server/Player.cs +++ b/Game.Server/Player.cs @@ -2365,9 +2365,6 @@ internal bool IsDead() { public virtual void ForceDropOfCarriedPhysObjects(BaseEntity? ground) { } - private Action? FnThink; - internal void Think() => FnThink?.Invoke(); - // todo: thinking about thinking... lots of thinking public Activity GetActivity() { return Activity.ACT_IDLE; } // TODO diff --git a/Game.Server/SoundEnt.cs b/Game.Server/SoundEnt.cs index 0a4ea43c3..5f45b3bf0 100644 --- a/Game.Server/SoundEnt.cs +++ b/Game.Server/SoundEnt.cs @@ -244,8 +244,14 @@ public SoundEnt() { } - public virtual void OnRestore() { - // todo + public override void OnRestore() { + base.OnRestore(); + + if (g_pSoundEnt != null) { + Assert(g_pSoundEnt != this); + Util.Remove(g_pSoundEnt); + } + g_pSoundEnt = this; } public override void Precache() { // todo diff --git a/Game.Shared/GameRules.cs b/Game.Shared/GameRules.cs index f24e0d7b7..2192acc14 100644 --- a/Game.Shared/GameRules.cs +++ b/Game.Shared/GameRules.cs @@ -118,7 +118,7 @@ public abstract class new Vector3(0, 0, 14) //VEC_DEAD_VIEWHEIGHT (DeadViewHeight) ); - public virtual ReadOnlySpan Name() => "GameRules"; + public override ReadOnlySpan Name() => "GameRules"; public abstract bool Damage_IsTimeBased(DamageType dmgType); // Damage types that are time-based. public abstract bool Damage_ShouldGibCorpse(DamageType dmgType); // Damage types that gib the corpse. diff --git a/Source.Engine/EngineRecvTable.cs b/Source.Engine/EngineRecvTable.cs index 66b1006ce..317e7fa39 100644 --- a/Source.Engine/EngineRecvTable.cs +++ b/Source.Engine/EngineRecvTable.cs @@ -267,8 +267,7 @@ public override void RecurseAndCallProxies(SendNode node, object? instance) { return val; } - // TODO: Review why this wasn't overridden. There may have been a good reason for it, I forget. But it's giving compiler warnings. - private object? CallPropProxy(SendNode curChild, int prop, object instance) { + public override object? CallPropProxy(SendNode curChild, int prop, object instance) { RecvProp recvProp = Decoder.GetDatatableProp(prop); object? val = null; diff --git a/Source.GUI.Controls/Frame.cs b/Source.GUI.Controls/Frame.cs index 709a1f7a0..704b6607f 100644 --- a/Source.GUI.Controls/Frame.cs +++ b/Source.GUI.Controls/Frame.cs @@ -542,7 +542,7 @@ public virtual void Activate() { Surface.SetMinimized(this, false); } - public virtual void DoModal() { + public override void DoModal() { MoveToCenterOfScreen(); InvalidateLayout(); Activate(); diff --git a/Source.GUI.Controls/HTML.cs b/Source.GUI.Controls/HTML.cs index c6189c843..e85485694 100644 --- a/Source.GUI.Controls/HTML.cs +++ b/Source.GUI.Controls/HTML.cs @@ -67,7 +67,7 @@ public HTMLFindBar(HTML parent) : base(parent, null) { internal void GetText(Span txt) => FindBar.GetText(txt); - internal void SetText(ReadOnlySpan v) => FindBar.SetText(v); + internal new void SetText(ReadOnlySpan v) => FindBar.SetText(v); internal void HideCountLabel() => FindCountLabel.SetVisible(false); diff --git a/Source.GUI.Controls/PropertySheet.cs b/Source.GUI.Controls/PropertySheet.cs index 30806f677..eddff9c6c 100644 --- a/Source.GUI.Controls/PropertySheet.cs +++ b/Source.GUI.Controls/PropertySheet.cs @@ -105,7 +105,7 @@ public override void OnThink() { base.OnThink(); } - public bool IsDroppable(List msglist) { + public override bool IsDroppable(List msglist) { AttemptingDrop = true; if (GetParent() == null) @@ -932,7 +932,7 @@ public void OnPanelDropped(List msglist) { // todo } - public bool IsDroppable(List msglist) { + public override bool IsDroppable(List msglist) { if (!DraggableTabs) return false; diff --git a/Source.GUI.Controls/TreeView.cs b/Source.GUI.Controls/TreeView.cs index 90cc6c9ab..4e14bf82f 100644 --- a/Source.GUI.Controls/TreeView.cs +++ b/Source.GUI.Controls/TreeView.cs @@ -271,7 +271,7 @@ public TreeNode(Panel? parent, TreeView treeView) : base(parent, "TreeNode") { ExpandableWithoutChildren = false; } - public void SetText(ReadOnlySpan text) => Text.SetText(text); + public new void SetText(ReadOnlySpan text) => Text.SetText(text); public void SetLabelEditingAllowed(bool state) { Assert(TreeView.IsLabelEditingAllowed()); From 0574ea316770107e927e44924deb675e46fda0aa Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Tue, 17 Nov 2026 03:29:08 +0000 Subject: [PATCH 2/9] Fixes --- Game.Client/BaseViewport.cs | 2 +- Game.Client/C_BaseEntity.cs | 2 +- Game.Client/C_FuncSmokeVolume.cs | 2 -- Game.Client/C_ParticleSmokeGrenade.cs | 2 +- Game.Client/C_TEBeamFollow.cs | 2 +- Game.Client/C_Team.cs | 2 +- Game.Client/ClientEntityList.cs | 2 +- Game.Client/ClientModeShared.cs | 4 ++-- Game.Client/HUD/BaseHudChat.cs | 2 +- Game.Client/HistoryResource.cs | 3 ++- Game.Client/Prediction.cs | 3 ++- Game.Server/AI_GoalPolice.cs | 2 +- Game.Server/AI_Hint.cs | 2 +- Game.Server/BaseAnimating.cs | 1 - Game.Server/BaseEntity.cs | 4 ++-- Game.Server/HL2MP/HL2MP_Player.cs | 2 +- Game.Server/NPC_Breen.cs | 2 +- Game.Server/NPC_Citizen.cs | 2 +- Game.Server/NPC_MetroPolice.cs | 2 +- Game.Server/NextBot/FuncNavPrerequisite.cs | 2 +- Game.Server/PathTrack.cs | 4 ++-- Game.Server/Team.cs | 6 +++--- Game.Server/TriggerPlayerMovement.cs | 2 +- Game.Server/Triggers.cs | 4 ++-- Game.Shared/AchievementMgr.cs | 3 ++- Game.Shared/GarrysMod/WeaponPhysCannon.cs | 2 -- Game.Shared/ModelSoundsCache.cs | 3 ++- Game.UI/OptionsSubMultiplayer.cs | 3 ++- Source.Common/Sentence.cs | 16 ++++++++-------- Source.Engine/Client/ClientState.cs | 2 +- Source.Engine/EngineSendTable.cs | 2 +- Source.Engine/GLRSurf.cs | 3 ++- Source.Engine/ModVis.cs | 3 ++- Source.Engine/R_Decal.cs | 4 ++-- Source.Filesystem/GarrysMod/AddonFileSystem.cs | 6 ++++-- Source.StdShader.Gl46/BlurFilterY.cs | 2 +- Source.StdShader.Gl46/Downsample_nohdr.cs | 2 +- Source.StdShader.Gl46/Eyes.cs | 2 +- Source.StdShader.Gl46/IntroScreenSpaceEffect.cs | 2 +- Source.StdShader.Gl46/LightmappedGeneric.cs | 2 +- Source.StdShader.Gl46/Occlusion.cs | 2 +- Source.StdShader.Gl46/Shadow.cs | 2 +- Source.StdShader.Gl46/ShadowModel.cs | 2 +- Source.StdShader.Gl46/Sky_HDR_DX9.cs | 2 +- Source.StdShader.Gl46/Sobel.cs | 2 +- Source.StdShader.Gl46/Sprite.cs | 2 +- Source.StdShader.Gl46/Teeth.cs | 2 +- Source.StdShader.Gl46/UnlitGeneric.cs | 2 +- Source.StdShader.Gl46/UnlitTwoTexture.cs | 2 +- Source.StdShader.Gl46/VertexLitGeneric.cs | 2 +- Source.StdShader.Gl46/Water_DX90.cs | 2 +- Source.StdShader.Gl46/WorldVertexTransition.cs | 2 +- Source.StdShader.Gl46/g_Sky.cs | 2 +- Source.StdShader.Gl46/g_bloom.cs | 2 +- Source.StdShader.Gl46/g_blurx.cs | 2 +- Source.StdShader.Gl46/g_blury.cs | 2 +- Source.StdShader.Gl46/g_bokehblur.cs | 2 +- Source.StdShader.Gl46/g_colourmodify.cs | 2 +- Source.StdShader.Gl46/g_downsample.cs | 2 +- Source.StdShader.Gl46/g_refract.cs | 2 +- Source.StdShader.Gl46/g_sharpen.cs | 2 +- Source.StdShader.Gl46/g_sunbeams.cs | 2 +- Source.StdShader.Gl46/g_texturize.cs | 2 +- Source.StdShader.Gl46/screenspace_general_dx9.cs | 2 +- 64 files changed, 85 insertions(+), 81 deletions(-) diff --git a/Game.Client/BaseViewport.cs b/Game.Client/BaseViewport.cs index 0a4bb243e..e6d0804a2 100644 --- a/Game.Client/BaseViewport.cs +++ b/Game.Client/BaseViewport.cs @@ -43,7 +43,7 @@ public class BaseViewport : EditablePanel, IViewPort readonly Hud HUD = Singleton(); readonly IEngineVGui EngineVGui = Singleton(); bool Initialized; - bool HasParent; + new bool HasParent; InlineArray2 OldSize; public override void OnScreenSizeChanged(int oldWide, int oldTall) { diff --git a/Game.Client/C_BaseEntity.cs b/Game.Client/C_BaseEntity.cs index 620889933..104a1f685 100644 --- a/Game.Client/C_BaseEntity.cs +++ b/Game.Client/C_BaseEntity.cs @@ -1007,7 +1007,7 @@ public ReadOnlySpan GetSubMaterialOverride(int index) { - public int GetTeamNumber() => TeamNum; + public virtual int GetTeamNumber() => TeamNum; public ref readonly Vector3 WorldAlignMins() { Assert(!CollisionProp().IsBoundsDefinedInEntitySpace()); diff --git a/Game.Client/C_FuncSmokeVolume.cs b/Game.Client/C_FuncSmokeVolume.cs index 94c474276..32f5d973c 100644 --- a/Game.Client/C_FuncSmokeVolume.cs +++ b/Game.Client/C_FuncSmokeVolume.cs @@ -1,7 +1,5 @@ using Game.Shared; -using Game.Shared; - using Source; using Source.Common; diff --git a/Game.Client/C_ParticleSmokeGrenade.cs b/Game.Client/C_ParticleSmokeGrenade.cs index 85246d571..f8f4ea1d4 100644 --- a/Game.Client/C_ParticleSmokeGrenade.cs +++ b/Game.Client/C_ParticleSmokeGrenade.cs @@ -15,7 +15,7 @@ public partial class C_ParticleSmokeGrenade : C_BaseParticleEntity ]; [NetworkVar("m_flSpawnTime")] - public float SpawnTime; + public new float SpawnTime; [NetworkVar("m_FadeStartTime")] public float FadeStartTime; [NetworkVar("m_FadeEndTime")] diff --git a/Game.Client/C_TEBeamFollow.cs b/Game.Client/C_TEBeamFollow.cs index f891fa970..0da332d9c 100644 --- a/Game.Client/C_TEBeamFollow.cs +++ b/Game.Client/C_TEBeamFollow.cs @@ -12,7 +12,7 @@ public partial class C_TEBeamFollow : C_BaseBeam ]; [NetworkVar("m_iEntIndex")] - public int EntIndex; + public new int EntIndex; } public static partial class TempEnts diff --git a/Game.Client/C_Team.cs b/Game.Client/C_Team.cs index 6fa66f556..e1b0bf4e5 100644 --- a/Game.Client/C_Team.cs +++ b/Game.Client/C_Team.cs @@ -90,7 +90,7 @@ public static void Recv(ref readonly RecvProxyData data, object instance, IField public void RemoveAllPlayers() => Players.Clear(); public override void PreDataUpdate(DataUpdateType updateType) => base.PreDataUpdate(updateType); public C_BasePlayer? GetPlayer(int idx) => (C_BasePlayer?)cl_entitylist.GetEnt(Players[idx]); - public int GetTeamNumber() => TeamNum; + public override int GetTeamNumber() => TeamNum; public ReadOnlySpan Get_Name() => ((Span)Teamname).SliceNullTerminatedString(); public int Get_Score() => Score; public int Get_Deaths() => Deaths; diff --git a/Game.Client/ClientEntityList.cs b/Game.Client/ClientEntityList.cs index 3c063110a..76481222b 100644 --- a/Game.Client/ClientEntityList.cs +++ b/Game.Client/ClientEntityList.cs @@ -218,7 +218,7 @@ public void RemoveListenerEntity(IClientEntityListener listener) { } - public BaseHandle InvalidHandle() => new(Constants.INVALID_EHANDLE_INDEX); + public new BaseHandle InvalidHandle() => new(Constants.INVALID_EHANDLE_INDEX); public IClientThinkable? GetClientThinkableFromHandle(in BaseHandle hEnt) { IClientUnknown? pEnt = GetClientUnknownFromHandle(hEnt); diff --git a/Game.Client/ClientModeShared.cs b/Game.Client/ClientModeShared.cs index f39772428..4ef3b813c 100644 --- a/Game.Client/ClientModeShared.cs +++ b/Game.Client/ClientModeShared.cs @@ -444,9 +444,9 @@ static void MsgFunc_VGUIMenu(bf_read msg) { if (count > 0) { KeyValues keys = new("data"); + Span name = stackalloc char[256]; + Span data = stackalloc char[255]; for (int i = 0; i < count; i++) { - Span name = stackalloc char[256]; - Span data = stackalloc char[255]; msg.ReadString(name); msg.ReadString(data); keys.SetString(name, data); diff --git a/Game.Client/HUD/BaseHudChat.cs b/Game.Client/HUD/BaseHudChat.cs index 47207126f..a1526af44 100644 --- a/Game.Client/HUD/BaseHudChat.cs +++ b/Game.Client/HUD/BaseHudChat.cs @@ -45,7 +45,7 @@ public override void ApplySchemeSettings(IScheme scheme) { SetFont(Font); } - internal IFont? GetFont() { + internal new IFont? GetFont() { return Font; } diff --git a/Game.Client/HistoryResource.cs b/Game.Client/HistoryResource.cs index 6d4e62c14..c44c6f15f 100644 --- a/Game.Client/HistoryResource.cs +++ b/Game.Client/HistoryResource.cs @@ -219,6 +219,7 @@ public override void Paint() { GetSize(out int wide, out int tall); + Span text = stackalloc char[16]; for (int i = 0; i < PickupHistory.Count; i++) { var item = PickupHistory[i]; if (item.Type != null) { @@ -308,7 +309,7 @@ public override void Paint() { itemAmmoIcon?.DrawSelf((int)(xpos - (itemAmmoIcon.Width() * 1.25f)), ypos, clr); if (amount != 0) { - Span text = stackalloc char[16]; + text.Clear(); sprintf(text, "%i").I(amount); ypos -= (Surface.GetFontTall(NumberFont) - itemIcon.Height()) / 2; diff --git a/Game.Client/Prediction.cs b/Game.Client/Prediction.cs index 126a91bfe..7b8410faa 100644 --- a/Game.Client/Prediction.cs +++ b/Game.Client/Prediction.cs @@ -228,6 +228,7 @@ public void PostNetworkDataReceived(int commandsAcknowledged) { // Transfer intermediate data from other predictables int c = predictables.GetPredictableCount(); int i; + Span szBuf = stackalloc char[32]; for (i = 0; i < c; i++) { C_BaseEntity? ent = predictables.GetPredictable(i); if (ent == null) @@ -238,7 +239,7 @@ public void PostNetworkDataReceived(int commandsAcknowledged) { PreviousAckHadErrors = true; if (showlist != 0) { - Span sz = stackalloc char[32]; + Span sz = szBuf; if (ent.EntIndex() == -1) sz = sprintf(sz, "handle %u").U((uint)ent.GetClientHandle().Index); else diff --git a/Game.Server/AI_GoalPolice.cs b/Game.Server/AI_GoalPolice.cs index 89a7c7586..236de40af 100644 --- a/Game.Server/AI_GoalPolice.cs +++ b/Game.Server/AI_GoalPolice.cs @@ -109,7 +109,7 @@ public void FireWarningLevelOutput(int level) { public void InputDisableKnockOut(InputData data) => OverrideKnockOut = false; public float Radius; - public EHANDLE Target = new(); + public new EHANDLE Target = new(); public string? TargetName; public bool OverrideKnockOut; diff --git a/Game.Server/AI_Hint.cs b/Game.Server/AI_Hint.cs index ead6c7674..f12195ea8 100644 --- a/Game.Server/AI_Hint.cs +++ b/Game.Server/AI_Hint.cs @@ -339,7 +339,7 @@ public float Yaw() { return GetLocalAngles().Y; } - bool IsViewable() { + public override bool IsViewable() { if (NodeData.Disabled != 0) return false; diff --git a/Game.Server/BaseAnimating.cs b/Game.Server/BaseAnimating.cs index b9493c0ca..b2ec8350d 100644 --- a/Game.Server/BaseAnimating.cs +++ b/Game.Server/BaseAnimating.cs @@ -396,7 +396,6 @@ public Activity GetSequenceActivity(int sequence) { public float GetModelScale() => ModelScale; protected StudioHdr? StudioHdr; - public Model? GetModel() => modelinfo.GetModel(GetModelIndex()); // todo... public StudioHdr? GetModelPtr() { diff --git a/Game.Server/BaseEntity.cs b/Game.Server/BaseEntity.cs index fb78338fa..e07ca355a 100644 --- a/Game.Server/BaseEntity.cs +++ b/Game.Server/BaseEntity.cs @@ -920,7 +920,7 @@ public bool IsStandable() { public virtual bool CanBeSeenBy(AI_BaseNPC npc) => true; - public bool IsViewable() { + public virtual bool IsViewable() { if (IsEffectActive(EntityEffects.NoDraw)) return false; @@ -1427,7 +1427,7 @@ public static void EmitSound(scoped in IRF filter, int entIndex, scoped in public Team? GetTeam() => GetGlobalTeam(TeamNum); - public int GetTeamNumber() => TeamNum; + public virtual int GetTeamNumber() => TeamNum; IPhysicsObject? PhysicsObject = null!; public virtual void VPhysicsUpdate(IPhysicsObject physics) { diff --git a/Game.Server/HL2MP/HL2MP_Player.cs b/Game.Server/HL2MP/HL2MP_Player.cs index ddde4e154..69d035e63 100644 --- a/Game.Server/HL2MP/HL2MP_Player.cs +++ b/Game.Server/HL2MP/HL2MP_Player.cs @@ -579,7 +579,7 @@ public bool ClientCommand(in TokenizedCommand args) { void CheatImpulseCommands(int impulse) { } - bool ShouldRunRateLimitedCommand(in TokenizedCommand args) { + new bool ShouldRunRateLimitedCommand(in TokenizedCommand args) { throw new NotImplementedException(); } diff --git a/Game.Server/NPC_Breen.cs b/Game.Server/NPC_Breen.cs index b7d435988..317a8c466 100644 --- a/Game.Server/NPC_Breen.cs +++ b/Game.Server/NPC_Breen.cs @@ -13,7 +13,7 @@ namespace Game.Server; public class NPC_Breen : AI_BaseActor { [Flags] - public enum SF + public new enum SF { BackgroundTalk = 1 << 16, } diff --git a/Game.Server/NPC_Citizen.cs b/Game.Server/NPC_Citizen.cs index 32f9e125c..be239982d 100644 --- a/Game.Server/NPC_Citizen.cs +++ b/Game.Server/NPC_Citizen.cs @@ -37,7 +37,7 @@ public enum CitizenExpressionType public class NPC_Citizen : NPC_PlayerCompanion { [Flags] - public enum SF + public new enum SF { Follow = 1 << 16, Medic = 1 << 17, diff --git a/Game.Server/NPC_MetroPolice.cs b/Game.Server/NPC_MetroPolice.cs index 6b959d128..06153f7fa 100644 --- a/Game.Server/NPC_MetroPolice.cs +++ b/Game.Server/NPC_MetroPolice.cs @@ -21,7 +21,7 @@ namespace Game.Server; public class NPC_MetroPolice : AI_BaseActor { [Flags] - public enum SF + public new enum SF { SimpleVersion = 0x00020000, AlwaysStitch = 0x00080000, diff --git a/Game.Server/NextBot/FuncNavPrerequisite.cs b/Game.Server/NextBot/FuncNavPrerequisite.cs index 47a79f090..f1d1cf8cd 100644 --- a/Game.Server/NextBot/FuncNavPrerequisite.cs +++ b/Game.Server/NextBot/FuncNavPrerequisite.cs @@ -11,6 +11,6 @@ class FuncNavPrerequisite : BaseTrigger int Task; string TaskEntityName; float TaskValue; - bool Disabled; + new bool Disabled; EHANDLE TaskEntity; } \ No newline at end of file diff --git a/Game.Server/PathTrack.cs b/Game.Server/PathTrack.cs index f9f3f45d9..3a3cd3ae4 100644 --- a/Game.Server/PathTrack.cs +++ b/Game.Server/PathTrack.cs @@ -92,7 +92,7 @@ public override void Activate() { Link(); } - void Link() { + new void Link() { BaseEntity? target; if (!string.IsNullOrEmpty(Target)) { @@ -187,7 +187,7 @@ public void TogglePath() { return path; } - public static PathTrack? Instance(Edict ent) { + public static new PathTrack? Instance(Edict ent) { BaseEntity? entity = BaseEntity.Instance(ent); if (FClassnameIs(entity, "path_track")) return (PathTrack?)entity; diff --git a/Game.Server/Team.cs b/Game.Server/Team.cs index a90d9700c..4645e29db 100644 --- a/Game.Server/Team.cs +++ b/Game.Server/Team.cs @@ -50,9 +50,9 @@ public static void Send(SendProp prop, object instance, IFieldAccessor field, re } } - internal ReadOnlySpan GetName() { - throw new NotImplementedException(); - } + public override int GetTeamNumber() => TeamNum; + + internal ReadOnlySpan GetName() => ((ReadOnlySpan)Teamname).SliceNullTerminatedString(); public void AddPlayer(BasePlayer player) { Players.Add(player); diff --git a/Game.Server/TriggerPlayerMovement.cs b/Game.Server/TriggerPlayerMovement.cs index 8c95d293c..6c7e94771 100644 --- a/Game.Server/TriggerPlayerMovement.cs +++ b/Game.Server/TriggerPlayerMovement.cs @@ -14,7 +14,7 @@ public partial class TriggerPlayerMovement : BaseTrigger ]; [Flags] - public enum SF + public new enum SF { MoveAutoDisable = 0x80, // disable auto movement AutoDuck = 0x800, // Duck automatically diff --git a/Game.Server/Triggers.cs b/Game.Server/Triggers.cs index b8a3b19b2..cac765f46 100644 --- a/Game.Server/Triggers.cs +++ b/Game.Server/Triggers.cs @@ -909,7 +909,7 @@ public override void Spawn() { public class TriggerLook : TriggerOnce { [Flags] - public enum SF + public new enum SF { FireOnce = 128, UseVelocity = 256, @@ -1224,7 +1224,7 @@ public override void Touch(BaseEntity? other) { public class TriggerTeleport : BaseTrigger { [Flags] - public enum SF + public new enum SF { PreserveAngles = 0x20, // Preserve angles even when a local landmark is not specified } diff --git a/Game.Shared/AchievementMgr.cs b/Game.Shared/AchievementMgr.cs index edcd893b3..c2a8be06c 100644 --- a/Game.Shared/AchievementMgr.cs +++ b/Game.Shared/AchievementMgr.cs @@ -844,6 +844,7 @@ public void SetAchievementThink(BaseAchievement achievement, float thinkTime) { } void UpdateStateFromSteam_Internal() { + Span progressName = stackalloc char[1024]; foreach (BaseAchievement achievement in MapAchievement.Values) { bool ret = Steam3Client().SteamUserStats().GetAchievementAndUnlockTime(achievement.GetName(), out bool achieved, out uint unlockTime); @@ -855,7 +856,7 @@ void UpdateStateFromSteam_Internal() { DevMsg($"ISteamUserStats::GetAchievement failed for {achievement.GetName()}\n"); if (achievement.StoreProgressInSteam()) { - Span progressName = stackalloc char[1024]; + progressName.Clear(); sprintf(progressName, "%s_STAT").S(achievement.GetStat()); ret = Steam3Client().SteamUserStats().GetStat(progressName.SliceNullTerminatedString(), out int value); if (ret) { diff --git a/Game.Shared/GarrysMod/WeaponPhysCannon.cs b/Game.Shared/GarrysMod/WeaponPhysCannon.cs index f535d755a..0aaf21905 100644 --- a/Game.Shared/GarrysMod/WeaponPhysCannon.cs +++ b/Game.Shared/GarrysMod/WeaponPhysCannon.cs @@ -4,8 +4,6 @@ #if CLIENT_DLL using Game.Client; -using Source; - #endif using Source.Common; diff --git a/Game.Shared/ModelSoundsCache.cs b/Game.Shared/ModelSoundsCache.cs index 9ec7b7eab..98005330e 100644 --- a/Game.Shared/ModelSoundsCache.cs +++ b/Game.Shared/ModelSoundsCache.cs @@ -53,6 +53,7 @@ public static void BuildAnimationEventSoundList(StudioHdr hdr, List soun Animation.VerifySequenceIndex(hdr); + Span soundname = stackalloc char[256]; for (int iSeq = 0; iSeq < hdr.GetNumSeq(); iSeq++) { MStudioSeqDesc seq = hdr.Seqdesc(iSeq); @@ -73,7 +74,7 @@ public static void BuildAnimationEventSoundList(StudioHdr hdr, List soun break; case CL_EVENT_FOOTSTEP_LEFT: case CL_EVENT_FOOTSTEP_RIGHT: { - Span soundname = stackalloc char[256]; + soundname.Clear(); ReadOnlySpan options = Encoding.ASCII.GetString(((ReadOnlySpan)ev.Options()).SliceNullTerminatedString()); if (options.IsEmpty) options = "NPC_CombineS"; diff --git a/Game.UI/OptionsSubMultiplayer.cs b/Game.UI/OptionsSubMultiplayer.cs index a804b4410..5c377c102 100644 --- a/Game.UI/OptionsSubMultiplayer.cs +++ b/Game.UI/OptionsSubMultiplayer.cs @@ -93,8 +93,9 @@ void InitLogoList(LabeledCommandComboBox cb) { ReadOnlySpan fn = g_pFileSystem.FindFirstEx(directory.SliceNullTerminatedString(), null, out FileFindHandle_t fh); int i = 0, initialItem = 0; + Span filename = stackalloc char[512]; while (!fn.IsEmpty) { - Span filename = stackalloc char[512]; + filename.Clear(); sprintf(filename, "materials/vgui/logos/%s").S(fn); if (strlen(filename) >= 4) { filename[(int)strlen(filename) - 4] = '\0'; diff --git a/Source.Common/Sentence.cs b/Source.Common/Sentence.cs index cfcd01e85..5bce7029f 100644 --- a/Source.Common/Sentence.cs +++ b/Source.Common/Sentence.cs @@ -372,6 +372,7 @@ void ParsePlaintext(UtlBuffer buf) { void ParseWords(UtlBuffer buf) { Span token = stackalloc char[4096]; Span word = stackalloc char[256]; + Span phonemename = stackalloc char[256]; while (true) { buf.GetString(token); @@ -407,7 +408,6 @@ void ParseWords(UtlBuffer buf) { // Parse phoneme int code = AToI(token); buf.GetString(token); - Span phonemename = stackalloc char[256]; strcpy(phonemename, token.SliceNullTerminatedString()); buf.GetString(token); start = StrToF(token); @@ -429,16 +429,16 @@ void ParseWords(UtlBuffer buf) { void ParseEmphasis(UtlBuffer buf) { Span token = stackalloc char[4096]; + Span t = stackalloc char[256]; + Span value = stackalloc char[256]; while (true) { buf.GetString(token); if (token[0] == '}') break; - Span t = stackalloc char[256]; strcpy(t, token.SliceNullTerminatedString()); buf.GetString(token); - Span value = stackalloc char[256]; strcpy(value, token.SliceNullTerminatedString()); EmphasisSample sample = default; @@ -455,6 +455,8 @@ void ParseEmphasis(UtlBuffer buf) { // This is obsolete, so it doesn't do anything with the data which is parsed. void ParseCloseCaption(UtlBuffer buf) { Span token = stackalloc char[4096]; + Span cc_type = stackalloc char[32]; + Span cc_stream = stackalloc byte[4096]; while (true) { // Format is // language_name @@ -478,8 +480,6 @@ void ParseCloseCaption(UtlBuffer buf) { if (stricmp(token.SliceNullTerminatedString(), "PHRASE") != 0) break; - Span cc_type = stackalloc char[32]; - Span cc_stream = stackalloc byte[4096]; int cc_length; buf.GetString(token); @@ -511,14 +511,14 @@ void ParseCloseCaption(UtlBuffer buf) { void ParseOptions(UtlBuffer buf) { Span token = stackalloc char[4096]; + Span key = stackalloc char[256]; + Span value = stackalloc char[256]; while (true) { buf.GetString(token); if (token[0] == '\0' || token[0] == '}') break; - Span key = stackalloc char[256]; strcpy(key, token.SliceNullTerminatedString()); - Span value = stackalloc char[256]; buf.GetString(token); strcpy(value, token.SliceNullTerminatedString()); @@ -531,6 +531,7 @@ void ParseOptions(UtlBuffer buf) { void ParseDataVersionOnePointZero(UtlBuffer buf) { Span token = stackalloc char[4096]; + Span section = stackalloc char[256]; while (true) { buf.GetString(token); @@ -541,7 +542,6 @@ void ParseDataVersionOnePointZero(UtlBuffer buf) { if (token[0] == '}') break; - Span section = stackalloc char[256]; strcpy(section, token.SliceNullTerminatedString()); buf.GetString(token); diff --git a/Source.Engine/Client/ClientState.cs b/Source.Engine/Client/ClientState.cs index a5a27d20c..47f9557d3 100644 --- a/Source.Engine/Client/ClientState.cs +++ b/Source.Engine/Client/ClientState.cs @@ -325,7 +325,7 @@ public override void ConnectionClosing(ReadOnlySpan reason) { } GameEventManager? gem; - GameEventManager gameEventManager => gem ??= (GameEventManager)Singleton(); + new GameEventManager gameEventManager => gem ??= (GameEventManager)Singleton(); protected override bool ProcessGameEventList(SVC_GameEventList msg) { return gameEventManager.ParseEventList(msg); } diff --git a/Source.Engine/EngineSendTable.cs b/Source.Engine/EngineSendTable.cs index 736efcd42..276cf5694 100644 --- a/Source.Engine/EngineSendTable.cs +++ b/Source.Engine/EngineSendTable.cs @@ -339,7 +339,7 @@ class EncodeInfo(SendTablePrecalc precalc, object structData, int objectId, bf_w class PropCullStack : DatatableStack { - SendTablePrecalc Precalc; + new SendTablePrecalc Precalc; int Client; List? OldStateProxies; int NumOldStateProxies; diff --git a/Source.Engine/GLRSurf.cs b/Source.Engine/GLRSurf.cs index 5635e5db4..b1014af27 100644 --- a/Source.Engine/GLRSurf.cs +++ b/Source.Engine/GLRSurf.cs @@ -1576,8 +1576,9 @@ public void LevelInit() { } public void ClearRenderHandles() { + Span brushModel = stackalloc char[5]; for (int brush = 1; brush < host_state.WorldBrush!.NumSubModels; ++brush) { - Span brushModel = stackalloc char[5]; + brushModel.Clear(); sprintf(brushModel, $"*{brush}"); Model? model = modelloader.GetModelForName(brushModel.SliceNullTerminatedString(), ModelLoaderFlags.Server); model?.Brush.RenderHandle = 0; diff --git a/Source.Engine/ModVis.cs b/Source.Engine/ModVis.cs index 81069ea38..ae17cba3c 100644 --- a/Source.Engine/ModVis.cs +++ b/Source.Engine/ModVis.cs @@ -209,8 +209,9 @@ public static void Map_VisMark(bool forceNoVis, Model? worldModel) { c = (CM.NumClusters() + 31) / 32; + Span mapVis = stackalloc byte[BSPFileCommon.MAX_MAP_CLUSTERS / 8]; for (i = 1; i < vis.NumClusters; i++) { - Span mapVis = stackalloc byte[BSPFileCommon.MAX_MAP_CLUSTERS / 8]; + mapVis.Clear(); CM.Vis(mapVis, mapVis.Length, vis.VisClusters[i].ViewCluster, CM.DVIS_PVS); diff --git a/Source.Engine/R_Decal.cs b/Source.Engine/R_Decal.cs index 7c9505fd6..52d535aad 100644 --- a/Source.Engine/R_Decal.cs +++ b/Source.Engine/R_Decal.cs @@ -963,13 +963,13 @@ static void DecalVertsLight(Span v, in DecalContext context, SurfaceH bool fullMatch = false; Decal? decal = MSurf_DecalPointer(surfID); List coveredList = []; + Span testBasis = stackalloc Vector3[3]; + Span testWorldScale = stackalloc float[2]; while (decal != null) { material = decal.Material; if ((decal.Flags & FDecal.Permanent) == 0 && (decal.Flags & FDecal.PlayerSpray) == 0 && material != null) { - Span testBasis = stackalloc Vector3[3]; - Span testWorldScale = stackalloc float[2]; SetupDecalTextureSpaceBasis(decal, ref ModelLoader.MSurf_Plane(ref surf).Normal, material, testBasis, testWorldScale); Vector2 decalMin = new(Vector3.Dot(decalInfo.Position - decalExtents[0], testBasis[0]) - decal.Dx + 0.5f, Vector3.Dot(decalInfo.Position - decalExtents[1], testBasis[1]) - decal.Dy + 0.5f); diff --git a/Source.Filesystem/GarrysMod/AddonFileSystem.cs b/Source.Filesystem/GarrysMod/AddonFileSystem.cs index cc3d7e960..18e8cbdf2 100644 --- a/Source.Filesystem/GarrysMod/AddonFileSystem.cs +++ b/Source.Filesystem/GarrysMod/AddonFileSystem.cs @@ -503,13 +503,15 @@ public void AddJob(Addon.Job.Base job) { public void MountFloatingAddons() { ReadOnlySpan file = g_FullFileSystem.FindFirstEx("*.gma", "GAME", out ulong findHandle); + Span fullPathBuffer = stackalloc char[MAX_PATH]; + Span relativeBuffer = stackalloc char[MAX_PATH]; while (!file.IsEmpty) { string fileName = new(file.SliceNullTerminatedString()); - Span fullPathBuffer = stackalloc char[MAX_PATH]; + fullPathBuffer.Clear(); ReadOnlySpan fullPath = g_FullFileSystem.RelativePathToFullPath(fileName, "GAME", fullPathBuffer); - Span relativeBuffer = stackalloc char[MAX_PATH]; + relativeBuffer.Clear(); bool converted = !fullPath.IsEmpty && g_FullFileSystem.FullPathToRelativePath(fullPath, relativeBuffer); string relative = converted ? new string(((ReadOnlySpan)relativeBuffer).SliceNullTerminatedString()) : ""; if (converted) { diff --git a/Source.StdShader.Gl46/BlurFilterY.cs b/Source.StdShader.Gl46/BlurFilterY.cs index df8243305..a7bffcbf6 100644 --- a/Source.StdShader.Gl46/BlurFilterY.cs +++ b/Source.StdShader.Gl46/BlurFilterY.cs @@ -25,7 +25,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/Downsample_nohdr.cs b/Source.StdShader.Gl46/Downsample_nohdr.cs index 23f617419..0f56c838d 100644 --- a/Source.StdShader.Gl46/Downsample_nohdr.cs +++ b/Source.StdShader.Gl46/Downsample_nohdr.cs @@ -26,7 +26,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/Eyes.cs b/Source.StdShader.Gl46/Eyes.cs index bc9a1719a..6082743f5 100644 --- a/Source.StdShader.Gl46/Eyes.cs +++ b/Source.StdShader.Gl46/Eyes.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/IntroScreenSpaceEffect.cs b/Source.StdShader.Gl46/IntroScreenSpaceEffect.cs index 9222cdfdb..9e3d4a39e 100644 --- a/Source.StdShader.Gl46/IntroScreenSpaceEffect.cs +++ b/Source.StdShader.Gl46/IntroScreenSpaceEffect.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/LightmappedGeneric.cs b/Source.StdShader.Gl46/LightmappedGeneric.cs index 1dd413c4a..beb55d895 100644 --- a/Source.StdShader.Gl46/LightmappedGeneric.cs +++ b/Source.StdShader.Gl46/LightmappedGeneric.cs @@ -39,7 +39,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/Occlusion.cs b/Source.StdShader.Gl46/Occlusion.cs index dbedaf504..8e21bc8a4 100644 --- a/Source.StdShader.Gl46/Occlusion.cs +++ b/Source.StdShader.Gl46/Occlusion.cs @@ -43,7 +43,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/Shadow.cs b/Source.StdShader.Gl46/Shadow.cs index 9840c9a7c..34deda225 100644 --- a/Source.StdShader.Gl46/Shadow.cs +++ b/Source.StdShader.Gl46/Shadow.cs @@ -45,7 +45,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/ShadowModel.cs b/Source.StdShader.Gl46/ShadowModel.cs index 731558545..2306b2bd9 100644 --- a/Source.StdShader.Gl46/ShadowModel.cs +++ b/Source.StdShader.Gl46/ShadowModel.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/Sky_HDR_DX9.cs b/Source.StdShader.Gl46/Sky_HDR_DX9.cs index 243708123..3c3956b19 100644 --- a/Source.StdShader.Gl46/Sky_HDR_DX9.cs +++ b/Source.StdShader.Gl46/Sky_HDR_DX9.cs @@ -28,7 +28,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/Sobel.cs b/Source.StdShader.Gl46/Sobel.cs index 17e9ecdbc..6496c8233 100644 --- a/Source.StdShader.Gl46/Sobel.cs +++ b/Source.StdShader.Gl46/Sobel.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/Sprite.cs b/Source.StdShader.Gl46/Sprite.cs index 33f8132dc..480ca613e 100644 --- a/Source.StdShader.Gl46/Sprite.cs +++ b/Source.StdShader.Gl46/Sprite.cs @@ -45,7 +45,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/Teeth.cs b/Source.StdShader.Gl46/Teeth.cs index 22c1f2204..8ac115e99 100644 --- a/Source.StdShader.Gl46/Teeth.cs +++ b/Source.StdShader.Gl46/Teeth.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/UnlitGeneric.cs b/Source.StdShader.Gl46/UnlitGeneric.cs index 834d4edf9..79174ad41 100644 --- a/Source.StdShader.Gl46/UnlitGeneric.cs +++ b/Source.StdShader.Gl46/UnlitGeneric.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/UnlitTwoTexture.cs b/Source.StdShader.Gl46/UnlitTwoTexture.cs index d98c7e140..448b76b2f 100644 --- a/Source.StdShader.Gl46/UnlitTwoTexture.cs +++ b/Source.StdShader.Gl46/UnlitTwoTexture.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/VertexLitGeneric.cs b/Source.StdShader.Gl46/VertexLitGeneric.cs index d3f1a7b97..bbdf8e639 100644 --- a/Source.StdShader.Gl46/VertexLitGeneric.cs +++ b/Source.StdShader.Gl46/VertexLitGeneric.cs @@ -39,7 +39,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/Water_DX90.cs b/Source.StdShader.Gl46/Water_DX90.cs index 7b34e7a28..d35ecdf4b 100644 --- a/Source.StdShader.Gl46/Water_DX90.cs +++ b/Source.StdShader.Gl46/Water_DX90.cs @@ -28,7 +28,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/WorldVertexTransition.cs b/Source.StdShader.Gl46/WorldVertexTransition.cs index 91ecd877a..682d7be03 100644 --- a/Source.StdShader.Gl46/WorldVertexTransition.cs +++ b/Source.StdShader.Gl46/WorldVertexTransition.cs @@ -45,7 +45,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_Sky.cs b/Source.StdShader.Gl46/g_Sky.cs index e6513e500..d0df4275b 100644 --- a/Source.StdShader.Gl46/g_Sky.cs +++ b/Source.StdShader.Gl46/g_Sky.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_bloom.cs b/Source.StdShader.Gl46/g_bloom.cs index 86bc93b7c..db7b514fc 100644 --- a/Source.StdShader.Gl46/g_bloom.cs +++ b/Source.StdShader.Gl46/g_bloom.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_blurx.cs b/Source.StdShader.Gl46/g_blurx.cs index a739bf810..f7923f770 100644 --- a/Source.StdShader.Gl46/g_blurx.cs +++ b/Source.StdShader.Gl46/g_blurx.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_blury.cs b/Source.StdShader.Gl46/g_blury.cs index 9756b85c0..e3b58ff54 100644 --- a/Source.StdShader.Gl46/g_blury.cs +++ b/Source.StdShader.Gl46/g_blury.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_bokehblur.cs b/Source.StdShader.Gl46/g_bokehblur.cs index 395e02977..954741f94 100644 --- a/Source.StdShader.Gl46/g_bokehblur.cs +++ b/Source.StdShader.Gl46/g_bokehblur.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_colourmodify.cs b/Source.StdShader.Gl46/g_colourmodify.cs index 608267bee..376eb0a15 100644 --- a/Source.StdShader.Gl46/g_colourmodify.cs +++ b/Source.StdShader.Gl46/g_colourmodify.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_downsample.cs b/Source.StdShader.Gl46/g_downsample.cs index 16e5426d7..c89d1ab02 100644 --- a/Source.StdShader.Gl46/g_downsample.cs +++ b/Source.StdShader.Gl46/g_downsample.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_refract.cs b/Source.StdShader.Gl46/g_refract.cs index 7dcbd4d91..248163b4d 100644 --- a/Source.StdShader.Gl46/g_refract.cs +++ b/Source.StdShader.Gl46/g_refract.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_sharpen.cs b/Source.StdShader.Gl46/g_sharpen.cs index 94f6022c0..432bcc134 100644 --- a/Source.StdShader.Gl46/g_sharpen.cs +++ b/Source.StdShader.Gl46/g_sharpen.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_sunbeams.cs b/Source.StdShader.Gl46/g_sunbeams.cs index 6e5f52e61..d29548caa 100644 --- a/Source.StdShader.Gl46/g_sunbeams.cs +++ b/Source.StdShader.Gl46/g_sunbeams.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/g_texturize.cs b/Source.StdShader.Gl46/g_texturize.cs index ca0d87d23..f20e68a24 100644 --- a/Source.StdShader.Gl46/g_texturize.cs +++ b/Source.StdShader.Gl46/g_texturize.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; diff --git a/Source.StdShader.Gl46/screenspace_general_dx9.cs b/Source.StdShader.Gl46/screenspace_general_dx9.cs index 50022d3b5..604d2c60d 100644 --- a/Source.StdShader.Gl46/screenspace_general_dx9.cs +++ b/Source.StdShader.Gl46/screenspace_general_dx9.cs @@ -44,7 +44,7 @@ public ShaderParam(string name, ShaderParamType type, ReadOnlySpan default } public static implicit operator int(ShaderParam param) => param.Index; public ReadOnlySpan GetName() => Info.Name; - public ShaderParamType GetType() => Info.Type; + public new ShaderParamType GetType() => Info.Type; public ReadOnlySpan GetDefaultValue() => Info.DefaultValue; public ShaderParamFlags GetFlags() => Info.Flags; public ReadOnlySpan GetHelp() => Info.Help; From eb62ef6f2ffb864be1fef9fa3af31c267f66c223 Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Tue, 17 Nov 2026 03:30:43 +0000 Subject: [PATCH 3/9] Fix span checks --- Game.Shared/MapEntitiesShared.cs | 2 +- Source.Engine/Client/ClientState.cs | 2 +- Source.Engine/Host.cs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Game.Shared/MapEntitiesShared.cs b/Game.Shared/MapEntitiesShared.cs index 7d6765d62..bba9cc864 100644 --- a/Game.Shared/MapEntitiesShared.cs +++ b/Game.Shared/MapEntitiesShared.cs @@ -168,7 +168,7 @@ public static ReadOnlySpan ParseToken(ReadOnlySpan data, scoped Span int len = 0; newToken[0] = 0; - if (data == default || data.IsEmpty) + if (data.IsEmpty) return null; if (s_BuildReverseMap) { diff --git a/Source.Engine/Client/ClientState.cs b/Source.Engine/Client/ClientState.cs index 47f9557d3..0bf088bf5 100644 --- a/Source.Engine/Client/ClientState.cs +++ b/Source.Engine/Client/ClientState.cs @@ -314,7 +314,7 @@ public override void FullConnect(NetAddress adr) { public override void SetServerTickCount(int tick) => ClockDriftMgr.ServerTick = tick; public override void ConnectionClosing(ReadOnlySpan reason) { if (SignOnState > SignOnState.None) { - if (reason != null && reason.Length > 0 && reason[0] == '#') + if (!reason.IsEmpty && reason[0] == '#') Common.ExplainDisconnection(true, reason); else Common.ExplainDisconnection(true, $"Disconnect: {reason}.\n"); diff --git a/Source.Engine/Host.cs b/Source.Engine/Host.cs index bee23c953..a509d66e9 100644 --- a/Source.Engine/Host.cs +++ b/Source.Engine/Host.cs @@ -919,7 +919,7 @@ void disconnect(in TokenizedCommand args) { void pause(in TokenizedCommand args, CommandSource source, int clientSlot) { #if !SWDS if (!sv.IsDedicated()) { - if (cl.LevelFileName == null || cl.LevelFileName.Length == 0) + if (cl.LevelFileName.IsEmpty) return; } #endif @@ -940,7 +940,7 @@ void pause(in TokenizedCommand args, CommandSource source, int clientSlot) { [ConCommand("setpause", "Set the pause state of the server.")] void setpause(in TokenizedCommand args, CommandSource source, int clientSlot) { #if !SWDS - if (cl.LevelFileName == null || cl.LevelFileName.Length == 0) + if (cl.LevelFileName.IsEmpty) return; #endif @@ -955,7 +955,7 @@ void setpause(in TokenizedCommand args, CommandSource source, int clientSlot) { [ConCommand("unpause", "Unpause the game.")] void unpause(in TokenizedCommand args, CommandSource source, int clientSlot) { #if !SWDS - if (cl.LevelFileName == null || cl.LevelFileName.Length == 0) + if (cl.LevelFileName.IsEmpty) return; #endif From 82b27e5db3cdcfb767894075623c8db3f8e487bc Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Tue, 17 Nov 2026 03:37:28 +0000 Subject: [PATCH 4/9] Fix ref safety warnings --- Game.Server/BaseAnimating.cs | 6 ++-- Game.Server/SoundEnt.cs | 5 +-- Source.Common/BoneSetup.cs | 8 ++--- Source.Common/Formats/BSP/BSPFile.cs | 5 +-- .../ISoundEmitterSystemBase.cs | 7 ++-- Source.Engine/CModel_Private.cs | 2 +- Source.Engine/GLRSurf.cs | 36 +++++++++---------- Source.Engine/Host.cs | 6 ++-- Source.Engine/SpatialPartition.cs | 8 ++--- 9 files changed, 38 insertions(+), 45 deletions(-) diff --git a/Game.Server/BaseAnimating.cs b/Game.Server/BaseAnimating.cs index b2ec8350d..88dc3eeb9 100644 --- a/Game.Server/BaseAnimating.cs +++ b/Game.Server/BaseAnimating.cs @@ -554,11 +554,9 @@ public BoneCache GetBoneCache() { pcache.UpdateBones(bonetoworld, studioHdr.NumBones(), gpGlobals.CurTime); } else { - BoneCacheParams parms = new(); + scoped BoneCacheParams parms = new(); parms.StudioHdr = studioHdr; - unsafe { - parms.BoneToWorld = bonetoworld; - } + parms.BoneToWorld = bonetoworld; parms.CurTime = gpGlobals.CurTime; parms.BoneMask = boneMask; diff --git a/Game.Server/SoundEnt.cs b/Game.Server/SoundEnt.cs index 5f45b3bf0..801d5a2fe 100644 --- a/Game.Server/SoundEnt.cs +++ b/Game.Server/SoundEnt.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Numerics; using System.Reflection; using System.Runtime.CompilerServices; @@ -110,8 +111,8 @@ public WorldSoundInstance() { public readonly bool DoesSoundExpire() => NoExpirationTime == false; public readonly TimeUnit_t SoundExpirationTime() => NoExpirationTime ? TimeUnit_t.MaxValue : ExpireTime; public void SetSoundOrigin(in Vector3 origin) => Origin = origin; - public unsafe ref readonly Vector3 GetSoundOrigin() => ref Origin; - public ref readonly Vector3 GetSoundReactOrigin() { + [UnscopedRef] public ref readonly Vector3 GetSoundOrigin() => ref Origin; + [UnscopedRef] public ref readonly Vector3 GetSoundReactOrigin() { switch (Type) { case SoundInstanceType.BulletImpact: case SoundInstanceType.PhysicsDanger: diff --git a/Source.Common/BoneSetup.cs b/Source.Common/BoneSetup.cs index 4e7578408..abb630e3e 100644 --- a/Source.Common/BoneSetup.cs +++ b/Source.Common/BoneSetup.cs @@ -177,7 +177,7 @@ public BoneSetup(StudioHdr studioHdr, int boneMask, ReadOnlySpan posePara } public void InitPose(Span pos, Span q) => InitPose(studioHdr, pos, q, boneMask); - public void InitPose(StudioHdr studioHdr, Span pos, Span q, int boneMask) { + public void InitPose(StudioHdr studioHdr, scoped Span pos, scoped Span q, int boneMask) { if (studioHdr.LinearBones() == null) { for (int i = 0; i < studioHdr.NumBones(); i++) { if ((studioHdr.BoneFlags(i) & boneMask) != 0) { @@ -198,7 +198,7 @@ public void InitPose(StudioHdr studioHdr, Span pos, Span q, } } - public unsafe void AccumulatePose(Span pos, Span q, int sequence, TimeUnit_t cycle, float weight, TimeUnit_t time, IKContext? ikContext) { + public unsafe void AccumulatePose(scoped Span pos, scoped Span q, int sequence, TimeUnit_t cycle, float weight, TimeUnit_t time, IKContext? ikContext) { Span pos2 = stackalloc Vector3[Studio.MAXSTUDIOBONES]; Span q2 = stackalloc Quaternion[Studio.MAXSTUDIOBONES]; @@ -1151,7 +1151,7 @@ private static void Studio_LocalPoseParameter(StudioHdr studioHdr, ReadOnlySpan< } } - private void AddLocalLayers(Span pos, Span q, MStudioSeqDesc seqdesc, int sequence, double cycle, double weight, double time, IKContext? ikContext) { + private void AddLocalLayers(scoped Span pos, scoped Span q, MStudioSeqDesc seqdesc, int sequence, double cycle, double weight, double time, IKContext? ikContext) { if ((seqdesc.Flags & StudioAnimSeqFlags.Local) == 0) return; @@ -1368,7 +1368,7 @@ internal static void BuildBoneChain(StudioHdr studioHdr, in Matrix3x4 rootxform, boneComputed.MarkBone(bone); } - private void AddSequenceLayers(Span pos, Span q, MStudioSeqDesc seqdesc, int sequence, double cycle, float weight, double time, IKContext? ikContext) { + private void AddSequenceLayers(scoped Span pos, scoped Span q, MStudioSeqDesc seqdesc, int sequence, double cycle, float weight, double time, IKContext? ikContext) { for (int i = 0; i < seqdesc.NumAutoLayers; i++) { MStudioAutoLayer pLayer = seqdesc.Autolayer(i); diff --git a/Source.Common/Formats/BSP/BSPFile.cs b/Source.Common/Formats/BSP/BSPFile.cs index 45a17c2fd..2fabf61d8 100644 --- a/Source.Common/Formats/BSP/BSPFile.cs +++ b/Source.Common/Formats/BSP/BSPFile.cs @@ -1,3 +1,4 @@ +using System.Diagnostics.CodeAnalysis; using System.Numerics; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; @@ -620,7 +621,7 @@ public struct LightZBuffer { const int SHADOW_ZBUF_RES = 8; public InlineArray384 Samples; - public unsafe ref LightShadowZBufferSample this[int face, int x, int y] => ref Samples[face * SHADOW_ZBUF_RES * SHADOW_ZBUF_RES + x * SHADOW_ZBUF_RES + y]; + [UnscopedRef] public ref LightShadowZBufferSample this[int face, int x, int y] => ref Samples[face * SHADOW_ZBUF_RES * SHADOW_ZBUF_RES + x * SHADOW_ZBUF_RES + y]; public void GetCoords(in Vector3 vecNormalizedDirection, out int nX, out int nY, out int nFace) { int nLargest = 0; @@ -647,7 +648,7 @@ public void GetCoords(in Vector3 vecNormalizedDirection, out int nX, out int nY, nY = (int)MathLib.RemapValClamped(vecNormalizedDirection[nAxis1] * flZ, -1, 1, 0, SHADOW_ZBUF_RES - 1); } - public ref LightShadowZBufferSample GetSample(in Vector3 vecNormalizedDirection) { + [UnscopedRef] public ref LightShadowZBufferSample GetSample(in Vector3 vecNormalizedDirection) { GetCoords(vecNormalizedDirection, out int nX, out int nY, out int nFace); return ref this[nFace, nX, nY]; } diff --git a/Source.Common/SoundEmitterSystem/ISoundEmitterSystemBase.cs b/Source.Common/SoundEmitterSystem/ISoundEmitterSystemBase.cs index f57318844..8d5809799 100644 --- a/Source.Common/SoundEmitterSystem/ISoundEmitterSystemBase.cs +++ b/Source.Common/SoundEmitterSystem/ISoundEmitterSystemBase.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Reflection.Emit; using System.Numerics; using System.Runtime.CompilerServices; @@ -440,9 +441,9 @@ public void SoundLevelFromString(ReadOnlySpan sz) { public readonly SoundEntityChannel GetChannel() => Channel; - public unsafe ref readonly VolumeInterval GetVolume() => ref Volume; - public unsafe ref readonly PitchInterval GetPitch() => ref Pitch; - public unsafe ref readonly SoundLevelInterval GetSoundLevel() => ref SoundLevel; + [UnscopedRef] public ref readonly VolumeInterval GetVolume() => ref Volume; + [UnscopedRef] public ref readonly PitchInterval GetPitch() => ref Pitch; + [UnscopedRef] public ref readonly SoundLevelInterval GetSoundLevel() => ref SoundLevel; public int GetDelayMsec() => DelayMsec; public bool OnlyPlayToOwner() => bPlayToOwnerOnly; public bool HadMissingWaveFiles() => bHadMissingWaveFiles; diff --git a/Source.Engine/CModel_Private.cs b/Source.Engine/CModel_Private.cs index cf8bd4536..7cd1e9e0a 100644 --- a/Source.Engine/CModel_Private.cs +++ b/Source.Engine/CModel_Private.cs @@ -710,7 +710,7 @@ internal static unsafe void UnsweptBoxTrace(TraceInfo traceInfo, in Ray ray, int Span leafs = stackalloc int[1024]; int i, numleafs; - LeafNums context; + scoped LeafNums context; context.LeafList = leafs; context.LeafTopNode = -1; context.LeafMaxCount = leafs.Length; diff --git a/Source.Engine/GLRSurf.cs b/Source.Engine/GLRSurf.cs index b1014af27..c6b5918c3 100644 --- a/Source.Engine/GLRSurf.cs +++ b/Source.Engine/GLRSurf.cs @@ -2122,29 +2122,25 @@ public bool EnumerateLeavesInBox(in Vector3 mins, in Vector3 maxs, ref T pEnu if (host_state.WorldModel == null) return false; - unsafe { - EnumLeafBoxInfo info = default; - info.BoxCenter = (mins + maxs) * 0.5f; - info.BoxHalfDiagonal = maxs - info.BoxCenter; - info.Iterator = ref pEnum; - info.Context = context; - info.BoxMax = maxs; - info.BoxMin = mins; - return EnumerateLeafInBox_R(host_state.WorldBrush!.Nodes![0], ref info); - } + scoped EnumLeafBoxInfo info = default; + info.BoxCenter = (mins + maxs) * 0.5f; + info.BoxHalfDiagonal = maxs - info.BoxCenter; + info.Iterator = ref pEnum; + info.Context = context; + info.BoxMax = maxs; + info.BoxMin = mins; + return EnumerateLeafInBox_R(host_state.WorldBrush!.Nodes![0], ref info); } public bool EnumerateLeavesInSphere(in Vector3 center, float radius, ref T pEnum, nint context) where T : ISpatialLeafEnumerator { - EnumLeafSphereInfo info = default; - unsafe { - info.Center = center; - info.Radius = radius; - info.Iterator = ref pEnum; - info.Context = context; - info.BoxCenter = center; - info.BoxHalfDiagonal = new(radius, radius, radius); - return EnumerateLeafInSphere_R(host_state.WorldBrush!.Nodes![0], ref info, ENUM_SPHERE_TEST_ALL); - } + scoped EnumLeafSphereInfo info = default; + info.Center = center; + info.Radius = radius; + info.Iterator = ref pEnum; + info.Context = context; + info.BoxCenter = center; + info.BoxHalfDiagonal = new(radius, radius, radius); + return EnumerateLeafInSphere_R(host_state.WorldBrush!.Nodes![0], ref info, ENUM_SPHERE_TEST_ALL); } public bool EnumerateLeavesAlongRay(in Ray ray, ref T pEnum, nint context) where T : ISpatialLeafEnumerator { diff --git a/Source.Engine/Host.cs b/Source.Engine/Host.cs index a509d66e9..ba274efef 100644 --- a/Source.Engine/Host.cs +++ b/Source.Engine/Host.cs @@ -1737,7 +1737,7 @@ internal static TimeUnit_t GetSoundDuration(ReadOnlySpan sample) { internal bool Changelevel(bool loadfromsavedgame, ReadOnlySpan mapname, ReadOnlySpan start) { Span _startspot = stackalloc char[MAX_PATH]; - Span startspot; + scoped Span startspot; Span oldlevel = stackalloc char[MAX_PATH]; #if !SWDS // SaveRestoreData? saveData = null; @@ -1804,9 +1804,7 @@ internal bool Changelevel(bool loadfromsavedgame, ReadOnlySpan mapname, Re startspot = null; else { strcpy(_startspot, start); - unsafe { - startspot = _startspot; - } + startspot = _startspot; } Warning("---- Host_Changelevel ----\n"); diff --git a/Source.Engine/SpatialPartition.cs b/Source.Engine/SpatialPartition.cs index b8733d779..5bd6e15d4 100644 --- a/Source.Engine/SpatialPartition.cs +++ b/Source.Engine/SpatialPartition.cs @@ -533,10 +533,8 @@ bool EnumerateElementsAlongRay_ExtrudedRay(SpatialPartitionListMask_t listM else voxelMin[iAxis] += nStep[iAxis]; - unsafe { - if (!EnumerateElementsAlongRay_ExtrudedRaySlice(listMask, ref iterator, intersectSweptBox, voxelMin, voxelMax, iAxis, nStep)) - return false; - } + if (!EnumerateElementsAlongRay_ExtrudedRaySlice(listMask, ref iterator, intersectSweptBox, voxelMin, voxelMax, iAxis, nStep)) + return false; } } return true; @@ -544,7 +542,7 @@ bool EnumerateElementsAlongRay_ExtrudedRay(SpatialPartitionListMask_t listM public bool EnumerateElementsAlongRay_ExtrudedRaySlice(SpatialPartitionListMask_t listMask, scoped ref IPE iterator, in IntersectSweptBox intersectSweptBox, - Span voxelMin, Span voxelMax, int iAxis, Span pStep) where IPE : struct, IPartitionEnumerator, allows ref struct { + scoped Span voxelMin, scoped Span voxelMax, int iAxis, scoped Span pStep) where IPE : struct, IPartitionEnumerator, allows ref struct { Span mins = stackalloc int[3] { voxelMin[0], voxelMin[1], voxelMin[2] }; Span maxs = stackalloc int[3] { voxelMax[0], voxelMax[1], voxelMax[2] }; From 815b4aef325b1b20c29bd8e2097c158d6abc90bf Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Tue, 17 Nov 2026 03:41:51 +0000 Subject: [PATCH 5/9] Fix nav nullability warnings --- Game.Server/NavMesh/NavArea.cs | 3 ++- Game.Server/NavMesh/NavGenerate.cs | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Game.Server/NavMesh/NavArea.cs b/Game.Server/NavMesh/NavArea.cs index 1bc3a5d4e..9017976bc 100644 --- a/Game.Server/NavMesh/NavArea.cs +++ b/Game.Server/NavMesh/NavArea.cs @@ -4,6 +4,7 @@ namespace Game.Server.NavMesh; using System.Collections.Concurrent; +using System.Diagnostics.CodeAnalysis; using System.Numerics; using Game.Server.NextBot; @@ -668,7 +669,7 @@ public void AssignNodes(NavArea area) { } } - public bool SplitEdit(bool splitAlongX, float splitEdge, out NavArea? outAlpha, out NavArea? outBeta) { + public bool SplitEdit(bool splitAlongX, float splitEdge, [NotNullWhen(true)] out NavArea? outAlpha, [NotNullWhen(true)] out NavArea? outBeta) { outAlpha = null; outBeta = null; diff --git a/Game.Server/NavMesh/NavGenerate.cs b/Game.Server/NavMesh/NavGenerate.cs index 7f69b5f80..94e46bed5 100644 --- a/Game.Server/NavMesh/NavGenerate.cs +++ b/Game.Server/NavMesh/NavGenerate.cs @@ -229,7 +229,7 @@ public void SubdivideX(NavArea area, bool canDivideX, bool canDivideY, int depth split += area.GetCorner(NavCornerType.NorthWest).X; split = NavMesh.Instance!.SnapToGrid(split); - if (area.SplitEdit(false, split, out NavArea alpha, out NavArea beta)) { + if (area.SplitEdit(false, split, out NavArea? alpha, out NavArea? beta)) { SubdivideX(alpha, canDivideX, canDivideY, depth); SubdivideX(beta, canDivideX, canDivideY, depth); } @@ -250,7 +250,7 @@ public void SubdivideY(NavArea area, bool canDivideX, bool canDivideY, int depth split += area.GetCorner(NavCornerType.NorthWest).Y; split = NavMesh.Instance!.SnapToGrid(split); - if (area.SplitEdit(true, split, out NavArea alpha, out NavArea beta)) { + if (area.SplitEdit(true, split, out NavArea? alpha, out NavArea? beta)) { SubdivideY(alpha, canDivideX, canDivideY, depth - 1); SubdivideY(beta, canDivideX, canDivideY, depth - 1); } @@ -730,7 +730,7 @@ static void SplitX(NavArea area) { Math.Abs(split - area.GetCorner(NavCornerType.SouthEast).X) < epsilon) return; - if (area.SplitEdit(false, split, out NavArea alpha, out NavArea beta)) { + if (area.SplitEdit(false, split, out NavArea? alpha, out NavArea? beta)) { SplitX(alpha); SplitX(beta); } @@ -750,7 +750,7 @@ static void SplitY(NavArea area) { Math.Abs(split - area.GetCorner(NavCornerType.SouthEast).Y) < epsilon) return; - if (area.SplitEdit(true, split, out NavArea alpha, out NavArea beta)) { + if (area.SplitEdit(true, split, out NavArea? alpha, out NavArea? beta)) { SplitY(alpha); SplitY(beta); } @@ -1004,10 +1004,10 @@ void ConnectGeneratedAreas() { NavNode? node; for (node = area.Node[(int)NavCornerType.NorthWest]; node != area.Node[(int)NavCornerType.NorthEast]; node = node.GetConnectedNode(NavDirType.East)) { - NavNode? adj = node.GetConnectedNode(NavDirType.North); + NavNode? adj = node!.GetConnectedNode(NavDirType.North); if (adj != null && adj.GetArea() != null && adj.GetConnectedNode(NavDirType.South) == node) { - area.ConnectTo(adj.GetArea(), NavDirType.North); + area.ConnectTo(adj.GetArea()!, NavDirType.North); } else { NavArea? downArea = FindJumpDownArea(node.GetPosition(), NavDirType.North); @@ -1017,9 +1017,9 @@ void ConnectGeneratedAreas() { } for (node = area.Node[(int)NavCornerType.NorthWest]; node != area.Node[(int)NavCornerType.SouthWest]; node = node.GetConnectedNode(NavDirType.South)) { - NavNode? adj = node.GetConnectedNode(NavDirType.West); + NavNode? adj = node!.GetConnectedNode(NavDirType.West); if (adj != null && adj.GetArea() != null && adj.GetConnectedNode(NavDirType.East) == node) - area.ConnectTo(adj.GetArea(), NavDirType.West); + area.ConnectTo(adj.GetArea()!, NavDirType.West); else { NavArea? downArea = FindJumpDownArea(node.GetPosition(), NavDirType.West); if (downArea != null && downArea != area) @@ -1032,12 +1032,12 @@ void ConnectGeneratedAreas() { node = node.GetConnectedNode(NavDirType.North); if (node != null) { - NavNode? end = area.Node[(int)NavCornerType.SouthEast].GetConnectedNode(NavDirType.North); + NavNode? end = area.Node[(int)NavCornerType.SouthEast]!.GetConnectedNode(NavDirType.North); for (; node != null && node != end; node = node.GetConnectedNode(NavDirType.East)) { NavNode? adj = node.GetConnectedNode(NavDirType.South); if (adj != null && adj.GetArea() != null && adj.GetConnectedNode(NavDirType.North) == node) - area.ConnectTo(adj.GetArea(), NavDirType.South); + area.ConnectTo(adj.GetArea()!, NavDirType.South); else { NavArea? downArea = FindJumpDownArea(node.GetPosition(), NavDirType.South); if (downArea != null && downArea != area) @@ -1047,7 +1047,7 @@ void ConnectGeneratedAreas() { } for (node = area.Node[(int)NavCornerType.SouthWest]; node != area.Node[(int)NavCornerType.SouthEast]; node = node.GetConnectedNode(NavDirType.East)) { - if (node.GetArea() != null) + if (node!.GetArea() != null) continue; NavNode? adj = node.GetConnectedNode(NavDirType.South); @@ -1067,12 +1067,12 @@ void ConnectGeneratedAreas() { node = node.GetConnectedNode(NavDirType.West); if (node != null) { - NavNode? end = area.Node[(int)NavCornerType.SouthEast].GetConnectedNode(NavDirType.West); + NavNode? end = area.Node[(int)NavCornerType.SouthEast]!.GetConnectedNode(NavDirType.West); for (; node != null && node != end; node = node.GetConnectedNode(NavDirType.South)) { NavNode? adj = node.GetConnectedNode(NavDirType.East); if (adj != null && adj.GetArea() != null && adj.GetConnectedNode(NavDirType.West) == node) { - area.ConnectTo(adj.GetArea(), NavDirType.East); + area.ConnectTo(adj.GetArea()!, NavDirType.East); } else { NavArea? downArea = FindJumpDownArea(node.GetPosition(), NavDirType.East); @@ -1254,8 +1254,8 @@ void FixConnections() { area.ComputePortal(adjArea, (NavDirType)dir, ref pos, out _); adjArea.GetClosestPointOnArea(ref pos, out Vector3 adjPos); - NavNode node = area.FindClosestNode(pos, (NavDirType)dir); - NavNode adjNode = adjArea.FindClosestNode(adjPos, OppositeDirection((NavDirType)dir)); + NavNode node = area.FindClosestNode(pos, (NavDirType)dir)!; + NavNode adjNode = adjArea.FindClosestNode(adjPos, OppositeDirection((NavDirType)dir))!; pos = node.GetPosition(); adjPos = adjNode.GetPosition(); From a51023252bb17b5e3b9df5e54583014c59d0df3e Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Tue, 17 Nov 2026 03:45:44 +0000 Subject: [PATCH 6/9] Fix spawn count --- Game.Client/View.cs | 12 ++++++------ Source.Engine/Client/ClientState.cs | 2 +- Source.Engine/Host.cs | 3 +-- Source.Engine/Server/GameServer.cs | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Game.Client/View.cs b/Game.Client/View.cs index b07e5fdbf..a202652cf 100644 --- a/Game.Client/View.cs +++ b/Game.Client/View.cs @@ -120,9 +120,7 @@ public ViewRender(IMaterialSystem materials, IServiceProvider services, Render e internal IRenderView render; - public void DisableVis() { - throw new NotImplementedException(); - } + public void DisableVis() => ForceNoVis = true; public void DriftPitch() { throw new NotImplementedException(); @@ -184,6 +182,9 @@ public float GetZNear() { public void Init() { render = services.GetRequiredService(); + DrawEntities = cvar.FindVar("r_drawentities"); + DrawBrushModels = cvar.FindVar("r_drawbrushmodels"); + TranslucentSingleColor.Init("debug/debugtranslucentsinglecolor", MaterialDefines.TEXTURE_GROUP_OTHER); ModulateSingleColor.Init("engine/modulatesinglecolor", MaterialDefines.TEXTURE_GROUP_OTHER); } @@ -984,9 +985,7 @@ public void SetScreenOverlayMaterial(IMaterial? pMaterial) { throw new NotImplementedException(); } - public bool ShouldDrawBrushModels() { - throw new NotImplementedException(); - } + public bool ShouldDrawBrushModels() => DrawBrushModels == null || DrawBrushModels.GetInt() != 0; public void Shutdown() { throw new NotImplementedException(); @@ -1019,6 +1018,7 @@ public void WriteSaveGameScreenshotOfSize(ReadOnlySpan pFilename, int widt } ConVar? DrawEntities; + ConVar? DrawBrushModels; internal bool ShouldDrawEntities() { return DrawEntities == null || DrawEntities.GetInt() != 0; diff --git a/Source.Engine/Client/ClientState.cs b/Source.Engine/Client/ClientState.cs index 0bf088bf5..06fb4fb30 100644 --- a/Source.Engine/Client/ClientState.cs +++ b/Source.Engine/Client/ClientState.cs @@ -1309,7 +1309,7 @@ public override bool ProcessServerInfo(SVC_ServerInfo msg) { g_ClientDLL?.HudVidInit(); - // gHostSpawnCount = m_nServerCount; + Host.gHostSpawnCount = ServerCount; #if !SWDS ((VideoMode_Common)videoMode).MarkClientViewRectDirty(); #endif diff --git a/Source.Engine/Host.cs b/Source.Engine/Host.cs index ba274efef..c65cdf51d 100644 --- a/Source.Engine/Host.cs +++ b/Source.Engine/Host.cs @@ -132,7 +132,7 @@ void AccumulateTime(TimeUnit_t dt) { soundServices.SetSoundFrametime(dt, FrameTime); } - int gHostSpawnCount; + internal int gHostSpawnCount; public int GetServerCount() { if (cl.SignOnState >= SignOnState.New) @@ -1603,7 +1603,6 @@ public void Error(ReadOnlySpan error) { static readonly ConVar cvarNext = new("next", "0", FCvar.Cheat, "Set to 1 to advance to next frame ( when singlestep == 1 )"); int ShouldRun_CurrentTick; - internal int SpawnCount; public bool ShouldRun() { if (singlestep.GetInt() == 0) diff --git a/Source.Engine/Server/GameServer.cs b/Source.Engine/Server/GameServer.cs index 3d681fea3..eb25540d1 100644 --- a/Source.Engine/Server/GameServer.cs +++ b/Source.Engine/Server/GameServer.cs @@ -544,7 +544,7 @@ internal bool SpawnServer(ReadOnlySpan mapName, ReadOnlySpan mapFile else ConDMsg($"Spawn Server: {mapName}\n"); - Host.SpawnCount = ++SpawnCount; + Host.gHostSpawnCount = ++SpawnCount; Host.deathmatch.SetValue(IsMultiplayer() ? 1 : 0); if (Host.coop.GetInt() != 0) From 43e4f0d777e54e1fb08cf5697ba60695d5306866 Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Tue, 17 Nov 2026 04:00:47 +0000 Subject: [PATCH 7/9] Some more fixes --- Game.Client/GarrysMod/C_GMOD_Player.cs | 2 +- Game.Client/Ragdoll.cs | 5 ++-- Game.Server/EntityList.cs | 7 +---- Game.Server/GarrysMod/GMOD_Player.cs | 2 +- Game.Shared/GarrysMod/LuaPlayer.cs | 2 ++ Game.Shared/GarrysMod/LuaSteamworks.cs | 4 +++ Game.Shared/GarrysMod/LuaVideoWriter.cs | 2 ++ Game.Shared/GarrysMod/WeaponBugBait.cs | 2 +- Game.Shared/GarrysMod/WeaponFrag.cs | 2 +- .../NetworkVarGenerator.cs | 26 +++++++++++++++---- Source.Common/Studio.cs | 2 -- Source.GUI.Controls/CircularProgressBar.cs | 2 +- Source.GUI.Controls/Frame.cs | 2 +- Source.GUI.Controls/HTML.cs | 2 +- Source.GUI/ImageBorder.cs | 6 +++-- 15 files changed, 44 insertions(+), 24 deletions(-) diff --git a/Game.Client/GarrysMod/C_GMOD_Player.cs b/Game.Client/GarrysMod/C_GMOD_Player.cs index 5c27ec45b..2a745e077 100644 --- a/Game.Client/GarrysMod/C_GMOD_Player.cs +++ b/Game.Client/GarrysMod/C_GMOD_Player.cs @@ -96,7 +96,7 @@ public virtual void SetWeaponColor(in Vector3 color) { [NetworkVar("m_iMaxArmor")] public int MaxArmor; [NetworkVar("m_flGravity")] - public float Gravity; + public new float Gravity; [NetworkVar("m_bSprintEnabled")] public bool SprintEnabled; diff --git a/Game.Client/Ragdoll.cs b/Game.Client/Ragdoll.cs index 51aa6e545..989f7027c 100644 --- a/Game.Client/Ragdoll.cs +++ b/Game.Client/Ragdoll.cs @@ -208,9 +208,10 @@ public static ClientRagdoll CreateRagdoll( ClientRagdoll ragdoll = new(); ragdoll.Init(ent, studiohdr, forceVector, forceBone, deltaBones0, deltaBones1, currentBonePosition, dt, fixedConstraints); - if (!ragdoll.IsValid()) + if (!ragdoll.IsValid()) { Msg($"Bad ragdoll for {studiohdr.Name()}"); - return null; + return null; + } return ragdoll; } diff --git a/Game.Server/EntityList.cs b/Game.Server/EntityList.cs index 8ba7e0dd0..db164c2d3 100644 --- a/Game.Server/EntityList.cs +++ b/Game.Server/EntityList.cs @@ -262,12 +262,7 @@ public void AddToDeleteList(IServerNetworkable? ent) { if (list != null) list = NextEntInfo(list); - while (list != null) { - return (BaseEntity?)list.Entity; - list = NextEntInfo(list); //?? - } - - return null; + return list != null ? (BaseEntity?)list.Entity : null; } public T? NextEntByClass(T? start) where T : BaseEntity { diff --git a/Game.Server/GarrysMod/GMOD_Player.cs b/Game.Server/GarrysMod/GMOD_Player.cs index d08e1cc30..47f42bbbc 100644 --- a/Game.Server/GarrysMod/GMOD_Player.cs +++ b/Game.Server/GarrysMod/GMOD_Player.cs @@ -302,7 +302,7 @@ public virtual void SetWeaponColor(in Vector3 color) { [NetworkVar("m_iMaxArmor")] public partial int MaxArmor { get; set; } [NetworkVar("m_flGravity")] - public partial float Gravity { get; set; } + public new partial float Gravity { get; set; } [NetworkVar("m_bSprintEnabled")] public partial bool SprintEnabled { get; set; } diff --git a/Game.Shared/GarrysMod/LuaPlayer.cs b/Game.Shared/GarrysMod/LuaPlayer.cs index ba58ec39b..fcdfaa263 100644 --- a/Game.Shared/GarrysMod/LuaPlayer.cs +++ b/Game.Shared/GarrysMod/LuaPlayer.cs @@ -219,7 +219,9 @@ static int Player__SetClassID(ILuaInterface lua) { gmodPlayer.NetworkStateChanged(); #endif gmodPlayer.PlayerClass = classID; +#pragma warning disable SRCLUA004 return 1; +#pragma warning restore SRCLUA004 } [LuaMethod] diff --git a/Game.Shared/GarrysMod/LuaSteamworks.cs b/Game.Shared/GarrysMod/LuaSteamworks.cs index b8ccbf939..1de39c86b 100644 --- a/Game.Shared/GarrysMod/LuaSteamworks.cs +++ b/Game.Shared/GarrysMod/LuaSteamworks.cs @@ -1191,7 +1191,9 @@ static int SetFilePlayed(ILuaInterface lua) { if (id == 0) return 0; SteamRemoteStorage.SetUserPublishedFileAction(new PublishedFileId_t(id), EWorkshopFileAction.k_EWorkshopFileActionPlayed); +#pragma warning disable SRCLUA004 return 1; +#pragma warning restore SRCLUA004 } [LuaFunction] @@ -1200,7 +1202,9 @@ static int SetFileCompleted(ILuaInterface lua) { if (id == 0) return 0; SteamRemoteStorage.SetUserPublishedFileAction(new PublishedFileId_t(id), EWorkshopFileAction.k_EWorkshopFileActionCompleted); +#pragma warning disable SRCLUA004 return 1; +#pragma warning restore SRCLUA004 } #endif diff --git a/Game.Shared/GarrysMod/LuaVideoWriter.cs b/Game.Shared/GarrysMod/LuaVideoWriter.cs index 8c740d760..38da1345f 100644 --- a/Game.Shared/GarrysMod/LuaVideoWriter.cs +++ b/Game.Shared/GarrysMod/LuaVideoWriter.cs @@ -70,7 +70,9 @@ static int IVideoWriter__SetRecordSound(ILuaInterface lua) { } writer.RecordSound = lua.GetBool(2); +#pragma warning disable SRCLUA004 return 1; +#pragma warning restore SRCLUA004 } } #endif diff --git a/Game.Shared/GarrysMod/WeaponBugBait.cs b/Game.Shared/GarrysMod/WeaponBugBait.cs index ec50d004c..8a2ca1989 100644 --- a/Game.Shared/GarrysMod/WeaponBugBait.cs +++ b/Game.Shared/GarrysMod/WeaponBugBait.cs @@ -37,7 +37,7 @@ public partial class WeaponBugBait : BaseHL2MPCombatWeapon ]; [NetworkVar("m_bRedraw")] - public partial bool Redraw { get; set; } + public new partial bool Redraw { get; set; } [NetworkVar("m_bDrawBackFinished")] public partial bool DrawbackFinished { get; set; } } diff --git a/Game.Shared/GarrysMod/WeaponFrag.cs b/Game.Shared/GarrysMod/WeaponFrag.cs index a7b5b62d4..d37f99b1d 100644 --- a/Game.Shared/GarrysMod/WeaponFrag.cs +++ b/Game.Shared/GarrysMod/WeaponFrag.cs @@ -39,7 +39,7 @@ public partial class WeaponFrag : BaseHL2MPCombatWeapon ]; [NetworkVar("m_bRedraw")] - public partial bool Redraw { get; set; } + public new partial bool Redraw { get; set; } [NetworkVar("m_fDrawbackFinished")] public partial bool DrawbackFinished { get; set; } [NetworkVar("m_AttackPaused")] diff --git a/Source.CodeAnalysis.NetworkVars/NetworkVarGenerator.cs b/Source.CodeAnalysis.NetworkVars/NetworkVarGenerator.cs index 2336aa3b7..39123553b 100644 --- a/Source.CodeAnalysis.NetworkVars/NetworkVarGenerator.cs +++ b/Source.CodeAnalysis.NetworkVars/NetworkVarGenerator.cs @@ -134,10 +134,24 @@ private static bool IsNetworkArray(ITypeSymbol type) .Where(m => m.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.PublicKeyword) || m.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) || m.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword) || m.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword) || m.IsKind(Microsoft.CodeAnalysis.CSharp.SyntaxKind.NewKeyword)) .Select(m => m.Text)), RefReadonly = prop.ReturnsByRefReadonly, - BaseHasFields = BaseHasNetworkVarFields(containingType.BaseType) + BaseHasFields = BaseHasNetworkVarFields(containingType.BaseType), + ForModifyHidesBase = BaseHasForModify(containingType.BaseType, prop.Name) }; } + private static bool BaseHasForModify(INamedTypeSymbol? type, string name) { + string forModify = name + "ForModify"; + for (INamedTypeSymbol? t = type; t != null; t = t.BaseType) { + if (t.GetMembers(forModify).Length > 0) + return true; + foreach (IPropertySymbol property in t.GetMembers(name).OfType()) { + if (property.GetAttributes().Any(a => a.AttributeClass?.ToDisplayString() == AttributeMetadataName)) + return true; + } + } + return false; + } + private static bool BaseHasNetworkVarFields(INamedTypeSymbol? type) { for (INamedTypeSymbol? t = type; t != null; t = t.BaseType) { if (t.ContainingType != null || t.IsGenericType) @@ -215,12 +229,13 @@ private static string BuildSource(PropertyModel type, List props) sb.Append(indent).Append("private ").Append(t).Append(' ').Append(backing).AppendLine(";"); string accessibility = p.Accessibility.Length == 0 ? "" : p.Accessibility + " "; + string forModify = p.ForModifyHidesBase ? "public new ref " : "public ref "; if (p.RefReadonly) { sb.Append(indent).Append(accessibility).Append("partial ref readonly ").Append(t).Append(' ').Append(name).Append(" { get => ref ").Append(backing).AppendLine("; }"); if (p.IsClient) - sb.Append(indent).Append("public ref ").Append(t).Append(' ').Append(name).Append("ForModify() => ref ").Append(backing).AppendLine(";"); + sb.Append(indent).Append(forModify).Append(t).Append(' ').Append(name).Append("ForModify() => ref ").Append(backing).AppendLine(";"); else { - sb.Append(indent).Append("public ref ").Append(t).Append(' ').Append(name).AppendLine("ForModify() {"); + sb.Append(indent).Append(forModify).Append(t).Append(' ').Append(name).AppendLine("ForModify() {"); sb.Append(indent).Append("\tNetworkStateChanged(NetworkVarFields.").Append(name).AppendLine(");"); sb.Append(indent).Append("\treturn ref ").Append(backing).AppendLine(";"); sb.Append(indent).AppendLine("}"); @@ -233,7 +248,7 @@ private static string BuildSource(PropertyModel type, List props) if (p.IsClient) { sb.Append(indent).Append("\tset => ").Append(backing).AppendLine(" = value;"); sb.Append(indent).AppendLine("}"); - sb.Append(indent).Append("public ref ").Append(t).Append(' ').Append(name).Append("ForModify() => ref ").Append(backing).AppendLine(";"); + sb.Append(indent).Append(forModify).Append(t).Append(' ').Append(name).Append("ForModify() => ref ").Append(backing).AppendLine(";"); sb.AppendLine(); continue; } @@ -250,7 +265,7 @@ private static string BuildSource(PropertyModel type, List props) sb.Append(indent).AppendLine("\t\t}"); sb.Append(indent).AppendLine("\t}"); sb.Append(indent).AppendLine("}"); - sb.Append(indent).Append("public ref ").Append(t).Append(' ').Append(name).AppendLine("ForModify() {"); + sb.Append(indent).Append(forModify).Append(t).Append(' ').Append(name).AppendLine("ForModify() {"); sb.Append(indent).Append("\tNetworkStateChanged(NetworkVarFields.").Append(name).AppendLine(");"); sb.Append(indent).Append("\treturn ref ").Append(backing).AppendLine(";"); sb.Append(indent).AppendLine("}"); @@ -325,6 +340,7 @@ public static PropertyModel ServerFieldError(string fieldName, string typeName, public string Accessibility { get; set; } = ""; public bool RefReadonly { get; set; } public bool BaseHasFields { get; set; } + public bool ForModifyHidesBase { get; set; } public Location Location { get; } } } diff --git a/Source.Common/Studio.cs b/Source.Common/Studio.cs index af4eac514..a195bee91 100644 --- a/Source.Common/Studio.cs +++ b/Source.Common/Studio.cs @@ -2992,8 +2992,6 @@ public MStudioTexture Texture(int i) { studioTextures = new MStudioTexture[NumTextures]; return studioTextures[i] ??= new(Data[(TextureIndex + (MStudioTexture.SIZE_OF_ONE * i))..]); - - return Studio.ProduceArrayIdx(this, ref studioTextures, NumTextures, TextureIndex, i, MStudioTexture.SIZE_OF_ONE, Data, MStudioTexture.FACTORY); } public int NumCDTextures; diff --git a/Source.GUI.Controls/CircularProgressBar.cs b/Source.GUI.Controls/CircularProgressBar.cs index 3c8f13b32..6c7be58ca 100644 --- a/Source.GUI.Controls/CircularProgressBar.cs +++ b/Source.GUI.Controls/CircularProgressBar.cs @@ -18,7 +18,7 @@ enum CircularProgressDir CounterClockwise } - int ProgressDirection; + new int ProgressDirection; int StartSegment; bool ReverseProgress; diff --git a/Source.GUI.Controls/Frame.cs b/Source.GUI.Controls/Frame.cs index 704b6607f..eb2df3c34 100644 --- a/Source.GUI.Controls/Frame.cs +++ b/Source.GUI.Controls/Frame.cs @@ -482,7 +482,7 @@ public class Frame : EditablePanel TextImage? Title; bool Moveable; bool Sizeable; - bool HasFocus; + new bool HasFocus; bool FlashWindow; bool DrawTitleBar; bool PreviouslyVisible; diff --git a/Source.GUI.Controls/HTML.cs b/Source.GUI.Controls/HTML.cs index e85485694..9e21d3d64 100644 --- a/Source.GUI.Controls/HTML.cs +++ b/Source.GUI.Controls/HTML.cs @@ -179,7 +179,7 @@ public CustomCursorCache_t(object? data) { BrowserCallback JSAlert; BrowserCallback JSConfirm; BrowserCallback CanGoBackForward; - BrowserCallback SetCursor; + new BrowserCallback SetCursor; BrowserCallback StatusText; BrowserCallback ShowTooltip; BrowserCallback UpdateTooltip; diff --git a/Source.GUI/ImageBorder.cs b/Source.GUI/ImageBorder.cs index c76fa6d45..7f8b5808f 100644 --- a/Source.GUI/ImageBorder.cs +++ b/Source.GUI/ImageBorder.cs @@ -11,13 +11,15 @@ public class ImageBorder : Border TextureID TextureID; bool Tiled; string? ImageName; - bool PaintFirst; + bool ShouldPaintFirst; public ImageBorder() { BackgroundType = PaintBackgroundType.Textured; TextureID = Surface.CreateNewTextureID(); } + public override bool PaintFirst() => ShouldPaintFirst; + public virtual void SetImage(ReadOnlySpan imageName) { if (!imageName.IsEmpty && imageName.Length > 0) { ImageName = "vgui/" + new string(imageName); @@ -81,6 +83,6 @@ public override void ApplySchemeSettings(IScheme? scheme, KeyValues inResourceDa ReadOnlySpan imageName = inResourceData.GetString("image", ""); SetImage(imageName); - PaintFirst = inResourceData.GetInt("paintfirst", 1) != 0; + ShouldPaintFirst = inResourceData.GetInt("paintfirst", 1) != 0; } } From 6bbc935c6cfdd5f4ef120029b07703403f838d22 Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Tue, 17 Nov 2026 04:12:11 +0000 Subject: [PATCH 8/9] Remove unnecessary unsafe modifiers --- Source.Common/AssertDialog.cs | 2 +- Source.Common/Bitbuffers/Bitbuf.cs | 2 +- Source.Common/Bitbuffers/bf_read.cs | 2 +- Source.Common/Bitbuffers/bf_write.cs | 6 +++--- Source.Common/BoneSetup.cs | 2 +- Source.Common/CFormatting.cs | 8 ++++---- Source.Common/Exts.cs | 16 ++++++++-------- Source.Common/Formats/BSP/BSPFile.cs | 2 +- Source.Common/MaterialSystem/IMesh.cs | 6 +++--- Source.Common/Mathematics/MathLib.cs | 12 ++++++------ Source.Common/NetworkVar.cs | 2 +- Source.Common/Networking/DataFragments.cs | 2 +- .../Networking/IConnectionlessPacketHandler.cs | 4 ++-- Source.Engine/CModel_Private.cs | 8 ++++---- Source.Engine/Cbuf.cs | 6 +++--- Source.Engine/Net.cs | 14 +++++++------- Source.Engine/NetChannel.cs | 12 ++++++------ Source.Engine/SpatialPartition.cs | 2 +- Source.Engine/Sys.cs | 2 +- Source.Filesystem/BaseFileSystem.cs | 2 +- Source.MaterialSystem/Surface/Clip2D.cs | 2 +- Source.MaterialSystem/Surface/FreeTypeFont.cs | 2 +- .../Surface/TextureDictionary.cs | 2 +- Source.MaterialSystem/Texture.cs | 2 +- Source.Physics/Main.cs | 2 +- Source.Physics/PhysicsCollide.cs | 4 ++-- Source.Physics/PhysicsConstraints.cs | 8 ++++---- Source.Physics/PhysicsEnvironment.cs | 2 +- Source.Physics/PhysicsFluidController.cs | 2 +- Source.Physics/PhysicsFriction.cs | 2 +- Source.Physics/PhysicsObject.cs | 2 +- Source.Physics/PhysicsPlayerController.cs | 2 +- Source.SDLSystem/SDL3_System.Win32.cs | 2 +- Source.SDLSystem/SDL3_System.cs | 4 ++-- Source.ShaderAPI.Gl46/IndexBufferGl46.cs | 2 +- Source.ShaderAPI.Gl46/MeshGl46.cs | 6 +++--- Source.ShaderAPI.Gl46/ShaderAPIGl46.cs | 12 ++++++------ Source.ShaderAPI.Gl46/ShaderShadow.cs | 6 +++--- Source.ShaderAPI.Gl46/VertexBufferGl46.cs | 4 ++-- Source.VTF/VTFTexture.cs | 2 +- 40 files changed, 91 insertions(+), 91 deletions(-) diff --git a/Source.Common/AssertDialog.cs b/Source.Common/AssertDialog.cs index b44ab42a4..939c73682 100644 --- a/Source.Common/AssertDialog.cs +++ b/Source.Common/AssertDialog.cs @@ -110,7 +110,7 @@ private static AssertDisable IgnoreAssertsNearby(string filename, int line, int #if DBGFLAG_HIDE_ASSERTS_FROM_DEBUGGING_STACK [DebuggerHidden] #endif - public static unsafe bool DoNewAssertDialog(ReadOnlySpan file, int line, ReadOnlySpan expression) { + public static bool DoNewAssertDialog(ReadOnlySpan file, int line, ReadOnlySpan expression) { if (AreAssertsDisabled()) return false; diff --git a/Source.Common/Bitbuffers/Bitbuf.cs b/Source.Common/Bitbuffers/Bitbuf.cs index c5f46fa35..0cc8482f8 100644 --- a/Source.Common/Bitbuffers/Bitbuf.cs +++ b/Source.Common/Bitbuffers/Bitbuf.cs @@ -5,7 +5,7 @@ namespace Source.Common.Bitbuffers; using int_ptr = nint; -public abstract unsafe class BitHelpers +public abstract class BitHelpers { private static readonly uint[] bitStringEndMasks = new uint[] { diff --git a/Source.Common/Bitbuffers/bf_read.cs b/Source.Common/Bitbuffers/bf_read.cs index aafe2dd52..fc0bb9ff3 100644 --- a/Source.Common/Bitbuffers/bf_read.cs +++ b/Source.Common/Bitbuffers/bf_read.cs @@ -554,7 +554,7 @@ public bool ReadBytes(Span pOut) { return !Overflowed; } - public unsafe bool ReadInto(out T output) where T : unmanaged { + public bool ReadInto(out T output) where T : unmanaged { output = default; Span data = stackalloc byte[sizeof(T)]; if (!ReadBytes(data)) diff --git a/Source.Common/Bitbuffers/bf_write.cs b/Source.Common/Bitbuffers/bf_write.cs index 183486db2..4fe8dfec2 100644 --- a/Source.Common/Bitbuffers/bf_write.cs +++ b/Source.Common/Bitbuffers/bf_write.cs @@ -66,9 +66,9 @@ public bf_write(byte[]? data, int bytes, int bits) { StartWriting(data, bytes, 0, bits); } - public unsafe void StartWriting(byte[]? inData, nuint bytes, int startBit = 0, int bits = -1) + public void StartWriting(byte[]? inData, nuint bytes, int startBit = 0, int bits = -1) => StartWriting(inData, (int)bytes, startBit, bits); - public unsafe void StartWriting(byte[]? inData, int bytes, int startBit = 0, int bits = -1) { + public void StartWriting(byte[]? inData, int bytes, int startBit = 0, int bits = -1) { // Ensure d-word alignment Debug.Assert(bytes % 4 == 0); @@ -670,7 +670,7 @@ public void WriteOneBitAt(int bit, int value) { } } - public unsafe void WriteUBitLong(uint curData, int numbits, bool checkRange = true) { + public void WriteUBitLong(uint curData, int numbits, bool checkRange = true) { #if NEW_BITBUFFER // Bounds checking.. if (curBit + numbits > dataBits) { diff --git a/Source.Common/BoneSetup.cs b/Source.Common/BoneSetup.cs index abb630e3e..7901e880a 100644 --- a/Source.Common/BoneSetup.cs +++ b/Source.Common/BoneSetup.cs @@ -198,7 +198,7 @@ public void InitPose(StudioHdr studioHdr, scoped Span pos, scoped Span< } } - public unsafe void AccumulatePose(scoped Span pos, scoped Span q, int sequence, TimeUnit_t cycle, float weight, TimeUnit_t time, IKContext? ikContext) { + public void AccumulatePose(scoped Span pos, scoped Span q, int sequence, TimeUnit_t cycle, float weight, TimeUnit_t time, IKContext? ikContext) { Span pos2 = stackalloc Vector3[Studio.MAXSTUDIOBONES]; Span q2 = stackalloc Quaternion[Studio.MAXSTUDIOBONES]; diff --git a/Source.Common/CFormatting.cs b/Source.Common/CFormatting.cs index 829942afc..da654cdcd 100644 --- a/Source.Common/CFormatting.cs +++ b/Source.Common/CFormatting.cs @@ -94,7 +94,7 @@ private unsafe void WriteAnyLiterals() { public static implicit operator Span(PrintF self) => self.input; public static implicit operator int(PrintF self) => self.input.Length; - public unsafe PrintF D(int i) { + public PrintF D(int i) { WriteAnyLiterals(); reader.ReadVariable(out char t, out int varIdx); Span buffer = stackalloc char[11]; @@ -107,7 +107,7 @@ public unsafe PrintF D(int i) { return this; } - public unsafe PrintF F(float i) { + public PrintF F(float i) { WriteAnyLiterals(); reader.ReadVariable(out char t, out int varIdx); Span buffer = stackalloc char[11]; @@ -120,7 +120,7 @@ public unsafe PrintF F(float i) { return this; } - public unsafe PrintF U(uint i) { + public PrintF U(uint i) { WriteAnyLiterals(); reader.ReadVariable(out char t, out int varIdx); Span buffer = stackalloc char[11]; @@ -132,7 +132,7 @@ public unsafe PrintF U(uint i) { WriteAnyLiterals(); return this; } - public unsafe PrintF D(long i) { + public PrintF D(long i) { WriteAnyLiterals(); reader.ReadVariable(out char t, out int varIdx); Span buffer = stackalloc char[19]; diff --git a/Source.Common/Exts.cs b/Source.Common/Exts.cs index 7fadc8c3d..2dc95f005 100644 --- a/Source.Common/Exts.cs +++ b/Source.Common/Exts.cs @@ -858,7 +858,7 @@ private static bool ParametersMatch(ParameterInfo[] parameters, ImmutableArray 0) { if (reader.PeekChar() == -1) return false; @@ -867,9 +867,9 @@ public static unsafe bool ReadNothing(this BinaryReader reader, int howMany) { } return true; } - public static unsafe int ReadASCIIStringInto(this BinaryReader reader, Span into) + public static int ReadASCIIStringInto(this BinaryReader reader, Span into) => ReadASCIIStringInto(reader, into, into.Length); - public static unsafe int ReadASCIIStringInto(this BinaryReader reader, Span into, int maxLength) { + public static int ReadASCIIStringInto(this BinaryReader reader, Span into, int maxLength) { Span asciiBlock = stackalloc byte[maxLength]; reader.Read(asciiBlock); return Encoding.ASCII.GetChars(asciiBlock, into); @@ -1006,7 +1006,7 @@ public static void EnsureCapacity(this ref Memory list, int ensureTo) { list.Add(new()); } - public static unsafe ulong Hash(this ReadOnlySpan str, bool invariant = true) { + public static ulong Hash(this ReadOnlySpan str, bool invariant = true) { // This might be a breaking change 12/21/2025 // But this should have been done from the start as a major consumer of potentially-not-null-terminated-strings str = str.SliceNullTerminatedString(); @@ -1044,7 +1044,7 @@ public static unsafe ulong Hash(this T target) where T : unmanaged { } } - public static unsafe ulong Hash(this Span target) where T : unmanaged { + public static ulong Hash(this Span target) where T : unmanaged { if (target.IsEmpty) return 0; ReadOnlySpan data = MemoryMarshal.Cast(target); return XXH64.DigestOf(data); @@ -1191,7 +1191,7 @@ public static bool PathStartsWith(this ReadOnlySpan str1, ReadOnlySpan Hash((ReadOnlySpan)target, invariant); + public static ulong Hash(this string target, bool invariant = true) => Hash((ReadOnlySpan)target, invariant); public static char Nibble(this char c) { if ((c >= '0') && (c <= '9')) return (char)(c - '0'); @@ -1808,12 +1808,12 @@ public void WriteBytes(ReadOnlySpan bytes) { public double ReadDouble() => ReadBytes(sizeof(double)).Cast()[0]; */ - public unsafe void Write(in T value) where T : unmanaged { + public void Write(in T value) where T : unmanaged { ReadOnlySpan bytes = new ReadOnlySpan(in value).Cast(); bytes.CopyTo(contents[ptr..]); ptr += bytes.Length; } - public unsafe void Write(Span value) where T : unmanaged { + public void Write(Span value) where T : unmanaged { for (int i = 0; i < value.Length; i++) Write(in value[i]); } diff --git a/Source.Common/Formats/BSP/BSPFile.cs b/Source.Common/Formats/BSP/BSPFile.cs index 2fabf61d8..e292848cb 100644 --- a/Source.Common/Formats/BSP/BSPFile.cs +++ b/Source.Common/Formats/BSP/BSPFile.cs @@ -235,7 +235,7 @@ public struct BSPLump /// /// public byte[] ReadBytes(Stream stream) => ReadBytes(stream)!; // << Never will be null when byte - public unsafe T[]? ReadBytes(Stream stream) where T : unmanaged { + public T[]? ReadBytes(Stream stream) where T : unmanaged { stream.Seek(FileOffset, SeekOrigin.Begin); int sizeofone = Unsafe.SizeOf(); diff --git a/Source.Common/MaterialSystem/IMesh.cs b/Source.Common/MaterialSystem/IMesh.cs index aebe89b08..9a2b850d8 100644 --- a/Source.Common/MaterialSystem/IMesh.cs +++ b/Source.Common/MaterialSystem/IMesh.cs @@ -506,7 +506,7 @@ internal void Specular3ubv(ReadOnlySpan c) { *(int*)pSpecular = col; } - internal unsafe void CompressedBoneWeight3fv(ReadOnlySpan boneWeights) { + internal void CompressedBoneWeight3fv(ReadOnlySpan boneWeights) { float* pDestWeights = OffsetFloatPointer(Desc.BoneWeight, CurrentVertex, Desc.BoneWeightSize); // No compression yet if (pDestWeights != null) { @@ -1004,8 +1004,8 @@ public void Color4ub(byte r, byte g, byte b, byte a) { byte* pDst = VertexBuilder.CurrColor; pDst[0] = r; pDst[1] = g; pDst[2] = b; pDst[3] = a; } - public unsafe void Color4ubv(ReadOnlySpan rgba) => VertexBuilder.Color4ubv(rgba); - public unsafe void Color4ubv(in Color rgba) { + public void Color4ubv(ReadOnlySpan rgba) => VertexBuilder.Color4ubv(rgba); + public void Color4ubv(in Color rgba) { *(Color*)VertexBuilder.CurrColor = rgba; } diff --git a/Source.Common/Mathematics/MathLib.cs b/Source.Common/Mathematics/MathLib.cs index 061f32b53..49b4e1b69 100644 --- a/Source.Common/Mathematics/MathLib.cs +++ b/Source.Common/Mathematics/MathLib.cs @@ -206,7 +206,7 @@ public unsafe Span this[int row] { return new(Unsafe.AsPointer(ref Unsafe.Add(ref M00, (row * 4))), 4); } } - public unsafe float this[int row, int col] { + public float this[int row, int col] { get { if (row < 0 || row >= 3) throw new ArgumentOutOfRangeException(nameof(row)); if (col < 0 || col >= 4) throw new ArgumentOutOfRangeException(nameof(col)); @@ -988,16 +988,16 @@ public static int BoxOnPlaneSide(in Vector3 emins, in Vector3 emaxs, in Collisio } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe uint SubInt(in fltx4 a, int idx) { + public static uint SubInt(in fltx4 a, int idx) { return a.AsUInt32().GetElement(idx); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe uint SubInt(in Vector3 a, int idx) { + public static uint SubInt(in Vector3 a, int idx) { float val = a[idx]; return Unsafe.As(ref val); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe uint SubInt(in Vector4 a, int idx) { + public static uint SubInt(in Vector4 a, int idx) { float val = a[idx]; return Unsafe.As(ref val); } @@ -4141,6 +4141,6 @@ public static class VectorFieldExts public static Span Base(this ref QAngle a) => MemoryMarshal.CreateSpan(ref Unsafe.As(ref a), 3); - public static unsafe ReadOnlySpan ReadOnlyBase(this in Vector3 v) => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As(ref Unsafe.AsRef(in v)), 3); - public static unsafe ReadOnlySpan ReadOnlyBase(this in QAngle a) => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As(ref Unsafe.AsRef(in a)), 3); + public static ReadOnlySpan ReadOnlyBase(this in Vector3 v) => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As(ref Unsafe.AsRef(in v)), 3); + public static ReadOnlySpan ReadOnlyBase(this in QAngle a) => MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As(ref Unsafe.AsRef(in a)), 3); } diff --git a/Source.Common/NetworkVar.cs b/Source.Common/NetworkVar.cs index 65bd59216..a5c3df653 100644 --- a/Source.Common/NetworkVar.cs +++ b/Source.Common/NetworkVar.cs @@ -34,7 +34,7 @@ public readonly ref Type GetForModify(int i) { return ref Value[i]; } - public readonly unsafe void Set(int i, in Type val) { + public readonly void Set(int i, in Type val) { Assert(i >= 0 && i < count); if (memcmp(in Value[i], in val) != 0) { NetworkStateChanged(i); diff --git a/Source.Common/Networking/DataFragments.cs b/Source.Common/Networking/DataFragments.cs index 31688bfc0..92d8c519e 100644 --- a/Source.Common/Networking/DataFragments.cs +++ b/Source.Common/Networking/DataFragments.cs @@ -4,7 +4,7 @@ namespace Source.Common.Networking; -public unsafe class DataFragments +public class DataFragments { public string? Filename; public byte[]? Buffer; diff --git a/Source.Common/Networking/IConnectionlessPacketHandler.cs b/Source.Common/Networking/IConnectionlessPacketHandler.cs index 733865279..ff1dcbb09 100644 --- a/Source.Common/Networking/IConnectionlessPacketHandler.cs +++ b/Source.Common/Networking/IConnectionlessPacketHandler.cs @@ -280,7 +280,7 @@ public class SplitPacketEntry public double LastActiveTime; } -public unsafe class NetScratchBuffer +public class NetScratchBuffer { public readonly byte[] Data = ArrayPool.Shared.Rent(MAX_MESSAGE); public int Length => Data.Length; @@ -322,7 +322,7 @@ public override string ToString() { } } -public unsafe class NetPacket +public class NetPacket { public NetAddress From; public byte[]? Data; diff --git a/Source.Engine/CModel_Private.cs b/Source.Engine/CModel_Private.cs index 7cd1e9e0a..44d6e5ceb 100644 --- a/Source.Engine/CModel_Private.cs +++ b/Source.Engine/CModel_Private.cs @@ -388,7 +388,7 @@ internal static TraceInfo BeginTrace() { return traceInfo; } - internal static unsafe int BoxLeafnums(ref LeafNums context, in Vector3 center, in Vector3 extents, int nodenum) { + internal static int BoxLeafnums(ref LeafNums context, in Vector3 center, in Vector3 extents, int nodenum) { int leafCount = 0; const int NODELIST_MAX = 1024; Span nodeList = stackalloc int[NODELIST_MAX]; @@ -455,7 +455,7 @@ static bool IsTraceBoxIntersectingBoxBrush(TraceInfo traceInfo, ref CollisionBox return MathLib.IsAllZeros(sep3); } - internal static unsafe void TestBoxInBrush(TraceInfo traceInfo, in CollisionBrush brush) { + internal static void TestBoxInBrush(TraceInfo traceInfo, in CollisionBrush brush) { if (brush.IsBox()) { ref CollisionBoxBrush box = ref traceInfo.BSPData!.MapBoxBrushes.AsSpan()[brush.GetBox()]; if (!IsTraceBoxIntersectingBoxBrush(traceInfo, ref box)) @@ -511,7 +511,7 @@ internal static unsafe void TestBoxInBrush(TraceInfo traceInfo, in CollisionBrus trace.FractionLeftSolid = 1.0f; trace.Contents = brush.Contents; } - internal static unsafe void TestInLeaf(TraceInfo traceInfo, int ndxLeaf) { + internal static void TestInLeaf(TraceInfo traceInfo, int ndxLeaf) { ref CollisionLeaf leaf = ref traceInfo.BSPData.MapLeafs.AsSpan()[ndxLeaf]; // trace ray/box sweep against all brushes in this leaf @@ -706,7 +706,7 @@ internal static void PostStab(TraceInfo traceInfo) { } } - internal static unsafe void UnsweptBoxTrace(TraceInfo traceInfo, in Ray ray, int headnode, Mask brushmask) { + internal static void UnsweptBoxTrace(TraceInfo traceInfo, in Ray ray, int headnode, Mask brushmask) { Span leafs = stackalloc int[1024]; int i, numleafs; diff --git a/Source.Engine/Cbuf.cs b/Source.Engine/Cbuf.cs index 692ce6099..4f74a1bb3 100644 --- a/Source.Engine/Cbuf.cs +++ b/Source.Engine/Cbuf.cs @@ -31,7 +31,7 @@ public class Command TokenizedCommand currentCommand; - public unsafe bool DequeueNextCommand() { + public bool DequeueNextCommand() { currentCommand.Reset(); Dbg.Assert(isProcessingCommands); if (Commands.Count == 0) @@ -66,7 +66,7 @@ public CommandBuffer() { public ref TokenizedCommand GetCommand() => ref currentCommand; - public unsafe bool AddText(ReadOnlySpan text, long tickDelay = 0) { + public bool AddText(ReadOnlySpan text, long tickDelay = 0) { long tick = currentTick + tickDelay; ReadOnlySpan currentCommand = text.SliceNullTerminatedString(); @@ -94,7 +94,7 @@ public unsafe bool AddText(ReadOnlySpan text, long tickDelay = 0) { return true; } - unsafe void Compact() { + void Compact() { argBufferSize = 0; Span tempBuffer = stackalloc char[ARGS_BUFFER_LENGTH]; Span writeBuffer = argsBuffer.AsSpan(); diff --git a/Source.Engine/Net.cs b/Source.Engine/Net.cs index 7e59f93bc..db1e6221c 100644 --- a/Source.Engine/Net.cs +++ b/Source.Engine/Net.cs @@ -256,7 +256,7 @@ public bool TryFindNetChannel(NetSocketType socket, NetAddress address, [NotNull return netchan != null; } - public unsafe void ProcessSocket(NetSocketType sock, IConnectionlessPacketHandler handler) { + public void ProcessSocket(NetSocketType sock, IConnectionlessPacketHandler handler) { NetPacket? packet; lock (NetChannels) { int numChannels = NetChannels.Count; @@ -533,7 +533,7 @@ public bool BufferToBufferDecompress(Span dst, ref uint dstLen, Span } private ArrayPool DecompressionPool = ArrayPool.Create(); - public unsafe uint GetDecompressedBufferSize(Span compressedbuf) { + public uint GetDecompressedBufferSize(Span compressedbuf) { if (compressedbuf.IsEmpty) return 0; @@ -636,7 +636,7 @@ public bool LagPacket(bool newdata, NetPacket packet) { return newdata; } - public unsafe NetPacket? GetPacket(NetSocketType sock, byte[] scratch) { + public NetPacket? GetPacket(NetSocketType sock, byte[] scratch) { DiscardStaleSplitPackets(sock); NetPacket packet = NetPackets[(int)sock]; @@ -976,7 +976,7 @@ public void Shutdown() { ConfigLoopbackBuffers(false); } - public unsafe int SendPacket(NetChannel chan, NetSocketType sock, NetAddress? to, byte[]? data, int length, bf_write? voicePayload = null, bool useCompression = false) { + public int SendPacket(NetChannel chan, NetSocketType sock, NetAddress? to, byte[]? data, int length, bf_write? voicePayload = null, bool useCompression = false) { int ret = -1; if (data == null) @@ -1050,12 +1050,12 @@ public unsafe int SendPacket(NetChannel chan, NetSocketType sock, NetAddress? to return ret; } - public unsafe int SendTo(bool verbose, Socket s, byte[] buf, int len, NetAddress to, int gameDataLength) { + public int SendTo(bool verbose, Socket s, byte[] buf, int len, NetAddress to, int gameDataLength) { int send = SendToImpl(s, buf, len, to, gameDataLength); return send; } - private unsafe int SendToImpl(Socket s, Span buf, int len, NetAddress to, int gameDataLength) { + private int SendToImpl(Socket s, Span buf, int len, NetAddress to, int gameDataLength) { return s.SendTo(buf.Slice(0, len), 0, to); } @@ -1139,7 +1139,7 @@ public void Reset() { } - public unsafe void SendLoopPacket(NetSocketType sock, int length, byte[] data, NetAddress? to) { + public void SendLoopPacket(NetSocketType sock, int length, byte[] data, NetAddress? to) { if (length > MAX_PAYLOAD) { DevMsg("NET_SendLoopPacket: packet too big (%i).\n", length); return; diff --git a/Source.Engine/NetChannel.cs b/Source.Engine/NetChannel.cs index 085640dba..3f1b71bd8 100644 --- a/Source.Engine/NetChannel.cs +++ b/Source.Engine/NetChannel.cs @@ -580,7 +580,7 @@ public static unsafe void WritePacketToConsole(byte* ptr, int length) { Console.WriteLine(); } - public unsafe void RemoveHeadInWaitingList(int list) { + public void RemoveHeadInWaitingList(int list) { DataFragments data = WaitingList[list][0]; data.Return(); @@ -589,7 +589,7 @@ public unsafe void RemoveHeadInWaitingList(int list) { WaitingList[list].Remove(data); } - public unsafe void CheckWaitingList(int list) { + public void CheckWaitingList(int list) { if (WaitingList[list].Count == 0 || OutSequenceAck <= 0) return; @@ -715,7 +715,7 @@ public void ProcessPacket(NetPacket packet, bool hasHeader) { MessageHandler.PacketEnd(); } - public unsafe bool CheckReceivingList(FragmentStream list) { + public bool CheckReceivingList(FragmentStream list) { DataFragments data = ReceiveList[(int)list]; if (data.Buffer == null) @@ -1018,7 +1018,7 @@ public bool SendData(bf_write msg, bool reliable) { return null; } - public unsafe void UpdateSubchannels() { + public void UpdateSubchannels() { // first check if there is a free subchannel SubChannel? freeSubChan = GetFreeSubChannel(); @@ -1321,7 +1321,7 @@ public unsafe bool SendSubChannelData(bf_write buf) { static ConVar net_minroutable = new("16", 0, "Forces larger payloads."); static ConVar net_maxroutable = new("1260", FCvar.Archive | FCvar.UserInfo, "Requested max packet size before packets are 'split'.", MIN_USER_MAXROUTABLE_SIZE, MAX_USER_MAXROUTABLE_SIZE); - private unsafe byte[] sendbuf = new byte[MAX_MESSAGE]; + private byte[] sendbuf = new byte[MAX_MESSAGE]; private bf_write send = new(); public unsafe int SendDatagram(bf_write? datagram) { if (Socket == NetSocketType.Client) { @@ -1474,7 +1474,7 @@ public void SetMaxRoutablePayloadSize(int splitSize) { public int GetMaxRoutablePayloadSize() => MaxRoutablePayloadSize; - public unsafe bool CreateFragmentsFromBuffer(bf_write buffer, FragmentStream stream) { + public bool CreateFragmentsFromBuffer(bf_write buffer, FragmentStream stream) { bf_write bfwrite = new(); DataFragments? data = null; diff --git a/Source.Engine/SpatialPartition.cs b/Source.Engine/SpatialPartition.cs index 5bd6e15d4..3797fc9b0 100644 --- a/Source.Engine/SpatialPartition.cs +++ b/Source.Engine/SpatialPartition.cs @@ -1013,7 +1013,7 @@ bool EnumerateElementsAlongRay_Ray(SpatialPartitionListMask_t listMask, return true; } - unsafe bool EnumerateElementsAlongRay_ExtrudedRay(SpatialPartitionListMask_t listMask, + bool EnumerateElementsAlongRay_ExtrudedRay(SpatialPartitionListMask_t listMask, in Ray ray, in Vector3 vecInvDelta, in Vector3 vecEnd, scoped ref IPE iterator) where IPE : struct, IPartitionEnumerator, allows ref struct { Vector3 vecMin = ray.Start - ray.Extents; Vector3 vecMax = ray.Start + ray.Extents; diff --git a/Source.Engine/Sys.cs b/Source.Engine/Sys.cs index 4ad000a9a..2ba699433 100644 --- a/Source.Engine/Sys.cs +++ b/Source.Engine/Sys.cs @@ -136,7 +136,7 @@ private void Write(string group, ReadOnlySpan str, in Color color, bool ro Span buffer = stackalloc char[256]; int bufferIdx = 0; - unsafe void writeTxt(ReadOnlySpan sub, in Color color) { + void writeTxt(ReadOnlySpan sub, in Color color) { #if DBGFLAG_WRITE_TO_STDOUT Console.Write(sub.Pastel(color)); #endif diff --git a/Source.Filesystem/BaseFileSystem.cs b/Source.Filesystem/BaseFileSystem.cs index b355a3563..e75d60cb2 100644 --- a/Source.Filesystem/BaseFileSystem.cs +++ b/Source.Filesystem/BaseFileSystem.cs @@ -581,7 +581,7 @@ readonly ref struct RenameFile_Op(ReadOnlySpan newPath) : IFirstToThePostO public bool Win(bool v) => v; } - public unsafe bool RenameFile(ReadOnlySpan oldPath, ReadOnlySpan newPath, ReadOnlySpan pathID) { + public bool RenameFile(ReadOnlySpan oldPath, ReadOnlySpan newPath, ReadOnlySpan pathID) { return FirstToThePost(oldPath, pathID, new RenameFile_Op(newPath), false, out _); } diff --git a/Source.MaterialSystem/Surface/Clip2D.cs b/Source.MaterialSystem/Surface/Clip2D.cs index f30259f92..e72854263 100644 --- a/Source.MaterialSystem/Surface/Clip2D.cs +++ b/Source.MaterialSystem/Surface/Clip2D.cs @@ -125,7 +125,7 @@ public static void ScreenClip(in ScissorRectState state, ScreenClipState clip, I } static ScreenClipState clipPolygon = new(); - public unsafe static int ClipPolygon(in ScissorRectState state, Span verts, int translateX, int translateY, out Span clippedVerts) { + public static int ClipPolygon(in ScissorRectState state, Span verts, int translateX, int translateY, out Span clippedVerts) { clipPolygon.TempVertices.EnsureCount(verts.Length * 4); clipPolygon.ClipVertices[0].EnsureCount(verts.Length * 4); clipPolygon.ClipVertices[1].EnsureCount(verts.Length * 4); diff --git a/Source.MaterialSystem/Surface/FreeTypeFont.cs b/Source.MaterialSystem/Surface/FreeTypeFont.cs index 033f38d8a..3e3611982 100644 --- a/Source.MaterialSystem/Surface/FreeTypeFont.cs +++ b/Source.MaterialSystem/Surface/FreeTypeFont.cs @@ -181,7 +181,7 @@ internal override void GetCharRGBA(char ch, int rgbaWide, int rgbaTall, Span rgba) { + private void DrawBitmap(FT_GlyphSlotRec_* rec, int rgbaWide, int rgbaTall, Span rgba) { FT_Bitmap_* bitmap = &rec->bitmap; byte* buffer = bitmap->buffer; int bmpWidth = (int)bitmap->width; diff --git a/Source.MaterialSystem/Surface/TextureDictionary.cs b/Source.MaterialSystem/Surface/TextureDictionary.cs index 1b0d7548d..b97ffbeb5 100644 --- a/Source.MaterialSystem/Surface/TextureDictionary.cs +++ b/Source.MaterialSystem/Surface/TextureDictionary.cs @@ -75,7 +75,7 @@ public void RegenerateTextureBits(ITexture texture, IVTFTexture vtfTexture, in R } } - internal unsafe void UpdateBackingBits(Rectangle subRect, Span bits, Rectangle uploadRect, ImageFormat format) { + internal void UpdateBackingBits(Rectangle subRect, Span bits, Rectangle uploadRect, ImageFormat format) { nint size = ImageLoader.GetMemRequired(Width, Height, 1, Format, false); if (TextureBits == null) { diff --git a/Source.MaterialSystem/Texture.cs b/Source.MaterialSystem/Texture.cs index 3a5ee5244..6a3d6f339 100644 --- a/Source.MaterialSystem/Texture.cs +++ b/Source.MaterialSystem/Texture.cs @@ -863,7 +863,7 @@ private int ComputeActualSize(bool ignorePicmip = false, IVTFTexture? vtfTexture return ComputeMipSkipCount(GetName(), DimsMapping, ignorePicmip, vtfTexture, Flags, DesiredDimensionLimit, ref StreamingMips, out CachedFileLodSettings, out DimsActual, out DimsAllocated, out stripFlags); } - private unsafe int ComputeMipSkipCount(ReadOnlySpan readOnlySpan, TexDimensions mappingDims, bool ignorePicmip, IVTFTexture? vtfTexture, uint flags, ushort desiredDimensionLimit, ref ushort streamingMips, out TextureLODControlSettings cachedFileLodSettings, out TexDimensions dimsActual, out TexDimensions dimsAllocated, out uint outStripFlags) { + private int ComputeMipSkipCount(ReadOnlySpan readOnlySpan, TexDimensions mappingDims, bool ignorePicmip, IVTFTexture? vtfTexture, uint flags, ushort desiredDimensionLimit, ref ushort streamingMips, out TextureLODControlSettings cachedFileLodSettings, out TexDimensions dimsActual, out TexDimensions dimsAllocated, out uint outStripFlags) { TexDimensions actualDims = mappingDims, allocatedDims = new(); bool bTextureMigration = (Flags & (uint)TextureFlags.Streamable) != 0; diff --git a/Source.Physics/Main.cs b/Source.Physics/Main.cs index ffe1de57d..cb53a638c 100644 --- a/Source.Physics/Main.cs +++ b/Source.Physics/Main.cs @@ -39,7 +39,7 @@ public void DisableCollisions(int index0, int index1) { public bool ShouldCollide(int index0, int index1) => (Bits[index0] & (1u << index1)) != 0; } -public unsafe class PhysicsInterface : IPhysics +public class PhysicsInterface : IPhysics { readonly List Environments = []; readonly Dictionary CollisionSets = []; diff --git a/Source.Physics/PhysicsCollide.cs b/Source.Physics/PhysicsCollide.cs index 0d3572c4f..14a78ebff 100644 --- a/Source.Physics/PhysicsCollide.cs +++ b/Source.Physics/PhysicsCollide.cs @@ -12,7 +12,7 @@ namespace Source.Physics; -internal sealed unsafe class BoxPhysConvex : PhysConvex +internal sealed class BoxPhysConvex : PhysConvex { public HullData Hull; public HullData SimHull; @@ -120,7 +120,7 @@ public void Free() { } } -internal sealed unsafe class BoxPhysCollide : PhysCollide +internal sealed class BoxPhysCollide : PhysCollide { public readonly List Convexes = []; public MeshData Mesh; diff --git a/Source.Physics/PhysicsConstraints.cs b/Source.Physics/PhysicsConstraints.cs index 08164fdd1..e965b3d93 100644 --- a/Source.Physics/PhysicsConstraints.cs +++ b/Source.Physics/PhysicsConstraints.cs @@ -9,7 +9,7 @@ namespace Source.Physics; -internal static unsafe class ConstraintMath +internal static class ConstraintMath { public static readonly Vector3 AxisX = new() { X = 1.0f, Y = 0.0f, Z = 0.0f }; public static readonly Vector3 AxisY = new() { X = 0.0f, Y = 1.0f, Z = 0.0f }; @@ -45,7 +45,7 @@ public static Quaternion LocalFrameForAxis(Body body, Vector3 fromAxis, Vector3 public static float Length(Vector3 v) => BoxToSource.Unitless(v).Length(); } -internal unsafe class PhysicsConstraint : IPhysicsConstraint +internal class PhysicsConstraint : IPhysicsConstraint { readonly PhysicsEnvironment Environment; PhysicsObject? Reference; @@ -478,7 +478,7 @@ public bool GetConstraintParams(out ConstraintBreakableParams parms) { public void OutputDebugInfo() { } } -internal unsafe partial class PhysicsEnvironment +internal partial class PhysicsEnvironment { readonly List Constraints = []; readonly List Pulleys = []; @@ -878,7 +878,7 @@ public void SolvePenetration(IPhysicsObject obj0, IPhysicsObject obj1) { } public void RemoveConstraint(PhysicsConstraint constraint) => Constraints.Remove(constraint); } -internal unsafe class PhysicsSpring : IPhysicsSpring +internal class PhysicsSpring : IPhysicsSpring { PhysicsObject? Start; PhysicsObject? End; diff --git a/Source.Physics/PhysicsEnvironment.cs b/Source.Physics/PhysicsEnvironment.cs index 7d33c1ada..448653f1d 100644 --- a/Source.Physics/PhysicsEnvironment.cs +++ b/Source.Physics/PhysicsEnvironment.cs @@ -21,7 +21,7 @@ internal static class PhysicsEnvironmentGlobals internal static IPhysicsObjectPairHash CreateObjectPairHash() => new ObjectPairHash(); } -internal unsafe partial class PhysicsEnvironment : IPhysicsEnvironment, ICustomFilterHandler, IPreSolveHandler +internal partial class PhysicsEnvironment : IPhysicsEnvironment, ICustomFilterHandler, IPreSolveHandler { static readonly ConVar vbox_substeps = new("vbox_substeps", "16", 0, "Solver substeps per physics step.", 1.0, 1024.0); static readonly ConVar vbox_contact_hertz = new("vbox_contact_hertz", "240", 0, "Contact stiffness in Hz. Lower is softer/smushier.", 1.0, 480.0); diff --git a/Source.Physics/PhysicsFluidController.cs b/Source.Physics/PhysicsFluidController.cs index e67c1507f..964024de8 100644 --- a/Source.Physics/PhysicsFluidController.cs +++ b/Source.Physics/PhysicsFluidController.cs @@ -11,7 +11,7 @@ namespace Source.Physics; -internal unsafe class PhysicsFluidController : IPhysicsFluidController +internal class PhysicsFluidController : IPhysicsFluidController { PhysicsObject? FluidObject; FluidParams Params; diff --git a/Source.Physics/PhysicsFriction.cs b/Source.Physics/PhysicsFriction.cs index 1ae0028ef..190481989 100644 --- a/Source.Physics/PhysicsFriction.cs +++ b/Source.Physics/PhysicsFriction.cs @@ -7,7 +7,7 @@ namespace Source.Physics; -internal unsafe class PhysicsFrictionSnapshot : IPhysicsFrictionSnapshot +internal class PhysicsFrictionSnapshot : IPhysicsFrictionSnapshot { struct Entry { diff --git a/Source.Physics/PhysicsObject.cs b/Source.Physics/PhysicsObject.cs index 149cea52a..493080075 100644 --- a/Source.Physics/PhysicsObject.cs +++ b/Source.Physics/PhysicsObject.cs @@ -11,7 +11,7 @@ namespace Source.Physics; -internal unsafe class PhysicsObject : IPhysicsObject +internal class PhysicsObject : IPhysicsObject { static ulong NextUniqueId = 1; diff --git a/Source.Physics/PhysicsPlayerController.cs b/Source.Physics/PhysicsPlayerController.cs index 90a48a424..7ad576b90 100644 --- a/Source.Physics/PhysicsPlayerController.cs +++ b/Source.Physics/PhysicsPlayerController.cs @@ -8,7 +8,7 @@ namespace Source.Physics; -internal unsafe class PhysicsPlayerController : IPhysicsPlayerController +internal class PhysicsPlayerController : IPhysicsPlayerController { const float GroundNormalZ = -0.7f; diff --git a/Source.SDLSystem/SDL3_System.Win32.cs b/Source.SDLSystem/SDL3_System.Win32.cs index 8dfea7beb..5c35c09de 100644 --- a/Source.SDLSystem/SDL3_System.Win32.cs +++ b/Source.SDLSystem/SDL3_System.Win32.cs @@ -4,7 +4,7 @@ namespace Source.SDLManager; -public unsafe partial class SDL3_System +public partial class SDL3_System { #pragma warning disable CA1416 // Validate platform compatibility (WIN32 ifdef catches this instead) static string[] possibleKeys = [@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", @"SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts"]; diff --git a/Source.SDLSystem/SDL3_System.cs b/Source.SDLSystem/SDL3_System.cs index 9d6767e61..60f55408c 100644 --- a/Source.SDLSystem/SDL3_System.cs +++ b/Source.SDLSystem/SDL3_System.cs @@ -27,7 +27,7 @@ public int GetAvailableDrives(Span buf) { return 0; } - public unsafe nuint GetClipboardText(nint offset, Span buf) { + public nuint GetClipboardText(nint offset, Span buf) { if (!SDL3.SDL_HasClipboardText()) return 0; @@ -120,7 +120,7 @@ public void SetClipboardImage(IWindow wnd, int x1, int y1, int x2, int y2) { throw new NotImplementedException(); } - public unsafe void SetClipboardText(ReadOnlySpan text) { + public void SetClipboardText(ReadOnlySpan text) { if (text.IsEmpty) SDL3.SDL_SetClipboardText(""); diff --git a/Source.ShaderAPI.Gl46/IndexBufferGl46.cs b/Source.ShaderAPI.Gl46/IndexBufferGl46.cs index 4e602982a..af20931ba 100644 --- a/Source.ShaderAPI.Gl46/IndexBufferGl46.cs +++ b/Source.ShaderAPI.Gl46/IndexBufferGl46.cs @@ -28,7 +28,7 @@ public unsafe class IndexBufferGl46 : IDisposable PersistentBufferRing? ring; bool Written; - public unsafe void RecomputeIBO() { + public void RecomputeIBO() { if (Dynamic) { if (ring == null || BufferSize > lastBufferSize) { lastBufferSize = BufferSize; diff --git a/Source.ShaderAPI.Gl46/MeshGl46.cs b/Source.ShaderAPI.Gl46/MeshGl46.cs index 6b26d4dca..5510ab9ae 100644 --- a/Source.ShaderAPI.Gl46/MeshGl46.cs +++ b/Source.ShaderAPI.Gl46/MeshGl46.cs @@ -94,7 +94,7 @@ public virtual void BeginCastBuffer(MaterialIndexFormat format) { throw new NotImplementedException(); } - public virtual unsafe void Draw(int firstIndex = -1, int indexCount = 0) { + public virtual void Draw(int firstIndex = -1, int indexCount = 0) { Assert(VertexBuffer != null); if (VertexBuffer == null) return; @@ -131,7 +131,7 @@ public virtual void Draw(ReadOnlySpan lis } } - private unsafe void DrawInternal(PrimList* primList, int lists) { + private void DrawInternal(PrimList* primList, int lists) { HandleLateCreation(); int i; @@ -369,7 +369,7 @@ public virtual void SetVertexFormat(VertexFormat fmt) { VertexFormat = fmt; } - public virtual unsafe void RenderPass() { + public virtual void RenderPass() { HandleLateCreation(); Assert(Type != MaterialPrimitiveType.Heterogenous); diff --git a/Source.ShaderAPI.Gl46/ShaderAPIGl46.cs b/Source.ShaderAPI.Gl46/ShaderAPIGl46.cs index f1eb550de..949e56cb8 100644 --- a/Source.ShaderAPI.Gl46/ShaderAPIGl46.cs +++ b/Source.ShaderAPI.Gl46/ShaderAPIGl46.cs @@ -126,7 +126,7 @@ public bool OnDeviceInit() { DeviceState DeviceState = DeviceState.OK; - public unsafe void ClearBuffers(bool clearColor, bool clearDepth, bool clearStencil, int renderTargetWidth = -1, int renderTargetHeight = -1) { + public void ClearBuffers(bool clearColor, bool clearDepth, bool clearStencil, int renderTargetWidth = -1, int renderTargetHeight = -1) { if (IsDeactivated()) return; @@ -1791,7 +1791,7 @@ public int GetCurrentNumBones() { Dictionary> locs = []; - public unsafe int LocateShaderUniform(ReadOnlySpan name) { + public int LocateShaderUniform(ReadOnlySpan name) { if (!activeVertexShader.IsValid()) { Warning("WARNING: Attempted to locate uniform on an invalid vertex shader!\n"); return -1; @@ -2176,7 +2176,7 @@ private unsafe void LoadTextureFromVTF(in TextureLoadInfo info, IVTFTexture vtf, - public unsafe ShaderAPITextureHandle_t CreateTexture( + public ShaderAPITextureHandle_t CreateTexture( int width, int height, int depth, @@ -2190,7 +2190,7 @@ public unsafe ShaderAPITextureHandle_t CreateTexture( CreateTextures(new Span(ref handle), width, height, depth, imageFormat, mipCount, copies, flags, debugName, textureGroup); return handle; } - public unsafe void CreateTextures( + public void CreateTextures( Span textureHandles, int width, int height, @@ -2432,7 +2432,7 @@ public enum InternalTextureFlags readonly Dictionary Textures = []; int currentTextureID = 1; public int AllocNewTextureID() => Interlocked.Increment(ref currentTextureID); - public unsafe void CreateTextureHandles(Span textureHandles) { + public void CreateTextureHandles(Span textureHandles) { int idxCreating = 0; ShaderAPITextureHandle_t hTexture; foreach (var texture in Textures) { @@ -2528,7 +2528,7 @@ private uint GetGL46Texture(ShaderAPITextureHandle_t textureHandle) { [MethodImpl(MethodImplOptions.AggressiveInlining)] public InternalTextureInfo? GetTexture() => Textures.TryGetValue(ModifyTextureHandle, out InternalTextureInfo? info) ? info : null; - public unsafe void TexImage2D(int mip, int face, ImageFormat dstFormat, int zOffset, int width, int height, ImageFormat srcFormat, bool srcIsTiled, Span imageData) { + public void TexImage2D(int mip, int face, ImageFormat dstFormat, int zOffset, int width, int height, ImageFormat srcFormat, bool srcIsTiled, Span imageData) { var tex = GetTexture(GetModifyTextureHandle()); TextureLoadInfo info = new(); info.TextureHandle = GetModifyTextureHandle(); diff --git a/Source.ShaderAPI.Gl46/ShaderShadow.cs b/Source.ShaderAPI.Gl46/ShaderShadow.cs index e9080d4fa..d82ee08b5 100644 --- a/Source.ShaderAPI.Gl46/ShaderShadow.cs +++ b/Source.ShaderAPI.Gl46/ShaderShadow.cs @@ -83,7 +83,7 @@ private static unsafe int SizeAligned(int alignment = 16) where T : unmanaged } string? name; - public unsafe ShadowStateGl46(ShaderAPIGl46 shaderAPI, IShaderSystemInternal shaderSystem, ReadOnlySpan name = default) { + public ShadowStateGl46(ShaderAPIGl46 shaderAPI, IShaderSystemInternal shaderSystem, ReadOnlySpan name = default) { ShaderAPI = shaderAPI; Shaders = shaderSystem; this.name = name.IsEmpty ? null : new(name); @@ -118,7 +118,7 @@ private unsafe void CreateShaderObjects() { bool needsBufferUpload = true; internal VertexFormat VertexFormat; - public unsafe void Dispose() { + public void Dispose() { if (!ShaderAPI.IsOwnerThread()) { Warning("NOT IN MAIN THREAD - CANNOT DELETE UBO - GRAPHICS MEMORY LEAK\n"); return; @@ -131,7 +131,7 @@ public unsafe void Dispose() { public ShaderRenderStateFlags GetFlags() => Flags; public void SetFlags(ShaderRenderStateFlags flags) => Flags = flags; - public unsafe void Activate() { + public void Activate() { CreateShaderObjects(); // Recreate UBO's, if we were lazy-loaded ReuploadBuffers(); // Reupload UBO's, if needed diff --git a/Source.ShaderAPI.Gl46/VertexBufferGl46.cs b/Source.ShaderAPI.Gl46/VertexBufferGl46.cs index 4d847f7b0..09966be3b 100644 --- a/Source.ShaderAPI.Gl46/VertexBufferGl46.cs +++ b/Source.ShaderAPI.Gl46/VertexBufferGl46.cs @@ -278,9 +278,9 @@ internal bool HasEnoughRoom(int numVertices) { return NextLockOffset() + (numVertices * VertexSize) <= BufferSize; } - unsafe static nint dummyData = (nint)NativeMemory.AlignedAlloc(512, 16); + static nint dummyData = (nint)NativeMemory.AlignedAlloc(512, 16); - public static unsafe void ComputeVertexDescription(byte* vertexMemory, VertexFormat vertexFormat, ref VertexDesc desc) { + public static void ComputeVertexDescription(byte* vertexMemory, VertexFormat vertexFormat, ref VertexDesc desc) { desc.NumBoneWeights = vertexFormat.GetBoneWeightsSize(); fixed (VertexDesc* descPtr = &desc) { nint offset = 0; diff --git a/Source.VTF/VTFTexture.cs b/Source.VTF/VTFTexture.cs index f87cfc9f2..f5bb883b4 100644 --- a/Source.VTF/VTFTexture.cs +++ b/Source.VTF/VTFTexture.cs @@ -980,7 +980,7 @@ private int ComputeMipCount() { } private static readonly sbyte[] VTF0 = [86, 84, 70, 0]; // VTF\0 - private unsafe bool ReadHeader(Stream stream, out VTFFileHeader header) { + private bool ReadHeader(Stream stream, out VTFFileHeader header) { using BinaryReader reader = new(stream, Encoding.ASCII, true); header = new(); From e5022d0e1615627c28f6c0c747dc9a7e54e1ef64 Mon Sep 17 00:00:00 2001 From: callumok2004 Date: Tue, 17 Nov 2026 19:10:50 +0000 Subject: [PATCH 9/9] Use base gravity field --- Game.Client/GarrysMod/C_GMOD_Player.cs | 2 -- Game.Server/BaseEntity.cs | 3 ++- Game.Server/GarrysMod/GMOD_Player.cs | 2 -- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Game.Client/GarrysMod/C_GMOD_Player.cs b/Game.Client/GarrysMod/C_GMOD_Player.cs index 2a745e077..28f6401b3 100644 --- a/Game.Client/GarrysMod/C_GMOD_Player.cs +++ b/Game.Client/GarrysMod/C_GMOD_Player.cs @@ -95,8 +95,6 @@ public virtual void SetWeaponColor(in Vector3 color) { public EHANDLE Hands = new(); [NetworkVar("m_iMaxArmor")] public int MaxArmor; - [NetworkVar("m_flGravity")] - public new float Gravity; [NetworkVar("m_bSprintEnabled")] public bool SprintEnabled; diff --git a/Game.Server/BaseEntity.cs b/Game.Server/BaseEntity.cs index e07ca355a..6e2f300e9 100644 --- a/Game.Server/BaseEntity.cs +++ b/Game.Server/BaseEntity.cs @@ -1019,7 +1019,6 @@ public string GetDebugName() { } EHANDLE Parent; - public float Gravity; public void SetPredictionEligible(bool canpredict) { } // nothing in game code public ref readonly Vector3 GetLocalOrigin() => ref __nv_Origin; public ref readonly QAngle GetLocalAngles() => ref __nv_Rotation; @@ -2020,6 +2019,8 @@ public ReadOnlySpan GetSubMaterialOverride(int index) { public partial Vector3 ViewOffset { get; set; } [NetworkVar("m_flFriction")] public partial float Friction { get; set; } + [NetworkVar("m_flGravity")] + public partial float Gravity { get; set; } public byte OldRenderMode; public Vector3 AbsOrigin; diff --git a/Game.Server/GarrysMod/GMOD_Player.cs b/Game.Server/GarrysMod/GMOD_Player.cs index 47f42bbbc..4aa7dbeed 100644 --- a/Game.Server/GarrysMod/GMOD_Player.cs +++ b/Game.Server/GarrysMod/GMOD_Player.cs @@ -301,8 +301,6 @@ public virtual void SetWeaponColor(in Vector3 color) { public partial EHANDLE Hands { get; set; } [NetworkVar("m_iMaxArmor")] public partial int MaxArmor { get; set; } - [NetworkVar("m_flGravity")] - public new partial float Gravity { get; set; } [NetworkVar("m_bSprintEnabled")] public partial bool SprintEnabled { get; set; }