-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathAssemblyProxy.cs
104 lines (91 loc) · 3.18 KB
/
AssemblyProxy.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
//!CompilerOption:AddRef:Clio.Localization.dll
using System;
using System.Collections.Concurrent;
using System.Reflection;
using System.Windows.Media;
using ff14bot;
using GreyMagic;
using LlamaLibrary.Logging;
using LlamaLibrary.Memory;
using Newtonsoft.Json.Serialization;
namespace LlamaLibrary
{
public static class AssemblyProxy
{
private static readonly ConcurrentDictionary<string, Assembly> Assemblies = new ConcurrentDictionary<string, Assembly>();
private static readonly LLogger Log = new LLogger("AssemblyProxy", Colors.Bisque, LogLevel.Information);
private static bool _initialized;
private static object _lock = new object();
public static void Init()
{
lock (_lock)
{
if (_initialized)
{
return;
}
_initialized = true;
}
try
{
AddAssembly("Newtonsoft", typeof(JsonContract).Assembly);
AddAssembly("GreyMagic", typeof(ExternalProcessMemory).Assembly);
AddAssembly("ff14bot", typeof(Core).Assembly);
AddAssembly("LlamaLibrary", typeof(OffsetManager).Assembly);
}
catch (Exception e)
{
Log.Error(e.ToString());
}
try
{
AddAssembly(Assembly.GetEntryAssembly()?.GetName().Name!, Assembly.GetEntryAssembly()!);
}
catch (Exception e)
{
Log.Error(e.ToString());
}
AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
}
public static void AddAssembly(string name, Assembly assembly)
{
//Add to dictionary, make sure it's not already there
if (Assemblies.ContainsKey(name))
{
return;
}
Assemblies.TryAdd(name, assembly);
}
private static Assembly? OnAssemblyResolve(object sender, ResolveEventArgs args)
{
if (Assemblies.TryGetValue(new AssemblyName(args.Name).Name, out var resolve))
{
return resolve;
}
if (!args.Name.Contains("resources"))
{
Log.Debug("Assembly not found: " + args.Name + "");
}
return null;
}
public static Assembly OnCurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
{
var assemblyName = new AssemblyName(args.Name);
switch (assemblyName.Name)
{
case "Newtonsoft":
return typeof(JsonContract).Assembly;
case "GreyMagic":
return Core.Memory.GetType().Assembly;
case "ff14bot":
return Core.Me.GetType().Assembly;
case "LlamaLibrary":
return typeof(OffsetManager).Assembly;
/*case "Clio.Localization":
return typeof(Infralution.Localization.Wpf.CultureManager).Assembly;*/
default:
return null!;
}
}
}
}