Decompiled source of EffigySelector v1.1.1

ScoutEffigySelector.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("VACNET")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+08778abfb5e284767a08e262ad6c94965e12b34d")]
[assembly: AssemblyProduct("VACNET")]
[assembly: AssemblyTitle("VACNET")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ScoutEffigyMod
{
	[BepInPlugin("com.gedisu.EffigySelector", "Effigy Selector", "1.1.1")]
	public class ModPlugin : BaseUnityPlugin
	{
		public static ConfigEntry<KeyCode> SwitchLeftKey { get; private set; }

		public static ConfigEntry<KeyCode> SwitchRightKey { get; private set; }

		public static ConfigEntry<bool> ShouldUseScrollWheel { get; private set; }

		public static ConfigEntry<float> FontSize { get; private set; }

		public static ConfigEntry<string> TextColorHex { get; private set; }

		public static Color GetTextColor()
		{
			//IL_001b: 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_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_0023: Unknown result type (might be due to invalid IL or missing references)
			Color result = default(Color);
			if (ColorUtility.TryParseHtmlString(TextColorHex.Value, ref result))
			{
				return result;
			}
			return Color.white;
		}

		private void Awake()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			SwitchLeftKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input", "SwitchLeft", (KeyCode)122, "Key to switch to the previous player in the list.");
			SwitchRightKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input", "SwitchRight", (KeyCode)99, "Key to switch to the next player in the list.");
			FontSize = ((BaseUnityPlugin)this).Config.Bind<float>("UI", "FontSize", 32f, "Font size of the on-screen prompt.");
			TextColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("UI", "TextColorHex", "#DFDBC2", "Color of prompt text in HEX format (e.g. #FFFFFF, #FF0000, #00FF88).");
			Harmony val = new Harmony("com.gedisu.EffigySelector");
			val.PatchAll();
			GameObject val2 = new GameObject("ScoutEffigyUI_Controller");
			Object.DontDestroyOnLoad((Object)(object)val2);
			val2.AddComponent<ScoutEffigySelectorUI>();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ScoutEffigySelector loaded!");
		}
	}
	[HarmonyPatch(typeof(ScoutEffigy), "FinishConstruction")]
	public class ScoutEffigy_FinishConstruction_Patch
	{
		public static Character TargetCharacterToRevive;

		[HarmonyPrefix]
		public static bool Prefix(ScoutEffigy __instance, ref GameObject __result, bool ___constructing, GameObject ___currentPreview, RaycastHit ___currentConstructHit)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			if (!___constructing || (Object)(object)___currentPreview == (Object)null)
			{
				__result = null;
				return false;
			}
			List<Character> deadCharacters = DeadPlayersManager.GetDeadCharacters();
			if (deadCharacters.Count == 0)
			{
				__result = null;
				return false;
			}
			Character val = TargetCharacterToRevive;
			if ((Object)(object)val == (Object)null || !deadCharacters.Contains(val))
			{
				val = deadCharacters[Random.Range(0, deadCharacters.Count)];
			}
			((MonoBehaviourPun)val).photonView.RPC("RPCA_ReviveAtPosition", (RpcTarget)0, new object[3]
			{
				((RaycastHit)(ref ___currentConstructHit)).point + Vector3.up * 1f,
				false,
				-1
			});
			if (Object.op_Implicit((Object)(object)Singleton<AchievementManager>.Instance))
			{
				Singleton<AchievementManager>.Instance.AddToRunBasedInt((RUNBASEDVALUETYPE)2, 1);
			}
			__result = null;
			TargetCharacterToRevive = null;
			return false;
		}
	}
	public static class DeadPlayersManager
	{
		private static List<Character> _cachedDeadList = new List<Character>();

		public static List<Character> GetDeadCharacters()
		{
			_cachedDeadList.Clear();
			if (Character.AllCharacters == null)
			{
				return _cachedDeadList;
			}
			foreach (Character allCharacter in Character.AllCharacters)
			{
				if ((Object)(object)allCharacter != (Object)null && (Object)(object)allCharacter.data != (Object)null && (allCharacter.data.dead || allCharacter.data.passedOut || allCharacter.data.fullyPassedOut))
				{
					_cachedDeadList.Add(allCharacter);
				}
			}
			return _cachedDeadList;
		}
	}
	public class ScoutEffigySelectorUI : MonoBehaviour
	{
		private int _currentTargetIndex = 0;

		private float _scrollCooldown = 0.15f;

		private float _nextScrollTime = 0f;

		private Item _cachedItem = null;

		private bool _hasEffigyComponent = false;

		private bool _isHoldingEffigy = false;

		private TextMeshProUGUI _customPrompt;

		private bool _isPromptSetup = false;

		private void Update()
		{
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter == (Object)null)
			{
				ResetState();
				HideUI();
				return;
			}
			Item currentItem = localCharacter.data.currentItem;
			if (_cachedItem != currentItem)
			{
				_cachedItem = currentItem;
				_hasEffigyComponent = (Object)(object)_cachedItem != (Object)null && (Object)(object)((Component)_cachedItem).GetComponent<ScoutEffigy>() != (Object)null;
			}
			_isHoldingEffigy = (Object)(object)_cachedItem != (Object)null && _hasEffigyComponent;
			if (!_isHoldingEffigy)
			{
				ScoutEffigy_FinishConstruction_Patch.TargetCharacterToRevive = null;
				HideUI();
				return;
			}
			List<Character> deadCharacters = DeadPlayersManager.GetDeadCharacters();
			if (deadCharacters.Count == 0)
			{
				ScoutEffigy_FinishConstruction_Patch.TargetCharacterToRevive = null;
				ManageUI(hasDeadPlayers: false, null);
				return;
			}
			if ((Object)(object)ScoutEffigy_FinishConstruction_Patch.TargetCharacterToRevive != (Object)null && !deadCharacters.Contains(ScoutEffigy_FinishConstruction_Patch.TargetCharacterToRevive))
			{
				ScoutEffigy_FinishConstruction_Patch.TargetCharacterToRevive = null;
				_currentTargetIndex = 0;
			}
			if ((Object)(object)ScoutEffigy_FinishConstruction_Patch.TargetCharacterToRevive == (Object)null)
			{
				ScoutEffigy_FinishConstruction_Patch.TargetCharacterToRevive = deadCharacters[0];
				_currentTargetIndex = 0;
			}
			float y = Input.mouseScrollDelta.y;
			bool flag = Time.time >= _nextScrollTime;
			bool flag2 = y > 0f && flag;
			bool flag3 = y < 0f && flag;
			if (Input.GetKeyDown(ModPlugin.SwitchLeftKey.Value) || flag2)
			{
				if (flag2)
				{
					_nextScrollTime = Time.time + _scrollCooldown;
				}
				_currentTargetIndex--;
				if (_currentTargetIndex < 0)
				{
					_currentTargetIndex = deadCharacters.Count - 1;
				}
			}
			else if (Input.GetKeyDown(ModPlugin.SwitchRightKey.Value) || flag3)
			{
				if (flag3)
				{
					_nextScrollTime = Time.time + _scrollCooldown;
				}
				_currentTargetIndex++;
				if (_currentTargetIndex >= deadCharacters.Count)
				{
					_currentTargetIndex = 0;
				}
			}
			_currentTargetIndex = Mathf.Clamp(_currentTargetIndex, 0, deadCharacters.Count - 1);
			ManageUI(hasDeadPlayers: true, ScoutEffigy_FinishConstruction_Patch.TargetCharacterToRevive = deadCharacters[_currentTargetIndex]);
		}

		private void ResetState()
		{
			_cachedItem = null;
			_hasEffigyComponent = false;
			_isHoldingEffigy = false;
			ScoutEffigy_FinishConstruction_Patch.TargetCharacterToRevive = null;
		}

		private void HideUI()
		{
			if ((Object)(object)_customPrompt != (Object)null && ((Behaviour)_customPrompt).enabled)
			{
				((Behaviour)_customPrompt).enabled = false;
			}
		}

		private void ManageUI(bool hasDeadPlayers, Character target)
		{
			//IL_0062: 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_009e: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			if (!_isPromptSetup || (Object)(object)_customPrompt == (Object)null)
			{
				SetupCustomPrompt();
			}
			if (!((Object)(object)_customPrompt != (Object)null))
			{
				return;
			}
			((Behaviour)_customPrompt).enabled = true;
			((TMP_Text)_customPrompt).fontSize = ModPlugin.FontSize.Value;
			((Graphic)_customPrompt).color = ModPlugin.GetTextColor();
			if (!hasDeadPlayers)
			{
				((TMP_Text)_customPrompt).text = "Everyone is alive";
				return;
			}
			string text = "FFD700";
			string text2 = ((object)ModPlugin.SwitchLeftKey.Value/*cast due to .constrained prefix*/).ToString();
			string text3 = ((object)ModPlugin.SwitchRightKey.Value/*cast due to .constrained prefix*/).ToString();
			CharacterCustomization componentInChildren = ((Component)target).GetComponentInChildren<CharacterCustomization>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				text = ColorUtility.ToHtmlStringRGB(componentInChildren.PlayerColor);
			}
			((TMP_Text)_customPrompt).text = "[" + text2 + "/" + text3 + " or Scroll] Revive: <color=#" + text + ">" + target.characterName + "</color>";
		}

		private void SetupCustomPrompt()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_005c: 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_0088: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: 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)
			GUIManager val = Object.FindFirstObjectByType<GUIManager>();
			if ((Object)(object)val != (Object)null && (Object)(object)val.hudCanvas != (Object)null)
			{
				GameObject val2 = new GameObject("ScoutEffigyPrompt");
				val2.transform.SetParent(((Component)val.hudCanvas).transform, false);
				RectTransform val3 = val2.AddComponent<RectTransform>();
				val3.anchorMin = new Vector2(0.5f, 0f);
				val3.anchorMax = new Vector2(0.5f, 0f);
				val3.pivot = new Vector2(0.5f, 0f);
				val3.anchoredPosition = new Vector2(0f, 120f);
				val3.sizeDelta = new Vector2(600f, 50f);
				_customPrompt = val2.AddComponent<TextMeshProUGUI>();
				((TMP_Text)_customPrompt).enableWordWrapping = false;
				((TMP_Text)_customPrompt).overflowMode = (TextOverflowModes)0;
				((TMP_Text)_customPrompt).alignment = (TextAlignmentOptions)514;
				((TMP_Text)_customPrompt).fontSize = ModPlugin.FontSize.Value;
				((Graphic)_customPrompt).color = ModPlugin.GetTextColor();
				if ((Object)(object)val.interactPromptText != (Object)null)
				{
					((TMP_Text)_customPrompt).font = ((TMP_Text)val.interactPromptText).font;
					((TMP_Text)_customPrompt).fontMaterial = ((TMP_Text)val.interactPromptText).fontMaterial;
				}
				Shadow val4 = val2.AddComponent<Shadow>();
				val4.effectColor = new Color(0f, 0f, 0f, 0.95f);
				val4.effectDistance = new Vector2(2f, -2f);
				_isPromptSetup = true;
			}
			else
			{
				Debug.LogWarning((object)"ScoutEffigy: GUIManager или его hudCanvas не найдены!");
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)_customPrompt != (Object)null && (Object)(object)((Component)_customPrompt).gameObject != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_customPrompt).gameObject);
			}
		}
	}
}