Exemplo n.º 1
0
 private void AlignMap(int lastTagOffset)
 {
     header.EndOfFile = lastTagOffset + tags[index.TagCount - 1].Size;
     header.EndOfFile = Alignment.Align(header.EndOfFile, AlignmentConstants.FileAlignment);
     map.SetLength(header.EndOfFile);
 }
Exemplo n.º 2
0
        public void WriteToMapStream(BinaryWriter writer, IList <string> strings, int magic)
        {
            int currentEnd;

            unchecked
            {
                magic     += (int)writer.BaseStream.Position;
                currentEnd = MetaRootSize + magic;
            }

            // tier 0
            writer.Write(playbackParameters.Count);
            writer.Write(currentEnd);
            currentEnd += playbackParameters.Count * Marshal.SizeOf(typeof(Playback));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            writer.Write(scales.Count);
            writer.Write(currentEnd);
            currentEnd += scales.Count * Marshal.SizeOf(typeof(Scale));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            writer.Write(importNames.Count);
            writer.Write(currentEnd);
            currentEnd += importNames.Count * Marshal.SizeOf(typeof(ImportName));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            writer.Write(pitchRangeParameters.Count);
            writer.Write(currentEnd);
            currentEnd += pitchRangeParameters.Count * Marshal.SizeOf(typeof(PitchRangeParametersBlock));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            writer.Write(pitchRanges.Count);
            writer.Write(currentEnd);
            currentEnd += pitchRanges.Count * Marshal.SizeOf(typeof(PitchRange));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            writer.Write(permutations.Count);
            writer.Write(currentEnd);
            currentEnd += permutations.Count * Marshal.SizeOf(typeof(Permutation));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            writer.Write(customPlaybacks.Count);
            writer.Write(currentEnd);
            currentEnd += customPlaybacks.Count * Marshal.SizeOf(typeof(CustomPlayback));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            writer.Write(runtimeFlags.Count);
            writer.Write(currentEnd);
            currentEnd += runtimeFlags.Count * Marshal.SizeOf(typeof(RuntimePermutationFlags));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            writer.Write(chunks.Count);
            writer.Write(currentEnd);
            currentEnd += chunks.Count * Marshal.SizeOf(typeof(Chunk));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            writer.Write(promotions.Count);
            writer.Write(currentEnd);
            currentEnd += promotions.Count * Marshal.SizeOf(typeof(Promotion));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            writer.Write(extraInfos.Count);
            writer.Write(currentEnd);
            currentEnd += extraInfos.Count * Marshal.SizeOf(typeof(ExtraInfo));
            currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);

            // tier 1
            for (int i = 0; i < playbackParameters.Count; i++)
            {
                writer.Write(Reinterpret.Object <Playback>(playbackParameters[i]));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            for (int i = 0; i < scales.Count; i++)
            {
                writer.Write(Reinterpret.Object <Scale>(scales[i]));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            for (int i = 0; i < importNames.Count; i++)
            {
                ImportName importName = new ImportName();
                short      index      = (short)strings.IndexOf(importNames[i]);
                if (index >= 0)
                {
                    importName.Index = index;
                    importName.Size  = (byte)importNames[i].Length;
                }
                writer.Write(Reinterpret.Object <ImportName>(importName));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            for (int i = 0; i < pitchRangeParameters.Count; i++)
            {
                writer.Write(Reinterpret.Object <PitchRangeParametersBlock>(pitchRangeParameters[i]));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            for (int i = 0; i < pitchRanges.Count; i++)
            {
                writer.Write(Reinterpret.Object <PitchRange>(pitchRanges[i]));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            for (int i = 0; i < permutations.Count; i++)
            {
                writer.Write(Reinterpret.Object <Permutation>(permutations[i]));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            for (int i = 0; i < customPlaybacks.Count; i++)
            {
                CustomPlayback customPlayback = customPlaybacks[i];

                if (customPlayback.FilterCount > 0)
                {
                    customPlayback.FilterOffset = currentEnd;
                    currentEnd += customPlayback.FilterCount * Marshal.SizeOf(typeof(CustomPlayback.Filter));
                    currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);
                }
                else
                {
                    customPlayback.FilterOffset = 0;
                }

                if (customPlayback.PitchPlaybackParametersCount > 0)
                {
                    customPlayback.PitchPlaybackParametersOffset = currentEnd;
                    currentEnd += customPlayback.PitchPlaybackParametersCount * Marshal.SizeOf(typeof(CustomPlayback.PitchPlaybackParameters));
                    currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);
                }
                else
                {
                    customPlayback.PitchPlaybackParametersOffset = 0;
                }

                writer.Write(Reinterpret.Object <CustomPlayback>(customPlayback));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            for (int i = 0; i < runtimeFlags.Count; i++)
            {
                writer.Write(Reinterpret.Object <RuntimePermutationFlags>(runtimeFlags[i]));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            for (int i = 0; i < chunks.Count; i++)
            {
                writer.Write(Reinterpret.Object <Chunk>(chunks[i]));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            for (int i = 0; i < promotions.Count; i++)
            {
                Promotion promotion = promotions[i];

                if (promotion.RuleCount > 0)
                {
                    promotion.RuleOffset = currentEnd;
                    currentEnd          += promotion.RuleCount * Marshal.SizeOf(typeof(Promotion.Rule));
                    currentEnd           = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);
                }
                else
                {
                    promotion.RuleOffset = 0;
                }

                if (promotion.TimerCount > 0)
                {
                    promotion.TimerOffset = currentEnd;
                    currentEnd           += promotion.TimerCount * Marshal.SizeOf(typeof(Promotion.Timer));
                    currentEnd            = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);
                }
                else
                {
                    promotion.TimerOffset = 0;
                }

                writer.Write(Reinterpret.Object <Promotion>(promotion));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            for (int i = 0; i < extraInfos.Count; i++)
            {
                ExtraInfo extraInfo = extraInfos[i];

                if (extraInfo.ResourceBlock.ResourceCount > 0)
                {
                    extraInfo.ResourceBlock.ResourceOffset = currentEnd;
                    currentEnd += extraInfo.ResourceBlock.ResourceCount * Marshal.SizeOf(typeof(ResourceBlock.Resource));
                    currentEnd  = Alignment.Align(currentEnd, AlignmentConstants.BlockAlignment);
                }
                else
                {
                    extraInfo.ResourceBlock.ResourceOffset = 0;
                }

                writer.Write(Reinterpret.Object <ExtraInfo>(extraInfo));
            }
            writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);

            // tier 2
            for (int i = 0; i < customPlaybacks.Count; i++)
            {
                for (int j = 0; j < customPlaybacks[i].FilterCount; j++)
                {
                    writer.Write(Reinterpret.Object <CustomPlayback.Filter>(customFilters[i][j]));
                }
                writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);
                for (int j = 0; j < customPlaybacks[i].PitchPlaybackParametersCount; j++)
                {
                    writer.Write(Reinterpret.Object <CustomPlayback.PitchPlaybackParameters>(customPitchParameters[i][j]));
                }
                writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);
            }

            for (int i = 0; i < promotions.Count; i++)
            {
                for (int j = 0; j < promotions[i].RuleCount; j++)
                {
                    writer.Write(Reinterpret.Object <Promotion.Rule>(promotionRules[i][j]));
                }
                writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);
                for (int j = 0; j < promotions[i].TimerCount; j++)
                {
                    writer.Write(Reinterpret.Object <Promotion.Timer>(promotionTimers[i][j]));
                }
                writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);
            }

            for (int i = 0; i < extraInfos.Count; i++)
            {
                for (int j = 0; j < extraInfos[i].ResourceBlock.ResourceCount; j++)
                {
                    writer.Write(Reinterpret.Object <ResourceBlock.Resource>(extraInfoResources[i][j]));
                }
                writer.BaseStream.Position = Alignment.Align((int)writer.BaseStream.Position, AlignmentConstants.BlockAlignment);
            }
        }