using System;
using System.Collections;
using System.Collections.Concurrent;
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.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using HG.Reflection;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using MonoMod.RuntimeDetour.HookGen;
using RoR2;
using RoR2.Achievements;
using RoR2.ConVar;
using RoR2.EntitlementManagement;
using RoR2.Items;
using RoR2.Networking;
using RoR2.UI;
using RoR2.UI.MainMenu;
using RoR2BepInExPack.LegacyAssetSystem;
using RoR2BepInExPack.ModCompatibility;
using RoR2BepInExPack.ReflectionHooks;
using RoR2BepInExPack.VanillaFixes;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("RoR2BepInExPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+f2449232ff5758c68f0daeb98d90c09cdfe5837c")]
[assembly: AssemblyProduct("RoR2BepInExPack")]
[assembly: AssemblyTitle("RoR2BepInExPack")]
[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 IsReadOnlyAttribute : 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 RoR2BepInExPack
{
internal static class HookWatcher
{
private static DetourModManager ModManager { get; set; }
internal static void Init()
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Expected O, but got Unknown
ModManager = new DetourModManager();
ModManager.OnHook += LogOnHook;
ModManager.OnILHook += LogILHook;
ModManager.OnDetour += LogDetour;
ModManager.OnNativeDetour += LogNativeDetour;
HookEndpointManager.OnAdd += LogHookAdd;
HookEndpointManager.OnModify += LogHookModify;
HookEndpointManager.OnRemove += LogHookRemove;
}
internal static void Destroy()
{
HookEndpointManager.OnRemove -= LogHookRemove;
HookEndpointManager.OnModify -= LogHookModify;
HookEndpointManager.OnAdd -= LogHookAdd;
ModManager.OnNativeDetour -= LogNativeDetour;
ModManager.OnDetour -= LogDetour;
ModManager.OnILHook -= LogILHook;
ModManager.OnHook -= LogOnHook;
ModManager.Dispose();
ModManager = null;
}
private static void LogOnHook(Assembly hookOwner, MethodBase originalMethod, MethodBase _, object __)
{
LogMethod(originalMethod, hookOwner);
}
private static void LogILHook(Assembly hookOwner, MethodBase originalMethod, Manipulator _)
{
LogMethod(originalMethod, hookOwner);
}
private static void LogDetour(Assembly hookOwner, MethodBase originalMethod, MethodBase _)
{
LogMethod(originalMethod, hookOwner);
}
private static void LogNativeDetour(Assembly hookOwner, MethodBase originalMethod, IntPtr _, IntPtr __)
{
LogMethod(originalMethod, hookOwner);
}
private static bool LogHookAdd(MethodBase originalMethod, Delegate @delegate)
{
return LogMethod(originalMethod, @delegate.Method.Module.Assembly);
}
private static bool LogHookModify(MethodBase originalMethod, Delegate @delegate)
{
return LogMethod(originalMethod, @delegate.Method.Module.Assembly);
}
private static bool LogHookRemove(MethodBase originalMethod, Delegate @delegate)
{
return LogMethod(originalMethod, @delegate.Method.Module.Assembly, added: false);
}
private static bool LogMethod(MemberInfo originalMethod, Assembly hookOwnerAssembly, bool added = true)
{
if (originalMethod == null)
{
return true;
}
string text = "Not Found";
if (hookOwnerAssembly != null)
{
text = Path.GetFileName(hookOwnerAssembly.Location);
}
Type declaringType = originalMethod.DeclaringType;
string name = originalMethod.Name;
string text2 = ((declaringType != null) ? $"{declaringType}.{name}" : name);
Log.Debug("Hook " + (added ? "added" : "removed") + " by assembly: " + text + " for: " + text2);
return true;
}
}
internal static class Log
{
internal static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(object data)
{
_logSource.LogDebug(data);
}
internal static void Error(object data)
{
_logSource.LogError(data);
}
internal static void Fatal(object data)
{
_logSource.LogFatal(data);
}
internal static void Info(object data)
{
_logSource.LogInfo(data);
}
internal static void Message(object data)
{
_logSource.LogMessage(data);
}
internal static void Warning(object data)
{
_logSource.LogWarning(data);
}
}
[BepInPlugin("___riskofthunder.RoR2BepInExPack", "RoR2BepInExPack", "1.11.0")]
public class RoR2BepInExPack : BaseUnityPlugin
{
public const string PluginGUID = "___riskofthunder.RoR2BepInExPack";
public const string PluginName = "RoR2BepInExPack";
public const string PluginVersion = "1.11.0";
private void Awake()
{
Log.Init(((BaseUnityPlugin)this).Logger);
RoR2Application.isModded = true;
HookWatcher.Init();
InitHooks();
}
private void OnEnable()
{
EnableHooks();
}
private void OnDisable()
{
DisableHooks();
}
private void OnDestroy()
{
DestroyHooks();
HookWatcher.Destroy();
}
private void InitHooks()
{
ILLine.Init();
AutoCatchReflectionTypeLoadException.Init();
SaferAchievementManager.Init();
SaferSearchableAttribute.Init();
SaferResourceAvailability.Init();
FixConsoleLog.Init();
FixConVar.Init();
FixDeathAnimLog.Init();
FixNullBone.Init();
FixExtraGameModesMenu.Init();
FixProjectileCatalogLimitError.Init();
SaferWWise.Init();
FixNullEntitlement.Init();
FixExposeLog.Init();
FixNonLethalOneHP.Init();
FixRunScaling.Init();
FixCharacterBodyRemoveOldestTimedBuff.Init();
FixDedicatedServerMaxPlayerCount.Init();
LegacyResourcesDetours.Init();
LegacyShaderDetours.Init();
FixMultiCorrupt.Init(((BaseUnityPlugin)this).Config);
}
private static void EnableHooks()
{
ILLine.Enable();
AutoCatchReflectionTypeLoadException.Enable();
SaferAchievementManager.Enable();
SaferSearchableAttribute.Enable();
SaferResourceAvailability.Enable();
FixConsoleLog.Enable();
FixConVar.Enable();
FixDeathAnimLog.Enable();
FixNullBone.Enable();
FixExtraGameModesMenu.Enable();
FixProjectileCatalogLimitError.Enable();
SaferWWise.Enable();
FixNullEntitlement.Enable();
FixExposeLog.Enable();
FixNonLethalOneHP.Enable();
FixRunScaling.Enable();
FixCharacterBodyRemoveOldestTimedBuff.Enable();
FixDedicatedServerMaxPlayerCount.Enable();
LegacyResourcesDetours.Enable();
LegacyShaderDetours.Enable();
FixMultiCorrupt.Enable();
}
private static void DisableHooks()
{
FixMultiCorrupt.Disable();
LegacyShaderDetours.Disable();
LegacyResourcesDetours.Disable();
FixDedicatedServerMaxPlayerCount.Disable();
FixCharacterBodyRemoveOldestTimedBuff.Disable();
FixRunScaling.Disable();
FixNonLethalOneHP.Disable();
FixExposeLog.Disable();
FixNullEntitlement.Disable();
SaferWWise.Disable();
FixProjectileCatalogLimitError.Disable();
FixExtraGameModesMenu.Disable();
FixNullBone.Disable();
FixDeathAnimLog.Disable();
FixConsoleLog.Disable();
FixConVar.Disable();
SaferResourceAvailability.Disable();
SaferSearchableAttribute.Disable();
SaferAchievementManager.Disable();
AutoCatchReflectionTypeLoadException.Disable();
ILLine.Disable();
}
private static void DestroyHooks()
{
FixMultiCorrupt.Destroy();
LegacyShaderDetours.Destroy();
LegacyResourcesDetours.Destroy();
FixDedicatedServerMaxPlayerCount.Destroy();
FixCharacterBodyRemoveOldestTimedBuff.Destroy();
FixRunScaling.Destroy();
FixNonLethalOneHP.Destroy();
FixExposeLog.Destroy();
FixNullEntitlement.Destroy();
SaferWWise.Destroy();
FixProjectileCatalogLimitError.Destroy();
FixExtraGameModesMenu.Destroy();
FixNullBone.Destroy();
FixDeathAnimLog.Destroy();
FixConsoleLog.Destroy();
FixConVar.Destroy();
SaferResourceAvailability.Destroy();
SaferSearchableAttribute.Destroy();
SaferAchievementManager.Destroy();
AutoCatchReflectionTypeLoadException.Destroy();
ILLine.Destroy();
}
}
}
namespace RoR2BepInExPack.Utilities
{
public class FixedConditionalWeakTable<TKey, TValue> : FixedConditionalWeakTableManager.IShrinkable where TKey : class where TValue : class
{
private readonly struct WeakReferenceWrapper<T> where T : class
{
public readonly int targetHashCode;
public readonly WeakReference<T> weakReference;
public readonly T target;
public WeakReferenceWrapper(T target, bool strongReference)
{
targetHashCode = target.GetHashCode();
if (strongReference)
{
this.target = target;
weakReference = null;
}
else
{
this.target = null;
weakReference = new WeakReference<T>(target);
}
}
public WeakReferenceWrapper(int targetHashCode)
{
this.targetHashCode = targetHashCode;
target = null;
weakReference = null;
}
}
[StructLayout(LayoutKind.Sequential, Size = 1)]
private readonly struct WeakReferenceWrapperComparer<T> : IEqualityComparer<WeakReferenceWrapper<T>> where T : class
{
public bool Equals(WeakReferenceWrapper<T> first, WeakReferenceWrapper<T> second)
{
T target = first.target;
T target2 = second.target;
T target3;
if (target == null && first.weakReference == null)
{
return !second.weakReference.TryGetTarget(out target3);
}
if (target2 == null && second.weakReference == null)
{
return !first.weakReference.TryGetTarget(out target3);
}
if (target == null && !first.weakReference.TryGetTarget(out target))
{
return false;
}
if (target2 == null && !second.weakReference.TryGetTarget(out target2))
{
return false;
}
return target == target2;
}
public int GetHashCode(WeakReferenceWrapper<T> obj)
{
return obj.targetHashCode;
}
}
private ConstructorInfo cachedConstructor;
private readonly ConcurrentDictionary<WeakReferenceWrapper<TKey>, TValue> valueByKey = new ConcurrentDictionary<WeakReferenceWrapper<TKey>, TValue>(default(WeakReferenceWrapperComparer<TKey>));
public FixedConditionalWeakTable()
{
FixedConditionalWeakTableManager.Add(this);
}
public void Add(TKey key, TValue value)
{
if (key == null)
{
throw new ArgumentNullException("key");
}
if (!valueByKey.TryAdd(new WeakReferenceWrapper<TKey>(key, strongReference: false), value))
{
throw new ArgumentException("The key already exists");
}
}
public bool Remove(TKey key)
{
TValue value;
return valueByKey.TryRemove(new WeakReferenceWrapper<TKey>(key, strongReference: true), out value);
}
public bool TryGetValue(TKey key, out TValue value)
{
return valueByKey.TryGetValue(new WeakReferenceWrapper<TKey>(key, strongReference: true), out value);
}
public TValue GetValue(TKey key, Func<TKey, TValue> defaultFunc)
{
if (TryGetValue(key, out var value))
{
return value;
}
value = defaultFunc(key);
Add(key, value);
return value;
}
public TValue GetOrCreateValue(TKey key)
{
if (TryGetValue(key, out var value))
{
return value;
}
if ((object)cachedConstructor == null)
{
Type typeFromHandle = typeof(TValue);
cachedConstructor = typeFromHandle.GetConstructor(Array.Empty<Type>());
if ((object)cachedConstructor == null)
{
throw new MissingMethodException(typeFromHandle.FullName + " doesn't have public parameterless constructor");
}
}
value = (TValue)cachedConstructor.Invoke(Array.Empty<object>());
Add(key, value);
return value;
}
void FixedConditionalWeakTableManager.IShrinkable.Shrink()
{
foreach (KeyValuePair<WeakReferenceWrapper<TKey>, TValue> item in valueByKey)
{
if (!item.Key.weakReference.TryGetTarget(out var _))
{
valueByKey.TryRemove(new WeakReferenceWrapper<TKey>(item.Key.targetHashCode), out var _);
}
}
}
}
internal static class FixedConditionalWeakTableManager
{
internal interface IShrinkable
{
void Shrink();
}
private const int shrinkAttemptDelay = 2000;
private static readonly object lockObject = new object();
private static readonly List<WeakReference<IShrinkable>> instances = new List<WeakReference<IShrinkable>>();
private static int lastCollectionCount = 0;
public static void Add(IShrinkable weakTable)
{
lock (lockObject)
{
if (instances.Count == 0)
{
new Thread(ShrinkThreadLoop).Start();
}
instances.Add(new WeakReference<IShrinkable>(weakTable));
}
}
private static void ShrinkThreadLoop()
{
while (true)
{
Thread.Sleep(2000);
int num = GC.CollectionCount(2);
if (lastCollectionCount == num)
{
continue;
}
lastCollectionCount = num;
lock (lockObject)
{
for (int num2 = instances.Count - 1; num2 >= 0; num2--)
{
if (!instances[num2].TryGetTarget(out var target))
{
instances.RemoveAt(num2);
}
else
{
target.Shrink();
}
}
if (instances.Count == 0)
{
break;
}
}
}
}
}
}
namespace RoR2BepInExPack.VanillaFixes
{
internal class ILLine
{
private static ILHook _hook;
internal static void Init()
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
HookConfig val = default(HookConfig);
val.ManualApply = true;
_hook = new ILHook((MethodBase)typeof(StackTrace).GetMethod("AddFrames", (BindingFlags)(-1)), new Manipulator(ShowILLine));
}
internal static void Enable()
{
_hook.Apply();
}
internal static void Disable()
{
_hook.Undo();
}
internal static void Destroy()
{
_hook.Free();
}
private static void ShowILLine(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
try
{
ILCursor val = new ILCursor(il);
val.GotoNext(new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)typeof(StackFrame).GetMethod("GetFileLineNumber", (BindingFlags)(-1)))
});
val.RemoveRange(2);
val.EmitDelegate<Func<StackFrame, string>>((Func<StackFrame, string>)GetLineOrIL);
}
catch (Exception arg)
{
Log.Error(string.Format("{0} hook failed.{1}{2}", "ShowILLine", Environment.NewLine, arg));
}
}
private static string GetLineOrIL(StackFrame instace)
{
int fileLineNumber = instace.GetFileLineNumber();
if (fileLineNumber != -1 && fileLineNumber != 0)
{
return fileLineNumber.ToString();
}
return "IL_" + instace.GetILOffset().ToString("X4");
}
}
internal class FixCharacterBodyRemoveOldestTimedBuff
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__FixRemoveOldestTimedBuff;
}
private static ILHook _ilHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_0063: Expected O, but got Unknown
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0057: Expected O, but got Unknown
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
MethodInfo? method = typeof(CharacterBody).GetMethod("RemoveOldestTimedBuff", (BindingFlags)(-1), null, new Type[1] { typeof(BuffIndex) }, null);
object obj = <>O.<0>__FixRemoveOldestTimedBuff;
if (obj == null)
{
Manipulator val3 = FixRemoveOldestTimedBuff;
<>O.<0>__FixRemoveOldestTimedBuff = val3;
obj = (object)val3;
}
_ilHook = new ILHook((MethodBase)method, (Manipulator)obj, ref val2);
}
internal static void Enable()
{
_ilHook.Apply();
}
internal static void Disable()
{
_ilHook.Undo();
}
internal static void Destroy()
{
_ilHook.Free();
}
private static void FixRemoveOldestTimedBuff(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
ILLabel val2 = default(ILLabel);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 1),
(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchBle(x, ref val2)
}))
{
val.Previous.OpCode = OpCodes.Blt;
}
else
{
Log.Error("FixRemoveOldestTimedBuff TryGotoNext failed, not applying patch");
}
}
}
internal class FixConsoleLog
{
private static Hook _hook;
internal static void Init()
{
//IL_0002: 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_0011: 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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
HookConfig val = default(HookConfig);
val.ManualApply = true;
HookConfig val2 = val;
_hook = new Hook((MethodBase)typeof(UnitySystemConsoleRedirector).GetMethod("Redirect", (BindingFlags)(-1)), typeof(FixConsoleLog).GetMethod("DoNothing", (BindingFlags)(-1)), val2);
}
internal static void Enable()
{
_hook.Apply();
}
internal static void Disable()
{
_hook.Undo();
}
internal static void Destroy()
{
_hook.Free();
}
private static void DoNothing()
{
}
}
internal static class FixConVar
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__ScanAllAssemblies;
public static Action<Console> <1>__LoadAllConVars;
}
private static ILHook _ilHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_004e: Expected O, but got Unknown
//IL_0037: 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
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
MethodInfo? method = typeof(Console).GetMethod("InitConVars", (BindingFlags)(-1));
object obj = <>O.<0>__ScanAllAssemblies;
if (obj == null)
{
Manipulator val3 = ScanAllAssemblies;
<>O.<0>__ScanAllAssemblies = val3;
obj = (object)val3;
}
_ilHook = new ILHook((MethodBase)method, (Manipulator)obj, ref val2);
}
internal static void Enable()
{
_ilHook.Apply();
}
internal static void Disable()
{
_ilHook.Undo();
}
internal static void Destroy()
{
_ilHook.Free();
}
private static void ScanAllAssemblies(ILContext il)
{
//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_0012: 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)
ILCursor val = new ILCursor(il);
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Action<Console>>((Action<Console>)LoadAllConVars);
val.Emit(OpCodes.Ret);
}
private static bool IsMonoFriendlyType(this Type type)
{
if (type.GetFields((BindingFlags)(-1)).Any((FieldInfo fi) => fi.FieldType.Name == "MonoFNPtrFakeClass"))
{
Log.Debug($"Not scanning {type} for ConVars due to it containing delegate pointer field(s)");
return false;
}
return true;
}
private static void LoadAllConVars(Console self)
{
//IL_0278: Unknown result type (might be due to invalid IL or missing references)
//IL_027f: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Expected O, but got Unknown
self.allConVars = new Dictionary<string, BaseConVar>();
self.archiveConVars = new List<BaseConVar>();
List<Type> list = new List<Type>();
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
try
{
if (assembly.GetCustomAttribute<OptInAttribute>() != null)
{
list.AddRange(from t in assembly.GetTypes()
where t.IsMonoFriendlyType()
select t);
}
}
catch (Exception data)
{
Log.Debug(data);
}
}
foreach (Type item in list)
{
try
{
FieldInfo[] fields = item.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fields)
{
try
{
if (fieldInfo.FieldType.IsSubclassOf(typeof(BaseConVar)))
{
if (fieldInfo.IsStatic)
{
BaseConVar val = (BaseConVar)fieldInfo.GetValue(null);
self.RegisterConVarInternal(val);
}
else if (item.GetCustomAttribute<CompilerGeneratedAttribute>() == null)
{
Debug.LogError((object)("ConVar defined as " + item.Name + "." + fieldInfo.Name + " could not be registered. ConVars must be static fields."));
}
}
}
catch (Exception data2)
{
Log.Debug(data2);
}
}
MethodInfo[] methods = item.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo in methods)
{
try
{
if (((MemberInfo)methodInfo).GetCustomAttribute<ConVarProviderAttribute>() == null)
{
continue;
}
if (methodInfo.ReturnType != typeof(IEnumerable<BaseConVar>) || methodInfo.GetParameters().Length != 0)
{
Debug.LogError((object)"ConVar provider {type.Name}.{methodInfo.Name} does not match the signature \"static IEnumerable<ConVar.BaseConVar>()\".");
continue;
}
if (!methodInfo.IsStatic)
{
Debug.LogError((object)("ConVar provider " + item.Name + "." + methodInfo.Name + " could not be invoked. Methods marked with the ConVarProvider attribute must be static."));
continue;
}
foreach (BaseConVar item2 in (IEnumerable<BaseConVar>)methodInfo.Invoke(null, Array.Empty<object>()))
{
self.RegisterConVarInternal(item2);
}
}
catch (Exception data3)
{
Log.Debug(data3);
}
}
}
catch (Exception data4)
{
Log.Debug(data4);
}
}
foreach (BaseConVar value in self.allConVars.Values)
{
try
{
if ((value.flags & 0x10) != 0)
{
value.defaultValue = value.GetString();
}
else if (value.defaultValue != null)
{
value.AttemptSetString(value.defaultValue);
}
}
catch (Exception data5)
{
Log.Error(data5);
}
}
}
}
internal class FixDeathAnimLog
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__FixLackingAnim;
}
private static ILHook _ilHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_004e: Expected O, but got Unknown
//IL_0037: 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
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
MethodInfo? method = typeof(GenericCharacterDeath).GetMethod("PlayDeathAnimation", (BindingFlags)(-1));
object obj = <>O.<0>__FixLackingAnim;
if (obj == null)
{
Manipulator val3 = FixLackingAnim;
<>O.<0>__FixLackingAnim = val3;
obj = (object)val3;
}
_ilHook = new ILHook((MethodBase)method, (Manipulator)obj, ref val2);
}
internal static void Enable()
{
_ilHook.Apply();
}
internal static void Disable()
{
_ilHook.Undo();
}
internal static void Destroy()
{
_ilHook.Free();
}
private static void FixLackingAnim(ILContext il)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
ILLabel label = val.DefineLabel();
MethodReference val2 = default(MethodReference);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, ref val2),
(Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref label)
}))
{
val.Emit(OpCodes.Ldloc_0);
val.EmitDelegate<Func<Animator, bool>>((Func<Animator, bool>)delegate(Animator anim)
{
for (int i = 0; i < anim.layerCount; i++)
{
if (anim.HasState(i, Animator.StringToHash("Death")))
{
return true;
}
}
return false;
});
val.Emit(OpCodes.Brfalse, (object)label);
}
else
{
Log.Error("FixDeathAnimLog TryGotoNext failed, not applying patch");
}
}
}
internal class FixDedicatedServerMaxPlayerCount
{
private static Hook _hook;
private static Hook _hook2;
internal static void Init()
{
//IL_0002: 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_0011: 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_0070: Expected O, but got Unknown
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Expected O, but got Unknown
HookConfig val = default(HookConfig);
val.ManualApply = true;
HookConfig val2 = val;
_hook = new Hook((MethodBase)typeof(NetworkManager).GetMethod("StartHost", (BindingFlags)(-1), null, new Type[2]
{
typeof(ConnectionConfig),
typeof(int)
}, null), (Delegate)new Func<Func<NetworkManager, ConnectionConfig, int, NetworkClient>, NetworkManager, ConnectionConfig, int, NetworkClient>(FixUsageOfMaxPlayerCountVariable), ref val2);
_hook2 = new Hook((MethodBase)typeof(NetworkManager).GetMethod("StartServer", (BindingFlags)(-1), null, new Type[2]
{
typeof(ConnectionConfig),
typeof(int)
}, null), (Delegate)new Func<Func<NetworkManager, ConnectionConfig, int, bool>, NetworkManager, ConnectionConfig, int, bool>(FixUsageOfMaxPlayerCountVariable2), ref val2);
}
internal static void Enable()
{
_hook.Apply();
_hook2.Apply();
}
internal static void Disable()
{
_hook2.Undo();
_hook.Undo();
}
internal static void Destroy()
{
_hook2.Free();
_hook.Free();
}
private static NetworkClient FixUsageOfMaxPlayerCountVariable(Func<NetworkManager, ConnectionConfig, int, NetworkClient> orig, NetworkManager self, ConnectionConfig config, int maxConnections)
{
return orig(self, config, SvMaxPlayersConVar.instance.intValue);
}
private static bool FixUsageOfMaxPlayerCountVariable2(Func<NetworkManager, ConnectionConfig, int, bool> orig, NetworkManager self, ConnectionConfig config, int maxConnections)
{
return orig(self, config, SvMaxPlayersConVar.instance.intValue);
}
}
internal class FixExposeLog
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__FixAddingExpose;
}
private static ILHook _ilHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_004e: Expected O, but got Unknown
//IL_0037: 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
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
MethodInfo? method = typeof(HealthComponent).GetMethod("TakeDamage", (BindingFlags)(-1));
object obj = <>O.<0>__FixAddingExpose;
if (obj == null)
{
Manipulator val3 = FixAddingExpose;
<>O.<0>__FixAddingExpose = val3;
obj = (object)val3;
}
_ilHook = new ILHook((MethodBase)method, (Manipulator)obj, ref val2);
}
internal static void Enable()
{
_ilHook.Apply();
}
internal static void Disable()
{
_ilHook.Undo();
}
internal static void Destroy()
{
_ilHook.Free();
}
private static void FixAddingExpose(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
ILLabel val2 = val.DefineLabel();
FieldReference val3 = default(FieldReference);
bool num = val.TryGotoNext(new Func<Instruction, bool>[4]
{
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 0),
(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, ref val3),
(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(Buffs).GetField("MercExpose")),
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, (MethodBase)typeof(CharacterBody).GetMethod("AddBuff", new Type[1] { typeof(BuffDef) }))
});
val.MarkLabel(val2);
if (num & val.TryGotoPrev(new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdstr(x, "Adding expose")
}))
{
val.Emit(OpCodes.Br, (object)val2);
}
else
{
Log.Error("FixExposeLog TryGotoNext failed, not applying patch");
}
}
}
internal class FixExtraGameModesMenu
{
private static Hook _hook;
internal static void Init()
{
//IL_0002: 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_0011: 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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
HookConfig val = default(HookConfig);
val.ManualApply = true;
HookConfig val2 = val;
_hook = new Hook((MethodBase)typeof(MainMenuController).GetMethod("Start", (BindingFlags)(-1)), typeof(FixExtraGameModesMenu).GetMethod("FixIt", (BindingFlags)(-1)), val2);
}
internal static void Enable()
{
_hook.Apply();
}
internal static void Disable()
{
_hook.Undo();
}
internal static void Destroy()
{
_hook.Free();
}
private static void FixIt(Action<MainMenuController> orig, MainMenuController self)
{
orig(self);
MPButton val = ((IEnumerable<MPButton>)((Component)self.extraGameModeMenuScreen).GetComponentsInChildren<MPButton>()).FirstOrDefault((Func<MPButton, bool>)((MPButton b) => ((Object)b).name == "GenericMenuButton (Eclipse)"));
if (Object.op_Implicit((Object)(object)val))
{
val.defaultFallbackButton = true;
}
}
}
internal class FixNonLethalOneHP
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__FixLethality;
}
private static ILHook _ilHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_004e: Expected O, but got Unknown
//IL_0037: 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
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
MethodInfo? method = typeof(HealthComponent).GetMethod("TakeDamage", (BindingFlags)(-1));
object obj = <>O.<0>__FixLethality;
if (obj == null)
{
Manipulator val3 = FixLethality;
<>O.<0>__FixLethality = val3;
obj = (object)val3;
}
_ilHook = new ILHook((MethodBase)method, (Manipulator)obj, ref val2);
}
internal static void Enable()
{
_ilHook.Apply();
}
internal static void Disable()
{
_ilHook.Undo();
}
internal static void Destroy()
{
_ilHook.Free();
}
private static void FixLethality(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
ILLabel val2 = default(ILLabel);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdfld(x, typeof(HealthComponent).GetField("health", (BindingFlags)(-1))),
(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 1f),
(Instruction x) => ILPatternMatchingExt.MatchBltUn(x, ref val2)
}))
{
int index = val.Index;
val.Index = index - 1;
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Func<float, HealthComponent, float>>((Func<float, HealthComponent, float>)((float targetHealth, HealthComponent self) => (!(self.health > 0f)) ? targetHealth : 0f));
}
else
{
Log.Error("FixNonLethalOneHP TryGotoNext failed, not applying patch");
}
}
}
internal class FixNullBone
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__FixBoneCheck;
}
private static ILHook _ilHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_004e: Expected O, but got Unknown
//IL_0037: 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
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
MethodInfo? method = typeof(DynamicBone).GetMethod("ApplyParticlesToTransforms", (BindingFlags)(-1));
object obj = <>O.<0>__FixBoneCheck;
if (obj == null)
{
Manipulator val3 = FixBoneCheck;
<>O.<0>__FixBoneCheck = val3;
obj = (object)val3;
}
_ilHook = new ILHook((MethodBase)method, (Manipulator)obj, ref val2);
}
internal static void Enable()
{
_ilHook.Apply();
}
internal static void Disable()
{
_ilHook.Undo();
}
internal static void Destroy()
{
_ilHook.Free();
}
private static void FixBoneCheck(ILContext il)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
ILLabel ifLabel = val.DefineLabel();
int localIndex = -1;
MethodReference val2 = default(MethodReference);
if (val.TryGotoNext(new Func<Instruction, bool>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, ref val2),
(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 1),
(Instruction x) => ILPatternMatchingExt.MatchBgt(x, ref ifLabel)
}) && val.TryGotoPrev(new Func<Instruction, bool>[2]
{
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref localIndex),
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, localIndex)
}))
{
int index = val.Index;
val.Index = index + 1;
val.Emit(OpCodes.Ldloc, localIndex);
val.EmitDelegate<Func<Particle, bool>>((Func<Particle, bool>)((Particle p) => Object.op_Implicit((Object)(object)p?.m_Transform)));
val.Emit(OpCodes.Brfalse, (object)ifLabel);
}
else
{
Log.Error("FixNullBone TryGotoNext failed, not applying patch");
}
}
}
internal class FixProjectileCatalogLimitError
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__IncreaseCatalogLimit;
}
private static ILHook _ilHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_004e: Expected O, but got Unknown
//IL_0037: 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
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
MethodInfo? method = typeof(ProjectileCatalog).GetMethod("SetProjectilePrefabs", (BindingFlags)(-1));
object obj = <>O.<0>__IncreaseCatalogLimit;
if (obj == null)
{
Manipulator val3 = IncreaseCatalogLimit;
<>O.<0>__IncreaseCatalogLimit = val3;
obj = (object)val3;
}
_ilHook = new ILHook((MethodBase)method, (Manipulator)obj, ref val2);
}
internal static void Enable()
{
_ilHook.Apply();
}
internal static void Disable()
{
_ilHook.Undo();
}
internal static void Destroy()
{
_ilHook.Free();
}
private static void IncreaseCatalogLimit(ILContext il)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
int locLimitIndex = -1;
ILLabel breakLabel = val.DefineLabel();
if (val.TryGotoNext((MoveType)0, new Func<Instruction, bool>[7]
{
(Instruction x) => ILPatternMatchingExt.MatchLdcI4(x, 256),
(Instruction x) => ILPatternMatchingExt.MatchStloc(x, ref locLimitIndex),
(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(ProjectileCatalog).GetField("projectilePrefabs", (BindingFlags)(-1))),
(Instruction x) => ILPatternMatchingExt.MatchLdlen(x),
(Instruction x) => ILPatternMatchingExt.MatchConvI4(x),
(Instruction x) => ILPatternMatchingExt.MatchLdloc(x, locLimitIndex),
(Instruction x) => ILPatternMatchingExt.MatchBle(x, ref breakLabel)
}))
{
val.Emit(OpCodes.Br, (object)breakLabel);
}
else
{
Log.Error("IncreaseCatalogLimit TryGotoNext failed, not applying patch");
}
}
}
internal static class FixRunScaling
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__CalculateDifficultyCoefficientOnRunStart;
public static Action<Run> <1>__CallRecalculateDifficultyCoefficent;
}
private static ILHook _ilHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_004e: Expected O, but got Unknown
//IL_0037: 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
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
MethodInfo? method = typeof(Run).GetMethod("Start", (BindingFlags)(-1));
object obj = <>O.<0>__CalculateDifficultyCoefficientOnRunStart;
if (obj == null)
{
Manipulator val3 = CalculateDifficultyCoefficientOnRunStart;
<>O.<0>__CalculateDifficultyCoefficientOnRunStart = val3;
obj = (object)val3;
}
_ilHook = new ILHook((MethodBase)method, (Manipulator)obj, ref val2);
}
internal static void Enable()
{
_ilHook.Apply();
}
internal static void Disable()
{
_ilHook.Undo();
}
internal static void Destroy()
{
_ilHook.Free();
}
private static void CalculateDifficultyCoefficientOnRunStart(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_006a: 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>[1]
{
(Instruction i) => ILPatternMatchingExt.MatchStfld<Run>(i, "allowNewParticipants")
}))
{
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction i) => ILPatternMatchingExt.MatchStfld<Run>(i, "allowNewParticipants")
}))
{
val.Emit(OpCodes.Ldarg_0);
val.EmitDelegate<Action<Run>>((Action<Run>)CallRecalculateDifficultyCoefficent);
}
else
{
Log.Error("CalculateDifficultyCoefficientOnRunStart TryGotoNext 2 failed, not applying patch");
}
}
else
{
Log.Error("CalculateDifficultyCoefficientOnRunStart TryGotoNext 1 failed, not applying patch");
}
static void CallRecalculateDifficultyCoefficent(Run instance)
{
if (NetworkServer.active && Object.op_Implicit((Object)(object)instance))
{
instance.RecalculateDifficultyCoefficent();
}
}
}
}
public class SaferAchievementManager
{
private static Hook _hook;
private static FieldInfo _achievementManagerOnAchievementsRegisteredFieldInfo;
public static event Func<Type, RegisterAchievementAttribute, RegisterAchievementAttribute> OnRegisterAchievementAttributeFound;
public static event Action<List<string>, Dictionary<string, AchievementDef>, List<AchievementDef>> OnCollectAchievementDefs;
internal static void Init()
{
//IL_0002: 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_0011: 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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
HookConfig val = default(HookConfig);
val.ManualApply = true;
HookConfig val2 = val;
_hook = new Hook((MethodBase)typeof(AchievementManager).GetMethod("CollectAchievementDefs", (BindingFlags)(-1)), typeof(SaferAchievementManager).GetMethod("SaferCollectAchievementDefs", (BindingFlags)(-1)), val2);
_achievementManagerOnAchievementsRegisteredFieldInfo = typeof(AchievementManager).GetField("onAchievementsRegistered", (BindingFlags)(-1));
}
internal static void Enable()
{
_hook.Apply();
}
internal static void Disable()
{
_hook.Undo();
}
internal static void Destroy()
{
_hook.Free();
}
private static void SaferCollectAchievementDefs(Action<Dictionary<string, AchievementDef>> _, Dictionary<string, AchievementDef> achievementIdentifierToDef)
{
//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0204: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_0258: Unknown result type (might be due to invalid IL or missing references)
//IL_026a: Expected O, but got Unknown
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Expected O, but got Unknown
//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
//IL_03db: Unknown result type (might be due to invalid IL or missing references)
//IL_0400: Unknown result type (might be due to invalid IL or missing references)
//IL_040f: Unknown result type (might be due to invalid IL or missing references)
//IL_0411: Unknown result type (might be due to invalid IL or missing references)
List<AchievementDef> list = new List<AchievementDef>();
achievementIdentifierToDef.Clear();
List<Assembly> list2 = new List<Assembly>();
if (RoR2Application.isModded)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly item in assemblies)
{
list2.Add(item);
}
}
else
{
list2.Add(typeof(BaseAchievement).Assembly);
}
foreach (Assembly item2 in list2)
{
foreach (Type item3 in from _type in item2.GetTypes()
where _type.IsSubclassOf(typeof(BaseAchievement))
orderby _type.Name
select _type)
{
RegisterAchievementAttribute val = null;
try
{
val = (RegisterAchievementAttribute)item3.GetCustomAttributes(inherit: false).FirstOrDefault((object v) => v is RegisterAchievementAttribute);
if (SaferAchievementManager.OnRegisterAchievementAttributeFound != null)
{
val = SaferAchievementManager.OnRegisterAchievementAttributeFound(item3, val);
}
}
catch (Exception ex)
{
Log.Debug("RegisterAchievementAttribute type.GetCustomAttributes(false) failed for : " + item3.FullName + Environment.NewLine + ex);
}
if (val == null)
{
continue;
}
if (achievementIdentifierToDef.ContainsKey(val.identifier))
{
Debug.LogErrorFormat("Class {0} attempted to register as achievement {1}, but class {2} has already registered as that achievement.", new object[3]
{
item3.FullName,
val.identifier,
AchievementManager.achievementNamesToDefs[val.identifier].type.FullName
});
continue;
}
UnlockableDef unlockableDef = UnlockableCatalog.GetUnlockableDef(val.unlockableRewardIdentifier);
AchievementDef achievementDef2 = new AchievementDef
{
identifier = val.identifier,
unlockableRewardIdentifier = val.unlockableRewardIdentifier,
prerequisiteAchievementIdentifier = val.prerequisiteAchievementIdentifier,
nameToken = "ACHIEVEMENT_" + val.identifier.ToUpper(CultureInfo.InvariantCulture) + "_NAME",
descriptionToken = "ACHIEVEMENT_" + val.identifier.ToUpper(CultureInfo.InvariantCulture) + "_DESCRIPTION",
type = item3,
serverTrackerType = val.serverTrackerType
};
if (Object.op_Implicit((Object)(object)unlockableDef) && Object.op_Implicit((Object)(object)unlockableDef.achievementIcon))
{
achievementDef2.SetAchievedIcon(unlockableDef.achievementIcon);
}
else
{
achievementDef2.iconPath = "Textures/AchievementIcons/tex" + val.identifier + "Icon";
}
AchievementManager.achievementIdentifiers.Add(val.identifier);
achievementIdentifierToDef.Add(val.identifier, achievementDef2);
list.Add(achievementDef2);
if ((Object)(object)unlockableDef != (Object)null)
{
unlockableDef.getHowToUnlockString = () => Language.GetStringFormatted("UNLOCK_VIA_ACHIEVEMENT_FORMAT", new object[2]
{
Language.GetString(achievementDef2.nameToken),
Language.GetString(achievementDef2.descriptionToken)
});
unlockableDef.getUnlockedString = () => Language.GetStringFormatted("UNLOCKED_FORMAT", new object[2]
{
Language.GetString(achievementDef2.nameToken),
Language.GetString(achievementDef2.descriptionToken)
});
}
}
}
SaferAchievementManager.OnCollectAchievementDefs?.Invoke(AchievementManager.achievementIdentifiers, achievementIdentifierToDef, list);
AchievementManager.achievementDefs = list.ToArray();
AchievementManager.SortAchievements(AchievementManager.achievementDefs);
AchievementManager.serverAchievementDefs = AchievementManager.achievementDefs.Where((AchievementDef achievementDef) => achievementDef.serverTrackerType != null).ToArray();
for (int j = 0; j < AchievementManager.achievementDefs.Length; j++)
{
AchievementManager.achievementDefs[j].index = new AchievementIndex
{
intValue = j
};
}
for (int k = 0; k < AchievementManager.serverAchievementDefs.Length; k++)
{
AchievementManager.serverAchievementDefs[k].serverIndex = new ServerAchievementIndex
{
intValue = k
};
}
for (int l = 0; l < AchievementManager.achievementIdentifiers.Count; l++)
{
string currentAchievementIdentifier = AchievementManager.achievementIdentifiers[l];
achievementIdentifierToDef[currentAchievementIdentifier].childAchievementIdentifiers = AchievementManager.achievementIdentifiers.Where((string v) => achievementIdentifierToDef[v].prerequisiteAchievementIdentifier == currentAchievementIdentifier).ToArray();
}
((Action)_achievementManagerOnAchievementsRegisteredFieldInfo.GetValue(null))?.Invoke();
}
}
internal class SaferResourceAvailability
{
private delegate void orig_MakeAvailable(ref ResourceAvailability self);
private static Hook _hook;
private static FieldInfo _onAvailableBackingFieldInfo;
internal static void Init()
{
//IL_0002: 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_0011: 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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
HookConfig val = default(HookConfig);
val.ManualApply = true;
HookConfig val2 = val;
_hook = new Hook((MethodBase)typeof(ResourceAvailability).GetMethod("MakeAvailable", (BindingFlags)(-1)), typeof(SaferResourceAvailability).GetMethod("TryCatchEachLoopIteration", (BindingFlags)(-1)), val2);
_onAvailableBackingFieldInfo = typeof(ResourceAvailability).GetField("onAvailable", BindingFlags.Instance | BindingFlags.NonPublic);
}
internal static void Enable()
{
_hook.Apply();
}
internal static void Disable()
{
_hook.Undo();
}
internal static void Destroy()
{
_hook.Free();
}
private static void TryCatchEachLoopIteration(orig_MakeAvailable orig, ref ResourceAvailability self)
{
//IL_0016: 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)
if (((ResourceAvailability)(ref self)).available)
{
return;
}
((ResourceAvailability)(ref self)).available = true;
Action action = (Action)_onAvailableBackingFieldInfo.GetValue(self);
if (action == null)
{
return;
}
Delegate[] invocationList = action.GetInvocationList();
for (int i = 0; i < invocationList.Length; i++)
{
Action action2 = (Action)invocationList[i];
try
{
action2();
}
catch (Exception data)
{
Log.Error(data);
}
}
_onAvailableBackingFieldInfo.SetValue(self, null);
}
}
internal class SaferSearchableAttribute
{
private static Hook _saferCctorHook;
private static Hook _deterministicCctorTimingHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_0071: 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_007c: Expected O, but got Unknown
HookConfig val = default(HookConfig);
val.ManualApply = true;
HookConfig val2 = val;
_saferCctorHook = new Hook((MethodBase)typeof(SearchableAttribute).GetMethod("ScanAllAssemblies", (BindingFlags)(-1)), typeof(SaferSearchableAttribute).GetMethod("TryCatchEachLoopIteration", (BindingFlags)(-1)), val2);
_deterministicCctorTimingHook = new Hook((MethodBase)typeof(RoR2Application).GetMethod("OnLoad", (BindingFlags)(-1)), typeof(SaferSearchableAttribute).GetMethod("DeterministicCctorTiming", (BindingFlags)(-1)), val2);
}
internal static void Enable()
{
_saferCctorHook.Apply();
_deterministicCctorTimingHook.Apply();
}
internal static void Disable()
{
_deterministicCctorTimingHook.Undo();
_saferCctorHook.Undo();
}
internal static void Destroy()
{
_deterministicCctorTimingHook.Free();
_saferCctorHook.Free();
}
private static void TryCatchEachLoopIteration(Action _)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
try
{
ScanAssembly(assembly);
}
catch (Exception ex)
{
Log.Debug("ScanAssembly failed for assembly : " + assembly.FullName + Environment.NewLine + ex);
}
}
}
private static void ScanAssembly(Assembly assembly)
{
if (SearchableAttribute.assemblyBlacklist.Contains(assembly.FullName))
{
return;
}
SearchableAttribute.assemblyBlacklist.Add(assembly.FullName);
if (assembly.GetCustomAttribute<OptInAttribute>() == null)
{
return;
}
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
SearchableAttribute[] array = Array.Empty<SearchableAttribute>();
try
{
array = (from a in type.GetCustomAttributes(inherit: false)
where a is SearchableAttribute
select a).Cast<SearchableAttribute>().ToArray();
}
catch (Exception ex)
{
Log.Debug("ScanAssembly type.GetCustomAttributes(false) failed for : " + type.FullName + Environment.NewLine + ex);
}
SearchableAttribute[] array2 = array;
foreach (SearchableAttribute val in array2)
{
try
{
SearchableAttribute.RegisterAttribute(val, (object)type);
}
catch (Exception ex2)
{
Log.Debug("SearchableAttribute.RegisterAttribute(attribute, type) failed for : " + type.FullName + Environment.NewLine + ex2);
}
}
MemberInfo[] array3 = Array.Empty<MemberInfo>();
try
{
array3 = type.GetMembers(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
}
catch (Exception ex3)
{
Log.Debug("type.GetMembers failed for : " + type.FullName + Environment.NewLine + ex3);
}
MemberInfo[] array4 = array3;
foreach (MemberInfo memberInfo in array4)
{
SearchableAttribute[] array5 = Array.Empty<SearchableAttribute>();
try
{
array5 = (from a in memberInfo.GetCustomAttributes(inherit: false)
where a is SearchableAttribute
select a).Cast<SearchableAttribute>().ToArray();
}
catch (Exception ex4)
{
Log.Debug("memberInfo.GetCustomAttributes(false) failed for : " + type.FullName + Environment.NewLine + memberInfo.Name + Environment.NewLine + ex4);
}
array2 = array5;
foreach (SearchableAttribute val2 in array2)
{
try
{
SearchableAttribute.RegisterAttribute(val2, (object)memberInfo);
}
catch (Exception ex5)
{
Log.Debug("SearchableAttribute.RegisterAttribute(attribute, memberInfo) failed for : " + type.FullName + Environment.NewLine + memberInfo.Name + Environment.NewLine + ex5);
}
}
}
}
}
private static IEnumerator DeterministicCctorTiming(Func<RoR2Application, IEnumerator> orig, RoR2Application self)
{
RunCctorAgain();
return orig(self);
}
private static void RunCctorAgain()
{
typeof(SearchableAttribute).TypeInitializer.Invoke(null, null);
}
}
}
namespace RoR2BepInExPack.Reflection
{
internal class ReflectionHelper
{
internal const BindingFlags AllFlags = (BindingFlags)(-1);
}
}
namespace RoR2BepInExPack.ReflectionHooks
{
internal class AutoCatchReflectionTypeLoadException
{
private static Hook _onHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_0067: Expected O, but got Unknown
HookConfig val = default(HookConfig);
val.ManualApply = true;
HookConfig val2 = val;
_onHook = new Hook((MethodBase)typeof(Assembly).GetMethods((BindingFlags)(-1)).First((MethodInfo m) => m.Name == "GetTypes" && m.GetParameters().Length == 0 && (m.MethodImplementationFlags & MethodImplAttributes.InternalCall) == 0), typeof(AutoCatchReflectionTypeLoadException).GetMethod("SaferGetTypes", (BindingFlags)(-1)), ref val2);
}
internal static void Enable()
{
_onHook.Apply();
}
internal static void Disable()
{
_onHook.Undo();
}
internal static void Destroy()
{
_onHook.Free();
}
private static Type[] SaferGetTypes(Func<Assembly, Type[]> orig, Assembly self)
{
Type[] array = Array.Empty<Type>();
try
{
array = orig(self);
}
catch (ReflectionTypeLoadException ex)
{
array = ex.Types.Where((Type t) => t != null).ToArray();
Log.Debug($"Assembly.GetTypes() failed for {self.FullName} (threw ReflectionTypeLoadException). {ex}");
}
return array;
}
}
}
namespace RoR2BepInExPack.ModCompatibility
{
internal class FixMultiCorrupt
{
internal enum ContagionPriority
{
First,
Last,
Random,
Rarest,
Alternate
}
private class ContagionAlternateTracker : MonoBehaviour
{
private static readonly Dictionary<Inventory, ContagionAlternateTracker> instances = new Dictionary<Inventory, ContagionAlternateTracker>();
private readonly Dictionary<ItemIndex, int> contagions = new Dictionary<ItemIndex, int>();
private Inventory inventory;
private void Awake()
{
inventory = ((Component)this).GetComponent<Inventory>();
instances[inventory] = this;
}
private void OnDestroy()
{
instances.Remove(inventory);
}
public int AddContagion(ItemIndex itemIndex)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
if (contagions.TryGetValue(itemIndex, out var value))
{
return contagions[itemIndex] = value + 1;
}
return contagions[itemIndex] = 0;
}
public static ContagionAlternateTracker GetOrAdd(Inventory inventory)
{
if (instances.TryGetValue(inventory, out var value))
{
return value;
}
return ((Component)inventory).gameObject.AddComponent<ContagionAlternateTracker>();
}
}
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__FixStep;
}
private static ILHook _stepInventoryInfectionILHook;
private static Hook _generateStageRNGOnHook;
private static Xoroshiro128Plus _voidRNG;
private static ConfigEntry<ContagionPriority> _contagionPriority;
internal static void Init(ConfigFile config)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Expected O, but got Unknown
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Expected O, but got Unknown
//IL_0052: 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: Expected O, but got Unknown
_contagionPriority = config.Bind<ContagionPriority>("General", "Contagion Priority", ContagionPriority.Random, "Determines behaviour for when multiple results are available for an item transformation.");
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
MethodInfo? method = typeof(ContagiousItemManager).GetMethod("StepInventoryInfection", (BindingFlags)(-1));
object obj = <>O.<0>__FixStep;
if (obj == null)
{
Manipulator val3 = FixStep;
<>O.<0>__FixStep = val3;
obj = (object)val3;
}
_stepInventoryInfectionILHook = new ILHook((MethodBase)method, (Manipulator)obj, ref val2);
HookConfig val4 = default(HookConfig);
val4.ManualApply = true;
HookConfig val5 = val4;
_generateStageRNGOnHook = new Hook((MethodBase)typeof(Run).GetMethod("GenerateStageRNG", (BindingFlags)(-1)), typeof(FixMultiCorrupt).GetMethod("OnGenerateStageRNG", (BindingFlags)(-1)), ref val5);
}
internal static void Enable()
{
_stepInventoryInfectionILHook.Apply();
_generateStageRNGOnHook.Apply();
}
internal static void Disable()
{
_stepInventoryInfectionILHook.Undo();
_generateStageRNGOnHook.Undo();
}
internal static void Destroy()
{
_stepInventoryInfectionILHook.Free();
_generateStageRNGOnHook.Free();
}
private static void FixStep(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_007d: 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_0096: 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>[3]
{
(Instruction x) => ILPatternMatchingExt.MatchLdsfld(x, typeof(ContagiousItemManager).GetField("originalToTransformed", (BindingFlags)(-1))),
(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, 1),
(Instruction x) => ILPatternMatchingExt.MatchLdelemI4(x)
}))
{
val.Emit(OpCodes.Pop);
val.Emit(OpCodes.Ldarg, 0);
val.Emit(OpCodes.Ldarg, 1);
val.EmitDelegate<Func<Inventory, ItemIndex, ItemIndex>>((Func<Inventory, ItemIndex, ItemIndex>)delegate(Inventory inventory, ItemIndex pureItem)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: 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_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
List<ItemIndex> list = inventory.itemAcquisitionOrder.Where((ItemIndex item) => ContagiousItemManager.GetOriginalItemIndex(item) == pureItem).ToList();
if (list.Count == 0)
{
list = (from info in (IEnumerable<TransformationInfo>)(object)ContagiousItemManager.transformationInfos
where info.originalItem == pureItem
select info.transformedItem).ToList();
}
switch (_contagionPriority.Value)
{
case ContagionPriority.First:
return list.First();
case ContagionPriority.Last:
return list.Last();
case ContagionPriority.Alternate:
{
ContagionAlternateTracker orAdd = ContagionAlternateTracker.GetOrAdd(inventory);
return list[orAdd.AddContagion(pureItem) % list.Count];
}
case ContagionPriority.Rarest:
list.Sort(delegate(ItemIndex item, ItemIndex item2)
{
//IL_0000: 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_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: 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)
ItemTier tier = ItemCatalog.GetItemDef(item).tier;
return ((Enum)(ItemTier)(ref tier)).CompareTo((object?)ItemCatalog.GetItemDef(item2).tier);
});
return list.Last();
case ContagionPriority.Random:
return list[_voidRNG.RangeInt(0, list.Count)];
default:
return ContagiousItemManager.originalToTransformed[pureItem];
}
});
}
else
{
Log.Error("FixMultiCorrupt TryGotoNext failed, not applying patch");
}
}
private static void OnGenerateStageRNG(Action<Run> orig, Run self)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
orig(self);
_voidRNG = new Xoroshiro128Plus(self.stageRng.nextUlong);
}
}
internal class FixNullEntitlement
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__FixEntitledCheck;
}
private static ILHook _localILHook;
private static ILHook _networkILHook;
internal static void Init()
{
//IL_0002: 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_0011: 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_004e: Expected O, but got Unknown
//IL_0037: 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_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Expected O, but got Unknown
//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_007e: Expected O, but got Unknown
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
MethodInfo? method = typeof(BaseUserEntitlementTracker<LocalUser>).GetMethod("UserHasEntitlement", (BindingFlags)(-1));
object obj = <>O.<0>__FixEntitledCheck;
if (obj == null)
{
Manipulator val3 = FixEntitledCheck;
<>O.<0>__FixEntitledCheck = val3;
obj = (object)val3;
}
_localILHook = new ILHook((MethodBase)method, (Manipulator)obj, ref val2);
MethodInfo? method2 = typeof(BaseUserEntitlementTracker<NetworkUser>).GetMethod("UserHasEntitlement", (BindingFlags)(-1));
object obj2 = <>O.<0>__FixEntitledCheck;
if (obj2 == null)
{
Manipulator val4 = FixEntitledCheck;
<>O.<0>__FixEntitledCheck = val4;
obj2 = (object)val4;
}
_networkILHook = new ILHook((MethodBase)method2, (Manipulator)obj2, ref val2);
}
internal static void Enable()
{
_localILHook.Apply();
_networkILHook.Apply();
}
internal static void Disable()
{
_localILHook.Undo();
_networkILHook.Undo();
}
internal static void Destroy()
{
_localILHook.Free();
_networkILHook.Free();
}
private static void FixEntitledCheck(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
//IL_0038: 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)
ILCursor val = new ILCursor(il);
if (val.TryGotoNext(new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchLdstr(x, "entitlementDef")
}))
{
val.Emit(OpCodes.Ldc_I4_1);
val.Emit(OpCodes.Ret);
}
else
{
Log.Error("FixNullEntitlement TryGotoNext failed, not applying patch");
}
}
}
internal class SaferWWise
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__EarlyReturnIfNoSoundEngine;
public static Func<bool> <1>__ReturnTrueIfNoSoundEngine;
}
private static List<ILHook> _hooks = new List<ILHook>();
internal static void Init()
{
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: 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_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
//IL_0077: 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_0082: Expected O, but got Unknown
if (!Application.isBatchMode)
{
return;
}
foreach (MethodInfo item in from m in typeof(AkSoundEngine).GetMethods(BindingFlags.Static | BindingFlags.Public)
where m.ReturnParameter.ParameterType == typeof(AKRESULT)
select m)
{
ILHookConfig val = default(ILHookConfig);
val.ManualApply = true;
ILHookConfig val2 = val;
List<ILHook> hooks = _hooks;
object obj = <>O.<0>__EarlyReturnIfNoSoundEngine;
if (obj == null)
{
Manipulator val3 = EarlyReturnIfNoSoundEngine;
<>O.<0>__EarlyReturnIfNoSoundEngine = val3;
obj = (object)val3;
}
hooks.Add(new ILHook((MethodBase)item, (Manipulator)obj, ref val2));
}
}
internal static void Enable()
{
foreach (ILHook hook in _hooks)
{
hook.Apply();
}
}
internal static void Disable()
{
foreach (ILHook hook in _hooks)
{
hook.Undo();
}
}
internal static void Destroy()
{
foreach (ILHook hook in _hooks)
{
hook.Free();
}
}
private static void EarlyReturnIfNoSoundEngine(ILContext il)
{
//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_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_0030: 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_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il);
val.EmitDelegate<Func<bool>>((Func<bool>)ReturnTrueIfNoSoundEngine);
int index = val.Index;
val.Emit(OpCodes.Ldc_I4, 2);
val.Emit(OpCodes.Ret);
ILLabel val2 = val.MarkLabel();
val.Index = index;
val.Emit(OpCodes.Brfalse, (object)val2);
static bool ReturnTrueIfNoSoundEngine()
{
return Application.isBatchMode;
}
}
}
}
namespace RoR2BepInExPack.LegacyAssetSystem
{
internal static class LegacyResourcesDetours
{
private delegate Object ResourcesLoadDefinition(string path, Type type);
private static MethodInfo _legacyResourcesAPILoad;
private static readonly Dictionary<Type, MethodInfo> GenericVersionsOfLegacyResourcesAPILoad = new Dictionary<Type, MethodInfo>();
private static NativeDetour _resourcesLoadDetour;
private static ResourcesLoadDefinition _origLoad;
private static MethodInfo GetGenericLegacyResourcesAPILoad(Type type)
{
if (!GenericVersionsOfLegacyResourcesAPILoad.TryGetValue(type, out var value))
{
value = (GenericVersionsOfLegacyResourcesAPILoad[type] = _legacyResourcesAPILoad.MakeGenericMethod(type));
}
return value;
}
internal static void Init()
{
//IL_001c: 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_002b: 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_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Expected O, but got Unknown
_legacyResourcesAPILoad = typeof(LegacyResourcesAPI).GetMethod("Load", (BindingFlags)(-1));
NativeDetourConfig val = default(NativeDetourConfig);
val.ManualApply = true;
NativeDetourConfig val2 = val;
_resourcesLoadDetour = new NativeDetour((MethodBase)typeof(Resources).GetMethod("Load", (BindingFlags)(-1), null, new Type[2]
{
typeof(string),
typeof(Type)
}, null), (MethodBase)typeof(LegacyResourcesDetours).GetMethod("OnResourcesLoad", (BindingFlags)(-1)), val2);
_origLoad = _resourcesLoadDetour.GenerateTrampoline<ResourcesLoadDefinition>();
}
internal static void Enable()
{
_resourcesLoadDetour.Apply();
}
internal static void Disable()
{
_resourcesLoadDetour.Undo();
}
internal static void Destroy()
{
_resourcesLoadDetour.Free();
}
private static Object OnResourcesLoad(string path, Type type)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
MethodInfo genericLegacyResourcesAPILoad = GetGenericLegacyResourcesAPILoad(type);
object[] parameters = new string[1] { path };
Object val = (Object)genericLegacyResourcesAPILoad.Invoke(null, parameters);
if (Object.op_Implicit(val))
{
return val;
}
return _origLoad(path, type);
}
}
internal static class LegacyShaderDetours
{
private delegate Shader ShaderFindDefinition(string path);
private static NativeDetour _shaderFindDetour;
private static ShaderFindDefinition _origFind;
internal static void Init()
{
//IL_0002: 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_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
NativeDetourConfig val = default(NativeDetourConfig);
val.ManualApply = true;
NativeDetourConfig val2 = val;
_shaderFindDetour = new NativeDetour((MethodBase)typeof(Shader).GetMethod("Find", (BindingFlags)(-1), null, new Type[1] { typeof(string) }, null), (MethodBase)typeof(LegacyShaderDetours).GetMethod("OnShaderFind", (BindingFlags)(-1)), val2);
_origFind = _shaderFindDetour.GenerateTrampoline<ShaderFindDefinition>();
}
internal static void Enable()
{
_shaderFindDetour.Apply();
}
internal static void Disable()
{
_shaderFindDetour.Undo();
}
internal static void Destroy()
{
_shaderFindDetour.Free();
}
private static Shader OnShaderFind(string path)
{
Shader val = LegacyShaderAPI.Find(path);
if (Object.op_Implicit((Object)(object)val))
{
return val;
}
return _origFind(path);
}
}
}