Decompiled source of PersistentRebirth v1.0.3

PersistentRebirth.dll

Decompiled 4 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RoR2;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PersistentRebirth")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d499e3e7f47576ef7dda072463273a315406e375")]
[assembly: AssemblyProduct("PersistentRebirth")]
[assembly: AssemblyTitle("PersistentRebirth")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 MiscFixes
{
	[BepInPlugin("comscore.PersistentRebirth", "PersistentRebirth", "1.0.3")]
	public class PersistentRebirthPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Run))]
		public class Rebirth
		{
			[HarmonyPatch("ServerGiveRebirthItems")]
			[HarmonyILManipulator]
			public static void GiveItem(ILContext il)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected O, but got Unknown
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val = new ILCursor(il);
				int num2 = default(int);
				int num = default(int);
				if (val.TryGotoNext((MoveType)1, new Func<Instruction, bool>[3]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num2),
					(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, ref num),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)AccessTools.PropertySetter(typeof(NetworkUser), "NetworkrebirthItem"))
				}))
				{
					ILLabel val2 = val.DefineLabel();
					val.Emit(OpCodes.Br, (object)val2);
					val.GotoNext((MoveType)2, new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)AccessTools.PropertySetter(typeof(NetworkUser), "NetworkrebirthItem"))
					});
					val.MarkLabel(val2);
				}
				else
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)"Unable to find IL for Run.ServerGiveRebirthItems, this mod may not work as intended!");
				}
			}

			[HarmonyPatch("Start")]
			[HarmonyILManipulator]
			public static void RunStart(ILContext il)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected O, but got Unknown
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				ILCursor val = new ILCursor(il);
				int num = default(int);
				if (val.TryGotoNext((MoveType)1, new Func<Instruction, bool>[5]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, ref num),
					(Instruction x) => ILPatternMatchingExt.MatchLdfld<NetworkUser>(x, "localUser"),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)AccessTools.PropertyGetter(typeof(LocalUser), "userProfile")),
					(Instruction x) => ILPatternMatchingExt.MatchLdnull(x),
					(Instruction x) => ILPatternMatchingExt.MatchStfld<UserProfile>(x, "RebirthItem")
				}))
				{
					ILLabel val2 = val.DefineLabel();
					val.Emit(OpCodes.Br, (object)val2);
					val.GotoNext(new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchStfld<UserProfile>(x, "RebirthItem")
					});
					val.MarkLabel(val2);
				}
				else
				{
					((BaseUnityPlugin)Instance).Logger.LogError((object)"Unable to find IL for Run.Start, this mod may not work as intended!");
				}
			}
		}

		public const string PluginGUID = "comscore.PersistentRebirth";

		public const string PluginAuthor = "score";

		public const string PluginName = "PersistentRebirth";

		public const string PluginVersion = "1.0.3";

		private ConfigEntry<bool> useDefault;

		private ConfigEntry<bool> overwriteStorage;

		private ConfigEntry<string> defaultItem;

		public static PersistentRebirthPlugin Instance { get; private set; }

		public void Awake()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			useDefault = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Defaults", "Use Custom Default", false, "Should this setting override the random default item? Applies when signing to your RoR2 profile on the main menu.");
			overwriteStorage = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Defaults", "Force Overwrite Storage", false, "If set to true, the stored item will be overwritten when signing into your profile. Use with caution. Setting will disable itself after overwriting an item.");
			defaultItem = ((BaseUnityPlugin)this).Config.Bind<string>("Item Defaults", "Default Item Name", "", "Sets the default rebirth item if there isn't one already stored. Use internal names.");
			LocalUserManager.onUserSignIn += LocalUserManager_onUserSignIn;
			new Harmony("comscore.PersistentRebirth").CreateClassProcessor(typeof(Rebirth)).Patch();
		}

		private void LocalUserManager_onUserSignIn(LocalUser user)
		{
			//IL_0060: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			if (!useDefault.Value || ((user != null) ? user.userProfile : null) == null)
			{
				return;
			}
			bool flag = string.IsNullOrEmpty(user.userProfile.RebirthItem);
			if (flag || overwriteStorage.Value)
			{
				if (!string.IsNullOrWhiteSpace(defaultItem.Value))
				{
					PickupIndex val = PickupCatalog.FindPickupIndex(ItemCatalog.FindItemIndex(defaultItem.Value));
					if (val != PickupIndex.none)
					{
						if (!flag)
						{
							((BaseUnityPlugin)Instance).Logger.LogWarning((object)("Force overwriting item " + user.userProfile.RebirthItem + " and replacing it with " + defaultItem.Value + "! Force Overwrite setting will now be disabled."));
							overwriteStorage.Value = false;
						}
						user.userProfile.RebirthItem = PickupCatalog.GetPickupDef(val).internalName;
					}
					else
					{
						((BaseUnityPlugin)Instance).Logger.LogError((object)("Could not find item named " + defaultItem.Value + "! Default rebirth item has not been applied!"));
					}
				}
				else if (overwriteStorage.Value)
				{
					((BaseUnityPlugin)Instance).Logger.LogWarning((object)("Force removing item " + (user.userProfile.RebirthItem ?? "NULL") + "! You will not have any stored item now. Force Overwrite setting will now be disabled."));
					overwriteStorage.Value = false;
					user.userProfile.RebirthItem = null;
				}
				else
				{
					((BaseUnityPlugin)Instance).Logger.LogWarning((object)"No default rebirth item has been configured! Default has not been applied!");
				}
			}
			else
			{
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)("User already has rebirth item " + user.userProfile.RebirthItem + "! Default rebirth item has not been applied!"));
			}
		}
	}
}