using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Security; using System.Security.Permissions; using System.Text; using System.Threading; using AssetRipper.Primitives; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Preloader.Core.Logging; using BepInEx.Unity.Common; using BepInEx.Unity.Mono.Bootstrap; using BepInEx.Unity.Mono.Logging; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: InternalsVisibleTo("UnityEngine")] [assembly: InternalsVisibleTo("UnityEngine.Core")] [assembly: AssemblyCompany("BepInEx")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright © 2022 BepInEx Team")] [assembly: AssemblyDescription("BepInEx support library for Mono Unity games")] [assembly: AssemblyFileVersion("6.0.0.0")] [assembly: AssemblyInformationalVersion("6.0.0-be.785+6abdba47eeebe08552282e7a58ef0f4a9ab60b62")] [assembly: AssemblyProduct("BepInEx.Unity.Mono")] [assembly: AssemblyTitle("BepInEx.Unity.Mono")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("6.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] [CompilerGenerated] internal sealed class <>z__ReadOnlyArray : IEnumerable, ICollection, IList, IEnumerable, ICollection, IList { int ICollection.Count => _items.Length; bool ICollection.IsSynchronized => false; object ICollection.SyncRoot => this; object IList.this[int index] { get { return _items[index]; } set { throw new NotSupportedException(); } } bool IList.IsFixedSize => true; bool IList.IsReadOnly => true; int ICollection.Count => _items.Length; bool ICollection.IsReadOnly => true; T IList.this[int index] { get { return _items[index]; } set { throw new NotSupportedException(); } } public <>z__ReadOnlyArray(T[] items) { _items = items; } IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)_items).GetEnumerator(); } void ICollection.CopyTo(Array array, int index) { ((ICollection)_items).CopyTo(array, index); } int IList.Add(object value) { throw new NotSupportedException(); } void IList.Clear() { throw new NotSupportedException(); } bool IList.Contains(object value) { return ((IList)_items).Contains(value); } int IList.IndexOf(object value) { return ((IList)_items).IndexOf(value); } void IList.Insert(int index, object value) { throw new NotSupportedException(); } void IList.Remove(object value) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)_items).GetEnumerator(); } void ICollection.Add(T item) { throw new NotSupportedException(); } void ICollection.Clear() { throw new NotSupportedException(); } bool ICollection.Contains(T item) { return ((ICollection)_items).Contains(item); } void ICollection.CopyTo(T[] array, int arrayIndex) { ((ICollection)_items).CopyTo(array, arrayIndex); } bool ICollection.Remove(T item) { throw new NotSupportedException(); } int IList.IndexOf(T item) { return ((IList)_items).IndexOf(item); } void IList.Insert(int index, T item) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } } 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 UnityEngine { internal sealed class UnityLogWriter { [MethodImpl(MethodImplOptions.InternalCall)] public static extern void WriteStringToUnityLogImpl(string s); [MethodImpl(MethodImplOptions.InternalCall)] public static extern void WriteStringToUnityLog(string s); } } namespace BepInEx { public class UnityInput { private static IInputSystem current; public static IInputSystem Current { get { if (current == null) { try { try { current = new LegacyInputSystem(); Logger.Log((LogLevel)32, (object)"[UnityInput] Using LegacyInputSystem"); } catch { current = new NewInputSystem(); Logger.Log((LogLevel)32, (object)"[UnityInput] Using NewInputSystem"); } } catch (Exception ex) { current = new NullInputSystem(); Logger.Log((LogLevel)4, (object)("[UnityInput] Failed to detect available input systems - " + ex)); } } return current; } } public bool LegacyInputSystemAvailable => Current is LegacyInputSystem; } public interface IInputSystem { Vector3 mousePosition { get; } Vector2 mouseScrollDelta { get; } bool mousePresent { get; } bool anyKey { get; } bool anyKeyDown { get; } IEnumerable SupportedKeyCodes { get; } bool GetKey(string name); bool GetKey(KeyCode key); bool GetKeyDown(string name); bool GetKeyDown(KeyCode key); bool GetKeyUp(string name); bool GetKeyUp(KeyCode key); bool GetMouseButton(int button); bool GetMouseButtonDown(int button); bool GetMouseButtonUp(int button); void ResetInputAxes(); } internal class NullInputSystem : IInputSystem { public Vector3 mousePosition => Vector3.zero; public Vector2 mouseScrollDelta => Vector2.zero; public bool mousePresent => false; public bool anyKey => false; public bool anyKeyDown => false; public IEnumerable SupportedKeyCodes { get; } = Enumerable.Empty(); public bool GetKey(string name) { return false; } public bool GetKey(KeyCode key) { return false; } public bool GetKeyDown(string name) { return false; } public bool GetKeyDown(KeyCode key) { return false; } public bool GetKeyUp(string name) { return false; } public bool GetKeyUp(KeyCode key) { return false; } public bool GetMouseButton(int button) { return false; } public bool GetMouseButtonDown(int button) { return false; } public bool GetMouseButtonUp(int button) { return false; } public void ResetInputAxes() { } } internal class NewInputSystem : IInputSystem { public Vector3 mousePosition => Vector2.op_Implicit(((InputControl)(object)((Pointer)Mouse.current).position).ReadValue()); public Vector2 mouseScrollDelta => ((InputControl)(object)Mouse.current.scroll).ReadValue(); public bool mousePresent => ((InputDevice)Mouse.current).enabled; public bool anyKey { get { if (((ButtonControl)Keyboard.current.anyKey).isPressed) { return true; } Mouse current = Mouse.current; if (!current.leftButton.isPressed && !current.rightButton.isPressed && !current.forwardButton.isPressed && !current.backButton.isPressed) { return current.middleButton.isPressed; } return true; } } public bool anyKeyDown { get { if (((ButtonControl)Keyboard.current.anyKey).wasPressedThisFrame) { return true; } Mouse current = Mouse.current; if (!current.leftButton.wasPressedThisFrame && !current.rightButton.wasPressedThisFrame && !current.forwardButton.wasPressedThisFrame && !current.backButton.wasPressedThisFrame) { return current.middleButton.wasPressedThisFrame; } return true; } } public IEnumerable SupportedKeyCodes { get; } = (from KeyCode x in Enum.GetValues(typeof(KeyCode)) where GetControl(x, silent: true) != null select x).ToList(); [MethodImpl(MethodImplOptions.NoInlining)] public NewInputSystem() { GetKeyDown((KeyCode)97); } public bool GetKey(string name) { ButtonControl control = GetControl(name); if (control == null) { return false; } return control.isPressed; } public bool GetKey(KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) ButtonControl control = GetControl(key); if (control == null) { return false; } return control.isPressed; } public bool GetKeyDown(string name) { ButtonControl control = GetControl(name); if (control == null) { return false; } return control.wasPressedThisFrame; } public bool GetKeyDown(KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) ButtonControl control = GetControl(key); if (control == null) { return false; } return control.wasPressedThisFrame; } public bool GetKeyUp(string name) { ButtonControl control = GetControl(name); if (control == null) { return false; } return control.wasReleasedThisFrame; } public bool GetKeyUp(KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) ButtonControl control = GetControl(key); if (control == null) { return false; } return control.wasReleasedThisFrame; } public bool GetMouseButton(int button) { ButtonControl control = GetControl((KeyCode)(323 + button)); if (control == null) { return false; } return control.isPressed; } public bool GetMouseButtonDown(int button) { ButtonControl control = GetControl((KeyCode)(323 + button)); if (control == null) { return false; } return control.wasPressedThisFrame; } public bool GetMouseButtonUp(int button) { ButtonControl control = GetControl((KeyCode)(323 + button)); if (control == null) { return false; } return control.wasReleasedThisFrame; } public void ResetInputAxes() { } private static ButtonControl GetControl(string name) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) return GetControl((KeyCode)Enum.Parse(typeof(KeyCode), name, ignoreCase: true)); } private static ButtonControl GetControl(KeyCode key, bool silent = false) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_07fe: Expected I4, but got Unknown //IL_0ce3: Unknown result type (might be due to invalid IL or missing references) //IL_0ce4: Unknown result type (might be due to invalid IL or missing references) //IL_0ce8: Unknown result type (might be due to invalid IL or missing references) //IL_0ceb: Unknown result type (might be due to invalid IL or missing references) //IL_0cf1: Expected O, but got Unknown //IL_0d16: Unknown result type (might be due to invalid IL or missing references) switch ((int)key) { case 8: return (ButtonControl)(object)Keyboard.current.backspaceKey; case 127: return (ButtonControl)(object)Keyboard.current.deleteKey; case 9: return (ButtonControl)(object)Keyboard.current.tabKey; case 13: return (ButtonControl)(object)Keyboard.current.enterKey; case 19: return (ButtonControl)(object)Keyboard.current.pauseKey; case 27: return (ButtonControl)(object)Keyboard.current.escapeKey; case 32: return (ButtonControl)(object)Keyboard.current.spaceKey; case 256: return (ButtonControl)(object)Keyboard.current.numpad0Key; case 257: return (ButtonControl)(object)Keyboard.current.numpad1Key; case 258: return (ButtonControl)(object)Keyboard.current.numpad2Key; case 259: return (ButtonControl)(object)Keyboard.current.numpad3Key; case 260: return (ButtonControl)(object)Keyboard.current.numpad4Key; case 261: return (ButtonControl)(object)Keyboard.current.numpad5Key; case 262: return (ButtonControl)(object)Keyboard.current.numpad6Key; case 263: return (ButtonControl)(object)Keyboard.current.numpad7Key; case 264: return (ButtonControl)(object)Keyboard.current.numpad8Key; case 265: return (ButtonControl)(object)Keyboard.current.numpad9Key; case 266: return (ButtonControl)(object)Keyboard.current.numpadPeriodKey; case 267: return (ButtonControl)(object)Keyboard.current.numpadDivideKey; case 268: return (ButtonControl)(object)Keyboard.current.numpadMultiplyKey; case 269: return (ButtonControl)(object)Keyboard.current.numpadMinusKey; case 270: return (ButtonControl)(object)Keyboard.current.numpadPlusKey; case 271: return (ButtonControl)(object)Keyboard.current.numpadEnterKey; case 272: return (ButtonControl)(object)Keyboard.current.numpadEqualsKey; case 273: return (ButtonControl)(object)Keyboard.current.upArrowKey; case 274: return (ButtonControl)(object)Keyboard.current.downArrowKey; case 275: return (ButtonControl)(object)Keyboard.current.rightArrowKey; case 276: return (ButtonControl)(object)Keyboard.current.leftArrowKey; case 277: return (ButtonControl)(object)Keyboard.current.insertKey; case 278: return (ButtonControl)(object)Keyboard.current.homeKey; case 279: return (ButtonControl)(object)Keyboard.current.endKey; case 280: return (ButtonControl)(object)Keyboard.current.pageUpKey; case 281: return (ButtonControl)(object)Keyboard.current.pageDownKey; case 282: return (ButtonControl)(object)Keyboard.current.f1Key; case 283: return (ButtonControl)(object)Keyboard.current.f2Key; case 284: return (ButtonControl)(object)Keyboard.current.f3Key; case 285: return (ButtonControl)(object)Keyboard.current.f4Key; case 286: return (ButtonControl)(object)Keyboard.current.f5Key; case 287: return (ButtonControl)(object)Keyboard.current.f6Key; case 288: return (ButtonControl)(object)Keyboard.current.f7Key; case 289: return (ButtonControl)(object)Keyboard.current.f8Key; case 290: return (ButtonControl)(object)Keyboard.current.f9Key; case 291: return (ButtonControl)(object)Keyboard.current.f10Key; case 292: return (ButtonControl)(object)Keyboard.current.f11Key; case 293: return (ButtonControl)(object)Keyboard.current.f12Key; case 48: return (ButtonControl)(object)Keyboard.current.digit0Key; case 49: return (ButtonControl)(object)Keyboard.current.digit1Key; case 50: return (ButtonControl)(object)Keyboard.current.digit2Key; case 51: return (ButtonControl)(object)Keyboard.current.digit3Key; case 52: return (ButtonControl)(object)Keyboard.current.digit4Key; case 53: return (ButtonControl)(object)Keyboard.current.digit5Key; case 54: return (ButtonControl)(object)Keyboard.current.digit6Key; case 55: return (ButtonControl)(object)Keyboard.current.digit7Key; case 56: return (ButtonControl)(object)Keyboard.current.digit8Key; case 57: return (ButtonControl)(object)Keyboard.current.digit9Key; case 39: return (ButtonControl)(object)Keyboard.current.quoteKey; case 43: return (ButtonControl)(object)Keyboard.current.numpadPlusKey; case 44: return (ButtonControl)(object)Keyboard.current.commaKey; case 45: return (ButtonControl)(object)Keyboard.current.minusKey; case 46: return (ButtonControl)(object)Keyboard.current.periodKey; case 47: return (ButtonControl)(object)Keyboard.current.slashKey; case 59: return (ButtonControl)(object)Keyboard.current.semicolonKey; case 61: return (ButtonControl)(object)Keyboard.current.equalsKey; case 91: return (ButtonControl)(object)Keyboard.current.leftBracketKey; case 92: return (ButtonControl)(object)Keyboard.current.backslashKey; case 93: return (ButtonControl)(object)Keyboard.current.rightBracketKey; case 96: return (ButtonControl)(object)Keyboard.current.backquoteKey; case 97: return (ButtonControl)(object)Keyboard.current.aKey; case 98: return (ButtonControl)(object)Keyboard.current.bKey; case 99: return (ButtonControl)(object)Keyboard.current.cKey; case 100: return (ButtonControl)(object)Keyboard.current.dKey; case 101: return (ButtonControl)(object)Keyboard.current.eKey; case 102: return (ButtonControl)(object)Keyboard.current.fKey; case 103: return (ButtonControl)(object)Keyboard.current.gKey; case 104: return (ButtonControl)(object)Keyboard.current.hKey; case 105: return (ButtonControl)(object)Keyboard.current.iKey; case 106: return (ButtonControl)(object)Keyboard.current.jKey; case 107: return (ButtonControl)(object)Keyboard.current.kKey; case 108: return (ButtonControl)(object)Keyboard.current.lKey; case 109: return (ButtonControl)(object)Keyboard.current.mKey; case 110: return (ButtonControl)(object)Keyboard.current.nKey; case 111: return (ButtonControl)(object)Keyboard.current.oKey; case 112: return (ButtonControl)(object)Keyboard.current.pKey; case 113: return (ButtonControl)(object)Keyboard.current.qKey; case 114: return (ButtonControl)(object)Keyboard.current.rKey; case 115: return (ButtonControl)(object)Keyboard.current.sKey; case 116: return (ButtonControl)(object)Keyboard.current.tKey; case 117: return (ButtonControl)(object)Keyboard.current.uKey; case 118: return (ButtonControl)(object)Keyboard.current.vKey; case 119: return (ButtonControl)(object)Keyboard.current.wKey; case 120: return (ButtonControl)(object)Keyboard.current.xKey; case 121: return (ButtonControl)(object)Keyboard.current.yKey; case 122: return (ButtonControl)(object)Keyboard.current.zKey; case 300: return (ButtonControl)(object)Keyboard.current.numLockKey; case 301: return (ButtonControl)(object)Keyboard.current.capsLockKey; case 302: return (ButtonControl)(object)Keyboard.current.scrollLockKey; case 303: return (ButtonControl)(object)Keyboard.current.rightShiftKey; case 304: return (ButtonControl)(object)Keyboard.current.leftShiftKey; case 305: return (ButtonControl)(object)Keyboard.current.rightCtrlKey; case 306: return (ButtonControl)(object)Keyboard.current.leftCtrlKey; case 307: return (ButtonControl)(object)Keyboard.current.rightAltKey; case 308: return (ButtonControl)(object)Keyboard.current.leftAltKey; case 310: return (ButtonControl)(object)Keyboard.current.leftCommandKey; case 311: return (ButtonControl)(object)Keyboard.current.leftWindowsKey; case 309: return (ButtonControl)(object)Keyboard.current.rightCommandKey; case 312: return (ButtonControl)(object)Keyboard.current.rightWindowsKey; case 316: return (ButtonControl)(object)Keyboard.current.printScreenKey; case 319: return (ButtonControl)(object)Keyboard.current.contextMenuKey; case 323: return Mouse.current.leftButton; case 324: return Mouse.current.rightButton; case 325: return Mouse.current.middleButton; case 326: return Mouse.current.backButton; case 327: return Mouse.current.forwardButton; default: if (!silent) { LogLevel val = (LogLevel)32; bool flag = default(bool); BepInExLogInterpolatedStringHandler val2 = new BepInExLogInterpolatedStringHandler(20, 2, val, ref flag); if (flag) { val2.AppendLiteral("["); val2.AppendFormatted("NewInputSystem"); val2.AppendLiteral("] Unsupported key: "); val2.AppendFormatted(key); } Logger.Log(val, val2); } return null; } } } internal class LegacyInputSystem : IInputSystem { public Vector3 mousePosition => Input.mousePosition; public Vector2 mouseScrollDelta => Input.mouseScrollDelta; public bool mousePresent => Input.mousePresent; public bool anyKey => Input.anyKey; public bool anyKeyDown => Input.anyKeyDown; public IEnumerable SupportedKeyCodes { get; } = (KeyCode[])Enum.GetValues(typeof(KeyCode)); [MethodImpl(MethodImplOptions.NoInlining)] public LegacyInputSystem() { Input.GetKeyDown((KeyCode)97); } public bool GetKey(string name) { return Input.GetKey(name); } public bool GetKey(KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return Input.GetKey(key); } public bool GetKeyDown(string name) { return Input.GetKeyDown(name); } public bool GetKeyDown(KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return Input.GetKeyDown(key); } public bool GetKeyUp(string name) { return Input.GetKeyUp(name); } public bool GetKeyUp(KeyCode key) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return Input.GetKeyUp(key); } public bool GetMouseButton(int button) { return Input.GetMouseButton(button); } public bool GetMouseButtonDown(int button) { return Input.GetMouseButtonDown(button); } public bool GetMouseButtonUp(int button) { return Input.GetMouseButtonUp(button); } public void ResetInputAxes() { Input.ResetInputAxes(); } } } namespace BepInEx.Unity.Mono { public abstract class BaseUnityPlugin : MonoBehaviour { public PluginInfo Info { get; } protected ManualLogSource Logger { get; } public ConfigFile Config { get; } protected BaseUnityPlugin() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_0055: 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_0081: Expected O, but got Unknown //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Expected O, but got Unknown BepInPlugin metadata = MetadataHelper.GetMetadata((object)this); if (metadata == null) { throw new InvalidOperationException("Can't create an instance of " + ((object)this).GetType().FullName + " because it inherits from BaseUnityPlugin and the BepInPlugin attribute is missing."); } Info = new PluginInfo { Metadata = metadata, Instance = this, Dependencies = MetadataHelper.GetDependencies(((object)this).GetType()), Processes = MetadataHelper.GetAttributes(((object)this).GetType()), Location = ((object)this).GetType().Assembly.Location }; Logger = Logger.CreateLogSource(metadata.Name); Config = new ConfigFile(Utility.CombinePaths(new string[2] { Paths.ConfigPath, metadata.GUID + ".cfg" }), false, metadata); } } public static class BepInExInstance { public static UnityChainloader Chainloader { get; } } public sealed class ThreadingHelper : MonoBehaviour, ISynchronizeInvoke { private sealed class InvokeResult : IAsyncResult { internal bool ExceptionThrown; public bool IsCompleted { get; private set; } public WaitHandle AsyncWaitHandle { get; } public object AsyncState { get; private set; } public bool CompletedSynchronously { get; private set; } public InvokeResult() { AsyncWaitHandle = new EventWaitHandle(initialState: false, EventResetMode.ManualReset); } public void Finish(object result, bool completedSynchronously) { AsyncState = result; CompletedSynchronously = completedSynchronously; IsCompleted = true; ((EventWaitHandle)AsyncWaitHandle).Set(); } } private readonly object _invokeLock = new object(); private Action _invokeList; private Thread _mainThread; public static ThreadingHelper Instance { get; private set; } public static ISynchronizeInvoke SynchronizingObject => Instance; public bool InvokeRequired { get { if (_mainThread != null) { return _mainThread != Thread.CurrentThread; } return true; } } private void Update() { if (_mainThread == null) { _mainThread = Thread.CurrentThread; } if (_invokeList == null) { return; } Action invokeList; lock (_invokeLock) { invokeList = _invokeList; _invokeList = null; } foreach (Action item in invokeList.GetInvocationList().Cast()) { try { item(); } catch (Exception ex) { LogInvocationException(ex); } } } internal static void Initialize() { //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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown GameObject val = new GameObject("BepInEx_ThreadingHelper") { hideFlags = (HideFlags)61 }; Object.DontDestroyOnLoad((Object)val); Instance = val.AddComponent(); } public void StartSyncInvoke(Action action) { if (action == null) { throw new ArgumentNullException("action"); } lock (_invokeLock) { _invokeList = (Action)Delegate.Combine(_invokeList, action); } } public void StartAsyncInvoke(Func action) { if (!ThreadPool.QueueUserWorkItem(DoWork)) { throw new NotSupportedException("Failed to queue the action on ThreadPool"); } void DoWork(object _) { try { Action action2 = action(); if (action2 != null) { StartSyncInvoke(action2); } } catch (Exception ex) { LogInvocationException(ex); } } } private static void LogInvocationException(Exception ex) { //IL_0010: 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_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown Logger.Log((LogLevel)2, (object)ex); if (ex.InnerException != null) { LogLevel val = (LogLevel)2; bool flag = default(bool); BepInExLogInterpolatedStringHandler val2 = new BepInExLogInterpolatedStringHandler(7, 1, val, ref flag); if (flag) { val2.AppendLiteral("INNER: "); val2.AppendFormatted(ex.InnerException); } Logger.Log(val, val2); } } IAsyncResult ISynchronizeInvoke.BeginInvoke(Delegate method, object[] args) { InvokeResult result = new InvokeResult(); if (!InvokeRequired) { result.Finish(Invoke(), completedSynchronously: true); } else { StartSyncInvoke(delegate { result.Finish(Invoke(), completedSynchronously: false); }); } return result; object Invoke() { try { return method.DynamicInvoke(args); } catch (Exception result2) { result.ExceptionThrown = true; return result2; } } } object ISynchronizeInvoke.EndInvoke(IAsyncResult result) { InvokeResult invokeResult = (InvokeResult)result; invokeResult.AsyncWaitHandle.WaitOne(); if (invokeResult.ExceptionThrown) { throw (Exception)invokeResult.AsyncState; } return invokeResult.AsyncState; } object ISynchronizeInvoke.Invoke(Delegate method, object[] args) { IAsyncResult result = ((ISynchronizeInvoke)this).BeginInvoke(method, args); return ((ISynchronizeInvoke)this).EndInvoke(result); } } public static class ThreadingExtensions { public static IEnumerable RunParallel(this IEnumerable data, Func work, int workerCount = -1) { foreach (TOut item in data.ToList().RunParallel(work)) { yield return item; } } public static IEnumerable RunParallel(this IList data, Func work, int workerCount = -1) { if (workerCount < 0) { workerCount = Mathf.Max(2, Environment.ProcessorCount); } else if (workerCount == 0) { throw new ArgumentException("Need at least 1 worker", "workerCount"); } int perThreadCount = Mathf.CeilToInt((float)data.Count / (float)workerCount); int doneCount = 0; object lockObj = new object(); ManualResetEvent are = new ManualResetEvent(initialState: false); IEnumerable doneItems = null; Exception exceptionThrown = null; for (int i = 0; i < workerCount; i++) { int first = i * perThreadCount; int last = Mathf.Min(first + perThreadCount, data.Count); ThreadPool.QueueUserWorkItem(delegate { List list = new List(perThreadCount); try { for (int j = first; j < last; j++) { if (exceptionThrown != null) { break; } list.Add(work(data[j])); } } catch (Exception ex) { exceptionThrown = ex; } lock (lockObj) { IEnumerable enumerable2; if (doneItems != null) { enumerable2 = list.Concat(doneItems); } else { IEnumerable enumerable3 = list; enumerable2 = enumerable3; } doneItems = enumerable2; int num = doneCount; doneCount = num + 1; are.Set(); } }); } bool isDone; do { are.WaitOne(); IEnumerable enumerable; lock (lockObj) { enumerable = doneItems; doneItems = null; isDone = doneCount == workerCount; } if (enumerable == null) { continue; } foreach (TOut item in enumerable) { yield return item; } } while (!isDone); if (exceptionThrown != null) { throw new TargetInvocationException("An exception was thrown inside one of the threads", exceptionThrown); } } public static void ForEachParallel(this IList data, Action work, int workerCount = -1) { if (workerCount < 0) { workerCount = Mathf.Max(2, Environment.ProcessorCount); } else if (workerCount == 0) { throw new ArgumentException("Need at least 1 worker", "workerCount"); } int currentIndex = data.Count; ManualResetEvent are = new ManualResetEvent(initialState: false); int runningCount = workerCount; Exception exceptionThrown = null; for (int i = 0; i < workerCount - 1; i++) { ThreadPool.QueueUserWorkItem(DoWork); } DoWork(null); are.WaitOne(); if (exceptionThrown != null) { throw new TargetInvocationException("An exception was thrown inside one of the threads", exceptionThrown); } void DoWork(object _) { try { while (exceptionThrown == null) { int num = Interlocked.Decrement(ref currentIndex); if (num < 0) { break; } work(data[num]); } } catch (Exception ex) { exceptionThrown = ex; } finally { if (Interlocked.Decrement(ref runningCount) <= 0) { are.Set(); } } } } } internal static class UnityTomlTypeConverters { [MethodImpl(MethodImplOptions.NoInlining)] public static void AddUnityEngineConverters() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown //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_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Expected O, but got Unknown //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Expected O, but got Unknown TypeConverter val = new TypeConverter { ConvertToString = (object obj, Type type) => ColorUtility.ToHtmlStringRGBA((Color)obj), ConvertToObject = delegate(string str, Type type) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) Color val3 = default(Color); if (!ColorUtility.TryParseHtmlString("#" + str.Trim('#', ' '), ref val3)) { throw new FormatException("Invalid color string, expected hex #RRGGBBAA"); } return val3; } }; TomlTypeConverter.AddConverter(typeof(Color), val); TypeConverter val2 = new TypeConverter { ConvertToString = (object obj, Type type) => JsonUtility.ToJson(obj), ConvertToObject = (string str, Type type) => JsonUtility.FromJson(str, type) }; TomlTypeConverter.AddConverter(typeof(Vector2), val2); TomlTypeConverter.AddConverter(typeof(Vector3), val2); TomlTypeConverter.AddConverter(typeof(Vector4), val2); TomlTypeConverter.AddConverter(typeof(Quaternion), val2); TomlTypeConverter.AddConverter(typeof(Rect), new TypeConverter { ConvertToObject = StringToRect, ConvertToString = RectToString }); } private static object StringToRect(string s, Type type) { //IL_0002: 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_011b: Unknown result type (might be due to invalid IL or missing references) Rect val = default(Rect); if (s == null) { return val; } string[] array = s.Trim('{', '}').Replace(" ", "").Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { ':' }); if (array2.Length == 2 && float.TryParse(array2[1], out var result)) { switch (array2[0].Trim(new char[1] { '"' })) { case "x": ((Rect)(ref val)).x = result; break; case "y": ((Rect)(ref val)).y = result; break; case "width": case "z": ((Rect)(ref val)).width = result; break; case "height": case "w": ((Rect)(ref val)).height = result; break; } } } return val; } private static string RectToString(object o, Type type) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) Rect val = (Rect)o; return string.Format(CultureInfo.InvariantCulture, "{{ \"x\":{0}, \"y\":{1}, \"width\":{2}, \"height\":{3} }}", ((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width, ((Rect)(ref val)).height); } } } namespace BepInEx.Unity.Mono.Logging { public class UnityLogListener : ILogListener, IDisposable { internal static readonly Action WriteStringToUnityLog; protected static readonly ConfigEntry ConfigUnityLogLevel; private readonly ConfigEntry LogConsoleToUnity = ConfigFile.CoreConfig.Bind("Logging", "LogConsoleToUnityLog", false, new StringBuilder().AppendLine("If enabled, writes Standard Output messages to Unity log").AppendLine("NOTE: By default, Unity does so automatically. Only use this option if no console messages are visible in Unity log").ToString()); public LogLevel LogLevelFilter => ConfigUnityLogLevel.Value; static UnityLogListener() { ConfigUnityLogLevel = ConfigFile.CoreConfig.Bind("Logging.Unity", "LogLevels", (LogLevel)31, "What log levels to log to Unity's output log."); MethodInfo[] methods = typeof(UnityLogWriter).GetMethods(BindingFlags.Static | BindingFlags.Public); foreach (MethodInfo methodInfo in methods) { try { methodInfo.Invoke(null, new object[1] { "" }); } catch { continue; } WriteStringToUnityLog = (Action)Delegate.CreateDelegate(typeof(Action), methodInfo); break; } if (WriteStringToUnityLog == null) { Logger.Log((LogLevel)2, (object)"Unable to start Unity log writer"); } } public void LogEvent(object sender, LogEventArgs eventArgs) { if (!(eventArgs.Source is UnityLogSource) && (LogConsoleToUnity.Value || eventArgs.Source.SourceName != "Console")) { WriteStringToUnityLog?.Invoke(eventArgs.ToStringLine()); } } public void Dispose() { } } public class UnityLogSource : ILogSource, IDisposable { private bool disposed; public string SourceName { get; } = "Unity Log"; public event EventHandler LogEvent; private static event EventHandler InternalUnityLogMessage; public UnityLogSource() { InternalUnityLogMessage += UnityLogMessageHandler; } public void Dispose() { if (!disposed) { InternalUnityLogMessage -= UnityLogMessageHandler; disposed = true; } } private void UnityLogMessageHandler(object sender, LogEventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown LogEventArgs e = new LogEventArgs(eventArgs.Data, eventArgs.Level, (ILogSource)(object)this); this.LogEvent?.Invoke(this, e); } static UnityLogSource() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Expected O, but got Unknown LogCallback val = new LogCallback(OnUnityLogMessageReceived); EventInfo eventInfo = typeof(Application).GetEvent("logMessageReceived", BindingFlags.Static | BindingFlags.Public); if ((object)eventInfo != null) { eventInfo.AddEventHandler(null, (Delegate?)(object)val); return; } typeof(Application).GetMethod("RegisterLogCallback", BindingFlags.Static | BindingFlags.Public).Invoke(null, new object[1] { val }); } private static void OnUnityLogMessageReceived(string message, string stackTrace, LogType type) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected I4, but got Unknown //IL_001d: 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_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Invalid comparison between Unknown and I4 //IL_0045: 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_0051: Expected O, but got Unknown LogLevel val; switch ((int)type) { case 0: case 1: case 4: val = (LogLevel)2; break; case 2: val = (LogLevel)4; break; default: val = (LogLevel)16; break; } if ((int)type == 4) { message = message + "\nStack trace:\n" + stackTrace; } UnityLogSource.InternalUnityLogMessage?.Invoke(null, new LogEventArgs((object)message, val, (ILogSource)null)); } } } namespace BepInEx.Unity.Mono.Configuration { public struct KeyboardShortcut { public static readonly KeyboardShortcut Empty; private static KeyCode[] modifierBlockKeyCodes; private readonly KeyCode[] _allKeys; public KeyCode MainKey { get { if (_allKeys != null && _allKeys.Length != 0) { return _allKeys[0]; } return (KeyCode)0; } } public IEnumerable Modifiers => _allKeys?.Skip(1) ?? Enumerable.Empty(); static KeyboardShortcut() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_0040: Expected O, but got Unknown TomlTypeConverter.AddConverter(typeof(KeyboardShortcut), new TypeConverter { ConvertToString = (object o, Type type) => ((KeyboardShortcut)o).Serialize(), ConvertToObject = (string s, Type type) => Deserialize(s) }); } public KeyboardShortcut(KeyCode mainKey, params KeyCode[] modifiers) : this(((IEnumerable)(object)new KeyCode[1] { (KeyCode)(int)mainKey }).Concat(modifiers).ToArray()) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Expected I4, but got Unknown //IL_001b: Unknown result type (might be due to invalid IL or missing references) if ((int)mainKey == 0 && modifiers.Any()) { throw new ArgumentException("Can't set mainKey to KeyCode.None if there are any modifiers"); } } private KeyboardShortcut(KeyCode[] keys) { _allKeys = SanitizeKeys(keys); } private static KeyCode[] SanitizeKeys(params KeyCode[] keys) { if (keys.Length == 0 || (int)keys[0] == 0) { return (KeyCode[])(object)new KeyCode[1]; } return ((IEnumerable)(object)new KeyCode[1] { keys[0] }).Concat(from x in keys.Skip(1).Distinct() where (int)x != (int)keys[0] orderby (int)x select x).ToArray(); } public static KeyboardShortcut Deserialize(string str) { try { return new KeyboardShortcut(((IEnumerable)str.Split(new char[5] { ' ', '+', ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries)).Select((Func)((string x) => (KeyCode)Enum.Parse(typeof(KeyCode), x))).ToArray()); } catch (SystemException ex) { Logger.Log((LogLevel)2, (object)("Failed to read keybind from settings: " + ex.Message)); return Empty; } } public unsafe string Serialize() { if (_allKeys == null) { return string.Empty; } return string.Join(" + ", _allKeys.Select((KeyCode x) => ((object)(*(KeyCode*)(&x))/*cast due to .constrained prefix*/).ToString()).ToArray()); } public bool IsDown() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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) KeyCode mainKey = MainKey; if ((int)mainKey == 0) { return false; } if (UnityInput.Current.GetKeyDown(mainKey)) { return ModifierKeyTest(); } return false; } public bool IsPressed() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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) KeyCode mainKey = MainKey; if ((int)mainKey == 0) { return false; } if (UnityInput.Current.GetKey(mainKey)) { return ModifierKeyTest(); } return false; } public bool IsUp() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0007: 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) KeyCode mainKey = MainKey; if ((int)mainKey == 0) { return false; } if (UnityInput.Current.GetKeyUp(mainKey)) { return ModifierKeyTest(); } return false; } private bool ModifierKeyTest() { //IL_0014: 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) KeyCode[] allKeys = _allKeys; KeyCode mainKey = MainKey; if (!allKeys.All((KeyCode c) => c == mainKey || UnityInput.Current.GetKey(c))) { return false; } if (modifierBlockKeyCodes == null) { modifierBlockKeyCodes = UnityInput.Current.SupportedKeyCodes.Except(new <>z__ReadOnlyArray((KeyCode[])(object)new KeyCode[8] { (KeyCode)323, (KeyCode)324, (KeyCode)325, (KeyCode)326, (KeyCode)327, (KeyCode)328, (KeyCode)329, default(KeyCode) })).ToArray(); } return modifierBlockKeyCodes.All((KeyCode c) => !UnityInput.Current.GetKey(c) || allKeys.Contains(c)); } public unsafe override string ToString() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if ((int)MainKey == 0) { return "Not set"; } return string.Join(" + ", _allKeys.Select((KeyCode c) => ((object)(*(KeyCode*)(&c))/*cast due to .constrained prefix*/).ToString()).ToArray()); } public override bool Equals(object obj) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) if (obj is KeyboardShortcut keyboardShortcut && MainKey == keyboardShortcut.MainKey) { return Modifiers.SequenceEqual(keyboardShortcut.Modifiers); } return false; } public override int GetHashCode() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) if ((int)MainKey == 0) { return 0; } return _allKeys.Aggregate(_allKeys.Length, (int current, KeyCode item) => current * 31 + item); } } } namespace BepInEx.Unity.Mono.Bootstrap { public class UnityChainloader : BaseChainloader { private static readonly ConfigEntry ConfigUnityLogging = ConfigFile.CoreConfig.Bind("Logging", "UnityLogListening", true, "Enables showing unity log messages in the BepInEx logging system."); private static readonly ConfigEntry ConfigDiskWriteUnityLog = ConfigFile.CoreConfig.Bind("Logging.Disk", "WriteUnityLog", false, "Include unity log messages in log file output."); private static readonly bool staticStartHasBeenCalled = false; private string _consoleTitle; public static UnityChainloader Instance { get; set; } public static GameObject ManagerObject { get; private set; } protected override string ConsoleTitle => _consoleTitle; private static string UnityVersion { [MethodImpl(MethodImplOptions.NoInlining)] get { return Application.unityVersion; } } [Obsolete("This method is public due to a limitation with Unity 4.x. DO NOT CALL", true)] public static void StaticStart(string gameExePath = null) { //IL_003f: 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_0044: 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_004d: Expected O, but got Unknown try { if (staticStartHasBeenCalled) { throw new InvalidOperationException("Cannot call StaticStart again"); } Logger.Log((LogLevel)32, (object)"Entering chainloader StaticStart"); UnityChainloader unityChainloader = new UnityChainloader(); ((BaseChainloader)unityChainloader).Initialize(gameExePath); ((BaseChainloader)unityChainloader).Execute(); Logger.Log((LogLevel)32, (object)"Exiting chainloader StaticStart"); } catch (Exception ex) { LogLevel val = (LogLevel)1; bool flag = default(bool); BepInExLogInterpolatedStringHandler val2 = new BepInExLogInterpolatedStringHandler(44, 1, val, ref flag); if (flag) { val2.AppendLiteral("Unable to complete chainloader StaticStart: "); val2.AppendFormatted(ex.Message); } Logger.Log(val, val2); Logger.Log((LogLevel)1, (object)ex.StackTrace); } } public override void Initialize(string gameExePath = null) { //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_004b: Expected O, but got Unknown //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: 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) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Expected O, but got Unknown try { Logger.Log((LogLevel)32, (object)"Entering chainloader initialize"); Instance = this; UnityTomlTypeConverters.AddUnityEngineConverters(); Logger.Log((LogLevel)32, (object)"Initializing ThreadingHelper"); ThreadingHelper.Initialize(); Logger.Log((LogLevel)32, (object)"Creating Manager object"); ManagerObject = new GameObject("BepInEx_Manager") { hideFlags = (HideFlags)61 }; Object.DontDestroyOnLoad((Object)(object)ManagerObject); Logger.Log((LogLevel)32, (object)"Getting game product name"); PropertyInfo property = typeof(Application).GetProperty("productName", BindingFlags.Static | BindingFlags.Public); _consoleTitle = $"{BaseChainloader.CurrentAssemblyName} {BaseChainloader.CurrentAssemblyVersion} - {property?.GetValue(null, null) ?? Path.GetFileNameWithoutExtension(Process.GetCurrentProcess().ProcessName)}"; Logger.Log((LogLevel)32, (object)"Falling back to BaseChainloader initializer"); base.Initialize(gameExePath); Logger.Log((LogLevel)32, (object)"Exiting chainloader initialize"); } catch (Exception ex) { LogLevel val = (LogLevel)1; bool flag = default(bool); BepInExLogInterpolatedStringHandler val2 = new BepInExLogInterpolatedStringHandler(37, 1, val, ref flag); if (flag) { val2.AppendLiteral("Unable to complete chainloader init: "); val2.AppendFormatted(ex.Message); } Logger.Log(val, val2); Logger.Log((LogLevel)1, (object)ex.StackTrace); } } protected override void InitializeLoggers() { //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_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: 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_0035: 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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) base.InitializeLoggers(); Logger.Listeners.Add((ILogListener)(object)new UnityLogListener()); UnityVersion version = UnityInfo.Version; UnityInfo.SetRuntimeUnityVersion(UnityVersion); if (UnityInfo.Version != version) { LogLevel val = (LogLevel)16; bool flag = default(bool); BepInExLogInterpolatedStringHandler val2 = new BepInExLogInterpolatedStringHandler(21, 1, val, ref flag); if (flag) { val2.AppendLiteral("UnityPlayer version: "); val2.AppendFormatted(UnityInfo.Version); } Logger.Log(val, val2); } if (!ConfigDiskWriteUnityLog.Value) { DiskLogListener.BlacklistedSources.Add("Unity Log"); } ChainloaderLogHelper.RewritePreloaderLogs(); if (ConfigUnityLogging.Value) { Logger.Sources.Add((ILogSource)(object)new UnityLogSource()); } } public override BaseUnityPlugin LoadPlugin(PluginInfo pluginInfo, Assembly pluginAssembly) { return (BaseUnityPlugin)(object)ManagerObject.AddComponent(pluginAssembly.GetType(pluginInfo.TypeName)); } } }