Decompiled source of Holdens Animated Face Mod v1.0.1

HoldensAnimatedFaces.dll

Decompiled 7 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 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("AnimatedFacesMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Holden")]
[assembly: AssemblyProduct("AnimatedFacesMod")]
[assembly: AssemblyCopyright("Copyright © Holden 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1de66124-e64e-471a-9f1b-af61cb229b0c")]
[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 AnimatedFaces;

public class ColorWheelWindow
{
	public Rect windowRect = new Rect(20f, 20f, 200f, 250f);

	public Color selectedColor = Color.white;

	public bool showColorWheel = false;

	public Texture2D colorWheelTexture;

	public Texture2D cursorTexture;

	public Vector2 cursorSize = new Vector2(20f, 20f);

	private bool firstLaunch = true;

	private Vector2 lastMousePosition;

	private bool capturingColor = false;

	private Rect cursorRect;

	private Rect colorRect;

	public event Action<Color> OnColorSelected;

	public ColorWheelWindow()
	{
		//IL_0015: 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_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		colorRect = new Rect(0f, 0f, 0f, 0f);
		cursorRect = new Rect(0f, 0f, cursorSize.x, cursorSize.y);
	}

	public void DrawWindow()
	{
		//IL_0041: 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_0061: Expected O, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)colorWheelTexture == (Object)null)
		{
			GenerateColorWheelTexture();
		}
		if ((Object)(object)cursorTexture == (Object)null)
		{
			GenerateCursorTexture();
		}
		if (showColorWheel)
		{
			windowRect = GUILayout.Window(2, windowRect, new WindowFunction(ColorWheelGUI), "Color Picker by Ron", Array.Empty<GUILayoutOption>());
		}
	}

	private void ColorWheelGUI(int windowID)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			alignment = (TextAnchor)4
		};
		GUILayout.BeginVertical(GUI.skin.box, Array.Empty<GUILayoutOption>());
		GUILayout.Label("Select with Right Mouse Button", val, Array.Empty<GUILayoutOption>());
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref windowRect)).width, 20f));
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		colorRect = GUILayoutUtility.GetRect((float)((Texture)colorWheelTexture).width, (float)((Texture)colorWheelTexture).height);
		Vector2 mousePosition = Event.current.mousePosition;
		if (capturingColor)
		{
			((Rect)(ref cursorRect)).position = new Vector2(mousePosition.x - cursorSize.x / 2f, mousePosition.y - cursorSize.y / 2f);
			((Rect)(ref cursorRect)).x = Mathf.Clamp(((Rect)(ref cursorRect)).x, ((Rect)(ref colorRect)).x, ((Rect)(ref colorRect)).xMax - ((Rect)(ref cursorRect)).width);
			((Rect)(ref cursorRect)).y = Mathf.Clamp(((Rect)(ref cursorRect)).y, ((Rect)(ref colorRect)).y, ((Rect)(ref colorRect)).yMax - ((Rect)(ref cursorRect)).height);
			selectedColor = GetColorUnderMouse(colorRect);
			UpdateCursorTexture(selectedColor);
			ColorUpdate();
		}
		GUI.DrawTexture(colorRect, (Texture)(object)colorWheelTexture);
		if (((Rect)(ref colorRect)).Contains(Event.current.mousePosition))
		{
			if (Input.GetMouseButton(0))
			{
				capturingColor = true;
				lastMousePosition = Event.current.mousePosition;
			}
			else
			{
				capturingColor = false;
			}
		}
		GUI.DrawTexture(cursorRect, (Texture)(object)cursorTexture);
		GUILayout.FlexibleSpace();
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		if (GUILayout.Button("OK", Array.Empty<GUILayoutOption>()))
		{
			showColorWheel = false;
			SelectColor(selectedColor);
		}
		if (GUILayout.Button("Cancel", Array.Empty<GUILayoutOption>()))
		{
			showColorWheel = false;
		}
		GUILayout.EndHorizontal();
	}

	public void SelectColor(Color color)
	{
		//IL_0006: 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_002c: Unknown result type (might be due to invalid IL or missing references)
		Color val = color;
		Debug.Log((object)("Cor selecionada: " + ((object)(Color)(ref val)).ToString()));
		this.OnColorSelected?.Invoke(color);
	}

	private void GenerateColorWheelTexture()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		int num = 256;
		colorWheelTexture = new Texture2D(num, num);
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num2 = Mathf.Atan2((float)(i - num / 2), (float)(j - num / 2));
				num2 = (num2 / (float)Math.PI + 1f) * 0.5f;
				float num3 = Mathf.Sqrt((float)((j - num / 2) * (j - num / 2) + (i - num / 2) * (i - num / 2))) / (float)(num / 2);
				colorWheelTexture.SetPixel(j, i, Color.HSVToRGB(num2, num3, 1f));
			}
		}
		colorWheelTexture.Apply();
	}

	private void GenerateCursorTexture()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		cursorTexture = new Texture2D((int)cursorSize.x, (int)cursorSize.y);
		float num = cursorSize.x / 2f;
		float num2 = cursorSize.y / 2f;
		float num3 = cursorSize.x / 2f;
		UpdateCursorTexture(selectedColor);
		cursorTexture.Apply();
	}

	public Color ColorUpdate()
	{
		//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_000a: Unknown result type (might be due to invalid IL or missing references)
		return selectedColor;
	}

	private void UpdateCursorTexture(Color color)
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		float num = cursorSize.x / 2f;
		float num2 = cursorSize.y / 2f;
		float num3 = cursorSize.x / 2f;
		for (int i = 0; (float)i < cursorSize.y; i++)
		{
			for (int j = 0; (float)j < cursorSize.x; j++)
			{
				float num4 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num2) * ((float)i - num2));
				if (num4 > num3)
				{
					cursorTexture.SetPixel(j, i, Color.clear);
				}
				else if (num4 > num3 * 0.7f)
				{
					cursorTexture.SetPixel(j, i, Color.black);
				}
				else
				{
					cursorTexture.SetPixel(j, i, color);
				}
			}
		}
		cursorTexture.Apply();
	}

	private Color GetColorUnderMouse(Rect colorRect)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: 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)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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)
		Vector2 mousePosition = Event.current.mousePosition;
		Vector2 position = ((Rect)(ref cursorRect)).position;
		Vector2 val = position - new Vector2(((Rect)(ref colorRect)).x, ((Rect)(ref colorRect)).y);
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(val.x / ((Rect)(ref colorRect)).width, 1f - val.y / ((Rect)(ref colorRect)).height);
		return colorWheelTexture.GetPixelBilinear(val2.x, val2.y);
	}
}
[ContentWarningPlugin("1de66124-e64e-471a-9f1b-af61cb229b0c", "1.0", true)]
[BepInPlugin("holden.plugin.main.AnimatedFaces", "Holden's Animated Faces Mod!", "1.0")]
public class Main : BaseUnityPlugin
{
	public bool isAnimating = false;

	public bool DisplayingWindow = false;

	public Rect windowRect = new Rect(0f, 0f, 500f, 650f);

	private readonly int title_height = 17;

	public ColorWheelWindow colorUtil = new ColorWheelWindow();

	private List<string> faceFrames = new List<string>();

	private float updateInterval = 1f / 15f;

	private float elapsedTime = 0f;

	private int counter = 0;

	private static CursorLockMode lockMode = (CursorLockMode)2;

	private static CursorHandler cursorHandler;

	public static void ApplyPatches()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		Debug.Log((object)"Trying to apply patches.");
		Harmony val = new Harmony("com.holden.codewarning");
		val.PatchAll(Assembly.GetExecutingAssembly());
		Debug.Log((object)"Harmony patches applied.");
	}

	private void Start()
	{
		ApplyPatches();
		faceFrames.Add("");
	}

	private void Update()
	{
		float.TryParse(faceFrames.Count.ToString(), out var result);
		updateInterval = 1f / result;
		if (Input.GetKeyDown((KeyCode)278))
		{
			DisplayingWindow = !DisplayingWindow;
			if (DisplayingWindow)
			{
				if ((Object)(object)Player.localPlayer != (Object)null)
				{
					ShowCursor();
					Player.localPlayer.data.hookedIntoTerminal = true;
				}
			}
			else if ((Object)(object)Player.localPlayer != (Object)null)
			{
				HideCursor();
				Player.localPlayer.data.hookedIntoTerminal = false;
			}
		}
		if (!Object.op_Implicit((Object)(object)Player.localPlayer) || Player.localPlayer.data.dead || !isAnimating)
		{
			return;
		}
		elapsedTime += Time.deltaTime;
		while (elapsedTime >= updateInterval)
		{
			elapsedTime -= updateInterval;
			PlayerVisor visor = Player.localPlayer.refs.visor;
			if (counter < faceFrames.Count)
			{
				visor.SetAllFaceSettings(Player.localPlayer.refs.visor.hue.Value, Player.localPlayer.refs.visor.visorColorIndex, faceFrames[counter], 0f, Player.localPlayer.refs.visor.FaceSize);
				counter++;
			}
			else
			{
				counter = 0;
			}
		}
	}

	public static void ShowCursor()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)cursorHandler != (Object)null)
		{
			((Behaviour)cursorHandler).enabled = false;
		}
		else
		{
			cursorHandler = Object.FindObjectOfType<CursorHandler>();
			((Behaviour)cursorHandler).enabled = false;
		}
		Cursor.visible = true;
		lockMode = Cursor.lockState;
		Cursor.lockState = (CursorLockMode)2;
	}

	public static void HideCursor()
	{
		if ((Object)(object)cursorHandler != (Object)null)
		{
			if (!((Behaviour)cursorHandler).enabled)
			{
				((Behaviour)cursorHandler).enabled = true;
				Cursor.visible = true;
			}
		}
		else if (!((Behaviour)cursorHandler).enabled)
		{
			cursorHandler = Object.FindObjectOfType<CursorHandler>();
			((Behaviour)cursorHandler).enabled = true;
			Cursor.visible = true;
		}
	}

	private void OnGUI()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Expected O, but got Unknown
		//IL_0043: 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)
		if (DisplayingWindow)
		{
			colorUtil.DrawWindow();
			GUI.backgroundColor = Color.black;
			windowRect = ClampToScreen(GUI.Window(9, windowRect, new WindowFunction(WindowFunc), "Holden's Animated Faces Mod!"));
		}
	}

	private Rect ClampToScreen(Rect window)
	{
		//IL_004f: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		((Rect)(ref window)).x = Mathf.Clamp(((Rect)(ref window)).x, 0f, (float)Screen.width - ((Rect)(ref window)).width);
		((Rect)(ref window)).y = Mathf.Clamp(((Rect)(ref window)).y, 0f, (float)Screen.height - ((Rect)(ref window)).height);
		return window;
	}

	private void WindowFunc(int winId)
	{
		//IL_001e: 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)
		try
		{
			GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref windowRect)).width, (float)title_height));
			int num = 0;
			int num2 = 0;
			GUILayout.BeginArea(new Rect((float)num, (float)(num2 + (title_height + 35)), ((Rect)(ref windowRect)).width, ((Rect)(ref windowRect)).height - (float)num2 - (float)(title_height + 35)));
			CenterLabel("Holden's Animated Faces");
			isAnimating = GUILayout.Toggle(isAnimating, "Play Face Animation", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Change Face Color", Array.Empty<GUILayoutOption>()))
			{
				colorUtil.showColorWheel = !colorUtil.showColorWheel;
				if (colorUtil.showColorWheel)
				{
					colorUtil.OnColorSelected += ChangeFaceColorSelected;
				}
				else
				{
					colorUtil.OnColorSelected -= ChangeFaceColorSelected;
				}
			}
			GUILayout.EndHorizontal();
			for (int i = 0; i < faceFrames.Count; i++)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.Label("Face Frame #" + i, Array.Empty<GUILayoutOption>());
				string text = GUILayout.TextField(faceFrames[i], 100, Array.Empty<GUILayoutOption>());
				if (text != faceFrames[i])
				{
					faceFrames[i] = text;
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.Label("Tip: Have several frames to form an animation", Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Add a Frame", Array.Empty<GUILayoutOption>()))
			{
				if (faceFrames.Count >= 10)
				{
					return;
				}
				faceFrames.Add("");
			}
			if (GUILayout.Button("Remove Last Frame", Array.Empty<GUILayoutOption>()))
			{
				faceFrames.Remove(faceFrames[faceFrames.Count - 1]);
			}
			CenterLabel("The face animations are displayed at 10 frames per second to avoid massive calls.");
			GUILayout.EndArea();
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("Error drawing main  window: " + ex));
		}
	}

	private void ChangeFaceColorSelected(Color color)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		Player.localPlayer.refs.visor.ApplyVisorColor(color);
		colorUtil.OnColorSelected -= ChangeFaceColorSelected;
	}

	private void CenterLabel(string label)
	{
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		GUILayout.Label(label, Array.Empty<GUILayoutOption>());
		GUILayout.FlexibleSpace();
		GUILayout.EndHorizontal();
	}
}