70 lines
2.4 KiB
C#
70 lines
2.4 KiB
C#
using BepInEx;
|
|
using BepInEx.Configuration;
|
|
using System;
|
|
using UnityEngine;
|
|
|
|
namespace UniformAim
|
|
{
|
|
internal class Core
|
|
{
|
|
//math stuff
|
|
internal float CalculateHFOV(float FOV)
|
|
{
|
|
//RETURNS RADIANS
|
|
return Camera.VerticalToHorizontalFieldOfView(FOV, Camera.main.aspect);
|
|
}
|
|
|
|
//calculate sensitivity based on FOV delta and coefficient
|
|
internal 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
|
|
static bool isScopeCameraActive()
|
|
{
|
|
if(Camera.allCamerasCount > 1) { return Camera.allCameras[1].GetComponent<Behaviour>().isActiveAndEnabled; }
|
|
return false;
|
|
}
|
|
|
|
//figure out current fov based on scope and in-game camera statuses
|
|
internal float DetermineCurrentFOV(float FPSCameraFOV = 60f, float ScopeCameraFOV = 28f, int SelectedScope = 0, int SelectedScopeMode = 0)
|
|
{
|
|
var leupold = SightPatches.customOpticPatches["scope_leupold_d_evo(Clone)"];
|
|
var ultima = SightPatches.customOpticPatches["tactical_mp155_kalashnikov_ultima_camera(Clone)"];
|
|
|
|
if (leupold != null && leupold.activeInHierarchy)
|
|
{
|
|
switch (Plugin.SelectedScope)
|
|
{
|
|
case 0: return Plugin.currentFPSCameraFOV;
|
|
case 1: return Plugin.currentScopeCameraFOV;
|
|
}
|
|
}
|
|
|
|
if (ultima != null && ultima.activeInHierarchy && isScopeCameraActive() && Plugin.currentScopeCameraFOV == 15)
|
|
{
|
|
return Plugin.currentFPSCameraFOV;
|
|
}
|
|
|
|
if (Plugin.SelectedScope == 0 && isScopeCameraActive())
|
|
{
|
|
return Plugin.currentScopeCameraFOV;
|
|
}
|
|
return Plugin.currentFPSCameraFOV;
|
|
}
|
|
}
|
|
}
|