internal static TmodFile[] FindMods() { Directory.CreateDirectory(ModPath); IList <TmodFile> files = new List <TmodFile>(); foreach (string fileName in Directory.GetFiles(ModPath, "*.tmod", SearchOption.TopDirectoryOnly)) { TmodFile file = new TmodFile(fileName); file.Read(); if (file.ValidMod() == null) { files.Add(file); } } return(files.ToArray()); }
internal static bool CreateModReferenceDlls(BuildProperties properties) { TmodFile[] refFiles = new TmodFile[properties.modReferences.Length]; for (int k = 0; k < properties.modReferences.Length; k++) { string modReference = properties.modReferences[k]; string filePath = ModLoader.ModPath + Path.DirectorySeparatorChar + modReference + ".tmod"; TmodFile refFile = new TmodFile(filePath); refFile = new TmodFile(filePath); refFile.Read(); if (!refFile.ValidMod()) { ErrorLogger.LogModReferenceError(refFile.Name); return(false); } refFiles[k] = refFile; } for (int k = 0; k < refFiles.Length; k++) { TmodFile refFile = refFiles[k]; string modReference = properties.modReferences[k]; byte[] data1; byte[] data2; if (refFile.HasFile("All")) { data1 = refFile.GetFile("All"); data2 = refFile.GetFile("All"); } else { data1 = refFile.GetFile("Windows"); data2 = refFile.GetFile("Other"); } string refFileName = ModLoader.ModSourcePath + Path.DirectorySeparatorChar + modReference; File.WriteAllBytes(refFileName + "1.dll", data1); File.WriteAllBytes(refFileName + "2.dll", data2); } return(true); }
private static bool FindReferencedMods(BuildProperties properties, Dictionary <string, LoadingMod> mods) { foreach (var refName in properties.RefNames(true)) { if (mods.ContainsKey(refName)) { continue; } var modFile = new TmodFile(Path.Combine(ModPath, refName + ".tmod")); modFile.Read(); var ex = modFile.ValidMod(); if (ex != null) { ErrorLogger.LogBuildError("Mod reference " + refName + " " + ex); return(false); } var mod = new LoadingMod(modFile, BuildProperties.ReadModFile(modFile)); mods[refName] = mod; FindReferencedMods(mod.properties, mods); } return(true); }
internal static void ReceiveMod(BinaryReader reader) { if (downloadingMod == null) { return; } try { if (downloadingFile == null) { Interface.downloadMod.SetDownloading(reader.ReadString()); Interface.downloadMod.SetCancel(() => { downloadingFile?.Close(); downloadingMod = null; Netplay.disconnect = true; Main.menuMode = 0; }); Main.menuMode = Interface.downloadModID; 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.downloadMod.SetProgress(downloadingFile.Position, downloadingLength); if (downloadingFile.Position == downloadingLength) { downloadingFile.Close(); var mod = new TmodFile(downloadingMod.path); mod.Read(); var ex = mod.ValidMod(); if (ex != null) { throw ex; } if (!downloadingMod.Matches(mod)) { throw new Exception("Hash mismatch"); } if (downloadingMod.signed && !mod.ValidModBrowserSignature) { throw new Exception("Mod was not signed by the Mod Browser"); } ModLoader.EnableMod(mod); if (downloadQueue.Count > 0) { DownloadNextMod(); } else { OnModsDownloaded(true); } } } catch (Exception e) { try { downloadingFile?.Close(); } catch {} File.Delete(downloadingMod.path); ErrorLogger.LogException(e, "An error occured while downloading " + downloadingMod.name); downloadingMod = null; } }