using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Diz.Skinning;
using EFT;
using EFT.CameraControl;
using EFT.Interactive;
using EFT.InventoryLogic;
using EFT.NextObservedPlayer;
using EFT.UI;
using stupid.solutions.Data;
using stupid.solutions.stupid.solutions.Data;
using UnityEngine;

namespace stupid.solutions.Utils;

public static class GameUtils
{
	public class Tracer
	{
		public Vector3 StartPos;

		public Vector3 EndPos;

		public float Time;
	}

	public class HitMarker
	{
		public Vector3 HitPos;

		public float Time;
	}

	public static Camera AimCamera;

	public static Material DrawMaterial;

	public static Vector2 ScreenCenter = new Vector2((float)Screen.width / 2f, (float)Screen.height / 2f);

	public static void InitMaterial()
	{
		try
		{
			DrawMaterial = new Material(Shader.Find("Hidden/Internal-Colored"))
			{
				hideFlags = HideFlags.HideAndDontSave
			};
			if (DrawMaterial.shader == null)
			{
				throw new Exception("Shader 'Hidden/Internal-Colored' not found or unavailable.");
			}
			ConsoleScreen.Log("Found Tracer Material Shader");
			DrawMaterial.SetInt("_SrcBlend", 5);
			DrawMaterial.SetInt("_DstBlend", 10);
			DrawMaterial.SetInt("_Cull", 0);
			DrawMaterial.SetInt("_ZWrite", 0);
			ConsoleScreen.Log("Set Tracer Material Parameters");
		}
		catch (Exception ex)
		{
			ConsoleScreen.LogError("[TracerESP] Failed to initialize material: " + ex.Message);
		}
	}

	public static float Map(float value, float sourceFrom, float sourceTo, float destinationFrom, float destinationTo)
	{
		return (value - sourceFrom) / (sourceTo - sourceFrom) * (destinationTo - destinationFrom) + destinationFrom;
	}

	public static bool IsPlayerValid(Player player)
	{
		if (player != null && player.Transform != null && player.PlayerBones != null)
		{
			return player.PlayerBones.transform != null;
		}
		return false;
	}

	public static bool IsOPlayerValid(ObservedPlayerView player)
	{
		if (player != null && player.Transform != null && player.PlayerBones != null)
		{
			return player.PlayerBones.transform != null;
		}
		return false;
	}

	public static bool IsExfiltrationPointValid(ExfiltrationPoint lootItem)
	{
		return lootItem != null;
	}

	public static bool IsTransitPointValid(TransitPoint lootItem)
	{
		return lootItem != null;
	}

	public static bool IsLootItemValid(LootItem lootItem)
	{
		if (lootItem != null && lootItem.Item != null)
		{
			return lootItem.Item.Template != null;
		}
		return false;
	}

	public static int? GetItemPrice(GameLootItem item)
	{
		string itemid = item.LootItem.TemplateId;
		List<ItemData> source = Menu2.pullItemIDs.itemList.Where((ItemData itemData2) => itemData2.Id == itemid).ToList();
		if (source.Any())
		{
			ItemData itemData = source.First();
			if (itemData.avg24hPrice > 0)
			{
				return itemData.avg24hPrice;
			}
			if (itemData.BasePrice > 0)
			{
				return itemData.BasePrice;
			}
		}
		return 0;
	}

	public static int? GetItemPriceBYID(string itemid)
	{
		List<ItemData> source = Menu2.pullItemIDs.itemList.Where((ItemData itemData2) => itemData2.Id == itemid).ToList();
		if (source.Any())
		{
			ItemData itemData = source.First();
			if (itemData.avg24hPrice > 0)
			{
				return itemData.avg24hPrice;
			}
			if (itemData.BasePrice > 0)
			{
				return itemData.BasePrice;
			}
		}
		return 0;
	}

	public static bool ShouldDisplayItem(ContainerItem lootItem)
	{
		if (lootItem == null || lootItem.Itemcat == ItemCategories.Uninitialized)
		{
			return false;
		}
		if (lootItem.Itemcat == ItemCategories.Superrare && Settings.superrare)
		{
			return true;
		}
		if (lootItem.Itemcat == ItemCategories.Kappa && Settings.kappa)
		{
			return true;
		}
		if (lootItem.Itemcat == ItemCategories.Quest && Settings.quest)
		{
			return true;
		}
		if (lootItem.Itemcat == ItemCategories.Wishlist && Settings.drawwishlistitem)
		{
			return true;
		}
		if (lootItem.Itemcat == ItemCategories.Stim && Settings.stim)
		{
			return true;
		}
		if (lootItem.Itemcat == ItemCategories.Hideout && Settings.drawhideoutitems)
		{
			return true;
		}
		if (lootItem.Itemcat == ItemCategories.Searched && Settings.searchItem)
		{
			return true;
		}
		if (lootItem.Itemcat == ItemCategories.Common && Settings.common)
		{
			return false;
		}
		if (lootItem.itemprice > Settings.ESPPRICEfiltervalue && Settings.ESPFilterbyprice)
		{
			return true;
		}
		return false;
	}

	public static Color GetItemColor(ItemCategories Itemcat)
	{
		if (Settings.searchItem && Itemcat == ItemCategories.Searched)
		{
			return Settings.SearchedColor;
		}
		if (Settings.kappa && Itemcat == ItemCategories.Kappa)
		{
			return Settings.KappaColor;
		}
		if (Settings.superrare && Itemcat == ItemCategories.Superrare)
		{
			return Settings.SuperrareColor;
		}
		if (Settings.stim && Itemcat == ItemCategories.Stim)
		{
			return Settings.StimItemColor;
		}
		if (Settings.quest && Itemcat == ItemCategories.Quest)
		{
			return Settings.QuestItemColor;
		}
		if (Settings.drawwishlistitem && Itemcat == ItemCategories.Wishlist)
		{
			return Settings.WishlistColor;
		}
		if (Settings.drawhideoutitems && Itemcat == ItemCategories.Hideout)
		{
			return Settings.HideoutColor;
		}
		if (Settings.common && Itemcat == ItemCategories.Common)
		{
			return Settings.CommonItemColor;
		}
		return Color.white;
	}

	public static (string playerText, string shorttext, Color playerColor) GetPlayerTextDetails(GamePlayer gamePlayer, WildSpawnType role)
	{
		string text = "  ";
		string text2 = "  ";
		Color white = Color.white;
		if (gamePlayer.Player.Profile.Info.Settings.IsBoss())
		{
			if (Main.IsBossByName(gamePlayer.Player.Profile.Info.Nickname.Localized()))
			{
				text2 = " Boss ";
				text = Main.TranslateBossName(gamePlayer.Player.Profile.Info.Nickname.Localized()) + "  [" + gamePlayer.FormattedDistance + "] ";
				white = Settings.BossandGuardColor;
			}
			else
			{
				switch (role)
				{
				case WildSpawnType.shooterBTR:
					text2 = " BTR ";
					text = " BTR [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.BTRColor;
					break;
				case WildSpawnType.peacefullZryachiyEvent:
				case WildSpawnType.ravangeZryachiyEvent:
					text2 = " Boss ";
					text = " Event Zryachi [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.BossandGuardColor;
					break;
				case WildSpawnType.bossTagillaAgro:
					text2 = " Boss ";
					text = " Shadow of Tagilla [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.BossandGuardColor;
					break;
				case WildSpawnType.bossKillaAgro:
					text2 = " Boss ";
					text = " Shadow of Killa [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.BossandGuardColor;
					break;
				case WildSpawnType.tagillaHelperAgro:
					text2 = " Guard ";
					text = " Guard [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.GuardColor;
					break;
				case WildSpawnType.infectedTagilla:
					text2 = " Boss ";
					text = " Zombie Tagilla [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.BossandGuardColor;
					break;
				case WildSpawnType.exUsec:
					text2 = " Rogue ";
					text = " Rogue [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.RogueColor;
					break;
				case WildSpawnType.pmcUSEC:
					text2 = " PMC ";
					text = $" [USEC] {gamePlayer.Player.Profile.Info.Nickname} [{gamePlayer.Player.Profile.Info.Level}] [{gamePlayer.FormattedDistance}] ";
					white = Settings.USECColor;
					break;
				case WildSpawnType.pmcBEAR:
					text2 = " PMC ";
					text = $" [BEAR] {gamePlayer.Player.Profile.Info.Nickname} [{gamePlayer.Player.Profile.Info.Level}] [{gamePlayer.FormattedDistance}] ";
					white = Settings.BEARColor;
					break;
				case WildSpawnType.followerZryachiy:
				case WildSpawnType.bossBoarSniper:
					text2 = " Guard ";
					text = " Guard [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.GuardColor;
					break;
				case WildSpawnType.pmcBot:
					text2 = " Raider ";
					text = " Raider [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.RaiderColor;
					break;
				case WildSpawnType.sectantPriest:
				case WildSpawnType.sectactPriestEvent:
				case WildSpawnType.sectantPredvestnik:
				case WildSpawnType.sectantPrizrak:
				case WildSpawnType.sectantOni:
					text2 = " Cultist ";
					text = " Cultist [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.CultistColor;
					break;
				case WildSpawnType.marksman:
				case WildSpawnType.assault:
				case WildSpawnType.assaultGroup:
					text2 = " Scav ";
					text = " Scav [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.ScavColor;
					break;
				case WildSpawnType.infectedAssault:
				case WildSpawnType.infectedPmc:
				case WildSpawnType.infectedCivil:
				case WildSpawnType.infectedLaborant:
					text2 = " [Z] ";
					text = " Zombie [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.ZombieColor;
					break;
				default:
				{
					text2 = " U-Boss ";
					string text3 = role.ToString();
					text = " Unknown Boss Entity Name : " + gamePlayer.Player.Profile.Info.Nickname + " [" + gamePlayer.FormattedDistance + "] Role : " + text3 + " ";
					white = Color.red;
					break;
				}
				}
			}
		}
		else
		{
			switch (role)
			{
			case WildSpawnType.sectantWarrior:
				text2 = " Cultist ";
				text = " Cultist[" + gamePlayer.FormattedDistance + "] ";
				white = Settings.CultistColor;
				break;
			case WildSpawnType.marksman:
				text2 = " Sniper ";
				text = " Scav Sniper [" + gamePlayer.FormattedDistance + "] ";
				white = Settings.ScavColor;
				break;
			case WildSpawnType.shooterBTR:
				text2 = " BTR ";
				text = " BTR [" + gamePlayer.FormattedDistance + "] ";
				white = Settings.BTRColor;
				break;
			case WildSpawnType.infectedAssault:
			case WildSpawnType.infectedPmc:
			case WildSpawnType.infectedCivil:
			case WildSpawnType.infectedLaborant:
				text2 = " [Z] ";
				text = " Zombie [" + gamePlayer.FormattedDistance + "] ";
				white = Settings.ZombieColor;
				break;
			case WildSpawnType.arenaFighter:
				text2 = " Fighter ";
				text = " Arena Fighter [" + gamePlayer.FormattedDistance + "] ";
				white = Settings.RaiderColor;
				break;
			default:
				if (role != WildSpawnType.marksman && role != WildSpawnType.assault)
				{
					text2 = " Guard ";
					text = " Guard [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.GuardColor;
				}
				else
				{
					text2 = " Scav ";
					text = " Scav [" + gamePlayer.FormattedDistance + "] ";
					white = Settings.ScavColor;
				}
				break;
			}
		}
		return (playerText: text, shorttext: text2, playerColor: white);
	}

	public static (string playerText, string shorttext, Color playerColor) GetPlayerTextDetailsO(OnlineGamePlayer gamePlayer)
	{
		string item = "  ";
		string item2 = "  ";
		Color item3 = Color.white;
		OnlineGamePlayer.PlayerType role = gamePlayer.role;
		if (role == OnlineGamePlayer.PlayerType.Boss)
		{
			item2 = " Boss ";
			item = Main.TranslateBossNameBYWST(gamePlayer.wst) + "  [" + gamePlayer.FormattedDistance + "] ";
			item3 = Settings.BossandGuardColor;
		}
		else if (role == OnlineGamePlayer.PlayerType.Guard)
		{
			item2 = " Guard ";
			item = " Guard [" + gamePlayer.FormattedDistance + "] ";
			item3 = Settings.GuardColor;
		}
		else if (role == OnlineGamePlayer.PlayerType.BTR)
		{
			item2 = " BTR ";
			item = " BTR [" + gamePlayer.FormattedDistance + "] ";
			item3 = Settings.BTRColor;
		}
		else if (role == OnlineGamePlayer.PlayerType.Cultist)
		{
			item2 = " Cultist ";
			item = " Cultist [" + gamePlayer.FormattedDistance + "] ";
			item3 = Settings.CultistColor;
		}
		else if (role == OnlineGamePlayer.PlayerType.Raider)
		{
			item2 = " Raider ";
			item = " Raider [" + gamePlayer.FormattedDistance + "] ";
			item3 = Settings.RaiderColor;
		}
		else if (role == OnlineGamePlayer.PlayerType.Rogue)
		{
			item2 = " Rogue ";
			item = " Rogue [" + gamePlayer.FormattedDistance + "] ";
			item3 = Settings.RogueColor;
		}
		else if (role == OnlineGamePlayer.PlayerType.Zombie)
		{
			item2 = " [Z] ";
			item = " Zombie [" + gamePlayer.FormattedDistance + "] ";
			item3 = Settings.ZombieColor;
		}
		else if (role == OnlineGamePlayer.PlayerType.Scav)
		{
			item2 = " Scav ";
			item = " Scav [" + gamePlayer.FormattedDistance + "] ";
			item3 = Settings.ScavColor;
		}
		else if (role == OnlineGamePlayer.PlayerType.Teammate && !gamePlayer.IsAI)
		{
			item2 = " [Teammate] ";
			item = $" [Teammate] {gamePlayer.NickName} [KD : {gamePlayer.kd:f1}] [{gamePlayer.FormattedDistance}] ";
			item3 = Settings.teammatecolor;
		}
		else if (role == OnlineGamePlayer.PlayerType.USEC && !gamePlayer.IsAI)
		{
			item2 = " USEC ";
			item = $" [LVL {gamePlayer.level} USEC] {gamePlayer.NickName} [KD : {gamePlayer.kd:f1}] [{gamePlayer.FormattedDistance}] ";
			item3 = Settings.USECColor;
		}
		else if (role == OnlineGamePlayer.PlayerType.BEAR && !gamePlayer.IsAI)
		{
			item2 = " BEAR ";
			item = $" [LVL {gamePlayer.level} BEAR] {gamePlayer.NickName} [KD : {gamePlayer.kd:f1}] [{gamePlayer.FormattedDistance}] ";
			item3 = Settings.BEARColor;
		}
		else if (role == OnlineGamePlayer.PlayerType.PlayerScav && !gamePlayer.IsAI)
		{
			item2 = " Player Scav ";
			item = " [Player Scav] " + ConvertRussianToLatin(gamePlayer.NickName) + " [" + gamePlayer.FormattedDistance + "] ";
			item3 = Settings.playerscavcolor;
		}
		return (playerText: item, shorttext: item2, playerColor: item3);
	}

	public static bool ContainsRussianCharacters(string input)
	{
		string pattern = "[\\u0400-\\u04FF]";
		return Regex.IsMatch(input, pattern);
	}

	public static bool IsHealing(string input)
	{
		if (string.IsNullOrWhiteSpace(input))
		{
			return false;
		}
		return new HashSet<string>(StringComparer.OrdinalIgnoreCase)
		{
			"Splint", "CMS", "Surv12", "Aseptic", "Army", "CAT", "CALOK-B", "Esmarch", "AI-2", "Car",
			"Salewa", "IFAK", "AFAK", "Grizzly"
		}.Contains(input.Trim());
	}

	public static string ConvertRussianToLatin(string input)
	{
		if (string.IsNullOrWhiteSpace(input))
		{
			return input;
		}
		Dictionary<char, string> dictionary = new Dictionary<char, string>
		{
			{ 'А', "A" },
			{ 'а', "a" },
			{ 'Б', "B" },
			{ 'б', "b" },
			{ 'В', "V" },
			{ 'в', "v" },
			{ 'Г', "G" },
			{ 'г', "g" },
			{ 'Д', "D" },
			{ 'д', "d" },
			{ 'Е', "E" },
			{ 'е', "e" },
			{ 'Ё', "Yo" },
			{ 'ё', "yo" },
			{ 'Ж', "Zh" },
			{ 'ж', "zh" },
			{ 'З', "Z" },
			{ 'з', "z" },
			{ 'И', "I" },
			{ 'и', "i" },
			{ 'Й', "Y" },
			{ 'й', "y" },
			{ 'К', "K" },
			{ 'к', "k" },
			{ 'Л', "L" },
			{ 'л', "l" },
			{ 'М', "M" },
			{ 'м', "m" },
			{ 'Н', "N" },
			{ 'н', "n" },
			{ 'О', "O" },
			{ 'о', "o" },
			{ 'П', "P" },
			{ 'п', "p" },
			{ 'Р', "R" },
			{ 'р', "r" },
			{ 'С', "S" },
			{ 'с', "s" },
			{ 'Т', "T" },
			{ 'т', "t" },
			{ 'У', "U" },
			{ 'у', "u" },
			{ 'Ф', "F" },
			{ 'ф', "f" },
			{ 'Х', "Kh" },
			{ 'х', "kh" },
			{ 'Ц', "Ts" },
			{ 'ц', "ts" },
			{ 'Ч', "Ch" },
			{ 'ч', "ch" },
			{ 'Ш', "Sh" },
			{ 'ш', "sh" },
			{ 'Щ', "Shch" },
			{ 'щ', "shch" },
			{ 'Ъ', "" },
			{ 'ъ', "" },
			{ 'Ы', "Y" },
			{ 'ы', "y" },
			{ 'Ь', "" },
			{ 'ь', "" },
			{ 'Э', "E" },
			{ 'э', "e" },
			{ 'Ю', "Yu" },
			{ 'ю', "yu" },
			{ 'Я', "Ya" },
			{ 'я', "ya" }
		};
		StringBuilder stringBuilder = new StringBuilder();
		foreach (char c in input)
		{
			if (dictionary.TryGetValue(c, out var value))
			{
				stringBuilder.Append(value);
			}
			else
			{
				stringBuilder.Append(c);
			}
		}
		return stringBuilder.ToString();
	}

	public static string ConvertLatinToRussian(string input)
	{
		if (string.IsNullOrWhiteSpace(input))
		{
			return input;
		}
		Dictionary<string, string> dictionary = new Dictionary<string, string>
		{
			{ "A", "А" },
			{ "a", "а" },
			{ "B", "Б" },
			{ "b", "б" },
			{ "V", "В" },
			{ "v", "в" },
			{ "G", "Г" },
			{ "g", "г" },
			{ "D", "Д" },
			{ "d", "д" },
			{ "E", "Е" },
			{ "e", "е" },
			{ "Yo", "Ё" },
			{ "yo", "ё" },
			{ "Zh", "Ж" },
			{ "zh", "ж" },
			{ "Z", "З" },
			{ "z", "з" },
			{ "I", "И" },
			{ "i", "и" },
			{ "Y", "Й" },
			{ "y", "й" },
			{ "K", "К" },
			{ "k", "к" },
			{ "L", "Л" },
			{ "l", "л" },
			{ "M", "М" },
			{ "m", "м" },
			{ "N", "Н" },
			{ "n", "н" },
			{ "O", "О" },
			{ "o", "о" },
			{ "P", "П" },
			{ "p", "п" },
			{ "R", "Р" },
			{ "r", "р" },
			{ "S", "С" },
			{ "s", "с" },
			{ "T", "Т" },
			{ "t", "т" },
			{ "U", "У" },
			{ "u", "у" },
			{ "F", "Ф" },
			{ "f", "ф" },
			{ "Kh", "Х" },
			{ "kh", "х" },
			{ "Ts", "Ц" },
			{ "ts", "ц" },
			{ "Ch", "Ч" },
			{ "ch", "ч" },
			{ "Sh", "Ш" },
			{ "sh", "ш" },
			{ "Shch", "Щ" },
			{ "shch", "щ" },
			{ "'", "ъ" },
			{ "Y", "Ы" },
			{ "y", "ы" },
			{ "''", "ь" },
			{ "E", "Э" },
			{ "e", "э" },
			{ "Yu", "Ю" },
			{ "yu", "ю" },
			{ "Ya", "Я" },
			{ "ya", "я" }
		};
		StringBuilder stringBuilder = new StringBuilder();
		for (int i = 0; i < input.Length; i++)
		{
			if (i < input.Length - 1)
			{
				string key = input.Substring(i, 2);
				if (dictionary.TryGetValue(key, out var value))
				{
					stringBuilder.Append(value);
					i++;
					continue;
				}
			}
			string text = input[i].ToString();
			if (dictionary.TryGetValue(text, out var value2))
			{
				stringBuilder.Append(value2);
			}
			else
			{
				stringBuilder.Append(text);
			}
		}
		return stringBuilder.ToString();
	}

	public static bool IsLootableContainerValid(LootableContainer lootableContainer)
	{
		if (lootableContainer != null)
		{
			return lootableContainer.Template != null;
		}
		return false;
	}

	public static bool IsPlayerAlive(Player player)
	{
		if (!IsPlayerValid(player))
		{
			return false;
		}
		if (player.HealthController == null)
		{
			return false;
		}
		return player.HealthController.IsAlive;
	}

	public static bool IsOPlayerAlive(ObservedPlayerView player)
	{
		if (!IsOPlayerValid(player))
		{
			return false;
		}
		if (player.HealthController == null)
		{
			return false;
		}
		return player.HealthController.IsAlive;
	}

	public static bool IsCorpseValid(Corpse corpse)
	{
		return corpse != null;
	}

	public static bool IsInventoryItemValid(Item item)
	{
		if (item != null)
		{
			return item.Template != null;
		}
		return false;
	}

	public static bool IsFriend(Player player)
	{
		if (Main.LocalPlayer.Profile.Info.GroupId == player.Profile.Info.GroupId && player.Profile.Info.GroupId != "0" && player.Profile.Info.GroupId != "")
		{
			return player.Profile.Info.GroupId != null;
		}
		return false;
	}

	public static bool IsInFov(Vector3 screenpos, float fovRadius)
	{
		Vector3 vector = screenpos;
		float num = Screen.width;
		float num2 = Screen.height;
		Vector2 a = new Vector2(num / 2f, num2 / 2f);
		Vector2 b = new Vector2(vector.x, vector.y);
		return Vector2.Distance(a, b) <= fovRadius;
	}

	public static Vector3 WorldPointToScreenPoint(Vector3 worldPoint)
	{
		if (Main.MainCamera == null)
		{
			return Vector3.zero;
		}
		Vector3 result = Main.MainCamera.WorldToScreenPoint(worldPoint);
		float num = (float)Screen.height / (float)Main.MainCamera.scaledPixelHeight;
		result.y = (float)Screen.height - result.y * num;
		result.x *= num;
		return result;
	}

	private static bool IsPointInScopeView(Vector3 worldPoint, Camera opticCamera)
	{
		OpticSight componentInChildren = Main.LocalPlayer.ProceduralWeaponAnimation.HandsContainer.Weapon.GetComponentInChildren<OpticSight>();
		if (componentInChildren == null)
		{
			return false;
		}
		Mesh mesh = componentInChildren.LensRenderer.GetComponent<MeshFilter>().mesh;
		Vector3 position = componentInChildren.LensRenderer.transform.TransformPoint(mesh.bounds.max);
		Vector3 position2 = componentInChildren.LensRenderer.transform.TransformPoint(mesh.bounds.min);
		Vector3 vector = opticCamera.WorldToScreenPoint(position);
		Vector3 vector2 = opticCamera.WorldToScreenPoint(position2);
		Vector3 vector3 = opticCamera.WorldToScreenPoint(worldPoint);
		if (vector3.x >= vector2.x && vector3.x <= vector.x && vector3.y >= vector2.y)
		{
			return vector3.y <= vector.y;
		}
		return false;
	}

	private static bool IsPointVisibleInCamera(Vector3 screenPoint, Camera camera)
	{
		Vector3 vector = camera.ScreenToViewportPoint(screenPoint);
		if (screenPoint.z > 0.01f && vector.x >= 0f && vector.x <= 1f && vector.y >= 0f)
		{
			return vector.y <= 1f;
		}
		return false;
	}

	public static void DrawTracer(Vector3 worldpos, Color color)
	{
		Vector3 vector = Main.ActiveCamera.WorldToScreenPoint(worldpos);
		vector.y = (float)Screen.height - vector.y;
		GL.PushMatrix();
		GL.Begin(1);
		DrawMaterial.SetPass(0);
		GL.Color(color);
		GL.Vertex3(Screen.width / 2, Screen.height, 0f);
		GL.Vertex3(vector.x, vector.y, 0f);
		GL.End();
		GL.PopMatrix();
	}

	public static bool IsScreenPointVisible(Vector3 screenPoint)
	{
		if (screenPoint.z > 0.01f && screenPoint.x > -5f && screenPoint.y > -5f && screenPoint.x < (float)Screen.width)
		{
			return screenPoint.y < (float)Screen.height;
		}
		return false;
	}

	public static Vector3 GetBonePosByID(Player player, int id)
	{
		try
		{
			return SkeletonBonePos(player.PlayerBones.AnimatedTransform.Original.gameObject.GetComponent<PlayerBody>().SkeletonRootJoint, id);
		}
		catch (Exception)
		{
			return Vector3.zero;
		}
	}

	public static Vector3 GetBonePosByIDO(ObservedPlayerView player, int id)
	{
		try
		{
			return SkeletonBonePos(player.PlayerBones.AnimatedTransform.Original.gameObject.GetComponent<PlayerBody>().SkeletonRootJoint, id);
		}
		catch (Exception)
		{
			return Vector3.zero;
		}
	}

	public static Vector3 SkeletonBonePos(Skeleton skeleton, int id)
	{
		return skeleton.Bones.ElementAt(id).Value.position;
	}

	public static Vector3 FinalVector(Player player, int bone)
	{
		try
		{
			return player.PlayerBody.SkeletonRootJoint.Bones.ElementAt(bone).Value.position;
		}
		catch
		{
			return Vector3.zero;
		}
	}

	public static Vector3 FinalVectorO(ObservedPlayerView player, int bone)
	{
		try
		{
			return player.PlayerBody.SkeletonRootJoint.Bones.ElementAt(bone).Value.position;
		}
		catch
		{
			return Vector3.zero;
		}
	}

	public static void UpdateCameraState(Player player)
	{
		Main.ActiveCamera = Main.MainCamera;
	}
}
