The extractor.
Inheritance: IDisposable
Beispiel #1
0
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        private static string GetAOPath()
        {
            string AOPath = string.Empty;
            bool foundAO = false;
            Console.WriteLine("Enter exit to close program");
            while (!foundAO)
            {
                if (File.Exists("config.txt"))
                {
                    TextReader tr = new StreamReader("config.txt");
                    AOPath = tr.ReadLine();
                    tr.Close();
                }

                foundAO = false;
                Console.Write("Please enter your AO Install Path [" + AOPath + "]:");
                string temp = Console.ReadLine();
                if (temp != string.Empty)
                {
                    AOPath = temp;
                }

                if (temp.ToLower() == "exit")
                {
                    return string.Empty;
                }

                if (!Directory.Exists(AOPath))
                {
                    continue;
                }

                try
                {
                    extractor = new Extractor(AOPath);
                    TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                    tw2.WriteLine(AOPath);
                    tw2.Close();
                    foundAO = true;
                    Console.WriteLine("Found AO Database on " + AOPath);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    foundAO = false;
                }

                // Try to add cd_image\data\db
                if (!foundAO)
                {
                    try
                    {
                        AOPath = Path.Combine(AOPath, "cd_image", "data", "db");
                        extractor = new Extractor(AOPath);
                        TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                        tw2.WriteLine(AOPath);
                        tw2.Close();
                        foundAO = true;
                        Console.WriteLine("Found AO Database on " + AOPath);
                    }
                    catch (Exception)
                    {
                        foundAO = false;
                    }
                }
            }

            return AOPath;
        }
 /// <summary>
 /// The is valid type.
 /// </summary>
 /// <param name="recordType">
 /// The record type.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public bool IsValidType(Extractor.RecordType recordType)
 {
     return this.Records.ContainsKey((int) recordType);
 }
Beispiel #3
0
        /// <summary>
        /// The GetData.
        /// </summary>
        /// <param name="path">
        /// The path.
        /// </param>
        /// <param name="recordtype">
        /// The recordtype.
        /// </param>
        public static void GetData(string path, Extractor.RecordType recordtype)
        {
            int[] items = extractor.GetRecordInstances(recordtype);
            int cou = 0;
            foreach (int item in items)
            {
                try
                {

                    using (
                        var fileStream = new FileStream(Path.Combine(
                            path, item.ToString(CultureInfo.InvariantCulture)),
                            FileMode.Create,
                            FileAccess.Write))
                    {
                        byte[] data = extractor.GetRecordData(recordtype, item);

                        fileStream.Write(data, 0, data.Length);
                    }
                    if (cou % 10 == 0)
                    {
                        Console.WriteLine(item);
                    }

                    cou++;
                }
                catch (Exception)
                {
                }
            }
        }
 /// <summary>
 /// The get record instances.
 /// </summary>
 /// <param name="recordType">
 /// The record type.
 /// </param>
 /// <returns>
 /// The <see cref="int[]"/>.
 /// </returns>
 public int[] GetRecordInstances(Extractor.RecordType recordType)
 {
     return this.Records[(int)recordType].Keys.ToArray();
 }
 /// <summary>
 /// The is valid instance.
 /// </summary>
 /// <param name="recordType">
 /// The record type.
 /// </param>
 /// <param name="recordInstance">
 /// The record instance.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public bool IsValidInstance(Extractor.RecordType recordType, int recordInstance)
 {
     return this.Records.ContainsKey((int)recordType) && this.Records[(int)recordType].ContainsKey(recordInstance);
 }
        /// <summary>
        /// The get record data.
        /// </summary>
        /// <param name="RecordType">
        /// The record type.
        /// </param>
        /// <param name="RecordInstance">
        /// The record instance.
        /// </param>
        /// <param name="decode">
        /// The decode.
        /// </param>
        /// <returns>
        /// The <see cref="byte[]"/>.
        /// </returns>
        /// <exception cref="InvalidDataException">
        /// </exception>
        public byte[] GetRecordData(Extractor.RecordType recordType, int recinstance, bool decode = false)
        {
            int rectype = (int)recordType;
            uint position = this.Records[rectype][recinstance];
            byte[] buffer = this.SegRead(34u, position);
            bStream bStream = new bStream(buffer);
            int num = bStream.ReadInt32_At(10u);
            if (rectype != num)
            {
                throw new InvalidDataException("Invalid Record Type");
            }

            int num2 = bStream.ReadInt32();
            if (recinstance != num2)
            {
                throw new InvalidDataException("Invalid Record Instance");
            }

            uint count = bStream.ReadUInt32() - 12u;
            byte[] array = this.SegRead(count, 4294967295u);
            if (decode)
            {
                ulong num3 = (ulong)recinstance;
                int i = 0;
                while (i < array.Length)
                {
                    num3 *= 16850947uL;
                    num3 %= 21023087759uL;
                    byte[] arg_B0_0 = array;
                    int expr_AB = i++;
                    arg_B0_0[expr_AB] ^= (byte)num3;
                }
            }

            return array;
        }
        /// <summary>
        /// The parse item.
        /// </summary>
        /// <param name="rectype">
        /// The rectype.
        /// </param>
        /// <param name="recnum">
        /// The recnum.
        /// </param>
        /// <param name="data">
        /// The data.
        /// </param>
        /// <param name="itemNamesSqlList">
        /// </param>
        /// <returns>
        /// The <see cref="AOItem"/>.
        /// </returns>
        public ItemTemplate ParseItem(Extractor.RecordType recordType, int recnum, byte[] data, List<string> itemNamesSqlList)
        {
            int rectype = (int)recordType;
            this.br = new BufferedReader(rectype, recnum, data);
            ItemTemplate aoi = new ItemTemplate();

            aoi.ID = recnum;
            this.br.Skip(16);

            int num = this.br.Read3F1();
            int argc0 = 0;

            int num2 = num - 1;
            int num3 = argc0;

            while (true)
            {
                int arg1c2 = num3;
                int num4 = num2;
                if (arg1c2 > num4)
                {
                    break;
                }

                int attrkey = this.br.ReadInt32();
                int attrval = this.br.ReadInt32();
                if (attrkey == 54)
                {
                    aoi.Quality = attrval;
                }
                else
                {
                    aoi.Stats.Add(attrkey, attrval);
                }

                num3++;
            }

            this.br.Skip(8);

            short num5 = this.br.ReadInt16();
            short num6 = this.br.ReadInt16();
            string itemname = string.Empty;
            if (num5 > 0)
            {
                itemname = this.br.ReadString(num5);
            }

            if (itemNamesSqlList != null)
            {
                itemNamesSqlList.Add(string.Format("( {0} , '{1}' , '{2}', '{3}' ) ",
                    recnum,
                    itemname.Replace("'", "''"),
                    Enum.GetName(typeof(Extractor.RecordType), recordType),
                    aoi.getItemAttribute(79)));
            }

            if (num6 > 0)
            {
                this.br.ReadString(num6); // Read and discard Description
            }

            bool flag4 = true;
            checked
            {
                while (this.br.Ptr < this.br.Buffer.Length - 8 && flag4)
                {
                    switch (this.br.ReadInt32()) // what are these ints ?
                    {
                        case 2:
                            this.ParseFunctionSet(aoi.Events);
                            break;
                        case 3:
                        case 5:
                        case 7:
                        case 8:
                        case 9:
                        case 10:
                        case 11:
                        case 12:
                        case 13:
                        case 15:
                        case 16:
                        case 17:
                        case 18:
                        case 19:
                        case 21:
                            goto IL_4BF;
                        case 4:
                            this.ParseAtkDefSet(aoi.Attack, aoi.Defend);
                            break;
                        case 6:
                            {
                                this.br.Skip(4);
                                int count = this.br.Read3F1() * 8;
                                this.br.Skip(count);
                                break;
                            }

                        case 14:
                            this.ParseAnimSoundSet(1, aoi);
                            break;
                        case 20:
                            this.ParseAnimSoundSet(2, aoi);
                            break;
                        case 22:
                            this.ParseActionSet(aoi.Actions);
                            break;
                        case 23:
                            this.ParseShopHash(aoi.Events);
                            break;
                        default:
                            goto IL_4BF;
                    }

                    continue;
                IL_4BF:
                    flag4 = false;
                }
            }

            return aoi;
        }
Beispiel #8
0
        /// <summary>
        /// </summary>
        /// <returns>
        /// </returns>
        private static string GetAOPath()
        {
            string AOPath  = string.Empty;
            bool   foundAO = false;

            Console.WriteLine("Enter exit to close program");
            while (!foundAO)
            {
                if (File.Exists("config.txt"))
                {
                    TextReader tr = new StreamReader("config.txt");
                    AOPath = tr.ReadLine();
                    tr.Close();
                }

                foundAO = false;
                Console.Write("Please enter your AO Install Path [" + AOPath + "]:");
                string temp = Console.ReadLine();
                if (temp != string.Empty)
                {
                    AOPath = temp;
                }

                if (temp.ToLower() == "exit")
                {
                    return(string.Empty);
                }

                if (!Directory.Exists(AOPath))
                {
                    continue;
                }

                try
                {
                    extractor = new Extractor(AOPath);
                    TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                    tw2.WriteLine(AOPath);
                    tw2.Close();
                    foundAO = true;
                    Console.WriteLine("Found AO Database on " + AOPath);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    foundAO = false;
                }

                // Try to add cd_image\data\db
                if (!foundAO)
                {
                    try
                    {
                        AOPath    = Path.Combine(AOPath, "cd_image", "data", "db");
                        extractor = new Extractor(AOPath);
                        TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                        tw2.WriteLine(AOPath);
                        tw2.Close();
                        foundAO = true;
                        Console.WriteLine("Found AO Database on " + AOPath);
                    }
                    catch (Exception)
                    {
                        foundAO = false;
                    }
                }
            }

            return(AOPath);
        }
Beispiel #9
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            Console.WriteLine("**********************************************************************");
            Console.WriteLine("**                                                                  **");
            Console.WriteLine("**  AO Item and Nano Extractor/Serializer v0.85beta                  **");
            Console.WriteLine("**                                                                  **");
            Console.WriteLine("**********************************************************************");

            Console.WriteLine();

            string AOPath  = string.Empty;
            bool   foundAO = false;

            Console.WriteLine("Enter exit to close program");
            while (!foundAO)
            {
                if (File.Exists("config.txt"))
                {
                    TextReader tr = new StreamReader("config.txt");
                    AOPath = tr.ReadLine();
                    tr.Close();
                }

                foundAO = false;
                Console.Write("Please enter your AO Install Path [" + AOPath + "]:");
                string temp = Console.ReadLine();
                if (temp != string.Empty)
                {
                    AOPath = temp;
                }

                if (temp.ToLower() == "exit")
                {
                    return;
                }

                if (!Directory.Exists(AOPath))
                {
                    continue;
                }

                try
                {
                    extractor = new Extractor(AOPath);
                    TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                    tw2.WriteLine(AOPath);
                    tw2.Close();
                    foundAO = true;
                    Console.WriteLine("Found AO Database on " + AOPath);
                }
                catch (Exception)
                {
                    foundAO = false;
                }

                // Try to add cd_image\data\db
                if (!foundAO)
                {
                    try
                    {
                        AOPath    = Path.Combine(AOPath, "cd_image\\data\\db");
                        extractor = new Extractor(AOPath);
                        TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                        tw2.WriteLine(AOPath);
                        tw2.Close();
                        foundAO = true;
                        Console.WriteLine("Found AO Database on " + AOPath);
                    }
                    catch (Exception)
                    {
                        foundAO = false;
                    }
                }
            }

            TextWriter tw = new StreamWriter("itemnames.sql", false, Encoding.GetEncoding("windows-1252"));

            tw.WriteLine("DROP TABLE IF EXISTS `itemnames`;");
            tw.WriteLine("CREATE TABLE `itemnames` (");
            tw.WriteLine("  `AOID` int(10) NOT NULL,");
            tw.WriteLine("  `Name` varchar(250) NOT NULL,");
            tw.WriteLine("  PRIMARY KEY (`AOID`)");
            tw.WriteLine(") ENGINE=MyIsam DEFAULT CHARSET=latin1;");
            tw.WriteLine();
            tw.Close();

            Console.WriteLine("Number of Items to extract: " + extractor.GetRecordInstances(0xF4254).Length);

            // ITEM RECORD TYPE
            Console.WriteLine("Number of Nanos to extract: " + extractor.GetRecordInstances(0xFDE85).Length);

            // NANO RECORD TYPE

            // Console.WriteLine(extractor.GetRecordInstances(0xF4241).Length); // Playfields
            // Console.WriteLine(extractor.GetRecordInstances(0xF4266).Length); // Nano Strains
            // Console.WriteLine(extractor.GetRecordInstances(0xF4264).Length); // Perks

            // GetData(@"D:\c#\extractor serializer\data\items\",0xf4254);
            // GetData(@"D:\c#\extractor serializer\data\nanos\",0xfde85);
            // GetData(@"D:\c#\extractor serializer\data\playfields\",0xf4241);
            // GetData(@"D:\c#\extractor serializer\data\nanostrains\",0xf4266);
            // GetData(@"D:\c#\extractor serializer\data\perks\",0xf4264);
            var np          = new NewParser();
            var rawItemList = new List <AOItem>();
            var rawNanoList = new List <AONanos>();

            foreach (int recnum in extractor.GetRecordInstances(0xFDE85))
            {
                rawNanoList.Add(np.ParseNano(0xFDE85, recnum, extractor.GetRecordData(0xFDE85, recnum), "temp.sql"));
            }

            File.Delete("temp.sql");
            Console.WriteLine();
            Console.WriteLine("Nanos extracted: " + rawNanoList.Count);

            List <string> ItemNamesSql = new List <string>();

            foreach (int recnum in extractor.GetRecordInstances(0xF4254))
            {
                rawItemList.Add(np.ParseItem(0xF4254, recnum, extractor.GetRecordData(0xF4254, recnum), ItemNamesSql));
            }

            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("Compacting itemnames.sql");
            TextWriter itnsql = new StreamWriter("itemnames.sql", true, Encoding.GetEncoding("windows-1252"));

            while (ItemNamesSql.Count > 0)
            {
                int    count   = 0;
                string toWrite = string.Empty;
                while ((count < 20) && (ItemNamesSql.Count > 0))
                {
                    if (toWrite.Length > 0)
                    {
                        toWrite += ",";
                    }

                    toWrite += ItemNamesSql[0];
                    ItemNamesSql.RemoveAt(0);
                    count++;
                }

                if (toWrite != string.Empty)
                {
                    itnsql.WriteLine("INSERT INTO itemnames VALUES " + toWrite + ";");
                }
            }

            itnsql.Close();

            // SerializationContext.Default.Serializers.Register(new AOFunctionArgumentsSerializer());
            Console.WriteLine();
            Console.WriteLine("Items extracted: " + rawItemList.Count);

            Console.WriteLine();
            Console.WriteLine("Creating serialized nano data file - please wait");
            Stream sf = new FileStream("nanos.dat", FileMode.Create);

            var ds = new ZOutputStream(sf, zlibConst.Z_BEST_COMPRESSION);
            var sm = new MemoryStream();
            MessagePackSerializer <List <AONanos> > bf = MessagePackSerializer.Create <List <AONanos> >();

            var nanoList2 = new List <AONanos>();

            int maxnum = 5000;

            byte[] buffer = BitConverter.GetBytes(maxnum);
            sm.Write(buffer, 0, buffer.Length);

            foreach (AONanos nanos in rawNanoList)
            {
                nanoList2.Add(nanos);
                if (nanoList2.Count == maxnum)
                {
                    bf.Pack(sm, nanoList2);
                    sm.Flush();
                    nanoList2.Clear();
                }
            }

            bf.Pack(sm, nanoList2);
            sm.Seek(0, SeekOrigin.Begin);
            CopyStream(sm, ds);
            sm.Close();
            ds.Close();

            Console.WriteLine();
            Console.WriteLine("Checking Nanos...");
            Console.WriteLine();
            NanoHandler.CacheAllNanos("nanos.dat");
            Console.WriteLine();
            Console.WriteLine("Nanos: " + NanoHandler.NanoList.Count + " successfully converted");

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Creating serialized item data file - please wait");

            sf = new FileStream("items.dat", FileMode.Create);

            ds = new ZOutputStream(sf, zlibConst.Z_BEST_COMPRESSION);
            sm = new MemoryStream();
            MessagePackSerializer <List <AOItem> > bf2 = MessagePackSerializer.Create <List <AOItem> >();

            List <AOItem> items = new List <AOItem>();

            maxnum = 5000;
            buffer = BitConverter.GetBytes(maxnum);
            sm.Write(buffer, 0, buffer.Length);

            foreach (AOItem it in rawItemList)
            {
                items.Add(it);
                if (items.Count == maxnum)
                {
                    bf2.Pack(sm, items);
                    sm.Flush();
                    items.Clear();
                }
            }

            bf2.Pack(sm, items);
            sm.Seek(0, SeekOrigin.Begin);
            CopyStream(sm, ds);
            sm.Close();
            ds.Close();

            Console.WriteLine();
            Console.WriteLine("Checking Items...");
            Console.WriteLine();

            ItemHandler.CacheAllItems("items.dat");

            Console.WriteLine("Items: " + ItemHandler.ItemList.Count + " successfully converted");

            Console.WriteLine();
            Console.WriteLine("Further Instructions:");
            Console.WriteLine("- Copy items.dat and nanos.dat into your CellAO folder and overwrite.");
            Console.WriteLine("- Apply itemnames.sql to your database");
            Console.WriteLine("Press Enter to exit and have fun with CellAO");
            Console.ReadLine();
        }
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            Console.WriteLine("**********************************************************************");
            Console.WriteLine("**                                                                  **");
            Console.WriteLine("**  AO Item and Nano Extractor/Serializer v0.85beta                  **");
            Console.WriteLine("**                                                                  **");
            Console.WriteLine("**********************************************************************");

            Console.WriteLine();

            string AOPath = string.Empty;
            bool foundAO = false;
            Console.WriteLine("Enter exit to close program");
            while (!foundAO)
            {
                if (File.Exists("config.txt"))
                {
                    TextReader tr = new StreamReader("config.txt");
                    AOPath = tr.ReadLine();
                    tr.Close();
                }

                foundAO = false;
                Console.Write("Please enter your AO Install Path [" + AOPath + "]:");
                string temp = Console.ReadLine();
                if (temp != string.Empty)
                {
                    AOPath = temp;
                }

                if (temp.ToLower() == "exit")
                {
                    return;
                }

                if (!Directory.Exists(AOPath))
                {
                    continue;
                }

                try
                {
                    extractor = new Extractor(AOPath);
                    TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                    tw2.WriteLine(AOPath);
                    tw2.Close();
                    foundAO = true;
                    Console.WriteLine("Found AO Database on " + AOPath);
                }
                catch (Exception)
                {
                    foundAO = false;
                }

                // Try to add cd_image\data\db
                if (!foundAO)
                {
                    try
                    {
                        AOPath = Path.Combine(AOPath, "cd_image\\data\\db");
                        extractor = new Extractor(AOPath);
                        TextWriter tw2 = new StreamWriter("config.txt", false, Encoding.GetEncoding("windows-1252"));
                        tw2.WriteLine(AOPath);
                        tw2.Close();
                        foundAO = true;
                        Console.WriteLine("Found AO Database on " + AOPath);
                    }
                    catch (Exception)
                    {
                        foundAO = false;
                    }
                }
            }

            TextWriter tw = new StreamWriter("itemnames.sql", false, Encoding.GetEncoding("windows-1252"));
            tw.WriteLine("DROP TABLE IF EXISTS `itemnames`;");
            tw.WriteLine("CREATE TABLE `itemnames` (");
            tw.WriteLine("  `AOID` int(10) NOT NULL,");
            tw.WriteLine("  `Name` varchar(250) NOT NULL,");
            tw.WriteLine("  PRIMARY KEY (`AOID`)");
            tw.WriteLine(") ENGINE=MyIsam DEFAULT CHARSET=latin1;");
            tw.WriteLine();
            tw.Close();

            Console.WriteLine("Number of Items to extract: " + extractor.GetRecordInstances(0xF4254).Length);

            // ITEM RECORD TYPE
            Console.WriteLine("Number of Nanos to extract: " + extractor.GetRecordInstances(0xFDE85).Length);

            // NANO RECORD TYPE

            // Console.WriteLine(extractor.GetRecordInstances(0xF4241).Length); // Playfields
            // Console.WriteLine(extractor.GetRecordInstances(0xF4266).Length); // Nano Strains
            // Console.WriteLine(extractor.GetRecordInstances(0xF4264).Length); // Perks

            // GetData(@"D:\c#\extractor serializer\data\items\",0xf4254);
            // GetData(@"D:\c#\extractor serializer\data\nanos\",0xfde85);
            // GetData(@"D:\c#\extractor serializer\data\playfields\",0xf4241);
            // GetData(@"D:\c#\extractor serializer\data\nanostrains\",0xf4266);
            // GetData(@"D:\c#\extractor serializer\data\perks\",0xf4264);
            var np = new NewParser();
            var rawItemList = new List<AOItem>();
            var rawNanoList = new List<AONanos>();
            foreach (int recnum in extractor.GetRecordInstances(0xFDE85))
            {
                rawNanoList.Add(np.ParseNano(0xFDE85, recnum, extractor.GetRecordData(0xFDE85, recnum), "temp.sql"));
            }

            File.Delete("temp.sql");
            Console.WriteLine();
            Console.WriteLine("Nanos extracted: " + rawNanoList.Count);

            List<string> ItemNamesSql = new List<string>();

            foreach (int recnum in extractor.GetRecordInstances(0xF4254))
            {
                rawItemList.Add(np.ParseItem(0xF4254, recnum, extractor.GetRecordData(0xF4254, recnum), ItemNamesSql));
            }

            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("Compacting itemnames.sql");
            TextWriter itnsql = new StreamWriter("itemnames.sql", true, Encoding.GetEncoding("windows-1252"));
            while (ItemNamesSql.Count > 0)
            {
                int count = 0;
                string toWrite = string.Empty;
                while ((count < 20) && (ItemNamesSql.Count > 0))
                {
                    if (toWrite.Length > 0)
                    {
                        toWrite += ",";
                    }

                    toWrite += ItemNamesSql[0];
                    ItemNamesSql.RemoveAt(0);
                    count++;
                }

                if (toWrite != string.Empty)
                {
                    itnsql.WriteLine("INSERT INTO itemnames VALUES " + toWrite + ";");
                }
            }

            itnsql.Close();

            // SerializationContext.Default.Serializers.Register(new AOFunctionArgumentsSerializer());
            Console.WriteLine();
            Console.WriteLine("Items extracted: " + rawItemList.Count);

            Console.WriteLine();
            Console.WriteLine("Creating serialized nano data file - please wait");
            Stream sf = new FileStream("nanos.dat", FileMode.Create);

            var ds = new ZOutputStream(sf, zlibConst.Z_BEST_COMPRESSION);
            var sm = new MemoryStream();
            MessagePackSerializer<List<AONanos>> bf = MessagePackSerializer.Create<List<AONanos>>();

            var nanoList2 = new List<AONanos>();

            int maxnum = 5000;
            byte[] buffer = BitConverter.GetBytes(maxnum);
            sm.Write(buffer, 0, buffer.Length);

            foreach (AONanos nanos in rawNanoList)
            {
                nanoList2.Add(nanos);
                if (nanoList2.Count == maxnum)
                {
                    bf.Pack(sm, nanoList2);
                    sm.Flush();
                    nanoList2.Clear();
                }
            }

            bf.Pack(sm, nanoList2);
            sm.Seek(0, SeekOrigin.Begin);
            CopyStream(sm, ds);
            sm.Close();
            ds.Close();

            Console.WriteLine();
            Console.WriteLine("Checking Nanos...");
            Console.WriteLine();
            NanoHandler.CacheAllNanos("nanos.dat");
            Console.WriteLine();
            Console.WriteLine("Nanos: " + NanoHandler.NanoList.Count + " successfully converted");

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Creating serialized item data file - please wait");

            sf = new FileStream("items.dat", FileMode.Create);

            ds = new ZOutputStream(sf, zlibConst.Z_BEST_COMPRESSION);
            sm = new MemoryStream();
            MessagePackSerializer<List<AOItem>> bf2 = MessagePackSerializer.Create<List<AOItem>>();

            List<AOItem> items = new List<AOItem>();

            maxnum = 5000;
            buffer = BitConverter.GetBytes(maxnum);
            sm.Write(buffer, 0, buffer.Length);

            foreach (AOItem it in rawItemList)
            {
                items.Add(it);
                if (items.Count == maxnum)
                {
                    bf2.Pack(sm, items);
                    sm.Flush();
                    items.Clear();
                }
            }

            bf2.Pack(sm, items);
            sm.Seek(0, SeekOrigin.Begin);
            CopyStream(sm, ds);
            sm.Close();
            ds.Close();

            Console.WriteLine();
            Console.WriteLine("Checking Items...");
            Console.WriteLine();

            ItemHandler.CacheAllItems("items.dat");

            Console.WriteLine("Items: " + ItemHandler.ItemList.Count + " successfully converted");

            Console.WriteLine();
            Console.WriteLine("Further Instructions:");
            Console.WriteLine("- Copy items.dat and nanos.dat into your CellAO folder and overwrite.");
            Console.WriteLine("- Apply itemnames.sql to your database");
            Console.WriteLine("Press Enter to exit and have fun with CellAO");
            Console.ReadLine();
        }