forked from space-commits/SPT-Realism-Mod-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
851 lines (752 loc) · 36.9 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
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
using Audio.AmbientSubsystem;
using BepInEx;
using BepInEx.Bootstrap;
using Comfort.Common;
using EFT;
using EFT.Interactive;
using Newtonsoft.Json;
using SPT.Common.Http;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
using static RealismMod.Attributes;
using static RealismMod.ZoneSpawner;
namespace RealismMod
{
public interface IRealismInfo { }
public class RealismConfig : IRealismInfo
{
public bool recoil_attachment_overhaul { get; set; }
public bool malf_changes { get; set; }
public bool realistic_ballistics { get; set; }
public bool med_changes { get; set; }
public bool headset_changes { get; set; }
public bool enable_stances { get; set; }
public bool movement_changes { get; set; }
public bool gear_weight { get; set; }
public bool reload_changes { get; set; }
public bool manual_chambering { get; set; }
public bool food_changes { get; set; }
public bool enable_hazard_zones { get; set; }
}
public class RealismInfo : IRealismInfo
{
public bool IsHalloween { get; set; }
public bool DoGasEvent { get; set; }
public bool DoExtraCultists { get; set; }
public bool DoExtraRaiders { get; set; }
public bool IsChristmas { get; set; }
public bool IsPreExplosion { get; set; }
public bool HasExploded { get; set; }
public bool IsNightTime { get; set; }
}
public enum EUpdateType
{
Full,
ModInfo,
ModConfig,
TimeOfDay
}
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, Plugin.PLUGINVERSION)]
public class Plugin : BaseUnityPlugin
{
private const string PLUGINVERSION = "1.4.7";
public static Dictionary<Enum, Sprite> IconCache = new Dictionary<Enum, Sprite>();
public static Dictionary<string, AudioClip> HitAudioClips = new Dictionary<string, AudioClip>();
public static Dictionary<string, AudioClip> GasMaskAudioClips = new Dictionary<string, AudioClip>();
public static Dictionary<string, AudioClip> HazardZoneClips = new Dictionary<string, AudioClip>();
public static Dictionary<string, AudioClip> DeviceAudioClips = new Dictionary<string, AudioClip>();
public static Dictionary<string, AudioClip> RadEventAudioClips = new Dictionary<string, AudioClip>();
public static Dictionary<string, AudioClip> GasEventAudioClips = new Dictionary<string, AudioClip>();
public static Dictionary<string, AudioClip> GasEventLongAudioClips = new Dictionary<string, AudioClip>();
public static Dictionary<string, Sprite> LoadedSprites = new Dictionary<string, Sprite>();
public static Dictionary<string, Texture> LoadedTextures = new Dictionary<string, Texture>();
private string _baseBundleFilepath;
private float _realDeltaTime = 0f;
public static float FPS = 1f;
//mounting UI
public static GameObject MountingUIGameObject { get; private set; }
public MountingUI MountingUIComponent;
//health controller
public static RealismHealthController RealHealthController;
//explosion
public static GameObject ExplosionGO { get; private set; }
//weather controller
private GameObject RealismWeatherGameObject { get; set; }
public static RealismWeatherController RealismWeatherComponent;
public static bool HasReloadedAudio = false;
public static bool FikaPresent = false;
public static bool FOVFixPresent = false;
private bool _detectedMods = false;
public static bool StartRechamberTimer = false;
public static float ChamberTimer = 0f;
public static bool CanLoadChamber = false;
public static bool BlockChambering = false;
private bool _gotProfileId = false;
public static RealismConfig ServerConfig;
public static RealismInfo ModInfo;
private static T UpdateInfoFromServer<T>(string route) where T : class, IRealismInfo
{
Utils.Logger.LogWarning("update from server: " + route);
var settings = new JsonSerializerSettings
{
MissingMemberHandling = MissingMemberHandling.Ignore
};
try
{
var json = RequestHandler.GetJson(route);
return JsonConvert.DeserializeObject<T>(json);
}
catch (Exception ex)
{
Utils.Logger.LogError($"REALISM MOD ERROR: FAILED TO FETCH DATA FROM SERVER USING ROUTE {route}: {ex.Message}");
return null;
}
}
public static void RequestRealismDataFromServer(EUpdateType updateType)
{
switch(updateType)
{
case EUpdateType.Full:
ServerConfig = UpdateInfoFromServer<RealismConfig>("/RealismMod/GetConfig");
ModInfo = UpdateInfoFromServer<RealismInfo>("/RealismMod/GetInfo");
break;
case EUpdateType.ModInfo:
ModInfo = UpdateInfoFromServer<RealismInfo>("/RealismMod/GetInfo");
break;
case EUpdateType.ModConfig:
ServerConfig = UpdateInfoFromServer<RealismConfig>("/RealismMod/GetConfig");
break;
case EUpdateType.TimeOfDay:
ModInfo = UpdateInfoFromServer<RealismInfo>("/RealismMod/GetTimeOfDay");
break;
}
}
private async void CacheIcons()
{
IconCache.Add(ENewItemAttributeId.ShotDispersion, Resources.Load<Sprite>("characteristics/icons/Velocity"));
IconCache.Add(ENewItemAttributeId.BluntThroughput, Resources.Load<Sprite>("characteristics/icons/armorMaterial"));
IconCache.Add(ENewItemAttributeId.VerticalRecoil, Resources.Load<Sprite>("characteristics/icons/Ergonomics"));
IconCache.Add(ENewItemAttributeId.HorizontalRecoil, Resources.Load<Sprite>("characteristics/icons/Recoil Back"));
IconCache.Add(ENewItemAttributeId.Dispersion, Resources.Load<Sprite>("characteristics/icons/Velocity"));
IconCache.Add(ENewItemAttributeId.CameraRecoil, Resources.Load<Sprite>("characteristics/icons/SightingRange"));
IconCache.Add(ENewItemAttributeId.AutoROF, Resources.Load<Sprite>("characteristics/icons/bFirerate"));
IconCache.Add(ENewItemAttributeId.SemiROF, Resources.Load<Sprite>("characteristics/icons/bFirerate"));
IconCache.Add(ENewItemAttributeId.ReloadSpeed, Resources.Load<Sprite>("characteristics/icons/weapFireType"));
IconCache.Add(ENewItemAttributeId.FixSpeed, Resources.Load<Sprite>("characteristics/icons/icon_info_raidmoddable"));
IconCache.Add(ENewItemAttributeId.ChamberSpeed, Resources.Load<Sprite>("characteristics/icons/icon_info_raidmoddable"));
IconCache.Add(ENewItemAttributeId.AimSpeed, Resources.Load<Sprite>("characteristics/icons/SightingRange"));
IconCache.Add(ENewItemAttributeId.Firerate, Resources.Load<Sprite>("characteristics/icons/bFirerate"));
IconCache.Add(ENewItemAttributeId.Damage, Resources.Load<Sprite>("characteristics/icons/icon_info_bulletspeed"));
IconCache.Add(ENewItemAttributeId.Penetration, Resources.Load<Sprite>("characteristics/icons/armorClass"));
IconCache.Add(ENewItemAttributeId.BallisticCoefficient, Resources.Load<Sprite>("characteristics/icons/SightingRange"));
IconCache.Add(ENewItemAttributeId.ArmorDamage, Resources.Load<Sprite>("characteristics/icons/armorMaterial"));
IconCache.Add(ENewItemAttributeId.FragmentationChance, Resources.Load<Sprite>("characteristics/icons/icon_info_bloodloss"));
IconCache.Add(ENewItemAttributeId.MalfunctionChance, Resources.Load<Sprite>("characteristics/icons/icon_info_raidmoddable"));
IconCache.Add(ENewItemAttributeId.CanSpall, Resources.Load<Sprite>("characteristics/icons/icon_info_bulletspeed"));
IconCache.Add(ENewItemAttributeId.SpallReduction, Resources.Load<Sprite>("characteristics/icons/Velocity"));
IconCache.Add(ENewItemAttributeId.GearReloadSpeed, Resources.Load<Sprite>("characteristics/icons/weapFireType"));
IconCache.Add(ENewItemAttributeId.CantADS, Resources.Load<Sprite>("characteristics/icons/SightingRange"));
IconCache.Add(ENewItemAttributeId.CanADS, Resources.Load<Sprite>("characteristics/icons/SightingRange"));
IconCache.Add(ENewItemAttributeId.NoiseReduction, Resources.Load<Sprite>("characteristics/icons/icon_info_loudness"));
IconCache.Add(ENewItemAttributeId.ProjectileCount, Resources.Load<Sprite>("characteristics/icons/icon_info_bulletspeed"));
IconCache.Add(ENewItemAttributeId.Convergence, Resources.Load<Sprite>("characteristics/icons/Ergonomics"));
IconCache.Add(ENewItemAttributeId.HBleedType, Resources.Load<Sprite>("characteristics/icons/icon_info_bloodloss"));
IconCache.Add(ENewItemAttributeId.LimbHpPerTick, Resources.Load<Sprite>("characteristics/icons/icon_info_bloodloss"));
IconCache.Add(ENewItemAttributeId.HpPerTick, Resources.Load<Sprite>("characteristics/icons/hpResource"));
IconCache.Add(ENewItemAttributeId.RemoveTrnqt, Resources.Load<Sprite>("characteristics/icons/hpResource"));
IconCache.Add(ENewItemAttributeId.Comfort, Resources.Load<Sprite>("characteristics/icons/Weight"));
IconCache.Add(ENewItemAttributeId.GasProtection, Resources.Load<Sprite>("characteristics/icons/icon_info_intoxication"));
IconCache.Add(ENewItemAttributeId.RadProtection, Resources.Load<Sprite>("characteristics/icons/icon_info_radiation"));
IconCache.Add(ENewItemAttributeId.PainKillerStrength, Resources.Load<Sprite>("characteristics/icons/hpResource"));
IconCache.Add(ENewItemAttributeId.MeleeDamage, Resources.Load<Sprite>("characteristics/icons/icon_info_bloodloss"));
IconCache.Add(ENewItemAttributeId.MeleePen, Resources.Load<Sprite>("characteristics/icons/icon_info_bulletspeed"));
IconCache.Add(ENewItemAttributeId.OutOfRaidHP, Resources.Load<Sprite>("characteristics/icons/hpResource"));
IconCache.Add(ENewItemAttributeId.StimType, Resources.Load<Sprite>("characteristics/icons/hpResource"));
IconCache.Add(ENewItemAttributeId.DurabilityBurn, Resources.Load<Sprite>("characteristics/icons/Velocity"));
IconCache.Add(ENewItemAttributeId.Heat, Resources.Load<Sprite>("characteristics/icons/Velocity"));
IconCache.Add(ENewItemAttributeId.MuzzleFlash, Resources.Load<Sprite>("characteristics/icons/Velocity"));
IconCache.Add(ENewItemAttributeId.Handling, Resources.Load<Sprite>("characteristics/icons/Ergonomics"));
IconCache.Add(ENewItemAttributeId.AimStability, Resources.Load<Sprite>("characteristics/icons/SightingRange"));
Sprite balanceSprite = await RequestResource<Sprite>(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\icons\\balance.png");
Sprite recoilAngleSprite = await RequestResource<Sprite>(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\icons\\recoilAngle.png");
IconCache.Add(ENewItemAttributeId.Balance, balanceSprite);
IconCache.Add(ENewItemAttributeId.RecoilAngle, recoilAngleSprite);
}
private void LoadTextures()
{
string[] texFilesDir = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\masks\\", "*.png");
foreach (string fileDir in texFilesDir)
{
LoadTexture(fileDir);
}
}
private void LoadSprites()
{
string[] iconFilesDir = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\icons\\", "*.png");
foreach (string fileDir in iconFilesDir)
{
LoadSprite(fileDir);
}
}
private async void LoadSprite(string path)
{
LoadedSprites[Path.GetFileName(path)] = await RequestResource<Sprite>(path);
}
private async void LoadTexture(string path)
{
LoadedTextures[Path.GetFileName(path)] = await RequestResource<Texture>(path, true);
}
private async Task<T> RequestResource<T>(string path, bool isMask = false) where T : class
{
UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(path);
UnityWebRequestAsyncOperation sendWeb = uwr.SendWebRequest();
while (!sendWeb.isDone)
await Task.Yield();
if (uwr.isNetworkError || uwr.isHttpError)
{
Logger.LogError("Realism Mod: Failed To Fetch Resource");
return null;
}
else
{
Texture2D texture = ((DownloadHandlerTexture)uwr.downloadHandler).texture;
if (typeof(T) == typeof(Texture))
{
if (isMask)
{
Texture2D flipped = new Texture2D(texture.width, texture.height);
for (int y = 0; y < texture.height; y++)
{
for (int x = 0; x < texture.width; x++)
{
flipped.SetPixel(x, texture.height - y - 1, texture.GetPixel(x, y));
}
}
flipped.Apply();
texture = flipped;
}
return texture as T;
}
else if (typeof(T) == typeof(Sprite))
{
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
return sprite as T;
}
else
{
Logger.LogError("Realism Mod: Unsupported resource type requested");
return null;
}
}
}
private async void LoadAudioClipHelper(string[] fileDirectories, Dictionary<string, AudioClip> clips)
{
foreach (var fileDir in fileDirectories)
{
clips[Path.GetFileName(fileDir)] = await RequestAudioClip(fileDir);
}
}
private void LoadAudioClips()
{
string[] hitSoundsDir = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\sounds\\hitsounds");
string[] gasMaskDir = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\sounds\\gasmask");
string[] hazardDir = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\sounds\\zones");
string[] deviceDir = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\sounds\\devices");
string[] gasEventAmbient = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\sounds\\zones\\mapgas\\default");
string[] radEventAmbient = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\sounds\\zones\\maprads");
string[] gasEventLongAmbient = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + "\\BepInEx\\plugins\\Realism\\sounds\\zones\\mapgas\\long");
HitAudioClips.Clear();
GasMaskAudioClips.Clear();
HazardZoneClips.Clear();
DeviceAudioClips.Clear();
GasEventAudioClips.Clear();
RadEventAudioClips.Clear();
LoadAudioClipHelper(hitSoundsDir, HitAudioClips);
LoadAudioClipHelper(gasMaskDir, GasMaskAudioClips);
LoadAudioClipHelper(hazardDir, HazardZoneClips);
LoadAudioClipHelper(deviceDir, DeviceAudioClips);
LoadAudioClipHelper(gasEventAmbient, GasEventAudioClips);
LoadAudioClipHelper(radEventAmbient, RadEventAudioClips);
LoadAudioClipHelper(gasEventLongAmbient, GasEventLongAudioClips);
Plugin.HasReloadedAudio = true;
}
private async Task<AudioClip> RequestAudioClip(string path)
{
string extension = Path.GetExtension(path);
AudioType audioType = AudioType.WAV;
switch (extension)
{
case ".wav":
audioType = AudioType.WAV;
break;
case ".ogg":
audioType = AudioType.OGGVORBIS;
break;
}
UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(path, audioType);
UnityWebRequestAsyncOperation sendWeb = uwr.SendWebRequest();
while (!sendWeb.isDone)
await Task.Yield();
if (uwr.isNetworkError || uwr.isHttpError)
{
Logger.LogError("Realism Mod: Failed To Fetch Audio Clip");
return null;
}
else
{
AudioClip audioclip = DownloadHandlerAudioClip.GetContent(uwr);
return audioclip;
}
}
private AssetBundle LoadAndInitializePrefabs(string bundlePath)
{
string fullPath = Path.Combine(_baseBundleFilepath, bundlePath);
AssetBundle bundle = AssetBundle.LoadFromFile(fullPath);
return bundle;
}
private void LoadBundles()
{
_baseBundleFilepath = Path.Combine(Environment.CurrentDirectory, "BepInEx\\plugins\\Realism\\bundles\\");
Assets.GooBarrelBundle = LoadAndInitializePrefabs("hazard_assets\\yellow_barrel.bundle");
Assets.BlueBoxBundle = LoadAndInitializePrefabs("hazard_assets\\bluebox.bundle");
Assets.RedForkLiftBundle = LoadAndInitializePrefabs("hazard_assets\\redforklift.bundle");
Assets.ElectroForkLiftBundle = LoadAndInitializePrefabs("hazard_assets\\electroforklift.bundle");
Assets.LabsCrateBundle = LoadAndInitializePrefabs("hazard_assets\\labscrate.bundle");
Assets.UralBundle = LoadAndInitializePrefabs("hazard_assets\\ural.bundle");
Assets.BluePalletBundle = LoadAndInitializePrefabs("hazard_assets\\bluepallet.bundle");
Assets.BlueFuelPalletClothBundle = LoadAndInitializePrefabs("hazard_assets\\bluebarrelpalletcloth.bundle");
Assets.BarrelPileBundle = LoadAndInitializePrefabs("hazard_assets\\barrelpile.bundle");
Assets.LabsCrateSmallBundle = LoadAndInitializePrefabs("hazard_assets\\labscratesmall.bundle");
Assets.YellowPlasticPalletBundle = LoadAndInitializePrefabs("hazard_assets\\yellowbarrelpallet.bundle");
Assets.WhitePlasticPalletBundle = LoadAndInitializePrefabs("hazard_assets\\whitebarrelpallet.bundle");
Assets.MetalFenceBundle = LoadAndInitializePrefabs("hazard_assets\\metalfence.bundle");
Assets.RedContainerBundle = LoadAndInitializePrefabs("hazard_assets\\redcontainer.bundle");
Assets.BlueContainerBundle = LoadAndInitializePrefabs("hazard_assets\\bluecontainer.bundle");
Assets.LabsBarrelPileBundle = LoadAndInitializePrefabs("hazard_assets\\labsbarrelpile.bundle");
Assets.RadSign1 = LoadAndInitializePrefabs("hazard_assets\\radsign1.bundle");
Assets.TerraGroupFence = LoadAndInitializePrefabs("hazard_assets\\terragroupchainfence.bundle");
Assets.ExplosionBundle = LoadAndInitializePrefabs("exp\\expl.bundle");
ExplosionGO = Assets.ExplosionBundle.LoadAsset<GameObject>("Assets/Explosion/Prefab/NUCLEAR_EXPLOSION.prefab");
DontDestroyOnLoad(ExplosionGO);
}
private void LoadMountingUI()
{
MountingUIGameObject = new GameObject();
MountingUIComponent = MountingUIGameObject.AddComponent<MountingUI>();
DontDestroyOnLoad(MountingUIGameObject);
}
private void LoadWeatherController()
{
RealismWeatherGameObject = new GameObject();
RealismWeatherComponent = RealismWeatherGameObject.AddComponent<RealismWeatherController>();
DontDestroyOnLoad(RealismWeatherGameObject);
}
private void LoadHealthController()
{
DamageTracker dmgTracker = new DamageTracker();
RealismHealthController healthController = new RealismHealthController(dmgTracker);
RealHealthController = healthController;
}
void Awake()
{
Utils.Logger = Logger;
try
{
RequestRealismDataFromServer(EUpdateType.Full);
LoadBundles();
LoadSprites();
LoadTextures();
LoadAudioClips();
CacheIcons();
ZoneData.DeserializeZoneData();
}
catch (Exception exception)
{
Logger.LogError(exception);
}
LoadMountingUI();
LoadWeatherController();
LoadHealthController();
PluginConfig.InitConfigBindings(Config);
MoveDaCube.InitTempBindings(Config); //TEMPORARY
LoadGeneralPatches();
//hazards
if (ServerConfig.enable_hazard_zones)
{
LoadHazardPatches();
}
//malfunctions
if (ServerConfig.malf_changes)
{
LoadMalfPatches();
}
//recoil and attachments
if (ServerConfig.recoil_attachment_overhaul)
{
LoadRecoilPatches();
}
LoadReloadPatches();
//Ballistics
if (ServerConfig.realistic_ballistics)
{
LoadBallisticsPatches();
}
//Deafen Effects
if (ServerConfig.headset_changes)
{
LoadDeafenPatches();
}
//gear patces
if (ServerConfig.gear_weight)
{
new TotalWeightPatch().Enable();
}
//Movement
if (ServerConfig.movement_changes)
{
LoadMovementPatches();
}
//Stances
if (ServerConfig.enable_stances)
{
LoadStancePatches();
}
//also needed for visual recoil
if (ServerConfig.enable_stances || ServerConfig.realistic_ballistics)
{
new ApplyComplexRotationPatch().Enable();
}
if (ServerConfig.enable_stances || ServerConfig.headset_changes)
{
new ADSAudioPatch().Enable();
}
//Health
if (ServerConfig.med_changes)
{
LoadMedicalPatches();
}
//needed for food and meds
if (ServerConfig.med_changes || ServerConfig.food_changes)
{
new ApplyItemStashPatch().Enable();
new StimStackPatch1().Enable();
new StimStackPatch2().Enable();
}
}
private void CheckForMods()
{
if (!_detectedMods && (int)Time.time % 5 == 0)
{
_detectedMods = true;
if (Chainloader.PluginInfos.ContainsKey("com.fika.core"))
{
FikaPresent = true;
}
if (Chainloader.PluginInfos.ContainsKey("FOVFix"))
{
FOVFixPresent = true;
}
}
}
private void CheckForProfileData()
{
//keep trying to get player profile id and update hazard values
if (!_gotProfileId)
{
try
{
var sessionData = Singleton<ClientApplication<ISession>>.Instance.GetClientBackEndSession();
ProfileData.PMCProfileId = sessionData.Profile.Id;
ProfileData.ScavProfileId = sessionData.ProfileOfPet.Id;
ProfileData.PMCLevel = sessionData.Profile.Info.Level;
if (ServerConfig.enable_hazard_zones)
{
HazardTracker.GetHazardValues(ProfileData.PMCProfileId);
}
_gotProfileId = true;
}
catch
{
if (PluginConfig.EnableLogging.Value) Logger.LogWarning("Realism Mod: Error Getting Profile ID, Retrying");
}
}
}
private void ZoneDebugUpdate()
{
if (Input.GetKeyDown(KeyCode.Keypad1))
{
var player = Utils.GetYourPlayer().Transform;
#pragma warning disable CS4014
Utils.LoadLoot(player.position, player.rotation, PluginConfig.TargetZone.Value);
#pragma warning disable CS4014
Utils.Logger.LogWarning("\"position\": {" + "\"x\":" + player.position.x + "," + "\"y\":" + player.position.y + "," + "\"z\":" + player.position.z + "},");
Utils.Logger.LogWarning("new Vector3(" + player.position.x + "f, " + player.position.y + "f, " + player.position.z + "f)");
Utils.Logger.LogWarning("\"rotation\": {" + "\"x\":" + player.rotation.eulerAngles.x + "," + "\"y\":" + player.eulerAngles.y + "," + "\"z\":" + player.eulerAngles.z + "}");
}
if (Input.GetKeyDown(KeyCode.Keypad0)) HazardTracker.WipeTracker();
if (Input.GetKeyDown(PluginConfig.AddZone.Value.MainKey)) DebugZones();
//if (Input.GetKeyDown(KeyCode.Keypad5)) Instantiate(Plugin.ExplosionGO, new Vector3(PluginConfig.test1.Value, PluginConfig.test2.Value, PluginConfig.test3.Value), new Quaternion(0, 0, 0, 0)); //new Vector3(1000f, 0f, 317f)
}
void Update()
{
//TEMPORARY
if (GameWorldController.GameStarted && PluginConfig.ZoneDebug.Value) MoveDaCube.Update();
//games procedural animations are highly affected by FPS. I balanced everything at 144 FPS, so need to factor it.
_realDeltaTime += (Time.unscaledDeltaTime - _realDeltaTime) * 0.1f;
FPS = 1.0f / _realDeltaTime;
CheckForProfileData();
CheckForMods();
if (ServerConfig.enable_hazard_zones) HazardTracker.OutOfRaidUpdate();
if (PluginConfig.ZoneDebug.Value) ZoneDebugUpdate();
Utils.CheckIsReady();
if (Utils.PlayerIsReady)
{
GameWorldController.GameWorldUpdate();
if (ServerConfig.med_changes) RealHealthController.ControllerUpdate();
if (!Plugin.HasReloadedAudio)
{
LoadAudioClips();
}
RecoilController.RecoilUpdate();
if (ServerConfig.headset_changes)
{
HeadsetGainController.AdjustHeadsetVolume();
if (DeafeningController.PrismEffects != null)
{
DeafeningController.DoDeafening();
}
}
if (ServerConfig.enable_stances)
{
StanceController.StanceState();
}
}
else
{
HasReloadedAudio = false;
}
}
private void LoadGeneralPatches()
{
//misc
new ChamberCheckUIPatch().Enable();
//multiple
new KeyInputPatch1().Enable();
new KeyInputPatch2().Enable();
new SyncWithCharacterSkillsPatch().Enable();
new OnItemAddedOrRemovedPatch().Enable();
new PlayerUpdatePatch().Enable();
new PlayerInitPatch().Enable();
new FaceshieldMaskPatch().Enable();
new PlayPhrasePatch().Enable();
new OnGameStartPatch().Enable();
new OnGameEndPatch().Enable();
new QuestCompletePatch().Enable();
//stats used by multiple features
new RigConstructorPatch().Enable();
new EquipmentPenaltyComponentPatch().Enable();
}
private void LoadHazardPatches()
{
new HealthPanelPatch().Enable();
new DropItemPatch().Enable();
new GetAvailableActionsPatch().Enable();
new BossSpawnPatch().Enable();
new LampPatch().Enable();
new AmbientSoundPlayerGroupPatch().Enable();
new DayTimeAmbientPatch().Enable();
new DayTimeSpawnPatch().Enable();
new BirdPatch().Enable();
}
private void LoadMalfPatches()
{
new RemoveSillyBossForcedMalf().Enable();
new GetTotalMalfunctionChancePatch().Enable();
new IsKnownMalfTypePatch().Enable();
if (ServerConfig.manual_chambering)
{
new SetAmmoCompatiblePatch().Enable();
new StartReloadPatch().Enable();
new StartEquipWeapPatch().Enable();
new SetAmmoOnMagPatch().Enable();
new PreChamberLoadPatch().Enable();
}
}
private void LoadRecoilPatches()
{
//procedural animations
/*new CalculateCameraPatch().Enable();*/
if (PluginConfig.EnableMuzzleEffects.Value) new MuzzleEffectsPatch().Enable();
new UpdateWeaponVariablesPatch().Enable();
new SetAimingSlowdownPatch().Enable();
new PwaWeaponParamsPatch().Enable();
new UpdateSwayFactorsPatch().Enable();
new GetOverweightPatch().Enable();
new SetOverweightPatch().Enable();
new BreathProcessPatch().Enable();
new CamRecoilPatch().Enable();
//weapon and related
new TotalShotgunDispersionPatch().Enable();
new GetDurabilityLossOnShotPatch().Enable();
new FireratePitchPatch().Enable();
new AutoFireRatePatch().Enable();
new SingleFireRatePatch().Enable();
new ErgoDeltaPatch().Enable();
new ErgoWeightPatch().Enable();
new PlayerErgoPatch().Enable();
new ToggleAimPatch().Enable();
new GetMalfunctionStatePatch().Enable();
if (PluginConfig.EnableZeroShift.Value)
{
new CalibrationLookAt().Enable();
new CalibrationLookAtScope().Enable();
}
//Stat Display Patches
new ModConstructorPatch().Enable();
new WeaponConstructorPatch().Enable();
new HRecoilDisplayStringValuePatch().Enable();
new HRecoilDisplayDeltaPatch().Enable();
new VRecoilDisplayStringValuePatch().Enable();
new VRecoilDisplayDeltaPatch().Enable();
new ModVRecoilStatDisplayPatchFloat().Enable();
new ModVRecoilStatDisplayPatchString().Enable();
new ErgoDisplayDeltaPatch().Enable();
new ErgoDisplayStringValuePatch().Enable();
new FireRateDisplayStringValuePatch().Enable();
new ModErgoStatDisplayPatch().Enable();
new GetAttributeIconPatches().Enable();
new MagazineMalfChanceDisplayPatch().Enable();
new BarrelModClassPatch().Enable();
new AmmoCaliberPatch().Enable();
new COIDeltaPatch().Enable();
new CenterOfImpactMOAPatch().Enable();
new COIDisplayDeltaPatch().Enable();
new COIDisplayStringValuePatch().Enable();
new GetTotalCenterOfImpactPatch().Enable();
//Recoil Patches
//new GetCameraRotationRecoilPatch().Enable(); makes recoil feel iffy, doesn't seem needed
new RecalcWeaponParametersPatch().Enable();
new AddRecoilForcePatch().Enable();
new RecoilAnglesPatch().Enable();
new ShootPatch().Enable();
new RotatePatch().Enable();
}
private void LoadReloadPatches()
{
//Reload Patches
if (ServerConfig.reload_changes)
{
new CanStartReloadPatch().Enable();
new ReloadMagPatch().Enable();
new QuickReloadMagPatch().Enable();
new SetMagTypeCurrentPatch().Enable();
new SetMagTypeNewPatch().Enable();
new SetMagInWeaponPatch().Enable();
new SetMalfRepairSpeedPatch().Enable();
new BoltActionReloadPatch().Enable();
new SetWeaponLevelPatch().Enable();
}
if (ServerConfig.reload_changes || ServerConfig.recoil_attachment_overhaul || ServerConfig.enable_stances)
{
new ReloadWithAmmoPatch().Enable();
new ReloadBarrelsPatch().Enable();
new ReloadCylinderMagazinePatch().Enable();
new OnMagInsertedPatch().Enable();
new SetSpeedParametersPatch().Enable();
new CheckAmmoPatch().Enable();
new CheckChamberPatch().Enable();
new RechamberPatch().Enable();
new SetAnimatorAndProceduralValuesPatch().Enable();
}
}
private void LoadStancePatches()
{
new ApplySimpleRotationPatch().Enable();
new InitTransformsPatch().Enable();
new ZeroAdjustmentsPatch().Enable();
new WeaponOverlappingPatch().Enable();
new WeaponLengthPatch().Enable();
new OnWeaponDrawPatch().Enable();
new UpdateHipInaccuracyPatch().Enable();
new SetFireModePatch().Enable();
new WeaponOverlapViewPatch().Enable();
new CollisionPatch().Enable();
new OperateStationaryWeaponPatch().Enable();
new SetTiltPatch().Enable();
new BattleUIScreenPatch().Enable();
new ChangePosePatch().Enable();
new MountingPatch().Enable();
new ShouldMoveWeapCloserPatch().Enable();
}
private void LoadMedicalPatches()
{
new SetQuickSlotPatch().Enable();
new ApplyItemPatch().Enable();
new BreathIsAudiblePatch().Enable();
new SetMedsInHandsPatch().Enable();
new ProceedMedsPatch().Enable();
new RemoveEffectPatch().Enable();
new StaminaRegenRatePatch().Enable();
new HealthEffectsConstructorPatch().Enable();
new HCApplyDamagePatch().Enable();
new RestoreBodyPartPatch().Enable();
new FlyingBulletPatch().Enable();
new ToggleHeadDevicePatch().Enable();
new HealCostDisplayShortPatch().Enable();
new HealCostDisplayFullPatch().Enable();
}
private void LoadMovementPatches()
{
if (PluginConfig.EnableMaterialSpeed.Value)
{
new CalculateSurfacePatch().Enable();
}
new ClampSpeedPatch().Enable();
new SprintAccelerationPatch().Enable();
new EnduranceSprintActionPatch().Enable();
new EnduranceMovementActionPatch().Enable();
}
private void LoadDeafenPatches()
{
new PrismEffectsEnablePatch().Enable();
new PrismEffectsDisablePatch().Enable();
new UpdatePhonesPatch().Enable();
new SetCompressorPatch().Enable();
new RegisterShotPatch().Enable();
new ExplosionPatch().Enable();
new GrenadeClassContusionPatch().Enable();
new CovertMovementVolumePatch().Enable();
new CovertMovementVolumeBySpeedPatch().Enable();
new CovertEquipmentVolumePatch().Enable();
new HeadsetConstructorPatch().Enable();
}
private void LoadBallisticsPatches()
{
/*new SetSkinPatch().Enable();*/
/*new CollidersPatch().Enable();*/
new PenetrationUIPatch().Enable();
new InitiateShotPatch().Enable();
new VelocityPatch().Enable();
new CreateShotPatch().Enable();
new ApplyArmorDamagePatch().Enable();
new ApplyDamageInfoPatch().Enable();
new SetPenetrationStatusPatch().Enable();
new IsPenetratedPatch().Enable();
new AfterPenPlatePatch().Enable();
new IsShotDeflectedByHeavyArmorPatch().Enable();
new ArmorLevelUIPatch().Enable();
new ArmorLevelDisplayPatch().Enable();
new ArmorClassStringPatch().Enable();
new DamageInfoPatch().Enable();
if (PluginConfig.EnableRagdollFix.Value) new ApplyCorpseImpulsePatch().Enable();
new GetCachedReadonlyQualitiesPatch().Enable();
}
}
}