Decompiled source of DeepNorthGemEnhancements v1.0.0

BepInEx/plugins/DeepNorthGemEnhancements/DeepNorthGemEnhancements.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Extensions;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Deep North Gem Enhancements")]
[assembly: AssemblyDescription("Adds gem-infused weapon variants and effects.")]
[assembly: AssemblyCompany("Andoryn")]
[assembly: AssemblyProduct("Deep North Gem Enhancements")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.34962")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 DeepNorthGemEnhancements
{
	internal static class DraumyxCharcoalVisual
	{
		private static readonly Color Charcoal = new Color(0.2f, 0.2f, 0.22f, 1f);

		internal static int RebuildDualDaggerGroundCloudsFromGrimvarn(CustomItem item, GameObject grimvarnPrefab)
		{
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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)
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null || (Object)(object)grimvarnPrefab == (Object)null)
			{
				return 0;
			}
			string[] obj = new string[2] { "attach/frostfire_vfx_right", "attach/frostfire_vfx_left" };
			int num = 0;
			string[] array = obj;
			foreach (string text in array)
			{
				Transform val = grimvarnPrefab.transform.Find(text);
				Transform val2 = ((Component)item.ItemDrop).transform.Find(text);
				Transform val3 = (((Object)(object)val == (Object)null) ? null : val.Find("GrimvarnClouds"));
				if ((Object)(object)val3 == (Object)null || (Object)(object)val2 == (Object)null)
				{
					Debug.LogWarning((object)("[DeepNorthGemEnhancements] Draumyx Dual Daggers could not map Grimvarn ground Clouds at '" + text + "'."));
					continue;
				}
				Transform val4 = val2.Find("GrimvarnClouds");
				if ((Object)(object)val4 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)((Component)val4).gameObject);
				}
				GameObject val5 = Object.Instantiate<GameObject>(((Component)val3).gameObject, val2, false);
				((Object)val5).name = ((Object)val3).name;
				val5.transform.localPosition = val3.localPosition;
				val5.transform.localRotation = val3.localRotation;
				val5.transform.localScale = val3.localScale;
				val5.SetActive(true);
				Transform val6 = val5.transform;
				while ((Object)(object)val6 != (Object)null && (Object)(object)val6 != (Object)(object)val2)
				{
					((Component)val6).gameObject.SetActive(true);
					val6 = val6.parent;
				}
				ParticleSystem[] componentsInChildren = val5.GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem obj2 in componentsInChildren)
				{
					EmissionModule emission = obj2.emission;
					((EmissionModule)(ref emission)).enabled = true;
					ParticleSystemRenderer component = ((Component)obj2).GetComponent<ParticleSystemRenderer>();
					if ((Object)(object)component != (Object)null)
					{
						((Renderer)component).enabled = true;
					}
					obj2.Play(true);
				}
				num++;
			}
			Debug.Log((object)$"[DeepNorthGemEnhancements] Rebuilt {num}/2 Draumyx Dual Daggers ground Clouds branches from Grimvarn.");
			return num;
		}

		internal static int TintClouds(CustomItem item, Color tint, bool clearAndRestart = false)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null)
			{
				return 0;
			}
			int num = 0;
			Transform[] componentsInChildren = ((Component)item.ItemDrop).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || !IsCloudsOrShadowsNode(((Object)val).name) || HasCloudsOrShadowsAncestor(val, ((Component)item.ItemDrop).transform))
				{
					continue;
				}
				ParticleSystem[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<ParticleSystem>(true);
				if (clearAndRestart)
				{
					ParticleSystem[] array = componentsInChildren2;
					for (int j = 0; j < array.Length; j++)
					{
						array[j].Stop(false, (ParticleSystemStopBehavior)0);
					}
				}
				GrimvarnSwordVisual.TintParticles(((Component)val).gameObject, tint);
				if (clearAndRestart)
				{
					ParticleSystem[] array = componentsInChildren2;
					for (int j = 0; j < array.Length; j++)
					{
						array[j].Play(false);
					}
				}
				num++;
				((Object)val).name = "Shadows";
			}
			Debug.Log((object)$"[DeepNorthGemEnhancements] Tinted and renamed {num} Clouds branch(es) to Shadows on '{((Object)item.ItemDrop).name}'.");
			return num;
		}

		internal static int ScaleShadows(CustomItem item, float emissionMultiplier, float sizeMultiplier)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00d6: 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)
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null)
			{
				return 0;
			}
			int num = 0;
			Transform[] componentsInChildren = ((Component)item.ItemDrop).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || !string.Equals(((Object)val).name, "Shadows", StringComparison.OrdinalIgnoreCase) || HasCloudsOrShadowsAncestor(val, ((Component)item.ItemDrop).transform))
				{
					continue;
				}
				ParticleSystem[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem obj in componentsInChildren2)
				{
					EmissionModule emission = obj.emission;
					((EmissionModule)(ref emission)).rateOverTime = ScaleCurve(((EmissionModule)(ref emission)).rateOverTime, emissionMultiplier);
					MainModule main = obj.main;
					if (((MainModule)(ref main)).startSize3D)
					{
						((MainModule)(ref main)).startSizeX = ScaleCurve(((MainModule)(ref main)).startSizeX, sizeMultiplier);
						((MainModule)(ref main)).startSizeY = ScaleCurve(((MainModule)(ref main)).startSizeY, sizeMultiplier);
						((MainModule)(ref main)).startSizeZ = ScaleCurve(((MainModule)(ref main)).startSizeZ, sizeMultiplier);
					}
					else
					{
						((MainModule)(ref main)).startSize = ScaleCurve(((MainModule)(ref main)).startSize, sizeMultiplier);
					}
					num++;
				}
			}
			Debug.Log((object)$"[DeepNorthGemEnhancements] Scaled Shadows on '{((Object)item.ItemDrop).name}': {num} particle system(s), emission x{emissionMultiplier:0.##}, size x{sizeMultiplier:0.##}.");
			return num;
		}

		private static MinMaxCurve ScaleCurve(MinMaxCurve curve, float multiplier)
		{
			//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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected I4, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystemCurveMode mode = ((MinMaxCurve)(ref curve)).mode;
			switch ((int)mode)
			{
			case 0:
				((MinMaxCurve)(ref curve)).constant = ((MinMaxCurve)(ref curve)).constant * multiplier;
				break;
			case 3:
				((MinMaxCurve)(ref curve)).constantMin = ((MinMaxCurve)(ref curve)).constantMin * multiplier;
				((MinMaxCurve)(ref curve)).constantMax = ((MinMaxCurve)(ref curve)).constantMax * multiplier;
				break;
			case 1:
			case 2:
				((MinMaxCurve)(ref curve)).curveMultiplier = ((MinMaxCurve)(ref curve)).curveMultiplier * multiplier;
				break;
			}
			return curve;
		}

		internal static int RemoveClouds(CustomItem item)
		{
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null)
			{
				return 0;
			}
			int num = 0;
			Transform[] componentsInChildren = ((Component)item.ItemDrop).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || !IsCloudsOrShadowsNode(((Object)val).name))
				{
					continue;
				}
				bool flag = false;
				Transform parent = val.parent;
				while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)((Component)item.ItemDrop).transform)
				{
					if (IsCloudsOrShadowsNode(((Object)parent).name))
					{
						flag = true;
						break;
					}
					parent = parent.parent;
				}
				if (!flag)
				{
					Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
					num++;
				}
			}
			Debug.Log((object)$"[DeepNorthGemEnhancements] Removed {num} Clouds branch(es) from '{((Object)item.ItemDrop).name}'.");
			return num;
		}

		private static bool IsCloudsOrShadowsNode(string name)
		{
			if (string.IsNullOrEmpty(name))
			{
				return false;
			}
			string a = (name.EndsWith("(Clone)", StringComparison.OrdinalIgnoreCase) ? name.Substring(0, name.Length - "(Clone)".Length).TrimEnd(Array.Empty<char>()) : name);
			if (!string.Equals(a, "Clouds", StringComparison.OrdinalIgnoreCase))
			{
				return string.Equals(a, "Shadows", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		private static bool HasCloudsOrShadowsAncestor(Transform node, Transform root)
		{
			Transform parent = node.parent;
			while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)root)
			{
				if (IsCloudsOrShadowsNode(((Object)parent).name))
				{
					return true;
				}
				parent = parent.parent;
			}
			return false;
		}

		internal static int RestoreNordAlbedo(CustomItem item, GameObject nordPrefab)
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Expected O, but got Unknown
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null || (Object)(object)nordPrefab == (Object)null)
			{
				return 0;
			}
			int num = 0;
			Renderer[] componentsInChildren = ((Component)item.ItemDrop).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if ((Object)(object)((Component)val).GetComponent<MeshFilter>() == (Object)null && (Object)(object)((Component)val).GetComponent<SkinnedMeshRenderer>() == (Object)null)
				{
					continue;
				}
				Renderer val2 = FindRenderer(nordPrefab, RelativePath(((Component)item.ItemDrop).transform, ((Component)val).transform));
				Material[] sharedMaterials = val.sharedMaterials;
				Material[] materials = (((Object)(object)val2 == (Object)null) ? null : val2.sharedMaterials);
				Material[] array = null;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val3 = sharedMaterials[j];
					Texture2D texture = GetTexture(materials, j);
					if (!((Object)(object)val3 == (Object)null) && !((Object)(object)texture == (Object)null) && val3.HasProperty("_MainTex"))
					{
						Material val4 = new Material(val3)
						{
							name = "Draumyx_NordBase_" + ((Object)val3).name
						};
						val4.SetTexture("_MainTex", (Texture)(object)texture);
						if (array == null)
						{
							array = (Material[])sharedMaterials.Clone();
						}
						array[j] = val4;
						num++;
					}
				}
				if (array != null)
				{
					val.sharedMaterials = array;
				}
			}
			Debug.Log((object)$"[DeepNorthGemEnhancements] Restored {num} Nord base albedo material(s) on '{((Object)item.ItemDrop).name}'.");
			return num;
		}

		internal static int TintWeaponAlbedo(CustomItem item, GameObject nordPrefab, GameObject frostfirePrefab, bool blackenBlueAccents, bool tintBaseCharcoal = true)
		{
			//IL_0165: 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_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Expected O, but got Unknown
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Expected O, but got Unknown
			//IL_01b3: 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)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null)
			{
				return 0;
			}
			int num = 0;
			int num2 = 0;
			Renderer[] componentsInChildren = ((Component)item.ItemDrop).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if ((Object)(object)((Component)val).GetComponent<MeshFilter>() == (Object)null && (Object)(object)((Component)val).GetComponent<SkinnedMeshRenderer>() == (Object)null)
				{
					continue;
				}
				string path = RelativePath(((Component)item.ItemDrop).transform, ((Component)val).transform);
				Renderer val2 = FindRenderer(nordPrefab, path);
				Renderer val3 = (blackenBlueAccents ? FindRenderer(frostfirePrefab, path) : null);
				Material[] sharedMaterials = val.sharedMaterials;
				Material[] materials = (((Object)(object)val2 == (Object)null) ? null : val2.sharedMaterials);
				Material[] materials2 = (((Object)(object)val3 == (Object)null) ? null : val3.sharedMaterials);
				Material[] array = null;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val4 = sharedMaterials[j];
					if ((Object)(object)val4 == (Object)null || !val4.HasProperty("_MainTex"))
					{
						continue;
					}
					Texture texture = val4.GetTexture("_MainTex");
					Texture2D val5 = (Texture2D)(object)((texture is Texture2D) ? texture : null);
					Texture2D val6 = GetTexture(materials, j) ?? val5;
					if ((Object)(object)val6 == (Object)null)
					{
						continue;
					}
					Texture2D texture2 = GetTexture(materials2, j);
					bool flag = blackenBlueAccents && (Object)(object)texture2 != (Object)null;
					Color32[] array2 = ReadPixels(val6);
					Color32[] frostfirePixels = (flag ? ReadPixels(texture2) : null);
					Color32[] array3 = (Color32[])(object)new Color32[array2.Length];
					for (int k = 0; k < array2.Length; k++)
					{
						Color32 val7 = array2[k];
						array3[k] = (tintBaseCharcoal ? TintCharcoal(val7) : val7);
						if (flag && IsBlueAccent(frostfirePixels, texture2, ((Texture)val6).width, ((Texture)val6).height, k) && IsWarmNordAccent(val7))
						{
							array3[k] = new Color32((byte)0, (byte)0, (byte)0, val7.a);
							num2++;
						}
					}
					Texture2D val8 = new Texture2D(((Texture)val6).width, ((Texture)val6).height, (TextureFormat)4, true, false)
					{
						name = (tintBaseCharcoal ? "Draumyx_Charcoal_" : "Draumyx_NordBase_") + ((Object)val6).name,
						filterMode = ((Texture)val6).filterMode,
						wrapMode = ((Texture)val6).wrapMode,
						anisoLevel = ((Texture)val6).anisoLevel
					};
					val8.SetPixels32(array3);
					val8.Apply(true, false);
					Material val9 = new Material(val4)
					{
						name = (tintBaseCharcoal ? "Draumyx_Charcoal_" : "Draumyx_Blackened_") + ((Object)val4).name
					};
					val9.SetTexture("_MainTex", (Texture)(object)val8);
					if (array == null)
					{
						array = (Material[])sharedMaterials.Clone();
					}
					array[j] = val9;
					num++;
				}
				if (array != null)
				{
					val.sharedMaterials = array;
				}
			}
			Debug.Log((object)$"[DeepNorthGemEnhancements] Updated {num} weapon material(s) on '{((Object)item.ItemDrop).name}'; charcoal base={tintBaseCharcoal}, blackened {num2} blue-accent texels.");
			return num;
		}

		private static Renderer FindRenderer(GameObject prefab, string path)
		{
			if ((Object)(object)prefab == (Object)null)
			{
				return null;
			}
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (string.Equals(RelativePath(prefab.transform, ((Component)val).transform), path, StringComparison.Ordinal))
				{
					return val;
				}
			}
			return null;
		}

		private static string RelativePath(Transform root, Transform target)
		{
			string text = ((Object)target).name;
			Transform parent = target.parent;
			while ((Object)(object)parent != (Object)null && (Object)(object)parent != (Object)(object)root)
			{
				text = ((Object)parent).name + "/" + text;
				parent = parent.parent;
			}
			return text;
		}

		private static Texture2D GetTexture(Material[] materials, int slot)
		{
			if (materials == null || slot >= materials.Length || (Object)(object)materials[slot] == (Object)null || !materials[slot].HasProperty("_MainTex"))
			{
				return null;
			}
			Texture texture = materials[slot].GetTexture("_MainTex");
			return (Texture2D)(object)((texture is Texture2D) ? texture : null);
		}

		private static Color32 TintCharcoal(Color32 source)
		{
			//IL_0000: 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)
			//IL_001b: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			float num = ((float)(int)source.r * 0.299f + (float)(int)source.g * 0.587f + (float)(int)source.b * 0.114f) / 255f;
			return new Color32((byte)(Charcoal.r * num * 255f), (byte)(Charcoal.g * num * 255f), (byte)(Charcoal.b * num * 255f), source.a);
		}

		private static bool IsBlueAccent(Color32[] frostfirePixels, Texture2D frostfireTexture, int outputWidth, int outputHeight, int index)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			int num = index % outputWidth;
			int num2 = index / outputWidth;
			int num3 = Mathf.Clamp(Mathf.FloorToInt(((float)num + 0.5f) * (float)((Texture)frostfireTexture).width / (float)outputWidth), 0, ((Texture)frostfireTexture).width - 1);
			int num4 = Mathf.Clamp(Mathf.FloorToInt(((float)num2 + 0.5f) * (float)((Texture)frostfireTexture).height / (float)outputHeight), 0, ((Texture)frostfireTexture).height - 1);
			Color32 val = frostfirePixels[num4 * ((Texture)frostfireTexture).width + num3];
			if (val.a > 0 && val.g - val.r >= 20)
			{
				return val.b - val.r >= 30;
			}
			return false;
		}

		private static bool IsWarmNordAccent(Color32 source)
		{
			//IL_0000: 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)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			if (source.a > 0 && source.r > 40 && source.r - source.g >= 12)
			{
				return source.r - source.b >= 16;
			}
			return false;
		}

		private static Color32[] ReadPixels(Texture2D source)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (((Texture)source).isReadable)
			{
				try
				{
					return source.GetPixels32();
				}
				catch (UnityException)
				{
				}
			}
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)source).width, ((Texture)source).height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)0);
			RenderTexture active = RenderTexture.active;
			Texture2D val = null;
			try
			{
				Graphics.Blit((Texture)(object)source, temporary);
				RenderTexture.active = temporary;
				val = new Texture2D(((Texture)source).width, ((Texture)source).height, (TextureFormat)4, false, false);
				val.ReadPixels(new Rect(0f, 0f, (float)((Texture)source).width, (float)((Texture)source).height), 0, 0, false);
				val.Apply(false, false);
				return val.GetPixels32();
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}
	}
	internal sealed class DraumyxConfusionStatusEffect : StatusEffect
	{
		private const string EffectName = "DeepNorthGemEnhancements_DraumyxConfusion";

		private static readonly int ConfusionStatusHash = StringExtensionMethods.GetStableHashCode("DeepNorthGemEnhancements_DraumyxConfusion");

		private const string DraumyxSuffix = "_Draumyx";

		private const string ShadowsiphonSuffix = "_Shadowsiphon";

		private const float TickInterval = 1f;

		private const float ConfusionLightIntensity = 0.65f;

		private const float ConfusionLightRange = 3f;

		private static readonly Color ConfusionLightColor = new Color(0.66f, 0.54f, 0.85f, 1f);

		private static readonly int DisorientedUntilKey = StringExtensionMethods.GetStableHashCode("DeepNorthGemEnhancements_DraumyxConfusedUntil");

		private static StatusEffect _template;

		private static EffectList _poisonTickEffects;

		private static Sprite _disorientedIcon;

		private Faction _originalFaction;

		private bool _changesFaction;

		private float _tickTimer;

		private GameObject _confusionLightObject;

		internal static int RegisterWeaponProcs(ObjectDB objectDb)
		{
			if ((Object)(object)objectDb == (Object)null)
			{
				return 0;
			}
			StatusEffect template = GetTemplate();
			int num = template.NameHash();
			StatusEffect val = objectDb.GetStatusEffect(num);
			if ((Object)(object)val == (Object)null)
			{
				objectDb.m_StatusEffects.Add(template);
				val = template;
			}
			if (!(val is DraumyxConfusionStatusEffect))
			{
				Debug.LogError((object)"[DeepNorthGemEnhancements] Disoriented status hash is already used by another status effect; Draumyx procs were not assigned.");
				return 0;
			}
			int num2 = 0;
			foreach (GameObject item in objectDb.m_items)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				bool flag = ((Object)item).name.EndsWith("_Draumyx", StringComparison.Ordinal);
				bool flag2 = ((Object)item).name.EndsWith("_Shadowsiphon", StringComparison.Ordinal);
				if (flag || flag2)
				{
					ItemDrop component = item.GetComponent<ItemDrop>();
					if (!((Object)(object)component == (Object)null) && component.m_itemData != null && component.m_itemData.m_shared != null)
					{
						SharedData shared = component.m_itemData.m_shared;
						shared.m_attackStatusEffect = val;
						shared.m_attackStatusEffectChance = Mathf.Clamp(flag ? ModConfig.DraumyxDisorientedProcChancePercent.Value : ModConfig.ShadowsiphonDisorientedProcChancePercent.Value, 0f, 100f) / 100f;
						num2++;
					}
				}
			}
			return num2;
		}

		private static StatusEffect GetTemplate()
		{
			if ((Object)(object)_template == (Object)null)
			{
				DraumyxConfusionStatusEffect draumyxConfusionStatusEffect = ScriptableObject.CreateInstance<DraumyxConfusionStatusEffect>();
				((Object)draumyxConfusionStatusEffect).name = "DeepNorthGemEnhancements_DraumyxConfusion";
				((StatusEffect)draumyxConfusionStatusEffect).m_name = "Disoriented";
				((StatusEffect)draumyxConfusionStatusEffect).m_tooltip = GetTooltip();
				((StatusEffect)draumyxConfusionStatusEffect).m_ttl = GetConfiguredDurationSeconds();
				((StatusEffect)draumyxConfusionStatusEffect).m_icon = GetDisorientedIcon();
				StatusEffect obj = (((Object)(object)ObjectDB.instance == (Object)null) ? null : ObjectDB.instance.GetStatusEffect(SEMan.s_statusEffectPoison));
				SE_Poison val = (SE_Poison)(object)((obj is SE_Poison) ? obj : null);
				if ((Object)(object)val != (Object)null)
				{
					((StatusEffect)draumyxConfusionStatusEffect).m_startEffects = CopyEffectList(((StatusEffect)val).m_startEffects);
					_poisonTickEffects = CopyEffectList(val.m_tickEffect);
				}
				else
				{
					Debug.LogWarning((object)"[DeepNorthGemEnhancements] Poison status VFX were unavailable; Disoriented will run without its borrowed smoke visuals.");
				}
				_template = (StatusEffect)(object)draumyxConfusionStatusEffect;
			}
			return _template;
		}

		private static string GetTooltip()
		{
			string text = Mathf.Clamp(ModConfig.DisorientedDamageReductionPercent.Value, 0f, 100f).ToString("0.##", CultureInfo.InvariantCulture);
			return "Damage dealt is reduced by " + text + "%. Creatures will wander or attack other creatures if able.";
		}

		private static float GetConfiguredDurationSeconds()
		{
			return Mathf.Max(0f, ModConfig.DisorientedDurationSeconds.Value);
		}

		internal static void RefreshConfiguredSettings(ObjectDB objectDb)
		{
			if (!((Object)(object)objectDb == (Object)null))
			{
				StatusEffect statusEffect = objectDb.GetStatusEffect(ConfusionStatusHash);
				if ((Object)(object)statusEffect != (Object)null)
				{
					statusEffect.m_tooltip = GetTooltip();
					statusEffect.m_ttl = GetConfiguredDurationSeconds();
				}
			}
		}

		private static Sprite GetDisorientedIcon()
		{
			//IL_006b: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: 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)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Expected O, but got Unknown
			//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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_disorientedIcon != (Object)null)
			{
				return _disorientedIcon;
			}
			StatusEffect val = (((Object)(object)ObjectDB.instance == (Object)null) ? null : ObjectDB.instance.GetStatusEffect(SEMan.s_statusEffectCold));
			Sprite val2 = (((Object)(object)val == (Object)null) ? null : val.m_icon);
			if ((Object)(object)val2 == (Object)null || (Object)(object)val2.texture == (Object)null)
			{
				Debug.LogWarning((object)"[DeepNorthGemEnhancements] Cold status icon was unavailable; Disoriented will have no icon.");
				return null;
			}
			try
			{
				Rect textureRect = val2.textureRect;
				Color32[] array = ReadTexturePixels(val2.texture);
				int num = Mathf.RoundToInt(((Rect)(ref textureRect)).x);
				int num2 = Mathf.RoundToInt(((Rect)(ref textureRect)).y);
				int num3 = Mathf.RoundToInt(((Rect)(ref textureRect)).width);
				int num4 = Mathf.RoundToInt(((Rect)(ref textureRect)).height);
				Color32[] array2 = (Color32[])(object)new Color32[num3 * num4];
				for (int i = 0; i < num4; i++)
				{
					for (int j = 0; j < num3; j++)
					{
						Color32 pixel = array[(num2 + i) * ((Texture)val2.texture).width + num + j];
						array2[i * num3 + j] = RecolorIconPixel(pixel);
					}
				}
				Texture2D val3 = new Texture2D(num3, num4, (TextureFormat)4, false, false)
				{
					name = "DeepNorthGemEnhancements_DisorientedIconTexture"
				};
				val3.SetPixels32(array2);
				val3.Apply(false, false);
				Vector2 val4 = default(Vector2);
				((Vector2)(ref val4))..ctor(val2.pivot.x / ((Rect)(ref textureRect)).width, val2.pivot.y / ((Rect)(ref textureRect)).height);
				_disorientedIcon = Sprite.Create(val3, new Rect(0f, 0f, (float)num3, (float)num4), val4, val2.pixelsPerUnit, 0u, (SpriteMeshType)0, val2.border);
				((Object)_disorientedIcon).name = "DeepNorthGemEnhancements_DisorientedIcon";
				return _disorientedIcon;
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[DeepNorthGemEnhancements] Could not create the recolored Cold icon for Disoriented: " + ex.Message));
				return null;
			}
		}

		private static Color32 RecolorIconPixel(Color32 pixel)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			if (pixel.a == 0)
			{
				return pixel;
			}
			int num = Mathf.Min(new int[3] { pixel.r, pixel.g, pixel.b });
			int num2 = Mathf.Max(new int[3] { pixel.r, pixel.g, pixel.b });
			bool num3 = (float)(int)pixel.b > (float)(int)pixel.r * 1.18f && (float)(int)pixel.b > (float)(int)pixel.g * 1.08f && pixel.b > 45;
			bool flag = num > 170 && num2 - num < 42;
			if (num3)
			{
				byte num4 = (byte)Mathf.Clamp(Mathf.RoundToInt((float)num2 * 0.3f), 22, 95);
				return new Color32(num4, num4, num4, pixel.a);
			}
			if (flag)
			{
				float num5 = Mathf.Clamp01((float)num2 / 255f);
				return new Color32((byte)(0.72f * num5 * 255f), (byte)(0.61f * num5 * 255f), (byte)(0.86f * num5 * 255f), pixel.a);
			}
			return pixel;
		}

		private static Color32[] ReadTexturePixels(Texture2D source)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (((Texture)source).isReadable)
			{
				try
				{
					return source.GetPixels32();
				}
				catch (UnityException)
				{
				}
			}
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)source).width, ((Texture)source).height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)0);
			RenderTexture active = RenderTexture.active;
			Texture2D val = null;
			try
			{
				Graphics.Blit((Texture)(object)source, temporary);
				RenderTexture.active = temporary;
				val = new Texture2D(((Texture)source).width, ((Texture)source).height, (TextureFormat)4, false, false);
				val.ReadPixels(new Rect(0f, 0f, (float)((Texture)source).width, (float)((Texture)source).height), 0, 0, false);
				val.Apply(false, false);
				return val.GetPixels32();
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		public override void Setup(Character character)
		{
			//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_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			_originalFaction = character.m_faction;
			((StatusEffect)this).Setup(character);
			_changesFaction = (int)_originalFaction != 8;
			if (_changesFaction)
			{
				character.m_faction = (Faction)0;
				UpdateSyncedFactionOverride();
			}
			else
			{
				ClearSyncedFactionOverride();
			}
			TintEffectInstances(base.m_startEffectInstances);
			CreateConfusionLight(character);
		}

		public override void ResetTime()
		{
			base.m_ttl = GetConfiguredDurationSeconds();
			((StatusEffect)this).ResetTime();
			UpdateSyncedFactionOverride();
		}

		public override void ModifyAttack(SkillType skill, ref HitData hitData)
		{
			float num = Mathf.Clamp(ModConfig.DisorientedDamageReductionPercent.Value, 0f, 100f) / 100f;
			hitData.ApplyModifier(1f - num);
		}

		public override void UpdateStatusEffect(float dt)
		{
			//IL_0060: 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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			((StatusEffect)this).UpdateStatusEffect(dt);
			if (_poisonTickEffects != null && _poisonTickEffects.HasEffects() && !((Object)(object)base.m_character == (Object)null))
			{
				_tickTimer -= dt;
				if (!(_tickTimer > 0f))
				{
					_tickTimer = 1f;
					TintEffectInstances(_poisonTickEffects.Create(((Component)base.m_character).transform.position, ((Component)base.m_character).transform.rotation, (Transform)null, 1f, -1, default(ZDOID)));
				}
			}
		}

		public override void Stop()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)base.m_character != (Object)null)
			{
				if (_changesFaction)
				{
					base.m_character.m_faction = _originalFaction;
				}
				ClearSyncedFactionOverride();
			}
			RemoveConfusionLight();
			((StatusEffect)this).Stop();
		}

		private void CreateConfusionLight(Character character)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0038: 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)
			RemoveConfusionLight();
			if (!((Object)(object)character == (Object)null))
			{
				_confusionLightObject = new GameObject("DeepNorthGemEnhancements_DisorientedLight");
				Transform transform = _confusionLightObject.transform;
				transform.SetParent(((Component)character).transform, false);
				transform.localPosition = Vector3.up;
				Light obj = _confusionLightObject.AddComponent<Light>();
				obj.type = (LightType)2;
				obj.color = ConfusionLightColor;
				obj.intensity = 0.65f;
				obj.range = 3f;
				obj.shadows = (LightShadows)0;
			}
		}

		private void RemoveConfusionLight()
		{
			if ((Object)(object)_confusionLightObject != (Object)null)
			{
				Object.Destroy((Object)(object)_confusionLightObject);
				_confusionLightObject = null;
			}
		}

		private void UpdateSyncedFactionOverride()
		{
			if (_changesFaction && !((Object)(object)base.m_character == (Object)null) && !((Object)(object)ZNet.instance == (Object)null))
			{
				ZNetView component = ((Component)base.m_character).GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner())
				{
					long ticks = ZNet.instance.GetTime().AddSeconds(GetConfiguredDurationSeconds()).Ticks;
					component.GetZDO().Set(DisorientedUntilKey, ticks);
				}
			}
		}

		private void ClearSyncedFactionOverride()
		{
			if (!((Object)(object)base.m_character == (Object)null))
			{
				ZNetView component = ((Component)base.m_character).GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner())
				{
					component.GetZDO().Set(DisorientedUntilKey, 0L);
				}
			}
		}

		private static EffectList CopyEffectList(EffectList source)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0063: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00d0: Expected O, but got Unknown
			EffectList val = new EffectList();
			if (source?.m_effectPrefabs == null)
			{
				return val;
			}
			val.m_effectPrefabs = (EffectData[])(object)new EffectData[source.m_effectPrefabs.Length];
			for (int i = 0; i < source.m_effectPrefabs.Length; i++)
			{
				EffectData val2 = source.m_effectPrefabs[i];
				if (val2 != null)
				{
					val.m_effectPrefabs[i] = new EffectData
					{
						m_prefab = val2.m_prefab,
						m_enabled = val2.m_enabled,
						m_variant = val2.m_variant,
						m_attach = val2.m_attach,
						m_follow = val2.m_follow,
						m_inheritParentRotation = val2.m_inheritParentRotation,
						m_inheritParentScale = val2.m_inheritParentScale,
						m_multiplyParentVisualScale = val2.m_multiplyParentVisualScale,
						m_randomRotation = val2.m_randomRotation,
						m_scale = val2.m_scale,
						m_childTransform = val2.m_childTransform
					};
				}
			}
			return val;
		}

		private static void TintEffectInstances(GameObject[] roots)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0072: 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_0081: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			if (roots == null)
			{
				return;
			}
			foreach (GameObject val in roots)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>(true);
				foreach (ParticleSystem obj in componentsInChildren)
				{
					MainModule main = obj.main;
					((MainModule)(ref main)).startColor = TintGradient(((MainModule)(ref main)).startColor);
					ColorOverLifetimeModule colorOverLifetime = obj.colorOverLifetime;
					if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
					{
						((ColorOverLifetimeModule)(ref colorOverLifetime)).color = TintGradient(((ColorOverLifetimeModule)(ref colorOverLifetime)).color);
					}
					ColorBySpeedModule colorBySpeed = obj.colorBySpeed;
					if (((ColorBySpeedModule)(ref colorBySpeed)).enabled)
					{
						((ColorBySpeedModule)(ref colorBySpeed)).color = TintGradient(((ColorBySpeedModule)(ref colorBySpeed)).color);
					}
				}
				Renderer[] componentsInChildren2 = val.GetComponentsInChildren<Renderer>(true);
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					Material[] materials = componentsInChildren2[j].materials;
					foreach (Material val2 in materials)
					{
						if (!((Object)(object)val2 == (Object)null))
						{
							TintMaterialColor(val2, "_Color");
							TintMaterialColor(val2, "_TintColor");
							TintMaterialColor(val2, "_EmissionColor");
						}
					}
				}
				Light[] componentsInChildren3 = val.GetComponentsInChildren<Light>(true);
				foreach (Light obj2 in componentsInChildren3)
				{
					obj2.color = LavenderTint(obj2.color);
					obj2.intensity *= 0.65f;
				}
			}
		}

		private static Color TintColor(Color source)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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)
			if (source.g > source.r * 1.12f && source.g > source.b * 1.08f)
			{
				float num = Mathf.Clamp(Mathf.Max(new float[3] { source.r, source.g, source.b }), 0.35f, 1f);
				Color val = default(Color);
				((Color)(ref val))..ctor(0.61f, 0.48f, 0.78f, source.a);
				return new Color(val.r * num, val.g * num, val.b * num, source.a);
			}
			float num2 = Mathf.Max(new float[3] { source.r, source.g, source.b }) * 0.35f;
			return new Color(num2 * 0.92f, num2 * 0.88f, num2, source.a);
		}

		private static void TintMaterialColor(Material material, string property)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			if (material.HasProperty(property))
			{
				material.SetColor(property, TintColor(material.GetColor(property)));
			}
		}

		private static MinMaxGradient TintGradient(MinMaxGradient source)
		{
			//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_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected I4, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystemGradientMode mode = ((MinMaxGradient)(ref source)).mode;
			return (MinMaxGradient)((int)mode switch
			{
				0 => new MinMaxGradient(TintColor(((MinMaxGradient)(ref source)).color)), 
				2 => new MinMaxGradient(TintColor(((MinMaxGradient)(ref source)).colorMin), TintColor(((MinMaxGradient)(ref source)).colorMax)), 
				1 => new MinMaxGradient(TintGradient(((MinMaxGradient)(ref source)).gradient)), 
				3 => new MinMaxGradient(TintGradient(((MinMaxGradient)(ref source)).gradientMin), TintGradient(((MinMaxGradient)(ref source)).gradientMax)), 
				4 => new MinMaxGradient(TintGradient(((MinMaxGradient)(ref source)).gradient)), 
				_ => source, 
			});
		}

		private static Gradient TintGradient(Gradient source)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			GradientColorKey[] colorKeys = source.colorKeys;
			for (int i = 0; i < colorKeys.Length; i++)
			{
				colorKeys[i].color = TintColor(colorKeys[i].color);
			}
			Gradient val = new Gradient();
			val.SetKeys(colorKeys, source.alphaKeys);
			return val;
		}

		private static Color LavenderTint(Color source)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0.56f, 0.43f, 0.72f, source.a);
		}

		internal static bool IsFactionOverridden(Character character)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			if ((Object)(object)character == (Object)null || (int)character.m_faction == 8 || (Object)(object)ZNet.instance == (Object)null)
			{
				return false;
			}
			ZNetView component = ((Component)character).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return false;
			}
			return component.GetZDO().GetLong(DisorientedUntilKey, 0L) > ZNet.instance.GetTime().Ticks;
		}

		internal static bool IsConfusionActive(Character character)
		{
			if ((Object)(object)character != (Object)null && character.GetSEMan() != null)
			{
				return character.GetSEMan().HaveStatusEffect(ConfusionStatusHash);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Character), "GetFaction")]
	internal static class DraumyxConfusionFactionPatch
	{
		[HarmonyPostfix]
		private static void Postfix(Character __instance, ref Faction __result)
		{
			if (DraumyxConfusionStatusEffect.IsFactionOverridden(__instance))
			{
				__result = (Faction)0;
			}
		}
	}
	[HarmonyPatch(typeof(BaseAI), "IsEnemy", new Type[]
	{
		typeof(Character),
		typeof(Character)
	})]
	internal static class DraumyxConfusionPlayerTargetPatch
	{
		[HarmonyPostfix]
		private static void Postfix(Character a, Character b, ref bool __result)
		{
			if (a is Player && (Object)(object)b != (Object)null && !b.IsPlayer() && DraumyxConfusionStatusEffect.IsFactionOverridden(b))
			{
				__result = true;
			}
		}
	}
	[HarmonyPatch(typeof(EnemyHud), "UpdateHuds")]
	internal static class DraumyxConfusionFriendlyHealthBarPatch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(BaseAI), "IsEnemy", new Type[2]
			{
				typeof(Character),
				typeof(Character)
			}, (Type[])null);
			MethodInfo operand = AccessTools.Method(typeof(DraumyxConfusionFriendlyHealthBarPatch), "IsEnemyForHealthBar", (Type[])null, (Type[])null);
			List<CodeInstruction> list = new List<CodeInstruction>();
			int num = 0;
			foreach (CodeInstruction instruction in instructions)
			{
				if (methodInfo != null && CodeInstructionExtensions.Calls(instruction, methodInfo))
				{
					CodeInstruction item = new CodeInstruction(instruction)
					{
						opcode = OpCodes.Call,
						operand = operand
					};
					list.Add(item);
					num++;
				}
				else
				{
					list.Add(instruction);
				}
			}
			if (num != 1)
			{
				Debug.LogWarning((object)("[DeepNorthGemEnhancements] Disoriented friendly health-bar patch found " + num + " EnemyHud faction check(s); expected 1."));
			}
			return list;
		}

		private static bool IsEnemyForHealthBar(Character player, Character target)
		{
			if (player is Player && (Object)(object)target != (Object)null && !target.IsPlayer() && DraumyxConfusionStatusEffect.IsFactionOverridden(target))
			{
				return false;
			}
			return BaseAI.IsEnemy(player, target);
		}
	}
	internal static class DraumyxConfusionWanderController
	{
		private static readonly int StateKey = StringExtensionMethods.GetStableHashCode("DeepNorthGemEnhancements_ConfusionWanderState");

		private static readonly int OriginalRangeKey = StringExtensionMethods.GetStableHashCode("DeepNorthGemEnhancements_ConfusionOriginalRange");

		private static readonly int OriginalPatrolKey = StringExtensionMethods.GetStableHashCode("DeepNorthGemEnhancements_ConfusionOriginalPatrol");

		private static readonly int OriginalPatrolPointKey = StringExtensionMethods.GetStableHashCode("DeepNorthGemEnhancements_ConfusionOriginalPatrolPoint");

		private static readonly int OriginalFollowKey = StringExtensionMethods.GetStableHashCode("DeepNorthGemEnhancements_ConfusionOriginalFollow");

		private static readonly int TemporaryPatrolPointKey = StringExtensionMethods.GetStableHashCode("DeepNorthGemEnhancements_ConfusionTemporaryPatrolPoint");

		private static readonly MethodInfo SetPatrolPointAtPosition = AccessTools.Method(typeof(BaseAI), "SetPatrolPoint", new Type[1] { typeof(Vector3) }, (Type[])null);

		internal static bool Update(BaseAI ai, bool aiUpdated)
		{
			if (!aiUpdated)
			{
				return false;
			}
			Character component = ((Component)ai).GetComponent<Character>();
			ZNetView val = (((Object)(object)component == (Object)null) ? null : ((Component)component).GetComponent<ZNetView>());
			if ((Object)(object)val == (Object)null || !val.IsValid() || !val.IsOwner())
			{
				return false;
			}
			ZDO zDO = val.GetZDO();
			if (DraumyxConfusionStatusEffect.IsFactionOverridden(component))
			{
				Apply(ai, zDO);
				return true;
			}
			Restore(ai, zDO);
			return false;
		}

		private static void Apply(BaseAI ai, ZDO zdo)
		{
			//IL_004b: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			if (!zdo.GetBool(StateKey, false))
			{
				zdo.Set(OriginalRangeKey, ai.m_randomMoveRange);
				zdo.Set(OriginalPatrolKey, zdo.GetBool(ZDOVars.s_patrol, false));
				zdo.Set(OriginalPatrolPointKey, zdo.GetVec3(ZDOVars.s_patrolPoint, ((Component)ai).transform.position));
				zdo.Set(OriginalFollowKey, zdo.GetString(ZDOVars.s_follow, ""));
				zdo.Set(TemporaryPatrolPointKey, ((Component)ai).transform.position);
				zdo.Set(StateKey, true);
				ai.SetPatrolPoint();
			}
			ai.m_randomMoveRange = Mathf.Max(0f, ModConfig.DisorientedWanderRangeMeters.Value);
		}

		private static void Restore(BaseAI ai, ZDO zdo)
		{
			//IL_0065: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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)
			if (!zdo.GetBool(StateKey, false))
			{
				return;
			}
			ai.m_randomMoveRange = zdo.GetFloat(OriginalRangeKey, ai.m_randomMoveRange);
			bool num = zdo.GetString(ZDOVars.s_follow, "") != zdo.GetString(OriginalFollowKey, "");
			int num2;
			if (zdo.GetBool(ZDOVars.s_patrol, false))
			{
				Vector3 val = zdo.GetVec3(ZDOVars.s_patrolPoint, ((Component)ai).transform.position) - zdo.GetVec3(TemporaryPatrolPointKey, ((Component)ai).transform.position);
				num2 = ((((Vector3)(ref val)).sqrMagnitude > 0.04f) ? 1 : 0);
			}
			else
			{
				num2 = 1;
			}
			bool flag = (byte)num2 != 0;
			if (!num && !flag)
			{
				if (zdo.GetBool(OriginalPatrolKey, false))
				{
					RestorePatrolPoint(ai, zdo.GetVec3(OriginalPatrolPointKey, ((Component)ai).transform.position));
				}
				else
				{
					ai.ResetPatrolPoint();
				}
			}
			zdo.Set(StateKey, false);
		}

		private static void RestorePatrolPoint(BaseAI ai, Vector3 point)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (SetPatrolPointAtPosition != null)
			{
				SetPatrolPointAtPosition.Invoke(ai, new object[1] { point });
			}
			else
			{
				ai.SetPatrolPoint();
			}
		}
	}
	[HarmonyPatch(typeof(MonsterAI), "UpdateAI", new Type[] { typeof(float) })]
	internal static class DraumyxConfusionMonsterAIWanderPatch
	{
		[HarmonyPostfix]
		private static void Postfix(MonsterAI __instance, bool __result)
		{
			DraumyxConfusionWanderController.Update((BaseAI)(object)__instance, __result);
		}
	}
	[HarmonyPatch(typeof(AnimalAI), "UpdateAI", new Type[] { typeof(float) })]
	internal static class DraumyxConfusionAnimalAIWanderPatch
	{
		private static readonly FieldInfo TargetField = AccessTools.Field(typeof(AnimalAI), "m_target");

		private static readonly FieldInfo NearFireTimeField = AccessTools.Field(typeof(BaseAI), "m_nearFireTime");

		private static readonly FieldInfo NearFireAreaField = AccessTools.Field(typeof(BaseAI), "m_nearFireArea");

		[HarmonyPostfix]
		private static void Postfix(AnimalAI __instance, bool __result)
		{
			if (DraumyxConfusionWanderController.Update((BaseAI)(object)__instance, __result) && !IsAvoidingFire(__instance))
			{
				Character val = (Character)((TargetField == null) ? null : /*isinst with value type is only supported in some contexts*/);
				if ((Object)(object)val != (Object)null && (val.IsDead() || !((BaseAI)__instance).IsEnemy(val)))
				{
					TargetField.SetValue(__instance, null);
				}
			}
		}

		private static bool IsAvoidingFire(AnimalAI ai)
		{
			if (!((BaseAI)ai).m_afraidOfFire || NearFireTimeField == null || NearFireAreaField == null)
			{
				return false;
			}
			float num = (float)NearFireTimeField.GetValue(ai);
			object? value = NearFireAreaField.GetValue(ai);
			if ((Object)((value is EffectArea) ? value : null) != (Object)null)
			{
				return Time.time - num < 6f;
			}
			return false;
		}
	}
	internal static class DraumyxSwordVisual
	{
		private const string FrostfireAlbedoName = "nordsword_fristflame_d";

		private const string NordAlbedoName = "nordsword_d";

		private static readonly Color32 VeydrisAccentPurple = new Color32((byte)70, (byte)42, (byte)92, byte.MaxValue);

		private static readonly Color SmokeColor = new Color(0.18f, 0.68f, 0.72f, 1f);

		private static readonly Color GlowColor = new Color(0.66f, 0.44f, 0.88f, 1f);

		internal static int RecolorFrostfireBlueAccentsBlack(CustomItem item, GameObject nordPrefab)
		{
			//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_015c: 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_0168: 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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Expected O, but got Unknown
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null || (Object)(object)nordPrefab == (Object)null)
			{
				return 0;
			}
			Texture2D val = FindAlbedo(nordPrefab, "nordsword_d");
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogWarning((object)"[DeepNorthGemEnhancements] Could not find the normal Nord sword albedo for the Draumyx gray base.");
				return 0;
			}
			int num = 0;
			Renderer[] componentsInChildren = ((Component)item.ItemDrop).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				Material[] sharedMaterials = val2.sharedMaterials;
				Material[] array = null;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val3 = sharedMaterials[j];
					if ((Object)(object)val3 == (Object)null || !val3.HasProperty("_MainTex"))
					{
						continue;
					}
					Texture texture = val3.GetTexture("_MainTex");
					Texture2D val4 = (Texture2D)(object)((texture is Texture2D) ? texture : null);
					if ((Object)(object)val4 == (Object)null || !string.Equals(((Object)val4).name, "nordsword_fristflame_d", StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
					if (((Texture)val4).width != ((Texture)val).width || ((Texture)val4).height != ((Texture)val).height)
					{
						Debug.LogWarning((object)"[DeepNorthGemEnhancements] Nord and Frostfire sword albedo dimensions differ; skipped Draumyx texture recolor.");
						continue;
					}
					Color32[] frostfirePixels = ReadTexturePixels(val4);
					Color32[] array2 = ReadTexturePixels(val);
					int num2 = BlackenBlueAccentPixels(frostfirePixels, array2, ((Texture)val4).width, ((Texture)val4).height);
					if (num2 == 0)
					{
						Debug.LogWarning((object)"[DeepNorthGemEnhancements] Frostfire sword albedo was found, but no blue pixels matched the Draumyx recolor mask.");
						continue;
					}
					Texture2D val5 = new Texture2D(((Texture)val4).width, ((Texture)val4).height, (TextureFormat)4, true, false)
					{
						name = "Draumyx_NordGray_BlackAccents",
						filterMode = ((Texture)val).filterMode,
						wrapMode = ((Texture)val).wrapMode,
						anisoLevel = ((Texture)val).anisoLevel
					};
					val5.SetPixels32(array2);
					val5.Apply(true, false);
					Material val6 = new Material(val3);
					((Object)val6).name = "Draumyx_Blackened_" + ((Object)val3).name;
					val6.SetTexture("_MainTex", (Texture)(object)val5);
					if (array == null)
					{
						array = (Material[])sharedMaterials.Clone();
					}
					array[j] = val6;
					num++;
					Debug.Log((object)$"[DeepNorthGemEnhancements] Restored Nord gray albedo and blackened {num2} Frostfire accent texels on '{((Object)item.ItemDrop).name}'.");
				}
				if (array != null)
				{
					val2.materials = array;
				}
			}
			if (num == 0)
			{
				Debug.LogWarning((object)"[DeepNorthGemEnhancements] Could not find the Frostfire sword albedo material on SwordGold_Draumyx.");
			}
			return num;
		}

		internal static int RecolorVeydrisSwordAccents(CustomItem item, GameObject nordPrefab, GameObject frostfirePrefab)
		{
			//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_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Expected O, but got Unknown
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Expected O, but got Unknown
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null || (Object)(object)nordPrefab == (Object)null || (Object)(object)frostfirePrefab == (Object)null)
			{
				return 0;
			}
			Texture2D val = FindAlbedo(nordPrefab, "nordsword_d");
			Texture2D val2 = FindAlbedo(frostfirePrefab, "nordsword_fristflame_d");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || ((Texture)val).width != ((Texture)val2).width || ((Texture)val).height != ((Texture)val2).height)
			{
				Debug.LogWarning((object)"[DeepNorthGemEnhancements] Nord/Frostfire sword albedos were unavailable or had different dimensions for Veydris.");
				return 0;
			}
			Color32[] array = ReadTexturePixels(val);
			Color32[] frostfirePixels = ReadTexturePixels(val2);
			int num = 0;
			Renderer[] componentsInChildren = ((Component)item.ItemDrop).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren)
			{
				Material[] sharedMaterials = val3.sharedMaterials;
				Material[] array2 = null;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val4 = sharedMaterials[j];
					Texture2D val5 = (Texture2D)(((Object)(object)val4 == (Object)null || !val4.HasProperty("_MainTex")) ? null : /*isinst with value type is only supported in some contexts*/);
					if ((Object)(object)val5 == (Object)null || !string.Equals(((Object)val5).name, "Draumyx_NordGray_BlackAccents", StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
					Color32[] array3 = (Color32[])array.Clone();
					int num2 = TintSwordAccentPixels(frostfirePixels, array3, ((Texture)val).width, ((Texture)val).height);
					if (num2 != 0)
					{
						Texture2D val6 = new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, true, false)
						{
							name = "Veydris_NordGray_PurpleAccents",
							filterMode = ((Texture)val).filterMode,
							wrapMode = ((Texture)val).wrapMode,
							anisoLevel = ((Texture)val).anisoLevel
						};
						val6.SetPixels32(array3);
						val6.Apply(true, false);
						Material val7 = new Material(val4)
						{
							name = "Veydris_PurpleAccents_" + ((Object)val4).name
						};
						val7.SetTexture("_MainTex", (Texture)(object)val6);
						if (array2 == null)
						{
							array2 = (Material[])sharedMaterials.Clone();
						}
						array2[j] = val7;
						num++;
						Debug.Log((object)$"[DeepNorthGemEnhancements] Recolored {num2} matched Frostfire accent texels dark purple on '{((Object)item.ItemDrop).name}'.");
					}
				}
				if (array2 != null)
				{
					val3.materials = array2;
				}
			}
			return num;
		}

		private static int TintSwordAccentPixels(Color32[] frostfirePixels, Color32[] nordPixels, int width, int height)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_007d: 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_009a: 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_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)
			int num = 0;
			int num2 = Mathf.RoundToInt((float)width * 0.625f);
			for (int i = 0; i < height; i++)
			{
				for (int j = num2; j < width; j++)
				{
					int num3 = i * width + j;
					Color32 val = frostfirePixels[num3];
					Color32 val2 = nordPixels[num3];
					if (val.a != 0 && val.g - val.r >= 20 && val.b - val.r >= 30 && val2.a != 0)
					{
						float num4 = ((float)(int)val2.r * 0.299f + (float)(int)val2.g * 0.587f + (float)(int)val2.b * 0.114f) / 255f;
						float num5 = 0.72f + 0.28f * num4;
						nordPixels[num3] = new Color32((byte)((float)(int)VeydrisAccentPurple.r * num5), (byte)((float)(int)VeydrisAccentPurple.g * num5), (byte)((float)(int)VeydrisAccentPurple.b * num5), val2.a);
						num++;
					}
				}
			}
			return num;
		}

		internal static int RecolorVeydrisMaskedAccents(CustomItem item, GameObject nordPrefab, GameObject frostfirePrefab, string nordTextureName, string frostfireTextureName, string weaponLabel, int minGreenRedDifference, int minBlueRedDifference, bool requireWarmNordAccent, float accentStartFraction = 0.625f, int warmRedGreenDifference = 12, int warmRedBlueDifference = 16)
		{
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null || (Object)(object)nordPrefab == (Object)null || (Object)(object)frostfirePrefab == (Object)null)
			{
				return 0;
			}
			Texture2D val = FindAlbedo(nordPrefab, nordTextureName);
			Texture2D val2 = FindAlbedo(frostfirePrefab, frostfireTextureName);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return 0;
			}
			Color32[] nordPixels = ReadTexturePixels(val);
			Color32[] frostfirePixels = ReadTexturePixels(val2);
			string targetName = "Draumyx_Nord" + weaponLabel + "_BlackAccents";
			int num = 0;
			Renderer[] componentsInChildren = ((Component)item.ItemDrop).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer renderer in componentsInChildren)
			{
				num += RecolorVeydrisRenderer(renderer, targetName, val, nordPixels, val2, frostfirePixels, minGreenRedDifference, minBlueRedDifference, requireWarmNordAccent, accentStartFraction, warmRedGreenDifference, warmRedBlueDifference);
			}
			return num;
		}

		private static int RecolorVeydrisRenderer(Renderer renderer, string targetName, Texture2D nord, Color32[] nordPixels, Texture2D frostfire, Color32[] frostfirePixels, int minGreenRedDifference, int minBlueRedDifference, bool requireWarmNordAccent, float accentStartFraction, int warmRedGreenDifference, int warmRedBlueDifference)
		{
			Material[] sharedMaterials = renderer.sharedMaterials;
			Material[] array = null;
			for (int i = 0; i < sharedMaterials.Length; i++)
			{
				Material val = sharedMaterials[i];
				Texture2D val2 = (Texture2D)(((Object)(object)val == (Object)null || !val.HasProperty("_MainTex")) ? null : /*isinst with value type is only supported in some contexts*/);
				if ((Object)(object)val2 == (Object)null || !string.Equals(((Object)val2).name, targetName, StringComparison.OrdinalIgnoreCase))
				{
					continue;
				}
				Color32[] array2 = (Color32[])nordPixels.Clone();
				int num = TintMaskedAccents(array2, ((Texture)nord).width, ((Texture)nord).height, frostfirePixels, ((Texture)frostfire).width, ((Texture)frostfire).height, minGreenRedDifference, minBlueRedDifference, requireWarmNordAccent, accentStartFraction, warmRedGreenDifference, warmRedBlueDifference);
				if (num != 0)
				{
					Material val3 = CreateVeydrisMaterial(val, nord, array2, targetName);
					if (array == null)
					{
						array = (Material[])sharedMaterials.Clone();
					}
					array[i] = val3;
					Debug.Log((object)$"[DeepNorthGemEnhancements] Recolored {num} {targetName} accent texels dark purple.");
				}
			}
			if (array == null)
			{
				return 0;
			}
			renderer.materials = array;
			return 1;
		}

		private static Material CreateVeydrisMaterial(Material source, Texture2D nord, Color32[] pixels, string targetName)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_0031: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			Texture2D val = new Texture2D(((Texture)nord).width, ((Texture)nord).height, (TextureFormat)4, true, false)
			{
				name = "Veydris_PurpleAccents_" + targetName,
				filterMode = ((Texture)nord).filterMode,
				wrapMode = ((Texture)nord).wrapMode,
				anisoLevel = ((Texture)nord).anisoLevel
			};
			val.SetPixels32(pixels);
			val.Apply(true, false);
			Material val2 = new Material(source)
			{
				name = "Veydris_PurpleAccents_" + ((Object)source).name
			};
			val2.SetTexture("_MainTex", (Texture)(object)val);
			return val2;
		}

		private static int TintMaskedAccents(Color32[] nordPixels, int nordWidth, int nordHeight, Color32[] frostfirePixels, int frostfireWidth, int frostfireHeight, int minGreenRedDifference, int minBlueRedDifference, bool requireWarmNordAccent, float accentStartFraction, int warmRedGreenDifference, int warmRedBlueDifference)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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)
			int num = 0;
			int num2 = Mathf.RoundToInt((float)frostfireWidth * accentStartFraction);
			for (int i = 0; i < nordHeight; i++)
			{
				int num3 = Mathf.Clamp(Mathf.FloorToInt(((float)i + 0.5f) * (float)frostfireHeight / (float)nordHeight), 0, frostfireHeight - 1);
				for (int j = 0; j < nordWidth; j++)
				{
					int num4 = Mathf.Clamp(Mathf.FloorToInt(((float)j + 0.5f) * (float)frostfireWidth / (float)nordWidth), 0, frostfireWidth - 1);
					if (num4 >= num2)
					{
						int num5 = i * nordWidth + j;
						Color32 val = frostfirePixels[num3 * frostfireWidth + num4];
						Color32 val2 = nordPixels[num5];
						bool flag = val2.a > 0 && val2.r > 40 && val2.r - val2.g >= warmRedGreenDifference && val2.r - val2.b >= warmRedBlueDifference;
						if (val.a != 0 && val.g - val.r >= minGreenRedDifference && val.b - val.r >= minBlueRedDifference && (!requireWarmNordAccent || flag))
						{
							nordPixels[num5] = TintVeydrisAccent(val2);
							num++;
						}
					}
				}
			}
			return num;
		}

		private static Color32 TintVeydrisAccent(Color32 nord)
		{
			//IL_0000: 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)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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)
			float num = ((float)(int)nord.r * 0.299f + (float)(int)nord.g * 0.587f + (float)(int)nord.b * 0.114f) / 255f;
			float num2 = 0.72f + 0.28f * num;
			return new Color32((byte)((float)(int)VeydrisAccentPurple.r * num2), (byte)((float)(int)VeydrisAccentPurple.g * num2), (byte)((float)(int)VeydrisAccentPurple.b * num2), nord.a);
		}

		internal static int RecolorGreatswordBlueAccentsBlack(CustomItem item, GameObject nordPrefab, GameObject frostfirePrefab)
		{
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Expected O, but got Unknown
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null || (Object)(object)nordPrefab == (Object)null || (Object)(object)frostfirePrefab == (Object)null)
			{
				return 0;
			}
			Texture2D val = FindAlbedo(nordPrefab, "nordlongsword_d");
			Texture2D val2 = FindAlbedo(frostfirePrefab, "nordlongsword_frostflame_d");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Debug.LogWarning((object)"[DeepNorthGemEnhancements] Could not find both Nord and Frostfire Greatsword albedos for the Draumyx accent mask.");
				return 0;
			}
			Color32[] array = ReadTexturePixels(val);
			Color32[] frostfirePixels = ReadTexturePixels(val2);
			int num = 0;
			Renderer[] componentsInChildren = ((Component)item.ItemDrop).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren)
			{
				Material[] sharedMaterials = val3.sharedMaterials;
				Material[] array2 = null;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val4 = sharedMaterials[j];
					Texture2D val5 = (Texture2D)(((Object)(object)val4 == (Object)null || !val4.HasProperty("_MainTex")) ? null : /*isinst with value type is only supported in some contexts*/);
					if ((Object)(object)val5 == (Object)null || !string.Equals(((Object)val5).name, ((Object)val2).name, StringComparison.OrdinalIgnoreCase))
					{
						continue;
					}
					Color32[] array3 = (Color32[])array.Clone();
					int num2 = BlackenGreatswordBlueAccents(frostfirePixels, ((Texture)val2).width, ((Texture)val2).height, array3, ((Texture)val).width, ((Texture)val).height);
					if (num2 == 0)
					{
						Debug.LogWarning((object)"[DeepNorthGemEnhancements] No Greatsword accent texels matched the normalized Frostfire blue mask.");
						continue;
					}
					Texture2D val6 = new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, true, false)
					{
						name = "Draumyx_NordGreatsword_BlackAccents",
						filterMode = ((Texture)val).filterMode,
						wrapMode = ((Texture)val).wrapMode,
						anisoLevel = ((Texture)val).anisoLevel
					};
					val6.SetPixels32(array3);
					val6.Apply(true, false);
					Material val7 = new Material(val4)
					{
						name = "Draumyx_Blackened_" + ((Object)val4).name
					};
					val7.SetTexture("_MainTex", (Texture)(object)val6);
					if (array2 == null)
					{
						array2 = (Material[])sharedMaterials.Clone();
					}
					array2[j] = val7;
					num++;
					Debug.Log((object)$"[DeepNorthGemEnhancements] Restored Nord gray Greatsword albedo and blackened {num2} Frostfire-mask texels on '{((Object)item.ItemDrop).name}'.");
				}
				if (array2 != null)
				{
					val3.materials = array2;
				}
			}
			if (num == 0)
			{
				Debug.LogWarning((object)"[DeepNorthGemEnhancements] Could not find the Frostfire Greatsword albedo material on THSwordGold_Draumyx.");
			}
			return num;
		}

		internal static int RecolorWeaponBlueAccentsBlack(CustomItem item, GameObject nordPrefab, GameObject frostfirePrefab, string nordTextureName, string frostfireTextureName, string weaponLabel, int minGreenRedDifference = 20, int minBlueRedDifference = 30, bool requireWarmNordAccent = false, float accentStartFraction = 0.625f)
		{
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: 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_018c: 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)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Expected O, but got Unknown
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Expected O, but got Unknown
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null || (Object)(object)nordPrefab == (Object)null || (Object)(object)frostfirePrefab == (Object)null)
			{
				return 0;
			}
			Texture2D val = FindAlbedo(nordPrefab, nordTextureName);
			Texture2D val2 = FindAlbedo(frostfirePrefab, frostfireTextureName);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Debug.LogWarning((object)("[DeepNorthGemEnhancements] Nord or Frostfire " + weaponLabel + " albedo was unavailable."));
				return 0;
			}
			Color32[] array = ReadTexturePixels(val);
			int num = BlackenBlueAccentPixelsNormalized(ReadTexturePixels(val2), ((Texture)val2).width, ((Texture)val2).height, array, ((Texture)val).width, ((Texture)val).height, minGreenRedDifference, minBlueRedDifference, requireWarmNordAccent, accentStartFraction);
			if (num == 0)
			{
				Debug.LogWarning((object)("[DeepNorthGemEnhancements] No Frostfire-blue Nord " + weaponLabel + " accent texels matched the Draumyx recolor mask."));
				return 0;
			}
			int num2 = 0;
			Renderer[] componentsInChildren = ((Component)item.ItemDrop).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren)
			{
				Material[] sharedMaterials = val3.sharedMaterials;
				Material[] array2 = null;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val4 = sharedMaterials[j];
					Texture2D val5 = (Texture2D)(((Object)(object)val4 == (Object)null || !val4.HasProperty("_MainTex")) ? null : /*isinst with value type is only supported in some contexts*/);
					if (!((Object)(object)val5 == (Object)null) && (string.Equals(((Object)val5).name, ((Object)val2).name, StringComparison.OrdinalIgnoreCase) || string.Equals(((Object)val5).name, ((Object)val).name, StringComparison.OrdinalIgnoreCase)))
					{
						Texture2D val6 = new Texture2D(((Texture)val).width, ((Texture)val).height, (TextureFormat)4, true, false)
						{
							name = "Draumyx_Nord" + weaponLabel + "_BlackAccents",
							filterMode = ((Texture)val).filterMode,
							wrapMode = ((Texture)val).wrapMode,
							anisoLevel = ((Texture)val).anisoLevel
						};
						val6.SetPixels32(array);
						val6.Apply(true, false);
						Material val7 = new Material(val4)
						{
							name = "Draumyx_Blackened_" + ((Object)val4).name
						};
						val7.SetTexture("_MainTex", (Texture)(object)val6);
						if (array2 == null)
						{
							array2 = (Material[])sharedMaterials.Clone();
						}
						array2[j] = val7;
						num2++;
					}
				}
				if (array2 != null)
				{
					val3.materials = array2;
				}
			}
			Debug.Log((object)$"[DeepNorthGemEnhancements] Restored Nord gray {weaponLabel} albedo and blackened {num} Frostfire-mask texels on '{((Object)item.ItemDrop).name}'.");
			return num2;
		}

		private static int BlackenGreatswordBlueAccents(Color32[] frostfirePixels, int frostfireWidth, int frostfireHeight, Color32[] nordPixels, int nordWidth, int nordHeight)
		{
			//IL_006c: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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)
			int num = 0;
			int num2 = Mathf.RoundToInt((float)frostfireWidth * 0.625f);
			for (int i = 0; i < nordHeight; i++)
			{
				int num3 = Mathf.Clamp(Mathf.FloorToInt(((float)i + 0.5f) * (float)frostfireHeight / (float)nordHeight), 0, frostfireHeight - 1);
				for (int j = 0; j < nordWidth; j++)
				{
					int num4 = Mathf.Clamp(Mathf.FloorToInt(((float)j + 0.5f) * (float)frostfireWidth / (float)nordWidth), 0, frostfireWidth - 1);
					if (num4 >= num2)
					{
						Color32 val = frostfirePixels[num3 * frostfireWidth + num4];
						int num5 = i * nordWidth + j;
						Color32 val2 = nordPixels[num5];
						bool num6 = val.a != 0 && val.g - val.r >= 20 && val.b - val.r >= 30;
						bool flag = val2.a != 0 && val2.r > 40 && val2.r - val2.g >= 12 && val2.r - val2.b >= 16;
						if (num6 && flag)
						{
							nordPixels[num5] = new Color32((byte)0, (byte)0, (byte)0, val2.a);
							num++;
						}
					}
				}
			}
			return num;
		}

		private static Texture2D FindAlbedo(GameObject prefab, string textureName)
		{
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Material[] sharedMaterials = componentsInChildren[i].sharedMaterials;
				foreach (Material val in sharedMaterials)
				{
					if (!((Object)(object)val == (Object)null) && val.HasProperty("_MainTex"))
					{
						Texture texture = val.GetTexture("_MainTex");
						Texture2D val2 = (Texture2D)(object)((texture is Texture2D) ? texture : null);
						if ((Object)(object)val2 != (Object)null && string.Equals(((Object)val2).name, textureName, StringComparison.OrdinalIgnoreCase))
						{
							return val2;
						}
					}
				}
			}
			return null;
		}

		private static Color32[] ReadTexturePixels(Texture2D source)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (((Texture)source).isReadable)
			{
				try
				{
					return source.GetPixels32();
				}
				catch (UnityException)
				{
				}
			}
			RenderTexture temporary = RenderTexture.GetTemporary(((Texture)source).width, ((Texture)source).height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)0);
			RenderTexture active = RenderTexture.active;
			Texture2D val = null;
			try
			{
				Graphics.Blit((Texture)(object)source, temporary);
				RenderTexture.active = temporary;
				val = new Texture2D(((Texture)source).width, ((Texture)source).height, (TextureFormat)4, false, false);
				val.ReadPixels(new Rect(0f, 0f, (float)((Texture)source).width, (float)((Texture)source).height), 0, 0, false);
				val.Apply(false, false);
				return val.GetPixels32();
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
		}

		private static int BlackenBlueAccentPixels(Color32[] frostfirePixels, Color32[] nordPixels, int width, int height, int minGreenRedDifference = 20, int minBlueRedDifference = 30, bool requireWarmNordAccent = false, float accentStartFraction = 0.625f)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_004a: 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_0081: 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_005d: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			int num2 = Mathf.RoundToInt((float)width * accentStartFraction);
			for (int i = 0; i < height; i++)
			{
				for (int j = num2; j < width; j++)
				{
					int num3 = i * width + j;
					Color32 val = frostfirePixels[num3];
					Color32 val2 = nordPixels[num3];
					bool flag = val2.a != 0 && val2.r > 40 && val2.r - val2.g >= 12 && val2.r - val2.b >= 16;
					if (val.a != 0 && val.g - val.r >= minGreenRedDifference && val.b - val.r >= minBlueRedDifference && (!requireWarmNordAccent || flag))
					{
						nordPixels[num3] = new Color32((byte)0, (byte)0, (byte)0, val2.a);
						num++;
					}
				}
			}
			return num;
		}

		private static int BlackenBlueAccentPixelsNormalized(Color32[] frostfirePixels, int frostfireWidth, int frostfireHeight, Color32[] nordPixels, int nordWidth, int nordHeight, int minGreenRedDifference, int minBlueRedDifference, bool requireWarmNordAccent, float accentStartFraction)
		{
			//IL_0072: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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)
			int num = 0;
			int num2 = Mathf.RoundToInt((float)frostfireWidth * accentStartFraction);
			for (int i = 0; i < nordHeight; i++)
			{
				int num3 = Mathf.Clamp(Mathf.FloorToInt(((float)i + 0.5f) * (float)frostfireHeight / (float)nordHeight), 0, frostfireHeight - 1);
				for (int j = 0; j < nordWidth; j++)
				{
					int num4 = Mathf.Clamp(Mathf.FloorToInt(((float)j + 0.5f) * (float)frostfireWidth / (float)nordWidth), 0, frostfireWidth - 1);
					if (num4 >= num2)
					{
						int num5 = i * nordWidth + j;
						Color32 val = frostfirePixels[num3 * frostfireWidth + num4];
						Color32 val2 = nordPixels[num5];
						bool flag = val2.a != 0 && val2.r > 40 && val2.r - val2.g >= 12 && val2.r - val2.b >= 16;
						if (val.a != 0 && val.g - val.r >= minGreenRedDifference && val.b - val.r >= minBlueRedDifference && (!requireWarmNordAccent || flag))
						{
							nordPixels[num5] = new Color32((byte)0, (byte)0, (byte)0, val2.a);
							num++;
						}
					}
				}
			}
			return num;
		}

		internal static int AttachTestVisual(CustomItem item, GameObject sourcePrefab)
		{
			//IL_00bb: 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)
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null || (Object)(object)sourcePrefab == (Object)null)
			{
				return 0;
			}
			Transform val = sourcePrefab.transform.Find("attach");
			Transform val2 = ((Component)item.ItemDrop).transform.Find("attach");
			Transform val3 = (((Object)(object)val == (Object)null) ? null : val.Find("UpgraderGlow"));
			Transform val4 = (((Object)(object)val2 == (Object)null) ? null : val2.Find("default"));
			Transform val5 = sourcePrefab.transform.Find("attach/default/VFX/Clouds");
			if ((Object)(object)val3 == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null)
			{
				Debug.LogWarning((object)"[DeepNorthGemEnhancements] Draumyx sword visual source or target paths are incomplete.");
				return 0;
			}
			Transform obj = ReplaceChild(val3, val2, GlowColor);
			((Object)obj).name = "DraumyxGlow";
			((Component)obj).gameObject.SetActive(true);
			Transform orCreateChild = GetOrCreateChild(val4, "VFX");
			ReplaceChild(val5, orCreateChild, SmokeColor);
			Debug.Log((object)"[DeepNorthGemEnhancements] Added teal BloodLightning glow and Clouds to SwordGold_Draumyx only.");
			return 2;
		}

		internal static int AttachCharcoalNidhoggSwirls(CustomItem item, GameObject nidhoggBloodPrefab)
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null || (Object)(object)nidhoggBloodPrefab == (Object)null)
			{
				return 0;
			}
			Transform val = nidhoggBloodPrefab.transform.Find("attach/default/glow/Swirls");
			Transform val2 = ((Component)item.ItemDrop).transform.Find("attach/default");
			Transform val3 = (((Object)(object)val == (Object)null) ? null : val.parent.parent);
			Transform val4 = (((Object)(object)val3 == (Object)null) ? null : val3.parent);
			Transform val5 = (((Object)(object)val2 == (Object)null) ? null : val2.parent);
			if ((Object)(object)val == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val5 == (Object)null)
			{
				Debug.LogWarning((object)"[DeepNorthGemEnhancements] Could not find the Nidhogg Swirls source or Draumyx sword default attachment.");
				return 0;
			}
			Transform val6 = val2.Find("DraumyxSwirlsAnchor");
			if ((Object)(object)val6 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)val6).gameObject);
			}
			GameObject val7 = new GameObject("DraumyxSwirlsAnchor");
			val7.transform.SetParent(val2, false);
			CopySourceAnchorIntoTargetFrame(val4, val3, val.parent, val5, val2, val7.transform);
			GameObject val8 = Object.Instantiate<GameObject>(((Component)val).gameObject, val7.transform, false);
			CopyTransform(val, val8.transform);
			((Object)val8).name = "Swirls";
			TintNidhoggSwirls(val8, Color.black);
			ParticleSystem[] componentsInChildren = val8.GetComponentsInChildren<ParticleSystem>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].Play(true);
			}
			Debug.Log((object)"[DeepNorthGemEnhancements] Added charcoal Nidhogg Swirls to SwordGold_Draumyx; omitted the glow mesh and blood drip.");
			return 1;
		}

		internal static int AttachCharcoalAxeBloodSwirls(CustomItem item, GameObject vaBloodAxePrefab)
		{
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((item != null) ? item.ItemDrop : null) == (Object)null || (Object)(object)vaBloodAxePrefab == (Object)null)
			{
				return 0;
			}
			Transform val = vaBloodAxePrefab.transform.Find("attach");
			Transform val2 = (((Object)(object)val == (Object)null) ? null : val.Find("Elemental_effect_area"));
			Transform val3 = ((Component)item.ItemDrop).transform.Find("attach");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
			{
				Debug.LogWarning((object)"[DeepNorthGemEnhancements