using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using RoR2;
using RoR2.UI;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("StopStealingMyMouse")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c9f696a934bbebf924129c3af4d48501c236063e")]
[assembly: AssemblyProduct("StopStealingMyMouse")]
[assembly: AssemblyTitle("StopStealingMyMouse")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 StopStealingMyMouse
{
[BepInPlugin("com.rune580.stopstealingmymouse", "Stop stealing my mouse!", "1.3.0")]
public sealed class StopStealingMyMousePlugin : BaseUnityPlugin
{
private const string ModName = "Stop stealing my mouse!";
private const string Author = "rune580";
private const string Guid = "com.rune580.stopstealingmymouse";
private const string Version = "1.3.0";
private static bool _arrestRoR2 = true;
private ILHook _mpEventSystemManagerHook;
private Hook _hgButtonHook;
private void Awake()
{
ArrestRoR2();
}
private void ArrestRoR2()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Expected O, but got Unknown
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
MethodInfo method = typeof(MPEventSystemManager).GetMethod("Update", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
_mpEventSystemManagerHook = new ILHook((MethodBase)method, new Manipulator(MPEventSystemManagerOnUpdate));
method = typeof(HGButton).GetMethod("OnClickCustom", BindingFlags.Instance | BindingFlags.Public);
MethodInfo method2 = ((object)this).GetType().GetMethod("HGButtonOnOnClickCustom", BindingFlags.Instance | BindingFlags.NonPublic);
_hgButtonHook = new Hook((MethodBase)method, method2, (object)this);
}
private void ReleaseRoR2()
{
_mpEventSystemManagerHook.Undo();
_hgButtonHook.Undo();
}
private void MPEventSystemManagerOnUpdate(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
ILCursor val = new ILCursor(il).Goto(0, (MoveType)0, false);
ILLabel val3 = default(ILLabel);
ILLabel val2 = default(ILLabel);
if (val.TryGotoNext((MoveType)2, new Func<Instruction, bool>[6]
{
(Instruction i) => ILPatternMatchingExt.MatchCall<Application>(i, "get_isBatchMode"),
(Instruction i) => ILPatternMatchingExt.MatchBrtrue(i, ref val3),
(Instruction i) => ILPatternMatchingExt.MatchCall<MPEventSystemManager>(i, "get_kbmEventSystem"),
(Instruction i) => ILPatternMatchingExt.MatchLdnull(i),
(Instruction i) => ILPatternMatchingExt.MatchCall<Object>(i, "op_Inequality"),
(Instruction i) => ILPatternMatchingExt.MatchBrfalse(i, ref val2)
}))
{
val.Emit(OpCodes.Call, (MethodBase)typeof(StopStealingMyMousePlugin).GetMethod("PreventTheft", BindingFlags.Static | BindingFlags.NonPublic));
val.Emit(OpCodes.Ret);
}
}
private static void PreventTheft()
{
if (_arrestRoR2)
{
Cursor.lockState = (CursorLockMode)0;
Cursor.visible = false;
}
}
private void HGButtonOnOnClickCustom(Action<HGButton> orig, HGButton self)
{
if (_arrestRoR2)
{
ReleaseRoR2();
}
orig(self);
}
private void OnApplicationFocus(bool hasFocus)
{
if (_arrestRoR2 && RoR2Application.loadFinished && hasFocus)
{
_arrestRoR2 = false;
Cursor.lockState = (CursorLockMode)2;
Cursor.visible = false;
}
}
}
}