@@ -24,6 +24,15 @@ public static void Start(string modDirectory, string json)
2424 try
2525 {
2626 var compilerAssembly = Assembly . LoadFrom ( Path . Combine ( lib . Directory , "Mono.CSharp.dll" ) ) ;
27+
28+ {
29+ // fix for misbehaving of AssemblyDefinition CheckReferencesPublicToken
30+ var harmony = HarmonyInstance . Create ( "DynModLib.CSharp" ) ;
31+ var mOriginal = compilerAssembly . GetType ( "Mono.CSharp.AssemblyDefinition" ) . GetMethod ( "CheckReferencesPublicToken" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
32+ var mPrefix = typeof ( Main ) . GetMethod ( nameof ( Prefix ) , BindingFlags . Static | BindingFlags . Public ) ;
33+ harmony . Patch ( mOriginal , new HarmonyMethod ( mPrefix ) ) ;
34+ }
35+
2736 var references = CollectReferences ( ) ;
2837 var compiler = new ModCompiler ( compilerAssembly , references ) ;
2938
@@ -45,6 +54,11 @@ public static void Start(string modDirectory, string json)
4554 }
4655 }
4756
57+ public static bool Prefix ( )
58+ {
59+ return false ;
60+ }
61+
4862 private static List < string > CollectReferences ( )
4963 {
5064 var references = GetManagedAssemblyPaths ( ) ;
@@ -75,11 +89,23 @@ internal class ModCompiler
7589 {
7690 private readonly Assembly compilerAssembly ;
7791 private readonly List < string > references ;
92+ private readonly DateTime lastestAssemblyWriteTime ;
7893
7994 internal ModCompiler ( Assembly compilerAssembly , List < string > references )
8095 {
8196 this . compilerAssembly = compilerAssembly ;
8297 this . references = references ;
98+
99+ var latestWriteTime = DateTime . MinValue ;
100+ foreach ( var reference in references )
101+ {
102+ var writeTime = File . GetLastWriteTime ( reference ) ;
103+ if ( writeTime . CompareTo ( latestWriteTime ) > 0 )
104+ {
105+ latestWriteTime = writeTime ;
106+ }
107+ }
108+ lastestAssemblyWriteTime = latestWriteTime ;
83109 }
84110
85111 private Mod mod ;
@@ -171,18 +197,24 @@ private void CompileAssembly(string outPath, List<string> refPaths, List<string>
171197 }
172198 }
173199
174- private static bool HasCachedAssembly ( string outPath , List < string > srcPaths )
200+ private bool HasCachedAssembly ( string outPath , List < string > srcPaths )
175201 {
176202 if ( ! File . Exists ( outPath ) )
177203 {
178204 return false ;
179205 }
180206
181207 var assemblyDateTime = File . GetLastWriteTime ( outPath ) ;
208+
209+ if ( lastestAssemblyWriteTime . CompareTo ( assemblyDateTime ) > 0 )
210+ {
211+ return false ;
212+ }
213+
182214 foreach ( var sourceFile in srcPaths )
183215 {
184216 var sourceDateTime = File . GetLastWriteTime ( sourceFile ) ;
185- if ( sourceDateTime . Subtract ( assemblyDateTime ) . Ticks > 0 )
217+ if ( sourceDateTime . CompareTo ( assemblyDateTime ) > 0 )
186218 {
187219 return false ;
188220 }
0 commit comments