public static void Restore(VehicleInfo prefab)
        {
            if (prefab == null)
            {
                return;
            }

            VehicleOptions options = new VehicleOptions();

            options.SetPrefab(prefab);

            DefaultOptions stored = m_default[prefab.name];

            if (stored == null)
            {
                return;
            }

            options.enabled            = stored.m_enabled;
            options.addBackEngine      = stored.m_addBackEngine;
            options.maxSpeed           = stored.m_maxSpeed;
            options.acceleration       = stored.m_acceleration;
            options.braking            = stored.m_braking;
            options.useColorVariations = stored.m_useColorVariations;
            options.color0             = stored.m_color0;
            options.color1             = stored.m_color1;
            options.color2             = stored.m_color2;
            options.color3             = stored.m_color3;
            options.capacity           = stored.m_capacity;
            prefab.m_placementStyle    = stored.m_placementStyle;
        }
        public static void CheckForConflicts()
        {
            StringBuilder conflicts = new StringBuilder();

            foreach (string name in m_default.Keys)
            {
                VehicleOptions options = new VehicleOptions();
                options.SetPrefab(m_prefabs[name]);

                DefaultOptions modded = m_modded[name];
                DefaultOptions stored = m_default[name];

                StringBuilder details = new StringBuilder();

                if (modded.m_enabled != stored.m_enabled && options.enabled == stored.m_enabled)
                {
                    options.enabled = modded.m_enabled;
                    details.Append("enabled, ");
                }
                if (modded.m_addBackEngine != stored.m_addBackEngine && options.addBackEngine == stored.m_addBackEngine)
                {
                    options.addBackEngine = modded.m_addBackEngine;
                    details.Append("back engine, ");
                }
                if (modded.m_maxSpeed != stored.m_maxSpeed && options.maxSpeed == stored.m_maxSpeed)
                {
                    options.maxSpeed = modded.m_maxSpeed;
                    details.Append("max speed, ");
                }
                if (modded.m_acceleration != stored.m_acceleration && options.acceleration == stored.m_acceleration)
                {
                    options.acceleration = modded.m_acceleration;
                    details.Append("acceleration, ");
                }
                if (modded.m_braking != stored.m_braking && options.braking == stored.m_braking)
                {
                    options.braking = modded.m_braking;
                    details.Append("braking, ");
                }
                if (modded.m_capacity != stored.m_capacity && options.capacity == stored.m_capacity)
                {
                    options.capacity = modded.m_capacity;
                    details.Append("capacity, ");
                }

                if (details.Length > 0)
                {
                    details.Length -= 2;
                    conflicts.AppendLine(options.name + ": " + details);
                }
            }

            if (conflicts.Length > 0)
            {
                VehicleOptions.UpdateTransfertVehicles();
                DebugUtils.Log("Conflicts detected (this message is harmless):" + Environment.NewLine + conflicts);
            }
        }
예제 #3
0
        /// <summary>
        /// Load and apply the configuration file
        /// </summary>
        public static void LoadConfig()
        {
            if (!isGameLoaded)
            {
                if (File.Exists(m_fileName))
                {
                    config.Deserialize(m_fileName);
                }
                return;
            }

            // Store modded values
            DefaultOptions.StoreAllModded();

            if (!File.Exists(m_fileName))
            {
                DebugUtils.Log("Configuration file not found. Creating new configuration file.");

                CreateConfig();

                return;
            }

            config.Deserialize(m_fileName);

            if (config.options == null)
            {
                DebugUtils.Log("Configuration empty. Default values will be used.");
            }
            else
            {
                // Remove unneeded options
                List <VehicleOptions> optionsList = new List <VehicleOptions>();

                for (uint i = 0; i < config.options.Length; i++)
                {
                    if (config.options[i] != null && config.options[i].prefab != null)
                    {
                        optionsList.Add(config.options[i]);
                    }
                }

                config.options = optionsList.ToArray();
            }

            // Checking for new vehicles
            CompileVehiclesList();

            // Checking for conflicts
            DefaultOptions.CheckForConflicts();

            // Update existing vehicles
            new EnumerableActionThread(VehicleOptions.UpdateCapacityUnits);
            new EnumerableActionThread(VehicleOptions.UpdateBackEngines);

            DebugUtils.Log("Configuration loaded");
            LogVehicleListSteamID();
        }
예제 #4
0
        public static void StoreAll()
        {
            DefaultOptions.Clear();
            for (uint i = 0; i < PrefabCollection <VehicleInfo> .PrefabCount(); i++)
            {
                DefaultOptions.Store(PrefabCollection <VehicleInfo> .GetPrefab(i));
            }

            DebugUtils.Log("Default values stored");
        }
예제 #5
0
 public override void OnReleased()
 {
     try
     {
         DebugUtils.Log("Restoring default values");
         DefaultOptions.RestoreAll();
         DefaultOptions.Clear();
     }
     catch (Exception e)
     {
         DebugUtils.LogException(e);
     }
 }
예제 #6
0
        /// <summary>
        /// Called when the level (game, map editor, asset editor) is loaded
        /// </summary>
        public override void OnLevelLoaded(LoadMode mode)
        {
            try
            {
                // Is it an actual game ?
                if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame)
                {
                    DefaultOptions.Clear();
                    return;
                }

                AdvancedVehicleOptions.isGameLoaded = true;

                if (instance != null)
                {
                    GameObject.DestroyImmediate(instance.gameObject);
                }

                instance = new GameObject("AdvancedVehicleOptions").AddComponent <AdvancedVehicleOptions>();

                try
                {
                    DefaultOptions.BuildVehicleInfoDictionary();
                    VehicleOptions.Clear();
                    DebugUtils.Log("UIMainPanel created");
                }
                catch
                {
                    DebugUtils.Log("Could not create UIMainPanel");

                    if (instance != null)
                    {
                        GameObject.Destroy(instance.gameObject);
                    }

                    return;
                }

                //new EnumerableActionThread(BrokenAssetsFix);
            }
            catch (Exception e)
            {
                if (instance != null)
                {
                    GameObject.Destroy(instance.gameObject);
                }
                DebugUtils.LogException(e);
            }
        }
예제 #7
0
        public override void OnCreated(ILoading loading)
        {
            try
            {
                // Storing default values ASAP (before any mods have the time to change values)
                DefaultOptions.StoreAll();

                // Creating a backup
                AdvancedVehicleOptions.SaveBackup();
            }
            catch (Exception e)
            {
                DebugUtils.LogException(e);
            }
        }
            private IEnumerator Store()
            {
                while (PrefabCollection <VehicleInfo> .GetPrefab(0) == null)
                {
                    yield return(null);
                }

                DefaultOptions.Clear();
                for (uint i = 0; i < PrefabCollection <VehicleInfo> .PrefabCount(); i++)
                {
                    DefaultOptions.Store(PrefabCollection <VehicleInfo> .GetPrefab(i));
                }

                DebugUtils.Log("Default values stored");
                Destroy(gameObject);
            }
예제 #9
0
        /// <summary>
        /// Init the configuration
        /// </summary>
        public static void InitConfig()
        {
            // Store modded values
            DefaultOptions.StoreAllModded();

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

                // Remove unneeded options
                List <VehicleOptions> optionsList = new List <VehicleOptions>();

                for (uint i = 0; i < config.options.Length; i++)
                {
                    if (config.options[i] != null && config.options[i].prefab != null)
                    {
                        optionsList.Add(config.options[i]);
                    }
                }

                config.options = optionsList.ToArray();
            }
            else if (File.Exists(m_fileName))
            {
                // Import config
                ImportConfig();
                return;
            }
            else
            {
                DebugUtils.Log("No configuration found. Default values will be used.");
            }

            // Checking for new vehicles
            CompileVehiclesList();

            // Checking for conflicts
            DefaultOptions.CheckForConflicts();

            // Update existing vehicles
            new EnumerableActionThread(VehicleOptions.UpdateCapacityUnits);
            new EnumerableActionThread(VehicleOptions.UpdateBackEngines);

            DebugUtils.Log("Configuration initialized");
            LogVehicleListSteamID();
        }
예제 #10
0
        /// <summary>
        /// Called when the level is unloaded
        /// </summary>
        public override void OnLevelUnloading()
        {
            try
            {
                DebugUtils.Log("Restoring default values");
                DefaultOptions.RestoreAll();
                DefaultOptions.Clear();

                if (instance != null)
                {
                    GameObject.Destroy(instance.gameObject);
                }

                AdvancedVehicleOptions.isGameLoaded = false;
            }
            catch (Exception e)
            {
                DebugUtils.LogException(e);
            }
        }
        public override void OnLoadData()
        {
            if (ToolManager.instance.m_properties.m_mode != ItemClass.Availability.Game)
            {
                return;
            }

            // Storing default values ASAP (before any mods have the time to change values)
            DefaultOptions.StoreAll();

            if (!serializableDataManager.EnumerateData().Contains(ID))
            {
                return;
            }
            var data = serializableDataManager.LoadData(ID);

            using (var ms = new MemoryStream(data))
            {
                AdvancedVehicleOptions.config.data = DataSerializer.Deserialize <Configuration>(ms, DataSerializer.Mode.Memory).data;
            }
        }