using BepInEx; using BepInEx.Configuration; using EFT; using UnityEngine; using Comfort.Common; using System.Reflection; using System; using System.ComponentModel; using EFT.UI; namespace CameraResolutionScale { [BepInPlugin("com.notGreg.cameraScaleControl", "notGreg's Camera Resolution Settings", "1.0.0")] public class Plugin : BaseUnityPlugin { ConfigEntry cameraResolutionScale; ConfigEntry scopeCameraResolutionScale; ConfigEntry disableFOVScaling; GameObject rootObject; string rootObjectPath = "Common UI/Common UI/SettingScreen"; GameObject fovObject; string fovObjectPath = "Game Settings/Image/Other Settings/FOV/FOV"; int defaultFOVValue = 50; SelectSlider fovSliderValue; enum fovScalingMode { Disabled, [Description("Only magnified optics")] ScopeOnly, Enabled } public event EventHandler SettingChanged; void Awake() { cameraResolutionScale = Config.Bind("General", "Main camera scale %", 80, new ConfigDescription("Main camera resulution sclae", new AcceptableValueRange(50, 100))); scopeCameraResolutionScale = Config.Bind("General", "Scope camera scale %", 40, new ConfigDescription("Scope camera resulution scale", new AcceptableValueRange(25, 100))); disableFOVScaling = Config.Bind("Experimental", "Disable ADS FOV scaling", fovScalingMode.Disabled); cameraResolutionScale.SettingChanged += (s, args) => { updateSSRatio(); }; scopeCameraResolutionScale.SettingChanged += (s, args) => { updateSSRatio(); }; Logger.LogInfo("Setting up game settings references"); rootObject = GameObject.Find(rootObjectPath); fovObject = rootObject.transform.Find(fovObjectPath).gameObject; fovSliderValue = fovObject.GetComponent(); defaultFOVValue = fovSliderValue.CurrentValue(); Logger.LogInfo($"Default camera FOV: {defaultFOVValue}"); } void updateSSRatio() { if (!isAiming && FPSCamera != null) { defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance); Logger.LogInfo($"Updating defaultSSRatio to {defaultSSRatio}"); } } float defaultSSRatio = 1.0f; Camera FPSCamera = null; Camera scopeCamera = null; bool isAiming = false; bool doneOnce = false; SSAA ssaaInstance = null; FieldInfo _currentSSRatio = null; FieldInfo _nextSSRation = null; Utils utils = new Utils(); void Update() { if (!utils.gameIsReady()) { //Logger.LogInfo("Resetting..."); doneOnce = false; FPSCamera = null; ssaaInstance = null; scopeCamera = null; return; } if (Camera.main == null) return; //Logger.LogInfo("Check FPS camera"); if (GameObject.Find("FPS Camera") != null && FPSCamera == null) { //Logger.LogInfo("Assigning FPS Camera"); FPSCamera = GameObject.Find("FPS Camera").GetComponent(); } //Logger.LogInfo("Check Scope camera"); if (GameObject.Find("BaseOpticCamera(Clone)") != null && scopeCamera == null) { //Logger.LogInfo("Assigning Scope Camera"); scopeCamera = GameObject.Find("BaseOpticCamera(Clone)").GetComponent(); } var handsController = ((Singleton.Instance.RegisteredPlayers[0].HandsController)); isAiming = handsController.IsAiming; //Logger.LogInfo("Checking ssaaInstance"); if(ssaaInstance == null) { ssaaInstance = FPSCamera.GetComponent(); //figure out a way to update it if resolution or reso scale changes _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); } //Logger.LogInfo("Checking if isAiming"); if (isAiming && !doneOnce) { if (FPSCamera == null) return; if (scopeCamera == null || scopeCamera.isActiveAndEnabled == false) return; Logger.LogInfo("Updating settings FOV to 50"); fovSliderValue.UpdateValue(50); _nextSSRation.SetValue(ssaaInstance, (float)(defaultSSRatio * cameraResolutionScale.Value / 100f)); Logger.LogInfo($"Updated to: {_nextSSRation.GetValue(ssaaInstance)}"); scopeCamera.GetComponent().OpticCameraToMainCameraResolutionRatio = (float)(scopeCameraResolutionScale.Value / 100f); doneOnce = true; return; } //Logger.LogInfo("Checking if not isAiming"); if (!isAiming && doneOnce) { Logger.LogInfo($"Restoring default hipfire FOV: {defaultFOVValue}"); fovSliderValue.UpdateValue(defaultFOVValue); Logger.LogInfo($"Restoring default scale: {defaultSSRatio}"); _nextSSRation.SetValue(ssaaInstance, defaultSSRatio); doneOnce = false; return; } } } }