Skip to content

Commit

Permalink
Merge pull request #31 from project-fika/dev
Browse files Browse the repository at this point in the history
Dev > Main
  • Loading branch information
Lacyway authored May 6, 2024
2 parents 38f44b6 + 00275b8 commit e1741e2
Show file tree
Hide file tree
Showing 20 changed files with 582 additions and 182 deletions.
2 changes: 1 addition & 1 deletion Fika.Core/AkiSupport/Airdrops/Utils/FikaItemFactoryUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FikaItemFactoryUtil
public FikaItemFactoryUtil()
{
itemFactory = Singleton<ItemFactory>.Instance;
logSource = new("ItemFactoryUtil");
logSource = Logger.CreateLogSource("ItemFactoryUtil");
}

public void BuildContainer(LootableContainer container, FikaAirdropConfigModel config, string dropType)
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/BTR/FikaBTRManager_Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal class FikaBTRManager_Client : MonoBehaviour
Type btrControllerType = typeof(BTRControllerClass);
_updateTaxiPriceMethod = AccessTools.GetDeclaredMethods(btrControllerType).Single(IsUpdateTaxiPriceMethod);
client = Singleton<FikaClient>.Instance;
btrLogger = new("BTR Client");
btrLogger = BepInEx.Logging.Logger.CreateLogSource("BTR Client");
}

private void Awake()
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/BTR/FikaBTRManager_Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal class FikaBTRManager_Host : MonoBehaviour
Type btrControllerType = typeof(BTRControllerClass);
_updateTaxiPriceMethod = AccessTools.GetDeclaredMethods(btrControllerType).Single(IsUpdateTaxiPriceMethod);
server = Singleton<FikaServer>.Instance;
btrLogger = new("BTR Host");
btrLogger = BepInEx.Logging.Logger.CreateLogSource("BTR Host");
}

public bool CanPlayerEnter(IPlayer player)
Expand Down
11 changes: 10 additions & 1 deletion Fika.Core/Coop/Components/CoopHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ protected void OnDestroy()
StopCoroutine(ProcessSpawnQueue());
if (PingRoutine != null)
{
StopCoroutine(PingRoutine);
StopCoroutine(PingRoutine);
}
}

Expand Down Expand Up @@ -493,21 +493,30 @@ private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int p
return null;

((CoopPlayer)otherPlayer).NetId = netId;
Logger.LogInfo($"SpawnObservedPlayer: {profile.Nickname} spawning with NetId {netId}");
if (!isAI)
{
HumanPlayers++;
}

if (!Players.ContainsKey(netId))
{
Players.Add(netId, (CoopPlayer)otherPlayer);
}
else
{
Logger.LogError($"Trying to add {otherPlayer.Profile.Nickname} to list of players but it was already there!");
}

if (!Singleton<GameWorld>.Instance.RegisteredPlayers.Any(x => x.Profile.ProfileId == profile.ProfileId))
Singleton<GameWorld>.Instance.RegisteredPlayers.Add(otherPlayer);

foreach (CoopPlayer player in Players.Values)
{
if (player is not ObservedCoopPlayer)
{
continue;
}

Collider playerCollider = otherPlayer.GetCharacterControllerCommon().GetCollider();
Collider otherCollider = player.GetCharacterControllerCommon().GetCollider();
Expand Down
291 changes: 200 additions & 91 deletions Fika.Core/Coop/Custom/FikaHealthBar.cs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Fika.Core/Coop/FreeCamera/FreeCameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private void ShowExtractMessage()
if (FikaPlugin.ExtractKey.Value.Modifiers.Count() > 0)
{
string modifiers = string.Join("+", FikaPlugin.ExtractKey.Value.Modifiers);
text = modifiers + "+" + text;
text = modifiers + " + " + text;
}
extractText = FikaUIUtils.CreateOverlayText($"Press '{text}' to extract");
}
Expand Down
120 changes: 64 additions & 56 deletions Fika.Core/Coop/GameMode/CoopGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
using HarmonyLib;
using JsonType;
using LiteNetLib.Utils;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
Expand Down Expand Up @@ -483,33 +482,31 @@ public override void vmethod_1(float timeBeforeDeploy)
/// <param name="timeBeforeDeploy">Time in seconds to count down</param>
private async void DeployScreen(float timeBeforeDeploy)
{
if (MatchmakerAcceptPatches.IsServer && MatchmakerAcceptPatches.HostExpectedNumberOfPlayers <= 1)
if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
{
if (fikaStartButton != null)
if (MatchmakerAcceptPatches.IsServer && MatchmakerAcceptPatches.HostExpectedNumberOfPlayers <= 1)
{
Destroy(fikaStartButton);
}
if (fikaStartButton != null)
{
Destroy(fikaStartButton);
}

if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
{
SetStatusModel status = new SetStatusModel(coopHandler.MyPlayer.ProfileId, LobbyEntry.ELobbyStatus.IN_GAME);
await FikaRequestHandler.UpdateSetStatus(status);
}

Singleton<FikaServer>.Instance.ReadyClients++;
base.vmethod_1(timeBeforeDeploy);
return;
}
Singleton<FikaServer>.Instance.ReadyClients++;
base.vmethod_1(timeBeforeDeploy);
return;
}

forceStart = false;
NetDataWriter writer = new();
forceStart = false;

MatchmakerAcceptPatches.GClass3163.ChangeStatus("Waiting for other players to finish loading...");
MatchmakerAcceptPatches.GClass3163.ChangeStatus("Waiting for other players to finish loading...");

fikaStartButton?.SetActive(true);
fikaStartButton?.SetActive(true);

if (MatchmakerAcceptPatches.IsServer)
{
if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
if (MatchmakerAcceptPatches.IsServer)
{
SetStatusModel status = new SetStatusModel(coopHandler.MyPlayer.ProfileId, LobbyEntry.ELobbyStatus.IN_GAME);
await FikaRequestHandler.UpdateSetStatus(status);
Expand All @@ -518,52 +515,56 @@ private async void DeployScreen(float timeBeforeDeploy)
{
await Task.Delay(100);
} while (coopHandler.HumanPlayers < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart);
}

FikaServer server = Singleton<FikaServer>.Instance;
server.ReadyClients++;
InformationPacket packet = new()
{
NumberOfPlayers = server.NetServer.ConnectedPeersCount,
ReadyPlayers = server.ReadyClients
};
NetDataWriter writer = new();
writer.Reset();
server.SendDataToAll(writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered);
FikaServer server = Singleton<FikaServer>.Instance;
server.ReadyClients++;
InformationPacket packet = new()
{
NumberOfPlayers = server.NetServer.ConnectedPeersCount,
ReadyPlayers = server.ReadyClients
};
writer.Reset();
server.SendDataToAll(writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered);

do
{
await Task.Delay(250);
} while (Singleton<FikaServer>.Instance.ReadyClients < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart);
}
else if (MatchmakerAcceptPatches.IsClient)
{
if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
do
{
await Task.Delay(250);
} while (Singleton<FikaServer>.Instance.ReadyClients < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart);

foreach (CoopPlayer player in coopHandler.Players.Values)
{
SyncNetIdPacket syncPacket = new(player.ProfileId, player.NetId);

writer.Reset();
Singleton<FikaServer>.Instance.SendDataToAll(writer, ref syncPacket, LiteNetLib.DeliveryMethod.ReliableUnordered);
}
}
else if (MatchmakerAcceptPatches.IsClient)
{
do
{
await Task.Delay(100);
} while (coopHandler.HumanPlayers < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart);
}

FikaClient client = Singleton<FikaClient>.Instance;
InformationPacket packet = new(true)
{
ReadyPlayers = 1
};
NetDataWriter writer = new();
writer.Reset();
client.SendData(writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered);
FikaClient client = Singleton<FikaClient>.Instance;
InformationPacket packet = new(true)
{
ReadyPlayers = 1
};
writer.Reset();
client.SendData(writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered);

do
do
{
await Task.Delay(250);
} while (Singleton<FikaClient>.Instance.ReadyClients < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart);
}

if (fikaStartButton != null)
{
await Task.Delay(250);
} while (Singleton<FikaClient>.Instance.ReadyClients < MatchmakerAcceptPatches.HostExpectedNumberOfPlayers && !forceStart);
}
Destroy(fikaStartButton);
}

if (fikaStartButton != null)
{
Destroy(fikaStartButton);
}

base.vmethod_1(timeBeforeDeploy);
Expand Down Expand Up @@ -653,7 +654,7 @@ public override async Task<LocalPlayer> vmethod_2(int playerId, Vector3 position
LocalPlayer myPlayer = await CoopPlayer.Create(playerId, spawnPoint.Position, spawnPoint.Rotation, "Player", "Main_", EPointOfView.FirstPerson, profile,
false, UpdateQueue, Player.EUpdateMode.Auto, Player.EUpdateMode.Auto,
GClass549.Config.CharacterController.ClientPlayerMode, () => Singleton<SharedGameSettingsClass>.Instance.Control.Settings.MouseSensitivity,
() => Singleton<SharedGameSettingsClass>.Instance.Control.Settings.MouseAimingSensitivity, new GClass1445(), 0, questController);
() => Singleton<SharedGameSettingsClass>.Instance.Control.Settings.MouseAimingSensitivity, new GClass1445(), MatchmakerAcceptPatches.IsServer ? 0 : 1000, questController);

profile.SetSpawnedInSession(profile.Side == EPlayerSide.Savage);

Expand Down Expand Up @@ -1374,8 +1375,15 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa

wavesSpawnScenario_0?.Stop();

PlayerLeftRequest body = new PlayerLeftRequest(myPlayer.ProfileId);
FikaRequestHandler.RaidLeave(body);
try
{
PlayerLeftRequest body = new(myPlayer.ProfileId);
FikaRequestHandler.RaidLeave(body);
}
catch (Exception)
{
FikaPlugin.Instance.FikaLogger.LogError("Unable to send RaidLeave request to server.");
}

if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
{
Expand Down
7 changes: 6 additions & 1 deletion Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using LiteNetLib.Utils;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Fika.Core.Coop.PacketHandlers
Expand Down Expand Up @@ -121,7 +122,11 @@ private void Update()
Client?.SendData(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered);
}
}
if (FikaPlugin.PingButton.Value.IsPressed() && player.IsYourPlayer && player.HealthController.IsAlive && FikaPlugin.UsePingSystem.Value)
if (Input.GetKey(FikaPlugin.PingButton.Value.MainKey)
&& FikaPlugin.PingButton.Value.Modifiers.All(Input.GetKey)
&& player.IsYourPlayer
&& player.HealthController.IsAlive
&& FikaPlugin.UsePingSystem.Value)
{
player?.Ping();
}
Expand Down
9 changes: 7 additions & 2 deletions Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace Fika.Core.Coop.PacketHandlers
Expand All @@ -34,7 +35,7 @@ public class ServerPacketSender : MonoBehaviour, IPacketSender

private void Awake()
{
logger = new("ServerPacketSender");
logger = BepInEx.Logging.Logger.CreateLogSource("ServerPacketSender");
player = GetComponent<CoopPlayer>();
}

Expand Down Expand Up @@ -128,7 +129,11 @@ private void Update()
Server?.SendDataToAll(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered);
}
}
if (FikaPlugin.PingButton.Value.IsPressed() && player.IsYourPlayer && player.HealthController.IsAlive && FikaPlugin.UsePingSystem.Value)
if (Input.GetKey(FikaPlugin.PingButton.Value.MainKey)
&& FikaPlugin.PingButton.Value.Modifiers.All(Input.GetKey)
&& player.IsYourPlayer
&& player.HealthController.IsAlive
&& FikaPlugin.UsePingSystem.Value)
{
player?.Ping();
}
Expand Down
11 changes: 9 additions & 2 deletions Fika.Core/Coop/Players/CoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ public override void ApplyDamageInfo(DamageInfo damageInfo, EBodyPart bodyPartTy
{
if (IsYourPlayer)
{
if (damageInfo.Player != null)
{
if (!FikaPlugin.Instance.FriendlyFire && damageInfo.Player.iPlayer is ObservedCoopPlayer observedCoopPlayer && !observedCoopPlayer.IsObservedAI)
{
return;
}
}
if (colliderType == EBodyPartColliderType.HeadCommon)
{
damageInfo.Damage *= FikaPlugin.HeadDamageMultiplier.Value;
Expand All @@ -221,7 +228,7 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy
return base.ApplyShot(damageInfo, bodyPartType, colliderType, armorPlateCollider, shotId);
}

return null;
return null;
}

public override void Proceed(bool withNetwork, Callback<GInterface125> callback, bool scheduled = true)
Expand Down Expand Up @@ -1280,7 +1287,7 @@ public virtual void HandleDamagePacket(DamagePacket packet)
if (!FikaPlugin.Instance.FriendlyFire && damageInfo.Player.iPlayer is ObservedCoopPlayer observedCoopPlayer && !observedCoopPlayer.IsObservedAI)
{
return;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Coop/Players/ObservedCoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ protected override async void Start()
{
IsObservedAI = true;
}

PacketSender = gameObject.AddComponent<ObservedPacketSender>();

if (IsObservedAI)
Expand Down
Loading

0 comments on commit e1741e2

Please sign in to comment.