Decompiled source of ValheimMexicanFood v1.0.0

plugins/ValheimMexicanFood.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
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: AssemblyVersion("0.0.0.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 ValheimMexicanFood
{
	[BepInPlugin("com.reggi.valheimmexicanfood", "Valheim Mexican Food", "0.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class MexicanFoodPlugin : BaseUnityPlugin
	{
		private class FoodFile
		{
			public List<FoodDef> foods = new List<FoodDef>();
		}

		private class FoodDef
		{
			public string id;

			public string asset;

			public bool enabled = true;

			public string basePrefab = "CookedLoxMeat";

			public string station = "piece_cauldron";

			public int stationLevel = 1;

			public float health;

			public float stamina;

			public float eitr;

			public float regen;

			public float duration = 1800f;

			public float scale = 1f;

			public float[] standOffset = new float[3];

			public float[] standRotation = new float[3];

			public float weight = 1f;

			public int stack = 10;

			public int craftAmount = 1;

			public List<Ingredient> recipe = new List<Ingredient>();

			public Dictionary<string, string> name = new Dictionary<string, string>();

			public Dictionary<string, string> description = new Dictionary<string, string>();

			public string LocKey => "item_" + id.ToLower();
		}

		private class Ingredient
		{
			public string item;

			public int amount = 1;
		}

		public const string PluginGUID = "com.reggi.valheimmexicanfood";

		public const string PluginName = "Valheim Mexican Food";

		public const string PluginVersion = "0.4.0";

		private AssetBundle bundle;

		internal static readonly Dictionary<int, (string id, Vector3 offset, Vector3 rotation)> StandAdjust = new Dictionary<int, (string, Vector3, Vector3)>();

		private List<FoodDef> foods = new List<FoodDef>();

		private void Awake()
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			bundle = AssetUtils.LoadAssetBundle(Path.Combine(directoryName, "mexicanfood"));
			if ((Object)(object)bundle == (Object)null)
			{
				Logger.LogError((object)"No se encontro el AssetBundle 'mexicanfood'.");
				return;
			}
			string text = Path.Combine(directoryName, "foods.json");
			if (!File.Exists(text))
			{
				Logger.LogError((object)("No se encontro " + text));
				return;
			}
			try
			{
				FoodFile foodFile = JsonConvert.DeserializeObject<FoodFile>(File.ReadAllText(text));
				if (foodFile?.foods != null)
				{
					foods = foodFile.foods;
				}
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Error leyendo foods.json: " + ex.Message));
				return;
			}
			AddTranslations();
			try
			{
				new Harmony("com.reggi.valheimmexicanfood").PatchAll(typeof(ItemStandPatch));
			}
			catch (Exception ex2)
			{
				Logger.LogWarning((object)("No se pudo ajustar el soporte de objetos: " + ex2.Message));
			}
			PrefabManager.OnVanillaPrefabsAvailable += AddFoods;
			Logger.LogInfo((object)string.Format("{0} {1} cargado con {2} platillos en foods.json.", "Valheim Mexican Food", "0.4.0", foods.Count));
		}

		private void AddTranslations()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			Dictionary<string, Dictionary<string, string>> dictionary = new Dictionary<string, Dictionary<string, string>>();
			foreach (FoodDef food in foods)
			{
				if (string.IsNullOrEmpty(food.id))
				{
					continue;
				}
				foreach (KeyValuePair<string, string> item in food.name)
				{
					Get(dictionary, item.Key)[food.LocKey] = item.Value;
				}
				foreach (KeyValuePair<string, string> item2 in food.description)
				{
					Get(dictionary, item2.Key)[food.LocKey + "_desc"] = item2.Value;
				}
			}
			Get(dictionary, "English")["piece_mf_comal"] = "Viking Comal";
			Get(dictionary, "English")["piece_mf_comal_desc"] = "A stone hearth with a wide griddle and a work table. Cook the dishes of the south here.";
			Get(dictionary, "Spanish")["piece_mf_comal"] = "Comal Vikingo";
			Get(dictionary, "Spanish")["piece_mf_comal_desc"] = "Un fogón de piedra con un comal ancho y una mesa de trabajo. Aquí se cocinan los platillos del sur.";
			Get(dictionary, "English")["piece_mf_metate"] = "Viking Metate";
			Get(dictionary, "English")["piece_mf_metate_desc"] = "A carved grinding stone. Place it near the Viking Comal to cook more elaborate dishes.";
			Get(dictionary, "Spanish")["piece_mf_metate"] = "Metate Vikingo";
			Get(dictionary, "Spanish")["piece_mf_metate_desc"] = "Una piedra de moler tallada. Ponla cerca del Comal Vikingo para cocinar platillos más elaborados.";
			foreach (KeyValuePair<string, Dictionary<string, string>> item3 in dictionary)
			{
				string key = item3.Key;
				localization.AddTranslation(ref key, item3.Value);
			}
		}

		private static Dictionary<string, string> Get(Dictionary<string, Dictionary<string, string>> d, string lang)
		{
			if (!d.TryGetValue(lang, out var value))
			{
				value = (d[lang] = new Dictionary<string, string>());
			}
			return value;
		}

		private void AddFoods()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= AddFoods;
			try
			{
				Stations.AddStations(bundle);
			}
			catch (Exception arg)
			{
				Logger.LogError((object)$"Error creando el comal/metate: {arg}");
			}
			int num = 0;
			foreach (FoodDef food in foods)
			{
				if (food.enabled && AddFood(food))
				{
					num++;
				}
			}
			Logger.LogInfo((object)$"Platillos agregados: {num}");
		}

		private bool AddFood(FoodDef def)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Expected O, but got Unknown
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Expected O, but got Unknown
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(def.id) || string.IsNullOrEmpty(def.asset))
			{
				Logger.LogWarning((object)"Hay un platillo sin 'id' o sin 'asset' en foods.json; se omite.");
				return false;
			}
			GameObject val = bundle.LoadAsset<GameObject>(def.asset);
			Sprite val2 = bundle.LoadAsset<Sprite>(def.asset + "_icon");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Logger.LogWarning((object)(def.id + ": no hay modelo o icono '" + def.asset + "' en el AssetBundle todavia; se omite."));
				return false;
			}
			List<RequirementConfig> list = new List<RequirementConfig>();
			foreach (Ingredient item in def.recipe)
			{
				if (!string.IsNullOrEmpty(item.item))
				{
					list.Add(new RequirementConfig(item.item, item.amount, 0, true));
				}
			}
			ItemConfig val3 = new ItemConfig();
			val3.Name = "$" + def.LocKey;
			val3.Description = "$" + def.LocKey + "_desc";
			val3.CraftingStation = def.station;
			val3.MinStationLevel = def.stationLevel;
			val3.Icons = (Sprite[])(object)new Sprite[1] { val2 };
			val3.Requirements = list.ToArray();
			val3.Amount = def.craftAmount;
			ItemConfig val4 = val3;
			CustomItem val5 = new CustomItem(def.id, def.basePrefab, val4);
			if (!val5.IsValid())
			{
				Logger.LogError((object)("No se pudo crear " + def.id + " (base: " + def.basePrefab + ")."));
				return false;
			}
			ReplaceVisual(val5.ItemPrefab, val, def.scale);
			StandAdjust[StringExtensionMethods.GetStableHashCode(def.id)] = (def.id, ToVec(def.standOffset), ToVec(def.standRotation));
			SharedData shared = val5.ItemDrop.m_itemData.m_shared;
			shared.m_food = def.health;
			shared.m_foodStamina = def.stamina;
			shared.m_foodEitr = def.eitr;
			shared.m_foodRegen = def.regen;
			shared.m_foodBurnTime = def.duration;
			shared.m_maxStackSize = def.stack;
			shared.m_weight = def.weight;
			ItemManager.Instance.AddItem(val5);
			Logger.LogInfo((object)("Platillo agregado: " + def.id));
			return true;
		}

		private static Vector3 ToVec(float[] a)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (a == null || a.Length < 3)
			{
				return Vector3.zero;
			}
			return new Vector3(a[0], a[1], a[2]);
		}

		private static void ReplaceVisual(GameObject prefab, GameObject model, float scale)
		{
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: 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_01a7: 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_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: 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_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: 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_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03de: Expected O, but got Unknown
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			Shader val = null;
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				if ((Object)(object)val2 != (Object)null && (Object)(object)val2.sharedMaterial != (Object)null && (Object)(object)val2.sharedMaterial.shader != (Object)null)
				{
					val = val2.sharedMaterial.shader;
					break;
				}
			}
			LODGroup component = prefab.GetComponent<LODGroup>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val3 in componentsInChildren)
			{
				if ((Object)(object)val3 != (Object)null)
				{
					val3.enabled = false;
				}
			}
			Collider[] componentsInChildren2 = prefab.GetComponentsInChildren<Collider>(true);
			foreach (Collider val4 in componentsInChildren2)
			{
				if ((Object)(object)val4 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)val4, true);
				}
			}
			GameObject val5 = Object.Instantiate<GameObject>(model, prefab.transform);
			((Object)val5).name = "visual";
			val5.transform.localPosition = Vector3.zero;
			val5.transform.localRotation = Quaternion.identity;
			val5.transform.localScale = Vector3.one * scale;
			val5.SetActive(true);
			Transform[] componentsInChildren3 = val5.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				((Component)componentsInChildren3[i]).gameObject.layer = prefab.layer;
			}
			Transform val6 = prefab.transform.Find("attach");
			if ((Object)(object)val6 != (Object)null)
			{
				val5.transform.SetParent(val6, false);
				val5.transform.localPosition = Vector3.zero;
				val5.transform.localRotation = Quaternion.identity;
				Vector3 val7 = default(Vector3);
				((Vector3)(ref val7))..ctor(val6.lossyScale.x / prefab.transform.lossyScale.x, val6.lossyScale.y / prefab.transform.lossyScale.y, val6.lossyScale.z / prefab.transform.lossyScale.z);
				if (val7.x > 0.0001f && val7.y > 0.0001f && val7.z > 0.0001f)
				{
					val5.transform.localScale = new Vector3(scale / val7.x, scale / val7.y, scale / val7.z);
				}
				Logger.LogInfo((object)$"[visual] {((Object)prefab).name}: escala de attach={val7}");
			}
			Matrix4x4 worldToLocalMatrix = prefab.transform.worldToLocalMatrix;
			bool flag = false;
			Bounds val8 = default(Bounds);
			MeshFilter[] componentsInChildren4 = val5.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val9 in componentsInChildren4)
			{
				if ((Object)(object)val9.sharedMesh == (Object)null)
				{
					continue;
				}
				Matrix4x4 val10 = worldToLocalMatrix * ((Component)val9).transform.localToWorldMatrix;
				Bounds bounds = val9.sharedMesh.bounds;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val11 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
					Vector3 val12 = ((Matrix4x4)(ref val10)).MultiplyPoint3x4(val11);
					if (!flag)
					{
						((Bounds)(ref val8))..ctor(val12, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref val8)).Encapsulate(val12);
					}
				}
			}
			if (flag)
			{
				BoxCollider obj = prefab.AddComponent<BoxCollider>();
				obj.center = ((Bounds)(ref val8)).center;
				obj.size = ((Bounds)(ref val8)).size;
			}
			componentsInChildren = val5.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val13 in componentsInChildren)
			{
				val13.enabled = true;
				Material[] sharedMaterials = val13.sharedMaterials;
				for (int k = 0; k < sharedMaterials.Length; k++)
				{
					if (!((Object)(object)sharedMaterials[k] == (Object)null))
					{
						Material val14 = new Material(sharedMaterials[k]);
						if ((Object)(object)val != (Object)null && ((Object)val).name == "Standard")
						{
							val14.shader = val;
						}
						if (val14.HasProperty("_MainTex") && sharedMaterials[k].HasProperty("_MainTex"))
						{
							val14.SetTexture("_MainTex", sharedMaterials[k].GetTexture("_MainTex"));
						}
						if (val14.HasProperty("_BumpMap") && sharedMaterials[k].HasProperty("_BumpMap"))
						{
							val14.SetTexture("_BumpMap", sharedMaterials[k].GetTexture("_BumpMap"));
						}
						if (val14.HasProperty("_Color"))
						{
							val14.SetColor("_Color", Color.white);
						}
						sharedMaterials[k] = val14;
					}
				}
				val13.sharedMaterials = sharedMaterials;
				string[] obj2 = new string[7]
				{
					"[visual] ",
					((Object)prefab).name,
					": shader=",
					null,
					null,
					null,
					null
				};
				Material sharedMaterial = val13.sharedMaterial;
				object obj3;
				if (sharedMaterial == null)
				{
					obj3 = null;
				}
				else
				{
					Shader shader = sharedMaterial.shader;
					obj3 = ((shader != null) ? ((Object)shader).name : null);
				}
				obj2[3] = (string)obj3;
				obj2[4] = " (vanilla: ";
				obj2[5] = ((val != null) ? ((Object)val).name : null);
				obj2[6] = ")";
				Logger.LogInfo((object)string.Concat(obj2));
			}
		}
	}
	internal static class Stations
	{
		public const string ComalId = "piece_mf_comal";

		public const string MetateId = "piece_mf_metate";

		public static void AddStations(AssetBundle bundle)
		{
			AddComal(bundle);
			AddMetate(bundle);
		}

		private static RequirementConfig Req(string item, int amount)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_001b: Expected O, but got Unknown
			return new RequirementConfig
			{
				Item = item,
				Amount = amount,
				Recover = true
			};
		}

		private static void AddComal(AssetBundle bundle)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			GameObject val = bundle.LoadAsset<GameObject>("VikingComal");
			Sprite val2 = bundle.LoadAsset<Sprite>("VikingComal_icon");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Logger.LogWarning((object)"No hay modelo o icono 'VikingComal' en el AssetBundle; no se agrega el comal.");
				return;
			}
			PieceConfig val3 = new PieceConfig();
			val3.Name = "$piece_mf_comal";
			val3.Description = "$piece_mf_comal_desc";
			val3.PieceTable = "Hammer";
			val3.Category = "Crafting";
			val3.CraftingStation = "piece_workbench";
			val3.Icon = val2;
			val3.Requirements = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				Req("Wood", 10),
				Req("Stone", 6),
				Req("Flint", 4)
			};
			PieceConfig val4 = val3;
			CustomPiece val5 = new CustomPiece("piece_mf_comal", "piece_workbench", val4);
			if (!val5.IsValid())
			{
				Logger.LogError((object)"No se pudo crear el comal.");
				return;
			}
			GameObject piecePrefab = val5.PiecePrefab;
			GameObject val6 = ReplacePieceVisual(piecePrefab, val);
			CraftingStation component = piecePrefab.GetComponent<CraftingStation>();
			if ((Object)(object)component != (Object)null)
			{
				component.m_name = "$piece_mf_comal";
				component.m_craftRequireRoof = false;
				component.m_craftRequireFire = false;
				component.m_showBasicRecipies = false;
				component.m_rangeBuild = 0f;
				GameObject prefab = PrefabManager.Instance.GetPrefab("piece_cauldron");
				CraftingStation val7 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<CraftingStation>() : null);
				if ((Object)(object)val7 != (Object)null)
				{
					component.m_craftItemEffects = val7.m_craftItemEffects;
					component.m_craftItemDoneEffects = val7.m_craftItemDoneEffects;
				}
				GameObject val8 = MakeFire(val6.transform);
				if ((Object)(object)val8 != (Object)null)
				{
					FieldInfo fieldInfo = AccessTools.Field(typeof(CraftingStation), "m_inUseObject");
					if (fieldInfo != null)
					{
						fieldInfo.SetValue(component, val8);
					}
					else
					{
						Logger.LogWarning((object)"CraftingStation no tiene m_inUseObject; el fuego no se conectara.");
					}
					val8.SetActive(false);
				}
			}
			PieceManager.Instance.AddPiece(val5);
			Logger.LogInfo((object)"Estacion agregada: Viking Comal");
		}

		private static void AddMetate(AssetBundle bundle)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			GameObject val = bundle.LoadAsset<GameObject>("VikingMetate");
			Sprite val2 = bundle.LoadAsset<Sprite>("VikingMetate_icon");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				Logger.LogWarning((object)"No hay modelo o icono 'VikingMetate' en el AssetBundle; no se agrega el metate.");
				return;
			}
			PieceConfig val3 = new PieceConfig();
			val3.Name = "$piece_mf_metate";
			val3.Description = "$piece_mf_metate_desc";
			val3.PieceTable = "Hammer";
			val3.Category = "Crafting";
			val3.CraftingStation = "piece_workbench";
			val3.ExtendStation = "piece_mf_comal";
			val3.Icon = val2;
			val3.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
			{
				Req("Stone", 6),
				Req("Copper", 2)
			};
			PieceConfig val4 = val3;
			CustomPiece val5 = new CustomPiece("piece_mf_metate", "piece_workbench_ext1", val4);
			if (!val5.IsValid())
			{
				Logger.LogError((object)"No se pudo crear el metate.");
				return;
			}
			ReplacePieceVisual(val5.PiecePrefab, val);
			PieceManager.Instance.AddPiece(val5);
			Logger.LogInfo((object)"Estacion agregada: Viking Metate");
		}

		private static GameObject ReplacePieceVisual(GameObject prefab, GameObject model)
		{
			//IL_00a7: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			LODGroup component = prefab.GetComponent<LODGroup>();
			if ((Object)(object)component != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component);
			}
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.enabled = false;
				}
			}
			Collider[] componentsInChildren2 = prefab.GetComponentsInChildren<Collider>(true);
			foreach (Collider val2 in componentsInChildren2)
			{
				if ((Object)(object)val2 != (Object)null && !val2.isTrigger)
				{
					Object.DestroyImmediate((Object)(object)val2, true);
				}
			}
			GameObject val3 = Object.Instantiate<GameObject>(model, prefab.transform);
			((Object)val3).name = "visual";
			val3.transform.localPosition = Vector3.zero;
			val3.transform.localRotation = Quaternion.identity;
			val3.transform.localScale = Vector3.one;
			val3.SetActive(true);
			Transform[] componentsInChildren3 = val3.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				((Component)componentsInChildren3[i]).gameObject.layer = prefab.layer;
			}
			componentsInChildren = val3.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].enabled = true;
			}
			Matrix4x4 worldToLocalMatrix = prefab.transform.worldToLocalMatrix;
			bool flag = false;
			Bounds val4 = default(Bounds);
			MeshFilter[] componentsInChildren4 = val3.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val5 in componentsInChildren4)
			{
				if ((Object)(object)val5.sharedMesh == (Object)null)
				{
					continue;
				}
				Matrix4x4 val6 = worldToLocalMatrix * ((Component)val5).transform.localToWorldMatrix;
				Bounds bounds = val5.sharedMesh.bounds;
				for (int j = 0; j < 8; j++)
				{
					Vector3 val7 = ((Matrix4x4)(ref val6)).MultiplyPoint3x4(((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1)))));
					if (!flag)
					{
						((Bounds)(ref val4))..ctor(val7, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref val4)).Encapsulate(val7);
					}
				}
			}
			if (flag)
			{
				BoxCollider obj = val3.AddComponent<BoxCollider>();
				obj.center = val3.transform.InverseTransformPoint(prefab.transform.TransformPoint(((Bounds)(ref val4)).center));
				obj.size = ((Bounds)(ref val4)).size;
			}
			WearNTear component2 = prefab.GetComponent<WearNTear>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.m_new = val3;
				component2.m_worn = val3;
				component2.m_broken = val3;
			}
			return val3;
		}

		private static GameObject MakeFire(Transform visual)
		{
			//IL_0123: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			Transform val = null;
			Transform[] componentsInChildren = ((Component)visual).GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren)
			{
				if (((Object)val2).name == "FirePoint")
				{
					val = val2;
					break;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogWarning((object)"El modelo del comal no tiene 'FirePoint'; se pone el fuego al centro.");
				val = visual;
			}
			GameObject prefab = PrefabManager.Instance.GetPrefab("fire_pit");
			Fireplace val3 = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Fireplace>() : null);
			GameObject val4 = null;
			if ((Object)(object)val3 != (Object)null)
			{
				string[] array = new string[2] { "m_enabledObjectHigh", "m_enabledObject" };
				foreach (string text in array)
				{
					FieldInfo fieldInfo = AccessTools.Field(typeof(Fireplace), text);
					if (fieldInfo != null)
					{
						object? value = fieldInfo.GetValue(val3);
						GameObject val5 = (GameObject)((value is GameObject) ? value : null);
						if (val5 != null && (Object)(object)val5 != (Object)null)
						{
							val4 = val5;
							break;
						}
					}
				}
			}
			if ((Object)(object)val4 == (Object)null)
			{
				Logger.LogWarning((object)"No se encontro el fuego de 'fire_pit'; el comal no tendra fuego.");
				return null;
			}
			GameObject val6 = Object.Instantiate<GameObject>(val4, val, false);
			((Object)val6).name = "mf_fire";
			val6.transform.localPosition = Vector3.zero;
			val6.transform.localRotation = Quaternion.identity;
			Vector3 lossyScale = val.lossyScale;
			float num = 0.45f / Mathf.Max(0.0001f, Mathf.Max(lossyScale.x, Mathf.Max(lossyScale.y, lossyScale.z)));
			val6.transform.localScale = Vector3.one * num;
			Component[] componentsInChildren2 = val6.GetComponentsInChildren<Component>(true);
			foreach (Component val7 in componentsInChildren2)
			{
				if ((Object)(object)val7 == (Object)null)
				{
					continue;
				}
				string name = ((object)val7).GetType().Name;
				if (!(val7 is Collider))
				{
					switch (name)
					{
					case "EffectArea":
					case "Aoe":
					case "SmokeSpawner":
					case "ZNetView":
					case "ZSyncTransform":
						break;
					default:
						continue;
					}
				}
				Object.DestroyImmediate((Object)(object)val7, true);
			}
			componentsInChildren = val6.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.layer = LayerMask.NameToLayer("Default");
			}
			Logger.LogInfo((object)$"[comal] fuego copiado de fire_pit ({((Object)val4).name}), escala {num:0.00}");
			return val6;
		}
	}
	[HarmonyPatch(typeof(ItemStand), "SetVisualItem")]
	internal static class ItemStandPatch
	{
		private static readonly FieldInfo VisualItemField = AccessTools.Field(typeof(ItemStand), "m_visualItem");

		private static void Postfix(ItemStand __instance, int itemHash)
		{
			//IL_0088: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_019f: 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_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			if (VisualItemField == null || !MexicanFoodPlugin.StandAdjust.TryGetValue(itemHash, out (string, Vector3, Vector3) value))
			{
				return;
			}
			object? value2 = VisualItemField.GetValue(__instance);
			GameObject val = (GameObject)((value2 is GameObject) ? value2 : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			string item = value.Item1;
			Transform val2 = null;
			Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true);
			foreach (Transform val3 in componentsInChildren)
			{
				if (((Object)val3).name == "visual")
				{
					val2 = val3;
					break;
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			val2.localPosition = Vector3.zero;
			val2.localRotation = Quaternion.identity;
			int num;
			if (TryBounds(((Component)__instance).transform, val.transform, out var bounds))
			{
				num = ((((Bounds)(ref bounds)).size.y < Mathf.Min(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z)) ? 1 : 0);
				if (num != 0)
				{
					val2.rotation = Quaternion.FromToRotation(val2.up, Vector3.up) * val2.rotation;
				}
			}
			else
			{
				num = 0;
			}
			val2.rotation *= Quaternion.Euler(value.Item3);
			if (num != 0 && TryBounds(val2, null, out var bounds2))
			{
				Vector3 val4 = default(Vector3);
				((Vector3)(ref val4))..ctor(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).max.y, ((Bounds)(ref bounds)).center.z);
				Vector3 val5 = default(Vector3);
				((Vector3)(ref val5))..ctor(((Bounds)(ref bounds2)).center.x, ((Bounds)(ref bounds2)).min.y, ((Bounds)(ref bounds2)).center.z);
				Transform obj = val2;
				obj.position += val4 - val5;
			}
			Transform obj2 = val2;
			obj2.position += value.Item2;
			Logger.LogInfo((object)$"[soporte] {item}: offset={value.Item2}, rotacion={value.Item3}");
		}

		private static bool TryBounds(Transform root, Transform exclude, out Bounds bounds)
		{
			//IL_0001: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			bounds = default(Bounds);
			bool flag = false;
			Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>();
			foreach (Renderer val in componentsInChildren)
			{
				if (val.enabled && (!((Object)(object)exclude != (Object)null) || !((Component)val).transform.IsChildOf(exclude)) && !(((object)val).GetType().Name == "ParticleSystemRenderer"))
				{
					if (!flag)
					{
						bounds = val.bounds;
						flag = true;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(val.bounds);
					}
				}
			}
			return flag;
		}
	}
}