Skip to content

Commit 2e61c0d

Browse files
committed
Random fixes
- Add my new dependency checker, not really useful for Waypoints, but I gotta put the code somewhere - Add a new patch for GetCall in AICellData, so we don't go out of bounds on maps like Streets and throw an exception - Bump version
1 parent ef499b5 commit 2e61c0d

File tree

5 files changed

+167
-3
lines changed

5 files changed

+167
-3
lines changed

DrakiaXYZ-Waypoints.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@
125125
<Compile Include="ConfigurationManagerAttributes.cs" />
126126
<Compile Include="CustomWaypoint.cs" />
127127
<Compile Include="CustomWaypointLoader.cs" />
128+
<Compile Include="Helpers\DependencyChecker.cs" />
128129
<Compile Include="Helpers\PatrolWayCustom.cs" />
129130
<Compile Include="Helpers\ExportModel.cs" />
130131
<Compile Include="Helpers\GameObjectHelper.cs" />
131132
<Compile Include="Helpers\Settings.cs" />
133+
<Compile Include="Patches\AICellDataGetCellPatch.cs" />
132134
<Compile Include="Patches\DebugPatch.cs" />
133135
<Compile Include="Patches\DoorBlockerPatch.cs" />
134136
<Compile Include="Patches\EditorPatch.cs" />

Helpers/DependencyChecker.cs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using BepInEx;
2+
using BepInEx.Bootstrap;
3+
using BepInEx.Configuration;
4+
using BepInEx.Logging;
5+
using System;
6+
using UnityEngine;
7+
8+
namespace DrakiaXYZ.Helpers
9+
{
10+
internal class DependencyChecker
11+
{
12+
/// <summary>
13+
/// Check that all of the BepInDependency entries for the given pluginType are available and instantiated. This allows a
14+
/// plugin to validate that its dependent plugins weren't disabled post-dependency check (Such as for the wrong EFT version)
15+
/// </summary>
16+
/// <param name="Logger"></param>
17+
/// <param name="Info"></param>
18+
/// <param name="pluginType"></param>
19+
/// <param name="Config"></param>
20+
/// <returns></returns>
21+
public static bool ValidateDependencies(ManualLogSource Logger, PluginInfo Info, Type pluginType, ConfigFile Config = null)
22+
{
23+
var noVersion = new Version("0.0.0");
24+
var dependencies = pluginType.GetCustomAttributes(typeof(BepInDependency), true) as BepInDependency[];
25+
26+
foreach (var dependency in dependencies)
27+
{
28+
PluginInfo pluginInfo;
29+
if (!Chainloader.PluginInfos.TryGetValue(dependency.DependencyGUID, out pluginInfo))
30+
{
31+
pluginInfo = null;
32+
}
33+
34+
// If the plugin isn't found, or the instance isn't enabled, it means the required plugin failed to load
35+
if (pluginInfo == null || pluginInfo.Instance?.enabled == false)
36+
{
37+
string dependencyName = pluginInfo?.Metadata.Name ?? dependency.DependencyGUID;
38+
string dependencyVersion = "";
39+
if (dependency.MinimumVersion > noVersion)
40+
{
41+
dependencyVersion = $" v{dependency.MinimumVersion}";
42+
}
43+
44+
string errorMessage = $"ERROR: This version of {Info.Metadata.Name} v{Info.Metadata.Version} depends on {dependencyName}{dependencyVersion}, but it was not loaded.";
45+
Logger.LogError(errorMessage);
46+
Chainloader.DependencyErrors.Add(errorMessage);
47+
48+
if (Config != null)
49+
{
50+
// This results in a bogus config entry in the BepInEx config file for the plugin, but it shouldn't hurt anything
51+
// We leave the "section" parameter empty so there's no section header drawn
52+
Config.Bind("", "MissingDeps", "", new ConfigDescription(
53+
errorMessage, null, new ConfigurationManagerAttributes
54+
{
55+
CustomDrawer = ErrorLabelDrawer,
56+
ReadOnly = true,
57+
HideDefaultButton = true,
58+
HideSettingName = true,
59+
Category = null
60+
}
61+
));
62+
}
63+
64+
return false;
65+
}
66+
}
67+
68+
return true;
69+
}
70+
71+
static void ErrorLabelDrawer(ConfigEntryBase entry)
72+
{
73+
GUIStyle styleNormal = new GUIStyle(GUI.skin.label);
74+
styleNormal.wordWrap = true;
75+
styleNormal.stretchWidth = true;
76+
77+
GUIStyle styleError = new GUIStyle(GUI.skin.label);
78+
styleError.stretchWidth = true;
79+
styleError.alignment = TextAnchor.MiddleCenter;
80+
styleError.normal.textColor = Color.red;
81+
styleError.fontStyle = FontStyle.Bold;
82+
83+
// General notice that we're the wrong version
84+
GUILayout.BeginVertical();
85+
GUILayout.Label(entry.Description.Description, styleNormal, new GUILayoutOption[] { GUILayout.ExpandWidth(true) });
86+
87+
// Centered red disabled text
88+
GUILayout.Label("Plugin has been disabled!", styleError, new GUILayoutOption[] { GUILayout.ExpandWidth(true) });
89+
GUILayout.EndVertical();
90+
}
91+
92+
#pragma warning disable 0169, 0414, 0649
93+
internal sealed class ConfigurationManagerAttributes
94+
{
95+
public bool? ShowRangeAsPercent;
96+
public System.Action<BepInEx.Configuration.ConfigEntryBase> CustomDrawer;
97+
public CustomHotkeyDrawerFunc CustomHotkeyDrawer;
98+
public delegate void CustomHotkeyDrawerFunc(BepInEx.Configuration.ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput);
99+
public bool? Browsable;
100+
public string Category;
101+
public object DefaultValue;
102+
public bool? HideDefaultButton;
103+
public bool? HideSettingName;
104+
public string Description;
105+
public string DispName;
106+
public int? Order;
107+
public bool? ReadOnly;
108+
public bool? IsAdvanced;
109+
public System.Func<object, string> ObjToStr;
110+
public System.Func<string, object> StrToObj;
111+
}
112+
}
113+
}

Patches/AICellDataGetCellPatch.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Aki.Reflection.Patching;
2+
using DrakiaXYZ.Waypoints.Components;
3+
using EFT;
4+
using HarmonyLib;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Linq;
8+
using System.Reflection;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace DrakiaXYZ.Waypoints.Patches
13+
{
14+
internal class AICellDataGetCellPatch : ModulePatch
15+
{
16+
private static AICell emptyCell;
17+
18+
protected override MethodBase GetTargetMethod()
19+
{
20+
emptyCell = new AICell();
21+
emptyCell.Links = new NavMeshDoorLink[0];
22+
23+
return AccessTools.Method(typeof(AICellData), "GetCell");
24+
}
25+
26+
[PatchPrefix]
27+
public static bool PatchPrefix(int i, int j, AICellData __instance, ref AICell __result)
28+
{
29+
int offset = i + (j * __instance.MaxIx);
30+
if (offset < __instance.List.Length)
31+
{
32+
__result = __instance.List[offset];
33+
}
34+
else
35+
{
36+
__result = emptyCell;
37+
}
38+
39+
return false;
40+
}
41+
}
42+
}

Patches/WaypointPatch.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using DrakiaXYZ.Waypoints.Helpers;
44
using EFT;
55
using HarmonyLib;
6+
using JetBrains.Annotations;
67
using Newtonsoft.Json;
78
using System;
89
using System.Collections.Generic;
@@ -32,7 +33,7 @@ protected override MethodBase GetTargetMethod()
3233
///
3334
/// </summary>
3435
[PatchPrefix]
35-
private static void PatchPrefix(BotZone[] botZones)
36+
private static void PatchPrefix(BotsController __instance, BotZone[] botZones)
3637
{
3738
var gameWorld = Singleton<GameWorld>.Instance;
3839
if (gameWorld == null)
@@ -160,7 +161,6 @@ private static void InjectNavmesh(GameWorld gameWorld)
160161
if (mapName == "tarkovstreets")
161162
{
162163
Logger.LogDebug("Injecting custom box colliders to expand Streets bot access");
163-
164164
GameObject chek15LobbyAddonRamp = new GameObject("chek15LobbyAddonRamp");
165165
chek15LobbyAddonRamp.layer = LayerMaskClass.LowPolyColliderLayer;
166166
chek15LobbyAddonRamp.transform.position = new Vector3(126.88f, 2.96f, 229.91f);

WaypointsPlugin.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using BepInEx;
22
using DrakiaXYZ.BigBrain.Brains;
3+
using DrakiaXYZ.Helpers;
34
using DrakiaXYZ.Waypoints.BrainLogic;
45
using DrakiaXYZ.Waypoints.Helpers;
56
using DrakiaXYZ.Waypoints.Patches;
@@ -12,7 +13,7 @@
1213

1314
namespace DrakiaXYZ.Waypoints
1415
{
15-
[BepInPlugin("xyz.drakia.waypoints", "DrakiaXYZ-Waypoints", "1.3.1")]
16+
[BepInPlugin("xyz.drakia.waypoints", "DrakiaXYZ-Waypoints", "1.3.2")]
1617
public class WaypointsPlugin : BaseUnityPlugin
1718
{
1819
public static string PluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
@@ -28,6 +29,11 @@ private void Awake()
2829
throw new Exception($"Invalid EFT Version");
2930
}
3031

32+
if (!DependencyChecker.ValidateDependencies(Logger, Info, this.GetType(), Config))
33+
{
34+
throw new Exception($"Missing Dependencies");
35+
}
36+
3137
Settings.Init(Config);
3238

3339
// Make sure plugin folders exist
@@ -44,6 +50,7 @@ private void Awake()
4450
new EditorPatch().Enable();
4551

4652
new DoorBlockerPatch().Enable();
53+
new AICellDataGetCellPatch().Enable();
4754
}
4855
catch (Exception ex)
4956
{

0 commit comments

Comments
 (0)