Skip to content

Commit

Permalink
Added DisconnectButton_Patch
Browse files Browse the repository at this point in the history
- Prevent host from clicking "Disconnect" in the main menu if peers are still connected.
  • Loading branch information
Lacyway committed Jun 14, 2024
1 parent aba1e79 commit ef8b979
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions Fika.Core/FikaPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ protected void Awake()
new BotCacher_Patch().Enable();
new InventoryScroll_Patch().Enable();
new AbstractGame_InRaid_Patch().Enable();
new DisconnectButton_Patch().Enable();
#if GOLDMASTER
new TOS_Patch().Enable();
#endif
Expand Down
32 changes: 32 additions & 0 deletions Fika.Core/UI/Patches/DisconnectButton_Patch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Comfort.Common;
using EFT.UI;
using Fika.Core.Coop.Matchmaker;
using Fika.Core.Networking;
using SPT.Reflection.Patching;
using System.Reflection;

namespace Fika.Core.UI.Patches
{
public class DisconnectButton_Patch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(MenuScreen).GetMethod(nameof(MenuScreen.method_11));
}

[PatchPrefix]
static bool Prefix()
{
if (MatchmakerAcceptPatches.IsServer)
{
FikaServer server = Singleton<FikaServer>.Instance;
if (server != null && server.NetServer.ConnectedPeersCount > 0)
{
NotificationManagerClass.DisplayWarningNotification($"You cannot disconnect while there are still peers connected! Remaining: {server.NetServer.ConnectedPeersCount}");
return false;
}
}
return true;
}
}
}

0 comments on commit ef8b979

Please sign in to comment.