Decompiled source of BetterWeaponWheel v2.0.1

plugins/BetterWeaponWheel.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[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("BetterWeaponWheel")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("improve the weapon wheel")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: AssemblyInformationalVersion("2.0.1+381e4446180f7f71353488ab51f632198fc0a70e")]
[assembly: AssemblyProduct("BetterWeaponWheel")]
[assembly: AssemblyTitle("BetterWeaponWheel")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.1.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]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BetterWeaponWheel
{
	[BepInPlugin("BetterWeaponWheel", "BetterWeaponWheel", "2.0.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private static readonly FieldInfo segmentsField = typeof(WeaponWheel).GetField("segments", BindingFlags.Instance | BindingFlags.NonPublic);

		public void Awake()
		{
			Harmony.CreateAndPatchAll(((object)this).GetType(), (string)null);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(WeaponWheel), "Update")]
		private static void UpdateWheelCursor(ref Vector2 ___direction)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			MonoSingleton<WheelDot>.Instance.UpdateCursor(___direction);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(WheelSegment), "SetActive")]
		private static void OverrideSegmentColors(WheelSegment __instance, ref bool active)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected I4, but got Unknown
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			if (active)
			{
				int num = (int)__instance.descriptor.variationColor;
				Color color = MonoSingleton<ColorBlindSettings>.Instance.variationColors[num];
				((Graphic)__instance.icon).color = color;
				((Graphic)__instance.iconGlow).color = color;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GunControl), "SwitchWeapon", new Type[]
		{
			typeof(int),
			typeof(List<GameObject>),
			typeof(bool),
			typeof(bool),
			typeof(bool),
			typeof(bool)
		})]
		[HarmonyPatch(typeof(WeaponWheel), "SetSegments")]
		private static void OverrideWheelIcons()
		{
			GunControl instance = MonoSingleton<GunControl>.Instance;
			List<WheelSegment> list = (List<WheelSegment>)segmentsField.GetValue(MonoSingleton<WeaponWheel>.Instance);
			int num = 0;
			for (int i = 0; i < instance.slots.Count; i++)
			{
				List<GameObject> list2 = instance.slots[i];
				if (list2.Any())
				{
					int index = ((i + 1 == instance.currentSlot) ? ((instance.currentVariation + 1) % list2.Count) : (instance.variationMemory ? PlayerPrefs.GetInt($"Slot{i + 1}Var", 0) : 0));
					WheelSegment val = list[num++];
					WeaponDescriptor weaponDescriptor = list2[index].GetComponent<WeaponIcon>().weaponDescriptor;
					if (!((Object)(object)val.descriptor == (Object)(object)weaponDescriptor))
					{
						val.descriptor = weaponDescriptor;
						val.icon.sprite = weaponDescriptor.icon;
						val.iconGlow.sprite = weaponDescriptor.glowIcon;
					}
				}
			}
		}
	}
	public sealed class WheelDot : MonoSingleton<WheelDot>
	{
		private bool initialized;

		private Vector2 position;

		private GameObject overlay = new GameObject();

		private GameObject wheelDot = new GameObject();

		public void Update()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (TryInit())
			{
				bool isActiveAndEnabled = ((Behaviour)MonoSingleton<WeaponWheel>.Instance).isActiveAndEnabled;
				overlay.SetActive(isActiveAndEnabled);
				wheelDot.SetActive(isActiveAndEnabled);
				if (isActiveAndEnabled)
				{
					wheelDot.GetComponent<RectTransform>().anchoredPosition = position * 71f;
				}
			}
		}

		private bool TryInit()
		{
			if (initialized)
			{
				return true;
			}
			InitOverlay();
			InitWheelDot();
			initialized = true;
			return true;
		}

		private void InitOverlay()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Overlay");
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 50;
			CanvasScaler obj2 = val.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.screenMatchMode = (ScreenMatchMode)0;
			obj2.matchWidthOrHeight = 0f;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			val.AddComponent<CanvasGroup>().blocksRaycasts = false;
			overlay = val;
		}

		private void InitWheelDot()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_006d: 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_0075: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			wheelDot = new GameObject();
			wheelDot.SetActive(false);
			Image val = wheelDot.AddComponent<Image>();
			val.sprite = null;
			int @int = MonoSingleton<PrefsManager>.Instance.GetInt("crossHairColor", 0);
			Image val2 = val;
			Color color;
			switch (@int)
			{
			case 0:
			case 1:
				color = Color.white;
				break;
			case 2:
				color = Color.gray;
				break;
			case 3:
				color = Color.black;
				break;
			case 4:
				color = Color.red;
				break;
			case 5:
				color = Color.green;
				break;
			case 6:
				color = Color.blue;
				break;
			case 7:
				color = Color.cyan;
				break;
			case 8:
				color = Color.yellow;
				break;
			case 9:
				color = Color.magenta;
				break;
			default:
				color = Color.white;
				break;
			}
			((Graphic)val2).color = color;
			if (@int == 0)
			{
				Crosshair component = MonoSingleton<StatsManager>.Instance.crosshair.GetComponent<Crosshair>();
				((Graphic)val).material = component.invertMaterial;
			}
			RectTransform component2 = wheelDot.GetComponent<RectTransform>();
			((Transform)component2).SetParent((Transform)(object)overlay.GetComponent<RectTransform>());
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			component2.anchorMax = val3;
			Vector2 pivot = (component2.anchorMin = val3);
			component2.pivot = pivot;
			component2.sizeDelta = new Vector2(3f, 3f);
			((Transform)component2).Rotate(0f, 0f, 45f);
		}

		public void UpdateCursor(Vector2 direction)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			position = direction;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BetterWeaponWheel";

		public const string PLUGIN_NAME = "BetterWeaponWheel";

		public const string PLUGIN_VERSION = "2.0.1";
	}
}