Decompiled source of LegendQOL v1.0.0

LegendQOL.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using IL;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using On;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("LegendQOL")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LegendQOL")]
[assembly: AssemblyTitle("LegendQOL")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace LegendQOL;

[BepInPlugin("xyz.yekoc.wizardoflegend.QoL", "Legend QOL", "1.0.0")]
public class LegendQOL : BaseUnityPlugin
{
	public List<TweakBase> tweakList = new List<TweakBase>();

	internal static ManualLogSource Logger { get; set; }

	public void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		tweakList.Add(new OutfitPlus());
		tweakList.Add(new BetterItemDrop());
		tweakList.Add(new UsefulItemPool());
		tweakList.Add(new InformativeGroups());
	}

	public void Start()
	{
		foreach (TweakBase tweak in tweakList)
		{
			tweak.Init(((BaseUnityPlugin)this).Config);
			if (tweak.enabled.Value)
			{
				tweak.Activate();
			}
		}
	}

	public void OnDestroy()
	{
		foreach (TweakBase tweak in tweakList)
		{
			tweak.Deactivate();
		}
		tweakList.Clear();
	}
}
public class TweakBase
{
	public bool active;

	public ConfigEntry<bool> enabled;

	public virtual void Init(ConfigFile config)
	{
		enabled = config.Bind<bool>(GetType().Name, "Enabled", true, "Enables this tweak.");
		enabled.SettingChanged += delegate(object conf, EventArgs val)
		{
			SettingChangedEventArgs e = (SettingChangedEventArgs)(object)((val is SettingChangedEventArgs) ? val : null);
			if ((e.ChangedSetting as ConfigEntry<bool>).Value)
			{
				Activate();
			}
			else
			{
				Deactivate();
			}
		};
	}

	public virtual void Activate()
	{
		active = true;
	}

	public virtual void Deactivate()
	{
		active = false;
	}
}
public class BetterItemDrop : TweakBase
{
	public override void Init(ConfigFile config)
	{
		base.Init(config);
	}

	public override void Activate()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		if (!active)
		{
			Inventory.DropItem += new Manipulator(ItemDropHook);
		}
		base.Activate();
	}

	public override void Deactivate()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		if (active)
		{
			Inventory.DropItem -= new Manipulator(ItemDropHook);
		}
		base.Deactivate();
	}

	internal void ItemDropHook(ILContext il)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Expected O, but got Unknown
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		ILLabel lab = val.DefineLabel();
		if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[2]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(Inventory).GetField("currentItem", (BindingFlags)(-1))),
			(Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref lab)
		}))
		{
			val.MoveAfterLabels();
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Func<Inventory, bool>>((Func<Inventory, bool>)((Inventory inv) => inv.currentItem.destroyOnDrop));
			val.Emit(OpCodes.Brtrue, (object)lab);
		}
	}
}
public class InformativeGroups : TweakBase
{
	private ILHook hook;

	public override void Init(ConfigFile config)
	{
		base.Init(config);
	}

	public override void Activate()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		if (!active)
		{
			hook = new ILHook((MethodBase)typeof(GroupItem).GetProperty("InfoStr", (BindingFlags)(-1)).GetGetMethod(), new Manipulator(GroupInfoHook));
		}
		base.Activate();
	}

	public override void Deactivate()
	{
		if (active)
		{
			hook.Free();
		}
		base.Deactivate();
	}

	internal void GroupInfoHook(ILContext il)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Expected O, but got Unknown
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		ILCursor val = new ILCursor(il);
		val.Emit(OpCodes.Ldarg_0);
		val.EmitDelegate<Action<GroupItem>>((Action<GroupItem>)delegate(GroupItem self)
		{
			self.updateInfoStr = self.itemInven.itemDict.Values.Any((Item i) => i.ExtraInfo != string.Empty);
		});
		if (val.TryGotoNext(new Func<Instruction, bool>[1]
		{
			(Instruction x) => ILPatternMatchingExt.MatchLdstr(x, "\n")
		}))
		{
			val.Emit(OpCodes.Ldarg_0);
			val.Emit(OpCodes.Ldloc_0);
			val.EmitDelegate<Func<string, GroupItem, string, string>>((Func<string, GroupItem, string, string>)delegate(string orig, GroupItem self, string itemName)
			{
				Item item = self.itemInven.GetItem(itemName);
				return orig + ((((item != null) ? item.ExtraInfo : null) != string.Empty) ? (" ( " + self.itemInven.GetItem(itemName).ExtraInfo + " )") : string.Empty);
			});
		}
	}
}
public class OutfitPlus : TweakBase
{
	public override void Init(ConfigFile config)
	{
		base.Init(config);
	}

	public override void Activate()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		if (!active)
		{
			OutfitMenu.LoadMenu += new hook_LoadMenu(OutfitPlusHook);
		}
		base.Activate();
	}

	public override void Deactivate()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		if (active)
		{
			OutfitMenu.LoadMenu -= new hook_LoadMenu(OutfitPlusHook);
		}
		base.Deactivate();
	}

	internal void OutfitPlusHook(orig_LoadMenu orig, OutfitMenu self, Player p)
	{
		orig.Invoke(self, p);
		Text outfitText = self.outfitText;
		outfitText.text += (p.outfitEnhanced ? "+" : "");
	}
}
public class UsefulItemPool : TweakBase
{
	public Dictionary<string, List<string>> toRemove = new Dictionary<string, List<string>> { 
	{
		"RushRunMod",
		new List<string>
		{
			SkillStoreLocatorItem.staticID,
			ItemStoreLocatorItem.staticID,
			MiscRoomLocatorItem.staticID,
			ExitRoomLocatorItem.staticID,
			"TokenCursed"
		}
	} };

	public override void Init(ConfigFile config)
	{
		base.Init(config);
	}

	public override void Activate()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		if (!active)
		{
			LootManager.ResetAvailableItems += new hook_ResetAvailableItems(ResetPoolHook);
		}
		base.Activate();
	}

	public override void Deactivate()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		if (active)
		{
			LootManager.ResetAvailableItems -= new hook_ResetAvailableItems(ResetPoolHook);
		}
		base.Deactivate();
	}

	public void ResetPoolHook(orig_ResetAvailableItems orig)
	{
		orig.Invoke();
		bool flag = true;
		Player[] activePlayers = GameController.activePlayers;
		foreach (Player val in activePlayers)
		{
			if (((VarStat<bool>)(object)val.outfitEnhanceAllowStat).CurrentValue)
			{
				flag = false;
			}
		}
		if (flag)
		{
			LootManager.RemoveIDFromAvailableList("TokenTailor");
		}
		if (!Object.op_Implicit((Object)(object)RunModifier.Instance))
		{
			return;
		}
		foreach (KeyValuePair<string, RunMod> item in RunModifier.Instance.runMods.Where((KeyValuePair<string, RunMod> m) => m.Value != null && toRemove.ContainsKey(m.Key)))
		{
			foreach (string item2 in toRemove[item.Key])
			{
				LootManager.RemoveIDFromAvailableList(item2);
			}
		}
	}
}