コード例 #1
0
        /// <summary>
        /// Ucitavamo save iz zadane putanje
        /// </summary>
        /// <param name="path">Putanja do save filea</param>
        private void LoadSaveFile(string path)
        {
            this.player           = new Player();
            this.playerBag        = new PlayerBag(pokemonVersion);
            this.pokemonStorage   = new PokemonStorage();
            this.pokedex          = new Pokedex();
            this.pokemonSave      = new PokemonSave(path);
            isReady               = false;
            uxNationalDex.Checked = false;

            //File je ucitan i spreman za obradu
            if (pokemonSave.isLoaded)
            {
                using (MemoryStream tempSave = new MemoryStream(pokemonSave.saveBank))
                {
                    using (BinaryReader br = new BinaryReader(tempSave))
                    {
                        // Za svaki slucaj postavit na pocetak
                        br.BaseStream.Seek(0, SeekOrigin.Begin);
                        #region Player
                        //Name
                        player.Name = br.ReadBytes(7);
                        //Gender
                        br.BaseStream.Seek(PokemonConstants.playerGenderOffset, SeekOrigin.Begin);
                        player.Gender = br.ReadByte();
                        //TrainerID
                        br.BaseStream.Seek(PokemonConstants.playerTrainerIDOffset, SeekOrigin.Begin);
                        player.TrainerID = br.ReadUInt32();

                        //EncryptionKey
                        if (pokemonVersion == PokemonVersion.Emerald)
                        {
                            br.BaseStream.Seek(PokemonConstants.playerEncryptionKeyOffset, SeekOrigin.Begin);
                            player.EncryptionKey = br.ReadUInt32();
                        }
                        else if (pokemonVersion == PokemonVersion.FireRedAndLeafGreen)
                        {
                            br.BaseStream.Seek(PokemonConstants.playerEncryptionKeyOffsetFireLeaf, SeekOrigin.Begin);
                            player.EncryptionKey = br.ReadUInt32();
                        }
                        else //Ruby, Sapphire
                        {
                            player.EncryptionKey = 0;
                        }
                        //Money and Coins
                        if (pokemonVersion == PokemonVersion.FireRedAndLeafGreen)
                        {
                            //Money
                            br.BaseStream.Seek(PokemonConstants.playerMoneyOffsetFireLeaf, SeekOrigin.Begin);
                            player.Money = br.ReadUInt32();
                            //Coins
                            br.BaseStream.Seek(PokemonConstants.playerCoinsOffsetFireLeaf, SeekOrigin.Begin);
                            player.Coins = br.ReadUInt16();
                        }
                        else //Emerald , Ruby, Sapphire
                        {
                            //Money
                            br.BaseStream.Seek(PokemonConstants.playerMoneyOffset, SeekOrigin.Begin);
                            player.Money = br.ReadUInt32();
                            //Coins
                            br.BaseStream.Seek(PokemonConstants.playerCoinsOffset, SeekOrigin.Begin);
                            player.Coins = br.ReadUInt16();
                        }

                        #endregion
                        #region Items - Bag
                        //Bag
                        if (pokemonVersion == PokemonVersion.FireRedAndLeafGreen)
                        {
                            br.BaseStream.Seek(PokemonConstants.bagOffsetFireLeaf, SeekOrigin.Begin);
                            playerBag.Load(br.ReadBytes(PokemonConstants.bagSizeinBytes));
                        }
                        else if (pokemonVersion == PokemonVersion.RubyAndSapphire)
                        {
                            br.BaseStream.Seek(PokemonConstants.bagOffset, SeekOrigin.Begin);
                            playerBag.Load(br.ReadBytes(PokemonConstants.bagSizeinBytesRubySapphire));
                        }
                        else//Emerald
                        {
                            br.BaseStream.Seek(PokemonConstants.bagOffset, SeekOrigin.Begin);
                            playerBag.Load(br.ReadBytes(PokemonConstants.bagSizeinBytes));
                        }
                        #endregion
                        //Pokemon Storage
                        br.BaseStream.Seek(PokemonConstants.pokemonStorageOffset, SeekOrigin.Begin);
                        pokemonStorage.Load(br.ReadBytes(PokemonConstants.pokemonStorageSize));

                        #region Pokedex
                        //Own
                        br.BaseStream.Seek(PokemonConstants.pokedexOwnOffset, SeekOrigin.Begin);
                        pokedex.LoadOwn(br.ReadBytes(49));
                        //Seen
                        br.BaseStream.Seek(PokemonConstants.pokedexSeenOffset, SeekOrigin.Begin);
                        pokedex.LoadSeen(br.ReadBytes(49));
                        #endregion
                    }
                }//end memory stream
                //Postavljamo enkripcijski kljuc u Items
                Item.EncryptionKey = player.EncryptionKeySmall;
                isReady            = true;
            }//end if
        }