Exemplo n.º 1
0
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog ofd = new OpenFileDialog();
                //ofd.Filter = "All files (*.*)|*.*";
                ofd.Filter = "MHX/Gen System File|system|All files (*.*)|*.*";
                ofd.FilterIndex = 1;

                if (ofd.ShowDialog() != DialogResult.OK)
                {
                    ofd.Dispose();
                    return;
                }

                //this.Text = ofd.SafeFileName;
                this.Text = string.Format("{0} [{1}]", Constants.EDITOR_VERSION, ofd.SafeFileName);
                filePath = ofd.FileName;
                dataExtractor = new DataExtractor(filePath);

                saveFile = dataExtractor.GetSaveFile();
                loadSave();

                ofd.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Loading Error");
                saveFile = null;
                clearForms();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Edit the FileData bytes to match the save file
        /// </summary>
        /// <param name="saveFile">The save file to save</param>
        public void SaveData(SaveFile saveFile)
        {
            BinaryWriter binaryWriter = new BinaryWriter((Stream)new MemoryStream(FileData));
            for (int index = 0; index < 3; index++)
            {
                if (FileData[Offsets.FIRST_CHAR_SLOT_USED + index] == 0)
                {
                    continue;
                }

                Player player = saveFile.Players[index];

                //General
                binaryWriter.BaseStream.Seek(player.SaveOffset, SeekOrigin.Begin);
                byte[] nameBuff = new byte[Constants.SIZEOF_NAME];
                Encoding.UTF8.GetBytes(player.Name, 0, player.Name.Length, nameBuff, 0);
                binaryWriter.Write(nameBuff);
                binaryWriter.Write(player.PlayTime);
                binaryWriter.Write(player.Funds);
                binaryWriter.Write(player.HunterRank);
                binaryWriter.BaseStream.Seek(2, SeekOrigin.Current); //Skip 2
                binaryWriter.Write(player.HunterArt1);
                binaryWriter.Write(player.HunterArt2);
                binaryWriter.Write(player.HunterArt3);

                //Stored Name
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.STORED_NAME_OFFSET, SeekOrigin.Begin);
                binaryWriter.Write(nameBuff);

                //Stored Play Time
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.STORED_PLAY_TIME_OFFSET, SeekOrigin.Begin);
                binaryWriter.Write(player.PlayTime);

                //Player Details
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.CHARACTER_VOICE_OFFSET, SeekOrigin.Begin);
                binaryWriter.Write(player.Voice);
                binaryWriter.Write(player.EyeColor);
                binaryWriter.Write(player.Clothing);
                binaryWriter.Write(player.Gender);
                binaryWriter.Write(player.HuntingStyle);
                binaryWriter.Write(player.HairStyle);
                binaryWriter.Write(player.Face);
                binaryWriter.Write(player.Features);

                //Player Colors
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.CHARACTER_SKIN_COLOR_OFFSET, SeekOrigin.Begin);
                binaryWriter.Write(player.SkinColorRGBA);
                binaryWriter.Write(player.HairColorRGBA);
                binaryWriter.Write(player.FeaturesColorRGBA);
                binaryWriter.Write(player.ClothingColorRGBA);

                //Points
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.HR_POINTS_OFFSET, SeekOrigin.Begin);
                binaryWriter.Write(player.HRPoints);
                binaryWriter.Write(player.Zenny);
                binaryWriter.BaseStream.Seek(4, SeekOrigin.Current); //Skip 4 unknown
                binaryWriter.Write(player.AcademyPoints);
                binaryWriter.Write(player.BerunaPoints);
                binaryWriter.Write(player.KokotoPoints);
                binaryWriter.Write(player.PokkePoints);
                binaryWriter.Write(player.YukumoPoints);

                //Item Box
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.ITEM_BOX_OFFSET, SeekOrigin.Begin);
                byte[] itemBoxBytes = PackItems(player.ItemBox);
                binaryWriter.Write(itemBoxBytes);

                //Item Pouch
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.POUCH_OFFSET, SeekOrigin.Begin);
                byte[] itemPouchBytes = PackItems(player.ItemPouch);
                binaryWriter.Write(itemPouchBytes);

                //Equipment
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.EQUIPMENT_BOX_OFFSET, SeekOrigin.Begin);
                for (int equipmentIndex = 0; equipmentIndex < Constants.TOTAL_ITEM_BOX_SLOTS; equipmentIndex++)
                {
                    binaryWriter.Write(player.EquipmentBox[equipmentIndex].EquipmentBytes);
                }

                //Palicos
                for (int pIndex = 0; pIndex < Constants.TOTAL_PALICOS; pIndex++)
                {
                    binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.PALICO_OFFSET + (pIndex * Constants.SIZEOF_PALICO), SeekOrigin.Begin);
                    binaryWriter.Write(PackPalico(player.Palicos[pIndex]));
                }

                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.PALICO_EQUIPMENT_OFFSET, SeekOrigin.Begin);
                for (int i = 0; i < Constants.TOTAL_PALICO_EQUIPMENT_SLOTS; i++)
                {
                    binaryWriter.Write(player.PalicoEquipment[i].EquipmentBytes);
                }

                //Guild Card
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.PLAYER_GUILD_CARD_OFFSET, SeekOrigin.Begin);
                binaryWriter.Write(player.PlayerGuildCard.GuildCardData);

                //Shops
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.CRAFTABLE_ARMOR_SHOP_OFFSET, SeekOrigin.Begin);
                for (int i = 0; i < Constants.TOTAL_CRAFTABLE_ARMOR_SHOPS; i++)
                {
                    binaryWriter.Write(player.CraftableArmorShops[i].ShopData);
                }

                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.CRAFTABLE_WEAPONS_OFFSET, SeekOrigin.Begin);
                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.
                    {
                        binaryWriter.Seek(40, SeekOrigin.Current);
                        continue;
                    }
                    binaryWriter.Write(player.CraftableWeaponShops[weaponIndex].ShopData);
                    weaponIndex++;
                }

                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.CRAFTABLE_PALICO_GEAR_OFFSET, SeekOrigin.Begin);
                for (int i = 0; i < Constants.TOTAL_CRAFTABLE_PALICO_SHOPS; i++)
                {
                    binaryWriter.Write(player.CraftablePalicoShops[i].ShopData);
                }

                //Unlocked Box Data
                binaryWriter.BaseStream.Seek(player.SaveOffset + Offsets.UNLOCKED_BOXES_OFFSET, SeekOrigin.Begin);
                binaryWriter.Write(player.UnlockedBoxData);
            }
        }