Decompiled source of ReRenderingOptions v1.3.0

ReRenderingOptions.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Xml;
using System.Xml.Serialization;
using BepInEx;
using Colossal;
using Colossal.IO.AssetDatabase;
using Colossal.Localization;
using Colossal.Logging;
using Game;
using Game.Common;
using Game.Modding;
using Game.Rendering;
using Game.SceneFlow;
using Game.Settings;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ReRenderingOptions.Exporter;
using ReRenderingOptions.Settings;
using ReRenderingOptions.Systems;
using Unity.Entities;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ReRenderingOptions")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("ReRenderingOptions\r\n")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3")]
[assembly: AssemblyProduct("ReRenderingOptions")]
[assembly: AssemblyTitle("ReRenderingOptions")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ReRenderingOptions
{
	[BepInPlugin("com.nyoko.rerenderingoptions", "ReRenderingOptions", "1.3")]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "com.nyoko.rerenderingoptions";

		private Mod _mod;

		public void Awake()
		{
			_mod = new Mod();
			_mod.OnLoad();
			_mod.Log.Info((object)"ReRenderingOptions 1.3");
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.nyoko.rerenderingoptions");
		}

		[HarmonyPatch(typeof(SystemOrder), "Initialize")]
		[HarmonyPostfix]
		private static void InjectSystems(UpdateSystem updateSystem)
		{
			Mod.Instance.OnCreateWorld(updateSystem);
		}
	}
	internal static class Initializer
	{
		public static class ConsoleColors
		{
			public static void WriteColored(string message, ConsoleColor foregroundColor, ConsoleColor backgroundColor)
			{
				Console.ForegroundColor = foregroundColor;
				Console.BackgroundColor = backgroundColor;
				Console.Write(message);
				Console.ResetColor();
			}

			public static void WriteLineColored(string message, ConsoleColor foregroundColor, ConsoleColor backgroundColor)
			{
				Console.ForegroundColor = foregroundColor;
				Console.BackgroundColor = backgroundColor;
				Console.WriteLine(message);
				Console.ResetColor();
			}
		}

		public static void OnLoad()
		{
		}

		public static void OnInitialized()
		{
		}
	}
	public static class Localization
	{
		public static void LoadTranslations(ModSetting settings, ILog log)
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected O, but got Unknown
			try
			{
				using StreamReader streamReader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("ReRenderingOptions.l10n.csv"));
				List<string> list = new List<string>();
				while (!streamReader.EndOfStream)
				{
					list.Add(streamReader.ReadLine());
				}
				log.Debug((object)"parsing translation file");
				IEnumerable<string[]> source = list.Select((string x) => x.Split(new char[1] { '\t' }));
				string[] supportedLocales = GameManager.instance.localizationManager.GetSupportedLocales();
				foreach (string text in supportedLocales)
				{
					try
					{
						int valueColumn = Array.IndexOf(source.First(), text);
						if (valueColumn > 1)
						{
							log.Debug((object)("found translation for " + text));
							MemorySource val = new MemorySource(source.Skip(1).ToDictionary((string[] x) => GenerateOptionsKey(x[0], x[1], settings), (string[] x) => x.ElementAtOrDefault(valueColumn)));
							GameManager.instance.localizationManager.AddSource(text, (IDictionarySource)(object)val);
						}
					}
					catch (Exception ex)
					{
						log.Error(ex, (object)("exception reading localization for locale " + text));
					}
				}
			}
			catch (Exception ex2)
			{
				log.Error(ex2, (object)"exception reading settings localization file");
			}
		}

		private static string GenerateOptionsKey(string context, string key, ModSetting settings)
		{
			return context switch
			{
				"Options.OPTION" => settings.GetOptionLabelLocaleID(key), 
				"Options.OPTION_DESCRIPTION" => settings.GetOptionDescLocaleID(key), 
				"Options.WARNING" => settings.GetOptionWarningLocaleID(key), 
				"Options.TAB" => settings.GetOptionTabLocaleID(key), 
				"Options.GROUP" => settings.GetOptionGroupLocaleID(key), 
				_ => settings.GetSettingsLocaleID(), 
			};
		}
	}
	public sealed class Mod : IMod
	{
		public const string ModName = "ReRenderingOptions";

		public static Mod Instance { get; private set; }

		internal ILog Log { get; private set; }

		internal ModSettings ActiveSettings { get; private set; }

		public void OnLoad()
		{
			Instance = this;
			Log = LogManager.GetLogger("ReRenderingOptions", true);
			Log.Info((object)"setting logging level to Debug");
			Log.effectivenessLevel = Level.Debug;
			Log.Info((object)"loading");
		}

		public void OnCreateWorld(UpdateSystem updateSystem)
		{
			ActiveSettings = new ModSettings((IMod)(object)this);
			((ModSetting)ActiveSettings).RegisterInOptionsUI();
			Localization.LoadTranslations((ModSetting)(object)ActiveSettings, Log);
			updateSystem.UpdateAfter<ModeSystem>((SystemUpdatePhase)10);
			updateSystem.UpdateAfter<ModeSystem>((SystemUpdatePhase)12);
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
			folderPath = Path.Combine(folderPath, "..", "LocalLow");
			string text = Path.Combine(Path.Combine(folderPath, "Colossal Order", "Cities Skylines II", "Mods", "ReRenderingOptions"), "RROSettings.xml");
			Console.WriteLine("ReRenderingOptions 1.3", ConsoleColor.Blue, ConsoleColor.Blue);
			Console.WriteLine("Support: https://discord.gg/5gZgRNm29e", ConsoleColor.Blue, ConsoleColor.Blue);
			Console.WriteLine("Donate: https://shorturl.at/hmpCW", ConsoleColor.Blue, ConsoleColor.Blue);
			Console.ForegroundColor = ConsoleColor.Magenta;
			Console.WriteLine(" ────────────────────────────────── ");
			Console.ResetColor();
			Debug.Log((object)("ReRenderingOptions exported settings located at:" + text.ToString()));
			ActiveSettings.Load();
		}

		public void OnDispose()
		{
			Log.Info((object)"disposing");
			Instance = null;
		}
	}
	[FileLocation("ReRenderingOptions")]
	public class ModSettings : ModSetting
	{
		public class CacheValues
		{
			public static float CacheQualityLevel;
		}

		private bool ForceLowGlobalQualityValue;

		public float LowestValueSet = 0.001f;

		public float HighestValueSet = 5f;

		public static float Fraction = 1f;

		public bool Loaded;

		[SettingsUISection("ForceLowGlobalQuality")]
		public bool ForceLowGlobalQuality
		{
			get
			{
				return ForceLowGlobalQualityValue;
			}
			set
			{
				ForceLowGlobalQualityValue = value;
				if (value)
				{
					GlobalVariables.GlobalQualityLevel = 0;
				}
			}
		}

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		[SettingsUISlider(min = 0f, max = 100f, step = 1f, unit = "percentage", scaleDragVolume = true, scalarMultiplier = 1f)]
		public float GlobalQuality { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		[SettingsUISlider(min = 0f, max = 100f, step = 1f, unit = "percentage", scaleDragVolume = true, scalarMultiplier = 1f)]
		public float globalTextureMipmapLimit { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		[SettingsUISlider(min = 0f, max = 100f, step = 1f, unit = "percentage", scaleDragVolume = true, scalarMultiplier = 1f)]
		public float ShadowDistance { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		[SettingsUISlider(min = 0f, max = 100f, step = 1f, unit = "percentage", scaleDragVolume = true, scalarMultiplier = 1f)]
		public float ShadowCascades { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		[SettingsUISlider(min = 0f, max = 100f, step = 1f, unit = "percentage", scaleDragVolume = true, scalarMultiplier = 1f)]
		public float shadowNearPlaneOffset { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		public bool realtimeReflectionProbes { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		public bool billboardsFaceCameraPosition { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		[SettingsUISlider(min = 0f, max = 100f, step = 1f, unit = "percentage", scaleDragVolume = true, scalarMultiplier = 1f)]
		public float asyncUploadTimeSlice { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		[SettingsUISlider(min = 0f, max = 100f, step = 1f, unit = "percentage", scaleDragVolume = true, scalarMultiplier = 1f)]
		public float asyncUploadBufferSize { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		[SettingsUISlider(min = 0f, max = 100f, step = 1f, unit = "percentage", scaleDragVolume = true, scalarMultiplier = 1f)]
		public float terrainDetailDensityScale { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		[SettingsUISlider(min = 0f, max = 100f, step = 1f, unit = "percentage", scaleDragVolume = true, scalarMultiplier = 1f)]
		public float terrainPixelError { get; set; }

		[SettingsUISection("Advanced")]
		[SettingsUISlider(min = -50f, max = 100f, step = 1f, unit = "integer", scalarMultiplier = 1f)]
		public float levelOfDetail { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		public bool lodCrossFade { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISlider(min = 0f, max = 16384f, step = 256f, unit = "integer")]
		public int maxLightCount { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISlider(min = 64f, max = 4096f, step = 64f, unit = "dataMegabytes")]
		public int meshMemoryBudget { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISection("Advanced")]
		public bool strictMeshMemory { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISlider(min = -50f, max = 5f, step = 1f, unit = "integer")]
		public int finalTessellation { get; set; }

		[SettingsUIAdvanced]
		[SettingsUISlider(min = -50f, max = 64f, step = 1f, unit = "integer")]
		public int targetPatchSize { get; set; }

		[XmlIgnore]
		[SettingsUIButton]
		[SettingsUISection("ResetModSettings")]
		[SettingsUIConfirmation(null, null)]
		public bool ResetModSettings
		{
			set
			{
				((Setting)this).SetDefaults();
				((Setting)this).ApplyAndSave();
			}
		}

		public ModSettings(IMod mod)
			: base(mod)
		{
		}

		public override void SetDefaults()
		{
			ForceLowGlobalQualityValue = false;
			GlobalVariables.GlobalQualityLevel = 1;
			GlobalVariables.globalTextureMipmapLimit = 1;
			GlobalVariables.shadowDistance = 1;
			GlobalVariables.shadowCascades = 1;
			GlobalVariables.shadowNearPlaneOffset = 1;
			GlobalVariables.realtimeReflectionProbes = true;
			GlobalVariables.billboardsFaceCameraPosition = true;
			GlobalVariables.asyncUploadTimeSlice = 1;
			GlobalVariables.asyncUploadBufferSize = 1;
			GlobalVariables.terrainDetailDensityScale = 1;
			GlobalVariables.terrainPixelError = 1;
		}

		public void SetSettings()
		{
			GlobalQuality = GlobalVariables.GlobalQualityLevel;
			globalTextureMipmapLimit = GlobalVariables.globalTextureMipmapLimit;
			ShadowDistance = GlobalVariables.shadowDistance;
			ShadowCascades = GlobalVariables.shadowCascades;
			shadowNearPlaneOffset = GlobalVariables.shadowNearPlaneOffset;
			realtimeReflectionProbes = GlobalVariables.realtimeReflectionProbes;
			billboardsFaceCameraPosition = GlobalVariables.billboardsFaceCameraPosition;
			asyncUploadTimeSlice = GlobalVariables.asyncUploadTimeSlice;
			asyncUploadBufferSize = GlobalVariables.asyncUploadBufferSize;
			terrainDetailDensityScale = GlobalVariables.terrainDetailDensityScale;
			terrainPixelError = GlobalVariables.terrainPixelError;
		}

		public override void Apply()
		{
			((Setting)this).Apply();
			World defaultGameObjectInjectionWorld = World.DefaultGameObjectInjectionWorld;
			RenderingSystem obj = ((defaultGameObjectInjectionWorld != null) ? defaultGameObjectInjectionWorld.GetExistingSystemManaged<RenderingSystem>() : null);
			obj.levelOfDetail = levelOfDetail;
			obj.lodCrossFade = lodCrossFade;
			obj.maxLightCount = maxLightCount;
			World defaultGameObjectInjectionWorld2 = World.DefaultGameObjectInjectionWorld;
			BatchMeshSystem val = ((defaultGameObjectInjectionWorld2 != null) ? defaultGameObjectInjectionWorld2.GetExistingSystemManaged<BatchMeshSystem>() : null);
			if (val != null)
			{
				val.memoryBudget = (ulong)meshMemoryBudget * 1048576uL;
				val.strictMemoryBudget = strictMeshMemory;
			}
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
			folderPath = Path.Combine(folderPath, "..", "LocalLow");
			string text = Path.Combine(folderPath, "Colossal Order", "Cities Skylines II", "Mods", "ReRenderingOptions");
			string filePath = Path.Combine(text, "RROSettings.xml");
			Directory.CreateDirectory(text);
			if (Loaded)
			{
				GlobalVariables.GlobalQualityLevel = Convert.ToInt32(GlobalQuality);
				GlobalVariables.globalTextureMipmapLimit = Convert.ToInt32(globalTextureMipmapLimit);
				GlobalVariables.shadowDistance = Convert.ToInt32(ShadowDistance);
				GlobalVariables.shadowCascades = Convert.ToInt32(ShadowCascades);
				GlobalVariables.shadowNearPlaneOffset = Convert.ToInt32(shadowNearPlaneOffset);
				GlobalVariables.realtimeReflectionProbes = realtimeReflectionProbes;
				GlobalVariables.billboardsFaceCameraPosition = billboardsFaceCameraPosition;
				GlobalVariables.asyncUploadTimeSlice = Convert.ToInt32(asyncUploadTimeSlice);
				GlobalVariables.asyncUploadBufferSize = Convert.ToInt32(asyncUploadBufferSize);
				GlobalVariables.terrainDetailDensityScale = Convert.ToInt32(terrainDetailDensityScale);
				GlobalVariables.terrainPixelError = Convert.ToInt32(terrainPixelError);
				GlobalVariables.levelOfDetail = levelOfDetail;
				SettingsExporter.SaveGlobalVariablesToXml(filePath);
			}
		}

		public void Load()
		{
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
			folderPath = Path.Combine(folderPath, "..", "LocalLow");
			SettingsExporter.LoadGlobalVariablesFromXml(Path.Combine(Path.Combine(folderPath, "Colossal Order", "Cities Skylines II", "Mods", "ReRenderingOptions"), "RROSettings.xml"));
			Loaded = true;
			SetSettings();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ReRenderingOptions";

		public const string PLUGIN_NAME = "ReRenderingOptions";

		public const string PLUGIN_VERSION = "1.3";
	}
}
namespace ReRenderingOptions.Systems
{
	public class ModeSystem : SystemBase
	{
		protected override void OnUpdate()
		{
			ApplyGraphicsSettings();
		}

		private void ApplyGraphicsSettings()
		{
			QualitySettings.SetQualityLevel(GlobalVariables.GlobalQualityLevel, true);
			QualitySettings.globalTextureMipmapLimit = GlobalVariables.globalTextureMipmapLimit;
			QualitySettings.shadows = (ShadowQuality)0;
			QualitySettings.shadowResolution = (ShadowResolution)0;
			QualitySettings.shadowDistance = GlobalVariables.shadowDistance;
			QualitySettings.shadowCascades = GlobalVariables.shadowCascades;
			QualitySettings.shadowProjection = (ShadowProjection)0;
			QualitySettings.shadowNearPlaneOffset = GlobalVariables.shadowNearPlaneOffset;
			QualitySettings.realtimeReflectionProbes = GlobalVariables.realtimeReflectionProbes;
			QualitySettings.billboardsFaceCameraPosition = GlobalVariables.billboardsFaceCameraPosition;
			QualitySettings.antiAliasing = 0;
			QualitySettings.asyncUploadTimeSlice = GlobalVariables.asyncUploadTimeSlice;
			QualitySettings.asyncUploadBufferSize = GlobalVariables.asyncUploadBufferSize;
			QualitySettings.terrainDetailDensityScale = GlobalVariables.terrainDetailDensityScale;
			QualitySettings.terrainPixelError = GlobalVariables.terrainPixelError;
		}
	}
}
namespace ReRenderingOptions.Settings
{
	internal class GlobalVariables
	{
		public static int GlobalQualityLevel;

		public static int globalTextureMipmapLimit;

		public static int shadowDistance;

		public static int shadowCascades;

		public static int shadowProjection;

		public static int shadowNearPlaneOffset;

		public static bool realtimeReflectionProbes;

		public static bool billboardsFaceCameraPosition;

		public static int antiAliasing;

		public static int asyncUploadTimeSlice;

		public static int asyncUploadBufferSize;

		public static int terrainDetailDensityScale;

		public static int terrainPixelError;

		public static float levelOfDetail { get; set; }
	}
}
namespace ReRenderingOptions.Patches
{
	internal class LevelOfDetailPatch
	{
		[HarmonyPatch(typeof(LevelOfDetailQualitySettings))]
		[HarmonyPatch("Apply")]
		private class LevelOfDetailQualitySettings_Apply_Patch
		{
			private static bool Prefix()
			{
				Debug.Log((object)"ReRenderingOptions: Patched ingame settings with RRO settings");
				return false;
			}
		}
	}
}
namespace ReRenderingOptions.Exporter
{
	public class SettingsExporter
	{
		public static void ExportSettings()
		{
			string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "RROSettings2.txt");
			try
			{
				using StreamWriter streamWriter = new StreamWriter(path);
				World defaultGameObjectInjectionWorld = World.DefaultGameObjectInjectionWorld;
				RenderingSystem val = ((defaultGameObjectInjectionWorld != null) ? defaultGameObjectInjectionWorld.GetExistingSystemManaged<RenderingSystem>() : null);
				if (val != null)
				{
					streamWriter.WriteLine("RERENDERING OPTIONS");
					streamWriter.WriteLine();
					streamWriter.WriteLine("Rendering System Settings:");
					streamWriter.WriteLine($"Level of Detail: {val.levelOfDetail}");
					streamWriter.WriteLine($"LOD Cross Fade: {val.lodCrossFade}");
					streamWriter.WriteLine($"Max Light Count: {val.maxLightCount}");
					streamWriter.WriteLine();
				}
				World defaultGameObjectInjectionWorld2 = World.DefaultGameObjectInjectionWorld;
				BatchMeshSystem val2 = ((defaultGameObjectInjectionWorld2 != null) ? defaultGameObjectInjectionWorld2.GetExistingSystemManaged<BatchMeshSystem>() : null);
				if (val2 != null)
				{
					streamWriter.WriteLine("Batch Mesh System Settings:");
					streamWriter.WriteLine($"Memory Budget: {(long)val2.memoryBudget / 1048576L} MB");
					streamWriter.WriteLine($"Strict Memory Budget: {val2.strictMemoryBudget}");
					streamWriter.WriteLine();
				}
				streamWriter.WriteLine("Global Variables Settings:");
				streamWriter.WriteLine($"Global Quality Level: {GlobalVariables.GlobalQualityLevel}");
				streamWriter.WriteLine($"Global Texture Mipmap Limit: {GlobalVariables.globalTextureMipmapLimit}");
				streamWriter.WriteLine($"Shadow Distance: {GlobalVariables.shadowDistance}");
				streamWriter.WriteLine($"Shadow Cascades: {GlobalVariables.shadowCascades}");
				streamWriter.WriteLine($"Shadow Near Plane Offset: {GlobalVariables.shadowNearPlaneOffset}");
				streamWriter.WriteLine($"Realtime Reflection Probes: {GlobalVariables.realtimeReflectionProbes}");
				streamWriter.WriteLine($"Billboards Face Camera Position: {GlobalVariables.billboardsFaceCameraPosition}");
				streamWriter.WriteLine($"Async Upload Time Slice: {GlobalVariables.asyncUploadTimeSlice}");
				streamWriter.WriteLine($"Async Upload Buffer Size: {GlobalVariables.asyncUploadBufferSize}");
				streamWriter.WriteLine($"Terrain Detail Density Scale: {GlobalVariables.terrainDetailDensityScale}");
				streamWriter.WriteLine($"Terrain Pixel Error: {GlobalVariables.terrainPixelError}");
			}
			catch (Exception ex)
			{
				Console.WriteLine("Error exporting settings: " + ex.Message);
			}
		}

		public static void SaveGlobalVariablesToXml(string filePath)
		{
			XmlDocument xmlDocument = new XmlDocument();
			XmlElement xmlElement = xmlDocument.CreateElement("GlobalVariables");
			xmlDocument.AppendChild(xmlElement);
			AddXmlElement(xmlDocument, xmlElement, "GlobalQualityLevel", GlobalVariables.GlobalQualityLevel.ToString("D"));
			AddXmlElement(xmlDocument, xmlElement, "globalTextureMipmapLimit", GlobalVariables.globalTextureMipmapLimit.ToString("D"));
			AddXmlElement(xmlDocument, xmlElement, "shadowDistance", GlobalVariables.shadowDistance.ToString());
			AddXmlElement(xmlDocument, xmlElement, "shadowCascades", GlobalVariables.shadowCascades.ToString());
			AddXmlElement(xmlDocument, xmlElement, "shadowNearPlaneOffset", GlobalVariables.shadowNearPlaneOffset.ToString());
			AddXmlElement(xmlDocument, xmlElement, "realtimeReflectionProbes", GlobalVariables.realtimeReflectionProbes.ToString());
			AddXmlElement(xmlDocument, xmlElement, "billboardsFaceCameraPosition", GlobalVariables.billboardsFaceCameraPosition.ToString());
			AddXmlElement(xmlDocument, xmlElement, "asyncUploadTimeSlice", GlobalVariables.asyncUploadTimeSlice.ToString("D"));
			AddXmlElement(xmlDocument, xmlElement, "asyncUploadBufferSize", GlobalVariables.asyncUploadBufferSize.ToString("D"));
			AddXmlElement(xmlDocument, xmlElement, "terrainDetailDensityScale", GlobalVariables.terrainDetailDensityScale.ToString("D"));
			AddXmlElement(xmlDocument, xmlElement, "terrainPixelError", GlobalVariables.terrainPixelError.ToString("D"));
			AddXmlElement(xmlDocument, xmlElement, "levelOfDetail", GlobalVariables.levelOfDetail.ToString());
			xmlDocument.Save(filePath);
		}

		private static void AddXmlElement(XmlDocument xmlDoc, XmlElement parentElement, string elementName, string value)
		{
			XmlElement xmlElement = xmlDoc.CreateElement(elementName);
			xmlElement.InnerText = value;
			parentElement.AppendChild(xmlElement);
		}

		public static void LoadGlobalVariablesFromXml(string filePath)
		{
			if (File.Exists(filePath))
			{
				XmlDocument xmlDocument = new XmlDocument();
				xmlDocument.Load(filePath);
				{
					foreach (XmlNode childNode in xmlDocument.DocumentElement.ChildNodes)
					{
						try
						{
							switch (childNode.Name)
							{
							case "GlobalQualityLevel":
								GlobalVariables.GlobalQualityLevel = Convert.ToInt32(childNode.InnerText);
								break;
							case "globalTextureMipmapLimit":
								GlobalVariables.globalTextureMipmapLimit = Convert.ToInt32(childNode.InnerText);
								break;
							case "shadowDistance":
								GlobalVariables.shadowDistance = Convert.ToInt32(childNode.InnerText);
								break;
							case "shadowCascades":
								GlobalVariables.shadowCascades = Convert.ToInt32(childNode.InnerText);
								break;
							case "shadowNearPlaneOffset":
								GlobalVariables.shadowNearPlaneOffset = Convert.ToInt32(childNode.InnerText);
								break;
							case "realtimeReflectionProbes":
								GlobalVariables.realtimeReflectionProbes = Convert.ToBoolean(childNode.InnerText);
								break;
							case "billboardsFaceCameraPosition":
								GlobalVariables.billboardsFaceCameraPosition = Convert.ToBoolean(childNode.InnerText);
								break;
							case "asyncUploadTimeSlice":
								GlobalVariables.asyncUploadTimeSlice = Convert.ToInt32(childNode.InnerText);
								break;
							case "asyncUploadBufferSize":
								GlobalVariables.asyncUploadBufferSize = Convert.ToInt32(childNode.InnerText);
								break;
							case "terrainDetailDensityScale":
								GlobalVariables.terrainDetailDensityScale = Convert.ToInt32(childNode.InnerText);
								break;
							case "terrainPixelError":
								GlobalVariables.terrainPixelError = Convert.ToInt32(childNode.InnerText);
								break;
							case "levelOfDetail":
							{
								if (float.TryParse(childNode.InnerText, out var result))
								{
									GlobalVariables.levelOfDetail = result;
								}
								else
								{
									Debug.Log((object)"Couldn't master Level of Detail.");
								}
								break;
							}
							default:
								_ = childNode.InnerText;
								break;
							}
						}
						catch (FormatException ex)
						{
							Debug.Log((object)("Format Exception: " + ex.Message + " occurred while parsing '" + childNode.Name + "' field."));
						}
					}
					return;
				}
			}
			Console.WriteLine("RRO: XML file not found or you haven't set any settings.");
		}
	}
}