Decompiled source of Innate Enchantments v1.1.0

BepInEx/plugins/com.binbin.InnateEnchantments.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Cards;
using HarmonyLib;
using InnateEnchantments;
using Microsoft.CodeAnalysis;
using Obeliskial_Essentials;

[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("com.binbin.InnateEnchantments")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+bbe941cef6aa3566a5fbf8b2fbf98a9dacdf3d22")]
[assembly: AssemblyProduct("InnateEnchantments")]
[assembly: AssemblyTitle("com.binbin.InnateEnchantments")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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;
		}
	}
}
public static class EssentialsCompatibility
{
	private static bool? _enabled;

	public static bool Enabled
	{
		get
		{
			bool valueOrDefault = _enabled == true;
			if (!_enabled.HasValue)
			{
				valueOrDefault = Chainloader.PluginInfos.ContainsKey("com.stiffmeds.obeliskialessentials");
				_enabled = valueOrDefault;
			}
			return _enabled.Value;
		}
	}

	[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
	public static void EssentialsRegister()
	{
		Essentials.RegisterMod(Plugin.PluginName, "binbin", "Innate Enchantments", Plugin.PluginVersion, Plugin.ModDate, "https://github.com/binbinmods/InnateEnchantments", (string[])null, "", 100, (string[])null, "", true);
		Plugin.LogInfo(Plugin.PluginGUID + " " + Plugin.PluginVersion + " has loaded with Essentials!");
	}
}
namespace InnateEnchantments
{
	[HarmonyPatch]
	public class AntiCheat
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetObeliskScore")]
		public static bool SetObeliskScorePrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetScore")]
		public static bool SetScorePrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetSingularityScore")]
		public static bool SetSingularityScorePrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetObeliskScoreLeaderboard")]
		public static bool SetObeliskScoreLeaderboardPrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetScoreLeaderboard")]
		public static bool SetScoreLeaderboardPrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetSingularityScoreLeaderboard")]
		public static bool SetSingularityScoreLeaderboardPrefix(ref SteamManager __instance, int score, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetWeeklyScore")]
		public static bool SetWeeklyScorePrefix(ref SteamManager __instance, int score, int week, string nick, string nickgroup, bool singleplayer = true)
		{
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(SteamManager), "SetWeeklyScoreLeaderboard")]
		public static bool SetWeeklyScoreLeaderboardPrefix(ref SteamManager __instance, int score, int week, string nick, string nickgroup, bool singleplayer = true)
		{
			return false;
		}
	}
	public class InnateEnchantmentsFunctions
	{
		public static bool CardShouldBeInnate(CardRealtimeData card)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			return card.HasCardType((CardType)28) && ((int)card.CardClass == 9 || ((int)card.CardClass == 5 && Plugin.ApplyToMonsterEnchantments.Value) || ((int)card.CardClass != 5 && Plugin.ApplyToNonSpecialEnchantments.Value));
		}

		public static bool CardShouldBeInnate(CardDataNew card)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Invalid comparison between Unknown and I4
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Invalid comparison between Unknown and I4
			return (int)card.CardType == 28 && ((int)card.CardClass == 9 || ((int)card.CardClass == 5 && Plugin.ApplyToMonsterEnchantments.Value) || ((int)card.CardClass != 5 && Plugin.ApplyToNonSpecialEnchantments.Value));
		}

		public static void SetInnateFlag(CardRealtimeData cardData)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)cardData).Field("flags");
			val.SetValue((object)(CustomFlags)(val.GetValue<CustomFlags>() | 2));
		}

		public static void SetInnateFlag(CardDataNew cardData)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)cardData).Field("flags");
			val.SetValue((object)(CustomFlags)(val.GetValue<CustomFlags>() | 2));
		}
	}
	[HarmonyPatch]
	public class InnateEnchantmentsPatches
	{
		public static bool devMode;

		public static bool bSelectingPerk;

		public static bool IsHost()
		{
			return GameManager.Instance.IsMultiplayer() && NetworkManager.Instance.IsMaster();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(Globals), "CreateGameContentRoutine")]
		public static void CreateGameContentRoutinePostfix(ref IEnumerator __result)
		{
			if (Plugin.EnableMod.Value)
			{
				try
				{
					__result = Plugin.RunAfter(__result, CreateGameContentPostfix);
					return;
				}
				catch (Exception ex)
				{
					Plugin.LogError("Error: " + ex.Message, "CreateGameContentRoutinePostfix");
					Plugin.LogError("Stack trace: " + ex.StackTrace, "CreateGameContentRoutinePostfix");
					return;
				}
			}
			Plugin.LogDebug("Mod is disabled. Returning.", "CreateGameContentRoutinePostfix");
		}

		public static void CreateGameContentPostfix()
		{
			Plugin.LogDebug("Checking cards to make innate...", "CreateGameContentPostfix");
			Dictionary<string, CardRealtimeData> value = Traverse.Create((object)Globals.Instance).Field("_Cards").GetValue<Dictionary<string, CardRealtimeData>>();
			Dictionary<string, CardRealtimeData> dictionary = new Dictionary<string, CardRealtimeData>(value);
			Dictionary<string, CardDataNew> value2 = Traverse.Create((object)Globals.Instance).Field("_CardsSource").GetValue<Dictionary<string, CardDataNew>>();
			Dictionary<string, CardDataNew> dictionary2 = new Dictionary<string, CardDataNew>(value2);
			if (value == null)
			{
				Plugin.LogError("Cards Dictionary is null", "CreateGameContentPostfix");
				return;
			}
			if (value2 == null)
			{
				Plugin.LogError("CardsSource Dictionary is null", "CreateGameContentPostfix");
				return;
			}
			HashSet<string> hashSet = new HashSet<string>();
			foreach (KeyValuePair<string, CardRealtimeData> item in value)
			{
				string key = item.Key;
				CardRealtimeData value3 = item.Value;
				if (InnateEnchantmentsFunctions.CardShouldBeInnate(value3))
				{
					InnateEnchantmentsFunctions.SetInnateFlag(value3);
					dictionary[key] = value3;
					if (!hashSet.Contains(value3.CardName))
					{
						Plugin.LogDebug($"Card {value3.CardName} has been updated. Innate is {value3.HasFlag((CustomFlags)2)}.", "CreateGameContentPostfix");
					}
					hashSet.Add(value3.CardName);
				}
			}
			foreach (KeyValuePair<string, CardDataNew> item2 in value2)
			{
				string key2 = item2.Key;
				CardDataNew value4 = item2.Value;
				if (InnateEnchantmentsFunctions.CardShouldBeInnate(value4))
				{
					InnateEnchantmentsFunctions.SetInnateFlag(value4);
					dictionary2[key2] = value4;
				}
			}
			Traverse.Create((object)Globals.Instance).Field("_Cards").SetValue((object)dictionary);
			Traverse.Create((object)Globals.Instance).Field("_CardsSource").SetValue((object)dictionary2);
			Plugin.LogDebug("Cards Dictionary has been updated", "CreateGameContentPostfix");
		}
	}
	[BepInPlugin("com.binbin.InnateEnchantments", "InnateEnchantments", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("AcrossTheObelisk.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public static string PluginName;

		public static string PluginVersion;

		public static string PluginGUID;

		internal static int ModDate = int.Parse(DateTime.Today.ToString("yyyyMMdd"));

		private readonly Harmony harmony = new Harmony("com.binbin.InnateEnchantments");

		internal static ManualLogSource Log;

		public static string debugBase = "com.binbin.InnateEnchantments ";

		public static ConfigEntry<bool> EnableMod { get; set; }

		public static ConfigEntry<bool> EnableDebugging { get; set; }

		public static ConfigEntry<bool> ApplyToMonsterEnchantments { get; set; }

		public static ConfigEntry<bool> ApplyToNonSpecialEnchantments { get; set; }

		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0039: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			//IL_0066: Expected O, but got Unknown
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_0093: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00c0: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			string text = "InnateEnchantments";
			EnableMod = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "EnableMod"), true, new ConfigDescription("Enables the mod. If false, the mod will not work then next time you load the game.", (AcceptableValueBase)null, Array.Empty<object>()));
			EnableDebugging = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "EnableDebugging"), false, new ConfigDescription("Enables the debugging", (AcceptableValueBase)null, Array.Empty<object>()));
			ApplyToMonsterEnchantments = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "ApplyToMonsterEnchantments"), false, new ConfigDescription("Makes all monster enchantments innate as well.", (AcceptableValueBase)null, Array.Empty<object>()));
			ApplyToNonSpecialEnchantments = ((BaseUnityPlugin)this).Config.Bind<bool>(new ConfigDefinition(text, "ApplyToNonSpecialEnchantments"), false, new ConfigDescription("Makes non-special enchantments innate as well. This applies to modded enchantments.", (AcceptableValueBase)null, Array.Empty<object>()));
			PluginName = "InnateEnchantments";
			PluginVersion = "1.1.0";
			PluginGUID = "com.binbin.InnateEnchantments";
			if (EnableMod.Value)
			{
				if (EssentialsCompatibility.Enabled)
				{
					EssentialsCompatibility.EssentialsRegister();
				}
				else
				{
					LogInfo(PluginGUID + " " + PluginVersion + " has loaded!");
				}
				harmony.PatchAll();
			}
		}

		internal static void LogDebug(string msg, [CallerMemberName] string caller = "")
		{
			if (EnableDebugging.Value)
			{
				Log.LogDebug((object)(debugBase + "- " + caller + " - " + msg));
			}
		}

		internal static void LogInfo(string msg)
		{
			Log.LogInfo((object)(debugBase + msg));
		}

		internal static void LogError(string msg, [CallerMemberName] string caller = "")
		{
			Log.LogError((object)(debugBase + "- " + caller + " - " + msg));
		}

		public static IEnumerator RunAfter(IEnumerator original, Action action)
		{
			while (original.MoveNext())
			{
				yield return original.Current;
			}
			action();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.binbin.InnateEnchantments";

		public const string PLUGIN_NAME = "InnateEnchantments";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}