Expanded ScalingMode to ScopesOnly and AllSights

This commit is contained in:
notGreg 2022-09-20 22:43:40 +02:00
parent 804e4643f4
commit 9fe689ef13

View File

@ -6,6 +6,7 @@ using Comfort.Common;
using System.Reflection;
using System.Collections;
using EFT.Settings.Graphics;
using System.ComponentModel;
namespace ScopeTweaks
{
@ -19,7 +20,10 @@ namespace ScopeTweaks
enum EFOVScalingMode
{
Disabled,
Enabled,
[Description("Magnified optics")]
ScopesOnly,
[Description("All sights")]
All,
}
void Awake()
@ -36,7 +40,7 @@ namespace ScopeTweaks
80,
new ConfigDescription("Scope camera resolution scale", new AcceptableValueRange<int>(25, 100)));
scopeFixType = Config.Bind("General", "High FOV scope tweak", EFOVScalingMode.Enabled, new ConfigDescription(""));
scopeFixType = Config.Bind("General", "High FOV sight tweak", EFOVScalingMode.ScopesOnly, new ConfigDescription(""));
}
Camera FPSCamera = null;
@ -57,12 +61,12 @@ namespace ScopeTweaks
{
case GameStatus.Started:
{
//Logger.LogInfo("Getting local player");
Logger.LogInfo("Getting local player");
mainPlayer = getLocalPlayer();
subscribeHandsChangedEvent();
//Logger.LogInfo("Assigning cameras...");
Logger.LogInfo("Assigning cameras...");
StartCoroutine(tryGetMainCamera());
StartCoroutine(tryGetScopeCamera());
@ -71,7 +75,7 @@ namespace ScopeTweaks
case GameStatus.SoftStopping:
case GameStatus.Stopped:
{
//Logger.LogInfo("Resetting...");
Logger.LogInfo("Resetting...");
FPSCamera = null;
scopeCamera = null;
mainPlayer = null;
@ -107,13 +111,13 @@ namespace ScopeTweaks
int getInGameFOV()
{
int fov = Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value;
//Logger.LogInfo($"In-game FOV: {fov}");
Logger.LogInfo($"In-game FOV: {fov}");
return fov;
}
void setInGameFOV(int value)
{
//Logger.LogInfo($"Setting FOV to {value}");
Logger.LogInfo($"setInGameFOV(): Update to {value}");
Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value = value;
}
@ -127,11 +131,11 @@ namespace ScopeTweaks
if (GameObject.Find(cameraName) != null)
{
FPSCamera = GameObject.Find(cameraName).GetComponent<Camera>();
//Logger.LogInfo($"{FPSCamera.name} found!");
Logger.LogInfo($"{FPSCamera.name} found!");
}
else
{
//Logger.LogMessage($"Camera \"{cameraName}\" not found, rescheduling...");
Logger.LogMessage($"Camera \"{cameraName}\" not found, rescheduling...");
yield return myDelaySec;
StartCoroutine(tryGetMainCamera());
yield break;
@ -150,14 +154,14 @@ namespace ScopeTweaks
if (GameObject.Find(cameraName) != null)
{
scopeCamera = GameObject.Find(cameraName).GetComponent<Camera>();
//Logger.LogInfo($"Camera \"{scopeCamera.name}\" found!");
Logger.LogInfo($"Camera \"{scopeCamera.name}\" found!");
}
yield break;
}
void setMainCameraResolutionScale(int value = 100)
{
//Logger.LogInfo($"Setting MainCam res scale to {value}%");
Logger.LogInfo($"Setting MainCam res scale to {value}%");
ssaaInstance = FPSCamera.GetComponent<SSAA>();
_nextSSRation = getFieldInfo("_nextSSRation");
_nextSSRation.SetValue(ssaaInstance, (float)(currentScalingFactor * value / 100f));
@ -166,10 +170,10 @@ namespace ScopeTweaks
void setScopeCameraResolutionScale(int value)
{
if(scopeCamera == null || !scopeCamera.isActiveAndEnabled)
{ //Logger.LogInfo("ScopeCam inactive or absent!");
{ Logger.LogInfo("ScopeCam inactive or absent!");
return; }
//Logger.LogInfo($"Setting Scope res scale to {value}%");
Logger.LogInfo($"Setting Scope res scale to {value}%");
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * value / 100);
}
@ -178,7 +182,7 @@ namespace ScopeTweaks
/// </summary>
void subscribeHandsChangedEvent()
{
//Logger.LogInfo("Subscribing to HandsChanged Event");
Logger.LogInfo("Subscribing to HandsChanged Event");
mainPlayer.HandsChangedEvent += (handsArgs) =>
{
subscribeOnAimingChangedEvent();
@ -187,33 +191,83 @@ namespace ScopeTweaks
void subscribeOnAimingChangedEvent()
{
//Logger.LogInfo("Subscribing to OnAimingChanged Event");
Logger.LogInfo("Subscribing to OnAimingChanged Event");
mainPlayer.HandsController.OnAimingChanged += (aimingArgs) =>
{
if (scopeFixType.Value != EFOVScalingMode.Enabled) return;
if(!mainPlayer.ProceduralWeaponAnimation.IsAiming)
{
GClass1774.Instance.SetFov(inGameFOV, 0.33f, false);
setInGameFOV(inGameFOV);
}
setMainCameraResolutionScale();
currentScalingFactor = getCurrentScalingFactor();
StartCoroutine(tryGetScopeCamera());
if(mainPlayer.HandsController.IsAiming)
{
if(inGameFOV != 50) { inGameFOV = getInGameFOV(); }
GClass1774.Instance.SetFov(35, 0.25f, false);
setInGameFOV(50);
setMainCameraResolutionScale(cameraResolutionScale.Value);
setScopeCameraResolutionScale(scopeCameraResolutionScale.Value);
return;
Logger.LogInfo("AimingChanged: notAiming");
if (!mainPlayer.ProceduralWeaponAnimation.IsAiming)
{
switch(scopeFixType.Value)
{
case EFOVScalingMode.Disabled:
{
Logger.LogInfo("Nothing to do!");
break;
}
case EFOVScalingMode.ScopesOnly:
{
setMainCameraResolutionScale();
GClass1774.Instance.SetFov(90, 0.33f, false);
setInGameFOV(inGameFOV);
break;
}
case EFOVScalingMode.All:
{
setMainCameraResolutionScale();
GClass1774.Instance.SetFov(90, 0.33f, false);
setInGameFOV(inGameFOV);
break;
}
}
}
Logger.LogInfo("Entering switch()");
if (mainPlayer.ProceduralWeaponAnimation.IsAiming)
{
if (inGameFOV != 50) { inGameFOV = getInGameFOV(); }
switch (scopeFixType.Value)
{
case EFOVScalingMode.Disabled:
{
Logger.LogInfo("Plugin is disabled!");
break;
}
case EFOVScalingMode.ScopesOnly:
{
Logger.LogInfo("Only magnified optics!");
if(scopeCamera.isActiveAndEnabled)
{
applyFixesWhileAiming();
}
break;
}
case EFOVScalingMode.All:
{
Logger.LogInfo("All sights!");
applyFixesWhileAiming();
break;
}
}
}
};
}
void applyFixesWhileAiming()
{
GClass1774.Instance.SetFov(35, 0.25f, false);
setInGameFOV(50);
setMainCameraResolutionScale(cameraResolutionScale.Value);
setScopeCameraResolutionScale(scopeCameraResolutionScale.Value);
}
/// <summary>
/// IN-GAME SETTINGS
/// </summary>
@ -222,12 +276,12 @@ namespace ScopeTweaks
float getCurrentScalingFactor()
{
//Logger.LogInfo("Getting current scaling factor:");
Logger.LogInfo("Getting current scaling factor:");
var graphics = Singleton<GClass1642>.Instance.Graphics.Settings;
if (!graphics.DLSSEnabled && !graphics.FSREnabled)
{
//Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}");
Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}");
return graphics.SuperSamplingFactor;
}
@ -242,7 +296,7 @@ namespace ScopeTweaks
case EDLSSMode.Performance: { DLSSFactor = 0.5f; break; }
case EDLSSMode.UltraPerformance: { DLSSFactor = 0.33f; break; }
}
//Logger.LogInfo($"DLSS factor: {DLSSFactor}");
Logger.LogInfo($"DLSS factor: {DLSSFactor}");
return DLSSFactor;
}
if (graphics.FSREnabled)
@ -256,11 +310,11 @@ namespace ScopeTweaks
case EFSRMode.Balanced: { FSRFactor = 0.59f; break; }
case EFSRMode.Performance: { FSRFactor = 0.5f; break; }
}
//Logger.LogInfo($"FSR factor: {FSRFactor}");
Logger.LogInfo($"FSR factor: {FSRFactor}");
return FSRFactor;
}
//Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f");
Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f");
return 1.0f;
}
}