Beispiel #1
0
        private void PopulateModOptions(BloonsMod bloonsMod)
        {
            var options = optionsList.GetComponentsInChildren <Transform>();

            if (options.Any(option => option.name != "ModOptions Container"))
            {
                foreach (var item in options)
                {
                    if (item.name != "ModOptions Container")
                    {
                        item.gameObject.SetActive(false);
                        GameObject.Destroy(item);
                    }
                }
            }

            for (int i = 0; i < bloonsMod.ModSettings.Values.Count; i++)
            {
                var modSetting = bloonsMod.ModSettings.ElementAt(i).Value;
                var modOption  = modSetting.ConstructModOption2(instantiatedUI.gameObject);

                var yCoord = ButtonOption.GetOriginalAsset(instantiatedUI).position.y - (i * 65);
                modOption.SetLocation(yCoord);
            }
        }
Beispiel #2
0
        internal static void LoadEmbeddedBundles(BloonsMod mod)
        {
            foreach (var name in mod.Assembly.GetManifestResourceNames().Where(s => s.EndsWith("bundle")))
            {
                var memoryStream = new MemoryStream();
                if (mod.Assembly.GetManifestResourceStream(name) is Stream stream)
                {
                    stream.CopyTo(memoryStream);
                    var bundle = AssetBundle.LoadFromMemory(memoryStream.ToArray());
                    var guid   = mod.IDPrefix;
                    if (bundle == null)
                    {
                        MelonLogger.Msg($"The bundle {name} is null!");
                        continue;
                    }

                    if (string.IsNullOrEmpty(bundle.name))
                    {
                        MelonLogger.Msg($"The bundle {name} has no name!");
                        continue;
                    }
                    if (bundle.name.EndsWith(".bundle"))
                    {
                        guid += bundle.name.Substring(0, bundle.name.LastIndexOf("."));
                    }
                    else
                    {
                        guid += bundle.name;
                    }
                    Bundles[guid] = bundle;
                    // MelonLogger.Msg("Successfully loaded bundle " + guid);
                }
            }
        }
 public UpdateInfo(BloonsMod mod)
 {
     GithubReleaseURL = mod.GithubReleaseURL;
     MelonInfoCsURL   = mod.MelonInfoCsURL;
     LatestURL        = mod.LatestURL;
     Name             = mod.Info.Name;
     CurrentVersion   = mod.Info.Version;
     Location         = mod.Location;
 }
        /// <summary>
        /// (Cross-Game compatible) Get's the directory where this mod's settings are or will be stored. Example: "BloonsTD6/Mods/BloonsTD6 Mod Helper/settings.txt"
        /// </summary>
        /// <param name="bloonsMod"></param>
        /// <param name="createIfNotExists">Create the mod's directory if it doesn't exist yet?</param>
        /// <returns></returns>
        public static string GetModSettingsDir(this BloonsMod bloonsMod, bool createIfNotExists = true)
        {
            var path = bloonsMod.GetModSettingsDir();

            if (createIfNotExists)
            {
                Directory.CreateDirectory(path);
            }
            return(path);
        }
        /// <summary>
        /// (Cross-Game compatible) Get the personal mod directory for this specific mod. Useful for keeping this mod's files seperate from other mods. Example: "BloonsTD6/Mods/BloonsTD6 Mod Helper/settings.txt"
        /// </summary>
        /// <param name="bloonsMod"></param>
        /// <param name="createIfNotExists">Create the mod's directory if it doesn't exist yet?</param>
        /// <returns></returns>
        public static string GetModDirectory(this BloonsMod bloonsMod, bool createIfNotExists = true)
        {
            string path = $"{Environment.CurrentDirectory}\\Mods\\{bloonsMod.GetModName()}";

            if (createIfNotExists)
            {
                Directory.CreateDirectory(path);
            }
            return(path);
        }
Beispiel #6
0
        private void PopulateModListItems(BloonsMod bloonsMod, int index)
        {
            var item = Object.Instantiate(modListItem, modList);

            var button = item.GetComponentInChildren <Button>();

            button.onClick.AddListener(() => PopulateModOptions(bloonsMod));
            button.GetComponentInChildren <Text>().text = bloonsMod.Info.Name;

            item.Show();
        }
Beispiel #7
0
        /// <summary>
        /// Gets a sprite reference by name for a specific mod
        /// </summary>
        /// <param name="mod">The BloonsMod that the texture is from</param>
        /// <param name="name">The file name of your texture, without the extension</param>
        /// <returns>A new SpriteReference, or null if there's no resource</returns>
        public static SpriteReference GetSpriteReference(BloonsMod mod, string name)
        {
            var guid = GetTextureGUID(mod, name);

            if (ResourceHandler.resources.ContainsKey(guid))
            {
                return(CreateSpriteReference(guid));
            }

            return(null);
        }
Beispiel #8
0
        private void PopulateModListItems(BloonsMod bloonsMod, int index)
        {
            var item = GameObject.Instantiate(modListItem, modList);

            var button = item.GetComponentInChildren <Button>();

            button.onClick.AddListener(() => PopulateModOptions(bloonsMod));
            button.GetComponentInChildren <Text>().text = bloonsMod.GetModName();

            var height = button.GetComponent <RectTransform>().rect.height;

            item.gameObject.transform.position = new Vector3(item.gameObject.transform.position.x, item.gameObject.transform.position.y - (index * 65)); //(index * height));
            item.Show();
        }
Beispiel #9
0
 internal static void LoadEmbeddedTextures(BloonsMod mod)
 {
     foreach (var name in mod.Assembly.GetManifestResourceNames().Where(s => s.EndsWith("png")))
     {
         using (var memoryStream = new MemoryStream())
         {
             if (mod.Assembly.GetManifestResourceStream(name) is Stream stream)
             {
                 stream.CopyTo(memoryStream);
                 var split = name.Split('.');
                 var guid  = mod.IDPrefix + split[split.Length - 2];
                 resources[guid] = memoryStream.ToArray();
             }
         }
     }
 }
        internal static IEnumerable <ModTower> GetModTowers(BloonsMod mod)
        {
            return(mod.GetType().Assembly.GetTypes()
                   .Where(type => !type.IsAbstract && type.IsPublic && type.IsSubclassOf(typeof(ModTower)))
                   .Where(type => type.GetConstructor(Type.EmptyTypes) != null)
                   .Select(type =>
            {
                if (!ModContent.Instances.ContainsKey(type))
                {
                    var tower = (ModTower)Activator.CreateInstance(type);
                    tower.mod = mod;
                    ModContent.Instances[type] = tower;
                }

                return (ModTower)ModContent.Instances[type];
            }));
        }
        internal static void LoadTowersAndUpgrades(BloonsMod mod)
        {
            var modUpgrades = GetModUpgrades(mod);
            var modTowers   = GetModTowers(mod);

            foreach (var modUpgrade in modUpgrades)
            {
                Game.instance.model.AddUpgrade(modUpgrade.GetUpgradeModel());
                modUpgrade.Tower.upgrades[modUpgrade.Path, modUpgrade.Tier] = modUpgrade;
                ModUpgrades.Add(modUpgrade);
            }

            foreach (var modTower in modTowers)
            {
                AddAllTowerModels(modTower);
                ModTowers.Add(modTower);
            }
        }
Beispiel #12
0
        private static void SaveModSettings(BloonsMod mod, string modSettingsDir)
        {
            if (!Directory.Exists(modSettingsDir))
            {
                Directory.CreateDirectory(modSettingsDir);
            }
            var fileName = $"{modSettingsDir}\\{mod.Info.Name}.json";

            using (var file = File.CreateText(fileName))
                using (var writer = new JsonTextWriter(file))
                {
                    writer.Formatting = Formatting.Indented;
                    writer.WriteStartObject();
                    foreach (var item in mod.ModSettings)
                    {
                        writer.WritePropertyName(item.Key);
                        writer.WriteValue(item.Value.GetValue());
                    }
                    writer.WriteEndObject();
                }
        }
Beispiel #13
0
        internal static void LoadModContent(BloonsMod mod)
        {
            mod.Content = mod.Assembly
                          .GetValidTypes()
                          .Where(CanLoadType)
                          .SelectMany(type => Create(type, mod))
                          .Where(content => content != null)
                          .OrderBy(content => content.RegistrationPriority)
                          .ToList();

            foreach (var modContent in mod.Content)
            {
                try
                {
                    modContent.Register();
                }
                catch (Exception e)
                {
                    MelonLogger.Error($"Failed to register {modContent.Name}");
                    MelonLogger.Error(e);
                }
            }

            foreach (var modContent in mod.Content)
            {
                try
                {
                    modContent.PostRegister();
                }
                catch (Exception e)
                {
                    MelonLogger.Error($"Failed to post register {modContent.Name}");
                    MelonLogger.Error(e);
                }
            }
        }
Beispiel #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <param name="mod"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        internal static IEnumerable <ModContent> Create(Type type, BloonsMod mod)
        {
            try
            {
                if (!Instances.ContainsKey(type))
                {
                    ModContent instance;
                    try
                    {
                        instance = (ModContent)Activator.CreateInstance(type);
                    }
                    catch (Exception)
                    {
                        MelonLogger.Error($"Error creating default {type.Name}");
                        MelonLogger.Error("A zero argument constructor is REQUIRED for all ModContent classes");
                        throw;
                    }

                    var instances = instance.Load().ToList();
                    foreach (var modContent in instances)
                    {
                        modContent.mod = mod;
                    }

                    Instances[type] = instances;
                }

                return(Instances[type]);
            }
            catch (Exception e)
            {
                MelonLogger.Error("Failed to load " + type.Name);
                MelonLogger.Error(e);
                return(Array.Empty <ModContent>());
            }
        }
Beispiel #15
0
        private void PopulateModOptions(BloonsMod bloonsMod)
        {
            var options = optionsList.GetComponentsInChildren <Transform>();

            if (options.Any(option => option.name != "ModOptions Container"))
            {
                foreach (var item in options)
                {
                    if (item.name != "ModOptions Container")
                    {
                        item.gameObject.SetActive(false);
                        Object.Destroy(item);
                    }
                }
            }

            var count = bloonsMod.ModSettings.Values.Count;

            for (var i = 0; i < count; i++)
            {
                var modSetting = bloonsMod.ModSettings.ElementAt(i).Value;
                modSetting.ConstructModOption(instantiatedUI.gameObject);
            }
        }
Beispiel #16
0
        /// <summary>
        /// Gets a texture's GUID by name for a specific mod
        /// <br/>
        /// Returns null if a Texture hasn't been loaded with that name
        /// </summary>
        /// <param name="mod">The BloonsMod that the texture is from</param>
        /// <param name="fileName">The file name of your texture, without the extension</param>
        /// <returns>The texture's GUID</returns>
        public static string GetTextureGUID(BloonsMod mod, string fileName)
        {
            var guid = mod?.IDPrefix + fileName;

            return(ResourceHandler.resources.ContainsKey(guid) ? guid : default);
Beispiel #17
0
 /// <summary>
 /// Gets a texture's GUID by name for a specific mod
 /// </summary>
 /// <param name="mod">The BloonsMod that the texture is from</param>
 /// <param name="name">The file name of your texture, without the extension</param>
 /// <returns>The texture's GUID</returns>
 public static string GetTextureGUID(BloonsMod mod, string name)
 {
     return(mod == null ? default : mod.IDPrefix + name);
 }
Beispiel #18
0
 /// <summary>
 /// Gets a sprite reference by name for a specific mod
 /// </summary>
 /// <param name="mod">The BloonsMod that the texture is from</param>
 /// <param name="name">The file name of your texture, without the extension</param>
 /// <returns>A new SpriteReference</returns>
 public static SpriteReference GetSpriteReference(BloonsMod mod, string name)
 {
     return(new SpriteReference(GetTextureGUID(mod, name)));
 }
Beispiel #19
0
 /// <summary>
 /// (Cross-Game compatible) Get's the directory where this mod's settings are or will be stored. Example: "BloonsTD6/Mods/BloonsTD6 Mod Helper/settings.txt"
 /// </summary>
 /// <param name="bloonsMod"></param>
 /// <returns></returns>
 public static string GetModSettingsDir(this BloonsMod bloonsMod)
 {
     return(Path.Combine(bloonsMod.GetModDirectory(), "Mod Settings"));
 }
Beispiel #20
0
 /// <summary>
 /// (Cross-Game compatible) Get the personal mod directory for this specific mod. Useful for keeping this mod's files seperate from other mods. Example: "BloonsTD6/Mods/BloonsTD6 Mod Helper/settings.txt"
 /// </summary>
 /// <param name="bloonsMod"></param>
 /// <returns></returns>
 public static string GetModDirectory(this BloonsMod bloonsMod)
 {
     return($"{Environment.CurrentDirectory}\\Mods\\{bloonsMod.GetModName()}");
 }
Beispiel #21
0
 /// <summary>
 /// (Cross-Game compatible) Get the name of this mod from it's dll name
 /// </summary>
 /// <param name="bloonsMod"></param>
 /// <returns></returns>
 public static string GetModName(this BloonsMod bloonsMod)
 {
     return(bloonsMod?.Assembly?.GetName()?.Name);
 }