Register for your free account! | Forgot your password?

Go Back   elitepvpers > Popular Games > Silkroad Online > SRO Coding Corner
You last visited: Yesterday at 23:59

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C#] Media.pk2 Parser For ISro (Source)

Discussion on [C#] Media.pk2 Parser For ISro (Source) within the SRO Coding Corner forum part of the Silkroad Online category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Mar 2009
Posts: 5
Received Thanks: 3
[C#] Media.pk2 Parser For ISro (Source)



Thx torstmn For Pk2 Reader
Attached Files
File Type: rar src+bin.rar (7.69 MB, 483 views)
File Type: rar bin.rar (939.1 KB, 176 views)
djbm is offline  
Thanks
1 User
Old 03/28/2013, 11:51   #2
 
elite*gold: 0
Join Date: Mar 2013
Posts: 55
Received Thanks: 4
Smile

Nice, ill use your source code this help me a lot. Anyway it doesnt works for me, at vsro pk2-s gives unmanaged exceptions, at isro pk2 stops at translating... But as i said thats no problem ill repair those things and its very useful for me.

There i modified the code a bit for vsro based servers. The pk2 sturcture is a bit different at vsro... So i didnt deleted the code what u wrote just commented the unneccesary things, to be clear for everyone what i changed. Now this tool saves the parsed things into 3 different txt's not in DB.
Code:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Reflection;

namespace DataParser
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            #region Dialog
            OpenFileDialog odlg = new OpenFileDialog();
            odlg.Title = "Select Media.pk2";
            odlg.Filter = "media.pk2|media.pk2";
            if (odlg.ShowDialog() != DialogResult.OK)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error => Not Select Media.PK2");
                Console.ResetColor();
                Console.ReadLine();
                return;
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Media.pk2 Key(isro = 169841):");
            string pk2Key = "169841";//Console.ReadLine();
            Console.ResetColor();
            /*
            SaveFileDialog sdlg = new SaveFileDialog();
            sdlg.Title = "Save Data";
            sdlg.Filter = "SQLite|*.db";
            if (sdlg.ShowDialog() != DialogResult.OK)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error => Save Dialog");
                Console.ResetColor();
                Console.ReadLine();
                return;
            }*/
            #endregion

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("Reading Media.Pk2");
            Console.WriteLine("----Reading Data----");
            PK2Reader.Reader Pk2Reader;
            try { Pk2Reader = new PK2Reader.Reader(odlg.FileName, pk2Key); }
            catch (Exception) 
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error => Not Valid Key");
                Console.ResetColor();
                Console.ReadLine();
                return;
            }
            Console.WriteLine("----Readed Data----");
            Console.ResetColor();

            #region SQL Initialize
            //SQLiteConnection Sc = new SQLiteConnection("Data Source=" + sdlg.FileName + "; Version=3; New=True; Compress=True; Journal Mode=Off;");
            //SQLiteCommand Slc = new SQLiteCommand("CREATE TABLE [Skills] ([ID] INTEGER  NULL,[Type] TEXT  NULL,[Subtype] TEXT  NULL,[Name] TEXT  NULL,[CastTime] INTEGER  NULL,[Cooldown] INTEGER  NULL,[MP] INTEGER  NULL,[Icon] BLOB  NULL);CREATE TABLE [Mobs] ([ID] INTEGER  NULL,[Type] TEXT  NULL,[Subtype] TEXT  NULL,[Name] TEXT  NULL,[Lvl] INTEGER  NULL,[Hp] INTEGER  NULL);CREATE TABLE [Items] ([ID] INTEGER  NULL,[Type] TEXT  NULL,[Subtype] TEXT  NULL,[Name] TEXT  NULL,[Level] INTEGER  NULL,[Stack] INTEGER  NULL,[Durability] INTEGER  NULL,[Icon] BLOB  NULL);", Sc);
            //Sc.Open();
            //Slc.ExecuteNonQuery();
            //Slc.Dispose();
            #endregion

            #region Data Initialize
            System.Threading.Thread.Sleep(500); 
            Console.ForegroundColor = ConsoleColor.Yellow;
            TextWriter tr = new StreamWriter("skills.txt",true);
            Console.WriteLine("----Reading Skill Data----");
            Generator_Skills.Initialize(Pk2Reader);
            tr.WriteLine("******************************************************************************************************************");
            tr.WriteLine("ID, TYPE, SUBTYPE, NAME, CASTTIME, COOLDOWN, MP_REQ");
            tr.WriteLine("******************************************************************************************************************");
            for (int i = 0; i < Generator_Skills.skills_list.Length; i++)
            {
                if (Generator_Skills.skills_list[i].qid != null && Generator_Skills.skills_list[i].qid != "")
                {
                    tr.WriteLine("Skill: " + Generator_Skills.skills_list[i].qid + ", " + Generator_Skills.skills_list[i].type + ", " + Generator_Skills.skills_list[i].subtype + ", " + Generator_Skills.skills_list[i].name + ", " + Generator_Skills.skills_list[i].casttime + ", " + Generator_Skills.skills_list[i].cooldown + ", " + Generator_Skills.skills_list[i].mpreq);
                    //Slc.Parameters.AddWithValue("@pic", Generator_Skills.skills_list[i].icon);
                    //Slc.ExecuteNonQuery();
                    //Slc.Dispose();
                    
                }
            }
            tr.WriteLine("");
            tr.WriteLine("---------------------------------------------------------------------------------------------------------------");
            tr.Write("");
            tr.Close();
            Console.WriteLine("----End Skill Data----");

            Console.ResetColor();

            System.Threading.Thread.Sleep(500);

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("----Reading Mob Data----");
            Generator_Mobs.Initialize(Pk2Reader);
            tr = new StreamWriter("mobs.txt", true);
            tr.WriteLine("******************************************************************************************************************");
            tr.WriteLine("ID, TYPE, SUBTYPE, NAME, LVL, HP");
            tr.WriteLine("******************************************************************************************************************");

            for (int i = 0; i < Generator_Mobs.object_list.Length; i++)
            {
                if (Generator_Mobs.object_list[i].qid != null && Generator_Mobs.object_list[i].qid != "")
                {
                    /*Slc = new SQLiteCommand*/
                    tr.WriteLine("Monster: " + ", " + Generator_Mobs.object_list[i].qid + ", " + Generator_Mobs.object_list[i].type + ", " + Generator_Mobs.object_list[i].subtype + ", " + Generator_Mobs.object_list[i].name + ", " + Generator_Mobs.object_list[i].level + ", " + Generator_Mobs.object_list[i].hp);
                    //Slc.ExecuteNonQuery();
                    //Slc.Dispose();
                }
            }
            tr.WriteLine("");
            tr.WriteLine("---------------------------------------------------------------------------------------------------------------");
            tr.Write("");
            tr.Close();
            Console.WriteLine("----End Mob Data----");
            Console.ResetColor();

            System.Threading.Thread.Sleep(500);

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("----Reading Item Data----");
            Generator_Items.Initialize(Pk2Reader);
            tr = new StreamWriter("items.txt", true);
            tr.WriteLine("******************************************************************************************************************");
            tr.WriteLine("ID, TYPE, SUBTYPE, NAME, LVL, STACK, DURA");
            tr.WriteLine("******************************************************************************************************************");

            for (int i = 0; i < Generator_Items.items_list.Length; i++)
            {
                if (Generator_Items.items_list[i].qid != null && Generator_Items.items_list[i].qid != "")
                {
                    tr.WriteLine("Item: " + Generator_Items.items_list[i].qid + ", " + Generator_Items.items_list[i].type + ", " + Generator_Items.items_list[i].subtype + ", " + Generator_Items.items_list[i].name + ", " + Generator_Items.items_list[i].level + ", " + Generator_Items.items_list[i].stack + ", " + Generator_Items.items_list[i].durability);
                    //Slc.Parameters.AddWithValue("@pic", Generator_Items.items_list[i].icon);
                    //Slc.ExecuteNonQuery();
                    //Slc.Dispose();
                }
            }
            Console.WriteLine("----End Item Data----");
            Console.ResetColor();
            #endregion

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("----End Generate Data----");
            Console.ResetColor();
            Console.ReadKey();
            tr.Close();
        }
    }

    class Generator_Skills
    {
        public struct Skill
        {
            public string qid;
            public string type;
            public string subtype;
            public string name;
            public string casttime;
            public string cooldown;
            public string mpreq;
            public byte[] icon;
        }
        public static Skill[] skills_list = new Skill[50000];
        public static int a = 0;

        public static void Initialize(PK2Reader.Reader reader)
        {
            a = 0;
            TextReader tr = new StreamReader(reader.GetFileStream("skilldata.txt"));
            string line = tr.ReadLine();
            while (line != null && line != "")
            {
                Generate(line, reader);
                line = tr.ReadLine();
            }

            tr.Close();

            Array.Resize(ref skills_list, (a + 1));
            Translate(reader);
        }

        public static void Generate(string input, PK2Reader.Reader reader)
        {
            Console.WriteLine("Add Skill List = " + input);
            System.Threading.Thread.Sleep(5);
            TextReader tr = new StreamReader(reader.GetFileStream(input));
            string line = tr.ReadLine();
            while (line != null)
            {
                if (line.StartsWith("1"))
                {
                    string[] splited = line.Split('	');
                    var skillicon = splited[61].Split('\\').Last().Replace(".ddj", ".PNG");
                    if ((splited[3].StartsWith("SKILL_CH") | splited[3].StartsWith("SKILL_EU")) && splited[62] != "xxx" && skillicon != "xxx")
                    {
                        skills_list[a].qid = splited[1];
                        skills_list[a].type = splited[3];
                        skills_list[a].subtype = splited[62];
                        skills_list[a].casttime = splited[13];
                        skills_list[a].cooldown = splited[14];
                        skills_list[a].mpreq = splited[53];
                        if (File.Exists("Icons\\" + skillicon))
                        {
                            FileStream fs = new FileStream("Icons\\" + skillicon, FileMode.Open, FileAccess.Read); ;
                            byte[] picbyte = new byte[fs.Length];
                            fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
                            fs.Close();
                            skills_list[a].icon = picbyte;
                        }
                        else { skills_list[a].icon = null; }
                        skills_list[a].icon = null;
                        a++;
                    }
                }
                line = tr.ReadLine();
            }
            tr.Close();
        }

        public static void Translate(PK2Reader.Reader reader)
        {
            Console.WriteLine("Translating Skills Name");
            TextReader tr = new StreamReader(reader.GetFileStream("textdata_equip&skill.txt"));
            //Console.WriteLine("AAAAAAAATMENT");
            string line = tr.ReadLine();
            //while (line != null && line != "")
            //{
                System.Threading.Thread.Sleep(5);
                TextReader trt = tr;//new StreamReader(reader.GetFileStream(line));
                string linet = line; //trt.ReadLine();
                while (linet != null)
                {
                    if (linet.StartsWith("1"))
                    {
                        string[] splitedt = linet.Split('	');
                        for (int i = 0; i < skills_list.Length; i++)
                        {
                            if (skills_list[i].subtype == splitedt[1])//!!!
                            {
                                skills_list[i].name = splitedt[9];
                            }
                            if (skills_list[i].name == "" || skills_list[i].name == null)
                            {
                                skills_list[i].name = skills_list[i].type;
                            }
                        }
                    }
                    linet = trt.ReadLine();
                }
                //trt.Close();
                //line = tr.ReadLine();
            //}

            tr.Close();

        }

    }

    class Generator_Mobs
    {
        public struct Mob
        {
            public string qid;
            public string type;
            public string subtype;
            public string name;
            public string level;
            public string hp;
        }

        public static Mob[] object_list = new Mob[500000];
        public static int a = 0;

        public static void Initialize(PK2Reader.Reader reader)
        {
            a = 0;
            TextReader tr = new StreamReader(reader.GetFileStream("characterdata.txt"));
            string line = tr.ReadLine();
            while (line != null && line != "")
            {
                Generate(line, reader);
                line = tr.ReadLine();
            }

            tr.Close();

            #region Teleport Building
            Console.WriteLine("Adding Objects List = teleportbuilding.txt");
            System.Threading.Thread.Sleep(5);
            tr = new StreamReader(reader.GetFileStream("teleportbuilding.txt"));
            line = tr.ReadLine();
            while (line != null)
            {
                if (line.StartsWith("1"))
                {
                    string[] splited = line.Split('	');
                    object_list[a].qid = splited[1];
                    object_list[a].type = splited[2];
                    object_list[a].subtype = splited[5];
                    object_list[a].level = "0";
                    object_list[a].hp = "0";
                    a++;
                }
                line = tr.ReadLine();
            }
            tr.Close();
            #endregion

            Console.WriteLine("");
            Array.Resize(ref object_list, (a + 1));
            Translate(reader);
        }

        public static void Generate(string input, PK2Reader.Reader reader)
        {
            Console.WriteLine("Adding Objects List = " + input);
            System.Threading.Thread.Sleep(1);
            TextReader tr = new StreamReader(reader.GetFileStream(input));
            string line = tr.ReadLine();
            while (line != null)
            {
                if (line.StartsWith("1"))
                {
                    string[] splited = line.Split('	');
                    object_list[a].qid = splited[1];
                    object_list[a].type = splited[2];
                    object_list[a].subtype = splited[5];
                    object_list[a].level = splited[57];
                    object_list[a].hp = splited[59];
                    a++;
                }
                line = tr.ReadLine();
            }
            tr.Close();
        }

        public static void Translate(PK2Reader.Reader reader)
        {
            Console.WriteLine("Translating Object Name");
            TextReader tr = new StreamReader(reader.GetFileStream("textdata_object.txt"));
            //Console.WriteLine("Atment");
            string line = tr.ReadLine();
            //while (line != null && line != "")
            //{
                System.Threading.Thread.Sleep(5);
                TextReader trt = tr; //new StreamReader(reader.GetFileStream(line));
                string linet = line;//trt.ReadLine();
                while (linet != null)
                {
                    if (linet.StartsWith("1"))
                    {
                        string[] splitedt = linet.Split('	');
                        if (splitedt.Count() >= 9)
                        {
                            for (int i = 0; i < object_list.Length; i++)
                            {
                                if (object_list[i].subtype == splitedt[1])//!!!
                                {
                                    object_list[i].name = splitedt[9];
                                }
                                if (object_list[i].name == "" || object_list[i].name == null)
                                {
                                    object_list[i].name = object_list[i].type;
                                }
                            }
                        }
                    }
                    linet = trt.ReadLine();
                //}
                //trt.Close();
                //line = tr.ReadLine();
            }
            
            tr.Close();

        }
    }

    class Generator_Items
    {
        public struct Item
        {
            public string qid;
            public string type;
            public string subtype;
            public string name;
            public string level;
            public string stack;
            public string durability;
            public byte[] icon;
        }
        public static Item[] items_list = new Item[500000];
        public static int a = 0;

        public static void Initialize(PK2Reader.Reader reader)
        {
            a = 0;
            TextReader tr = new StreamReader(reader.GetFileStream("itemdata.txt"));
            string line = tr.ReadLine();
            while (line != null && line != "")
            {
                Generate(line, reader);
                line = tr.ReadLine();
            }

            tr.Close();

            Console.WriteLine("");
            Array.Resize(ref items_list, (a + 1));
            Translate(reader);
        }

        public static void Generate(string input, PK2Reader.Reader reader)
        {
            Console.WriteLine("Adding Items List = " + input);
            System.Threading.Thread.Sleep(1);
            TextReader tr = new StreamReader(reader.GetFileStream(input));
            string line = tr.ReadLine();
            while (line != null)
            {
                if (line.StartsWith("1"))
                {
                    try
                    {
                        string[] splited = line.Split('	');
                        var itemicon = splited[54].Split('\\').Last().Replace(".ddj", ".PNG");
                        items_list[a].qid = splited[1];
                        items_list[a].type = splited[2];
                        items_list[a].subtype = splited[5];
                        items_list[a].level = splited[33];
                        if (items_list[a].level.Length > 3)
                        {
                            items_list[a].level = items_list[a].level.Remove(3, (items_list[a].level.Length - 3));
                        }
                        items_list[a].stack = splited[57];
                        items_list[a].durability = splited[63].Split('.')[0];

                        if (File.Exists("Icons\\" + itemicon))
                        {
                            FileStream fs = new FileStream("Icons\\" + itemicon, FileMode.Open, FileAccess.Read); ;
                            byte[] picbyte = new byte[fs.Length];
                            fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
                            fs.Close();

                            items_list[a].icon = picbyte;
                        }
                        else { items_list[a].icon = null; }
                        a++;
                    }
                    catch
                    {
                        items_list[a].level = "0";
                        items_list[a].stack = "1";
                        items_list[a].durability = "0";
                    }
                }
                line = tr.ReadLine();
            }
            tr.Close();
        }

        public static void Translate(PK2Reader.Reader reader)
        {
            Console.WriteLine("Translating Item Name");
            TextReader tr = new StreamReader(reader.GetFileStream("textdata_equip&skill.txt"));
            //string line = tr.ReadLine();
            //while (line != null && line != "")
            //{
                System.Threading.Thread.Sleep(5);
                TextReader trt = tr;//new StreamReader(reader.GetFileStream(line));
                string linet = trt.ReadLine();
                while (linet != null)
                {
                    if (linet.StartsWith("1"))
                    {
                        string[] splitedt = linet.Split('	');
                        for (int i = 0; i < items_list.Length; i++)
                        {
                            if (items_list[i].subtype == splitedt[1])//!!!
                            {
                                //MessageBox.Show("IGEN");
                                items_list[i].name = splitedt[9];
                            }
                            if (items_list[i].name == "" || items_list[i].name == null)
                            {
                                items_list[i].name = items_list[i].type;
                            }
                        }
                    }
                    linet = trt.ReadLine();
                }
                //trt.Close();
                //line = tr.ReadLine();
            //}
            trt.Close();
            tr.Close();

            tr = new StreamReader(reader.GetFileStream("textdata_object.txt"));
            //line = tr.ReadLine();
            //while (line != null && line != "")
            //{
                System.Threading.Thread.Sleep(5);
                 trt = tr;//new StreamReader(reader.GetFileStream(line));
                //linet=null;
                 linet = trt.ReadLine();
                while (linet != null)
                {
                    if (linet.StartsWith("1"))
                    {
                        string[] splitedt = linet.Split('	');
                        if (splitedt.Count() >= 9)
                        {
                            for (int i = 0; i < items_list.Length; i++)
                            {
                                if (items_list[i].subtype == splitedt[1])//!!!
                                {
                                    //MessageBox.Show("Igen");
                                    items_list[i].name = splitedt[9];//!!!
                                }
                                if (items_list[a].name == "" || items_list[a].name == null)
                                {
                                    //MessageBox.Show("Nem");
                                    items_list[a].name = items_list[a].type;
                                }
                            }
                        }
                    }
                    linet = trt.ReadLine();
                }
                trt.Close();
                //line = tr.ReadLine();
            tr.Close();
            

            //tr.Close();

        }

    }
}
miamidolphin is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
NEED ISRO MEDIA PK2 1.317
10/03/2013 - SRO Private Server - 1 Replies
SOME ONE HAVE ISRO MEDIA.PK2 ISRO 1.317 THX I HAVE THE CLIENT NEED ONLY MEDIA PK2.
Latest iSro media.pk2
09/08/2011 - Silkroad Online - 3 Replies
can anyone upload it here.I need it, but i don't play iSro and i don't want to download hole client for a media.pk. Thanks if anyone helps.
[Request] Original Media.pk2 iSRO.!
02/08/2011 - Silkroad Online - 4 Replies
well title say everything, i need the original media.pk2 because i forget to make an backup of mine :( so if someone can upload it i will give you the thanks :D



All times are GMT +1. The time now is 00:01.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.