66using System . Reflection ;
77using BattleTech ;
88using Harmony ;
9- using JetBrains . Annotations ;
9+
10+ // ReSharper disable UnusedMember.Global
11+ // ReSharper disable MemberCanBePrivate.Global
1012
1113namespace BattleTechModLoader
1214{
1315 using static Logger ;
1416
15- [ UsedImplicitly ]
1617 public static class BTModLoader
1718 {
1819 private const BindingFlags PUBLIC_STATIC_BINDING_FLAGS = BindingFlags . Public | BindingFlags . Static ;
20+ private static readonly List < string > IGNORE_FILE_NAMES = new List < string > ( )
21+ {
22+ "0Harmony.dll" ,
23+ "BattleTechModLoader.dll"
24+ } ;
1925
20- [ UsedImplicitly ]
2126 public static string ModDirectory { get ; private set ; }
22-
23- [ UsedImplicitly ]
27+
2428 public static void LoadDLL ( string path , string methodName = "Init" , string typeName = null ,
2529 object [ ] prms = null , BindingFlags bFlags = PUBLIC_STATIC_BINDING_FLAGS )
2630 {
@@ -51,11 +55,14 @@ public static void LoadDLL(string path, string methodName = "Init", string typeN
5155 foreach ( var type in types )
5256 {
5357 var entryMethod = type . GetMethod ( methodName , bFlags ) ;
54- var methodParams = entryMethod . GetParameters ( ) ;
58+ var methodParams = entryMethod ? . GetParameters ( ) ;
59+
60+ if ( methodParams == null )
61+ continue ;
5562
5663 if ( methodParams . Length == 0 )
5764 {
58- LogWithDate ( $ "{ fileName } : Found and called entry point with void param: { type . Name } . { entryMethod . Name } ") ;
65+ LogWithDate ( $ "{ fileName } : Found and called entry point \" { entryMethod } \" in type \" { type . FullName } \" ") ;
5966 entryMethod . Invoke ( null , null ) ;
6067 }
6168 else
@@ -74,7 +81,7 @@ public static void LoadDLL(string path, string methodName = "Init", string typeN
7481
7582 if ( paramsMatch )
7683 {
77- LogWithDate ( $ "{ fileName } : Found and called entry point with params: { type . Name } . { entryMethod . Name } ") ;
84+ LogWithDate ( $ "{ fileName } : Found and called entry point \" { entryMethod } \" in type \" { type . FullName } \" ") ;
7885 entryMethod . Invoke ( null , prms ) ;
7986 continue ;
8087 }
@@ -96,7 +103,7 @@ public static void LoadDLL(string path, string methodName = "Init", string typeN
96103 }
97104
98105 if ( methodParams . Length == 0 ) continue ;
99-
106+
100107 Log ( "\t Method Params:" ) ;
101108 foreach ( var prm in methodParams )
102109 {
@@ -111,7 +118,6 @@ public static void LoadDLL(string path, string methodName = "Init", string typeN
111118 }
112119 }
113120
114- [ UsedImplicitly ]
115121 public static void Init ( )
116122 {
117123 var manifestDirectory = Path . GetDirectoryName ( VersionManifestUtilities . MANIFEST_FILEPATH )
@@ -151,54 +157,13 @@ public static void Init()
151157 // load the dlls
152158 foreach ( var dllPath in dllPaths )
153159 {
154- Log ( $ "Found DLL: { Path . GetFileName ( dllPath ) } " ) ;
155- LoadDLL ( dllPath ) ;
160+ if ( ! IGNORE_FILE_NAMES . Contains ( Path . GetFileName ( dllPath ) ) )
161+ LoadDLL ( dllPath ) ;
156162 }
157163
158164 // do some simple benchmarking
159165 sw . Stop ( ) ;
160- Log ( "" ) ;
161- Log ( $ "Took { sw . Elapsed . TotalSeconds } seconds to load mods") ;
162-
163- // print out harmony summary
164- var patchedMethods = harmony . GetPatchedMethods ( ) . ToArray ( ) ;
165- if ( patchedMethods . Length == 0 )
166- {
167- Log ( "No Harmony Patches loaded." ) ;
168- return ;
169- }
170-
171- Log ( "" ) ;
172- Log ( "Harmony Patched Methods (after mod loader startup):" ) ;
173-
174- foreach ( var method in patchedMethods )
175- {
176- var info = harmony . GetPatchInfo ( method ) ;
177-
178- if ( info == null ) continue ;
179-
180- Log ( $ "{ method . ReflectedType . FullName } .{ method . Name } :") ;
181-
182- // prefixes
183- if ( info . Prefixes . Count != 0 )
184- Log ( "\t Prefixes:" ) ;
185- foreach ( var patch in info . Prefixes )
186- Log ( $ "\t \t { patch . owner } ") ;
187-
188- // transpilers
189- if ( info . Transpilers . Count != 0 )
190- Log ( "\t Transpilers:" ) ;
191- foreach ( var patch in info . Transpilers )
192- Log ( $ "\t \t { patch . owner } ") ;
193-
194- // postfixes
195- if ( info . Postfixes . Count != 0 )
196- Log ( "\t Postfixes:" ) ;
197- foreach ( var patch in info . Postfixes )
198- Log ( $ "\t \t { patch . owner } ") ;
199- }
200-
201- Log ( "" ) ;
166+ Log ( $ "\n Took { sw . Elapsed . TotalSeconds } seconds to load mods\n ") ;
202167 }
203168 }
204169}
0 commit comments