Decompiled source of EmoteWheel v1.0.0

EmoteWheel.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("EmoteWheel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EmoteWheel")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b404dec9-2569-4583-8089-1bae71ce6300")]
[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 EmoteWheel;

[BepInPlugin("com.Playboy.EmoteWheel", "EmoteWheel", "1.0.0")]
public class Main : BaseUnityPlugin
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	private class Patch_Shop_1
	{
		public static FieldInfo m_CategoryItemDicFieldInfo = typeof(ShopHandler).GetField("m_CategoryItemDic", BindingFlags.Instance | BindingFlags.NonPublic);

		private static void Postfix(ref ShopHandler __instance)
		{
			//IL_0070: 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_0082: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			if (instance.emoteShopItems.Count > 0)
			{
				return;
			}
			Dictionary<ShopItemCategory, List<ShopItem>> categoryItemDic = GetCategoryItemDic(__instance);
			if (!categoryItemDic.TryGetValue((ShopItemCategory)4, out var value))
			{
				Debug.Log((object)"EMOTE ITEMS NOT FOUND");
			}
			if (!categoryItemDic.TryGetValue((ShopItemCategory)5, out var value2))
			{
				Debug.Log((object)"EMOTE 2 ITEMS NOT FOUND");
			}
			foreach (ShopItem item in value)
			{
				instance.emoteShopItems.Add(item);
			}
			foreach (ShopItem item2 in value2)
			{
				instance.emoteShopItems.Add(item2);
			}
			for (int i = 0; i < instance.emoteShopItems.Count; i++)
			{
				instance.emoteShopIcons.Add(SpriteToTexture2D(instance.emoteShopItems[i].Item.icon));
			}
		}

		public static Texture2D SpriteToTexture2D(Sprite sprite)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			Rect rect = sprite.rect;
			if (((Rect)(ref rect)).width == (float)((Texture)sprite.texture).width)
			{
				rect = sprite.rect;
				if (((Rect)(ref rect)).height == (float)((Texture)sprite.texture).height)
				{
					return sprite.texture;
				}
			}
			rect = sprite.rect;
			int num = (int)((Rect)(ref rect)).width;
			rect = sprite.rect;
			Texture2D val = new Texture2D(num, (int)((Rect)(ref rect)).height);
			Texture2D texture = sprite.texture;
			rect = sprite.rect;
			int num2 = (int)((Rect)(ref rect)).x;
			rect = sprite.rect;
			int num3 = (int)((Rect)(ref rect)).y;
			rect = sprite.rect;
			int num4 = (int)((Rect)(ref rect)).width;
			rect = sprite.rect;
			Color[] pixels = texture.GetPixels(num2, num3, num4, (int)((Rect)(ref rect)).height);
			val.SetPixels(pixels);
			val.Apply();
			return val;
		}

		public static Dictionary<ShopItemCategory, List<ShopItem>> GetCategoryItemDic(ShopHandler inst)
		{
			if (m_CategoryItemDicFieldInfo == null)
			{
				Debug.Log((object)"m_CategoryItemDicFieldInfo not found.");
				return null;
			}
			return (Dictionary<ShopItemCategory, List<ShopItem>>)m_CategoryItemDicFieldInfo.GetValue(inst);
		}
	}

	private static Main instance;

	public static Harmony harmony;

	public const string PLAYERPREFS_KEY_SELECTEDINDEX = "emoteWheelMod_Index";

	public float radius = 200f;

	public float iconSize = 50f;

	public float gapAngle = 5f;

	public List<ShopItem> emoteShopItems = new List<ShopItem>();

	public List<Texture2D> emoteShopIcons = new List<Texture2D>();

	public int selectedIndex = 0;

	public float selectedIndexRaw = 0f;

	private Texture2D backgroundCircle;

	public int circleRadius = 250;

	public ConfigEntry<KeyCode> emoteWheelKeybind { get; set; }

	private void Awake()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		instance = this;
		harmony = new Harmony("Playboy.EmoteWheel");
		harmony.PatchAll();
		emoteWheelKeybind = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotkeys", "Emote Wheel", (KeyCode)99, (ConfigDescription)null);
		Color grey = Color.grey;
		grey.a = 0.4f;
		backgroundCircle = CreateCircleTexture(circleRadius, grey);
		selectedIndex = PlayerPrefs.GetInt("emoteWheelMod_Index", 0);
		selectedIndexRaw = selectedIndex;
	}

	private void OnGUI()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0280: Unknown result type (might be due to invalid IL or missing references)
		//IL_0282: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_028b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Expected O, but got Unknown
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Player.localPlayer == (Object)null)
		{
			return;
		}
		if (Input.GetKeyUp(emoteWheelKeybind.Value))
		{
			Player.localPlayer.refs.emotes.PlayEmote(emoteShopItems[selectedIndex].Item);
		}
		else
		{
			if (!Input.GetKey(emoteWheelKeybind.Value))
			{
				return;
			}
			float axis = Input.GetAxis("Mouse ScrollWheel");
			axis *= 1.5f;
			selectedIndexRaw -= axis;
			int count = emoteShopItems.Count;
			int num = Mathf.RoundToInt(selectedIndexRaw) % count;
			if (num < 0)
			{
				num += count;
			}
			if (num != selectedIndex)
			{
				selectedIndex = num;
				PlayerPrefs.SetInt("emoteWheelMod_Index", selectedIndex);
			}
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor((float)(Screen.width / 2), (float)(Screen.height / 2));
			int count2 = emoteShopIcons.Count;
			float num2 = 360f / (float)count2 - gapAngle;
			float num3 = -90f;
			Vector2 val2 = val;
			int num4 = circleRadius * 2;
			Rect val3 = default(Rect);
			((Rect)(ref val3))..ctor((float)(Screen.width / 2 - circleRadius), (float)(Screen.height / 2 - circleRadius), (float)num4, (float)num4);
			GUI.DrawTexture(val3, (Texture)(object)backgroundCircle);
			Vector2 val4 = default(Vector2);
			Rect val6 = default(Rect);
			for (int i = 0; i < count2; i++)
			{
				((Vector2)(ref val4))..ctor(Mathf.Cos(num3 * ((float)Math.PI / 180f)) * radius, Mathf.Sin(num3 * ((float)Math.PI / 180f)) * radius);
				Vector2 val5 = val + val4 - new Vector2(iconSize, iconSize) * 0.5f;
				((Rect)(ref val6))..ctor(val5.x, val5.y, iconSize, iconSize);
				GUI.DrawTexture(val6, (Texture)(object)emoteShopIcons[i]);
				num3 += num2 + gapAngle;
				if (i == selectedIndex)
				{
					Vector2 val7 = val5;
					val7.x += iconSize / 2f;
					val7.y += iconSize / 2f;
					val2 = val7;
				}
			}
			Vector2 val8 = val;
			Vector2 val9 = val2;
			val9 = Vector2.Lerp(val8, val9, 0.75f);
			val8 = Vector2.Lerp(val8, val9, 0.4f);
			DrawLine(val8, val9, Color.black, 3f);
			GUIStyle val10 = new GUIStyle(GUI.skin.label);
			val10.alignment = (TextAnchor)4;
			val10.normal.textColor = Color.black;
			val10.fontSize = 24;
			Rect val11 = default(Rect);
			((Rect)(ref val11))..ctor(0f, 0f, (float)Screen.width, (float)Screen.height);
			Rect val12 = val11;
			ShopItem val13 = emoteShopItems[selectedIndex];
			GUI.Label(val12, ((ShopItem)(ref val13)).DisplayName, val10);
		}
	}

	private Texture2D CreateCircleTexture(int radius, Color color)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Expected O, but got Unknown
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(2 * radius, 2 * radius);
		((Texture)val).filterMode = (FilterMode)0;
		Color[] array = (Color[])(object)new Color[4 * radius * radius];
		for (int i = 0; i < 2 * radius; i++)
		{
			for (int j = 0; j < 2 * radius; j++)
			{
				int num = i - radius;
				int num2 = j - radius;
				if (num * num + num2 * num2 <= radius * radius)
				{
					array[i + j * 2 * radius] = color;
				}
				else
				{
					array[i + j * 2 * radius] = Color.clear;
				}
			}
		}
		val.SetPixels(array);
		val.Apply();
		return val;
	}

	private void DrawLine(Vector2 pointA, Vector2 pointB, Color color, float width)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//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_0022: 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_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: 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_0082: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(1, 1);
		val.SetPixel(0, 0, color);
		val.Apply();
		Vector2 val2 = pointB - pointA;
		float num = Mathf.Atan2(val2.y, val2.x) * 57.29578f;
		float magnitude = ((Vector2)(ref val2)).magnitude;
		Matrix4x4 matrix = GUI.matrix;
		Color color2 = GUI.color;
		GUI.color = color;
		GUIUtility.RotateAroundPivot(num, pointA);
		GUI.DrawTexture(new Rect(pointA.x, pointA.y, magnitude, width), (Texture)(object)val);
		GUI.matrix = matrix;
		GUI.color = color2;
	}
}