2.0.0-RC1
This commit is contained in:
parent
3a0497140b
commit
804e4643f4
@ -12,9 +12,6 @@ namespace ScopeTweaks
|
|||||||
[BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "2.0.0")]
|
[BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "2.0.0")]
|
||||||
public class Plugin : BaseUnityPlugin
|
public class Plugin : BaseUnityPlugin
|
||||||
{
|
{
|
||||||
Utils utils = new Utils();
|
|
||||||
CameraUtils scopeRes = new CameraUtils();
|
|
||||||
|
|
||||||
ConfigEntry<int> cameraResolutionScale;
|
ConfigEntry<int> cameraResolutionScale;
|
||||||
ConfigEntry<int> scopeCameraResolutionScale;
|
ConfigEntry<int> scopeCameraResolutionScale;
|
||||||
ConfigEntry<EFOVScalingMode> scopeFixType;
|
ConfigEntry<EFOVScalingMode> scopeFixType;
|
||||||
@ -31,12 +28,12 @@ namespace ScopeTweaks
|
|||||||
"General",
|
"General",
|
||||||
"Main camera scale %",
|
"Main camera scale %",
|
||||||
80,
|
80,
|
||||||
new ConfigDescription("Main camera resolution scale", new AcceptableValueRange<int>(50, 100)));
|
new ConfigDescription("Main camera resolution scale", new AcceptableValueRange<int>(25, 100)));
|
||||||
|
|
||||||
scopeCameraResolutionScale = Config.Bind(
|
scopeCameraResolutionScale = Config.Bind(
|
||||||
"General",
|
"General",
|
||||||
"Scope camera scale %",
|
"Scope camera scale %",
|
||||||
40,
|
80,
|
||||||
new ConfigDescription("Scope camera resolution scale", new AcceptableValueRange<int>(25, 100)));
|
new ConfigDescription("Scope camera resolution scale", new AcceptableValueRange<int>(25, 100)));
|
||||||
|
|
||||||
scopeFixType = Config.Bind("General", "High FOV scope tweak", EFOVScalingMode.Enabled, new ConfigDescription(""));
|
scopeFixType = Config.Bind("General", "High FOV scope tweak", EFOVScalingMode.Enabled, new ConfigDescription(""));
|
||||||
@ -47,203 +44,185 @@ namespace ScopeTweaks
|
|||||||
|
|
||||||
SSAA ssaaInstance = null;
|
SSAA ssaaInstance = null;
|
||||||
FieldInfo _nextSSRation = null;
|
FieldInfo _nextSSRation = null;
|
||||||
|
WaitForSeconds myDelaySec = new WaitForSeconds(1);
|
||||||
|
|
||||||
int defaultFOVValue;
|
void Update()
|
||||||
|
|
||||||
void setUpCameras()
|
|
||||||
{
|
{
|
||||||
//Logger.LogInfo("Game started!");
|
if (Singleton<AbstractGame>.Instance == null) return;
|
||||||
|
GameStatus currentGameState = Singleton<AbstractGame>.Instance.Status;
|
||||||
|
|
||||||
//Logger.LogInfo("Get FPS Camera");
|
if (!gameStateChanged(currentGameState)) return;
|
||||||
|
|
||||||
|
switch(currentGameState)
|
||||||
|
{
|
||||||
|
case GameStatus.Started:
|
||||||
|
{
|
||||||
|
//Logger.LogInfo("Getting local player");
|
||||||
|
mainPlayer = getLocalPlayer();
|
||||||
|
|
||||||
|
subscribeHandsChangedEvent();
|
||||||
|
|
||||||
|
//Logger.LogInfo("Assigning cameras...");
|
||||||
StartCoroutine(tryGetMainCamera());
|
StartCoroutine(tryGetMainCamera());
|
||||||
|
|
||||||
//Logger.LogInfo("Get Scope Camera");
|
|
||||||
StartCoroutine(tryGetScopeCamera());
|
StartCoroutine(tryGetScopeCamera());
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GameStatus.SoftStopping:
|
||||||
|
case GameStatus.Stopped:
|
||||||
|
{
|
||||||
|
//Logger.LogInfo("Resetting...");
|
||||||
|
FPSCamera = null;
|
||||||
|
scopeCamera = null;
|
||||||
|
mainPlayer = null;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WaitForSeconds myDelaySec = new WaitForSeconds(1);
|
/// <summary>
|
||||||
|
/// GAME STATUS
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
GameStatus lastGameState;
|
||||||
|
bool gameStateChanged(GameStatus currentState)
|
||||||
|
{
|
||||||
|
if (currentState == lastGameState) return false;
|
||||||
|
lastGameState = currentState;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player mainPlayer;
|
||||||
|
Player getLocalPlayer()
|
||||||
|
{
|
||||||
|
return Singleton<GameWorld>.Instance.RegisteredPlayers.Find(p => p.IsYourPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// FIELD OF VIEW
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
|
int inGameFOV;
|
||||||
|
int getInGameFOV()
|
||||||
|
{
|
||||||
|
int fov = Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value;
|
||||||
|
//Logger.LogInfo($"In-game FOV: {fov}");
|
||||||
|
return fov;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setInGameFOV(int value)
|
||||||
|
{
|
||||||
|
//Logger.LogInfo($"Setting FOV to {value}");
|
||||||
|
Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CAMERA SETUP
|
||||||
|
/// </summary>
|
||||||
|
|
||||||
IEnumerator tryGetMainCamera()
|
IEnumerator tryGetMainCamera()
|
||||||
{
|
{
|
||||||
if (scopeRes.getMainCamera() == null)
|
string cameraName = "FPS Camera";
|
||||||
|
if (GameObject.Find(cameraName) != null)
|
||||||
{
|
{
|
||||||
|
FPSCamera = GameObject.Find(cameraName).GetComponent<Camera>();
|
||||||
|
//Logger.LogInfo($"{FPSCamera.name} found!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Logger.LogMessage($"Camera \"{cameraName}\" not found, rescheduling...");
|
||||||
yield return myDelaySec;
|
yield return myDelaySec;
|
||||||
StartCoroutine(tryGetMainCamera());
|
StartCoroutine(tryGetMainCamera());
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
FPSCamera = scopeRes.getMainCamera();
|
yield return null;
|
||||||
defaultFOVValue = (int)FPSCamera.fieldOfView;
|
}
|
||||||
|
|
||||||
//Logger.LogInfo("Get SSAAInstance (Camera)");
|
FieldInfo getFieldInfo(string fieldName)
|
||||||
ssaaInstance = scopeRes.getSSAAInstance(FPSCamera);
|
{
|
||||||
|
return typeof(SSAA).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
//Logger.LogInfo("Set SSRatios");
|
|
||||||
_nextSSRation = scopeRes.getFieldInfo("_nextSSRation");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerator tryGetScopeCamera()
|
IEnumerator tryGetScopeCamera()
|
||||||
{
|
{
|
||||||
if (scopeRes.getScopeCamera() == null)
|
string cameraName = "BaseOpticCamera(Clone)";
|
||||||
|
if (GameObject.Find(cameraName) != null)
|
||||||
{
|
{
|
||||||
//Logger.LogInfo("ScopeCamera not found! Restarting...");
|
scopeCamera = GameObject.Find(cameraName).GetComponent<Camera>();
|
||||||
yield return myDelaySec;
|
//Logger.LogInfo($"Camera \"{scopeCamera.name}\" found!");
|
||||||
StartCoroutine(tryGetScopeCamera());
|
}
|
||||||
yield break;
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Logger.LogInfo("Assigning scopeCamera");
|
void setMainCameraResolutionScale(int value = 100)
|
||||||
scopeCamera = scopeRes.getScopeCamera();
|
{
|
||||||
|
//Logger.LogInfo($"Setting MainCam res scale to {value}%");
|
||||||
|
ssaaInstance = FPSCamera.GetComponent<SSAA>();
|
||||||
|
_nextSSRation = getFieldInfo("_nextSSRation");
|
||||||
|
_nextSSRation.SetValue(ssaaInstance, (float)(currentScalingFactor * value / 100f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateMainCameraResolution(float value)
|
void setScopeCameraResolutionScale(int value)
|
||||||
{
|
{
|
||||||
//Logger.LogInfo($"Updating {Camera.main.name} SSRatio to {value / 100f}");
|
if(scopeCamera == null || !scopeCamera.isActiveAndEnabled)
|
||||||
_nextSSRation.SetValue(ssaaInstance, (float)(getCurrentScalingFactor() * value / 100f));
|
{ //Logger.LogInfo("ScopeCam inactive or absent!");
|
||||||
|
return; }
|
||||||
|
|
||||||
|
//Logger.LogInfo($"Setting Scope res scale to {value}%");
|
||||||
|
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * value / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateScopeCameraResolution(float value)
|
/// <summary>
|
||||||
|
/// PLAYER WEAPON EVENTS
|
||||||
|
/// </summary>
|
||||||
|
void subscribeHandsChangedEvent()
|
||||||
{
|
{
|
||||||
//Logger.LogInfo($"Updating {scopeCamera.name} to {value / 100f}");
|
//Logger.LogInfo("Subscribing to HandsChanged Event");
|
||||||
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(value / 100f);
|
mainPlayer.HandsChangedEvent += (handsArgs) =>
|
||||||
|
{
|
||||||
|
subscribeOnAimingChangedEvent();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateInGameFOVValue(int value)
|
void subscribeOnAimingChangedEvent()
|
||||||
{
|
{
|
||||||
//Logger.LogInfo($"Updating in-game FOV value to: {value}");
|
//Logger.LogInfo("Subscribing to OnAimingChanged Event");
|
||||||
Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value = value;
|
mainPlayer.HandsController.OnAimingChanged += (aimingArgs) =>
|
||||||
|
{
|
||||||
|
if (scopeFixType.Value != EFOVScalingMode.Enabled) return;
|
||||||
|
if(!mainPlayer.ProceduralWeaponAnimation.IsAiming)
|
||||||
|
{
|
||||||
|
GClass1774.Instance.SetFov(inGameFOV, 0.33f, false);
|
||||||
|
setInGameFOV(inGameFOV);
|
||||||
}
|
}
|
||||||
|
setMainCameraResolutionScale();
|
||||||
|
|
||||||
void onAimingChanged()
|
currentScalingFactor = getCurrentScalingFactor();
|
||||||
{
|
StartCoroutine(tryGetScopeCamera());
|
||||||
//Logger.LogInfo($"isAiming: {mainPlayer.HandsController.IsAiming}");
|
|
||||||
if(mainPlayer.HandsController.IsAiming)
|
if(mainPlayer.HandsController.IsAiming)
|
||||||
{
|
{
|
||||||
//Logger.LogInfo($"Updating MainCamRes to {cameraResolutionScale.Value}");
|
if(inGameFOV != 50) { inGameFOV = getInGameFOV(); }
|
||||||
updateMainCameraResolution(cameraResolutionScale.Value);
|
|
||||||
|
|
||||||
switch (scopeFixType.Value)
|
GClass1774.Instance.SetFov(35, 0.25f, false);
|
||||||
{
|
setInGameFOV(50);
|
||||||
case EFOVScalingMode.Disabled:
|
|
||||||
{ break; }
|
|
||||||
case EFOVScalingMode.Enabled:
|
|
||||||
{
|
|
||||||
//Logger.LogInfo($"Scopes only! ScopeCamRes: {scopeCameraResolutionScale.Value}");
|
|
||||||
if (scopeCamera == null || !scopeCamera.isActiveAndEnabled) break;
|
|
||||||
updateScopeCameraResolution(scopeCameraResolutionScale.Value);
|
|
||||||
updateInGameFOVValue(50);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
setMainCameraResolutionScale(cameraResolutionScale.Value);
|
||||||
|
setScopeCameraResolutionScale(scopeCameraResolutionScale.Value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mainPlayer.HandsController.IsAiming)
|
|
||||||
{
|
|
||||||
//Logger.LogWarning($"Restoring default MainCamRes {defaultSSRatio * 100f}");
|
|
||||||
updateMainCameraResolution(getCurrentScalingFactor() * 100f);
|
|
||||||
|
|
||||||
switch (scopeFixType.Value)
|
|
||||||
{
|
|
||||||
case EFOVScalingMode.Disabled: { break; }
|
|
||||||
case EFOVScalingMode.Enabled:
|
|
||||||
{
|
|
||||||
//Logger.LogInfo($"Restoring FOV to {defaultFOVValue}");
|
|
||||||
updateInGameFOVValue(defaultFOVValue);
|
|
||||||
GClass1774.Instance.SetFov(defaultFOVValue, 1f, true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void subscribeToOnAimingChanged()
|
|
||||||
{
|
|
||||||
mainPlayer.HandsController.OnAimingChanged += (args) =>
|
|
||||||
{
|
|
||||||
onAimingChanged();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
GameStatus lastGameState = GameStatus.Stopped;
|
/// <summary>
|
||||||
bool gameStateChanged(GameStatus currentState)
|
/// IN-GAME SETTINGS
|
||||||
{
|
/// </summary>
|
||||||
if (lastGameState != currentState)
|
|
||||||
{
|
|
||||||
lastGameState = currentState;
|
|
||||||
//Logger.LogInfo($"GameState changed! {currentState}");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//Logger.LogInfo("GameState unchanged.");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator tryApplyHideoutWorkaround()
|
float currentScalingFactor;
|
||||||
{
|
|
||||||
if (Singleton<HideoutPlayer>.Instance != null)
|
|
||||||
{
|
|
||||||
Singleton<HideoutPlayer>.Instance.HandsChangedEvent += (argsHand) =>
|
|
||||||
{
|
|
||||||
Singleton<HideoutPlayer>.Instance.HandsController.OnAimingChanged += (argsAim) =>
|
|
||||||
{
|
|
||||||
onAimingChanged();
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
yield return myDelaySec;
|
|
||||||
StartCoroutine(tryApplyHideoutWorkaround());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Player mainPlayer = null;
|
|
||||||
bool doneOnce = false;
|
|
||||||
void Update()
|
|
||||||
{
|
|
||||||
if (Singleton<AbstractGame>.Instance == null)
|
|
||||||
{
|
|
||||||
doneOnce = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
GameStatus currentGameState = Singleton<AbstractGame>.Instance.Status;
|
|
||||||
|
|
||||||
if (currentGameState == GameStatus.Started && mainPlayer != null && mainPlayer.GetType() == typeof(HideoutPlayer) && !doneOnce)
|
|
||||||
{
|
|
||||||
//Logger.LogInfo("Hideout workaround");
|
|
||||||
doneOnce = true;
|
|
||||||
StartCoroutine(tryApplyHideoutWorkaround());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!gameStateChanged(currentGameState)) return;
|
|
||||||
|
|
||||||
if ((currentGameState == GameStatus.SoftStopping || currentGameState == GameStatus.Stopped))
|
|
||||||
{
|
|
||||||
//Logger.LogInfo("Game is stopping, resetting stuffs for the next raid");
|
|
||||||
mainPlayer = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (currentGameState == GameStatus.Started)
|
|
||||||
{
|
|
||||||
//Logger.LogInfo("Getting local player");
|
|
||||||
mainPlayer = utils.getLocalPlayer();
|
|
||||||
|
|
||||||
//Logger.LogInfo("setUpCameras()");
|
|
||||||
setUpCameras();
|
|
||||||
|
|
||||||
//Logger.LogInfo("Grab default FOV from settings singleton");
|
|
||||||
defaultFOVValue = Singleton<GClass1642>.Instance.Game.Settings.FieldOfView;
|
|
||||||
|
|
||||||
mainPlayer.HandsChangedEvent += (args) =>
|
|
||||||
{
|
|
||||||
//Logger.LogInfo($"Hands changed! {args.Item.Name} Subscribing again...");
|
|
||||||
subscribeToOnAimingChanged();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float getCurrentScalingFactor()
|
float getCurrentScalingFactor()
|
||||||
{
|
{
|
||||||
|
//Logger.LogInfo("Getting current scaling factor:");
|
||||||
var graphics = Singleton<GClass1642>.Instance.Graphics.Settings;
|
var graphics = Singleton<GClass1642>.Instance.Graphics.Settings;
|
||||||
|
|
||||||
if (!graphics.DLSSEnabled && !graphics.FSREnabled)
|
if (!graphics.DLSSEnabled && !graphics.FSREnabled)
|
||||||
@ -281,7 +260,7 @@ namespace ScopeTweaks
|
|||||||
return FSRFactor;
|
return FSRFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f");
|
//Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f");
|
||||||
return 1.0f;
|
return 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
namespace ScopeTweaks
|
|
||||||
{
|
|
||||||
public class CameraUtils
|
|
||||||
{
|
|
||||||
public Camera getMainCamera()
|
|
||||||
{
|
|
||||||
Camera fpsCamera = GameObject.Find("FPS Camera").GetComponent<Camera>();
|
|
||||||
if (fpsCamera != null && fpsCamera.isActiveAndEnabled) return fpsCamera;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Camera getScopeCamera()
|
|
||||||
{
|
|
||||||
if (Camera.allCamerasCount <= 1) return null;
|
|
||||||
string scopeCamName = "BaseOpticCamera(Clone)";
|
|
||||||
if (GameObject.Find(scopeCamName) == null) return null;
|
|
||||||
Camera scopeCamera = GameObject.Find("BaseOpticCamera(Clone)").GetComponent<Camera>();
|
|
||||||
if (scopeCamera != null && scopeCamera.isActiveAndEnabled) return scopeCamera;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public SSAA getSSAAInstance(Camera camera)
|
|
||||||
{
|
|
||||||
return camera.GetComponent<SSAA>();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public FieldInfo getFieldInfo(string fieldName)
|
|
||||||
{
|
|
||||||
return typeof(SSAA).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
using Comfort.Common;
|
|
||||||
using EFT;
|
|
||||||
|
|
||||||
namespace ScopeTweaks
|
|
||||||
{
|
|
||||||
public class Utils
|
|
||||||
{
|
|
||||||
public bool gameIsReady()
|
|
||||||
{
|
|
||||||
var gameWorld = Singleton<GameWorld>.Instance;
|
|
||||||
var sessionResultPanel = Singleton<SessionResultPanel>.Instance;
|
|
||||||
|
|
||||||
if (gameWorld == null
|
|
||||||
|| gameWorld.AllPlayers == null
|
|
||||||
|| gameWorld.AllPlayers.Count <= 0
|
|
||||||
|| sessionResultPanel != null)
|
|
||||||
{ return false; }
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Player getLocalPlayer()
|
|
||||||
{
|
|
||||||
return Singleton<GameWorld>.Instance.RegisteredPlayers.Find(p => p.IsYourPlayer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -70,8 +70,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Plugin.cs" />
|
<Compile Include="Plugin.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="UpdateScopeResolution.cs" />
|
|
||||||
<Compile Include="Utils.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user