Decompiled source of Repo Unfinished v1.0.0

EmpressPixelRift.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Empress")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmpressPixelRift")]
[assembly: AssemblyTitle("EmpressPixelRift")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 EmpressPixelRift
{
	[BepInPlugin("empress.repo.pixelrift", "EmpressPixelRift", "1.0.0")]
	public sealed class EmpressPixelRiftPlugin : BaseUnityPlugin
	{
		internal const string PluginGuid = "empress.repo.pixelrift";

		internal const string PluginName = "EmpressPixelRift";

		internal const string PluginVersion = "1.0.0";

		internal ConfigEntry<bool> EmpressEnabled;

		internal ConfigEntry<bool> EmpressCrunchTextures;

		internal ConfigEntry<int> EmpressTextureResolution;

		internal ConfigEntry<int> EmpressTextureConversionsPerFrame;

		internal ConfigEntry<bool> EmpressPointFilterEverything;

		internal ConfigEntry<bool> EmpressCrunchMaterials;

		internal ConfigEntry<int> EmpressColorSteps;

		internal ConfigEntry<bool> EmpressFlattenSpecular;

		internal ConfigEntry<bool> EmpressCrunchMeshes;

		internal ConfigEntry<bool> EmpressStaticMeshCrunchOnly;

		internal ConfigEntry<bool> EmpressFallbackBlockMeshes;

		internal ConfigEntry<float> EmpressMeshSnap;

		internal ConfigEntry<int> EmpressRenderersPerFrame;

		internal ConfigEntry<bool> EmpressShowConversionBar;

		internal ConfigEntry<bool> EmpressStabilizeCulling;

		internal ConfigEntry<bool> EmpressLockLodGroups;

		internal ConfigEntry<bool> EmpressStabilizeLights;

		internal ConfigEntry<bool> EmpressFreezeLightFlicker;

		internal ConfigEntry<bool> EmpressDisableLightShadows;

		internal ConfigEntry<bool> EmpressStableShaders;

		internal ConfigEntry<bool> EmpressPixelEnemies;

		internal ConfigEntry<bool> EmpressDamageEnemyAnimators;

		internal ConfigEntry<KeyCode> EmpressToggleKey;

		private EmpressPixelRiftRuntime? empressRuntime;

		private Harmony? empressHarmony;

		internal static EmpressPixelRiftPlugin? Instance { get; private set; }

		internal ManualLogSource EmpressLog => ((BaseUnityPlugin)this).Logger;

		private void Awake()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_009d: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Expected O, but got Unknown
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Expected O, but got Unknown
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Expected O, but got Unknown
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Expected O, but got Unknown
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Expected O, but got Unknown
			Instance = this;
			((Object)this).hideFlags = (HideFlags)(((Object)this).hideFlags | 0x3D);
			GameObject gameObject = ((Component)this).gameObject;
			((Object)gameObject).hideFlags = (HideFlags)(((Object)gameObject).hideFlags | 0x3D);
			EmpressEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "Enabled", true, "Turns the Empress PixelRift overhaul on or off.");
			EmpressCrunchTextures = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "CrunchTextures", true, "Generates low resolution pixel copies of game textures and swaps them onto materials.");
			EmpressTextureResolution = ((BaseUnityPlugin)this).Config.Bind<int>("Empress PixelRift", "TextureResolution", 32, new ConfigDescription("Generated texture size. 16 is brutal, 32 is Minecraft-ish, 64 is softer.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 128), Array.Empty<object>()));
			EmpressTextureConversionsPerFrame = ((BaseUnityPlugin)this).Config.Bind<int>("Empress PixelRift", "TextureConversionsPerFrame", 2, new ConfigDescription("How many texture conversions Empress may process per frame.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 12), Array.Empty<object>()));
			EmpressPointFilterEverything = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "PointFilterEverything", true, "Forces point filtering on textures for crisp pixel edges.");
			EmpressCrunchMaterials = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "CrunchMaterials", true, "Quantizes material colors into chunky game-like color steps.");
			EmpressColorSteps = ((BaseUnityPlugin)this).Config.Bind<int>("Empress PixelRift", "ColorSteps", 6, new ConfigDescription("Material and texture color steps.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 16), Array.Empty<object>()));
			EmpressFlattenSpecular = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "FlattenSpecular", true, "Removes shiny modern material settings for a flatter voxel look.");
			EmpressCrunchMeshes = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "CrunchMeshes", true, "Snaps shared meshes into chunky low-poly shapes.");
			EmpressStaticMeshCrunchOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "StaticMeshCrunchOnly", true, "Only crunches stable world meshes so player, held, enemy, and moving visual meshes do not become haunted cubes.");
			EmpressFallbackBlockMeshes = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "FallbackBlockMeshes", false, "Experimental. Replaces unreadable meshes with bounding boxes. Off by default because holes and doorways must stay real.");
			EmpressMeshSnap = ((BaseUnityPlugin)this).Config.Bind<float>("Empress PixelRift", "MeshSnap", 0.05f, new ConfigDescription("Vertex snap strength for the mesh crunch.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.005f, 0.25f), Array.Empty<object>()));
			EmpressRenderersPerFrame = ((BaseUnityPlugin)this).Config.Bind<int>("Empress PixelRift", "RenderersPerFrame", 80, new ConfigDescription("How many scene renderers Empress converts per frame while a scene loads.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 500), Array.Empty<object>()));
			EmpressShowConversionBar = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "ShowConversionBar", true, "Shows the Empress conversion bar while PixelRift caches the scene.");
			EmpressStabilizeCulling = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "StabilizeCulling", true, "Pads converted bounds and stops Unity from hiding converted pieces too aggressively.");
			EmpressLockLodGroups = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "LockLODGroups", true, "Keeps converted LOD objects on their highest visible form so chunks do not pop while moving.");
			EmpressStabilizeLights = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "StabilizeLights", true, "Calms scene lights after conversion so the chunky look does not shimmer or blink.");
			EmpressFreezeLightFlicker = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "FreezeLightFlicker", true, "Pins light intensity, range, bounce, and color to their converted scene values.");
			EmpressDisableLightShadows = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "DisableLightShadows", true, "Disables realtime light shadows to prevent blocky shadow flicker.");
			EmpressStableShaders = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "StableShaders", true, "Replaces animated custom material shaders with stable PixelRift material clones.");
			EmpressPixelEnemies = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "PixelEnemies", true, "Converts spawned enemies when their spawn event fires instead of scanning forever.");
			EmpressDamageEnemyAnimators = ((BaseUnityPlugin)this).Config.Bind<bool>("Empress PixelRift", "DamageEnemyAnimators", true, "Makes enemy animation playback look busted and prototype-like.");
			EmpressToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Empress Controls", "ToggleKey", (KeyCode)290, "Toggles PixelRift while in game.");
			empressHarmony = new Harmony("empress.repo.pixelrift");
			empressHarmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyParent), "SpawnRPC", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(EmpressPixelRiftPlugin), "EmpressEnemySpawnedPatch", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			GameObject val = new GameObject("EmpressPixelRift.Runtime")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)(object)val);
			empressRuntime = val.AddComponent<EmpressPixelRiftRuntime>();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Empress PixelRift is ready to tear the renderer into blocks.");
		}

		private static void EmpressEnemySpawnedPatch(EnemyParent __instance)
		{
			EmpressPixelRiftRuntime.EmpressQueueEnemy(__instance);
		}
	}
	internal sealed class EmpressPixelRiftRuntime : MonoBehaviour
	{
		private static readonly string[] EmpressTextureProperties = new string[9] { "_MainTex", "_BaseMap", "_EmissionMap", "_BumpMap", "_MetallicGlossMap", "_OcclusionMap", "_DetailAlbedoMap", "_DetailMask", "_ParallaxMap" };

		private static readonly string[] EmpressColorProperties = new string[4] { "_Color", "_BaseColor", "_EmissionColor", "_SpecColor" };

		private static readonly string[] EmpressFloatProperties = new string[6] { "_Glossiness", "_GlossMapScale", "_Metallic", "_Smoothness", "_SpecularHighlights", "_EnvironmentReflections" };

		private static readonly string[] EmpressRendererRejectWords = new string[43]
		{
			"collider", "collision", "collide", "trigger", "hurtbox", "hitbox", "bounds", "bounding", "volume", "zone",
			"blocker", "occluder", "occlusion", "navmesh", "probe", "helper", "gizmo", "debug", "range", "radius",
			"sensor", "detector", "marker", "ghost", "placeholder", "phys grab", "player", "avatar", "local", "viewmodel",
			"view model", "firstperson", "first person", "fpv", "camera", "flashlight", "hand", "hands", "arm", "arms",
			"head", "body", "torso"
		};

		private static readonly string[] EmpressDelicateMeshWords = new string[27]
		{
			"door", "extractor", "extraction", "frame", "grate", "grille", "bars", "barrier", "fence", "rail",
			"railing", "window", "glass", "vent", "ladder", "stairs", "shelf", "shelves", "rack", "wire",
			"cable", "pipe", "antenna", "antennae", "chain", "handle", "sign"
		};

		private static readonly string[] EmpressMeshCrunchSkipWords = new string[9] { "truck", "vehicle", "snow vehicle", "wheel", "axle", "dish", "antenna", "antennae", "logo plane" };

		private static readonly string[] EmpressEnemyRendererRejectWords = new string[16]
		{
			"collider", "collision", "trigger", "hurtbox", "hitbox", "bounds", "volume", "zone", "helper", "gizmo",
			"debug", "sensor", "detector", "marker", "placeholder", "phys grab"
		};

		private readonly Dictionary<int, EmpressTextureState> empressTextureStates = new Dictionary<int, EmpressTextureState>();

		private readonly Dictionary<int, Texture> empressTextureCopies = new Dictionary<int, Texture>();

		private readonly Dictionary<string, EmpressMaterialTextureState> empressMaterialTextureStates = new Dictionary<string, EmpressMaterialTextureState>(StringComparer.Ordinal);

		private readonly Dictionary<string, EmpressMaterialColorState> empressMaterialColorStates = new Dictionary<string, EmpressMaterialColorState>(StringComparer.Ordinal);

		private readonly Dictionary<string, EmpressMaterialFloatState> empressMaterialFloatStates = new Dictionary<string, EmpressMaterialFloatState>(StringComparer.Ordinal);

		private readonly Dictionary<int, EmpressRendererMaterialState> empressRendererMaterialStates = new Dictionary<int, EmpressRendererMaterialState>();

		private readonly Dictionary<int, Material> empressStableMaterialCopies = new Dictionary<int, Material>();

		private readonly Dictionary<int, Mesh> empressMeshCopies = new Dictionary<int, Mesh>();

		private readonly Dictionary<int, Mesh> empressEnemyMeshCopies = new Dictionary<int, Mesh>();

		private readonly Dictionary<int, EmpressMeshFilterState> empressMeshFilterStates = new Dictionary<int, EmpressMeshFilterState>();

		private readonly Dictionary<int, EmpressSkinnedMeshState> empressSkinnedMeshStates = new Dictionary<int, EmpressSkinnedMeshState>();

		private readonly Dictionary<int, EmpressAnimatorState> empressAnimatorStates = new Dictionary<int, EmpressAnimatorState>();

		private readonly Dictionary<int, EmpressRendererCullingState> empressRendererCullingStates = new Dictionary<int, EmpressRendererCullingState>();

		private readonly Dictionary<int, EmpressSkinnedBoundsState> empressSkinnedBoundsStates = new Dictionary<int, EmpressSkinnedBoundsState>();

		private readonly Dictionary<int, EmpressLodGroupState> empressLodGroupStates = new Dictionary<int, EmpressLodGroupState>();

		private readonly Dictionary<int, EmpressLightState> empressLightStates = new Dictionary<int, EmpressLightState>();

		private readonly Queue<EmpressTextureJob> empressTextureJobs = new Queue<EmpressTextureJob>();

		private readonly Queue<Renderer> empressRendererJobs = new Queue<Renderer>();

		private readonly Queue<GameObject> empressEnemyJobs = new Queue<GameObject>();

		private readonly HashSet<int> empressQueuedRendererIds = new HashSet<int>();

		private readonly HashSet<int> empressConvertedRendererIds = new HashSet<int>();

		private readonly HashSet<int> empressQueuedEnemyIds = new HashSet<int>();

		private readonly HashSet<int> empressConvertedEnemyIds = new HashSet<int>();

		private readonly HashSet<string> empressQueuedSlots = new HashSet<string>(StringComparer.Ordinal);

		private int empressTotalRendererJobs;

		private int empressProcessedRendererJobs;

		private float empressSceneConversionTime;

		private float empressSceneScanDeadline;

		private bool empressConversionQueued = true;

		private bool empressConversionActive;

		private bool empressRuntimeEnabled;

		private int empressSceneConversionAttempts;

		private int empressStableSceneScans;

		private Shader? empressOpaqueShader;

		private Shader? empressCutoutShader;

		private static EmpressPixelRiftPlugin? EmpressPlugin => EmpressPixelRiftPlugin.Instance;

		private static EmpressPixelRiftRuntime? EmpressRuntime { get; set; }

		internal static void EmpressQueueEnemy(EnemyParent enemyParent)
		{
			if (!((Object)(object)enemyParent == (Object)null) && !((Object)(object)EmpressRuntime == (Object)null))
			{
				EmpressRuntime.EmpressQueueEnemyObject(((Component)enemyParent).gameObject);
			}
		}

		private void Awake()
		{
			EmpressRuntime = this;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			SceneManager.sceneLoaded += EmpressSceneLoaded;
			EmpressScheduleSceneConversion(1f);
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= EmpressSceneLoaded;
			if ((Object)(object)EmpressRuntime == (Object)(object)this)
			{
				EmpressRuntime = null;
			}
			EmpressDisableRift();
		}

		private void OnGUI()
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			EmpressPixelRiftPlugin empressPlugin = EmpressPlugin;
			if (!((Object)(object)empressPlugin == (Object)null) && empressPlugin.EmpressEnabled.Value && empressPlugin.EmpressShowConversionBar.Value && empressConversionActive)
			{
				float num = ((empressTotalRendererJobs <= 0) ? 0f : Mathf.Clamp01((float)empressProcessedRendererJobs / (float)empressTotalRendererJobs));
				float num2 = ((empressTextureJobs.Count == 0) ? 1f : 0.88f);
				float num3 = Mathf.Clamp01(num * num2);
				float num4 = Mathf.Min(520f, (float)Screen.width - 80f);
				float num5 = 18f;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(((float)Screen.width - num4) * 0.5f, (float)Screen.height - 58f, num4, num5);
				Rect val2 = new Rect(((Rect)(ref val)).x + 2f, ((Rect)(ref val)).y + 2f, (((Rect)(ref val)).width - 4f) * num3, ((Rect)(ref val)).height - 4f);
				Color color = GUI.color;
				GUI.color = new Color(0f, 0f, 0f, 0.72f);
				GUI.DrawTexture(val, (Texture)(object)Texture2D.whiteTexture);
				GUI.color = new Color(1f, 0.18f, 0.68f, 0.92f);
				GUI.DrawTexture(val2, (Texture)(object)Texture2D.whiteTexture);
				GUI.color = new Color(1f, 0.86f, 0.96f, 1f);
				GUI.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y - 22f, ((Rect)(ref val)).width, 20f), "EMPRESS PIXELRIFT // converting scene " + Mathf.RoundToInt(num3 * 100f) + "%");
				GUI.color = color;
			}
		}

		private void Update()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			EmpressPixelRiftPlugin empressPlugin = EmpressPlugin;
			if ((Object)(object)empressPlugin == (Object)null)
			{
				return;
			}
			if (Input.GetKeyDown(empressPlugin.EmpressToggleKey.Value))
			{
				empressPlugin.EmpressEnabled.Value = !empressPlugin.EmpressEnabled.Value;
			}
			if (!empressPlugin.EmpressEnabled.Value)
			{
				EmpressDisableRift();
				return;
			}
			if (empressConversionQueued && Time.unscaledTime >= empressSceneConversionTime)
			{
				EmpressScanSceneRenderers();
			}
			EmpressProcessRendererJobs(empressPlugin);
			EmpressProcessEnemyJobs(empressPlugin);
			EmpressProcessTextureJobs(empressPlugin);
			EmpressMaintainLights(empressPlugin);
			if (empressConversionActive && !empressConversionQueued && empressRendererJobs.Count == 0 && empressTextureJobs.Count == 0)
			{
				empressConversionActive = false;
			}
			empressRuntimeEnabled = true;
		}

		private void EmpressSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			EmpressRestoreWorldStyle();
			EmpressScheduleSceneConversion(1f);
		}

		private void EmpressScheduleSceneConversion(float delay)
		{
			empressSceneConversionTime = Time.unscaledTime + delay;
			empressSceneScanDeadline = Time.unscaledTime + 18f;
			empressConversionQueued = true;
			empressConversionActive = true;
			empressRendererJobs.Clear();
			empressEnemyJobs.Clear();
			empressQueuedRendererIds.Clear();
			empressConvertedRendererIds.Clear();
			empressQueuedEnemyIds.Clear();
			empressConvertedEnemyIds.Clear();
			empressTotalRendererJobs = 0;
			empressProcessedRendererJobs = 0;
			empressSceneConversionAttempts = 0;
			empressStableSceneScans = 0;
		}

		private void EmpressScanSceneRenderers()
		{
			EmpressPixelRiftPlugin empressPlugin = EmpressPlugin;
			if ((Object)(object)empressPlugin != (Object)null)
			{
				EmpressScanSceneLights(empressPlugin);
				EmpressScanSceneEnemies(empressPlugin);
			}
			Renderer[] array = Object.FindObjectsOfType<Renderer>();
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = LayerMask.NameToLayer("UI");
			Renderer[] array2 = array;
			foreach (Renderer val in array2)
			{
				if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy)
				{
					num2++;
					continue;
				}
				if (num4 >= 0 && ((Component)val).gameObject.layer == num4)
				{
					num2++;
					continue;
				}
				if (EmpressShouldRejectRenderer(val))
				{
					num2++;
					continue;
				}
				num++;
				int instanceID = ((Object)val).GetInstanceID();
				if (!empressQueuedRendererIds.Contains(instanceID) && !empressConvertedRendererIds.Contains(instanceID))
				{
					empressQueuedRendererIds.Add(instanceID);
					empressRendererJobs.Enqueue(val);
					num3++;
				}
			}
			if (num3 > 0)
			{
				empressTotalRendererJobs += num3;
				empressStableSceneScans = 0;
			}
			else
			{
				empressStableSceneScans++;
			}
			if (num == 0 && empressSceneConversionAttempts < 12)
			{
				empressSceneConversionAttempts++;
				empressSceneConversionTime = Time.unscaledTime + 0.5f;
				empressConversionQueued = true;
				empressConversionActive = true;
				EmpressPixelRiftPlugin? empressPlugin2 = EmpressPlugin;
				if (empressPlugin2 != null)
				{
					empressPlugin2.EmpressLog.LogInfo((object)("Empress PixelRift is waiting for scene renderers. Saw " + array.Length + ", skipped " + num2 + "."));
				}
				return;
			}
			bool flag = Time.unscaledTime >= empressSceneScanDeadline || empressStableSceneScans >= 5;
			empressConversionActive = empressTotalRendererJobs > 0 || empressRendererJobs.Count > 0 || empressTextureJobs.Count > 0;
			empressConversionQueued = !flag;
			if (empressConversionQueued)
			{
				empressSceneConversionTime = Time.unscaledTime + 0.75f;
			}
			EmpressPixelRiftPlugin? empressPlugin3 = EmpressPlugin;
			if (empressPlugin3 != null)
			{
				empressPlugin3.EmpressLog.LogInfo((object)("Empress PixelRift scene scan queued " + num3 + " new renderers. Total " + empressTotalRendererJobs + ". Saw " + array.Length + ", accepted " + num + ", skipped " + num2 + "."));
			}
			if (flag)
			{
				EmpressPixelRiftPlugin? empressPlugin4 = EmpressPlugin;
				if (empressPlugin4 != null)
				{
					empressPlugin4.EmpressLog.LogInfo((object)("Empress PixelRift scene cache locked with " + empressTotalRendererJobs + " renderers."));
				}
			}
		}

		private void EmpressProcessRendererJobs(EmpressPixelRiftPlugin plugin)
		{
			int num = Mathf.Clamp(plugin.EmpressRenderersPerFrame.Value, 10, 500);
			int num2 = 0;
			while (num2 < num && empressRendererJobs.Count > 0)
			{
				Renderer val = empressRendererJobs.Dequeue();
				if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy || EmpressShouldRejectRenderer(val))
				{
					num2++;
					empressProcessedRendererJobs++;
					continue;
				}
				empressConvertedRendererIds.Add(((Object)val).GetInstanceID());
				EmpressStabilizeRenderer(plugin, val);
				Material[] array = EmpressGetRendererMaterials(plugin, val);
				foreach (Material val2 in array)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						EmpressStyleMaterial(plugin, val2);
					}
				}
				EmpressStyleMesh(plugin, val);
				EmpressStabilizeRenderer(plugin, val);
				num2++;
				empressProcessedRendererJobs++;
			}
		}

		private void EmpressScanSceneLights(EmpressPixelRiftPlugin plugin)
		{
			if (!plugin.EmpressStabilizeLights.Value)
			{
				return;
			}
			Light[] array = Object.FindObjectsOfType<Light>();
			foreach (Light val in array)
			{
				if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeInHierarchy)
				{
					int instanceID = ((Object)val).GetInstanceID();
					if (!empressLightStates.ContainsKey(instanceID))
					{
						empressLightStates[instanceID] = new EmpressLightState(val);
					}
					EmpressApplyLightStability(plugin, val, empressLightStates[instanceID]);
				}
			}
		}

		private void EmpressScanSceneEnemies(EmpressPixelRiftPlugin plugin)
		{
			if (!plugin.EmpressPixelEnemies.Value)
			{
				return;
			}
			EnemyParent[] array = Object.FindObjectsOfType<EnemyParent>();
			foreach (EnemyParent val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					EmpressQueueEnemyObject(((Component)val).gameObject);
				}
			}
		}

		private void EmpressQueueEnemyObject(GameObject enemyObject)
		{
			if (!((Object)(object)enemyObject == (Object)null))
			{
				int instanceID = ((Object)enemyObject).GetInstanceID();
				if (!empressQueuedEnemyIds.Contains(instanceID) && !empressConvertedEnemyIds.Contains(instanceID))
				{
					empressQueuedEnemyIds.Add(instanceID);
					empressEnemyJobs.Enqueue(enemyObject);
				}
			}
		}

		private void EmpressProcessEnemyJobs(EmpressPixelRiftPlugin plugin)
		{
			if (!plugin.EmpressPixelEnemies.Value)
			{
				empressEnemyJobs.Clear();
				return;
			}
			int num = 0;
			while (num < 4 && empressEnemyJobs.Count > 0)
			{
				GameObject val = empressEnemyJobs.Dequeue();
				if ((Object)(object)val == (Object)null)
				{
					num++;
					continue;
				}
				int instanceID = ((Object)val).GetInstanceID();
				empressConvertedEnemyIds.Add(instanceID);
				Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val2 in componentsInChildren)
				{
					if ((Object)(object)val2 == (Object)null || EmpressShouldRejectEnemyRenderer(val2))
					{
						continue;
					}
					EmpressStabilizeRenderer(plugin, val2);
					Material[] array = EmpressGetRendererMaterials(plugin, val2);
					foreach (Material val3 in array)
					{
						if ((Object)(object)val3 != (Object)null)
						{
							EmpressStyleMaterial(plugin, val3);
						}
					}
					EmpressStyleEnemyMesh(plugin, val2);
					EmpressStabilizeRenderer(plugin, val2);
				}
				if (plugin.EmpressDamageEnemyAnimators.Value)
				{
					EmpressDamageEnemyAnimators(val, instanceID);
				}
				num++;
			}
		}

		private bool EmpressShouldRejectEnemyRenderer(Renderer renderer)
		{
			string text = EmpressObjectPath(((Component)renderer).transform);
			for (int i = 0; i < EmpressEnemyRendererRejectWords.Length; i++)
			{
				if (text.IndexOf(EmpressEnemyRendererRejectWords[i], StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			return false;
		}

		private void EmpressDamageEnemyAnimators(GameObject enemyObject, int seed)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			Animator[] componentsInChildren = enemyObject.GetComponentsInChildren<Animator>(true);
			foreach (Animator val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null))
				{
					int instanceID = ((Object)val).GetInstanceID();
					if (!empressAnimatorStates.ContainsKey(instanceID))
					{
						empressAnimatorStates[instanceID] = new EmpressAnimatorState(val, val.speed, val.cullingMode);
					}
					float num = EmpressStableNoise(seed + instanceID);
					val.speed = Mathf.Lerp(0.12f, 0.58f, num);
					val.cullingMode = (AnimatorCullingMode)0;
				}
			}
		}

		private void EmpressStyleEnemyMesh(EmpressPixelRiftPlugin plugin, Renderer renderer)
		{
			float snap = Mathf.Clamp(plugin.EmpressMeshSnap.Value, 0.005f, 0.25f) * 2f;
			SkinnedMeshRenderer val = (SkinnedMeshRenderer)(object)((renderer is SkinnedMeshRenderer) ? renderer : null);
			if (val != null)
			{
				Mesh val2 = val.sharedMesh;
				int instanceID = ((Object)val).GetInstanceID();
				if (empressSkinnedMeshStates.TryGetValue(instanceID, out EmpressSkinnedMeshState value))
				{
					val2 = value.Mesh;
				}
				else if ((Object)(object)val2 != (Object)null)
				{
					empressSkinnedMeshStates[instanceID] = new EmpressSkinnedMeshState(val, val2);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					val.sharedMesh = EmpressGetEnemyPixelMesh(val2, snap);
				}
				return;
			}
			MeshFilter component = ((Component)renderer).GetComponent<MeshFilter>();
			if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
			{
				int instanceID2 = ((Object)component).GetInstanceID();
				Mesh val3 = component.sharedMesh;
				if (empressMeshFilterStates.TryGetValue(instanceID2, out EmpressMeshFilterState value2))
				{
					val3 = value2.Mesh;
				}
				else
				{
					empressMeshFilterStates[instanceID2] = new EmpressMeshFilterState(component, val3);
				}
				component.sharedMesh = EmpressGetEnemyPixelMesh(val3, snap);
			}
		}

		private Mesh EmpressGetEnemyPixelMesh(Mesh source, float snap)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0088: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)source).GetInstanceID();
			if (empressEnemyMeshCopies.TryGetValue(instanceID, out Mesh value))
			{
				return value;
			}
			if (!source.isReadable)
			{
				empressEnemyMeshCopies[instanceID] = source;
				return source;
			}
			Mesh val = Object.Instantiate<Mesh>(source);
			((Object)val).name = "EmpressPixelRift.Enemy." + ((Object)source).name;
			Vector3[] vertices = val.vertices;
			float num = EmpressStableNoise(instanceID);
			for (int i = 0; i < vertices.Length; i++)
			{
				Vector3 val2 = vertices[i];
				val2.x = Mathf.Round(val2.x / snap) * snap;
				val2.y = Mathf.Round(val2.y / snap) * snap;
				val2.z = Mathf.Round(val2.z / snap) * snap;
				if (i % 9 == 0)
				{
					val2 += new Vector3((num - 0.5f) * snap, EmpressStableNoise(instanceID + i) * snap * 0.5f, (0.5f - num) * snap);
				}
				vertices[i] = val2;
			}
			val.vertices = vertices;
			val.RecalculateBounds();
			EmpressPadMeshBounds(val, snap);
			empressEnemyMeshCopies[instanceID] = val;
			return val;
		}

		private float EmpressStableNoise(int seed)
		{
			return Mathf.Abs(Mathf.Sin((float)seed * 12.9898f) * 43758.547f) % 1f;
		}

		private void EmpressMaintainLights(EmpressPixelRiftPlugin plugin)
		{
			if (!plugin.EmpressStabilizeLights.Value || empressLightStates.Count == 0)
			{
				return;
			}
			foreach (EmpressLightState value in empressLightStates.Values)
			{
				if ((Object)(object)value.Light != (Object)null && ((Component)value.Light).gameObject.activeInHierarchy)
				{
					EmpressApplyLightStability(plugin, value.Light, value);
				}
			}
		}

		private void EmpressApplyLightStability(EmpressPixelRiftPlugin plugin, Light light, EmpressLightState state)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (plugin.EmpressFreezeLightFlicker.Value)
			{
				light.intensity = state.Intensity;
				light.range = state.Range;
				light.bounceIntensity = state.BounceIntensity;
				light.color = state.Color;
			}
			if (plugin.EmpressDisableLightShadows.Value)
			{
				light.shadows = (LightShadows)0;
				light.shadowStrength = 0f;
			}
			light.renderMode = (LightRenderMode)1;
		}

		private Material[] EmpressGetRendererMaterials(EmpressPixelRiftPlugin plugin, Renderer renderer)
		{
			Material[] sharedMaterials = renderer.sharedMaterials;
			if (!plugin.EmpressStableShaders.Value || EmpressShouldKeepOriginalShaderRenderer(renderer))
			{
				return sharedMaterials;
			}
			int instanceID = ((Object)renderer).GetInstanceID();
			if (!empressRendererMaterialStates.ContainsKey(instanceID))
			{
				empressRendererMaterialStates[instanceID] = new EmpressRendererMaterialState(renderer, sharedMaterials);
			}
			Material[] array = (Material[])(object)new Material[sharedMaterials.Length];
			bool flag = false;
			for (int i = 0; i < sharedMaterials.Length; i++)
			{
				Material val = sharedMaterials[i];
				if (!((Object)(object)val == (Object)null) && (Object)(object)(array[i] = EmpressGetStableMaterial(val)) != (Object)(object)val)
				{
					flag = true;
				}
			}
			if (flag)
			{
				renderer.sharedMaterials = array;
				return array;
			}
			return sharedMaterials;
		}

		private bool EmpressShouldKeepOriginalShaderRenderer(Renderer renderer)
		{
			string name = ((object)renderer).GetType().Name;
			if (name.IndexOf("Particle", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Trail", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return name.IndexOf("Line", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return true;
		}

		private Material EmpressGetStableMaterial(Material material)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_008d: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)material).GetInstanceID();
			if (empressStableMaterialCopies.TryGetValue(instanceID, out Material value))
			{
				return value;
			}
			string text = EmpressFindPrimaryTextureProperty(material);
			bool flag = EmpressUsesCutoutMaterial(material) || text.Length > 0;
			Shader val = EmpressGetStableShader(flag);
			if ((Object)(object)val == (Object)null)
			{
				empressStableMaterialCopies[instanceID] = material;
				return material;
			}
			value = new Material(val)
			{
				name = "EmpressPixelRift.Stable." + ((Object)material).name,
				renderQueue = (flag ? 2450 : material.renderQueue)
			};
			Texture val2 = ((text.Length == 0) ? null : material.GetTexture(text));
			if ((Object)(object)val2 != (Object)null && value.HasProperty("_MainTex"))
			{
				value.SetTexture("_MainTex", val2);
				value.SetTextureScale("_MainTex", material.GetTextureScale(text));
				value.SetTextureOffset("_MainTex", material.GetTextureOffset(text));
			}
			if (value.HasProperty("_Color"))
			{
				value.SetColor("_Color", EmpressFindPrimaryColor(material));
			}
			if (value.HasProperty("_Cutoff"))
			{
				value.SetFloat("_Cutoff", Mathf.Min(EmpressFindCutoff(material), 0.2f));
			}
			if (value.HasProperty("_Glossiness"))
			{
				value.SetFloat("_Glossiness", 0f);
			}
			if (value.HasProperty("_Metallic"))
			{
				value.SetFloat("_Metallic", 0f);
			}
			empressStableMaterialCopies[instanceID] = value;
			return value;
		}

		private Shader? EmpressGetStableShader(bool cutout)
		{
			if (cutout)
			{
				if ((Object)(object)empressCutoutShader == (Object)null)
				{
					empressCutoutShader = Shader.Find("Legacy Shaders/Transparent/Cutout/Diffuse") ?? Shader.Find("Transparent/Cutout/Diffuse") ?? Shader.Find("Standard");
				}
				return empressCutoutShader;
			}
			if ((Object)(object)empressOpaqueShader == (Object)null)
			{
				empressOpaqueShader = Shader.Find("Standard") ?? Shader.Find("Diffuse") ?? Shader.Find("Legacy Shaders/Diffuse") ?? Shader.Find("Unlit/Texture");
			}
			return empressOpaqueShader;
		}

		private bool EmpressUsesCutoutMaterial(Material material)
		{
			string text = ((Object)material).name + " " + (((Object)(object)material.shader != (Object)null) ? ((Object)material.shader).name : string.Empty);
			if (text.IndexOf("alpha", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("clip", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("cutout", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("transparent", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
			if (material.renderQueue >= 2450)
			{
				return material.renderQueue < 3000;
			}
			return false;
		}

		private string EmpressFindPrimaryTextureProperty(Material material)
		{
			for (int i = 0; i < EmpressTextureProperties.Length; i++)
			{
				string text = EmpressTextureProperties[i];
				if (material.HasProperty(text) && (Object)(object)material.GetTexture(text) != (Object)null)
				{
					return text;
				}
			}
			return string.Empty;
		}

		private Color EmpressFindPrimaryColor(Material material)
		{
			//IL_002b: 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)
			for (int i = 0; i < EmpressColorProperties.Length; i++)
			{
				string text = EmpressColorProperties[i];
				if (material.HasProperty(text))
				{
					return material.GetColor(text);
				}
			}
			return Color.white;
		}

		private float EmpressFindCutoff(Material material)
		{
			if (material.HasProperty("_Cutoff"))
			{
				return Mathf.Clamp01(material.GetFloat("_Cutoff"));
			}
			return 0.45f;
		}

		private void EmpressStyleMaterial(EmpressPixelRiftPlugin plugin, Material material)
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00f5: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			if (plugin.EmpressPointFilterEverything.Value || plugin.EmpressCrunchTextures.Value)
			{
				for (int i = 0; i < EmpressTextureProperties.Length; i++)
				{
					string text = EmpressTextureProperties[i];
					if (!material.HasProperty(text))
					{
						continue;
					}
					Texture texture = material.GetTexture(text);
					if (!((Object)(object)texture == (Object)null))
					{
						EmpressRememberMaterialTexture(material, text, texture);
						if (plugin.EmpressCrunchTextures.Value)
						{
							EmpressQueueTextureCrunch(material, text, texture);
						}
						else
						{
							EmpressPointTexture(texture);
						}
					}
				}
			}
			if (plugin.EmpressCrunchMaterials.Value)
			{
				for (int j = 0; j < EmpressColorProperties.Length; j++)
				{
					string text2 = EmpressColorProperties[j];
					if (material.HasProperty(text2))
					{
						EmpressRememberMaterialColor(material, text2);
						Color color = empressMaterialColorStates[EmpressMaterialKey(material, text2)].Color;
						Color val = ((text2 == "_EmissionColor" || text2 == "_SpecColor") ? Color.black : EmpressQuantizeColor(color, plugin.EmpressColorSteps.Value));
						material.SetColor(text2, val);
					}
				}
			}
			if (!plugin.EmpressFlattenSpecular.Value)
			{
				return;
			}
			for (int k = 0; k < EmpressFloatProperties.Length; k++)
			{
				string text3 = EmpressFloatProperties[k];
				if (material.HasProperty(text3))
				{
					EmpressRememberMaterialFloat(material, text3);
					material.SetFloat(text3, 0f);
				}
			}
		}

		private void EmpressRememberMaterialTexture(Material material, string property, Texture texture)
		{
			string key = EmpressMaterialKey(material, property);
			if (!empressMaterialTextureStates.ContainsKey(key))
			{
				empressMaterialTextureStates[key] = new EmpressMaterialTextureState(material, property, texture);
			}
		}

		private void EmpressRememberMaterialColor(Material material, string property)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			string key = EmpressMaterialKey(material, property);
			if (!empressMaterialColorStates.ContainsKey(key))
			{
				empressMaterialColorStates[key] = new EmpressMaterialColorState(material, property, material.GetColor(property));
			}
		}

		private void EmpressRememberMaterialFloat(Material material, string property)
		{
			string key = EmpressMaterialKey(material, property);
			if (!empressMaterialFloatStates.ContainsKey(key))
			{
				empressMaterialFloatStates[key] = new EmpressMaterialFloatState(material, property, material.GetFloat(property));
			}
		}

		private void EmpressStyleMesh(EmpressPixelRiftPlugin plugin, Renderer renderer)
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			if (!plugin.EmpressCrunchMeshes.Value || EmpressShouldSkipMeshCrunch(plugin, renderer))
			{
				return;
			}
			float snap = Mathf.Clamp(plugin.EmpressMeshSnap.Value, 0.005f, 0.25f);
			SkinnedMeshRenderer val = (SkinnedMeshRenderer)(object)((renderer is SkinnedMeshRenderer) ? renderer : null);
			if (val != null)
			{
				Mesh val2 = val.sharedMesh;
				int instanceID = ((Object)val).GetInstanceID();
				if (empressSkinnedMeshStates.TryGetValue(instanceID, out EmpressSkinnedMeshState value))
				{
					val2 = value.Mesh;
				}
				else if ((Object)(object)val2 != (Object)null)
				{
					empressSkinnedMeshStates[instanceID] = new EmpressSkinnedMeshState(val, val2);
				}
				if (!((Object)(object)val2 == (Object)null))
				{
					val.sharedMesh = EmpressGetPixelMesh(renderer, val2, ((Renderer)val).localBounds, snap);
				}
				return;
			}
			MeshFilter component = ((Component)renderer).GetComponent<MeshFilter>();
			if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
			{
				int instanceID2 = ((Object)component).GetInstanceID();
				Mesh val3 = component.sharedMesh;
				if (empressMeshFilterStates.TryGetValue(instanceID2, out EmpressMeshFilterState value2))
				{
					val3 = value2.Mesh;
				}
				else
				{
					empressMeshFilterStates[instanceID2] = new EmpressMeshFilterState(component, val3);
				}
				component.sharedMesh = EmpressGetPixelMesh(renderer, val3, val3.bounds, snap);
			}
		}

		private Mesh EmpressGetPixelMesh(Renderer renderer, Mesh source, Bounds fallbackBounds, float snap)
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00a7: 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)
			int instanceID = ((Object)source).GetInstanceID();
			if (empressMeshCopies.TryGetValue(instanceID, out Mesh value))
			{
				return value;
			}
			Mesh val;
			if (source.isReadable)
			{
				try
				{
					val = Object.Instantiate<Mesh>(source);
					((Object)val).name = "EmpressPixelRift." + ((Object)source).name;
					Vector3[] vertices = val.vertices;
					for (int i = 0; i < vertices.Length; i++)
					{
						Vector3 val2 = vertices[i];
						val2.x = Mathf.Round(val2.x / snap) * snap;
						val2.y = Mathf.Round(val2.y / snap) * snap;
						val2.z = Mathf.Round(val2.z / snap) * snap;
						vertices[i] = val2;
					}
					val.vertices = vertices;
					val.RecalculateBounds();
					EmpressPadMeshBounds(val, snap);
					empressMeshCopies[instanceID] = val;
					return val;
				}
				catch
				{
				}
			}
			if (EmpressShouldKeepOriginalShape(renderer, source, fallbackBounds) || EmpressShouldAvoidFallbackBlock(renderer, fallbackBounds))
			{
				empressMeshCopies[instanceID] = source;
				return source;
			}
			EmpressPixelRiftPlugin? empressPlugin = EmpressPlugin;
			if (empressPlugin == null || !empressPlugin.EmpressFallbackBlockMeshes.Value)
			{
				empressMeshCopies[instanceID] = source;
				return source;
			}
			val = EmpressCreateBoundsMesh(source, fallbackBounds, snap);
			empressMeshCopies[instanceID] = val;
			return val;
		}

		private bool EmpressShouldSkipMeshCrunch(EmpressPixelRiftPlugin plugin, Renderer renderer)
		{
			string text = EmpressObjectPath(((Component)renderer).transform);
			for (int i = 0; i < EmpressMeshCrunchSkipWords.Length; i++)
			{
				if (text.IndexOf(EmpressMeshCrunchSkipWords[i], StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			if (!plugin.EmpressStaticMeshCrunchOnly.Value)
			{
				return false;
			}
			if (renderer is SkinnedMeshRenderer)
			{
				return true;
			}
			return EmpressHasDynamicOwner(renderer);
		}

		private bool EmpressShouldAvoidFallbackBlock(Renderer renderer, Bounds bounds)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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)
			string text = EmpressObjectPath(((Component)renderer).transform);
			for (int i = 0; i < EmpressMeshCrunchSkipWords.Length; i++)
			{
				if (text.IndexOf(EmpressMeshCrunchSkipWords[i], StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			if (renderer is SkinnedMeshRenderer || EmpressHasDynamicOwner(renderer))
			{
				return true;
			}
			Vector3 size = ((Bounds)(ref bounds)).size;
			float num = Mathf.Max(size.x, Mathf.Max(size.y, size.z));
			if (Mathf.Min(size.x, Mathf.Min(size.y, size.z)) < 0.02f || num > 18f)
			{
				return true;
			}
			return false;
		}

		private bool EmpressHasDynamicOwner(Renderer renderer)
		{
			Transform transform = ((Component)renderer).transform;
			if (!((Object)(object)((Component)transform).GetComponentInParent<Rigidbody>() != (Object)null) && !((Object)(object)((Component)transform).GetComponentInParent<Animator>() != (Object)null))
			{
				return (Object)(object)((Component)transform).GetComponentInParent<CharacterController>() != (Object)null;
			}
			return true;
		}

		private void EmpressStabilizeRenderer(EmpressPixelRiftPlugin plugin, Renderer renderer)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if (plugin.EmpressStabilizeCulling.Value)
			{
				int instanceID = ((Object)renderer).GetInstanceID();
				if (!empressRendererCullingStates.ContainsKey(instanceID))
				{
					empressRendererCullingStates[instanceID] = new EmpressRendererCullingState(renderer, renderer.allowOcclusionWhenDynamic);
				}
				renderer.allowOcclusionWhenDynamic = false;
				SkinnedMeshRenderer val = (SkinnedMeshRenderer)(object)((renderer is SkinnedMeshRenderer) ? renderer : null);
				if (val != null)
				{
					int instanceID2 = ((Object)val).GetInstanceID();
					if (!empressSkinnedBoundsStates.TryGetValue(instanceID2, out EmpressSkinnedBoundsState value))
					{
						value = new EmpressSkinnedBoundsState(val, ((Renderer)val).localBounds, val.updateWhenOffscreen);
						empressSkinnedBoundsStates[instanceID2] = value;
					}
					((Renderer)val).localBounds = EmpressPaddedBounds(value.Bounds, plugin.EmpressMeshSnap.Value);
					val.updateWhenOffscreen = true;
				}
			}
			if (!plugin.EmpressLockLodGroups.Value)
			{
				return;
			}
			LODGroup componentInParent = ((Component)renderer).GetComponentInParent<LODGroup>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				int instanceID3 = ((Object)componentInParent).GetInstanceID();
				if (!empressLodGroupStates.ContainsKey(instanceID3))
				{
					empressLodGroupStates[instanceID3] = new EmpressLodGroupState(componentInParent);
				}
				componentInParent.ForceLOD(0);
			}
		}

		private bool EmpressShouldRejectRenderer(Renderer renderer)
		{
			if ((Object)(object)renderer == (Object)null)
			{
				return true;
			}
			string text = EmpressObjectPath(((Component)renderer).transform);
			for (int i = 0; i < EmpressRendererRejectWords.Length; i++)
			{
				if (text.IndexOf(EmpressRendererRejectWords[i], StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			Material[] sharedMaterials = renderer.sharedMaterials;
			if (sharedMaterials == null || sharedMaterials.Length == 0)
			{
				return false;
			}
			int num = 0;
			foreach (Material val in sharedMaterials)
			{
				if (!((Object)(object)val == (Object)null) && EmpressMaterialVisible(val))
				{
					num++;
				}
			}
			return num == 0;
		}

		private bool EmpressShouldKeepOriginalShape(Renderer renderer, Mesh source, Bounds bounds)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			string text = EmpressObjectPath(((Component)renderer).transform) + " " + ((Object)source).name;
			for (int i = 0; i < EmpressDelicateMeshWords.Length; i++)
			{
				if (text.IndexOf(EmpressDelicateMeshWords[i], StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			Vector3 size = ((Bounds)(ref bounds)).size;
			float num = Mathf.Max(size.x, Mathf.Max(size.y, size.z));
			float num2 = Mathf.Max(0.001f, Mathf.Min(size.x, Mathf.Min(size.y, size.z)));
			if (num / num2 > 12f)
			{
				return true;
			}
			return false;
		}

		private bool EmpressMaterialVisible(Material material)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < EmpressColorProperties.Length; i++)
			{
				string text = EmpressColorProperties[i];
				if (material.HasProperty(text) && material.GetColor(text).a > 0.05f)
				{
					return true;
				}
			}
			for (int j = 0; j < EmpressTextureProperties.Length; j++)
			{
				string text2 = EmpressTextureProperties[j];
				if (material.HasProperty(text2) && (Object)(object)material.GetTexture(text2) != (Object)null)
				{
					return true;
				}
			}
			return material.renderQueue < 3000;
		}

		private string EmpressObjectPath(Transform transform)
		{
			string text = ((Object)transform).name;
			Transform parent = transform.parent;
			int num = 0;
			while ((Object)(object)parent != (Object)null && num < 8)
			{
				text = ((Object)parent).name + "/" + text;
				parent = parent.parent;
				num++;
			}
			return text;
		}

		private Mesh EmpressCreateBoundsMesh(Mesh source, Bounds bounds, float snap)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00b0: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: 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_0133: 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)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: 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_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Expected O, but got Unknown
			Vector3 size = ((Bounds)(ref bounds)).size;
			size.x = Mathf.Max(snap, Mathf.Round(size.x / snap) * snap);
			size.y = Mathf.Max(snap, Mathf.Round(size.y / snap) * snap);
			size.z = Mathf.Max(snap, Mathf.Round(size.z / snap) * snap);
			Vector3 center = ((Bounds)(ref bounds)).center;
			Vector3 val = size * 0.5f;
			Vector3 val2 = center - val;
			Vector3 val3 = center + val;
			Vector3[] vertices = (Vector3[])(object)new Vector3[8]
			{
				new Vector3(val2.x, val2.y, val2.z),
				new Vector3(val3.x, val2.y, val2.z),
				new Vector3(val3.x, val3.y, val2.z),
				new Vector3(val2.x, val3.y, val2.z),
				new Vector3(val2.x, val2.y, val3.z),
				new Vector3(val3.x, val2.y, val3.z),
				new Vector3(val3.x, val3.y, val3.z),
				new Vector3(val2.x, val3.y, val3.z)
			};
			int[] triangles = new int[36]
			{
				0, 2, 1, 0, 3, 2, 5, 6, 4, 6,
				7, 4, 4, 7, 0, 7, 3, 0, 1, 2,
				5, 2, 6, 5, 3, 7, 2, 7, 6, 2,
				4, 0, 5, 0, 1, 5
			};
			Vector2[] uv = (Vector2[])(object)new Vector2[8]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(1f, 1f),
				new Vector2(0f, 1f),
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(1f, 1f),
				new Vector2(0f, 1f)
			};
			Mesh val4 = new Mesh
			{
				name = "EmpressPixelRift.Block." + ((Object)source).name,
				vertices = vertices,
				triangles = triangles,
				uv = uv
			};
			val4.RecalculateNormals();
			val4.RecalculateBounds();
			EmpressPadMeshBounds(val4, snap);
			return val4;
		}

		private void EmpressPadMeshBounds(Mesh mesh, float snap)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			mesh.bounds = EmpressPaddedBounds(mesh.bounds, snap);
		}

		private Bounds EmpressPaddedBounds(Bounds bounds, float snap)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(0.25f, Mathf.Clamp(snap, 0.005f, 0.25f) * 8f);
			((Bounds)(ref bounds)).Expand(num);
			return bounds;
		}

		private void EmpressQueueTextureCrunch(Material material, string property, Texture texture)
		{
			string item = EmpressMaterialKey(material, property);
			int instanceID = ((Object)texture).GetInstanceID();
			if (empressTextureCopies.TryGetValue(instanceID, out Texture value))
			{
				material.SetTexture(property, value);
				EmpressPointTexture(value);
				return;
			}
			if (empressQueuedSlots.Add(item))
			{
				empressTextureJobs.Enqueue(new EmpressTextureJob(material, property, texture));
			}
			EmpressPointTexture(texture);
		}

		private void EmpressProcessTextureJobs(EmpressPixelRiftPlugin plugin)
		{
			int num = Mathf.Clamp(plugin.EmpressTextureConversionsPerFrame.Value, 1, 12);
			int num2 = 0;
			while (num2 < num && empressTextureJobs.Count > 0)
			{
				EmpressTextureJob empressTextureJob = empressTextureJobs.Dequeue();
				if ((Object)(object)empressTextureJob.Material == (Object)null || (Object)(object)empressTextureJob.Source == (Object)null || !empressTextureJob.Material.HasProperty(empressTextureJob.Property))
				{
					num2++;
					continue;
				}
				Texture source = empressTextureJob.Source;
				int instanceID = ((Object)source).GetInstanceID();
				if (!empressTextureCopies.TryGetValue(instanceID, out Texture value))
				{
					value = EmpressCreatePixelTexture(source, plugin.EmpressTextureResolution.Value, plugin.EmpressColorSteps.Value);
					empressTextureCopies[instanceID] = value;
				}
				empressTextureJob.Material.SetTexture(empressTextureJob.Property, value);
				EmpressPointTexture(value);
				num2++;
			}
		}

		private Texture EmpressCreatePixelTexture(Texture source, int resolution, int steps)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Clamp(resolution, 8, 128);
			RenderTexture active = RenderTexture.active;
			RenderTexture temporary = RenderTexture.GetTemporary(num, num, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)0);
			((Texture)temporary).filterMode = (FilterMode)0;
			Graphics.Blit(source, temporary);
			RenderTexture.active = temporary;
			Texture2D val = new Texture2D(num, num, (TextureFormat)4, false)
			{
				name = "EmpressPixelRift." + ((Object)source).name,
				filterMode = (FilterMode)0,
				wrapMode = source.wrapMode,
				anisoLevel = 0,
				mipMapBias = 0f
			};
			val.ReadPixels(new Rect(0f, 0f, (float)num, (float)num), 0, 0, false);
			Color[] pixels = val.GetPixels();
			for (int i = 0; i < pixels.Length; i++)
			{
				pixels[i] = EmpressQuantizeColor(pixels[i], steps);
			}
			val.SetPixels(pixels);
			val.Apply(false, false);
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
			return (Texture)(object)val;
		}

		private void EmpressPointTexture(Texture texture)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			int instanceID = ((Object)texture).GetInstanceID();
			if (!empressTextureStates.ContainsKey(instanceID))
			{
				empressTextureStates[instanceID] = new EmpressTextureState(texture, texture.filterMode, texture.anisoLevel, texture.mipMapBias);
			}
			texture.filterMode = (FilterMode)0;
			texture.anisoLevel = 0;
			texture.mipMapBias = 0f;
		}

		private void EmpressDisableRift()
		{
			if (empressRuntimeEnabled)
			{
				EmpressRestoreWorldStyle();
				empressRuntimeEnabled = false;
			}
		}

		private void EmpressRestoreWorldStyle()
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ff: Unknown result type (might be due to invalid IL or missing references)
			foreach (EmpressMaterialTextureState value in empressMaterialTextureStates.Values)
			{
				if ((Object)(object)value.Material != (Object)null && value.Material.HasProperty(value.Property))
				{
					value.Material.SetTexture(value.Property, value.Texture);
				}
			}
			foreach (EmpressMaterialColorState value2 in empressMaterialColorStates.Values)
			{
				if ((Object)(object)value2.Material != (Object)null && value2.Material.HasProperty(value2.Property))
				{
					value2.Material.SetColor(value2.Property, value2.Color);
				}
			}
			foreach (EmpressMaterialFloatState value3 in empressMaterialFloatStates.Values)
			{
				if ((Object)(object)value3.Material != (Object)null && value3.Material.HasProperty(value3.Property))
				{
					value3.Material.SetFloat(value3.Property, value3.Value);
				}
			}
			foreach (EmpressTextureState value4 in empressTextureStates.Values)
			{
				if ((Object)(object)value4.Texture != (Object)null)
				{
					value4.Texture.filterMode = value4.FilterMode;
					value4.Texture.anisoLevel = value4.AnisoLevel;
					value4.Texture.mipMapBias = value4.MipMapBias;
				}
			}
			foreach (EmpressRendererMaterialState value5 in empressRendererMaterialStates.Values)
			{
				if ((Object)(object)value5.Renderer != (Object)null)
				{
					value5.Renderer.sharedMaterials = value5.Materials;
				}
			}
			foreach (EmpressMeshFilterState value6 in empressMeshFilterStates.Values)
			{
				if ((Object)(object)value6.MeshFilter != (Object)null)
				{
					value6.MeshFilter.sharedMesh = value6.Mesh;
				}
			}
			foreach (EmpressSkinnedMeshState value7 in empressSkinnedMeshStates.Values)
			{
				if ((Object)(object)value7.Renderer != (Object)null)
				{
					value7.Renderer.sharedMesh = value7.Mesh;
				}
			}
			foreach (EmpressAnimatorState value8 in empressAnimatorStates.Values)
			{
				if ((Object)(object)value8.Animator != (Object)null)
				{
					value8.Animator.speed = value8.Speed;
					value8.Animator.cullingMode = value8.CullingMode;
				}
			}
			foreach (EmpressRendererCullingState value9 in empressRendererCullingStates.Values)
			{
				if ((Object)(object)value9.Renderer != (Object)null)
				{
					value9.Renderer.allowOcclusionWhenDynamic = value9.AllowOcclusionWhenDynamic;
				}
			}
			foreach (EmpressSkinnedBoundsState value10 in empressSkinnedBoundsStates.Values)
			{
				if ((Object)(object)value10.Renderer != (Object)null)
				{
					((Renderer)value10.Renderer).localBounds = value10.Bounds;
					value10.Renderer.updateWhenOffscreen = value10.UpdateWhenOffscreen;
				}
			}
			foreach (EmpressLodGroupState value11 in empressLodGroupStates.Values)
			{
				if ((Object)(object)value11.LodGroup != (Object)null)
				{
					value11.LodGroup.ForceLOD(-1);
				}
			}
			foreach (EmpressLightState value12 in empressLightStates.Values)
			{
				if ((Object)(object)value12.Light != (Object)null)
				{
					value12.Light.intensity = value12.Intensity;
					value12.Light.range = value12.Range;
					value12.Light.bounceIntensity = value12.BounceIntensity;
					value12.Light.color = value12.Color;
					value12.Light.shadows = value12.Shadows;
					value12.Light.shadowStrength = value12.ShadowStrength;
					value12.Light.renderMode = value12.RenderMode;
				}
			}
			empressMaterialTextureStates.Clear();
			empressMaterialColorStates.Clear();
			empressMaterialFloatStates.Clear();
			empressRendererMaterialStates.Clear();
			empressStableMaterialCopies.Clear();
			empressTextureStates.Clear();
			empressMeshCopies.Clear();
			empressEnemyMeshCopies.Clear();
			empressMeshFilterStates.Clear();
			empressSkinnedMeshStates.Clear();
			empressAnimatorStates.Clear();
			empressRendererCullingStates.Clear();
			empressSkinnedBoundsStates.Clear();
			empressLodGroupStates.Clear();
			empressLightStates.Clear();
			empressTextureJobs.Clear();
			empressRendererJobs.Clear();
			empressEnemyJobs.Clear();
			empressQueuedRendererIds.Clear();
			empressConvertedRendererIds.Clear();
			empressQueuedEnemyIds.Clear();
			empressConvertedEnemyIds.Clear();
			empressQueuedSlots.Clear();
			empressTotalRendererJobs = 0;
			empressProcessedRendererJobs = 0;
			empressConversionActive = false;
		}

		private static Color EmpressQuantizeColor(Color color, int steps)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(1f, (float)Mathf.Clamp(steps, 2, 16) - 1f);
			color.r = Mathf.Round(color.r * num) / num;
			color.g = Mathf.Round(color.g * num) / num;
			color.b = Mathf.Round(color.b * num) / num;
			return color;
		}

		private static string EmpressMaterialKey(Material material, string property)
		{
			return ((Object)material).GetInstanceID() + ":" + property;
		}
	}
	internal sealed class EmpressTextureState
	{
		internal Texture Texture { get; }

		internal FilterMode FilterMode { get; }

		internal int AnisoLevel { get; }

		internal float MipMapBias { get; }

		internal EmpressTextureState(Texture texture, FilterMode filterMode, int anisoLevel, float mipMapBias)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Texture = texture;
			FilterMode = filterMode;
			AnisoLevel = anisoLevel;
			MipMapBias = mipMapBias;
		}
	}
	internal sealed class EmpressMaterialTextureState
	{
		internal Material Material { get; }

		internal string Property { get; }

		internal Texture Texture { get; }

		internal EmpressMaterialTextureState(Material material, string property, Texture texture)
		{
			Material = material;
			Property = property;
			Texture = texture;
		}
	}
	internal sealed class EmpressMaterialColorState
	{
		internal Material Material { get; }

		internal string Property { get; }

		internal Color Color { get; }

		internal EmpressMaterialColorState(Material material, string property, Color color)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Material = material;
			Property = property;
			Color = color;
		}
	}
	internal sealed class EmpressMaterialFloatState
	{
		internal Material Material { get; }

		internal string Property { get; }

		internal float Value { get; }

		internal EmpressMaterialFloatState(Material material, string property, float value)
		{
			Material = material;
			Property = property;
			Value = value;
		}
	}
	internal sealed class EmpressRendererMaterialState
	{
		internal Renderer Renderer { get; }

		internal Material[] Materials { get; }

		internal EmpressRendererMaterialState(Renderer renderer, Material[] materials)
		{
			Renderer = renderer;
			Materials = materials;
		}
	}
	internal sealed class EmpressMeshFilterState
	{
		internal MeshFilter MeshFilter { get; }

		internal Mesh Mesh { get; }

		internal EmpressMeshFilterState(MeshFilter meshFilter, Mesh mesh)
		{
			MeshFilter = meshFilter;
			Mesh = mesh;
		}
	}
	internal sealed class EmpressSkinnedMeshState
	{
		internal SkinnedMeshRenderer Renderer { get; }

		internal Mesh Mesh { get; }

		internal EmpressSkinnedMeshState(SkinnedMeshRenderer renderer, Mesh mesh)
		{
			Renderer = renderer;
			Mesh = mesh;
		}
	}
	internal sealed class EmpressAnimatorState
	{
		internal Animator Animator { get; }

		internal float Speed { get; }

		internal AnimatorCullingMode CullingMode { get; }

		internal EmpressAnimatorState(Animator animator, float speed, AnimatorCullingMode cullingMode)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Animator = animator;
			Speed = speed;
			CullingMode = cullingMode;
		}
	}
	internal sealed class EmpressRendererCullingState
	{
		internal Renderer Renderer { get; }

		internal bool AllowOcclusionWhenDynamic { get; }

		internal EmpressRendererCullingState(Renderer renderer, bool allowOcclusionWhenDynamic)
		{
			Renderer = renderer;
			AllowOcclusionWhenDynamic = allowOcclusionWhenDynamic;
		}
	}
	internal sealed class EmpressSkinnedBoundsState
	{
		internal SkinnedMeshRenderer Renderer { get; }

		internal Bounds Bounds { get; }

		internal bool UpdateWhenOffscreen { get; }

		internal EmpressSkinnedBoundsState(SkinnedMeshRenderer renderer, Bounds bounds, bool updateWhenOffscreen)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Renderer = renderer;
			Bounds = bounds;
			UpdateWhenOffscreen = updateWhenOffscreen;
		}
	}
	internal sealed class EmpressLodGroupState
	{
		internal LODGroup LodGroup { get; }

		internal EmpressLodGroupState(LODGroup lodGroup)
		{
			LodGroup = lodGroup;
		}
	}
	internal sealed class EmpressLightState
	{
		internal Light Light { get; }

		internal float Intensity { get; }

		internal float Range { get; }

		internal float BounceIntensity { get; }

		internal Color Color { get; }

		internal LightShadows Shadows { get; }

		internal float ShadowStrength { get; }

		internal LightRenderMode RenderMode { get; }

		internal EmpressLightState(Light light)
		{
			//IL_0033: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			Light = light;
			Intensity = light.intensity;
			Range = light.range;
			BounceIntensity = light.bounceIntensity;
			Color = light.color;
			Shadows = light.shadows;
			ShadowStrength = light.shadowStrength;
			RenderMode = light.renderMode;
		}
	}
	internal sealed class EmpressTextureJob
	{
		internal Material Material { get; }

		internal string Property { get; }

		internal Texture Source { get; }

		internal EmpressTextureJob(Material material, string property, Texture source)
		{
			Material = material;
			Property = property;
			Source = source;
		}
	}
}