FOV scaling is now fixed via a method patch instead of arcane workarounds. This might be the one.

Removed FOV scaling settings.
This commit is contained in:
notGreg 2023-04-04 19:30:08 +02:00
parent d491111a48
commit 16daa9b33c
3 changed files with 25 additions and 150 deletions

View File

@ -0,0 +1,19 @@
using Aki.Reflection.Patching;
using EFT;
using System.Reflection;
namespace ScopeTweaks
{
internal class CalculateScaleValueByFovPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(EFT.Player).GetMethod("CalculateScaleValueByFov");
}
[PatchPostfix]
public static void PatchPostfix(ref float ___float_10)
{
___float_10 = 1.0f;
}
}
}

View File

@ -5,7 +5,6 @@ using Comfort.Common;
using EFT; using EFT;
using EFT.Settings.Graphics; using EFT.Settings.Graphics;
using System.Collections; using System.Collections;
using System.ComponentModel;
using UnityEngine; using UnityEngine;
/* Dependencies: /* Dependencies:
@ -23,30 +22,13 @@ using UnityEngine;
*/ */
namespace ScopeTweaks namespace ScopeTweaks
{ {
[BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "3.5.3")] [BepInPlugin("com.notGreg.scopeTweaks", "notGreg's Scope Tweaks", "3.5.4")]
[BepInDependency("FOVFix", BepInDependency.DependencyFlags.SoftDependency)] [BepInDependency("FOVFix", BepInDependency.DependencyFlags.SoftDependency)]
public class Plugin : BaseUnityPlugin public class Plugin : BaseUnityPlugin
{ {
ConfigEntry<int> scopeCameraResolutionScale; ConfigEntry<int> scopeCameraResolutionScale;
//ConfigEntry<EFOVScalingMode> scopeFixType;
ConfigEntry<bool> enableDebug; ConfigEntry<bool> enableDebug;
enum EFOVScalingMode
{
Disabled,
[Description("Magnified optics")]
ScopesOnly,
[Description("All sights")]
All,
}
//The following assignments should allow for faster patching in the future.
//The correct GClass can be found by searching for "ClearSettings" in Assembly-CSharp.dll via dnSpy, netFiddle, ilSpy, etc.
SharedGameSettingsClass settingsLibrary = Singleton<SharedGameSettingsClass>.Instance;
//The correct GClass can be found by searching for "SetFov" in Assembly-CSharp.dll via dnSpy, netFiddle, ilSpy, etc.
CameraClass setFovLibrary = CameraClass.Instance;
void Awake() void Awake()
{ {
@ -54,6 +36,10 @@ namespace ScopeTweaks
{ {
Logger.LogWarning("Fontaine's FOV Fix detected! FOV Fix will NOT be available."); Logger.LogWarning("Fontaine's FOV Fix detected! FOV Fix will NOT be available.");
} }
else
{
new CalculateScaleValueByFovPatch().Enable();
}
scopeCameraResolutionScale = Config.Bind( scopeCameraResolutionScale = Config.Bind(
"General", "General",
@ -61,12 +47,6 @@ namespace ScopeTweaks
80, 80,
new ConfigDescription("Additional override applied on top of currently enabled resolution scaling method.", new AcceptableValueRange<int>(10, 100))); new ConfigDescription("Additional override applied on top of currently enabled resolution scaling method.", new AcceptableValueRange<int>(10, 100)));
//scopeFixType = Config.Bind(
//"General",
//"High FOV sight tweak",
//EFOVScalingMode.ScopesOnly,
//new ConfigDescription(""));
enableDebug = Config.Bind("Debug", "Enable debug logging", false); enableDebug = Config.Bind("Debug", "Enable debug logging", false);
} }
@ -76,34 +56,6 @@ namespace ScopeTweaks
if (Singleton<AbstractGame>.Instance == null) return; if (Singleton<AbstractGame>.Instance == null) return;
GameStatus currentGameState = Singleton<AbstractGame>.Instance.Status; GameStatus currentGameState = Singleton<AbstractGame>.Instance.Status;
if (mainPlayer != null)
{
if (Input.GetKeyDown("["))
{
StopAllCoroutines();
CameraClass.Instance.SetFov(35, 1.0f, true);
}
if (Input.GetKeyDown("]"))
{
StopAllCoroutines();
CameraClass.Instance.SetFov(defaultInGameFOV, 1.0f, true);
}
}
//if (mainPlayer != null && mainPlayer.ProceduralWeaponAnimation.IsAiming)
//{
// if (Input.GetMouseButtonDown(0))
// {
// inGameFOV = 50;
// }
// if (Input.GetMouseButtonUp(0))
// {
// inGameFOV = defaultInGameFOV;
// }
//}
//logic should only execute once per game instead of every frame //logic should only execute once per game instead of every frame
if (!gameStateChanged(currentGameState)) return; if (!gameStateChanged(currentGameState)) return;
@ -119,21 +71,16 @@ namespace ScopeTweaks
if (enableDebug.Value) Logger.LogInfo("Assigning cameras..."); if (enableDebug.Value) Logger.LogInfo("Assigning cameras...");
StartCoroutine(tryGetScopeCamera()); StartCoroutine(tryGetScopeCamera());
defaultInGameFOV = inGameFOV;
break; break;
} }
case GameStatus.SoftStopping: case GameStatus.SoftStopping:
case GameStatus.Stopping: case GameStatus.Stopping:
case GameStatus.Stopped: case GameStatus.Stopped:
{ {
if (enableDebug.Value) Logger.LogInfo("Resetting..."); if (enableDebug.Value) Logger.LogInfo("Resetting...");
scopeCamera = null; scopeCamera = null;
mainPlayer = null; mainPlayer = null;
if (enableDebug.Value) Logger.LogInfo($"Restoring FOV in settings: {defaultInGameFOV}");
inGameFOV = defaultInGameFOV;
break; break;
} }
default: break; default: break;
@ -163,24 +110,6 @@ namespace ScopeTweaks
return localPlayer; return localPlayer;
} }
/// <summary>
/// FIELD OF VIEW
/// </summary>
///
private int defaultInGameFOV;
private int inGameFOV
{
get
{
int fov = Singleton<SharedGameSettingsClass>.Instance.Game.Settings.FieldOfView.Value;
return fov;
}
set
{
Singleton<SharedGameSettingsClass>.Instance.Game.Settings.FieldOfView.Value = value;
}
}
/// <summary> /// <summary>
/// CAMERA SETUP /// CAMERA SETUP
/// </summary> /// </summary>
@ -239,87 +168,13 @@ namespace ScopeTweaks
currentScalingFactor = getCurrentScalingFactor(); currentScalingFactor = getCurrentScalingFactor();
StartCoroutine(tryGetScopeCamera()); StartCoroutine(tryGetScopeCamera());
//if (!mainPlayer.ProceduralWeaponAnimation.IsAiming)
//{
// float aimSpeed = 0.7f * mainPlayer.ProceduralWeaponAnimation.AimingSpeed;
// switch (scopeFixType.Value)
// {
// case EFOVScalingMode.Disabled:
// {
// break;
// }
// case EFOVScalingMode.ScopesOnly:
// {
// if (mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic)
// {
// inGameFOV = defaultInGameFOV;
// StopAllCoroutines();
// setFovLibrary.SetFov(defaultInGameFOV, aimSpeed, true);
// //mainPlayer.ProceduralWeaponAnimation.ApplyFovAdjustments(mainPlayer);
// }
// break;
// }
// case EFOVScalingMode.All:
// {
// inGameFOV = defaultInGameFOV;
// StopAllCoroutines();
// setFovLibrary.SetFov(defaultInGameFOV, aimSpeed, true);
// //mainPlayer.ProceduralWeaponAnimation.ApplyFovAdjustments(mainPlayer);
// break;
// }
// }
// return;
//}
if (mainPlayer.ProceduralWeaponAnimation.IsAiming) if (mainPlayer.ProceduralWeaponAnimation.IsAiming)
{ {
if(enableDebug.Value) Logger.LogInfo($"Scope: {mainPlayer.ProceduralWeaponAnimation.CurrentAimingMod.Item.LocalizedName()} isOptic: {mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic}");
if (enableDebug.Value) Logger.LogInfo("Updating scope resolution");
setScopeCameraResolutionScale(scopeCameraResolutionScale.Value); setScopeCameraResolutionScale(scopeCameraResolutionScale.Value);
defaultInGameFOV = inGameFOV;
//switch (scopeFixType.Value)
//{
// case EFOVScalingMode.Disabled:
// {
// break;
// }
// case EFOVScalingMode.ScopesOnly:
// {
// if (mainPlayer.ProceduralWeaponAnimation.CurrentScope.IsOptic)
// {
// forceADSFOV();
// }
// break;
// }
// case EFOVScalingMode.All:
// {
// forceADSFOV();
// break;
// }
//}
} }
}; };
} }
void forceADSFOV()
{
if (enableDebug.Value) Logger.LogInfo("Applying aiming tweaks");
float aimSpeed = mainPlayer.ProceduralWeaponAnimation.AimingSpeed * 0.7f;
//Doesn't take effect if Fontaine's FOV Fix is loaded.
if (!Chainloader.PluginInfos.ContainsKey("FOVFix"))
{
setFovLibrary.SetFov(35, aimSpeed, false);
inGameFOV = 50;
}
}
float currentScalingFactor = 1.0f; float currentScalingFactor = 1.0f;
float getCurrentScalingFactor() float getCurrentScalingFactor()

View File

@ -31,6 +31,7 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Patch.cs" />
<Compile Include="Plugin.cs" /> <Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>