1010
1111namespace ScriptLoader
1212{
13- [ BepInPlugin ( "horse.coder.tools.scriptloader" , "C# Script Loader" , "1.2" ) ]
13+ [ BepInPlugin ( "horse.coder.tools.scriptloader" , "C# Script Loader" , "1.2.1 " ) ]
1414 public class ScriptLoader : BaseUnityPlugin
1515 {
1616 private readonly string scriptsPath = Path . Combine ( Paths . GameRootPath , "scripts" ) ;
@@ -82,11 +82,21 @@ private void CompileScripts()
8282 if ( ! File . Exists ( ignoresPath ) )
8383 File . WriteAllText ( ignoresPath , "" ) ;
8484
85+ bool IsValidProcess ( string scriptFile )
86+ {
87+ var si = availableScripts [ scriptFile ] ;
88+
89+ if ( si . ProcessFilters . Count == 0 )
90+ return true ;
91+ return si . ProcessFilters . Any ( p => string . Equals ( p . ToLowerInvariant ( ) . Replace ( ".exe" , "" ) , Paths . ProcessName ,
92+ StringComparison . InvariantCultureIgnoreCase ) ) ;
93+ }
94+
8595 var ignores = new HashSet < string > ( File . ReadAllLines ( ignoresPath ) . Select ( s => s . Trim ( ) ) ) ;
86- var scriptsToCompile = files . Where ( f => ! ignores . Contains ( Path . GetFileName ( f ) ) ) . ToList ( ) ;
96+ var scriptsToCompile = files . Where ( f => IsValidProcess ( f ) && ! ignores . Contains ( Path . GetFileName ( f ) ) ) . ToList ( ) ;
8797
8898 Logger . LogInfo (
89- $ "Found { files . Length } scripts to compile, skipping { files . Length - scriptsToCompile . Count } scripts because of `scriptignores`") ;
99+ $ "Found { files . Length } scripts to compile, skipping { files . Length - scriptsToCompile . Count } scripts because of `scriptignores` or process filters ") ;
90100
91101 var md5 = MD5 . Create ( ) ;
92102 var scriptDict = new Dictionary < string , byte [ ] > ( ) ;
@@ -108,7 +118,7 @@ private void CompileScripts()
108118
109119 foreach ( var scriptFile in scriptsToCompile )
110120 {
111- if ( ! availableScripts . TryGetValue ( scriptFile , out var info ) || info == null ) continue ;
121+ if ( ! availableScripts . TryGetValue ( scriptFile , out var info ) ) continue ;
112122 foreach ( var infoReference in info . References )
113123 Assembly . LoadFile ( infoReference ) ;
114124 }
0 commit comments