diff --git a/Game.Client/C_BaseAnimating.cs b/Game.Client/C_BaseAnimating.cs index 45024d26a..1fcfc6408 100644 --- a/Game.Client/C_BaseAnimating.cs +++ b/Game.Client/C_BaseAnimating.cs @@ -965,7 +965,7 @@ private static void RecvProxy_Sequence(ref readonly RecvProxyData data, object i public virtual void DoMuzzleFlash() => MuzzleFlashParity = unchecked((byte)((MuzzleFlashParity + 1) & ((1 << (int)EntityEffects.MuzzleflashBits) - 1))); - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BaseAnimating); + public static readonly new ClientClass ClientClass = new ClientClass(DT_BaseAnimating); protected override StudioHdr? OnNewModel() { InvalidateMdlCache(); int i; diff --git a/Game.Client/C_BaseAnimatingOverlay.cs b/Game.Client/C_BaseAnimatingOverlay.cs index 0eec93895..6bf17f870 100644 --- a/Game.Client/C_BaseAnimatingOverlay.cs +++ b/Game.Client/C_BaseAnimatingOverlay.cs @@ -74,7 +74,7 @@ private static void ResizeAnimationLayerCallback(object instance, object list, i public static readonly RecvTable DT_BaseAnimatingOverlay = new(DT_BaseAnimating, [ RecvPropDataTable("overlay_vars", DT_OverlayVars) - ]); public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BaseAnimatingOverlay); + ]); public static readonly new ClientClass ClientClass = new ClientClass(DT_BaseAnimatingOverlay); [NetworkName("m_AnimOverlay")] readonly List AnimOverlay = []; diff --git a/Game.Client/C_BaseCombatCharacter.cs b/Game.Client/C_BaseCombatCharacter.cs index 4deac43da..1be1bcc3a 100644 --- a/Game.Client/C_BaseCombatCharacter.cs +++ b/Game.Client/C_BaseCombatCharacter.cs @@ -31,7 +31,7 @@ public partial class C_BaseCombatCharacter : C_BaseFlex RecvPropArray3(FIELD.OF_ARRAY(nameof(MyWeapons)), RecvPropEHandle( FIELD.OF_ARRAY(nameof(MyWeapons)))), RecvPropInt(FIELD.OF(nameof(BloodColor))) ]); - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BaseCombatCharacter); + public static readonly new ClientClass ClientClass = new ClientClass(DT_BaseCombatCharacter); public C_BaseCombatWeapon? GetWeapon(int i) => MyWeapons[i].Get(); diff --git a/Game.Client/C_BaseEntity.cs b/Game.Client/C_BaseEntity.cs index f66ae2bf1..c1e85ea20 100644 --- a/Game.Client/C_BaseEntity.cs +++ b/Game.Client/C_BaseEntity.cs @@ -675,7 +675,7 @@ private static void RecvProxy_MoveType(ref readonly RecvProxyData data, object i public void SetCollisionBounds(in Vector3 mins, in Vector3 maxs) => CollisionProp().SetCollisionBounds(in mins, in maxs); - public static readonly ClientClass ClientClass = new ClientClass(null, null, DT_BaseEntity); + public static readonly ClientClass ClientClass = new ClientClass(DT_BaseEntity); const float coordTolerance = 2.0f / (float)(1 << (int)COORD_FRACTIONAL_BITS); public float GetGravity() => Gravity; diff --git a/Game.Client/C_BaseFlex.cs b/Game.Client/C_BaseFlex.cs index d9fa6a4dd..d94783153 100644 --- a/Game.Client/C_BaseFlex.cs +++ b/Game.Client/C_BaseFlex.cs @@ -169,7 +169,7 @@ public partial class C_BaseFlex : C_BaseAnimatingOverlay, IHasLocalToGlobalFlexS RecvPropVector ( FIELD.OF(nameof(Lean))), RecvPropVector ( FIELD.OF(nameof(Shift))), ]); - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BaseFlex); + public static readonly new ClientClass ClientClass = new ClientClass(DT_BaseFlex); [NetworkName("m_flexWeight")] public InlineArray96 FlexWeight; [NetworkName("m_blinktoggle")] diff --git a/Game.Client/C_BasePlayer.cs b/Game.Client/C_BasePlayer.cs index 0bb29b466..a43df8961 100644 --- a/Game.Client/C_BasePlayer.cs +++ b/Game.Client/C_BasePlayer.cs @@ -475,7 +475,7 @@ private void PlayPlayerJingle() { RecvPropBool(FIELD.OF(nameof(UseWeaponsInVehicle))), RecvPropDataTable("localdata", DT_LocalPlayerExclusive), - ]); public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BasePlayer); + ]); public static readonly new ClientClass ClientClass = new ClientClass(DT_BasePlayer); static C_BasePlayer? localPlayer; diff --git a/Game.Client/C_EnvTonemapController.cs b/Game.Client/C_EnvTonemapController.cs index 27d704773..4b147920b 100644 --- a/Game.Client/C_EnvTonemapController.cs +++ b/Game.Client/C_EnvTonemapController.cs @@ -18,7 +18,7 @@ public class C_EnvTonemapController : C_BaseEntity RecvPropFloat(FIELD.OF(nameof(CustomAutoExposureMax))), RecvPropFloat(FIELD.OF(nameof(CustomBloomScale))), RecvPropFloat(FIELD.OF(nameof(CustomBloomScaleMinimum))), - ]); public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_EnvTonemapController); + ]); public static readonly new ClientClass ClientClass = new ClientClass(DT_EnvTonemapController); [NetworkName("m_bUseCustomAutoExposureMin")] public bool UseCustomAutoExposureMin; diff --git a/Game.Client/C_PlayerResource.cs b/Game.Client/C_PlayerResource.cs index 3db3617d8..17e402762 100644 --- a/Game.Client/C_PlayerResource.cs +++ b/Game.Client/C_PlayerResource.cs @@ -29,7 +29,7 @@ public class C_PlayerResource : C_BaseEntity RecvPropArray3(FIELD.OF_ARRAY(nameof(Health)), RecvPropInt(FIELD.OF_ARRAYINDEX(nameof(Health), 0))), RecvPropArray3(FIELD.OF_ARRAY(nameof(Armor)), RecvPropInt(FIELD.OF_ARRAYINDEX(nameof(Armor)))), ]); - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_PlayerResource); + public static readonly new ClientClass ClientClass = new ClientClass(DT_PlayerResource); [NetworkName("m_iPing")] InlineArrayMaxPlayersPlusOne Ping = new(); diff --git a/Game.Client/C_Team.cs b/Game.Client/C_Team.cs index c0fd05aab..56d064c80 100644 --- a/Game.Client/C_Team.cs +++ b/Game.Client/C_Team.cs @@ -68,7 +68,7 @@ private static void RecvProxy_PlayerList(ref readonly RecvProxyData data, object team.Players[data.Element] = data.Value.Int; } - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_Team); + public static readonly new ClientClass ClientClass = new ClientClass(DT_Team); public readonly List Players = []; [NetworkName("m_szTeamname")] diff --git a/Game.Client/C_World.cs b/Game.Client/C_World.cs index 1214b5e46..f01d2910f 100644 --- a/Game.Client/C_World.cs +++ b/Game.Client/C_World.cs @@ -34,7 +34,7 @@ public C_World() : base() { RecvPropString(FIELD.OF(nameof(DetailSpriteMaterial))), ]); - public static new readonly ClientClass ClientClass = new ClientClass(null, null, DT_WORLD); + public static new readonly ClientClass ClientClass = new ClientClass(DT_WORLD); public override bool Init(int entNum, int serialNum) { WaveHeight = 0.0f; diff --git a/Game.Client/Game.Client.csproj b/Game.Client/Game.Client.csproj index 78929b603..1d5041ab2 100644 --- a/Game.Client/Game.Client.csproj +++ b/Game.Client/Game.Client.csproj @@ -38,6 +38,7 @@ + diff --git a/Game.Client/GarrysMod/C_GMOD_Player.cs b/Game.Client/GarrysMod/C_GMOD_Player.cs index 78a235cab..5b1d3b278 100644 --- a/Game.Client/GarrysMod/C_GMOD_Player.cs +++ b/Game.Client/GarrysMod/C_GMOD_Player.cs @@ -41,7 +41,7 @@ public partial class C_GMOD_Player() : C_HL2MP_Player() RecvPropFloat(FIELD.OF(nameof(Gravity))), RecvPropBool(FIELD.OF(nameof(SprintEnabled))), ]); - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_GMOD_Player); + public static readonly new ClientClass ClientClass = new ClientClass(DT_GMOD_Player); [NetworkName("m_iGModPlayerFlags")] public int GModPlayerFlags; diff --git a/Game.Client/HL2/C_BaseHLPlayer.cs b/Game.Client/HL2/C_BaseHLPlayer.cs index 9bb14fbd5..0b9d625ab 100644 --- a/Game.Client/HL2/C_BaseHLPlayer.cs +++ b/Game.Client/HL2/C_BaseHLPlayer.cs @@ -15,7 +15,7 @@ public partial class C_BaseHLPlayer : C_BasePlayer RecvPropDataTable("m_HL2Local", FIELD.OF(nameof(HL2Local)), C_HL2PlayerLocalData.DT_HL2Local, 0, DataTableRecvProxy_PointerDataTable), RecvPropBool(FIELD.OF(nameof(m_bIsSprinting))) ]); - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_HL2_Player); + public static readonly new ClientClass ClientClass = new ClientClass(DT_HL2_Player); public static readonly new DataMap PredMap = new(typeof(C_BaseHLPlayer), C_BasePlayer.PredMap, [ DEFINE.PRED_TYPEDESCRIPTION( nameof(HL2Local), C_HL2PlayerLocalData.PredMap ), diff --git a/Game.Client/HL2MP/C_HL2MP_Player.cs b/Game.Client/HL2MP/C_HL2MP_Player.cs index d6250d39a..2e1dbf8c3 100644 --- a/Game.Client/HL2MP/C_HL2MP_Player.cs +++ b/Game.Client/HL2MP/C_HL2MP_Player.cs @@ -48,7 +48,7 @@ public partial class C_HL2MP_Player : C_BaseHLPlayer RecvPropInt(FIELD.OF(nameof(SpawnInterpCounter))), RecvPropBool(FIELD.OF(nameof(IsWalking))) ]); - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_HL2MP_Player); + public static readonly new ClientClass ClientClass = new ClientClass(DT_HL2MP_Player); public readonly HL2MPPlayerAnimState PlayerAnimState; [NetworkName("m_angEyeAngles")] @@ -136,7 +136,7 @@ public class C_HL2MPRagdoll : C_BaseAnimatingOverlay RecvPropVector(FIELD_RD.OF(nameof(Force))), RecvPropVector(FIELD_RD.OF(nameof(RagdollVelocity))) ]); - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_HL2MPRagdoll); + public static readonly new ClientClass ClientClass = new ClientClass(DT_HL2MPRagdoll); [NetworkName("m_vecRagdollOrigin")] public Vector3 RagdollOrigin; diff --git a/Game.Server/Game.Server.csproj b/Game.Server/Game.Server.csproj index 42bbf67e0..50e77af85 100644 --- a/Game.Server/Game.Server.csproj +++ b/Game.Server/Game.Server.csproj @@ -17,6 +17,8 @@ OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> + diff --git a/Game.Shared/BaseDoor.cs b/Game.Shared/BaseDoor.cs index 7bbd53bdc..871a5e128 100644 --- a/Game.Shared/BaseDoor.cs +++ b/Game.Shared/BaseDoor.cs @@ -21,7 +21,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BaseDoor); + public static readonly new ClientClass ClientClass = new ClientClass(DT_BaseDoor); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_BaseDoor); #endif diff --git a/Game.Shared/BaseGrenade.cs b/Game.Shared/BaseGrenade.cs index 960421d57..27d542540 100644 --- a/Game.Shared/BaseGrenade.cs +++ b/Game.Shared/BaseGrenade.cs @@ -37,7 +37,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BaseGrenade); + public static readonly new ClientClass ClientClass = new ClientClass(DT_BaseGrenade); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_BaseGrenade); #endif diff --git a/Game.Shared/BaseToggle.cs b/Game.Shared/BaseToggle.cs index 10b6dcb52..c351116a2 100644 --- a/Game.Shared/BaseToggle.cs +++ b/Game.Shared/BaseToggle.cs @@ -27,7 +27,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BaseToggle); + public static readonly new ClientClass ClientClass = new ClientClass(DT_BaseToggle); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_BaseToggle); #endif diff --git a/Game.Shared/BaseViewModel.cs b/Game.Shared/BaseViewModel.cs index 1189fb866..3b92ef1b5 100644 --- a/Game.Shared/BaseViewModel.cs +++ b/Game.Shared/BaseViewModel.cs @@ -111,7 +111,7 @@ private static void RecvProxy_SequenceNum(ref readonly RecvProxyData data, objec model.SetCycle(0); } } - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BaseViewModel); + public static readonly new ClientClass ClientClass = new ClientClass(DT_BaseViewModel); #else #pragma warning disable CS0109 // Member does not hide an inherited member; new keyword is not required public static readonly new ServerClass ServerClass = new ServerClass(DT_BaseViewModel); diff --git a/Game.Shared/Beam.cs b/Game.Shared/Beam.cs index 4828d266d..ab344807d 100644 --- a/Game.Shared/Beam.cs +++ b/Game.Shared/Beam.cs @@ -141,7 +141,7 @@ private static void RecvProxy_Beam_ScrollSpeed(ref readonly RecvProxyData data, beam.Speed = val; } - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_Beam); + public static readonly new ClientClass ClientClass = new ClientClass(DT_Beam); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_Beam); #endif diff --git a/Game.Shared/FuncLadder.cs b/Game.Shared/FuncLadder.cs index 75ca492fb..4b0c721a5 100644 --- a/Game.Shared/FuncLadder.cs +++ b/Game.Shared/FuncLadder.cs @@ -53,7 +53,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_FuncLadder); + public static readonly new ClientClass ClientClass = new ClientClass(DT_FuncLadder); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_FuncLadder); #endif diff --git a/Game.Shared/GameRules.cs b/Game.Shared/GameRules.cs index 9660bd478..7a657a076 100644 --- a/Game.Shared/GameRules.cs +++ b/Game.Shared/GameRules.cs @@ -83,7 +83,7 @@ public static readonly #endif DT_GameRulesProxy = new([]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_GameRulesProxy); + public static readonly new ClientClass ClientClass = new ClientClass(DT_GameRulesProxy); #else #pragma warning disable CS0109 // Member does not hide an inherited member; new keyword is not required public static readonly new ServerClass ServerClass = new ServerClass(DT_GameRulesProxy); diff --git a/Game.Shared/GarrysMod/BaseHL2MPBludgeonWeapon.cs b/Game.Shared/GarrysMod/BaseHL2MPBludgeonWeapon.cs index 58265efb1..213b88de2 100644 --- a/Game.Shared/GarrysMod/BaseHL2MPBludgeonWeapon.cs +++ b/Game.Shared/GarrysMod/BaseHL2MPBludgeonWeapon.cs @@ -24,7 +24,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BaseHL2MPBludgeonWeapon); + public static readonly new ClientClass ClientClass = new ClientClass(DT_BaseHL2MPBludgeonWeapon); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_BaseHL2MPBludgeonWeapon); #endif diff --git a/Game.Shared/GarrysMod/GMODGameRules.cs b/Game.Shared/GarrysMod/GMODGameRules.cs index a6acd22f4..61c95d0ad 100644 --- a/Game.Shared/GarrysMod/GMODGameRules.cs +++ b/Game.Shared/GarrysMod/GMODGameRules.cs @@ -79,7 +79,7 @@ public static object SendProxy_GMODRules(SendProp prop, object instance, IFieldA ]); #endif #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_GMODGameRulesProxy); + public static readonly new ClientClass ClientClass = new ClientClass(DT_GMODGameRulesProxy); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_GMODGameRulesProxy); #endif diff --git a/Game.Shared/GarrysMod/HL2MPMachineGun.cs b/Game.Shared/GarrysMod/HL2MPMachineGun.cs index 961fe8f22..fca290556 100644 --- a/Game.Shared/GarrysMod/HL2MPMachineGun.cs +++ b/Game.Shared/GarrysMod/HL2MPMachineGun.cs @@ -23,7 +23,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_HL2MPMachineGun); + public static readonly new ClientClass ClientClass = new ClientClass(DT_HL2MPMachineGun); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_HL2MPMachineGun); #endif diff --git a/Game.Shared/GarrysMod/Weapon357.cs b/Game.Shared/GarrysMod/Weapon357.cs index 8f1865614..59d8638da 100644 --- a/Game.Shared/GarrysMod/Weapon357.cs +++ b/Game.Shared/GarrysMod/Weapon357.cs @@ -27,7 +27,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_Weapon357); + public static readonly new ClientClass ClientClass = new ClientClass(DT_Weapon357); public static readonly new DataMap PredMap = new([], typeof(Weapon357), BaseHL2MPCombatWeapon.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else public static readonly new ServerClass ServerClass = new ServerClass(DT_Weapon357); diff --git a/Game.Shared/GarrysMod/WeaponAR2.cs b/Game.Shared/GarrysMod/WeaponAR2.cs index 356d43c80..09169f94e 100644 --- a/Game.Shared/GarrysMod/WeaponAR2.cs +++ b/Game.Shared/GarrysMod/WeaponAR2.cs @@ -22,7 +22,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponAR2); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponAR2); public static readonly new DataMap PredMap = new([], typeof(WeaponAR2), HL2MPMachineGun.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponAR2); diff --git a/Game.Shared/GarrysMod/WeaponBugBait.cs b/Game.Shared/GarrysMod/WeaponBugBait.cs index 4f298b3f9..542034f34 100644 --- a/Game.Shared/GarrysMod/WeaponBugBait.cs +++ b/Game.Shared/GarrysMod/WeaponBugBait.cs @@ -24,7 +24,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponBugBait); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponBugBait); public static readonly new DataMap PredMap = new([], typeof(WeaponBugBait), BaseHL2MPCombatWeapon.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else diff --git a/Game.Shared/GarrysMod/WeaponCrossbow.cs b/Game.Shared/GarrysMod/WeaponCrossbow.cs index fb1bc6113..f22c5794f 100644 --- a/Game.Shared/GarrysMod/WeaponCrossbow.cs +++ b/Game.Shared/GarrysMod/WeaponCrossbow.cs @@ -36,7 +36,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponCrossbow); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponCrossbow); public static readonly new DataMap PredMap = new([], typeof(WeaponCrossbow), BaseHL2MPCombatWeapon.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponCrossbow); diff --git a/Game.Shared/GarrysMod/WeaponCrowbar.cs b/Game.Shared/GarrysMod/WeaponCrowbar.cs index 9ef0b2566..e31100ccf 100644 --- a/Game.Shared/GarrysMod/WeaponCrowbar.cs +++ b/Game.Shared/GarrysMod/WeaponCrowbar.cs @@ -31,7 +31,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponCrowbar); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponCrowbar); public static readonly new DataMap PredMap = new([], typeof(WeaponCrowbar), BaseHL2MPBludgeonWeapon.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else diff --git a/Game.Shared/GarrysMod/WeaponFrag.cs b/Game.Shared/GarrysMod/WeaponFrag.cs index 8fcdf0d69..7bf27e077 100644 --- a/Game.Shared/GarrysMod/WeaponFrag.cs +++ b/Game.Shared/GarrysMod/WeaponFrag.cs @@ -26,7 +26,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponFrag); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponFrag); public static readonly new DataMap PredMap = new([], typeof(WeaponFrag), BaseHL2MPCombatWeapon.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else diff --git a/Game.Shared/GarrysMod/WeaponPhysCannon.cs b/Game.Shared/GarrysMod/WeaponPhysCannon.cs index 5e11dc00a..56c6006b7 100644 --- a/Game.Shared/GarrysMod/WeaponPhysCannon.cs +++ b/Game.Shared/GarrysMod/WeaponPhysCannon.cs @@ -193,7 +193,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponPhysCannon); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponPhysCannon); public static readonly new DataMap PredMap = new([], typeof(WeaponPhysCannon), BaseHL2MPCombatWeapon.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else diff --git a/Game.Shared/GarrysMod/WeaponPistol.cs b/Game.Shared/GarrysMod/WeaponPistol.cs index 8cb2a8212..f063e5db4 100644 --- a/Game.Shared/GarrysMod/WeaponPistol.cs +++ b/Game.Shared/GarrysMod/WeaponPistol.cs @@ -30,7 +30,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponPistol); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponPistol); public static readonly new DataMap PredMap = new([], typeof(WeaponPistol), HL2MPMachineGun.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponPistol); diff --git a/Game.Shared/GarrysMod/WeaponRPG.cs b/Game.Shared/GarrysMod/WeaponRPG.cs index 9087c3814..36a3460f3 100644 --- a/Game.Shared/GarrysMod/WeaponRPG.cs +++ b/Game.Shared/GarrysMod/WeaponRPG.cs @@ -34,7 +34,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponRPG); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponRPG); public static readonly new DataMap PredMap = new([], typeof(WeaponRPG), BaseHL2MPCombatWeapon.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponRPG); @@ -67,7 +67,7 @@ public static readonly #endif DT_LaserDot = new(DT_BaseEntity, []); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_LaserDot); + public static readonly new ClientClass ClientClass = new ClientClass(DT_LaserDot); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_LaserDot); #endif diff --git a/Game.Shared/GarrysMod/WeaponSLAM.cs b/Game.Shared/GarrysMod/WeaponSLAM.cs index 4b9f07436..6433a81c8 100644 --- a/Game.Shared/GarrysMod/WeaponSLAM.cs +++ b/Game.Shared/GarrysMod/WeaponSLAM.cs @@ -38,7 +38,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_Weapon_SLAM); + public static readonly new ClientClass ClientClass = new ClientClass(DT_Weapon_SLAM); public static readonly new DataMap PredMap = new([], typeof(WeaponSLAM), BaseHL2MPCombatWeapon.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else public static readonly new ServerClass ServerClass = new ServerClass(DT_Weapon_SLAM); diff --git a/Game.Shared/GarrysMod/WeaponSMG1.cs b/Game.Shared/GarrysMod/WeaponSMG1.cs index 64e30817c..0eaff1027 100644 --- a/Game.Shared/GarrysMod/WeaponSMG1.cs +++ b/Game.Shared/GarrysMod/WeaponSMG1.cs @@ -23,7 +23,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponSMG1); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponSMG1); public static readonly new DataMap PredMap = new([], typeof(WeaponSMG1), HL2MPMachineGun.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponSMG1); diff --git a/Game.Shared/GarrysMod/WeaponShotgun.cs b/Game.Shared/GarrysMod/WeaponShotgun.cs index 841b9cc5a..006120f64 100644 --- a/Game.Shared/GarrysMod/WeaponShotgun.cs +++ b/Game.Shared/GarrysMod/WeaponShotgun.cs @@ -32,7 +32,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponShotgun); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponShotgun); public static readonly new DataMap PredMap = new([], typeof(WeaponShotgun), BaseHL2MPCombatWeapon.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponShotgun); diff --git a/Game.Shared/GarrysMod/WeaponStunStick.cs b/Game.Shared/GarrysMod/WeaponStunStick.cs index 33d436ac1..c41d68b72 100644 --- a/Game.Shared/GarrysMod/WeaponStunStick.cs +++ b/Game.Shared/GarrysMod/WeaponStunStick.cs @@ -29,7 +29,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponStunStick); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponStunStick); public static readonly new DataMap PredMap = new([], typeof(WeaponStunStick), BaseHL2MPBludgeonWeapon.PredMap); public override DataMap? GetPredDescMap() => PredMap; #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponStunStick); diff --git a/Game.Shared/HL1/Weapon357_HL1.cs b/Game.Shared/HL1/Weapon357_HL1.cs index 4f96e49b8..19fc9b7fe 100644 --- a/Game.Shared/HL1/Weapon357_HL1.cs +++ b/Game.Shared/HL1/Weapon357_HL1.cs @@ -20,7 +20,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_Weapon357_HL1); + public static readonly new ClientClass ClientClass = new ClientClass(DT_Weapon357_HL1); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_Weapon357_HL1); #endif diff --git a/Game.Shared/HL1/WeaponCrossbow_HL1.cs b/Game.Shared/HL1/WeaponCrossbow_HL1.cs index de1f91566..d92ec1782 100644 --- a/Game.Shared/HL1/WeaponCrossbow_HL1.cs +++ b/Game.Shared/HL1/WeaponCrossbow_HL1.cs @@ -20,7 +20,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponCrossbow_HL1); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponCrossbow_HL1); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponCrossbow_HL1); #endif diff --git a/Game.Shared/HL1/WeaponCrowbar_HL1.cs b/Game.Shared/HL1/WeaponCrowbar_HL1.cs index 5fca0d7a2..4f896ee42 100644 --- a/Game.Shared/HL1/WeaponCrowbar_HL1.cs +++ b/Game.Shared/HL1/WeaponCrowbar_HL1.cs @@ -14,7 +14,7 @@ public static readonly #endif DT_WeaponCrowbar_HL1 = new(DT_BaseHL1MPCombatWeapon, []); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponCrowbar_HL1); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponCrowbar_HL1); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponCrowbar_HL1); #endif diff --git a/Game.Shared/HL1/WeaponEgon.cs b/Game.Shared/HL1/WeaponEgon.cs index 2f6360114..cc0e69424 100644 --- a/Game.Shared/HL1/WeaponEgon.cs +++ b/Game.Shared/HL1/WeaponEgon.cs @@ -14,7 +14,7 @@ public static readonly #endif DT_WeaponEgon = new(DT_BaseHL1MPCombatWeapon, []); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponEgon); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponEgon); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponEgon); #endif diff --git a/Game.Shared/HL1/WeaponGauss.cs b/Game.Shared/HL1/WeaponGauss.cs index 3147368d2..5b273deb0 100644 --- a/Game.Shared/HL1/WeaponGauss.cs +++ b/Game.Shared/HL1/WeaponGauss.cs @@ -30,7 +30,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponGauss); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponGauss); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponGauss); #endif diff --git a/Game.Shared/HL1/WeaponGlock.cs b/Game.Shared/HL1/WeaponGlock.cs index 7e4b0a51d..0a4abc55e 100644 --- a/Game.Shared/HL1/WeaponGlock.cs +++ b/Game.Shared/HL1/WeaponGlock.cs @@ -14,7 +14,7 @@ public static readonly #endif DT_WeaponGlock = new(DT_BaseHL1MPCombatWeapon, []); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponGlock); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponGlock); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponGlock); #endif diff --git a/Game.Shared/HL1/WeaponHandGrenade.cs b/Game.Shared/HL1/WeaponHandGrenade.cs index 2514b35b7..95c8ebe63 100644 --- a/Game.Shared/HL1/WeaponHandGrenade.cs +++ b/Game.Shared/HL1/WeaponHandGrenade.cs @@ -22,7 +22,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponHandGrenade); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponHandGrenade); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponHandGrenade); #endif diff --git a/Game.Shared/HL1/WeaponHgun.cs b/Game.Shared/HL1/WeaponHgun.cs index 65308e7ea..5fa20af48 100644 --- a/Game.Shared/HL1/WeaponHgun.cs +++ b/Game.Shared/HL1/WeaponHgun.cs @@ -22,7 +22,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponHgun); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponHgun); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponHgun); #endif diff --git a/Game.Shared/HL1/WeaponMP5.cs b/Game.Shared/HL1/WeaponMP5.cs index c4d5d3205..6939f7d89 100644 --- a/Game.Shared/HL1/WeaponMP5.cs +++ b/Game.Shared/HL1/WeaponMP5.cs @@ -14,7 +14,7 @@ public static readonly #endif DT_WeaponMP5 = new(DT_BaseHL1MPCombatWeapon, []); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponMP5); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponMP5); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponMP5); #endif diff --git a/Game.Shared/HL1/WeaponRPG_HL1.cs b/Game.Shared/HL1/WeaponRPG_HL1.cs index 363f97825..3385e6c4b 100644 --- a/Game.Shared/HL1/WeaponRPG_HL1.cs +++ b/Game.Shared/HL1/WeaponRPG_HL1.cs @@ -27,7 +27,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponRPG_HL1); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponRPG_HL1); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponRPG_HL1); #endif @@ -59,7 +59,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_LaserDot_HL1); + public static readonly new ClientClass ClientClass = new ClientClass(DT_LaserDot_HL1); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_LaserDot_HL1); #endif diff --git a/Game.Shared/HL1/WeaponSatchel.cs b/Game.Shared/HL1/WeaponSatchel.cs index be862f04d..b4319e92a 100644 --- a/Game.Shared/HL1/WeaponSatchel.cs +++ b/Game.Shared/HL1/WeaponSatchel.cs @@ -28,7 +28,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponSatchel); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponSatchel); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponSatchel); #endif diff --git a/Game.Shared/HL1/WeaponShotgun_HL1.cs b/Game.Shared/HL1/WeaponShotgun_HL1.cs index 60ebc7e59..a9d751ebe 100644 --- a/Game.Shared/HL1/WeaponShotgun_HL1.cs +++ b/Game.Shared/HL1/WeaponShotgun_HL1.cs @@ -22,7 +22,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponShotgun_HL1); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponShotgun_HL1); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponShotgun_HL1); #endif diff --git a/Game.Shared/HL1/WeaponSnark.cs b/Game.Shared/HL1/WeaponSnark.cs index 7b7f2984a..9f3c0e1c9 100644 --- a/Game.Shared/HL1/WeaponSnark.cs +++ b/Game.Shared/HL1/WeaponSnark.cs @@ -20,7 +20,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponSnark); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponSnark); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponSnark); #endif diff --git a/Game.Shared/HL1/WeaponTripMine.cs b/Game.Shared/HL1/WeaponTripMine.cs index a83e2a891..c87826596 100644 --- a/Game.Shared/HL1/WeaponTripMine.cs +++ b/Game.Shared/HL1/WeaponTripMine.cs @@ -22,7 +22,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_WeaponTripMine); + public static readonly new ClientClass ClientClass = new ClientClass(DT_WeaponTripMine); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_WeaponTripMine); #endif diff --git a/Game.Shared/HL2/BaseHLCombatWeapon.cs b/Game.Shared/HL2/BaseHLCombatWeapon.cs index 87976b5da..cbfae10c3 100644 --- a/Game.Shared/HL2/BaseHLCombatWeapon.cs +++ b/Game.Shared/HL2/BaseHLCombatWeapon.cs @@ -30,7 +30,7 @@ public static readonly #endif DT_BaseHLCombatWeapon = new(DT_BaseCombatWeapon, []); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_BaseHLCombatWeapon); + public static readonly new ClientClass ClientClass = new ClientClass(DT_BaseHLCombatWeapon); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_BaseHLCombatWeapon); #endif diff --git a/Game.Shared/HL2MP/HL2MPGameRules.cs b/Game.Shared/HL2MP/HL2MPGameRules.cs index dd57cc115..0750ee653 100644 --- a/Game.Shared/HL2MP/HL2MPGameRules.cs +++ b/Game.Shared/HL2MP/HL2MPGameRules.cs @@ -69,7 +69,7 @@ public static object SendProxy_HL2MPRules(SendProp prop, object instance, IField } #endif #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_HL2MPGameRulesProxy); + public static readonly new ClientClass ClientClass = new ClientClass(DT_HL2MPGameRulesProxy); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_HL2MPGameRulesProxy); #endif diff --git a/Game.Shared/PredictedViewModel.cs b/Game.Shared/PredictedViewModel.cs index 176d8ffc7..6f1988c08 100644 --- a/Game.Shared/PredictedViewModel.cs +++ b/Game.Shared/PredictedViewModel.cs @@ -29,7 +29,7 @@ public static readonly #endif DT_PredictedViewModel = new(DT_BaseViewModel, []); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_PredictedViewModel); + public static readonly new ClientClass ClientClass = new ClientClass(DT_PredictedViewModel); #else #pragma warning disable CS0109 // Member does not hide an inherited member; new keyword is not required public static readonly new ServerClass ServerClass = new ServerClass(DT_PredictedViewModel); diff --git a/Game.Shared/Sprite.cs b/Game.Shared/Sprite.cs index e801ea9c0..b36c36322 100644 --- a/Game.Shared/Sprite.cs +++ b/Game.Shared/Sprite.cs @@ -47,7 +47,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_Sprite); + public static readonly new ClientClass ClientClass = new ClientClass(DT_Sprite); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_Sprite); #endif @@ -92,7 +92,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_SpriteOriented); + public static readonly new ClientClass ClientClass = new ClientClass(DT_SpriteOriented); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_SpriteOriented); #endif diff --git a/Game.Shared/SpriteTrail.cs b/Game.Shared/SpriteTrail.cs index 47df9727b..ec5deed36 100644 --- a/Game.Shared/SpriteTrail.cs +++ b/Game.Shared/SpriteTrail.cs @@ -36,7 +36,7 @@ public static readonly #endif ]); #if CLIENT_DLL - public static readonly new ClientClass ClientClass = new ClientClass(null, null, DT_SpriteTrail); + public static readonly new ClientClass ClientClass = new ClientClass(DT_SpriteTrail); #else public static readonly new ServerClass ServerClass = new ServerClass(DT_SpriteTrail); #endif diff --git a/Source.CodeAnalysis.NetworkClasses/NetworkClassRegistrationGenerator.cs b/Source.CodeAnalysis.NetworkClasses/NetworkClassRegistrationGenerator.cs new file mode 100644 index 000000000..a204cf566 --- /dev/null +++ b/Source.CodeAnalysis.NetworkClasses/NetworkClassRegistrationGenerator.cs @@ -0,0 +1,239 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Text; +using System.Threading; + +namespace Source.CodeAnalysis.NetworkClasses +{ + [Generator(LanguageNames.CSharp)] + public sealed class NetworkClassRegistrationGenerator : IIncrementalGenerator + { + const string ClientClassName = "Source.Common.ClientClass"; + const string ServerClassName = "Source.Common.ServerClass"; + const string NetworkNameAttributeName = "Source.Common.NetworkNameAttribute"; + const string FactoryAttributeName = "Source.Common.ImplementClientClassFactoryAttribute"; + const string ClientEntityName = "Source.Common.IClientEntity"; + + static readonly DiagnosticDescriptor DuplicateSite = new DiagnosticDescriptor( + "SDNNC001", "Duplicate network class site", + "Network class sites in {0} and {1} share the key {2}:{3}", + "NetworkClasses", DiagnosticSeverity.Error, true); + + static readonly DiagnosticDescriptor InaccessibleType = new DiagnosticDescriptor( + "SDNNC002", "Inaccessible network class type", + "{0} declares a network class but is not accessible from generated code", + "NetworkClasses", DiagnosticSeverity.Error, true); + + public void Initialize(IncrementalGeneratorInitializationContext context) { + IncrementalValuesProvider sites = context.SyntaxProvider.CreateSyntaxProvider( + static (node, _) => IsCandidate(node), + static (ctx, ct) => Transform(ctx, ct)) + .Where(static site => site != null) + .Select(static (site, _) => site!); + + context.RegisterSourceOutput(sites.Collect(), static (spc, items) => Emit(spc, items)); + } + + sealed class Site : System.IEquatable + { + public bool IsClient; + public string File = ""; + public int Line; + public string TypeName = ""; + public string FullyQualified = ""; + public string? NetworkName; + public string? Factory; + public bool Accessible; + + public bool Equals(Site? other) => other != null && IsClient == other.IsClient && File == other.File && Line == other.Line + && TypeName == other.TypeName && FullyQualified == other.FullyQualified && NetworkName == other.NetworkName + && Factory == other.Factory && Accessible == other.Accessible; + + public override bool Equals(object? obj) => Equals(obj as Site); + + public override int GetHashCode() => (FullyQualified.GetHashCode() * 397) ^ Line; + } + + static bool IsCandidate(SyntaxNode node) { + if (node is ImplicitObjectCreationExpressionSyntax) + return true; + + if (node is not ObjectCreationExpressionSyntax creation) + return false; + + string name = creation.Type switch { + IdentifierNameSyntax identifier => identifier.Identifier.ValueText, + QualifiedNameSyntax qualified => qualified.Right.Identifier.ValueText, + AliasQualifiedNameSyntax alias => alias.Name.Identifier.ValueText, + _ => "" + }; + + return IsNetworkClassName(name) || IsNetworkClassAlias(creation, name); + } + + static bool IsNetworkClassName(string name) => name == "ClientClass" || name == "ServerClass"; + + static bool IsNetworkClassAlias(SyntaxNode node, string name) { + if (name.Length == 0) + return false; + + foreach (SyntaxNode ancestor in node.Ancestors()) { + SyntaxList usings = ancestor switch { + CompilationUnitSyntax unit => unit.Usings, + BaseNamespaceDeclarationSyntax ns => ns.Usings, + _ => default + }; + + foreach (UsingDirectiveSyntax directive in usings) { + if (directive.Alias?.Name.Identifier.ValueText != name || directive.Name == null) + continue; + + string target = directive.Name switch { + QualifiedNameSyntax qualified => qualified.Right.Identifier.ValueText, + IdentifierNameSyntax identifier => identifier.Identifier.ValueText, + AliasQualifiedNameSyntax alias => alias.Name.Identifier.ValueText, + _ => "" + }; + return IsNetworkClassName(target); + } + } + return false; + } + + static string FileName(string path) { + int slash = path.LastIndexOfAny(new[] { '/', '\\' }); + return slash == -1 ? path : path.Substring(slash + 1); + } + + static Site? Transform(GeneratorSyntaxContext ctx, CancellationToken ct) { + BaseObjectCreationExpressionSyntax creation = (BaseObjectCreationExpressionSyntax)ctx.Node; + if (ctx.SemanticModel.GetSymbolInfo(creation, ct).Symbol is not IMethodSymbol constructor) + return null; + + string kind = constructor.ContainingType.ToDisplayString(); + bool isClient = kind == ClientClassName; + if (!isClient && kind != ServerClassName) + return null; + + ISymbol? enclosing = ctx.SemanticModel.GetEnclosingSymbol(creation.SpanStart, ct); + INamedTypeSymbol? owner = enclosing as INamedTypeSymbol ?? enclosing?.ContainingType; + if (owner == null) + return null; + + Compilation compilation = ctx.SemanticModel.Compilation; + + return new Site { + IsClient = isClient, + File = FileName(creation.SyntaxTree.FilePath), + Line = creation.GetLocation().GetLineSpan().StartLinePosition.Line + 1, + TypeName = owner.Name, + FullyQualified = owner.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat), + NetworkName = GetNetworkName(owner), + Factory = isClient ? GetFactory(owner) : null, + Accessible = compilation.IsSymbolAccessibleWithin(owner, compilation.Assembly), + }; + } + + static string? GetNetworkName(INamedTypeSymbol owner) { + foreach (AttributeData attribute in owner.GetAttributes()) { + if (attribute.AttributeClass?.ToDisplayString() == NetworkNameAttributeName && attribute.ConstructorArguments.Length == 1) + return attribute.ConstructorArguments[0].Value as string; + } + return null; + } + + static string? GetFactory(INamedTypeSymbol owner) { + string fullyQualified = owner.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + + foreach (IMethodSymbol method in owner.GetMembers().OfType()) { + if (method.IsStatic && method.GetAttributes().Any(a => a.AttributeClass?.ToDisplayString() == FactoryAttributeName)) + return $"{fullyQualified}.{method.Name}"; + } + + if (owner.IsAbstract || owner.IsGenericType) + return null; + + if (!owner.AllInterfaces.Any(i => i.ToDisplayString() == ClientEntityName)) + return null; + + if (!owner.InstanceConstructors.Any(c => c.DeclaredAccessibility == Accessibility.Public && c.Parameters.Length == 0)) + return null; + + if (!HasInit(owner)) + return null; + + return $"static (entNum, serialNum) => {{ {fullyQualified} entity = new {fullyQualified}(); return entity.Init(entNum, serialNum) ? entity : null!; }}"; + } + + static bool HasInit(INamedTypeSymbol owner) { + for (INamedTypeSymbol? type = owner; type != null; type = type.BaseType) { + foreach (IMethodSymbol method in type.GetMembers("Init").OfType()) { + if (!method.IsStatic && method.DeclaredAccessibility == Accessibility.Public + && method.ReturnType.SpecialType == SpecialType.System_Boolean && method.Parameters.Length == 2 + && method.Parameters[0].Type.SpecialType == SpecialType.System_Int32 + && method.Parameters[1].Type.SpecialType == SpecialType.System_Int32) + return true; + } + } + return false; + } + + static string Literal(string? value) => value == null ? "null" : SymbolDisplay.FormatLiteral(value, true); + + static void Emit(SourceProductionContext spc, ImmutableArray items) { + if (items.IsEmpty) + return; + + List sorted = items.OrderBy(s => s.IsClient ? 0 : 1).ThenBy(s => s.File, System.StringComparer.Ordinal).ThenBy(s => s.Line).ToList(); + + bool failed = false; + Dictionary<(bool, string, int), Site> seen = new Dictionary<(bool, string, int), Site>(); + foreach (Site site in sorted) { + if (!site.Accessible) { + spc.ReportDiagnostic(Diagnostic.Create(InaccessibleType, Location.None, site.FullyQualified)); + failed = true; + } + + if (seen.TryGetValue((site.IsClient, site.File, site.Line), out Site? existing)) { + spc.ReportDiagnostic(Diagnostic.Create(DuplicateSite, Location.None, existing.FullyQualified, site.FullyQualified, site.File, site.Line)); + failed = true; + } + else + seen.Add((site.IsClient, site.File, site.Line), site); + } + + if (failed) + return; + + StringBuilder sb = new StringBuilder(); + sb.AppendLine("// "); + sb.AppendLine("#nullable enable"); + sb.AppendLine("#pragma warning disable CA2255"); + sb.AppendLine("namespace Source.Generated"); + sb.AppendLine("{"); + sb.AppendLine("\tinternal static class NetworkClassRegistration"); + sb.AppendLine("\t{"); + sb.AppendLine("\t\t[global::System.Runtime.CompilerServices.ModuleInitializer]"); + sb.AppendLine("\t\tinternal static void Register()"); + sb.AppendLine("\t\t{"); + + foreach (Site site in sorted) { + if (site.IsClient) + sb.Append($"\t\t\tglobal::Source.Common.ClientClass.RegisterSite({Literal(site.File)}, {site.Line}, {Literal(site.TypeName)}, {Literal(site.NetworkName)}, {site.Factory ?? "null"});\n"); + else + sb.Append($"\t\t\tglobal::Source.Common.ServerClass.RegisterSite({Literal(site.File)}, {site.Line}, {Literal(site.TypeName)}, {Literal(site.NetworkName)});\n"); + } + + sb.AppendLine("\t\t}"); + sb.AppendLine("\t}"); + sb.AppendLine("}"); + + spc.AddSource("NetworkClassRegistration.g.cs", sb.ToString()); + } + } +} diff --git a/Source.CodeAnalysis.NetworkClasses/Source.CodeAnalysis.NetworkClasses.csproj b/Source.CodeAnalysis.NetworkClasses/Source.CodeAnalysis.NetworkClasses.csproj new file mode 100644 index 000000000..5fe2175b2 --- /dev/null +++ b/Source.CodeAnalysis.NetworkClasses/Source.CodeAnalysis.NetworkClasses.csproj @@ -0,0 +1,19 @@ + + + + netstandard2.0 + false + true + true + latest + enable + false + Debug;Release;Debug (Dedicated);Release (Dedicated) + + + + + + + + diff --git a/Source.Common/ClientClass.cs b/Source.Common/ClientClass.cs index 9ad2c1ae7..692c7273d 100644 --- a/Source.Common/ClientClass.cs +++ b/Source.Common/ClientClass.cs @@ -1,6 +1,4 @@ -using System.Diagnostics.CodeAnalysis; -using System.Reflection; -using System.Reflection.Emit; +using System.Reflection; using System.Runtime.CompilerServices; namespace Source.Common; @@ -41,73 +39,29 @@ public class ClientClass public ClientClass? Next; public int ClassID; - void AssembleDynamicCreateFn(Type t, [NotNull] ref CreateClientClassFn? createFn) { - if (t.IsAssignableTo(typeof(IClientEntity))) { - // Lets see if there's a good ImplementClientClassFactoryAttribute method... - var factoryMethod = t.GetMethodsWithAttribute().FirstOrDefault().Key; - if (factoryMethod != null) { - createFn = factoryMethod.CreateDelegate(); - return; - } + readonly record struct Site(string TypeName, string? NetworkName, CreateClientClassFn? CreateFn); + static readonly Dictionary<(string File, int Line), Site> Sites = []; - DynamicMethod method = new DynamicMethod($"CreateObjectDynImpl_{t.Name}", typeof(IClientNetworkable), [typeof(int), typeof(int)]); - ILGenerator il = method.GetILGenerator(); + public static void RegisterSite(string file, int line, string typeName, string? networkName, CreateClientClassFn? createFn) => Sites[(file, line)] = new(typeName, networkName, createFn); - LocalBuilder ret = il.DeclareLocal(t); - LocalBuilder success = il.DeclareLocal(typeof(bool)); - - Label returnNull = il.DefineLabel(); - Label returnObj = il.DefineLabel(); - - il.Emit(OpCodes.Newobj, t.GetConstructor(Type.EmptyTypes)!); - il.Emit(OpCodes.Stloc, ret); - - il.Emit(OpCodes.Ldloc, ret); - il.Emit(OpCodes.Ldarg_0); // entNum - il.Emit(OpCodes.Ldarg_1); // serialNum - il.Emit(OpCodes.Callvirt, t.GetMethod("Init", new[] { typeof(int), typeof(int) })!); - il.Emit(OpCodes.Stloc, success); - - il.Emit(OpCodes.Ldloc, success); - il.Emit(OpCodes.Brfalse_S, returnNull); - - il.Emit(OpCodes.Ldloc, ret); - il.Emit(OpCodes.Br_S, returnObj); - - il.MarkLabel(returnNull); - il.Emit(OpCodes.Ldnull); - - il.MarkLabel(returnObj); - il.Emit(OpCodes.Ret); - - createFn = method.CreateDelegate(); - } - else - createFn = (_, _) => throw new NotImplementedException($"ClientClass did not define how to create type '{t.Name}'"); + static Site TakeSite(string callerFile, int callerLine) { + if (!Sites.Remove((NetworkClassSite.FileName(callerFile), callerLine), out Site site)) + throw new NullReferenceException($"No generated ClientClass registration for {callerFile}:{callerLine}"); + return site; } - public ClientClass(RecvTable recvTable, [CallerArgumentExpression(nameof(recvTable))] string? nameOfTable = null) { - Type t = WhoCalledMe(skipFrames: 2) ?? throw new NullReferenceException("This doesnt work as well as we hoped!"); - AssembleDynamicCreateFn(t, ref CreateFn); + static CreateClientClassFn GetCreateFn(in Site site) { + string typeName = site.TypeName; + return site.CreateFn ?? ((_, _) => throw new NotImplementedException($"ClientClass did not define how to create type '{typeName}'")); + } - NetworkName = NetworkNameAttribute.Get(t); - RecvTable = recvTable; + static string GetNetworkName(in Site site) => site.NetworkName ?? throw new NullReferenceException($"{site.TypeName} is missing a {nameof(NetworkNameAttribute)}"); - if (nameOfTable != null) - recvTable.NetTableName = nameOfTable; + public ClientClass(RecvTable recvTable, [CallerArgumentExpression(nameof(recvTable))] string? nameOfTable = null, [CallerFilePath] string callerFile = "", [CallerLineNumber] int callerLine = 0) { + Site site = TakeSite(callerFile, callerLine); + CreateFn = GetCreateFn(in site); - Next = Head; - Head = this; - ClassID = -1; - } - public ClientClass(CreateClientClassFn? createFn, CreateEventFn? createEventFn, RecvTable recvTable, [CallerArgumentExpression(nameof(recvTable))] string? nameOfTable = null) { - Type t = WhoCalledMe(skipFrames: 2) ?? throw new NullReferenceException("This doesnt work as well as we hoped!"); - if (createFn == null) - AssembleDynamicCreateFn(t, ref createFn); - - CreateFn = createFn; - CreateEventFn = createEventFn; - NetworkName = NetworkNameAttribute.Get(t); + NetworkName = GetNetworkName(in site); RecvTable = recvTable; if (nameOfTable != null) diff --git a/Source.Common/Exts.cs b/Source.Common/Exts.cs index 0cd88f9c2..e8ed40f1f 100644 --- a/Source.Common/Exts.cs +++ b/Source.Common/Exts.cs @@ -1444,21 +1444,6 @@ public static string[] GeneratePaddedStrings(int min, int max) { } return arr; } - /// - /// Try to get the type that called this method, taking account of skip frames if necessary - /// - /// - /// - public static Type? WhoCalledMe(int skipFrames = 1) { - var stack = new StackTrace(skipFrames: skipFrames, fNeedFileInfo: false); - for (int i = 0; i < stack.FrameCount; i++) { - var method = stack.GetFrame(i)!.GetMethod()!; - var declaringType = method.DeclaringType; - if (declaringType != null && declaringType != typeof(GlobalReflectionUtils)) - return declaringType; - } - return null; - } } public static class ReflectionUtils { @@ -1595,13 +1580,6 @@ public static IEnumerable> GetFieldsWithAttribute( yield return new(field, attr); } } - public static IEnumerable> GetMethodsWithAttribute(this Type type) where T : Attribute { - foreach (var method in type.GetMethods()) { - T? attr = type.GetCustomAttribute(); - if (attr != null) - yield return new(method, attr); - } - } } /// diff --git a/Source.Common/ServerClass.cs b/Source.Common/ServerClass.cs index 353c9c8d0..9e6aa9940 100644 --- a/Source.Common/ServerClass.cs +++ b/Source.Common/ServerClass.cs @@ -26,21 +26,35 @@ public static ServerClass GetOrError(Type t) { public class NetworkNameAttribute(string name) : Attribute { public readonly string Name = name; +} - public static string Get(Type t) => t.GetCustomAttribute(false)?.Name ?? throw new NullReferenceException($"{t.Name} is missing a {nameof(NetworkNameAttribute)}"); +static class NetworkClassSite +{ + public static string FileName(string path) => path[(path.LastIndexOfAny(['/', '\\']) + 1)..]; } public class ServerClass { public static ServerClass? Head; + readonly record struct Site(string TypeName, string? NetworkName); + static readonly Dictionary<(string File, int Line), Site> Sites = []; + + public static void RegisterSite(string file, int line, string typeName, string? networkName) => Sites[(file, line)] = new(typeName, networkName); + + static string TakeNetworkName(string callerFile, int callerLine) { + if (!Sites.Remove((NetworkClassSite.FileName(callerFile), callerLine), out Site site)) + throw new NullReferenceException($"No generated ServerClass registration for {callerFile}:{callerLine}"); + return site.NetworkName ?? throw new NullReferenceException($"{site.TypeName} is missing a {nameof(NetworkNameAttribute)}"); + } + public string NetworkName; public SendTable Table; public ServerClass? Next; public int ClassID; public int InstanceBaselineIndex = INetworkStringTable.INVALID_STRING_INDEX; - public ServerClass(SendTable table, [CallerArgumentExpression(nameof(table))] string? nameOfTable = null) { - NetworkName = NetworkNameAttribute.Get(WhoCalledMe(skipFrames: 2) ?? throw new NullReferenceException("This doesnt work as well as we hoped!")); + public ServerClass(SendTable table, [CallerArgumentExpression(nameof(table))] string? nameOfTable = null, [CallerFilePath] string callerFile = "", [CallerLineNumber] int callerLine = 0) { + NetworkName = TakeNetworkName(callerFile, callerLine); Table = table; if (nameOfTable != null) table.NetTableName = nameOfTable; diff --git a/Source.NET.slnx b/Source.NET.slnx index 3b030d3ed..c1712cfeb 100644 --- a/Source.NET.slnx +++ b/Source.NET.slnx @@ -28,6 +28,9 @@ + + +