Skip to content

Commit

Permalink
Ported code from 3.8.3 to 3.9
Browse files Browse the repository at this point in the history
  • Loading branch information
trippyone committed Jul 6, 2024
1 parent ab7c08b commit bc001da
Show file tree
Hide file tree
Showing 26 changed files with 1,110 additions and 36 deletions.
14 changes: 11 additions & 3 deletions Fika-Plugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fika.Core", "Fika.Core\Fika.Core.csproj", "{79F0E889-A195-42B4-8656-4F35685BBB80}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fika.Dedicated", "..\Fika-Plugin_main\Fika.Dedicated\Fika.Dedicated.csproj", "{AB4298A9-5EA3-4882-ABFF-2EC62A514815}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
GoldMaster|Any CPU = GoldMaster|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{79F0E889-A195-42B4-8656-4F35685BBB80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{79F0E889-A195-42B4-8656-4F35685BBB80}.Debug|Any CPU.Build.0 = Debug|Any CPU
{79F0E889-A195-42B4-8656-4F35685BBB80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79F0E889-A195-42B4-8656-4F35685BBB80}.Release|Any CPU.Build.0 = Release|Any CPU
{79F0E889-A195-42B4-8656-4F35685BBB80}.GoldMaster|Any CPU.ActiveCfg = GoldMaster|Any CPU
{79F0E889-A195-42B4-8656-4F35685BBB80}.GoldMaster|Any CPU.Build.0 = GoldMaster|Any CPU
{79F0E889-A195-42B4-8656-4F35685BBB80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{79F0E889-A195-42B4-8656-4F35685BBB80}.Release|Any CPU.Build.0 = Release|Any CPU
{AB4298A9-5EA3-4882-ABFF-2EC62A514815}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB4298A9-5EA3-4882-ABFF-2EC62A514815}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB4298A9-5EA3-4882-ABFF-2EC62A514815}.GoldMaster|Any CPU.ActiveCfg = Debug|Any CPU
{AB4298A9-5EA3-4882-ABFF-2EC62A514815}.GoldMaster|Any CPU.Build.0 = Debug|Any CPU
{AB4298A9-5EA3-4882-ABFF-2EC62A514815}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB4298A9-5EA3-4882-ABFF-2EC62A514815}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Binary file modified Fika.Core/Bundles/Files/newmatchmakerui.bundle
Binary file not shown.
1 change: 1 addition & 0 deletions Fika.Core/Coop/Utils/FikaBackendUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static class FikaBackendUtils
public static bool IsServer => MatchingType == EMatchmakerType.GroupLeader;
public static bool IsClient => MatchingType == EMatchmakerType.GroupPlayer;
public static bool IsSinglePlayer => MatchingType == EMatchmakerType.Single;
public static bool IsDedicated = false;
public static PlayersRaidReadyPanel PlayersRaidReadyPanel;
public static MatchMakerGroupPreview MatchMakerGroupPreview;
public static int HostExpectedNumberOfPlayers = 1;
Expand Down
23 changes: 23 additions & 0 deletions Fika.Core/Models/SetDedicatedStatusRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using EFT;
using EFT.Bots;
using JsonType;
using System.Runtime.Serialization;

namespace Fika.Core.Models
{
[DataContract]
public struct SetDedicatedStatusRequest
{
[DataMember(Name = "sessionId")]
public string SessionId { get; set; }

[DataMember(Name = "status")]
public string Status { get; set; }

public SetDedicatedStatusRequest(string sessionId, string status)
{
SessionId = sessionId;
Status = status;
}
}
}
19 changes: 19 additions & 0 deletions Fika.Core/Models/SetDedicatedStatusResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace Fika.Core.Models
{
[DataContract]
public struct SetDedicatedStatusResponse
{
[DataMember(Name = "sessionId")]
public string SessionId { get; set; }

[DataMember(Name = "status")]
public string Status { get; set; }
}
}
38 changes: 38 additions & 0 deletions Fika.Core/Models/StartDedicatedRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using EFT;
using EFT.Bots;
using JsonType;
using System.Runtime.Serialization;

namespace Fika.Core.Models
{
[DataContract]
public struct StartDedicatedRequest
{
[DataMember(Name = "expectedNumberOfPlayers")]
public int ExpectedNumPlayers { get; set; }

[DataMember(Name = "time")]
public EDateTime Time { get; set; }

[DataMember(Name = "locationId")]
public string LocationId { readonly get; set; }

[DataMember(Name = "spawnPlace")]
public EPlayersSpawnPlace SpawnPlace { readonly get; set; }

[DataMember(Name = "metabolismDisabled")]
public bool MetabolismDisabled { readonly get; set; }

[DataMember(Name = "timeAndWeatherSettings")]
public TimeAndWeatherSettings TimeAndWeatherSettings { readonly get; set; }

[DataMember(Name = "botSettings")]
public BotControllerSettings BotSettings { readonly get; set; }

[DataMember(Name = "wavesSettings")]
public WavesSettings WavesSettings { readonly get; set; }

[DataMember(Name = "side")]
public ESideType Side { readonly get; set; }
}
}
14 changes: 14 additions & 0 deletions Fika.Core/Models/StartDedicatedResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Runtime.Serialization;

namespace Fika.Core.Models
{
[DataContract]
public struct StartDedicatedResponse
{
[DataMember(Name = "matchId")]
public string MatchId { get; set; }

[DataMember(Name = "error")]
public string Error { get; set; }
}
}
135 changes: 135 additions & 0 deletions Fika.Core/Networking/FikaDedicatedWebSocket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
using BepInEx.Logging;
using EFT.UI.Matchmaker;
using EFT.UI;
using EFT;
using Fika.Core.UI.Custom;
using LiteNetLib;
using SPT.Common.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using WebSocketSharp;
using HarmonyLib;
using Newtonsoft.Json.Linq;
using Comfort.Common;

namespace Fika.Core.Networking
{
public class FikaDedicatedWebSocket
{
private static ManualLogSource logger = BepInEx.Logging.Logger.CreateLogSource("Fika.DedicatedWebSocket");

public string Host { get; set; }
public string Url { get; set; }
public string SessionId { get; set; }
public bool Connected
{
get
{
return _webSocket.ReadyState == WebSocketState.Open;
}
}

private WebSocket _webSocket;

public FikaDedicatedWebSocket()
{
Host = RequestHandler.Host.Replace("http", "ws");
SessionId = RequestHandler.SessionId;
Url = $"{Host}/fika/dedicatedraidservice/{SessionId}?";

_webSocket = new WebSocket(Url)
{
WaitTime = TimeSpan.FromMinutes(1),
EmitOnPing = true
};

_webSocket.OnOpen += WebSocket_OnOpen;
//_webSocket.OnError += WebSocket_OnError;
_webSocket.OnMessage += WebSocket_OnMessage;
//_webSocket.OnClose += WebSocket_OnClose;
}

public void Connect()
{
_webSocket.Connect();
}

public void Close()
{
_webSocket.Close();
}


private void WebSocket_OnOpen(object sender, EventArgs e)
{
logger.LogInfo("Connected to FikaNatPunchRelayService as server");
}

private void WebSocket_OnMessage(object sender, MessageEventArgs e)
{
if (e == null)
{
return;
}

if (string.IsNullOrEmpty(e.Data))
{
return;
}

JObject jsonObject = JObject.Parse(e.Data);

if(!jsonObject.ContainsKey("type"))
{
return;
}

string type = jsonObject["type"].ToString();

switch (type)
{
case "fikaDedicatedJoinMatch":

ConsoleScreen.Log("received fikaJoinMatch");
string matchId = jsonObject.Value<string>("matchId");
MatchMakerAcceptScreen matchMakerAcceptScreen = GameObject.FindObjectOfType<MatchMakerAcceptScreen>();
if (matchMakerAcceptScreen == null)
{
PreloaderUI.Instance.ShowErrorScreen("Fika Dedicated Error", "Failed to find MatchMakerAcceptScreen", () =>
{
var acceptScreen = GameObject.FindObjectOfType<MatchMakerAcceptScreen>();
var controller = Traverse.Create(acceptScreen).Field<MatchMakerAcceptScreen.GClass3177>("ScreenController").Value;
controller.CloseScreen();
});

return;
}

if (matchId is not null)
{
//Singleton<GUISounds>.Instance.PlayUISound(EUISoundType.QuestCompleted);
TarkovApplication tarkovApplication = (TarkovApplication)Singleton<ClientApplication<ISession>>.Instance;
tarkovApplication.StartCoroutine(MatchMakerUIScript.JoinMatch(tarkovApplication.Session.Profile.Id, matchId, null, () =>
{
Traverse.Create(matchMakerAcceptScreen).Field<DefaultUIButton>("_acceptButton").Value.OnClick.Invoke();
}));
}
else
{
PreloaderUI.Instance.ShowErrorScreen("Fika Dedicated Error", "Received fikaJoinMatch WS event but there was no matchId", () =>
{
var acceptScreen = GameObject.FindObjectOfType<MatchMakerAcceptScreen>();
var controller = Traverse.Create(acceptScreen).Field<MatchMakerAcceptScreen.GClass3177>("ScreenController").Value;
controller.CloseScreen();
});
}

break;
}
}
}
}
28 changes: 28 additions & 0 deletions Fika.Core/Networking/FikaServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,34 @@ public void OnPeerDisconnected(NetPeer peer, DisconnectInfo disconnectInfo)
{
timeSinceLastPeerDisconnected = DateTime.Now;
}

if (FikaBackendUtils.IsDedicated)
{
if (_netServer.ConnectedPeersCount == 0)
{
foreach (var profile in Singleton<ClientApplication<ISession>>.Instance.Session.AllProfiles)
{
if (profile is null)
{
continue;
}

if (profile.ProfileId == RequestHandler.SessionId)
{
foreach (var bodyPartHealth in profile.Health.BodyParts.Values)
{
bodyPartHealth.Effects.Clear();
bodyPartHealth.Health.Current = bodyPartHealth.Health.Maximum;
}
}
}

// End the raid
Singleton<IFikaGame>.Instance.Stop(Singleton<GameWorld>.Instance.MainPlayer.ProfileId,
Singleton<IFikaGame>.Instance.MyExitStatus,
Singleton<IFikaGame>.Instance.MyExitLocation, 0);
}
}
}

public void WriteNet(NetLogLevel level, string str, params object[] args)
Expand Down
10 changes: 10 additions & 0 deletions Fika.Core/Networking/Http/FikaHttpHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,15 @@ public static async Task<RaidSettingsResponse> GetRaidSettings(RaidSettingsReque
{
return await PostJsonAsync<RaidSettingsRequest, RaidSettingsResponse>("/fika/raid/getsettings", data);
}

public static async Task<StartDedicatedResponse> StartDedicated(StartDedicatedRequest request)
{
return await PostJsonAsync<StartDedicatedRequest, StartDedicatedResponse>("/fika/raid/dedicated/start", request);
}

public static async Task<SetDedicatedStatusResponse> SetDedicatedStatus(SetDedicatedStatusRequest request)
{
return await PostJsonAsync<SetDedicatedStatusRequest, SetDedicatedStatusResponse>("/fika/raid/dedicated/status", request);
}
}
}
Loading

0 comments on commit bc001da

Please sign in to comment.