Skip to content

Commit

Permalink
fix(client): quests/achievements related to exitName
Browse files Browse the repository at this point in the history
The PTT custom extract name is used only at the end of the process.
In other words, we use the custom extract name only for the server-side
and let the client handle his stuff with the vanilla exitName value.
  • Loading branch information
guillaumearm committed Jan 1, 2025
1 parent 5350ef8 commit f4c5434
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 17 deletions.
30 changes: 30 additions & 0 deletions PTT-Plugin/Patches/LocalRaidEndedPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Comfort.Common;
using EFT;
using SPT.Reflection.Patching;
using System.Reflection;
using PTT.Services;
using System.Linq;
using System.Collections.Generic;

namespace PTT.Patches;

internal class LocalRaidEndedPatch() : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(Class301).GetMethod(nameof(Class301.LocalRaidEnded));
}

[PatchPrefix]
public static bool PatchPrefix(Class301 __instance, LocalRaidSettings settings, ref GClass1924 results, GClass1301[] lostInsuredItems, Dictionary<string, GClass1301[]> transferItems)
{
string customExtractName = Plugin.ExfilsTargetsService.ConsumeExtractName();

if (customExtractName != null)
{
results.exitName = customExtractName;
}

return true;
}
}
1 change: 1 addition & 0 deletions PTT-Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected void Awake()
new Patches.ScavExfiltrationPointPatch().Enable();
new Patches.OnGameStartedPatch().Enable();
new Patches.LocalRaidStartedPatch().Enable();
new Patches.LocalRaidEndedPatch().Enable();
new Patches.MenuScreenAwakePatch().Enable();

Helpers.Logger.Info($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
Expand Down
9 changes: 3 additions & 6 deletions PTT-Plugin/Services/CustomExfilService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public static void ExtractTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)

LocalGame localGame = Singleton<AbstractGame>.Instance as LocalGame;
Player player = Singleton<GameWorld>.Instance.MainPlayer;
string customExtractName = exfilTarget.GetCustomExitName(exfil);

Logger.Info($"started extraction on '{customExtractName}'");
Logger.Info($"started extraction on '{exfilTarget.GetCustomExitName(exfil)}'");

if (localGame == null)
{
Expand All @@ -38,7 +36,7 @@ public static void ExtractTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
}

float delay = 0f;
localGame.Stop(player.ProfileId, ExitStatus.Survived, customExtractName, delay);
localGame.Stop(player.ProfileId, ExitStatus.Survived, exfil.Settings.Name, delay);
Logger.Info($"local game stopped for profile '${player.ProfileId}'");
}

Expand All @@ -51,8 +49,7 @@ public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
}

TransitPoint transit = Transit.Create(exfil, exfilTarget);
string customTransitName = transit.parameters.name;
Logger.Info($"started transit on '{customTransitName}'");
Logger.Info($"started transit on '{transit.parameters.name}'");

if (!TransitControllerAbstractClass.Exist(out GClass1642 vanillaTransitController))
{
Expand Down
13 changes: 4 additions & 9 deletions PTT-Plugin/Services/CustomExfilServiceFika.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public static void ExtractTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
{
CoopGame coopGame = (CoopGame)Singleton<IFikaGame>.Instance;
CoopPlayer coopPlayer = (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;

string customExtractName = exfilTarget.GetCustomExitName(exfil);
Logger.Info($"(FIKA) started extraction on '{customExtractName}'");
Logger.Info($"(FIKA) started extraction on '{exfilTarget.GetCustomExitName(exfil)}'");

if (coopGame == null)
{
Expand All @@ -32,19 +30,16 @@ public static void ExtractTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
return;
}

coopGame.ExitLocation = customExtractName; // not sure if it's needed
coopGame.ExitLocation = exfil.Settings.Name;
coopGame.Extract(coopPlayer, exfil, null);
Logger.Info($"(FIKA) extraction done for profile {coopPlayer.ProfileId}");

}

public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
{
CoopGame coopGame = (CoopGame)Singleton<IFikaGame>.Instance;
CoopPlayer coopPlayer = (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;

string customTransitName = exfilTarget.GetCustomExitName(exfil);
Logger.Info($"started transit on '{customTransitName}'");
Logger.Info($"started transit on '{exfilTarget.GetCustomExitName(exfil)}'");

if (coopGame == null)
{
Expand Down Expand Up @@ -92,7 +87,7 @@ public static void TransitTo(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
transitController.alreadyTransits.Add(coopPlayer.ProfileId, transitPayload);

// 3. trigger extract
coopGame.ExitLocation = customTransitName; // not sure if it's needed
coopGame.ExitLocation = exfil.Settings.Name;
coopGame.Extract(coopPlayer, null, transit);
Logger.Info($"(FIKA) transit done for profile '${coopPlayer.ProfileId}'");
}
Expand Down
6 changes: 4 additions & 2 deletions PTT-Plugin/Services/ExfilPromptService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ private CustomExfilAction CreateCustomExfilAction(ExfiltrationPoint exfil, Exfil
{
_actionToExecuteOnConfirm = () =>
{
Sound.PlayTransitConfirm();
Plugin.ExfilsTargetsService.SaveExfil(exfil, exfilTarget);
CustomExfilService.TransitTo(exfil, exfilTarget);
Sound.PlayTransitConfirm();
};
Sound.PlayMenuEnter();
SelectFirstPromptItem();
Expand All @@ -84,8 +85,9 @@ private CustomExfilAction CreateCustomExfilAction(ExfiltrationPoint exfil, Exfil
{
_actionToExecuteOnConfirm = () =>
{
Sound.PlayExtractConfirm();
Plugin.ExfilsTargetsService.SaveExfil(exfil, exfilTarget);
CustomExfilService.ExtractTo(exfil, exfilTarget);
Sound.PlayExtractConfirm();
};
Sound.PlayMenuEnter();
SelectFirstPromptItem();
Expand Down
14 changes: 14 additions & 0 deletions PTT-Plugin/Services/ExfilsTargetsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,32 @@
using PTT.Data;
using PTT.Helpers;
using Comfort.Common;
using EFT.Interactive;

namespace PTT.Services;

public class ExfilsTargetsService
{
public ExfilsTargetsResponse ExfilsTargets { get; private set; } = new() { data = { } };
private string UsedCustomExtractName { get; set; } = null;

public void Init()
{
FetchExfilsTargetsForCurrentLocation();
}

public void SaveExfil(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
{
UsedCustomExtractName = exfilTarget.GetCustomExitName(exfil);
}

public string ConsumeExtractName()
{
string extractName = UsedCustomExtractName;
UsedCustomExtractName = null;
return extractName;
}

private void FetchExfilsTargetsForCurrentLocation()
{
string locationId = Singleton<GameWorld>.Instance?.LocationId;
Expand Down

0 comments on commit f4c5434

Please sign in to comment.