/// <summary>
        /// Initialize all stuffs required for the connection and settings
        /// </summary>
        private void Initialize()
        {
            Pk2Reader pk2Reader = null;

            try
            {
                // Load pk2 reader
                pk2Reader = new Pk2Reader(LauncherSettings.PATH_PK2_MEDIA, LauncherSettings.CLIENT_BLOWFISH_KEY);

                // Load settings
                m_Config = new ConfigViewModel();
                m_Config.Load(pk2Reader);

                // Extract essential stuffs for the process
                if (pk2Reader.TryGetDivisionInfo(out m_DivisionInfo) &&
                    pk2Reader.TryGetGateport(out m_Gateport) &&
                    pk2Reader.TryGetVersion(out m_Version) &&
                    pk2Reader.TryGetLocale(out m_Locale))
                {
                    IsLoaded = true;
                    // Force string to be updated
                    Version = m_Version;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            finally
            {
                pk2Reader?.Close();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Try to loads all required everything to create the connection to server
        /// </summary>
        private void LoadPk2()
        {
            Pk2Reader pk2Reader = null;

            try
            {
                // Load pk2 reader
                pk2Reader = new Pk2Reader(LauncherSettings.PATH_PK2_MEDIA, LauncherSettings.CLIENT_BLOWFISH_KEY);

                // Try to load Type.txt
                m_Config.LoadTypeFile(pk2Reader);

                // Extract essential stuffs for the process
                if (pk2Reader.TryGetDivisionInfo(out m_DivisionInfo) &&
                    pk2Reader.TryGetGateport(out m_Gateport) &&
                    pk2Reader.TryGetVersion(out m_Version) &&
                    pk2Reader.TryGetLocale(out m_Locale))
                {
                    IsLoaded = true;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            finally
            {
                pk2Reader?.Close();
            }
        }
Exemplo n.º 3
0
        private void Control_Click(object sender, EventArgs e)
        {
            Control c = (Control)sender;

            switch (c.Name)
            {
            case "btnWinExit":
                if (tGenerateData != null)
                {
                    if (tGenerateData.ThreadState == ThreadState.WaitSleepJoin || tGenerateData.ThreadState == ThreadState.Running)
                    {
                        if (MessageBox.Show(this, "The process still running. Are you sure?", "xBot - Pk2 Extractor", MessageBoxButtons.YesNo) != DialogResult.Yes)
                        {
                            return;
                        }
                    }
                    tGenerateData.Abort();
                    if (db != null)
                    {
                        db.Close();
                    }
                    if (pk2 != null)
                    {
                        pk2.Close();
                        pk2.Dispose();
                    }
                }
                this.Close();
                break;

            case "btnStart":
                btnStart.Enabled       = false;
                tGenerateData          = new Thread(ThreadGenerateData);
                tGenerateData.Priority = ThreadPriority.Highest;
                tGenerateData.Start();
                break;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Try to generate the database.
        /// </summary>
        public void ThreadGenerateData()
        {
            Log("Opening Pk2 file using " + (tbxBlowfishKey.Text != "" ? "blowfish key: " + tbxBlowfishKey.Text : "default blowfish key"));
            LogState("Opening Pk2 file...");
            try
            {
                pk2 = new Pk2Reader(MediaPk2Path, tbxBlowfishKey.Text);
            }
            catch
            {
                Log("Error opening Pk2 file. Possibly wrong blowfish key");
                LogState("Error");
                btnStart.InvokeIfRequired(() => {
                    btnStart.Enabled = true;
                });
                return;
            }
            Log("Pk2 file opened!");
            LogState();

            // Fill info to Main GUI
            Window w = Window.Get;

            try
            {
                Log("Extracting Silkroad Version");
                LogState("Extracting...");
                // Reading
                Packet p = new Packet(0, false, false, pk2.GetFileBytes("SV.T"));
                p.Lock();
                int    dataLength = p.ReadInt();
                byte[] dataBuffer = p.ReadByteArray(dataLength);
                // Decoding
                Blowfish bf = new Blowfish();
                bf.Initialize(Encoding.ASCII.GetBytes("SILKROADVERSION"), 0, dataLength);
                byte[] dataDecoded = bf.Decode(dataBuffer);
                this.Version = uint.Parse(Encoding.ASCII.GetString(dataDecoded, 0, 4));
            }
            catch (Exception ex)
            {
                Log("Extracting error, the version cannot be readed. " + ex.Message);
                LogState("Error");
                btnStart.InvokeIfRequired(() => {
                    btnStart.Enabled = true;
                });
                return;
            }

            try
            {
                Log("Extracting Locale & Gateway");
                LogState("Extracting...");
                // Reading
                Packet p = new Packet(0, false, false, pk2.GetFileBytes("DIVISIONINFO.TXT"));
                p.Lock();
                this.Locale = p.ReadByte();
                byte divisionCount = p.ReadByte();
                for (int i = 0; i < divisionCount; i++)
                {
                    string DivisionName = p.ReadString(p.ReadInt());
                    p.ReadByte();                     // 0

                    byte gatewayCount = p.ReadByte();
                    Gateways = new System.Collections.Generic.List <string>(gatewayCount);
                    for (int j = 0; j < gatewayCount; j++)
                    {
                        string gatewayHost = p.ReadString(p.ReadInt());
                        p.ReadByte();                         // 0

                        Gateways.Add(gatewayHost);
                    }
                }
            }
            catch (Exception ex)
            {
                Log("Extracting error, gateways cannot be readed. " + ex.Message);
                LogState("Error");
                btnStart.InvokeIfRequired(() => {
                    btnStart.Enabled = true;
                });
                return;
            }

            try
            {
                Log("Extracting Gateport");
                LogState("Extracting...");
                // Reading
                Packet p = new Packet(0, false, false, pk2.GetFileBytes("GATEPORT.TXT"));
                p.Lock();

                string test = p.ReadString(p.RemainingRead());
                this.Gateport = ushort.Parse(test);
            }
            catch (Exception ex)
            {
                Log("Extracting error, the gateport cannot be readed. " + ex.Message);
                LogState("Error");
                btnStart.InvokeIfRequired(() => {
                    btnStart.Enabled = true;
                });
                return;
            }

            // Updating database
            Log("Creating Database...");
            string dbPath = GetDatabasePath(SilkroadName);

            if (File.Exists(dbPath))
            {
                LogState("Deleting old database");
                if (!WinAPI.FileTryDelete(dbPath))
                {
                    // Deleting issues
                    Log("The database from \"" + SilkroadName + "\" is being used by another program. Please, close all the bots and try again!");
                    LogState("Error");
                    btnStart.InvokeIfRequired(() => {
                        btnStart.Font = new Font(btnStart.Font, FontStyle.Regular);
                    });
                    return;
                }
            }
            // Creating the database
            LogState("Creating database");
            db = new SQLDatabase(dbPath);
            if (!db.Create())
            {
                Log("Error creating the database. Please, close all the bots and try again!");
                LogState("Error");
                btnStart.InvokeIfRequired(() => {
                    btnStart.Font = new Font(btnStart.Font, FontStyle.Regular);
                });
                return;
            }
            Log("Database has been created!");

            // Create connection
            LogState("Connecting to database");
            if (!db.Connect())
            {
                Log("Database connection error!");
                Log("Error");
                return;
            }
            LogState("Connected");

            // Generating database
            Log("Generating database (this may take a while)");
            SetLanguageIndex();
            Log("Loading name references...");
            LoadNameReferences();
            Log("Loading & Adding text references...");
            LoadTextReferences();
            AddTextReferences();
            Log("Adding Items...");
            AddItems();
            Log("Adding Magic options...");
            AddMagicOptions();
            Log("Adding Characters & Mobs...");
            AddModels();
            Log("Adding Masteries & Skills...");
            AddMasteries();
            AddSkills();
            Log("Adding Exp. & Levels...");
            AddLevelExperience();
            Log("Adding Shops...");
            AddShops();
            Log("Loading Teleport references");
            LoadTeleportData();
            Log("Adding Teleports & Structures...");
            AddTeleportBuildings();
            AddTeleportLinks();
            Log("Adding Regions...");
            AddRegions();
            Log("Database has been generated correctly!");

            Log("Creating Item icons...");
            AddItemIcons();
            Log("Creating Skill icons...");
            AddSkillIcons();
            if (this.cbxMinimap.Checked)
            {
                Log("Creating minimap images to the bot folder...");
                AddMinimap();
            }

            Log("All has been generated succesfully, Enjoy! :)");
            db.Close();
            pk2.Close();
            pk2.Dispose();
            LogState("Closing Pk2 file...");
            Thread.Sleep(1000);

            WinAPI.InvokeIfRequired(this, () => {
                this.DialogResult = DialogResult.OK;
                this.Activate();
                this.Close();
            });
        }