Decompiled source of ChooseYourKarma v0.1.0

ChooseYourKarma.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[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 Prototype
{
	[BepInPlugin("prototype.karma.unlock", "ChooseYourKarma", "0.1.0")]
	internal class ChooseYourKarma : BaseUnityPlugin
	{
		public const string version = "0.1.0";

		public const string identifier = "prototype.karma.unlock";

		protected void Awake()
		{
			Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OnLoad));
		}

		private void OnLoad()
		{
			Language english = Language.english;
			english.SetStringByToken("RULE_HEADER_KARMA_SUBTITLE", "Selecting a <style=cLunarObjective>Karma</style> level will make the final boss fight more challenging.\n\n<i>Challenges can still be unlocked.<i>");
			english.SetStringByToken("RULE_KARMAENABLED_CHOICE_OFF_DESC", "This choice is not available, as <style=cLunarObjective>Karma</style> no longer increases over the course of the run.");
		}

		[HarmonyPatch(typeof(KarmaManager), "SelectValidTriggers")]
		[HarmonyPostfix]
		private static void SelectValidTriggers(KarmaManager __instance)
		{
			__instance.DiscardAllTriggers();
			KarmaManager.onKarmaChangedClient -= __instance.NotifyKarmaIncreaseClient;
		}

		[HarmonyPatch(typeof(RuleDef), "FromKarma")]
		[HarmonyPostfix]
		private static void FromKarma(RuleDef __result)
		{
			foreach (RuleChoiceDef choice in __result.choices)
			{
				object extraData = choice.extraData;
				if (extraData is int && (int)extraData == -1)
				{
					choice.excludeByDefault = true;
				}
				else
				{
					choice.requiredUnlockable = null;
				}
			}
		}

		[HarmonyPatch(typeof(EclipseRun), "OverrideRuleChoices")]
		[HarmonyPostfix]
		private static void OverrideRuleChoices(RuleChoiceMask mustInclude, RuleChoiceMask mustExclude)
		{
			foreach (RuleChoiceDef choice in RuleBook.startingKarmaRule.choices)
			{
				((SerializableBitArray)mustInclude)[choice.globalIndex] = false;
				((SerializableBitArray)mustExclude)[choice.globalIndex] = false;
			}
		}

		[HarmonyPatch(typeof(HUD), "OnEnable")]
		[HarmonyPostfix]
		private static void OnEnable(HUD __instance)
		{
			KarmaIcon componentInChildren = __instance.mainUIPanel.GetComponentInChildren<KarmaIcon>();
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				RectTransform holder = componentInChildren.holder;
				if (Object.op_Implicit((Object)(object)holder))
				{
					((Transform)holder).SetParent(__instance.scoreboardPanel.transform, true);
				}
			}
		}
	}
}