10
10
using LlamaLibrary . Memory ;
11
11
using Newtonsoft . Json . Serialization ;
12
12
13
- namespace LlamaLibrary
13
+ namespace LlamaLibrary ;
14
+
15
+ public static class AssemblyProxy
14
16
{
15
- public static class AssemblyProxy
16
- {
17
- private static readonly ConcurrentDictionary < string , Assembly > Assemblies = new ConcurrentDictionary < string , Assembly > ( ) ;
18
- private static readonly LLogger Log = new LLogger ( "AssemblyProxy" , Colors . Bisque ) ;
19
- private static bool _initialized ;
20
- private static object _lock = new object ( ) ;
17
+ private static readonly ConcurrentDictionary < string , Assembly > Assemblies = new ConcurrentDictionary < string , Assembly > ( StringComparer . Ordinal ) ;
18
+ private static readonly LLogger Log = new LLogger ( "AssemblyProxy" , Colors . Bisque ) ;
19
+ private static bool _initialized ;
20
+ private static object _lock = new object ( ) ;
21
21
22
- public static void Init ( )
22
+ public static void Init ( )
23
+ {
24
+ lock ( _lock )
23
25
{
24
- lock ( _lock )
25
- {
26
- if ( _initialized )
27
- {
28
- return ;
29
- }
30
-
31
- _initialized = true ;
32
- }
33
-
34
- try
35
- {
36
- AddAssembly ( "Newtonsoft" , typeof ( JsonContract ) . Assembly ) ;
37
- AddAssembly ( "GreyMagic" , typeof ( ExternalProcessMemory ) . Assembly ) ;
38
- AddAssembly ( "ff14bot" , typeof ( Core ) . Assembly ) ;
39
- AddAssembly ( "LlamaLibrary" , typeof ( OffsetManager ) . Assembly ) ;
40
- }
41
- catch ( Exception e )
42
- {
43
- Log . Error ( e . ToString ( ) ) ;
44
- }
45
-
46
- try
47
- {
48
- AddAssembly ( Assembly . GetEntryAssembly ( ) ? . GetName ( ) . Name ! , Assembly . GetEntryAssembly ( ) ! ) ;
49
- }
50
- catch ( Exception e )
26
+ if ( _initialized )
51
27
{
52
- Log . Error ( e . ToString ( ) ) ;
28
+ return ;
53
29
}
54
30
55
- AppDomain . CurrentDomain . AssemblyResolve += OnAssemblyResolve ;
31
+ _initialized = true ;
56
32
}
57
33
58
- public static void AddAssembly ( string name , Assembly assembly )
34
+ try
59
35
{
60
- //Add to dictionary, make sure it's not already there
61
- if ( Assemblies . ContainsKey ( name ) )
62
- {
63
- return ;
64
- }
36
+ AddAssembly ( "Newtonsoft" , typeof ( JsonContract ) . Assembly ) ;
37
+ AddAssembly ( "GreyMagic" , typeof ( ExternalProcessMemory ) . Assembly ) ;
38
+ AddAssembly ( "ff14bot" , typeof ( Core ) . Assembly ) ;
39
+ AddAssembly ( "LlamaLibrary" , typeof ( OffsetManager ) . Assembly ) ;
40
+ }
41
+ catch ( Exception e )
42
+ {
43
+ Log . Error ( e . ToString ( ) ) ;
44
+ }
65
45
66
- Assemblies . TryAdd ( name , assembly ) ;
46
+ try
47
+ {
48
+ AddAssembly ( Assembly . GetEntryAssembly ( ) ? . GetName ( ) . Name ! , Assembly . GetEntryAssembly ( ) ! ) ;
67
49
}
50
+ catch ( Exception e )
51
+ {
52
+ Log . Error ( e . ToString ( ) ) ;
53
+ }
54
+
55
+ AppDomain . CurrentDomain . AssemblyResolve += OnAssemblyResolve ;
56
+ }
68
57
69
- private static Assembly ? OnAssemblyResolve ( object ? sender , ResolveEventArgs args )
58
+ public static void AddAssembly ( string name , Assembly assembly )
59
+ {
60
+ //Add to dictionary, make sure it's not already there
61
+ if ( Assemblies . ContainsKey ( name ) )
70
62
{
71
- if ( Assemblies . TryGetValue ( new AssemblyName ( args . Name ) . Name ?? string . Empty , out var resolve ) )
72
- {
73
- return resolve ;
74
- }
63
+ return ;
64
+ }
75
65
76
- if ( ! args . Name . Contains ( "resources" ) )
77
- {
78
- Log . Debug ( "Assembly not found: " + args . Name + "" ) ;
79
- }
66
+ Assemblies . TryAdd ( name , assembly ) ;
67
+ }
80
68
81
- return null ;
69
+ private static Assembly ? OnAssemblyResolve ( object ? sender , ResolveEventArgs args )
70
+ {
71
+ if ( Assemblies . TryGetValue ( new AssemblyName ( args . Name ) . Name ?? string . Empty , out var resolve ) )
72
+ {
73
+ return resolve ;
82
74
}
83
75
84
- public static Assembly OnCurrentDomainOnAssemblyResolve ( object sender , ResolveEventArgs args )
76
+ if ( ! args . Name . Contains ( "resources" ) )
85
77
{
86
- var assemblyName = new AssemblyName ( args . Name ) ;
87
- switch ( assemblyName . Name )
88
- {
89
- case "Newtonsoft" :
90
- return typeof ( JsonContract ) . Assembly ;
91
- case "GreyMagic" :
92
- return Core . Memory . GetType ( ) . Assembly ;
93
- case "ff14bot" :
94
- return Core . Me . GetType ( ) . Assembly ;
95
- case "LlamaLibrary" :
96
- return typeof ( OffsetManager ) . Assembly ;
97
- /*case "Clio.Localization":
98
- return typeof(Infralution.Localization.Wpf.CultureManager).Assembly;*/
99
- default :
100
- return null ! ;
101
- }
78
+ Log . Debug ( "Assembly not found: " + args . Name + "" ) ;
79
+ }
80
+
81
+ return null ;
82
+ }
83
+
84
+ public static Assembly OnCurrentDomainOnAssemblyResolve ( object sender , ResolveEventArgs args )
85
+ {
86
+ var assemblyName = new AssemblyName ( args . Name ) ;
87
+ switch ( assemblyName . Name )
88
+ {
89
+ case "Newtonsoft" :
90
+ return typeof ( JsonContract ) . Assembly ;
91
+ case "GreyMagic" :
92
+ return Core . Memory . GetType ( ) . Assembly ;
93
+ case "ff14bot" :
94
+ return Core . Me . GetType ( ) . Assembly ;
95
+ case "LlamaLibrary" :
96
+ return typeof ( OffsetManager ) . Assembly ;
97
+ /*case "Clio.Localization":
98
+ return typeof(Infralution.Localization.Wpf.CultureManager).Assembly;*/
99
+ default :
100
+ return null ! ;
102
101
}
103
102
}
104
103
}
0 commit comments