// Receive a mod when connecting to server internal static void ReceiveMod(BinaryReader reader) { if (downloadingMod == null) { return; } try { if (downloadingFile == null) { Interface.progress.Show(displayText: reader.ReadString(), cancel: CancelDownload); ModLoader.GetMod(downloadingMod.name)?.Close(); downloadingLength = reader.ReadInt64(); downloadingFile = new FileStream(downloadingMod.path, FileMode.Create); return; } var bytes = reader.ReadBytes((int)Math.Min(downloadingLength - downloadingFile.Position, CHUNK_SIZE)); downloadingFile.Write(bytes, 0, bytes.Length); Interface.progress.Progress = downloadingFile.Position / (float)downloadingLength; if (downloadingFile.Position == downloadingLength) { downloadingFile.Close(); var mod = new TmodFile(downloadingMod.path); using (mod.Open()) { } if (!downloadingMod.Matches(mod)) { throw new Exception(Language.GetTextValue("tModLoader.MPErrorModHashMismatch")); } if (downloadingMod.signed && onlyDownloadSignedMods && !mod.ValidModBrowserSignature) { throw new Exception(Language.GetTextValue("tModLoader.MPErrorModNotSigned")); } ModLoader.EnableMod(mod.name); if (downloadQueue.Count > 0) { DownloadNextMod(); } else { OnModsDownloaded(true); } } } catch (Exception e) { try { downloadingFile?.Close(); File.Delete(downloadingMod.path); } catch (Exception exc2) { Logging.tML.Error("Unknown error during mod sync", exc2); } var msg = Language.GetTextValue("tModLoader.MPErrorModDownloadError", downloadingMod.name); Logging.tML.Error(msg, e); Interface.errorMessage.Show(msg + e, 0); Netplay.disconnect = true; downloadingMod = null; } }