using BepInEx; using System; using UnityEngine; namespace UniformAim { public class Core { //math stuff //Get screen aspect ratio public static float GetAspectRatio() { return Camera.allCameras[0].aspect; } //Calculate horizontal FOV based on vertical FOV and aspect ratio public static float CalculateHFOV(float FOV) { float vFOVRad = FOV / 2 * Mathf.Deg2Rad; float hFOVRad = (float)(2 * Math.Atan(GetAspectRatio() * Math.Tan(vFOVRad))); return (float)(hFOVRad * Mathf.Rad2Deg); } //calculate sensitivity based on FOV delta and coefficient public static 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 static float DetermineCurrentFOV() { //dirty fix for the Ultima MP-155 shotgun if (Plugin.currentFPSCameraFOV> 35 && isScopeCameraActive() && Plugin.currentScopeCameraFOV == 15) { return Plugin.currentFPSCameraFOV; } if (Plugin.SelectedScope == 0 && isScopeCameraActive()) { return Plugin.currentScopeCameraFOV; } else { return Plugin.currentFPSCameraFOV; } } } }