Beispiel #1
0
        // Loads the txt file into the List view
        public void LoadData(NSListView listview, OpenFileDialog openfile)
        {
            openfile.InitialDirectory = GetFilePath();
            string[] datatypes = { "CHAR", "float", "WORD", "DWORD", "BYTE", "int" };

            if (openfile.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var rtb = new RichTextBox {
                Text = File.ReadAllText(openfile.FileName)
            };
            var i = 0;

            foreach (var line in rtb.Lines)
            {
                if (line == "--")
                {
                    for (var index = 0; index < datatypes.Length; index++)
                    {
                        if (datatypes[index] == rtb.Lines[i + 1] && OnlyHexInString(rtb.Lines[i + 3]))
                        {
                            listview.AddItem(rtb.Lines[i + 1], rtb.Lines[i + 2], rtb.Lines[i + 3].ToUpper());
                        }
                    }
                }
                i++;
            }
        }
Beispiel #2
0
        //Clears all the items from the list view
        public void ClearAll(NSListView listview)
        {
            var length = listview.Items.Length;

            for (var i = 0; i < length; i++)
            {
                listview.RemoveItemAt(0);
            }
        }
Beispiel #3
0
        //A function that gets all of the names from the listview
        public string[] Getnames(NSListView listview)
        {
            var names = new string[listview.Items.Length];

            for (var i = 0; i < listview.Items.Length; i++)
            {
                names[i] = listview.Items[i].SubItems[0].Text;
            }
            return(names);
        }
Beispiel #4
0
        //A function that gets all of the offsets from the list view
        public string[] Getoffsets(NSListView listview)
        {
            var offsets = new string[listview.Items.Length];

            for (var i = 0; i < listview.Items.Length; i++)
            {
                offsets[i] = listview.Items[i].SubItems[1].Text;
            }
            return(offsets);
        }
Beispiel #5
0
 //A function that finds the data type of the offset from the listview
 private static string Findtype(NSListView listview, string valuetosearch)
 {
     for (var i = 0; i < listview.Items.Length; i++)
     {
         if (listview.Items[i].SubItems[1].Text == valuetosearch)
         {
             return(listview.Items[i].Text);
         }
     }
     return(null);
 }
Beispiel #6
0
        public bool IsOffsetExists(string offset, NSListView listview)
        {
            var func = new StructBuilderFunctions();

            for (var i = 0; i < listview.Items.Length; i++)
            {
                if (offset == func.Getoffsets(listview)[i])
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #7
0
        public bool IsNameExists(string name, NSListView listview)
        {
            var func = new StructBuilderFunctions();

            for (var i = 0; i < listview.Items.Length; i++)
            {
                if (name == func.Getnames(listview)[i])
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #8
0
        //Writes down the "Format"
        public string Serialize(NSListView listview)
        {
            string value = null;

            for (var i = 0; i < listview.Items.Length; i++)
            {
                value += "--" + Environment.NewLine;
                value += listview.Items[i].Text + Environment.NewLine;
                value += listview.Items[i].SubItems[0].Text + Environment.NewLine;
                value += listview.Items[i].SubItems[1].Text + Environment.NewLine;
            }
            return(value);
        }
Beispiel #9
0
        //The main function
        public string Buildstruct(string name, NSListView listview, bool isInt, bool isComment)
        {
            //======== Declare our global Variables ============
            //The string that will hold our struct
            string generatedstruct = null;
            //The variable that will hold the last byte of the offset
            uint lastbyte = 0;
            //Just an add-on so we can have a unique name in unknownbytes. Even a random number/words will work
            var unknowndatacount = 0;
            //The variable that will hold the offsets
            var offsets = new uint[listview.Items.Length];

            // ======= Where the magic begins ==========

            //Get the offsets from the list view then save it into our variable
            for (var i = 0; i < listview.Items.Length; i++)
            {
                offsets[i] = Convert.ToUInt32(Getoffsets(listview)[i], 16);
            }

            //Sort our array of offset from least to greatest
            Array.Sort(offsets);

            //Write our headers
            generatedstruct += "struct " + name + Environment.NewLine;
            generatedstruct += "{" + Environment.NewLine;

            //Loop all the offsets
            for (var i = 0; i < offsets.Length; i++)
            {
                //Calculate the useless data that we have to skip
                var unknowndata = offsets[i] - lastbyte;
                //Dont write if there are no useless data
                if (unknowndata != 0)
                {
                    //Write the useless bytes we have to skip
                    generatedstruct += "char UnknownData" + unknowndatacount + "[";

                    //If the user wants the unknowndata in integer format
                    if (isInt)
                    {
                        generatedstruct += unknowndata + "];";
                        //If the user wants it to be commented
                        if (isComment)
                        {
                            generatedstruct += "    //0x" + lastbyte.ToString("X");
                        }
                    }
                    //If the user wants the unknowndata in hex format
                    else
                    {
                        generatedstruct += "0x" + unknowndata.ToString("X") + "];";
                        //If the user wants it to be commented
                        if (isComment)
                        {
                            generatedstruct += "  //0x" + lastbyte.ToString("X");
                        }
                    }
                    generatedstruct += Environment.NewLine;
                    //Add 1 to the count so we can have a unique name in the next loop
                    unknowndatacount++;
                }
                //Write the offsets
                generatedstruct += Findtype(listview, offsets[i].ToString("X")) + " " +
                                   Findname(listview, offsets[i].ToString("X")) + ";";
                //If the user wants it to be commented
                if (isComment)
                {
                    generatedstruct += "    //0x" + offsets[i].ToString("X");
                }
                generatedstruct += Environment.NewLine;

                //In here, we assign the value for lastbyte of the offset
                switch (Findtype(listview, offsets[i].ToString("X")))
                {
                case "float":
                    lastbyte = offsets[i] + sizeof(float);
                    break;

                case "WORD":
                    lastbyte = offsets[i] + sizeof(ushort);
                    break;

                case "DWORD":
                    lastbyte = offsets[i] + sizeof(uint);
                    break;

                case "BYTE":
                    lastbyte = offsets[i] + sizeof(byte);
                    break;

                case "int":
                    lastbyte = offsets[i] + sizeof(int);
                    break;
                }

                // *Since the size of a char is not constant, getting it's size is different*
                // Let's find the datatype with "CHAR"
                if (Findtype(listview, offsets[i].ToString("X")).Contains("CHAR"))
                {
                    //If found, get it's size then add it to the offset so we can have the last byte of it.
                    lastbyte = offsets[i] +
                               (uint)Convert.ToInt32(Getcharsize(Findname(listview, offsets[i].ToString("X"))));
                }
            }

            //Write our footer :]
            generatedstruct += "};" + Environment.NewLine;

            //Extract the generated struct
            return(generatedstruct);
        }
Beispiel #10
0
 //Remove the selected item form the list view
 public void RemoveSelected(NSListView listview)
 {
     listview.RemoveItems(listview.SelectedItems);
 }
Beispiel #11
0
        // Evento click items
        // Muestra detalles de movimiento seleccionado
        private void NSLvItems_Click(object sender, EventArgs e)
        {
            if (NSLvItems.Items.Length > 0)
            {
                // Item seleccionado
                NSListView items = (NSListView)sender;

                // Cargar Tablero
                string[] tablero = items.SelectedItems[0].SubItems[6].Text.Split(',');

                // Tablero
                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 8; j++)
                    {
                        PictureBox casilla = (PictureBox)Controls.Find("PbxCasilla" + i + "" + j, true)[0];

                        if (casilla.Tag.ToString()[0] == 'B')
                        {
                            casilla.BackColor = Color.FromArgb(100, 100, 100);
                        }
                        else if (casilla.Tag.ToString()[0] == 'N')
                        {
                            casilla.BackColor = Color.FromArgb(25, 25, 25);
                        }

                        switch (Convert.ToInt32(tablero[i * 8 + j]))
                        {
                        // Peones
                        case Pieza.IDPEONB:
                            casilla.Image = UAChess.Properties.Resources.PzPeonB;
                            break;

                        case Pieza.IDPEONN:
                            casilla.Image = UAChess.Properties.Resources.PzPeonN;
                            break;

                        // Caballos
                        case Pieza.IDCABALLOB:
                            casilla.Image = UAChess.Properties.Resources.PzCaballoB;
                            break;

                        case Pieza.IDCABALLON:
                            casilla.Image = UAChess.Properties.Resources.PzCaballoN;
                            break;

                        // Alfiles
                        case Pieza.IDALFILB:
                            casilla.Image = UAChess.Properties.Resources.PzAlfilB;
                            break;

                        case Pieza.IDALFILN:
                            casilla.Image = UAChess.Properties.Resources.PzAlfilN;
                            break;

                        // Torres
                        case Pieza.IDTORREB:
                            casilla.Image = UAChess.Properties.Resources.PzTorreB;
                            break;

                        case Pieza.IDTORREN:
                            casilla.Image = UAChess.Properties.Resources.PzTorreN;
                            break;

                        // Damas
                        case Pieza.IDDAMAB:
                            casilla.Image = UAChess.Properties.Resources.PzDamaB;
                            break;

                        case Pieza.IDDAMAN:
                            casilla.Image = UAChess.Properties.Resources.PzDamaN;
                            break;

                        // Reyes
                        case Pieza.IDREYB:
                            casilla.Image = UAChess.Properties.Resources.PzReyB;
                            break;

                        case Pieza.IDREYN:
                            casilla.Image = UAChess.Properties.Resources.PzReyN;
                            break;

                        // Vacio
                        default:
                            casilla.Image = null;
                            break;
                        }
                    }
                }

                // Cargar movimiento
                string[] movimiento = items.SelectedItems[0].SubItems[3].Text.Split(',');

                int po = Convert.ToInt32(movimiento[0]);
                int xo = Convert.ToInt32(movimiento[1]);
                int yo = Convert.ToInt32(movimiento[2]);
                int pd = Convert.ToInt32(movimiento[3]);
                int xd = Convert.ToInt32(movimiento[4]);
                int yd = Convert.ToInt32(movimiento[5]);
                int me = Convert.ToInt32(movimiento[6]);
                int pe = Convert.ToInt32(movimiento[7]);

                PictureBox casillaO = (PictureBox)Controls.Find("PbxCasilla" + xo + "" + yo, true)[0];
                PictureBox casillaD = (PictureBox)Controls.Find("PbxCasilla" + xd + "" + yd, true)[0];

                // Movimiento NORMAL
                casillaD.Image = casillaO.Image;
                casillaO.Image = null;

                // Movimiento ALPASO blancas
                if (po > 0 && me == Tablero.ALPASO)
                {
                    PictureBox casilla = (PictureBox)Controls.Find("PbxCasilla" + xd + "" + (yd - 1), true)[0];
                    casilla.Image = null;
                }
                // Movimiento ALPASO negras
                else if (po < 0 && me == Tablero.ALPASO)
                {
                    PictureBox casilla = (PictureBox)Controls.Find("PbxCasilla" + xd + "" + (yd + 1), true)[0];
                    casilla.Image = null;
                }
                // Movimiento ENROQUEC blancas
                else if (po > 0 && me == Tablero.ENROQUEC)
                {
                    PictureBox casillaTO = (PictureBox)Controls.Find("PbxCasilla70", true)[0];
                    PictureBox casillaTD = (PictureBox)Controls.Find("PbxCasilla" + (xd - 1) + "" + yd, true)[0];

                    casillaTD.Image = casillaTO.Image;
                    casillaTO.Image = null;
                }
                // Movimiento ENROQUEC negras
                else if (po < 0 && me == Tablero.ENROQUEC)
                {
                    PictureBox casillaTO = (PictureBox)Controls.Find("PbxCasilla77", true)[0];
                    PictureBox casillaTD = (PictureBox)Controls.Find("PbxCasilla" + (xd - 1) + "" + yd, true)[0];

                    casillaTD.Image = casillaTO.Image;
                    casillaTO.Image = null;
                }

                // Movimiento ENROQUEL blancas
                else if (po > 0 && me == Tablero.ENROQUEL)
                {
                    PictureBox casillaTO = (PictureBox)Controls.Find("PbxCasilla00", true)[0];
                    PictureBox casillaTD = (PictureBox)Controls.Find("PbxCasilla" + (xd + 1) + "" + yd, true)[0];

                    casillaTD.Image = casillaTO.Image;
                    casillaTO.Image = null;
                }

                // Movimiento ENROQUEL negras
                else if (po < 0 && me == Tablero.ENROQUEL)
                {
                    PictureBox casillaTO = (PictureBox)Controls.Find("PbxCasilla07", true)[0];
                    PictureBox casillaTD = (PictureBox)Controls.Find("PbxCasilla" + (xd + 1) + "" + yd, true)[0];

                    casillaTD.Image = casillaTO.Image;
                    casillaTO.Image = null;
                }
                // Movimiento CORONA blancas
                else if (po > 0 && me == Tablero.CORONA)
                {
                    // Promocion
                    switch (pe)
                    {
                    case Pieza.IDDAMAB:
                        casillaD.Image = UAChess.Properties.Resources.PzDamaB;
                        break;

                    case Pieza.IDTORREB:
                        casillaD.Image = UAChess.Properties.Resources.PzTorreB;
                        break;

                    case Pieza.IDALFILB:
                        casillaD.Image = UAChess.Properties.Resources.PzAlfilB;
                        break;

                    case Pieza.IDCABALLOB:
                        casillaD.Image = UAChess.Properties.Resources.PzCaballoB;
                        break;
                    }
                }
                // Movimiento CORONA negras
                else if (po < 0 && me == Tablero.CORONA)
                {
                    // Promocion
                    switch (pe)
                    {
                    case Pieza.IDDAMAN:
                        casillaD.Image = UAChess.Properties.Resources.PzDamaN;
                        break;

                    case Pieza.IDTORREN:
                        casillaD.Image = UAChess.Properties.Resources.PzTorreN;
                        break;

                    case Pieza.IDALFILN:
                        casillaO.Image = UAChess.Properties.Resources.PzAlfilN;
                        break;

                    case Pieza.IDCABALLON:
                        casillaO.Image = UAChess.Properties.Resources.PzCaballoN;
                        break;
                    }
                }

                // Marcar movimiento
                casillaO.BackColor = Color.LightGreen;
                casillaD.BackColor = Color.LightGreen;

                // Detalles
                ArrayList partida = Program.bbdd.ConsultaObtenerPartidas(items.SelectedItems[0].SubItems[4].Text, items.SelectedItems[0].SubItems[5].Text);

                LblDEvento.Text    = partida[2].ToString();
                LblDLugar.Text     = partida[3].ToString();
                LblDBlancas.Text   = partida[6].ToString() + " [" + partida[7].ToString() + "]";
                LblDNegras.Text    = partida[8].ToString() + " [" + partida[9].ToString() + "]";
                LblDResultado.Text = partida[10].ToString();
            }
        }