Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of PartialEclipse8 v1.3.2
plugins/PartialEclipse/PartialEclipse.dll
Decompiled 5 months agousing 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.Bootstrap; 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.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("RegalTurtle.PartialEclipse", "PartialEclipse", "1.3.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.3.2"; private static readonly HashSet<NetworkUser> votedForEclipse1 = new HashSet<NetworkUser>(); private static readonly HashSet<NetworkUser> votedForEclipse3 = new HashSet<NetworkUser>(); 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 onBodyStart = typeof(CharacterMaster).GetMethod("OnBodyStart", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); private static readonly MethodInfo onCharacterHitGroundServer = typeof(GlobalEventManager).GetMethod("OnCharacterHitGroundServer", BindingFlags.Instance | BindingFlags.Public | 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); public static bool EclipseArtifactsInstalled => Chainloader.PluginInfos.ContainsKey("Judgy.EclipseArtifacts"); private static void OnBodyStart(ILContext il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); Instruction next; if (EclipseArtifactsInstalled) { if (!val.TryGotoNext(new Func<Instruction, bool>[1] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt<Run>(x, "get_selectedDifficulty") })) { Log.Error("Failed to find Eclipse 1 check, EclipseArtifacts loaded"); return; } next = val.Next.Next.Next.Next.Next.Next.Next; } else { ILLabel val2 = default(ILLabel); if (!val.TryGotoNext(new Func<Instruction, bool>[3] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt<Run>(x, "get_selectedDifficulty"), (Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 3), (Instruction x) => ILPatternMatchingExt.MatchBlt(x, ref val2) })) { Log.Error("Failed to find Eclipse 1 check"); return; } next = val.Next.Next.Next.Next; } int index = val.Index; val.Index = index - 1; val.Emit(OpCodes.Ldarg_0); val.EmitDelegate<Func<CharacterMaster, bool>>((Func<CharacterMaster, bool>)((CharacterMaster selfMaster) => votedForEclipse1.Any((NetworkUser el) => (Object)(object)el.master == (Object)(object)selfMaster))); val.Emit(OpCodes.Brtrue_S, next); } private static void OnCharacterHitGroundServerEdit(ILContext il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); Instruction next; if (EclipseArtifactsInstalled) { if (!val.TryGotoNext(new Func<Instruction, bool>[1] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt<Run>(x, "get_selectedDifficulty") })) { Log.Error("Failed to find Eclipse 3 check, EclipseArtifacts loaded"); return; } next = val.Next.Next.Next.Next.Next.Next.Next; } else { ILLabel val2 = default(ILLabel); if (!val.TryGotoNext(new Func<Instruction, bool>[3] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt<Run>(x, "get_selectedDifficulty"), (Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 5), (Instruction x) => ILPatternMatchingExt.MatchBlt(x, ref val2) })) { Log.Error("Failed to find Eclipse 3 check"); return; } next = val.Next.Next.Next.Next; } int index = val.Index; val.Index = index - 1; val.Emit(OpCodes.Ldarg_1); val.EmitDelegate<Func<CharacterBody, bool>>((Func<CharacterBody, bool>)((CharacterBody selfCharacterBody) => votedForEclipse3.Any((NetworkUser el) => (Object)(object)el.master == (Object)(object)selfCharacterBody.master))); val.Emit(OpCodes.Brtrue_S, next); } 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); Instruction next; if (EclipseArtifactsInstalled) { if (!val.TryGotoNext(new Func<Instruction, bool>[1] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt<Run>(x, "get_selectedDifficulty") })) { Log.Error("Failed to find Eclipse 5 check, EclipseArtifacts loaded"); return; } next = val.Next.Next.Next.Next.Next.Next.Next; } else { ILLabel val2 = default(ILLabel); if (!val.TryGotoNext(new Func<Instruction, bool>[3] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt<Run>(x, "get_selectedDifficulty"), (Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 7), (Instruction x) => ILPatternMatchingExt.MatchBlt(x, ref val2) })) { Log.Error("Failed to find Eclipse 5 check"); return; } next = val.Next.Next.Next.Next; } int index = val.Index; val.Index = index - 1; val.Emit(OpCodes.Ldarg_0); val.EmitDelegate<Func<HealthComponent, bool>>((Func<HealthComponent, bool>)((HealthComponent selfHealthComponent) => votedForEclipse5.Any((NetworkUser el) => (Object)(object)el.master == (Object)(object)selfHealthComponent.body.master))); val.Emit(OpCodes.Brtrue_S, next); } 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_0138: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); Instruction next; if (EclipseArtifactsInstalled) { if (!val.TryGotoNext(new Func<Instruction, bool>[1] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt<Run>(x, "get_selectedDifficulty") })) { Log.Error("Failed to find Eclipse 8 check, EclipseArtifacts loaded"); return; } next = val.Next.Next.Next.Next.Next.Next.Next; } else { ILLabel val2 = default(ILLabel); if (!val.TryGotoNext(new Func<Instruction, bool>[3] { (Instruction x) => ILPatternMatchingExt.MatchCallvirt<Run>(x, "get_selectedDifficulty"), (Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 10), (Instruction x) => ILPatternMatchingExt.MatchBlt(x, ref val2) })) { Log.Error("Failed to find Eclipse 8 check"); return; } next = val.Next.Next.Next.Next; } int index = val.Index; val.Index = index - 1; val.Emit(OpCodes.Ldarg_0); val.EmitDelegate<Func<HealthComponent, bool>>((Func<HealthComponent, bool>)((HealthComponent selfHealthComponent) => votedForEclipse8.Any((NetworkUser el) => (Object)(object)el.master == (Object)(object)selfHealthComponent.body.master))); val.Emit(OpCodes.Brtrue_S, next); } 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) { votedForEclipse1.Clear(); votedForEclipse3.Clear(); votedForEclipse5.Clear(); votedForEclipse8.Clear(); RuleChoiceDef val = RuleCatalog.FindChoiceDef("Artifacts.PartialEclipse1.On"); RuleChoiceDef val2 = RuleCatalog.FindChoiceDef("Artifacts.PartialEclipse3.On"); RuleChoiceDef val3 = RuleCatalog.FindChoiceDef("Artifacts.PartialEclipse5.On"); RuleChoiceDef val4 = RuleCatalog.FindChoiceDef("Artifacts.PartialEclipse8.On"); foreach (NetworkUser readOnlyInstances in NetworkUser.readOnlyInstancesList) { PreGameRuleVoteController val5 = PreGameRuleVoteController.FindForUser(readOnlyInstances); if (val5.IsChoiceVoted(val)) { votedForEclipse1.Add(readOnlyInstances); } if (val5.IsChoiceVoted(val2)) { votedForEclipse3.Add(readOnlyInstances); } if (val5.IsChoiceVoted(val3)) { votedForEclipse5.Add(readOnlyInstances); } if (val5.IsChoiceVoted(val4)) { votedForEclipse8.Add(readOnlyInstances); } } Console.WriteLine(votedForEclipse8); orig(self); } public void Awake() { Log.Init(((BaseUnityPlugin)this).Logger); new PartialEclipse1Artifact(); new PartialEclipse3Artifact(); new PartialEclipse5Artifact(); new PartialEclipse8Artifact(); } public void Destroy() { HookEndpointManager.Remove((MethodBase)startRun, (Delegate)new Action<Action<PreGameController>, PreGameController>(PreGameControllerStartRun)); HookEndpointManager.Unmodify((MethodBase)onBodyStart, (Delegate)new Action<ILContext>(OnBodyStart)); HookEndpointManager.Unmodify((MethodBase)onCharacterHitGroundServer, (Delegate)new Action<ILContext>(OnCharacterHitGroundServerEdit)); HookEndpointManager.Unmodify((MethodBase)heal, (Delegate)new Action<ILContext>(Heal)); HookEndpointManager.Unmodify((MethodBase)damage, (Delegate)new Action<ILContext>(TakeDamageProcess)); } public void Start() { HookEndpointManager.Add((MethodBase)startRun, (Delegate)new Action<Action<PreGameController>, PreGameController>(PreGameControllerStartRun)); HookEndpointManager.Modify((MethodBase)onBodyStart, (Delegate)new Action<ILContext>(OnBodyStart)); HookEndpointManager.Modify((MethodBase)onCharacterHitGroundServer, (Delegate)new Action<ILContext>(OnCharacterHitGroundServerEdit)); HookEndpointManager.Modify((MethodBase)heal, (Delegate)new Action<ILContext>(Heal)); HookEndpointManager.Modify((MethodBase)damage, (Delegate)new Action<ILContext>(TakeDamageProcess)); } } internal class PartialEclipse1Artifact { public static ArtifactDef artifact; public PartialEclipse1Artifact() { LanguageAPI.Add("PARTIALECLIPSE_PARTIALECLIPSE1_NAME", "Artifact of Partial Eclipse 1"); LanguageAPI.Add("PARTIALECLIPSE_PARTIALECLIPSE1_DESC", "Applies Eclipse 1 for people who select the artifact."); artifact = ScriptableObject.CreateInstance<ArtifactDef>(); artifact.cachedName = "PartialEclipse1"; artifact.nameToken = "PARTIALECLIPSE_PARTIALECLIPSE1_NAME"; artifact.descriptionToken = "PARTIALECLIPSE_PARTIALECLIPSE1_DESC"; artifact.smallIconSelectedSprite = CreateSpriteNew("E1_selected"); artifact.smallIconDeselectedSprite = CreateSpriteNew("E1_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 PartialEclipse3Artifact { public static ArtifactDef artifact; public PartialEclipse3Artifact() { LanguageAPI.Add("PARTIALECLIPSE_PARTIALECLIPSE3_NAME", "Artifact of Partial Eclipse 3"); LanguageAPI.Add("PARTIALECLIPSE_PARTIALECLIPSE3_DESC", "Applies Eclipse 3 for people who select the artifact."); artifact = ScriptableObject.CreateInstance<ArtifactDef>(); artifact.cachedName = "PartialEclipse3"; artifact.nameToken = "PARTIALECLIPSE_PARTIALECLIPSE3_NAME"; artifact.descriptionToken = "PARTIALECLIPSE_PARTIALECLIPSE3_DESC"; artifact.smallIconSelectedSprite = CreateSpriteNew("E3_selected"); artifact.smallIconDeselectedSprite = CreateSpriteNew("E3_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 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[] E1_deselected { get { object @object = ResourceManager.GetObject("E1_deselected", resourceCulture); return (byte[])@object; } } internal static byte[] E1_selected { get { object @object = ResourceManager.GetObject("E1_selected", resourceCulture); return (byte[])@object; } } internal static byte[] E3_deselected { get { object @object = ResourceManager.GetObject("E3_deselected", resourceCulture); return (byte[])@object; } } internal static byte[] E3_selected { get { object @object = ResourceManager.GetObject("E3_selected", resourceCulture); return (byte[])@object; } } 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() { } } }