public void Deserialize(DataSerializer s)
        {
            try
            {
                options = null;
                data    = null;

                int count = s.ReadInt32();
                data = new VehicleData[count];

                DebugUtils.Log("AVO Savegame Version " + s.version);

                for (int i = 0; i < count; i++)
                {
                    data[i]               = new VehicleData();
                    data[i].name          = s.ReadUniqueString();
                    data[i].enabled       = s.ReadBool();
                    data[i].addBackEngine = s.ReadBool();
                    data[i].maxSpeed      = s.ReadFloat();
                    data[i].acceleration  = s.ReadFloat();
                    data[i].braking       = s.ReadFloat();

                    if (s.version >= 2)                                          // Skip loading new vehicle propertiers for all versions below 1.9.0
                    {
                        data[i].turning        = s.ReadFloat();
                        data[i].springs        = s.ReadFloat();
                        data[i].dampers        = s.ReadFloat();
                        data[i].leanMultiplier = s.ReadFloat();
                        data[i].nodMultiplier  = s.ReadFloat();
                    }

                    data[i].useColorVariations = s.ReadBool();
                    data[i].color0             = new HexaColor(s.ReadUniqueString());
                    data[i].color1             = new HexaColor(s.ReadUniqueString());
                    data[i].color2             = new HexaColor(s.ReadUniqueString());
                    data[i].color3             = new HexaColor(s.ReadUniqueString());
                    data[i].capacity           = s.ReadInt32();

                    if (s.version >= 3)                                         // Skip loading Special Capacity for all versions below 1.9.3
                    {
                        data[i].specialcapacity = s.ReadInt32();
                        data[i].isLargeVehicle  = s.ReadBool();
                    }
                }
            }
            catch (Exception e)
            {
                // Couldn't Deserialize
                DebugUtils.Warning("Couldn't deserialize");
                DebugUtils.LogException(e);
            }
        }
        public void Deserialize(string filename)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
            Configuration config        = null;

            options = null;
            data    = null;

            try
            {
                // Trying to Deserialize the configuration file
                using (FileStream stream = new FileStream(filename, FileMode.Open))
                {
                    config = xmlSerializer.Deserialize(stream) as Configuration;
                }
            }
            catch (Exception e)
            {
                // Couldn't Deserialize (XML malformed?)
                DebugUtils.Warning("Couldn't load configuration (XML malformed?)");
                DebugUtils.LogException(e);

                config = null;
            }

            if (config != null)
            {
                data = config.data;

                if (data != null)
                {
                    // Saves all default vehicle options that might not exist on the map
                    // I.E. Snowplow on non-snowy maps
                    m_defaultVehicles.Clear();
                    for (int i = 0; i < data.Length; i++)
                    {
                        if (data[i] != null && !data[i].isCustomAsset)
                        {
                            m_defaultVehicles.Add(data[i]);
                        }
                    }
                }


                if (AdvancedVehicleOptionsUID.isGameLoaded)
                {
                    DataToOptions();
                }
            }
        }
        // Serialize to file
        public void Serialize(string filename)
        {
            try
            {
                if (AdvancedVehicleOptionsUID.isGameLoaded)
                {
                    OptionsToData();
                }

                // Add back default vehicle options that might not exist on the map
                // I.E. Snowplow on non-snowy maps
                if (m_defaultVehicles.Count > 0)
                {
                    List <VehicleData> new_data = new List <VehicleData>(data);

                    for (int i = 0; i < m_defaultVehicles.Count; i++)
                    {
                        bool found = false;
                        for (int j = 0; j < data.Length; j++)
                        {
                            if (m_defaultVehicles[i].name == data[j].name)
                            {
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            new_data.Add(m_defaultVehicles[i]);
                        }
                    }

                    data = new_data.ToArray();
                }

                using (FileStream stream = new FileStream(filename, FileMode.OpenOrCreate))
                {
                    stream.SetLength(0); // Emptying the file !!!
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(Configuration));
                    xmlSerializer.Serialize(stream, this);
                    DebugUtils.Log("Configuration saved");
                }
            }
            catch (Exception e)
            {
                DebugUtils.Warning("Couldn't save configuration at \"" + Directory.GetCurrentDirectory() + "\"");
                DebugUtils.LogException(e);
            }
        }
        public void Deserialize(DataSerializer s)
        {
            try
            {
                options = null;
                data    = null;

                int count = s.ReadInt32();
                data = new VehicleData[count];

                for (int i = 0; i < count; i++)
                {
                    data[i]                    = new VehicleData();
                    data[i].name               = s.ReadUniqueString();
                    data[i].enabled            = s.ReadBool();
                    data[i].addBackEngine      = s.ReadBool();
                    data[i].maxSpeed           = s.ReadFloat();
                    data[i].acceleration       = s.ReadFloat();
                    data[i].braking            = s.ReadFloat();
                    data[i].turning            = s.ReadFloat();
                    data[i].springs            = s.ReadFloat();
                    data[i].dampers            = s.ReadFloat();
                    data[i].leanMultiplier     = s.ReadFloat();
                    data[i].nodMultiplier      = s.ReadFloat();
                    data[i].useColorVariations = s.ReadBool();
                    data[i].color0             = new HexaColor(s.ReadUniqueString());
                    data[i].color1             = new HexaColor(s.ReadUniqueString());
                    data[i].color2             = new HexaColor(s.ReadUniqueString());
                    data[i].color3             = new HexaColor(s.ReadUniqueString());
                    data[i].capacity           = s.ReadInt32();
                }
            }
            catch (Exception e)
            {
                // Couldn't Deserialize
                DebugUtils.Warning("Couldn't deserialize");
                DebugUtils.LogException(e);
            }
        }