コード例 #1
0
        /// <summary>
        /// <para>Replaces current sound effect with a new one</para>
        ///
        /// Throws InvalidOperationException if current sound cannot be replaced
        /// </summary>
        public static void ReplaceWith(this SoundEffect source, SoundEffect newSound)
        {
            if (!source.IsReplacable())
            {
                throw new InvalidOperationException($"Sound effect {source} is not replacable!");
            }

            var replacableAttribute = source.GetAttribute <ReplacableAttribute>();
            var addresses           = replacableAttribute.Addresses;

            var newValue = (ushort)newSound;

            var effect = source.GetAttribute <EffectAttribute>();

            if (effect != null)
            {
                newValue = (ushort)((effect.Flags & 0x0E00) | (newValue & 0xF1FF));
            }
            else
            {
                newValue = (ushort)(newSound + DefaultSoundEffectFlags);
            }

            foreach (var address in addresses)
            {
                ReadWriteUtils.WriteToROM(address, newValue);
            }
        }