forked from space-commits/SPT-Realism-Mod-Client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cs
243 lines (227 loc) · 9.67 KB
/
Utils.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
using BepInEx.Logging;
using Comfort.Common;
using EFT;
using EFT.InventoryLogic;
using System;
using System.IO;
using System.Reflection;
namespace RealismMod
{
public static class Utils
{
public static ManualLogSource Logger;
public static bool Verified = false;
public static bool IsReady = false;
public static bool IsInHideout = false;
public static bool WeaponReady = false;
public static bool HasRunErgoWeightCalc = false;
public static string Silencer = "550aa4cd4bdc2dd8348b456c";
public static string FlashHider = "550aa4bf4bdc2dd6348b456b";
public static string MuzzleCombo = "550aa4dd4bdc2dc9348b4569";
public static string Barrel = "555ef6e44bdc2de9068b457e";
public static string Mount = "55818b224bdc2dde698b456f";
public static string Receiver = "55818a304bdc2db5418b457d";
public static string Stock = "55818a594bdc2db9688b456a";
public static string Charge = "55818a6f4bdc2db9688b456b";
public static string CompactCollimator = "55818acf4bdc2dde698b456b";
public static string Collimator = "55818ad54bdc2ddc698b4569";
public static string AssaultScope = "55818add4bdc2d5b648b456f";
public static string Scope = "55818ae44bdc2dde698b456c";
public static string IronSight = "55818ac54bdc2d5b648b456e";
public static string SpecialScope = "55818aeb4bdc2ddc698b456a";
public static string AuxiliaryMod = "5a74651486f7744e73386dd1";
public static string Foregrip = "55818af64bdc2d5b648b4570";
public static string PistolGrip = "55818a684bdc2ddd698b456d";
public static string Gasblock = "56ea9461d2720b67698b456f";
public static string Handguard = "55818a104bdc2db9688b4569";
public static string Bipod = "55818afb4bdc2dde698b456d";
public static string Flashlight = "55818b084bdc2d5b648b4571";
public static string TacticalCombo = "55818b164bdc2ddc698b456c";
public static string UBGL = "55818b014bdc2ddc698b456b";
public static bool AreFloatsEqual(float a, float b, float epsilon = 0.001f)
{
float difference = Math.Abs(a - b);
return difference < epsilon;
}
public static bool IsNull(string[] confItemArray, int expectedLength = 0)
{
if (confItemArray != null && confItemArray.Length > expectedLength)
{
if (confItemArray[0] == "SPTRM")
{
return false;
}
}
return true;
}
public static bool ConfItemsIsNullOrInvalid(string[] confItemArray, int length)
{
if (confItemArray != null && confItemArray.Length >= length)
{
if (confItemArray[0] == "SPTRM")
{
return false;
}
}
return true;
}
public static Player GetYourPlayer()
{
GameWorld gameWorld = Singleton<GameWorld>.Instance;
return gameWorld.MainPlayer;
}
public static Player GetPlayerByID(string id)
{
GameWorld gameWorld = Singleton<GameWorld>.Instance;
return gameWorld.GetAlivePlayerByProfileID(id);
}
public static bool CheckIsReady()
{
GameWorld gameWorld = Singleton<GameWorld>.Instance;
SessionResultPanel sessionResultPanel = Singleton<SessionResultPanel>.Instance;
Player player = gameWorld?.MainPlayer;
if (player != null)
{
Utils.WeaponReady = player?.HandsController != null && player?.HandsController?.Item != null && player?.HandsController?.Item is Weapon ? true : false;
Utils.IsInHideout = player is HideoutPlayer ? true : false;
}
if (gameWorld == null || gameWorld.AllAlivePlayersList == null || gameWorld.MainPlayer == null || sessionResultPanel != null)
{
Utils.IsReady = false;
return false;
}
Utils.IsReady = true;
return true;
}
public static void SafelyAddAttributeToList(ItemAttributeClass itemAttribute, Mod __instance)
{
if (itemAttribute.Base() != 0f)
{
__instance.Attributes.Add(itemAttribute);
}
}
public static void VerifyFileIntegrity(ManualLogSource Logger)
{
var dllLoc = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string checksum = "d2F5ZmFyZXI=";
byte[] bytes = Convert.FromBase64String(checksum);
string decodedString = System.Text.Encoding.UTF8.GetString(bytes);
var modsLoc = Path.Combine(dllLoc, "..", "..", "user", "mods", decodedString);
var fullPath = Path.GetFullPath(modsLoc);
if (Directory.Exists(fullPath))
{
/*Environment.Exit(0);*/
Verified = true;
Logger.LogWarning("Verification Checksum: {0}" + checksum);
}
}
public static string GenId()
{
return Guid.NewGuid().ToString();
}
public static bool IsSight(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Scope] || mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[AssaultScope] || mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[SpecialScope] || mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[CompactCollimator] || mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Collimator] || mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[IronSight];
}
public static bool IsMuzzleDevice(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[MuzzleCombo] || mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Silencer] || mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[FlashHider];
}
public static bool IsStock(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Stock];
}
public static bool IsSilencer(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Silencer];
}
public static bool IsMagazine(Mod mod)
{
return (mod is MagazineClass);
}
public static bool IsFlashHider(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[FlashHider];
}
public static bool IsMuzzleCombo(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[MuzzleCombo];
}
public static bool IsBarrel(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Barrel];
}
public static bool IsMount(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Mount];
}
public static bool IsReceiver(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Receiver];
}
public static bool IsCharge(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Charge];
}
public static bool IsCompactCollimator(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[CompactCollimator];
}
public static bool IsCollimator(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Collimator];
}
public static bool IsAssaultScope(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[AssaultScope];
}
public static bool IsScope(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Scope];
}
public static bool IsIronSight(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[IronSight];
}
public static bool IsSpecialScope(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[SpecialScope];
}
public static bool IsAuxiliaryMod(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[AuxiliaryMod];
}
public static bool IsForegrip(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Foregrip];
}
public static bool IsPistolGrip(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[PistolGrip];
}
public static bool IsGasblock(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Gasblock];
}
public static bool IsHandguard(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Handguard];
}
public static bool IsBipod(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Bipod];
}
public static bool IsFlashlight(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[Flashlight];
}
public static bool IsTacticalCombo(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[TacticalCombo];
}
public static bool IsUBGL(Mod mod)
{
return mod.GetType() == TemplateIdToObjectMappingsClass.TypeTable[UBGL];
}
}
}