Decompiled source of UnlockAccountModes v1.0.0

BepInEx/plugins/UnlockAccountModes.dll

Decompiled 8 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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("UnlockAccountModes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Removes the server time offset, so in-game time exactly matches system time.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("UnlockAccountModes")]
[assembly: AssemblyTitle("UnlockAccountModes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 UnlockAccountModes
{
	internal static class AccountUnlocks
	{
		private const int FlagAdmin = 2;

		private const int FlagDev = 4;

		private const int FlagBacker = 8;

		private const int FlagEarlyBird = 16;

		private const int FlagSecretCult = 32;

		internal static int ResolveFlags()
		{
			int num = 0;
			if (PluginConfig.EnableDebug.Value)
			{
				num |= 6;
			}
			if (PluginConfig.EnableBacker.Value)
			{
				num |= 8;
			}
			if (PluginConfig.EnableEarlyBird.Value)
			{
				num |= 0x10;
			}
			if (PluginConfig.EnableSecretCultist.Value)
			{
				num |= 0x20;
			}
			return num;
		}

		internal static void ApplyUnlocks(object playerBaseInstance)
		{
			if (playerBaseInstance == null)
			{
				Plugin.Log.LogWarning((object)"playerBaseInstance is null, skipping");
				return;
			}
			int value = ResolveFlags();
			Type enumType = AccessTools.TypeByName("AccountUnlocks");
			object value2 = Enum.ToObject(enumType, value);
			Type type = AccessTools.TypeByName("PlayerBase");
			FieldInfo fieldInfo = AccessTools.Field(type, "accountUnlocks");
			fieldInfo.SetValue(playerBaseInstance, value2);
			PropertyInfo propertyInfo = AccessTools.Property(type, "NetworkaccountUnlocks");
			try
			{
				propertyInfo.SetValue(playerBaseInstance, value2);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("NetworkaccountUnlocks setter threw, continuing: " + ex.Message));
			}
		}
	}
	[BepInPlugin("com.robotic_scarab.unlockaccountmodes", "UnlockAccountModes", "1.0.0")]
	[BepInProcess("BookOfTravels.exe")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			PluginConfig.Init(((BaseUnityPlugin)this).Config);
			new Harmony("com.robotic_scarab.unlockaccountmodes").PatchAll();
			Log.LogInfo((object)"UnlockAccountModes loaded.");
		}
	}
	[HarmonyPatch]
	internal static class Patch_PlayerBase_OnStartLocalPlayer
	{
		private static MethodBase? TargetMethod()
		{
			Type type = AccessTools.TypeByName("PlayerBase");
			return (type == null) ? null : AccessTools.Method(type, "OnStartLocalPlayer", (Type[])null, (Type[])null);
		}

		private static void Postfix(object __instance)
		{
			try
			{
				AccountUnlocks.ApplyUnlocks(__instance);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Patch_PlayerBase_OnStartLocalPlayer threw: {arg}");
			}
		}
	}
	internal static class PluginConfig
	{
		internal static ConfigEntry<bool> EnableDebug;

		internal static ConfigEntry<bool> EnableBacker;

		internal static ConfigEntry<bool> EnableEarlyBird;

		internal static ConfigEntry<bool> EnableSecretCultist;

		internal static void Init(ConfigFile config)
		{
			EnableDebug = config.Bind<bool>("General", "EnableDebugMode", true, "If true, enables the Debug account mode, which allows the debug menu to be opened in-game. If false, mode is not turned on.");
			EnableBacker = config.Bind<bool>("General", "EnableBackerMode", false, "If true, enables the Backer account mode, which allows getting the Traveller's Knapsack from any Trainmasters Stash. If false, mode is not turned on.");
			EnableEarlyBird = config.Bind<bool>("General", "EnableEarlyBirdMode", false, "If true, enables the Early Bird account mode, which allows getting the early bird Lantern of Early Light and Ring of Cycles items from any Trainmasters Stash. If false, mode is not turned on.");
			EnableSecretCultist = config.Bind<bool>("General", "EnableSecretCultistMode", false, "If true, enables the Secret Cultist account mode, which allows getting the Fan of the Hidden from any Trainmasters Stash. If false, mode is not turned on.");
		}
	}
	internal static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.robotic_scarab.unlockaccountmodes";

		public const string PLUGIN_NAME = "UnlockAccountModes";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}