示例#1
0
        /// <summary>
        /// Fetches the manifest from the sound package
        /// </summary>
        /// <param name="name">An out variable that returns the package name</param>
        /// <returns></returns>
        public SoundPackManifest GetManifest(out string name)
        {
            // Check cache
            if (Manifest != null)
            {
                name = PackageName;
                return(Manifest);
            }

            // Load the file entry from the archive
            var entry = Archive.GetEntry("manifest.sii");

            if (entry == null)
            {
                name = string.Empty;
                return(null);
            }

            // Parse the sii file
            var document = new SiiDocument(typeof(SoundPackManifest));

            using (StreamReader reader = new StreamReader(entry.Open()))
                document.Load(reader.ReadToEnd().Trim());

            // Grab the manifest object
            PackageName = name = new List <string>(document.Definitions.Keys).First();
            return(document.GetDefinition <SoundPackManifest>(PackageName));
        }
示例#2
0
        /// <summary>
        /// Fetches the specified sound accessory
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public AccessorySoundData GetSoundFile(SoundLocation type)
        {
            // Check cache
            switch (type)
            {
            case SoundLocation.Interior: if (Interior != null)
                {
                    return(Interior);
                }
                break;

            case SoundLocation.Exterior: if (Exterior != null)
                {
                    return(Exterior);
                }
                break;
            }

            // Load the file entry from the archive
            var entry = Archive.GetEntry(type == SoundLocation.Interior ? "interior.sii" : "exterior.sii");

            if (entry == null)
            {
                return(null);
            }

            // Parse the sii file
            var document = new SiiDocument(typeof(AccessorySoundData), typeof(SoundData), typeof(SoundEngineData));

            using (StreamReader reader = new StreamReader(entry.Open()))
                document.Load(reader.ReadToEnd().Trim());

            // return the main object
            var key  = new List <string>(document.Definitions.Keys).First();
            var item = document.GetDefinition <AccessorySoundData>(key);

            // Cache the sound data
            if (type == SoundLocation.Interior)
            {
                Interior = item;
            }
            else
            {
                Exterior = item;
            }

            // return
            return(item);
        }
示例#3
0
        private static void Main(string[] args)
        {
            var text = default(string);

            using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("Sandbox.TestFile.txt"))
                using (var reader = new StreamReader(stream))
                    text = reader.ReadToEnd();

            // All classes that appear in the SII document must be passed into the constructor.
            var document = new SiiDocument(typeof(AccessoryEngineData));

            //var document = new SiiDocument(typeof(AccessorySoundData), typeof(SoundData), typeof(SoundEngineData));

            // Load the entire document.
            document.Load(text);

            // Get specific unit definition.
            List <string> keys       = new List <string>(document.Definitions.Keys);
            var           engineData = document.GetDefinition <AccessoryEngineData>(keys[0]);

            // Debug stuff, just printing out all the fields
            var type      = engineData.GetType();
            var className = type.GetCustomAttribute <SiiUnitAttribute>().ClassName;

            Console.WriteLine("{2} = {0} ({1})", type.Name, className, keys[0]);

            var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            foreach (var property in properties)
            {
                var attribute = property.GetCustomAttribute <SiiAttributeAttribute>().Name;
                var getter    = property.GetGetMethod();

                Console.WriteLine("  - {0} = {1}", attribute, getter.Invoke(engineData, null));
            }

            Console.Read();
        }
示例#4
0
        private void importButton_Click(object sender, EventArgs e)
        {
            // Request the user supply the steam library path
            var dialog = new OpenFileDialog();

            dialog.Title  = "Engine SII File Import";
            dialog.Filter = "SiiNunit|*.sii";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    var document = new SiiDocument(typeof(AccessoryEngineData));

                    using (FileStream stream = File.OpenRead(dialog.FileName))
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            // Read the file contents
                            string contents = reader.ReadToEnd().Trim();
                            document.Load(contents);

                            // Grab the engine object
                            List <string> objects = new List <string>(document.Definitions.Keys);
                            if (objects.Count == 0)
                            {
                                MessageBox.Show("Unable to find any engine data in this sii document!",
                                                "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning
                                                );
                                return;
                            }

                            // Grab the engine
                            var engine = document.GetDefinition <AccessoryEngineData>(objects[0]);

                            // === Set form values
                            int len = objects[0].IndexOf('.');
                            unitNameBox.Text     = objects[0].Substring(0, len);
                            engineNameBox.Text   = engine.Name;
                            filenameTextBox.Text = Path.GetFileName(dialog.FileName);
                            unlockBox.SetValueInRange(engine.UnlockLevel);
                            priceBox.SetValueInRange(engine.Price);
                            neutralRpmBox.SetValueInRange(engine?.RpmLimitNeutral ?? 2200);
                            rpmLimitBox.SetValueInRange((decimal)engine.RpmLimit);
                            idleRpmBox.SetValueInRange(engine?.IdleRpm ?? 650);
                            brakeStrengthBox.SetValueInRange((decimal)engine.BrakeStrength);
                            brakePositionsBox.SetValueInRange(engine.BrakePositions);
                            automaticDSCheckBox.Checked = engine.BrakeDownshift == 1;

                            // Misc
                            if (engine.RpmRangeEngineBrake.X > 0f)
                            {
                                engineBrakeLow.SetValueInRange((int)engine.RpmRangeEngineBrake.X);
                                engineBrakeHigh.SetValueInRange((int)engine.RpmRangeEngineBrake.Y);
                            }
                            consumptionBox.SetValueInRange((decimal)engine.FuelConsumption * 100);
                            adBlueConsumption.SetValueInRange((decimal)engine.AdblueConsumption);
                            adBlueNoPowerLimit.SetValueInRange((decimal)engine.NoAdbluePowerLimit);
                            conflictsTextBox.Lines = engine?.Conflicts ?? new string[] { };

                            // Tab 3
                            if (engine.RpmRange_LowGear.X > 0f)
                            {
                                rpmRangeBox1.SetValueInRange((int)engine.RpmRange_LowGear.X);
                                rpmRangeBox2.SetValueInRange((int)engine.RpmRange_LowGear.Y);
                            }
                            if (engine.RpmRange_HighGear.X > 0f)
                            {
                                rpmRangeBox3.SetValueInRange((int)engine.RpmRange_HighGear.X);
                                rpmRangeBox4.SetValueInRange((int)engine.RpmRange_HighGear.Y);
                            }
                            if (engine.RpmRange_PowerBoost.X > 0f)
                            {
                                rpmRangeBox5.SetValueInRange((int)engine.RpmRange_PowerBoost.X);
                                rpmRangeBox6.SetValueInRange((int)engine.RpmRange_PowerBoost.Y);
                            }

                            // Parse Horsepower
                            Regex reg = new Regex("^(?<hp>[0-9]+)", RegexOptions.Multiline);
                            if (reg.IsMatch(engine.Info[0]))
                            {
                                horsepowerBox.SetValueInRange(Int32.Parse(reg.Match(engine.Info[0]).Groups["hp"].Value));
                            }

                            if (engine.TorqueCurves?.Length > 0)
                            {
                                // Clear torque curves
                                chart1.Series[0].Points.Clear();
                                ratioListView.Items.Clear();
                                Ratios.Clear();

                                // Set new torque curves
                                foreach (Vector2 vector in engine.TorqueCurves)
                                {
                                    TorqueRatio ratio = new TorqueRatio();
                                    ratio.RpmLevel = (int)vector.X;
                                    ratio.Ratio    = Math.Round(vector.Y, 4);
                                    Ratios.Add(ratio);
                                }

                                // Fill ratio view
                                PopulateTorqueRatios();
                            }

                            // Set torque value
                            torqueBox.SetValueInRange((Program.Config.UnitSystem == UnitSystem.Imperial)
                            ? Metrics.NewtonMetersToTorque((decimal)engine.Torque, torqueBox.DecimalPlaces)
                            : Math.Round((decimal)engine.Torque, torqueBox.DecimalPlaces)
                                                      );

                            // Defaults (skip sounds)
                            if (engine.Defaults != null)
                            {
                                fileDefaultsTextBox.Lines = (from x in engine.Defaults where !x.Contains("/sound/") select x).ToArray();
                            }

                            // Overrides (skip sounds)
                            if (engine.Overrides != null)
                            {
                                fileOverridesTextBox.Lines = (from x in engine.Overrides where !x.Contains("/sound/") select x).ToArray();
                            }

                            // Alert the user
                            MessageBox.Show(
                                $"Successfully imported the engine \"{engine.Name}\"! You must now select an engine series for this engine.",
                                "Import Successful", MessageBoxButtons.OK, MessageBoxIcon.Information
                                );
                        }
                }
                catch (SiiSyntaxException ex)
                {
                    StringBuilder builder = new StringBuilder("A Syntax error occured while parsing the sii file!");
                    builder.AppendLine();
                    builder.AppendLine();
                    builder.AppendLine($"Message: {ex.Message.Replace("\0", "\\0")}");
                    builder.AppendLine();
                    builder.AppendLine($"Line: {ex.Span.Start.Line}");
                    builder.AppendLine($"Column: {ex.Span.Start.Column}");
                    MessageBox.Show(builder.ToString(), "Sii Syntax Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (SiiException ex)
                {
                    StringBuilder builder = new StringBuilder("Failed to parse the sii file.");
                    builder.AppendLine();
                    builder.AppendLine($"Message: {ex.Message}");
                    MessageBox.Show(builder.ToString(), "Sii Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "An Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
示例#5
0
        private void importButton_Click(object sender, EventArgs e)
        {
            // Request the user supply the steam library path
            OpenFileDialog Dialog = new OpenFileDialog();

            Dialog.Title  = "Transmission SII File Import";
            Dialog.Filter = "SiiNunit|*.sii";
            if (Dialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    // Create document
                    var document = new SiiDocument(typeof(AccessoryTransmissionData), typeof(TransmissionNames));

                    using (FileStream stream = File.OpenRead(Dialog.FileName))
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            // Read the file contents
                            string contents = reader.ReadToEnd().Trim();
                            document.Load(contents);

                            // Grab the engine object
                            List <string> objects = new List <string>(document.Definitions.Keys);
                            if (objects.Count == 0)
                            {
                                MessageBox.Show("Unable to find any transmission data in this sii document!",
                                                "Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning
                                                );
                                return;
                            }

                            // Grab the transmission
                            var transmission = document.GetDefinition <AccessoryTransmissionData>(objects[0]);

                            // === Set form values
                            unitNameBox.Text  = Path.GetFileNameWithoutExtension(Dialog.FileName);
                            transNameBox.Text = transmission.Name;
                            unlockBox.SetValueInRange(transmission.UnlockLevel);
                            priceBox.SetValueInRange(transmission.Price);
                            diffRatio.SetValueInRange(transmission.DifferentialRatio);
                            if (transmission.StallTorqueRatio > 0m)
                            {
                                stallRatio.SetValueInRange(transmission.StallTorqueRatio);
                                hasTorqueConverter.Checked = true;
                            }
                            if (transmission.Retarder > 0)
                            {
                                retardPositions.SetValueInRange(transmission.Retarder);
                                hasRetarder.Checked = true;
                            }
                            fileDefaultsTextBox.Lines = transmission.Defaults;
                            filenameTextBox.Text      = Path.GetFileName(Dialog.FileName);
                            conflictsTextBox.Lines    = transmission.Conflicts;
                            suitablesTextBox.Lines    = transmission.Suitables;

                            // Clear chart points and gears
                            chart1.Series[0].Points.Clear();
                            gearListView.Items.Clear();
                            ForwardGears.Clear();
                            ReverseGears.Clear();

                            // Set gear ratios
                            var nameList = transmission.GearNames?.Reverse?.ToList();
                            int i        = 0;
                            foreach (var item in transmission.ReverseRatios)
                            {
                                string name = (nameList != null && i < nameList.Count) ? nameList[i] : string.Empty;
                                ReverseGears.Add(new TransmissionGear()
                                {
                                    Name      = name,
                                    Ratio     = item,
                                    GearIndex = i++
                                });
                            }

                            nameList = transmission.GearNames?.Forward?.ToList();
                            i        = 0;
                            foreach (var item in transmission.ForwardRatios)
                            {
                                string name = (nameList != null && i < nameList.Count) ? nameList[i] : string.Empty;
                                ForwardGears.Add(new TransmissionGear()
                                {
                                    Name      = name,
                                    Ratio     = item,
                                    GearIndex = i++
                                });
                            }

                            // Fill ratio view
                            PopulateGears();

                            // Flag
                            GearsChanged = true;

                            // Defaults (skip sounds)
                            if (transmission.Defaults != null)
                            {
                                fileDefaultsTextBox.Lines = transmission.Defaults;
                            }

                            // Alert the user
                            MessageBox.Show(
                                $"Successfully imported the transmission \"{transmission.Name}\"! You must now select a series for this transmission.",
                                "Import Successful", MessageBoxButtons.OK, MessageBoxIcon.Information
                                );
                        }
                }
                catch (SiiSyntaxException ex)
                {
                    StringBuilder builder = new StringBuilder("A Syntax error occured while parsing the sii file!");
                    builder.AppendLine();
                    builder.AppendLine();
                    builder.AppendLine($"Message: {ex.Message.Replace("\0", "\\0")}");
                    builder.AppendLine();
                    builder.AppendLine($"Line: {ex.Span.Start.Line}");
                    builder.AppendLine($"Column: {ex.Span.Start.Column}");
                    MessageBox.Show(builder.ToString(), "Sii Syntax Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (SiiException ex)
                {
                    StringBuilder builder = new StringBuilder("Failed to parse the sii file.");
                    builder.AppendLine();
                    builder.AppendLine($"Message: {ex.Message}");
                    MessageBox.Show(builder.ToString(), "Sii Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "An Error Occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }