Exemplo n.º 1
0
        public static void Pack(string EveFolder, string outFile = null)
        {
            var eve = new EVE();

            string folderA = Path.Combine(EveFolder, "A");

            string[] foldersInA = Directory.GetDirectories(folderA);
            Array.Sort(foldersInA);
            foreach (var eventGroupFolder in foldersInA)
            {
                var      lst        = new List <(byte[], EVE.Event)>();
                string[] eventFiles = Directory.GetFiles(eventGroupFolder, "*.psle");
                Array.Sort(eventFiles);
                string[] binFiles = Directory.GetFiles(eventGroupFolder, "*.bin");
                Array.Sort(binFiles);
                if (eventFiles.Length != binFiles.Length)
                {
                    throw new Exception($"Different number of bin files to psle in '{eventGroupFolder}' ({eventFiles.Length}, {binFiles.Length})");
                }
                for (int i = 0; i < eventFiles.Length; i++)
                {
                    var eventFile = eventFiles[i];
                    var binFile   = binFiles[i];
                    var e         = new EVE.Event()
                    {
                        AllData = File.ReadAllBytes(eventFile)
                    };
                    var bin = File.ReadAllBytes(binFile);
                    Debug.Assert(bin.Length == 0x40);
                    lst.Add((bin, e));
                }
                eve.EventGroupsA.Add(lst);
            }

            string folderB = Path.Combine(EveFolder, "B");

            string[] foldersInB = Directory.GetDirectories(folderB);
            Array.Sort(foldersInB);
            foreach (var eventGroupFolder in foldersInB)
            {
                var lst = new List <EVE.Event>();
                foreach (var eventFile in Directory.GetFiles(eventGroupFolder, "*.psle"))
                {
                    var e = new EVE.Event()
                    {
                        AllData = File.ReadAllBytes(eventFile)
                    };
                    lst.Add(e);
                }
                eve.EventGroupsB.Add(lst);
            }

            string headerInfo = Path.Combine(EveFolder, "headerinfo.bin");

            using (var br = new BinaryReader(File.OpenRead(headerInfo)))
            {
                eve.FileId = br.ReadInt32();
                if (eve.FileId != 0x64 && eve.FileId != 0x65)
                {
                    throw new Exception("Unexpected File Id");
                }
                eve.HeaderUnknown = br.ReadInt32();
            }

            outFile = outFile ?? FileUtil.MakeUniquePath(EveFolder + ".eve");
            eve.Save(outFile);
        }