Skip to content

Commit

Permalink
Handle destroying OnDisable
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Dec 2, 2024
1 parent 82b402c commit bd615a6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,15 @@ private void WebSocket_OnMessage(object sender, MessageEventArgs e)
case "fikaDedicatedJoinMatch":
string matchId = jsonObject.Value<string>("matchId");

GameObject matchmakerObject = MatchmakerAcceptScreen_Show_Patch.MatchmakerObject;
MatchMakerAcceptScreen matchMakerAcceptScreen = FikaBackendUtils.MatchMakerAcceptScreenInstance;

if (!string.IsNullOrEmpty(matchId))
{
TarkovApplication tarkovApplication = (TarkovApplication)Singleton<ClientApplication<ISession>>.Instance;

tarkovApplication.StartCoroutine(MatchMakerUIScript.JoinMatch(tarkovApplication.Session.Profile.Id, matchId, null, (bool success) =>
{
if (success)
{
// Hide matchmaker UI
matchmakerObject.SetActive(false);

// Matchmaker next screen (accept)
matchMakerAcceptScreen.method_19().HandleExceptions();
}
Expand All @@ -126,7 +121,6 @@ private void WebSocket_OnMessage(object sender, MessageEventArgs e)
else
{
PreloaderUI.Instance.ShowErrorScreen("Fika Dedicated Error", "Received fikaJoinMatch WS event but there was no matchId");
matchmakerObject.SetActive(true);
}

FikaPlugin.DedicatedRaidWebSocket.Close();
Expand Down
16 changes: 4 additions & 12 deletions Fika.Core/UI/Custom/MatchMakerUIScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected void OnDisable()
StopCoroutine(serverQueryRoutine);
serverQueryRoutine = null;
}
DestroyThis();
}

protected void Start()
Expand All @@ -78,11 +79,6 @@ protected void Start()

protected void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
DestroyThis();
}

if (stopQuery)
{
if (serverQueryRoutine != null)
Expand Down Expand Up @@ -273,7 +269,6 @@ private void CreateMatchMakerUI()
FikaBackendUtils.HostExpectedNumberOfPlayers = int.Parse(fikaMatchMakerUi.PlayerAmountText.text);
await FikaBackendUtils.CreateMatch(FikaBackendUtils.Profile.ProfileId, FikaBackendUtils.PMCName, raidSettings);
acceptButton.OnClick.Invoke();
DestroyThis();
}
else
{
Expand Down Expand Up @@ -331,7 +326,6 @@ private void CreateMatchMakerUI()
UnityEngine.Events.UnityEvent newEvent = new();
newEvent.AddListener(() =>
{
DestroyThis();
backButton.OnClick.Invoke();
});
DefaultUIButton newButtonComponent = newBackButton.GetComponent<DefaultUIButton>();
Expand Down Expand Up @@ -360,11 +354,10 @@ private void ToggleLoading(bool enabled)
StopCoroutine(serverQueryRoutine);
serverQueryRoutine = null;
}
return;
}
else if (!enabled)
{
serverQueryRoutine = StartCoroutine(ServerQuery());
}

serverQueryRoutine = StartCoroutine(ServerQuery());
}

private void AutoRefresh()
Expand Down Expand Up @@ -554,7 +547,6 @@ private void RefreshUI()
{
if (success)
{
DestroyThis();
acceptButton.OnClick.Invoke();
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using SPT.Reflection.Patching;
using System.Linq;
using System.Reflection;
using UnityEngine;

namespace Fika.Core.UI.Patches.MatchmakerAcceptScreen
{
Expand All @@ -18,22 +17,15 @@ protected override MethodBase GetTargetMethod()
.First(x => x.Name == "Show" && x.GetParameters()[0].Name == "session");
}

public static GameObject MatchmakerObject { get; set; }

[PatchPrefix]
private static void Prefix(ref RaidSettings raidSettings, DefaultUIButton ____acceptButton, DefaultUIButton ____backButton)
private static void Prefix(MatchMakerAcceptScreen __instance, ref RaidSettings raidSettings, DefaultUIButton ____acceptButton, DefaultUIButton ____backButton)
{
if (MatchmakerObject == null)
{
MatchmakerObject = new GameObject("MatchmakerObject");
}

if (raidSettings.Side == ESideType.Savage)
{
raidSettings.RaidMode = ERaidMode.Local;
}

MatchMakerUIScript newMatchMaker = MatchmakerObject.GetOrAddComponent<MatchMakerUIScript>();
MatchMakerUIScript newMatchMaker = __instance.gameObject.GetOrAddComponent<MatchMakerUIScript>();
newMatchMaker.raidSettings = raidSettings;
newMatchMaker.acceptButton = ____acceptButton;
newMatchMaker.backButton = ____backButton;
Expand Down

0 comments on commit bd615a6

Please sign in to comment.