Decompiled source of DisableKarma v1.0.1

plugins/ToggleKarma/ToggleKarma.dll

Decompiled 20 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using RoR2;
using UnityEngine;

[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("ExamplePlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExamplePlugin")]
[assembly: AssemblyTitle("ExamplePlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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;
		}
	}
}
namespace ExamplePlugin
{
	[BepInPlugin("LostKarma.ToggleKarma", "ToggleKarma", "1.0.1")]
	public class ExamplePlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "LostKarma.ToggleKarma";

		public const string PluginAuthor = "LostKarma";

		public const string PluginName = "ToggleKarma";

		public const string PluginVersion = "1.0.1";

		public void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("LostKarma.ToggleKarma");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Karma unlocked on Eclipse.");
		}
	}
	[HarmonyPatch(typeof(EclipseRun), "OverrideRuleChoices")]
	public static class EclipseRunPatches
	{
		[HarmonyPostfix]
		public static void Postfix_OverrideRuleChoices(RuleChoiceMask mustInclude, RuleChoiceMask mustExclude)
		{
			RuleDef val = RuleCatalog.FindRuleDef("Karma.InitialLevel");
			if (val == null)
			{
				return;
			}
			foreach (RuleChoiceDef choice in val.choices)
			{
				((SerializableBitArray)mustInclude)[choice.globalIndex] = false;
				((SerializableBitArray)mustExclude)[choice.globalIndex] = false;
			}
		}
	}
	[HarmonyPatch(typeof(PreGameController), "RecalculateModifierAvailability")]
	public static class PreGameControllerPatches
	{
		[HarmonyPostfix]
		public static void Postfix_RecalculateModifierAvailability(PreGameController __instance)
		{
			RuleDef val = RuleCatalog.FindRuleDef("Karma.InitialLevel");
			if (val == null)
			{
				return;
			}
			Traverse val2 = Traverse.Create((object)__instance);
			RuleChoiceMask value = val2.Field("unlockedChoiceMask").GetValue<RuleChoiceMask>();
			RuleChoiceMask value2 = val2.Field("dependencyChoiceMask").GetValue<RuleChoiceMask>();
			RuleChoiceMask value3 = val2.Field("entitlementChoiceMask").GetValue<RuleChoiceMask>();
			RuleChoiceMask value4 = val2.Field("requiredExpansionEnabledChoiceMask").GetValue<RuleChoiceMask>();
			foreach (RuleChoiceDef choice in val.choices)
			{
				if (value != null)
				{
					((SerializableBitArray)value)[choice.globalIndex] = true;
				}
				if (value2 != null)
				{
					((SerializableBitArray)value2)[choice.globalIndex] = true;
				}
				if (value3 != null)
				{
					((SerializableBitArray)value3)[choice.globalIndex] = true;
				}
				if (value4 != null)
				{
					((SerializableBitArray)value4)[choice.globalIndex] = true;
				}
			}
			val2.Method("ResolveChoiceMask", Array.Empty<object>()).GetValue();
		}
	}
	[HarmonyPatch(typeof(RuleCatalog), "HiddenTestKarmaConvar")]
	public static class RuleCatalogPatches
	{
		[HarmonyPrefix]
		public static bool Prefix_HiddenTestKarmaConvar(ref bool __result)
		{
			__result = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(PreGameController), "EnforceValidRuleChoices")]
	public static class EnforceValidRuleChoicesPatch
	{
		[HarmonyPostfix]
		public static void Postfix_EnforceValidRuleChoices(PreGameController __instance)
		{
			RuleDef val = RuleCatalog.FindRuleDef("Karma.InitialLevel");
			if (val == null)
			{
				return;
			}
			LocalUser firstLocalUser = LocalUserManager.GetFirstLocalUser();
			if (firstLocalUser == null)
			{
				return;
			}
			NetworkUser currentNetworkUser = firstLocalUser.currentNetworkUser;
			if ((Object)(object)currentNetworkUser == (Object)null)
			{
				return;
			}
			PreGameRuleVoteController val2 = PreGameRuleVoteController.FindForUser(currentNetworkUser);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			FieldInfo field = typeof(PreGameRuleVoteController).GetField("votes", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null || !(field.GetValue(val2) is Array array))
			{
				return;
			}
			object value = array.GetValue(val.globalIndex);
			if (value == null)
			{
				return;
			}
			FieldInfo field2 = value.GetType().GetField("internalValue", BindingFlags.Instance | BindingFlags.NonPublic);
			if (!(field2 == null))
			{
				byte b = (byte)field2.GetValue(value);
				int num = b - 1;
				if (num >= 0 && num < val.choices.Count)
				{
					RuleChoiceDef val3 = val.choices[num];
					__instance.ApplyChoice(val3.globalIndex);
				}
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		private static string Format(object data, string file, int line)
		{
			string fileName = Path.GetFileName(file);
			return $"[{fileName}:{line}] {data}";
		}

		internal static void Debug(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogDebug((object)Format(data, file, line));
		}

		internal static void Error(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogError((object)Format(data, file, line));
		}

		internal static void Fatal(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogFatal((object)Format(data, file, line));
		}

		internal static void Info(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogInfo((object)Format(data, file, line));
		}

		internal static void Message(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogMessage((object)Format(data, file, line));
		}

		internal static void Warning(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogWarning((object)Format(data, file, line));
		}
	}
}