Skip to content

Commit

Permalink
fixed memory for hideout
Browse files Browse the repository at this point in the history
  • Loading branch information
space-commits committed Feb 25, 2025
1 parent 189d8e5 commit 9240f7e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 20 deletions.
58 changes: 47 additions & 11 deletions FovController.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,40 @@
using Comfort.Common;
using BepInEx;
using Comfort.Common;
using EFT;
using EFT.Animations;
using EFT.InventoryLogic;
using EFT.UI;
using EFT.UI.Ragfair;
using HarmonyLib;
using RealismMod;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using UnityEngine;
using static EFT.Player;

namespace FOVFix
{

public static class WeaponClassExtension
{
private static readonly ConditionalWeakTable<Item, StrongBox<string>> _customPropertyValues = new ConditionalWeakTable<Item, StrongBox<string>>();

public static string GetCustomProperty(this Item instance)
{
if (_customPropertyValues.TryGetValue(instance, out var box))
return box.Value;
return default;
}

public static void SetCustomProperty(this Item instance, string value)
{
if (_customPropertyValues.TryGetValue(instance, out var box))
box.Value = value;
else
_customPropertyValues.Add(instance, new StrongBox<string>(value));
}
}


public class ValueWatcher<T>
{
private T _watchedValue;
Expand Down Expand Up @@ -47,25 +67,41 @@ public class FovController

public Dictionary<string, float> WeaponOffsets = new Dictionary<string, float>();

public Weapon CurrentWeapon { get; set; }
public string WeapId { get; set; }
public float CurrentScopeFOV { get; set; } = 0f;
public bool IsToggleZoom { get; set; } = false;
public bool IsPistol { get; set; } = false;

public float ScrollCameraOffset
{
get
{
if (WeapId != null)
if (CurrentWeapon != null)
{
WeaponOffsets.TryGetValue(WeapId, out float offset);
return offset;
string id;
if (Utils.IsInHideout)
{
id = WeaponClassExtension.GetCustomProperty(CurrentWeapon);
}
else id = WeapId;

WeaponOffsets.TryGetValue(id, out float offset);
return offset;
}

return 0f;
}
set
{
float scrollCameraOffset = Mathf.Clamp(value, -0.04f, 0.04f);
if (WeapId != null) WeaponOffsets[WeapId] = scrollCameraOffset;
string id;
if (Utils.IsInHideout)
{
id = WeaponClassExtension.GetCustomProperty(CurrentWeapon);
}
else id = WeapId;
if (!id.IsNullOrWhiteSpace()) WeaponOffsets[id] = scrollCameraOffset;
}
}

Expand Down Expand Up @@ -144,7 +180,7 @@ public void CheckScopeFOV()

public void CheckScope()
{
if (IsPWANull() || !Utils.WeaponReady) return;
if (IsPWANull() || !Utils.WeaponIsReady) return;
var pwa = _player.ProceduralWeaponAnimation;
if (pwa.AimIndex < pwa.ScopeAimTransforms.Count) OpticWatcher.WatchedValue = pwa.CurrentScope.IsOptic;
}
Expand Down Expand Up @@ -197,7 +233,7 @@ private void HandleCameraOffsetInput()
public void ControllerUpdate()
{
Utils.CheckIsReady();
if (!Utils.IsReady) return;
if (!Utils.PlayerIsReady) return;

if (_player == null) _player = Singleton<GameWorld>.Instance.MainPlayer;
if (_player != null)
Expand Down
21 changes: 20 additions & 1 deletion FovPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@

namespace FOVFix
{
public class CloneItemPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(GClass3105).GetMethod("CloneItem", BindingFlags.Static | BindingFlags.Public)?.MakeGenericMethod(typeof(Item));
}

[PatchPostfix]
private static void PatchPostfix(Item originalItem, ref Item __result)
{
if (Utils.PlayerIsReady && Utils.IsInHideout && originalItem is Weapon)
{
WeaponClassExtension.SetCustomProperty(__result, originalItem.Id);
}
}
}

//can modifer Optic cam FOV here but doesnt' work for fixed optics, and causes bugs when swapping between variable and fixed optics on different guns
public class CameraUpdatePatch : ModulePatch
{
Expand Down Expand Up @@ -378,9 +395,11 @@ private static void PatchPostfix(ref EFT.Animations.ProceduralWeaponAnimation __
Player player = (Player)playerField.GetValue(firearmController);
if (player != null && player.IsYourPlayer)
{
//cloned weapon appears here

Plugin.FovController.IsPistol = firearmController.Weapon.WeapClass == "pistol";
Plugin.FovController.WeapId = firearmController.Item.Id;
Plugin.FovController.WeapId = firearmController.Weapon.Id;
Plugin.FovController.CurrentWeapon = firearmController.Weapon;
Plugin.FovController.ChangeMainCamFOV();
}
}
Expand Down
5 changes: 2 additions & 3 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,9 @@ private void Awake()
new FovValuePatch().Enable();
new AimingSensitivityPatch().Enable();
new ScopeSensitivityPatch().Enable();
new CloneItemPatch().Enable();
if (Plugin.EnableFovScaleFix.Value) new CalculateScaleValueByFovPatch().Enable();
//new ScopeZoomPatch().Enable();
//new OpticPanelPatch().Enable();
//new CameraUpdatePatch().Enable();

}

private void CheckForMods()
Expand Down
19 changes: 14 additions & 5 deletions Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public static class Utils

public static string[] scopeTypes = new string[] { "55818acf4bdc2dde698b456b", "55818ad54bdc2ddc698b4569", "55818add4bdc2d5b648b456f", "55818ae44bdc2dde698b456c", "55818ac54bdc2d5b648b456e", "55818aeb4bdc2ddc698b456a" };

public static bool IsReady = false;
public static bool WeaponReady = false;
public static bool PlayerIsReady = false;
public static bool WeaponIsReady = false;
public static bool IsInHideout = false;

public static Player GetYourPlayer()
{
Expand All @@ -40,15 +41,23 @@ public static bool CheckIsReady()
Player player = gameWorld?.MainPlayer;
if (player != null)
{
Utils.WeaponReady = player?.HandsController != null && player?.HandsController?.Item != null && player?.HandsController?.Item is Weapon ? true : false;
Utils.WeaponIsReady = player?.HandsController != null && player?.HandsController?.Item != null && player?.HandsController?.Item is Weapon ? true : false;
Utils.IsInHideout = player is HideoutPlayer ? true : false;
}
else
{
Utils.WeaponIsReady = false;
Utils.IsInHideout = false;
}

if (gameWorld == null || gameWorld.AllAlivePlayersList == null || gameWorld.MainPlayer == null || sessionResultPanel != null)
{
Utils.IsReady = false;
Utils.PlayerIsReady = false;
Utils.WeaponIsReady = false;
Utils.IsInHideout = false;
return false;
}
Utils.IsReady = true;
Utils.PlayerIsReady = true;
return true;
}

Expand Down

0 comments on commit 9240f7e

Please sign in to comment.