public void LoadAssemblies() { if (!NeedsReload) { return; } try { modFile.Read(TmodFile.LoadedState.Code); foreach (var dll in properties.dllReferences) { LoadAssembly(EncapsulateReferences(modFile.GetFile("lib/" + dll + ".dll"))); } assembly = LoadAssembly(EncapsulateReferences(modFile.GetMainAssembly()), modFile.GetMainPDB()); NeedsReload = false; } catch (Exception e) { e.Data["mod"] = Name; throw; } }
internal static LocalMod[] FindMods() { Directory.CreateDirectory(ModPath); var mods = new List <LocalMod>(); foreach (string fileName in Directory.GetFiles(ModPath, "*.tmod", SearchOption.TopDirectoryOnly)) { var lastModified = File.GetLastWriteTime(fileName); if (!modsDirCache.TryGetValue(fileName, out var mod) || mod.lastModified != lastModified) { var modFile = new TmodFile(fileName); try { modFile.Read(TmodFile.LoadedState.Info); } catch (Exception e) //this will probably spam, given the number of calls to FindMods { ErrorLogger.LogException(e, Language.GetTextValue("tModLoader.LoadErrorErrorReadingModFile", modFile.path)); continue; } mod = new LocalMod(modFile) { lastModified = lastModified }; modsDirCache[fileName] = mod; } mods.Add(mod); } return(mods.OrderBy(x => x.Name, StringComparer.InvariantCulture).ToArray()); }
private void FindReferencedMods(BuildProperties properties, Dictionary <string, LocalMod> mods) { foreach (var refName in properties.RefNames(true)) { if (mods.ContainsKey(refName)) { continue; } LocalMod mod; try { var modFile = new TmodFile(Path.Combine(ModPath, refName + ".tmod")); modFile.Read(); mod = new LocalMod(modFile); modFile.Close(); } catch (Exception ex) { throw new Exception(Language.GetTextValue("tModLoader.BuildErrorModReference", refName), ex); } mods[refName] = mod; FindReferencedMods(mod.properties, mods); } }
private void FindReferencedMods(BuildProperties properties, Dictionary <string, LocalMod> mods, bool requireWeak) { foreach (var refName in properties.RefNames(true)) { if (mods.ContainsKey(refName)) { continue; } bool isWeak = properties.weakReferences.Any(r => r.mod == refName); LocalMod mod; try { var modFile = new TmodFile(Path.Combine(ModPath, refName + ".tmod")); modFile.Read(); mod = new LocalMod(modFile); modFile.Close(); } catch (FileNotFoundException) when(isWeak && !requireWeak) { // don't recursively require weak deps, if the mod author needs to compile against them, they'll have them installed continue; } catch (Exception ex) { throw new Exception(Language.GetTextValue("tModLoader.BuildErrorModReference", refName), ex); } mods[refName] = mod; FindReferencedMods(mod.properties, mods, false); } }
internal static TmodFile[] FindMods() { Directory.CreateDirectory(ModPath); IList <TmodFile> files = new List <TmodFile>(); foreach (string fileName in Directory.GetFiles(ModPath, "*.tmod", SearchOption.TopDirectoryOnly)) { var lastModified = File.GetLastWriteTime(fileName); Tuple <DateTime, TmodFile> cacheMod; TmodFile file = null; if (findModsCache.TryGetValue(fileName, out cacheMod)) { if (cacheMod.Item1 == lastModified) { file = cacheMod.Item2; } else { findModsCache.Remove(fileName); } } if (file == null) { file = new TmodFile(fileName); file.Read(); findModsCache.Add(fileName, new Tuple <DateTime, TmodFile>(lastModified, file)); } if (file.ValidMod() == null) { files.Add(file); } } return(files.OrderBy(x => x.name, StringComparer.InvariantCulture).ToArray()); }
private static bool FindReferencedMods(BuildProperties properties, Dictionary <string, LocalMod> mods) { foreach (var refName in properties.RefNames(true)) { if (mods.ContainsKey(refName)) { continue; } var modFile = new TmodFile(Path.Combine(ModPath, refName + ".tmod")); try { modFile.Read(TmodFile.LoadedState.Code); } catch (Exception ex) { ErrorLogger.LogBuildError("Mod reference " + refName + " " + ex); return(false); } var mod = new LocalMod(modFile); mods[refName] = mod; FindReferencedMods(mod.properties, mods); } return(true); }
public ITmodFile LoadFile(string path) { if (!File.Exists(path)) { throw new FileNotFoundException(); } var file = new TmodFile(path, _implementation); file.Read(); return(file); }
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 Dictionary <string, List <string> > dependencyCache; // for some internal features that need to lookup dependencies after load internal static LocalMod[] FindMods() { Directory.CreateDirectory(ModLoader.ModPath); var mods = new List <LocalMod>(); foreach (string fileName in Directory.GetFiles(ModLoader.ModPath, "*.tmod", SearchOption.TopDirectoryOnly)) { if (Path.GetFileName(fileName) == "temporaryDownload.tmod") { continue; } var lastModified = File.GetLastWriteTime(fileName); if (!modsDirCache.TryGetValue(fileName, out var mod) || mod.lastModified != lastModified) { try { var modFile = new TmodFile(fileName); modFile.Read(); modFile.VerifyCoreFiles(); mod = new LocalMod(modFile) { lastModified = lastModified }; modFile.Close(); } catch (Exception e) { if (!readFailures.Contains(fileName)) { Logging.tML.Warn("Failed to read " + fileName, e); } else { readFailures.Add(fileName); } continue; } modsDirCache[fileName] = mod; } mods.Add(mod); } return(mods.OrderBy(x => x.Name, StringComparer.InvariantCulture).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(TmodFile.LoadedState.Info); if (!downloadingMod.Matches(mod)) { throw new Exception(Language.GetTextValue("tModLoader.MPErrorModHashMismatch")); } if (downloadingMod.signed && !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(); } catch { } File.Delete(downloadingMod.path); ErrorLogger.LogException(e, Language.GetTextValue("tModLoader.MPErrorModDownloadError", downloadingMod.name)); downloadingMod = null; } }
internal static void ReceiveMod(BinaryReader reader) { if (downloadingMod == null) { return; } try { if (downloadingFile == null) { // TODO migrate to download UI, create new StreamingDownloadRequest // TODO I hope this works fine without UI for the moment... //Interface.downloadMod.SetDownloading(reader.ReadString()); //Interface.downloadMod.SetCancel(CancelDownload); Main.menuMode = Interface.downloadModID; ModLoader.GetMod(downloadingMod.name)?.File?.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.downloadMod.SetProgress(downloadingFile.Position, downloadingLength); if (downloadingFile.Position == downloadingLength) { downloadingFile.Close(); var mod = new TmodFile(downloadingMod.path); mod.Read(); mod.Close(); if (!downloadingMod.Matches(mod)) { throw new Exception(Language.GetTextValue("tModLoader.MPErrorModHashMismatch")); } if (downloadingMod.signed && !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 { } var msg = Language.GetTextValue("tModLoader.MPErrorModDownloadError", downloadingMod.name); Logging.tML.Error(msg, e); Interface.errorMessage.Show(msg + e, 0); Netplay.disconnect = true; downloadingMod = null; } }