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 22:12:16 +02:00
|
|
|
|
using EFT.UI;
|
|
|
|
|
using EFT.Animations;
|
|
|
|
|
using System.ComponentModel;
|
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-17 20:08:36 +02:00
|
|
|
|
[BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "1.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 22:12:16 +02:00
|
|
|
|
[Description("Only affect scopes")]
|
|
|
|
|
ScopesOnly,
|
|
|
|
|
[Description("Affect all sights")]
|
|
|
|
|
All
|
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-18 22:12:16 +02:00
|
|
|
|
scopeFixType = Config.Bind("General", "Disable ADS FOV scaling", EFOVScalingMode.ScopesOnly, 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
|
|
|
|
float defaultSSRatio = 1.0f;
|
|
|
|
|
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 _currentSSRatio = null;
|
|
|
|
|
FieldInfo _nextSSRation = null;
|
2022-09-16 10:29:54 +02:00
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
int defaultFOVValue = 50;
|
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");
|
|
|
|
|
_currentSSRatio = scopeRes.getFieldInfo("_currentSSRatio");
|
2022-09-15 21:14:26 +02:00
|
|
|
|
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo($"Updating defaultSSRatio to {_nextSSRation.GetValue(ssaaInstance)}");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance);
|
|
|
|
|
}
|
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)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInfo($"Updating {Camera.main.name} SSRatio to {value / 100f}");
|
|
|
|
|
_nextSSRation.SetValue(ssaaInstance, (float)(defaultSSRatio * value / 100f));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateScopeCameraResolution(float value)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInfo($"Updating {scopeCamera.name} to {value / 100f}");
|
|
|
|
|
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(value / 100f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void updateInGameFOVValue(int value)
|
|
|
|
|
{
|
|
|
|
|
Logger.LogInfo($"Updating in-game FOV value to: {value}");
|
|
|
|
|
Singleton<GClass1630>.Instance.Game.Settings.FieldOfView.Value = value;
|
|
|
|
|
}
|
2022-09-17 19:49:55 +02:00
|
|
|
|
void subscribeToOnAimingChanged()
|
|
|
|
|
{
|
|
|
|
|
mainPlayer.HandsController.OnAimingChanged += (args) =>
|
|
|
|
|
{
|
2022-09-18 22:12:16 +02:00
|
|
|
|
switch (scopeFixType.Value)
|
2022-09-17 19:49:55 +02:00
|
|
|
|
{
|
2022-09-18 22:12:16 +02:00
|
|
|
|
case EFOVScalingMode.Disabled: { break; }
|
|
|
|
|
case EFOVScalingMode.ScopesOnly:
|
|
|
|
|
{
|
|
|
|
|
if (scopeCamera == null || !scopeCamera.isActiveAndEnabled) break;
|
|
|
|
|
updateScopeCameraResolution(scopeCameraResolutionScale.Value);
|
|
|
|
|
updateInGameFOVValue(50);
|
|
|
|
|
break; }
|
|
|
|
|
case EFOVScalingMode.All:
|
|
|
|
|
{
|
|
|
|
|
updateScopeCameraResolution(scopeCameraResolutionScale.Value);
|
|
|
|
|
updateInGameFOVValue(50);
|
|
|
|
|
break; }
|
|
|
|
|
}
|
2022-09-17 19:49:55 +02:00
|
|
|
|
|
2022-09-18 22:12:16 +02:00
|
|
|
|
|
|
|
|
|
if (mainPlayer.HandsController.IsAiming)
|
|
|
|
|
{
|
|
|
|
|
updateMainCameraResolution(cameraResolutionScale.Value);
|
2022-09-17 19:49:55 +02:00
|
|
|
|
if (scopeCamera != null && scopeCamera.isActiveAndEnabled)
|
|
|
|
|
{
|
2022-09-18 22:12:16 +02:00
|
|
|
|
updateScopeCameraResolution(scopeCameraResolutionScale.Value);
|
|
|
|
|
updateInGameFOVValue(50);
|
2022-09-17 19:49:55 +02:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mainPlayer.HandsController.IsAiming)
|
|
|
|
|
{
|
2022-09-18 22:12:16 +02:00
|
|
|
|
updateMainCameraResolution(defaultSSRatio);
|
|
|
|
|
updateInGameFOVValue(defaultFOVValue);
|
|
|
|
|
GClass1762.Instance.SetFov(defaultFOVValue, 1f, true);
|
2022-09-17 19:49:55 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
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-17 19:49:55 +02:00
|
|
|
|
Player mainPlayer = null;
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-18 22:12:16 +02:00
|
|
|
|
void hideoutWorkaround()
|
|
|
|
|
{
|
|
|
|
|
if (mainPlayer.HandsController.IsAiming)
|
|
|
|
|
{
|
|
|
|
|
if (mainPlayer.HandsController.IsAiming)
|
|
|
|
|
{
|
|
|
|
|
updateMainCameraResolution(cameraResolutionScale.Value);
|
|
|
|
|
if (scopeCamera != null && scopeCamera.isActiveAndEnabled)
|
|
|
|
|
{
|
|
|
|
|
updateScopeCameraResolution(scopeCameraResolutionScale.Value);
|
|
|
|
|
updateInGameFOVValue(50);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mainPlayer.HandsController.IsAiming)
|
|
|
|
|
{
|
|
|
|
|
updateMainCameraResolution(defaultSSRatio);
|
|
|
|
|
|
|
|
|
|
updateInGameFOVValue(defaultFOVValue);
|
|
|
|
|
GClass1762.Instance.SetFov(defaultFOVValue, 1f, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
void Update()
|
|
|
|
|
{
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-17 19:49:55 +02:00
|
|
|
|
if (Singleton<AbstractGame>.Instance == null) return;
|
|
|
|
|
GameStatus currentGameState = Singleton<AbstractGame>.Instance.Status;
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-18 22:12:16 +02:00
|
|
|
|
if (currentGameState == GameStatus.Started && mainPlayer != null && mainPlayer.GetType() == typeof(HideoutPlayer))
|
2022-09-15 21:14:26 +02:00
|
|
|
|
{
|
2022-09-18 22:12:16 +02:00
|
|
|
|
switch(scopeFixType.Value)
|
2022-09-17 19:49:55 +02:00
|
|
|
|
{
|
2022-09-18 22:12:16 +02:00
|
|
|
|
case EFOVScalingMode.Disabled: { break; }
|
|
|
|
|
default: { hideoutWorkaround(); break; }
|
2022-09-17 19:49:55 +02:00
|
|
|
|
}
|
2022-09-18 22:12:16 +02:00
|
|
|
|
|
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-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo($"Returned: {mainPlayer.GetType()}");
|
2022-09-15 21:14:26 +02:00
|
|
|
|
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("Updating default FOV value");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
if (defaultFOVValue != Camera.main.fieldOfView) { defaultFOVValue = (int)Camera.main.fieldOfView; }
|
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-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("UpdateSSRatio()");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
defaultSSRatio = (float)_nextSSRation.GetValue(ssaaInstance);
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo($"Updating defaultSSRatio to {defaultSSRatio}");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
//updateSSRatio();
|
2022-09-16 13:24:26 +02:00
|
|
|
|
|
2022-09-17 20:08:36 +02:00
|
|
|
|
//Logger.LogInfo("subscibeToOnAimingChanged()");
|
2022-09-17 19:49:55 +02:00
|
|
|
|
subscribeToOnAimingChanged();
|
2022-09-08 21:29:16 +02:00
|
|
|
|
|
2022-09-18 22:12:16 +02:00
|
|
|
|
defaultFOVValue = Singleton<GClass1630>.Instance.Game.Settings.FieldOfView;
|
2022-09-11 18:48:53 +02:00
|
|
|
|
return;
|
2022-09-08 21:29:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|