Exemple #1
0
		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;
		}
Exemple #2
0
		internal static TmodFile[] FindMods()
		{
			Directory.CreateDirectory(ModPath);
			string[] fileNames = Directory.GetFiles(ModPath, "*.tmod", SearchOption.TopDirectoryOnly);
			IList<TmodFile> files = new List<TmodFile>();
			foreach (string fileName in fileNames)
			{
				TmodFile file = new TmodFile(fileName);
				file.Read();
				if (file.ValidMod())
				{
					files.Add(file);
				}
			}
			return files.ToArray();
		}
Exemple #3
0
		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;
			}
		}
Exemple #4
0
        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;
        }
 private static BuildProperties ReadBuildProperties(string modDir)
 {
     string propertiesFile = modDir + Path.DirectorySeparatorChar + "build.txt";
     BuildProperties properties = new BuildProperties();
     if (!File.Exists(propertiesFile))
     {
         return properties;
     }
     string[] lines = File.ReadAllLines(propertiesFile);
     foreach (string line in lines)
     {
         if (line.Length == 0)
         {
             continue;
         }
         int split = line.IndexOf('=');
         string property = line.Substring(0, split).Trim();
         string value = line.Substring(split + 1).Trim();
         if (value.Length == 0)
         {
             continue;
         }
         switch (property)
         {
             case "dllReferences":
                 string[] dllReferences = value.Split(',');
                 for (int k = 0; k < dllReferences.Length; k++)
                 {
                     string dllReference = dllReferences[k].Trim();
                     if (dllReference.Length > 0)
                     {
                         dllReferences[k] = dllReference;
                     }
                 }
                 properties.dllReferences = dllReferences;
                 break;
             case "modReferences":
                 string[] modReferences = value.Split(',');
                 for (int k = 0; k < modReferences.Length; k++)
                 {
                     string modReference = modReferences[k].Trim();
                     if (modReference.Length > 0)
                     {
                         modReferences[k] = modReference;
                     }
                 }
                 properties.modReferences = modReferences;
                 break;
             case "author":
                 properties.author = value;
                 break;
             case "version":
                 properties.version = value;
                 break;
             case "displayName":
                 properties.displayName = value;
                 break;
         }
     }
     foreach (string modReference in properties.modReferences)
     {
         TmodFile refFile = new TmodFile(ModPath + Path.DirectorySeparatorChar + modReference + ".tmod");
         refFile.Read();
         if (!refFile.ValidMod())
         {
             ErrorLogger.LogModReferenceError(refFile.Name);
             return null;
         }
         byte[] data1 = refFile.GetFile("Windows");
         byte[] data2 = refFile.GetFile("Other");
         string refFileName = ModSourcePath + Path.DirectorySeparatorChar + modReference;
         File.WriteAllBytes(refFileName + "1.dll", refFile.GetFile("Windows"));
         File.WriteAllBytes(refFileName + "2.dll", refFile.GetFile("Other"));
     }
     return properties;
 }