Skip to content

Commit

Permalink
Merge pull request #27 from project-fika/dev
Browse files Browse the repository at this point in the history
Dev > main | spt 3.8.1
  • Loading branch information
Lacyway authored May 4, 2024
2 parents 4f5f13b + f102995 commit 732bcc5
Show file tree
Hide file tree
Showing 41 changed files with 500 additions and 296 deletions.
4 changes: 1 addition & 3 deletions Fika.Core/Bundles/Files/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
To build these assets, Please refer to the Fika-SDK for more information.
It will tell you how to install the SDK & build the assets.
https://github.com/project-fika/Fika-SDK
These assets are managed and built by the Fika team
6 changes: 3 additions & 3 deletions Fika.Core/Coop/BTR/FikaBTRManager_Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private void Update()
BTRPacket packet = btrPackets.Dequeue();
if (packet.HasBotProfileId)
{
AttachBot(packet.BotProfileId);
AttachBot(packet.BotNetId);
}
if (packet.HasShot)
{
Expand Down Expand Up @@ -151,11 +151,11 @@ private void ObservedShot(Vector3 position, Vector3 direction)
firearmController.method_54(weaponSoundPlayer, btrMachineGunAmmo, position, direction, false);
}

public void AttachBot(string profileId)
public void AttachBot(int netId)
{
if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
{
if (coopHandler.Players.TryGetValue(profileId, out CoopPlayer player))
if (coopHandler.Players.TryGetValue(netId, out CoopPlayer player))
{
BTRTurretView turretView = btrClientSide.turret;

Expand Down
7 changes: 4 additions & 3 deletions Fika.Core/Coop/BTR/FikaBTRManager_Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using EFT.InventoryLogic;
using EFT.Vehicle;
using Fika.Core.Coop.GameMode;
using Fika.Core.Coop.Players;
using Fika.Core.Networking;
using HarmonyLib;
using LiteNetLib;
Expand Down Expand Up @@ -138,7 +139,7 @@ private IEnumerator SendBotProfileId()
{
BTRDataPacket = btrDataPacket,
HasBotProfileId = true,
BotProfileId = btrBotShooter.ProfileId
BotNetId = ((CoopPlayer)btrBotShooter.GetPlayer).NetId
};

writer.Reset();
Expand Down Expand Up @@ -383,7 +384,7 @@ private void BtrTraderServicePurchased(ETraderServiceType serviceType, string su

GenericPacket responsePacket = new(EPackageType.TraderServiceNotification)
{
ProfileId = gameWorld.MainPlayer.ProfileId,
NetId = ((CoopPlayer)gameWorld.MainPlayer).NetId,
TraderServiceType = serviceType
};

Expand Down Expand Up @@ -417,7 +418,7 @@ public void NetworkBtrTraderServicePurchased(BTRServicePacket packet)

GenericPacket responsePacket = new(EPackageType.TraderServiceNotification)
{
ProfileId = gameWorld.MainPlayer.ProfileId,
NetId = ((CoopPlayer)gameWorld.MainPlayer).NetId,
TraderServiceType = packet.TraderServiceType
};

Expand Down
4 changes: 2 additions & 2 deletions Fika.Core/Coop/ClientClasses/CoopClientHealthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public override void SendNetworkSyncPacket(GStruct346 packet)

if (!isBot)
{
coopPlayer?.PacketSender?.HealthSyncPackets.Enqueue(new(coopPlayer.ProfileId)
coopPlayer?.PacketSender?.HealthSyncPackets.Enqueue(new(coopPlayer.NetId)
{
Packet = packet
});
}
else
{
coopBot?.PacketSender?.HealthSyncPackets.Enqueue(new(coopBot.ProfileId)
coopBot?.PacketSender?.HealthSyncPackets.Enqueue(new(coopBot.NetId)
{
Packet = packet
});
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/Components/CoopExfilManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private void ExfiltrationPoint_OnStatusChanged(ExfiltrationPoint point, EExfiltr
CoopPlayer mainPlayer = (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;
GenericPacket packet = new(EPackageType.ExfilCountdown)
{
ProfileId = mainPlayer.ProfileId,
NetId = mainPlayer.NetId,
ExfilName = point.Settings.Name,
ExfilStartTime = point.ExfiltrationStartTime
};
Expand Down
39 changes: 22 additions & 17 deletions Fika.Core/Coop/Components/CoopHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class CoopHandler : MonoBehaviour
/// <summary>
/// ProfileId to Player instance
/// </summary>
public Dictionary<string, CoopPlayer> Players { get; } = new();
public Dictionary<int, CoopPlayer> Players { get; } = new();
public int HumanPlayers = 1;
public List<string> ExtractedPlayers { get; set; } = [];
public List<int> ExtractedPlayers { get; set; } = [];
ManualLogSource Logger { get; set; }
public CoopPlayer MyPlayer => (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;

Expand All @@ -45,12 +45,13 @@ public class CoopHandler : MonoBehaviour
//private Thread loopThread;
//private CancellationTokenSource loopToken;

public class SpawnObject(Profile profile, Vector3 position, bool isAlive, bool isAI)
public class SpawnObject(Profile profile, Vector3 position, bool isAlive, bool isAI, int netId)
{
public Profile Profile { get; set; } = profile;
public Vector3 Position { get; set; } = position;
public bool IsAlive { get; set; } = isAlive;
public bool IsAI { get; set; } = isAI;
public int NetId { get; set; } = netId;
}

public bool RunAsyncTasks { get; set; } = true;
Expand Down Expand Up @@ -180,10 +181,13 @@ protected void OnDestroy()
loopThread?.Join();*/

StopCoroutine(ProcessSpawnQueue());
StopCoroutine(PingRoutine);
if (PingRoutine != null)
{
StopCoroutine(PingRoutine);
}
}

public bool RequestQuitGame { get; set; }
private bool requestQuitGame = false;

/// <summary>
/// The state your character or game is in to Quit.
Expand Down Expand Up @@ -232,7 +236,7 @@ public EQuitState GetQuitState()
}

// Extractions
if (coopGame.ExtractedPlayers.Contains(MyPlayer.ProfileId))
if (coopGame.ExtractedPlayers.Contains(MyPlayer.NetId))
{
quitState = EQuitState.YouHaveExtracted;
}
Expand All @@ -247,9 +251,9 @@ void ProcessQuitting()
{
EQuitState quitState = GetQuitState();

if (Input.GetKeyDown(KeyCode.F8) && quitState != EQuitState.NONE && !RequestQuitGame)
if (FikaPlugin.ExtractKey.Value.IsDown() && quitState != EQuitState.NONE && !requestQuitGame)
{
RequestQuitGame = true;
requestQuitGame = true;

// If you are the server / host
if (MatchmakerAcceptPatches.IsServer)
Expand All @@ -258,13 +262,13 @@ void ProcessQuitting()
if ((Singleton<FikaServer>.Instance.NetServer.ConnectedPeersCount > 0) && quitState != EQuitState.NONE)
{
NotificationManagerClass.DisplayWarningNotification("HOSTING: You cannot exit the game until all clients have disconnected.");
RequestQuitGame = false;
requestQuitGame = false;
return;
}
else if (Singleton<FikaServer>.Instance.NetServer.ConnectedPeersCount == 0 && Singleton<FikaServer>.Instance.timeSinceLastPeerDisconnected > DateTime.Now.AddSeconds(-5) && Singleton<FikaServer>.Instance.hasHadPeer)
{
NotificationManagerClass.DisplayWarningNotification($"HOSTING: Please wait at least 5 seconds after the last peer disconnected before quitting.");
RequestQuitGame = false;
requestQuitGame = false;
return;
}
else
Expand Down Expand Up @@ -325,7 +329,7 @@ private void ReadFromServerCharacters()
if (Players.Count > 0)
{
requestPacket.HasCharacters = true;
requestPacket.Characters = [.. Players.Keys, .. queuedProfileIds];
requestPacket.Characters = [.. Players.Values.Select(p => p.ProfileId), .. queuedProfileIds];
}

NetDataWriter writer = Singleton<FikaClient>.Instance.DataWriter;
Expand Down Expand Up @@ -382,7 +386,7 @@ await Singleton<PoolManager>.Instance.LoadBundlesAndCreatePools(PoolManager.Pool
}
});

LocalPlayer otherPlayer = SpawnObservedPlayer(spawnObject.Profile, spawnObject.Position, playerId, spawnObject.IsAI);
LocalPlayer otherPlayer = SpawnObservedPlayer(spawnObject.Profile, spawnObject.Position, playerId, spawnObject.IsAI, spawnObject.NetId);

if (!spawnObject.IsAlive)
{
Expand Down Expand Up @@ -439,7 +443,7 @@ private IEnumerator ProcessSpawnQueue()
}
}

public void QueueProfile(Profile profile, Vector3 position, bool isAlive = true, bool isAI = false)
public void QueueProfile(Profile profile, Vector3 position, int netId, bool isAlive = true, bool isAI = false)
{
if (Singleton<GameWorld>.Instance.RegisteredPlayers.Any(x => x.ProfileId == profile.ProfileId))
return;
Expand All @@ -452,7 +456,7 @@ public void QueueProfile(Profile profile, Vector3 position, bool isAlive = true,

queuedProfileIds.Add(profile.ProfileId);
Logger.LogInfo($"Queueing profile: {profile.Nickname}, {profile.ProfileId}");
spawnQueue.Enqueue(new SpawnObject(profile, position, isAlive, isAI));
spawnQueue.Enqueue(new SpawnObject(profile, position, isAlive, isAI, netId));
}

public WorldInteractiveObject GetInteractiveObject(string objectId, out WorldInteractiveObject worldInteractiveObject)
Expand All @@ -464,7 +468,7 @@ public WorldInteractiveObject GetInteractiveObject(string objectId, out WorldInt
return null;
}

private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int playerId, bool isAI)
private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int playerId, bool isAI, int netId)
{
LocalPlayer otherPlayer = ObservedCoopPlayer.CreateObservedPlayer(
playerId,
Expand All @@ -488,12 +492,13 @@ private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int p
if (otherPlayer == null)
return null;

((CoopPlayer)otherPlayer).NetId = netId;
if (!isAI)
HumanPlayers++;

if (!Players.ContainsKey(profile.ProfileId))
if (!Players.ContainsKey(netId))
{
Players.Add(profile.ProfileId, (CoopPlayer)otherPlayer);
Players.Add(netId, (CoopPlayer)otherPlayer);
}

if (!Singleton<GameWorld>.Instance.RegisteredPlayers.Any(x => x.Profile.ProfileId == profile.ProfileId))
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/Factories/PingFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private void Awake()
{
image = GetComponentInChildren<Image>();
image.color = Color.clear;
Destroy(gameObject, 3f);
Destroy(gameObject, FikaPlugin.PingTime.Value);
}

private void Update()
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/FreeCamera/FreeCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ protected void Update()

Player player = Singleton<GameWorld>.Instance.MainPlayer;

if (!coopHandler.ExtractedPlayers.Contains(player.ProfileId) && player.HealthController.IsAlive)
if (!coopHandler.ExtractedPlayers.Contains(((CoopPlayer)player).NetId) && player.HealthController.IsAlive)
{
player?.Teleport(transform.position);
}
Expand Down
72 changes: 67 additions & 5 deletions Fika.Core/Coop/FreeCamera/FreeCameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
using EFT.UI;
using Fika.Core.Coop.Components;
using Fika.Core.Coop.GameMode;
using Fika.Core.Coop.Players;
using Fika.Core.UI;
using Koenigz.PerfectCulling;
using Koenigz.PerfectCulling.EFT;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;

Expand Down Expand Up @@ -38,11 +43,12 @@ public class FreeCameraController : MonoBehaviour
private bool deathFadeEnabled;
private float DeadTime = 0f;
private DisablerCullingObjectBase[] allCullingObjects;
private List<PerfectCullingBakeGroup> previouslyActiveBakeGroups;

protected void Awake()
{
CameraParent = new GameObject("CameraParent");
var FCamera = CameraParent.GetOrAddComponent<Camera>();
Camera FCamera = CameraParent.GetOrAddComponent<Camera>();
FCamera.enabled = false;
}

Expand Down Expand Up @@ -73,6 +79,7 @@ protected void Start()
deathFade.enabled = true;

allCullingObjects = FindObjectsOfType<DisablerCullingObjectBase>();
previouslyActiveBakeGroups = [];
}

protected void Update()
Expand Down Expand Up @@ -127,7 +134,7 @@ protected void Update()

if (quitState == CoopHandler.EQuitState.YouHaveExtracted && !extracted)
{
if (coopGame.ExtractedPlayers.Contains(_player.ProfileId))
if (coopGame.ExtractedPlayers.Contains(((CoopPlayer)_player).NetId))
{
extracted = true;
ShowExtractMessage();
Expand Down Expand Up @@ -225,7 +232,13 @@ private void ShowExtractMessage()
{
if (FikaPlugin.ShowExtractMessage.Value)
{
extractText = FikaUIUtils.CreateOverlayText("Press 'F8' to extract");
string text = FikaPlugin.ExtractKey.Value.MainKey.ToString();
if (FikaPlugin.ExtractKey.Value.Modifiers.Count() > 0)
{
string modifiers = string.Join("+", FikaPlugin.ExtractKey.Value.Modifiers);
text = modifiers + "+" + text;
}
extractText = FikaUIUtils.CreateOverlayText($"Press '{text}' to extract");
}
}

Expand Down Expand Up @@ -318,6 +331,30 @@ private void SetPlayerToFreecamMode(Player localPlayer)
cullingObject.SetComponentsEnabled(true);
}
FikaPlugin.Instance.FikaLogger.LogDebug($"Enabled {count} Culling Triggers.");

PerfectCullingAdaptiveGrid perfectCullingAdaptiveGrid = FindObjectOfType<PerfectCullingAdaptiveGrid>();
if (perfectCullingAdaptiveGrid != null)
{
if (perfectCullingAdaptiveGrid.RuntimeGroupMapping.Count > 0)
{
foreach (PerfectCullingCrossSceneGroup sceneGroup in perfectCullingAdaptiveGrid.RuntimeGroupMapping)
{
foreach (PerfectCullingBakeGroup bakeGroup in sceneGroup.bakeGroups)
{
if (!bakeGroup.IsEnabled)
{
bakeGroup.IsEnabled = true;
}
else
{
previouslyActiveBakeGroups.Add(bakeGroup);
}
}

sceneGroup.enabled = false;
}
}
}
}

/// <summary>
Expand All @@ -326,7 +363,6 @@ private void SetPlayerToFreecamMode(Player localPlayer)
/// <param name="localPlayer"></param>
private void SetPlayerToFirstPersonMode(Player localPlayer)
{

// re-enable _gamePlayerOwner
_gamePlayerOwner.enabled = true;
_freeCamScript.SetActive(false);
Expand All @@ -345,6 +381,32 @@ private void SetPlayerToFirstPersonMode(Player localPlayer)
cullingObject.SetComponentsEnabled(false);
}
FikaPlugin.Instance.FikaLogger.LogDebug($"Disabled {count} Culling Triggers.");

PerfectCullingAdaptiveGrid perfectCullingAdaptiveGrid = FindObjectOfType<PerfectCullingAdaptiveGrid>();
if (perfectCullingAdaptiveGrid != null)
{
if (perfectCullingAdaptiveGrid.RuntimeGroupMapping.Count > 0)
{
foreach (PerfectCullingCrossSceneGroup sceneGroup in perfectCullingAdaptiveGrid.RuntimeGroupMapping)
{
sceneGroup.enabled = true;

foreach (PerfectCullingBakeGroup bakeGroup in sceneGroup.bakeGroups)
{
if (bakeGroup.IsEnabled && !previouslyActiveBakeGroups.Contains(bakeGroup))
{
bakeGroup.IsEnabled = false;
}
else
{
previouslyActiveBakeGroups.Remove(bakeGroup);
}
}

previouslyActiveBakeGroups.Clear();
}
}
}
}

/// <summary>
Expand All @@ -354,7 +416,7 @@ private void SetPlayerToFirstPersonMode(Player localPlayer)
private Player GetLocalPlayerFromWorld()
{
// If the GameWorld instance is null or has no RegisteredPlayers, it most likely means we're not in a raid
var gameWorld = Singleton<GameWorld>.Instance;
GameWorld gameWorld = Singleton<GameWorld>.Instance;
if (gameWorld == null || gameWorld.MainPlayer == null)
{
return null;
Expand Down
Loading

0 comments on commit 732bcc5

Please sign in to comment.