Decompiled source of PartialEclipse8 v1.0.1

PartialEclipse8.dll

Decompiled 4 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour.HookGen;
using PartialEclipse8.Properties;
using R2API;
using R2API.Utils;
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.0", FrameworkDisplayName = "")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PartialEclipse8
{
	[BepInPlugin("com.RegalTurtle.PartialEclipse", "Partial Eclipse", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[R2APISubmoduleDependency(new string[] { "LanguageAPI", "RecalculateStatsAPI", "ItemAPI", "EliteAPI", "ContentAddition" })]
	public class PartialEclipse8Plugin : BaseUnityPlugin
	{
		public const string GUID = "com.RegalTurtle.PartialEclipse";

		public const string Name = "Partial Eclipse";

		public const string Version = "1.0.0";

		private static readonly HashSet<NetworkUser> votedForEclipse = new HashSet<NetworkUser>();

		private static readonly MethodInfo damage = typeof(HealthComponent).GetMethod("TakeDamage");

		private static readonly MethodInfo startRun = typeof(PreGameController).GetMethod("StartRun", BindingFlags.Instance | BindingFlags.NonPublic);

		private static void TakeDamage(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[5]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<HealthComponent>(x, "body"),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<CharacterBody>(x, "get_teamComponent"),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<TeamComponent>(x, "get_teamIndex"),
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1)
			});
			val.Emit(OpCodes.Ldloc, 42);
			val.Emit(OpCodes.Ldloc, 7);
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Action<CharacterMaster, float, HealthComponent>>((Action<CharacterMaster, float, HealthComponent>)NewTakeCurse);
		}

		public static bool ShouldTakeCurse(CharacterMaster master)
		{
			if (votedForEclipse.Any((NetworkUser el) => (Object)(object)el.master == (Object)(object)master))
			{
				return true;
			}
			return false;
		}

		public static void NewTakeCurse(CharacterMaster master, float num, HealthComponent that)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Invalid comparison between Unknown and I4
			if ((Object)(object)master != (Object)null && (int)master.teamIndex == 1 && votedForEclipse.Any((NetworkUser el) => (Object)(object)el.master == (Object)(object)master || (Object)(object)el.master == (Object)(object)master.minionOwnership.ownerMaster))
			{
				float num2 = num / that.fullCombinedHealth * 100f;
				float num3 = 0.4f;
				int num4 = Mathf.FloorToInt(num2 * num3);
				for (int i = 0; i < num4; i++)
				{
					that.body.AddBuff(Buffs.PermanentCurse);
				}
			}
		}

		private static void PreGameControllerStartRun(Action<PreGameController> orig, PreGameController self)
		{
			votedForEclipse.Clear();
			RuleChoiceDef val = RuleCatalog.FindChoiceDef("Artifacts.PartialEclipse8.On");
			foreach (NetworkUser readOnlyInstances in NetworkUser.readOnlyInstancesList)
			{
				PreGameRuleVoteController val2 = PreGameRuleVoteController.FindForUser(readOnlyInstances);
				if (val2.IsChoiceVoted(val))
				{
					votedForEclipse.Add(readOnlyInstances);
				}
			}
			orig(self);
		}

		public void Awake()
		{
			new PartialEclipse8Artifact();
		}

		public void Destroy()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			HookEndpointManager.Unmodify((MethodBase)damage, (Delegate)new Manipulator(TakeDamage));
		}

		public void Start()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			HookEndpointManager.Add((MethodBase)startRun, (Delegate)new Action<Action<PreGameController>, PreGameController>(PreGameControllerStartRun));
			HookEndpointManager.Modify((MethodBase)damage, (Delegate)new Manipulator(TakeDamage));
		}
	}
	public class PartialEclipse8Artifact
	{
		public static ArtifactDef artifact;

		public PartialEclipse8Artifact()
		{
			LanguageAPI.Add("PARTIALECLIPSE_PARTIALECLIPSE8_NAME", "Artifact of Partial Eclipse");
			LanguageAPI.Add("PARTIALECLIPSE_PARTIALECLIPSE8_DESC", "Applies Eclipse 8 for people who select the artifact.");
			artifact = ScriptableObject.CreateInstance<ArtifactDef>();
			artifact.cachedName = "PartialEclipse8";
			artifact.nameToken = "PARTIALECLIPSE_PARTIALECLIPSE8_NAME";
			artifact.descriptionToken = "PARTIALECLIPSE_PARTIALECLIPSE8_DESC";
			artifact.smallIconSelectedSprite = CreateSpriteNew("selected");
			artifact.smallIconDeselectedSprite = CreateSpriteNew("deselected");
			ContentAddition.AddArtifactDef(artifact);
		}

		public static Sprite CreateSpriteNew(string fileName)
		{
			return LoadResourceSprite(fileName);
		}

		public static Sprite LoadResourceSprite(string resName)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false);
			Sprite result = null;
			try
			{
				byte[] array = (byte[])Resources.ResourceManager.GetObject(resName);
				ImageConversion.LoadImage(val, array, false);
				val.Apply();
				result = Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(64f, 64f));
			}
			catch (Exception ex)
			{
				Debug.LogError((object)ex.ToString());
			}
			return result;
		}
	}
}
namespace PartialEclipse8.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("PartialEclipse8.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] deselected
		{
			get
			{
				object @object = ResourceManager.GetObject("deselected", resourceCulture);
				return (byte[])@object;
			}
		}

		internal static byte[] selected
		{
			get
			{
				object @object = ResourceManager.GetObject("selected", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Resources()
		{
		}
	}
}