예제 #1
0
        /// <summary>
        /// Splits character data into several sections for easier parsing
        /// </summary>
        private void ReadHeaders(byte[] rawCharacterData)
        {
            if (rawCharacterData[0] != 0x55 || rawCharacterData[1] != 0xAA || rawCharacterData[2] != 0x55 || rawCharacterData[3] != 0xAA)
            {
                throw new Exception("Not a Diablo II Save file");
            }

            OriginalCharacterBytes = null;
            OriginalSkillBytes = null;
            OriginalInventoryBytes = null;

            byte[] statBytes = GetStatBytes(rawCharacterData);
            byte[] characterBytes = GetCharacterBytes(rawCharacterData);
            byte[] skillBytes = GetSkillBytes(rawCharacterData);
            byte[] inventoryBytes = GetInventoryBytes(rawCharacterData);

            inventory = new Inventory(inventoryBytes);
            character = new Character(characterBytes);
            stat = new Stat(statBytes);
            skill = new Skill(skillBytes);

            // Stats will always be different, we're not reading the fractional portion of hp/mana/stamina
            FailedCharacterDecoding = !characterBytes.SequenceEqual(character.GetCharacterBytes());
            FailedSkillDecoding = !skillBytes.SequenceEqual(skill.GetSkillBytes());
            FailedInventoryDecoding = !inventoryBytes.SequenceEqual(inventory.GetInventoryBytes(character.HasMercenary));

            if (FailedCharacterDecoding)
            {
                OriginalCharacterBytes = characterBytes;
            }
            if (FailedInventoryDecoding)
            {
                OriginalInventoryBytes = inventoryBytes;
            }
            if (FailedSkillDecoding)
            {
                OriginalSkillBytes = skillBytes;
            }
        }