Decompiled source of KeepMyCharacter v1.0.1

plugins/KeepMyCharacter/KeepMyCharacter.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Reptile;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("KeepMyCharacter")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KeepMyCharacter")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("872cd37c-778b-4975-a043-d64b76933aa8")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace KeepMyCharacter
{
	public static class Extensions
	{
		private static BindingFlags flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		public static T GetValue<T>(this object input, string name, params object[] methodParams)
		{
			if (input.GetMember(name, out var member))
			{
				switch (member.MemberType)
				{
				case MemberTypes.Field:
					return (T)(member as FieldInfo).GetValue(input);
				case MemberTypes.Property:
					return (T)(member as PropertyInfo).GetValue(input, null);
				case MemberTypes.Method:
					return (T)(member as MethodInfo).Invoke(input, methodParams);
				}
			}
			return default(T);
		}

		public static T GetMember<T>(this object input, string name) where T : MemberInfo
		{
			if (input.GetMember(name, out var member))
			{
				return (T)member;
			}
			return null;
		}

		private static bool GetMember(this object input, string name, out MemberInfo member)
		{
			MemberInfo[] member2 = input.GetType().GetMember(name, flags);
			if (member2 != null && member2.Length != 0)
			{
				member = member2.First();
				return true;
			}
			Debug.LogError((object)("No Member \"" + name + "\" Could Be Found..."));
			member = null;
			return false;
		}
	}
	[BepInPlugin("ninjacookie.brc.keepmycharacter", "KeepMyCharacter", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string pluginGuid = "ninjacookie.brc.keepmycharacter";

		public const string pluginName = "KeepMyCharacter";

		public const string pluginVersion = "1.0.1";

		public void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("ninjacookie.brc.keepmycharacter").PatchAll();
		}
	}
}
namespace KeepMyCharacter.Patches
{
	internal class Patch_KeepCharacter : HarmonyPatch
	{
		[HarmonyPatch(typeof(ProgressObject), "SetPlayerAsCharacter", new Type[] { typeof(Characters) })]
		public static class ProgressObject_SetPlayerAsCharacter_Patch
		{
			public static void Prefix(ref Characters character)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected I4, but got Unknown
				character = (Characters)(int)GetCurrentCharacter();
			}
		}

		[HarmonyPatch(typeof(ProgressObject), "SetPlayerAsCharacter", new Type[] { typeof(string) })]
		public static class ProgressObject_SetPlayerAsCharacter_String_Patch
		{
			public static void Prefix(ref string character)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				Characters currentCharacter = GetCurrentCharacter();
				character = ((object)(Characters)(ref currentCharacter)).ToString();
			}
		}

		[HarmonyPatch(typeof(Encounter), "SetPlayerAsCharacter")]
		public static class Encounter_SetPlayerAsCharacter_Patch
		{
			public static void Prefix(ref Characters character)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected I4, but got Unknown
				character = (Characters)(int)GetCurrentCharacter();
			}
		}

		[HarmonyPatch(typeof(NPC), "SetPlayerAsHeadmanWithJetpack")]
		public static class NPC_SetPlayerAsHeadmanWithJetpack_Patch
		{
			public static bool Prefix()
			{
				return false;
			}
		}

		private static Characters GetCurrentCharacter()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			WorldHandler instance = WorldHandler.instance;
			Player val = ((instance != null) ? instance.GetCurrentPlayer() : null);
			if ((Object)(object)val != (Object)null)
			{
				return val.GetValue<Characters>("character", Array.Empty<object>());
			}
			return (Characters)0;
		}
	}
}