Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev > Main #31

Merged
merged 34 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3e8afda
nameplate improvements
NickMillion May 4, 2024
369bbca
peripheral checks now properly handle up/down scaling
NickMillion May 4, 2024
144d9cd
actually reverting some performance things to make sure i have a func…
NickMillion May 4, 2024
f5bb82e
Fix friendly fire not working not working with grenades
Lacyway May 4, 2024
41fd2e7
Fix reference
Lacyway May 4, 2024
60f1301
cleanup/refactor + performance probably
NickMillion May 4, 2024
0ebeefd
Revert "cleanup/refactor + performance probably"
NickMillion May 4, 2024
16e918e
why are you like this git
NickMillion May 4, 2024
a8e5809
Merge branch 'dev' into dev
NickMillion May 4, 2024
210b183
Fix friendly fire logic
Lacyway May 5, 2024
04651fa
Prevent crash from RaidLeave failure
Lacyway May 5, 2024
280d258
Cleanup
Lacyway May 5, 2024
ee5f698
basic nameplate occlusion using existing isVisible check
NickMillion May 5, 2024
7587223
Removed occlusion setting, implemented throttled updates, all element…
NickMillion May 5, 2024
4d19a38
remove unused int
NickMillion May 5, 2024
4d59ea2
Merge branch 'project-fika:dev' into dev
NickMillion May 5, 2024
0427165
NamePlate -> Name Plate to make Lacy happy
NickMillion May 5, 2024
da3184c
Merge pull request #25 from NickMillion/dev
Lacyway May 5, 2024
79a678f
WIP NetId resync
Lacyway May 5, 2024
4a4124a
Test before setting new NetId
Lacyway May 6, 2024
5048f81
Log NetId assignment
Lacyway May 6, 2024
2fe957d
WIP Allow pinging when moving
Lacyway May 6, 2024
28522fc
Ping servers before attempting to connect
Lacyway May 6, 2024
6bd3924
Cleanup
Lacyway May 6, 2024
5421dea
Update loggers
Lacyway May 6, 2024
ace8093
More logging in CoopHandler
Lacyway May 6, 2024
81361c0
More logging in Fika Client
Lacyway May 6, 2024
df2041d
Assign standard NetId of 1000 to clients
Lacyway May 6, 2024
6273364
Ping for 3 seconds rather than 5 ticks
Lacyway May 6, 2024
537b823
Improve health bar update
Lacyway May 6, 2024
248cf1b
Explicit vars
Lacyway May 6, 2024
e94466b
More explicit vars
Lacyway May 6, 2024
ad8406e
Update extract text when using modifiers
Lacyway May 6, 2024
00275b8
3s > 5s timeout
Lacyway May 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading