@@ -515,36 +515,52 @@ internal static void UnloadPlugins()
515515 }
516516 }
517517
518- private static Assembly CurrentDomain_AssemblyResolve ( object sender , ResolveEventArgs args )
518+ private static Assembly ResolveAssembly ( string pluginsPath , string fileName )
519519 {
520- string fileName = args . Name . Split ( ',' ) [ 0 ] ;
521- string path = Path . Combine ( ServerPluginsDirectoryPath , fileName + ".dll" ) ;
522520 try
523521 {
524- if ( File . Exists ( path ) )
525- {
526- Assembly assembly ;
527- if ( ! loadedAssemblies . TryGetValue ( fileName , out assembly ) )
528- {
529- var pdbPath = Path . ChangeExtension ( fileName , ".pdb" ) ;
530- assembly = Assembly . Load ( File . ReadAllBytes ( path ) , File . Exists ( pdbPath ) ? File . ReadAllBytes ( pdbPath ) : null ) ;
531- // We just do this to return a proper error message incase this is a resolved plugin assembly
532- // referencing an old TerrariaServer version.
533- if ( ! InvalidateAssembly ( assembly , fileName ) )
534- throw new InvalidOperationException (
535- "The assembly is referencing a version of TerrariaServer prior 1.14." ) ;
522+ string pluginPath = Path . Combine ( pluginsPath , fileName + ".dll" ) ;
536523
537- loadedAssemblies . Add ( fileName , assembly ) ;
538- }
539- return assembly ;
540- }
524+ if ( ! File . Exists ( pluginPath ) ) return null ;
525+
526+ if ( loadedAssemblies . TryGetValue ( fileName , out var assembly ) ) return assembly ;
527+
528+ var pdbPath = Path . ChangeExtension ( pluginPath , ".pdb" ) ;
529+ assembly = Assembly . Load ( File . ReadAllBytes ( pluginPath ) ,
530+ File . Exists ( pdbPath ) ? File . ReadAllBytes ( pdbPath ) : null ) ;
531+
532+ // We just do this to return a proper error message incase this is a resolved plugin assembly
533+ // referencing an old TerrariaServer version.
534+ if ( ! InvalidateAssembly ( assembly , fileName ) )
535+ throw new InvalidOperationException (
536+ "The assembly is referencing a version of TerrariaServer prior 1.14." ) ;
537+
538+ loadedAssemblies . Add ( fileName , assembly ) ;
539+
540+ return assembly ;
541541 }
542542 catch ( Exception ex )
543543 {
544544 LogWriter . ServerWriteLine (
545- string . Format ( "Error on resolving assembly \" {0 }.dll\" :\n {1}" , fileName , ex ) ,
545+ $ "Error on resolving assembly \" { fileName } .dll\" :\n { ex } " ,
546546 TraceLevel . Error ) ;
547547 }
548+
549+ return null ;
550+ }
551+
552+ private static Assembly CurrentDomain_AssemblyResolve ( object sender , ResolveEventArgs args )
553+ {
554+ string fileName = args . Name . Split ( ',' ) [ 0 ] ;
555+ List < string > pluginsPaths = [ ServerPluginsDirectoryPath , ..AdditionalPluginsPaths ] ;
556+
557+ foreach ( string pluginsPath in pluginsPaths )
558+ {
559+ Assembly assembly = ResolveAssembly ( pluginsPath , fileName ) ;
560+
561+ if ( assembly != null ) return assembly ;
562+ }
563+
548564 return null ;
549565 }
550566
0 commit comments