Decompiled source of EnchantmentRunicChannel v1.0.3

EnchantmentRunicChannel.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace RE_EnchantmentRunicChannel
{
	public class RE_EnchantmentRecipeItem_ProcessDescription
	{
		public static bool Prefix(EnchantmentRecipeItem __instance, ManualLogSource Log)
		{
			//IL_00ab: 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_01f8: 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)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0312: Unknown result type (might be due to invalid IL or missing references)
			//IL_0527: Unknown result type (might be due to invalid IL or missing references)
			//IL_052c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0566: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0613: Unknown result type (might be due to invalid IL or missing references)
			//IL_061a: Unknown result type (might be due to invalid IL or missing references)
			//IL_061f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0684: Unknown result type (might be due to invalid IL or missing references)
			//IL_0637: Unknown result type (might be due to invalid IL or missing references)
			//IL_063e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_096d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0972: Unknown result type (might be due to invalid IL or missing references)
			//IL_0974: Unknown result type (might be due to invalid IL or missing references)
			//IL_098b: Expected I4, but got Unknown
			if (__instance.Recipes.Length < 1)
			{
				((Item)__instance).m_localizedDescription = ((Item)__instance).Description;
				return true;
			}
			StringBuilder stringBuilder = new StringBuilder();
			string loc = LocalizationManager.Instance.GetLoc("ItemTag_Incense");
			stringBuilder.AppendLine(loc + ": " + __instance.Recipes[0].PillarDatas[0].CompatibleIngredients[0].SpecificIngredient.Name);
			stringBuilder.AppendLine("");
			StringBuilder stringBuilder2 = new StringBuilder();
			for (int i = 0; i < __instance.Recipes[0].PillarDatas.Length; i++)
			{
				if (i > 0)
				{
					stringBuilder2.Append(", ");
				}
				stringBuilder2.Append(LocalizationManager.Instance.GetLoc($"Compass_{__instance.Recipes[0].PillarDatas[i].Direction}"));
				if (__instance.Recipes[0].PillarDatas[i].IsFar)
				{
					stringBuilder2.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_PillarFar"));
				}
				else
				{
					stringBuilder2.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_PillarClose"));
				}
			}
			stringBuilder.AppendLine(LocalizationManager.Instance.GetLoc("EnchantmentCondition_PillarPlacement") + ": " + stringBuilder2.ToString());
			stringBuilder.AppendLine("");
			bool flag = true;
			for (int j = 0; j < __instance.Recipes.Length; j++)
			{
				for (int k = 0; k < __instance.Recipes[j].CompatibleEquipments.CompatibleEquipments.Length; k++)
				{
					if ((int)__instance.Recipes[j].CompatibleEquipments.CompatibleEquipments[k].Type == 0)
					{
						flag = false;
						break;
					}
				}
				if (!flag)
				{
					break;
				}
			}
			StringBuilder stringBuilder3 = new StringBuilder();
			HashSet<string> hashSet = new HashSet<string>();
			Tag tag;
			for (int l = 0; l < __instance.Recipes.Length; l++)
			{
				if (l > 0)
				{
					stringBuilder3.Append(", ");
				}
				tag = __instance.Recipes[l].CompatibleEquipments.EquipmentTag.Tag;
				if (((Tag)(ref tag)).IsSet)
				{
					stringBuilder3.Append(LocalizationManager.Instance.GetLoc("ItemTag_" + __instance.Recipes[l].CompatibleEquipments.EquipmentTag.Tag.TagName.Replace(" ", "")));
				}
				else
				{
					flag = true;
				}
				for (int m = 0; m < __instance.Recipes[l].CompatibleEquipments.CompatibleEquipments.Length; m++)
				{
					if ((int)__instance.Recipes[l].CompatibleEquipments.CompatibleEquipments[m].Type == 0)
					{
						string text = "";
						if (__instance.Recipes[l].CompatibleEquipments.CompatibleEquipments[m].IngredientTag.Tag == __instance.Recipes[l].CompatibleEquipments.EquipmentTag.Tag)
						{
							text = text + LocalizationManager.Instance.GetLoc("EnchantmentCondition_AnyTag") + " ";
						}
						text += LocalizationManager.Instance.GetLoc("ItemTag_" + __instance.Recipes[l].CompatibleEquipments.CompatibleEquipments[m].IngredientTag.Tag.TagName.Replace(" ", ""));
						hashSet.Add(text);
					}
					else if ((Object)(object)__instance.Recipes[l].CompatibleEquipments.CompatibleEquipments[m].SpecificIngredient != (Object)null)
					{
						hashSet.Add(LocalizationManager.Instance.GetItemName(__instance.Recipes[l].CompatibleEquipments.CompatibleEquipments[m].SpecificIngredient.ItemID));
					}
				}
			}
			StringBuilder stringBuilder4 = new StringBuilder();
			int num = 0;
			foreach (string item in hashSet)
			{
				if (num >= 1)
				{
					stringBuilder4.Append(", ");
				}
				stringBuilder4.Append(item);
				num++;
			}
			if (!flag)
			{
				stringBuilder.AppendLine(LocalizationManager.Instance.GetLoc("EnchantmentCondition_Equipment") + ": " + stringBuilder3.ToString());
				stringBuilder.AppendLine(LocalizationManager.Instance.GetLoc("EnchantmentCondition_Type") + ": " + stringBuilder4.ToString());
			}
			else
			{
				stringBuilder.AppendLine(LocalizationManager.Instance.GetLoc("EnchantmentCondition_Equipment") + ": " + stringBuilder4.ToString());
			}
			stringBuilder.AppendLine("");
			Log.LogMessage((object)$"EnchantmentRecipeItem_ProcessDescription {((Item)__instance).Name} with {__instance.Recipes.Length} recipes");
			for (int n = 0; n < __instance.Recipes.Length; n++)
			{
				EnchantmentRecipe val = __instance.Recipes[n];
				Log.LogMessage((object)$"Recipe {n} {val.RecipeID} {((Object)val).name}.");
				tag = val.CompatibleEquipments.EquipmentTag.Tag;
				if (((Tag)(ref tag)).IsSet)
				{
					Log.LogMessage((object)("Recipe " + ((Object)val).name + " EquipmentTag= " + val.CompatibleEquipments.EquipmentTag.Tag.TagName + "."));
				}
				else
				{
					Log.LogMessage((object)("Recipe " + ((Object)val).name + " EquipmentTag null."));
				}
				for (int num2 = 0; num2 < val.CompatibleEquipments.CompatibleEquipments.Length; num2++)
				{
					IngredientData val2 = val.CompatibleEquipments.CompatibleEquipments[num2];
					Log.LogMessage((object)$"Recipe Ingredient {num2} type= {((object)(IngredientType)(ref val2.Type)).ToString()}.");
					if (val2.IngredientTag != null)
					{
						Log.LogMessage((object)$"Recipe Ingredient {num2} tag= {((object)val2.IngredientTag).ToString()} .");
						tag = val2.IngredientTag.Tag;
						if (((Tag)(ref tag)).IsSet)
						{
							Log.LogMessage((object)$"Recipe Ingredient {num2} IngredientTag= {val2.IngredientTag.Tag.TagName}.");
						}
						else
						{
							Log.LogMessage((object)$"Recipe Ingredient {num2} IngredientTag not set.");
						}
					}
					else
					{
						Log.LogMessage((object)$"Recipe Ingredient {num2} IngredientTag null.");
					}
					if ((Object)(object)val2.SpecificIngredient != (Object)null)
					{
						Log.LogMessage((object)$"Recipe Ingredient {num2} SpecificIngredient= {((object)val2.SpecificIngredient).ToString()} Name= {val2.SpecificIngredient.Name} ItemId={val2.SpecificIngredient.ItemID}.");
					}
					else
					{
						Log.LogMessage((object)$"Recipe Ingredient {num2} SpecificIngredient null.");
					}
				}
			}
			bool flag2 = false;
			StringBuilder stringBuilder5 = new StringBuilder();
			for (int num3 = 0; num3 < __instance.Recipes[0].TimeOfDay.Length; num3++)
			{
				if (flag2)
				{
					stringBuilder5.Append(", ");
				}
				if (__instance.Recipes[0].TimeOfDay[num3].x == 18f && __instance.Recipes[0].TimeOfDay[num3].y == 5f)
				{
					stringBuilder5.Append(LocalizationManager.Instance.GetLoc("TimeOfDay_Night"));
				}
				else if (__instance.Recipes[0].TimeOfDay[num3].x == 5f && __instance.Recipes[0].TimeOfDay[num3].y == 18f)
				{
					stringBuilder5.Append(LocalizationManager.Instance.GetLoc("TimeOfDay_Day"));
				}
				else
				{
					stringBuilder5.Append($"Between {__instance.Recipes[0].TimeOfDay[num3].x} and {__instance.Recipes[0].TimeOfDay[num3].y}");
				}
				flag2 = true;
			}
			if (UnityEngineExtensions.Contains<TemperatureSteps>(__instance.Recipes[0].Temperature, (TemperatureSteps)2))
			{
				if (flag2)
				{
					stringBuilder5.Append(", ");
				}
				stringBuilder5.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_ColdWeather"));
				flag2 = true;
			}
			if (UnityEngineExtensions.Contains<TemperatureSteps>(__instance.Recipes[0].Temperature, (TemperatureSteps)6))
			{
				if (flag2)
				{
					stringBuilder5.Append(", ");
				}
				stringBuilder5.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_HotWeather"));
				flag2 = true;
			}
			if (__instance.Recipes[0].WindAltarActivated)
			{
				if (flag2)
				{
					stringBuilder5.Append(", ");
				}
				stringBuilder5.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_WindAltar"));
				flag2 = true;
			}
			if (__instance.Recipes[0].Weather.Length != 0)
			{
				for (int num4 = 0; num4 < __instance.Recipes[0].Weather.Length; num4++)
				{
					if (flag2)
					{
						stringBuilder5.Append(", ");
					}
					WeaterType weather = __instance.Recipes[0].Weather[num4].Weather;
					switch ((int)weather)
					{
					case 0:
						stringBuilder5.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_WeatherClear"));
						flag2 = true;
						break;
					case 1:
						stringBuilder5.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_WeatherRain"));
						flag2 = true;
						break;
					case 2:
						stringBuilder5.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_WeatherSnow"));
						flag2 = true;
						break;
					case 3:
						stringBuilder5.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_WeatherFog"));
						flag2 = true;
						break;
					}
				}
			}
			if (flag2)
			{
				stringBuilder.AppendLine(LocalizationManager.Instance.GetLoc("EnchantmentCondition_ExtraConditions") + ": " + stringBuilder5.ToString());
			}
			if (string.IsNullOrEmpty(__instance.Recipes[0].OverrideRegionLocKey))
			{
				if (__instance.Recipes[0].Region != null && __instance.Recipes[0].Region.Length != 0)
				{
					StringBuilder stringBuilder6 = new StringBuilder();
					if (UnityEngineExtensions.SequenceEqualExt<AreaEnum>((IList<AreaEnum>)__instance.Recipes[0].Region, (IList<AreaEnum>)AreaManager.Regions))
					{
						stringBuilder6.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_Outdoors"));
					}
					else if (UnityEngineExtensions.SequenceEqualExt<AreaEnum>((IList<AreaEnum>)__instance.Recipes[0].Region, (IList<AreaEnum>)AreaManager.TrogDungeons))
					{
						stringBuilder6.Append(LocalizationManager.Instance.GetLoc("EnchantmentCondition_TrogDungeons"));
					}
					else
					{
						for (int num5 = 0; num5 < __instance.Recipes[0].Region.Length; num5++)
						{
							if (num5 >= 1)
							{
								stringBuilder6.Append(", ");
							}
							stringBuilder6.Append(AreaManager.Instance.GetAreaName(__instance.Recipes[0].Region[num5]));
						}
					}
					stringBuilder.AppendLine(LocalizationManager.Instance.GetLoc("EnchantmentCondition_Locations") + ": " + stringBuilder6.ToString());
				}
			}
			else
			{
				stringBuilder.AppendLine(string.Concat(str2: (!__instance.Recipes[0].OverrideRegionLocKey.StartsWith("BuildingID_")) ? LocalizationManager.Instance.GetLoc(__instance.Recipes[0].OverrideRegionLocKey) : ((!int.TryParse(__instance.Recipes[0].OverrideRegionLocKey.Replace("BuildingID_", ""), out var result)) ? LocalizationManager.Instance.GetLoc(__instance.Recipes[0].OverrideRegionLocKey) : LocalizationManager.Instance.GetItemName(result)), str0: LocalizationManager.Instance.GetLoc("EnchantmentCondition_Locations"), str1: ": "));
			}
			((Item)__instance).m_localizedDescription = stringBuilder.ToString();
			return false;
		}
	}
}
namespace EnchantmentRunicChannel
{
	[BepInPlugin("Tchernobill.EnchantmentRunicChannel", "EnchantmentRunicChannel", "1.0.3")]
	public class EnchantmentRunicChannel : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(AttackSkill), "OwnerHasAllRequiredItems")]
		public class AttackSkill_OwnerHasAllRequiredItems
		{
			[HarmonyPrefix]
			public static bool Prefix(AttackSkill __instance, ref bool __result)
			{
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				if (IsRune(__instance))
				{
					CharacterEquipment equipment = ((EffectSynchronizer)__instance).OwnerCharacter.Inventory.Equipment;
					for (int i = 0; i < equipment.m_equipmentSlots.Length; i++)
					{
						EquipmentSlot val = equipment.m_equipmentSlots[i];
						if (!((Object)(object)val != (Object)null) || !Object.op_Implicit((Object)(object)val.EquippedItem))
						{
							continue;
						}
						for (int j = 0; j < __instance.RequiredTags.Length; j++)
						{
							if (((Item)val.EquippedItem).HasTag(__instance.RequiredTags[j].Tag))
							{
								__result = true;
								return false;
							}
						}
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(Equipment), "AddEnchantment", new Type[]
		{
			typeof(int),
			typeof(bool)
		})]
		public class Equipment_AddEnchantment
		{
			[HarmonyPrefix]
			public static bool Prefix(Equipment __instance, ref int _enchantmentID, ref bool _fromSync)
			{
				//IL_0020: 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)
				if (_enchantmentID == -71000)
				{
					Tag? lexiconTag = GetLexiconTag();
					if (lexiconTag.HasValue)
					{
						((TagListSelectorComponent)((Item)__instance).m_tagSource).AddTag(lexiconTag.Value);
						Log.LogMessage((object)string.Format("{0} {1} Equipment_AddEnchantment Runic Channel({2}) adds {3} Tag on {4}", "EnchantmentRunicChannel", "1.0.3", _enchantmentID, lexiconTag.Value.TagName, ((Item)__instance).Name));
					}
				}
				return true;
			}
		}

		public const string GUID = "Tchernobill.EnchantmentRunicChannel";

		public const string NAME = "EnchantmentRunicChannel";

		public const string VERSION = "1.0.3";

		internal static ManualLogSource Log;

		private static List<int> runesList = new List<int> { 8100210, 8100220, 8100230, 8100240 };

		public const int runicChannel = -71000;

		public const string lexiconTagName = "Lexicon";

		private static Tag? lexiconTag = null;

		internal void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			new Harmony("Tchernobill.EnchantmentRunicChannel").PatchAll();
		}

		public static Tag? GetLexiconTag()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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)
			if (!lexiconTag.HasValue)
			{
				foreach (Tag dbTag in TagSourceManager.Instance.DbTags)
				{
					if (dbTag.TagName == "Lexicon")
					{
						return lexiconTag = dbTag;
					}
				}
				return null;
			}
			return lexiconTag;
		}

		public static bool IsRune(AttackSkill instance)
		{
			foreach (int runes in runesList)
			{
				if (((Item)instance).ItemID == runes)
				{
					return true;
				}
			}
			return false;
		}
	}
}