Removed main camera resolution scale while aiming due to performance issues.

Updated for SPT-AKI 3.5.3
This commit is contained in:
notGreg 2023-04-01 16:46:33 +02:00
parent bc0d156034
commit dbfc74cd26
2 changed files with 36 additions and 120 deletions

View File

@ -23,10 +23,9 @@ using UnityEngine;
*/
namespace ScopeTweaks
{
[BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "3.5.0")]
[BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "3.5.3")]
public class Plugin : BaseUnityPlugin
{
ConfigEntry<int> cameraResolutionScale;
ConfigEntry<int> scopeCameraResolutionScale;
ConfigEntry<EFOVScalingMode> scopeFixType;
ConfigEntry<bool> enableDebug;
@ -41,25 +40,16 @@ namespace ScopeTweaks
}
//The following assignments should allow for faster patching in the future.
//The correct GClass can be found by searching for "ClearSettings" in Assembly-CSharp.dll via dnSpy, netFiddle, ilSpy, etc.
//GClass1642 settingsLibrary = Singleton<GClass1642>.Instance; //used by SPT-AKI 3.2.3
//GClass1653 settingsLibrary = Singleton<GClass1653>.Instance; //used by SPT-AKI 3.3.0
//GClass1659 settingsLibrary = Singleton<GClass1659>.Instance; //used by SPT-AKI 3.4.1
//The correct GClass can be found by searching for "ClearSettings" in Assembly-CSharp.dll via dnSpy, netFiddle, ilSpy, etc.
SharedGameSettingsClass settingsLibrary = Singleton<SharedGameSettingsClass>.Instance;
//The correct GClass can be found by searching for "SetFov" in Assembly-CSharp.dll via dnSpy, netFiddle, ilSpy, etc.
//GClass1774 setFovLibrary = Singleton<GClass1774>.Instance; //used by SPT-AKI 3.2.3
//GClass1785 setFovLibrary = Singleton<GClass1785>.Instance; //used by SPT-AKI 3.3.0
CameraClass setFovLibrary = CameraClass.Instance; //used by SPT-AKI 3.4.1 and 3.5.0
CameraClass setFovLibrary = CameraClass.Instance;
void Awake()
{
cameraResolutionScale = Config.Bind(
"General",
"Main camera scale %",
80,
new ConfigDescription("Additional override applied on top of currently enabled resolution scaling method.", new AcceptableValueRange<int>(25, 100)));
scopeCameraResolutionScale = Config.Bind(
"General",
@ -95,7 +85,6 @@ namespace ScopeTweaks
subscribeHandsChangedEvent();
if (enableDebug.Value) Logger.LogInfo("Assigning cameras...");
StartCoroutine(tryGetMainCamera());
StartCoroutine(tryGetScopeCamera());
defaultInGameFOV = inGameFOV;
@ -108,7 +97,6 @@ namespace ScopeTweaks
{
if (enableDebug.Value) Logger.LogInfo("Resetting...");
FPSCamera = null;
scopeCamera = null;
mainPlayer = null;
@ -134,7 +122,7 @@ namespace ScopeTweaks
return true;
}
Player mainPlayer;
Player mainPlayer = null;
//find and return the player character in the session
Player getLocalPlayer()
{
@ -153,56 +141,22 @@ namespace ScopeTweaks
{
get
{
//int fov = settingsLibrary.Game.Settings.FieldOfView.Value;
//int fov = Singleton<GClass1659>.Instance.Game.Settings.FieldOfView.Value; //SPT-AKI 3.4.1
int fov = Singleton<GClass1776>.Instance.Game.Settings.FieldOfView.Value; // SPT-AKI 3.5.0
int fov = Singleton<SharedGameSettingsClass>.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}");
//settingsLibrary.Game.Settings.FieldOfView.Value = value;
//int fov = Singleton<GClass1659>.Instance.Game.Settings.FieldOfView.Value;
Singleton<GClass1776>.Instance.Game.Settings.FieldOfView.Value = value; // SPT-AKI 3.5.0
Singleton<SharedGameSettingsClass>.Instance.Game.Settings.FieldOfView.Value = value;
}
}
/// <summary>
/// CAMERA SETUP
/// </summary>
Camera FPSCamera = null;
Camera scopeCamera = null;
SSAA ssaaInstance = null;
FieldInfo _nextSSRation = null;
WaitForSeconds myDelaySec = new WaitForSeconds(1);
IEnumerator tryGetMainCamera()
{
string cameraName = "FPS Camera";
if (GameObject.Find(cameraName) != null)
{
FPSCamera = GameObject.Find(cameraName).GetComponent<Camera>();
if (enableDebug.Value) Logger.LogInfo($"{FPSCamera.name} found!");
StopCoroutine(tryGetMainCamera());
}
else
{
if (enableDebug.Value) Logger.LogMessage($"Camera \"{cameraName}\" not found.");
yield return myDelaySec;
StartCoroutine(tryGetMainCamera());
yield break;
}
yield return null;
}
FieldInfo getFieldInfo(string fieldName)
{
return typeof(SSAA).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
}
IEnumerator tryGetScopeCamera()
{
string cameraName = "BaseOpticCamera(Clone)";
@ -214,19 +168,6 @@ namespace ScopeTweaks
}
yield break;
}
void setMainCameraResolutionScale(int value = 100)
{
if (ssaaInstance == null)
{
ssaaInstance = FPSCamera.GetComponent<SSAA>();
_nextSSRation = getFieldInfo("_nextSSRation");
}
float target_res = currentScalingFactor * (value / 100.0f);
if (enableDebug.Value) Logger.LogInfo($"Setting MainCam res scale to {Mathf.Round(target_res*100.0f)}%");
//_nextSSRation.SetValue(ssaaInstance, (float)(currentScalingFactor * (value / 100.0f)));
}
SSAAOptic ssaaOpticInstance = null;
@ -283,18 +224,19 @@ namespace ScopeTweaks
case EFOVScalingMode.ScopesOnly:
{
if (enableDebug.Value) Logger.LogInfo($"Switch: Not Aiming: ScalingMode: {scopeFixType.Value}");
setMainCameraResolutionScale();
setFovLibrary.SetFov(defaultInGameFOV, aimSpeed, false);
inGameFOV = defaultInGameFOV;
if (mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic)
{
setFovLibrary.SetFov(defaultInGameFOV, aimSpeed, false);
inGameFOV = defaultInGameFOV;
mainPlayer.ProceduralWeaponAnimation.ResetFovAdjustments(mainPlayer);
mainPlayer.ProceduralWeaponAnimation.ResetFovAdjustments(mainPlayer);
}
break;
}
case EFOVScalingMode.All:
{
if (enableDebug.Value) Logger.LogInfo($"Switch: Not Aiming: ScalingMode: {scopeFixType.Value}");
setMainCameraResolutionScale();
setFovLibrary.SetFov(defaultInGameFOV, aimSpeed, false);
inGameFOV = defaultInGameFOV;
@ -309,6 +251,7 @@ namespace ScopeTweaks
if (mainPlayer.ProceduralWeaponAnimation.IsAiming)
{
Logger.LogInfo($"Scope: {mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod.Item.LocalizedName()} isOptic: {mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic}");
defaultInGameFOV = inGameFOV;
switch (scopeFixType.Value)
{
@ -320,14 +263,10 @@ namespace ScopeTweaks
case EFOVScalingMode.ScopesOnly:
{
if (enableDebug.Value) Logger.LogInfo($"Switch: Aiming: ScalingMode: {scopeFixType.Value}");
if (scopeCamera != null && scopeCamera.isActiveAndEnabled)
if (mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic)
{
applyFixesWhileAiming();
}
else
{
if (enableDebug.Value) Logger.LogInfo("ScopeCamera not found or disabled!");
}
break;
}
case EFOVScalingMode.All:
@ -345,37 +284,25 @@ namespace ScopeTweaks
void applyFixesWhileAiming()
{
//if (enableDebug.Value) Logger.LogInfo($"AimingSpeed: {mainPlayer.ProceduralWeaponAnimation.AimingSpeed}");
if (enableDebug.Value) Logger.LogInfo("Applying aiming tweaks");
float aimSpeed = mainPlayer.ProceduralWeaponAnimation.AimingSpeed * 0.7f;
// Classic method of forcing 50 fov while aiming
setFovLibrary.SetFov(35, aimSpeed, false);
inGameFOV = 50;
if (enableDebug.Value) Logger.LogInfo("Updating scope resolution");
setMainCameraResolutionScale(cameraResolutionScale.Value);
if (enableDebug.Value) Logger.LogInfo("Updating scope resolution");
setScopeCameraResolutionScale(scopeCameraResolutionScale.Value);
}
/// <summary>
/// IN-GAME SETTINGS
/// </summary>
float currentScalingFactor = 1.0f;
float getCurrentScalingFactor()
{
if (enableDebug.Value) Logger.LogInfo("Getting current scaling factor:");
//var graphics = settingsLibrary.Graphics.Settings; //SPT-AKI 3.3.0
//var graphics = Singleton<GClass1659>.Instance.Graphics.Settings; // SPT-AKI 3.4.1
var graphics = Singleton<GClass1776>.Instance.Graphics.Settings; // SPT-AKI 3.5.0
//if (!graphics.DLSSEnabled && !graphics.FSREnabled)
//{
// if (enableDebug.Value) Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}");
// return graphics.SuperSamplingFactor;
//}
var graphics = Singleton<SharedGameSettingsClass>.Instance.Graphics.Settings;
if (graphics.DLSSEnabled)
{
@ -422,9 +349,6 @@ namespace ScopeTweaks
if (enableDebug.Value) Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}");
return graphics.SuperSamplingFactor;
//if (enableDebug.Value) Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f");
//return 1.0f;
}
}
}

View File

@ -35,38 +35,30 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Aki.Reflection, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\Aki.Reflection.dll</HintPath>
<Reference Include="Aki.Reflection">
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\Aki.Reflection.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll</HintPath>
<Reference Include="Assembly-CSharp">
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx, Version=5.4.21.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.0\BepInEx\core\BepInEx.dll</HintPath>
<Reference Include="BepInEx">
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.3\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
<Reference Include="Comfort, Version=1.0.0.4, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\Comfort.dll</HintPath>
<Reference Include="Comfort">
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\Comfort.dll</HintPath>
</Reference>
<Reference Include="ItemComponent.Types, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\ItemComponent.Types.dll</HintPath>
<Reference Include="ItemComponent.Types">
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\ItemComponent.Types.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="Unity.Postprocessing.Runtime, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\Unity.Postprocessing.Runtime.dll</HintPath>
<Reference Include="Unity.Postprocessing.Runtime">
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\Unity.Postprocessing.Runtime.dll</HintPath>
</Reference>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\UnityEngine.dll</HintPath>
<Reference Include="UnityEngine">
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.0\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<Reference Include="UnityEngine.CoreModule">
<HintPath>E:\SPT-AKI\SPT-AKI 3.5.3\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />