Skip to content

Commit

Permalink
feat!: multiple offraid_position by exfils
Browse files Browse the repository at this point in the history
+ integration with Jehree's Interactable Exfils API
  • Loading branch information
Trap committed Dec 22, 2024
1 parent f43d8a8 commit 0fa13b9
Show file tree
Hide file tree
Showing 23 changed files with 517 additions and 75 deletions.
33 changes: 33 additions & 0 deletions PTT-Plugin/Data/ExfilsTargets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SPT.Common.Http;
using Newtonsoft.Json;

namespace PTT.Data;

/**
* Request
**/
public class ExfilsTargetsRequest
{
public string locationId;
}

/**
* Response
**/
public class ExfilsTargetsResponse
{
// indexed by exit name
public Dictionary<string, List<ExfilTarget>> data;
}

public class ExfilTarget
{
public bool isTransit;
public string transitMapId; // transit only
public string transitSpawnPointId; // transit only
public string offraidPosition; // empty on transit
}
38 changes: 0 additions & 38 deletions PTT-Plugin/Examples.cs

This file was deleted.

21 changes: 21 additions & 0 deletions PTT-Plugin/Helpers/HttpRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using SPT.Common.Http;
using Newtonsoft.Json;

using PTT.Data;

namespace PTT.Helpers;


internal static class HttpRequest
{
private const string EXFILS_TARGETS_PATH = "/PathToTarkov/ExfilsTargets";

static public ExfilsTargetsResponse FetchExfilsTargets(string locationId)
{
string jsonRequest = JsonConvert.SerializeObject(new ExfilsTargetsRequest { locationId = locationId });
string jsonResponse = RequestHandler.PostJson(EXFILS_TARGETS_PATH, jsonRequest);
var response = JsonConvert.DeserializeObject<ExfilsTargetsResponse>(jsonResponse);
return response ?? throw new Exception("FetchExfilsTargets: response is null");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using EFT;

namespace PTT.Utils;
namespace PTT.Helpers;

internal class Trader
{
Expand Down
6 changes: 5 additions & 1 deletion PTT-Plugin/PTT.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net471</TargetFramework>
<AssemblyName>Trap.PathToTarkov</AssemblyName>
<Description>Client patches for Path to Tarkov</Description>
<Version>1.1.0</Version>
Expand Down Expand Up @@ -49,6 +49,10 @@
<Reference Include="InteractableExfilsAPI">
<HintPath>$(PathToSPT)\BepInEx\plugins\InteractableExfilsAPI.dll</HintPath>
</Reference>

<Reference Include="Fika.Core">
<HintPath>$(PathToSPT)\BepInEx\plugins\Fika.Core.dll</HintPath>
</Reference>
</ItemGroup>

<!-- <ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
Expand Down
4 changes: 2 additions & 2 deletions PTT-Plugin/Patches/HideLockedTraderPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected override MethodBase GetTargetMethod() =>
[PatchPostfix]
protected static void Postfix(TraderPanel __instance, ref Profile.TraderInfo trader)
{
if (Utils.Trader.IsHidden(ref trader))
if (Helpers.Trader.IsHidden(ref trader))
{
__instance.HideGameObject();
}
Expand All @@ -30,7 +30,7 @@ protected override MethodBase GetTargetMethod() =>
[PatchPostfix]
protected static void Postfix(TraderCard __instance, ref Profile.TraderInfo trader)
{
if (Utils.Trader.IsHidden(ref trader))
if (Helpers.Trader.IsHidden(ref trader))
{
__instance.HideGameObject();
}
Expand Down
1 change: 0 additions & 1 deletion PTT-Plugin/Patches/InitAllExfiltrationPointsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using EFT;
using EFT.Interactive;
using HarmonyLib;
using System.Runtime.CompilerServices;

namespace PTT.Patches;

Expand Down
32 changes: 32 additions & 0 deletions PTT-Plugin/Patches/OnGameStartedPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Comfort.Common;
using EFT;
using SPT.Reflection.Patching;
using System.Reflection;
using PTT.Services;

namespace PTT.Patches;

internal class OnGameStartedPatch() : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(GameWorld).GetMethod(nameof(GameWorld.OnGameStarted));
}

[PatchPrefix]
public static bool PatchPrefix()
{
var exfilsTargetsService = Singleton<ExfilsTargetsService>.Instance;

if (exfilsTargetsService != null)
{
exfilsTargetsService.Init();
}
else
{
Logger.LogError("[PTT] ExfilsTargetsService instance not found");
}

return true;
}
}
21 changes: 13 additions & 8 deletions PTT-Plugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,44 @@
using Comfort.Common;
using InteractableExfilsAPI.Singletons;

using PTT.Services;
using PTT.Helpers;

namespace PTT;

[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
protected void Awake()
{
Logger.LogInfo($"[PTT] Plugin {PluginInfo.PLUGIN_GUID} is loading...");

Settings.Config.Init(Config);
Singleton<ExfilsTargetsService>.Create(new ExfilsTargetsService(Logger));

new Patches.HideLockedTraderCardPatch().Enable();
new Patches.HideLockedTraderPanelPatch().Enable();
new Patches.InitAllExfiltrationPointsPatch().Enable();
new Patches.ScavExfiltrationPointPatch().Enable();
new Patches.OnGameStartedPatch().Enable();

Logger.LogInfo($"[PTT] Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
}

protected void Start()
{
InteractableExfilsService interactableExfilsService = Singleton<InteractableExfilsService>.Instance;

InteractableExfilsService interactableExfilsService = Singleton<InteractableExfilsService>.Instance;
var exfilsTargetsService = Singleton<ExfilsTargetsService>.Instance;
if (interactableExfilsService != null)
{
interactableExfilsService.OnActionsAppliedEvent += Examples.SimpleExample;
interactableExfilsService.OnActionsAppliedEvent += Examples.RequiresManualActivation;
interactableExfilsService.OnActionsAppliedEvent -= interactableExfilsService.ApplyExtractToggleAction;

Logger.LogInfo($"[PTT] Interactable Exfils API: added custom actions");
var exfilPromptService = new ExfilPromptService(Logger, interactableExfilsService, exfilsTargetsService);
exfilPromptService.InitPromptHandlers();
Logger.LogInfo($"[PTT] Interactable Exfils API: initialized exfils prompt handlers");
}
else
{
Logger.LogError($"[PTT] Interactable exfils API not found");
Logger.LogError($"[PTT] Interactable exfils API: not found");
}

}
}
41 changes: 41 additions & 0 deletions PTT-Plugin/Services/CustomExfilService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using EFT;
using EFT.Interactive;
using Comfort.Common;
using BepInEx.Logging;
using Fika.Core.Coop.GameMode;
using Fika.Core.Coop.Players;
using System.Reflection;
using Fika.Core.Coop.Components;

namespace PTT.Services;

public static class CustomExfilService
{
public static bool FikaExtractTo(ExfiltrationPoint exfiltrationPoint, string customExfilName)
{
// BaseLocalGame<EftGamePlayerOwner> localGame = Singleton<AbstractGame>.Instance as BaseLocalGame<EftGamePlayerOwner>;
// Player player = Singleton<GameWorld>.Instance.MainPlayer;

CoopGame coopGame = (CoopGame)Singleton<IFikaGame>.Instance;
CoopPlayer coopPlayer = (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;

if (coopGame == null || coopPlayer == null)
{
return false;
}

// if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler))
// {
// // coopHandler.ExtractedPlayers.Add(coopPlayer.NetId);
// // coopHandler.Players.Remove(coopPlayer.NetId);

// // coopGame.ExitLocation = exfiltrationPoint.Settings.Name;
// return true;
// }

coopGame.ExitLocation = customExfilName;
coopGame.Extract(coopPlayer, exfiltrationPoint, null);
return true;
}
}
64 changes: 64 additions & 0 deletions PTT-Plugin/Services/CustomTransitService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using EFT;
using Comfort.Common;
using EFT.Interactive;
using Fika.Core.Coop.GameMode;
using Fika.Core.Coop.Players;

namespace PTT.Services;

public static class CustomTransitService
{
public static bool TransitTo(string locationId, string exitName)
{
LocalGame localGame = Singleton<AbstractGame>.Instance as LocalGame;
Player player = Singleton<GameWorld>.Instance.MainPlayer;
if (localGame == null || player == null) return false;
if (!TarkovApplication.Exist(out TarkovApplication tarkovApplication)) return false;
if (!TransitControllerAbstractClass.Exist(out GClass1642 vanillaTransitController)) return false;

// 1. set transitionStatus
var raidSettings = tarkovApplication.CurrentRaidSettings;
var transitionStatus = new GStruct136(locationId, false, raidSettings.Side, raidSettings.RaidMode, raidSettings.SelectedDateTime);
tarkovApplication.transitionStatus = transitionStatus;

// 2. add the transitPayload in alreadyTransits
// this will avoid an error when calling the `LocalRaidEnded` task
string transitHash = Guid.NewGuid().ToString();
GClass1926 transitPayload = new GClass1926
{
hash = transitHash,
playersCount = 1, // TODO: fika support ?
ip = "",
location = locationId,
profiles = [], // TODO: fika support ?
transitionRaidId = raidSettings.KeyId, // pretty sure it's not correct but it seems to not cause any issue
raidMode = raidSettings.RaidMode,
side = (player.Side == EPlayerSide.Savage) ? ESideType.Savage : ESideType.Pmc,
dayTime = raidSettings.SelectedDateTime
};
vanillaTransitController.alreadyTransits.Add(player.ProfileId, transitPayload);

// 3. stop the game
localGame.Stop(player.ProfileId, ExitStatus.Transit, exitName, 0f);

return true;
}

public static bool FikaTransitTo(ExfiltrationPoint exfiltrationPoint)
{
// BaseLocalGame<EftGamePlayerOwner> localGame = Singleton<AbstractGame>.Instance as BaseLocalGame<EftGamePlayerOwner>;
// Player player = Singleton<GameWorld>.Instance.MainPlayer;

// CoopGame coopGame = (CoopGame)Singleton<IFikaGame>.Instance;
// CoopPlayer coopPlayer = (CoopPlayer)Singleton<GameWorld>.Instance.MainPlayer;

// if (coopGame == null || coopPlayer == null)
// {
// return false;
// }

// coopGame.Extract(coopPlayer, exfiltrationPoint);
return true;
}
}
Loading

0 comments on commit 0fa13b9

Please sign in to comment.