diff --git a/Core/Bootstrap.cs b/Core/Bootstrap.cs index 3806293..df6e54d 100644 --- a/Core/Bootstrap.cs +++ b/Core/Bootstrap.cs @@ -18,6 +18,7 @@ namespace LeagueSharp.SDK { using System.Globalization; + using System.Runtime.CompilerServices; using System.Security.Permissions; using System.Threading; @@ -72,7 +73,7 @@ public static void Init(string[] args) Logging.Write()(LogLevel.Info, "[SDK Bootstrap] Resources Initialized."); // Load GameObjects. - GameObjects.Initialize(); + RuntimeHelpers.RunClassConstructor(typeof(GameObjects).TypeHandle); Logging.Write()(LogLevel.Info, "[SDK Bootstrap] GameObjects Initialized."); // Create L# menu diff --git a/Core/GameObjects.cs b/Core/GameObjects.cs index f939fa4..e9b7e45 100644 --- a/Core/GameObjects.cs +++ b/Core/GameObjects.cs @@ -163,8 +163,7 @@ public static class GameObjects /// /// The general particle emitters list. /// - private static readonly List ParticleEmittersList = - new List(); + private static readonly List ParticleEmittersList = new List(); /// /// The shops list. @@ -186,11 +185,6 @@ public static class GameObjects /// private static readonly List WardsList = new List(); - /// - /// Indicates whether the stack was initialized and saved required instances. - /// - private static bool initialized; - #endregion #region Constructors and Destructors @@ -200,7 +194,61 @@ public static class GameObjects /// static GameObjects() { - Initialize(); + Events.OnLoad += (sender, args) => + { + Player = ObjectManager.Player; + + HeroesList.AddRange(ObjectManager.Get()); + MinionsList.AddRange( + ObjectManager.Get() + .Where( + o => o.Team != GameObjectTeam.Neutral && !o.GetMinionType().HasFlag(MinionTypes.Ward))); + TurretsList.AddRange(ObjectManager.Get()); + InhibitorsList.AddRange(ObjectManager.Get()); + JungleList.AddRange( + ObjectManager.Get() + .Where(o => o.Team == GameObjectTeam.Neutral && o.Name != "WardCorpse")); + WardsList.AddRange( + ObjectManager.Get().Where(o => o.GetMinionType().HasFlag(MinionTypes.Ward))); + ShopsList.AddRange(ObjectManager.Get()); + SpawnPointsList.AddRange(ObjectManager.Get()); + GameObjectsList.AddRange(ObjectManager.Get()); + NexusList.AddRange(ObjectManager.Get()); + AttackableUnitsList.AddRange(ObjectManager.Get()); + ParticleEmittersList.AddRange(ObjectManager.Get()); + + EnemyHeroesList.AddRange(HeroesList.Where(o => o.IsEnemy)); + EnemyMinionsList.AddRange(MinionsList.Where(o => o.IsEnemy)); + EnemyTurretsList.AddRange(TurretsList.Where(o => o.IsEnemy)); + EnemyInhibitorsList.AddRange(InhibitorsList.Where(o => o.IsEnemy)); + EnemyList.AddRange( + EnemyHeroesList.Cast().Concat(EnemyMinionsList).Concat(EnemyTurretsList)); + EnemyNexus = NexusList.SingleOrDefault(n => n.IsEnemy); + + AllyHeroesList.AddRange(HeroesList.Where(o => o.IsAlly)); + AllyMinionsList.AddRange(MinionsList.Where(o => o.IsAlly)); + AllyTurretsList.AddRange(TurretsList.Where(o => o.IsAlly)); + AllyInhibitorsList.AddRange(InhibitorsList.Where(o => o.IsAlly)); + AllyList.AddRange( + AllyHeroesList.Cast().Concat(AllyMinionsList).Concat(AllyTurretsList)); + AllyNexus = NexusList.SingleOrDefault(n => n.IsAlly); + + JungleSmallList.AddRange(JungleList.Where(o => o.GetJungleType() == JungleType.Small)); + JungleLargeList.AddRange(JungleList.Where(o => o.GetJungleType() == JungleType.Large)); + JungleLegendaryList.AddRange(JungleList.Where(o => o.GetJungleType() == JungleType.Legendary)); + + AllyWardsList.AddRange(WardsList.Where(o => o.IsAlly)); + EnemyWardsList.AddRange(WardsList.Where(o => o.IsEnemy)); + + AllyShopsList.AddRange(ShopsList.Where(o => o.IsAlly)); + EnemyShopsList.AddRange(ShopsList.Where(o => o.IsEnemy)); + + AllySpawnPointsList.AddRange(SpawnPointsList.Where(o => o.IsAlly)); + EnemySpawnPointsList.AddRange(SpawnPointsList.Where(o => o.IsEnemy)); + + GameObject.OnCreate += OnCreate; + GameObject.OnDelete += OnDelete; + }; } #endregion @@ -210,172 +258,172 @@ static GameObjects() /// /// Gets the game objects. /// - public static IEnumerable AllGameObjects => GameObjectsList; + public static IReadOnlyCollection AllGameObjects => GameObjectsList.AsReadOnly(); /// /// Gets the ally. /// - public static IEnumerable Ally => AllyList; + public static IReadOnlyCollection Ally => AllyList.AsReadOnly(); /// /// Gets the ally heroes. /// - public static IEnumerable AllyHeroes => AllyHeroesList; + public static IReadOnlyCollection AllyHeroes => AllyHeroesList.AsReadOnly(); /// /// Gets the ally inhibitors. /// - public static IEnumerable AllyInhibitors => AllyInhibitorsList; + public static IReadOnlyCollection AllyInhibitors => AllyInhibitorsList.AsReadOnly(); /// /// Gets the ally minions. /// - public static IEnumerable AllyMinions => AllyMinionsList; + public static IReadOnlyCollection AllyMinions => AllyMinionsList.AsReadOnly(); /// /// Gets or sets the ally nexus. /// - public static Obj_HQ AllyNexus { get; set; } + public static Obj_HQ AllyNexus { get; private set; } /// /// Gets the ally shops. /// - public static IEnumerable AllyShops => AllyShopsList; + public static IReadOnlyCollection AllyShops => AllyShopsList.AsReadOnly(); /// /// Gets the ally spawn points. /// - public static IEnumerable AllySpawnPoints => AllySpawnPointsList; + public static IReadOnlyCollection AllySpawnPoints => AllySpawnPointsList.AsReadOnly(); /// /// Gets the ally turrets. /// - public static IEnumerable AllyTurrets => AllyTurretsList; + public static IReadOnlyCollection AllyTurrets => AllyTurretsList.AsReadOnly(); /// /// Gets the ally wards. /// - public static IEnumerable AllyWards => AllyWardsList; + public static IReadOnlyCollection AllyWards => AllyWardsList.AsReadOnly(); /// /// Gets the attackable units. /// - public static IEnumerable AttackableUnits => AttackableUnitsList; + public static IReadOnlyCollection AttackableUnits => AttackableUnitsList.AsReadOnly(); /// /// Gets the enemy. /// - public static IEnumerable Enemy => EnemyList; + public static IReadOnlyCollection Enemy => EnemyList.AsReadOnly(); /// /// Gets the enemy heroes. /// - public static IEnumerable EnemyHeroes => EnemyHeroesList; + public static IReadOnlyCollection EnemyHeroes => EnemyHeroesList.AsReadOnly(); /// /// Gets the enemy inhibitors. /// - public static IEnumerable EnemyInhibitors => EnemyInhibitorsList; + public static IReadOnlyCollection EnemyInhibitors => EnemyInhibitorsList.AsReadOnly(); /// /// Gets the enemy minions. /// - public static IEnumerable EnemyMinions => EnemyMinionsList; + public static IEnumerable EnemyMinions => EnemyMinionsList.AsReadOnly(); /// /// Gets or sets the enemy nexus. /// - public static Obj_HQ EnemyNexus { get; set; } + public static Obj_HQ EnemyNexus { get; private set; } /// /// Gets the enemy shops. /// - public static IEnumerable EnemyShops => EnemyShopsList; + public static IReadOnlyCollection EnemyShops => EnemyShopsList.AsReadOnly(); /// /// Gets the enemy spawn points. /// - public static IEnumerable EnemySpawnPoints => EnemySpawnPointsList; + public static IReadOnlyCollection EnemySpawnPoints => EnemySpawnPointsList.AsReadOnly(); /// /// Gets the enemy turrets. /// - public static IEnumerable EnemyTurrets => EnemyTurretsList; + public static IReadOnlyCollection EnemyTurrets => EnemyTurretsList.AsReadOnly(); /// /// Gets the enemy wards. /// - public static IEnumerable EnemyWards => EnemyWardsList; + public static IReadOnlyCollection EnemyWards => EnemyWardsList.AsReadOnly(); /// /// Gets the heroes. /// - public static IEnumerable Heroes => HeroesList; + public static IReadOnlyCollection Heroes => HeroesList.AsReadOnly(); /// /// Gets the inhibitors. /// - public static IEnumerable Inhibitors => InhibitorsList; + public static IReadOnlyCollection Inhibitors => InhibitorsList.AsReadOnly(); /// /// Gets the jungle. /// - public static IEnumerable Jungle => JungleList; + public static IReadOnlyCollection Jungle => JungleList.AsReadOnly(); /// /// Gets the jungle large. /// - public static IEnumerable JungleLarge => JungleLargeList; + public static IReadOnlyCollection JungleLarge => JungleLargeList.AsReadOnly(); /// /// Gets the jungle legendary. /// - public static IEnumerable JungleLegendary => JungleLegendaryList; + public static IReadOnlyCollection JungleLegendary => JungleLegendaryList.AsReadOnly(); /// /// Gets the jungle small. /// - public static IEnumerable JungleSmall => JungleSmallList; + public static IReadOnlyCollection JungleSmall => JungleSmallList.AsReadOnly(); /// /// Gets the minions. /// - public static IEnumerable Minions => MinionsList; + public static IReadOnlyCollection Minions => MinionsList.AsReadOnly(); /// /// Gets the nexuses. /// - public static IEnumerable Nexuses => NexusList; + public static IReadOnlyCollection Nexuses => NexusList.AsReadOnly(); /// /// Gets the general particle emitters. /// - public static IEnumerable ParticleEmitters => ParticleEmittersList; + public static IReadOnlyCollection ParticleEmitters => ParticleEmittersList.AsReadOnly(); /// /// Gets or sets the player. /// - public static Obj_AI_Hero Player { get; set; } + public static Obj_AI_Hero Player { get; private set; } /// /// Gets the shops. /// - public static IEnumerable Shops => ShopsList; + public static IReadOnlyCollection Shops => ShopsList.AsReadOnly(); /// /// Gets the spawn points. /// - public static IEnumerable SpawnPoints => SpawnPointsList; + public static IReadOnlyCollection SpawnPoints => SpawnPointsList.AsReadOnly(); /// /// Gets the turrets. /// - public static IEnumerable Turrets => TurretsList; + public static IReadOnlyCollection Turrets => TurretsList.AsReadOnly(); /// /// Gets the wards. /// - public static IEnumerable Wards => WardsList; + public static IReadOnlyCollection Wards => WardsList.AsReadOnly(); #endregion @@ -402,7 +450,7 @@ public static bool Compare(this GameObject gameObject, GameObject @object) /// /// The List containing the requested type. /// - public static IEnumerable Get() where T : GameObject, new() + public static IEnumerable Get() where T : GameObject { return AllGameObjects.OfType(); } @@ -425,75 +473,6 @@ public static bool Compare(this GameObject gameObject, GameObject @object) #region Methods - /// - /// The initialize method. - /// - internal static void Initialize() - { - if (initialized) - { - return; - } - - initialized = true; - - Events.OnLoad += (sender, args) => - { - Player = ObjectManager.Player; - - HeroesList.AddRange(ObjectManager.Get()); - MinionsList.AddRange( - ObjectManager.Get() - .Where( - o => o.Team != GameObjectTeam.Neutral && !o.GetMinionType().HasFlag(MinionTypes.Ward))); - TurretsList.AddRange(ObjectManager.Get()); - InhibitorsList.AddRange(ObjectManager.Get()); - JungleList.AddRange( - ObjectManager.Get() - .Where(o => o.Team == GameObjectTeam.Neutral && o.Name != "WardCorpse")); - WardsList.AddRange( - ObjectManager.Get().Where(o => o.GetMinionType().HasFlag(MinionTypes.Ward))); - ShopsList.AddRange(ObjectManager.Get()); - SpawnPointsList.AddRange(ObjectManager.Get()); - GameObjectsList.AddRange(ObjectManager.Get()); - NexusList.AddRange(ObjectManager.Get()); - AttackableUnitsList.AddRange(ObjectManager.Get()); - ParticleEmittersList.AddRange(ObjectManager.Get()); - - EnemyHeroesList.AddRange(HeroesList.Where(o => o.IsEnemy)); - EnemyMinionsList.AddRange(MinionsList.Where(o => o.IsEnemy)); - EnemyTurretsList.AddRange(TurretsList.Where(o => o.IsEnemy)); - EnemyInhibitorsList.AddRange(InhibitorsList.Where(o => o.IsEnemy)); - EnemyList.AddRange( - EnemyHeroesList.Cast().Concat(EnemyMinionsList).Concat(EnemyTurretsList)); - EnemyNexus = NexusList.FirstOrDefault(n => n.IsEnemy); - - AllyHeroesList.AddRange(HeroesList.Where(o => o.IsAlly)); - AllyMinionsList.AddRange(MinionsList.Where(o => o.IsAlly)); - AllyTurretsList.AddRange(TurretsList.Where(o => o.IsAlly)); - AllyInhibitorsList.AddRange(InhibitorsList.Where(o => o.IsAlly)); - AllyList.AddRange( - AllyHeroesList.Cast().Concat(AllyMinionsList).Concat(AllyTurretsList)); - AllyNexus = NexusList.FirstOrDefault(n => n.IsAlly); - - JungleSmallList.AddRange(JungleList.Where(o => o.GetJungleType() == JungleType.Small)); - JungleLargeList.AddRange(JungleList.Where(o => o.GetJungleType() == JungleType.Large)); - JungleLegendaryList.AddRange(JungleList.Where(o => o.GetJungleType() == JungleType.Legendary)); - - AllyWardsList.AddRange(WardsList.Where(o => o.IsAlly)); - EnemyWardsList.AddRange(WardsList.Where(o => o.IsEnemy)); - - AllyShopsList.AddRange(ShopsList.Where(o => o.IsAlly)); - EnemyShopsList.AddRange(ShopsList.Where(o => o.IsEnemy)); - - AllySpawnPointsList.AddRange(SpawnPointsList.Where(o => o.IsAlly)); - EnemySpawnPointsList.AddRange(SpawnPointsList.Where(o => o.IsEnemy)); - - GameObject.OnCreate += OnCreate; - GameObject.OnDelete += OnDelete; - }; - } - /// /// OnCreate event. /// diff --git a/Core/Wrappers/Spells/Spell.cs b/Core/Wrappers/Spells/Spell.cs index 18efdda..eb8b6d4 100644 --- a/Core/Wrappers/Spells/Spell.cs +++ b/Core/Wrappers/Spells/Spell.cs @@ -66,7 +66,8 @@ public class Spell /// /// The Minimum Mana Percentage /// - private float minManaPercent; + private float minManaPercent; + #endregion #region Constructors and Destructors @@ -120,6 +121,7 @@ public Spell(SpellSlot slot, float range = float.MaxValue) #endregion #region Public Properties + /// /// Cast Condition Delegate /// @@ -772,7 +774,7 @@ public List GetCollision(Vector2 fromVector2, List to, flo /// /// Unit's predicted health /// - public float GetHealthPrediction(Obj_AI_Base unit) + public virtual float GetHealthPrediction(Obj_AI_Base unit) { var time = (int)((this.Delay * 1000) + (this.From.Distance(unit.ServerPosition) / this.Speed) - 100); return Health.GetPrediction(unit, time); @@ -857,7 +859,7 @@ public FarmLocation GetLineFarmLocation(List minionPositions, float ove /// /// output /// - public PredictionOutput GetPrediction( + public virtual PredictionOutput GetPrediction( Obj_AI_Base unit, bool aoe = false, float overrideRange = -1, @@ -868,7 +870,7 @@ public PredictionOutput GetPrediction( new PredictionInput { Unit = unit, Delay = this.Delay, Radius = this.Width, Speed = this.Speed, From = this.From, - Range = (overrideRange > 0) ? overrideRange : this.Range, Collision = this.Collision, + Range = overrideRange > 0 ? overrideRange : this.Range, Collision = this.Collision, Type = this.Type, RangeCheckFrom = this.RangeCheckFrom, AoE = aoe, CollisionObjects = collisionable });