Fixed an exception related to updating a non-existent camera

Temporarily disabled main camera resolution change due to performance issues
This commit is contained in:
notGreg 2023-02-20 17:08:45 +01:00
parent 7d32b9b13c
commit 634f939007

View File

@ -161,7 +161,7 @@ namespace ScopeTweaks
if (enableDebug.Value) Logger.LogInfo($"set_defaultInGameFOV: Writing to settings: {value}"); if (enableDebug.Value) Logger.LogInfo($"set_defaultInGameFOV: Writing to settings: {value}");
//settingsLibrary.Game.Settings.FieldOfView.Value = value; //settingsLibrary.Game.Settings.FieldOfView.Value = value;
//int fov = Singleton<GClass1659>.Instance.Game.Settings.FieldOfView.Value; //int fov = Singleton<GClass1659>.Instance.Game.Settings.FieldOfView.Value;
int fov = Singleton<GClass1776>.Instance.Game.Settings.FieldOfView.Value; // SPT-AKI 3.5.0 Singleton<GClass1776>.Instance.Game.Settings.FieldOfView.Value = value; // SPT-AKI 3.5.0
} }
} }
@ -183,6 +183,7 @@ namespace ScopeTweaks
{ {
FPSCamera = GameObject.Find(cameraName).GetComponent<Camera>(); FPSCamera = GameObject.Find(cameraName).GetComponent<Camera>();
if (enableDebug.Value) Logger.LogInfo($"{FPSCamera.name} found!"); if (enableDebug.Value) Logger.LogInfo($"{FPSCamera.name} found!");
StopCoroutine(tryGetMainCamera());
} }
else else
{ {
@ -206,26 +207,25 @@ namespace ScopeTweaks
{ {
scopeCamera = GameObject.Find(cameraName).GetComponent<Camera>(); scopeCamera = GameObject.Find(cameraName).GetComponent<Camera>();
if (enableDebug.Value) Logger.LogInfo($"Camera \"{scopeCamera.name}\" found!"); if (enableDebug.Value) Logger.LogInfo($"Camera \"{scopeCamera.name}\" found!");
StopCoroutine(tryGetScopeCamera());
} }
yield break; yield break;
} }
void setMainCameraResolutionScale(int value = 100) void setMainCameraResolutionScale(int value = 100)
{ {
if (ssaaInstance == null)
//if (settingsLibrary.Graphics.Settings.DLSSEnabled)
//if (Singleton<GClass1659>.Instance.Graphics.Settings.DLSSEnabled)
if (Singleton<GClass1776>.Instance.Graphics.Settings.DLSSEnabled)
{ {
if (enableDebug.Value) Logger.LogInfo("DLSS enabled - skipping MainCamera resolution change");
return;
}
if (enableDebug.Value) Logger.LogInfo($"Setting MainCam res scale to {value}%");
ssaaInstance = FPSCamera.GetComponent<SSAA>(); ssaaInstance = FPSCamera.GetComponent<SSAA>();
_nextSSRation = getFieldInfo("_nextSSRation"); _nextSSRation = getFieldInfo("_nextSSRation");
_nextSSRation.SetValue(ssaaInstance, (float)(currentScalingFactor * value / 100f));
} }
float target_res = currentScalingFactor * (value / 100.0f);
if (enableDebug.Value) Logger.LogInfo($"Setting MainCam res scale to {target_res}%");
//_nextSSRation.SetValue(ssaaInstance, (float)(currentScalingFactor * (value / 100.0f)));
}
SSAAOptic ssaaOpticInstance = null;
void setScopeCameraResolutionScale(int value) void setScopeCameraResolutionScale(int value)
{ {
@ -236,7 +236,13 @@ namespace ScopeTweaks
} }
if (enableDebug.Value) Logger.LogInfo($"Setting Scope res scale to {value}%"); if (enableDebug.Value) Logger.LogInfo($"Setting Scope res scale to {value}%");
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * (value / 100f));
if (ssaaOpticInstance == null)
{
ssaaOpticInstance = scopeCamera.GetComponent<SSAAOptic>();
}
ssaaOpticInstance.OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * (value / 100.0f));
} }
/// <summary> /// <summary>
@ -306,10 +312,13 @@ namespace ScopeTweaks
case EFOVScalingMode.ScopesOnly: case EFOVScalingMode.ScopesOnly:
{ {
if (enableDebug.Value) Logger.LogInfo($"Switch: Aiming: ScalingMode: {scopeFixType.Value}"); if (enableDebug.Value) Logger.LogInfo($"Switch: Aiming: ScalingMode: {scopeFixType.Value}");
if (scopeCamera.isActiveAndEnabled) if (scopeCamera != null && scopeCamera.isActiveAndEnabled)
{
applyFixesWhileAiming();
}
else
{ {
if (enableDebug.Value) Logger.LogInfo("ScopeCamera not found or disabled!"); if (enableDebug.Value) Logger.LogInfo("ScopeCamera not found or disabled!");
applyFixesWhileAiming();
} }
break; break;
} }
@ -328,10 +337,10 @@ namespace ScopeTweaks
void applyFixesWhileAiming() void applyFixesWhileAiming()
{ {
if (enableDebug.Value) Logger.LogInfo($"AimingSpeed: {mainPlayer.ProceduralWeaponAnimation.AimingSpeed}"); //if (enableDebug.Value) Logger.LogInfo($"AimingSpeed: {mainPlayer.ProceduralWeaponAnimation.AimingSpeed}");
if (enableDebug.Value) Logger.LogInfo("Changing FOV while aiming"); if (enableDebug.Value) Logger.LogInfo("Applying aiming tweaks");
setFovLibrary.SetFov(35, 0.25f, false); //SPT-AKI 3.3.0 setFovLibrary.SetFov(35, 0.25f, false);
inGameFOV = 50; inGameFOV = 50;
if (enableDebug.Value) Logger.LogInfo("Updating scope resolution"); if (enableDebug.Value) Logger.LogInfo("Updating scope resolution");
@ -352,11 +361,11 @@ namespace ScopeTweaks
//var graphics = Singleton<GClass1659>.Instance.Graphics.Settings; // SPT-AKI 3.4.1 //var graphics = Singleton<GClass1659>.Instance.Graphics.Settings; // SPT-AKI 3.4.1
var graphics = Singleton<GClass1776>.Instance.Graphics.Settings; // SPT-AKI 3.5.0 var graphics = Singleton<GClass1776>.Instance.Graphics.Settings; // SPT-AKI 3.5.0
if (!graphics.DLSSEnabled && !graphics.FSREnabled) //if (!graphics.DLSSEnabled && !graphics.FSREnabled)
{ //{
if (enableDebug.Value) Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}"); // if (enableDebug.Value) Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}");
return graphics.SuperSamplingFactor; // return graphics.SuperSamplingFactor;
} //}
if (graphics.DLSSEnabled) if (graphics.DLSSEnabled)
{ {
@ -401,8 +410,11 @@ namespace ScopeTweaks
return FSR2Factor; return FSR2Factor;
} }
if (enableDebug.Value) Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f"); if (enableDebug.Value) Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}");
return 1.0f; return graphics.SuperSamplingFactor;
//if (enableDebug.Value) Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f");
//return 1.0f;
} }
} }
} }