Decompiled source of HitMeatAlpha v0.1.0

FreeGriller.dll

Decompiled a year ago
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using OtherLoader;
using UnityEngine;
using UnityEngine.UI;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace NGA
{
	public class FGTimeUi : MonoBehaviour
	{
		[SerializeField]
		public Text timeText;

		private void Start()
		{
			((MonoBehaviour)this).InvokeRepeating("UpdateTimeDisplay", 1f, 1f);
		}

		private void UpdateTimeDisplay()
		{
			if ((Object)(object)FGTimeSystem.Instance != (Object)null && (Object)(object)timeText != (Object)null)
			{
				timeText.text = FGTimeSystem.Instance.CurrentTime.ToString("o");
			}
		}

		private void OnDisable()
		{
			((MonoBehaviour)this).CancelInvoke("UpdateTimeDisplay");
		}
	}
	public class FGWristUi : MonoBehaviour
	{
		private int selectedTabIx = 0;

		private int enemyIdMult = 1;

		private int currQuestTabType = 0;

		private int selectedQuestIndex = -1;

		[Header("UI References")]
		private Transform Canvas;

		private Transform ButtonsSection;

		private Transform TimeText;

		private Transform TravelTab;

		private Transform ContractsTab;

		private Transform ContractsVertList;

		private Transform ContractStickerTempl;

		private Transform TimeTab;

		public Transform Face;

		public FVRViveHand[] Hands = (FVRViveHand[])(object)new FVRViveHand[2];

		private FVRViveHand m_currentHand;

		private bool m_hasHands = false;

		private bool m_isActive = false;

		private float m_wristPointRange = 60f;

		private float m_faceAngleRange = 45f;

		public void Start()
		{
			SetHandsAndFace(((Component)GM.CurrentPlayerBody.RightHand).GetComponent<FVRViveHand>(), ((Component)GM.CurrentPlayerBody.LeftHand).GetComponent<FVRViveHand>(), ((Component)GM.CurrentPlayerBody.EyeCam).transform);
			FindUiVariables();
			AddTimeUiRunner();
			CloseTabs();
		}

		public void Update()
		{
			UpdateWristMenu();
		}

		private void FindUiVariables()
		{
			Canvas = ((Component)this).transform.Find("Canvas");
			ButtonsSection = Canvas.Find("SubmenuButs");
			TravelTab = Canvas.Find("TravelTab");
			ContractsTab = Canvas.Find("ContractsTab");
			TimeTab = Canvas.Find("TimeTab");
			TimeText = Canvas.Find("Time");
			ContractsVertList = ContractsTab.Find("ContractsList");
			ContractStickerTempl = ContractsVertList.Find("ContractStickerTmpl");
		}

		public void CloseTabs()
		{
			((Component)TravelTab).gameObject.SetActive(false);
			((Component)ContractsTab).gameObject.SetActive(false);
			((Component)TimeTab).gameObject.SetActive(false);
		}

		public void ClearContractTexts()
		{
			Text componentInChildren = ((Component)ContractStickerTempl.Find("Description")).GetComponentInChildren<Text>();
			componentInChildren.text = "";
			Text componentInChildren2 = ((Component)ContractsTab.Find("ContractDescription").Find("Description")).GetComponentInChildren<Text>();
			componentInChildren2.text = "";
		}

		public void BTN_DisplayQuests(int i)
		{
			currQuestTabType = i;
			selectedQuestIndex = -1;
			ClearContractTexts();
			List<FGContract> currentContractList = GetCurrentContractList();
			string text = i switch
			{
				0 => "[Available]", 
				1 => "[Active]", 
				_ => "", 
			};
			Text componentInChildren = ((Component)ContractStickerTempl.Find("Description")).GetComponentInChildren<Text>();
			using (List<FGContract>.Enumerator enumerator = currentContractList.GetEnumerator())
			{
				if (enumerator.MoveNext())
				{
					FGContract current = enumerator.Current;
					componentInChildren.text = "" + current.DisplayName + "\n" + current.TargetFirstName + " " + current.TargetLastName + "\n" + current.Infraction + "\n" + text;
				}
			}
			selectedQuestIndex = ((currentContractList.Count == 0) ? (-1) : 0);
			BTN_DisplayQuestDetail();
		}

		public void BTN_DisplayQuestDetail()
		{
			if (selectedQuestIndex >= 0)
			{
				List<FGContract> currentContractList = GetCurrentContractList();
				if (selectedQuestIndex < currentContractList.Count)
				{
					FGContract val = currentContractList[selectedQuestIndex];
					Text componentInChildren = ((Component)ContractsTab.Find("ContractDescription").Find("Description")).GetComponentInChildren<Text>();
					componentInChildren.text = val.PrintContract();
				}
			}
		}

		private List<FGContract> GetCurrentContractList()
		{
			return currQuestTabType switch
			{
				0 => FG_GM.Instance.contractMan.GetAvailableContracts(), 
				1 => FG_GM.Instance.contractMan.GetActiveContracts(), 
				_ => new List<FGContract>(), 
			};
		}

		public void BTN_AcceptContract()
		{
			if (selectedQuestIndex < 0 || currQuestTabType != 0)
			{
				Debug.LogWarning((object)("Selected index is invalid " + selectedQuestIndex + " or you didn't select Available tab " + currQuestTabType));
				return;
			}
			List<FGContract> currentContractList = GetCurrentContractList();
			if (selectedQuestIndex >= currentContractList.Count)
			{
				Debug.LogWarning((object)("Selected index is invalid too big " + selectedQuestIndex + " compared to available contracts list " + currentContractList.Count));
			}
			else
			{
				FG_GM.Instance.contractMan.AcceptContract(currentContractList[selectedQuestIndex].uniqueID);
				BTN_DisplayQuests(currQuestTabType);
				Debug.LogWarning((object)"Allegedly accepted quest.");
			}
		}

		public void BTN_OpenTab(int index)
		{
			CloseTabs();
			switch (index)
			{
			case 0:
				((Component)TravelTab).gameObject.SetActive(true);
				break;
			case 1:
				((Component)ContractsTab).gameObject.SetActive(true);
				BTN_DisplayQuests(currQuestTabType);
				break;
			case 2:
				((Component)TimeTab).gameObject.SetActive(true);
				break;
			default:
				Debug.LogError((object)("Selected tab not supported: " + index));
				return;
			}
			selectedTabIx = index;
		}

		public void BTN_TravelHome()
		{
			FG_GM.Instance.TransitionToLevel("IndoorRange_Updated");
		}

		public void BTN_TravelArea()
		{
			FG_GM.Instance.TransitionToLevel("Grillhouse_2Story");
		}

		public void BTN_AdvanceHour()
		{
			FGTimeSystem.Instance.AdvanceTime(3600);
		}

		public void AddTimeUiRunner()
		{
			FGTimeUi fGTimeUi = ((Component)this).gameObject.AddComponent<FGTimeUi>();
			Text componentInChildren = ((Component)TimeText).GetComponentInChildren<Text>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				fGTimeUi.timeText = componentInChildren;
			}
		}

		private void UpdateWristMenu()
		{
			//IL_0045: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Invalid comparison between Unknown and I4
			//IL_01ab: 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_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Invalid comparison between Unknown and I4
			if (!m_hasHands)
			{
				return;
			}
			if (m_isActive)
			{
				PositionWristMenu();
				if ((Object)(object)m_currentHand.CurrentInteractable != (Object)null || Vector3.Angle(m_currentHand.GetWristMenuTarget().forward, -Face.forward) >= m_wristPointRange)
				{
					Deactivate();
					return;
				}
				if ((Object)(object)m_currentHand != (Object)null)
				{
					Vector3 val = m_currentHand.GetWristMenuTarget().position - Face.position;
					if (Vector3.Angle(Face.forward, val) >= m_faceAngleRange)
					{
						Deactivate();
						return;
					}
				}
			}
			if (m_isActive)
			{
				return;
			}
			for (int i = 0; i < Hands.Length; i++)
			{
				if ((Object)(object)Hands[i].CurrentInteractable == (Object)null && Vector3.Angle(Hands[i].GetWristMenuTarget().forward, -Face.forward) < m_wristPointRange)
				{
					Vector3 val2 = Hands[i].GetWristMenuTarget().position - Face.position;
					if ((!Hands[i].IsThisTheRightHand || (int)GM.Options.ControlOptions.WristMenuState != 2) && (Hands[i].IsThisTheRightHand || (int)GM.Options.ControlOptions.WristMenuState != 1) && Vector3.Angle(Face.forward, val2) < m_faceAngleRange)
					{
						ActivateOnHand(Hands[i]);
					}
				}
			}
		}

		public void SetHandsAndFace(FVRViveHand Hand0, FVRViveHand Hand1, Transform face)
		{
			Hands = (FVRViveHand[])(object)new FVRViveHand[2];
			Hands[0] = Hand0;
			Hands[1] = Hand1;
			Face = face;
			m_hasHands = true;
		}

		public void PositionWristMenu()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_0046: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (m_isActive && (Object)(object)m_currentHand != (Object)null)
			{
				Transform wristMenuTarget = m_currentHand.GetWristMenuTarget();
				((Component)this).transform.position = wristMenuTarget.position + wristMenuTarget.right * -1f;
				((Component)this).transform.rotation = wristMenuTarget.rotation * Quaternion.Euler(0f, -90f, 0f);
			}
		}

		private void ActivateOnHand(FVRViveHand hand)
		{
			if (!m_isActive)
			{
				m_isActive = true;
				m_currentHand = hand;
				((Component)Canvas).gameObject.SetActive(true);
				PositionWristMenu();
			}
		}

		public void Deactivate()
		{
			if (m_isActive)
			{
				m_isActive = false;
				((Component)Canvas).gameObject.SetActive(false);
			}
		}
	}
}
namespace NGA.FreeGriller
{
	[BepInPlugin("NGA.FreeGriller", "FreeGriller", "0.0.1")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class FreeGrillerPlugin : BaseUnityPlugin
	{
		private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		internal static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			LoadAssets();
		}

		private void LoadAssets()
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "NGA.FreeGriller");
			OtherLoader.RegisterDirectLoad(BasePath, "NGA.FreeGriller", "", "", "nga_freegrillerui", "");
		}
	}
}