using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LCVR.Managers;
using TooManyEmotesVRFix.Patches;
using TooManyEmotesVRFix.Tools;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TooManyEmotesVRFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TooManyEmotesVRFix")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cdbbb476-26d6-4951-b66f-2667d45fe642")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace TooManyEmotesVRFix.Tools
{
public static class PatchHelper
{
public static HarmonyMethod Method(Expression<Action> action, bool debug = false)
{
//IL_000f: 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_0020: Expected O, but got Unknown
return new HarmonyMethod(SymbolExtensions.GetMethodInfo(action), -1, (string[])null, (string[])null, (bool?)debug)
{
priority = 10000
};
}
public static HarmonyMethod Method<A>(Expression<Action<A>> action, bool debug = false)
{
//IL_000f: 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_0020: Expected O, but got Unknown
return new HarmonyMethod(SymbolExtensions.GetMethodInfo<A>(action), -1, (string[])null, (string[])null, (bool?)debug)
{
priority = 10000
};
}
public static HarmonyMethod Method<A, B>(Expression<Action<A, B>> action, bool debug = false)
{
//IL_000f: 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_0020: Expected O, but got Unknown
return new HarmonyMethod(SymbolExtensions.GetMethodInfo((LambdaExpression)action), -1, (string[])null, (string[])null, (bool?)debug)
{
priority = 10000
};
}
}
public static class Reflection
{
public static Type Type(string type)
{
return AccessTools.TypeByName(type);
}
public static List<ConstructorInfo> Constructors(string type)
{
return AccessTools.GetDeclaredConstructors(Type(type), (bool?)null);
}
public static List<ConstructorInfo> Constructors(Type type)
{
return AccessTools.GetDeclaredConstructors(type, (bool?)null);
}
public static MethodBase Method(string type, string method, Type[] args = null, bool declared = true)
{
if (declared)
{
return AccessTools.DeclaredMethod(Type(type), method, args, (Type[])null);
}
return AccessTools.Method(Type(type), method, args, (Type[])null);
}
public static MethodBase Method(Type type, string method, Type[] args = null, bool declared = true)
{
if (declared)
{
return AccessTools.DeclaredMethod(type, method, args, (Type[])null);
}
return AccessTools.Method(type, method, args, (Type[])null);
}
public static FieldInfo Field(string type, string field, bool declared = true)
{
if (declared)
{
return AccessTools.DeclaredField(Type(type), field);
}
return AccessTools.Field(Type(type), field);
}
public static FieldInfo Field(Type type, string field, bool declared = true)
{
if (declared)
{
return AccessTools.DeclaredField(type, field);
}
return AccessTools.Field(type, field);
}
public static PropertyInfo Property(string type, string property, bool declared = true)
{
if (declared)
{
return AccessTools.DeclaredProperty(Type(type), property);
}
return AccessTools.Property(Type(type), property);
}
public static PropertyInfo Property(Type type, string property, bool declared = true)
{
if (declared)
{
return AccessTools.DeclaredProperty(type, property);
}
return AccessTools.Property(type, property);
}
}
}
namespace TooManyEmotesVRFix.Patches
{
public static class LVCR_Compat_Patches
{
public static void Apply(Harmony harmony)
{
harmony.Patch(Reflection.Method("TooManyEmotes.Compatibility.LCVR_Compat", "get_LoadedAndEnabled"), (HarmonyMethod)null, (HarmonyMethod)null, PatchHelper.Method(() => GetterTranspiler(null, null)), (HarmonyMethod)null, (HarmonyMethod)null);
}
private static IEnumerable<CodeInstruction> GetterTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
List<CodeInstruction> list = new List<CodeInstruction>();
foreach (CodeInstruction instruction in instructions)
{
if (instruction.opcode == OpCodes.Call && instruction.operand is MethodInfo methodInfo && methodInfo.Name.Equals("get_VRModeEnabled"))
{
instruction.operand = Reflection.Method("TooManyEmotesVRFix.Patches.LVCR_Compat_Hook", "IsInVr");
}
list.Add(instruction);
}
return list;
}
}
public static class LVCR_Compat_Hook
{
public static bool IsInVr()
{
return VRSession.InVR;
}
}
}
namespace TooManyEmotesVRFix.Core
{
public static class TooManyEmotesVRFixInfo
{
public const string GUID = "lauriichan.tmevrfix";
public const string PrintName = "TooManyEmotesVRFix";
public const string Version = "1.0.0";
}
[BepInPlugin("lauriichan.tmevrfix", "TooManyEmotesVRFix", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal class TooManyEmotesVRFixPlugin : BaseUnityPlugin
{
private Harmony harmony;
public static ManualLogSource Log { get; private set; }
public void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
SetupPatches();
}
private void SetupPatches()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
if (harmony == null)
{
harmony = new Harmony("lauriichan.tmevrfix");
LVCR_Compat_Patches.Apply(harmony);
}
}
public void OnDestroy()
{
if (harmony != null)
{
harmony.UnpatchSelf();
harmony = null;
}
}
}
}