Skip to content

Commit

Permalink
feat: transits and exfils prompt (#62)
Browse files Browse the repository at this point in the history
based on #61 

## Remaining TODOs
- [x] check for "." in spawnConfig
- [x] check for "." in offraid positions (check in "infiltrations")
- [x] check for "." in exfil names (check "exfiltrations")
- [x] universal build (should work without fika)
  • Loading branch information
guillaumearm authored Dec 25, 2024
2 parents 9a2d95f + 4923686 commit f7fa6a1
Show file tree
Hide file tree
Showing 31 changed files with 1,320 additions and 212 deletions.
55 changes: 55 additions & 0 deletions PTT-Plugin/Data/ExfilsTargets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SPT.Common.Http;
using Newtonsoft.Json;
using EFT.Interactive;

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

// TODO: i18n support (use the offraid position displayName)
public string GetCustomActionName()
{
if (isTransit)
{
return $"Transit to {transitMapId}";
}

return $"Extract to {offraidPosition}";
}

public string GetCustomExitName(ExfiltrationPoint exfil)
{
if (isTransit)
{
return $"{exfil.Settings.Name}.{transitMapId}.{transitSpawnPointId}";
}

return $"{exfil.Settings.Name}.{offraidPosition}";
}
}
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");
}
}
28 changes: 28 additions & 0 deletions PTT-Plugin/Helpers/Logger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using BepInEx.Logging;

namespace PTT.Helpers;

internal static class Logger
{
private static ManualLogSource _logger;

internal static void Init(ManualLogSource logger)
{
_logger = logger;
}

internal static void Info(string content)
{
_logger.LogInfo($"[PTT] {content}");
}

internal static void Warning(string content)
{
_logger.LogWarning($"[PTT] Warning: {content}");
}

internal static void Error(string content)
{
_logger.LogError($"[PTT] Error: {content}");
}
}
4 changes: 2 additions & 2 deletions PTT-Plugin/Utils/Trader.cs → PTT-Plugin/Helpers/Trader.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using EFT;

namespace PTT.Utils;
namespace PTT.Helpers;

internal class Trader
internal static class Trader
{
internal static bool IsHidden(ref Profile.TraderInfo trader)
{
Expand Down
30 changes: 30 additions & 0 deletions PTT-Plugin/Helpers/Transit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using EFT.Interactive;
using PTT.Data;

namespace PTT.Helpers;

internal static class Transit
{
static public TransitPoint Create(ExfiltrationPoint exfil, ExfilTarget exfilTarget)
{
string locationId = exfilTarget.transitMapId;
string customTransitName = exfilTarget.GetCustomExitName(exfil);

return new TransitPoint
{
Enabled = true,
IsActive = true,
// Controller = vanillaTransitController, // not needed
parameters = new LocationSettingsClass.Location.TransitParameters
{
active = true,
id = 1,
name = customTransitName,
description = customTransitName,
conditions = string.Empty,
target = "", // should be "_Id" of the corresponding location base but not needed here
location = locationId,
}
};
}
}
45 changes: 34 additions & 11 deletions PTT-Plugin/PTT.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<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>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<PathToSPT>..\..\..\..</PathToSPT>
</PropertyGroup>

<ItemGroup>
Expand All @@ -15,24 +15,47 @@
</ItemGroup>

<ItemGroup>
<Reference Include="spt-reflection">
<HintPath>..\..\..\..\BepInEx\plugins\spt\spt-reflection.dll</HintPath>
<Reference Include="spt-common">
<HintPath>$(PathToSPT)\BepInEx\plugins\spt\spt-common.dll</HintPath>
</Reference>
<Reference Include="Sirenix.Serialization">
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\Sirenix.Serialization.dll</HintPath>
<Reference Include="spt-reflection">
<HintPath>$(PathToSPT)\BepInEx\plugins\spt\spt-reflection.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>$(PathToSPT)\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
<Reference Include="Comfort">
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\Comfort.dll</HintPath>
</Reference>
<Reference Include="Comfort.Unity">
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\Comfort.Unity.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="Sirenix.Serialization">
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\Sirenix.Serialization.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>$(PathToSPT)\EscapeFromTarkov_Data\Managed\Newtonsoft.Json.dll</HintPath>
</Reference>

<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'">
<!-- <ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>
</ItemGroup> -->
</Project>
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
11 changes: 7 additions & 4 deletions PTT-Plugin/Patches/InitAllExfiltrationPointsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using SPT.Reflection.Patching;
using EFT;
using EFT.Interactive;
using HarmonyLib;

Expand Down Expand Up @@ -38,7 +39,7 @@ protected override MethodBase GetTargetMethod()
}

[PatchPrefix]
protected static bool PatchPrefix(ref ExfiltrationControllerClass __instance, LocationExitClass[] settings, bool justLoadSettings = false, bool giveAuthority = true)
protected static bool PatchPrefix(ref ExfiltrationControllerClass __instance, MongoID locationId, LocationExitClass[] settings, bool justLoadSettings = false, string disabledScavExits = "", bool giveAuthority = true)
{
ExfiltrationPoint[] source = LocationScene.GetAllObjects<ExfiltrationPoint>(false).ToArray();
ExfiltrationPoint[] scavExfilArr = source.Where(new Func<ExfiltrationPoint, bool>(IsScavExfil)).ToArray();
Expand Down Expand Up @@ -66,7 +67,7 @@ protected static bool PatchPrefix(ref ExfiltrationControllerClass __instance, Lo

foreach (ScavExfiltrationPoint scavExfiltrationPoint in __instance.ScavExfiltrationPoints)
{
Logger.LogWarning("Scav Exfil name = " + scavExfiltrationPoint.Settings.Name);
Helpers.Logger.Info("Scav Exfil name = " + scavExfiltrationPoint.Settings.Name);
SharedExfiltrationPoint sharedExfiltrationPoint = scavExfiltrationPoint as SharedExfiltrationPoint;
if (sharedExfiltrationPoint != null && sharedExfiltrationPoint.IsMandatoryForScavs)
{
Expand All @@ -84,12 +85,14 @@ protected static bool PatchPrefix(ref ExfiltrationControllerClass __instance, Lo

foreach (ExfiltrationPoint exfiltrationPoint in __instance.ExfiltrationPoints)
{
Logger.LogWarning("PMC Exfil name = " + exfiltrationPoint.Settings.Name);
Helpers.Logger.Info("PMC Exfil name = " + exfiltrationPoint.Settings.Name);
exitName = exfiltrationPoint.Settings.Name;
LocationExitClass locationExit = settings.FirstOrDefault(new Func<LocationExitClass, bool>(NameMatches));
int num = Array.IndexOf(source, exfiltrationPoint) + 1;
MongoID mongoID = locationId.Add(num + 1);
if (locationExit != null)
{
exfiltrationPoint.LoadSettings(exfiltrationPoint.Id, locationExit, giveAuthority);
exfiltrationPoint.LoadSettings(mongoID, locationExit, giveAuthority);
if (!justLoadSettings && !RandomRange(exfiltrationPoint))
{
exfiltrationPoint.SetStatusLogged(EExfiltrationStatus.NotPresent, "ExfiltrationController.InitAllExfiltrationPoints-2");
Expand Down
21 changes: 21 additions & 0 deletions PTT-Plugin/Patches/LocalRaidStartedPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Comfort.Common;
using EFT;
using SPT.Reflection.Patching;
using System.Reflection;
using PTT.Services;

namespace PTT.Patches;

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

[PatchPostfix]
public static void PatchPostfix(Class301 __instance, LocalRaidSettings settings)
{
LocalRaidSettingsRetriever.Settings = settings;
}
}
30 changes: 30 additions & 0 deletions PTT-Plugin/Patches/OnGameStartedPatch.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;

namespace PTT.Patches;

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

[PatchPrefix]
public static bool PatchPrefix()
{
if (Plugin.ExfilsTargetsService != null)
{
Plugin.ExfilsTargetsService.Init();
}
else
{
Helpers.Logger.Error("ExfilsTargetsService instance not found");
}

return true;
}
}
40 changes: 37 additions & 3 deletions PTT-Plugin/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
using BepInEx;
using BepInEx.Logging;
using BepInEx.Bootstrap;

using PTT.Services;

namespace PTT;

[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
public void Awake()
public static bool FikaIsInstalled { get; private set; }
public static ManualLogSource LogSource { get; private set; }
public static ExfilsTargetsService ExfilsTargetsService;

private static bool InteractableExfilsApiIsInstalled { get; set; }

protected void Awake()
{
Settings.Config.Init(Config);
Helpers.Logger.Init(Logger);
Helpers.Logger.Info($"Plugin {PluginInfo.PLUGIN_GUID} is loading...");

LogSource = Logger;
FikaIsInstalled = Chainloader.PluginInfos.ContainsKey("com.fika.core");
InteractableExfilsApiIsInstalled = Chainloader.PluginInfos.ContainsKey("Jehree.InteractableExfilsAPI");

ExfilsTargetsService = new ExfilsTargetsService();

if (FikaIsInstalled)
{
Helpers.Logger.Info($"Fika.Core plugin detected");
}

Settings.Config.Init(Config);
new Patches.HideLockedTraderCardPatch().Enable();
new Patches.HideLockedTraderPanelPatch().Enable();
new Patches.InitAllExfiltrationPointsPatch().Enable();
new Patches.ScavExfiltrationPointPatch().Enable();
new Patches.OnGameStartedPatch().Enable();
new Patches.LocalRaidStartedPatch().Enable();

Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
Helpers.Logger.Info($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
}

protected void Start()
{
if (InteractableExfilsApiIsInstalled)
{
Helpers.Logger.Info($"Jehree.InteractableExfilsAPI plugin detected");
IEApiWrapper.Init(ExfilsTargetsService);
}
}
}
Loading

0 comments on commit f7fa6a1

Please sign in to comment.