/// <summary>
        /// Serializes an encrypted string for OpenSpace games
        /// </summary>
        /// <param name="s">The serializer</param>
        /// <param name="value">The string value</param>
        /// <param name="xorKey">The xor key to use</param>
        /// <param name="name">The string value name, for logging</param>
        /// <returns>The string value</returns>
        public static string SerializeOpenSpaceEncryptedString(this IBinarySerializer s, string value, byte xorKey, string name = null)
        {
            // Serialize the length
            var length = s.Serialize <int>(value?.Length ?? 0, name: $"{nameof(value)}.Length");

            // Serialize the string value using the xor key
            s.DoXOR(xorKey, () => value = s.SerializeString(value, length, name: $"{nameof(value)}"));

            // Return the value
            return(value);
        }
예제 #2
0
        /// <summary>
        /// Handles the serialization using the specified serializer
        /// </summary>
        /// <param name="s">The serializer</param>
        public void Serialize(IBinarySerializer s)
        {
            // Get the settings
            var settings = s.GetSettings <Ray1Settings>();

            if (settings.Game == Ray1Game.Rayman1)
            {
                FileOffset = s.Serialize <uint>(FileOffset, name: nameof(FileOffset));
                FileSize   = s.Serialize <uint>(FileSize, name: nameof(FileSize));
                XORKey     = s.Serialize <byte>(XORKey, name: nameof(XORKey));
                Checksum   = s.Serialize <byte>(Checksum, name: nameof(Checksum));

                s.SerializeArray <byte>(new byte[2], 2, name: "Padding");
            }
            else
            {
                XORKey     = s.Serialize <byte>(XORKey, name: nameof(XORKey));
                Checksum   = s.Serialize <byte>(Checksum, name: nameof(Checksum));
                FileOffset = s.Serialize <uint>(FileOffset, name: nameof(FileOffset));
                FileSize   = s.Serialize <uint>(FileSize, name: nameof(FileSize));

                s.DoXOR(XORKey, () => FileName = s.SerializeString(FileName, 9, name: nameof(FileName)));
            }
        }