2022-08-28 08:19:09 +02:00
|
|
|
|
using BepInEx;
|
|
|
|
|
using BepInEx.Configuration;
|
|
|
|
|
using System;
|
2022-08-04 18:13:18 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace UniformAim
|
|
|
|
|
{
|
|
|
|
|
public class Core
|
|
|
|
|
{
|
|
|
|
|
//math stuff
|
2022-08-28 08:19:09 +02:00
|
|
|
|
public float CalculateHFOV(float FOV)
|
2022-08-04 18:13:18 +02:00
|
|
|
|
{
|
2022-08-05 21:58:10 +02:00
|
|
|
|
//RETURNS RADIANS
|
2022-08-16 13:31:25 +02:00
|
|
|
|
return Camera.VerticalToHorizontalFieldOfView(FOV, Camera.main.aspect);
|
2022-08-04 18:13:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//calculate sensitivity based on FOV delta and coefficient
|
2022-08-28 08:19:09 +02:00
|
|
|
|
public float CalculateSensitivity(float aimedFOV, float hipFOV)
|
2022-08-04 18:13:18 +02:00
|
|
|
|
{
|
|
|
|
|
//calculate horizontal FOV values for inputs
|
2022-08-16 13:31:25 +02:00
|
|
|
|
aimedFOV = CalculateHFOV(aimedFOV) * Mathf.Deg2Rad;
|
|
|
|
|
hipFOV = CalculateHFOV(hipFOV) * Mathf.Deg2Rad;
|
2022-08-04 18:13:18 +02:00
|
|
|
|
|
|
|
|
|
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<Behaviour>().isActiveAndEnabled; }
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
//figure out current fov based on scope and in-game camera statuses
|
2022-08-28 08:19:09 +02:00
|
|
|
|
public float DetermineCurrentFOV(float FPSCameraFOV, float ScopeCameraFOV, int SelectedScope, int SelectedScopeMode = 0)
|
2022-08-04 18:13:18 +02:00
|
|
|
|
{
|
|
|
|
|
//dirty fix for the Ultima MP-155 shotgun
|
2022-08-28 08:19:09 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(GameObject.Find("tactical_mp155_kalashnikov_ultima_camera(Clone)").GetComponent<Behaviour>().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; }
|
2022-08-04 18:13:18 +02:00
|
|
|
|
|
2022-08-28 08:19:09 +02:00
|
|
|
|
//dirty fix for Leupold D-EVO mod
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(GameObject.Find("scope_leupold_d_evo(Clone)").GetComponent<Behaviour>().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; }
|
2022-08-04 18:13:18 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|