Ejemplo n.º 1
0
        private static List <VehicleSirenSetup> ParseXMLFile(string _File)
        {
            List <VehicleSirenSetup> AllVehicleSirenSetups = new List <VehicleSirenSetup>();

            try
            {
                List <string> PresetSirenNames      = Enum.GetNames(typeof(Siren.PresetSirenNames)).ToList();
                List <string> LowerPresetSirenNames = PresetSirenNames.Select(z => z.ToLower()).ToList();
                List <string> SirenTypeNames        = Enum.GetNames(typeof(Siren.SirenTypes)).ToList();
                List <string> LowerSirenTypeNames   = SirenTypeNames.Select(z => z.ToLower()).ToList();

                XDocument xdoc = XDocument.Load(_File);
                foreach (XElement x in xdoc.Descendants("VehicleSirenSetup"))
                {
                    List <Model> vehmodels = new List <Model>();
                    foreach (XElement element in x.Elements("VehicleModel"))
                    {
                        vehmodels.Add(element.Value);
                    }
                    foreach (Model vehmodel in vehmodels)
                    {
                        if ((!AllVehicleSirenSetups.Select(y => y.VehicleModel).Contains(vehmodel) && vehmodel.IsValid))
                        {
                            List <Siren> VehicleSetupSirens = new List <Siren>();
                            foreach (XElement y in x.Element("Sirens").Descendants())
                            {
                                string         SirenFileIdentifier;
                                string         SirenType = ((string)y).ToLower().Trim();
                                WaveFileReader SirenWaveProvider;
                                if (LowerPresetSirenNames.Contains(SirenType))
                                {
                                    Siren.PresetSirenNames sirenname = (Siren.PresetSirenNames)Enum.Parse(typeof(Siren.PresetSirenNames), PresetSirenNames[LowerPresetSirenNames.IndexOf(SirenType)]);
                                    SirenWaveProvider   = new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[sirenname] + FileExtension);
                                    SirenFileIdentifier = sirenname.ToString();
                                }
                                else
                                {
                                    if (File.Exists(CustomSirensPathModifier + SirenType + FileExtension))
                                    {
                                        SirenWaveProvider   = new WaveFileReader(CustomSirensPathModifier + SirenType + FileExtension);
                                        SirenFileIdentifier = SirenType;
                                    }
                                    else
                                    {
                                        Game.LogTrivial("Custom siren path doesn't exist: " + CustomSirensPathModifier + SirenType + FileExtension);
                                        Albo1125.Common.CommonLibrary.ExtensionMethods.DisplayPopupTextBoxWithConfirmation("Siren Mastery", "You have set a custom siren called " + SirenType + " in your VehicleSirenSetup.xml file, but the following path doesn't exist: " + CustomSirensPathModifier + SirenType + FileExtension + ". Skipping this siren.", false);
                                        continue;
                                    }
                                }

                                Siren.SirenTypes sirtype = (Siren.SirenTypes)Enum.Parse(typeof(Siren.SirenTypes), SirenTypeNames[LowerSirenTypeNames.IndexOf(((string)y.Attribute("SirenType")).ToLower())]);
                                float            Volume  = string.IsNullOrWhiteSpace((string)y.Attribute("Volume")) ? SirenMasterySetup.Volume + (sirtype == Siren.SirenTypes.Horn ? 0.065f : 0f) : float.Parse((string)y.Attribute("Volume"), CultureInfo.InvariantCulture);
                                VehicleSetupSirens.Add(new Siren(SirenWaveProvider, Volume, sirtype, SirenFileIdentifier));
                            }
                            for (int i = 0; i < 4; i++)
                            {
                                if (VehicleSetupSirens.Count <= i)
                                {
                                    Game.LogTrivial("Not enough sirens specified - setting siren " + (i + 1));
                                    Game.DisplayNotification("Not enough sirens specified, there must be at least 4 sirens per vehiclesirensetup. Setting siren number " + (i + 1) + " to default.");
                                    if (i == 0)
                                    {
                                        VehicleSetupSirens.Add(new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PolicePrimary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Primary, Siren.PresetSirenNames.PolicePrimary.ToString()));
                                    }
                                    else if (i == 1)
                                    {
                                        VehicleSetupSirens.Add(new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PoliceSecondary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, Siren.PresetSirenNames.PoliceSecondary.ToString()));
                                    }
                                    else if (i == 2)
                                    {
                                        VehicleSetupSirens.Add(new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PoliceTertiary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, Siren.PresetSirenNames.PoliceTertiary.ToString()));
                                    }
                                    else if (i == 3)
                                    {
                                        VehicleSetupSirens.Add(new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.Bullhorn] + FileExtension), SirenMasterySetup.Volume + 0.065f, Siren.SirenTypes.Horn, Siren.PresetSirenNames.Bullhorn.ToString()));
                                    }
                                }
                            }
                            List <Siren.SirenTypes> sirtypes = VehicleSetupSirens.Select(y => y.SirenType).ToList();
                            int count = 1;
                            foreach (Siren.SirenTypes sirentype in Enum.GetValues(typeof(Siren.SirenTypes)))
                            {
                                if (!sirtypes.Contains(sirentype) && sirentype != Siren.SirenTypes.ForcedOnly)
                                {
                                    Game.LogTrivial("SirenSetup for " + vehmodel + " contains no " + sirentype.ToString() + ". Setting siren " + count + " as " + sirentype);
                                    VehicleSetupSirens[count - 1].SirenType = sirentype;
                                }
                                count++;
                                if (count == 3)
                                {
                                    count++;
                                }
                            }
                            foreach (XAttribute att in x.Attributes("DefaultFor"))
                            {
                                if (!string.IsNullOrWhiteSpace((string)att))
                                {
                                    if (((string)att).ToLower() == "policecar")
                                    {
                                        DefaultPoliceSetup = new VehicleSirenSetup(vehmodel, VehicleSetupSirens);
                                    }
                                    else if (((string)att).ToLower() == "policebike")
                                    {
                                        DefaultPoliceBikeSetup = new VehicleSirenSetup(vehmodel, VehicleSetupSirens);
                                    }
                                }
                            }
                            AllVehicleSirenSetups.Add(new VehicleSirenSetup(vehmodel, VehicleSetupSirens));
                        }
                        else
                        {
                            Game.LogTrivial("Skipping duplicate or invalid vehicle model siren setup - " + vehmodel.Name);
                        }
                    }
                }
            }
            catch (System.Xml.XmlException e)
            {
                Game.LogTrivial(e.ToString());
                Game.LogTrivial("Setting default vehicle siren setups.");
                Albo1125.Common.CommonLibrary.ExtensionMethods.DisplayPopupTextBoxWithConfirmation("Siren Mastery", "Your VehicleSirenSetup.xml file is not valid. You may have made a mistake while editing it. Error thrown at Line " + e.LineNumber + ", at character number " + e.LinePosition + ". Check RAGEPluginHook.log for full error. Setting default vehicle siren setups.", false);
                AllVehicleSirenSetups = new List <VehicleSirenSetup>();
            }
            return(AllVehicleSirenSetups);
        }
Ejemplo n.º 2
0
        private static void LoadVehicleSirenSetups()
        {
            if (!File.Exists(VehicleSirenSettingsPath))
            {
                new XDocument(
                    new XElement("SirenMastery",
                                 new XComment("Siren Mastery by Albo1125." + Environment.NewLine + "Please review the Siren Mastery documentation for full instructions on how to set this up." + Environment.NewLine + "There is also a folder included in the Siren Mastery download containing a few examples for your convenience, along with a tutorial video." + Environment.NewLine + "You can add as many VehicleSirenSetups as you want. They must be between the <SirenMastery> and </SirenMastery> brackets."


                                              ), new XElement("VehicleSirenSetup",

                                                              new XElement("VehicleModel", "POLICE"),
                                                              new XElement("VehicleModel", "POLICE2"),
                                                              new XElement("Sirens",
                                                                           new XElement("Siren1", new XAttribute("SirenType", "Primary"), "PolicePrimary"),
                                                                           new XElement("Siren2", new XAttribute("SirenType", "Secondary"), "PoliceSecondary"),
                                                                           new XElement("Siren3", new XAttribute("SirenType", "Secondary"), "PoliceTertiary"),
                                                                           new XElement("Siren4", new XAttribute("SirenType", "Horn"), "Bullhorn")
                                                                           )
                                                              )

                                 )
                    )
                .Save(VehicleSirenSettingsPath);
            }

            DefaultPoliceSetup = new VehicleSirenSetup();
            DefaultPoliceSetup.VehicleModel = "POLICE";
            DefaultPoliceSetup.Sirens       = new List <Siren>()
            {
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PolicePrimary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Primary, "PolicePrimary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PoliceSecondary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "PoliceSecondary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PoliceTertiary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "PoliceTertiary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.Bullhorn] + FileExtension), SirenMasterySetup.Volume + 0.065f, Siren.SirenTypes.Horn, "Bullhorn")
            };
            DefaultAmbulanceSetup = new VehicleSirenSetup();
            DefaultAmbulanceSetup.VehicleModel = "AMBULANCE";
            DefaultAmbulanceSetup.Sirens       = new List <Siren>()
            {
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.AmbulancePrimary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Primary, "AmbulancePrimary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.AmbulanceSecondary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "AmbulanceSecondary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.AmbulanceTertiary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "AmbulanceTertiary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.Bullhorn] + FileExtension), SirenMasterySetup.Volume + 0.065f, Siren.SirenTypes.Horn, "Bullhorn"),
            };
            DefaultFiretruckSetup = new VehicleSirenSetup();
            DefaultFiretruckSetup.VehicleModel = "FIRETRUK";
            DefaultFiretruckSetup.Sirens       = new List <Siren>()
            {
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.FireTruckPrimary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Primary, "FireTruckPrimary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.FireTruckSecondary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "FireTruckSecondary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PoliceTertiary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "PoliceTertiary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.FireTruckHorn] + FileExtension), SirenMasterySetup.Volume + 0.065f, Siren.SirenTypes.Horn, "FireHorn"),
            };
            DefaultFIBSetup = new VehicleSirenSetup();
            DefaultFIBSetup.VehicleModel = "FBI";
            DefaultFIBSetup.Sirens       = new List <Siren>()
            {
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.FIBPrimary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Primary, "FIBPrimary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.FIBSecondary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "FIBSecondary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PoliceTertiary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "PoliceTertiary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.Bullhorn] + FileExtension), SirenMasterySetup.Volume + 0.065f, Siren.SirenTypes.Horn, "Bullhorn"),
            };

            DefaultPoliceBikeSetup = new VehicleSirenSetup();
            DefaultPoliceBikeSetup.VehicleModel = "POLICEB";
            DefaultPoliceBikeSetup.Sirens       = new List <Siren>()
            {
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PoliceBikePrimary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Primary, "PoliceBikePrimary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PoliceBikeSecondary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "PoliceBikeSecondary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PoliceTertiary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "PoliceTertiary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.Bullhorn] + FileExtension), SirenMasterySetup.Volume + 0.065f, Siren.SirenTypes.Horn, "Bullhorn"),
            };

            DefaultGrangerSetup = new VehicleSirenSetup();
            DefaultGrangerSetup.VehicleModel = "SHERIFF2";
            DefaultGrangerSetup.Sirens       = new List <Siren>()
            {
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.GrangerPrimary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Primary, "GrangerPrimary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.GrangerSecondary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "GrangerSecondary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.PoliceTertiary] + FileExtension), SirenMasterySetup.Volume, Siren.SirenTypes.Secondary, "PoliceTertiary"),
                new Siren(new WaveFileReader(PresetSirensPathModifier + Siren.PresetSirenNamesFileNames[Siren.PresetSirenNames.Bullhorn] + FileExtension), SirenMasterySetup.Volume + 0.065f, Siren.SirenTypes.Horn, "Bullhorn"),
            };

            List <string> PresetSirenNames      = Enum.GetNames(typeof(Siren.PresetSirenNames)).ToList();
            List <string> LowerPresetSirenNames = PresetSirenNames.Select(z => z.ToLower()).ToList();

            //Read in the defaults for vehicles
            //List<VehicleSirenSetup> DefaultSirenSetups = ParseXMLFile(VehicleDefaultSirenSettingsPath, true);
            //List <string> DefaultEntryNames = (DefaultSirenSetups.Select(x => x.VehicleModel.Name.ToLower())).ToList();
            //if (DefaultEntryNames.Contains("policecar"))
            //{
            //    DefaultPoliceSetup = DefaultSirenSetups.FirstOrDefault(x => x.VehicleModel.Name.ToLower() == "policecar");
            //}
            //if (DefaultEntryNames.Contains("policebike"))
            //{
            //    DefaultPoliceBikeSetup = DefaultSirenSetups.FirstOrDefault(x => x.VehicleModel.Name.ToLower() == "policebike");
            //}


            List <VehicleSirenSetup> AllVehicleSirenSetups = ParseXMLFile(VehicleSirenSettingsPath);

            Game.LogTrivial("Reading SirenMastery VehicleSirenSetup.xml");


            AllVehicleSirenSetups.ForEach(x => ModelsWithSirenSetups.Add(x.VehicleModel, x));
            Game.LogTrivial("All VehicleSirenSetups:");
            foreach (VehicleSirenSetup setup in AllVehicleSirenSetups)
            {
                Game.LogTrivial(Environment.NewLine + setup.VehicleModel.Name + " Sirens:");
                foreach (Siren s in setup.Sirens)
                {
                    string msg = "";
                    msg += "ID: " + s.SirenFileIdentifier;
                    msg += " SirenType: " + s.SirenType.ToString();
                    msg += " Vol: " + s.Volume.ToString();
                    Game.LogTrivial(msg);
                }
            }
        }