public List <string> GetWorldGeoMaterials(VMF myVMF) { var materialsused = new List <string>(); foreach (var brush in myVMF.World.Body) { if (brush.Name == "solid") // If we find the name solid, that means that its a brush { var thisblock = (VBlock)brush; foreach (var side in thisblock.Body) { if (side.Name == "side") { var thisside = (VBlock)side; foreach (var plane in thisside.Body) { if (plane.Name == "material") { var thisname = (VProperty)plane; if (!materialsused.Contains(thisname.Value)) { materialsused.Add(thisname.Value); } } } } } } } return(materialsused); }
private List <string> getAssetsFromMap(string fullPath) { setStatusMessage("Reading VMF " + fullPath, COLOR_ORANGE); assets = VMF.GetAssets(fullPath, game, mod, launcher); return(assets); }
static void BuildInstanceTree(Dictionary <int, Tuple <string, List <int> > > tree, int maxDepth, int currentDepth, VMF vmf, string vmfPath, int currentID, string mapsRoot) { // Add entry var links = new List <int>(); tree.Add(currentID, Tuple.Create(vmfPath, links)); if (currentDepth > maxDepth) { return; } // Identify subInstances var subInstancePaths = vmf.Body .Where(node => node.Name == "entity" && node is VBlock && (node as VBlock).HasPropertyWithKeyValue("classname", "func_instance")) .Cast <VBlock>() .Select(instance => instance.GetPropertyWithKey("file").Value); foreach (var subInstancepath in subInstancePaths) { // Clean subInstancePath and use absolute path string subInstanceAbsolutePath = Path.Combine(mapsRoot, subInstancepath).ToLower(); // Check if this instance path exists already in the dictionary, if it does set that to be the subInstanceID int subInstanceID; var existingEntry = tree.Values.Where(t => t.Item1 == subInstanceAbsolutePath).FirstOrDefault(); if (existingEntry != null) { subInstanceID = tree.Where(kvp => kvp.Value == existingEntry).FirstOrDefault().Key; } else { subInstanceID = BuildInstanceDictionaryKeyIndex++; } // Add link from currentID to subInstanceID if (!links.Contains(subInstanceID)) { links.Add(subInstanceID); } // Handle when instance file doesn't exist if (!File.Exists(subInstanceAbsolutePath)) { Console.WriteLine("file not found: \"{0}\"", subInstanceAbsolutePath); throw new Exception("Missing Instance"); //TODO: Create unique exception } // Load instance VMF subInstance = new VMF(File.ReadAllLines(subInstanceAbsolutePath)); // Recurse to get the rest of the instance tree BuildInstanceTree(tree, maxDepth, currentDepth + 1, subInstance, subInstanceAbsolutePath, subInstanceID, mapsRoot); } }
public List <VBlock> GetEntityList(VMF myVMF) { var entities = new List <VBlock>(); foreach (var entity in myVMF.Body) { if (entity.Name == "entity") { var thisentity = (VBlock)entity; entities.Add(thisentity); } } return(entities); }
public VMFAdapter(string filename, int horizontal_scale = 64, int vertical_scale = 64, NailsConfig config = null) { this.Config = config; if (Config == null) { Config = new NailsConfig(); } this._filename = filename; this._horizontal_scale = horizontal_scale; this._vertical_scale = vertical_scale; this._vmf = new VMF(); // Blank VMF in case export is called before input }
/// <summary> /// Setup the bounds of the world /// </summary> /// <param name="StartX"></param> /// <param name="StartZ"></param> /// <param name="EndX"></param> /// <param name="EndZ"></param> /// <param name="TopY"></param> /// <param name="BottomY"></param> public static void SetWorldBounds(int StartX, int StartZ, int EndX, int EndZ, int TopY, int BottomY) { //Start VMF shell file valveMapFile = ValardMapFormatConverter.VMFConverter.SetupBasicVFM(); //Start should be smaller if (StartX > EndX) { xStart = EndX; xEnd = StartX; } else { xStart = StartX; xEnd = EndX; } //Start should be smaller if (StartZ > EndZ) { zStart = EndZ; zEnd = StartZ; } else { zStart = StartZ; zEnd = EndZ; } //Bottom should be smaller if (BottomY > yTop) { yTop = BottomY; yBottom = TopY; } else { yTop = TopY; yBottom = BottomY; } xOffset = xStart * -1; yOffset = yBottom * -1; zOffset = zStart * -1; yTopOff = yTop + yOffset; xEndOff = xEnd + xOffset; zEndOff = zEnd + zOffset; }
private static void insertInstanceIntoVMF(instanceData instance, VMF output_vmf) { try { IList <int> list = null; VBlock instance_block = new VBlock("entity"); instance_block.Body.Add(new VProperty("id", instance.ent_id.ToString())); instance_block.Body.Add(new VProperty("classname", "func_instance")); instance_block.Body.Add(new VProperty("angles", "0 " + instance.rotation + " 0")); instance_block.Body.Add(new VProperty("origin", instance.xpos + " " + instance.ypos + " " + instance.zpos)); instance_block.Body.Add(new VProperty("file", instance.filename)); output_vmf.Body.Add(instance_block); } catch (Exception e) { log.Error("VMFAdapter.insertInstanceIntoVMF(): Caught exception: ", e); log.Info(string.Format("Failed to insert instance: {0}", instance.filename)); } }
static void Main(string[] args) { #if DEBUG var vmfPath = Path.GetFullPath(@".\..\..\Tests\dev_room.vmf"); var configPath = Path.GetFullPath(@".\..\..\Tests\remotecompile.cfg"); #else var vmfPath = "path.vmf"; var configPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "remotecompile.cfg"); #endif //TODO: Take parameter of map to compile //TODO: Take parameter of maps root path for instances // Temporarily use vmf location var mapsRoot = Path.GetDirectoryName(vmfPath); //TODO: Take optional parameter of config file path //TODO: Load local config file, if it doesn't exist, create a default one Config config; if (File.Exists(configPath)) { //TODO: Load config } else { #region Create default config config = new Config(new List <IVNode> { new VBlock("RemoteCompileConfig", new List <IVNode> { new VBlock("BuildServer", new List <IVNode> { new VProperty("Address", "127.0.0.1") , new VProperty("Port", "9043") , new VProperty("Username", "") , new VProperty("Password", "") , new VBlock("AuthLock", new List <IVNode> { new VProperty("Token", "") , new VProperty("Expires", "") }) }) , new VProperty("BuildTarget", "Source SDK 2013") //TODO: Add all available VBSP, VVIS, VRAD parameters , new VBlock("VBSP", new List <IVNode> { new VProperty("", "") }) , new VBlock("VVIS", new List <IVNode> { new VProperty("", "") }) , new VBlock("VRAD", new List <IVNode> { new VProperty("", "") }) }) }); File.WriteAllLines(configPath, config.ToVMFStrings()); #endregion } // Load VMF if (!File.Exists(vmfPath)) { // Early exit Console.WriteLine("Map does not exist \"{0}\"", vmfPath); return; } var vmfFileContents = File.ReadAllLines(vmfPath); var vmf = new VMF(vmfFileContents); // Recursively identify and load dependent instances // Track instance dependency tree to recognize instance recursion // Only dig 100 levels deep unless otherwise specified in the config var instanceTree = new Dictionary <int, Tuple <string, List <int> > >(); BuildInstanceTree(instanceTree, 100, 0, vmf, vmfPath, BuildInstanceDictionaryKeyIndex++, mapsRoot); //TODO: Make sure there is no recursion in the instanceTree //TODO: Request hashes of all dependent resources from server. // Compare results to local copies. // Notify user of the comparison //TODO: Send compile request with serialized parameters, and list of incoming resources //TODO: Send copy of vmf and instances to server //TODO: Spin off waiting thread for server to execute OnCompleteBuild commands // This could include: downloading the map, and running the game }
/** * Imports a VMF file to create a NailsMap. Uses the file name passed in when this adapter was constructed. * <author>1upD</author> * TODO Add more error checking */ public NailsMap Import() { try { // Reset adapter VMF this._vmf = new VMF(); NailsMap map = new NailsMap(); List <string> lines = new List <string>(); using (StreamReader sr = new StreamReader(new FileStream(this._filename, FileMode.OpenOrCreate))) { while (!sr.EndOfStream) { lines.Add(sr.ReadLine()); } } VMF input_vmf = new VMF(lines.ToArray()); for (int blockIndex = 0; blockIndex < input_vmf.Body.Count; blockIndex++) { // Should this object be included when the VMF is output? bool includeThisBlock = true; // Get the next object from the VMF var obj = input_vmf.Body[blockIndex]; try { // Try to cast to block VMFParser.VBlock block = (VMFParser.VBlock)obj; // If this block is an entity if (block.Name == "entity") { var body = block.Body; foreach (var innerObj in body) { try { VMFParser.VProperty prop = (VMFParser.VProperty)innerObj; // If this block is an instance if (prop.Name == "classname" && prop.Value == "func_instance") { VProperty fileProperty = (VProperty)body.Where(p => p.Name == "file").ToList()[0]; var filePathParts = fileProperty.Value.Split('/'); // If this is a nails instance if (filePathParts[0] == "Nails") { // Get position VProperty originProperty = (VProperty)body.Where(p => p.Name == "origin").ToList()[0]; var originParts = originProperty.Value.Split(' '); int x_pos = int.Parse(originParts[0]) / this._horizontal_scale; int y_pos = int.Parse(originParts[1]) / this._horizontal_scale; int z_pos = int.Parse(originParts[2]) / this._vertical_scale; string style = filePathParts[1]; map.MarkLocation(style, x_pos, y_pos, z_pos); // Remove this block from the vmf includeThisBlock = false; } break; } } catch (InvalidCastException e) { log.Error("Invalid cast exception. VMF Object is not a VProperty.", e); } } } } catch (InvalidCastException e) { log.Error("Invalid cast exception. VMF object is not a VBlock.", e); } // If this object is not a Nails block, add it to the adapter's VMF to be output later if (includeThisBlock) { this._vmf.Body.Add(obj); } } return(map); } catch (Exception e) { log.Error("VMFAdapter.Import(): Caught exception: ", e); log.Info(string.Format("Failed to read from VMF file: {0}", this._filename)); } return(null); }
static void Main(string[] args) { Console.WriteLine("Squidski's Source 1 -> Source 2 Project Environment Creator"); // Create json if it doesn't exist, and load json into memory if it does. JSONInit(); // If any of the paths in paths.json are invalid, stop the program. if (!File.Exists(Paths.game_info) || !Directory.Exists(Paths.game_path) || !Directory.Exists(Paths.main_path) || !File.Exists(Paths.pak_dir) || !File.Exists(Paths.vpk_exe)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("One or more of the paths in paths.json are invalid!"); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); // Close. Environment.Exit(0) also tells the operating system the program was closed normally and didn't just crash. Environment.Exit(0); } Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); if (args.Length < 1) { Console.WriteLine("No parameters provided"); Console.ReadKey(); Environment.Exit(1); } Console.WriteLine("Parsing VMF..."); string[] vmftext = File.ReadAllLines(args[0]); var userVMF = new VMF(vmftext); Console.WriteLine("VMF Successfully Parsed!"); var entityUtil = new EntityUtil(); Console.WriteLine("Reading entities..."); var S1entityListinVMF = entityUtil.GetEntityList(userVMF); Console.WriteLine($"Found {S1entityListinVMF.Count} entities in VMF"); Console.WriteLine("Getting list of prop models..."); var S1propModelListinVMF = entityUtil.GetPropModelList(S1entityListinVMF); Console.WriteLine($"Found {S1propModelListinVMF.Count} unique prop models in VMF"); Console.WriteLine("Getting list of decal materials..."); var S1decalMaterialListinVMF = entityUtil.GetDecalMaterialList(S1entityListinVMF); Console.WriteLine($"Found {S1decalMaterialListinVMF.Count} decal materials in VMF"); Console.WriteLine("Getting list of overlay materials..."); var S1overlayMaterialListinVMF = entityUtil.GetOverlayMaterialList(S1entityListinVMF); Console.WriteLine($"Found {S1overlayMaterialListinVMF.Count} overlay materials in VMF"); Console.WriteLine("Getting list of materials used on brush entities..."); var S1brushEntityMaterialListinVMF = entityUtil.GetBrushEntityMaterialList(S1entityListinVMF); Console.WriteLine($"Found {S1brushEntityMaterialListinVMF.Count} materials used on brush entities in VMF"); var materialReader = new MaterialReader(); Console.WriteLine("Reading materials used on world geometry..."); var S1brushMaterialsinVMF = materialReader.GetWorldGeoMaterials(userVMF); Console.WriteLine($"Found {S1brushMaterialsinVMF.Count} materials used on world geometry in VMF"); Console.WriteLine("Combining material lists..."); var S1usedMaterialsNoModels = materialReader.CombineMaterials(S1decalMaterialListinVMF, S1overlayMaterialListinVMF, S1brushEntityMaterialListinVMF, S1brushMaterialsinVMF); Console.WriteLine($"Found {S1usedMaterialsNoModels.Count} unique materials (excluding models)"); Console.WriteLine("Getting asset information from VPK..."); var vpk = new VPK_Reader(); Console.WriteLine($"Successfully retrieved information on {vpk.VPK_OUTPUT.Count} assets inside VPK"); Console.WriteLine("Finding decal, overlay, and brush textures used that are included in VPK..."); var S1materialsInVPKNoModels = vpk.GetMaterialsUsedInVPK(S1usedMaterialsNoModels); Console.WriteLine($"Found {S1materialsInVPKNoModels.Count} materials (Missing {S1usedMaterialsNoModels.Count - S1materialsInVPKNoModels.Count})"); Console.WriteLine("Finding models used that are included in the VPK..."); var S1modelsInVPK = vpk.GetModelsUsedInVPK(S1propModelListinVMF); Console.WriteLine($"Found {S1modelsInVPK.Count} models (Missing {S1propModelListinVMF.Count - S1modelsInVPK.Count})"); Console.WriteLine("Reading gameinfo.txt for additional searchpaths..."); var gameinfo = new GameInfo(); Console.WriteLine($"Found {gameinfo.SearchPaths.Count} additional searchpaths"); Console.WriteLine("Scanning searchpaths for additional assets..."); var S1modelsNotInVPK = GetListDifference(S1propModelListinVMF, S1modelsInVPK); var S1materialsNotInVPK = GetListDifference(S1usedMaterialsNoModels, S1materialsInVPKNoModels, true); var searchPathInfo = new SearchPathInfo(gameinfo.SearchPaths, S1modelsNotInVPK, S1materialsNotInVPK); Console.WriteLine($"Found {searchPathInfo.SearchPathFindingsMaterials.Count} Materials and {searchPathInfo.SearchPathFindingsModels.Count} Models in SearchPaths"); if (S1materialsNotInVPK.Count - searchPathInfo.SearchPathFindingsMaterials.Count != 0) { Console.WriteLine($"Missing {S1materialsNotInVPK.Count - searchPathInfo.SearchPathFindingsMaterials.Count} materials after all searches"); } if (S1modelsNotInVPK.Count - searchPathInfo.SearchPathFindingsModels.Count != 0) { Console.WriteLine($"Missing {S1modelsNotInVPK.Count - searchPathInfo.SearchPathFindingsModels.Count} models after all searches"); } Console.WriteLine("Creating project directory structure..."); Directory.CreateDirectory("source2/models"); Directory.CreateDirectory("source2/materials"); Console.WriteLine("Project directory structure sucessfully created!"); Console.WriteLine("Getting materials from VPK"); int materialsExtracted = vpk.GrabMaterialsFromVPK(S1materialsInVPKNoModels); Console.WriteLine($"{materialsExtracted} materials extracted successfully!"); Console.WriteLine("Getting textures from materials"); vpk.GrabTexturesFromMaterials(); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; Console.WriteLine($"Completed in {ts.Seconds}.{ts.Milliseconds} seconds"); Console.ReadKey(); }
static void Main(string[] args) { var oldVMFFilePath = string.Empty; var newVMFFilePath = string.Empty; var p = new OptionSet() { { "o|old=", v => { oldVMFFilePath = v; } } , { "n|new=", v => { newVMFFilePath = v; } } }; var extra = p.Parse(args); #if DEBUG oldVMFFilePath = "../../Test/test_2p.vmf"; newVMFFilePath = "../../Test/test_2p_alt.vmf"; #endif if (!File.Exists(oldVMFFilePath) || !File.Exists(newVMFFilePath)) { //exit return; } var oldVMF = new VMF(File.ReadAllLines(oldVMFFilePath)); var newVMF = new VMF(File.ReadAllLines(newVMFFilePath)); var outVMF = new VMF(); var oldWorld = oldVMF.Body.Where(node => node.Name == "world").Where(node => node is VBlock).Cast <VBlock>().FirstOrDefault(); var newWorld = newVMF.Body.Where(node => node.Name == "world").Where(node => node is VBlock).Cast <VBlock>().FirstOrDefault(); //should totally use a dictionary instead var oldEntitiesList = oldVMF.Body.Where(node => node.Name == "entity").Where(node => node is VBlock).Cast <VBlock>().Select(block => Tuple.Create(block.Body.Where(property => property.Name == "id" && property is VProperty).Cast <VProperty>().FirstOrDefault()?.Value ?? "0", block)).ToList(); var newEntitiesList = newVMF.Body.Where(node => node.Name == "entity").Where(node => node is VBlock).Cast <VBlock>().Select(block => Tuple.Create(block.Body.Where(property => property.Name == "id" && property is VProperty).Cast <VProperty>().FirstOrDefault()?.Value ?? "0", block)).ToList(); //copy oldVMF outVMF = new VMF(oldVMF.ToVMFStrings()); //remove all the entities outVMF = new VMF(outVMF.Body.Where(node => node.Name != "entity").ToList()); //find the world var outWorldIndex = outVMF.Body.IndexOf(outVMF.Body.Where(node => node.Name == "world").Where(node => node is VBlock).Cast <VBlock>().FirstOrDefault()); //make a new one var outNewWorld = (outVMF.Body[outWorldIndex] as VBlock).Body.Where(node => node.Name != "solid").ToList(); //swap it in outVMF.Body[outWorldIndex] = new VBlock("world", outNewWorld); //don't include any duplicate IDs in the diffing process var entitiesNewDuplicateID = newEntitiesList.Where(newEntityTuple1 => newEntitiesList.Where(newEntityTuple2 => newEntityTuple1.Item1 == newEntityTuple2.Item1).Count() > 1).ToList(); var entitiesOldDuplicateID = oldEntitiesList.Where(oldEntityTuple1 => oldEntitiesList.Where(oldEntityTuple2 => oldEntityTuple1.Item1 == oldEntityTuple2.Item1).Count() > 1).ToList(); newEntitiesList.RemoveAll(entityTuple => entitiesNewDuplicateID.Where(duplicate => duplicate == entityTuple).Count() > 0); oldEntitiesList.RemoveAll(entityTuple => entitiesOldDuplicateID.Where(duplicate => duplicate == entityTuple).Count() > 0); var entitiesRemoved = oldEntitiesList.Where(oldEntityTuple => newEntitiesList.Where(newEntityTuple => newEntityTuple.Item1 == oldEntityTuple.Item1).Count() == 0).ToList(); var entitiesAdded = newEntitiesList.Where(newEntityTuple => oldEntitiesList.Where(oldEntityTuple => newEntityTuple.Item1 == oldEntityTuple.Item1).Count() == 0).ToList(); var entitiesOldRemaining = oldEntitiesList.Where(oldEntityTuple => newEntitiesList.Where(newEntityTuple => newEntityTuple.Item1 == oldEntityTuple.Item1).Count() > 0).ToList(); var entitiesNewRemaining = newEntitiesList.Where(newEntityTuple => oldEntitiesList.Where(oldEntityTuple => newEntityTuple.Item1 == oldEntityTuple.Item1).Count() > 0).ToList(); var entitiesNoChange = new List <Tuple <string, VBlock> >(); var entitiesOldChange = new List <Tuple <string, VBlock> >(); var entitiesNewChange = new List <Tuple <string, VBlock> >(); foreach (var oldEntityTuple in entitiesOldRemaining) { var newEntityTuple = entitiesNewRemaining.Where(newEntTuple => newEntTuple.Item1 == oldEntityTuple.Item1).FirstOrDefault(); if (VBlockMatches(oldEntityTuple.Item2, newEntityTuple.Item2)) { entitiesNoChange.Add(oldEntityTuple); } else { entitiesOldChange.Add(oldEntityTuple); entitiesNewChange.Add(newEntityTuple); } } //TODO: Include solids in the above diff checking, and separate them out when generating final VMF //set mapversion to 1 //iterate through world find differences, add to outWorld and visgroups //iterate through the rest of the entities and do the same File.WriteAllLines("diff.vmf", outVMF.ToVMFStrings()); }
static int CollapseInstances(VMF vmf) { #region Identify useable IDs int usableID = vmf.Body.GetHighestID() + 1; #endregion var world = vmf.Body.Where(node => node.Name == "world").Where(node => node is VBlock).Cast <VBlock>().FirstOrDefault(); if (world == null) { Console.WriteLine("Can't find \"world\""); return(-1); } int lastEntityLocation = 0; lastEntityLocation = vmf.Body.IndexOf(world) + vmf.Body.Where(node => node.Name == "entity").Count(); int autoInstance = 0; var entities = vmf.Body.Where(item => item.Name == "entity").Select(item => item as VBlock).ToList(); var instances = entities.Where(entity => entity.Body.Where(item => item.Name == "classname" && (item as VProperty).Value == "func_instance").Count() > 0).ToList(); foreach (var instance in instances) { // Get instance targetname string instanceTargetName = ""; var instanceTargetNameProperty = instance.Body.Where(node => node.Name == "targetname" && node.GetType() == typeof(VProperty)).Select(node => node as VProperty).FirstOrDefault(); if ((instanceTargetNameProperty?.Value ?? "") == "") { instanceTargetName = String.Format("AutoInstance{0}", autoInstance++); } // TODO: Give it a default name if unnamed (or not?). // Load the instance vmf var fileProp = instance.Body.Where(node => node.Name == "file" && node.GetType() == typeof(VProperty)).Select(node => node as VProperty).FirstOrDefault(); if (fileProp == null || string.IsNullOrEmpty(fileProp.Value.Trim())) { // Looks like there is no file property, or its empty continue; } if (!File.Exists(fileProp.Value)) { // TODO: What do you do when the file doesn't exist? Probably should throw up some sort of error. // Just skip it for now. continue; } var instanceVMF = new VMF(File.ReadAllLines(fileProp.Value)); // Clone the important parts // TODO: think about collapsing groups // TODO: only grab visible entities var instanceVisibleEntities = instanceVMF.Body.Where(node => node.Name == "entity").Where(node => node is VBlock).Cast <VBlock>(); var instanceVisibleSolids = instanceVMF.Body.Where(node => node.Name == "world").Where(node => node is VBlock).Cast <VBlock>() .SelectMany(node => node.Body.Where(worldNode => worldNode.Name == "solid").Where(worldNode => worldNode is VBlock).Cast <VBlock>() ); // Update each entity into the map with relative offsets and angles from the instance point, and the instance origin (defaults at 0 0 0) // angles and origin var instanceOriginProperty = instance.Body.Where(node => node.Name == "origin" && node.GetType() == typeof(VProperty)).Select(node => node as VProperty).FirstOrDefault(); var instanceAnglesProperty = instance.Body.Where(node => node.Name == "angles" && node.GetType() == typeof(VProperty)).Select(node => node as VProperty).FirstOrDefault(); var instanceOrigin = new Vector3(instanceOriginProperty?.Value ?? "0 0 0"); var instanceAngles = new Vector3(instanceAnglesProperty?.Value ?? "0 0 0"); var fixupStyle = int.Parse(instance.Body.Where(node => node.Name == "fixup_style" && node.GetType() == typeof(VProperty)).Select(node => node as VProperty).FirstOrDefault()?.Value ?? "0"); foreach (var entity in instanceVisibleEntities) { VBlock collapsedEntity = CollapseEntity(entity, fixupStyle, instanceTargetName, instanceOrigin, instanceAngles, ref usableID); vmf.Body.Insert(lastEntityLocation++, collapsedEntity); } foreach (var solid in instanceVisibleSolids) { VBlock collapsedSolid = CollapseSolid(solid, ref usableID); world.Body.Add(collapsedSolid); } // Rename all internal communication // Link external IO // Replace replaceable parameters // Replace replaceable materials // Insert into actual map // Remove instance from map vmf.Body.Remove(instance); } return(0); }
static int Main(string[] args) { #if DEBUG //args = new string[] { "-file", "dev_room.vmf" }; args = new string[] { "-file", "1_instance.vmf" }; Utils.DirectoryCopy(@"../../instances", "instances", true, true); #endif #if !DEBUG try { #endif #region Get execution parameters string filePath = null; string gamePath = null; for (int i = 0; i < args.Length; i++) { if (args[i] == "-file" && i + 1 < args.Length && !args[i + 1].StartsWith("-")) { filePath = args[++i]; } else if (args[i] == "-game" && i + 1 < args.Length && !args[i + 1].StartsWith("-")) { gamePath = args[++i]; //does this matter, or should I use the vmfs path to find the instances } // else if // Add additional parameters here } if (filePath == null) { Console.ForegroundColor = ConsoleColor.Red; return(1); } #endregion #region Load VMF Console.Write("Loading file contents from \"" + filePath + "\"..."); string[] fileContents = File.ReadAllLines(filePath); Console.WriteLine("Complete."); Console.Write("Parsing vmf "); VMF vmf = new VMF(fileContents); #endregion CollapseInstances(vmf); #region Save Altered VMF string newFilePath = ""; newFilePath = filePath.EndsWith(".vmf") ? filePath.Insert(filePath.LastIndexOf("."), "_new") : filePath + "_new"; File.WriteAllLines(newFilePath, vmf.ToVMFStrings()); #endregion #if !DEBUG } #region catch - display exception catch (Exception ex) { WriteLine("Exception:", ConsoleColor.Yellow); WriteLine(ex.ToString(), ConsoleColor.Red); return(1); } #endregion #endif return(0); }
private void GenerateAssetsList(VMF vmf) { List <string> Assets = new List <string>(); Thread mThread = new Thread(delegate() { //Generate Filter if (!File.Exists(FILTER_FILE_PATH)) { createFilter(); } if (cb_IgnoreFilter.Checked) { FILTER_LIST = new List <string>(); using (var sr = new StreamReader(FILTER_FILE_PATH)) { string l; while ((l = sr.ReadLine()) != null) { FILTER_LIST.Add(l); } sr.Close(); } } else { FILTER_LIST = new List <string>(); } foreach (string srcFile in vmf.GetModels()) { if (!FILTER_LIST.Contains(Path.GetFileName(srcFile).ToLower())) { //Look for files that can be overriden by sources string overridefilenoExtension = ""; foreach (string SOURCE in srcDirs) { if (File.Exists(SOURCE + "\\" + srcFile)) { overridefilenoExtension = Path.GetDirectoryName(SOURCE + "\\" + srcFile) + "\\" + Path.GetFileNameWithoutExtension(SOURCE + "\\" + srcFile); } } string MDL_EXT = ".mdl"; if (File.Exists(overridefilenoExtension + MDL_EXT)) // If the mdl file doesn't exist then there's no reason to look for it's additional files { Assets.Add(overridefilenoExtension + MDL_EXT); string EXTENSION = ".mdl"; if (cb_sw.Checked) { EXTENSION = ".sw.vtx"; if (File.Exists(overridefilenoExtension + EXTENSION))//.sw.vtx { Assets.Add(overridefilenoExtension + EXTENSION); } else { this.Invoke(new MethodInvoker(delegate() { Log("Missing " + EXTENSION + " for " + Path.GetFileName(overridefilenoExtension + MDL_EXT)); })); } } if (cb_dx80.Checked) { EXTENSION = ".dx80.vtx"; if (File.Exists(overridefilenoExtension + EXTENSION))//.dx80.vtx { Assets.Add(overridefilenoExtension + EXTENSION); } else { this.Invoke(new MethodInvoker(delegate() { Log("Missing " + EXTENSION + " for " + Path.GetFileName(overridefilenoExtension + MDL_EXT)); })); } } if (cb_dx90.Checked) { EXTENSION = ".dx90.vtx"; if (File.Exists(overridefilenoExtension + EXTENSION))//.dx90.vtx { Assets.Add(overridefilenoExtension + EXTENSION); } else { this.Invoke(new MethodInvoker(delegate() { Log("Missing " + EXTENSION + " for " + Path.GetFileName(overridefilenoExtension + MDL_EXT)); })); } } if (cb_phy.Checked) { EXTENSION = ".phy"; if (File.Exists(overridefilenoExtension + EXTENSION))//.phy { Assets.Add(overridefilenoExtension + EXTENSION); } else { this.Invoke(new MethodInvoker(delegate() { Log("Missing " + EXTENSION + " for " + Path.GetFileName(overridefilenoExtension + MDL_EXT)); })); } } if (cb_ani.Checked) { EXTENSION = ".ani"; if (File.Exists(overridefilenoExtension + EXTENSION))//.ani { Assets.Add(overridefilenoExtension + EXTENSION); } else { this.Invoke(new MethodInvoker(delegate() { Log("Missing " + EXTENSION + " for " + Path.GetFileName(overridefilenoExtension + MDL_EXT)); })); } } if (cb_vvd.Checked) { EXTENSION = ".vvd"; if (File.Exists(overridefilenoExtension + EXTENSION))//.vvd { Assets.Add(overridefilenoExtension + EXTENSION); } else { this.Invoke(new MethodInvoker(delegate() { Log("Missing " + EXTENSION + " for " + Path.GetFileName(overridefilenoExtension + MDL_EXT)); })); } } } } else { this.Invoke(new MethodInvoker(delegate() { Log("Filtered " + Path.GetFileName(srcFile).ToLower()); })); } } foreach (string srcFile in vmf.GetMaterials()) { if (!FILTER_LIST.Contains(Path.GetFileName(srcFile).ToLower())) { string overridefile = ""; foreach (string SOURCE in srcDirs) { if (File.Exists(SOURCE + "\\" + srcFile)) { overridefile = SOURCE + "\\" + srcFile; } } if (overridefile != "") { Assets.Add(overridefile); } } else { this.Invoke(new MethodInvoker(delegate() { Log("Filtered " + Path.GetFileName(srcFile).ToLower()); })); } } foreach (string srcFile in vmf.GetTexture()) { if (!FILTER_LIST.Contains(Path.GetFileName(srcFile).ToLower())) { string overridefile = ""; foreach (string SOURCE in srcDirs) { if (File.Exists(SOURCE + "\\" + srcFile)) { overridefile = SOURCE + "\\" + srcFile; } } if (overridefile != "") { Assets.Add(overridefile); } } else { this.Invoke(new MethodInvoker(delegate() { Log("Filtered " + Path.GetFileName(srcFile).ToLower()); })); } } foreach (string srcFile in vmf.GetSounds()) { if (!FILTER_LIST.Contains(Path.GetFileName(srcFile).ToLower())) { string overridefile = ""; foreach (string SOURCE in srcDirs) { if (File.Exists(SOURCE + "\\" + srcFile)) { overridefile = SOURCE + "\\" + srcFile; } } if (overridefile != "") { Assets.Add(overridefile); } } else { this.Invoke(new MethodInvoker(delegate() { Log("Filtered " + Path.GetFileName(srcFile).ToLower()); })); } } if (!cb_use_bspzip.Checked) { CopyToOutput(Assets.ToArray()); } else { Usebspzip(Assets.ToArray()); } if (sear.MISSING_MODELS.Count != 0) { this.Invoke(new MethodInvoker(delegate() { Log("Missing Models: "); })); foreach (string MISSING in sear.MISSING_MODELS) { this.Invoke(new MethodInvoker(delegate() { Log(" " + MISSING); })); } } if (sear.MISSING_MATERIALS.Count != 0) { this.Invoke(new MethodInvoker(delegate() { Log("Missing Materials: "); })); foreach (string MISSING in sear.MISSING_MATERIALS) { this.Invoke(new MethodInvoker(delegate() { Log(" " + MISSING); })); } } if (sear.MISSING_TEXTURES.Count != 0) { this.Invoke(new MethodInvoker(delegate() { Log("Missing Textures: "); })); foreach (string MISSING in sear.MISSING_TEXTURES) { this.Invoke(new MethodInvoker(delegate() { Log(" " + MISSING); })); } } if (sear.MISSING_SOUNDS.Count != 0) { this.Invoke(new MethodInvoker(delegate() { Log("Missing Sounds: "); })); foreach (string MISSING in sear.MISSING_SOUNDS) { this.Invoke(new MethodInvoker(delegate() { Log(" " + MISSING); })); } } this.Invoke(new MethodInvoker(delegate() { Log("------------------------------------------------"); })); this.Invoke(new MethodInvoker(delegate() { Log("Done."); })); }); mThread.Start(); }