Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom extracts fully implemented 😎 #54

Open
wants to merge 8 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
266 changes: 266 additions & 0 deletions PTT-Extracts/Core/CustomExtractHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
#if !UNITY_EDITOR
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using EFT.Interactive;
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using System.IO;
using Newtonsoft.Json;
using EFT.InventoryLogic;
using Comfort.Common;
using EFT;
using EFT.UI;
using static EFT.SpeedTree.TreeWind;
using UnityEngine.SceneManagement;
using PTTExtracts.Utils;
using SPT.Common.Http;
using System.Xml;

namespace PTTExtracts.Core
{
public static class CustomExtractHandler
{
public static List<ExitGroup> customExtracts;

public static void PatchExfiltrationPoints(List<ExfiltrationPoint> pmcExfilList)
{
// Ensure that custom extracts are loaded
if (customExtracts == null)
{
Console.WriteLine("Custom extracts are not loaded. Requesting data from the server now...");
CustomExtractUtils.LoadCustomExtracts(); // Ensure that the static field is set
}

// If customExtracts is still null after attempting to load, log an error and return
if (customExtracts == null)
{
Console.WriteLine("Custom extracts could not be loaded. Exiting PatchExfiltrationPoints.");
return;
}

string currentLocationId = CustomExtractUtils.GetCurrentLocationId()?.ToLower();

// Proceed with processing if customExtracts is not null

foreach (var exitGroup in customExtracts)
{
if (exitGroup.Id.ToLower() != currentLocationId)
{
continue;
}

foreach (var exitData in exitGroup.exits)
{
Vector3 position = new Vector3(exitData.CubeData.Position.x, exitData.CubeData.Position.y, exitData.CubeData.Position.z);
Vector3 scale = new Vector3(exitData.CubeData.Scale.x, exitData.CubeData.Scale.y, exitData.CubeData.Scale.z);
Quaternion rotation = Quaternion.Euler(exitData.CubeData.Rotation.x, exitData.CubeData.Rotation.y, exitData.CubeData.Rotation.z);
string name = exitData.CubeData.Name;

GameObject newExtractObject = CustomExtractUtils.CreateExtractionGameObject(position, scale, rotation, name);

if (newExtractObject == null)
{
continue;
}

ExfiltrationPoint newExtractData = CustomExtractUtils.InitializeExtractionData(newExtractObject, exitData);
pmcExfilList.Add(newExtractData);
}
}
}

}

public class CustomExtractUtils
{
public static void LoadCustomExtracts()
{
try
{
var response = WebRequestUtils.Get<ResponseWrapper<List<ExitGroup>>>("/PathToTarkov/CustomExtracts");

if (response != null && response.Success)
{
CustomExtractHandler.customExtracts = response.Data;
Console.WriteLine("Custom extracts successfully retrieved from the server.");
// Log the entire list by serializing it to JSON
var jsonExtracts = JsonConvert.SerializeObject(CustomExtractHandler.customExtracts, Newtonsoft.Json.Formatting.Indented);

}
else
{
Console.WriteLine("Error retrieving custom extracts: No data or response was unsuccessful.");
}
}
catch (Exception ex)
{
Console.WriteLine("Error loading custom extracts: " + ex.Message);
}
}


public static string GetCurrentLocationId()
{
TarkovApplication tarkovApplication = (TarkovApplication)Singleton<ClientApplication<ISession>>.Instance;

RaidSettings currentRaidSettings = (RaidSettings)typeof(TarkovApplication)
.GetField("_raidSettings", BindingFlags.Instance | BindingFlags.NonPublic)
.GetValue(tarkovApplication);

return currentRaidSettings?.SelectedLocation?.Id;
}

public static GameObject CreateExtractionGameObject(Vector3 position, Vector3 scale, Quaternion rotation, string name)
{
try
{
GameObject newCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
newCube.name = name;
newCube.GetComponent<MeshRenderer>().enabled = false;
BoxCollider boxCollider = newCube.AddComponent<BoxCollider>();
newCube.transform.position = position;
newCube.transform.localScale = scale;
newCube.transform.rotation = rotation;
newCube.AddComponent<ExfiltrationPoint>().ExtendedCollider = boxCollider;

return newCube;
}
catch (Exception ex)
{
Console.WriteLine("Error creating new extract game object: " + ex.Message);
return null;
}
}

public static ExfiltrationPoint InitializeExtractionData(GameObject extractObject, ExitData exitData)
{
try
{
ExfiltrationPoint exfiltrationPointScript = extractObject.GetComponent<ExfiltrationPoint>();
// Assuming EExfiltrationStatus is an enum
if (Enum.TryParse<EExfiltrationStatus>(exitData?.AdditionalSettings?.Status, out EExfiltrationStatus parsedStatus))
{
exfiltrationPointScript.Status = parsedStatus;
}
else
{
// Handle the case where parsing fails
Console.WriteLine($"Error parsing exfiltration status: {exitData?.AdditionalSettings?.Status}");
// Sets default status to "RegularMode"
exfiltrationPointScript.Status = EExfiltrationStatus.RegularMode;
Console.WriteLine("Set status to RegularMode");
}

exfiltrationPointScript.ExfiltrationStartTime = 0f;
exfiltrationPointScript.Settings.Name = exitData?.ExtractData?.Name;
exfiltrationPointScript.Settings.ExfiltrationType = exitData?.ExtractData?.ExfiltrationType ?? default(EExfiltrationType);
exfiltrationPointScript.Settings.ExfiltrationTime = exitData?.ExtractData?.ExfiltrationTime ?? 0f;
exfiltrationPointScript.Settings.PlayersCount = exitData?.ExtractData?.PlayersCount ?? 0;
exfiltrationPointScript.Settings.Chance = exitData?.ExtractData?.Chance ?? 0;
exfiltrationPointScript.Settings.MinTime = exitData?.ExtractData?.MinTime ?? 0f;
exfiltrationPointScript.Settings.MaxTime = exitData?.ExtractData?.MaxTime ?? 0f;
exfiltrationPointScript.Settings.StartTime = exitData?.AdditionalSettings?.StartTime ?? 0;

ExfiltrationRequirement requirement = new ExfiltrationRequirement();
if (Enum.TryParse<ERequirementState>(exitData?.ExtractData?.Requirement, out ERequirementState parsedRequirement))
{
requirement.Requirement = parsedRequirement;
#if DEBUG
Console.WriteLine($"Extract Requirement: {requirement.Requirement}");
#endif
}
else
{
// Handle the case where the string doesn't match any enum value
Console.WriteLine($"Error parsing requirement state: {exitData?.ExtractData?.Requirement}");
// Sets default state to None
requirement.Requirement = ERequirementState.None;
Console.WriteLine("Set requirement state to None");
}
requirement.Id = exitData?.ExtractData?.Id;
requirement.Count = exitData?.ExtractData?.Count ?? 69;
if (Enum.TryParse<EquipmentSlot>(exitData?.ExtractData?.RequiredSlot, out EquipmentSlot parsedSlot))
{
requirement.RequiredSlot = parsedSlot;
#if DEBUG
Console.WriteLine($"Parsed Required Slot: {requirement.RequiredSlot}");
#endif
}
else
{
Console.WriteLine($"Error parsing equipment slot: {exitData?.ExtractData?.RequiredSlot}");
}
requirement.RequirementTip = exitData?.ExtractData?.RequirementTip; // Replace with the desired tip
#if DEBUG
Console.WriteLine($"Requirement Tip: {requirement.RequirementTip}");
#endif
exfiltrationPointScript.Requirements = new ExfiltrationRequirement[] { requirement };
#if DEBUG
Console.WriteLine("Requirements added successfully.");
#endif
return exfiltrationPointScript;

}
catch (Exception ex)
{
Console.WriteLine("Error initializing ExfiltrationPoint data: " + ex.Message);
return null;
}
}

}

public class ExitData
{
public ExtractData ExtractData { get; set; }
public AdditionalSettings AdditionalSettings { get; set; }
public CubeData CubeData { get; set; } // Add this property
}
public class PositionData
{
public float x { get; set; }
public float y { get; set; }
public float z { get; set; }
}
public class ExtractData
{
public int Chance { get; set; }
public string EntryPoints { get; set; }
public float ExfiltrationTime { get; set; }
public string Id { get; set; }
public float MaxTime { get; set; }
public float MinTime { get; set; }
public string Name { get; set; }
public int PlayersCount { get; set; }
public string Requirement { get; set; }
public int Count { get; set; }
public string RequiredSlot { get; set; }
public string RequirementTip { get; set; }
public EExfiltrationType ExfiltrationType { get; set; } // Add this property
}
public class AdditionalSettings
{
public int StartTime { get; set; }
public string Status { get; set; }
}
public class ExitGroup
{
public string Id { get; set; }
public List<ExitData> exits { get; set; }
}
public class CubeData
{
public string Name { get; set; }
public PositionData Position { get; set; }
public Vector3 Scale { get; set; }
public Vector3 Rotation { get; set; }
}

}
#endif
47 changes: 34 additions & 13 deletions PTT-Extracts/PTTExtracts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,53 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>PTTExtracts</AssemblyName>
<Description>Unlock scavs exfiltrations for PMCs (Patches for Path to Tarkov)</Description>
<Version>1.0.1</Version>
<Description>Extract Patches for Path to Tarkov</Description>
<Version>1.0.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
</ItemGroup>

<ItemGroup>
<Reference Include="spt-reflection">
<HintPath>..\..\..\..\BepInEx\plugins\spt\spt-reflection.dll</HintPath>
<Reference Include="0Harmony, Version=2.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\BepInEx\core\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Comfort, Version=1.0.0.4, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\Comfort.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="UnityEngine">
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="spt-common">
<HintPath>..\..\..\..\BepInEx\plugins\spt\spt-common.dll</HintPath>
</Reference>
<Reference Include="spt-reflection">
<HintPath>..\..\..\..\BepInEx\plugins\spt\spt-reflection.dll</HintPath>
</Reference>
<Reference Include="uLipSync.Runtime">
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\uLipSync.Runtime.dll</HintPath>
</Reference>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup>

<Reference Include="BepInEx">
<HintPath>..\..\..\..\BepInEx\core\BepInEx.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\..\..\..\EscapeFromTarkov_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
</ItemGroup>
Expand Down
Loading
Loading