-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEL.cs
More file actions
117 lines (94 loc) · 3.65 KB
/
Copy pathEL.cs
File metadata and controls
117 lines (94 loc) · 3.65 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
using Colossal.Logging;
using Game;
using Game.Modding;
using HarmonyLib;
using System.Linq;
using Game.SceneFlow;
using System.IO;
using System.Reflection;
using Game.Prefabs;
using Game.UI.InGame;
using Game.UI.Menu;
using Unity.Entities;
using UnityEngine;
using ExtraLib.Systems;
using ExtraLib.Systems.UI;
using ExtraLib.Helpers;
using ExtraLib.Mono;
using Logger = ExtraLib.Debugger.Logger;
using ExtraLib.Systems.UI.ExtraPanels;
namespace ExtraLib
{
public class EL : IMod
{
public static ILog log = LogManager.GetLogger($"{nameof(ExtraLib)}").SetShowsErrorsInUI(false);
#if DEBUG
internal static Logger Logger = new(log, true);
#else
internal static Logger Logger = new(log, false);
#endif
private Harmony harmony;
internal static string ResourcesIcons { get; private set; }
public static ExtraLibMonoScript extraLibMonoScript;
public static PrefabSystem m_PrefabSystem;
public static EntityManager m_EntityManager;
public static ToolbarUISystem m_ToolbarUISystem;
public static NotificationUISystem m_NotificationUISystem;
public void OnLoad(UpdateSystem updateSystem)
{
Logger.Info(nameof(OnLoad));
if (!GameManager.instance.modManager.TryGetExecutableAsset(this, out var asset))
{
Logger.Fatal("Failed to get the ExecutableAsset. The mod isn't loaded.");
return;
}
Logger.Info($"Current ExtraLib asset at {asset.path}");
FileInfo fileInfo = new(asset.path);
Icons.LoadIconsFolder(Icons.IconsResourceKey, fileInfo.Directory.FullName);
ResourcesIcons = Path.Combine(fileInfo.DirectoryName, "Icons");
ExtraLocalization.LoadLocalization(Logger, Assembly.GetExecutingAssembly(), false);
updateSystem.UpdateAt<AssetMultiCategory>(SystemUpdatePhase.UIUpdate);
updateSystem.UpdateAt<ExtraPanelsUISystem>(SystemUpdatePhase.UIUpdate);
updateSystem.UpdateAt<MainSystem>(SystemUpdatePhase.LateUpdate);
#if DEBUG
ExtraPanelsUISystem extraPanelsUISystem = updateSystem.World.GetOrCreateSystemManaged<ExtraPanelsUISystem>();
extraPanelsUISystem.AddExtraPanel<TestExtraPanel>();
#endif
//PrefabsHelper.LoadPrefabsInDirectory(Path.Combine(fileInfo.Directory.FullName, "Prefabs"));
harmony = new($"{nameof(ExtraLib)}.{nameof(EL)}");
harmony.PatchAll(typeof(EL).Assembly);
var patchedMethods = harmony.GetPatchedMethods().ToArray();
Logger.Info($"Plugin ExtraLib made patches! Patched methods: " + patchedMethods.Length);
foreach (var patchedMethod in patchedMethods)
{
Logger.Info($"Patched method: {patchedMethod.Module.Name}:{patchedMethod.Name}");
}
}
public void OnDispose()
{
Logger.Info(nameof(OnDispose));
harmony.UnpatchAll($"{nameof(ExtraLib)}.{nameof(EL)}");
Icons.UnLoadAllIconsFolder();
}
internal static Stream GetEmbedded(string embeddedPath)
{
return Assembly.GetExecutingAssembly().GetManifestResourceStream("ExtraLib.embedded." + embeddedPath);
}
public static void AddOnEditEnities(MainSystem.OnEditEnities onEditEnities, EntityQueryDesc entityQueryDesc)
{
AddOnEditEnities(new(onEditEnities, entityQueryDesc));
}
public static void AddOnEditEnities(MainSystem.EntityRequester entityRequester)
{
MainSystem.entityRequesters.Add(entityRequester);
}
public static void AddOnMainMenu(MainSystem.OnMainMenu OnMainMenu)
{
MainSystem.onMainMenu += OnMainMenu;
}
public static void AddOnInitialize(MainSystem.OnInitialize OnInitialize)
{
MainSystem.onInitialize += OnInitialize;
}
}
}