Skip to content

Commit

Permalink
Merge branch '3.9-dev' of https://github.com/project-fika/Fika-Plugin
Browse files Browse the repository at this point in the history
…into 3.9-dev
  • Loading branch information
Lacyway committed Jun 5, 2024
2 parents e72eea5 + de7fcde commit f172e65
Show file tree
Hide file tree
Showing 10 changed files with 730 additions and 664 deletions.
1,226 changes: 595 additions & 631 deletions Fika.Core/Coop/Components/CoopHandler.cs

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions Fika.Core/Coop/Components/FikaPinger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Fika.Core.Networking.Http;
using Fika.Core.Networking.Http.Models;
using System.Collections;
using System.Threading.Tasks;
using UnityEngine;

namespace Fika.Core.Coop.Components
{
public class FikaPinger : MonoBehaviour
{
private Coroutine pingRoutine;

public void StartPingRoutine()
{
pingRoutine = StartCoroutine(PingServer());
}

public void StopPingRoutine()
{
if (pingRoutine != null)
{
StopCoroutine(pingRoutine);
pingRoutine = null;
}
}

private IEnumerator PingServer()
{
PingRequest pingRequest = new();

while (true)
{
Task pingTask = FikaRequestHandler.UpdatePing(pingRequest);
while (!pingTask.IsCompleted)
{
yield return null;
}
yield return new WaitForSeconds(30);
}
}

private void OnDestroy()
{
StopPingRoutine();
}
}
}
6 changes: 3 additions & 3 deletions Fika.Core/Coop/Custom/FikaHealthBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ private void UpdateScreenSpacePosition(bool throttleUpdate)
playerPlate.ScalarObjectScreen.active = true;

float processedDistance = Mathf.Clamp(sqrDistance / 625, 0.6f, 1f);
Vector3 position = new(currentPlayer.PlayerBones.Neck.position.x, currentPlayer.PlayerBones.Neck.position.y + (1f * processedDistance), currentPlayer.PlayerBones.Neck.position.z);

if (!WorldToScreen.GetScreenPoint(position, mainPlayer, out Vector3 screenPoint))
Vector3 position = new(currentPlayer.PlayerBones.Neck.position.x, currentPlayer.PlayerBones.Neck.position.y + (1f * processedDistance), currentPlayer.PlayerBones.Neck.position.z);
if (!WorldToScreen.GetScreenPoint(position, mainPlayer, out Vector3 screenPoint, FikaPlugin.NamePlateUseOpticZoom.Value))
{
UpdateColorTextMeshProUGUI(playerPlate.playerNameScreen, 0);
UpdateColorImage(playerPlate.healthBarScreen, 0);
Expand Down
15 changes: 12 additions & 3 deletions Fika.Core/Coop/Factories/PingFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ protected void Update()
screenScale = outputWidth / inputWidth;
}

if (WorldToScreen.GetScreenPoint(hitPoint, mainPlayer, out Vector3 screenPoint))
if (WorldToScreen.GetScreenPoint(hitPoint, mainPlayer, out Vector3 screenPoint, FikaPlugin.PingUseOpticZoom.Value))
{
float distanceToCenter = Vector3.Distance(screenPoint, new Vector3(Screen.width, Screen.height, 0) / 2);

if (distanceToCenter < 200)
{
image.color = new Color(_pingColor.r, _pingColor.g, _pingColor.b, Mathf.Max(0.05f, distanceToCenter / 200));
image.color = new Color(_pingColor.r, _pingColor.g, _pingColor.b, Mathf.Max(FikaPlugin.PingMinimumOpacity.Value, distanceToCenter / 200));
}
else
{
Expand All @@ -108,7 +108,16 @@ public virtual void Initialize(ref Vector3 point, Object userObject, Color pingC

float distance = Mathf.Clamp(Vector3.Distance(CameraClass.Instance.Camera.transform.position, transform.position) / 100, 0.4f, 0.6f);
float pingSize = FikaPlugin.PingSize.Value;
image.rectTransform.localScale = new Vector3(pingSize, pingSize, pingSize) * distance;
Vector3 scaledSize = new Vector3(pingSize, pingSize, pingSize);
if (FikaPlugin.PingScaleWithDistance.Value == true)
{
scaledSize *= distance;
}
else
{
scaledSize *= 0.5f;
}
image.rectTransform.localScale = scaledSize;
}
}

Expand Down
2 changes: 2 additions & 0 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1920,6 +1920,8 @@ public override void Dispose()
Destroy(newDynamicAI);
}

NetManagerUtils.StopPinger();

FikaPlugin.DynamicAI.SettingChanged -= DynamicAI_SettingChanged;
FikaPlugin.DynamicAIRate.SettingChanged -= DynamicAIRate_SettingChanged;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public static async Task Postfix(Task __result, TarkovApplication __instance, Ti
throw new ArgumentNullException("timeHasComeScreenController");
}

bool isServer = MatchmakerAcceptPatches.IsServer;

LocationSettingsClass.Location location = ____raidSettings.SelectedLocation;

MatchmakerAcceptPatches.GClass3182 = timeHasComeScreenController;
Expand All @@ -86,6 +88,10 @@ public static async Task Postfix(Task __result, TarkovApplication __instance, Ti
}

NetManagerUtils.CreateNetManager(MatchmakerAcceptPatches.IsServer);
if (isServer)
{
NetManagerUtils.StartPinger();
}

ISession session = CurrentSession;

Expand All @@ -99,7 +105,7 @@ public static async Task Postfix(Task __result, TarkovApplication __instance, Ti

await session.SendRaidSettings(____raidSettings);

if (MatchmakerAcceptPatches.IsClient)
if (!isServer)
{
timeHasComeScreenController.ChangeStatus("Joining coop game...");

Expand All @@ -125,7 +131,7 @@ public static async Task Postfix(Task __result, TarkovApplication __instance, Ti
Singleton<AbstractGame>.Create(coopGame);
FikaEventDispatcher.DispatchEvent(new AbstractGameCreatedEvent(coopGame));

if (MatchmakerAcceptPatches.IsClient)
if (!isServer)
{
coopGame.SetMatchmakerStatus("Coop game joined");
}
Expand Down
26 changes: 26 additions & 0 deletions Fika.Core/Coop/Utils/NetManagerUtils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BepInEx.Logging;
using Comfort.Common;
using Fika.Core.Coop.Components;
using Fika.Core.Coop.Players;
using Fika.Core.Networking;
using System.Threading.Tasks;
Expand Down Expand Up @@ -95,5 +96,30 @@ public static Task SetupGameVariables(bool isServer, CoopPlayer coopPlayer)

return Task.CompletedTask;
}

public static void StartPinger()
{
if (FikaGameObject != null)
{
FikaPinger fikaPinger = FikaGameObject.AddComponent<FikaPinger>();
fikaPinger.StartPingRoutine();
}
}

public static void StopPinger()
{
if (FikaGameObject != null)
{
FikaPinger fikaPinger = FikaGameObject.GetComponent<FikaPinger>();
if (fikaPinger != null)
{
Object.Destroy(fikaPinger);
}
else
{
logger.LogError("StopPinger: Could not find FikaPinger!");
}
}
}
}
}
36 changes: 24 additions & 12 deletions Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class FikaPlugin : BaseUnityPlugin
public static ConfigEntry<bool> UseHealthNumber { get; set; }
public static ConfigEntry<bool> UsePlateFactionSide { get; set; }
public static ConfigEntry<bool> HideNamePlateInOptic { get; set; }
public static ConfigEntry<bool> NamePlateUseOpticZoom { get; set; }
public static ConfigEntry<bool> DecreaseOpacityNotLookingAt { get; set; }
public static ConfigEntry<float> NamePlateScale { get; set; }
public static ConfigEntry<float> OpacityInADS { get; set; }
Expand All @@ -132,6 +133,9 @@ public class FikaPlugin : BaseUnityPlugin
public static ConfigEntry<int> PingTime { get; set; }
public static ConfigEntry<bool> PlayPingAnimation { get; set; }
public static ConfigEntry<bool> ShowPingDuringOptics { get; set; }
public static ConfigEntry<bool> PingUseOpticZoom { get; set; }
public static ConfigEntry<bool> PingScaleWithDistance { get; set; }
public static ConfigEntry<float> PingMinimumOpacity { get; set; }

// Coop | Debug
public static ConfigEntry<KeyboardShortcut> FreeCamButton { get; set; }
Expand Down Expand Up @@ -285,15 +289,17 @@ private void SetupConfig()

// Coop | Name Plates

UseNamePlates = Config.Bind("Coop | Name Plates", "Show Player Name Plates", false, new ConfigDescription("Toggle Health-Bars & Names.", tags: new ConfigurationManagerAttributes() { Order = 10 }));
UseNamePlates = Config.Bind("Coop | Name Plates", "Show Player Name Plates", false, new ConfigDescription("Toggle Health-Bars & Names.", tags: new ConfigurationManagerAttributes() { Order = 11 }));

HideHealthBar = Config.Bind("Coop | Name Plates", "Hide Health Bar", false, new ConfigDescription("Completely hides the health bar.", tags: new ConfigurationManagerAttributes() { Order = 9 }));
HideHealthBar = Config.Bind("Coop | Name Plates", "Hide Health Bar", false, new ConfigDescription("Completely hides the health bar.", tags: new ConfigurationManagerAttributes() { Order = 10 }));

UseHealthNumber = Config.Bind("Coop | Name Plates", "Show HP% instead of bar", false, new ConfigDescription("Shows health in % amount instead of using the bar.", tags: new ConfigurationManagerAttributes() { Order = 8 }));
UseHealthNumber = Config.Bind("Coop | Name Plates", "Show HP% instead of bar", false, new ConfigDescription("Shows health in % amount instead of using the bar.", tags: new ConfigurationManagerAttributes() { Order = 9 }));

UsePlateFactionSide = Config.Bind("Coop | Name Plates", "Show Player Faction Icon", true, new ConfigDescription("Shows the player faction icon next to the HP bar.", tags: new ConfigurationManagerAttributes() { Order = 7 }));
UsePlateFactionSide = Config.Bind("Coop | Name Plates", "Show Player Faction Icon", true, new ConfigDescription("Shows the player faction icon next to the HP bar.", tags: new ConfigurationManagerAttributes() { Order = 8 }));

HideNamePlateInOptic = Config.Bind("Coop | Name Plates", "Hide Name Plate in Optic", true, new ConfigDescription("Hides the name plate when viewing through PiP scopes since it's kinda janky.", tags: new ConfigurationManagerAttributes() { Order = 6 }));
HideNamePlateInOptic = Config.Bind("Coop | Name Plates", "Hide Name Plate in Optic", true, new ConfigDescription("Hides the name plate when viewing through PiP scopes.", tags: new ConfigurationManagerAttributes() { Order = 7 }));

NamePlateUseOpticZoom = Config.Bind("Coop | Name Plates", "Name Plates Use Optic Zoom", true, new ConfigDescription("If name plate location should be displayed using the PiP optic camera.", tags: new ConfigurationManagerAttributes() { Order = 6, IsAdvanced = true }));

DecreaseOpacityNotLookingAt = Config.Bind("Coop | Name Plates", "Decrease Opacity In Peripheral", true, new ConfigDescription("Decreases the opacity of the name plates when not looking at a player.", tags: new ConfigurationManagerAttributes() { Order = 5 }));

Expand All @@ -309,19 +315,25 @@ private void SetupConfig()

// Coop | Custom

UsePingSystem = Config.Bind("Coop | Custom", "Ping System", false, new ConfigDescription("Toggle Ping System. If enabled you can receive and send pings by pressing the ping key.", tags: new ConfigurationManagerAttributes() { Order = 7 }));
UsePingSystem = Config.Bind("Coop | Custom", "Ping System", false, new ConfigDescription("Toggle Ping System. If enabled you can receive and send pings by pressing the ping key.", tags: new ConfigurationManagerAttributes() { Order = 9 }));

PingButton = Config.Bind("Coop | Custom", "Ping Button", new KeyboardShortcut(KeyCode.U), new ConfigDescription("Button used to send pings.", tags: new ConfigurationManagerAttributes() { Order = 8 }));

PingColor = Config.Bind("Coop | Custom", "Ping Color", Color.white, new ConfigDescription("The color of your pings when displayed for other players.", tags: new ConfigurationManagerAttributes() { Order = 7 }));

PingSize = Config.Bind("Coop | Custom", "Ping Size", 1f, new ConfigDescription("The multiplier of the ping size.", new AcceptableValueRange<float>(0.1f, 2f), new ConfigurationManagerAttributes() { Order = 6 }));

PingButton = Config.Bind("Coop | Custom", "Ping Button", new KeyboardShortcut(KeyCode.U), new ConfigDescription("Button used to send pings.", tags: new ConfigurationManagerAttributes() { Order = 6 }));
PingTime = Config.Bind("Coop | Custom", "Ping Time", 3, new ConfigDescription("How long pings should be displayed.", new AcceptableValueRange<int>(2, 10), new ConfigurationManagerAttributes() { Order = 5 }));

PingColor = Config.Bind("Coop | Custom", "Ping Color", Color.white, new ConfigDescription("The color of your pings when displayed for other players.", tags: new ConfigurationManagerAttributes() { Order = 5 }));
PlayPingAnimation = Config.Bind("Coop | Custom", "Play Ping Animation", false, new ConfigDescription("Plays the pointing animation automatically when pinging. Can interfere with gameplay.", tags: new ConfigurationManagerAttributes() { Order = 4 }));

PingSize = Config.Bind("Coop | Custom", "Ping Size", 1f, new ConfigDescription("The multiplier of the ping size.", new AcceptableValueRange<float>(0.1f, 2f), new ConfigurationManagerAttributes() { Order = 4 }));
ShowPingDuringOptics = Config.Bind("Coop | Custom", "Show Ping During Optics", false, new ConfigDescription("If pings should be displayed while aiming down an optics scope.", tags: new ConfigurationManagerAttributes() { Order = 3 }));

PingTime = Config.Bind("Coop | Custom", "Ping Time", 3, new ConfigDescription("How long pings should be displayed.", new AcceptableValueRange<int>(2, 10), new ConfigurationManagerAttributes() { Order = 3 }));
PingUseOpticZoom = Config.Bind("Coop | Custom", "Ping Use Optic Zoom", true, new ConfigDescription("If ping location should be displayed using the PiP optic camera.", tags: new ConfigurationManagerAttributes() { Order = 2, IsAdvanced = true }));

PlayPingAnimation = Config.Bind("Coop | Custom", "Play Ping Animation", false, new ConfigDescription("Plays the pointing animation automatically when pinging. Can interfere with gameplay.", tags: new ConfigurationManagerAttributes() { Order = 2 }));
PingScaleWithDistance = Config.Bind("Coop | Custom", "Ping Scale With Distance", true, new ConfigDescription("If ping size should scale with distance from player.", tags: new ConfigurationManagerAttributes() { Order = 1, IsAdvanced = true }));

ShowPingDuringOptics = Config.Bind("Coop | Custom", "Show Ping During Optics", false, new ConfigDescription("If pings should be displayed while aiming down an optics scope.", tags: new ConfigurationManagerAttributes() { Order = 1 }));
PingMinimumOpacity = Config.Bind("Coop | Custom", "Ping Minimum Opacity", 0.05f, new ConfigDescription("The minimum opacity of pings when looking straight at them.", new AcceptableValueRange<float>(0f, 0.5f), new ConfigurationManagerAttributes() { Order = 0, IsAdvanced = true }));

// Coop | Debug

Expand Down
22 changes: 11 additions & 11 deletions Fika.Core/Networking/Models/PingRequest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Fika.Core.Coop.Components;
using Fika.Core.Coop.Matchmaker;
using System.Runtime.Serialization;

namespace Fika.Core.Networking.Http.Models
{
[DataContract]
public struct PingRequest
{
[DataMember(Name = "serverId")]
public string ServerId;
[DataContract]
public struct PingRequest
{
[DataMember(Name = "serverId")]
public string ServerId;

public PingRequest()
{
ServerId = CoopHandler.GetServerId();
}
}
public PingRequest()
{
ServerId = MatchmakerAcceptPatches.GetGroupId();
}
}
}
4 changes: 2 additions & 2 deletions Fika.Core/Utils/WorldToScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Fika.Core.Utils
{
public static class WorldToScreen
{
public static bool GetScreenPoint(Vector3 worldPosition, CoopPlayer mainPlayer, out Vector3 screenPoint)
public static bool GetScreenPoint(Vector3 worldPosition, CoopPlayer mainPlayer, out Vector3 screenPoint, bool useOpticCamera = true)
{
CameraClass worldCameraInstance = CameraClass.Instance;
Camera worldCamera = worldCameraInstance.Camera;
Expand All @@ -22,7 +22,7 @@ public static bool GetScreenPoint(Vector3 worldPosition, CoopPlayer mainPlayer,

ProceduralWeaponAnimation weaponAnimation = mainPlayer.ProceduralWeaponAnimation;

if (weaponAnimation != null)
if (useOpticCamera && weaponAnimation != null)
{
if (weaponAnimation.IsAiming && weaponAnimation.CurrentScope.IsOptic)
{
Expand Down

0 comments on commit f172e65

Please sign in to comment.