Esempio n. 1
0
        static void ModMountCfg(string gmod, string cstrike)
        {
            VProperty prop = VdfConvert.Deserialize(File.ReadAllText(string.Join(Path.DirectorySeparatorChar, new List <string> {
                gmod, "garrysmod", "cfg", "mount.cfg"
            })));

            prop.Value["cstrike"] = new VValue(cstrike);
            File.WriteAllText(string.Join(Path.DirectorySeparatorChar, new List <string> {
                gmod, "garrysmod", "cfg", "mount.cfg"
            }), VdfConvert.Serialize(prop));
        }
        public static string toVdf(BindingList <Mount> Mounts)
        {
            var mountcfg = new Dictionary <string, string>();

            foreach (var mount in Mounts)
            {
                mountcfg.Add(mount.Name, mount.Path.FullName);
            }
            return(VdfConvert.Serialize(new VProperty("mountcfg", JToken.FromObject(mountcfg).ToVdf()), new VdfSerializerSettings {
                UsesEscapeSequences = false
            }));
        }
Esempio n. 3
0
        public void Save(string savename)
        {
            // serialize back to a string
            string newLevel = VdfConvert.Serialize(level);

            // remove opening and closing curly braces as vmf does not use these
            string newVmf = newLevel.Substring(1, newLevel.Length - 4);

            // untab every line once to make thing look nicer
            newVmf = newVmf.Replace("\n\t", "\n");

            // write the new vmf output
            // TODO: we could do a compile here if we felt like it
            File.WriteAllText(savename, newVmf);
        }
Esempio n. 4
0
        private void WriteGameInfo(VToken info)
        {
            var updated = EnableFormatting ? VdfConvert.Serialize(info, VdfSerializerSettings.Common) : VdfConvert.Serialize(info, VdfSerializerSettings.Default);

            File.WriteAllText(_path, updated, Windows1252);
        }
Esempio n. 5
0
        private static int XmlToVdf(string xmlFile, string vdfFile)
        {
            try
            {
                Dictionary <string, Achievement> achievements = new Dictionary <string, Achievement>();
                string language = null;
                string achId    = "";

                // Read the XML and get the achievements

                XmlReader xml = XmlReader.Create(xmlFile);
                while (xml.Read())
                {
                    if (xml.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    if (language == null)
                    {
                        xml.MoveToAttribute("language");
                        language = xml.Value;
                    }
                    else
                    {
                        if (xml.HasAttributes)
                        {
                            xml.MoveToAttribute("key");
                            achId = xml.Value;
                            achievements.Add(achId, new Achievement());
                        }
                        else
                        {
                            string name  = xml.Name;
                            string value = xml.ReadString();

                            if (name == "name")
                            {
                                achievements[achId].Name = value;
                            }
                            else
                            {
                                achievements[achId].Description = value;
                            }
                        }
                    }
                }


                // Now write everything in the VDF

                VProperty root = new VProperty();
                root.Key = "lang";

                VObject obj = new VObject();
                obj.Add("Language", new VValue(language));

                VObject tokens = new VObject();
                foreach (var ach in achievements)
                {
                    tokens.Add(ach.Key + "_NAME", new VValue(ach.Value.Name));
                    tokens.Add(ach.Key + "_DESC", new VValue(ach.Value.Description));
                }
                obj.Add("Tokens", tokens);

                VProperty propTokens = new VProperty()
                {
                    Key   = "Tokens",
                    Value = new VValue(tokens)
                };

                root.Value = obj;

                string result = VdfConvert.Serialize(root);

                File.WriteAllText(vdfFile, result);

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(1);
            }
        }
        static private void MaterialModifyAndExport(Dictionary <string, string> materialVpkData, MainWindow exportWindow, DirectoryInfo exportPath)
        {
            List <MaterialParameter> EnabledParameters = exportWindow.GetEnabledMaterialParameters();

            foreach (var a in materialVpkData)
            {
                try
                {
                    VdfSerializerSettings settings = new VdfSerializerSettings
                    {
                        UsesEscapeSequences = false
                    };
                    dynamic conversion         = VdfConvert.Deserialize(materialVpkData[a.Key], settings);
                    Random  randomNumGenerator = new Random();
                    foreach (MaterialParameter enabledParameter in EnabledParameters)
                    {
                        if (!TestForFilteredShaders(enabledParameter.ShaderFilterMode, conversion, enabledParameter.ShaderFilterArray))
                        {
                            continue;
                        }
                        if (!TestForFilteredProxies(enabledParameter.ProxyFilterMode, conversion, enabledParameter.ProxyFilterArray))
                        {
                            continue;
                        }
                        if (enabledParameter.RandomizerChance != 100 &&
                            randomNumGenerator.Next(1, 101) >= enabledParameter.RandomizerChance + 1)    //Confirm this is accurate..?
                        {
                            continue;
                        }

                        float valueOffset = enabledParameter.RandomizerOffset;
                        if (enabledParameter.RandomizerOffset != 0.0f)
                        {
                            valueOffset *= (float)(randomNumGenerator.NextDouble() * 2.0 - 1.0);
                        }
                        switch (enabledParameter.ParamType.ToString())
                        {
                        //TODO: Interpret float values
                        //case "vector3-float":
                        //    VMTInteraction.InsertVector3IntoMaterial(conversion,
                        //                                             enabledParameter.Parameter,
                        //                                             VMTInteraction.ConvertStringToVector3Float(enabledParameter.ParamValue));
                        //    break;
                        case "vector3":
                            if (enabledParameter.Parameter == "$color" || enabledParameter.Parameter == "$color2")
                            {
                                conversion = VMTInteraction.InsertVector3IntoMaterial(conversion,
                                                                                      VMTInteraction.PerformColorChecks(conversion.Key),
                                                                                      VMTInteraction.ConvertStringToVector3Int(enabledParameter.ParamValue));
                            }
                            else
                            {
                                conversion = VMTInteraction.InsertVector3IntoMaterial(conversion,
                                                                                      enabledParameter.Parameter,
                                                                                      VMTInteraction.ConvertStringToVector3Int(enabledParameter.ParamValue));
                            }
                            break;

                        case "boolean":
                            conversion = VMTInteraction.InsertValueIntoMaterial(conversion, enabledParameter.Parameter, Int32.Parse(enabledParameter.ParamValue));
                            break;

                        case "integer":
                            conversion = VMTInteraction.InsertValueIntoMaterial(conversion, enabledParameter.Parameter, Int32.Parse(enabledParameter.ParamValue) + (int)Math.Ceiling(valueOffset));
                            break;

                        case "string":
                            conversion = VMTInteraction.InsertValueIntoMaterial(conversion, enabledParameter.Parameter, enabledParameter.ParamValue);
                            break;

                        case "float":
                            conversion = VMTInteraction.InsertValueIntoMaterial(conversion, enabledParameter.Parameter, float.Parse(enabledParameter.ParamValue + valueOffset));
                            break;

                        case "proxy":
                            conversion = VMTInteraction.InsertProxyIntoMaterial(conversion, enabledParameter.Parameter, enabledParameter.ParamValue);
                            break;

                        case "choices":
                            conversion = VMTInteraction.InsertRandomChoiceIntoMaterial(conversion, enabledParameter.Parameter, enabledParameter.ParamValue);
                            break;

                        default:
                            break;     //Unimplemented type.
                        }
                    }
                    DirectoryInfo di = new DirectoryInfo(Path.GetDirectoryName(Path.Combine(exportPath.FullName, a.Key)));
                    di.Create();
                    try
                    {
                        File.AppendAllText(Path.Combine(exportPath.FullName, a.Key), VdfConvert.Serialize(conversion, settings));
                    }
                    catch (FileNotFoundException)
                    {
                        exportWindow.WriteMessage("The file " + a.Key + " could not be modified since the file path is too long.");
                    }
                }
                catch (VdfException)
                {
                    exportWindow.WriteMessage("The file " + a.Key + " could not be modified due to an faulty data structure.");
                }
            }
        }