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")]
|
||||
public class Plugin : BaseUnityPlugin
|
||||
{
|
||||
Utils utils = new Utils();
|
||||
CameraUtils scopeRes = new CameraUtils();
|
||||
|
||||
ConfigEntry<int> cameraResolutionScale;
|
||||
ConfigEntry<int> scopeCameraResolutionScale;
|
||||
ConfigEntry<EFOVScalingMode> scopeFixType;
|
||||
@ -31,12 +28,12 @@ namespace ScopeTweaks
|
||||
"General",
|
||||
"Main camera scale %",
|
||||
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(
|
||||
"General",
|
||||
"Scope camera scale %",
|
||||
40,
|
||||
80,
|
||||
new ConfigDescription("Scope camera resolution scale", new AcceptableValueRange<int>(25, 100)));
|
||||
|
||||
scopeFixType = Config.Bind("General", "High FOV scope tweak", EFOVScalingMode.Enabled, new ConfigDescription(""));
|
||||
@ -47,203 +44,185 @@ namespace ScopeTweaks
|
||||
|
||||
SSAA ssaaInstance = null;
|
||||
FieldInfo _nextSSRation = null;
|
||||
WaitForSeconds myDelaySec = new WaitForSeconds(1);
|
||||
|
||||
int defaultFOVValue;
|
||||
|
||||
void setUpCameras()
|
||||
void Update()
|
||||
{
|
||||
//Logger.LogInfo("Game started!");
|
||||
if (Singleton<AbstractGame>.Instance == null) return;
|
||||
GameStatus currentGameState = Singleton<AbstractGame>.Instance.Status;
|
||||
|
||||
//Logger.LogInfo("Get FPS Camera");
|
||||
StartCoroutine(tryGetMainCamera());
|
||||
if (!gameStateChanged(currentGameState)) return;
|
||||
|
||||
//Logger.LogInfo("Get Scope Camera");
|
||||
StartCoroutine(tryGetScopeCamera());
|
||||
switch(currentGameState)
|
||||
{
|
||||
case GameStatus.Started:
|
||||
{
|
||||
//Logger.LogInfo("Getting local player");
|
||||
mainPlayer = getLocalPlayer();
|
||||
|
||||
subscribeHandsChangedEvent();
|
||||
|
||||
//Logger.LogInfo("Assigning cameras...");
|
||||
StartCoroutine(tryGetMainCamera());
|
||||
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()
|
||||
{
|
||||
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;
|
||||
StartCoroutine(tryGetMainCamera());
|
||||
yield break;
|
||||
}
|
||||
FPSCamera = scopeRes.getMainCamera();
|
||||
defaultFOVValue = (int)FPSCamera.fieldOfView;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
//Logger.LogInfo("Get SSAAInstance (Camera)");
|
||||
ssaaInstance = scopeRes.getSSAAInstance(FPSCamera);
|
||||
|
||||
//Logger.LogInfo("Set SSRatios");
|
||||
_nextSSRation = scopeRes.getFieldInfo("_nextSSRation");
|
||||
FieldInfo getFieldInfo(string fieldName)
|
||||
{
|
||||
return typeof(SSAA).GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
}
|
||||
|
||||
IEnumerator tryGetScopeCamera()
|
||||
{
|
||||
if (scopeRes.getScopeCamera() == null)
|
||||
string cameraName = "BaseOpticCamera(Clone)";
|
||||
if (GameObject.Find(cameraName) != null)
|
||||
{
|
||||
//Logger.LogInfo("ScopeCamera not found! Restarting...");
|
||||
yield return myDelaySec;
|
||||
StartCoroutine(tryGetScopeCamera());
|
||||
yield break;
|
||||
scopeCamera = GameObject.Find(cameraName).GetComponent<Camera>();
|
||||
//Logger.LogInfo($"Camera \"{scopeCamera.name}\" found!");
|
||||
}
|
||||
|
||||
//Logger.LogInfo("Assigning scopeCamera");
|
||||
scopeCamera = scopeRes.getScopeCamera();
|
||||
yield break;
|
||||
}
|
||||
|
||||
void updateMainCameraResolution(float value)
|
||||
void setMainCameraResolutionScale(int value = 100)
|
||||
{
|
||||
//Logger.LogInfo($"Updating {Camera.main.name} SSRatio to {value / 100f}");
|
||||
_nextSSRation.SetValue(ssaaInstance, (float)(getCurrentScalingFactor() * value / 100f));
|
||||
//Logger.LogInfo($"Setting MainCam res scale to {value}%");
|
||||
ssaaInstance = FPSCamera.GetComponent<SSAA>();
|
||||
_nextSSRation = getFieldInfo("_nextSSRation");
|
||||
_nextSSRation.SetValue(ssaaInstance, (float)(currentScalingFactor * value / 100f));
|
||||
}
|
||||
|
||||
void updateScopeCameraResolution(float value)
|
||||
void setScopeCameraResolutionScale(int value)
|
||||
{
|
||||
//Logger.LogInfo($"Updating {scopeCamera.name} to {value / 100f}");
|
||||
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(value / 100f);
|
||||
if(scopeCamera == null || !scopeCamera.isActiveAndEnabled)
|
||||
{ //Logger.LogInfo("ScopeCam inactive or absent!");
|
||||
return; }
|
||||
|
||||
//Logger.LogInfo($"Setting Scope res scale to {value}%");
|
||||
scopeCamera.GetComponent<SSAAOptic>().OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * value / 100);
|
||||
}
|
||||
|
||||
void updateInGameFOVValue(int value)
|
||||
/// <summary>
|
||||
/// PLAYER WEAPON EVENTS
|
||||
/// </summary>
|
||||
void subscribeHandsChangedEvent()
|
||||
{
|
||||
//Logger.LogInfo($"Updating in-game FOV value to: {value}");
|
||||
Singleton<GClass1642>.Instance.Game.Settings.FieldOfView.Value = value;
|
||||
}
|
||||
|
||||
void onAimingChanged()
|
||||
{
|
||||
//Logger.LogInfo($"isAiming: {mainPlayer.HandsController.IsAiming}");
|
||||
if (mainPlayer.HandsController.IsAiming)
|
||||
//Logger.LogInfo("Subscribing to HandsChanged Event");
|
||||
mainPlayer.HandsChangedEvent += (handsArgs) =>
|
||||
{
|
||||
//Logger.LogInfo($"Updating MainCamRes to {cameraResolutionScale.Value}");
|
||||
updateMainCameraResolution(cameraResolutionScale.Value);
|
||||
|
||||
switch (scopeFixType.Value)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
subscribeOnAimingChangedEvent();
|
||||
};
|
||||
}
|
||||
|
||||
GameStatus lastGameState = GameStatus.Stopped;
|
||||
bool gameStateChanged(GameStatus currentState)
|
||||
void subscribeOnAimingChangedEvent()
|
||||
{
|
||||
if (lastGameState != currentState)
|
||||
//Logger.LogInfo("Subscribing to OnAimingChanged Event");
|
||||
mainPlayer.HandsController.OnAimingChanged += (aimingArgs) =>
|
||||
{
|
||||
lastGameState = currentState;
|
||||
//Logger.LogInfo($"GameState changed! {currentState}");
|
||||
return true;
|
||||
}
|
||||
//Logger.LogInfo("GameState unchanged.");
|
||||
return false;
|
||||
}
|
||||
|
||||
IEnumerator tryApplyHideoutWorkaround()
|
||||
{
|
||||
if (Singleton<HideoutPlayer>.Instance != null)
|
||||
{
|
||||
Singleton<HideoutPlayer>.Instance.HandsChangedEvent += (argsHand) =>
|
||||
if (scopeFixType.Value != EFOVScalingMode.Enabled) return;
|
||||
if(!mainPlayer.ProceduralWeaponAnimation.IsAiming)
|
||||
{
|
||||
Singleton<HideoutPlayer>.Instance.HandsController.OnAimingChanged += (argsAim) =>
|
||||
{
|
||||
onAimingChanged();
|
||||
};
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return myDelaySec;
|
||||
StartCoroutine(tryApplyHideoutWorkaround());
|
||||
}
|
||||
}
|
||||
GClass1774.Instance.SetFov(inGameFOV, 0.33f, false);
|
||||
setInGameFOV(inGameFOV);
|
||||
}
|
||||
setMainCameraResolutionScale();
|
||||
|
||||
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) =>
|
||||
currentScalingFactor = getCurrentScalingFactor();
|
||||
StartCoroutine(tryGetScopeCamera());
|
||||
if(mainPlayer.HandsController.IsAiming)
|
||||
{
|
||||
//Logger.LogInfo($"Hands changed! {args.Item.Name} Subscribing again...");
|
||||
subscribeToOnAimingChanged();
|
||||
};
|
||||
}
|
||||
if(inGameFOV != 50) { inGameFOV = getInGameFOV(); }
|
||||
|
||||
GClass1774.Instance.SetFov(35, 0.25f, false);
|
||||
setInGameFOV(50);
|
||||
|
||||
setMainCameraResolutionScale(cameraResolutionScale.Value);
|
||||
setScopeCameraResolutionScale(scopeCameraResolutionScale.Value);
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IN-GAME SETTINGS
|
||||
/// </summary>
|
||||
|
||||
float currentScalingFactor;
|
||||
|
||||
float getCurrentScalingFactor()
|
||||
{
|
||||
//Logger.LogInfo("Getting current scaling factor:");
|
||||
var graphics = Singleton<GClass1642>.Instance.Graphics.Settings;
|
||||
|
||||
if (!graphics.DLSSEnabled && !graphics.FSREnabled)
|
||||
@ -281,8 +260,8 @@ namespace ScopeTweaks
|
||||
return FSRFactor;
|
||||
}
|
||||
|
||||
Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 1.0f");
|
||||
//Logger.LogInfo($"GetCurrentScalingFactor(): Something went wrong. Returning 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>
|
||||
<Compile Include="Plugin.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UpdateScopeResolution.cs" />
|
||||
<Compile Include="Utils.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user