using BepInEx; using BepInEx.Configuration; using EFT; using UnityEngine; using Comfort.Common; using System.Reflection; using System.Collections; namespace CameraResolutionScale { [BepInPlugin("com.notGreg.cameraScaleControl", "notGreg's Camera Resolution Settings", "1.0.0")] public class Plugin : BaseUnityPlugin { Utils utils = new Utils(); DisableFOVScaling fovScaling = new DisableFOVScaling(); UpdateScopeResolution scopeRes = new UpdateScopeResolution(); ConfigEntry cameraResolutionScale; ConfigEntry scopeCameraResolutionScale; ConfigEntry fovCompDistScale; enum fovScalingMode { Disabled, Enabled } void Awake() { cameraResolutionScale = Config.Bind( "General", "Main camera scale %", 80, new ConfigDescription("Main camera resolution scale", new AcceptableValueRange(50, 100))); scopeCameraResolutionScale = Config.Bind( "General", "Scope camera scale %", 40, new ConfigDescription("Scope camera resolution scale", new AcceptableValueRange(25, 100))); fovCompDistScale = Config.Bind( "Experimental", "FOV Compensation Dist. Scale", 0, new ConfigDescription("Adjusts _fovCompensatoryDistance variable, makes scopes more useable at high FOV values", new AcceptableValueRange(0, 100))); } float defaultSSRatio = 1.0f; Camera FPSCamera = null; Camera scopeCamera = null; SSAA ssaaInstance = null; FieldInfo _currentSSRatio = null; FieldInfo _nextSSRation = null; int defaultFOVValue = 50; void setUpCameras() { Logger.LogInfo("Game started!"); Logger.LogInfo("Get FPS Camera"); StartCoroutine(tryGetMainCamera()); Logger.LogInfo("Get Scope Camera"); StartCoroutine(tryGetScopeCamera()); } WaitForSeconds myDelaySec = new WaitForSeconds(1); IEnumerator tryGetMainCamera() { if (scopeRes.getMainCamera() == null) { yield return myDelaySec; StartCoroutine(tryGetMainCamera()); yield break; } FPSCamera = scopeRes.getMainCamera(); Logger.LogInfo("Get SSAAInstance (Camera)"); ssaaInstance = scopeRes.getSSAAInstance(FPSCamera); Logger.LogInfo("Set SSRatios"); _nextSSRation = scopeRes.getFieldInfo("_nextSSRation"); _currentSSRatio = scopeRes.getFieldInfo("_currentSSRatio"); Logger.LogInfo($"Updating defaultSSRatio to {_nextSSRation.GetValue(ssaaInstance)}"); defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance); } IEnumerator tryGetScopeCamera() { if (scopeRes.getScopeCamera() == null) { Logger.LogInfo("ScopeCamera not found! Restarting..."); yield return myDelaySec; StartCoroutine(tryGetScopeCamera()); yield break; } Logger.LogInfo("Assigning scopeCamera"); scopeCamera = scopeRes.getScopeCamera(); } void subscribeToOnAimingChanged() { Logger.LogInfo($"subscribeToOnAimingChanged: player = {mainPlayer}"); mainPlayer.HandsController.OnAimingChanged += (args) => { Logger.LogInfo("Changing fovCompDist"); mainPlayer.ProceduralWeaponAnimation._fovCompensatoryDistance = -0.03f * fovCompDistScale.Value / 100f; if (mainPlayer.HandsController.IsAiming) { Logger.LogInfo("Updating camera resolutions"); _nextSSRation.SetValue(ssaaInstance, (float)(defaultSSRatio * cameraResolutionScale.Value / 100f)); if (scopeCamera != null && scopeCamera.isActiveAndEnabled) { scopeCamera.GetComponent().OpticCameraToMainCameraResolutionRatio = (float)(scopeCameraResolutionScale.Value / 100f); } return; } if (!mainPlayer.HandsController.IsAiming) { Logger.LogInfo("Restoring camera resolutions"); _nextSSRation.SetValue(ssaaInstance, (float)(defaultSSRatio)); return; } }; } GameStatus lastGameState = GameStatus.Stopped; bool gameStateChanged(GameStatus currentState) { if (lastGameState != currentState) { lastGameState = currentState; Logger.LogInfo($"GameState changed! {currentState}"); return true; } //Logger.LogInfo("GameState unchanged."); return false; } Player mainPlayer = null; void Update() { if (Singleton.Instance == null) return; GameStatus currentGameState = Singleton.Instance.Status; if (currentGameState == GameStatus.Started && mainPlayer != null) { if (mainPlayer.HandsController.IsAiming) { mainPlayer.ProceduralWeaponAnimation._fovCompensatoryDistance = -0.03f * fovCompDistScale.Value / 100f; } } if (!gameStateChanged(currentGameState)) return; if ((currentGameState == GameStatus.SoftStopping || currentGameState == GameStatus.Stopped)) { Logger.LogInfo("Game is stopping, resetting stuffs for the next raid"); mainPlayer = null; return; } if (currentGameState == GameStatus.Started) { Logger.LogInfo("Getting local player"); mainPlayer = utils.getLocalPlayer(); Logger.LogInfo($"Returned: {mainPlayer.GetType()}"); Logger.LogInfo("Updating default FOV value"); if (defaultFOVValue != Camera.main.fieldOfView) { defaultFOVValue = (int)Camera.main.fieldOfView; } Logger.LogInfo("setUpCameras()"); setUpCameras(); Logger.LogInfo("UpdateSSRatio()"); defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance); Logger.LogInfo($"Updating defaultSSRatio to {defaultSSRatio}"); //updateSSRatio(); Logger.LogInfo("subscibeToOnAimingChanged()"); subscribeToOnAimingChanged(); return; } } //void updateSSRatio() //{ // if (!isAiming && FPSCamera != null) // { // defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance); // Logger.LogInfo($"Updating defaultSSRatio to {defaultSSRatio}"); // } //} } }