Ejemplo n.º 1
0
        internal MessageItem(Message message, int index, AssetLoader loader)
            : base(loader)
        {
            BinaryReader reader = loader.Reader;

            Message = message;
            Index   = index;

            switch (message.MajorVersion)
            {
            case 3:
                Noun      = reader.ReadByte();
                Verb      = reader.ReadByte();
                Condition = reader.ReadByte();
                Sequence  = reader.ReadByte();
                Talker    = reader.ReadByte();
                Offset    = reader.ReadUInt16();
                Unknowns.ReadBytes(reader, 3);
                break;

            case 4:
            case 5:
                Noun      = reader.ReadByte();
                Verb      = reader.ReadByte();
                Condition = reader.ReadByte();
                Sequence  = reader.ReadByte();
                Talker    = reader.ReadByte();
                Offset    = reader.ReadUInt16();
                Unknowns.ReadBytes(reader, 4);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 2
0
        internal Palette(AssetLoader loader)
            : base(loader)
        {
            BinaryReader reader = loader.Reader;

            Unknowns.ReadBytes(reader, 25);            // Offset 0-24
            int firstIndex = reader.ReadByte();        // Offset 25-25

            Unknowns.ReadBytes(reader, 3);             // Offset 26-28
            int count = reader.ReadUInt16();           // Offset 29-30

            Unknowns.ReadBytes(reader, 1);             // Offset 31-31
            byte format = reader.ReadByte();           // Offset 32-32

            Unknowns.ReadBytes(reader, 4);             // Offset 33-36
            // Offset 37

            PaletteColor[] colors = new PaletteColor[count];
            Colors     = new ReadOnlyCollection <PaletteColor>(colors);
            FlatColors = new Codex <Color>(256);
            for (int index = 0; index < firstIndex; index++)
            {
                FlatColors.Add(Color.Purple);
            }
            for (int index = 0; index < count; index++)
            {
                PaletteColor color;

                switch (format)
                {
                case 0:                         // Variable (byte used, byte red, byte green, byte blue)
                    color = new PaletteColor(reader.ReadByte() != 0, reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
                    break;

                case 1:                         // Constant (byte red, byte green, byte blue)
                    color = new PaletteColor(reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
                    break;

                default:
                    throw new NotImplementedException();
                }

                colors[index] = color;
                FlatColors.Add(color);
            }

            PaletteAsset = new PaletteAsset(Manager, Name ?? "Palette", FlatColors);
        }
Ejemplo n.º 3
0
        internal void ReadAddOn(BinaryReader reader)
        {
            switch (Message.MajorVersion)
            {
            case 4:
                string value = reader.ReadStringz(Encoding.ASCII);
                if (!string.IsNullOrEmpty(value))
                {
                    Comment = value;
                }
                Unknowns.ReadBytes(reader, 6);
                break;

            case 5:
                Unknowns.ReadBytes(reader, 6);
                break;

            default:
                throw new NotImplementedException();
            }
        }
Ejemplo n.º 4
0
        internal void LoadHeaders(AssetLoader loader)
        {
            BinaryReader reader = loader.Reader;

            reader.BaseStream.Position = HeaderOffset;
            Unknowns.ReadBytes(reader, 447);
            byte[] encryptedTitleKey = reader.ReadBytes(16);
            Unknowns.ReadBytes(reader, 13);
            byte[] titleId = reader.ReadBytes(16);
            Unknowns.ReadBytes(reader, 204);
            DataOffset = reader.ReadUInt32() * 4L + HeaderOffset;
            DataLength = reader.ReadUInt32() * 4L;

            byte[] keyIv = new byte[16];
            titleId.CopyTo(0, 8, keyIv, 0);

            ICryptoTransform keyDecryptor = Cypher.CreateDecryptor(MasterKey, keyIv);

            Key = keyDecryptor.TransformFinalBlock(encryptedTitleKey, 0, encryptedTitleKey.Length);

            LoadFileTable(this, OpenReader(), NintendoOpticalDiscSystem.Wii);
            SortChildrenRecursively();
        }
Ejemplo n.º 5
0
        internal NintendoOpticalDisc(AssetLoader loader)
            : base(loader)
        {
            BinaryReader reader;

            int magic = loader.Reader.ReadInt32();

            loader.Reader.BaseStream.Seek(-4, SeekOrigin.Current);
            if (magic == DolphinCompressedDisc.Magic)
            {
                var disc   = new DolphinCompressedDisc(loader.Reader);
                var stream = new DolphinCompressedDiscStream(disc);
                loader.Reader = new BigEndianBinaryReader(stream);
            }
            else
            {
                loader.MakeBigEndian();
            }

            reader = Reader = loader.Reader;

            DiscId               = (NintendoOpticalDiscId)reader.ReadByte();
            DiscGame             = (NintendoOpticalDiscGame)reader.ReadInt16();
            DiscRegion           = (NintendoOpticalDiscRegion)reader.ReadByte();
            DiscMaker            = (NintendoOpticalDiscMaker)reader.ReadInt16();
            DiscNumber           = reader.ReadByte();
            DiscVersion          = reader.ReadByte();
            DiscAudioStreaming   = reader.ReadByte();
            DiscStreamBufferSize = reader.ReadByte();
            Unknowns.ReadBytes(reader, 14);
            int wiiMagic      = reader.ReadInt32();
            int gameCubeMagic = reader.ReadInt32();

            if (wiiMagic == (int)NintendoOpticalDiscSystem.Wii)
            {
                DiscSystem = NintendoOpticalDiscSystem.Wii;
            }
            else if (gameCubeMagic == (int)NintendoOpticalDiscSystem.GameCube)
            {
                DiscSystem = Wii.NintendoOpticalDiscSystem.GameCube;
            }
            else
            {
                throw new InvalidDataException();
            }

            DiscTitle = reader.ReadStringz(64, Encoding.ASCII);

            if (DiscSystem == Wii.NintendoOpticalDiscSystem.GameCube)
            {
                NintendoOpticalDiscPartition.LoadFileTable(this, reader, DiscSystem);
            }
            else
            {
                reader.BaseStream.Position = VolumeTableOffset;
                for (int volumeIndex = 0; volumeIndex < 4; volumeIndex++)
                {
                    int  partitionCount       = reader.ReadInt32();
                    long partitionTableOffset = reader.ReadUInt32() * 4L;

                    if (partitionCount > 0)
                    {
                        new NintendoOpticalDiscVolume(this, volumeIndex, partitionCount, partitionTableOffset);
                    }
                }

                foreach (NintendoOpticalDiscVolume volume in Children)
                {
                    volume.LoadPartitions(loader);
                }
                foreach (NintendoOpticalDiscVolume volume in Children)
                {
                    foreach (NintendoOpticalDiscPartition partition in volume.Children)
                    {
                        partition.LoadHeaders(loader);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        internal Image(AssetManager manager, BinaryReader reader, string name, Asset context)
            : base(manager, name)
        {
            using (reader) {
                int height = reader.ReadByte();
                int width  = reader.ReadByte() * 8;
                reader.RequireZeroes(4);
                int frameCount = reader.ReadUInt16();
                if (frameCount == 0)
                {
                    throw new InvalidDataException();
                }

                byte baseColorIndex = reader.ReadByte();
                int  colorCount     = reader.ReadByte() + 1;

                // Need to initialize palette.
                Color[] colors = new Color[256];

                for (int index = 0; index < 16; index++)
                {
                    colors[index] = Raster.DefaultEgaColors[index];
                }

                for (int index = 0; index < colorCount; index++)
                {
                    colors[index + baseColorIndex] = Color.FromArgb(reader.ReadByte() * 255 / 63, reader.ReadByte() * 255 / 63, reader.ReadByte() * 255 / 63);
                }

                PaletteAsset palette = new PaletteAsset(Manager, Name + " palette", colors);

                Unknowns.ReadBytes(reader, (colorCount + 1) / 2);                 // EGA color map, two colours per byte.
                Unknowns.ReadBytes(reader, 4);

                int remaining = checked ((int)(reader.BaseStream.Length - reader.BaseStream.Position));

                if (remaining == width * height * frameCount + 28)
                {
                    Unknowns.ReadBytes(reader, 28);
                    remaining -= 28;
                }

                if (remaining != width * height * frameCount || (height != 0 && remaining % height != 0))
                {
                    throw new InvalidDataException("Expected file length is not correct.");
                }

                int[] indices = new int[width * height];

                if (width == 0 || height == 0)
                {
                    AddChild(palette);
                }
                else
                {
                    for (int index = 0; index < frameCount; index++)
                    {
                        reader.ReadBytesAsInt32(indices, 0, indices.Length);
                        var resource = new IndexedTextureAsset(Manager, "Frame " + index, palette, width, height, indices);
                        AddChild(resource);
                    }
                }

                // Hack for "over.dax" files to use their multiple palettes.
                if (context is ArchiveRecord && ((ArchiveRecord)context).Id >= 51 && string.Equals(Path.GetFileName(context.Parent.Name), "over.dax", StringComparison.InvariantCultureIgnoreCase))
                {
                    Archive archive = (Archive)context.Parent;

                    for (int id = 1; id <= 4; id++)
                    {
                        palette = (PaletteAsset)archive.RecordsById[id].Contents.Children[0];
                        var frame = new IndexedTextureAsset(Manager, "Palette " + id, palette, width, height, indices);
                        AddChild(frame);
                    }
                }
            }
        }