Decompiled source of OperatorTweaks v1.0.1

plugins/OperatorTweaks/OperatorTweaks.dll

Decompiled 6 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.DroneTech;
using HG.GeneralSerializer;
using IL.EntityStates.DroneTech;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OperatorTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+66b8978b7ee799c0be6fee3e2525e5d79d040f90")]
[assembly: AssemblyProduct("OperatorTweaks")]
[assembly: AssemblyTitle("OperatorTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 OperatorTweaks
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

		private static string Format(object data, string file, int line)
		{
			string fileName = Path.GetFileName(file);
			return $"[{fileName}:{line}] {data}";
		}

		internal static void Debug(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogDebug((object)Format(data, file, line));
		}

		internal static void Error(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogError((object)Format(data, file, line));
		}

		internal static void Fatal(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogFatal((object)Format(data, file, line));
		}

		internal static void Info(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogInfo((object)Format(data, file, line));
		}

		internal static void Message(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogMessage((object)Format(data, file, line));
		}

		internal static void Warning(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogWarning((object)Format(data, file, line));
		}
	}
	public static class OperatorTweaksSettings
	{
		public static ConfigEntry<int> ShieldTransparency { get; set; }

		public static ConfigEntry<float> ShieldExitTime { get; set; }

		public static ConfigEntry<float> ShieldDurationForMaxCharge { get; set; }

		public static ConfigEntry<bool> LeapUseMovementDirection { get; set; }
	}
	[BepInPlugin("disro.OperatorTweaks", "OperatorTweaks", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class OperatorTweaks : BaseUnityPlugin
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<Instruction, bool> <>9__7_1;

			public static Func<Instruction, bool> <>9__7_2;

			public static Func<Instruction, bool> <>9__7_3;

			public static Func<Instruction, bool> <>9__7_4;

			public static Func<DroneLeap, Vector3> <>9__7_5;

			public static Manipulator <>9__7_0;

			internal void <ApplyLeapModifications>b__7_0(ILContext il)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Expected O, but got Unknown
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: 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.MatchStloc(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchLdloca(x, 0),
					(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Ray>(x, "get_direction")
				}))
				{
					val.Emit(OpCodes.Pop);
					val.Emit(OpCodes.Ldarg_0);
					val.EmitDelegate<Func<DroneLeap, Vector3>>((Func<DroneLeap, Vector3>)delegate(DroneLeap self)
					{
						//IL_0019: Unknown result type (might be due to invalid IL or missing references)
						//IL_000b: Unknown result type (might be due to invalid IL or missing references)
						//IL_0010: Unknown result type (might be due to invalid IL or missing references)
						//IL_0013: Unknown result type (might be due to invalid IL or missing references)
						InputBankTest inputBank = ((EntityState)self).inputBank;
						if (inputBank == null)
						{
							Ray aimRay = ((BaseState)self).GetAimRay();
							return ((Ray)(ref aimRay)).direction;
						}
						return inputBank.moveVector;
					});
				}
				else
				{
					Log.Debug("Hook failed!", "I:\\_important\\_hobby\\c#\\ror2mods\\OperatorTweaks\\OperatorTweaks\\OperatorTweaks.cs", 117);
				}
			}

			internal bool <ApplyLeapModifications>b__7_1(Instruction x)
			{
				return ILPatternMatchingExt.MatchStloc(x, 0);
			}

			internal bool <ApplyLeapModifications>b__7_2(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdarg(x, 0);
			}

			internal bool <ApplyLeapModifications>b__7_3(Instruction x)
			{
				return ILPatternMatchingExt.MatchLdloca(x, 0);
			}

			internal bool <ApplyLeapModifications>b__7_4(Instruction x)
			{
				return ILPatternMatchingExt.MatchCallOrCallvirt<Ray>(x, "get_direction");
			}

			internal Vector3 <ApplyLeapModifications>b__7_5(DroneLeap self)
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				InputBankTest inputBank = ((EntityState)self).inputBank;
				if (inputBank == null)
				{
					Ray aimRay = ((BaseState)self).GetAimRay();
					return ((Ray)(ref aimRay)).direction;
				}
				return inputBank.moveVector;
			}
		}

		public const string PluginGUID = "disro.OperatorTweaks";

		public const string PluginAuthor = "disro";

		public const string PluginName = "OperatorTweaks";

		public const string PluginVersion = "1.0.0";

		private EntityStateConfiguration _shieldAsset;

		public void Awake()
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			Log.Init(((BaseUnityPlugin)this).Logger);
			OperatorTweaksSettings.ShieldTransparency = ((BaseUnityPlugin)this).Config.Bind<int>("Shield", "Shield Transparency", 100, "The percent of the original shield transparency");
			OperatorTweaksSettings.ShieldDurationForMaxCharge = ((BaseUnityPlugin)this).Config.Bind<float>("Shield", "Shield Duration For Max Charge", 2f, "Seconds until the shield is fully charged up");
			OperatorTweaksSettings.ShieldExitTime = ((BaseUnityPlugin)this).Config.Bind<float>("Shield", "Shield exit time", 0.1f, "Delay before the shield is sent flying after key release. Set to 0 for no delay");
			OperatorTweaksSettings.LeapUseMovementDirection = ((BaseUnityPlugin)this).Config.Bind<bool>("Leap", "Use movement direction", false, "Makes the leap use movement direction of the character instead of your aim");
			if (RiskOfOptionsCompatability.Enabled)
			{
				RiskOfOptionsCompatability.InitConfig();
			}
			_shieldAsset = Addressables.LoadAssetAsync<EntityStateConfiguration>((object)"RoR2/DLC3/Drone Tech/EntityStates.DroneTech.Weapon.ShieldFormation.asset").WaitForCompletion();
			ApplyShieldModifications(_shieldAsset);
			ApplyLeapModifications();
		}

		private void ApplyShieldModifications(EntityStateConfiguration shieldAsset)
		{
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)shieldAsset))
			{
				Log.Error("Shield asset missing", "I:\\_important\\_hobby\\c#\\ror2mods\\OperatorTweaks\\OperatorTweaks\\OperatorTweaks.cs", 56);
				return;
			}
			float num = (float)OperatorTweaksSettings.ShieldTransparency.Value / 100f;
			float value = OperatorTweaksSettings.ShieldExitTime.Value;
			float value2 = OperatorTweaksSettings.ShieldDurationForMaxCharge.Value;
			SerializedField[] serializedFields = shieldAsset.serializedFieldsCollection.serializedFields;
			for (int i = 0; i < serializedFields.Length; i++)
			{
				string fieldName = serializedFields[i].fieldName;
				if (fieldName == null)
				{
					continue;
				}
				int length = fieldName.Length;
				if (length <= 8)
				{
					if (length != 7)
					{
						if (length != 8)
						{
							continue;
						}
						char c = fieldName[0];
						if (c != 'c')
						{
							if (c == 'e' && fieldName == "exitTime")
							{
								Log.Debug("exitTime before: " + serializedFields[i].fieldValue.stringValue, "I:\\_important\\_hobby\\c#\\ror2mods\\OperatorTweaks\\OperatorTweaks\\OperatorTweaks.cs", 79);
								serializedFields[i].fieldValue.stringValue = StringSerializer.Serialize(typeof(float), (object)value);
								Log.Debug("exitTime now: " + serializedFields[i].fieldValue.stringValue, "I:\\_important\\_hobby\\c#\\ror2mods\\OperatorTweaks\\OperatorTweaks\\OperatorTweaks.cs", 81);
							}
							continue;
						}
						if (!(fieldName == "color100"))
						{
							continue;
						}
					}
					else
					{
						char c = fieldName[5];
						if (c != '2')
						{
							if (c != '5')
							{
								if (c != '7' || !(fieldName == "color75"))
								{
									continue;
								}
							}
							else if (!(fieldName == "color50"))
							{
								continue;
							}
						}
						else if (!(fieldName == "color25"))
						{
							continue;
						}
					}
				}
				else
				{
					if (length != 12)
					{
						if (length == 20 && fieldName == "durationForMaxCharge")
						{
							Log.Debug("durationForMaxCharge before: " + serializedFields[i].fieldValue.stringValue, "I:\\_important\\_hobby\\c#\\ror2mods\\OperatorTweaks\\OperatorTweaks\\OperatorTweaks.cs", 84);
							serializedFields[i].fieldValue.stringValue = StringSerializer.Serialize(typeof(float), (object)value2);
							Log.Debug("durationForMaxCharge now: " + serializedFields[i].fieldValue.stringValue, "I:\\_important\\_hobby\\c#\\ror2mods\\OperatorTweaks\\OperatorTweaks\\OperatorTweaks.cs", 86);
						}
						continue;
					}
					if (!(fieldName == "defaultColor"))
					{
						continue;
					}
				}
				Color val = (Color)StringSerializer.Deserialize(typeof(Color), serializedFields[i].fieldValue.stringValue);
				val.a *= num;
				serializedFields[i].fieldValue.stringValue = StringSerializer.Serialize(typeof(Color), (object)val);
			}
		}

		private void ApplyLeapModifications()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			if (!OperatorTweaksSettings.LeapUseMovementDirection.Value)
			{
				return;
			}
			object obj = <>c.<>9__7_0;
			if (obj == null)
			{
				Manipulator val = delegate(ILContext il)
				{
					//IL_0001: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: Expected O, but got Unknown
					//IL_009f: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
					ILCursor val2 = new ILCursor(il);
					if (val2.TryGotoNext((MoveType)2, new Func<Instruction, bool>[4]
					{
						(Instruction x) => ILPatternMatchingExt.MatchStloc(x, 0),
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
						(Instruction x) => ILPatternMatchingExt.MatchLdloca(x, 0),
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Ray>(x, "get_direction")
					}))
					{
						val2.Emit(OpCodes.Pop);
						val2.Emit(OpCodes.Ldarg_0);
						val2.EmitDelegate<Func<DroneLeap, Vector3>>((Func<DroneLeap, Vector3>)delegate(DroneLeap self)
						{
							//IL_0019: Unknown result type (might be due to invalid IL or missing references)
							//IL_000b: Unknown result type (might be due to invalid IL or missing references)
							//IL_0010: Unknown result type (might be due to invalid IL or missing references)
							//IL_0013: Unknown result type (might be due to invalid IL or missing references)
							InputBankTest inputBank = ((EntityState)self).inputBank;
							if (inputBank == null)
							{
								Ray aimRay = ((BaseState)self).GetAimRay();
								return ((Ray)(ref aimRay)).direction;
							}
							return inputBank.moveVector;
						});
					}
					else
					{
						Log.Debug("Hook failed!", "I:\\_important\\_hobby\\c#\\ror2mods\\OperatorTweaks\\OperatorTweaks\\OperatorTweaks.cs", 117);
					}
				};
				<>c.<>9__7_0 = val;
				obj = (object)val;
			}
			DroneLeap.OnEnter += (Manipulator)obj;
		}
	}
	internal class RiskOfOptionsCompatability
	{
		private static bool? _enabled;

		public static bool Enabled
		{
			get
			{
				if (!_enabled.HasValue)
				{
					_enabled = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");
				}
				return _enabled.Value;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void InitConfig()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			//IL_006e: 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_007e: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(OperatorTweaksSettings.ShieldTransparency, new IntSliderConfig
			{
				min = 0,
				max = 200,
				restartRequired = true
			}));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(OperatorTweaksSettings.ShieldExitTime, new StepSliderConfig
			{
				min = 0f,
				max = 1f,
				increment = 0.05f,
				restartRequired = true
			}));
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(OperatorTweaksSettings.ShieldDurationForMaxCharge, new StepSliderConfig
			{
				min = 0f,
				max = 4f,
				increment = 0.1f,
				restartRequired = true
			}));
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(OperatorTweaksSettings.LeapUseMovementDirection, new CheckBoxConfig
			{
				restartRequired = true
			}));
		}
	}
}