/// <summary>
 /// Loads the presets for server multipliers and the changes for the singleplayer. If the loading is not successful, the default values are assumed.
 /// </summary>
 /// <param name="serverMultipliers"></param>
 /// <returns></returns>
 public static bool TryLoadServerMultipliersPresets(out ServerMultipliersPresets serverMultipliersPresets)
 {
     serverMultipliersPresets = new ServerMultipliersPresets();
     if (FileService.LoadJsonFile(FileService.GetJsonPath(FileService.ValuesServerMultipliers), out ServerMultipliersPresets readData, out string errorMessage))
     {
         if (Values.IsValidFormatVersion(readData.format))
         {
             serverMultipliersPresets = readData;
             return(true);
         }
         MessageBoxes.ShowMessageBox($"File {FileService.ValuesServerMultipliers} is a format that is unsupported in this version of ARK Smart Breeding." +
                                     "\n\nTry updating to a newer version.");
     }
Esempio n. 2
0
 /// <summary>
 /// Loads the presets for server multipliers and the changes for the singleplayer. If the loading is not successful, the default values are assumed.
 /// </summary>
 /// <param name="serverMultipliers"></param>
 /// <returns></returns>
 public static bool TryLoadServerMultipliersPresets(out ServerMultipliersPresets serverMultipliersPresets)
 {
     serverMultipliersPresets = new ServerMultipliersPresets();
     if (FileService.LoadJsonFile(FileService.GetJsonPath(FileService.ValuesServerMultipliers), out ServerMultipliersPresets readData, out string errorMessage))
     {
         if (Values.IsValidFormatVersion(readData.format))
         {
             serverMultipliersPresets = readData;
             return(true);
         }
         MessageBox.Show($"File {FileService.ValuesServerMultipliers} is a format that is unsupported in this version of ARK Smart Breeding." +
                         "\n\nTry updating to a newer version.",
                         $"{Loc.S("error")} - {Utils.ApplicationNameVersion}", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
Esempio n. 3
0
 /// <summary>
 /// Loads the presets for server multipliers and the changes for the singleplayer. If the loading is not successful, the default values are assumed.
 /// </summary>
 /// <param name="serverMultipliers"></param>
 /// <returns></returns>
 public static bool TryLoadServerMultipliersPresets(out ServerMultipliersPresets serverMultipliersPresets)
 {
     serverMultipliersPresets = new ServerMultipliersPresets();
     try
     {
         using (FileStream file = FileService.GetJsonFileStream(FileService.ValuesServerMultipliers))
         {
             DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ServerMultipliersPresets), new DataContractJsonSerializerSettings()
             {
                 UseSimpleDictionaryFormat = true
             });
             var tmpV = (ServerMultipliersPresets)ser.ReadObject(file);
             if (tmpV.format != Values.CURRENT_FORMAT_VERSION)
             {
                 throw new FormatException("Unhandled format version");
             }
             serverMultipliersPresets = tmpV;
             return(true);
         }
     }
     catch (FileNotFoundException)
     {
         if (MessageBox.Show($"Servermultipliers-File {FileService.ValuesServerMultipliers} not found. " +
                             "ARK Smart Breeding will not work properly without that file.\n\n" +
                             "Do you want to visit the releases page to redownload it?",
                             "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
         {
             System.Diagnostics.Process.Start(Updater.ReleasesUrl);
         }
         return(false);
     }
     catch (FormatException)
     {
         MessageBox.Show($"File {FileService.ValuesServerMultipliers} is a format that is unsupported in this version of ARK Smart Breeding." +
                         "\n\nTry updating to a newer version.",
                         "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
     catch (Exception e)
     {
         MessageBox.Show($"File {FileService.ValuesServerMultipliers} couldn't be opened or read.\nErrormessage:\n\n" + e.Message,
                         "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(false);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Loads the values from the default file.
        /// </summary>
        /// <returns></returns>
        public bool LoadValues()
        {
            try
            {
                using (FileStream file = FileService.GetJsonFileStream(Path.Combine(FileService.ValuesFolder, FileService.ValuesJson)))
                {
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Values)
                                                                                    , new DataContractJsonSerializerSettings()
                    {
                        UseSimpleDictionaryFormat = true
                    }
                                                                                    );
                    var tmpV = (Values)ser.ReadObject(file);
                    if (tmpV.format != CURRENT_FORMAT_VERSION)
                    {
                        throw new FormatException("Unhandled format version");
                    }
                    _V = tmpV;
                }
            }
            catch (FileNotFoundException)
            {
                if (MessageBox.Show($"Values-File {FileService.ValuesJson} not found. " +
                                    "ARK Smart Breeding will not work properly without that file.\n\n" +
                                    "Do you want to visit the releases page to redownload it?",
                                    "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start(Updater.ReleasesUrl);
                }
                return(false);
            }
            catch (FormatException)
            {
                MessageBox.Show($"File {FileService.ValuesJson} is a format that is unsupported in this version of ARK Smart Breeding." +
                                "\n\nTry updating to a newer version.",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(NullReferenceException))
                {
                    throw;
                }
                MessageBox.Show($"File {FileService.ValuesJson} couldn't be opened or read.\nErrormessage:\n\n" + e.Message,
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            bool setTamingFood = TamingFoodData.TryLoadDefaultFoodData(out specialFoodData);

            if (specialFoodData == null)
            {
                specialFoodData = new Dictionary <string, TamingData>();
            }
            _V.specialFoodData = specialFoodData;

            if (setTamingFood && specialFoodData.ContainsKey("default"))
            {
                _V.defaultFoodData = specialFoodData["default"].specialFoodValues;
            }
            else
            {
                _V.defaultFoodData = new Dictionary <string, TamingFood>();
            }

            _V.speciesNames = new List <string>();
            foreach (Species sp in _V.species)
            {
                _V.speciesNames.Add(sp.name);
                if (setTamingFood && specialFoodData.ContainsKey(sp.name))
                {
                    sp.taming.eats = specialFoodData[sp.name].eats;
                    sp.taming.specialFoodValues = specialFoodData[sp.name].specialFoodValues;
                }
            }

            OrderSpecies();

            _V.LoadAliases();
            _V.UpdateSpeciesBlueprintDictionaries();
            _V.loadedModsHash = CreatureCollection.CalculateModListHash(new List <Mod>());

            if (_V.modsManifest == null)
            {
                if (modsManifest != null)
                {
                    _V.modsManifest = modsManifest;
                }
                else
                {
                    _V.LoadModsManifest();
                }
            }

            if (serverMultipliersPresets != null)
            {
                _V.serverMultipliersPresets = serverMultipliersPresets;
            }
            else if (!ServerMultipliersPresets.TryLoadServerMultipliersPresets(out _V.serverMultipliersPresets))
            {
                MessageBox.Show("The file with the server multipliers couldn't be loaded. Changed settings, e.g. for the singleplayer will be not available.\nIt's recommended to download the application again.",
                                "Server multiplier file not loaded.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(true);
        }