Ejemplo n.º 1
0
        /// <summary>
        /// Returns a list of the relative paths of the assets used by this asset, excluding the particle itself
        /// </summary>
        /// <param name="relativePath">Path of the asset relative to the mod folder</param>
        /// <param name="game">The base game name (i.e. Source SDK Base 2013 Singleplayer)</param>
        /// <param name="mod">The mod and folder name, in the following format: Mod Title (mod_folder)</param>
        /// <param name="launcher">An instance of the Source SDK lib</param>
        /// <returns></returns>
        public static List <string> GetAssets(string relativePath, Game game, Mod mod, Launcher launcher)
        {
            if (string.IsNullOrEmpty(relativePath) || game == null || mod == null || launcher == null)
            {
                return(null);
            }

            List <string> assets      = new List <string>();
            List <string> searchPaths = mod.GetSearchPaths();

            foreach (string searchPath in searchPaths)
            {
                string particlePath = searchPath + "\\" + relativePath;

                if (!File.Exists(particlePath))
                {
                    continue;
                }

                List <string> materials = GetMaterials(particlePath);
                foreach (string material in materials)
                {
                    assets.Add(material.Replace("\\", "/"));
                    assets.AddRange(VMT.GetAssets(material, game, mod, launcher));
                }

                break;
            }

            return(assets);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a list of the relative paths of the assets used by this asset, excluding the model itself
        /// </summary>
        /// <param name="relativePath">Path of the asset relative to the mod folder</param>
        /// <param name="game">The base game name (i.e. Source SDK Base 2013 Singleplayer)</param>
        /// <param name="mod">The mod and folder name, in the following format: Mod Title (mod_folder)</param>
        /// <param name="launcher">An instance of the Source SDK lib</param>
        /// <returns></returns>
        public static List <string> GetAssets(string relativePath, Game game, Mod mod, Launcher launcher)
        {
            if (string.IsNullOrEmpty(relativePath) || game == null || mod == null || launcher == null)
            {
                return(null);
            }

            List <string> assets      = new List <string>();
            List <string> searchPaths = mod.GetSearchPaths();

            foreach (string searchPath in searchPaths)
            {
                string modelPath = searchPath + "\\" + relativePath;

                // Check if the model exists in the current search path.
                if (!File.Exists(modelPath))
                {
                    continue;
                }

                string directory = Path.GetDirectoryName(modelPath);
                string modelName = Path.GetFileNameWithoutExtension(modelPath).ToLower();

                // Search for files with the same name as the model, but with different extensions
                foreach (string file in Directory.GetFiles(directory))
                {
                    string fileName = Path.GetFileName(file.ToLower());
                    if (fileName.Substring(0, fileName.IndexOf(".")) == modelName)
                    {
                        string filePath = relativePath.Replace(modelName + ".mdl", string.Empty) + fileName;
                        assets.Add(filePath);
                    }
                }

                // Search for materials used by the model
                List <string> materials = GetMaterials(modelPath);
                foreach (string material in materials)
                {
                    assets.Add(material.Replace("\\", "/"));
                    assets.AddRange(VMT.GetAssets(material, game, mod, launcher));
                }

                break;
            }

            return(assets);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a list of the relative paths of the assets used by this asset, including the bsp
        /// </summary>
        /// <param name="fullPath">Full path to the asset</param>
        /// <param name="game">The base game name (i.e. Source SDK Base 2013 Singleplayer)</param>
        /// <param name="mod">The mod and folder name, in the following format: Mod Title (mod_folder)</param>
        /// <param name="launcher">An instance of the Source SDK lib</param>
        /// <returns></returns>
        public static List <string> GetAssets(string fullPath, Game game, Mod mod, Launcher launcher)
        {
            if (string.IsNullOrEmpty(fullPath) ||
                game == null ||
                mod == null ||
                launcher == null)
            {
                return(null);
            }

            List <string> assets = new List <string>();

            SourceSDK.KeyValue map = SourceSDK.KeyValue.readChunkfile(fullPath, false);

            // Add maps assets
            String mapName = Path.GetFileNameWithoutExtension(fullPath).ToLower();

            assets.Add("maps/" + mapName + ".bsp");

            // Add material assets
            List <SourceSDK.KeyValue> materials = map.findChildrenByKey("material");

            foreach (SourceSDK.KeyValue kv in materials)
            {
                string value = "materials/" + kv.getValue().ToLower() + ".vmt";
                if (!assets.Contains(value))
                {
                    assets.Add(value);
                    assets.AddRange(VMT.GetAssets(value, game, mod, launcher));
                }
            }

            // Add model and sprite assets
            List <SourceSDK.KeyValue> models = map.findChildrenByKey("model");

            foreach (SourceSDK.KeyValue kv in models)
            {
                string value = kv.getValue().ToLower();
                if (!assets.Contains(value))
                {
                    assets.Add(kv.getValue().ToLower());
                    assets.AddRange(MDL.GetAssets(value, game, mod, launcher));
                }
            }

            // Add sound assets
            List <SourceSDK.KeyValue> sounds = map.findChildrenByKey("message");

            foreach (SourceSDK.KeyValue kv in sounds)
            {
                string value = kv.getValue().ToLower();
                if ((value.EndsWith(".wav") || value.EndsWith(".mp3")) && !assets.Contains(value))
                {
                    string v = kv.getValue().ToLower();
                    if (v.StartsWith("#"))
                    {
                        v = v.Substring(1);
                    }
                    assets.Add("sound/" + v);
                }
            }

            // Add particle assets
            List <SourceSDK.KeyValue> effectsKVs = map.findChildrenByKey("effect_name");
            List <string>             effects    = new List <string>();
            List <string>             pcfFiles   = PCF.GetAllFiles(launcher);

            foreach (SourceSDK.KeyValue kv in effectsKVs)
            {
                effects.Add(kv.getValue());
            }
            effects = effects.Distinct().ToList();
            foreach (string pcf in pcfFiles)
            {
                if (PCF.ContainsEffect(effects, pcf))
                {
                    string asset = pcf.Substring(pcf.IndexOf("\\particles\\") + 1).Replace("\\", "/");
                    assets.Add(asset);
                    assets.AddRange(PCF.GetAssets(asset, game, mod, launcher));
                }
            }

            // Add skybox
            SourceSDK.KeyValue skybox = map.findChildByKey("skyname");
            if (skybox != null)
            {
                string value = skybox.getValue().ToLower();

                string[] parts = new string[] { "up", "dn", "lf", "rt", "ft", "bk" };
                foreach (string part in parts)
                {
                    assets.Add("materials/skybox/" + value + part + ".vmt");
                    VMT.GetAssets("materials/skybox/" + value + part + ".vmt", game, mod, launcher);
                }
            }

            assets = assets.Distinct().ToList();

            return(assets);
        }