-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: transits and exfils prompt (#62)
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
Showing
31 changed files
with
1,320 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.