コード例 #1
0
        public List <MaterialParameter> GetEnabledMaterialParameters()
        {
            List <MaterialParameter> materialParameters = new List <MaterialParameter>();

            for (var i = 0; i < materialParameterList.Items.Count; i++)
            {
                if (materialParameterList.GetItemChecked(i))
                {
                    MaterialParameter param = (materialParameterList.Items[i] as MaterialParameterDisplayListEntry).Param;
                    int result = VMTInteraction.VerifyParameter(param);
                    if (result != -1)
                    {
                        if (result == 0)
                        {
                            progressBox.AppendText("WARNING: Parameter " + param.ParamName + " is missing required settings. Please check the parameter settings for more info and try again.\r\n");
                        }
                        if (result == 1)
                        {
                            progressBox.AppendText("WARNING: Parameter " + param.ParamName + " is of type " + param.ParamType + "but the value is " + param.ParamValue + ". Please check the parameter settings and try again.\r\n");
                        }
                        WriteMessage("Parameter " + param.ParamName + " has been deselected.\r\n");
                        materialParameterList.SetItemChecked(i, false);
                    }
                    else
                    {
                        materialParameters.Add(param);
                    }
                }
            }
            return(materialParameters);
        }
コード例 #2
0
 /// <summary>
 /// Performs a test on a materialFile to see if a proxy exists, and returns the result of the filter. TODO: Simplify.
 /// </summary>
 /// <param name="filterMode">Set to 0 if it should NOT be used, set to 1 if it SHOULD ONLY be used.</param>
 /// <param name="materialFile"></param>
 /// <param name="proxyFilterArray"></param>
 /// <returns>True if the parameter be included, false if not.</returns>
 static private bool TestForFilteredProxies(int filterMode, dynamic materialFile, List <string> proxyFilterArray) //Any possible simplifications?
 {
     if (filterMode == 0)
     {
         foreach (string proxyFilter in proxyFilterArray)
         {
             if (VMTInteraction.ContainsProxy(materialFile, proxyFilter))
             {
                 return(false);
             }
         }
         return(true);
     }
     else
     {
         foreach (string proxyFilter in proxyFilterArray)
         {
             if (VMTInteraction.ContainsProxy(materialFile, proxyFilter))
             {
                 return(true);
             }
         }
         return(false);
     }
 }
コード例 #3
0
        private async void StartPackagingButton_Click(object sender, EventArgs e)
        {
            progressBox.Clear();
            if (!ConfirmValidGame())
            {
                toolStripStatusLabel1.Text = "ERROR: Cannot export. gameinfo.txt not present in specified directory. Please confirm the location to the \"tf\" folder in the Export tab.";
                return;
            }
            try
            {
                if (!Directory.Exists(Path.GetDirectoryName(saveFileDialog1.FileName)))
                {
                    WriteMessage("ERROR: Tne export directory is not accessible.", ExportState.ErrorFatal);
                    return;
                }
            }
            catch (ArgumentException)
            {
                WriteMessage("ERROR: Tne export directory is not accessible.", ExportState.ErrorFatal);
                return;
            }
            for (var i = 0; i < materialParameterList.Items.Count; i++)
            // Considering using this as a way to preset the parameters so that I don't need to
            // run constant cases later on when the process begins.
            {
                if (materialParameterList.GetItemChecked(i))
                {
                    MaterialParameter param = (materialParameterList.Items[i] as MaterialParameterDisplayListEntry).Param;
                    int result = VMTInteraction.VerifyParameter(param);
                    if (result != -1)
                    {
                        if (result == 0)
                        {
                            progressBox.AppendText("WARNING: Parameter " + param.ParamName + " is missing required settings. Please check the parameter settings for more info and try again.\r\n");
                        }
                        if (result == 1)
                        {
                            progressBox.AppendText("WARNING: Parameter " + param.ParamName + " is of type " + param.ParamType + "but the value is " + param.ParamValue + ". Please check the parameter settings and try again.\r\n");
                        }
                        WriteMessage("Parameter " + param.ParamName + " has been deselected.\r\n");
                        materialParameterList.SetItemChecked(i, false);
                    }
                }
            }
            if (materialParameterList.CheckedItems.Count == 0)
            {
                WriteMessage("ERROR: No parameters have been selected.", ExportState.ErrorFatal);
                return;
            }

            if (exportingState)
            {
                progressBox.AppendText("I've started, so I'll finish.\r\n");
                //cancellationTokenSource.Cancel(); //Cancel immediately.
            }
            else
            {
                startPackagingButton.Text = "Abort Packaging";
            }


            ////
            ////
            ////BEGIN
            ////
            ////
            ////

            DirectoryInfo           exportPath              = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "TF2AssetManager", Path.GetFileNameWithoutExtension(Properties.Settings.Default.VpkLocation)));
            string                  tempFileLocation        = Path.Combine(Path.GetTempPath(), "TF2AssetManager", Path.GetFileName(saveFileDialog1.FileName));
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       token = cancellationTokenSource.Token;

            exportingState = true;


            List <string> includedCustomFiles = new List <string>();

            foreach (string itemChecked in customFileCheckList.CheckedItems)
            {
                includedCustomFiles.Add(itemChecked);
            }

            WriteMessage("Searching for files in the TF2 assets...", ExportState.Begin);
            ExportProcess.Export(pathToExecutableDirectory, customFilesCheckBox.Checked, includedCustomFiles, this);
            try
            {
                File.Delete(saveFileDialog1.FileName);
                File.Move(tempFileLocation, saveFileDialog1.FileName);
                WriteMessage("Operation complete.", ExportState.Success, "Export complete.");
            }
            catch (IOException)
            {
                WriteMessage("ERROR: The file is already in use by another process. Please close the process that is using this file.", ExportState.ErrorFatal, "An error has occurred during exporting. The target export file already exists, and cannot be written over.");
            }
            ClearAllTempFiles(exportPath, tempFileLocation);
            exportingState            = false;
            startPackagingButton.Text = "Begin Packaging";
        }
コード例 #4
0
        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.");
                }
            }
        }