Decompiled source of QBZ191 v0.1.1

plugins\QBZ191.dll

Decompiled 4 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace QBZ191;

[BepInPlugin("cn_xc.QBZ191", "QBZ-191", "0.1.1")]
public class Plugin : BaseUnityPlugin
{
	private Harmony _harmony;

	private static MethodInfo _toggleItem;

	private static MethodInfo _localViewId;

	private void Awake()
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Expected O, but got Unknown
		try
		{
			_toggleItem = AccessTools.Method(typeof(ItemToggle), "ToggleItem", new Type[2]
			{
				typeof(bool),
				typeof(int)
			}, (Type[])null);
			try
			{
				_localViewId = AccessTools.Method(typeof(SemiFunc), "PhotonViewIDPlayerAvatarLocal", (Type[])null, (Type[])null);
			}
			catch
			{
			}
			MethodInfo methodInfo = AccessTools.Method(typeof(ItemGun), "Shoot", new Type[0], (Type[])null);
			_harmony = new Harmony("cn_xc.QBZ191");
			if (methodInfo != null && _toggleItem != null)
			{
				_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin).GetMethod("ShootPostfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"QBZ-191 半自动已加载(Shoot 后置复位)。");
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"QBZ-191 半自动:找不到 ItemGun.Shoot 或 ItemToggle.ToggleItem。");
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("QBZ-191 补丁加载失败: " + ex));
		}
	}

	internal static bool IsOurGun(ItemGun gun)
	{
		try
		{
			if ((Object)(object)gun == (Object)null)
			{
				return false;
			}
			string name = ((Object)((Component)gun).gameObject).name;
			return !string.IsNullOrEmpty(name) && name.IndexOf("QBZ191", StringComparison.OrdinalIgnoreCase) >= 0;
		}
		catch
		{
			return false;
		}
	}

	internal static void ShootPostfix(ItemGun __instance, bool __result)
	{
		try
		{
			if (!__result || !IsOurGun(__instance))
			{
				return;
			}
			ItemToggle component = ((Component)__instance).GetComponent<ItemToggle>();
			if ((Object)(object)component == (Object)null || !component.toggleState)
			{
				return;
			}
			int num = 0;
			try
			{
				if (_localViewId != null)
				{
					num = (int)_localViewId.Invoke(null, null);
				}
			}
			catch
			{
			}
			_toggleItem.Invoke(component, new object[2] { false, num });
		}
		catch
		{
		}
	}
}