Decompiled source of Feastgut Relic v0.2.3

BepInEx/plugins/RomsligMage/RomsligMage.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("RomsligMage")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.3.0")]
[assembly: AssemblyInformationalVersion("0.2.3")]
[assembly: AssemblyProduct("RomsligMage")]
[assembly: AssemblyTitle("RomsligMage")]
[assembly: AssemblyVersion("0.2.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RomsligMage
{
	internal static class FoodHud
	{
		[HarmonyPatch(typeof(Hud), "UpdateFood")]
		private static class UpdateSlot
		{
			private static void Postfix(Hud __instance, Player player)
			{
				if (Ensure(__instance) && Object.op_Implicit((Object)(object)fourthSlot))
				{
					fourthSlot.SetActive(Plugin.FoodLimit(player) == 4);
				}
			}
		}

		[HarmonyPatch(typeof(Hud), "Awake")]
		private static class Initialize
		{
			private static void Postfix(Hud __instance)
			{
				Ensure(__instance);
			}
		}

		private static Hud prepared;

		private static GameObject fourthSlot;

		private static readonly string[] Names = new string[3] { "m_foodBars", "m_foodIcons", "m_foodTime" };

		internal static bool Ensure(Hud hud)
		{
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)hud))
			{
				return false;
			}
			if ((Object)(object)prepared == (Object)(object)hud)
			{
				return true;
			}
			List<GameObject> list = new List<GameObject>();
			FieldInfo[] array = null;
			Array[] array2 = null;
			try
			{
				array = Names.Select((string n) => AccessTools.Field(typeof(Hud), n)).ToArray();
				if (array.Any((FieldInfo f) => f == null))
				{
					return false;
				}
				array2 = array.Select((FieldInfo f) => f.GetValue(hud) as Array).ToArray();
				if (array2.Any((Array a) => a == null))
				{
					return false;
				}
				if (array2.All((Array a) => a.Length == 4))
				{
					prepared = hud;
					return true;
				}
				if (array2.Any((Array a) => a.Length != 3))
				{
					return false;
				}
				Component[] array3 = array2[1].Cast<Component>().ToArray();
				Component[] array4 = array2[2].Cast<Component>().ToArray();
				if (array3.Any((Component c) => !Object.op_Implicit((Object)(object)c)) || array4.Any((Component c) => !Object.op_Implicit((Object)(object)c)))
				{
					throw new InvalidOperationException("Missing food icon or timer");
				}
				int topIndex = Array.IndexOf(array3, array3.OrderByDescending((Component c) => c.transform.position.y).First());
				RectTransform slot = default(RectTransform);
				ref RectTransform reference = ref slot;
				Transform parent = array3[topIndex].transform.parent;
				reference = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				if (!Object.op_Implicit((Object)(object)slot) || (Object)(object)array4[topIndex].transform.parent != (Object)(object)slot || array3.Where((Component c, int i) => i != topIndex).Any((Component c) => c.transform.IsChildOf((Transform)(object)slot)))
				{
					throw new InvalidOperationException("Unsupported food slot hierarchy");
				}
				float[] array5 = (from c in array3
					select ((RectTransform)c.transform.parent).anchoredPosition.y into y
					orderby y
					select y).ToArray();
				float num = (array5[2] - array5[0]) / 2f;
				if (num < 1f)
				{
					throw new InvalidOperationException("Unsupported food slot spacing");
				}
				GameObject val = Object.Instantiate<GameObject>(((Component)slot).gameObject, ((Transform)slot).parent, false);
				list.Add(val);
				((Object)val).name = "TK_FourthFoodSlot";
				((RectTransform)val.transform).anchoredPosition = slot.anchoredPosition + Vector2.up * num;
				Component component = ((Component)val.transform.Find(((Object)array3[topIndex].transform).name)).GetComponent(((object)array3[topIndex]).GetType());
				Component component2 = ((Component)val.transform.Find(((Object)array4[topIndex].transform).name)).GetComponent(((object)array4[topIndex]).GetType());
				if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component2))
				{
					throw new InvalidOperationException("Missing cloned food graphics");
				}
				Array[] array6 = new Array[3];
				for (int num2 = 0; num2 < array2.Length; num2++)
				{
					Array obj = array2[num2];
					Component[] array7 = obj.Cast<Component>().ToArray();
					if (array7.Any((Component c) => !Object.op_Implicit((Object)(object)c)))
					{
						throw new InvalidOperationException("Missing HUD component");
					}
					Component val4;
					switch (num2)
					{
					case 1:
						val4 = component;
						break;
					case 2:
						val4 = component2;
						break;
					default:
					{
						Component val2 = array7[topIndex];
						GameObject val3 = Object.Instantiate<GameObject>(val2.gameObject, val2.transform.parent, false);
						list.Add(val3);
						((Object)val3).name = "TK_Fourth_" + Names[num2];
						val4 = val3.GetComponent(((object)val2).GetType());
						val3.SetActive(false);
						break;
					}
					}
					if (!Object.op_Implicit((Object)(object)val4))
					{
						throw new InvalidOperationException("Missing cloned component");
					}
					Array array8 = Array.CreateInstance(obj.GetType().GetElementType(), 4);
					Array.Copy(obj, array8, 3);
					array8.SetValue(val4, 3);
					array6[num2] = array8;
				}
				for (int num3 = 0; num3 < array.Length; num3++)
				{
					array[num3].SetValue(hud, array6[num3]);
				}
				fourthSlot = val;
				fourthSlot.SetActive(false);
				prepared = hud;
				return true;
			}
			catch (Exception ex)
			{
				if (array != null && array2 != null)
				{
					for (int num4 = 0; num4 < array.Length; num4++)
					{
						if (array[num4] != null && array2[num4] != null)
						{
							array[num4].SetValue(hud, array2[num4]);
						}
					}
				}
				foreach (GameObject item in list)
				{
					Object.Destroy((Object)(object)item);
				}
				Logger.LogWarning((object)("Feastgut Relic HUD unavailable: " + ex.Message));
				return false;
			}
		}
	}
	[BepInPlugin("tk.valheim.romsligmage", "Feastgut Relic", "0.2.3")]
	[BepInDependency("com.jotunn.jotunn", "2.30.2")]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Player), "CanEat")]
		private static class CanEatPatch
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
			{
				return PatchLimit(instructions, __originalMethod);
			}
		}

		[HarmonyPatch(typeof(Player), "EatFood")]
		private static class EatFoodPatch
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
			{
				return PatchLimit(instructions, __originalMethod);
			}
		}

		[HarmonyPatch(typeof(Trader), "GetAvailableItems")]
		private static class ShopPatch
		{
			private static void Postfix(Trader __instance, ref List<TradeItem> __result)
			{
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_00fa: Expected O, but got Unknown
				//IL_00ff: Expected O, but got Unknown
				if (Ready && Object.op_Implicit((Object)(object)Stomach) && BossDefeated() && !Unlocked(Player.m_localPlayer) && (((Object)__instance).name.Equals("Haldor", StringComparison.OrdinalIgnoreCase) || ((Object)__instance).name.StartsWith("Haldor(", StringComparison.OrdinalIgnoreCase)) && !__result.Any((TradeItem x) => (Object)(object)x.m_prefab != (Object)null && ((Object)x.m_prefab).name == "TK_RomsligMage"))
				{
					__result = new List<TradeItem>(__result)
					{
						new TradeItem
						{
							m_prefab = Stomach.GetComponent<ItemDrop>(),
							m_stack = 1,
							m_price = Price.Value,
							m_name = "Feastgut Relic",
							m_tooltip = string.Empty,
							m_requiredGlobalKey = string.Empty,
							m_buyKey = string.Empty,
							m_incrementKey = string.Empty,
							m_buyPlayerEffects = new EffectList
							{
								m_effectPrefabs = (EffectData[])(object)new EffectData[0]
							}
						}
					};
				}
			}
		}

		[HarmonyPatch(typeof(Player), "CanConsumeItem")]
		private static class CanConsumePatch
		{
			private static bool Prefix(Player __instance, ItemData item, ref bool __result)
			{
				if (!IsStomach(item))
				{
					return true;
				}
				__result = true;
				return false;
			}
		}

		[HarmonyPatch(typeof(Player), "ConsumeItem")]
		private static class ConsumePatch
		{
			private static bool Prefix(Player __instance, Inventory inventory, ItemData item, ref bool __result)
			{
				if (!IsStomach(item))
				{
					return true;
				}
				__result = false;
				if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer)
				{
					return false;
				}
				string text = ((!Ready) ? "Food slots could not be updated. Check the BepInEx log." : (Unlocked(__instance) ? "You already have four food slots." : ((!BossDefeated()) ? "Yagluth must be defeated in this world." : null)));
				if (text != null)
				{
					((Character)__instance).Message((MessageType)2, text, 0, (Sprite)null, false);
					return false;
				}
				inventory = inventory ?? ((Humanoid)__instance).GetInventory();
				if (!inventory.ContainsItem(item) || item.m_stack < 1)
				{
					return false;
				}
				if (!FoodHud.Ensure(Hud.instance))
				{
					((Character)__instance).Message((MessageType)2, "Unsupported food display. The stomach was not consumed.", 0, (Sprite)null, false);
					return false;
				}
				if (!inventory.RemoveItem(item, 1))
				{
					return false;
				}
				__instance.m_customData["tk.valheim.romsligmage.unlocked.v1"] = "1";
				((Character)__instance).Message((MessageType)2, "Your stomach grows! You now have four permanent food slots.", 0, (Sprite)null, false);
				__result = true;
				return false;
			}
		}

		public const string Guid = "tk.valheim.romsligmage";

		public const string Prefab = "TK_RomsligMage";

		public const string UnlockKey = "tk.valheim.romsligmage.unlocked.v1";

		internal static Plugin Instance;

		internal static ConfigEntry<int> Price;

		internal static bool CanEatPatched;

		internal static bool EatFoodPatched;

		internal static GameObject Stomach;

		private Harmony harmony;

		internal static bool Ready
		{
			get
			{
				if (CanEatPatched)
				{
					return EatFoodPatched;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			Instance = this;
			Price = ((BaseUnityPlugin)this).Config.Bind<int>("Haldor", "Price", 2000, new ConfigDescription("Price in coins. Synchronized from the server in multiplayer.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100000), new object[1] { (object)new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			} }));
			harmony = new Harmony("tk.valheim.romsligmage");
			try
			{
				harmony.PatchAll(typeof(Plugin).Assembly);
			}
			catch (Exception ex)
			{
				CanEatPatched = (EatFoodPatched = false);
				harmony.UnpatchSelf();
				((BaseUnityPlugin)this).Logger.LogError((object)("Mod disabled: patch installation failed. " + ex));
				return;
			}
			PrefabManager.OnVanillaPrefabsAvailable += Register;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Feastgut Relic 0.2.3 loaded; food patches ready: " + Ready));
		}

		private void OnDestroy()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}

		private void Register()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			try
			{
				CustomItem val = new CustomItem("TK_RomsligMage", "Entrails");
				SharedData shared = val.ItemDrop.m_itemData.m_shared;
				shared.m_name = "Feastgut Relic";
				shared.m_description = "A stomach infused with jotun power. Consume once to permanently unlock a fourth food slot. Yagluth must be defeated in this world. The upgrade stays with your character.";
				shared.m_itemType = (ItemType)2;
				shared.m_maxStackSize = 1;
				shared.m_weight = 0.5f;
				shared.m_food = (shared.m_foodStamina = (shared.m_foodEitr = 0f));
				shared.m_consumeStatusEffect = null;
				StomachVisual.Apply(val.ItemPrefab);
				Sprite val2 = StomachIcon.Load();
				if (Object.op_Implicit((Object)(object)val2))
				{
					shared.m_icons = (Sprite[])(object)new Sprite[1] { val2 };
				}
				if (!ItemManager.Instance.AddItem(val))
				{
					throw new InvalidOperationException("Item registration rejected");
				}
				Stomach = val.ItemPrefab;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Stomach registration failed: " + ex));
			}
		}

		internal static bool Unlocked(Player player)
		{
			if ((Object)(object)player != (Object)null && player.m_customData != null && player.m_customData.TryGetValue("tk.valheim.romsligmage.unlocked.v1", out var value))
			{
				return value == "1";
			}
			return false;
		}

		internal static bool IsStomach(ItemData item)
		{
			if (item != null && (Object)(object)item.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name == "TK_RomsligMage";
			}
			return false;
		}

		internal static bool BossDefeated()
		{
			if ((Object)(object)ZoneSystem.instance != (Object)null)
			{
				return ZoneSystem.instance.GetGlobalKey("defeated_goblinking");
			}
			return false;
		}

		public static int FoodLimit(Player player)
		{
			if (!Ready || !Unlocked(player))
			{
				return 3;
			}
			return 4;
		}

		internal static IEnumerable<CodeInstruction> PatchLimit(IEnumerable<CodeInstruction> input, MethodBase method)
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			List<CodeInstruction> list = input.ToList();
			List<int> list2 = new List<int>();
			for (int i = 1; i < list.Count - 1; i++)
			{
				if (CodeInstructionExtensions.LoadsConstant(list[i], 3L) && list[i - 1].operand is MethodInfo methodInfo && !(methodInfo.Name != "get_Count") && !(methodInfo.DeclaringType != typeof(List<Food>)) && list[i + 1].opcode.FlowControl == FlowControl.Cond_Branch)
				{
					list2.Add(i);
				}
			}
			if (list2.Count != 1)
			{
				((BaseUnityPlugin)Instance).Logger.LogError((object)(method.Name + ": expected exactly one food-count comparison; found " + list2.Count + ". Upgrade disabled."));
				return list;
			}
			int num = list2[0];
			CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
			val.labels.AddRange(list[num].labels);
			val.blocks.AddRange(list[num].blocks);
			list[num] = val;
			list.Insert(num + 1, new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Plugin), "FoodLimit", (Type[])null, (Type[])null)));
			if (method.Name == "CanEat")
			{
				CanEatPatched = true;
			}
			if (method.Name == "EatFood")
			{
				EatFoodPatched = true;
			}
			return list;
		}
	}
	internal static class StomachIcon
	{
		private static Sprite cached;

		internal static Sprite Load()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)cached))
			{
				return cached;
			}
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("RomsligMage.StomachIcon.png");
			if (stream == null)
			{
				throw new InvalidOperationException("Embedded stomach icon is missing.");
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			MethodInfo method = typeof(ImageConversion).GetMethod("LoadImage", new Type[3]
			{
				typeof(Texture2D),
				typeof(byte[]),
				typeof(bool)
			});
			if (method == null || !(bool)method.Invoke(null, new object[3]
			{
				val,
				memoryStream.ToArray(),
				false
			}))
			{
				Object.Destroy((Object)(object)val);
				throw new InvalidOperationException("Could not decode stomach icon.");
			}
			((Object)val).name = "JotunStomachIcon";
			((Texture)val).wrapMode = (TextureWrapMode)1;
			cached = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			((Object)cached).name = "JotunStomachIcon";
			return cached;
		}
	}
	internal static class StomachVisual
	{
		internal static void Apply(GameObject prefab)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0077: 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_00c9: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: 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)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: 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_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Expected O, but got Unknown
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			Renderer? obj = ((IEnumerable<Renderer>)componentsInChildren).FirstOrDefault((Func<Renderer, bool>)((Renderer r) => Object.op_Implicit((Object)(object)r.sharedMaterial) && Object.op_Implicit((Object)(object)r.sharedMaterial.shader)));
			if (!Object.op_Implicit((Object)(object)obj))
			{
				throw new InvalidOperationException("Entrails material unavailable");
			}
			Material val = new Material(obj.sharedMaterial);
			((Object)val).name = "TK_StomachMaterial";
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", new Color(0.64f, 0.23f, 0.23f));
			}
			if (val.HasProperty("_MainTex"))
			{
				val.SetTexture("_MainTex", (Texture)(object)Texture2D.whiteTexture);
			}
			Renderer[] array = componentsInChildren;
			for (int num = 0; num < array.Length; num++)
			{
				array[num].enabled = false;
			}
			GameObject val2 = new GameObject("TK_StomachMesh");
			val2.transform.SetParent(prefab.transform, false);
			val2.transform.localPosition = new Vector3(0f, 0.15f, 0f);
			Vector3[] array2 = (Vector3[])(object)new Vector3[10]
			{
				new Vector3(-0.1f, 0.29f, 0f),
				new Vector3(-0.1f, 0.23f, 0f),
				new Vector3(-0.09f, 0.15f, 0f),
				new Vector3(-0.04f, 0.08f, 0f),
				new Vector3(0.02f, -0.01f, 0f),
				new Vector3(0.08f, -0.09f, 0f),
				new Vector3(0.15f, -0.1f, 0f),
				new Vector3(0.21f, -0.05f, 0f),
				new Vector3(0.22f, 0.02f, 0f),
				new Vector3(0.27f, 0.05f, 0f)
			};
			float[] array3 = new float[10] { 0.023f, 0.025f, 0.06f, 0.105f, 0.13f, 0.115f, 0.08f, 0.042f, 0.024f, 0.018f };
			List<Vector3> list = new List<Vector3>();
			List<int> list2 = new List<int>();
			List<Vector2> list3 = new List<Vector2>();
			Vector3 val4 = default(Vector3);
			for (int num2 = 0; num2 < array2.Length; num2++)
			{
				Vector3 val3 = array2[Math.Min(num2 + 1, array2.Length - 1)] - array2[Math.Max(0, num2 - 1)];
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				((Vector3)(ref val4))..ctor(0f - normalized.y, normalized.x, 0f);
				for (int num3 = 0; num3 < 12; num3++)
				{
					float num4 = (float)num3 * (float)Math.PI * 2f / 12f;
					list.Add(array2[num2] + val4 * (Mathf.Cos(num4) * array3[num2]) + Vector3.forward * (Mathf.Sin(num4) * array3[num2] * 0.65f));
					list3.Add(new Vector2((float)num3 / 12f, (float)num2 / (float)(array2.Length - 1)));
					if (num2 != 0)
					{
						int num5 = (num2 - 1) * 12 + num3;
						int num6 = (num2 - 1) * 12 + (num3 + 1) % 12;
						list2.AddRange(new int[6]
						{
							num5,
							num6,
							num5 + 12,
							num6,
							num6 + 12,
							num5 + 12
						});
					}
				}
			}
			for (int num7 = 0; num7 < 2; num7++)
			{
				int num8 = ((num7 != 0) ? ((array2.Length - 1) * 12) : 0);
				int count = list.Count;
				list.Add(array2[(num7 != 0) ? (array2.Length - 1) : 0]);
				list3.Add(Vector2.one * 0.5f);
				for (int num9 = 0; num9 < 12; num9++)
				{
					list2.AddRange((num7 == 0) ? new int[3]
					{
						count,
						num8 + (num9 + 1) % 12,
						num8 + num9
					} : new int[3]
					{
						count,
						num8 + num9,
						num8 + (num9 + 1) % 12
					});
				}
			}
			Mesh val5 = new Mesh
			{
				name = "TK_Stomach"
			};
			val5.SetVertices(list);
			val5.SetTriangles(list2, 0);
			val5.SetUVs(0, list3);
			val5.RecalculateNormals();
			val5.RecalculateBounds();
			val2.AddComponent<MeshFilter>().sharedMesh = val5;
			((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = val;
		}
	}
}