using System;
using EFT;
using EFT.UI;
using stupid.solutions.Data;
using stupid.solutions.stupid.solutions.Data;
using stupid.solutions.Utils;
using UnityEngine;

namespace stupid.solutions.Features;

public class BulletMovement
{
	public bool MagicBullet_Hook(Vector3 prevPosition, Vector3 nextPosition)
	{
		Aimbot.BulletMovementHook.Unhook();
		bool result = false;
		try
		{
			if (Settings.MagicBullet && Input.GetMouseButton(0))
			{
				GamePlayer target = Aimbot.Target;
				OnlineGamePlayer oTarget = Aimbot.OTarget;
				if (target != null)
				{
					Vector3 zero = Vector3.zero;
					WildSpawnType role = target.Player.Profile.Info.Settings.Role;
					zero = ((role == WildSpawnType.infectedAssault || role == WildSpawnType.infectedCivil || role == WildSpawnType.infectedLaborant || role == WildSpawnType.infectedPmc) ? GameUtils.GetBonePosByID(target.Player, Aimbot.zombiebone) : GameUtils.GetBonePosByID(target.Player, Settings.Aimbone));
					Vector3 normalized = (Main.LocalPlayer.Fireport.position - zero).normalized;
					prevPosition = zero + normalized * 0.1f;
					nextPosition = zero;
				}
				else if (oTarget != null)
				{
					Vector3 zero2 = Vector3.zero;
					WildSpawnType wildSpawnType = WildSpawnType.pmcUSEC;
					zero2 = ((wildSpawnType == WildSpawnType.infectedAssault || wildSpawnType == WildSpawnType.infectedCivil || wildSpawnType == WildSpawnType.infectedLaborant || wildSpawnType == WildSpawnType.infectedPmc) ? GameUtils.GetBonePosByIDO(oTarget.Player, Aimbot.zombiebone) : GameUtils.GetBonePosByIDO(oTarget.Player, Settings.Aimbone));
					Vector3 normalized2 = (Main.LocalPlayer.Fireport.position - zero2).normalized;
					prevPosition = zero2 + normalized2 * 0.1f;
					nextPosition = zero2;
				}
			}
			result = (bool)Aimbot.BulletMovementHook.OriginalMethod.Invoke(this, new object[2] { prevPosition, nextPosition });
		}
		catch (Exception ex)
		{
			ConsoleScreen.Log("Exception in hook method:");
			ConsoleScreen.Log($"Exception Type: {ex.GetType()}");
			ConsoleScreen.Log("Exception Message: " + ex.Message);
			ConsoleScreen.Log("Stack Trace: " + ex.StackTrace);
		}
		finally
		{
			Aimbot.BulletMovementHook.Hook();
		}
		return result;
	}
}
