forked from derbismarck/SIT.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStayInTarkovPlugin.cs
418 lines (345 loc) · 16 KB
/
StayInTarkovPlugin.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
using Aki.Custom.Patches;
using BepInEx;
using BepInEx.Bootstrap;
using Comfort.Common;
using DrakiaXYZ.BigBrain.Brains;
using DrakiaXYZ.Waypoints.BrainLogic;
using EFT;
using EFT.Communications;
using EFT.UI;
using Newtonsoft.Json;
using SIT.Core.AI.PMCLogic.RushSpawn;
using SIT.Core.AkiSupport.Airdrops;
using SIT.Core.AkiSupport.Custom;
using SIT.Core.AkiSupport.Singleplayer;
using SIT.Core.AkiSupport.SITFixes;
using SIT.Core.Configuration;
using SIT.Core.Coop;
using SIT.Core.Coop.AI;
using SIT.Core.Core;
using SIT.Core.Core.FileChecker;
using SIT.Core.Core.Web;
using SIT.Core.Misc;
using SIT.Core.Other;
using SIT.Core.SP.Menus;
using SIT.Core.SP.PlayerPatches;
using SIT.Core.SP.PlayerPatches.Health;
using SIT.Core.SP.Raid;
using SIT.Core.SP.ScavMode;
using SIT.Tarkov.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace SIT.Core
{
[BepInPlugin("SIT.Core", "SIT.Core", "1.8.0")]
[BepInProcess("EscapeFromTarkov.exe")]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
public static PluginConfigSettings Settings { get; private set; }
private bool ShownDependancyError { get; set; }
public static string EFTVersionMajor { get; internal set; }
public static Dictionary<string, string> LanguageDictionary { get; } = new Dictionary<string, string>();
private void Awake()
{
Instance = this;
Settings = new PluginConfigSettings(Logger, Config);
LogDependancyErrors();
// Gather the Major/Minor numbers of EFT ASAP
new VersionLabelPatch(Config).Enable();
StartCoroutine(VersionChecks());
ReadInLanguageDictionary();
EnableCorePatches();
EnableSPPatches();
EnableCoopPatches();
OtherPatches.Run(Config, this);
Logger.LogInfo($"Stay in Tarkov is loaded!");
SceneManager.sceneLoaded += SceneManager_sceneLoaded;
}
private void ReadInLanguageDictionary()
{
Logger.LogDebug(Thread.CurrentThread.CurrentCulture);
var languageFiles = new List<string>();
foreach(var mrs in typeof(Plugin).Assembly.GetManifestResourceNames().Where(x=>x.StartsWith("SIT.Core.Resources.Language")))
{
languageFiles.Add(mrs);
Logger.LogInfo(mrs);
}
Logger.LogDebug(Thread.CurrentThread.CurrentCulture.Name);
var firstPartOfLang = Thread.CurrentThread.CurrentCulture.Name.ToLower().Substring(0, 2);
Logger.LogDebug(firstPartOfLang);
Stream stream = null;
StreamReader sr = null;
string str = null;
Dictionary<string, string> resultLocaleDictionary = null;
switch (firstPartOfLang)
{
case "zh":
switch(Thread.CurrentThread.CurrentCulture.Name.ToLower())
{
case "zh_TW":
stream = typeof(Plugin).Assembly.GetManifestResourceStream(languageFiles.First(x => x.EndsWith("TraditionalChinese.json")));
sr = new StreamReader(stream);
str = sr.ReadToEnd();
resultLocaleDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(str);
break;
case "zh_CN":
default:
stream = typeof(Plugin).Assembly.GetManifestResourceStream(languageFiles.First(x => x.EndsWith("SimplifiedChinese.json")));
sr = new StreamReader(stream);
str = sr.ReadToEnd();
resultLocaleDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(str);
break;
}
break;
case "en":
default:
stream = typeof(Plugin).Assembly.GetManifestResourceStream(languageFiles.First(x => x.EndsWith("English.json")));
sr = new StreamReader(stream);
str = sr.ReadToEnd();
resultLocaleDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(str);
break;
}
if (resultLocaleDictionary == null)
return;
foreach (var kvp in resultLocaleDictionary)
{
LanguageDictionary.Add(kvp.Key, kvp.Value);
}
Logger.LogDebug("Loaded in the following Language Dictionary");
Logger.LogDebug(LanguageDictionary.ToJson());
}
private IEnumerator VersionChecks()
{
while (true)
{
yield return new WaitForSeconds(1);
if (!string.IsNullOrEmpty(EFTVersionMajor))
{
Logger.LogInfo("Version Check: Detected:" + EFTVersionMajor);
if (EFTVersionMajor.Split('.').Length > 4)
{
var majorN1 = EFTVersionMajor.Split('.')[0]; // 0
var majorN2 = EFTVersionMajor.Split('.')[1]; // 13
var majorN3 = EFTVersionMajor.Split('.')[2]; // 1
var majorN4 = EFTVersionMajor.Split('.')[3]; // 1
var majorN5 = EFTVersionMajor.Split('.')[4]; // build number
//0.13.5.0.25725
if (majorN1 != "0" || majorN2 != "13" || majorN3 != "5" || majorN4 != "0")
{
Logger.LogError("Version Check: This version of SIT is not designed to work with this version of EFT.");
}
else
{
Logger.LogInfo("Version Check: OK.");
}
}
yield break;
}
}
}
private void EnableCorePatches()
{
// SIT Legal Game Checker
var lcRemover = Config.Bind<bool>("Debug Settings", "LC Remover", false).Value;
if (!lcRemover)
{
LegalGameCheck.LegalityCheck();
}
var enabled = Config.Bind<bool>("SIT Core Patches", "Enable", true);
if (!enabled.Value) // if it is disabled. stop all SIT Core Patches.
{
Logger.LogInfo("SIT Core Patches has been disabled! Ignoring Patches.");
return;
}
// File Checker
new ConsistencySinglePatch().Enable();
new ConsistencyMultiPatch().Enable();
new RunFilesCheckingPatch().Enable();
// BattlEye
new BattlEyePatch().Enable();
new BattlEyePatchFirstPassRun().Enable();
new BattlEyePatchFirstPassUpdate().Enable();
// Web Requests
new SslCertificatePatch().Enable();
new UnityWebRequestPatch().Enable();
new TransportPrefixPatch().Enable();
new WebSocketPatch().Enable();
//new TarkovTransportWSInstanceHookPatch().Enable();
//new TarkovTransportHttpInstanceHookPatch().Enable();
new SendCommandsPatch().Enable();
}
private void EnableSPPatches()
{
var enabled = Config.Bind<bool>("SIT.SP", "Enable", true);
if (!enabled.Value) // if it is disabled. stop all SIT SP Patches.
{
Logger.LogInfo("SIT SP Patches has been disabled! Ignoring Patches.");
return;
}
//// --------- PMC Dogtags -------------------
new UpdateDogtagPatch().Enable();
//// --------- Player Init & Health -------------------
EnableSPPatches_PlayerHealth(Config);
//// --------- SCAV MODE ---------------------
new DisableScavModePatch().Enable();
//// --------- Airdrop -----------------------
new AirdropPatch().Enable();
//// --------- Screens ----------------
EnableSPPatches_Screens(Config);
//// --------- Progression -----------------------
EnableSPPatches_PlayerProgression();
//// --------------------------------------
// Bots
EnableSPPatches_Bots(Config);
new QTEPatch().Enable();
new TinnitusFixPatch().Enable();
//try
//{
// BundleManager.GetBundles();
// new EasyAssetsPatch().Enable();
// new EasyBundlePatch().Enable();
//}
//catch (Exception ex)
//{
// Logger.LogError("// --- ERROR -----------------------------------------------");
// Logger.LogError("Bundle System Failed!!");
// Logger.LogError(ex.ToString());
// Logger.LogError("// --- ERROR -----------------------------------------------");
//}
new WavesSpawnScenarioInitPatch(Config).Enable();
new WavesSpawnScenarioMethodPatch().Enable();
}
private static void EnableSPPatches_Screens(BepInEx.Configuration.ConfigFile config)
{
//new OfflineRaidMenuPatch().Enable();
new OfflineSettingsScreenPatch().Enable();
new InsuranceScreenPatch().Enable();
new MatchmakerLocationScreen_DisableReadyButton_Patch().Enable();
//try
//{
// new MatchmakerLocationScreen_DisableLevelLock_Patch().Enable();
//}
//catch(Exception ex) { Plugin.Instance.Logger.LogError(ex.Message); }
new LighthouseBridgePatch().Enable();
new LighthouseTransmitterPatch().Enable();
new PostRaidHealScreenPatch().Enable();
}
private static void EnableSPPatches_PlayerProgression()
{
new OfflineSaveProfile().Enable();
new ExperienceGainFix().Enable();
}
private void EnableSPPatches_PlayerHealth(BepInEx.Configuration.ConfigFile config)
{
var enabled = config.Bind<bool>("SIT.SP", "EnableHealthPatches", true);
if (!enabled.Value)
return;
new Player_Init_SP_Patch().Enable();
new ChangeHealthPatch().Enable();
new ChangeHydrationPatch().Enable();
new ChangeEnergyPatch().Enable();
new OnDeadPatch(Config).Enable();
new MainMenuControllerForHealthListenerPatch().Enable();
}
private static void EnableSPPatches_Bots(BepInEx.Configuration.ConfigFile config)
{
new CoreDifficultyPatch().Enable();
new BotDifficultyPatch().Enable();
new GetNewBotTemplatesPatch().Enable();
new BotSettingsRepoClassIsFollowerFixPatch().Enable();
new IsPlayerEnemyPatch().Enable();
new IsPlayerEnemyByRolePatch().Enable();
new PmcFirstAidPatch().Enable();
new SpawnProcessNegativeValuePatch().Enable();
new CustomAiPatch().Enable();
new LocationLootCacheBustingPatch().Enable();
var enabled = config.Bind<bool>("SIT.SP", "EnableBotPatches", true);
if (!enabled.Value)
return;
new AddEnemyToAllGroupsInBotZonePatch().Enable();
new CheckAndAddEnemyPatch().Enable();
new BotCreatorTeleportPMCPatch().Enable();
BrainManager.AddCustomLayer(typeof(PMCRushSpawnLayer), new List<string>() { "Assault", "PMC" }, 9999);
}
private void EnableCoopPatches()
{
CoopPatches.Run(Config);
}
public static GameWorld gameWorld { get; private set; }
private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
{
//GetPoolManager();
GetBackendConfigurationInstance();
if (Singleton<GameWorld>.Instantiated)
gameWorld = Singleton<GameWorld>.Instance;
}
private void GetBackendConfigurationInstance()
{
if (
PatchConstants.BackendStaticConfigurationType != null &&
PatchConstants.BackendStaticConfigurationConfigInstance == null)
{
PatchConstants.BackendStaticConfigurationConfigInstance = ReflectionHelpers.GetPropertyFromType(PatchConstants.BackendStaticConfigurationType, "Config").GetValue(null);
//Logger.LogInfo($"BackendStaticConfigurationConfigInstance Type:{ PatchConstants.BackendStaticConfigurationConfigInstance.GetType().Name }");
}
if (PatchConstants.BackendStaticConfigurationConfigInstance != null
&& PatchConstants.CharacterControllerSettings.CharacterControllerInstance == null
)
{
PatchConstants.CharacterControllerSettings.CharacterControllerInstance
= ReflectionHelpers.GetFieldOrPropertyFromInstance<object>(PatchConstants.BackendStaticConfigurationConfigInstance, "CharacterController", false);
//Logger.LogInfo($"PatchConstants.CharacterControllerInstance Type:{PatchConstants.CharacterControllerSettings.CharacterControllerInstance.GetType().Name}");
}
if (PatchConstants.CharacterControllerSettings.CharacterControllerInstance != null
&& PatchConstants.CharacterControllerSettings.ClientPlayerMode == null
)
{
PatchConstants.CharacterControllerSettings.ClientPlayerMode
= ReflectionHelpers.GetFieldOrPropertyFromInstance<CharacterControllerSpawner.Mode>(PatchConstants.CharacterControllerSettings.CharacterControllerInstance, "ClientPlayerMode", false);
PatchConstants.CharacterControllerSettings.ObservedPlayerMode
= ReflectionHelpers.GetFieldOrPropertyFromInstance<CharacterControllerSpawner.Mode>(PatchConstants.CharacterControllerSettings.CharacterControllerInstance, "ObservedPlayerMode", false);
PatchConstants.CharacterControllerSettings.BotPlayerMode
= ReflectionHelpers.GetFieldOrPropertyFromInstance<CharacterControllerSpawner.Mode>(PatchConstants.CharacterControllerSettings.CharacterControllerInstance, "BotPlayerMode", false);
}
}
private void LogDependancyErrors()
{
// Skip if we've already shown the message, or there are no errors
if (ShownDependancyError || Chainloader.DependencyErrors.Count == 0)
{
return;
}
StringBuilder stringBuilder = new();
stringBuilder.AppendLine("Errors occurred during plugin loading");
stringBuilder.AppendLine("-------------------------------------");
stringBuilder.AppendLine();
foreach (string error in Chainloader.DependencyErrors)
{
stringBuilder.AppendLine(error);
stringBuilder.AppendLine();
}
string errorMessage = stringBuilder.ToString();
DisplayMessageNotifications.DisplayMessageNotification($"{errorMessage}", ENotificationDurationType.Infinite, ENotificationIconType.Alert, UnityEngine.Color.red);
// Show an error in the BepInEx console/log file
Logger.LogError(errorMessage);
// Show an error in the in-game console, we have to write this in reverse order because of the nature of the console output
foreach (string line in errorMessage.Split('\n').Reverse())
{
if (line.Trim().Length > 0)
{
ConsoleScreen.LogError(line);
}
}
ShownDependancyError = true;
}
}
}