public static bool Mod(this InstallerWindow ins, string file) { string inPath = Path.Combine(ins.MainModDir, file); string outPath = Path.Combine(ins.MainModDir, file + ".tmp.dll"); MonoModder monomod = new MonoModder() { InputPath = inPath, OutputPath = outPath }; monomod.SetupETGModder(); using (FileStream fileStream = File.Open(LogPath, FileMode.Append)) { using (StreamWriter streamWriter = new StreamWriter(fileStream)) { monomod.Logger = (string s) => ins.OnActivity(); monomod.Logger += (string s) => streamWriter.WriteLine(s); // Unity wants .mdbs // monomod.WriterParameters.SymbolWriterProvider = new Mono.Cecil.Mdb.MdbWriterProvider(); string db = Path.ChangeExtension(inPath, "pdb"); string dbTmp = Path.ChangeExtension(outPath, "pdb"); if (!File.Exists(db)) { db = inPath + ".mdb"; dbTmp = outPath + ".mdb"; } #if !DEBUG RETRY: try { #endif monomod.Read(); // Read main module first monomod.ReadMod(Directory.GetParent(inPath).FullName); // ... then mods monomod.MapDependencies(); // ... then all dependencies monomod.AutoPatch(); // Patch, monomod.Write(); // and write. monomod.Dispose(); // Finally, dispose, because file access happens now. File.Delete(inPath); File.Move(outPath, inPath); if (File.Exists(db)) { File.Delete(db); } if (File.Exists(dbTmp)) { File.Move(dbTmp, db); } return(true); #if !DEBUG } catch (ArgumentException e) { monomod.Dispose(); if (File.Exists(db)) { File.Delete(db); if (File.Exists(dbTmp)) { File.Delete(dbTmp); } goto RETRY; } ins.LogLine(e.ToString()); throw; return(false); } catch (Exception e) { monomod.Dispose(); ins.LogLine(e.ToString()); throw; return(false); } #endif } } }