Decompiled source of Creaturesoforigins v1.1.0

Creaturesoforigins.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CreatureManager;
using HarmonyLib;
using ItemManager;
using JetBrains.Annotations;
using LocalizationManager;
using MagicaCloth2;
using Microsoft.CodeAnalysis;
using PieceManager;
using ServerSync;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.ObjectPool;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Callbacks;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Creaturesoforigins")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Azathoth")]
[assembly: AssemblyProduct("Creaturesoforigins")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("29D394C1-8423-4048-B5A7-08ABE81DBA99")]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace PieceManager
{
	[PublicAPI]
	public static class MaterialReplacer
	{
		public enum ShaderType
		{
			PieceShader,
			VegetationShader,
			RockShader,
			RugShader,
			GrassShader,
			CustomCreature,
			UseUnityShader,
			ToonDeferred
		}

		private static readonly Dictionary<GameObject, bool> ObjectToSwap;

		private static readonly Dictionary<string, Material> OriginalMaterials;

		private static readonly Dictionary<GameObject, ShaderType> ObjectsForShaderReplace;

		private static readonly HashSet<GameObject> ArmoredHumanoidShaderObjects;

		private static readonly HashSet<GameObject> FurCreatureShaderObjects;

		private static readonly HashSet<GameObject> SkeletonHammerShaderObjects;

		private static readonly HashSet<GameObject> ExternalAlphaCreatureShaderObjects;

		private static readonly Dictionary<string, Texture2D> ExternalAlphaBakedTextureCache;

		private static readonly HashSet<GameObject> DoubleSidedUseUnityShaderObjects;

		private static readonly HashSet<GameObject> StarwarsCharacterMaterialFixObjects;

		private static readonly HashSet<GameObject> WookieeRendererSplitFixObjects;

		private static readonly Dictionary<Mesh, Mesh> BackfaceMeshCache;

		private static readonly HashSet<Mesh> BackfaceMeshWarnings;

		private static readonly Dictionary<GameObject, Color> LightsaberBladeObjects;

		private static readonly Dictionary<GameObject, Color> EmbeddedLightsaberBladeObjects;

		private static readonly Dictionary<GameObject, Color> EmissiveVfxObjects;

		private static readonly HashSet<Shader> CachedShaders;

		private static bool hasRun;

		static MaterialReplacer()
		{
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			ArmoredHumanoidShaderObjects = new HashSet<GameObject>();
			FurCreatureShaderObjects = new HashSet<GameObject>();
			SkeletonHammerShaderObjects = new HashSet<GameObject>();
			ExternalAlphaCreatureShaderObjects = new HashSet<GameObject>();
			ExternalAlphaBakedTextureCache = new Dictionary<string, Texture2D>();
			DoubleSidedUseUnityShaderObjects = new HashSet<GameObject>();
			StarwarsCharacterMaterialFixObjects = new HashSet<GameObject>();
			WookieeRendererSplitFixObjects = new HashSet<GameObject>();
			BackfaceMeshCache = new Dictionary<Mesh, Mesh>();
			BackfaceMeshWarnings = new HashSet<Mesh>();
			LightsaberBladeObjects = new Dictionary<GameObject, Color>();
			EmbeddedLightsaberBladeObjects = new Dictionary<GameObject, Color>();
			EmissiveVfxObjects = new Dictionary<GameObject, Color>();
			CachedShaders = new HashSet<Shader>();
			hasRun = false;
			OriginalMaterials = new Dictionary<string, Material>();
			ObjectToSwap = new Dictionary<GameObject, bool>();
			ObjectsForShaderReplace = new Dictionary<GameObject, ShaderType>();
			Harmony val = new Harmony("org.bepinex.helpers.PieceManager");
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ZoneSystem), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(MaterialReplacer), "ReplaceAllMaterialsWithOriginal", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		public static void RegisterGameObjectForShaderSwap(GameObject go, ShaderType type)
		{
			if (!((Object)(object)go == (Object)null))
			{
				if (!ObjectsForShaderReplace.ContainsKey(go))
				{
					ObjectsForShaderReplace.Add(go, type);
				}
				else
				{
					ObjectsForShaderReplace[go] = type;
				}
			}
		}

		public static void RegisterArmoredHumanoidForShaderSwap(GameObject go)
		{
			if (!((Object)(object)go == (Object)null))
			{
				FurCreatureShaderObjects.Remove(go);
				if (!ArmoredHumanoidShaderObjects.Contains(go))
				{
					ArmoredHumanoidShaderObjects.Add(go);
				}
				if (!ObjectsForShaderReplace.ContainsKey(go))
				{
					ObjectsForShaderReplace.Add(go, ShaderType.ToonDeferred);
				}
				else
				{
					ObjectsForShaderReplace[go] = ShaderType.ToonDeferred;
				}
			}
		}

		public static void RegisterFurCreatureForShaderSwap(GameObject go)
		{
			if (!((Object)(object)go == (Object)null))
			{
				ArmoredHumanoidShaderObjects.Remove(go);
				if (!FurCreatureShaderObjects.Contains(go))
				{
					FurCreatureShaderObjects.Add(go);
				}
				if (!ObjectsForShaderReplace.ContainsKey(go))
				{
					ObjectsForShaderReplace.Add(go, ShaderType.CustomCreature);
				}
				else
				{
					ObjectsForShaderReplace[go] = ShaderType.CustomCreature;
				}
			}
		}

		public static void RegisterExternalAlphaCreatureForShaderSwap(GameObject go)
		{
			if (!((Object)(object)go == (Object)null))
			{
				ArmoredHumanoidShaderObjects.Remove(go);
				FurCreatureShaderObjects.Remove(go);
				SkeletonHammerShaderObjects.Remove(go);
				DoubleSidedUseUnityShaderObjects.Remove(go);
				StarwarsCharacterMaterialFixObjects.Remove(go);
				WookieeRendererSplitFixObjects.Remove(go);
				ExternalAlphaCreatureShaderObjects.Add(go);
				ObjectsForShaderReplace[go] = ShaderType.CustomCreature;
			}
		}

		public static void RegisterSkeletonHammerForShaderSwap(GameObject go)
		{
			if (!((Object)(object)go == (Object)null))
			{
				ArmoredHumanoidShaderObjects.Remove(go);
				FurCreatureShaderObjects.Remove(go);
				if (!SkeletonHammerShaderObjects.Contains(go))
				{
					SkeletonHammerShaderObjects.Add(go);
				}
				if (!ObjectsForShaderReplace.ContainsKey(go))
				{
					ObjectsForShaderReplace.Add(go, ShaderType.CustomCreature);
				}
				else
				{
					ObjectsForShaderReplace[go] = ShaderType.CustomCreature;
				}
			}
		}

		public static void RegisterDoubleSidedUseUnityShader(GameObject go)
		{
			if (!((Object)(object)go == (Object)null))
			{
				ArmoredHumanoidShaderObjects.Remove(go);
				FurCreatureShaderObjects.Remove(go);
				SkeletonHammerShaderObjects.Remove(go);
				StarwarsCharacterMaterialFixObjects.Remove(go);
				if (!DoubleSidedUseUnityShaderObjects.Contains(go))
				{
					DoubleSidedUseUnityShaderObjects.Add(go);
				}
				if (!ObjectsForShaderReplace.ContainsKey(go))
				{
					ObjectsForShaderReplace.Add(go, ShaderType.UseUnityShader);
				}
				else
				{
					ObjectsForShaderReplace[go] = ShaderType.UseUnityShader;
				}
			}
		}

		public static void RegisterWookieeFurFix(GameObject go)
		{
			if (!((Object)(object)go == (Object)null))
			{
				ArmoredHumanoidShaderObjects.Remove(go);
				FurCreatureShaderObjects.Remove(go);
				SkeletonHammerShaderObjects.Remove(go);
				DoubleSidedUseUnityShaderObjects.Remove(go);
				StarwarsCharacterMaterialFixObjects.Remove(go);
				if (!WookieeRendererSplitFixObjects.Contains(go))
				{
					WookieeRendererSplitFixObjects.Add(go);
				}
				if (!ObjectsForShaderReplace.ContainsKey(go))
				{
					ObjectsForShaderReplace.Add(go, ShaderType.UseUnityShader);
				}
				else
				{
					ObjectsForShaderReplace[go] = ShaderType.UseUnityShader;
				}
			}
		}

		public static void RegisterStarwarsCharacterMaterialFix(GameObject go)
		{
			if (!((Object)(object)go == (Object)null))
			{
				ArmoredHumanoidShaderObjects.Remove(go);
				FurCreatureShaderObjects.Remove(go);
				SkeletonHammerShaderObjects.Remove(go);
				DoubleSidedUseUnityShaderObjects.Remove(go);
				if (!StarwarsCharacterMaterialFixObjects.Contains(go))
				{
					StarwarsCharacterMaterialFixObjects.Add(go);
				}
				if (!ObjectsForShaderReplace.ContainsKey(go))
				{
					ObjectsForShaderReplace.Add(go, ShaderType.CustomCreature);
				}
				else
				{
					ObjectsForShaderReplace[go] = ShaderType.CustomCreature;
				}
			}
		}

		public static void RegisterLightsaberBlade(GameObject go, Color bladeColor)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)go == (Object)null))
			{
				ArmoredHumanoidShaderObjects.Remove(go);
				FurCreatureShaderObjects.Remove(go);
				SkeletonHammerShaderObjects.Remove(go);
				DoubleSidedUseUnityShaderObjects.Remove(go);
				StarwarsCharacterMaterialFixObjects.Remove(go);
				WookieeRendererSplitFixObjects.Remove(go);
				ObjectsForShaderReplace.Remove(go);
				LightsaberBladeObjects[go] = bladeColor;
			}
		}

		public static void RegisterEmbeddedLightsaberBlade(GameObject go, Color bladeColor)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)go == (Object)null))
			{
				EmbeddedLightsaberBladeObjects[go] = bladeColor;
			}
		}

		public static void RegisterEmissiveVfx(GameObject go, Color vfxColor)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)go == (Object)null))
			{
				ArmoredHumanoidShaderObjects.Remove(go);
				FurCreatureShaderObjects.Remove(go);
				SkeletonHammerShaderObjects.Remove(go);
				DoubleSidedUseUnityShaderObjects.Remove(go);
				StarwarsCharacterMaterialFixObjects.Remove(go);
				WookieeRendererSplitFixObjects.Remove(go);
				ObjectsForShaderReplace.Remove(go);
				EmissiveVfxObjects[go] = vfxColor;
			}
		}

		public static void RegisterGameObjectForMatSwap(GameObject go, bool isJotunnMock = false)
		{
			if (!((Object)(object)go == (Object)null) && !ObjectToSwap.ContainsKey(go))
			{
				ObjectToSwap.Add(go, isJotunnMock);
			}
		}

		private static void GetAllMaterials()
		{
			Material[] array = Resources.FindObjectsOfTypeAll<Material>();
			foreach (Material val in array)
			{
				OriginalMaterials[((Object)val).name] = val;
			}
		}

		[HarmonyPriority(700)]
		private static void ReplaceAllMaterialsWithOriginal()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			if ((int)SystemInfo.graphicsDeviceType == 4 || hasRun)
			{
				return;
			}
			if (OriginalMaterials.Count == 0)
			{
				GetAllMaterials();
			}
			foreach (KeyValuePair<GameObject, bool> item in ObjectToSwap)
			{
				GameObject key = item.Key;
				bool value = item.Value;
				ProcessGameObjectMaterials(key, value);
			}
			AssetBundle[] array = Resources.FindObjectsOfTypeAll<AssetBundle>();
			AssetBundle[] array2 = array;
			foreach (AssetBundle val in array2)
			{
				IEnumerable<Shader> enumerable3;
				try
				{
					IEnumerable<Shader> enumerable2;
					if (!val.isStreamedSceneAssetBundle || !Object.op_Implicit((Object)(object)val))
					{
						IEnumerable<Shader> enumerable = val.LoadAllAssets<Shader>();
						enumerable2 = enumerable;
					}
					else
					{
						enumerable2 = from shader in ((IEnumerable<string>)val.GetAllAssetNames()).Select((Func<string, Shader>)val.LoadAsset<Shader>)
							where (Object)(object)shader != (Object)null
							select shader;
					}
					enumerable3 = enumerable2;
				}
				catch (Exception)
				{
					continue;
				}
				if (enumerable3 == null)
				{
					continue;
				}
				foreach (Shader item2 in enumerable3)
				{
					CachedShaders.Add(item2);
				}
			}
			foreach (KeyValuePair<GameObject, ShaderType> item3 in ObjectsForShaderReplace)
			{
				GameObject key2 = item3.Key;
				ShaderType value2 = item3.Value;
				ProcessGameObjectShaders(key2, value2);
			}
			foreach (KeyValuePair<GameObject, Color> lightsaberBladeObject in LightsaberBladeObjects)
			{
				ProcessLightsaberBladeMaterials(lightsaberBladeObject.Key, lightsaberBladeObject.Value);
			}
			foreach (KeyValuePair<GameObject, Color> embeddedLightsaberBladeObject in EmbeddedLightsaberBladeObjects)
			{
				ProcessLightsaberBladeMaterials(embeddedLightsaberBladeObject.Key, embeddedLightsaberBladeObject.Value, includeCylinderRenderers: true);
			}
			foreach (KeyValuePair<GameObject, Color> emissiveVfxObject in EmissiveVfxObjects)
			{
				ProcessEmissiveVfxMaterials(emissiveVfxObject.Key, emissiveVfxObject.Value);
			}
			hasRun = true;
		}

		private static void ProcessGameObjectMaterials(GameObject go, bool isJotunnMock)
		{
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				Material[] sharedMaterials = val.sharedMaterials.Select((Material material) => ((Object)(object)material == (Object)null) ? null : ReplaceMaterial(material, isJotunnMock)).ToArray();
				val.sharedMaterials = sharedMaterials;
			}
		}

		private static Material ReplaceMaterial(Material originalMaterial, bool isJotunnMock)
		{
			if ((Object)(object)originalMaterial == (Object)null)
			{
				return null;
			}
			string text = (isJotunnMock ? "JVLmock_" : "_REPLACE_");
			if (!((Object)originalMaterial).name.StartsWith(text, StringComparison.Ordinal))
			{
				return originalMaterial;
			}
			string text2 = ((Object)originalMaterial).name.Replace(" (Instance)", "").Replace(text, "");
			if (OriginalMaterials.TryGetValue(text2, out Material value))
			{
				return value;
			}
			Debug.LogWarning((object)("No suitable material found to replace: " + text2));
			return originalMaterial;
		}

		private static void ProcessGameObjectShaders(GameObject go, ShaderType shaderType)
		{
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			if (ExternalAlphaCreatureShaderObjects.Contains(go))
			{
				ProcessExternalAlphaCreatureShaders(go);
				return;
			}
			if (DoubleSidedUseUnityShaderObjects.Contains(go))
			{
				ProcessDoubleSidedUseUnityShader(go);
				return;
			}
			if (StarwarsCharacterMaterialFixObjects.Contains(go))
			{
				ProcessStarwarsCharacterMaterialShaders(go);
				return;
			}
			if (WookieeRendererSplitFixObjects.Contains(go))
			{
				ProcessWookieeRendererSplitFix(go);
				return;
			}
			if (SkeletonHammerShaderObjects.Contains(go))
			{
				ProcessSkeletonHammerShaders(go);
				return;
			}
			if (ArmoredHumanoidShaderObjects.Contains(go))
			{
				ProcessArmoredHumanoidShaders(go);
				return;
			}
			if (FurCreatureShaderObjects.Contains(go))
			{
				ProcessFurCreatureShaders(go);
				return;
			}
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				foreach (Material val2 in sharedMaterials)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						val2.shader = GetShaderForType(val2.shader, shaderType, ((Object)val2.shader).name);
					}
				}
			}
		}

		private static bool ShouldSkipRenderer(Renderer renderer)
		{
			if ((Object)(object)renderer == (Object)null)
			{
				return true;
			}
			string text = ((Object)renderer).name.ToLowerInvariant();
			return text.Contains("eyepos") || text.Contains("collider") || text.Contains("hitbox") || text.Contains("ragdoll") || text.Contains("trigger") || text.Contains("starwarsbackface");
		}

		private static void ProcessDoubleSidedUseUnityShader(GameObject go)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (ShouldSkipRenderer(val))
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null))
					{
						Material val3 = new Material(val2)
						{
							name = ((Object)val2).name + "_StarwarsUnityDoubleSided"
						};
						val3.shader = GetShaderForType(val3.shader, ShaderType.UseUnityShader, ((Object)val3.shader).name);
						ApplyDoubleSidedCreatureSettings(val3);
						PreserveTransparency(val3);
						sharedMaterials[j] = val3;
						flag = true;
					}
				}
				if (flag)
				{
					val.sharedMaterials = sharedMaterials;
				}
			}
			EnsureBackfaceRenderers(go);
		}

		private static void ProcessStarwarsCharacterMaterialShaders(GameObject go)
		{
			//IL_0073: 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_0092: Expected O, but got Unknown
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (ShouldSkipRenderer(val))
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null))
					{
						Material val3 = new Material(val2)
						{
							name = ((Object)val2).name + "_StarwarsCharacterCreature"
						};
						ApplyStarwarsCharacterMaterial(val3);
						sharedMaterials[j] = val3;
						flag = true;
					}
				}
				if (flag)
				{
					val.sharedMaterials = sharedMaterials;
				}
			}
			EnsureBackfaceRenderers(go);
		}

		private static void ApplyStarwarsCharacterMaterial(Material material)
		{
			//IL_004c: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: 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)
			Texture firstTextureOrDefault = GetFirstTextureOrDefault(material, "_MainTex", "_BaseMap", "_BaseColorMap");
			Texture firstTextureOrDefault2 = GetFirstTextureOrDefault(material, "_BumpMap", "_NormalMap", "_NormalTex");
			Color val = GetFirstColorOrDefault(material, Color.white, "_Color", "_BaseColor", "_MainColor");
			float floatOrDefault = GetFloatOrDefault(material, "_Metallic", 0f);
			float floatOrDefault2 = GetFloatOrDefault(material, "_Glossiness", 0.32f);
			float floatOrDefault3 = GetFloatOrDefault(material, "_Smoothness", floatOrDefault2);
			float floatOrDefault4 = GetFloatOrDefault(material, "_Cutoff", 0.5f);
			material.shader = FindShaderWithName(material.shader, "Custom/Creature");
			ApplyDoubleSidedCreatureSettings(material);
			if (LooksLikeUnityMissingShaderTint(val))
			{
				val = Color.white;
			}
			SetTextureIfExists(material, "_MainTex", firstTextureOrDefault);
			SetTextureIfExists(material, "_BaseMap", firstTextureOrDefault);
			if ((Object)(object)firstTextureOrDefault2 != (Object)null)
			{
				SetTextureIfExists(material, "_BumpMap", firstTextureOrDefault2);
				SetTextureIfExists(material, "_NormalMap", firstTextureOrDefault2);
				SetTextureIfExists(material, "_NormalTex", firstTextureOrDefault2);
				material.EnableKeyword("_NORMALMAP");
			}
			float floatOrDefault5 = GetFloatOrDefault(material, "_BumpScale", 1f);
			float value = Mathf.Clamp(floatOrDefault5, 0.15f, 0.35f);
			SetFloatIfExists(material, "_BumpScale", value);
			SetColorIfExists(material, "_Color", val);
			SetColorIfExists(material, "_BaseColor", val);
			SetColorIfExists(material, "_MainColor", val);
			SetFloatIfExists(material, "_Metallic", floatOrDefault);
			SetFloatIfExists(material, "_Glossiness", floatOrDefault2);
			SetFloatIfExists(material, "_Smoothness", floatOrDefault3);
			SetFloatIfExists(material, "_Cutoff", floatOrDefault4);
		}

		private static void PreserveTransparency(Material material)
		{
			if (!((Object)(object)material == (Object)null))
			{
				float floatOrDefault = GetFloatOrDefault(material, "_Cutoff", 0.5f);
				SetFloatIfExists(material, "_Cutoff", floatOrDefault);
				if (material.HasProperty("_Mode"))
				{
					SetFloatIfExists(material, "_Mode", material.GetFloat("_Mode"));
				}
				if (material.HasProperty("_SrcBlend") && material.HasProperty("_DstBlend"))
				{
					SetFloatIfExists(material, "_SrcBlend", material.GetFloat("_SrcBlend"));
					SetFloatIfExists(material, "_DstBlend", material.GetFloat("_DstBlend"));
				}
			}
		}

		private static void EnsureBackfaceRenderers(GameObject go)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Expected O, but got Unknown
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			SkinnedMeshRenderer[] componentsInChildren = go.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.sharedMesh == (Object)null) && !ShouldSkipRenderer((Renderer)(object)val) && !((Object)(object)((Component)val).transform.Find("StarwarsBackfaceRenderer") != (Object)null))
				{
					Mesh backfaceMesh = GetBackfaceMesh(val.sharedMesh);
					if (!((Object)(object)backfaceMesh == (Object)null))
					{
						GameObject val2 = new GameObject("StarwarsBackfaceRenderer");
						val2.transform.SetParent(((Component)val).transform, false);
						SkinnedMeshRenderer val3 = val2.AddComponent<SkinnedMeshRenderer>();
						val3.sharedMesh = backfaceMesh;
						((Renderer)val3).sharedMaterials = CreateBackfaceSafeMaterials(((Renderer)val).sharedMaterials);
						val3.rootBone = val.rootBone;
						val3.bones = val.bones;
						((Renderer)val3).localBounds = ((Renderer)val).localBounds;
						val3.updateWhenOffscreen = val.updateWhenOffscreen;
						val3.quality = val.quality;
						((Renderer)val3).shadowCastingMode = ((Renderer)val).shadowCastingMode;
						((Renderer)val3).receiveShadows = ((Renderer)val).receiveShadows;
					}
				}
			}
			MeshRenderer[] componentsInChildren2 = go.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val4 in componentsInChildren2)
			{
				if ((Object)(object)val4 == (Object)null || ShouldSkipRenderer((Renderer)(object)val4) || (Object)(object)((Component)val4).transform.Find("StarwarsBackfaceRenderer") != (Object)null)
				{
					continue;
				}
				MeshFilter component = ((Component)val4).GetComponent<MeshFilter>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
				{
					Mesh backfaceMesh2 = GetBackfaceMesh(component.sharedMesh);
					if (!((Object)(object)backfaceMesh2 == (Object)null))
					{
						GameObject val5 = new GameObject("StarwarsBackfaceRenderer");
						val5.transform.SetParent(((Component)val4).transform, false);
						MeshFilter val6 = val5.AddComponent<MeshFilter>();
						val6.sharedMesh = backfaceMesh2;
						MeshRenderer val7 = val5.AddComponent<MeshRenderer>();
						((Renderer)val7).sharedMaterials = CreateBackfaceSafeMaterials(((Renderer)val4).sharedMaterials);
						((Renderer)val7).shadowCastingMode = ((Renderer)val4).shadowCastingMode;
						((Renderer)val7).receiveShadows = ((Renderer)val4).receiveShadows;
					}
				}
			}
		}

		private static Material[] CreateBackfaceSafeMaterials(Material[] sourceMaterials)
		{
			//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_0063: Expected O, but got Unknown
			if (sourceMaterials == null)
			{
				return Array.Empty<Material>();
			}
			Material[] array = (Material[])(object)new Material[sourceMaterials.Length];
			for (int i = 0; i < sourceMaterials.Length; i++)
			{
				Material val = sourceMaterials[i];
				if ((Object)(object)val == (Object)null)
				{
					array[i] = null;
					continue;
				}
				Material val2 = new Material(val)
				{
					name = ((Object)val).name + "_StarwarsBackfaceSafe"
				};
				SetFloatIfExists(val2, "_BumpScale", 0f);
				if (val2.HasProperty("_BumpMap"))
				{
					val2.SetTexture("_BumpMap", (Texture)null);
				}
				if (val2.HasProperty("_NormalMap"))
				{
					val2.SetTexture("_NormalMap", (Texture)null);
				}
				if (val2.HasProperty("_NormalTex"))
				{
					val2.SetTexture("_NormalTex", (Texture)null);
				}
				val2.DisableKeyword("_NORMALMAP");
				ApplyDoubleSidedCreatureSettings(val2);
				PreserveTransparency(val2);
				array[i] = val2;
			}
			return array;
		}

		private static Mesh GetBackfaceMesh(Mesh originalMesh)
		{
			if ((Object)(object)originalMesh == (Object)null)
			{
				return null;
			}
			if (BackfaceMeshCache.TryGetValue(originalMesh, out Mesh value))
			{
				return value;
			}
			if (!originalMesh.isReadable)
			{
				if (BackfaceMeshWarnings.Add(originalMesh))
				{
					Debug.LogWarning((object)("[Starwars Backface] La malla '" + ((Object)originalMesh).name + "' no tiene Read/Write Enabled. Se omitirá su copia de caras internas. Activa Read/Write Enabled en el FBX y reconstruye el AssetBundle."));
				}
				return null;
			}
			Mesh val = null;
			try
			{
				val = Object.Instantiate<Mesh>(originalMesh);
				((Object)val).name = ((Object)originalMesh).name + "_StarwarsBackface";
				for (int i = 0; i < val.subMeshCount; i++)
				{
					int[] triangles = val.GetTriangles(i);
					for (int j = 0; j + 2 < triangles.Length; j += 3)
					{
						int num = triangles[j];
						triangles[j] = triangles[j + 1];
						triangles[j + 1] = num;
					}
					val.SetTriangles(triangles, i, false);
				}
				val.RecalculateBounds();
				BackfaceMeshCache[originalMesh] = val;
				return val;
			}
			catch (Exception ex)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				if (BackfaceMeshWarnings.Add(originalMesh))
				{
					Debug.LogWarning((object)("[Starwars Backface] No se pudo generar la malla interna para '" + ((Object)originalMesh).name + "': " + ex.Message));
				}
				return null;
			}
		}

		private static void ProcessWookieeRendererSplitFix(GameObject go)
		{
			//IL_0073: 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_0092: Expected O, but got Unknown
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (ShouldSkipRenderer(val))
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null))
					{
						Material val3 = new Material(val2)
						{
							name = ((Object)val2).name + "_StarwarsWookieeSplit"
						};
						if (IsWookieeHairRenderer(val))
						{
							ApplyWookieeHairCutout(val3);
						}
						else
						{
							ApplyWookieeSolidOpaque(val3);
						}
						sharedMaterials[j] = val3;
						flag = true;
					}
				}
				if (flag)
				{
					val.sharedMaterials = sharedMaterials;
				}
			}
			EnsureWookieeSolidCoreRenderers(go);
		}

		private static void EnsureWookieeSolidCoreRenderers(GameObject go)
		{
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_0110: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			SkinnedMeshRenderer[] componentsInChildren = go.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.sharedMesh == (Object)null) && !ShouldSkipRenderer((Renderer)(object)val) && !IsWookieeHairRenderer((Renderer)(object)val) && !((Object)(object)((Component)val).transform.Find("StarwarsWookieeSolidCoreRenderer") != (Object)null))
				{
					string text = ((Object)val).name.ToLowerInvariant();
					if (text.Contains("head") || text.Contains("body") || text.Contains("cuerpo") || text.Contains("cabeza") || text.Contains("m_head"))
					{
						GameObject val2 = new GameObject("StarwarsWookieeSolidCoreRenderer");
						val2.transform.SetParent(((Component)val).transform, false);
						val2.transform.localPosition = Vector3.zero;
						val2.transform.localRotation = Quaternion.identity;
						val2.transform.localScale = Vector3.one * 0.992f;
						SkinnedMeshRenderer val3 = val2.AddComponent<SkinnedMeshRenderer>();
						val3.sharedMesh = val.sharedMesh;
						val3.rootBone = val.rootBone;
						val3.bones = val.bones;
						((Renderer)val3).localBounds = ((Renderer)val).localBounds;
						val3.updateWhenOffscreen = val.updateWhenOffscreen;
						val3.quality = val.quality;
						((Renderer)val3).shadowCastingMode = ((Renderer)val).shadowCastingMode;
						((Renderer)val3).receiveShadows = ((Renderer)val).receiveShadows;
						((Renderer)val3).sharedMaterials = CreateWookieeSolidCoreMaterials(((Renderer)val).sharedMaterials);
					}
				}
			}
		}

		private static Material[] CreateWookieeSolidCoreMaterials(Material[] sourceMaterials)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			if (sourceMaterials == null)
			{
				return Array.Empty<Material>();
			}
			Material[] array = (Material[])(object)new Material[sourceMaterials.Length];
			for (int i = 0; i < sourceMaterials.Length; i++)
			{
				Material val = sourceMaterials[i];
				if ((Object)(object)val == (Object)null)
				{
					array[i] = null;
					continue;
				}
				Material val2 = new Material(val)
				{
					name = ((Object)val).name + "_StarwarsWookieeSolidCore"
				};
				ApplyWookieeSolidOpaque(val2);
				val2.renderQueue = 1990;
				array[i] = val2;
			}
			return array;
		}

		private static bool IsWookieeHairRenderer(Renderer renderer)
		{
			if ((Object)(object)renderer == (Object)null)
			{
				return false;
			}
			string text = ((Object)renderer).name.ToLowerInvariant();
			return text.Contains("haircard") || text.Contains("haircards") || text.Contains("hair_card") || text.Contains("hair cards");
		}

		private static void ApplyWookieeHairCutout(Material material)
		{
			//IL_006d: 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_0095: 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_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)material == (Object)null) && !((Object)(object)material.shader == (Object)null))
			{
				Texture firstTextureOrDefault = GetFirstTextureOrDefault(material, "_MainTex", "_BaseMap", "_BaseColorMap");
				Texture firstTextureOrDefault2 = GetFirstTextureOrDefault(material, "_BumpMap", "_NormalMap", "_NormalTex");
				Color firstColorOrDefault = GetFirstColorOrDefault(material, Color.white, "_Color", "_BaseColor", "_MainColor");
				material.shader = GetShaderForType(material.shader, ShaderType.UseUnityShader, ((Object)material.shader).name);
				SetTextureIfExists(material, "_MainTex", firstTextureOrDefault);
				SetTextureIfExists(material, "_BaseMap", firstTextureOrDefault);
				if ((Object)(object)firstTextureOrDefault2 != (Object)null)
				{
					SetTextureIfExists(material, "_BumpMap", firstTextureOrDefault2);
					SetTextureIfExists(material, "_NormalMap", firstTextureOrDefault2);
					SetTextureIfExists(material, "_NormalTex", firstTextureOrDefault2);
					material.EnableKeyword("_NORMALMAP");
				}
				firstColorOrDefault.a = 1f;
				SetColorIfExists(material, "_Color", firstColorOrDefault);
				SetColorIfExists(material, "_BaseColor", firstColorOrDefault);
				SetColorIfExists(material, "_MainColor", firstColorOrDefault);
				SetFloatIfExists(material, "_Mode", 1f);
				SetFloatIfExists(material, "_Surface", 0f);
				SetFloatIfExists(material, "_AlphaClip", 1f);
				SetFloatIfExists(material, "_Cutoff", Mathf.Clamp(GetFloatOrDefault(material, "_Cutoff", 0.5f), 0.35f, 0.6f));
				SetFloatIfExists(material, "_SrcBlend", 1f);
				SetFloatIfExists(material, "_DstBlend", 0f);
				SetFloatIfExists(material, "_ZWrite", 1f);
				SetFloatIfExists(material, "_Cull", 0f);
				SetFloatIfExists(material, "_CullMode", 0f);
				material.SetOverrideTag("RenderType", "TransparentCutout");
				material.EnableKeyword("_ALPHATEST_ON");
				material.DisableKeyword("_ALPHABLEND_ON");
				material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
				material.doubleSidedGI = true;
				material.renderQueue = 2450;
			}
		}

		private static void ApplyWookieeSolidOpaque(Material material)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)material == (Object)null) && !((Object)(object)material.shader == (Object)null))
			{
				Texture firstTextureOrDefault = GetFirstTextureOrDefault(material, "_MainTex", "_BaseMap", "_BaseColorMap");
				Texture firstTextureOrDefault2 = GetFirstTextureOrDefault(material, "_BumpMap", "_NormalMap", "_NormalTex");
				Color val = GetFirstColorOrDefault(material, Color.white, "_Color", "_BaseColor", "_MainColor");
				float floatOrDefault = GetFloatOrDefault(material, "_Metallic", 0f);
				float floatOrDefault2 = GetFloatOrDefault(material, "_Glossiness", 0.25f);
				float floatOrDefault3 = GetFloatOrDefault(material, "_Smoothness", floatOrDefault2);
				material.shader = GetShaderForType(material.shader, ShaderType.UseUnityShader, ((Object)material.shader).name);
				if (LooksLikeUnityMissingShaderTint(val))
				{
					val = Color.white;
				}
				val.a = 1f;
				SetTextureIfExists(material, "_MainTex", firstTextureOrDefault);
				SetTextureIfExists(material, "_BaseMap", firstTextureOrDefault);
				if ((Object)(object)firstTextureOrDefault2 != (Object)null)
				{
					SetTextureIfExists(material, "_BumpMap", firstTextureOrDefault2);
					SetTextureIfExists(material, "_NormalMap", firstTextureOrDefault2);
					SetTextureIfExists(material, "_NormalTex", firstTextureOrDefault2);
					material.EnableKeyword("_NORMALMAP");
				}
				SetColorIfExists(material, "_Color", val);
				SetColorIfExists(material, "_BaseColor", val);
				SetColorIfExists(material, "_MainColor", val);
				SetFloatIfExists(material, "_Metallic", floatOrDefault);
				SetFloatIfExists(material, "_Glossiness", floatOrDefault2);
				SetFloatIfExists(material, "_Smoothness", floatOrDefault3);
				ForceMaterialOpaqueHard(material);
				SetFloatIfExists(material, "_Cull", 0f);
				SetFloatIfExists(material, "_CullMode", 0f);
				material.doubleSidedGI = true;
			}
		}

		private static void ForceMaterialOpaqueHard(Material material)
		{
			if (!((Object)(object)material == (Object)null))
			{
				material.SetOverrideTag("RenderType", "Opaque");
				SetFloatIfExists(material, "_Mode", 0f);
				SetFloatIfExists(material, "_Surface", 0f);
				SetFloatIfExists(material, "_Blend", 0f);
				SetFloatIfExists(material, "_Alpha", 1f);
				SetFloatIfExists(material, "_AlphaClip", 0f);
				SetFloatIfExists(material, "_AlphaToMask", 0f);
				SetFloatIfExists(material, "_Cutoff", 0f);
				SetFloatIfExists(material, "_SrcBlend", 1f);
				SetFloatIfExists(material, "_DstBlend", 0f);
				SetFloatIfExists(material, "_ZWrite", 1f);
				material.DisableKeyword("_ALPHATEST_ON");
				material.DisableKeyword("_ALPHABLEND_ON");
				material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
				material.DisableKeyword("_SURFACE_TYPE_TRANSPARENT");
				material.EnableKeyword("_SURFACE_TYPE_OPAQUE");
				material.renderQueue = 2000;
			}
		}

		private static void ProcessArmoredHumanoidShaders(GameObject go)
		{
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				string text = ((Object)val).name.ToLowerInvariant();
				if (text.Contains("eyepos") || text.Contains("collider") || text.Contains("hitbox"))
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				foreach (Material val2 in sharedMaterials)
				{
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null))
					{
						val2.shader = FindShaderWithName(val2.shader, "ToonDeferredShading2017");
					}
				}
			}
		}

		private static void ProcessExternalAlphaCreatureShaders(GameObject go)
		{
			//IL_0079: 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_0098: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (ShouldSkipRenderer(val))
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if ((Object)(object)val2 == (Object)null || (Object)(object)val2.shader == (Object)null)
					{
						continue;
					}
					Material val3 = new Material(val2)
					{
						name = ((Object)val2).name + "_CO_ExternalAlphaCreature"
					};
					Texture firstTextureOrDefault = GetFirstTextureOrDefault(val2, "_MainTex", "_BaseMap", "_BaseColorMap");
					Texture textureOrDefault = GetTextureOrDefault(val2, "_AlphaTex");
					float floatOrDefault = GetFloatOrDefault(val2, "_UseAlphaTex", ((Object)(object)textureOrDefault != (Object)null) ? 1f : 0f);
					float floatOrDefault2 = GetFloatOrDefault(val2, "_AlphaChannel", 1f);
					bool invertAlpha = GetFloatOrDefault(val2, "_InvertAlpha", 0f) > 0.5f;
					float floatOrDefault3 = GetFloatOrDefault(val2, "_Cutoff", 0.5f);
					Texture firstTextureOrDefault2 = GetFirstTextureOrDefault(val2, "_MetallicGlossMap", "_MetallicMap", "_MaskMap");
					Texture firstTextureOrDefault3 = GetFirstTextureOrDefault(val2, "_BumpMap", "_NormalMap", "_NormalTex");
					Texture firstTextureOrDefault4 = GetFirstTextureOrDefault(val2, "_OcclusionMap", "_AOMap");
					Texture firstTextureOrDefault5 = GetFirstTextureOrDefault(val2, "_EmissionMap", "_EmissiveMap");
					Color firstColorOrDefault = GetFirstColorOrDefault(val2, Color.white, "_Color", "_BaseColor", "_MainColor");
					Color firstColorOrDefault2 = GetFirstColorOrDefault(val2, Color.black, "_EmissionColor");
					float floatOrDefault4 = GetFloatOrDefault(val2, "_Metallic", 0f);
					float floatOrDefault5 = GetFloatOrDefault(val2, "_Glossiness", 0.5f);
					float floatOrDefault6 = GetFloatOrDefault(val2, "_BumpScale", 1f);
					float floatOrDefault7 = GetFloatOrDefault(val2, "_OcclusionStrength", 1f);
					float floatOrDefault8 = GetFloatOrDefault(val2, "_SmoothnessSource", 0f);
					bool flag2 = (Object)(object)firstTextureOrDefault != (Object)null && (Object)(object)textureOrDefault != (Object)null && floatOrDefault > 0.5f;
					if (ShouldPreserveOriginalMetalMaterial(val2, flag2, firstTextureOrDefault2, floatOrDefault4))
					{
						continue;
					}
					Texture value = firstTextureOrDefault;
					if (flag2)
					{
						Vector2 alphaScale = (val2.HasProperty("_AlphaTex") ? val2.GetTextureScale("_AlphaTex") : Vector2.one);
						Vector2 alphaOffset = (val2.HasProperty("_AlphaTex") ? val2.GetTextureOffset("_AlphaTex") : Vector2.zero);
						Texture2D orCreateExternalAlphaTexture = GetOrCreateExternalAlphaTexture(firstTextureOrDefault, textureOrDefault, floatOrDefault2, invertAlpha, alphaScale, alphaOffset);
						if ((Object)(object)orCreateExternalAlphaTexture != (Object)null)
						{
							value = (Texture)(object)orCreateExternalAlphaTexture;
						}
					}
					val3.shader = FindShaderWithName(val3.shader, "Custom/Creature");
					SetTextureIfExists(val3, "_MainTex", value);
					SetTextureIfExists(val3, "_BaseMap", value);
					SetTextureIfExists(val3, "_BaseColorMap", value);
					SetColorIfExists(val3, "_Color", firstColorOrDefault);
					SetColorIfExists(val3, "_BaseColor", firstColorOrDefault);
					SetColorIfExists(val3, "_MainColor", firstColorOrDefault);
					if ((Object)(object)firstTextureOrDefault2 != (Object)null)
					{
						SetTextureIfExists(val3, "_MetallicGlossMap", firstTextureOrDefault2);
						SetTextureIfExists(val3, "_MetallicMap", firstTextureOrDefault2);
						SetTextureIfExists(val3, "_MaskMap", firstTextureOrDefault2);
						val3.EnableKeyword("_METALLICGLOSSMAP");
					}
					else
					{
						val3.DisableKeyword("_METALLICGLOSSMAP");
					}
					SetFloatIfExists(val3, "_Metallic", floatOrDefault4);
					SetFloatIfExists(val3, "_Glossiness", floatOrDefault5);
					SetFloatIfExists(val3, "_GlossMapScale", floatOrDefault5);
					SetFloatIfExists(val3, "_Smoothness", floatOrDefault5);
					SetFloatIfExists(val3, "_SmoothnessSource", floatOrDefault8);
					SetFloatIfExists(val3, "_SmoothnessTextureChannel", floatOrDefault8);
					if ((Object)(object)firstTextureOrDefault3 != (Object)null)
					{
						SetTextureIfExists(val3, "_BumpMap", firstTextureOrDefault3);
						SetTextureIfExists(val3, "_NormalMap", firstTextureOrDefault3);
						SetTextureIfExists(val3, "_NormalTex", firstTextureOrDefault3);
						SetFloatIfExists(val3, "_BumpScale", floatOrDefault6);
						val3.EnableKeyword("_NORMALMAP");
					}
					if ((Object)(object)firstTextureOrDefault4 != (Object)null)
					{
						SetTextureIfExists(val3, "_OcclusionMap", firstTextureOrDefault4);
						SetFloatIfExists(val3, "_OcclusionStrength", floatOrDefault7);
					}
					if ((Object)(object)firstTextureOrDefault5 != (Object)null)
					{
						SetTextureIfExists(val3, "_EmissionMap", firstTextureOrDefault5);
						SetColorIfExists(val3, "_EmissionColor", firstColorOrDefault2);
						if (((Color)(ref firstColorOrDefault2)).maxColorComponent > 0.001f)
						{
							val3.EnableKeyword("_EMISSION");
						}
					}
					ApplyDoubleSidedCreatureSettings(val3);
					if (flag2)
					{
						SetFloatIfExists(val3, "_Cutoff", floatOrDefault3);
						SetFloatIfExists(val3, "_AlphaClip", 1f);
						SetFloatIfExists(val3, "_AlphaTest", 1f);
						val3.SetOverrideTag("RenderType", "TransparentCutout");
						val3.EnableKeyword("_ALPHATEST_ON");
						val3.DisableKeyword("_ALPHABLEND_ON");
						val3.DisableKeyword("_ALPHAPREMULTIPLY_ON");
						val3.renderQueue = 2450;
					}
					else
					{
						val3.DisableKeyword("_ALPHATEST_ON");
						val3.DisableKeyword("_ALPHABLEND_ON");
						val3.DisableKeyword("_ALPHAPREMULTIPLY_ON");
					}
					sharedMaterials[j] = val3;
					flag = true;
				}
				if (flag)
				{
					val.sharedMaterials = sharedMaterials;
					val.shadowCastingMode = (ShadowCastingMode)2;
				}
			}
		}

		private static bool ShouldPreserveOriginalMetalMaterial(Material material, bool usesExternalAlpha, Texture metallicGlossMap, float metallic)
		{
			if ((Object)(object)material == (Object)null || usesExternalAlpha)
			{
				return false;
			}
			string text = ((Object)material).name.Replace(" (Instance)", "").ToLowerInvariant();
			if (text.Contains("coin") || text.Contains("gold") || text.Contains("metallic"))
			{
				return true;
			}
			return (Object)(object)metallicGlossMap != (Object)null || metallic >= 0.5f;
		}

		private static Texture2D GetOrCreateExternalAlphaTexture(Texture mainTexture, Texture alphaTexture, float alphaChannel, bool invertAlpha, Vector2 alphaScale, Vector2 alphaOffset)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mainTexture == (Object)null || (Object)(object)alphaTexture == (Object)null)
			{
				return null;
			}
			string key = $"{((Object)mainTexture).GetInstanceID()}|" + $"{((Object)alphaTexture).GetInstanceID()}|" + $"{alphaChannel:F3}|" + $"{invertAlpha}|" + $"{alphaScale.x:F4},{alphaScale.y:F4}|" + $"{alphaOffset.x:F4},{alphaOffset.y:F4}";
			if (ExternalAlphaBakedTextureCache.TryGetValue(key, out Texture2D value))
			{
				return value;
			}
			Texture2D val = null;
			Texture2D val2 = null;
			try
			{
				val = ReadTextureToRgba32(mainTexture, linear: false);
				val2 = ReadTextureToRgba32(alphaTexture, linear: true);
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
				{
					return null;
				}
				int width = ((Texture)val).width;
				int height = ((Texture)val).height;
				Color32[] pixels = val.GetPixels32();
				for (int i = 0; i < height; i++)
				{
					float num = ((float)i + 0.5f) / (float)height;
					for (int j = 0; j < width; j++)
					{
						float num2 = ((float)j + 0.5f) / (float)width;
						float num3 = num2 * alphaScale.x + alphaOffset.x;
						float num4 = num * alphaScale.y + alphaOffset.y;
						num3 = Mathf.Repeat(num3, 1f);
						num4 = Mathf.Repeat(num4, 1f);
						Color pixelBilinear = val2.GetPixelBilinear(num3, num4);
						float num5 = ((alphaChannel > 0.5f) ? pixelBilinear.a : pixelBilinear.r);
						if (invertAlpha)
						{
							num5 = 1f - num5;
						}
						int num6 = i * width + j;
						Color32 val3 = pixels[num6];
						float num7 = (float)(int)val3.a / 255f;
						float num8 = Mathf.Clamp01(num7 * num5);
						val3.a = (byte)Mathf.RoundToInt(num8 * 255f);
						pixels[num6] = val3;
					}
				}
				Texture2D val4 = new Texture2D(width, height, (TextureFormat)4, true, false)
				{
					name = ((Object)mainTexture).name + "_CO_ExternalAlphaBaked",
					wrapMode = mainTexture.wrapMode,
					filterMode = mainTexture.filterMode,
					anisoLevel = mainTexture.anisoLevel
				};
				val4.SetPixels32(pixels);
				val4.Apply(true, true);
				ExternalAlphaBakedTextureCache[key] = val4;
				return val4;
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[CO External Alpha Creature] No se pudo hornear la máscara '" + ((Object)alphaTexture).name + "' en '" + ((Object)mainTexture).name + "': " + ex.Message));
				return null;
			}
			finally
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					Object.Destroy((Object)(object)val2);
				}
			}
		}

		private static Texture2D ReadTextureToRgba32(Texture sourceTexture, bool linear)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)sourceTexture == (Object)null)
			{
				return null;
			}
			int num = Mathf.Max(1, sourceTexture.width);
			int num2 = Mathf.Max(1, sourceTexture.height);
			RenderTexture temporary = RenderTexture.GetTemporary(num, num2, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)(linear ? 1 : 2));
			RenderTexture active = RenderTexture.active;
			try
			{
				Graphics.Blit(sourceTexture, temporary);
				RenderTexture.active = temporary;
				Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false, linear);
				val.ReadPixels(new Rect(0f, 0f, (float)num, (float)num2), 0, 0, false);
				val.Apply(false, false);
				return val;
			}
			finally
			{
				RenderTexture.active = active;
				RenderTexture.ReleaseTemporary(temporary);
			}
		}

		private static void ProcessFurCreatureShaders(GameObject go)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				string text = ((Object)val).name.ToLowerInvariant();
				if (text.Contains("eyepos") || text.Contains("collider") || text.Contains("hitbox"))
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null))
					{
						Material val3 = new Material(val2)
						{
							name = ((Object)val2).name + "_GlitnirCreature"
						};
						ApplyFurCreatureMaterial(val3);
						sharedMaterials[j] = val3;
						flag = true;
					}
				}
				if (flag)
				{
					val.sharedMaterials = sharedMaterials;
				}
			}
		}

		private static void ApplyFurCreatureMaterial(Material material)
		{
			//IL_004c: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			Texture firstTextureOrDefault = GetFirstTextureOrDefault(material, "_MainTex", "_BaseMap", "_BaseColorMap");
			Texture firstTextureOrDefault2 = GetFirstTextureOrDefault(material, "_BumpMap", "_NormalMap", "_NormalTex");
			Color val = GetFirstColorOrDefault(material, Color.white, "_Color", "_BaseColor", "_MainColor");
			float floatOrDefault = GetFloatOrDefault(material, "_Metallic", 0f);
			float floatOrDefault2 = GetFloatOrDefault(material, "_Glossiness", 0.18f);
			float floatOrDefault3 = GetFloatOrDefault(material, "_Smoothness", floatOrDefault2);
			float floatOrDefault4 = GetFloatOrDefault(material, "_Cutoff", 0.5f);
			material.shader = FindShaderWithName(material.shader, "Custom/Creature");
			ApplyDoubleSidedCreatureSettings(material);
			if (LooksLikeUnityMissingShaderTint(val))
			{
				val = Color.white;
			}
			SetTextureIfExists(material, "_MainTex", firstTextureOrDefault);
			SetTextureIfExists(material, "_BaseMap", firstTextureOrDefault);
			if ((Object)(object)firstTextureOrDefault2 != (Object)null)
			{
				SetTextureIfExists(material, "_BumpMap", firstTextureOrDefault2);
				material.EnableKeyword("_NORMALMAP");
			}
			SetColorIfExists(material, "_Color", val);
			SetColorIfExists(material, "_BaseColor", val);
			SetColorIfExists(material, "_MainColor", val);
			SetFloatIfExists(material, "_Metallic", floatOrDefault);
			SetFloatIfExists(material, "_Glossiness", floatOrDefault2);
			SetFloatIfExists(material, "_Smoothness", floatOrDefault3);
			SetFloatIfExists(material, "_Cutoff", floatOrDefault4);
		}

		private static void ProcessSkeletonHammerShaders(GameObject go)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				string text = ((Object)val).name.ToLowerInvariant();
				if (text.Contains("eyepos") || text.Contains("collider") || text.Contains("hitbox"))
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null))
					{
						Material val3 = new Material(val2)
						{
							name = ((Object)val2).name + "_GlitnirSkeleton"
						};
						ApplySkeletonHammerMaterial(val, val3);
						sharedMaterials[j] = val3;
						flag = true;
					}
				}
				if (flag)
				{
					val.sharedMaterials = sharedMaterials;
				}
			}
		}

		private static void ApplySkeletonHammerMaterial(Renderer renderer, Material material)
		{
			//IL_001f: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			Texture textureOrDefault = GetTextureOrDefault(material, "_MainTex");
			Texture textureOrDefault2 = GetTextureOrDefault(material, "_BumpMap");
			Color colorOrDefault = GetColorOrDefault(material, "_Color", Color.white);
			float floatOrDefault = GetFloatOrDefault(material, "_Cutoff", 0.5f);
			string text = ((Object)material).name.Replace(" (Instance)", "").ToLowerInvariant();
			string text2 = ((Object)renderer).name.ToLowerInvariant();
			bool flag = text.Contains("armor") || text.Contains("hammer") || text.Contains("mace") || text.Contains("metal") || text.Contains("plate") || text.Contains("helm") || text2.Contains("weapon") || text2.Contains("hammer") || text2.Contains("mace");
			material.shader = FindShaderWithName(material.shader, "Custom/Creature");
			ApplyDoubleSidedCreatureSettings(material);
			if ((Object)(object)textureOrDefault != (Object)null && material.HasProperty("_MainTex"))
			{
				material.SetTexture("_MainTex", textureOrDefault);
			}
			if ((Object)(object)textureOrDefault2 != (Object)null && material.HasProperty("_BumpMap"))
			{
				material.SetTexture("_BumpMap", textureOrDefault2);
				material.EnableKeyword("_NORMALMAP");
			}
			float num = (flag ? 0.82f : 0.95f);
			Color value = default(Color);
			((Color)(ref value))..ctor(Mathf.Clamp01(colorOrDefault.r * num), Mathf.Clamp01(colorOrDefault.g * num), Mathf.Clamp01(colorOrDefault.b * num), colorOrDefault.a);
			SetColorIfExists(material, "_Color", value);
			SetColorIfExists(material, "_BaseColor", value);
			SetColorIfExists(material, "_MainColor", value);
			SetFloatIfExists(material, "_Metallic", flag ? 0.05f : 0f);
			SetFloatIfExists(material, "_Glossiness", flag ? 0.28f : 0.18f);
			SetFloatIfExists(material, "_Smoothness", flag ? 0.28f : 0.18f);
			SetFloatIfExists(material, "_Cutoff", floatOrDefault);
		}

		private static void ApplyDoubleSidedCreatureSettings(Material material)
		{
			if ((Object)(object)material == (Object)null)
			{
				return;
			}
			bool flag = false;
			string[] array = new string[4] { "_Cull", "_CullMode", "_CullModeForward", "_CullModeDeferred" };
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (material.HasProperty(text))
				{
					material.SetFloat(text, 0f);
					flag = true;
				}
			}
			if (material.HasProperty("_DoubleSidedEnable"))
			{
				material.SetFloat("_DoubleSidedEnable", 1f);
			}
			if (material.HasProperty("_DoubleSidedNormalMode"))
			{
				material.SetFloat("_DoubleSidedNormalMode", 1f);
			}
			material.EnableKeyword("_DOUBLESIDED_ON");
			material.doubleSidedGI = true;
		}

		private static void ProcessLightsaberBladeMaterials(GameObject go, Color bladeColor, bool includeCylinderRenderers = false)
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_0098: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Material[] sharedMaterials = val.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val2 = sharedMaterials[j];
					if (!((Object)(object)val2 == (Object)null) && IsLightsaberBladeMaterial(val, val2, includeCylinderRenderers))
					{
						Material val3 = new Material(val2)
						{
							name = ((Object)val2).name + "_StarwarsBlade"
						};
						ApplyLightsaberBladeMaterial(val3, bladeColor);
						sharedMaterials[j] = val3;
						flag = true;
					}
				}
				if (flag)
				{
					val.sharedMaterials = sharedMaterials;
					AddLightsaberBladeLight(val, bladeColor);
				}
			}
		}

		private static bool IsLightsaberBladeMaterial(Renderer renderer, Material material, bool includeCylinderRenderers = false)
		{
			string text = ((Object)renderer).name.ToLowerInvariant();
			string text2 = ((Object)material).name.Replace(" (Instance)", "").ToLowerInvariant();
			return text.Contains("laser") || text.Contains("blade") || text.Contains("sable") || text2.Contains("laser") || text2.Contains("blade") || text2.Contains("sable") || (includeCylinderRenderers && (text.Contains("cylinder") || text2.Contains("cylinder")));
		}

		private static void ApplyLightsaberBladeMaterial(Material material, Color bladeColor)
		{
			//IL_002f: 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_003e: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0069: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_0085: 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_00a4: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Unlit/Color") ?? Shader.Find("Particles/Standard Unlit");
			if ((Object)(object)val != (Object)null)
			{
				material.shader = val;
			}
			Color value = Color.white * 1.6f + new Color(bladeColor.r, bladeColor.g, bladeColor.b, 1f) * 3.2f;
			Color value2 = Color.white * 1.1f + new Color(bladeColor.r, bladeColor.g, bladeColor.b, 1f) * 5.5f;
			value.a = 1f;
			value2.a = 1f;
			SetColorIfExists(material, "_Color", value);
			SetColorIfExists(material, "_MainColor", value);
			SetColorIfExists(material, "_BaseColor", value);
			SetColorIfExists(material, "_EmissionColor", value2);
			SetColorIfExists(material, "_SpecColor", Color.black);
			SetFloatIfExists(material, "_Metallic", 0f);
			SetFloatIfExists(material, "_Glossiness", 0f);
			SetFloatIfExists(material, "_Smoothness", 0f);
			SetFloatIfExists(material, "_BumpScale", 0f);
			if (material.HasProperty("_BumpMap"))
			{
				material.SetTexture("_BumpMap", (Texture)null);
			}
			material.EnableKeyword("_EMISSION");
			material.DisableKeyword("_NORMALMAP");
			material.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			material.renderQueue = -1;
		}

		private static void AddLightsaberBladeLight(Renderer renderer, Color bladeColor)
		{
			//IL_001f: 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)
			Transform val = ((Component)renderer).transform.Find("StarwarsBladeLight");
			GameObject val2 = (GameObject)(Object.op_Implicit((Object)(object)val) ? ((object)((Component)val).gameObject) : ((object)new GameObject("StarwarsBladeLight")));
			if (!Object.op_Implicit((Object)(object)val))
			{
				val2.transform.SetParent(((Component)renderer).transform, false);
			}
			Light val3 = val2.GetComponent<Light>() ?? val2.AddComponent<Light>();
			val3.type = (LightType)2;
			val3.color = bladeColor;
			val3.intensity = 1.25f;
			val3.range = 3.5f;
			val3.shadows = (LightShadows)0;
		}

		private static void ProcessEmissiveVfxMaterials(GameObject go, Color vfxColor)
		{
			//IL_0011: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//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_006f: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)go == (Object)null)
			{
				return;
			}
			Color val = Color.white * 0.35f + new Color(vfxColor.r, vfxColor.g, vfxColor.b, 1f) * 1.65f;
			val.a = 1f;
			ParticleSystem[] componentsInChildren = go.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val2 in componentsInChildren)
			{
				MainModule main = val2.main;
				((MainModule)(ref main)).startColor = new MinMaxGradient(val);
			}
			Renderer[] componentsInChildren2 = go.GetComponentsInChildren<Renderer>(true);
			Renderer[] array = componentsInChildren2;
			foreach (Renderer val3 in array)
			{
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				Material[] sharedMaterials = val3.sharedMaterials;
				bool flag = false;
				for (int k = 0; k < sharedMaterials.Length; k++)
				{
					Material val4 = sharedMaterials[k];
					if (!((Object)(object)val4 == (Object)null))
					{
						Material val5 = new Material(val4)
						{
							name = ((Object)val4).name + "_StarwarsVfx"
						};
						ApplyEmissiveVfxMaterial(val5, vfxColor);
						sharedMaterials[k] = val5;
						flag = true;
					}
				}
				if (flag)
				{
					val3.sharedMaterials = sharedMaterials;
				}
			}
		}

		private static void ApplyEmissiveVfxMaterial(Material material, Color vfxColor)
		{
			//IL_003d: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_008d: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Particles/Standard Unlit") ?? Shader.Find("Unlit/Transparent") ?? Shader.Find("Unlit/Color");
			if ((Object)(object)val != (Object)null)
			{
				material.shader = val;
			}
			Color value = Color.white * 0.45f + new Color(vfxColor.r, vfxColor.g, vfxColor.b, 1f) * 2.25f;
			Color value2 = Color.white * 0.25f + new Color(vfxColor.r, vfxColor.g, vfxColor.b, 1f) * 4.5f;
			value.a = 1f;
			value2.a = 1f;
			SetColorIfExists(material, "_Color", value);
			SetColorIfExists(material, "_TintColor", value);
			SetColorIfExists(material, "_MainColor", value);
			SetColorIfExists(material, "_BaseColor", value);
			SetColorIfExists(material, "_EmissionColor", value2);
			SetFloatIfExists(material, "_Metallic", 0f);
			SetFloatIfExists(material, "_Glossiness", 0f);
			SetFloatIfExists(material, "_Smoothness", 0f);
			SetFloatIfExists(material, "_BumpScale", 0f);
			material.EnableKeyword("_EMISSION");
			material.DisableKeyword("_NORMALMAP");
			material.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
		}

		private static Texture? GetFirstTextureOrDefault(Material material, params string[] names)
		{
			foreach (string name in names)
			{
				Texture textureOrDefault = GetTextureOrDefault(material, name);
				if ((Object)(object)textureOrDefault != (Object)null)
				{
					return textureOrDefault;
				}
			}
			return null;
		}

		private static Texture? GetTextureOrDefault(Material material, string name)
		{
			if ((Object)(object)material != (Object)null && material.HasProperty(name))
			{
				return material.GetTexture(name);
			}
			return null;
		}

		private static Color GetFirstColorOrDefault(Material material, Color fallback, params string[] names)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			foreach (string text in names)
			{
				if ((Object)(object)material != (Object)null && material.HasProperty(text))
				{
					return material.GetColor(text);
				}
			}
			return fallback;
		}

		private static Color GetColorOrDefault(Material material, string name, Color fallback)
		{
			//IL_0023: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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)
			if ((Object)(object)material != (Object)null && material.HasProperty(name))
			{
				return material.GetColor(name);
			}
			return fallback;
		}

		private static bool LooksLikeUnityMissingShaderTint(Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			return color.r > 0.55f && color.b > 0.55f && color.g < 0.48f && Mathf.Abs(color.r - color.b) < 0.35f;
		}

		private static float GetFloatOrDefault(Material material, string name, float fallback)
		{
			if ((Object)(object)material != (Object)null && material.HasProperty(name))
			{
				return material.GetFloat(name);
			}
			return fallback;
		}

		private static void SetFloatIfExists(Material material, string name, float value)
		{
			if ((Object)(object)material != (Object)null && material.HasProperty(name))
			{
				material.SetFloat(name, value);
			}
		}

		private static void SetTextureIfExists(Material material, string name, Texture? value)
		{
			if ((Object)(object)material != (Object)null && (Object)(object)value != (Object)null && material.HasProperty(name))
			{
				material.SetTexture(name, value);
			}
		}

		private static void SetColorIfExists(Material material, string name, Color value)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)material != (Object)null && material.HasProperty(name))
			{
				material.SetColor(name, value);
			}
		}

		private static Shader GetShaderForType(Shader orig, ShaderType shaderType, string originalShaderName)
		{
			return (Shader)(shaderType switch
			{
				ShaderType.PieceShader => FindShaderWithName(orig, "Custom/Piece"), 
				ShaderType.VegetationShader => FindShaderWithName(orig, "Custom/Vegetation"), 
				ShaderType.RockShader => FindShaderWithName(orig, "Custom/StaticRock"), 
				ShaderType.RugShader => FindShaderWithName(orig, "Custom/Rug"), 
				ShaderType.GrassShader => FindShaderWithName(orig, "Custom/Grass"), 
				ShaderType.CustomCreature => FindShaderWithName(orig, "Custom/Creature"), 
				ShaderType.ToonDeferred => FindShaderWithName(orig, "ToonDeferredShading2017"), 
				ShaderType.UseUnityShader => FindShaderWithName(orig, ((Object)(object)FindShaderWithName(orig, originalShaderName) != (Object)null) ? originalShaderName : "ToonDeferredShading2017"), 
				_ => FindShaderWithName(orig, "Standard"), 
			});
		}

		public static Shader FindShaderWithName(Shader origShader, string name)
		{
			foreach (Shader cachedShader in CachedShaders)
			{
				if (((Object)cachedShader).name == name)
				{
					return cachedShader;
				}
			}
			return origShader;
		}
	}
}
namespace LocalizationManager
{
	[PublicAPI]
	public class Localizer
	{
		private static readonly Dictionary<string, Dictionary<string, Func<string>>> PlaceholderProcessors;

		private static readonly Dictionary<string, Dictionary<string, string>> loadedTexts;

		private static readonly ConditionalWeakTable<Localization, string> localizationLanguage;

		private static readonly List<WeakReference<Localization>> localizationObjects;

		private static BaseUnityPlugin? _plugin;

		private static readonly List<string> fileExtensions;

		private static BaseUnityPlugin plugin
		{
			get
			{
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Expected O, but got Unknown
				if (_plugin == null)
				{
					IEnumerable<TypeInfo> source;
					try
					{
						source = Assembly.GetExecutingAssembly().DefinedTypes.ToList();
					}
					catch (ReflectionTypeLoadException ex)
					{
						source = from t in ex.Types
							where t != null
							select t.GetTypeInfo();
					}
					_plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
				}
				return _plugin;
			}
		}

		private static void UpdatePlaceholderText(Localization localization, string key)
		{
			localizationLanguage.TryGetValue(localization, out string value);
			string text = loadedTexts[value][key];
			if (PlaceholderProcessors.TryGetValue(key, out Dictionary<string, Func<string>> value2))
			{
				text = value2.Aggregate(text, (string current, KeyValuePair<string, Func<string>> kv) => current.Replace("{" + kv.Key + "}", kv.Value()));
			}
			localization.AddWord(key, text);
		}

		public static void AddPlaceholder<T>(string key, string placeholder, ConfigEntry<T> config, Func<T, string>? convertConfigValue = null) where T : notnull
		{
			if (convertConfigValue == null)
			{
				convertConfigValue = (T val) => val.ToString();
			}
			if (!PlaceholderProcessors.ContainsKey(key))
			{
				PlaceholderProcessors[key] = new Dictionary<string, Func<string>>();
			}
			config.SettingChanged += delegate
			{
				UpdatePlaceholder();
			};
			if (loadedTexts.ContainsKey(Localization.instance.GetSelectedLanguage()))
			{
				UpdatePlaceholder();
			}
			void UpdatePlaceholder()
			{
				PlaceholderProcessors[key][placeholder] = () => convertConfigValue(config.Value);
				UpdatePlaceholderText(Localization.instance, key);
			}
		}

		public static void AddText(string key, string text)
		{
			List<WeakReference<Localization>> list = new List<WeakReference<Localization>>();
			foreach (WeakReference<Localization> localizationObject in localizationObjects)
			{
				if (localizationObject.TryGetTarget(out var target))
				{
					Dictionary<string, string> dictionary = loadedTexts[localizationLanguage.GetOrCreateValue(target)];
					if (!target.m_translations.ContainsKey(key))
					{
						dictionary[key] = text;
						target.AddWord(key, text);
					}
				}
				else
				{
					list.Add(localizationObject);
				}
			}
			foreach (WeakReference<Localization> item in list)
			{
				localizationObjects.Remove(item);
			}
		}

		public static void Load()
		{
			LoadLocalization(Localization.instance, Localization.instance.GetSelectedLanguage());
		}

		private static void LoadLocalization(Localization __instance, string language)
		{
			if (!localizationLanguage.Remove(__instance))
			{
				localizationObjects.Add(new WeakReference<Localization>(__instance));
			}
			localizationLanguage.Add(__instance, language);
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (string item in from f in Directory.GetFiles(Path.GetDirectoryName(Paths.PluginPath), plugin.Info.Metadata.Name + ".*", SearchOption.AllDirectories)
				where fileExtensions.IndexOf(Path.GetExtension(f)) >= 0
				select f)
			{
				string text = Path.GetFileNameWithoutExtension(item).Split(new char[1] { '.' })[1];
				if (dictionary.ContainsKey(text))
				{
					Debug.LogWarning((object)("Duplicate key " + text + " found for " + plugin.Info.Metadata.Name + ". The duplicate file found at " + item + " will be skipped."));
				}
				else
				{
					dictionary[text] = item;
				}
			}
			byte[] array = LoadTranslationFromAssembly("English");
			if (array == null)
			{
				throw new Exception("Found no English localizations in mod " + plugin.Info.Metadata.Name + ". Expected an embedded resource translations/English.json or translations/English.yml.");
			}
			Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(Encoding.UTF8.GetString(array));
			if (dictionary2 == null)
			{
				throw new Exception("Localization for mod " + plugin.Info.Metadata.Name + " failed: Localization file was empty.");
			}
			string text2 = null;
			if (language != "English")
			{
				if (dictionary.ContainsKey(language))
				{
					text2 = File.ReadAllText(dictionary[language]);
				}
				else
				{
					byte[] array2 = LoadTranslationFromAssembly(language);
					if (array2 != null)
					{
						text2 = Encoding.UTF8.GetString(array2);
					}
				}
			}
			if (text2 == null && dictionary.ContainsKey("English"))
			{
				text2 = File.ReadAllText(dictionary["English"]);
			}
			if (text2 != null)
			{
				foreach (KeyValuePair<string, string> item2 in new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(text2) ?? new Dictionary<string, string>())
				{
					dictionary2[item2.Key] = item2.Value;
				}
			}
			loadedTexts[language] = dictionary2;
			foreach (KeyValuePair<string, string> item3 in dictionary2)
			{
				UpdatePlaceholderText(__instance, item3.Key);
			}
		}

		static Localizer()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			PlaceholderProcessors = new Dictionary<string, Dictionary<string, Func<string>>>();
			loadedTexts = new Dictionary<string, Dictionary<string, string>>();
			localizationLanguage = new ConditionalWeakTable<Localization, string>();
			localizationObjects = new List<WeakReference<Localization>>();
			fileExtensions = new List<string> { ".json", ".yml" };
			Harmony val = new Harmony("org.bepinex.helpers.LocalizationManager");
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "LoadCSV", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static byte[]? LoadTranslationFromAssembly(string language)
		{
			foreach (string fileExtension in fileExtensions)
			{
				byte[] array = ReadEmbeddedFileBytes("translations." + language + fileExtension);
				if (array != null)
				{
					return array;
				}
			}
			return null;
		}

		public static byte[]? ReadEmbeddedFileBytes(string resourceFileName, Assembly? containingAssembly = null)
		{
			using MemoryStream memoryStream = new MemoryStream();
			if ((object)containingAssembly == null)
			{
				containingAssembly = Assembly.GetCallingAssembly();
			}
			string text = containingAssembly.GetManifestResourceNames().FirstOrDefault((string str) => str.EndsWith(resourceFileName, StringComparison.Ordinal));
			if (text != null)
			{
				containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream);
			}
			return (memoryStream.Length == 0L) ? null : memoryStream.ToArray();
		}
	}
}
namespace ItemManager
{
	[PublicAPI]
	public enum CraftingTable
	{
		Disabled,
		Inventory,
		[InternalName("piece_workbench")]
		Workbench,
		[InternalName("piece_cauldron")]
		Cauldron,
		[InternalName("piece_MeadCauldron")]
		MeadCauldron,
		[InternalName("forge")]
		Forge,
		[InternalName("piece_artisanstation")]
		ArtisanTable,
		[InternalName("piece_stonecutter")]
		StoneCutter,
		[InternalName("piece_magetable")]
		MageTable,
		[InternalName("piece_preptable")]
		PrepTable,
		[InternalName("blackforge")]
		BlackForge,
		Custom
	}
	[PublicAPI]
	public enum ConversionPiece
	{
		Disabled,
		[InternalName("smelter")]
		Smelter,
		[InternalName("charcoal_kiln")]
		CharcoalKiln,
		[InternalName("blastfurnace")]
		BlastFurnace,
		[InternalName("windmill")]
		Windmill,
		[InternalName("piece_spinningwheel")]
		SpinningWheel,
		[InternalName("eitrrefinery")]
		EitrRefinery,
		Custom
	}
	public class InternalName : Attribute
	{
		public readonly string internalName;

		public InternalName(string internalName)
		{
			this.internalName = internalName;
		}
	}
	[PublicAPI]
	public class RequiredResourceList
	{
		public readonly List<Requirement> Requirements = new List<Requirement>();

		public bool Free = false;

		public void Add(string itemName, int amount, int quality = 0)
		{
			Requirements.Add(new Requirement
			{
				itemName = itemName,
				amount = amount,
				quality = quality
			});
		}

		public void Add(string itemName, ConfigEntry<int> amountConfig, int quality = 0)
		{
			Requirements.Add(new Requirement
			{
				itemName = itemName,
				amountConfig = amountConfig,
				quality = quality
			});
		}
	}
	[PublicAPI]
	public class CraftingStationList
	{
		public readonly List<CraftingStationConfig> Stations = new List<CraftingStationConfig>();

		public void Add(CraftingTable table, int level)
		{
			Stations.Add(new CraftingStationConfig
			{
				Table = table,
				level = level
			});
		}

		public void Add(string customTable, int level)
		{
			Stations.Add(new CraftingStationConfig
			{
				Table = CraftingTable.Custom,
				level = level,
				custom = customTable
			});
		}
	}
	[PublicAPI]
	public class ItemRecipe
	{
		public readonly RequiredResourceList RequiredItems = new RequiredResourceList();

		public readonly RequiredResourceList RequiredUpgradeItems = new RequiredResourceList();

		public readonly CraftingStationList Crafting = new CraftingStationList();

		public int CraftAmount = 1;

		public bool RequireOnlyOneIngredient = false;

		public float QualityResultAmountMultiplier = 1f;

		public ConfigEntryBase? RecipeIsActive = null;
	}
	[PublicAPI]
	public class Trade
	{
		public Trader Trader = Trader.None;

		public uint Price = 0u;

		public uint Stack = 1u;

		public string? RequiredGlobalKey = null;
	}
	[PublicAPI]
	[Flags]
	public enum Trader
	{
		None = 0,
		Haldor = 1,
		Hildir = 2
	}
	public struct Requirement
	{
		public string itemName;

		public int amount;

		public ConfigEntry<int>? amountConfig;

		[Description("Set to a non-zero value to apply the requirement only for a specific quality")]
		public int quality;
	}
	public struct CraftingStationConfig
	{
		public CraftingTable Table;

		public int level;

		public string? custom;
	}
	[Flags]
	public enum Configurability
	{
		Disabled = 0,
		Recipe = 1,
		Stats = 2,
		Drop = 4,
		Trader = 8,
		Full = 0xF
	}
	[PublicAPI]
	public class DropTargets
	{
		public readonly List<DropTarget> Drops = new List<DropTarget>();

		public void Add(string creatureName, float chance, int min = 1, int? max = null, bool levelMultiplier = true)
		{
			Drops.Add(new DropTarget
			{
				creature = creatureName,
				chance = chance,
				min = min,
				max = (max ?? min),
				levelMultiplier = levelMultiplier
			});
		}
	}
	public struct DropTarget
	{
		public string creature;

		public int min;

		public int max;

		public float chance;

		public bool levelMultiplier;
	}
	public enum Toggle
	{
		On = 1,
		Off = 0
	}
	[PublicAPI]
	public class Item
	{
		private class ItemConfig
		{
			public ConfigEntry<string>? craft;

			public ConfigEntry<string>? upgrade;

			public ConfigEntry<CraftingTable> table = null;

			public ConfigEntry<int> tableLevel = null;

			public ConfigEntry<string> customTable = null;

			public ConfigEntry<int>? maximumTableLevel;

			public ConfigEntry<Toggle> requireOneIngredient = null;

			public ConfigEntry<float> qualityResultAmountMultiplier = null;
		}

		private class TraderConfig
		{
			public ConfigEntry<Trader> trader = null;

			public ConfigEntry<uint> price = null;

			public ConfigEntry<uint> stack = null;

			public ConfigEntry<string> requiredGlobalKey = null;
		}

		private class RequirementQuality
		{
			public int quality;
		}

		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order;

			[UsedImplicitly]
			public bool? Browsable;

			[UsedImplicitly]
			public string? Category;

			[UsedImplicitly]
			public Action<ConfigEntryBase>? CustomDrawer;

			public Func<bool>? browsability;
		}

		[PublicAPI]
		public enum DamageModifier
		{
			Normal,
			Resistant,
			Weak,
			Immune,
			Ignore,
			VeryResistant,
			VeryWeak,
			None
		}

		private delegate void setDmgFunc(ref DamageTypes dmg, float value);

		private class SerializedRequirements
		{
			public readonly List<Requirement> Reqs;

			public SerializedRequirements(List<Requirement> reqs)
			{
				Reqs = reqs;
			}

			public SerializedRequirements(string reqs)
				: this(reqs.Split(new char[1] { ',' }).Select(delegate(string r)
				{
					string[] array = r.Split(new char[1] { ':' });
					int result;
					int result2;
					return new Requirement
					{
						itemName = array[0],
						amount = ((array.Length <= 1 || !int.TryParse(array[1], out result)) ? 1 : result),
						quality = ((array.Length > 2 && int.TryParse(array[2], out result2)) ? result2 : 0)
					};
				}).ToList())
			{
			}

			public override string ToString()
			{
				return string.Join(",", Reqs.Select((Requirement r) => $"{r.itemName}:{r.amount}" + ((r.quality > 0) ? $":{r.quality}" : "")));
			}

			public static ItemDrop? fetchByName(ObjectDB objectDB, string name)
			{
				GameObject itemPrefab = objectDB.GetItemPrefab(name);
				ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if ((Object)(object)val == (Object)null)
				{
					Debug.LogWarning((object)("The required item '" + name + "' does not exist."));
				}
				return val;
			}

			public static Requirement[] toPieceReqs(ObjectDB objectDB, SerializedRequirements craft, SerializedRequirements upgrade)
			{
				//IL_0100: 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_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_019b: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01af: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b2: Expected O, but got Unknown
				//IL_01b7: Expected O, but got Unknown
				//IL_012c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0135: Expected O, but got Unknown
				Dictionary<string, Requirement> dictionary = craft.Reqs.Where((Requirement r) => r.itemName != "").ToDictionary((Func<Requirement, string>)((Requirement r) => r.itemName), (Func<Requirement, Requirement>)delegate(Requirement r)
				{
					//IL_000e: 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_0030: 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)
					ItemDrop val6 = ResItem(r);
					return (val6 == null) ? ((Requirement)null) : new Requirement
					{
						m_amount = (r.amountConfig?.Value ?? r.amount),
						m_resItem = val6,
						m_amountPerLevel = 0
					};
				});
				List<Requirement> list = dictionary.Values.Where((Requirement v) => v != null).ToList();
				foreach (Requirement item in upgrade.Reqs.Where((Requirement r) => r.itemName != ""))
				{
					if (item.quality > 0)
					{
						ItemDrop val = ResItem(item);
						if (val != null)
						{
							Requirement val2 = new Requirement
							{
								m_resItem = val,
								m_amountPerLevel = (item.amountConfig?.Value ?? item.amount),
								m_amount = 0
							};
							list.Add(val2);
							requirementQuality.Add(val2, new RequirementQuality
							{
								quality = item.quality
							});
						}
						continue;
					}
					if (!dictionary.TryGetValue(item.itemName, out var value) || value == null)
					{
						ItemDrop val3 = ResItem(item);
						if (val3 != null)
						{
							string itemName = item.itemName;
							Requirement val4 = new Requirement
							{
								m_resItem = val3,
								m_amount = 0
							};
							Requirement val5 = val4;
							dictionary[itemName] = val4;
							value = val5;
							list.Add(value);
						}
					}
					if (value != null)
					{
						value.m_amountPerLevel = item.amountConfig?.Value ?? item.amount;
					}
				}
				return list.ToArray();
				ItemDrop? ResItem(Requirement r)
				{
					return fetchByName(objectDB, r.itemName);
				}
			}
		}

		private class SerializedDrop
		{
			public readonly List<DropTarget> Drops;

			public SerializedDrop(List<DropTarget> drops)
			{
				Drops = drops;
			}

			public SerializedDrop(string drops)
			{
				Drops = ((drops == "") ? ((IEnumerable<string>)Array.Empty<string>()) : ((IEnumerable<string>)drops.Split(new char[1] { ',' }))).Select(delegate(string r)
				{
					string[] array = r.Split(new char[1] { ':' });
					if (array.Length <= 2 || !int.TryParse(array[2], out var result))
					{
						result = 1;
					}
					if (array.Length <= 3 || !int.TryParse(array[3], out var result2))
					{
						result2 = result;
					}
					bool levelMultiplier = array.Length <= 4 || array[4] != "0";
					float result3;
					return new DropTarget
					{
						creature = array[0],
						chance = ((array.Length > 1 && float.TryParse(array[1], out result3)) ? result3 : 1f),
						min = result,
						max = result2,
						levelMultiplier = levelMultiplier
					};
				}).ToList();
			}

			public override string ToString()
			{
				return string.Join(",", Drops.Select((DropTarget r) => $"{r.creature}:{r.chance.ToString(CultureInfo.InvariantCulture)}:{r.min}:" + ((r.min == r.max) ? "" : $"{r.max}") + (r.levelMultiplier ? "" : ":0")));
			}

			private static Character? fetchByName(ZNetScene netScene, string name)
			{
				GameObject prefab = netScene.GetPrefab(name);
				Character val = ((prefab != null) ? prefab.GetComponent<Character>() : null);
				if ((Object)(object)val == (Object)null)
				{
					Debug.LogWarning((object)("The drop target character '" + name + "' does not exist."));
				}
				return val;
			}

			public Dictionary<Character, Drop> toCharacterDrops(ZNetScene netScene, GameObject item)
			{
				//IL_0039: 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_0045: 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_005d: 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_007a: Expected O, but got Unknown
				Dictionary<Character, Drop> dictionary = new Dictionary<Character, Drop>();
				foreach (DropTa