Decompiled source of ReplaceConsumableItemDescriptions v2.0.1

ReplaceItemDescriptions.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[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")]
[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 ReplaceItemDescriptions;

[BepInPlugin("theGrungler.ReplaceItemDescriptions", "ReplaceItemDescriptions", "1.0.0")]
public class ReplaceItemDescriptions : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Character), "Awake")]
	public class ReplacePrefabDescriptions
	{
		[HarmonyPostfix]
		public static void Awake(Character __instance)
		{
			if (runAlready)
			{
				return;
			}
			Log.LogMessage((object)"Loading ResourcesPrefabManager");
			ResourcesPrefabManager instance = ResourcesPrefabManager.Instance;
			if (!instance.Loaded)
			{
				Log.LogMessage((object)"Manager not Initialized");
				return;
			}
			Dictionary<string, Item> iTEM_PREFABS = ResourcesPrefabManager.ITEM_PREFABS;
			KeyValuePair<string, Item>[] array = iTEM_PREFABS.ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				KeyValuePair<string, Item> keyValuePair = array[i];
				try
				{
					Item itemPrefab = instance.GetItemPrefab(keyValuePair.Value.ItemID);
					if (!itemPrefab.IsUsable)
					{
						continue;
					}
					Transform transform = ((Component)itemPrefab).transform;
					if ((Object)(object)transform == (Object)null)
					{
						continue;
					}
					Transform val = transform.Find("Effects");
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Effect[] components = ((Component)val).GetComponents<Effect>();
					if (components.Length != 0)
					{
						StringBuilder stringBuilder = new StringBuilder();
						Effect[] array2 = components;
						foreach (Effect effect in array2)
						{
							appendStatusText(stringBuilder, effect);
						}
						if (stringBuilder.Length != 0)
						{
							stringBuilder.Append("\n");
							stringBuilder.Append(itemPrefab.Description);
							AccessTools.Field(typeof(Item), "m_localizedDescription").SetValue(itemPrefab, stringBuilder.ToString());
						}
					}
				}
				catch (Exception)
				{
				}
			}
			runAlready = true;
		}
	}

	[HarmonyPatch(typeof(Item), "BaseInit")]
	public class Item_BaseInit
	{
		[HarmonyPostfix]
		public static void BaseInit(Item __instance)
		{
			try
			{
				if (!__instance.IsUsable)
				{
					return;
				}
				Transform transform = ((Component)__instance).transform;
				if ((Object)(object)transform == (Object)null)
				{
					return;
				}
				Transform val = transform.Find("Effects");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				Effect[] components = ((Component)val).GetComponents<Effect>();
				if (components.Length != 0)
				{
					StringBuilder stringBuilder = new StringBuilder();
					Log.LogMessage((object)((Object)__instance).name);
					Effect[] array = components;
					foreach (Effect effect in array)
					{
						appendStatusText(stringBuilder, effect);
					}
					if (stringBuilder.Length != 0)
					{
						stringBuilder.Append("\n");
						stringBuilder.Append(__instance.Description);
						AccessTools.Field(typeof(Item), "m_localizedDescription").SetValue(__instance, stringBuilder.ToString());
					}
				}
			}
			catch (Exception)
			{
			}
		}
	}

	public const string GUID = "theGrungler.ReplaceItemDescriptions";

	public const string NAME = "ReplaceItemDescriptions";

	public const string VERSION = "1.0.0";

	public const string DISPLAY_NAME = "ReplaceItemDescriptions";

	internal static bool runAlready;

	internal static ManualLogSource Log;

	private static Harmony _harmony;

	internal void Awake()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogMessage((object)"Starting ReplaceItemDescriptions 1.0.0!");
		InitializeConfig();
		_harmony = new Harmony("theGrungler.ReplaceItemDescriptions");
		_harmony.PatchAll();
	}

	private static void appendStatusText(StringBuilder sb, Effect effect)
	{
		//IL_001c: 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_0090: 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_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: 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_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0300: Expected O, but got Unknown
		//IL_0324: Unknown result type (might be due to invalid IL or missing references)
		//IL_0373: Unknown result type (might be due to invalid IL or missing references)
		if (((object)effect).GetType() == typeof(AddStatusEffect))
		{
			StatusEffect status = ((AddStatusEffect)effect).Status;
			sb.AppendLine(status.IdentifierName);
		}
		else if (((object)effect).GetType() == typeof(AddBoonEffect))
		{
			StatusEffect status2 = ((AddStatusEffect)(AddBoonEffect)effect).Status;
			sb.AppendLine(status2.StatusName);
		}
		else if (((object)effect).GetType() == typeof(ImbueWeapon))
		{
			ImbueEffectPreset imbuedEffect = ((ImbueObject)(ImbueWeapon)effect).ImbuedEffect;
			sb.AppendLine(imbuedEffect.Name);
		}
		else if (((object)effect).GetType() == typeof(AffectBurntHealth))
		{
			float affectQuantity = ((AffectBurntHealth)effect).AffectQuantity;
			sb.AppendLine("Burnt Health " + affectQuantity.ToString("-#;+#;0"));
		}
		else if (((object)effect).GetType() == typeof(AffectBurntMana))
		{
			float affectQuantity2 = ((AffectBurntMana)effect).AffectQuantity;
			sb.AppendLine("Burnt Mana " + affectQuantity2.ToString("-#;+#;0"));
		}
		else if (((object)effect).GetType() == typeof(AffectBurntStamina))
		{
			float affectQuantity3 = ((AffectBurntStamina)effect).AffectQuantity;
			sb.AppendLine("Burnt Stamina " + affectQuantity3.ToString("-#;+#;0"));
		}
		else if (((object)effect).GetType() == typeof(AffectCorruption))
		{
			float affectQuantity4 = ((AffectCorruption)effect).AffectQuantity;
			sb.AppendLine("Corruption " + (affectQuantity4 / 10f).ToString("+#;-#;0") + "%");
		}
		else if (((object)effect).GetType() == typeof(AffectHealth))
		{
			float affectQuantity5 = ((AffectHealth)effect).AffectQuantity;
			sb.AppendLine("Health " + affectQuantity5.ToString("+#;-#;0"));
		}
		else if (((object)effect).GetType() == typeof(AffectMana))
		{
			float value = ((AffectMana)effect).Value;
			sb.AppendLine("Mana " + value.ToString("+#;-#;0") + "%");
		}
		else if (((object)effect).GetType() == typeof(AffectStamina))
		{
			float affectQuantity6 = ((AffectStamina)effect).AffectQuantity;
			sb.AppendLine("Stamina " + affectQuantity6.ToString("+#;-#;0"));
		}
		else if (((object)effect).GetType() == typeof(RemoveStatusEffect))
		{
			appendRemoveStatusEffect((RemoveStatusEffect)effect, sb);
		}
		else if (((object)effect).GetType() == typeof(AffectFood))
		{
			sb.AppendLine("Food " + ((AffectNeed)(AffectFood)effect).m_affectQuantity / 10f + "%");
		}
		else if (((object)effect).GetType() == typeof(AffectDrink))
		{
			sb.AppendLine("Drink " + ((AffectNeed)(AffectDrink)effect).m_affectQuantity / 10f + "%");
		}
	}

	private static void appendRemoveStatusEffect(RemoveStatusEffect effect, StringBuilder sb)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Invalid comparison between Unknown and I4
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Invalid comparison between Unknown and I4
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Invalid comparison between Unknown and I4
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Invalid comparison between Unknown and I4
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Invalid comparison between Unknown and I4
		RemoveTypes cleanseType = effect.CleanseType;
		if ((int)cleanseType == 2)
		{
			sb.AppendLine("Remove " + effect.StatusType.Tag.TagName);
		}
		else if ((int)cleanseType == 1)
		{
			sb.AppendLine("Remove " + ((UidSelector<StatusEffectFamily>)(object)effect.StatusFamily).Internal_Get().Name);
		}
		else if ((int)cleanseType == 0)
		{
			sb.AppendLine("Remove " + effect.StatusEffect.IdentifierName);
		}
		else if ((int)cleanseType == 3)
		{
			sb.AppendLine("Remove " + effect.StatusName);
		}
		else if ((int)cleanseType == 4)
		{
			sb.AppendLine("Remove negative statuses");
		}
	}

	internal void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		Log.LogMessage((object)"Destoryed");
		((BaseUnityPlugin)this).Config.Clear();
	}

	private void InitializeConfig()
	{
	}

	internal void Update()
	{
	}
}