using System;
using EFT;
using EFT.InventoryLogic;
using stupid.solutions.Data;
using stupid.solutions.HenryBot;
using stupid.solutions.stupid.solutions.Data;
using stupid.solutions.Utils;
using UnityEngine;

namespace stupid.solutions.Features;

public class HookObject
{
	public object SilentAimHook(object ammo, Vector3 origin, Vector3 direction, int fireIndex, Player player, Item weapon, float speedFactor = 1f, int fragmentIndex = 0)
	{
		try
		{
			if (Main.LocalPlayer?.HandsController.Item is Weapon && Settings.SilentAim && Input.GetMouseButton(0))
			{
				GamePlayer target = Aimbot.Target;
				OnlineGamePlayer oTarget = Aimbot.OTarget;
				if ((target != null || oTarget != null) && Main.LocalPlayer != null)
				{
					Vector3 zero = Vector3.zero;
					if (Main.OnlineGamePlayers.Count > 0)
					{
						WildSpawnType wildSpawnType = WildSpawnType.pmcUSEC;
						zero = ((wildSpawnType == WildSpawnType.infectedAssault || wildSpawnType == WildSpawnType.infectedCivil || wildSpawnType == WildSpawnType.infectedLaborant || wildSpawnType == WildSpawnType.infectedPmc) ? (GameUtils.FinalVectorO(oTarget.Player, Aimbot.zombiebone) + new Vector3(0f, 0.072f, 0f)) : (GameUtils.FinalVectorO(oTarget.Player, Settings.Aimbone) + new Vector3(0f, 0.072f, 0f)));
						if (Main.LocalPlayer.WeaponRoot != null)
						{
							direction = (zero - origin).normalized;
							origin = Main.LocalPlayer.Fireport.position;
						}
					}
					else
					{
						WildSpawnType role = target.Player.Profile.Info.Settings.Role;
						zero = ((role == WildSpawnType.infectedAssault || role == WildSpawnType.infectedCivil || role == WildSpawnType.infectedLaborant || role == WildSpawnType.infectedPmc) ? (GameUtils.FinalVector(target.Player, Aimbot.zombiebone) + new Vector3(0f, 0.072f, 0f)) : (GameUtils.FinalVector(target.Player, Settings.Aimbone) + new Vector3(0f, 0.072f, 0f)));
						if (Main.LocalPlayer.WeaponRoot != null)
						{
							direction = (zero - origin).normalized;
							origin = Main.LocalPlayer.Fireport.position;
						}
					}
				}
			}
			else if (Main.LocalPlayer?.HandsController.Item is Weapon && Settings.henryison)
			{
				GamePlayer currentTarget = HenryBotBrain.currentTarget;
				if (currentTarget != null && Main.LocalPlayer != null)
				{
					Vector3 zero2 = Vector3.zero;
					WildSpawnType role2 = currentTarget.Player.Profile.Info.Settings.Role;
					zero2 = ((role2 == WildSpawnType.infectedAssault || role2 == WildSpawnType.infectedCivil || role2 == WildSpawnType.infectedLaborant || role2 == WildSpawnType.infectedPmc) ? (GameUtils.FinalVector(currentTarget.Player, Aimbot.zombiebone) + new Vector3(0f, 0.072f, 0f)) : (GameUtils.FinalVector(currentTarget.Player, Settings.Aimbone) + new Vector3(0f, 0.072f, 0f)));
					if (Main.LocalPlayer.WeaponRoot != null)
					{
						direction = (zero2 - origin).normalized;
						origin = Main.LocalPlayer.Fireport.position;
					}
				}
			}
			Aimbot.CreateShotHook.Unhook();
			object[] parameters = new object[8] { ammo, origin, direction, fireIndex, player, weapon, speedFactor, fragmentIndex };
			object result = Aimbot.CreateShotHook.OriginalMethod.Invoke(this, parameters);
			Aimbot.CreateShotHook.Hook();
			return result;
		}
		catch (Exception)
		{
			throw;
		}
	}
}
