/// <summary>
        /// (Cross-Game compatible) Recursively get every WeaponModels this TowerModel has
        /// </summary>
        public static List <WeaponModel> GetWeapons(this TowerModel towerModel)
        {
            List <AttackModel> attackModels = towerModel.GetAttackModels();

            if (attackModels is null)
            {
                return(null);
            }

            if (!attackModels.Any())
            {
                return(new List <WeaponModel>());
            }

            List <WeaponModel> weaponModels = new List <WeaponModel>();

            foreach (AttackModel attackModel in attackModels)
            {
                Il2CppReferenceArray <WeaponModel> weapons = attackModel.weapons;
                if (weapons != null)
                {
                    weaponModels.AddRange(weapons);
                }
            }

            return(weaponModels);
        }
 /// <summary>
 /// Sets all elements in the <see cref="Il2CppReferenceArray{T}"/> to the default value of each element type.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="referenceArray"></param>
 public static void Clear <T>(this Il2CppReferenceArray <T> referenceArray) where T : Il2CppSystem.Object
 {
     for (int i = 0; i < referenceArray.Length; i++)
     {
         referenceArray[i] = default;
     }
 }
Example #3
0
 /// <summary>
 /// (Cross-Game compatible) Performs the specified action on each element
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <param name="action">Action to preform on each element</param>
 public static void ForEach <T>(this Il2CppReferenceArray <T> source, Action <T> action) where T : Il2CppSystem.Object
 {
     for (int i = 0; i < source.Count; i++)
     {
         action.Invoke(source[i]);
     }
 }
Example #4
0
        /// <summary>
        /// Spawn bloons in game
        /// </summary>
        /// <param name="inGame"></param>
        /// <param name="round"></param>
        public static void SpawnBloons(this InGame inGame, int round)
        {
            GameModel model = inGame.GetGameModel();

            int index = (round < 100) ? round - 1 : round - 100;
            Il2CppReferenceArray <BloonEmissionModel> emissions = (round < 100) ? model.GetRoundSet().rounds[index].emissions : model.freeplayGroups[index].bloonEmissions;

            inGame.SpawnBloons(emissions);
        }
        /// <summary>
        /// (Cross-Game compatible) Check if this has any items of type TCast
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TCast">The Type you're checking for</typeparam>
        /// <param name="referenceArray"></param>
        /// <returns></returns>
        public static bool HasItemsOfType <TSource, TCast>(this Il2CppReferenceArray <TSource> referenceArray)
            where TSource : Il2CppSystem.Object
            where TCast : Il2CppSystem.Object
        {
            try { TSource result = referenceArray.First(item => item.IsType <TCast>()); }
            catch (Exception) { return(false); }

            return(true);
        }
Example #6
0
        /// <summary>
        /// Get the game object that owns all InGame UI elements
        /// </summary>
        /// <param name="inGame"></param>
        /// <returns></returns>
        public static GameObject GetInGameUI(this InGame inGame)
        {
            Scene scene = SceneManager.GetSceneByName("InGameUi");
            Il2CppReferenceArray <GameObject> rootGameObjects = scene.GetRootGameObjects();

            const int  uiIndex = 1;
            GameObject ui      = rootGameObjects[uiIndex];

            return(ui);
        }
Example #7
0
        /// <summary>
        /// (Cross-Game compatible) Return as Il2CppReferenceArray
        /// </summary>
        public static Il2CppReferenceArray <T> ToIl2CppReferenceArray <T>(this T[] array) where T : Il2CppSystem.Object
        {
            Il2CppReferenceArray <T> il2cppArray = new Il2CppReferenceArray <T>(array.Length);

            for (int i = 0; i < array.Length; i++)
            {
                il2cppArray[i] = array[i];
            }

            return(il2cppArray);
        }
Example #8
0
 /// <summary>
 /// (Cross-Game compatible) Return whether or not there are any elements in this that match the predicate
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="source"></param>
 /// <param name="predicate"></param>
 /// <returns></returns>
 public static bool Any <T>(this Il2CppReferenceArray <T> source, Func <T, bool> predicate) where T : Il2CppSystem.Object
 {
     for (int i = 0; i < source.Count; i++)
     {
         if (predicate(source[i]))
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// (Cross-Game compatible) Return a duplicate of this
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public static Il2CppReferenceArray <T> Duplicate <T>(this Il2CppReferenceArray <T> list) where T : Il2CppSystem.Object
        {
            List <T> newList = new List <T>();

            foreach (T item in list)
            {
                newList.Add(item);
            }

            return(newList.ToIl2CppReferenceArray());
        }
        /// <summary>
        /// (Cross-Game compatible) Return as LockList
        /// </summary>
        public static LockList <T> ToLockList <T>(this Il2CppReferenceArray <T> referenceArray) where T : Il2CppSystem.Object
        {
            LockList <T> lockList = new LockList <T>();

            foreach (T item in referenceArray)
            {
                lockList.Add(item);
            }

            return(lockList);
        }
        /// <summary>
        /// (Cross-Game compatible) Return as a System.Array
        /// </summary>
        public static T[] ToArray <T>(this Il2CppReferenceArray <T> referenceArray) where T : Il2CppSystem.Object
        {
            T[] newArray = new T[] { };
            foreach (T item in referenceArray)
            {
                Array.Resize(ref newArray, newArray.Length + 1);
                newArray[newArray.Length - 1] = item;
            }

            return(newArray);
        }
Example #12
0
        /// <summary>
        /// (Cross-Game compatible) Return as Il2CppReferenceArray
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumerable"></param>
        /// <returns></returns>
        public static Il2CppReferenceArray <T> ToIl2CppReferenceArray <T>(this IEnumerable <T> enumerable) where T : Il2CppSystem.Object
        {
            Il2CppReferenceArray <T> il2cppArray = new Il2CppReferenceArray <T>(enumerable.Count());

            for (int i = 0; i < enumerable.Count(); i++)
            {
                il2cppArray[i] = enumerable.ElementAt(i);
            }

            return(il2cppArray);
        }
        /// <summary>
        /// (Cross-Game compatible) Return as Il2CppSystem.List
        /// </summary>
        public static Il2CppSystem.Collections.Generic.List <T> ToIl2CppList <T>(this Il2CppReferenceArray <T> referenceArray)
            where T : Il2CppSystem.Object
        {
            Il2CppSystem.Collections.Generic.List <T> il2CppList = new Il2CppSystem.Collections.Generic.List <T>();
            foreach (T item in referenceArray)
            {
                il2CppList.Add(item);
            }

            return(il2CppList);
        }
        /// <summary>
        /// (Cross-Game compatible) Return as Il2CppReferenceArray
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="il2CppList"></param>
        /// <returns></returns>
        public static Il2CppReferenceArray <T> ToIl2CppReferenceArray <T>(this List <T> il2CppList) where T : Il2CppSystem.Object
        {
            Il2CppReferenceArray <T> il2cppArray = new Il2CppReferenceArray <T>(il2CppList.Count);

            for (int i = 0; i < il2CppList.Count; i++)
            {
                il2cppArray[i] = il2CppList[i];
            }

            return(il2cppArray);
        }
        /// <summary>
        /// Not tested
        /// </summary>
        public static SizedList <T> ToSizedList <T>(this Il2CppReferenceArray <T> referenceArray) where T : Il2CppSystem.Object
        {
            SizedList <T> sizedList = new SizedList <T>();

            foreach (T item in referenceArray)
            {
                sizedList.Add(item);
            }

            return(sizedList);
        }
        /// <summary>
        /// (Cross-Game compatible) Return a duplicate of this as type TCast
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TCast"></typeparam>
        /// <param name="list"></param>
        /// <returns></returns>
        public static Il2CppReferenceArray <TCast> DuplicateAs <TSource, TCast>(this Il2CppReferenceArray <TSource> list)
            where TSource : Il2CppSystem.Object where TCast : Il2CppSystem.Object
        {
            List <TCast> newList = new List <TCast>();

            foreach (TSource item in list)
            {
                newList.Add(item.TryCast <TCast>());
            }

            return(newList.ToIl2CppReferenceArray());
        }
Example #17
0
        /// <summary>
        /// (Cross-Game compatible) Return the index of the element that matches the predicate
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="source"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static int FindIndex <T>(this Il2CppReferenceArray <T> source, Func <T, bool> predicate) where T : Il2CppSystem.Object
        {
            for (int i = 0; i < source.Count; i++)
            {
                if (predicate(source[i]))
                {
                    return(i);
                }
            }

            return(-1);
        }
Example #18
0
        /// <summary>
        /// Return all ProjectileModels from every TowerModel in the game
        /// </summary>
        public static List <ProjectileModel> GetAllProjectileModels(this GameModel model)
        {
            List <ProjectileModel>            projectileModels = new List <ProjectileModel>();
            Il2CppReferenceArray <TowerModel> towerModels      = model.towers;

            foreach (TowerModel towerModel in towerModels)
            {
                projectileModels.AddRange(towerModel.GetAllProjectiles());
            }

            return(projectileModels);
        }
        /// <summary>
        /// (Cross-Game compatible) Return the first item of type TCast
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TCast">The Type of the Item you want</typeparam>
        /// <param name="referenceArray"></param>
        /// <returns></returns>
        public static TCast GetItemOfType <TSource, TCast>(this Il2CppReferenceArray <TSource> referenceArray)
            where TCast : Il2CppSystem.Object
            where TSource : Il2CppSystem.Object
        {
            if (!HasItemsOfType <TSource, TCast>(referenceArray))
            {
                return(null);
            }

            TSource result = referenceArray.FirstOrDefault(item => item.TryCast <TCast>() != null);

            return(result.TryCast <TCast>());
        }
        /// <summary>
        /// (Cross-Game compatible) Return as Il2CppReferenceArray
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumerable"></param>
        /// <returns></returns>
        public static Il2CppReferenceArray <T> ToIl2CppReferenceArray <T>(this IEnumerable <T> enumerable) where T : Il2CppSystem.Object
        {
            Il2CppReferenceArray <T> il2cppArray = new Il2CppReferenceArray <T>(enumerable.Count());

            int i          = 0;
            var enumerator = enumerable.GetEnumeratorCollections();

            while (enumerator.MoveNext())
            {
                il2cppArray[i] = enumerator.Current.Cast <T>();
                i++;
            }

            return(il2cppArray);
        }
        /// <summary>
        /// (Cross-Game compatible) Return as Il2CppReferenceArray
        /// </summary>
        public static Il2CppReferenceArray <Il2CppSystem.Object> ToIl2CppReferenceArray(this IEnumerator enumerator)
        {
            Il2CppReferenceArray <Il2CppSystem.Object> il2cppArray =
                new Il2CppReferenceArray <Il2CppSystem.Object>(enumerator.Count());

            int i = 0;

            while (enumerator.MoveNext())
            {
                il2cppArray[i] = enumerator.Current;
                i++;
            }


            return(il2cppArray);
        }
Example #22
0
        /// <summary>
        /// Return all AttackModels from every TowerModel in the game
        /// </summary>
        public static List <AttackModel> GetAllAttackModels(this GameModel model)
        {
            List <AttackModel> attackModels          = new List <AttackModel>();
            Il2CppReferenceArray <TowerModel> towers = model.towers;

            foreach (TowerModel tower in towers)
            {
                List <AttackModel> attacks = tower.GetAttackModels();
                if (attacks != null && attacks.Any())
                {
                    attackModels.AddRange(attacks);
                }
            }

            return(attackModels);
        }
Example #23
0
        /// <summary>
        /// Return all AbilityModels from every TowerModel in the game
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static List <AbilityModel> GetAllAbilityModels(this GameModel model)
        {
            List <AbilityModel> abilityModels        = new List <AbilityModel>();
            Il2CppReferenceArray <TowerModel> towers = model.towers;

            foreach (TowerModel tower in towers)
            {
                List <AbilityModel> abilities = tower.GetAbilites();
                if (abilities != null && abilities.Any())
                {
                    abilityModels.AddRange(abilities);
                }
            }

            return(abilityModels);
        }
Example #24
0
        /// <summary>
        /// Return all WeaponModels from every AttackModel in the game
        /// </summary>
        public static List <WeaponModel> GetAllWeaponModels(this GameModel model)
        {
            List <WeaponModel> weaponModels = new List <WeaponModel>();
            List <AttackModel> attackModels = model.GetAllAttackModels();

            foreach (AttackModel attackModel in attackModels)
            {
                Il2CppReferenceArray <WeaponModel> weapons = attackModel.weapons;
                if (weapons != null && weapons.Any())
                {
                    weaponModels.AddRange(weapons);
                }
            }

            return(weaponModels);
        }
        /// <summary>
        /// (Cross-Game compatible) Return this with an additional Item added to it
        /// </summary>
        /// <typeparam name="T">The Type of the Item to add</typeparam>
        /// <param name="referenceArray"></param>
        /// <param name="objectToAdd">Item to add</param>
        /// <returns></returns>
        public static Il2CppReferenceArray <T> AddTo <T>(this Il2CppReferenceArray <T> referenceArray, T objectToAdd) where T : Il2CppSystem.Object
        {
            if (referenceArray is null)
            {
                referenceArray = new Il2CppReferenceArray <T>(0);
            }

            Il2CppReferenceArray <T> newRef = new Il2CppReferenceArray <T>(referenceArray.Count + 1);

            for (int i = 0; i < referenceArray.Count; i++)
            {
                newRef[i] = referenceArray[i];
            }

            newRef[newRef.Length - 1] = objectToAdd;

            return(newRef);
        }
        /// <summary>
        /// (Cross-Game compatible) Return all Items of type TCast
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TCast">The Type of the Items you want</typeparam>
        /// <param name="referenceArray"></param>
        /// <returns></returns>
        public static List <TCast> GetItemsOfType <TSource, TCast>(this Il2CppReferenceArray <TSource> referenceArray)
            where TSource : Il2CppSystem.Object
            where TCast : Il2CppSystem.Object
        {
            if (!HasItemsOfType <TSource, TCast>(referenceArray))
            {
                return(null);
            }

            List <TCast> results = new List <TCast>();

            foreach (var item in referenceArray)
            {
                if (item.IsType(out TCast tryCast))
                {
                    results.Add(tryCast);
                }
            }

            return(results);
        }
        /// <summary>
        /// (Cross-Game compatible) Return this with additional Items added to it
        /// </summary>
        /// <typeparam name="T">The Type of the Items to add</typeparam>
        /// <param name="referenceArray"></param>
        /// <param name="objectsToAdd">Items to add</param>
        /// <returns></returns>
        public static Il2CppReferenceArray <T> AddTo <T>(this Il2CppReferenceArray <T> referenceArray, Il2CppReferenceArray <T> objectsToAdd) where T : Il2CppSystem.Object
        {
            if (referenceArray is null)
            {
                referenceArray = new Il2CppReferenceArray <T>(0);
            }

            int size = referenceArray.Count + objectsToAdd.Count;
            Il2CppReferenceArray <T> newReference = new Il2CppReferenceArray <T>(size);

            List <T> tempList = new List <T>(referenceArray);

            tempList.AddRange(objectsToAdd);

            for (int i = 0; i < tempList.Count; i++)
            {
                T item = tempList[i];
                newReference[i] = item;
            }

            return(newReference);
        }
Example #28
0
        /// <summary>
        /// Add multiple TowerModels to the game more efficiently than calling the single method repeatedly.
        /// </summary>
        public static void AddTowersToGame(this GameModel model, IEnumerable <TowerModel> towerModels)
        {
            var array        = towerModels.ToArray();
            var towersLength = model.towers.Length;
            var newArray     = new Il2CppReferenceArray <TowerModel>(towersLength + array.Length);

            for (var i = 0; i < towersLength; i++)
            {
                newArray[i] = model.towers[i];
            }

            for (var i = 0; i < array.Length; i++)
            {
                newArray[i + towersLength] = array[i];
            }

            model.towers = newArray;

            foreach (var towerModel in array)
            {
                model.AddChildDependant(towerModel);
                ModTowerHelper.TowerCache[towerModel.name] = towerModel;
            }
        }
        /// <summary>
        /// (Cross-Game compatible) Return this with the first Item of type TCast removed
        /// </summary>
        /// <typeparam name="TSource"></typeparam>
        /// <typeparam name="TCast">The Type of the Item you want to remove</typeparam>
        /// <param name="referenceArray"></param>
        /// <param name="itemToRemove">The specific Item to remove</param>
        /// <returns></returns>
        public static Il2CppReferenceArray <TSource> RemoveItem <TSource, TCast>(this Il2CppReferenceArray <TSource> referenceArray, TCast itemToRemove)
            where TSource : Il2CppSystem.Object where TCast : Il2CppSystem.Object
        {
            if (!HasItemsOfType <TSource, TCast>(referenceArray))
            {
                return(referenceArray);
            }

            List <TSource> arrayList = referenceArray.ToList();

            for (int i = 0; i < referenceArray.Count; i++)
            {
                TSource item = referenceArray[i];
                if (item is null || !item.Equals(itemToRemove.TryCast <TCast>()))
                {
                    continue;
                }

                arrayList.RemoveAt(i);
                break;
            }

            return(arrayList.ToIl2CppReferenceArray());
        }
Example #30
0
 /// <summary>
 /// Spawn bloons in game
 /// </summary>
 /// <param name="inGame"></param>
 /// <param name="bloonEmissionModels"></param>
 public static void SpawnBloons(this InGame inGame, Il2CppReferenceArray <BloonEmissionModel> bloonEmissionModels)
 {
     inGame.GetUnityToSimulation().SpawnBloons(bloonEmissionModels, inGame.GetUnityToSimulation().GetCurrentRound(), 0);
 }