namespace SHNDecrypt
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class ExpEditor : Form
    {
        private Button button1;
        private IContainer components;
        private int expCol = 9;
        private NumericUpDown expNumeric;
        private frmMain form;
        private GroupBox groupBox1;
        private Label label1;
        private decimal savedExp;

        public ExpEditor(frmMain frm)
        {
            this.form = frm;
            this.InitializeComponent();
            if (frm.file == null)
            {
                base.Close();
            }
            this.expCol = this.GetExpColNum();
            if (this.expCol != -1)
            {
                int num = Convert.ToInt32(frm.file.table.Rows[0][this.expCol]);
                this.expNumeric.Value = decimal.Divide(num, 20M);
                this.savedExp = this.expNumeric.Value;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            try
            {
                this.FixPrevious();
                this.form.SQLStatus.Text = "New mob rate: " + this.expNumeric.Value + "x.";
                base.Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void ExpEditor_Load(object sender, EventArgs e)
        {
        }

        private void FixPrevious()
        {
            for (int i = 0; i < this.form.file.table.Rows.Count; i++)
            {
                int num2 = (int) (Convert.ToInt32(this.form.file.table.Rows[i][this.expCol]) / this.savedExp);
                long num3 = (long) (num2 * this.expNumeric.Value);
                if (num3 > 0x7fffffffL)
                {
                    num3 = 0x7fffffffL;
                }
                this.form.file.table.Rows[i][this.expCol] = Convert.ToInt32(num3);
            }
        }

        public int GetExpColNum()
        {
            for (int i = 0; i < this.form.file.table.Columns.Count; i++)
            {
                if (this.form.file.table.Columns[i].ToString() == "MonEXP")
                {
                    return i;
                }
            }
            return -1;
        }

        private void InitializeComponent()
        {
            ComponentResourceManager manager = new ComponentResourceManager(typeof(ExpEditor));
            this.groupBox1 = new GroupBox();
            this.button1 = new Button();
            this.expNumeric = new NumericUpDown();
            this.label1 = new Label();
            this.groupBox1.SuspendLayout();
            this.expNumeric.BeginInit();
            base.SuspendLayout();
            this.groupBox1.Controls.Add(this.button1);
            this.groupBox1.Controls.Add(this.expNumeric);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Location = new Point(12, 12);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0x10a, 0x56);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Experience:";
            this.button1.Location = new Point(0x52, 0x2e);
            this.button1.Name = "button1";
            this.button1.Size = new Size(0xab, 0x1c);
            this.button1.TabIndex = 5;
            this.button1.Text = "Change";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new EventHandler(this.button1_Click_1);
            this.expNumeric.DecimalPlaces = 10;
            this.expNumeric.Location = new Point(0x52, 20);
            int[] bits = new int[4];
            bits[0] = 0x7d0;
            this.expNumeric.Maximum = new decimal(bits);
            this.expNumeric.Name = "expNumeric";
            this.expNumeric.Size = new Size(0xab, 20);
            this.expNumeric.TabIndex = 4;
            int[] numArray2 = new int[4];
            numArray2[0] = 1;
            this.expNumeric.Value = new decimal(numArray2);
            this.label1.AutoSize = true;
            this.label1.Location = new Point(6, 0x19);
            this.label1.Name = "label1";
            this.label1.Size = new Size(70, 13);
            this.label1.TabIndex = 3;
            this.label1.Text = "Current Rate:";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(290, 0x6c);
            base.Controls.Add(this.groupBox1);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.Icon = (Icon) manager.GetObject("$this.Icon");
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "ExpEditor";
            base.StartPosition = FormStartPosition.CenterParent;
            this.Text = "Experience Rate Editor";
            base.Load += new EventHandler(this.ExpEditor_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.expNumeric.EndInit();
            base.ResumeLayout(false);
        }
    }
}

