Ejemplo n.º 1
0
        public List <Objectives> ObtenerObjectivesPartidaGuardada(int PosicionObjectives, string PrefijoObjectives, string RtuaPartidaGuardada)
        {
            //Crear lector.
            Lector = new BinaryReaderBigEndian(new FileStream(RtuaPartidaGuardada, FileMode.Open, FileAccess.Read));

            //Crear Lista
            List <Objectives> ObjectivesEncontrados = new List <Objectives>();

            //Variables importantes.
            int  NumeroInventario, Contador = 0;
            uint DatosLeidos;

            //Ir a la sección donde están los objectives.
            Lector.BaseStream.Seek(unchecked ((int)PosicionObjectives), SeekOrigin.Begin);

            //Número de objectives que hay.
            NumeroInventario = checked ((int)SwapBytes(Lector.ReadUInt32()));

            //Buscar los objectives.
            while (Contador < NumeroInventario)
            {
                //Leer datos
                DatosLeidos = SwapBytes(Lector.ReadUInt32());

                //Comprobar si lo que ha leido es un objective.
                if (DatosLeidos.ToString("X4").StartsWith(PrefijoObjectives))
                {
                    if (DatosLeidos.ToString("X4").Length == 8)
                    {
                        ObjectivesEncontrados.Add(new Objectives {
                            ObjectiveNumHex = DatosLeidos.ToString("X4"), ValorObjective = int.Parse(SwapBytes(Lector.ReadUInt32()).ToString("X4"), System.Globalization.NumberStyles.HexNumber).ToString()
                        });
                        Contador++;
                    }
                }

                //Si son datos de relleno o se han hecho las 1700 iteraciones sale del bucle.
                if (DatosLeidos.ToString("X4").Equals("55555555") || Contador == 1700)
                {
                    break;
                }
            }
            Lector.Close();

            return(ObjectivesEncontrados);
        }