Skip to content

Commit 60881ba

Browse files
authored
Support for EFT 0.16.1.35392 and SPT-AKI 3.11.1 (#674)
* Initial port * Fix project * Update plugin as well * Restore spawnbot feature * Refactor * Style * Whitelist this plugin for spt-aki beta releases * Use EftBulletClass now * Apply latest be-testing fixes * Bump packages * Introduce defines * Code gardening * Remove watermark * Refactor getting static fields, given sp-tarkov/modules#29 * Use SpawnBotByTypeForce * Use collection expressions * Fix NoMalfunctions * Remove Reflection wrappers * Rename SPT-AKI into SPT * Update version * More renames
1 parent f5dd701 commit 60881ba

37 files changed

+236
-282
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ labels: ''
66
assignees: ''
77
---
88

9-
**Please do not submit bugs for unsupported EFT or unstable SPT-AKI versions**
10-
Double check the [main page](https://github.com/sailro/EscapeFromTarkov-Trainer) for the latest EFT and SPT-AKI versions we support.
9+
**Please do not submit bugs for unsupported EFT or unstable SPT versions**
10+
Double check the [main page](https://github.com/sailro/EscapeFromTarkov-Trainer) for the latest EFT and SPT versions we support.
1111

1212
**Describe the bug**
1313
A clear and concise description of what the bug is.

.github/RELEASE_TEMPLATE/content.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ This is an universal installer for the trainer. In most cases you just need to r
1919
- Still not working? It will then try to disable faulting features.
2020
- No need for SDKs, third party dependencies or Visual Studio, the Installer is self-contained.
2121
- Before EscapeFromTarkov `0.13.0.21531`, it should work for `live` (do not do that, you'll be detected & banned!).
22-
- Given EscapeFromTarkov `0.13.0.21531` or later prevent this trainer to be loaded using NLog configuration. It is now mandatory to use `SPT-AKI/BepInEx` for recent versions.
23-
- **Important**: if you are using `SPT-AKI`, please make sure you have run the game at least once before installing the trainer. `SPT-AKI` is patching binaries during the first run, and we need to compile against those patched binaries. If you install this trainer on stock binaries, the game will freeze at the startup screen.
22+
- Given EscapeFromTarkov `0.13.0.21531` or later prevent this trainer to be loaded using NLog configuration. It is now mandatory to use `SPT/BepInEx` for recent versions.
23+
- **Important**: if you are using `SPT`, please make sure you have run the game at least once before installing the trainer. `SPT` is patching binaries during the first run, and we need to compile against those patched binaries. If you install this trainer on stock binaries, the game will freeze at the startup screen.
2424

2525
![image](https://user-images.githubusercontent.com/638167/146071436-401b4f80-f4bb-4dfb-8cdc-23ef5bfc79c3.png)
2626

2727
## 3- It will copy all needed files for you.
2828
- The freshly-compiled trainer bits will be copied to `EscapeFromTarkov_Data\Managed\NLog.EFT.Trainer.dll`.
2929
- The outline shader will be copied to `EscapeFromTarkov_Data\outline`
3030
- `EscapeFromTarkov_Data\Managed\NLog.dll.nlog` will be created or patched, depending on the content. (This is for legacy EscapeFromTarkov versions, before `0.13.0.21531`).
31-
- It will compile a SPT-AKI/BepInEx plugin named `aki-efttrainer.dll` in `BepInEx\plugins`
31+
- It will compile a SPT/BepInEx plugin named `spt-efttrainer.dll` in `BepInEx\plugins`
3232

3333
![image](https://user-images.githubusercontent.com/638167/211163262-e49bca08-642c-4512-b92f-c2c1de4bead1.png)
3434

3535
## Troubleshooting:
36-
- The game is stuck after installing the trainer : if you are using `SPT-AKI`, please make sure you have run the game at least once before installing the trainer. `SPT-AKI` is patching binaries during the first run, and we need to compile against those patched binaries. If you install this trainer on stock binaries, the game will freeze at the startup screen.
36+
- The game is stuck after installing the trainer : if you are using `SPT`, please make sure you have run the game at least once before installing the trainer. `SPT` is patching binaries during the first run, and we need to compile against those patched binaries. If you install this trainer on stock binaries, the game will freeze at the startup screen.
3737
- The trainer is not loaded : are you sure you are running the proper EFT instance? you can double check with the file `%LOCALAPPDATA%Low\Battlestate Games\EscapeFromTarkov\Player.log`, search for an installation path (often along with `Fallback handler could not load library` errors). Perhaps you forgot to update your shortcuts to `server.exe`/`launcher.exe` files.
3838
- The installer is unable to compile the trainer for an old EFT version : sorry I do not plan to support old versions, please upgrade.
3939
- The installer is unable to compile the trainer for a new EFT version : please file an [issue](https://github.com/sailro/EscapeFromTarkov-Trainer/issues/new/choose).

BepInExPlugin/AkiEftTrainerPlugin.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

BepInExPlugin/BepInExPlugin.csproj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
77
<ProjectGuid>{00C66BBD-ED7F-4E01-B7E4-0388F76FD31C}</ProjectGuid>
88
<OutputType>Library</OutputType>
9-
<AssemblyName>aki-efttrainer</AssemblyName>
9+
<AssemblyName>spt-efttrainer</AssemblyName>
1010
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
1111
<FileAlignment>512</FileAlignment>
1212
<LangVersion>latest</LangVersion>
@@ -23,7 +23,7 @@
2323
<DebugType>full</DebugType>
2424
<Optimize>false</Optimize>
2525
<OutputPath>bin\Debug\</OutputPath>
26-
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<DefineConstants>TRACE;DEBUG</DefineConstants>
2727
<ErrorReport>prompt</ErrorReport>
2828
<WarningLevel>4</WarningLevel>
2929
</PropertyGroup>
@@ -37,9 +37,12 @@
3737
<WarningLevel>4</WarningLevel>
3838
</PropertyGroup>
3939
<ItemGroup>
40+
<!-- Framework -->
4041
<Reference Include="System" />
41-
</ItemGroup>
42-
<ItemGroup>
42+
<Reference Include="System.Core" />
43+
<Reference Include="netstandard">
44+
<HintPath>$(EFTManagedPath)\netstandard.dll</HintPath>
45+
</Reference>
4346
<!-- Unity -->
4447
<Reference Include="UnityEngine">
4548
<HintPath>$(EFTManagedPath)\UnityEngine.dll</HintPath>
@@ -53,7 +56,7 @@
5356
</Reference>
5457
</ItemGroup>
5558
<ItemGroup>
56-
<Compile Include="AkiEftTrainerPlugin.cs" />
59+
<Compile Include="SptEftTrainerPlugin.cs" />
5760
<Compile Include="Properties\AssemblyInfo.cs" />
5861
</ItemGroup>
5962
<ItemGroup>

BepInExPlugin/SptEftTrainerPlugin.cs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using BepInEx;
5+
using EFT.Trainer;
6+
using JetBrains.Annotations;
7+
8+
[BepInPlugin(PluginId, "SPT.EftTrainer", "1.0.0")]
9+
[UsedImplicitly]
10+
public class SptEftTrainerPlugin : BaseUnityPlugin
11+
{
12+
private const string PluginId = "com.SPT.efttrainer";
13+
public static bool Loaded = false;
14+
15+
[UsedImplicitly]
16+
public void Awake()
17+
{
18+
if (Loaded)
19+
return;
20+
21+
Loader.Load();
22+
Loaded = true;
23+
24+
HandleSptBetaReleases();
25+
}
26+
27+
[UsedImplicitly]
28+
public void OnGUI()
29+
{
30+
if (_commitHash == null)
31+
return;
32+
33+
var hash = _commitHash.GetValue(null) as string;
34+
if (hash == string.Empty)
35+
{
36+
// Stop monitoring
37+
_commitHash = null;
38+
return;
39+
}
40+
41+
// Suppress this dumb watermark
42+
_commitHash.SetValue(null, string.Empty);
43+
}
44+
45+
private static FieldInfo _commitHash;
46+
private static void HandleSptBetaReleases()
47+
{
48+
// Whitelist this plugin for spt beta releases
49+
var menuNotificationManager = Type.GetType("SPT.Custom.Utils.MenuNotificationManager, spt-custom", throwOnError: false);
50+
if (menuNotificationManager == null)
51+
return;
52+
53+
var hashField = GetStaticField(menuNotificationManager, "whitelistedPlugins");
54+
if (hashField == null)
55+
return;
56+
57+
var hashset = hashField.GetValue(null) as HashSet<string>;
58+
hashset?.Add(PluginId);
59+
60+
_commitHash = GetStaticField(menuNotificationManager, "commitHash");
61+
}
62+
63+
private static FieldInfo GetStaticField(Type type, string name)
64+
{
65+
return type.GetField(name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)
66+
?? type.GetField(char.ToUpper(name[0]) + name.Substring(1), BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
67+
}
68+
}

Configuration/ColorConverter.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ public override bool CanConvert(Type objectType)
6464
public static string[] ColorNames()
6565
{
6666
var colorType = typeof(Color);
67-
return colorType
67+
return [.. colorType
6868
.GetProperties(BindingFlags.Static | BindingFlags.Public)
6969
.Where(p => p.PropertyType == colorType)
70-
.Select(p => p.Name)
71-
.ToArray();
70+
.Select(p => p.Name)];
7271
}
7372
}

ConsoleCommands/BaseTemplateCommand.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
#nullable enable
1+
#nullable enable
52

63
namespace EFT.Trainer.ConsoleCommands;
74

ConsoleCommands/Spawn.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ internal static void SpawnTemplate(string template, Player player, ConsoleComman
6565

6666
private static void SpawnTemplate(ItemTemplate template, Player player, ConsoleCommand command)
6767
{
68-
var poolManager = Singleton<PoolManager>.Instance;
68+
var poolManager = Singleton<PoolManagerClass>.Instance;
6969

7070
poolManager
71-
.LoadBundlesAndCreatePools(PoolManager.PoolsCategory.Raid, PoolManager.AssemblyType.Online, [.. template.AllResources], JobPriority.Immediate)
71+
.LoadBundlesAndCreatePools(PoolManagerClass.PoolsCategory.Raid, PoolManagerClass.AssemblyType.Online, [.. template.AllResources], JobPriorityClass.Immediate)
7272
.ContinueWith(task =>
7373
{
7474
AsyncWorker.RunInMainTread(delegate

ConsoleCommands/SpawnBot.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ private static void SpawnBots(string[] bots)
5151
return;
5252

5353
var controller = instance.BotsController;
54+
var spawner = controller?.BotSpawner;
55+
56+
if (spawner == null)
57+
return;
5458

5559
foreach (var bot in bots)
56-
controller.SpawnBotDebugServer(EPlayerSide.Savage, false, (WildSpawnType)Enum.Parse(typeof(WildSpawnType), bot), BotDifficulty.normal, true);
60+
spawner.SpawnBotByTypeForce(1, (WildSpawnType)Enum.Parse(typeof(WildSpawnType), bot), BotDifficulty.normal, null);
5761
}
5862

5963
private static string[] FindBots(string search)
@@ -70,9 +74,7 @@ private static string[] FindBots(string search)
7074
if (exactMatch.Length == 1)
7175
return exactMatch;
7276

73-
return names
74-
.Where(n => n.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0)
75-
.ToArray();
77+
return [.. names.Where(n => n.IndexOf(search, StringComparison.OrdinalIgnoreCase) >= 0)];
7678
}
7779

7880
private static string[] GetBotNames()

ConsoleCommands/SpawnHideoutItems.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ public override void Execute()
3535
return;
3636

3737
foreach (var template in templates)
38-
Spawn.SpawnTemplate(template, player, this, i => true);
38+
Spawn.SpawnTemplate(template, player, this, _ => true);
3939
}
4040
}

Extensions/LootableContainerExtensions.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

Features/AirDrop.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Linq;
2-
using Comfort.Common;
32
using EFT.InventoryLogic;
43
using EFT.Trainer.Properties;
54
using JetBrains.Annotations;

Features/Ammunition.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Comfort.Common;
33
using EFT.Ballistics;
44
using EFT.InventoryLogic;
5-
using EFT.Trainer.Model;
65
using EFT.Trainer.Properties;
76
using JetBrains.Annotations;
87

@@ -19,21 +18,20 @@ internal class Ammunition : ToggleFeature
1918
public override bool Enabled { get; set; } = false;
2019

2120
[UsedImplicitly]
22-
private static void ShootPostfix(object shot)
21+
private static void ShootPostfix(EftBulletClass shot)
2322
{
2423
var feature = FeatureFactory.GetFeature<Ammunition>();
2524
if (feature == null || !feature.Enabled)
2625
return;
2726

28-
var shotWrapper = new ShotWrapper(shot);
29-
if (shotWrapper.Weapon is not Weapon weapon)
27+
if (shot.Weapon is not Weapon weapon)
3028
return;
3129

32-
var ammo = shotWrapper.Ammo;
30+
var ammo = shot.Ammo;
3331
if (ammo == null)
3432
return;
3533

36-
var player = shotWrapper.Player;
34+
var player = shot.Player.iPlayer;
3735
if (player is not { IsYourPlayer: true })
3836
return;
3937

@@ -75,7 +73,7 @@ protected override void UpdateWhenEnabled()
7573
{
7674
HarmonyPatchOnce(harmony =>
7775
{
78-
HarmonyPostfix(harmony, typeof(BallisticsCalculator), nameof(BallisticsCalculator.Shoot), nameof(ShootPostfix));
76+
HarmonyPostfix(harmony, typeof(BallisticsCalculator), nameof(BallisticsCalculator.Shoot), nameof(ShootPostfix), [typeof(EftBulletClass)]);
7977
});
8078
}
8179
}

Features/Examine.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using EFT.InventoryLogic;
2-
using EFT.Trainer.ConsoleCommands;
32
using EFT.Trainer.Properties;
43
using JetBrains.Annotations;
54
using static EFT.Player;

Features/Feature.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,31 @@ protected void AddConsoleLog(string log)
9191
ConsoleScreen.Log(log);
9292
}
9393

94-
public override ETranslateResult TranslateCommand(ECommand command)
94+
#if EFT_LIVE
95+
protected
96+
#else
97+
public
98+
#endif
99+
override ETranslateResult TranslateCommand(ECommand command)
95100
{
96101
return ETranslateResult.Ignore;
97102
}
98103

99-
public override void TranslateAxes(ref float[] axes)
104+
#if EFT_LIVE
105+
protected
106+
#else
107+
public
108+
#endif
109+
override void TranslateAxes(ref float[] axes)
100110
{
101111
}
102112

103-
public override ECursorResult ShouldLockCursor()
113+
#if EFT_LIVE
114+
protected
115+
#else
116+
public
117+
#endif
118+
override ECursorResult ShouldLockCursor()
104119
{
105120
return ECursorResult.Ignore;
106121
}

Features/FeatureFactory.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,18 @@ namespace EFT.Trainer.Features;
99
internal static class FeatureFactory
1010
{
1111
private static GameObject? _gameObject = null;
12-
private static readonly Lazy<Type[]> _types = new(() => typeof(FeatureFactory)
12+
private static readonly Lazy<Type[]> _types = new(() => [.. typeof(FeatureFactory)
1313
.Assembly
1414
.GetTypes()
15-
.Where(t => t.IsSubclassOf(typeof(Feature)) && !t.IsAbstract)
16-
.ToArray());
15+
.Where(t => t.IsSubclassOf(typeof(Feature)) && !t.IsAbstract)]);
1716

1817
public static Feature[] RegisterAllFeatures(GameObject gameObject)
1918
{
2019
_gameObject = gameObject;
2120

22-
return GetAllFeatureTypes()
21+
return [.. GetAllFeatureTypes()
2322
.Select(gameObject.GetOrAddComponent)
24-
.OfType<Feature>()
25-
.ToArray();
23+
.OfType<Feature>()];
2624
}
2725

2826
public static Type[] GetAllFeatureTypes()
@@ -42,16 +40,13 @@ public static Feature[] GetAllFeatures()
4240
if (_gameObject == null)
4341
return [];
4442

45-
return GetAllFeatureTypes()
43+
return [.. GetAllFeatureTypes()
4644
.Select(_gameObject.GetComponent)
47-
.OfType<Feature>()
48-
.ToArray();
45+
.OfType<Feature>()];
4946
}
5047

5148
public static ToggleFeature[] GetAllToggleableFeatures()
5249
{
53-
return GetAllFeatures()
54-
.OfType<ToggleFeature>()
55-
.ToArray();
50+
return [.. GetAllFeatures().OfType<ToggleFeature>()];
5651
}
5752
}

0 commit comments

Comments
 (0)