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
        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)
            {
                string path = ModPath + Path.DirectorySeparatorChar + modReference + ".tmod";
                if (!File.Exists(path))
                {
                    ErrorLogger.LogModReferenceError(modReference);
                    return(null);
                }
                byte[] data;
                using (FileStream fileStream = File.OpenRead(path))
                {
                    using (BinaryReader reader = new BinaryReader(fileStream))
                    {
                        fileStream.Seek(reader.ReadInt32(), SeekOrigin.Current);
                        data = reader.ReadBytes(reader.ReadInt32());
                    }
                }
                using (FileStream writeStream = File.Create(ModSourcePath + Path.DirectorySeparatorChar + modReference + ".dll"))
                {
                    using (BinaryWriter writer = new BinaryWriter(writeStream))
                    {
                        writer.Write(data);
                    }
                }
            }
            return(properties);
        }