public SaveFile(Player[] players) { this.Players = players; }
/// <summary> /// Get a save file from the FileData bytes /// </summary> /// <returns>A save file object from the file given</returns> public SaveFile GetSaveFile() { Player[] players = new Player[3]; BinaryReader binaryReader = new BinaryReader((Stream) new MemoryStream(FileData)); for (int index = 0; index < 3; index++) { Player player = new Player(); if (FileData[Offsets.FIRST_CHAR_SLOT_USED + index] == 0) { players[index] = null; continue; } //Player Base Offset binaryReader.BaseStream.Seek(Offsets.FIRST_CHARACTER_OFFSET + (index * 4), SeekOrigin.Begin); player.SaveOffset = binaryReader.ReadUInt32(); //Player General binaryReader.BaseStream.Seek(player.SaveOffset, SeekOrigin.Begin); //player.Name = Encoding.UTF8.GetString(binaryReader.ReadBytes(32), 0, 32); //Loading Screen. Might have problem when you save as prowler binaryReader.ReadBytes(32); //Skips first 32 bytes player.PlayTime = binaryReader.ReadUInt32(); player.Funds = binaryReader.ReadInt32(); //How much money is on loading screen player.HunterRank = binaryReader.ReadUInt16(); binaryReader.ReadUInt16(); //Skip 2 1-byte unknowns player.HunterArt1 = binaryReader.ReadUInt16(); player.HunterArt2 = binaryReader.ReadUInt16(); player.HunterArt3 = binaryReader.ReadUInt16(); binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.STORED_NAME_OFFSET, SeekOrigin.Begin); player.Name = Encoding.UTF8.GetString(binaryReader.ReadBytes(32), 0, 32); //Player Details binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.CHARACTER_VOICE_OFFSET, SeekOrigin.Begin); player.Voice = binaryReader.ReadByte(); player.EyeColor = binaryReader.ReadByte(); player.Clothing = binaryReader.ReadByte(); player.Gender = binaryReader.ReadByte(); player.HuntingStyle = binaryReader.ReadByte(); player.HairStyle = binaryReader.ReadByte(); player.Face = binaryReader.ReadByte(); player.Features = binaryReader.ReadByte(); //Player Colors binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.CHARACTER_SKIN_COLOR_OFFSET, SeekOrigin.Begin); player.SkinColorRGBA = binaryReader.ReadBytes(4); player.HairColorRGBA = binaryReader.ReadBytes(4); player.FeaturesColorRGBA = binaryReader.ReadBytes(4); player.ClothingColorRGBA = binaryReader.ReadBytes(4); //Points binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.HR_POINTS_OFFSET, SeekOrigin.Begin); player.HRPoints = binaryReader.ReadInt32(); player.Zenny = binaryReader.ReadInt32(); binaryReader.ReadInt32(); //Skip 4-byte unkown player.AcademyPoints = binaryReader.ReadInt32(); player.BerunaPoints = binaryReader.ReadInt32(); player.KokotoPoints = binaryReader.ReadInt32(); player.PokkePoints = binaryReader.ReadInt32(); player.YukumoPoints = binaryReader.ReadInt32(); //Item Box binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.ITEM_BOX_OFFSET, SeekOrigin.Begin); byte[] itemBoxBytes = binaryReader.ReadBytes(Constants.SIZEOF_ITEMBOX); player.ItemBox = GetItems(itemBoxBytes); //Pouch binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.POUCH_OFFSET, SeekOrigin.Begin); byte[] itemPouchBytes = binaryReader.ReadBytes(Constants.SIZEOF_ITEMPOUCH); player.ItemPouch = GetItems(itemPouchBytes); //Equipment binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.EQUIPMENT_BOX_OFFSET, SeekOrigin.Begin); player.EquipmentBox = new Equipment[Constants.TOTAL_ITEM_BOX_SLOTS]; for (int equipmentIndex = 0; equipmentIndex < Constants.TOTAL_ITEM_BOX_SLOTS; equipmentIndex++) { player.EquipmentBox[equipmentIndex] = new Equipment(binaryReader.ReadBytes(Constants.SIZEOF_EQUIPMENT)); } //Palicos player.Palicos = new Palico[Constants.TOTAL_PALICOS]; for(int pIndex = 0; pIndex < Constants.TOTAL_PALICOS; pIndex++) { binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.PALICO_OFFSET + (pIndex * Constants.SIZEOF_PALICO), SeekOrigin.Begin); player.Palicos[pIndex] = GetPalcio(binaryReader.ReadBytes(Constants.SIZEOF_PALICO)); } //Palico Equipment binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.PALICO_EQUIPMENT_OFFSET, SeekOrigin.Begin); player.PalicoEquipment = new Equipment[Constants.TOTAL_PALICO_EQUIPMENT_SLOTS]; for (int i = 0; i < Constants.TOTAL_PALICO_EQUIPMENT_SLOTS; i++) { player.PalicoEquipment[i] = new Equipment(binaryReader.ReadBytes(Constants.SIZEOF_EQUIPMENT)); } binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.PLAYER_GUILD_CARD_OFFSET, SeekOrigin.Begin); player.PlayerGuildCard = new GuildCard(binaryReader.ReadBytes(Constants.SIZEOF_GUILD_CARD)); //Shops binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.CRAFTABLE_ARMOR_SHOP_OFFSET, SeekOrigin.Begin); player.CraftableArmorShops = new Shop[Constants.TOTAL_CRAFTABLE_ARMOR_SHOPS]; for (int i = 0; i < Constants.TOTAL_CRAFTABLE_ARMOR_SHOPS; i++) { player.CraftableArmorShops[i] = new Shop(binaryReader.ReadBytes(Constants.SIZEOF_CRAFTABLE_ARMOR)); } binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.CRAFTABLE_WEAPONS_OFFSET, SeekOrigin.Begin); player.CraftableWeaponShops = new Shop[Constants.TOTAL_CRAFTABLE_WEAPON_SHOPS]; int weaponIndex = 0; for (int i = 0; i < 15; i++) { if (i == 5) //Skip the medium bow gun. I dont even know why capcom has this. { binaryReader.ReadBytes(Constants.SIZEOF_CRAFTABLE_WEAPON); continue; } player.CraftableWeaponShops[weaponIndex] = new Shop(binaryReader.ReadBytes(Constants.SIZEOF_CRAFTABLE_WEAPON)); weaponIndex++; } binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.CRAFTABLE_PALICO_GEAR_OFFSET, SeekOrigin.Begin); player.CraftablePalicoShops = new Shop[Constants.TOTAL_CRAFTABLE_PALICO_SHOPS]; for (int i = 0; i < Constants.TOTAL_CRAFTABLE_PALICO_SHOPS; i++) { player.CraftablePalicoShops[i] = new Shop(binaryReader.ReadBytes(Constants.SIZEOF_CRAFTABLE_PALICO_GEAR)); } //Unlocked Box Data binaryReader.BaseStream.Seek(player.SaveOffset + Offsets.UNLOCKED_BOXES_OFFSET, SeekOrigin.Begin); player.UnlockedBoxData = binaryReader.ReadBytes(8); players[index] = player; } return new SaveFile(players); }