// Token: 0x06000360 RID: 864 RVA: 0x0000436C File Offset: 0x0000256C
 internal static Unit9 GetUnitFast(uint?handle)
 {
     if (handle != null)
     {
         return(EntityManager9.GetUnitFast(handle.Value));
     }
     return(null);
 }
 // Token: 0x06000365 RID: 869 RVA: 0x00004385 File Offset: 0x00002585
 private static void AutoReload()
 {
     if (EntityManager9.Heroes.Any((Hero9 x) => x.IsMyHero))
     {
         return;
     }
     EntityManager9.ForceReload();
 }
 // Token: 0x06000363 RID: 867 RVA: 0x0001B704 File Offset: 0x00019904
 private static void AddCurrentAbilities()
 {
     foreach (Ability ability in ObjectManager.GetEntitiesFast <Ability>().Concat(ObjectManager.GetDormantEntities <Ability>()))
     {
         if (ability.IsValid)
         {
             EntityManager9.AddAbility(ability);
         }
     }
 }
        // Token: 0x0600036A RID: 874 RVA: 0x0001B954 File Offset: 0x00019B54
        private static void LoadCheck()
        {
            Unit9 unit = EntityManager9.Units.FirstOrDefault((Unit9 x) => x.IsMyHero);

            if (unit != null && unit.IsValid && unit.MoveCapability != MoveCapability.None)
            {
                UpdateManager.Subscribe(new Action(EntityManager9.AutoReload), 5000, true);
                return;
            }
            Logger.Warn("O9K was not loaded successfully, reloading...");
            EntityManager9.ForceReload();
            UpdateManager.Subscribe(new Action(EntityManager9.AutoReload), 5000, true);
        }
 // Token: 0x06000356 RID: 854 RVA: 0x0001AEA0 File Offset: 0x000190A0
 public static void ForceReload()
 {
     try
     {
         foreach (Unit9 unit in EntityManager9.Units)
         {
             try
             {
                 EntityManager9.EventHandler <Unit9> unitRemoved = EntityManager9.UnitRemoved;
                 if (unitRemoved != null)
                 {
                     unitRemoved(unit);
                 }
             }
             finally
             {
                 IDisposable disposable;
                 if ((disposable = (unit as IDisposable)) != null)
                 {
                     disposable.Dispose();
                 }
             }
         }
         foreach (Ability9 ability in EntityManager9.Abilities)
         {
             try
             {
                 EntityManager9.EventHandler <Ability9> abilityRemoved = EntityManager9.AbilityRemoved;
                 if (abilityRemoved != null)
                 {
                     abilityRemoved(ability);
                 }
             }
             finally
             {
                 ability.Dispose();
             }
         }
         EntityManager9.units.Clear();
         EntityManager9.abilities.Clear();
         EntityManager9.AddCurrentUnits();
         EntityManager9.AddCurrentAbilities();
     }
     catch (Exception exception)
     {
         Logger.Error(exception, null);
     }
 }
 // Token: 0x0600033D RID: 829 RVA: 0x0001A9B8 File Offset: 0x00018BB8
 static EntityManager9()
 {
     foreach (Type type in from x in Assembly.GetExecutingAssembly().GetTypes()
              where !x.IsAbstract && x.IsClass
              select x)
     {
         if (typeof(Ability9).IsAssignableFrom(type))
         {
             using (IEnumerator <AbilityIdAttribute> enumerator2 = type.GetCustomAttributes <AbilityIdAttribute>().GetEnumerator())
             {
                 while (enumerator2.MoveNext())
                 {
                     AbilityIdAttribute abilityIdAttribute = enumerator2.Current;
                     EntityManager9.abilityTypes.Add(abilityIdAttribute.AbilityId, type);
                 }
                 continue;
             }
         }
         if (typeof(Hero9).IsAssignableFrom(type))
         {
             using (IEnumerator <HeroIdAttribute> enumerator3 = type.GetCustomAttributes <HeroIdAttribute>().GetEnumerator())
             {
                 while (enumerator3.MoveNext())
                 {
                     HeroIdAttribute heroIdAttribute = enumerator3.Current;
                     EntityManager9.heroTypes.Add(heroIdAttribute.HeroId, type);
                 }
                 continue;
             }
         }
         if (typeof(Unit9).IsAssignableFrom(type))
         {
             foreach (UnitNameAttribute unitNameAttribute in type.GetCustomAttributes <UnitNameAttribute>())
             {
                 EntityManager9.unitTypes.Add(unitNameAttribute.Name, type);
             }
         }
     }
     EntityManager9.UnitMonitor          = new UnitMonitor();
     EntityManager9.AbilityMonitor       = new AbilityMonitor();
     EntityManager9.delayedEntityHandler = UpdateManager.Subscribe(new Action(EntityManager9.DelayedEntitiesOnUpdate), 1000, false);
     EntityManager9.AddCurrentUnits();
     EntityManager9.AddCurrentAbilities();
     ObjectManager.OnAddEntity    += EntityManager9.OnAddEntity;
     ObjectManager.OnRemoveEntity += EntityManager9.OnRemoveEntity;
     UpdateManager.BeginInvoke(new Action(EntityManager9.DemoModeCheck), 2000);
     UpdateManager.BeginInvoke(new Action(EntityManager9.LoadCheck), 5000);
 }
 // Token: 0x06000368 RID: 872 RVA: 0x0001B7FC File Offset: 0x000199FC
 private static void DelayedEntitiesOnUpdate()
 {
     try
     {
         for (int i = EntityManager9.delayedHeroes.Count - 1; i > -1; i--)
         {
             Hero hero = EntityManager9.delayedHeroes[i];
             if (!hero.IsValid)
             {
                 EntityManager9.delayedHeroes.RemoveAt(i);
             }
             else if (hero.HeroId != HeroId.npc_dota_hero_base && hero.Inventory != null)
             {
                 EntityManager9.delayedHeroes.RemoveAt(i);
                 EntityManager9.AddUnit(hero);
             }
         }
         for (int j = EntityManager9.delayedAbilities.Count - 1; j > -1; j--)
         {
             Ability ability = EntityManager9.delayedAbilities[j];
             if (!ability.IsValid)
             {
                 EntityManager9.delayedAbilities.RemoveAt(j);
             }
             else
             {
                 Entity       owner        = ability.Owner;
                 EntityHandle?entityHandle = (owner != null) ? new EntityHandle?(owner.Handle) : null;
                 if (!(EntityManager9.GetUnitFast((entityHandle != null) ? new uint?(entityHandle.GetValueOrDefault()) : null) == null))
                 {
                     EntityManager9.delayedAbilities.RemoveAt(j);
                     EntityManager9.AddAbility(ability);
                 }
             }
         }
         if (EntityManager9.delayedAbilities.Count == 0 && EntityManager9.delayedHeroes.Count == 0)
         {
             EntityManager9.delayedEntityHandler.IsEnabled = false;
         }
     }
     catch (Exception exception)
     {
         Logger.Error(exception, null);
     }
 }
 // Token: 0x06000364 RID: 868 RVA: 0x0001B764 File Offset: 0x00019964
 private static void AddCurrentUnits()
 {
     EntityManager9.AddUnit(ObjectManager.LocalHero);
     foreach (Unit unit in ObjectManager.GetEntitiesFast <Unit>().Concat(ObjectManager.GetDormantEntities <Unit>()))
     {
         if (unit.IsValid && !unit.Position.IsZero)
         {
             if (unit is Building)
             {
                 EntityManager9.AddBuilding(unit);
             }
             else
             {
                 EntityManager9.AddUnit(unit);
             }
         }
     }
     EntityManager9.trees = ObjectManager.GetEntities <Tree>().ToArray <Tree>();
 }
 // Token: 0x06000361 RID: 865 RVA: 0x0001B578 File Offset: 0x00019778
 internal static void RemoveAbility(Ability ability)
 {
     try
     {
         Ability9 abilityFast = EntityManager9.GetAbilityFast(ability.Handle);
         if (!(abilityFast == null))
         {
             abilityFast.Dispose();
             EntityManager9.abilities.Remove(abilityFast.Handle);
             EntityManager9.EventHandler <Ability9> abilityRemoved = EntityManager9.AbilityRemoved;
             if (abilityRemoved != null)
             {
                 abilityRemoved(abilityFast);
             }
         }
     }
     catch (Exception exception)
     {
         Logger.Error(exception, ability, null);
     }
 }
 // Token: 0x06000362 RID: 866 RVA: 0x0001B5E4 File Offset: 0x000197E4
 private static void AddBuilding(Unit building)
 {
     try
     {
         Unit9 unit = EntityManager9.GetUnitFast(building.Handle);
         if (!(unit != null))
         {
             string networkName = building.NetworkName;
             if (!(networkName == "CDOTA_BaseNPC_Tower"))
             {
                 if (!(networkName == "CDOTA_BaseNPC_Barracks"))
                 {
                     if (!(networkName == "CDOTA_BaseNPC_Healer"))
                     {
                         if (!(networkName == "CDOTA_Unit_Fountain"))
                         {
                             if (networkName == "CDOTA_BaseNPC_Shop")
                             {
                                 return;
                             }
                             unit = new Building9(building);
                         }
                         else
                         {
                             unit = new Building9(building)
                             {
                                 IsFountain = true
                             };
                             if (unit.Team == EntityManager9.Owner.Team)
                             {
                                 EntityManager9.AllyFountain = unit.Position;
                             }
                             else
                             {
                                 EntityManager9.EnemyFountain = unit.Position;
                             }
                         }
                     }
                     else
                     {
                         unit = new Shrine9(building);
                     }
                 }
                 else
                 {
                     unit = new Building9(building)
                     {
                         IsBarrack = true
                     };
                 }
             }
             else
             {
                 unit = new Tower9((Tower)building);
             }
             EntityManager9.units[unit.Handle] = unit;
             EntityManager9.EventHandler <Unit9> eventHandler = EntityManager9.unitAdded;
             if (eventHandler != null)
             {
                 eventHandler(unit);
             }
         }
     }
     catch (Exception exception)
     {
         Logger.Error(exception, building, null);
     }
 }
 // Token: 0x0600035D RID: 861 RVA: 0x0001B36C File Offset: 0x0001956C
 internal static void ChangeEntityControl(Entity entity)
 {
     try
     {
         Unit9 unit = EntityManager9.GetUnit(entity.Handle);
         if (!(unit == null))
         {
             Entity owner = entity.Owner;
             if (owner != null && owner.IsValid)
             {
                 if (!unit.IsHero)
                 {
                     Entity baseOwner = unit.BaseOwner;
                     if (baseOwner != null && baseOwner.IsValid && unit.BaseOwner.Handle == owner.Handle)
                     {
                         return;
                     }
                 }
                 EntityManager9.EventHandler <Unit9> unitRemoved = EntityManager9.UnitRemoved;
                 if (unitRemoved != null)
                 {
                     unitRemoved(unit);
                 }
                 foreach (Ability9 entity2 in unit.Abilities)
                 {
                     EntityManager9.EventHandler <Ability9> abilityRemoved = EntityManager9.AbilityRemoved;
                     if (abilityRemoved != null)
                     {
                         abilityRemoved(entity2);
                     }
                 }
                 unit.IsControllable = unit.BaseUnit.IsControllable;
                 unit.Team           = unit.BaseUnit.Team;
                 unit.EnemyTeam      = ((unit.Team == Team.Radiant) ? Team.Dire : Team.Radiant);
                 unit.BaseOwner      = owner;
                 Unit unit2;
                 if ((unit2 = (owner as Unit)) != null)
                 {
                     unit.Owner = EntityManager9.AddUnit(unit2);
                 }
                 EntityManager9.EventHandler <Unit9> eventHandler = EntityManager9.unitAdded;
                 if (eventHandler != null)
                 {
                     eventHandler(unit);
                 }
                 foreach (Ability9 entity3 in unit.Abilities)
                 {
                     EntityManager9.EventHandler <Ability9> eventHandler2 = EntityManager9.abilityAdded;
                     if (eventHandler2 != null)
                     {
                         eventHandler2(entity3);
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Logger.Error(exception, entity, "Change owner");
     }
 }
        // Token: 0x0600035C RID: 860 RVA: 0x0001B1C8 File Offset: 0x000193C8
        internal static Unit9 AddUnit(Unit unit)
        {
            Unit9 result;

            try
            {
                if (EntityManager9.ignoredUnits.Contains(unit.Name))
                {
                    result = null;
                }
                else
                {
                    Unit9 unit2 = EntityManager9.GetUnitFast(unit.Handle);
                    if (unit2 != null)
                    {
                        result = unit2;
                    }
                    else
                    {
                        Hero hero;
                        Type type2;
                        if ((hero = (unit as Hero)) != null)
                        {
                            if (hero.HeroId == HeroId.npc_dota_hero_base || hero.Inventory == null)
                            {
                                EntityManager9.DelayedAdd(hero);
                                return(null);
                            }
                            Type type;
                            if (EntityManager9.heroTypes.TryGetValue(hero.HeroId, out type))
                            {
                                unit2 = (Hero9)Activator.CreateInstance(type, new object[]
                                {
                                    hero
                                });
                            }
                            else
                            {
                                unit2 = new Hero9(hero);
                            }
                            if (!unit2.IsIllusion && unit2.Handle == ObjectManager.LocalHero.Handle)
                            {
                                EntityManager9.Owner.SetHero(unit2);
                            }
                        }
                        else if (EntityManager9.unitTypes.TryGetValue(unit.Name, out type2))
                        {
                            unit2 = (Unit9)Activator.CreateInstance(type2, new object[]
                            {
                                unit
                            });
                        }
                        else
                        {
                            unit2 = new Unit9(unit);
                        }
                        EntityManager9.units[unit2.Handle] = unit2;
                        Unit unit3;
                        if ((unit3 = (unit2.BaseOwner as Unit)) != null && unit3.IsValid)
                        {
                            try
                            {
                                unit2.Owner = EntityManager9.AddUnit(unit3);
                            }
                            catch (Exception exception)
                            {
                                Logger.Error(exception, "Set unit owner");
                            }
                        }
                        EntityManager9.UnitMonitor.CheckModifiers(unit2);
                        EntityManager9.EventHandler <Unit9> eventHandler = EntityManager9.unitAdded;
                        if (eventHandler != null)
                        {
                            eventHandler(unit2);
                        }
                        result = unit2;
                    }
                }
            }
            catch (Exception exception2)
            {
                Logger.Error(exception2, unit, null);
                result = null;
            }
            return(result);
        }
        // Token: 0x0600035B RID: 859 RVA: 0x0001B068 File Offset: 0x00019268
        internal static Ability9 AddAbility(Ability ability)
        {
            Ability9 result;

            try
            {
                Type type;
                if (!EntityManager9.abilityTypes.TryGetValue(ability.Id, out type))
                {
                    result = null;
                }
                else
                {
                    Ability9 ability2 = EntityManager9.GetAbilityFast(ability.Handle);
                    if (ability2 != null)
                    {
                        result = ability2;
                    }
                    else
                    {
                        Entity       owner        = ability.Owner;
                        EntityHandle?entityHandle = (owner != null) ? new EntityHandle?(owner.Handle) : null;
                        Unit9        unitFast     = EntityManager9.GetUnitFast((entityHandle != null) ? new uint?(entityHandle.GetValueOrDefault()) : null);
                        if (unitFast == null)
                        {
                            EntityManager9.DelayedAdd(ability);
                            result = null;
                        }
                        else
                        {
                            Item item;
                            if ((item = (ability as Item)) != null)
                            {
                                if (item.PurchaseTime < 0f)
                                {
                                    return(null);
                                }
                            }
                            else if (ability.AbilitySlot < AbilitySlot.Slot_1 && !ability.IsHidden)
                            {
                                return(null);
                            }
                            ability2 = (Ability9)Activator.CreateInstance(type, new object[]
                            {
                                ability
                            });
                            ability2.SetPrediction(EntityManager9.predictionManager);
                            EntityManager9.AbilityMonitor.SetOwner(ability2, unitFast);
                            EntityManager9.abilities[ability2.Handle] = ability2;
                            EntityManager9.EventHandler <Ability9> eventHandler = EntityManager9.abilityAdded;
                            if (eventHandler != null)
                            {
                                eventHandler(ability2);
                            }
                            result = ability2;
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, ability, null);
                result = null;
            }
            return(result);
        }