96 lines
3.5 KiB
C#
Raw Normal View History

2022-09-08 21:29:16 +02:00
using BepInEx;
using BepInEx.Configuration;
using EFT;
using UnityEngine;
using Comfort.Common;
2022-09-11 18:48:53 +02:00
using System.Collections;
using System.Reflection;
2022-09-08 21:29:16 +02:00
namespace CameraResolutionScale
2022-09-08 21:29:16 +02:00
{
[BepInPlugin("com.notGreg.cameraScaleControl", "notGreg's Camera Resolution Settings", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
ConfigEntry<int> cameraResolutionScale;
ConfigEntry<int> scopeCameraResolutionScale;
void Awake()
{
cameraResolutionScale = Config.Bind("General", "Main camera scale %", 80, new ConfigDescription("Main camera resulution sclae", new AcceptableValueRange<int>(50, 100)));
scopeCameraResolutionScale = Config.Bind("General", "Scope camera scale %", 40, new ConfigDescription("Scope camera resulution scale", new AcceptableValueRange<int>(25, 100)));
2022-09-08 21:29:16 +02:00
}
float defaultSSRatio = 1.0f;
Camera FPSCamera = null;
2022-09-08 21:29:16 +02:00
Camera scopeCamera = null;
bool isAiming = false;
2022-09-11 18:48:53 +02:00
bool doneOnce = false;
2022-09-08 21:29:16 +02:00
SSAA ssaaInstance = null;
FieldInfo _currentSSRatio = null;
FieldInfo _nextSSRation = null;
2022-09-08 21:29:16 +02:00
Utils utils = new Utils();
2022-09-08 21:29:16 +02:00
void Update()
{
if (!utils.gameIsReady())
2022-09-08 21:29:16 +02:00
{
//reset everything ahead of time
FPSCamera = null;
scopeCamera = null;
doneOnce = false;
ssaaInstance = null;
2022-09-08 21:29:16 +02:00
return;
}
if (Camera.allCamerasCount < 1) return;
if (GameObject.Find("FPS Camera") != null && FPSCamera == null)
{
FPSCamera = GameObject.Find("FPS Camera").GetComponent<Camera>();
}
if (GameObject.Find("BaseOpticCamera(Clone)") != null && scopeCamera == null)
{
scopeCamera = GameObject.Find("BaseOpticCamera(Clone)").GetComponent<Camera>();
}
2022-09-08 21:29:16 +02:00
var handsController = ((Singleton<GameWorld>.Instance.RegisteredPlayers[0].HandsController));
isAiming = handsController.IsAiming;
if(ssaaInstance == null)
{
ssaaInstance = FPSCamera.GetComponent<SSAA>();
_nextSSRation = typeof(SSAA).GetField("_nextSSRation", BindingFlags.NonPublic | BindingFlags.Instance);
_currentSSRatio = typeof(SSAA).GetField("_currentSSRatio", BindingFlags.NonPublic | BindingFlags.Instance);
Logger.LogInfo($"Updating defaultSSRatio to {_nextSSRation.GetValue(ssaaInstance)}");
defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance);
}
2022-09-11 18:48:53 +02:00
if (isAiming && !doneOnce)
2022-09-08 21:29:16 +02:00
{
if (FPSCamera == null) return;
if (scopeCamera == null || scopeCamera.isActiveAndEnabled == false) return;
_nextSSRation.SetValue(ssaaInstance, (float)(defaultSSRatio * cameraResolutionScale.Value / 100f));
Logger.LogInfo($"Updated to: {_nextSSRation.GetValue(ssaaInstance)}");
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(scopeCameraResolutionScale.Value / 100f);
2022-09-11 18:48:53 +02:00
doneOnce = true;
2022-09-08 21:29:16 +02:00
return;
}
if (!isAiming && doneOnce)
2022-09-08 21:29:16 +02:00
{
Logger.LogInfo($"Restoring default scale: {defaultSSRatio}");
_nextSSRation.SetValue(ssaaInstance, defaultSSRatio);
2022-09-11 18:48:53 +02:00
doneOnce = false;
return;
2022-09-08 21:29:16 +02:00
}
}
}
}