-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWaypointsPlugin.cs
109 lines (97 loc) · 4.06 KB
/
WaypointsPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using SPT.Reflection.Patching;
using BepInEx;
using DrakiaXYZ.Helpers;
using DrakiaXYZ.Waypoints.Helpers;
using DrakiaXYZ.Waypoints.Patches;
using DrakiaXYZ.Waypoints.VersionChecker;
using EFT;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using HarmonyLib;
using BepInEx.Logging;
namespace DrakiaXYZ.Waypoints
{
[BepInPlugin("xyz.drakia.waypoints", "DrakiaXYZ-Waypoints", "1.6.2")]
[BepInDependency("com.SPT.core", "3.10.0")]
public class WaypointsPlugin : BaseUnityPlugin
{
public static string PluginFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
public static string MeshFolder = Path.Combine(PluginFolder, "mesh");
public static string PointsFolder = Path.Combine(PluginFolder, "points");
public static string NavMeshFolder = Path.Combine(PluginFolder, "navmesh");
private void Awake()
{
if (!TarkovVersion.CheckEftVersion(Logger, Info, Config))
{
throw new Exception($"Invalid EFT Version");
}
if (!DependencyChecker.ValidateDependencies(Logger, Info, this.GetType(), Config))
{
throw new Exception($"Missing Dependencies");
}
Settings.Init(Config);
try
{
new DebugPatch().Enable();
new WaypointPatch().Enable();
new DoorLinkPatch().Enable();
new DoorLinkStateChangePatch().Enable();
new SwitchDoorBlockerPatch().Enable();
new ExfilDoorBlockerPatch().Enable();
new FindPathPatch().Enable();
//new GroupPointCachePatch().Enable();
//new BotVoxelesPersonalActivatePatch().Enable();
//new GroupPointGetByIdPatch().Enable();
// Debug perf timing output
//new PerfTimingPatch().Enable();
}
catch (Exception ex)
{
Logger.LogError($"{GetType().Name}: {ex}");
throw;
}
}
public class PerfTimingPatch
{
protected static ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource(nameof(ModulePatch));
public void Enable()
{
var harmony = new Harmony("xyz.drakia.waypoints");
//var props = AccessTools.GetDeclaredProperties(typeof(BotOwner));
//foreach (var prop in props)
//{
// var method = prop.PropertyType.GetMethod("Activate");
// if (method != null && !method.IsAbstract)
// {
// Logger.LogDebug($"Adding timing to {prop.PropertyType.Name}::{method.Name}");
// var target = method;
// var prefix = new HarmonyMethod(typeof(PerfTimingPatch).GetMethod("PatchPrefix"));
// var postfix = new HarmonyMethod(typeof(PerfTimingPatch).GetMethod("PatchPostfix"));
// harmony.Patch(target, prefix, postfix);
// }
//}
// Time the overall activate method
{
var target = AccessTools.Method(typeof(BotOwner), nameof(BotOwner.method_10));
var prefix = new HarmonyMethod(typeof(PerfTimingPatch).GetMethod("PatchPrefix"));
var postfix = new HarmonyMethod(typeof(PerfTimingPatch).GetMethod("PatchPostfix"));
harmony.Patch(target, prefix, postfix);
}
}
[PatchPrefix]
public static void PatchPrefix(out Stopwatch __state)
{
__state = new Stopwatch();
__state.Start();
}
[PatchPostfix]
public static void PatchPostfix(object __instance, Stopwatch __state)
{
__state.Stop();
Logger.LogDebug($"{__instance.GetType()} Activate took {__state.ElapsedMilliseconds}ms");
}
}
}
}