plugins/AWPGunFix.dll

Decompiled an hour ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
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 AWPGunFix;

[BepInPlugin("cn_xc.AWPGunFix", "AWP Gun Fix", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private static MethodInfo _toggleItem;

	private static MethodInfo _localViewId;

	private void Awake()
	{
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Expected O, but got Unknown
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		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 val = new Harmony("cn_xc.AWPGunFix");
			if (methodInfo != null && _toggleItem != null)
			{
				val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin).GetMethod("ShootPostfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null);
				Log.LogInfo((object)"AWPGunFix 已加载(AWP 单发)");
			}
			else
			{
				Log.LogWarning((object)"AWPGunFix: 找不到 ItemGun.Shoot / ItemToggle.ToggleItem");
			}
		}
		catch (Exception ex)
		{
			Log.LogError((object)("AWPGunFix 加载失败: " + ex));
		}
	}

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

	internal static void ShootPostfix(ItemGun __instance, bool __result)
	{
		try
		{
			if (!IsAwp(__instance) || !__result)
			{
				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
		{
		}
	}
}