using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Comfort.Common;
using EFT;
using EFT.Animations;
using EFT.Animations.Recoil;
using EFT.Interactive;
using EFT.InventoryLogic;
using EFT.NextObservedPlayer;
using EFT.UI;
using stupid.solutions.Data;
using stupid.solutions.Features.ESP;
using stupid.solutions.stupid.solutions.Data;
using stupid.solutions.Utils;
using UnityEngine;

namespace stupid.solutions;

internal class Exploits : MonoBehaviour
{
	private static readonly Array _bodyParts = Enum.GetValues(typeof(EBodyPart));

	public static BotOwner _botOwner;

	private static Coroutine artillerycoroutine;

	private float waitime = 3f;

	private static Material cachedskyboxmaterial;

	private static bool doorhooked = false;

	private static Dictionary<int, Vector3> originalHeadScales = new Dictionary<int, Vector3>();

	private static Dictionary<int, bool> isHeadScaled = new Dictionary<int, bool>();

	private static TestHook PlayTripwireInteractionHook;

	private static TestHook StopTripwireInteractionHook;

	private static bool isPlayHooked = false;

	private static bool isStopHooked = false;

	private static TestHook AntiFPSDropHook;

	private static bool isantifpshooked = false;

	public void Update()
	{
		if (Input.GetKeyDown(KeyCode.F5))
		{
			ConsoleScreen.IAmDevShowMeLogs = !ConsoleScreen.IAmDevShowMeLogs;
			ConsoleScreen.Log($"Toggling Dev Logs {ConsoleScreen.IAmDevShowMeLogs}");
		}
		if (Input.GetKeyDown(KeyCode.F6))
		{
			ConsoleScreen.Log("Gameworld Location ID : " + Main.GameWorld.LocationId);
		}
		if (Main.GameWorld == null && isHeadScaled.Count > 0)
		{
			isHeadScaled.Clear();
		}
		if (Main.GameWorld == null && originalHeadScales.Count > 0)
		{
			originalHeadScales.Clear();
		}
	}

	public static void UnlockAllDoors()
	{
		if (!(Main.GameWorld != null))
		{
			return;
		}
		if (Main.OnlineGamePlayers.Count > 0)
		{
			ConsoleScreen.Log("No Opening doors in Online !!!");
			return;
		}
		Door[] array = UnityEngine.Object.FindObjectsOfType<Door>();
		foreach (Door door in array)
		{
			if (door.DoorState != EDoorState.Open && !(Vector3.Distance(door.transform.position, Main.LocalPlayer.Position) > 20f))
			{
				door.DoorState = EDoorState.Shut;
			}
		}
	}

	public static void SwitchToThirdPerson()
	{
		if (Main.LocalPlayer != null)
		{
			Main.LocalPlayer.PointOfView = EPointOfView.ThirdPerson;
			if (Main.LocalPlayer.CameraPosition != null)
			{
				Main.LocalPlayer.CameraPosition.localPosition = new Vector3(0f, 0.5f, -2f);
				Main.MainCamera.transform.localRotation = Quaternion.identity;
			}
		}
	}

	public static void FreeCameraUpdate()
	{
		if (!(Main.LocalPlayer == null) && !(Main.MainCamera == null))
		{
			Transform transform = Main.MainCamera.transform;
			float num = 2f;
			if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
			{
				num = 10f;
			}
			Vector3 zero = Vector3.zero;
			if (Input.GetKey(KeyCode.UpArrow))
			{
				zero += transform.forward;
			}
			if (Input.GetKey(KeyCode.DownArrow))
			{
				zero -= transform.forward;
			}
			if (Input.GetKey(KeyCode.LeftArrow))
			{
				zero -= transform.right;
			}
			if (Input.GetKey(KeyCode.RightArrow))
			{
				zero += transform.right;
			}
			if (zero != Vector3.zero)
			{
				transform.position += zero.normalized * num * Time.deltaTime;
			}
		}
	}

	public static void SwitchToFirstPerson()
	{
		if (Main.LocalPlayer != null)
		{
			Main.LocalPlayer.PointOfView = EPointOfView.FirstPerson;
		}
	}

	public static void FlyHack()
	{
		if (Main.LocalPlayer != null && Main.LocalPlayer.Transform != null && Main.MainCamera != null)
		{
			Main.LocalPlayer.MovementContext.FreefallTime = 0f;
			Main.LocalPlayer.MovementContext.IsGrounded = true;
			if (Input.GetKey(KeyCode.Space))
			{
				Main.LocalPlayer.MovementContext.FreefallTime = -0.4f;
				Main.LocalPlayer.Transform.position += Main.LocalPlayer.Transform.up / 5f * Settings.Speed;
			}
			if (Input.GetKey(KeyCode.LeftControl))
			{
				Main.LocalPlayer.Transform.position -= Main.LocalPlayer.Transform.up / 5f * Settings.Speed;
			}
		}
	}

	public static void SpeedHack()
	{
		if (Input.GetKey(KeyCode.W))
		{
			Main.LocalPlayer.Transform.position += Main.LocalPlayer.Transform.forward / 5f * Settings.Speed;
		}
		if (Input.GetKey(KeyCode.S))
		{
			Main.LocalPlayer.Transform.position -= Main.LocalPlayer.Transform.forward / 5f * Settings.Speed;
		}
		if (Input.GetKey(KeyCode.A))
		{
			Main.LocalPlayer.Transform.position -= Main.LocalPlayer.Transform.right / 5f * Settings.Speed;
		}
		if (Input.GetKey(KeyCode.D))
		{
			Main.LocalPlayer.Transform.position += Main.LocalPlayer.Transform.right / 5f * Settings.Speed;
		}
	}

	public static void InfiniteStamina()
	{
		if (Main.LocalPlayer.Physical.Stamina.Current < 75f)
		{
			Main.LocalPlayer.Physical.Stamina.Current = Main.LocalPlayer.Physical.Stamina.TotalCapacity.Value;
		}
		if (Main.LocalPlayer.Physical.HandsStamina.Current < 75f)
		{
			Main.LocalPlayer.Physical.HandsStamina.Current = Main.LocalPlayer.Physical.HandsStamina.TotalCapacity.Value;
		}
		if (Main.LocalPlayer.Physical.Oxygen.Current < 75f)
		{
			Main.LocalPlayer.Physical.Oxygen.Current = Main.LocalPlayer.Physical.Oxygen.TotalCapacity.Value;
		}
		Main.LocalPlayer.RemoveStateSpeedLimit(Player.ESpeedLimit.Weight);
		Main.LocalPlayer.RemoveStateSpeedLimit(Player.ESpeedLimit.Swamp);
		Main.LocalPlayer.RemoveStateSpeedLimit(Player.ESpeedLimit.SurfaceNormal);
		Main.LocalPlayer.RemoveStateSpeedLimit(Player.ESpeedLimit.Shot);
		Main.LocalPlayer.RemoveStateSpeedLimit(Player.ESpeedLimit.HealthCondition);
		Main.LocalPlayer.RemoveStateSpeedLimit(Player.ESpeedLimit.Fall);
		Main.LocalPlayer.RemoveStateSpeedLimit(Player.ESpeedLimit.BarbedWire);
		Main.LocalPlayer.RemoveStateSpeedLimit(Player.ESpeedLimit.Armor);
		Main.LocalPlayer.RemoveStateSpeedLimit(Player.ESpeedLimit.Aiming);
	}

	public static void Instaheal()
	{
		if (!Input.GetKey(Settings.Instahealkey) || Settings.allinputdisabled)
		{
			return;
		}
		foreach (EBodyPart bodyPart in _bodyParts)
		{
			if (Main.LocalPlayer.ActiveHealthController.IsBodyPartBroken(bodyPart) || Main.LocalPlayer.ActiveHealthController.IsBodyPartDestroyed(bodyPart))
			{
				Main.LocalPlayer.ActiveHealthController.RestoreBodyPart(bodyPart, 1f);
			}
			Main.LocalPlayer.ActiveHealthController.RemoveNegativeEffects(bodyPart);
			Main.LocalPlayer.ActiveHealthController.RemoveNegativeEffects(EBodyPart.Common);
			Main.LocalPlayer.ActiveHealthController.RestoreFullHealth();
			Main.LocalPlayer.ActiveHealthController.ChangeHealth(bodyPart, 1000000f, default(_F167));
			Main.LocalPlayer.ActiveHealthController.ApplyDamage(bodyPart, 0f, default(_F167));
		}
	}

	public static void Godmode()
	{
		Player localPlayer = Main.LocalPlayer;
		if (localPlayer != null && localPlayer.ActiveHealthController != null && Settings.Godmode)
		{
			Main.fixedgodmode = false;
			if (localPlayer.ActiveHealthController.DamageCoeff != -1f)
			{
				localPlayer.ActiveHealthController.SetDamageCoeff(-1f);
				localPlayer.ActiveHealthController.RemoveNegativeEffects(EBodyPart.Common);
				localPlayer.ActiveHealthController.RestoreFullHealth();
				localPlayer.ActiveHealthController.ChangeEnergy(999f);
				localPlayer.ActiveHealthController.ChangeHydration(999f);
				localPlayer.ActiveHealthController.DoPainKiller();
			}
			if (localPlayer.ActiveHealthController.FallSafeHeight != 9999999f)
			{
				localPlayer.ActiveHealthController.FallSafeHeight = 9999999f;
			}
		}
	}

	public static void ResetGodmode()
	{
		Player localPlayer = Main.LocalPlayer;
		if (localPlayer != null && localPlayer.ActiveHealthController != null)
		{
			localPlayer.ActiveHealthController.SetDamageCoeff(1f);
			localPlayer.ActiveHealthController.FallSafeHeight = 1f;
			localPlayer.ActiveHealthController.ChangeEnergy(100f);
			localPlayer.ActiveHealthController.ChangeHydration(100f);
			localPlayer.ActiveHealthController.RemoveMedEffect();
			localPlayer.ActiveHealthController.DoPermanentHealthBoost(0f);
			Settings.Godmode = false;
		}
	}

	public static void Flares()
	{
		if (Input.GetKeyDown(KeyCode.RightBracket) && !Settings.allinputdisabled)
		{
			CallAirdrop(takeNearbyPoint: true, Main.LocalPlayer.Position);
		}
	}

	public static void CallAirdrop(bool takeNearbyPoint = false, Vector3 position = default(Vector3))
	{
		GameWorld gameWorld = Main.GameWorld;
		EFTHardSettings.Instance.WindFactor = 0f;
		if (gameWorld != null)
		{
			gameWorld.InitAirdrop(null, takeNearbyPoint, position);
			ConsoleScreen.Log("Airdrop has been called.");
		}
		else
		{
			ConsoleScreen.Log("GameWorld is null, cannot initiate airdrop.");
		}
	}

	public static void Thermals()
	{
		Main._thermalVision.On = Settings.Thermal;
		ThermalVision thermalVision = Main._thermalVision;
		thermalVision.IsFpsStuck = false;
		thermalVision.IsGlitch = false;
		thermalVision.IsMotionBlurred = false;
		thermalVision.IsNoisy = false;
		thermalVision.IsPixelated = false;
		thermalVision.TextureMask.Color = new Color(0f, 0f, 0f, 0f);
		thermalVision.TextureMask.Stretch = false;
		thermalVision.TextureMask.Size = 0f;
	}

	public static void KillALL()
	{
		GameWorld instance = Singleton<GameWorld>.Instance;
		if (!(instance != null))
		{
			return;
		}
		foreach (Player item in instance.AllAlivePlayersList.Where((Player x) => !x.IsYourPlayer))
		{
			if (!item.IsYourPlayer)
			{
				item.ActiveHealthController.Kill(EDamageType.Landmine);
			}
		}
	}

	public static void TPall()
	{
		GameWorld instance = Singleton<GameWorld>.Instance;
		if (!(instance != null))
		{
			return;
		}
		foreach (Player item in instance.AllAlivePlayersList.Where((Player x) => !x.IsYourPlayer))
		{
			bool flag = Main.IsBossByName(item.Profile.Info.Nickname.Localized());
			WildSpawnType role = item.Profile.Info.Settings.Role;
			if (!item.IsYourPlayer)
			{
				if (!Settings.tpboss && !Settings.tppmc)
				{
					Vector3 position = Main.LocalPlayer.gameObject.transform.position;
					Vector3 forward = Main.LocalPlayer.gameObject.transform.forward;
					float num = 5f;
					Vector3 position2 = position + forward * num;
					item.Teleport(position2, onServerToo: true);
				}
				if (Settings.tpboss && flag && role != WildSpawnType.pmcUSEC && role != WildSpawnType.pmcBEAR)
				{
					Vector3 position3 = Main.LocalPlayer.gameObject.transform.position;
					Vector3 forward2 = Main.LocalPlayer.gameObject.transform.forward;
					float num2 = 5f;
					Vector3 position4 = position3 + forward2 * num2;
					item.Teleport(position4, onServerToo: true);
				}
				if (role == WildSpawnType.pmcUSEC || (role == WildSpawnType.pmcBEAR && Settings.tppmc))
				{
					Vector3 position5 = Main.LocalPlayer.gameObject.transform.position;
					Vector3 forward3 = Main.LocalPlayer.gameObject.transform.forward;
					float num3 = 5f;
					Vector3 position6 = position5 + forward3 * num3;
					item.Teleport(position6, onServerToo: true);
				}
			}
		}
	}

	public static void RemoveVisor()
	{
		Main._visorEffect.Intensity = (Settings.NoVisor ? 0f : 1f);
	}

	public static void InstaHit()
	{
		if (Main.LocalPlayer.HandsController.Item is Weapon)
		{
			Main.LocalPlayerWeapon.Template.Velocity = 1000f;
			Main.LocalPlayerWeapon.CurrentAmmoTemplate.PenetrationChanceObstacle = 100000f;
			Main.LocalPlayerWeapon.CurrentAmmoTemplate.PenetrationPower = 1000000;
			Main.LocalPlayerWeapon.CurrentAmmoTemplate.RicochetChance = 0f;
		}
	}

	public static void NoRecoil()
	{
		if (!Settings.NoRecoil || Main.LocalPlayer == null)
		{
			return;
		}
		IRecoilShotEffect recoilShotEffect = Main.LocalPlayer.ProceduralWeaponAnimation.Shootingg?.CurrentRecoilEffect;
		if (recoilShotEffect != null)
		{
			recoilShotEffect.CameraRotationRecoilEffect.Intensity = 0f;
			recoilShotEffect.HandPositionRecoilEffect.Intensity = 0f;
			recoilShotEffect.HandRotationRecoilEffect.Intensity = 0f;
			ProceduralWeaponAnimation proceduralWeaponAnimation = Main.LocalPlayer.ProceduralWeaponAnimation;
			if (!(proceduralWeaponAnimation == null))
			{
				MotionEffector motionReact = proceduralWeaponAnimation.MotionReact;
				motionReact.Intensity = 0f;
				motionReact.SwayFactors = Vector3.zero;
				motionReact.Velocity = Vector3.zero;
				proceduralWeaponAnimation.Breath.Intensity = 0f;
				proceduralWeaponAnimation.Walk.Intensity = 0f;
				proceduralWeaponAnimation.ForceReact.Intensity = 0f;
				proceduralWeaponAnimation.WalkEffectorEnabled = false;
			}
		}
	}

	public static void RemoveNoRecoil()
	{
		if (Main.LocalPlayer == null)
		{
			return;
		}
		Player localPlayer = Main.LocalPlayer;
		if (!(localPlayer.ProceduralWeaponAnimation == null))
		{
			IRecoilShotEffect recoilShotEffect = localPlayer.ProceduralWeaponAnimation.Shootingg?.CurrentRecoilEffect;
			if (recoilShotEffect != null)
			{
				recoilShotEffect.CameraRotationRecoilEffect.Intensity = 1f;
				recoilShotEffect.HandPositionRecoilEffect.Intensity = 1f;
				recoilShotEffect.HandRotationRecoilEffect.Intensity = 1f;
			}
		}
	}

	public static void NoJam()
	{
		if (Main.LocalPlayer.HandsController.Item is Weapon && Main.LocalPlayerWeapon.Template != null && Main.LocalPlayer != null)
		{
			Main.LocalPlayerWeapon.Template.AllowOverheat = false;
			Main.LocalPlayerWeapon.Template.AllowMisfire = false;
			Main.LocalPlayerWeapon.Template.AllowJam = false;
			Main.LocalPlayerWeapon.Template.AllowFeed = false;
			Main.LocalPlayerWeapon.Template.AllowSlide = false;
			Main.LocalPlayerWeapon.Template.DurabilityBurnRatio = 0f;
		}
	}

	public static void RemoveNoJam()
	{
		if (Main.LocalPlayer.HandsController.Item is Weapon && Main.LocalPlayerWeapon != null)
		{
			Main.LocalPlayerWeapon.Template.AllowOverheat = true;
			Main.LocalPlayerWeapon.Template.AllowMisfire = true;
			Main.LocalPlayerWeapon.Template.AllowJam = true;
			Main.LocalPlayerWeapon.Template.AllowFeed = true;
			Main.LocalPlayerWeapon.Template.AllowSlide = true;
			Main.LocalPlayerWeapon.Template.DurabilityBurnRatio = 1f;
		}
	}

	public static void ChangeFireRate()
	{
		if (!(Main.LocalPlayer.HandsController.Item is Weapon) || !(Main.LocalPlayer.HandsController.Item is Weapon weapon))
		{
			return;
		}
		Main.LocalPlayerWeapon.Template.bFirerate = 2000;
		weapon.GetItemComponent<FireModeComponent>().FireMode = Weapon.EFireMode.fullauto;
		Main.LocalPlayer.GetComponent<Player.FirearmController>().Item.Template.BoltAction = false;
		if (Main.LocalPlayer.HandsController is Player.FirearmController firearmController)
		{
			WeaponTemplate weaponTemplate = firearmController.Item?.Template;
			if (weaponTemplate != null)
			{
				weaponTemplate.BoltAction = false;
				weaponTemplate.bFirerate = 2000;
			}
		}
	}

	public static void Fullbright()
	{
		if (Settings.fullbright)
		{
			if (!GameFullBright.LightCalled && GameFullBright.Enabled)
			{
				GameFullBright.LightGameObject = new GameObject("Fullbright");
				GameFullBright.FullBrightLight = GameFullBright.LightGameObject.AddComponent<Light>();
				GameFullBright.FullBrightLight.color = new Color(1f, 0.96f, 0.91f);
				GameFullBright.FullBrightLight.range = 2000f;
				GameFullBright.FullBrightLight.intensity = 0.6f;
				GameFullBright.LightCalled = true;
			}
			GameFullBright.Enabled = true;
			if (!(GameFullBright.FullBrightLight == null))
			{
				Main._tempPosition = Main.LocalPlayer.Transform.position;
				Main._tempPosition.y += 0.2f;
				GameFullBright.LightGameObject.transform.position = Main._tempPosition;
			}
		}
	}

	public static void RemoveFullbright()
	{
		if (GameFullBright.FullBrightLight != null)
		{
			UnityEngine.Object.Destroy(GameFullBright.FullBrightLight);
		}
		GameFullBright.LightCalled = false;
	}

	public static void Minecraftmode()
	{
		GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
		gameObject.transform.localScale = new Vector3(1f, 1f, 1f);
		Vector3 position = Main.LocalPlayer.gameObject.transform.position;
		Vector3 forward = Main.LocalPlayer.gameObject.transform.forward;
		float num = 3f;
		RaycastHit hitInfo;
		Vector3 position2 = ((!Physics.Raycast(new Ray(position, forward), out hitInfo, num)) ? (position + forward * num) : hitInfo.point);
		gameObject.transform.position = position2;
		Material material = Main.bundle.LoadAsset<Material>("minecraftmaterial");
		if (material != null)
		{
			gameObject.GetComponent<Renderer>().material = material;
		}
		AudioClip audioClip = Main.bundle.LoadAsset<AudioClip>("minecraftsound");
		if (audioClip != null)
		{
			AudioSource audioSource = gameObject.AddComponent<AudioSource>();
			audioSource.clip = audioClip;
			audioSource.Play();
		}
	}

	public static void Invisibletobots()
	{
	}

	public static void TestShelling(Vector3 shellingpos)
	{
		Main.audioSource.clip = Main.artillerycall;
		Main.audioSource.volume = 0.1f;
		Main.audioSource.Play();
		Main.GameWorld.ServerShellingController.StartShellingPosition(shellingpos);
		PlayArtilleryAnswerAsync();
	}

	private static async void PlayArtilleryAnswerAsync()
	{
		await Task.Delay(3000);
		Main.audioSource.clip = Main.artilleryaccept;
		Main.audioSource.volume = 0.1f;
		Main.audioSource.Play();
	}

	public static void AlwaysSurvive()
	{
		ConsoleScreen.Log("Hooking alwayssurvived...");
		Type type = Main.FindType("LocalGame");
		if (type != null)
		{
			MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			MethodInfo[] array = methods;
			for (int i = 0; i < array.Length; i++)
			{
				_ = array[i];
			}
			MethodInfo methodInfo = methods.FirstOrDefault((MethodInfo m) => m.Name == "Stop");
			if (methodInfo != null)
			{
				ConsoleScreen.Log("Stop method found successfully.");
				ConsoleScreen.Log($"Stop method details - Name: {methodInfo.Name}, ReturnType: {methodInfo.ReturnType}, IsPublic: {methodInfo.IsPublic}, IsPrivate: {methodInfo.IsPrivate}, IsProtected: {methodInfo.IsFamily}");
				try
				{
					Main.alwayssurvivedhook = new TestHook();
					Main.alwayssurvivedhook.Init(methodInfo, typeof(StatusManager).GetMethod("Stop_Hook"));
					Main.alwayssurvivedhook.Hook();
					ConsoleScreen.Log("alwayssurvived hook applied successfully.");
					Main.nothooked = false;
				}
				catch (Exception ex)
				{
					ConsoleScreen.Log("Error while hooking method: " + ex.Message);
				}
			}
		}
		else
		{
			ConsoleScreen.Log("Failed to find LocalGame type.");
		}
	}

	public static void RemoveFilters1()
	{
		ConsoleScreen.Log("Hooking CheckItemFilter...");
		Type type = Main.FindType("ItemFilter");
		if (type != null)
		{
			MethodInfo methodInfo = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == "CheckItemFilter");
			if (methodInfo != null)
			{
				ConsoleScreen.Log("CheckItemFilter method found successfully.");
				try
				{
					Main.checkItemFilterHook = new TestHook();
					Main.checkItemFilterHook.Init(methodInfo, typeof(StatusManager).GetMethod("CheckItemFilter_Hook"));
					Main.checkItemFilterHook.Hook();
					ConsoleScreen.Log("CheckItemFilter hook applied successfully.");
					Main.hookedCheckItemFilter = true;
					return;
				}
				catch (Exception ex)
				{
					ConsoleScreen.Log("Error while hooking CheckItemFilter method: " + ex.Message);
					return;
				}
			}
			ConsoleScreen.Log("CheckItemFilter method not found.");
		}
		else
		{
			ConsoleScreen.Log("Failed to find ItemFilter type.");
		}
	}

	public static void RemoveFilters2()
	{
		ConsoleScreen.Log("Hooking CheckItemExcludedFilter...");
		Type type = Main.FindType("ItemFilter");
		if (type != null)
		{
			MethodInfo methodInfo = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == "CheckItemExcludedFilter");
			if (methodInfo != null)
			{
				ConsoleScreen.Log("CheckItemExcludedFilter method found successfully.");
				try
				{
					Main.checkItemExcludedFilterHook = new TestHook();
					Main.checkItemExcludedFilterHook.Init(methodInfo, typeof(StatusManager).GetMethod("CheckItemExcludedFilter_Hook"));
					Main.checkItemExcludedFilterHook.Hook();
					ConsoleScreen.Log("CheckItemExcludedFilter hook applied successfully.");
					Main.hookedCheckItemExcludedFilter = true;
					return;
				}
				catch (Exception ex)
				{
					ConsoleScreen.Log("Error while hooking CheckItemExcludedFilter method: " + ex.Message);
					return;
				}
			}
			ConsoleScreen.Log("CheckItemExcludedFilter method not found.");
		}
		else
		{
			ConsoleScreen.Log("Failed to find ItemFilter type.");
		}
	}

	public static void CheckAndAddAmmoToChamber()
	{
		try
		{
			if (!(Main.LocalPlayer != null) || Main.LocalPlayerWeapon == null)
			{
				return;
			}
			Weapon localPlayerWeapon = Main.LocalPlayerWeapon;
			if (localPlayerWeapon.IsGrenadeLauncher)
			{
				HandleGrenadeAmmo(localPlayerWeapon);
				return;
			}
			_EF1A currentMagazine = localPlayerWeapon.GetCurrentMagazine();
			string ammoID = Main.ammoID;
			Item item = new ItemFactory().CreateItem(ammoID);
			if (item == null)
			{
				return;
			}
			if (currentMagazine != null && currentMagazine.Count < currentMagazine.MaxCount)
			{
				currentMagazine.Cartridges?.Add(item, simulate: false);
				return;
			}
			Slot[] chambers = localPlayerWeapon.Chambers;
			for (int i = 0; i < chambers.Length; i++)
			{
				chambers[i].Add(item, simulate: false);
			}
		}
		catch (Exception)
		{
		}
	}

	private static void HandleGrenadeAmmo(Weapon weapon)
	{
		try
		{
			ItemFactory itemFactory = new ItemFactory();
			IEnumerable<Slot> allSlots = weapon.AllSlots;
			if (allSlots == null || !allSlots.Any())
			{
				return;
			}
			string grenadeId = Main.ammoID;
			if (string.IsNullOrEmpty(grenadeId))
			{
				return;
			}
			foreach (Slot item2 in allSlots)
			{
				ItemFilter[] filters = item2.Filters;
				if (filters != null && filters.Length != 0 && filters.Any((ItemFilter filter) => filter != null && filter.Filter?.Contains(grenadeId) == true))
				{
					Item item = itemFactory.CreateItem(grenadeId);
					if (item != null)
					{
						item.SpawnedInSession = true;
						item2.AddWithoutRestrictions(item);
					}
				}
			}
		}
		catch (Exception)
		{
		}
	}

	public static void Teleport(string tpname)
	{
		try
		{
			tpname = tpname.ToLower();
			List<GameLootItem> list = new List<GameLootItem>();
			foreach (GameLootItem gameLootItem2 in ItemESP._gameLootItems)
			{
				ItemCategories itemcat = gameLootItem2.Itemcat;
				bool flag = false;
				if (itemcat == ItemCategories.Quest && Settings.questTP)
				{
					flag = true;
				}
				else if (itemcat == ItemCategories.Superrare && Settings.superrareTP)
				{
					flag = true;
				}
				else if (itemcat == ItemCategories.Kappa && Settings.kappaTP)
				{
					flag = true;
				}
				else if (itemcat == ItemCategories.Stim && Settings.StimTP)
				{
					flag = true;
				}
				else if (itemcat == ItemCategories.Wishlist && Settings.TPwishlistitem)
				{
					flag = true;
				}
				else if (itemcat == ItemCategories.Hideout && Settings.TPhideoutitem)
				{
					flag = true;
				}
				else if (gameLootItem2.itemprice > Settings.ESPPRICEfiltervalue && Settings.TPHVitem)
				{
					flag = true;
				}
				if ((gameLootItem2.LocalizedName.ToLower().Contains(tpname) || gameLootItem2.ShortName.ToLower().Contains(tpname)) && Settings.searchTP)
				{
					flag = true;
				}
				if (flag)
				{
					list.Add(gameLootItem2);
				}
			}
			if (Settings.questTP)
			{
				List<LootItem> list2 = Main.GameWorld.LootItems.Where((LootItem x) => x.Item.Template.QuestItem).ToList();
				foreach (LootItem item2 in list2)
				{
					GameLootItem item = new GameLootItem(item2);
					list.Add(item);
				}
				ConsoleScreen.Log($"[Teleport] Static spawned quest items found: {list2.Count}");
			}
			List<GameLootItem> list3 = list.OrderBy((GameLootItem gameLootItem2) => gameLootItem2.LocalizedName.ToLower()).ToList();
			int count = list3.Count;
			if (count > 0)
			{
				float num = 360f / (float)count;
				float loottpradius = Settings.loottpradius;
				Vector3 position = Main.LocalPlayer.gameObject.transform.position;
				position.y += 1f;
				for (int num2 = 0; num2 < count; num2++)
				{
					float f = (float)Math.PI / 180f * ((float)num2 * num);
					float num3 = Mathf.Cos(f) * loottpradius;
					float num4 = Mathf.Sin(f) * loottpradius;
					Vector3 position2 = new Vector3(position.x + num3, position.y, position.z + num4);
					GameLootItem gameLootItem = list3[num2];
					try
					{
						Rigidbody component = gameLootItem.LootItem.gameObject.GetComponent<Rigidbody>();
						if (component != null)
						{
							component.isKinematic = true;
						}
						gameLootItem.LootItem.gameObject.transform.position = position2;
						GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere);
						obj.GetComponent<SphereCollider>().enabled = false;
						obj.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
						obj.transform.position = position2;
						UnityEngine.Object.Destroy(obj, 1f);
					}
					catch (Exception ex)
					{
						ConsoleScreen.Log("[Teleport] Error teleporting item '" + gameLootItem.LocalizedName + "': " + ex.Message);
					}
				}
			}
			ConsoleScreen.Log("[Teleport] Teleportation complete.");
		}
		catch (Exception ex2)
		{
			ConsoleScreen.Log("[Teleport] Exception: " + ex2.Message);
		}
	}

	public static void BulletsPerShot(int bulletsPerShot)
	{
		if (Main.LocalPlayer.HandsController.Item is Weapon)
		{
			Main.LocalPlayerWeapon.CurrentAmmoTemplate.ProjectileCount = Settings.bulletspershot;
		}
	}

	public static void ExtendItemHitbox(GameLootItem item)
	{
		if (item?.LootItem?.gameObject != null)
		{
			GameObject obj = item.LootItem.gameObject;
			obj.transform.localScale *= 5f;
			Collider component = obj.GetComponent<Collider>();
			if (component != null)
			{
				component.transform.localScale *= 5f;
				component.enabled = false;
				component.enabled = true;
			}
		}
	}

	public static void HandleBigHeads()
	{
		if (Main.OnlineGamePlayers.Count > 0)
		{
			foreach (OnlineGamePlayer onlineGamePlayer in Main.OnlineGamePlayers)
			{
				if (onlineGamePlayer.role != OnlineGamePlayer.PlayerType.Teammate)
				{
					ObservedPlayerView player = onlineGamePlayer.Player;
					if (player != null && player.PlayerBones != null && player.PlayerBones.Head != null)
					{
						int instanceID = player.GetInstanceID();
						if (!isHeadScaled.ContainsKey(instanceID))
						{
							isHeadScaled[instanceID] = false;
							originalHeadScales[instanceID] = player.PlayerBones.Head.Original.localScale;
						}
						float num = 4f;
						if (Settings.BigHeads)
						{
							if (!isHeadScaled[instanceID])
							{
								Vector3 localScale = originalHeadScales[instanceID] * num;
								player.PlayerBones.Head.Original.localScale = localScale;
								isHeadScaled[instanceID] = true;
							}
						}
						else if (!Settings.BigHeads && isHeadScaled[instanceID])
						{
							player.PlayerBones.Head.Original.localScale = originalHeadScales[instanceID];
							isHeadScaled[instanceID] = false;
						}
					}
				}
			}
			return;
		}
		foreach (GamePlayer gamePlayer in Main.GamePlayers)
		{
			Player player2 = gamePlayer.Player;
			if (!(player2 != null) || !(player2.PlayerBones != null) || player2.PlayerBones.Head == null)
			{
				continue;
			}
			int instanceID2 = player2.GetInstanceID();
			if (!isHeadScaled.ContainsKey(instanceID2))
			{
				isHeadScaled[instanceID2] = false;
				originalHeadScales[instanceID2] = player2.PlayerBones.Head.Original.localScale;
			}
			if (Settings.BigHeads)
			{
				if (!isHeadScaled[instanceID2])
				{
					Vector3 localScale2 = originalHeadScales[instanceID2] * 4f;
					player2.PlayerBones.Head.Original.localScale = localScale2;
					isHeadScaled[instanceID2] = true;
				}
			}
			else if (!Settings.BigHeads && isHeadScaled[instanceID2])
			{
				player2.PlayerBones.Head.Original.localScale = originalHeadScales[instanceID2];
				isHeadScaled[instanceID2] = false;
			}
		}
	}

	public static void FPSExploit()
	{
		if (!isPlayHooked)
		{
			MethodInfo method = typeof(Player).GetMethod("PlayTripwireInteractionSound", BindingFlags.Instance | BindingFlags.Public);
			MethodInfo method2 = typeof(TripwireHooks).GetMethod("PlayTripwireInteractionSound_Hook", BindingFlags.Static | BindingFlags.Public);
			PlayTripwireInteractionHook = new TestHook();
			PlayTripwireInteractionHook.Init(method, method2);
			PlayTripwireInteractionHook.Hook();
			isPlayHooked = true;
		}
		ClientPlayer clientPlayer = (ClientPlayer)Main.LocalPlayer;
		clientPlayer.PlayTripwireInteractionSound(10f, hasMultiTool: false);
		MethodInfo method3 = typeof(ClientPlayer).GetMethod("SendTripwireInteractionSoundState", BindingFlags.Instance | BindingFlags.NonPublic);
		if (method3 != null)
		{
			try
			{
				EInteractionStatus eInteractionStatus = EInteractionStatus.Started;
				bool flag = false;
				bool flag2 = false;
				method3.Invoke(clientPlayer, new object[3] { eInteractionStatus, flag, flag2 });
				ConsoleScreen.Log("Called SendTripwireInteractionSoundState with parameters: " + $"interactionStatus={eInteractionStatus}, isSuccess={flag}, hasMultiTool={flag2}.");
				return;
			}
			catch (Exception arg)
			{
				ConsoleScreen.Log($"Error with sending tripwire interaction : \n {arg}");
				return;
			}
		}
		ConsoleScreen.Log("Failed to locate SendTripwireInteractionSoundState method.");
	}

	public static void PreventTripwireSoundExploit()
	{
		if (!isantifpshooked)
		{
			AntiFPSDropHook = new TestHook();
			AntiFPSDropHook.Init(typeof(ObservedPlayerAudioController).GetMethod("method_14", BindingFlags.Instance | BindingFlags.NonPublic), typeof(TripwireHooks).GetMethod("AntiTripWire_Hook"));
			AntiFPSDropHook.Hook();
			isantifpshooked = true;
			ConsoleScreen.Log("hooked sound protection");
		}
	}

	public static void changeskybox()
	{
		cachedskyboxmaterial = Main.levelSettings.skybox;
		Material skybox = Main.bundle.LoadAsset<Material>("skyboxmaterial.mat");
		if (cachedskyboxmaterial != null)
		{
			Main.levelSettings.skybox = skybox;
		}
	}
}
