示例#1
0
        internal static void EditVDF(SDVMMSettings Settings)
        {
            try
            {
                var files = Directory.GetFiles(Path.Combine(Settings.SteamFolder, "userdata"), "localconfig.vdf", SearchOption.AllDirectories).ToArray();

                // find game settings

                int i = 0;
                for (i = 0; i < files.Length; i++)
                {
                    // read file
                    var fileText = File.ReadAllText(files[i]);
                    if (fileText == null)
                    {
                        continue;
                    }
                    VdfSerializerSettings ste = new VdfSerializerSettings();
                    ste.UsesEscapeSequences = true;

                    raw = VdfConvert.Deserialize(fileText, ste);
                    VObject data = (VObject)raw.Value.Software.Valve.Steam.Apps;


                    if (data.ContainsKey("413150"))
                    {
                        game = (VObject)raw.Value.Software.Valve.Steam.Apps["413150"];
                        break;
                    }
                }

                // check fail conditions
                if (game == null)
                {
                    MessageBox.Show(MainWindow.Translation.SDVInstalled, "error");
                    return;
                }
                if (game.ContainsKey("LaunchOptions"))
                {
                    MessageBox.Show(MainWindow.Translation.LaunchOptionExist, "error");
                    return;
                }
                if (File.Exists(Path.Combine(files[i], "localconfig-sdvmm.vdf.bak")))
                {
                    MessageBox.Show(MainWindow.Translation.LaunchOptionApplied, "error");
                    return;
                }
                // kill steam
                foreach (var process in Process.GetProcessesByName("Steam"))
                {
                    process.Kill();
                }


                // apply launch options
                if (!File.Exists(Path.Combine(Path.GetDirectoryName(files[i]), "localconfig-sdvmm.vdf.bak")))
                {
                    File.Copy(files[i], Path.Combine(Path.GetDirectoryName(files[i]), "localconfig-sdvmm.vdf.bak"));
                }
                //VValue launchOptions = new VValue(@String.Join(""," ","\\\"",MainWindow.SDVMMSettings.GameFolder.Replace("\\","\\\\"),"\\\\" ,"StardewModdingAPI.exe","\\\" ", "%command%"));

                string path          = Path.Combine(MainWindow.SDVMMSettings.GameFolder, "StardewModdingAPI.exe").Replace(@"\", @"\\");
                VValue launchOptions = new VValue($" \\\"{path}\\\" %command%");

                game.Add("LaunchOptions", launchOptions);
                File.WriteAllText(files[i], raw.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "error");
            }
        }
        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.");
                }
            }
        }