2022-09-08 21:29:16 +02:00
|
|
|
|
using BepInEx;
|
|
|
|
|
using BepInEx.Configuration;
|
|
|
|
|
using EFT;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Comfort.Common;
|
2022-09-15 21:14:26 +02:00
|
|
|
|
using System.Reflection;
|
2022-09-17 19:49:55 +02:00
|
|
|
|
using System.Collections;
|
2022-09-18 23:54:23 +02:00
|
|
|
|
using EFT.Settings.Graphics;
|
2022-09-08 21:29:16 +02:00
|
|
|
|
|
2022-09-17 20:08:36 +02:00
|
|
|
|
namespace ScopeTweaks
|
2022-09-08 21:29:16 +02:00
|
|
|
|
{
|
2022-09-19 07:59:29 +02:00
|
|
|
|
[BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "2.0.0")]
|
2022-09-08 21:29:16 +02:00
|
|
|
|
public class Plugin : BaseUnityPlugin
|
|
|
|
|
{
|
2022-09-17 19:49:55 +02:00
|
|
|
|
Utils utils = new Utils();
|
2022-09-17 20:08:36 +02:00
|
|
|
|
CameraUtils scopeRes = new CameraUtils();
|
2022-09-17 19:49:55 +02:00
|
|
|
|
|
2022-09-08 21:29:16 +02:00
|
|
|
|
ConfigEntry<int> cameraResolutionScale;
|
|
|
|
|
ConfigEntry<int> scopeCameraResolutionScale;
|
2022-09-18 22:12:16 +02:00
|
|
|
|
ConfigEntry<EFOVScalingMode> scopeFixType;
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-18 22:12:16 +02:00
|
|
|
|
enum EFOVScalingMode
|
2022-09-17 19:49:55 +02:00
|
|
|
|
{
|
2022-09-16 13:24:26 +02:00
|
|
|
|
Disabled,
|
2022-09-18 23:54:23 +02:00
|
|
|
|
Enabled,
|
2022-09-16 13:24:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
cameraResolutionScale = Config.Bind(
|
|
|
|
|
"General",
|
|
|
|
|
"Main camera scale %",
|
|
|
|
|
80,
|
|
|
|
|
new ConfigDescription("Main camera resolution scale", new AcceptableValueRange<int>(50, 100)));
|
|
|
|
|
|
|
|
|
|
scopeCameraResolutionScale = Config.Bind(
|
|
|
|
|
"General",
|
|
|
|
|
"Scope camera scale %",
|
|
|
|
|
40,
|
|
|
|
|
new ConfigDescription("Scope camera resolution scale", new AcceptableValueRange<int>(25, 100)));
|
|
|
|
|
|
2022-09-19 00:03:42 +02:00
|
|
|
|
scopeFixType = Config.Bind("General", "High FOV scope tweak", EFOVScalingMode.Enabled, new ConfigDescription(""));
|
2022-09-17 19:49:55 +02:00
|
|
|
|
}
|
2022-09-08 21:29:16 +02:00
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
Camera FPSCamera = null;
|
|
|
|
|
Camera scopeCamera = null;
|
2022-09-16 10:29:54 +02:00
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
SSAA ssaaInstance = null;
|
|
|
|
|
FieldInfo _nextSSRation = null;
|
2022-09-16 10:29:54 +02:00
|
|
|
|
|
2022-09-18 23:54:23 +02:00
|
|
|
|
int defaultFOVValue;
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
void setUpCameras()
|
|
|
|
|
{
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("Game started!");
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("Get FPS Camera");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
StartCoroutine(tryGetMainCamera());
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("Get Scope Camera");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
StartCoroutine(tryGetScopeCamera());
|
2022-09-16 10:29:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
WaitForSeconds myDelaySec = new WaitForSeconds(1);
|
|
|
|
|
IEnumerator tryGetMainCamera()
|
2022-09-16 10:29:54 +02:00
|
|
|
|
{
|
2022-09-17 19:49:55 +02:00
|
|
|
|
if (scopeRes.getMainCamera() == null)
|
2022-09-16 10:29:54 +02:00
|
|
|
|
{
|
2022-09-17 19:49:55 +02:00
|
|
|
|
yield return myDelaySec;
|
|
|
|
|
StartCoroutine(tryGetMainCamera());
|
|
|
|
|
yield break;
|
2022-09-16 10:29:54 +02:00
|
|
|
|
}
|
2022-09-17 19:49:55 +02:00
|
|
|
|
FPSCamera = scopeRes.getMainCamera();
|
2022-09-18 22:12:16 +02:00
|
|
|
|
defaultFOVValue = (int)FPSCamera.fieldOfView;
|
2022-09-08 21:29:16 +02:00
|
|
|
|
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("Get SSAAInstance (Camera)");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
ssaaInstance = scopeRes.getSSAAInstance(FPSCamera);
|
2022-09-08 21:29:16 +02:00
|
|
|
|
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("Set SSRatios");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
_nextSSRation = scopeRes.getFieldInfo("_nextSSRation");
|
|
|
|
|
}
|
2022-09-15 21:14:26 +02:00
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
IEnumerator tryGetScopeCamera()
|
2022-09-08 21:29:16 +02:00
|
|
|
|
{
|
2022-09-17 19:49:55 +02:00
|
|
|
|
if (scopeRes.getScopeCamera() == null)
|
2022-09-08 21:29:16 +02:00
|
|
|
|
{
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("ScopeCamera not found! Restarting...");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
yield return myDelaySec;
|
|
|
|
|
StartCoroutine(tryGetScopeCamera());
|
|
|
|
|
yield break;
|
2022-09-15 21:14:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("Assigning scopeCamera");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
scopeCamera = scopeRes.getScopeCamera();
|
|
|
|
|
}
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-18 22:12:16 +02:00
|
|
|
|
void updateMainCameraResolution(float value)
|
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
//Logger.LogInfo($"Updating {Camera.main.name} SSRatio to {value / 100f}");
|
|
|
|
|
_nextSSRation.SetValue(ssaaInstance, (float)(getCurrentScalingFactor() * value / 100f));
|
2022-09-18 22:12:16 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateScopeCameraResolution(float value)
|
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
//Logger.LogInfo($"Updating {scopeCamera.name} to {value / 100f}");
|
2022-09-18 22:12:16 +02:00
|
|
|
|
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(value / 100f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateInGameFOVValue(int value)
|
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
//Logger.LogInfo($"Updating in-game FOV value to: {value}");
|
2022-09-19 07:59:29 +02:00
|
|
|
|
Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value = value;
|
2022-09-18 22:12:16 +02:00
|
|
|
|
}
|
2022-09-18 23:54:23 +02:00
|
|
|
|
|
|
|
|
|
void onAimingChanged()
|
2022-09-17 19:49:55 +02:00
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
//Logger.LogInfo($"isAiming: {mainPlayer.HandsController.IsAiming}");
|
|
|
|
|
if (mainPlayer.HandsController.IsAiming)
|
2022-09-17 19:49:55 +02:00
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
//Logger.LogInfo($"Updating MainCamRes to {cameraResolutionScale.Value}");
|
|
|
|
|
updateMainCameraResolution(cameraResolutionScale.Value);
|
|
|
|
|
|
2022-09-18 22:12:16 +02:00
|
|
|
|
switch (scopeFixType.Value)
|
2022-09-17 19:49:55 +02:00
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
case EFOVScalingMode.Disabled:
|
|
|
|
|
{ break; }
|
|
|
|
|
case EFOVScalingMode.Enabled:
|
2022-09-18 22:12:16 +02:00
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
//Logger.LogInfo($"Scopes only! ScopeCamRes: {scopeCameraResolutionScale.Value}");
|
2022-09-18 22:12:16 +02:00
|
|
|
|
if (scopeCamera == null || !scopeCamera.isActiveAndEnabled) break;
|
|
|
|
|
updateScopeCameraResolution(scopeCameraResolutionScale.Value);
|
|
|
|
|
updateInGameFOVValue(50);
|
2022-09-18 23:54:23 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-09-18 22:12:16 +02:00
|
|
|
|
}
|
2022-09-17 19:49:55 +02:00
|
|
|
|
|
2022-09-18 23:54:23 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-09-18 22:12:16 +02:00
|
|
|
|
|
2022-09-18 23:54:23 +02:00
|
|
|
|
if (!mainPlayer.HandsController.IsAiming)
|
|
|
|
|
{
|
|
|
|
|
//Logger.LogWarning($"Restoring default MainCamRes {defaultSSRatio * 100f}");
|
|
|
|
|
updateMainCameraResolution(getCurrentScalingFactor() * 100f);
|
2022-09-17 19:49:55 +02:00
|
|
|
|
|
2022-09-18 23:54:23 +02:00
|
|
|
|
switch (scopeFixType.Value)
|
2022-09-17 19:49:55 +02:00
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
case EFOVScalingMode.Disabled: { break; }
|
|
|
|
|
case EFOVScalingMode.Enabled:
|
|
|
|
|
{
|
|
|
|
|
//Logger.LogInfo($"Restoring FOV to {defaultFOVValue}");
|
|
|
|
|
updateInGameFOVValue(defaultFOVValue);
|
2022-09-19 07:59:29 +02:00
|
|
|
|
GClass1774.Instance.SetFov(defaultFOVValue, 1f, true);
|
2022-09-18 23:54:23 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-09-17 19:49:55 +02:00
|
|
|
|
}
|
2022-09-18 23:54:23 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void subscribeToOnAimingChanged()
|
|
|
|
|
{
|
|
|
|
|
mainPlayer.HandsController.OnAimingChanged += (args) =>
|
|
|
|
|
{
|
|
|
|
|
onAimingChanged();
|
2022-09-17 19:49:55 +02:00
|
|
|
|
};
|
|
|
|
|
}
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
GameStatus lastGameState = GameStatus.Stopped;
|
|
|
|
|
bool gameStateChanged(GameStatus currentState)
|
|
|
|
|
{
|
|
|
|
|
if (lastGameState != currentState)
|
|
|
|
|
{
|
|
|
|
|
lastGameState = currentState;
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo($"GameState changed! {currentState}");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
//Logger.LogInfo("GameState unchanged.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-18 23:54:23 +02:00
|
|
|
|
IEnumerator tryApplyHideoutWorkaround()
|
2022-09-18 22:12:16 +02:00
|
|
|
|
{
|
2022-09-18 23:59:26 +02:00
|
|
|
|
if (Singleton<HideoutPlayer>.Instance != null)
|
2022-09-18 22:12:16 +02:00
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
Singleton<HideoutPlayer>.Instance.HandsChangedEvent += (argsHand) =>
|
2022-09-18 22:12:16 +02:00
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
Singleton<HideoutPlayer>.Instance.HandsController.OnAimingChanged += (argsAim) =>
|
2022-09-18 22:12:16 +02:00
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
onAimingChanged();
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
yield return myDelaySec;
|
|
|
|
|
StartCoroutine(tryApplyHideoutWorkaround());
|
2022-09-18 22:12:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 23:54:23 +02:00
|
|
|
|
Player mainPlayer = null;
|
|
|
|
|
bool doneOnce = false;
|
2022-09-17 19:49:55 +02:00
|
|
|
|
void Update()
|
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
if (Singleton<AbstractGame>.Instance == null)
|
|
|
|
|
{
|
|
|
|
|
doneOnce = false;
|
2022-09-18 23:59:26 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
2022-09-17 19:49:55 +02:00
|
|
|
|
GameStatus currentGameState = Singleton<AbstractGame>.Instance.Status;
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-18 23:54:23 +02:00
|
|
|
|
if (currentGameState == GameStatus.Started && mainPlayer != null && mainPlayer.GetType() == typeof(HideoutPlayer) && !doneOnce)
|
2022-09-15 21:14:26 +02:00
|
|
|
|
{
|
2022-09-18 23:54:23 +02:00
|
|
|
|
//Logger.LogInfo("Hideout workaround");
|
|
|
|
|
doneOnce = true;
|
|
|
|
|
StartCoroutine(tryApplyHideoutWorkaround());
|
2022-09-17 19:49:55 +02:00
|
|
|
|
}
|
2022-09-16 10:29:54 +02:00
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
if (!gameStateChanged(currentGameState)) return;
|
2022-09-15 21:14:26 +02:00
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
if ((currentGameState == GameStatus.SoftStopping || currentGameState == GameStatus.Stopped))
|
|
|
|
|
{
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("Game is stopping, resetting stuffs for the next raid");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
mainPlayer = null;
|
|
|
|
|
return;
|
2022-09-15 21:14:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
if (currentGameState == GameStatus.Started)
|
2022-09-08 21:29:16 +02:00
|
|
|
|
{
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("Getting local player");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
mainPlayer = utils.getLocalPlayer();
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("setUpCameras()");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
setUpCameras();
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-18 23:54:23 +02:00
|
|
|
|
//Logger.LogInfo("Grab default FOV from settings singleton");
|
2022-09-19 07:59:29 +02:00
|
|
|
|
defaultFOVValue = Singleton<GClass1642>.Instance.Game.Settings.FieldOfView;
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-18 23:54:23 +02:00
|
|
|
|
mainPlayer.HandsChangedEvent += (args) =>
|
|
|
|
|
{
|
|
|
|
|
//Logger.LogInfo($"Hands changed! {args.Item.Name} Subscribing again...");
|
|
|
|
|
subscribeToOnAimingChanged();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-08 21:29:16 +02:00
|
|
|
|
|
2022-09-18 23:54:23 +02:00
|
|
|
|
float getCurrentScalingFactor()
|
|
|
|
|
{
|
2022-09-19 07:59:29 +02:00
|
|
|
|
var graphics = Singleton<GClass1642>.Instance.Graphics.Settings;
|
2022-09-18 23:54:23 +02:00
|
|
|
|
|
|
|
|
|
if (!graphics.DLSSEnabled && !graphics.FSREnabled)
|
|
|
|
|
{
|
|
|
|
|
//Logger.LogInfo($"Supersampling factor: {graphics.SuperSamplingFactor}");
|
|
|
|
|
return graphics.SuperSamplingFactor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
//Logger.LogInfo($"DLSS factor: {DLSSFactor}");
|
|
|
|
|
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; }
|
|
|
|
|
}
|
|
|
|
|
//Logger.LogInfo($"FSR factor: {FSRFactor}");
|
|
|
|
|
return FSRFactor;
|
2022-09-08 21:29:16 +02:00
|
|
|
|
}
|
2022-09-18 23:54:23 +02:00
|
|
|
|
|
|
|
|
|
Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f");
|
|
|
|
|
return 1.0f;
|
2022-09-08 21:29:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|