Decompiled source of Interpolate Projectile Ghost v1.0.0

plugins/InterpolateProjectileGhost.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using IL.RoR2.Projectile;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using On.RoR2.Projectile;
using RoR2.Projectile;
using RoR2BepInExPack.Utilities;
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("InterpolateProjectileGhost")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("InterpolateProjectileGhost")]
[assembly: AssemblyTitle("InterpolateProjectileGhost")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 InterpolateProjectileGhost
{
	[Serializable]
	[BepInPlugin("com.brynzananas.interpolateprojectileghost", "Interpolate Projectile Ghost", "1.0.0")]
	public class InterpolateProjectileGhostPlugin : BaseUnityPlugin
	{
		public class InterpolateProjectileGhost
		{
			public Vector3 oldPosition;

			public Vector3 newPosition;

			public Quaternion oldRotation;

			public Quaternion newRotation;

			public Vector3 oldScale;

			public Vector3 newScale;
		}

		public const string ModGuid = "com.brynzananas.interpolateprojectileghost";

		public const string ModName = "Interpolate Projectile Ghost";

		public const string ModVer = "1.0.0";

		private static FixedConditionalWeakTable<ProjectileGhostController, InterpolateProjectileGhost> keyValuePairs = new FixedConditionalWeakTable<ProjectileGhostController, InterpolateProjectileGhost>();

		private static bool _hooksSet;

		public void Awake()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			if (!_hooksSet)
			{
				_hooksSet = true;
				ProjectileGhostController.Awake += new hook_Awake(ProjectileGhostController_Awake);
				ProjectileGhostController.CopyTransform += new hook_CopyTransform(ProjectileGhostController_CopyTransform);
				ProjectileController.Start += new Manipulator(ProjectileController_Start);
			}
		}

		private void ProjectileController_Start(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[4]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
				(Instruction x) => ILPatternMatchingExt.MatchCall<ProjectileController>(x, "get_ghost"),
				(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1),
				(Instruction x) => ILPatternMatchingExt.MatchCallvirt<Behaviour>(x, "set_enabled")
			}))
			{
				val.Emit(OpCodes.Ldarg_0);
				val.EmitDelegate<Action<ProjectileController>>((Action<ProjectileController>)SetNewPosition);
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogError((object)(((MemberReference)il.Method).Name + " IL Hook 1 failed!"));
			}
		}

		private static void SetNewPosition(ProjectileController projectileController)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			ProjectileGhostController ghost = projectileController.ghost;
			InterpolateProjectileGhost interpolateProjectileGhost = default(InterpolateProjectileGhost);
			if (keyValuePairs.TryGetValue(ghost, ref interpolateProjectileGhost))
			{
				Transform transform = ((Component)projectileController).transform;
				interpolateProjectileGhost.newPosition = transform.position;
				interpolateProjectileGhost.oldPosition = interpolateProjectileGhost.newPosition;
				interpolateProjectileGhost.newRotation = transform.rotation;
				interpolateProjectileGhost.oldRotation = interpolateProjectileGhost.newRotation;
				if (ghost.inheritScaleFromProjectile)
				{
					interpolateProjectileGhost.newScale = transform.localScale;
					interpolateProjectileGhost.oldScale = interpolateProjectileGhost.newScale;
				}
			}
		}

		public void OnDestroy()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			if (_hooksSet)
			{
				_hooksSet = false;
				ProjectileGhostController.Awake -= new hook_Awake(ProjectileGhostController_Awake);
				ProjectileGhostController.CopyTransform -= new hook_CopyTransform(ProjectileGhostController_CopyTransform);
				ProjectileController.Start -= new Manipulator(ProjectileController_Start);
			}
		}

		public void Update()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			float num = (Time.time - Time.fixedTime) / Time.fixedDeltaTime;
			foreach (KeyValuePair<ProjectileGhostController, InterpolateProjectileGhost> keyValuePair in keyValuePairs)
			{
				ProjectileGhostController key = keyValuePair.Key;
				if (Object.op_Implicit((Object)(object)key))
				{
					InterpolateProjectileGhost value = keyValuePair.Value;
					Vector3 position = Vector3.Lerp(value.oldPosition, value.newPosition, num);
					Quaternion rotation = Quaternion.Lerp(value.oldRotation, value.newRotation, num);
					Vector3 localScale = Vector3.Lerp(value.oldScale, value.newScale, num);
					key.transform.localScale = localScale;
					key.transform.position = position;
					key.transform.rotation = rotation;
				}
			}
		}

		private void ProjectileGhostController_CopyTransform(orig_CopyTransform orig, ProjectileGhostController self, Transform src)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			InterpolateProjectileGhost interpolateProjectileGhost = default(InterpolateProjectileGhost);
			if (keyValuePairs.TryGetValue(self, ref interpolateProjectileGhost))
			{
				interpolateProjectileGhost.oldPosition = interpolateProjectileGhost.newPosition;
				interpolateProjectileGhost.newPosition = src.position;
				interpolateProjectileGhost.oldRotation = interpolateProjectileGhost.newRotation;
				interpolateProjectileGhost.newRotation = src.rotation;
				if (self.inheritScaleFromProjectile)
				{
					interpolateProjectileGhost.oldScale = interpolateProjectileGhost.newScale;
					interpolateProjectileGhost.newScale = src.localScale;
				}
			}
		}

		private void ProjectileGhostController_Awake(orig_Awake orig, ProjectileGhostController self)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			orig.Invoke(self);
			if (!keyValuePairs.ContainsKey(self))
			{
				keyValuePairs.Add(self, new InterpolateProjectileGhost
				{
					oldPosition = self.transform.position,
					newPosition = self.transform.position,
					oldRotation = self.transform.rotation,
					newRotation = self.transform.rotation,
					oldScale = self.transform.localScale,
					newScale = self.transform.localScale
				});
			}
		}
	}
}