Reimplemented non-ADS weapon scaling.

This commit is contained in:
notGreg 2023-04-06 17:06:51 +02:00
parent 16daa9b33c
commit 8d0a20c7e0
2 changed files with 27 additions and 7 deletions

View File

@ -8,7 +8,7 @@ namespace ScopeTweaks
{
protected override MethodBase GetTargetMethod()
{
return typeof(EFT.Player).GetMethod("CalculateScaleValueByFov");
return typeof(Player).GetMethod("CalculateScaleValueByFov");
}
[PatchPostfix]
public static void PatchPostfix(ref float ___float_10)

View File

@ -5,6 +5,7 @@ using Comfort.Common;
using EFT;
using EFT.Settings.Graphics;
using System.Collections;
using System.Reflection;
using UnityEngine;
/* Dependencies:
@ -29,7 +30,6 @@ namespace ScopeTweaks
ConfigEntry<int> scopeCameraResolutionScale;
ConfigEntry<bool> enableDebug;
void Awake()
{
if (Chainloader.PluginInfos.ContainsKey("FOVFix"))
@ -50,12 +50,30 @@ namespace ScopeTweaks
enableDebug = Config.Bind("Debug", "Enable debug logging", false);
}
void FixedUpdate()
void Update()
{
//Check if the game is in a valid state and execute logic depening on the status of the game
if (Singleton<AbstractGame>.Instance == null) return;
GameStatus currentGameState = Singleton<AbstractGame>.Instance.Status;
if (mainPlayer != null)
{
int inGameFov = Singleton<SharedGameSettingsClass>.Instance.Game.Settings.FieldOfView;
float fov_clamped = Mathf.Clamp(inGameFov, 50, 75);
target_scale = Mathf.Lerp(1.0f, 0.65f, (fov_clamped - 50) / 25);
if (mainPlayer.ProceduralWeaponAnimation.IsAiming)
{
mainPlayer.RibcageScaleCurrent = 1.0f;
mainPlayer.RibcageScaleCurrentTarget = 1.0f;
}
else
{
mainPlayer.RibcageScaleCurrentTarget = target_scale;
mainPlayer.RibcageScaleCurrent = target_scale;
}
}
//logic should only execute once per game instead of every frame
if (!gameStateChanged(currentGameState)) return;
@ -144,7 +162,7 @@ namespace ScopeTweaks
ssaaOpticInstance = scopeCamera.GetComponent<SSAAOptic>();
}
ssaaOpticInstance.OpticCameraToMainCameraResolutionRatio = (float)(currentScalingFactor * (value / 100.0f));
ssaaOpticInstance.OpticCameraToMainCameraResolutionRatio = (float)(currentResoScalingFactor * (value / 100.0f));
}
/// <summary>
@ -160,24 +178,26 @@ namespace ScopeTweaks
};
}
internal static float target_scale = 1.0f;
void subscribeOnAimingChangedEvent()
{
if (enableDebug.Value) Logger.LogInfo("Subscribing to OnAimingChanged Event");
mainPlayer.HandsController.OnAimingChanged += (aimingArgs) =>
{
currentScalingFactor = getCurrentScalingFactor();
currentResoScalingFactor = getcurrentResoScalingFactor();
StartCoroutine(tryGetScopeCamera());
if (mainPlayer.ProceduralWeaponAnimation.IsAiming)
{
target_scale = 1.0f;
setScopeCameraResolutionScale(scopeCameraResolutionScale.Value);
}
};
}
float currentScalingFactor = 1.0f;
float currentResoScalingFactor = 1.0f;
float getCurrentScalingFactor()
float getcurrentResoScalingFactor()
{
if (enableDebug.Value) Logger.LogInfo("Getting current scaling factor:");
var graphics = Singleton<SharedGameSettingsClass>.Instance.Graphics.Settings;