using BepInEx; using BepInEx.Configuration; using System; using UnityEngine; namespace UniformAim { public class Core { //math stuff public float CalculateHFOV(float FOV) { //RETURNS RADIANS return Camera.VerticalToHorizontalFieldOfView(FOV, Camera.main.aspect); } //calculate sensitivity based on FOV delta and coefficient public float CalculateSensitivity(float aimedFOV, float hipFOV) { //calculate horizontal FOV values for inputs aimedFOV = CalculateHFOV(aimedFOV) * Mathf.Deg2Rad; hipFOV = CalculateHFOV(hipFOV) * Mathf.Deg2Rad; float exponent = (float)(100f / Plugin.configCoeff.Value); float tanRatio = (float)(Math.Tan(aimedFOV / 2) / (Math.Tan(hipFOV / 2))); float sensitivity = Plugin.configSens.Value / 100f; float result = (float)Math.Pow(tanRatio, exponent) * sensitivity; return result; } //check if BaseOpticCamera is present and active public static bool isScopeCameraActive() { if(Camera.allCamerasCount > 1) { return Camera.allCameras[1].GetComponent().isActiveAndEnabled; } return false; } //figure out current fov based on scope and in-game camera statuses public float DetermineCurrentFOV(float FPSCameraFOV, float ScopeCameraFOV, int SelectedScope, int SelectedScopeMode = 0) { //dirty fix for the Ultima MP-155 shotgun try { if(GameObject.Find("tactical_mp155_kalashnikov_ultima_camera(Clone)").GetComponent().isActiveAndEnabled) { if (Plugin.currentFPSCameraFOV > (Plugin.configFOV.Value - 15) && isScopeCameraActive() && Plugin.currentScopeCameraFOV == 15) { return Plugin.currentFPSCameraFOV; } } } catch (NullReferenceException) { return Plugin.currentFPSCameraFOV; } //if (Plugin.currentFPSCameraFOV > (Plugin.configFOV.Value - 15) && isScopeCameraActive() && Plugin.currentScopeCameraFOV == 15) { return Plugin.currentFPSCameraFOV; } //dirty fix for Leupold D-EVO mod try { if(GameObject.Find("scope_leupold_d_evo(Clone)").GetComponent().isActiveAndEnabled) { switch (Plugin.SelectedScope) { case 0: return Plugin.currentFPSCameraFOV; case 1: return Plugin.currentScopeCameraFOV; } } } catch(NullReferenceException) { return Plugin.currentFPSCameraFOV; } try { if(Camera.main.isActiveAndEnabled && Plugin.SelectedScope == 0 && isScopeCameraActive()) { return Plugin.currentScopeCameraFOV; } else { return Plugin.currentFPSCameraFOV; } } catch (NullReferenceException) { return Plugin.configFOV.Value; } // if (Plugin.SelectedScope == 0 && isScopeCameraActive()) { return Plugin.currentScopeCameraFOV; } else { return Plugin.currentFPSCameraFOV; } } } }