Exemple #1
0
        static CompileSpecification()
        {
            Specifications = new List <CompileSpecification>();
            var specFolder = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Specifications");

            if (Directory.Exists(specFolder))
            {
                foreach (var file in Directory.GetFiles(specFolder, "*.vdf"))
                {
                    try
                    {
                        var gs = GenericStructure.Parse(file);
                        foreach (var spec in gs.Where(x => x.Name == "Specification"))
                        {
                            Specifications.Add(Parse(spec));
                        }
                    }
                    catch
                    {
                        // Not a valid GS
                    }
                }
            }
            if (!Specifications.Any())
            {
                Specifications.Add(new CompileSpecification {
                    ID = "None", Name = "No Specifications Found"
                });
            }
        }
        public void TestParseMultiple()
        {
            var input =
                @"Test
                {
                    key value
                }
                Test2
                {
                    key2 value2
                }";
            var parsed = GenericStructure.Parse(new StringReader(input)).ToList();

            Assert.AreEqual(2, parsed.Count);
            Assert.AreEqual("Test", parsed[0].Name);
            CollectionAssert.AreEquivalent(new List <string> {
                "key"
            }, parsed[0].GetPropertyKeys().ToList());
            Assert.AreEqual("value", parsed[0]["key"]);
            Assert.AreEqual("Test2", parsed[1].Name);
            CollectionAssert.AreEquivalent(new List <string> {
                "key2"
            }, parsed[1].GetPropertyKeys().ToList());
            Assert.AreEqual("value2", parsed[1]["key2"]);
        }
        public void TestFirstLineNoWhitespace()
        {
            // Found in TF2: materials\ambulance\amb_red.vmt
            var input =
                @"""vertexlitgeneric"" {
                    ""$basetexture"" ""ambulance/amb_red""
                    ""$envmapmask"" ""ambulance/amb_spec""
                    ""$envmap"" ""env_cubemap""
                    ""$envmaptint"" ""[ 0.5020 0.5020 0.5020 ]""
                    ""$surfaceprop"" ""metal""
                }";
            var parsed = GenericStructure.Parse(new StringReader(input)).Single();

            Assert.AreEqual("vertexlitgeneric", parsed.Name);

            var keys = parsed.GetPropertyKeys().ToList();

            Assert.AreEqual(5, keys.Count);
            CollectionAssert.AreEquivalent(new List <string> {
                "$basetexture", "$envmapmask", "$envmap", "$envmaptint", "$surfaceprop"
            }, keys);

            Assert.AreEqual("ambulance/amb_red", parsed["$basetexture"]);
            Assert.AreEqual("ambulance/amb_spec", parsed["$envmapmask"]);
            Assert.AreEqual("env_cubemap", parsed["$envmap"]);
            Assert.AreEqual("[ 0.5020 0.5020 0.5020 ]", parsed["$envmaptint"]);
            Assert.AreEqual("metal", parsed["$surfaceprop"]);
        }
        public void TestParseWhitespace()
        {
            var input =
                @"

                Test

                {

                    key value



                }";
            var list = GenericStructure.Parse(new StringReader(input)).ToList();

            Assert.AreEqual(1, list.Count);
            var parsed = list[0];

            Assert.AreEqual("Test", parsed.Name);
            CollectionAssert.AreEquivalent(new List <string> {
                "key"
            }, parsed.GetPropertyKeys().ToList());
            Assert.AreEqual("value", parsed["key"]);
        }
Exemple #5
0
 private static IEnumerable <MapObject> ExtractCopyStream(Document document, string str)
 {
     using (var tr = new StringReader(str)) {
         try {
             var gs = GenericStructure.Parse(tr);
             return(VmfProvider.ExtractCopyStream(gs.FirstOrDefault(), document.Map.IDGenerator));
         } catch {
             return(null);
         }
     }
 }
        public void TestParseBasic()
        {
            var input =
                @"Test
                {
                    key value
                }";
            var parsed = GenericStructure.Parse(new StringReader(input)).First();

            Assert.AreEqual("Test", parsed.Name);
            CollectionAssert.AreEquivalent(new List <string> {
                "key"
            }, parsed.GetPropertyKeys().ToList());
            Assert.AreEqual("value", parsed["key"]);
        }
Exemple #7
0
 private static IEnumerable <MapObject> ExtractCopyStream(Document document, string str)
 {
     using (var tr = new StringReader(str))
     {
         try
         {
             var gs = GenericStructure.Parse(tr);
             return(VmfProvider.ExtractCopyStream(gs.FirstOrDefault(), document.Map.IDGenerator, document.Map.WorldSpawn.MetaData.Get <Dictionary <string, UInt32> >("EntityCounts")));
         }
         catch
         {
             return(null);
         }
     }
 }
Exemple #8
0
        public void TestMapObjectSerialisation()
        {
            // compare the *'s:
            // brush -> GS -> string* -> GS -> brush -> GS -> string*

            var brush        = new BlockBrush();
            var b            = brush.Create(new IDGenerator(), new Box(Coordinate.Zero, Coordinate.One * 100), null, 0);
            var serialised   = GenericStructure.Serialise(b);
            var toString     = serialised.ToString();
            var parsed       = GenericStructure.Parse(new StringReader(toString));
            var deserialised = GenericStructure.Deserialise <List <MapObject> >(parsed.First());
            var reserialised = GenericStructure.Serialise(deserialised);

            Assert.AreEqual(serialised.ToString(), reserialised.ToString());
        }
Exemple #9
0
        private static GenericStructure ReadSettingsFile()
        {
            if (File.Exists(SettingsFile))
            {
                return(GenericStructure.Parse(SettingsFile).FirstOrDefault());
            }

            var exec = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var path = Path.Combine(exec, "Settings.vdf");

            if (File.Exists(path))
            {
                return(GenericStructure.Parse(path).FirstOrDefault());
            }

            return(null);
        }
        public void TestParseQuotes()
        {
            var input =
                @"""Test Name""
                {
                    ""key"" ""value""
                    ""key with spaces"" ""value with spaces""
                }";
            var parsed = GenericStructure.Parse(new StringReader(input)).First();

            Assert.AreEqual("Test Name", parsed.Name);
            CollectionAssert.AreEquivalent(new List <string> {
                "key", "key with spaces"
            }, parsed.GetPropertyKeys().ToList());
            Assert.AreEqual("value", parsed["key"]);
            Assert.AreEqual("value with spaces", parsed["key with spaces"]);
        }
        public void TestParseChildren()
        {
            var input =
                @"Test
                {
                    key value
                    Child
                    {
                        key2 value2
                        Child2
                        {
                            key3 value3
                        }
                    }
                }";
            var parsed = GenericStructure.Parse(new StringReader(input)).First();

            Assert.AreEqual("Test", parsed.Name);
            CollectionAssert.AreEquivalent(new List <string> {
                "key"
            }, parsed.GetPropertyKeys().ToList());
            Assert.AreEqual("value", parsed["key"]);
            Assert.AreEqual(1, parsed.Children.Count);

            var child = parsed.Children.First();

            Assert.AreEqual("Child", child.Name);
            CollectionAssert.AreEquivalent(new List <string> {
                "key2"
            }, child.GetPropertyKeys().ToList());
            Assert.AreEqual("value2", child["key2"]);
            Assert.AreEqual(1, child.Children.Count);

            child = child.Children.First();
            Assert.AreEqual("Child2", child.Name);
            CollectionAssert.AreEquivalent(new List <string> {
                "key3"
            }, child.GetPropertyKeys().ToList());
            Assert.AreEqual("value3", child["key3"]);
        }
Exemple #12
0
        public void VmtStatsCollectorTest()
        {
            var exclude = new[]
            {
                "ambulance",
                "backpack",
                "cable",
                "console",
                "cp_bloodstained",
                "customcubemaps",
                "detail",
                "debug",
                "effects",
                "engine",
                "environment maps",
                "halflife",
                "matsys_regressiontest",
                "hlmv",
                "hud",
                "logo",
                "maps",
                "models",
                "overviews",
                "particle",
                "particles",
                "perftest",
                "pl_halfacre",
                "pl_hoodoo",
                "scripted",
                "shadertest",
                "sprites",
                "sun",
                "vgui",
                "voice",
            };

            var stats = new Dictionary <string, int>();

            using (var fs = new VpkDirectory(new FileInfo(@"F:\Steam\SteamApps\common\Team Fortress 2\tf\tf2_misc_dir.vpk")))
            {
                using (var ss = fs.GetStreamSource())
                {
                    //var vmts = fs.SearchFiles("materials", ".vmt$", true);
                    var subs = fs.GetDirectories("materials").Where(x => !exclude.Contains(x.Split('/')[1]));
                    var vmts = subs.SelectMany(x => fs.SearchFiles(x, ".vmt$", true));
                    foreach (var vmt in vmts)
                    {
                        using (var sr = new StreamReader(ss.OpenFile(vmt)))
                        {
                            var parsed = GenericStructure.Parse(sr).First();
                            var type   = parsed.Name.ToLowerInvariant();
                            if (!stats.ContainsKey(type))
                            {
                                stats.Add(type, 0);
                            }
                            stats[type]++;
                            if (type == "refract" || type == "replacements" || type == "modulate")
                            {
                                Console.WriteLine(type + " " + vmt);
                            }
                        }
                    }
                }
            }
            foreach (var kv in stats.OrderByDescending(x => x.Value))
            {
                Console.WriteLine(kv.Key + " - " + kv.Value);
            }
        }
Exemple #13
0
        protected override DataStructures.MapObjects.Map GetFromStream(Stream stream, string fgd = null)
        {
            using (var reader = new StreamReader(stream))
            {
                var parent = new GenericStructure("Root");
                parent.Children.AddRange(GenericStructure.Parse(reader));
                // Sections from a Hammer map:
                // - world
                // - entity
                // - visgroups
                // - cordon
                // Not done yet
                // - versioninfo
                // - viewsettings
                // - cameras

                var map = new DataStructures.MapObjects.Map();

                var world        = parent.GetChildren("world").FirstOrDefault();
                var entities     = parent.GetChildren("entity");
                var visgroups    = parent.GetChildren("visgroups").SelectMany(x => x.GetChildren("visgroup"));
                var cameras      = parent.GetChildren("cameras").FirstOrDefault();
                var cordon       = parent.GetChildren("cordon").FirstOrDefault();
                var viewsettings = parent.GetChildren("viewsettings").FirstOrDefault();

                foreach (var visgroup in visgroups)
                {
                    var vg = ReadVisgroup(visgroup);
                    if (vg.ID < 0 && vg.Name == "Auto")
                    {
                        continue;
                    }
                    map.Visgroups.Add(vg);
                }

                if (world != null)
                {
                    map.WorldSpawn = ReadWorld(world, map.IDGenerator);
                }
                foreach (var entity in entities)
                {
                    var ent       = ReadEntity(entity, map.IDGenerator);
                    var groupid   = entity.Children.Where(x => x.Name == "editor").Select(x => x.PropertyInteger("groupid")).FirstOrDefault();
                    var entParent = groupid > 0 ? map.WorldSpawn.Find(x => x.ID == groupid && x is Group).FirstOrDefault() ?? map.WorldSpawn : map.WorldSpawn;
                    ent.SetParent(entParent);
                }

                var activeCamera = 0;
                if (cameras != null)
                {
                    activeCamera = cameras.PropertyInteger("activecamera");
                    foreach (var cam in cameras.GetChildren("camera"))
                    {
                        var pos  = cam.PropertyCoordinate("position");
                        var look = cam.PropertyCoordinate("look");
                        if (pos != null && look != null)
                        {
                            map.Cameras.Add(new Camera {
                                EyePosition = pos, LookPosition = look
                            });
                        }
                    }
                }
                if (!map.Cameras.Any())
                {
                    map.Cameras.Add(new Camera {
                        EyePosition = Coordinate.Zero, LookPosition = Coordinate.UnitY
                    });
                }
                if (activeCamera < 0 || activeCamera >= map.Cameras.Count)
                {
                    activeCamera = 0;
                }
                map.ActiveCamera = map.Cameras[activeCamera];

                if (cordon != null)
                {
                    var start = cordon.PropertyCoordinate("mins", map.CordonBounds.Start);
                    var end   = cordon.PropertyCoordinate("maxs", map.CordonBounds.End);
                    map.CordonBounds = new Box(start, end);
                    map.Cordon       = cordon.PropertyBoolean("active", map.Cordon);
                }

                if (viewsettings != null)
                {
                    map.SnapToGrid         = viewsettings.PropertyBoolean("bSnapToGrid", map.SnapToGrid);
                    map.Show2DGrid         = viewsettings.PropertyBoolean("bShowGrid", map.Show2DGrid);
                    map.Show3DGrid         = viewsettings.PropertyBoolean("bShow3DGrid", map.Show3DGrid);
                    map.GridSpacing        = viewsettings.PropertyDecimal("nGridSpacing", map.GridSpacing);
                    map.IgnoreGrouping     = viewsettings.PropertyBoolean("bIgnoreGrouping", map.IgnoreGrouping);
                    map.HideFaceMask       = viewsettings.PropertyBoolean("bHideFaceMask", map.HideFaceMask);
                    map.HideNullTextures   = viewsettings.PropertyBoolean("bHideNullTextures", map.HideNullTextures);
                    map.TextureLock        = viewsettings.PropertyBoolean("bTextureLock", map.TextureLock);
                    map.TextureScalingLock = viewsettings.PropertyBoolean("bTextureScalingLock", map.TextureScalingLock);
                }

                return(map);
            }
        }
Exemple #14
0
        public override IEnumerable <TexturePackage> CreatePackages(IEnumerable <string> sourceRoots, IEnumerable <string> additionalPackages, IEnumerable <string> blacklist, IEnumerable <string> whitelist)
        {
            var blist = blacklist.Select(x => x.TrimEnd('/', '\\')).Where(x => !String.IsNullOrWhiteSpace(x)).ToList();
            var wlist = whitelist.Select(x => x.TrimEnd('/', '\\')).Where(x => !String.IsNullOrWhiteSpace(x)).ToList();

            var roots    = sourceRoots.ToList();
            var packages = new Dictionary <string, TexturePackage>();

            var types = new HashSet <string>
            {
                "unlitgeneric",
                "lightmappedgeneric",
                "lightmappedreflective",
                "water",
                "sprite",
                "decalmodulate",
                "modulate",
                "subrect",
                "worldvertextransition",
                "lightmapped_4wayblend",
                "unlittwotexture",
                "worldtwotextureblend",
                "skyfog"
            };

            var packageRoot = String.Join(";", roots);
            var add         = additionalPackages.ToList();

            var vmtRoot = new QuickRoot(roots, add, "materials", ".vmt");
            var vtfRoot = new QuickRoot(roots, add, "materials", ".vtf");

            const StringComparison ctype = StringComparison.InvariantCultureIgnoreCase;

            foreach (var vmt in vmtRoot.GetFiles())
            {
                var idx = vmt.LastIndexOf('/');
                var dir = idx >= 0 ? vmt.Substring(0, idx) : "";

                if ((blist.Any(x => dir.Equals(x, ctype) || dir.StartsWith(x + '/', ctype))) ||
                    (wlist.Any() && !wlist.Any(x => dir.Equals(x, ctype) || dir.StartsWith(x + '/', ctype))))
                {
                    continue;
                }

                if (!packages.ContainsKey(dir))
                {
                    packages.Add(dir, new TexturePackage(packageRoot, dir, this));
                }
                if (packages[dir].HasTexture(vmt))
                {
                    continue;
                }

                var gs = GenericStructure.Parse(new StreamReader(vmtRoot.OpenFile(vmt))).FirstOrDefault();
                if (gs == null || !types.Contains(gs.Name.ToLowerInvariant()))
                {
                    continue;
                }

                var baseTexture = gs.GetPropertyValue("$basetexture", true);
                if (baseTexture == null)
                {
                    continue;
                }
                baseTexture = baseTexture.ToLowerInvariant().Replace('\\', '/');

                if (!vtfRoot.HasFile(baseTexture))
                {
                    continue;
                }

                var size = Vtf.VtfProvider.GetSize(vtfRoot.OpenFile(baseTexture));
                packages[dir].AddTexture(new TextureItem(packages[dir], vmt, GetFlags(gs), baseTexture, size.Width, size.Height));
            }

            vmtRoot.Dispose();

            foreach (var tp in packages.Values)
            {
                _roots.Add(tp, vtfRoot);
            }

            return(packages.Values);
        }