/// <summary> /// Returns a list of the relative paths of the assets used by this asset, excluding the asset 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 materialPath = searchPath + "\\" + relativePath; if (!File.Exists(materialPath)) { continue; } SourceSDK.KeyValue material = SourceSDK.KeyValue.readChunkfile(materialPath); List <SourceSDK.KeyValue> textures = new List <SourceSDK.KeyValue>(); textures.Add(material.getChildByKey("$basetexture")); textures.Add(material.getChildByKey("$detail")); textures.Add(material.getChildByKey("$blendmodulatetexture")); textures.Add(material.getChildByKey("$envmapmask")); textures.Add(material.getChildByKey("$bumpmap")); textures.Add(material.getChildByKey("$parallaxmap")); textures.Add(material.getChildByKey("$basetexture2")); textures.Add(material.getChildByKey("%tooltexture")); foreach (SourceSDK.KeyValue textureKv in textures) { if (textureKv == null) { continue; } string textureValue = "materials/" + textureKv.getValue().ToLower() + ".vtf"; if (!assets.Contains(textureValue)) { assets.Add(textureValue); } } break; } return(assets); }
private void SavePresets() { SourceSDK.KeyValue root = new SourceSDK.KeyValue("Presets"); foreach (RunPreset preset in presets) { SourceSDK.KeyValue presetKV = new SourceSDK.KeyValue(preset.name); presetKV.addChild("Name", preset.name); presetKV.addChild("Engine", preset.engine); presetKV.addChild("Game", preset.game); presetKV.addChild("Mod", preset.mod); presetKV.addChild("RunMode", RunMode.ToString(preset.runMode)); presetKV.addChild("Exe", preset.exePath); presetKV.addChild("Command", preset.command); root.addChild(preset.name, presetKV); } SourceSDK.KeyValue.writeChunkFile(PRESET_PATH, root); }
private void LoadPresets() { if (!File.Exists(PRESET_PATH) && File.Exists(PRESET_PATH.Replace(".cfg", "_default.cfg"))) { File.Copy(PRESET_PATH.Replace(".cfg", "_default.cfg"), PRESET_PATH); } SourceSDK.KeyValue root = SourceSDK.KeyValue.readChunkfile(PRESET_PATH); presets = new List <RunPreset>(); availablePresets = new List <RunPreset>(); presetCombo.Properties.Items.Clear(); foreach (SourceSDK.KeyValue kv in root.getChildren()) { RunPreset preset = new RunPreset(); preset.name = (kv.getValue("name") != string.Empty ? kv.getValue("name") : kv.getKey()); preset.engine = kv.getValue("engine"); preset.game = kv.getValue("game"); preset.mod = kv.getValue("mod"); preset.exePath = kv.getValue("exe"); preset.command = kv.getValue("command"); preset.runMode = RunMode.FromString(kv.findChildByKey("runmode").getValue()); presets.Add(preset); if ( (preset.mod == string.Empty || preset.mod == new DirectoryInfo(launcher.GetCurrentMod().installPath).Name) && (preset.game == string.Empty || preset.game == launcher.GetCurrentGame().name) && (preset.engine == string.Empty || preset.engine == Engine.ToString(launcher.GetCurrentGame().engine)) ) { availablePresets.Add(preset); } } updatePresetCombo(); }
/// <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); }