Ejemplo n.º 1
0
        public static void Unpack(string filePath, string outFolder = null)
        {
            var eve = new EVE(filePath);

            outFolder = outFolder ?? FileUtil.MakeUniquePath(Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath)));
            Directory.CreateDirectory(outFolder);

            {
                string folderA = Path.Combine(outFolder, "A");
                Directory.CreateDirectory(folderA);
                int groupCount = 0;
                foreach (var eventGroup in eve.EventGroupsA)
                {
                    string eventGroupFolder = Path.Combine(folderA, groupCount++.ToString().PadLeft(4, '0'));
                    Directory.CreateDirectory(eventGroupFolder);
                    int eventCount = 0;
                    foreach (var e in eventGroup)
                    {
                        string baseFile    = Path.Combine(eventGroupFolder, eventCount++.ToString().PadLeft(4, '0'));
                        string eventFile   = baseFile + ".psle";
                        string unknownFile = baseFile + ".bin";
                        File.WriteAllBytes(eventFile, e.Item2.AllData);
                        File.WriteAllBytes(unknownFile, e.Item1);
                    }
                }
            }

            {
                string folderB = Path.Combine(outFolder, "B");
                Directory.CreateDirectory(folderB);
                int groupCount = 0;
                foreach (var eventGroup in eve.EventGroupsB)
                {
                    string eventGroupFolder = Path.Combine(folderB, groupCount++.ToString().PadLeft(4, '0'));
                    Directory.CreateDirectory(eventGroupFolder);
                    int eventCount = 0;
                    foreach (var e in eventGroup)
                    {
                        string baseFile  = Path.Combine(eventGroupFolder, eventCount++.ToString().PadLeft(4, '0'));
                        string eventFile = baseFile + ".psle";
                        File.WriteAllBytes(eventFile, e.AllData);
                    }
                }
            }

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

            using (var bw = new BinaryWriter(File.Create(headerInfo)))
            {
                bw.Write(eve.FileId);
                bw.Write(eve.HeaderUnknown);
            }
        }
Ejemplo n.º 2
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);
        }