Decompiled source of DynamicResolutionExtended v1.0.0

DynamicResolutionExtended.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.Serialization;
using BepInEx;
using Colossal;
using Colossal.IO.AssetDatabase;
using Colossal.Localization;
using Colossal.Logging;
using DynamicResolutionExtended.Systems;
using Game;
using Game.Common;
using Game.Modding;
using Game.Rendering.Utilities;
using Game.SceneFlow;
using Game.Settings;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Entities;

[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("DynamicResolutionExtended")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Dynamic Resolution Extended")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DynamicResolutionExtended")]
[assembly: AssemblyTitle("DynamicResolutionExtended")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 DynamicResolutionExtended
{
	[BepInPlugin("com.nyoko.DynamicResolutionExtended", "Dynamic Resolution Extended", "1.0")]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "com.nyoko.DynamicResolutionExtended";

		private Mod _mod;

		public void Awake()
		{
			_mod = new Mod();
			_mod.OnLoad();
			_mod.Log.Info((object)"=======Dynamic Resolution Extended=======");
			_mod.Log.Info((object)"=======     Initialized   =======");
			_mod.Log.Info((object)"=======                   =======");
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.nyoko.DynamicResolutionExtended");
		}

		[HarmonyPatch(typeof(SystemOrder), "Initialize")]
		[HarmonyPostfix]
		private static void InjectSystems(UpdateSystem updateSystem)
		{
			Mod.Instance.OnCreateWorld(updateSystem);
		}
	}
	internal static class Initializer
	{
		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("DynamicResolutionExtended.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), 
				_ => settings.GetSettingsLocaleID(), 
			};
		}
	}
	public sealed class Mod : IMod
	{
		public const string ModName = "DynamicResolutionExtended";

		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("DynamicResolutionExtended", 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)12);
		}

		public void OnDispose()
		{
			Log.Info((object)"disposing");
			Instance = null;
		}
	}
	[FileLocation("DynamicResolutionExtended")]
	public class ModSettings : ModSetting
	{
		private bool HighestValue;

		public float LowestValueSet = 0.001f;

		public float HighestValueSet = 5f;

		public static float Fraction = 1f;

		private bool LowestValue;

		[SettingsUISection("SetHigherValue")]
		public bool SetHigherValue
		{
			get
			{
				return HighestValue;
			}
			set
			{
				HighestValue = value;
				Contra = value;
				if (value)
				{
					LowestValue = false;
					Fraction = HighestValueSet;
				}
				EnsureState();
			}
		}

		[SettingsUISection("SetLowerValue")]
		public bool SetLowerValue
		{
			get
			{
				return LowestValue;
			}
			set
			{
				LowestValue = value;
				if (value)
				{
					HighestValue = false;
					Fraction = LowestValueSet;
				}
				EnsureState();
			}
		}

		[SettingsUIHidden]
		public bool Contra { get; set; }

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

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

		public override void SetDefaults()
		{
			HighestValue = false;
			LowestValue = false;
		}

		public bool StartingTilesHidden()
		{
			return SetHigherValue;
		}

		private void EnsureState()
		{
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DynamicResolutionExtended";

		public const string PLUGIN_NAME = "DynamicResolutionExtended";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace DynamicResolutionExtended.Systems
{
	public class ModeSystem : SystemBase
	{
		protected override void OnUpdate()
		{
			SetPrivateFieldValue();
		}

		public void SetPrivateFieldValue()
		{
			FieldInfo field = typeof(AdaptiveDynamicResolutionScale).GetField("s_CurrentScaleFraction", BindingFlags.Static | BindingFlags.NonPublic);
			if (field != null)
			{
				field.SetValue(null, ModSettings.Fraction);
			}
			else
			{
				Console.WriteLine("[Critical] CurrentScaleFraction not found.");
			}
		}
	}
}