예제 #1
0
파일: DCT.cs 프로젝트: uebari/TeraEmuTools
        public static DataCenter GetDataCenter(string path = "dc.bin")
        {
            if (_dataCenter == null)
            {
                using (FileStream fs = File.OpenRead(path))
                {
                    _dataCenter = Serializer.Deserialize<DataCenter>(fs);
                }
            }

            return _dataCenter;
        }
예제 #2
0
파일: DCT.cs 프로젝트: uebari/TeraEmuTools
        public static void Unpack()
        {
            Console.WriteLine("\n--- DC Unpack ---\n");
            Stopwatch stopwatch = Stopwatch.StartNew();

            //Devide DataCenter

            if (!File.Exists("data.dec"))
                CutFileData("dc.dec", "data.dec", 0x00000294, 0x025D0B04);

            if (!File.Exists("structs.dec"))
                CutFileData("dc.dec", "structs.dec", 0x02600508, 0x039F5100);

            if (!File.Exists("strings.dec"))
                CutFileData("dc.dec", "strings.dec", 0x03A0059C, 0x05320444);

            if (!File.Exists("strings_id.dec"))
                CutFileData("dc.dec", "strings_id.dec", 0x058B7910, 0x05A1D05C);

            if (!File.Exists("args.dec"))
                CutFileData("dc.dec", "args.dec", 0x05A1D068, 0x05A382DC);

            //

            #region StringIds

            if (!File.Exists("strings_id.bin"))
            {
                ReadStringIds("strings_id.dec");

                using (FileStream fs = File.Create("strings_id.bin"))
                {
                    Serializer.Serialize(fs, StringIds);
                }
            }
            else
            {
                using (FileStream fs = File.OpenRead("strings_id.bin"))
                {
                    StringIds = Serializer.Deserialize<Dictionary<int, KeyValuePair<string, byte[]>>>(fs);
                }
            }

            Console.WriteLine("Readed {0} string id's...", StringIds.Count);

            #endregion

            #region Strings

            if (!File.Exists("strings.bin"))
            {
                ReadStrings("strings.dec", 0x020000);

                using (FileStream fs = File.Create("strings.bin"))
                {
                    Serializer.Serialize(fs, Strings);
                }
            }
            else
            {
                using (FileStream fs = File.OpenRead("strings.bin"))
                {
                    Strings = Serializer.Deserialize<Dictionary<string, string>>(fs);
                }
            }

            Console.WriteLine("Readed {0} strings...", Strings.Count);

            #endregion

            ReadArgs("args.dec");

            ReadValues("data.dec");

            ReadObjects("structs.dec");

            Console.WriteLine("Readed {0} structures...", DcObjects.Count);

            //

            Console.WriteLine("Build DataCenter protobuf...");

            DataCenter dataCenter = new DataCenter
                                        {
                                            Values = Values,
                                            Objects = DcObjects,
                                            MainObjects = new List<DcObject>(),
                                        };

            bool[] used = new bool[DcObjects.Count];

            for (int i = 0; i < DcObjects.Count; i++)
                for (int j = 0; j < DcObjects[i].SubCount; j++)
                    used[DcObjects[i].SubShift + j] = true;

            for (int i = 0; i < DcObjects.Count; i++)
            {
                if (used[i] || DcObjects[i].Name == "Hash")
                    continue;

                dataCenter.MainObjects.Add(DcObjects[i]);
            }

            using (FileStream fs = File.Create("dc.bin"))
            {
                Serializer.Serialize(fs, dataCenter);
            }

            //

            stopwatch.Stop();
            Console.WriteLine("\rAll done in {0}s", (stopwatch.ElapsedMilliseconds / 1000.0).ToString("0.00"));
        }
예제 #3
0
        public static void Unpack(string lang)
        {
            language = lang;

            Console.WriteLine("\n--- DC Unpack ---\n");
            Stopwatch stopwatch = Stopwatch.StartNew();

            //Devide DataCenter
            switch (language)
            {
                case "eng":
                {
                    CutFilesEng();
                    break;
                }

                case "ger":
                {
                    CutFilesGer();
                    break;
                }
            }

            #region StringIds
            Console.Write("processing String IDs: ");

            if (!File.Exists("strings_id.bin"))
            {
                ReadStringIds("strings_id.dec");

                using (FileStream fs = File.Create("strings_id.bin"))
                {
                    Serializer.Serialize(fs, StringIds);
                }
            }
            else
            {
                using (FileStream fs = File.OpenRead("strings_id.bin"))
                {
                    StringIds = Serializer.Deserialize<Dictionary<int, KeyValuePair<string, byte[]>>>(fs);
                }
            }

            Console.WriteLine("{0} - DONE", StringIds.Count);

            #endregion

            #region Strings

            Console.Write("processing Strings   : ");

            if (!File.Exists("strings.bin"))
            {
                ReadStrings("strings.dec", 0x020000);

                using (FileStream fs = File.Create("strings.bin"))
                {
                    Serializer.Serialize(fs, Strings);
                }
            }
            else
            {
                using (FileStream fs = File.OpenRead("strings.bin"))
                {
                    Strings = Serializer.Deserialize<Dictionary<string, string>>(fs);
                }
            }

            Console.WriteLine("{0} - DONE", Strings.Count);

            #endregion

            Console.Write("processing Args IDs  : ");

            if (!File.Exists("args_id.bin"))
            {
                ReadArgIds("args_id.dec");

                using (FileStream fs = File.Create("args_id.bin"))
                {
                    Serializer.Serialize(fs, ArgIds);
                }
            }
            else
            {
                using (FileStream fs = File.OpenRead("args_id.bin"))
                {
                    ArgIds = Serializer.Deserialize<Dictionary<int, KeyValuePair<string, byte[]>>>(fs);
                }
            }

            Console.WriteLine("{0} - DONE", ArgIds.Count+1);

            ReadArgs("args.dec");

            ReadValues("data.dec");

            ReadObjects("structs.dec");

            Console.WriteLine("--------------------------------------------------");

            DataCenter dataCenter = new DataCenter
                                        {
                                            Values = Values,
                                            Objects = DcObjects,
                                            MainObjects = new List<DcObject>(),
                                        };

            bool[] used = new bool[DcObjects.Count];
            int counter = 1;
            //go trough all Objects
            for (int i = 0; i < DcObjects.Count; i++)

                for (int j = 0; j < DcObjects[i].SubCount; j++)
                    used[DcObjects[i].SubShift + j] = true;

            for (int i = 0; i < DcObjects.Count; i++)
            {
                txt = "\rObject -> MainObject : " + counter+1;
                Console.Write(txt + " - {0}%", (100f * i / DcObjects.Count).ToString("0.00"));
                if (used[i] || DcObjects[i].Name == "Hash")
                 continue;

               dataCenter.MainObjects.Add(DcObjects[i]);
               counter++;
            }

            Console.Out.WriteLine(txt+ " - DONE            ");
            Console.Write("building DataCenter protobuf...");
            using (FileStream fs = File.Create("dc.bin"))
            {
                Serializer.Serialize(fs, dataCenter);
            }
            Console.WriteLine(" - DONE");
            Console.WriteLine("--------------------------------------------------");
            stopwatch.Stop();
            Console.WriteLine("\rAll done in {0}s", (stopwatch.ElapsedMilliseconds / 1000.0).ToString("0.00"));
            Console.WriteLine("--------------------------------------------------");
        }