Decompiled source of NiceMode v0.1.1

plugins/NiceMode/NiceMode.dll

Decompiled 12 hours ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.Tables;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.SceneManagement;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace NiceMode;

[BepInPlugin("mvffyn.NiceMode", "Nice Mode", "0.1.1")]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "mvffyn.NiceMode";

	public const string NAME = "Nice Mode";

	public const string VERSION = "0.1.1";

	internal static ManualLogSource Log;

	internal static string PluginDir;

	internal static ConfigEntry<bool> EnableTextOverrides;

	internal static ConfigEntry<bool> EnableFriendLines;

	internal static ConfigEntry<string> FriendName;

	internal static ConfigEntry<bool> EnableColorGrade;

	internal static ConfigEntry<float> Saturation;

	internal static ConfigEntry<float> Contrast;

	internal static ConfigEntry<float> ShadowLift;

	internal static ConfigEntry<bool> EnableLevelMood;

	internal static ConfigEntry<string> FogColorHex;

	internal static ConfigEntry<string> AmbientColorHex;

	internal static ConfigEntry<float> FogDistanceMultiplier;

	internal static ConfigEntry<float> Bloom;

	internal static ConfigEntry<bool> EnablePastelMaterials;

	internal static ConfigEntry<float> PastelStrength;

	internal static ConfigEntry<bool> PastelMonsters;

	internal static ConfigEntry<float> MonsterGlow;

	internal static Dictionary<string, List<string>> FriendLines = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);

	internal static Dictionary<string, Dictionary<string, string>> TextOverrides = new Dictionary<string, Dictionary<string, string>>();

	private void Awake()
	{
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Expected O, but got Unknown
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Expected O, but got Unknown
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Expected O, but got Unknown
		//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Expected O, but got Unknown
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Expected O, but got Unknown
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Expected O, but got Unknown
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Expected O, but got Unknown
		//IL_0305: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		PluginDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		EnableTextOverrides = ((BaseUnityPlugin)this).Config.Bind<bool>("Text", "EnableTextOverrides", true, "Cheerful names for levels, monsters, items, upgrades and HUD text (Localization/*.tsv).");
		EnableFriendLines = ((BaseUnityPlugin)this).Config.Bind<bool>("Text", "EnableFriendLines", true, "Replace the Taxman's truck-screen dialogue with Your Best Friend's lines (TaxmanLines.tsv).");
		FriendName = ((BaseUnityPlugin)this).Config.Bind<string>("Text", "FriendName", "Your Best Friend :)", "Nickname shown for the Taxman on the truck screen.");
		EnableColorGrade = ((BaseUnityPlugin)this).Config.Bind<bool>("Look", "EnableColorGrade", true, "Bright, saturated, lifted-shadow color grade. The heart of Nice Mode.");
		Saturation = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "Saturation", 45f, new ConfigDescription("Extra saturation added to the game's color grading (-100..100).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-100f, 100f), Array.Empty<object>()));
		Contrast = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "Contrast", -15f, new ConfigDescription("Contrast adjustment added to the game's color grading. Negative = softer, dreamier.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-100f, 100f), Array.Empty<object>()));
		ShadowLift = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "ShadowLift", 0.18f, new ConfigDescription("How much to brighten the darkest parts of the image (0 = game default, 0.5 = very washed out).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.6f), Array.Empty<object>()));
		EnableLevelMood = ((BaseUnityPlugin)this).Config.Bind<bool>("Look", "EnableLevelMood", true, "Rewrite every level's fog, ambient light, bloom and vignette to a pastel mood.");
		FogColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("Look", "FogColor", "#F6B8E0", "Fog color (hex). Cotton-candy pink by default.");
		AmbientColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("Look", "AmbientColor", "#C9B8F5", "Ambient light color (hex). Soft lavender by default.");
		FogDistanceMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "FogDistanceMultiplier", 1.6f, new ConfigDescription("Multiplies fog start/end distance so rooms feel airier.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 4f), Array.Empty<object>()));
		Bloom = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "Bloom", 6f, new ConfigDescription("Bloom intensity for every level. Vanilla levels sit around 1-3.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), Array.Empty<object>()));
		EnablePastelMaterials = ((BaseUnityPlugin)this).Config.Bind<bool>("Look", "EnablePastelMaterials", true, "Re-tint world and prop materials toward a pastel palette when a level is generated.");
		PastelStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "PastelStrength", 0.7f, new ConfigDescription("How far material colors move toward their pastel target (0 = off, 1 = full pastel).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		PastelMonsters = ((BaseUnityPlugin)this).Config.Bind<bool>("Look", "PastelMonsters", true, "Also pastelize monster materials. Baby-pink Headman, anyone?");
		MonsterGlow = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "MonsterGlow", 0.35f, new ConfigDescription("Soft emissive glow added to monsters so pastel shows even on dark textures (0 = none, 1 = neon plush).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		LoadTextOverrides();
		LoadFriendLines();
		Harmony val = new Harmony("mvffyn.NiceMode");
		val.PatchAll(typeof(LocalizationPatches));
		val.PatchAll(typeof(TruckScreenPatches));
		if (EnableLevelMood.Value)
		{
			val.PatchAll(typeof(LevelMoodPatches));
		}
		if (EnableColorGrade.Value)
		{
			val.PatchAll(typeof(ColorGradePatches));
		}
		if (EnablePastelMaterials.Value && PastelStrength.Value > 0f)
		{
			val.PatchAll(typeof(PastelPatches));
		}
		Log.LogInfo((object)"Nice Mode 0.1.1 loaded. Everything is fine. :)");
	}

	private static string[] ReadDataLines(string relativePath, string resourceName, out string source)
	{
		string text = Path.Combine(PluginDir, relativePath.Replace('/', Path.DirectorySeparatorChar));
		if (File.Exists(text))
		{
			source = text;
			return File.ReadAllLines(text);
		}
		using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
		if (stream == null)
		{
			source = null;
			return new string[0];
		}
		using StreamReader streamReader = new StreamReader(stream);
		source = "embedded:" + resourceName;
		return streamReader.ReadToEnd().Split(new string[2] { "\r\n", "\n" }, StringSplitOptions.None);
	}

	private static void LoadTextOverrides()
	{
		string[] array = new string[3] { "HUD", "Menu", "Game" };
		foreach (string text in array)
		{
			string source;
			string[] array2 = ReadDataLines("Localization/" + text + ".tsv", "NiceMode." + text + ".tsv", out source);
			if (source == null)
			{
				Log.LogWarning((object)("No data for table " + text));
				continue;
			}
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			string[] array3 = array2;
			foreach (string text2 in array3)
			{
				string text3 = text2.TrimStart('\ufeff');
				if (!string.IsNullOrWhiteSpace(text3) && !text3.StartsWith("#"))
				{
					int num = text3.IndexOf('\t');
					if (num > 0)
					{
						dictionary[text3.Substring(0, num).Trim()] = text3.Substring(num + 1).Replace("\\n", "\n");
					}
				}
			}
			TextOverrides[text] = dictionary;
			Log.LogInfo((object)("Loaded " + dictionary.Count + " text overrides for table " + text + " from " + source));
		}
	}

	private static void LoadFriendLines()
	{
		string source;
		string[] array = ReadDataLines("TaxmanLines.tsv", "NiceMode.TaxmanLines.tsv", out source);
		if (source == null)
		{
			Log.LogWarning((object)"TaxmanLines.tsv not found.");
			return;
		}
		string[] array2 = array;
		foreach (string text in array2)
		{
			string text2 = text.TrimStart('\ufeff');
			if (string.IsNullOrWhiteSpace(text2) || text2.StartsWith("#"))
			{
				continue;
			}
			int num = text2.IndexOf('\t');
			if (num > 0)
			{
				string key = text2.Substring(0, num).Trim();
				if (!FriendLines.TryGetValue(key, out var value))
				{
					value = new List<string>();
					FriendLines[key] = value;
				}
				value.Add(text2.Substring(num + 1));
			}
		}
		Log.LogInfo((object)("Loaded Best Friend dialogue for " + FriendLines.Count + " message types from " + source));
	}

	internal static void ApplyTextOverrides()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		if (!EnableTextOverrides.Value)
		{
			return;
		}
		int num = 0;
		foreach (KeyValuePair<string, Dictionary<string, string>> textOverride in TextOverrides)
		{
			try
			{
				StringTable table = ((LocalizedDatabase<StringTable, StringTableEntry>)(object)LocalizationSettings.StringDatabase).GetTable(TableReference.op_Implicit(textOverride.Key), LocalizationSettings.ProjectLocale);
				if ((Object)(object)table == (Object)null)
				{
					Log.LogWarning((object)("String table not found: " + textOverride.Key));
					continue;
				}
				foreach (KeyValuePair<string, string> item in textOverride.Value)
				{
					StringTableEntry entry = ((DetailedLocalizationTable<StringTableEntry>)(object)table).GetEntry(item.Key);
					if (entry != null)
					{
						entry.Value = item.Value;
					}
					else
					{
						((DetailedLocalizationTable<StringTableEntry>)(object)table).AddEntry(item.Key, item.Value);
					}
					num++;
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed applying overrides to table " + textOverride.Key + ": " + ex.Message));
			}
		}
		Log.LogInfo((object)("Applied " + num + " cheerful text overrides."));
	}

	internal static Color ParseHex(string hex, Color fallback)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		Color val = default(Color);
		return (!ColorUtility.TryParseHtmlString(hex, ref val)) ? fallback : val;
	}
}
[HarmonyPatch(typeof(LocalizationManager), "Awake")]
internal static class LocalizationPatches
{
	[HarmonyPostfix]
	private static void Postfix()
	{
		Plugin.ApplyTextOverrides();
	}
}
[HarmonyPatch(typeof(TruckScreenText), "Start")]
internal static class TruckScreenPatches
{
	private static readonly FieldInfo NicknameField = AccessTools.Field(typeof(TruckScreenText), "nicknameTaxman");

	private static readonly FieldInfo CurrentNicknameField = AccessTools.Field(typeof(TruckScreenText), "currentNickname");

	[HarmonyPostfix]
	private static void Postfix(TruckScreenText __instance)
	{
		try
		{
			if (NicknameField != null && !string.IsNullOrEmpty(Plugin.FriendName.Value))
			{
				NicknameField.SetValue(__instance, Plugin.FriendName.Value);
				if (CurrentNicknameField != null)
				{
					CurrentNicknameField.SetValue(__instance, Plugin.FriendName.Value);
				}
			}
			if (!Plugin.EnableFriendLines.Value || __instance.pages == null)
			{
				return;
			}
			int num = 0;
			foreach (TextPages page in __instance.pages)
			{
				if (page == null || page.textLines == null)
				{
					continue;
				}
				foreach (TextLine textLine in page.textLines)
				{
					if (textLine != null && !string.IsNullOrEmpty(textLine.messageName) && Plugin.FriendLines.TryGetValue(textLine.messageName, out var value) && value.Count != 0)
					{
						textLine.textLines = new List<string>(value);
						num++;
					}
				}
			}
			Plugin.Log.LogInfo((object)("Your Best Friend rewrote " + num + " truck screen message pools."));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("TruckScreenText patch failed: " + ex));
		}
	}
}
[HarmonyPatch(typeof(RunManager), "Awake")]
internal static class LevelMoodPatches
{
	private static readonly HashSet<int> Done = new HashSet<int>();

	[HarmonyPostfix]
	private static void Postfix(RunManager __instance)
	{
		try
		{
			int num = 0;
			num += Apply(__instance.levels);
			num += Apply(__instance.levelShop);
			num += Apply(__instance.levelArena);
			Apply(__instance.levelLobby);
			Apply(__instance.levelTutorial);
			Plugin.Log.LogInfo((object)("Pastel mood applied to " + num + " level definitions."));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Level mood patch failed: " + ex));
		}
	}

	private static int Apply(List<Level> levels)
	{
		if (levels == null)
		{
			return 0;
		}
		int num = 0;
		foreach (Level level in levels)
		{
			if (Apply(level))
			{
				num++;
			}
		}
		return num;
	}

	private static bool Apply(Level level)
	{
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: 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)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)level == (Object)null || Done.Contains(((Object)level).GetInstanceID()))
		{
			return false;
		}
		Done.Add(((Object)level).GetInstanceID());
		Color val = Plugin.ParseHex(Plugin.FogColorHex.Value, new Color(0.96f, 0.72f, 0.88f));
		Color val2 = Plugin.ParseHex(Plugin.AmbientColorHex.Value, new Color(0.79f, 0.72f, 0.96f));
		level.FogColor = val;
		level.FogStartDistance *= Plugin.FogDistanceMultiplier.Value;
		level.FogEndDistance *= Plugin.FogDistanceMultiplier.Value;
		level.AmbientColor = val2;
		level.AmbientColorAdaptation = Color.Lerp(level.AmbientColorAdaptation, val2, 0.7f);
		level.ColorTemperature = 12f;
		level.ColorFilter = Color.Lerp(level.ColorFilter, new Color(1f, 0.93f, 0.98f), 0.8f);
		level.BloomIntensity = Plugin.Bloom.Value;
		level.BloomThreshold = Mathf.Min(level.BloomThreshold, 0.9f);
		level.VignetteIntensity = 0f;
		level.VignetteColor = val;
		return true;
	}
}
[HarmonyPatch(typeof(PostProcessing), "Setup")]
internal static class ColorGradePatches
{
	private static readonly FieldInfo ColorGradingField = AccessTools.Field(typeof(PostProcessing), "colorGrading");

	private static readonly FieldInfo SatBaseField = AccessTools.Field(typeof(PostProcessing), "colorGradingSaturation");

	private static readonly FieldInfo ConBaseField = AccessTools.Field(typeof(PostProcessing), "colorGradingContrast");

	[HarmonyPostfix]
	private static void Postfix(PostProcessing __instance)
	{
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			ColorGrading val = (ColorGrading)((!(ColorGradingField != null)) ? null : /*isinst with value type is only supported in some contexts*/);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"ColorGrading not found on PostProcessing.");
				return;
			}
			float num = Mathf.Clamp(((ParameterOverride<float>)(object)val.saturation).value + Plugin.Saturation.Value, -100f, 100f);
			float num2 = Mathf.Clamp(((ParameterOverride<float>)(object)val.contrast).value + Plugin.Contrast.Value, -100f, 100f);
			((ParameterOverride<float>)(object)val.saturation).value = num;
			((ParameterOverride<float>)(object)val.contrast).value = num2;
			if (SatBaseField != null)
			{
				SatBaseField.SetValue(__instance, num);
			}
			if (ConBaseField != null)
			{
				ConBaseField.SetValue(__instance, num2);
			}
			float value = Plugin.ShadowLift.Value;
			if (value > 0f)
			{
				((ParameterOverride)val.lift).overrideState = true;
				((ParameterOverride<Vector4>)(object)val.lift).value = new Vector4(1f, 0.96f, 1f, value);
				((ParameterOverride)val.gamma).overrideState = true;
				((ParameterOverride<Vector4>)(object)val.gamma).value = new Vector4(1f, 1f, 1f, value * 0.35f);
				((ParameterOverride)val.gain).overrideState = true;
				((ParameterOverride<Vector4>)(object)val.gain).value = new Vector4(1f, 1f, 1f, value * 0.25f);
			}
			Plugin.Log.LogInfo((object)("Color grade applied: saturation " + num + ", contrast " + num2 + ", lift " + value));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Color grade patch failed: " + ex));
		}
	}
}
internal static class Pastel
{
	private static readonly HashSet<int> Visited = new HashSet<int>();

	private static readonly float[] Hues = new float[8]
	{
		67f / 72f,
		4f / 9f,
		5f / 9f,
		11f / 72f,
		55f / 72f,
		5f / 72f,
		37f / 72f,
		35f / 36f
	};

	private static readonly string[] ColorProps = new string[7] { "_Color", "_BaseColor", "_MainColor", "_TintColor", "_ColorTint", "_Tint", "_AlbedoColor" };

	private static readonly string[] SkipShaderWords = new string[7] { "UI", "TextMeshPro", "TMP", "Sprites", "GUI", "Skybox", "Particles" };

	private static readonly string[] SkipMaterialWords = new string[6] { "Player", "player", "Map", "map", "UI", "Cosmetic" };

	private static readonly HashSet<int> MonsterVisited = new HashSet<int>();

	internal static void PastelizeAll(string reason)
	{
		float num = Mathf.Clamp01(Plugin.PastelStrength.Value);
		if (num <= 0f)
		{
			return;
		}
		int num2 = 0;
		int num3 = 0;
		Material[] array;
		try
		{
			array = Resources.FindObjectsOfTypeAll<Material>();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not enumerate materials: " + ex.Message));
			return;
		}
		Material[] array2 = array;
		foreach (Material val in array2)
		{
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			int instanceID = ((Object)val).GetInstanceID();
			if (!Visited.Contains(instanceID))
			{
				Visited.Add(instanceID);
				if (ShouldSkip(val))
				{
					num3++;
				}
				else if (Pastelize(val, num))
				{
					num2++;
				}
			}
		}
		Plugin.Log.LogInfo((object)("Pastelized " + num2 + " materials (" + num3 + " skipped) after " + reason + "."));
	}

	internal static void PastelizeMonster(Component root)
	{
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0214: Unknown result type (might be due to invalid IL or missing references)
		//IL_025b: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)root == (Object)null || !Plugin.PastelMonsters.Value)
		{
			return;
		}
		float num = Mathf.Clamp01(Plugin.MonsterGlow.Value);
		int num2 = 0;
		Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
		foreach (Renderer val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null || val is ParticleSystemRenderer)
			{
				continue;
			}
			Material[] sharedMaterials = val.sharedMaterials;
			foreach (Material val2 in sharedMaterials)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				int instanceID = ((Object)val2).GetInstanceID();
				if (MonsterVisited.Contains(instanceID))
				{
					continue;
				}
				MonsterVisited.Add(instanceID);
				string text = ((!((Object)(object)val2.shader != (Object)null)) ? string.Empty : ((Object)val2.shader).name);
				if (text.IndexOf("Particles", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					continue;
				}
				float num3 = Hues[Mathf.Abs((((Object)val2).name ?? string.Empty).GetHashCode()) % Hues.Length];
				Color val3 = Color.HSVToRGB(num3, 0.4f, 1f);
				Color val4 = Color.HSVToRGB((num3 + 0.08f) % 1f, 0.55f, 1f);
				string[] colorProps = ColorProps;
				foreach (string text2 in colorProps)
				{
					if (val2.HasProperty(text2))
					{
						Color color = val2.GetColor(text2);
						Color val5 = val3;
						val5.a = color.a;
						val2.SetColor(text2, val5);
					}
				}
				if (val2.HasProperty("_FresnelColor"))
				{
					val2.SetColor("_FresnelColor", val4);
				}
				if (num > 0f && val2.HasProperty("_EmissionColor"))
				{
					val2.EnableKeyword("_EMISSION");
					Color color2 = val2.GetColor("_EmissionColor");
					Color val6 = val3 * num;
					val2.SetColor("_EmissionColor", new Color(Mathf.Max(color2.r, val6.r), Mathf.Max(color2.g, val6.g), Mathf.Max(color2.b, val6.b), 1f));
				}
				num2++;
			}
		}
		if (num2 > 0)
		{
			Plugin.Log.LogInfo((object)("Candy-coated " + num2 + " monster materials on " + ((Object)root).name + "."));
		}
	}

	private static bool ShouldSkip(Material m)
	{
		string text = ((!((Object)(object)m.shader != (Object)null)) ? string.Empty : ((Object)m.shader).name);
		string[] skipShaderWords = SkipShaderWords;
		foreach (string value in skipShaderWords)
		{
			if (text.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
		}
		string text2 = ((Object)m).name ?? string.Empty;
		string[] skipMaterialWords = SkipMaterialWords;
		foreach (string value2 in skipMaterialWords)
		{
			if (text2.IndexOf(value2, StringComparison.Ordinal) >= 0)
			{
				return true;
			}
		}
		if (text2.IndexOf("Enemy", StringComparison.OrdinalIgnoreCase) >= 0 || text2.IndexOf("Headman", StringComparison.Ordinal) >= 0 || text2.IndexOf("HeadGrabber", StringComparison.Ordinal) >= 0)
		{
			return true;
		}
		return false;
	}

	private static bool Pastelize(Material m, float t)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: 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_0110: 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_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		bool flag = false;
		float num = Hues[Mathf.Abs((((Object)m).name ?? string.Empty).GetHashCode()) % Hues.Length];
		string[] colorProps = ColorProps;
		float num2 = default(float);
		float num3 = default(float);
		float num4 = default(float);
		foreach (string text in colorProps)
		{
			if (m.HasProperty(text))
			{
				Color color = m.GetColor(text);
				float a = color.a;
				Color.RGBToHSV(color, ref num2, ref num3, ref num4);
				float num5 = ((!(num3 < 0.18f) && !(num4 < 0.25f)) ? num2 : num);
				Color val = Color.HSVToRGB(num5, 0.38f, Mathf.Max(num4, 0.9f));
				Color val2 = Color.Lerp(color, val, t);
				val2.a = a;
				m.SetColor(text, val2);
				flag = true;
			}
		}
		if (flag && m.HasProperty("_EmissionColor"))
		{
			Color color2 = m.GetColor("_EmissionColor");
			if (((Color)(ref color2)).maxColorComponent > 0.05f)
			{
				float num6 = default(float);
				float num7 = default(float);
				float num8 = default(float);
				Color.RGBToHSV(color2, ref num6, ref num7, ref num8);
				m.SetColor("_EmissionColor", Color.Lerp(color2, Color.HSVToRGB(num6, 0.45f, num8), t * 0.6f));
			}
		}
		return flag;
	}
}
[HarmonyPatch]
internal static class PastelPatches
{
	[HarmonyPatch(typeof(LevelGenerator), "GenerateDone")]
	[HarmonyPostfix]
	private static void AfterGenerate()
	{
		Pastel.PastelizeAll("level generation");
	}

	[HarmonyPatch(typeof(PostProcessing), "Setup")]
	[HarmonyPostfix]
	private static void AfterPostSetup()
	{
		Pastel.PastelizeAll("scene setup");
	}

	[HarmonyPatch(typeof(EnemyParent), "Spawn")]
	[HarmonyPostfix]
	private static void AfterEnemySpawn(EnemyParent __instance)
	{
		Pastel.PastelizeMonster((Component)(object)__instance);
	}

	[HarmonyPatch(typeof(LevelGenerator), "GenerateDone")]
	[HarmonyPostfix]
	private static void AfterGenerateMonsters()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			EnemyParent[] array = Resources.FindObjectsOfTypeAll<EnemyParent>();
			foreach (EnemyParent val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					Scene scene = ((Component)val).gameObject.scene;
					if (((Scene)(ref scene)).IsValid())
					{
						Pastel.PastelizeMonster((Component)(object)val);
					}
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Monster pass skipped: " + ex.Message));
		}
	}
}