Implemented debug switch.

FOV update on aim-in
replaced *InGameFOV() functions with a property
This commit is contained in:
notGreg 2022-09-28 20:14:35 +02:00
parent 7edad7d276
commit b87e4e014a

View File

@ -7,15 +7,18 @@ using System.Reflection;
using System.Collections;
using EFT.Settings.Graphics;
using System.ComponentModel;
using EFT.Animations;
using UnityEngine.Rendering.PostProcessing;
namespace ScopeTweaks
{
[BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "2.0.0")]
[BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "2.1.0")]
public class Plugin : BaseUnityPlugin
{
ConfigEntry<int> cameraResolutionScale;
ConfigEntry<int> scopeCameraResolutionScale;
ConfigEntry<EFOVScalingMode> scopeFixType;
ConfigEntry<bool> enableDebug;
enum EFOVScalingMode
{
@ -38,16 +41,17 @@ namespace ScopeTweaks
"General",
"Scope camera scale %",
80,
new ConfigDescription("Additional override applied on top of currently enabled resolution scaling method.", new AcceptableValueRange<int>(25, (int)(100f / currentScalingFactor))));
new ConfigDescription("Additional override applied on top of currently enabled resolution scaling method.", new AcceptableValueRange<int>(25, 100)));
scopeFixType = Config.Bind("General", "High FOV sight tweak", EFOVScalingMode.ScopesOnly, new ConfigDescription(""));
scopeFixType = Config.Bind(
"General",
"High FOV sight tweak",
EFOVScalingMode.ScopesOnly,
new ConfigDescription(""));
enableDebug = Config.Bind("Debug", "Enable debug logging", false);
}
void Update()
{
if (Singleton<AbstractGame>.Instance == null) return;
@ -59,24 +63,32 @@ namespace ScopeTweaks
{
case GameStatus.Started:
{
Logger.LogInfo("Getting local player");
if(enableDebug.Value)Logger.LogInfo("Getting local player");
mainPlayer = getLocalPlayer();
subscribeHandsChangedEvent();
Logger.LogInfo("Assigning cameras...");
if(enableDebug.Value)Logger.LogInfo("Assigning cameras...");
StartCoroutine(tryGetMainCamera());
StartCoroutine(tryGetScopeCamera());
defaultInGameFOV = inGameFOV;
break;
}
case GameStatus.SoftStopping:
case GameStatus.Stopping:
case GameStatus.Stopped:
{
Logger.LogInfo("Resetting...");
if(enableDebug.Value)Logger.LogInfo("Resetting...");
FPSCamera = null;
scopeCamera = null;
mainPlayer = null;
if(enableDebug.Value)Logger.LogInfo($"Restoring FOV in settings: {defaultInGameFOV}");
inGameFOV = defaultInGameFOV;
break;
}
default: break;
@ -104,19 +116,19 @@ namespace ScopeTweaks
/// <summary>
/// FIELD OF VIEW
/// </summary>
int inGameFOV;
int getInGameFOV()
///
private int defaultInGameFOV;
private int inGameFOV
{
int fov = Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value;
Logger.LogInfo($"In-game FOV: {fov}");
return fov;
}
void setInGameFOV(int value)
{
Logger.LogInfo($"setInGameFOV(): Update to {value}");
Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value = value;
get {
int fov = Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value;
if (enableDebug.Value) Logger.LogInfo($"get_defaultInGameFOV: Reading from settings: {fov}");
return fov;
}
set {
if (enableDebug.Value) Logger.LogInfo($"set_defaultInGameFOV: Writing to settings: {value}");
Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value = value;
}
}
/// <summary>
@ -136,11 +148,11 @@ namespace ScopeTweaks
if (GameObject.Find(cameraName) != null)
{
FPSCamera = GameObject.Find(cameraName).GetComponent<Camera>();
Logger.LogInfo($"{FPSCamera.name} found!");
if(enableDebug.Value)Logger.LogInfo($"{FPSCamera.name} found!");
}
else
{
Logger.LogMessage($"Camera \"{cameraName}\" not found, rescheduling...");
if(enableDebug.Value)Logger.LogMessage($"Camera \"{cameraName}\" not found.");
yield return myDelaySec;
StartCoroutine(tryGetMainCamera());
yield break;
@ -159,14 +171,14 @@ namespace ScopeTweaks
if (GameObject.Find(cameraName) != null)
{
scopeCamera = GameObject.Find(cameraName).GetComponent<Camera>();
Logger.LogInfo($"Camera \"{scopeCamera.name}\" found!");
if(enableDebug.Value)Logger.LogInfo($"Camera \"{scopeCamera.name}\" found!");
}
yield break;
}
void setMainCameraResolutionScale(int value = 100)
{
Logger.LogInfo($"Setting MainCam res scale to {value}%");
if(enableDebug.Value)Logger.LogInfo($"Setting MainCam res scale to {value}%");
ssaaInstance = FPSCamera.GetComponent<SSAA>();
_nextSSRation = getFieldInfo("_nextSSRation");
_nextSSRation.SetValue(ssaaInstance, (float)(currentScalingFactor * value / 100f));
@ -175,11 +187,11 @@ namespace ScopeTweaks
void setScopeCameraResolutionScale(int value)
{
if(scopeCamera == null || !scopeCamera.isActiveAndEnabled)
{ Logger.LogInfo("ScopeCam inactive or absent!");
{ if(enableDebug.Value)Logger.LogInfo("ScopeCam inactive or absent!");
return; }
Logger.LogInfo($"Setting Scope res scale to {value}%");
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * value / 100);
if(enableDebug.Value)Logger.LogInfo($"Setting Scope res scale to {value}%");
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * (value / 100f));
}
/// <summary>
@ -187,7 +199,7 @@ namespace ScopeTweaks
/// </summary>
void subscribeHandsChangedEvent()
{
Logger.LogInfo("Subscribing to HandsChanged Event");
if(enableDebug.Value)Logger.LogInfo("Subscribing to HandsChanged Event");
mainPlayer.HandsChangedEvent += (handsArgs) =>
{
subscribeOnAimingChangedEvent();
@ -197,62 +209,67 @@ namespace ScopeTweaks
void subscribeOnAimingChangedEvent()
{
Logger.LogInfo("Subscribing to OnAimingChanged Event");
if(enableDebug.Value)Logger.LogInfo("Subscribing to OnAimingChanged Event");
mainPlayer.HandsController.OnAimingChanged += (aimingArgs) =>
{
currentScalingFactor = getCurrentScalingFactor();
StartCoroutine(tryGetScopeCamera());
Logger.LogInfo("AimingChanged: notAiming");
if (!mainPlayer.ProceduralWeaponAnimation.IsAiming)
{
switch(scopeFixType.Value)
{
switch(scopeFixType.Value)
{
case EFOVScalingMode.Disabled:
{
Logger.LogInfo("Nothing to do!");
if(enableDebug.Value)Logger.LogInfo($"Switch: Not Aiming: ScalingMode: {scopeFixType.Value}");
break;
}
case EFOVScalingMode.ScopesOnly:
{
if(enableDebug.Value)Logger.LogInfo($"Switch: Not Aiming: ScalingMode: {scopeFixType.Value}");
setMainCameraResolutionScale();
GClass1774.Instance.SetFov(inGameFOV, 0.33f, false);
setInGameFOV(inGameFOV);
GClass1774.Instance.SetFov(defaultInGameFOV, 0.33f, false);
inGameFOV = defaultInGameFOV;
break;
}
case EFOVScalingMode.All:
{
if(enableDebug.Value)Logger.LogInfo($"Switch: Not Aiming: ScalingMode: {scopeFixType.Value}");
setMainCameraResolutionScale();
GClass1774.Instance.SetFov(inGameFOV, 0.33f, false);
setInGameFOV(inGameFOV);
GClass1774.Instance.SetFov(defaultInGameFOV, 0.33f, false);
inGameFOV = defaultInGameFOV;
break;
}
}
}
}
Logger.LogInfo("Entering switch()");
if (mainPlayer.ProceduralWeaponAnimation.IsAiming)
{
if (inGameFOV != 50) { inGameFOV = getInGameFOV(); }
defaultInGameFOV = inGameFOV;
switch (scopeFixType.Value)
{
case EFOVScalingMode.Disabled:
{
Logger.LogInfo("Plugin is disabled!");
if(enableDebug.Value)Logger.LogInfo($"Switch: Aiming: ScalingMode: {scopeFixType.Value}");
break;
}
case EFOVScalingMode.ScopesOnly:
{
Logger.LogInfo("Only magnified optics!");
if(scopeCamera.isActiveAndEnabled)
if(enableDebug.Value)Logger.LogInfo($"Switch: Aiming: ScalingMode: {scopeFixType.Value}");
if (scopeCamera.isActiveAndEnabled)
{
if(enableDebug.Value)Logger.LogInfo("ScopeCamera not found or disabled!");
applyFixesWhileAiming();
}
break;
}
case EFOVScalingMode.All:
{
Logger.LogInfo("All sights!");
if(enableDebug.Value)Logger.LogInfo($"Switch: Aiming: ScalingMode: {scopeFixType.Value}");
applyFixesWhileAiming();
@ -265,9 +282,13 @@ namespace ScopeTweaks
void applyFixesWhileAiming()
{
if(enableDebug.Value)Logger.LogInfo($"AimingSpeed: {mainPlayer.ProceduralWeaponAnimation.AimingSpeed}");
if(enableDebug.Value)Logger.LogInfo("Changing FOV while aiming");
GClass1774.Instance.SetFov(35, 0.25f, false);
setInGameFOV(50);
inGameFOV = 50;
if(enableDebug.Value)Logger.LogInfo("Updating scope resolution");
setMainCameraResolutionScale(cameraResolutionScale.Value);
setScopeCameraResolutionScale(scopeCameraResolutionScale.Value);
}
@ -280,12 +301,12 @@ namespace ScopeTweaks
float getCurrentScalingFactor()
{
Logger.LogInfo("Getting current scaling factor:");
if(enableDebug.Value)Logger.LogInfo("Getting current scaling factor:");
var graphics = Singleton<GClass1642>.Instance.Graphics.Settings;
if (!graphics.DLSSEnabled && !graphics.FSREnabled)
{
Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}");
if(enableDebug.Value)Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}");
return graphics.SuperSamplingFactor;
}
@ -300,7 +321,7 @@ namespace ScopeTweaks
case EDLSSMode.Performance: { DLSSFactor = 0.5f; break; }
case EDLSSMode.UltraPerformance: { DLSSFactor = 0.33f; break; }
}
Logger.LogInfo($"DLSS factor: {DLSSFactor}");
if(enableDebug.Value)Logger.LogInfo($"DLSS factor: {DLSSFactor}");
return DLSSFactor;
}
if (graphics.FSREnabled)
@ -314,11 +335,11 @@ namespace ScopeTweaks
case EFSRMode.Balanced: { FSRFactor = 0.59f; break; }
case EFSRMode.Performance: { FSRFactor = 0.5f; break; }
}
Logger.LogInfo($"FSR factor: {FSRFactor}");
if(enableDebug.Value)Logger.LogInfo($"FSR factor: {FSRFactor}");
return FSRFactor;
}
Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f");
if(enableDebug.Value)Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f");
return 1.0f;
}
}