-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOther.cs
More file actions
592 lines (551 loc) · 19.4 KB
/
Other.cs
File metadata and controls
592 lines (551 loc) · 19.4 KB
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
using UnityEngine;
using System.Runtime.InteropServices;
using System.Text;
using System.Reflection;
using MelonLoader;
using System.IO;
using System;
using FunPlusEssentials.Essentials;
using Hashtable = ExitGames.Client.Photon.Hashtable;
using System.Collections.Generic;
using UnhollowerBaseLib;
using UnhollowerRuntimeLib;
using FunPlusEssentials.CustomContent;
namespace FunPlusEssentials.Other
{
public static class CuteLogger
{
public static void Meow(string msg)
{
if (!Config.logsEnabled) return;
MelonLogger.Msg(msg);
Log("[Meow] " + msg);
}
public static void Meow(ConsoleColor color, string msg)
{
if (!Config.logsEnabled) return;
MelonLogger.Msg(color, msg);
Log("[Meow] " + msg);
}
public static void Quack(string msg)
{
if (!Config.logsEnabled) return;
MelonLogger.Warning(msg);
Log("[Quack] " + msg);
}
public static void Bark(string msg)
{
if (!Config.logsEnabled) return;
MelonLogger.Error(msg);
Log("[Bark] " + msg);
}
public static void Log(string msg)
{
using (var file = new StreamWriter(Config.mainPath + @"\fpe_log.txt", true))
{
file.WriteLine(msg);
file.Close();
}
}
public static void ClearLogs()
{
File.WriteAllText(Config.mainPath + @"\fpe_log.txt", "");
}
}
public static class Loader
{
//Static class instead of _instance
// Usage from any other script:
// MySprite = IMG2Sprite.LoadNewSprite(FilePath, [PixelsPerUnit (optional)], [spriteType(optional)])
public static Sprite LoadNewSprite(string FilePath, float PixelsPerUnit = 100.0f, SpriteMeshType spriteType = SpriteMeshType.Tight)
{
// Load a PNG or JPG image from disk to a Texture2D, assign this texture to a new sprite and return its reference
Texture2D SpriteTexture = LoadTexture(FilePath);
Sprite NewSprite = Sprite.Create(SpriteTexture, new Rect(0, 0, SpriteTexture.width, SpriteTexture.height), new Vector2(0.5f, 0.5f), PixelsPerUnit);
return NewSprite;
}
public static Sprite ConvertTextureToSprite(Texture2D texture, float PixelsPerUnit = 100.0f, SpriteMeshType spriteType = SpriteMeshType.Tight)
{
// Converts a Texture2D to a sprite, assign this texture to a new sprite and return its reference
Sprite NewSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0), PixelsPerUnit, 0, spriteType);
return NewSprite;
}
public static Sprite ConvertTextureToSprite(Texture2D texture, Vector2 pivot)
{
// Converts a Texture2D to a sprite, assign this texture to a new sprite and return its reference
Sprite NewSprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), pivot, 100f, 0, SpriteMeshType.Tight);
return NewSprite;
}
public static Texture2D LoadTexture(string FilePath)
{
Texture2D Tex2D;
if (File.Exists(FilePath))
{
FilePath = @"file://" + FilePath;
var req = new WWW(FilePath);
Tex2D = req.texture;
if (Tex2D != null)
{
return Tex2D;
}
}
return null;
}
public static AudioClip LoadAudioClip(string FilePath)
{
AudioClip clip;
if (File.Exists(FilePath))
{
FilePath = @"file://" + FilePath;
var req = new WWW(FilePath);
clip = req.GetAudioClip();
if (clip != null)
{
return clip;
}
}
return null;
}
}
class IniFile // revision 11
{
string Path;
string EXE = Assembly.GetExecutingAssembly().GetName().Name;
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern long WritePrivateProfileString(string Section, string Key, string Value, string FilePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
static extern int GetPrivateProfileString(string Section, string Key, string Default, StringBuilder RetVal, int Size, string FilePath);
public IniFile(string IniPath = null)
{
Path = new System.IO.FileInfo(IniPath ?? EXE + ".ini").FullName;
}
public string Read(string Key, string Section = null)
{
var RetVal = new StringBuilder(255);
GetPrivateProfileString(Section ?? EXE, Key, "", RetVal, 255, Path);
return RetVal.ToString();
}
public void Write(string Key, string Value, string Section = null)
{
WritePrivateProfileString(Section ?? EXE, Key, Value, Path);
}
public void DeleteKey(string Key, string Section = null)
{
Write(Key, null, Section ?? EXE);
}
public void DeleteSection(string Section = null)
{
Write(null, null, Section ?? EXE);
}
public bool KeyExists(string Key, string Section = null)
{
return Read(Key, Section).Length > 0;
}
}
public static class BundleManager
{
public static Il2CppAssetBundle loadedScene;
public static GameObject LoadAssetBundle(string bundleName, string prefabName, string path)
{
CuteLogger.Meow("loading bundle " + prefabName);
var bundle = Il2CppAssetBundleManager.LoadFromFile(Path.Combine(path, bundleName));
if (bundle == null)
{
CuteLogger.Bark("Failed to load AssetBundle!");
return null;
}
// loadedBundles.Add(bundle);
return bundle.LoadAsset<GameObject>(prefabName);
//GameObject prefab = bundle.LoadAsset<GameObject>(prefabName);
//return Instantiate(prefab);
}
public static Sprite LoadSpriteBundle(string prefabName, string path)
{
CuteLogger.Meow("loading bundle " + prefabName);
var bundle = Il2CppAssetBundleManager.LoadFromFile(path);
if (bundle == null)
{
CuteLogger.Bark("Failed to load AssetBundle!");
return null;
}
return bundle.LoadAsset<Sprite>(prefabName);
}
public static AudioClip LoadAudioBundle(string prefabName, string path)
{
CuteLogger.Meow("loading audio bundle " + prefabName);
var bundle = Il2CppAssetBundleManager.LoadFromFile(path);
if (bundle == null)
{
CuteLogger.Bark("Failed to load AssetBundle!");
return null;
}
return bundle.LoadAsset<AudioClip>(prefabName);
}
public static Il2CppAssetBundle LoadBundle(string path)
{
CuteLogger.Meow("loading bundle " + path);
var bundle = Il2CppAssetBundleManager.LoadFromFile(path);
if (bundle == null)
{
CuteLogger.Bark("Failed to load AssetBundle!");
return null;
}
return bundle;
}
public static void LoadSceneBundle(string bundleName, string prefabName, string path)
{
CuteLogger.Meow("loading scene bundle " + prefabName);
var bundle = Il2CppAssetBundleManager.LoadFromFile(Path.Combine(path, bundleName));
if (bundle == null)
{
CuteLogger.Bark("Failed to load AssetBundle!");
}
loadedScene = bundle;
//GameObject prefab = bundle.LoadAsset<GameObject>(prefabName);
//return Instantiate(prefab);
}
}
[RegisterTypeInIl2Cpp]
public class LobbyHelper : MonoBehaviour
{
public LobbyHelper(IntPtr ptr) : base(ptr) { }
public LobbyMenu lobby;
public int depth = 0;
private void Start()
{
}
private void OnGUI()
{
if (lobby.FANLKBJODCL && !lobby.EJLDOIOJGPC && (lobby.NNKFEAPBLCK == 4 || lobby.NNKFEAPBLCK == 2))
{
GUI.depth = depth;
GUI.skin = lobby.BIPMFIBNFBC;
int num = Screen.height / 17;
int num2 = Screen.width / 17;
string text = "<color=grey>☐</color>";
if (MapManager.useCustomNPCs)
{
text = "<color=green>☑</color>";
}
MapManager.useCustomNPCs = GUI.Toggle(new Rect(Screen.width - num * 13, Screen.height - num * 4, num * 6, num), MapManager.useCustomNPCs, string.Concat(new string[]
{
"<size=",
((float)num / 1.75f).ToString(),
">",
text,
" ",
"<color=white>Custom Content</color>",
"</size>"
}));
}
if (lobby.FANLKBJODCL && !lobby.EJLDOIOJGPC && (lobby.NNKFEAPBLCK == 3))
{
GUI.depth = depth;
GUI.skin = lobby.BIPMFIBNFBC;
int num = Screen.height / 17;
int num2 = Screen.width / 17;
string text = "<color=grey>☐</color>";
if (Plague.Enabled)
{
text = "<color=green>☑</color>";
}
Plague.Enabled = GUI.Toggle(new Rect(Screen.width - num * 13, Screen.height - num * 4, num * 6, num), Plague.Enabled, string.Concat(new string[]
{
"<size=",
((float)num / 1.75f).ToString(),
">",
text,
" ",
"<color=white>Plague mode</color>",
"</size>"
}));
}
}
}
public static class Helper //все дерьмо из этого класса нужно в отедльную библиотеку чтобы не засорять мод
{
#region FIELDS
private static GameObject _roomGo;
private static GameObject _playerGo;
private static MultiplayerChat _multiplayerChat;
private static PhotonView _rpcView;
private static WhoKilledWho _whoKilledWho;
private static RoomMultiplayerMenu _roomMultiplayerMenu;
private static SurvivalMechanics _survivalMechanics;
private static WeaponManager _weaponManager;
private static LobbyMenu _lobbyMenu;
private static PlayerDamage _playerDamage;
private static PlayerMonster _playerMonster;
private static FPScontroller _fpsController;
private static AmmoDisplay _ammoDisplay;
private static UpdaterV2 _updaterV2;
private static Volume _console;
#endregion
#region PROPERTIES
public static Volume Console
{
get
{
if (_console == null)
{
_console = GameObject.FindObjectOfType<Volume>();
}
return _console;
}
}
public static PhotonView RPCView
{
get
{
if (_rpcView == null)
{
_rpcView = RoomMultiplayerMenu.photonView;
}
return _rpcView;
}
}
public static UpdaterV2 UpdaterV2
{
get
{
if (_updaterV2 == null)
{
_updaterV2 = GameObject.FindObjectOfType<UpdaterV2>();
}
return _updaterV2;
}
}
public static SurvivalMechanics SurvivalMechanics
{
get
{
if (_survivalMechanics == null)
{
_survivalMechanics = Room.GetComponent<SurvivalMechanics>();
}
return _survivalMechanics;
}
}
public static WhoKilledWho WhoKilledWho
{
get
{
if (_whoKilledWho == null)
{
_whoKilledWho = Room.GetComponent<WhoKilledWho>();
}
return _whoKilledWho;
}
}
public static AmmoDisplay AmmoDisplay
{
get
{
if (_ammoDisplay == null)
{
_ammoDisplay = GameObject.FindObjectOfType<AmmoDisplay>();
}
return _ammoDisplay;
}
}
public static FPScontroller FPSController
{
get
{
if (_fpsController == null)
{
_fpsController = Player.GetComponent<FPScontroller>();
}
return _fpsController;
}
}
public static bool IsPlayer
{
get
{
return PlayerDamage != null;
}
}
public static bool IsMonster
{
get
{
return PlayerMonster != null;
}
}
public static PlayerDamage PlayerDamage
{
get
{
if (_playerDamage == null)
{
_playerDamage = Player.GetComponent<PlayerDamage>();
}
return _playerDamage;
}
}
public static PlayerMonster PlayerMonster
{
get
{
if (_playerMonster == null)
{
_playerMonster = Player.GetComponent<PlayerMonster>();
}
return _playerMonster;
}
}
public static WeaponManager WeaponManager
{
get
{
if (_weaponManager == null)
{
_weaponManager = GameObject.FindObjectOfType<WeaponManager>();
}
return _weaponManager;
}
}
public static GameObject Player
{
get
{
if (_playerGo == null)
{
_playerGo = GameObject.FindObjectOfType<FPSinput>().gameObject;
}
return _playerGo;
}
}
public static MultiplayerChat MultiplayerChat
{
get
{
if (_multiplayerChat == null)
{
_multiplayerChat = GameObject.FindObjectOfType<MultiplayerChat>();
}
return _multiplayerChat;
}
}
public static GameObject Room
{
get
{
if (_roomGo == null)
{
_roomGo = GameObject.FindObjectOfType<RoomMultiplayerMenu>().gameObject;
}
return _roomGo;
}
}
public static RoomMultiplayerMenu RoomMultiplayerMenu
{
get
{
if (_roomMultiplayerMenu == null)
{
_roomMultiplayerMenu = GameObject.FindObjectOfType<RoomMultiplayerMenu>();
}
return _roomMultiplayerMenu;
}
}
public static LobbyMenu LobbyMenu
{
get
{
if (_lobbyMenu == null)
{
_lobbyMenu = GameObject.FindObjectOfType<LobbyMenu>();
}
return _lobbyMenu;
}
}
#endregion
static T CopyComponent<T>(T original, GameObject destination) where T : Component
{
Il2CppSystem.Type type = original.GetIl2CppType();
Component copy = destination.AddComponent(type);
var fields = type.GetFields(Il2CppSystem.Reflection.BindingFlags.Default);
foreach (Il2CppSystem.Reflection.FieldInfo field in fields)
field.SetValue(copy, field.GetValue(original));
return copy as T;
}
public static List<FileSystemInfo> GetAllDirectories(string dir)
{
DirectoryInfo dirInfo = new DirectoryInfo(dir);
List<FileSystemInfo> allDirectories = new List<FileSystemInfo>();
allDirectories.AddRange(dirInfo.GetDirectories("*", SearchOption.AllDirectories));
return allDirectories;
}
public static void SendChatMessage(string senderName, string text, string nameColor = "", string textColor = "")
{
// RoomMultiplayerMenu.PGIHKEOJBCH = color;
MultiplayerChat.HLIDELGJEON(Paint(senderName, nameColor), Paint(text, textColor), "Team A");
// RoomMultiplayerMenu.PGIHKEOJBCH = new Color(1, 0, 0, 1);
}
public static void SetRoomProperty(string property, Il2CppSystem.Object parameter)
{
Hashtable newsettings = new Hashtable();
newsettings[property] = parameter;
PhotonNetwork.room.SetCustomProperties(newsettings);
}
public static void SetPropertyV2(string property, string parameter)
{
Hashtable hashtable = new Hashtable
{
[property] = parameter
};
PhotonNetwork.player.SetCustomProperties(hashtable);
}
public static void SetProperty(string property, string parameter)
{
Hashtable hashtable = new Hashtable
{
[property] = parameter
};
foreach (PlayerProperties pp in GameObject.FindObjectsOfType<PlayerProperties>())
{
if (pp.GetComponent<PhotonView>().ownerId == PhotonNetwork.player.ID)
{
pp.SetProperties(hashtable);
}
}
}
public static Il2CppSystem.Object GetProperty(PhotonPlayer player, string property)
{
foreach (PlayerProperties pp in GameObject.FindObjectsOfType<PlayerProperties>())
{
if (pp.gameObject.GetComponent<PhotonView>().owner.ID == player.ID)
{
return pp.GetProperties(property);
}
}
return null;
}
public static object GetPropertyV2(PhotonPlayer player, string keyName)
{
foreach (PlayerProperties pp in GameObject.FindObjectsOfType<PlayerProperties>())
{
if (pp.gameObject.GetComponent<PhotonView>().ownerId == player.ID)
{
return pp.photonView.owner.GetCustomPropertiesV2(keyName);
}
}
return null;
}
public static string Paint(string text, string color)
{
if (color != "") return $"<color={color}>{text}</color>";
else return text;
}
public static PhotonPlayer FindPlayer(string nickName)
{
foreach (PhotonPlayer player in PhotonNetwork.playerList)
{
if (player.name == nickName) return player;
}
return PhotonNetwork.player;
}
}
}