2022-09-08 21:29:16 +02:00
using BepInEx ;
2023-04-02 09:13:21 +02:00
using BepInEx.Bootstrap ;
2022-09-08 21:29:16 +02:00
using BepInEx.Configuration ;
using Comfort.Common ;
2023-01-10 11:49:09 +01:00
using EFT ;
2022-09-18 23:54:23 +02:00
using EFT.Settings.Graphics ;
2023-06-01 17:55:11 +02:00
//using System.Collections;
//using System.Reflection;
using System.Threading.Tasks ;
2023-01-10 11:49:09 +01:00
using UnityEngine ;
2022-09-08 21:29:16 +02:00
2023-01-10 11:49:09 +01:00
/ * Dependencies :
* . . / BepInEx / core /
* BepInEx . dll
* . . / EscapeFromTarkov_Data / Managed /
* Aki . Reflection . dll
* Assembly - CSharp . dll
* Comfort . dll
* ItemComponent . Types . dll
* System . dll
* Unity . Postprocessing . Runtime . dll
* UnityEngine . dll
* UnityEngine . CoreModule . dll
* /
2022-09-17 20:08:36 +02:00
namespace ScopeTweaks
2022-09-08 21:29:16 +02:00
{
2023-06-01 17:59:16 +02:00
[BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "3.5.7")]
2023-04-02 09:13:21 +02:00
[BepInDependency("FOVFix", BepInDependency.DependencyFlags.SoftDependency)]
2022-09-08 21:29:16 +02:00
public class Plugin : BaseUnityPlugin
{
2023-06-01 17:55:11 +02:00
//ConfigEntry<int> scopeCameraResolutionScale;
2022-09-28 20:14:35 +02:00
ConfigEntry < bool > enableDebug ;
2022-09-16 13:24:26 +02:00
2022-09-17 19:49:55 +02:00
void Awake ( )
{
2023-04-02 09:13:21 +02:00
if ( Chainloader . PluginInfos . ContainsKey ( "FOVFix" ) )
{
Logger . LogWarning ( "Fontaine's FOV Fix detected! FOV Fix will NOT be available." ) ;
}
2023-04-04 19:30:08 +02:00
else
{
new CalculateScaleValueByFovPatch ( ) . Enable ( ) ;
}
2022-09-17 19:49:55 +02:00
2023-06-01 17:55:11 +02:00
//scopeCameraResolutionScale = Config.Bind(
// "General",
// "Scope camera scale %",
// 80,
// new ConfigDescription("Additional override applied on top of currently enabled resolution scaling method.", new AcceptableValueRange<int>(10, 100)));
2022-09-24 08:42:25 +02:00
2022-09-28 20:14:35 +02:00
enableDebug = Config . Bind ( "Debug" , "Enable debug logging" , false ) ;
}
2022-09-16 10:29:54 +02:00
2023-04-06 17:06:51 +02:00
void Update ( )
2022-09-17 19:49:55 +02:00
{
2023-01-10 11:49:09 +01:00
//Check if the game is in a valid state and execute logic depening on the status of the game
2022-09-20 22:02:46 +02:00
if ( Singleton < AbstractGame > . Instance = = null ) return ;
GameStatus currentGameState = Singleton < AbstractGame > . Instance . Status ;
2022-09-16 13:24:26 +02:00
2023-04-06 17:06:51 +02:00
if ( mainPlayer ! = null )
{
int inGameFov = Singleton < SharedGameSettingsClass > . Instance . Game . Settings . FieldOfView ;
float fov_clamped = Mathf . Clamp ( inGameFov , 50 , 75 ) ;
target_scale = Mathf . Lerp ( 1.0f , 0.65f , ( fov_clamped - 50 ) / 25 ) ;
if ( mainPlayer . ProceduralWeaponAnimation . IsAiming )
{
mainPlayer . RibcageScaleCurrent = 1.0f ;
mainPlayer . RibcageScaleCurrentTarget = 1.0f ;
}
else
{
mainPlayer . RibcageScaleCurrentTarget = target_scale ;
mainPlayer . RibcageScaleCurrent = target_scale ;
}
}
2023-01-10 11:49:09 +01:00
//logic should only execute once per game instead of every frame
2022-09-20 22:02:46 +02:00
if ( ! gameStateChanged ( currentGameState ) ) return ;
2022-09-16 10:29:54 +02:00
2023-01-10 11:49:09 +01:00
switch ( currentGameState )
2022-09-16 10:29:54 +02:00
{
2022-09-20 22:02:46 +02:00
case GameStatus . Started :
{
2023-01-10 11:49:09 +01:00
if ( enableDebug . Value ) Logger . LogInfo ( "Getting local player" ) ;
2022-09-20 22:02:46 +02:00
mainPlayer = getLocalPlayer ( ) ;
2022-09-08 21:29:16 +02:00
2022-09-20 22:02:46 +02:00
subscribeHandsChangedEvent ( ) ;
break ;
}
case GameStatus . SoftStopping :
2022-09-28 20:14:35 +02:00
case GameStatus . Stopping :
2022-09-20 22:02:46 +02:00
case GameStatus . Stopped :
{
2023-01-10 11:49:09 +01:00
if ( enableDebug . Value ) Logger . LogInfo ( "Resetting..." ) ;
2022-09-20 22:02:46 +02:00
scopeCamera = null ;
mainPlayer = null ;
2022-09-28 20:14:35 +02:00
2022-09-20 22:02:46 +02:00
break ;
}
default : break ;
2022-09-15 21:14:26 +02:00
}
2022-09-20 22:02:46 +02:00
}
/// <summary>
/// GAME STATUS
/// </summary>
2022-09-15 21:14:26 +02:00
2022-09-20 22:02:46 +02:00
GameStatus lastGameState ;
2023-01-10 11:49:09 +01:00
//compare current game status to the last saved game status, return true if game status has changed
2022-09-20 22:02:46 +02:00
bool gameStateChanged ( GameStatus currentState )
{
if ( currentState = = lastGameState ) return false ;
lastGameState = currentState ;
return true ;
2022-09-17 19:49:55 +02:00
}
2022-09-16 13:24:26 +02:00
2023-04-01 16:46:33 +02:00
Player mainPlayer = null ;
2023-01-10 11:49:09 +01:00
//find and return the player character in the session
2022-09-20 22:02:46 +02:00
Player getLocalPlayer ( )
2022-09-18 22:12:16 +02:00
{
2023-02-27 20:25:16 +01:00
if ( enableDebug . Value ) Logger . LogInfo ( "Looking for local player..." ) ;
Player localPlayer = Singleton < GameWorld > . Instance . RegisteredPlayers . Find ( p = > p . IsYourPlayer ) ;
if ( enableDebug . Value & & localPlayer ! = null ) Logger . LogInfo ( $"Found local player: {localPlayer.GetType()}" ) ;
return localPlayer ;
2022-09-18 22:12:16 +02:00
}
2022-09-20 22:02:46 +02:00
/// <summary>
/// CAMERA SETUP
/// </summary>
2022-09-24 08:42:25 +02:00
Camera scopeCamera = null ;
2023-06-01 17:55:11 +02:00
async void tryGetScopeCamera ( )
2022-09-17 19:49:55 +02:00
{
2022-09-20 22:02:46 +02:00
string cameraName = "BaseOpticCamera(Clone)" ;
2023-06-01 17:55:11 +02:00
if ( await Task . Run ( ( ) = > GameObject . Find ( cameraName ) ! = null ) )
2022-09-17 19:49:55 +02:00
{
2023-06-01 17:55:11 +02:00
scopeCamera = await Task . Run ( ( ) = > GameObject . Find ( cameraName ) . GetComponent < Camera > ( ) ) ;
2022-09-17 19:49:55 +02:00
}
}
2022-09-18 22:12:16 +02:00
2023-06-01 17:55:11 +02:00
//SSAAOptic ssaaOpticInstance = null; //Component has been nuked by BSG, thanks Nikita :)
//TODO: Find a workaround to achieve the same result (scale scope resolution while ADS)
2023-02-20 17:08:45 +01:00
2023-06-01 17:55:11 +02:00
//void setScopeCameraResolutionScale(int value)
//{
// if (scopeCamera == null || !scopeCamera.isActiveAndEnabled)
// {
// if (enableDebug.Value) Logger.LogInfo("ScopeCam inactive or absent!");
// return;
// }
2022-09-16 13:24:26 +02:00
2023-06-01 17:55:11 +02:00
// if (enableDebug.Value) Logger.LogInfo($"Setting Scope res scale to {value}%");
2023-02-20 17:08:45 +01:00
2023-06-01 17:55:11 +02:00
// if (ssaaOpticInstance == null)
// {
// ssaaOpticInstance = scopeCamera.GetComponent<SSAAOptic>();
// }
2023-02-20 17:08:45 +01:00
2023-06-01 17:55:11 +02:00
// ssaaOpticInstance.OpticCameraToMainCameraResolutionRatio = (float)(currentResoScalingFactor * (value / 100.0f));
//}
2022-09-15 21:14:26 +02:00
2022-09-20 22:02:46 +02:00
/// <summary>
/// PLAYER WEAPON EVENTS
/// </summary>
2023-04-03 11:47:11 +02:00
2022-09-20 22:02:46 +02:00
void subscribeHandsChangedEvent ( )
{
2023-01-10 11:49:09 +01:00
if ( enableDebug . Value ) Logger . LogInfo ( "Subscribing to HandsChanged Event" ) ;
2022-09-20 22:02:46 +02:00
mainPlayer . HandsChangedEvent + = ( handsArgs ) = >
2022-09-17 19:49:55 +02:00
{
2022-09-20 22:02:46 +02:00
subscribeOnAimingChangedEvent ( ) ;
} ;
}
2022-09-15 21:14:26 +02:00
2023-04-06 17:06:51 +02:00
internal static float target_scale = 1.0f ;
2022-09-20 22:02:46 +02:00
void subscribeOnAimingChangedEvent ( )
{
2023-01-10 11:49:09 +01:00
if ( enableDebug . Value ) Logger . LogInfo ( "Subscribing to OnAimingChanged Event" ) ;
2022-09-20 22:02:46 +02:00
mainPlayer . HandsController . OnAimingChanged + = ( aimingArgs ) = >
2022-09-08 21:29:16 +02:00
{
2023-04-06 17:06:51 +02:00
currentResoScalingFactor = getcurrentResoScalingFactor ( ) ;
2023-06-01 17:55:11 +02:00
tryGetScopeCamera ( ) ;
2022-09-20 22:43:40 +02:00
if ( mainPlayer . ProceduralWeaponAnimation . IsAiming )
2022-09-18 23:54:23 +02:00
{
2023-04-06 17:06:51 +02:00
target_scale = 1.0f ;
2023-06-01 17:55:11 +02:00
//setScopeCameraResolutionScale(scopeCameraResolutionScale.Value);
2022-09-20 22:02:46 +02:00
}
} ;
2022-09-18 23:54:23 +02:00
}
2022-09-08 21:29:16 +02:00
2023-04-06 17:06:51 +02:00
float currentResoScalingFactor = 1.0f ;
2022-09-20 22:02:46 +02:00
2023-04-06 17:06:51 +02:00
float getcurrentResoScalingFactor ( )
2022-09-18 23:54:23 +02:00
{
2023-01-10 11:49:09 +01:00
if ( enableDebug . Value ) Logger . LogInfo ( "Getting current scaling factor:" ) ;
2023-04-01 16:46:33 +02:00
var graphics = Singleton < SharedGameSettingsClass > . Instance . Graphics . Settings ;
2022-09-18 23:54:23 +02:00
if ( graphics . DLSSEnabled )
{
float DLSSFactor = 1.0f ;
switch ( graphics . DLSSMode . Value )
{
case EDLSSMode . Off : { DLSSFactor = 1.0f ; break ; }
case EDLSSMode . Quality : { DLSSFactor = 0.67f ; break ; }
case EDLSSMode . Balanced : { DLSSFactor = 0.58f ; break ; }
case EDLSSMode . Performance : { DLSSFactor = 0.5f ; break ; }
2022-09-18 23:59:26 +02:00
case EDLSSMode . UltraPerformance : { DLSSFactor = 0.33f ; break ; }
2022-09-18 23:54:23 +02:00
}
2023-01-10 11:49:09 +01:00
if ( enableDebug . Value ) Logger . LogInfo ( $"DLSS factor: {DLSSFactor}" ) ;
2022-09-18 23:54:23 +02:00
return DLSSFactor ;
}
if ( graphics . FSREnabled )
{
float FSRFactor = 1.0f ;
switch ( graphics . FSRMode . Value )
{
case EFSRMode . Off : { FSRFactor = 1.0f ; break ; }
2022-09-18 23:59:26 +02:00
case EFSRMode . UltraQuality : { FSRFactor = 0.77f ; break ; }
2022-09-18 23:54:23 +02:00
case EFSRMode . Quality : { FSRFactor = 0.66f ; break ; }
case EFSRMode . Balanced : { FSRFactor = 0.59f ; break ; }
case EFSRMode . Performance : { FSRFactor = 0.5f ; break ; }
}
2023-01-10 11:49:09 +01:00
if ( enableDebug . Value ) Logger . LogInfo ( $"FSR factor: {FSRFactor}" ) ;
2022-09-18 23:54:23 +02:00
return FSRFactor ;
2022-09-08 21:29:16 +02:00
}
2023-02-19 11:58:12 +01:00
if ( graphics . FSR2Enabled )
{
float FSR2Factor = 1.0f ;
switch ( graphics . FSR2Mode . Value )
{
case EFSR2Mode . Off : { FSR2Factor = 1.0f ; break ; }
case EFSR2Mode . Quality : { FSR2Factor = 0.67f ; break ; }
case EFSR2Mode . Balanced : { FSR2Factor = 0.59f ; break ; }
case EFSR2Mode . Performance : { FSR2Factor = 0.5f ; break ; }
case EFSR2Mode . UltraPerformance : { FSR2Factor = 0.33f ; break ; }
}
if ( enableDebug . Value ) Logger . LogInfo ( $"FSR factor: {FSR2Factor}" ) ;
return FSR2Factor ;
}
2022-09-18 23:54:23 +02:00
2023-02-20 17:08:45 +01:00
if ( enableDebug . Value ) Logger . LogInfo ( $"Supersampling factor: {graphics.SuperSamplingFactor}" ) ;
return graphics . SuperSamplingFactor ;
2022-09-08 21:29:16 +02:00
}
2023-01-10 11:49:09 +01:00
}
2022-09-20 22:02:46 +02:00
}