Decompiled source of PartialEclipse8 v1.2.2

plugins/PartialEclipse/PartialEclipse.dll

Decompiled 2 weeks 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour.HookGen;
using PartialEclipse.Properties;
using R2API;
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 = "")]
[assembly: AssemblyCompany("PartialEclipse")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PartialEclipse")]
[assembly: AssemblyTitle("PartialEclipse")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace PartialEclipse
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("RegalTurtle.PartialEclipse", "PartialEclipse", "1.2.2")]
	public class PartialEclipse : BaseUnityPlugin
	{
		public const string PluginGUID = "RegalTurtle.PartialEclipse";

		public const string PluginAuthor = "RegalTurtle";

		public const string PluginName = "PartialEclipse";

		public const string PluginVersion = "1.2.2";

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

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

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

		private static readonly MethodInfo heal = typeof(HealthComponent).GetMethod("Heal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly MethodInfo damage = typeof(HealthComponent).GetMethod("TakeDamageProcess", BindingFlags.Instance | BindingFlags.NonPublic);

		private static void Heal(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.GotoNext(new Func<Instruction, bool>[4]
			{
				(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.Ldarg_0);
			val.Emit(OpCodes.Ldarg_1);
			val.EmitDelegate<Func<HealthComponent, float, float>>((Func<HealthComponent, float, float>)NewHalfHealing);
			val.Emit(OpCodes.Starg_S, (byte)1);
		}

		public static float NewHalfHealing(HealthComponent that, float healAmount)
		{
			if (votedForEclipse5.Any((NetworkUser el) => (Object)(object)el.master == (Object)(object)that.body.master))
			{
				return healAmount / 2f;
			}
			return healAmount;
		}

		private static void TakeDamageProcess(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, 61);
			val.Emit(OpCodes.Ldloc, 8);
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Action<CharacterMaster, float, HealthComponent>>((Action<CharacterMaster, float, HealthComponent>)NewTakeCurse);
		}

		public static void NewTakeCurse(CharacterMaster master, float damageAmount, HealthComponent that)
		{
			if (votedForEclipse8.Any((NetworkUser el) => (Object)(object)el.master == (Object)(object)master))
			{
				float num = damageAmount / that.fullCombinedHealth * 100f;
				float num2 = 0.4f;
				int num3 = Mathf.FloorToInt(num * num2);
				for (int i = 0; i < num3; i++)
				{
					that.body.AddBuff(Buffs.PermanentCurse);
				}
			}
		}

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

		public void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			new PartialEclipse5Artifact();
			new PartialEclipse8Artifact();
		}

		public void Destroy()
		{
			HookEndpointManager.Unmodify((MethodBase)damage, (Delegate)new Action<ILContext>(TakeDamageProcess));
			HookEndpointManager.Unmodify((MethodBase)heal, (Delegate)new Action<ILContext>(Heal));
		}

		public void Start()
		{
			HookEndpointManager.Add((MethodBase)startRun, (Delegate)new Action<Action<PreGameController>, PreGameController>(PreGameControllerStartRun));
			HookEndpointManager.Modify((MethodBase)damage, (Delegate)new Action<ILContext>(TakeDamageProcess));
			HookEndpointManager.Modify((MethodBase)heal, (Delegate)new Action<ILContext>(Heal));
		}
	}
	internal class PartialEclipse5Artifact
	{
		public static ArtifactDef artifact;

		public PartialEclipse5Artifact()
		{
			LanguageAPI.Add("PARTIALECLIPSE_PARTIALECLIPSE5_NAME", "Artifact of Partial Eclipse 5");
			LanguageAPI.Add("PARTIALECLIPSE_PARTIALECLIPSE5_DESC", "Applies Eclipse 5 for people who select the artifact.");
			artifact = ScriptableObject.CreateInstance<ArtifactDef>();
			artifact.cachedName = "PartialEclipse5";
			artifact.nameToken = "PARTIALECLIPSE_PARTIALECLIPSE5_NAME";
			artifact.descriptionToken = "PARTIALECLIPSE_PARTIALECLIPSE5_DESC";
			artifact.smallIconSelectedSprite = CreateSpriteNew("E5_selected");
			artifact.smallIconDeselectedSprite = CreateSpriteNew("E5_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;
		}
	}
	internal class PartialEclipse8Artifact
	{
		public static ArtifactDef artifact;

		public PartialEclipse8Artifact()
		{
			LanguageAPI.Add("PARTIALECLIPSE_PARTIALECLIPSE8_NAME", "Artifact of Partial Eclipse 8");
			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("E8_selected");
			artifact.smallIconDeselectedSprite = CreateSpriteNew("E8_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 PartialEclipse.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.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("PartialEclipse.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[] E5_deselected
		{
			get
			{
				object @object = ResourceManager.GetObject("E5_deselected", resourceCulture);
				return (byte[])@object;
			}
		}

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

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

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

		internal Resources()
		{
		}
	}
}