Decompiled source of TrimpFix v1.0.0

plugins/TrimpFix/TrimpFix.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using IL.RoR2;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using MonoMod.Cil;
using MonoMod.Utils;
using R2API.Utils;
using RiskOfOptions;
using RoR2;
using TrimpFix.Utilities;
using TrimpFix.Utilities.Extensions;
using UnityEngine;
using UnityEngine.ResourceManagement.AsyncOperations;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: NetworkCompatibility(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TrimpFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+84be663e8b422b74898991748eabaff334b2ed63")]
[assembly: AssemblyProduct("TrimpFix")]
[assembly: AssemblyTitle("TrimpFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class ParamCollectionAttribute : Attribute
	{
	}
	[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 TrimpFix
{
	internal static class LanguageFolderHandler
	{
		public static void Register(string searchFolder, string langFolderName = "lang")
		{
			string langFolderPath = Path.Combine(searchFolder, langFolderName);
			if (Directory.Exists(langFolderPath))
			{
				Language.collectLanguageRootFolders += delegate(List<string> folders)
				{
					folders.Add(langFolderPath);
				};
			}
			else
			{
				Log.Error("Lang folder not found: " + langFolderPath, "D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\LanguageFolderHandler.cs", "Register", 21);
			}
		}
	}
	internal static class Log
	{
		private static readonly StringBuilder _sharedStringBuilder;

		private static readonly object _stringBuilderLock;

		private static readonly int _cachedCallerPathPrefixLength;

		private static ManualLogSource _logSource;

		static Log()
		{
			_sharedStringBuilder = new StringBuilder(256);
			_stringBuilderLock = new object();
			_cachedCallerPathPrefixLength = getCallerPathPrefixLength("D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\Log.cs");
			static int getCallerPathPrefixLength([CallerFilePath] string callerPath = null)
			{
				int num = callerPath.LastIndexOf("TrimpFix\\");
				if (num >= 0)
				{
					return num + "TrimpFix\\".Length;
				}
				Debug.LogError((object)"[TrimpFix] Logger failed to determine caller path prefix length");
				return 0;
			}
		}

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

		private static string buildCallerLogString(string callerPath, string callerMemberName, int callerLineNumber, object data)
		{
			lock (_stringBuilderLock)
			{
				return _sharedStringBuilder.Clear().Append(callerPath, _cachedCallerPathPrefixLength, callerPath.Length - _cachedCallerPathPrefixLength).Append(':')
					.Append(callerLineNumber)
					.Append(" (")
					.Append(callerMemberName)
					.Append("): ")
					.Append(data)
					.ToString();
			}
		}

		[Conditional("DEBUG")]
		internal static void Debug(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogDebug((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		[Conditional("DEBUG")]
		internal static void Debug_NoCallerPrefix(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogError((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void Error_NoCallerPrefix(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogFatal((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void Fatal_NoCallerPrefix(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogInfo((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void Info_NoCallerPrefix(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogMessage((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void Message_NoCallerPrefix(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			_logSource.LogWarning((object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void Warning_NoCallerPrefix(object data)
		{
			_logSource.LogWarning(data);
		}

		internal static void LogType(LogLevel level, object data, [CallerFilePath] string callerPath = "", [CallerMemberName] string callerMemberName = "", [CallerLineNumber] int callerLineNumber = -1)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if ((level & 0x20) == 0)
			{
				_logSource.Log(level, (object)buildCallerLogString(callerPath, callerMemberName, callerLineNumber, data));
			}
		}

		[MethodImpl(MethodImplOptions.AggressiveInlining)]
		internal static void LogType_NoCallerPrefix(LogLevel level, object data)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			if ((level & 0x20) == 0)
			{
				_logSource.Log(level, data);
			}
		}
	}
	[BepInPlugin("com.Gorakh.TrimpFix", "TrimpFix", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class TrimpFixPlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Manipulator <0>__GlobalEventManager_OnCharacterHitGroundServer;

			public static Func<float, float> <1>__ignoreUpwards;
		}

		public const string PluginGUID = "com.Gorakh.TrimpFix";

		public const string PluginAuthor = "Gorakh";

		public const string PluginName = "TrimpFix";

		public const string PluginVersion = "1.0.0";

		private static TrimpFixPlugin _instance;

		internal static TrimpFixPlugin Instance => _instance;

		private void Awake()
		{
			Stopwatch stopwatch = Stopwatch.StartNew();
			SingletonHelper.Assign<TrimpFixPlugin>(ref _instance, this);
			Log.Init(((BaseUnityPlugin)this).Logger);
			stopwatch.Stop();
			Log.Message_NoCallerPrefix($"Initialized in {stopwatch.Elapsed.TotalMilliseconds:F0}ms");
		}

		private void OnEnable()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			object obj = <>O.<0>__GlobalEventManager_OnCharacterHitGroundServer;
			if (obj == null)
			{
				Manipulator val = GlobalEventManager_OnCharacterHitGroundServer;
				<>O.<0>__GlobalEventManager_OnCharacterHitGroundServer = val;
				obj = (object)val;
			}
			GlobalEventManager.OnCharacterHitGroundServer += (Manipulator)obj;
		}

		private void OnDisable()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			object obj = <>O.<0>__GlobalEventManager_OnCharacterHitGroundServer;
			if (obj == null)
			{
				Manipulator val = GlobalEventManager_OnCharacterHitGroundServer;
				<>O.<0>__GlobalEventManager_OnCharacterHitGroundServer = val;
				obj = (object)val;
			}
			GlobalEventManager.OnCharacterHitGroundServer -= (Manipulator)obj;
		}

		private void OnDestroy()
		{
			SingletonHelper.Unassign<TrimpFixPlugin>(ref _instance, this);
		}

		private static void GlobalEventManager_OnCharacterHitGroundServer(ILContext il)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			ILCursor val = new ILCursor(il);
			ILCursor[] array = default(ILCursor[]);
			if (!val.TryFindNext(ref array, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdfld<HitGroundInfo>(x, "velocity"),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<Mathf>(x, "Abs")
			}))
			{
				Log.Error("Failed to find patch location", "D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\TrimpFixPlugin.cs", "GlobalEventManager_OnCharacterHitGroundServer", 64);
				return;
			}
			val.Goto(array[1].Next, (MoveType)0, false);
			val.EmitDelegate<Func<float, float>>((Func<float, float>)ignoreUpwards);
			static float ignoreUpwards(float yVelocity)
			{
				if (yVelocity > 0f)
				{
					return 0f;
				}
				return yVelocity;
			}
		}
	}
}
namespace TrimpFix.Utilities
{
	public static class FileUtils
	{
		public static FileInfo SearchUpwards(DirectoryInfo startDir, DirectoryInfo endDir, string searchPattern)
		{
			if (startDir == null)
			{
				throw new ArgumentNullException("startDir");
			}
			if (endDir == null)
			{
				throw new ArgumentNullException("endDir");
			}
			if (string.IsNullOrEmpty(searchPattern))
			{
				throw new ArgumentException("'searchPattern' cannot be null or empty.", "searchPattern");
			}
			if (!startDir.IsChildOf(endDir))
			{
				return null;
			}
			for (DirectoryInfo directoryInfo = startDir; directoryInfo != null; directoryInfo = directoryInfo.Parent)
			{
				FileInfo fileInfo = directoryInfo.EnumerateFiles(searchPattern, SearchOption.TopDirectoryOnly).FirstOrDefault();
				if (fileInfo != null)
				{
					return fileInfo;
				}
				if (string.Equals(directoryInfo.FullName, endDir.FullName, StringComparison.OrdinalIgnoreCase))
				{
					break;
				}
			}
			return null;
		}

		public static FileInfo SearchUpwards(DirectoryInfo startDir, string searchPattern)
		{
			return SearchUpwards(startDir, startDir.Root, searchPattern);
		}
	}
}
namespace TrimpFix.Utilities.Extensions
{
	public static class AssetLoadExtensions
	{
		public static void CallOnSuccess<T>(this AsyncOperationHandle<T> handle, Action<T> onSuccess)
		{
			handle.Completed += delegate(AsyncOperationHandle<T> handle)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Invalid comparison between Unknown and I4
				if ((int)handle.Status == 2)
				{
					Log.Error("Failed to load asset '" + handle.LocationName + "'", "D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\Utilities\\Extensions\\AssetLoadExtensions.cs", "CallOnSuccess", 19);
				}
				else
				{
					onSuccess(handle.Result);
				}
			};
		}
	}
	public static class CollectionExtensions
	{
		public static void EnsureCapacity<T>(this List<T> list, int capacity)
		{
			if (list == null)
			{
				throw new ArgumentNullException("list");
			}
			if (list.Capacity < capacity)
			{
				list.Capacity = capacity;
			}
		}
	}
	public static class FileExtensions
	{
		public static bool IsChildOf(this DirectoryInfo dir, DirectoryInfo other)
		{
			if (dir != null && other != null)
			{
				return dir.FullName.StartsWith(other.FullName, ignoreCase: true, CultureInfo.InvariantCulture);
			}
			return false;
		}
	}
	public static class PatchExtensions
	{
		public static void EmitSkipMethodCall(this ILCursor c)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			c.EmitSkipMethodCall(OpCodes.Br);
		}

		public static void EmitSkipMethodCall(this ILCursor c, OpCode branchOpCode)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			c.EmitSkipMethodCall(branchOpCode, null);
		}

		public static void EmitSkipMethodCall(this ILCursor c, OpCode branchOpCode, Action<ILCursor> emitSkippedReturnValue)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			if (c == null)
			{
				throw new ArgumentNullException("c");
			}
			if ((int)((OpCode)(ref branchOpCode)).FlowControl != 0 && (int)((OpCode)(ref branchOpCode)).FlowControl != 3)
			{
				throw new ArgumentException($"Invalid branch OpCode: {branchOpCode}");
			}
			MethodReference val = default(MethodReference);
			if (c.Next == null || !ILPatternMatchingExt.MatchCallOrCallvirt(c.Next, ref val))
			{
				Log.Error($"Failed to find method call to skip: {((MemberReference)c.Context.Method).FullName} at instruction {c.Next.SafeToString()} ({c.Index})", "D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\Utilities\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 60);
				return;
			}
			MethodDefinition val2 = Extensions.SafeResolve(val);
			if (val2 == null)
			{
				Log.Error($"Failed to resolve method '{((MemberReference)val).FullName}': {((MemberReference)c.Context.Method).FullName} at instruction {c.Next.SafeToString()} ({c.Index})", "D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\Utilities\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 68);
				return;
			}
			int num = ((MethodReference)val2).Parameters.Count + ((!val2.IsStatic) ? 1 : 0);
			bool flag = Extensions.Is((MemberReference)(object)((MethodReference)val2).ReturnType, (MemberInfo)typeof(void));
			ILLabel val3 = c.DefineLabel();
			c.Emit(branchOpCode, (object)val3);
			int index = c.Index;
			c.Index = index + 1;
			if (num == 0 && flag)
			{
				c.MarkLabel(val3);
				return;
			}
			ILLabel val4 = c.DefineLabel();
			c.Emit(OpCodes.Br, (object)val4);
			c.MarkLabel(val3);
			for (int i = 0; i < num; i++)
			{
				c.Emit(OpCodes.Pop);
			}
			if (emitSkippedReturnValue != null)
			{
				emitSkippedReturnValue(c);
			}
			else if (!flag)
			{
				Log.Warning($"Skipped method ({((MemberReference)val2).FullName}) is not void, emitting default value: {((MemberReference)c.Context.Method).FullName} at instruction {c.Next.SafeToString()} ({c.Index})", "D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\Utilities\\Extensions\\PatchExtensions.cs", "EmitSkipMethodCall", 103);
				if (((MethodReference)val2).ReturnType.IsValueType)
				{
					VariableDefinition val5 = c.Context.AddVariable(((MethodReference)val2).ReturnType);
					c.Emit(OpCodes.Ldloca, val5);
					c.Emit(OpCodes.Initobj, ((MethodReference)val2).ReturnType);
					c.Emit(OpCodes.Ldloc, val5);
				}
				else
				{
					c.Emit(OpCodes.Ldnull);
				}
			}
			c.MarkLabel(val4);
		}

		public static bool TryFindForeachContinueLabel(this ILCursor cursor, out ILLabel continueLabel)
		{
			ILCursor val = cursor.Clone();
			int enumeratorLocalIndex = -1;
			MethodReference method2 = default(MethodReference);
			if (!val.TryGotoPrev(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, ref method2) && isEnumerableGetEnumerator(method2)
			}) || !val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref enumeratorLocalIndex)
			}))
			{
				Log.Warning("Failed to find GetEnumerator call", "D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\Utilities\\Extensions\\PatchExtensions.cs", "TryFindForeachContinueLabel", 155);
				continueLabel = null;
				return false;
			}
			val = cursor.Clone();
			if (!val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[2]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, enumeratorLocalIndex),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<IEnumerator>(x, "MoveNext")
			}))
			{
				Log.Warning("Failed to find matching MoveNext call", "D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\Utilities\\Extensions\\PatchExtensions.cs", "TryFindForeachContinueLabel", 165);
				continueLabel = null;
				return false;
			}
			continueLabel = val.MarkLabel();
			return true;
			static bool isEnumerableGetEnumerator(MethodReference method)
			{
				if (method == null)
				{
					return false;
				}
				if (!string.Equals(((MemberReference)method).Name, "GetEnumerator"))
				{
					return false;
				}
				return true;
			}
		}

		public static string SafeToString(this Instruction instruction)
		{
			//IL_0036: 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)
			if (instruction == null)
			{
				return "NULL";
			}
			try
			{
				return ((object)instruction).ToString();
			}
			catch
			{
			}
			StringBuilder stringBuilder = new StringBuilder();
			StringBuilder stringBuilder2 = stringBuilder.Append(formatLabel(instruction)).Append(": ");
			OpCode opCode = instruction.OpCode;
			stringBuilder2.Append(((OpCode)(ref opCode)).Name);
			if (instruction.Operand != null)
			{
				stringBuilder.Append(' ');
				object operand = instruction.Operand;
				Instruction val = (Instruction)((operand is Instruction) ? operand : null);
				if (val == null)
				{
					if (operand is IEnumerable<Instruction> source)
					{
						stringBuilder.Append('[').Append(string.Join(", ", source.Select(formatLabel))).Append(']');
					}
					else
					{
						stringBuilder.Append(instruction.Operand);
					}
				}
				else
				{
					stringBuilder.Append(formatLabel(val));
				}
			}
			return stringBuilder.ToString();
			static string formatLabel(Instruction instruction)
			{
				if (instruction == null)
				{
					return "IL_????";
				}
				return $"IL_{instruction.Offset:x4}";
			}
		}

		public static bool TryFindParameter(this MethodReference method, Type parameterType, string parameterName, out ParameterDefinition parameter)
		{
			//IL_0048: 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)
			if (method == null)
			{
				throw new ArgumentNullException("method");
			}
			if (parameterType == null && string.IsNullOrEmpty(parameterName))
			{
				throw new ArgumentException("Cannot find parameter for method " + ((MemberReference)method).FullName + ": Neither parameter type or name specified");
			}
			if (method.HasParameters)
			{
				Enumerator<ParameterDefinition> enumerator = method.Parameters.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						ParameterDefinition current = enumerator.Current;
						if ((string.IsNullOrEmpty(parameterName) || ((ParameterReference)current).Name == parameterName) && (parameterType == null || Extensions.Is((MemberReference)(object)((ParameterReference)current).ParameterType, (MemberInfo)parameterType)))
						{
							parameter = current;
							return true;
						}
					}
				}
				finally
				{
					((IDisposable)enumerator).Dispose();
				}
			}
			parameter = null;
			return false;
		}

		public static bool TryFindParameter(this MethodReference method, string name, out ParameterDefinition parameter)
		{
			return method.TryFindParameter(null, name, out parameter);
		}

		public static bool TryFindParameter(this MethodReference method, Type type, out ParameterDefinition parameter)
		{
			return method.TryFindParameter(type, null, out parameter);
		}

		public static bool TryFindParameter<T>(this MethodReference method, string name, out ParameterDefinition parameter)
		{
			return method.TryFindParameter(typeof(T), name, out parameter);
		}

		public static bool TryFindParameter<T>(this MethodReference method, out ParameterDefinition parameter)
		{
			return method.TryFindParameter(typeof(T), null, out parameter);
		}

		public static VariableDefinition AddVariable(this ILContext context, TypeReference variableType)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			VariableDefinition val = new VariableDefinition(variableType);
			context.Method.Body.Variables.Add(val);
			return val;
		}

		public static VariableDefinition AddVariable(this ILContext context, Type variableType)
		{
			return context.AddVariable(context.Import(variableType));
		}

		public static VariableDefinition AddVariable<T>(this ILContext context)
		{
			return context.AddVariable(context.Import(typeof(T)));
		}

		public static void EmitStoreStack(this ILCursor cursor, [ParamCollection] IReadOnlyList<VariableDefinition> variables)
		{
			//IL_0031: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			if (cursor == null)
			{
				throw new ArgumentNullException("cursor");
			}
			if (variables == null)
			{
				throw new ArgumentNullException("variables");
			}
			if (variables.Count != 0)
			{
				for (int num = variables.Count - 1; num >= 1; num--)
				{
					cursor.Emit(OpCodes.Stloc, variables[num]);
				}
				cursor.Emit(OpCodes.Dup);
				cursor.Emit(OpCodes.Stloc, variables[0]);
				for (int i = 1; i < variables.Count; i++)
				{
					cursor.Emit(OpCodes.Ldloc, variables[i]);
				}
			}
		}
	}
}
namespace TrimpFix.ModCompatibility
{
	internal static class RiskOfOptionsCompat
	{
		private static Sprite _iconSprite;

		private const string MOD_GUID = "com.Gorakh.TrimpFix";

		private const string MOD_NAME = "TrimpFix";

		public static bool Enabled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddOptions()
		{
			ModSettingsManager.SetModDescription("Options for TrimpFix", "com.Gorakh.TrimpFix", "TrimpFix");
			Sprite val = tryGetIcon();
			if (Object.op_Implicit((Object)(object)val))
			{
				ModSettingsManager.SetModIcon(val, "com.Gorakh.TrimpFix", "TrimpFix");
			}
		}

		private static Sprite tryGetIcon()
		{
			if (!Object.op_Implicit((Object)(object)_iconSprite))
			{
				_iconSprite = tryGenerateIcon();
				if (!Object.op_Implicit((Object)(object)_iconSprite))
				{
					Log.Warning("Failed to get config icon", "D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\ModCompatibility\\RiskOfOptionsCompat.cs", "tryGetIcon", 42);
				}
			}
			return _iconSprite;
		}

		private static Sprite tryGenerateIcon()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			DirectoryInfo startDir = new DirectoryInfo(Path.GetDirectoryName(((BaseUnityPlugin)TrimpFixPlugin.Instance).Info.Location));
			DirectoryInfo endDir = new DirectoryInfo(Paths.PluginPath);
			FileInfo fileInfo = FileUtils.SearchUpwards(startDir, endDir, "icon.png");
			if (fileInfo == null)
			{
				return null;
			}
			byte[] array;
			try
			{
				array = File.ReadAllBytes(fileInfo.FullName);
			}
			catch (Exception arg)
			{
				Log.Error_NoCallerPrefix($"Failed to read icon file '{fileInfo.FullName}': {arg}");
				return null;
			}
			Texture2D val = new Texture2D(256, 256);
			((Object)val).name = "texTrimpFixIcon";
			if (!ImageConversion.LoadImage(val, array))
			{
				Object.Destroy((Object)(object)val);
				Log.Error("Failed to load icon into texture", "D:\\Git\\RoR2\\TrimpFix\\TrimpFix\\ModCompatibility\\RiskOfOptionsCompat.cs", "tryGenerateIcon", 76);
				return null;
			}
			Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			((Object)obj).name = "TrimpFixIcon";
			return obj;
		}
	}
}