forked from cybensis/SPT-VR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
156 lines (127 loc) · 5.3 KB
/
Plugin.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using System;
using System.IO;
using System.Reflection;
using TarkovVR.ModSupport;
using Unity.XR.OpenVR;
using UnityEngine;
using UnityEngine.XR.Management;
using Valve.VR;
namespace TarkovVR;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
public static ManualLogSource MyLog;
private void Awake()
{
// Plugin startup logic
Logger.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} is loaded!");
MyLog = Logger;
ApplyPatches("TarkovVR.Patches");
//Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
SteamVR_Actions.PreInitialize();
InitializeConditionalPatches();
SteamVR_Settings.instance.pauseGameWhenDashboardVisible = true;
var generalSettings = ScriptableObject.CreateInstance<XRGeneralSettings>();
var managerSettings = ScriptableObject.CreateInstance<XRManagerSettings>();
var xrLoader = ScriptableObject.CreateInstance<OpenVRLoader>();
var settings = OpenVRSettings.GetSettings();
settings.StereoRenderingMode = OpenVRSettings.StereoRenderingModes.MultiPass;
generalSettings.Manager = managerSettings;
managerSettings.loaders.Clear();
managerSettings.loaders.Add(xrLoader);
managerSettings.InitializeLoaderSync(); ;
XRGeneralSettings.AttemptInitializeXRSDKOnLoad();
XRGeneralSettings.AttemptStartXRSDKOnBeforeSplashScreen();
//Application.runInBackground = true;
SteamVR.Initialize();
//0.0688 -0.2245 -0.0326
//354.4751 187.1817 105.2293
}
private void InitializeConditionalPatches()
{
string modDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BepInEx\\plugins\\kmyuhkyuk-EFTApi\\EFTConfiguration.dll");
if (File.Exists(modDllPath))
{
// Load the assembly
Assembly modAssembly = Assembly.LoadFrom(modDllPath);
// Check for the required types and methods in the loaded assembly
Type configViewType = modAssembly.GetType("EFTConfiguration.Views.EFTConfigurationView");
if (configViewType != null)
{
// Apply conditional patches
InstalledMods.EFTApiInstalled = true;
ApplyPatches("TarkovVR.ModSupport.EFTApi");
MyLog.LogInfo("Dependent mod found and patches applied.");
}
else
{
MyLog.LogWarning("Required types/methods not found in the dependent mod.");
}
}
else
{
MyLog.LogWarning("Dependent mod DLL not found. Some functionality will be disabled.");
}
modDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BepInEx\\plugins\\AmandsGraphics.dll");
if (File.Exists(modDllPath))
{
// Load the assembly
Assembly modAssembly = Assembly.LoadFrom(modDllPath);
// Check for the required types and methods in the loaded assembly
Type configViewType = modAssembly.GetType("AmandsGraphics.AmandsGraphicsClass");
if (configViewType != null)
{
// Apply conditional patches
InstalledMods.AmandsGraphicsInstalled = true;
ApplyPatches("TarkovVR.ModSupport.AmandsGraphics");
MyLog.LogInfo("Dependent mod found and patches applied.");
}
else
{
MyLog.LogWarning("Required types/methods not found in the dependent mod.");
}
}
else
{
MyLog.LogWarning("Dependent mod DLL not found. Some functionality will be disabled.");
}
modDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BepInEx\\plugins\\Fika.Core.dll");
if (File.Exists(modDllPath))
{
// Load the assembly
Assembly modAssembly = Assembly.LoadFrom(modDllPath);
// Check for the required types and methods in the loaded assembly
Type configViewType = modAssembly.GetType("MatchMakerUI");
if (configViewType != null)
{
// Apply conditional patches
InstalledMods.FIKAInstalled = true;
ApplyPatches("TarkovVR.ModSupport.FIKA");
MyLog.LogInfo("Dependent mod found and patches applied.");
}
else
{
MyLog.LogWarning("Required types/methods not found in the dependent mod.");
}
}
else
{
MyLog.LogWarning("Dependent mod DLL not found. Some functionality will be disabled.");
}
}
private void ApplyPatches(string @namespace)
{
var harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
var assembly = Assembly.GetExecutingAssembly();
foreach (var type in assembly.GetTypes())
{
if (type.Namespace != null && type.Namespace.StartsWith(@namespace))
{
harmony.CreateClassProcessor(type).Patch();
}
}
}
}