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 ColorAdjustments.UI;
using ColorAdjustmentsMod.Settings;
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;
using ReRenderingOptions.Systems;
using Unity.Entities;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
[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("ColorAdjustments")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("ReRenderingOptions\r\n")]
[assembly: AssemblyFileVersion("1.3.1.0")]
[assembly: AssemblyInformationalVersion("1.3.1")]
[assembly: AssemblyProduct("ColorAdjustments")]
[assembly: AssemblyTitle("ColorAdjustments")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.1.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 ColorAdjustments
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ColorAdjustments";
public const string PLUGIN_NAME = "ColorAdjustments";
public const string PLUGIN_VERSION = "1.3.1";
}
}
namespace ColorAdjustments.UI
{
public class SliderPanel : MonoBehaviour
{
private float slider1Value = GlobalVariables.Instance.PostExposure;
private float slider2Value = GlobalVariables.Instance.Contrast;
private float slider3Value = GlobalVariables.Instance.hueShift;
private float slider4Value = GlobalVariables.Instance.Saturation;
private bool panelVisible;
private Rect panelRect = new Rect(10f, 10f, 300f, 200f);
private Rect buttonRect = new Rect(10f, 10f, 150f, 30f);
private Vector2 panelOffset;
private Vector2 buttonOffset;
private bool isDraggingPanel;
private bool isDraggingButton;
private Vector2 buttonDragStartPosition;
private bool buttonVisible { get; set; }
private void Update()
{
if (GlobalVariables.Instance.ButtonActive)
{
buttonVisible = true;
}
else
{
buttonVisible = false;
}
if ((Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307)) && Input.GetKeyDown((KeyCode)99))
{
panelVisible = !panelVisible;
}
}
private void OnGUI()
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
if (buttonVisible)
{
buttonRect = GUI.Window(1, buttonRect, new WindowFunction(ButtonWindow), "ColorAdjustments");
}
if (panelVisible)
{
panelRect = GUI.Window(0, panelRect, new WindowFunction(PanelWindow), "ColorAdjustments");
}
}
private void ButtonWindow(int windowID)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
if (GUI.Button(new Rect(0f, 0f, ((Rect)(ref buttonRect)).width, ((Rect)(ref buttonRect)).height), "ColorAdjustments"))
{
panelVisible = !panelVisible;
}
if ((int)Event.current.type == 0 && Event.current.button == 1)
{
isDraggingButton = true;
buttonDragStartPosition = Event.current.mousePosition - ((Rect)(ref buttonRect)).position;
}
if (isDraggingButton)
{
((Rect)(ref buttonRect)).position = Event.current.mousePosition - buttonDragStartPosition;
}
}
private void PanelWindow(int windowID)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_0297: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Invalid comparison between Unknown and I4
//IL_0335: Unknown result type (might be due to invalid IL or missing references)
//IL_033b: Invalid comparison between Unknown and I4
//IL_0316: Unknown result type (might be due to invalid IL or missing references)
//IL_0320: Unknown result type (might be due to invalid IL or missing references)
//IL_0325: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref panelRect)).width, 20f));
GUI.Label(new Rect(20f, 20f, 100f, 20f), "Post Exposure");
slider1Value = GUI.HorizontalSlider(new Rect(20f, 40f, 100f, 20f), slider1Value, 0f, 100f);
GlobalVariables.Instance.PostExposure = slider1Value;
GUI.Label(new Rect(20f, 60f, 100f, 20f), "Contrast");
slider2Value = GUI.HorizontalSlider(new Rect(20f, 80f, 100f, 20f), slider2Value, 0f, 100f);
slider2Value = Mathf.Round(slider2Value * 1000f) / 1000f;
GlobalVariables.Instance.Contrast = slider2Value;
GUI.Label(new Rect(20f, 100f, 100f, 20f), "Hue Shift");
slider3Value = GUI.HorizontalSlider(new Rect(20f, 120f, 100f, 20f), slider3Value, -180f, 180f);
slider3Value = Mathf.Round(slider3Value * 1000f) / 1000f;
GlobalVariables.Instance.hueShift = slider3Value;
GUI.Label(new Rect(20f, 140f, 100f, 20f), "Saturation");
slider4Value = GUI.HorizontalSlider(new Rect(20f, 160f, 100f, 20f), slider4Value, 0f, 100f);
slider4Value = Mathf.Round(slider4Value * 1000f) / 1000f;
GlobalVariables.Instance.Saturation = slider4Value;
string s = GUI.TextField(new Rect(130f, 40f, 40f, 20f), slider1Value.ToString());
slider1Value = float.Parse(s);
string s2 = GUI.TextField(new Rect(130f, 80f, 40f, 20f), slider2Value.ToString());
slider2Value = float.Parse(s2);
string s3 = GUI.TextField(new Rect(130f, 120f, 40f, 20f), slider3Value.ToString());
slider3Value = float.Parse(s3);
string s4 = GUI.TextField(new Rect(130f, 160f, 40f, 20f), slider4Value.ToString());
slider4Value = float.Parse(s4);
if ((int)Event.current.type == 3 && Event.current.button == 0)
{
isDraggingPanel = true;
panelOffset = ((Rect)(ref panelRect)).position - Event.current.mousePosition;
}
else if ((int)Event.current.type == 1)
{
isDraggingPanel = false;
}
}
}
}
namespace UnityEngine.Rendering.HighDefinition
{
[HarmonyPatch(typeof(ColorAdjustments))]
[HarmonyPatch("IsActive")]
internal class ColorAdjustmentsPatch
{
private static void Postfix(ref bool __result)
{
Debug.Log((object)"Patched ColorAdjustments");
__result = true;
}
}
[HarmonyPatch(typeof(WhiteBalance))]
[HarmonyPatch("IsActive")]
internal class WhiteBalancePatch
{
private static bool Prefix()
{
Debug.Log((object)"WhiteBalance.IsActive() has been prevented");
return false;
}
}
}
namespace ReRenderingOptions
{
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("ColorAdjustments.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(),
};
}
}
}
namespace ReRenderingOptions.Systems
{
internal class EnablerVolumeSystem : SystemBase
{
protected override void OnUpdate()
{
System.InitializedVolume = true;
}
}
internal class System : SystemBase
{
private Volume Volume = new Volume();
private ColorAdjustments colorAdjustments;
private PhotoModeRenderSystem PhotoModeRenderSystem;
public static bool InitializedVolume = false;
public static bool PanelInitialized = false;
public static bool Panel = true;
protected override void OnUpdate()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Expected O, but got Unknown
if (Panel)
{
new GameObject().AddComponent<SliderPanel>();
PanelInitialized = true;
Panel = false;
}
FieldInfo field = typeof(LightingSystem).GetField("m_ColorAdjustments", BindingFlags.Instance | BindingFlags.NonPublic);
if (!(field != null))
{
return;
}
LightingSystem existingSystemManaged = ((ComponentSystemBase)this).World.GetExistingSystemManaged<LightingSystem>();
colorAdjustments = (ColorAdjustments)field.GetValue(existingSystemManaged);
if (!((Object)(object)colorAdjustments != (Object)null))
{
return;
}
((VolumeParameter<float>)(object)colorAdjustments.postExposure).Override(GlobalVariables.Instance.PostExposure);
((VolumeParameter<float>)(object)colorAdjustments.contrast).Override(GlobalVariables.Instance.Contrast);
((VolumeParameter<float>)(object)colorAdjustments.hueShift).Override(GlobalVariables.Instance.hueShift);
((VolumeParameter<float>)(object)colorAdjustments.saturation).Override(GlobalVariables.Instance.Saturation);
_ = ((VolumeParameter<float>)(object)colorAdjustments.postExposure).value;
_ = ((VolumeParameter<float>)(object)colorAdjustments.contrast).value;
FieldInfo field2 = typeof(PhotoModeRenderSystem).GetField("m_WhiteBalance", BindingFlags.Instance | BindingFlags.NonPublic);
if (!(field2 != null))
{
return;
}
PhotoModeRenderSystem existingSystemManaged2 = ((ComponentSystemBase)this).World.GetExistingSystemManaged<PhotoModeRenderSystem>();
if (existingSystemManaged2 != null)
{
WhiteBalance val = (WhiteBalance)field2.GetValue(existingSystemManaged2);
if ((Object)(object)val != (Object)null)
{
((VolumeParameter<float>)(object)val.temperature).Override(GlobalVariables.Instance.Temperature);
((VolumeParameter<float>)(object)val.tint).Override(GlobalVariables.Instance.Tint);
}
}
}
}
}
namespace ColorAdjustmentsMod.Settings
{
[Serializable]
public class GlobalVariables
{
private static GlobalVariables instance;
[XmlElement]
public float PostExposure { get; set; }
[XmlElement]
public float Contrast { get; set; }
[XmlElement]
public float hueShift { get; set; }
[XmlElement]
public float Saturation { get; set; }
[XmlElement]
public float Temperature { get; set; }
[XmlElement]
public float Tint { get; set; }
[XmlElement]
public bool ButtonActive { get; set; }
public static GlobalVariables Instance
{
get
{
if (instance == null)
{
instance = new GlobalVariables();
}
return instance;
}
}
public static void SaveToFile(string filePath)
{
try
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(GlobalVariables));
using TextWriter textWriter = new StreamWriter(filePath);
xmlSerializer.Serialize(textWriter, Instance);
}
catch (Exception ex)
{
Console.WriteLine("Error saving GlobalVariables to file: " + ex.Message);
}
}
public static GlobalVariables LoadFromFile(string filePath)
{
try
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(GlobalVariables));
using TextReader textReader = new StreamReader(filePath);
GlobalVariables globalVariables = (GlobalVariables)xmlSerializer.Deserialize(textReader);
Instance.PostExposure = globalVariables.PostExposure;
Instance.Contrast = globalVariables.Contrast;
Instance.hueShift = globalVariables.hueShift;
Instance.Saturation = globalVariables.Saturation;
Instance.Temperature = globalVariables.Temperature;
Instance.Tint = globalVariables.Tint;
Instance.ButtonActive = globalVariables.ButtonActive;
return globalVariables;
}
catch (Exception)
{
Console.WriteLine("Failed to load ColorAdjustments settings. Ensure that at least one setting is set.");
return null;
}
}
}
}
namespace ColorAdjustmentsMod.Mod
{
[BepInPlugin("com.nyoko.coloradjustments", "ColorAdjustments", "1.3.1")]
[HarmonyPatch]
public class Plugin : BaseUnityPlugin
{
public const string GUID = "com.nyoko.coloradjustments";
private Mod _mod;
public void Awake()
{
_mod = new Mod();
_mod.OnLoad();
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.nyoko.coloradjustments");
}
[HarmonyPatch(typeof(SystemOrder), "Initialize")]
[HarmonyPostfix]
private static void InjectSystems(UpdateSystem updateSystem)
{
Mod.Instance.OnCreateWorld(updateSystem);
}
}
public sealed class Mod : IMod
{
public const string ModName = "ColorAdjustments";
public static string Version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
public bool Compatible;
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("ColorAdjustments", true);
Log.Info((object)"setting logging level to Debug");
Log.effectivenessLevel = Level.Debug;
Log.Info((object)"loading");
}
public void OnCreateWorld(UpdateSystem updateSystem)
{
if (Application.version.ToString().Equals("1.0.19f1"))
{
Compatible = true;
}
if (Compatible)
{
ActiveSettings = new ModSettings((IMod)(object)this);
((ModSetting)ActiveSettings).RegisterInOptionsUI();
Localization.LoadTranslations((ModSetting)(object)ActiveSettings, Log);
updateSystem.UpdateAfter<ReRenderingOptions.Systems.System>((SystemUpdatePhase)12);
updateSystem.UpdateAfter<EnablerVolumeSystem>((SystemUpdatePhase)12);
updateSystem.UpdateAfter<ReRenderingOptions.Systems.System>((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", "ColorAdjustments"), "ColorAdjustments.xml");
Console.WriteLine("ColorAdjustments " + Version, 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)("ColorAdjustments exported settings located at:" + text));
GlobalVariables.LoadFromFile(text);
}
else
{
Console.WriteLine("ColorAdjustments is not compatible with your game version. Contact the developer: https://discord.gg/5gZgRNm29e");
}
}
public void OnDispose()
{
Log.Info((object)"disposing");
Instance = null;
}
}
[FileLocation("ColorAdjustments")]
public class ModSettings : ModSetting
{
public float LowestValueSet = 0.001f;
public float HighestValueSet = 5f;
public static float Fraction = 1f;
public bool Loaded;
[SettingsUISection("Advanced")]
public bool ButtonActive
{
get
{
return GlobalVariables.Instance.ButtonActive;
}
set
{
GlobalVariables.Instance.ButtonActive = value;
SaveToFileIn();
}
}
[SettingsUISection("Advanced")]
[SettingsUISlider(min = -500f, max = 1000f, step = 1f, unit = "percentage", scaleDragVolume = true, scalarMultiplier = 100f)]
public float PostExposure
{
get
{
return GlobalVariables.Instance.PostExposure;
}
set
{
GlobalVariables.Instance.PostExposure = value;
SaveToFileIn();
}
}
[SettingsUISection("Advanced")]
[SettingsUISlider(min = -10000f, max = 10000f, step = 10f, unit = "integer", scaleDragVolume = true, scalarMultiplier = 100f)]
public float Contrast
{
get
{
return GlobalVariables.Instance.Contrast;
}
set
{
GlobalVariables.Instance.Contrast = value;
SaveToFileIn();
}
}
[SettingsUISection("Advanced")]
[SettingsUISlider(min = -10000f, max = 10000f, step = 10f, unit = "integer", scaleDragVolume = true, scalarMultiplier = 100f)]
public float HueShift
{
get
{
return GlobalVariables.Instance.hueShift;
}
set
{
GlobalVariables.Instance.hueShift = value;
SaveToFileIn();
}
}
[SettingsUISection("Advanced")]
[SettingsUISlider(min = -10000f, max = 10000f, step = 10f, unit = "integer", scaleDragVolume = true, scalarMultiplier = 100f)]
public float Saturation
{
get
{
return GlobalVariables.Instance.Saturation;
}
set
{
GlobalVariables.Instance.Saturation = value;
SaveToFileIn();
}
}
[XmlIgnore]
[SettingsUIButton]
[SettingsUISection("ResetModSettings")]
[SettingsUIConfirmation(null, null)]
public bool ResetModSettings
{
set
{
((Setting)this).SetDefaults();
((Setting)this).ApplyAndSave();
}
}
[SettingsUIButton]
[SettingsUISection("Advanced")]
public bool OpenLocationButton
{
set
{
OpenLocation();
}
}
[SettingsUIButton]
[SettingsUISection("Advanced")]
public bool Support
{
set
{
OpenDiscordInvite();
}
}
public ModSettings(IMod mod)
: base(mod)
{
}
public override void SetDefaults()
{
GlobalVariables.Instance.hueShift = 1f;
GlobalVariables.Instance.PostExposure = 1f;
GlobalVariables.Instance.Saturation = 1f;
GlobalVariables.Instance.Contrast = 1f;
SaveToFileIn();
}
public void OpenLocation()
{
try
{
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", "ColorAdjustments"), "ColorAdjustments.xml");
if (File.Exists(text))
{
Process.Start(text);
}
else
{
Console.WriteLine("File not found: " + text);
}
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
public void OpenDiscordInvite()
{
try
{
Process.Start("https://discord.gg/5JcaKwDBHn");
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: " + ex.Message);
}
}
public void SaveToFileIn()
{
string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
folderPath = Path.Combine(folderPath, "..", "LocalLow");
string text = Path.Combine(folderPath, "Colossal Order", "Cities Skylines II", "Mods", "ColorAdjustments");
Directory.CreateDirectory(text);
GlobalVariables.SaveToFile(Path.Combine(text, "ColorAdjustments.xml"));
}
public void SetSettings()
{
}
public override void Apply()
{
((Setting)this).Apply();
}
}
}