Пример #1
0
        protected void SerializeTileMap(SerializerObject s)
        {
            switch (StructType)
            {
            case Type.Layer2D:
            case Type.SplinterCellZoom:
            case Type.PoP:
                MapData = s.SerializeObjectArray <MapTile>(MapData, Width * Height, onPreSerialize: m => {
                    if (!UsesTileKitDirectly)
                    {
                        if (TileKitIndex == 1)
                        {
                            m.GBATileType = MapTile.GBA_TileType.FGTile;
                        }
                        else
                        {
                            m.GBATileType = MapTile.GBA_TileType.BGTile;
                        }
                    }
                    m.Is8Bpp = ColorMode == GBA_ColorMode.Color8bpp;
                }, name: nameof(MapData));
                break;

            case Type.RotscaleLayerMode7:
                Mode7Data = s.SerializeArray <byte>(Mode7Data, Width * Height, name: nameof(Mode7Data));
                break;

            case Type.Collision:
                CollisionData = s.SerializeArray <GBA_TileCollisionType>(CollisionData, Width * Height, name: nameof(CollisionData));
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            InstrumentSize = s.Serialize <uint>(InstrumentSize, name: nameof(InstrumentSize));
            InstrumentName = s.SerializeString(InstrumentName, 22, Encoding.ASCII, name: nameof(InstrumentName));
            InstrumentType = s.Serialize <byte>(InstrumentType, name: nameof(InstrumentType));
            NumSamples     = s.Serialize <ushort>(NumSamples, name: nameof(NumSamples));
            if (NumSamples > 0)
            {
                SampleHeaderSize         = s.Serialize <uint>(SampleHeaderSize, name: nameof(SampleHeaderSize));
                SampleKeymapAssignments  = s.SerializeArray <byte>(SampleKeymapAssignments, 96, name: nameof(SampleKeymapAssignments));
                PointsForVolumeEnvelope  = s.SerializeArray <ushort>(PointsForVolumeEnvelope, 24, name: nameof(PointsForVolumeEnvelope));
                PointsForPanningEnvelope = s.SerializeArray <ushort>(PointsForPanningEnvelope, 24, name: nameof(PointsForPanningEnvelope));

                NumVolumePoints       = s.Serialize <byte>(NumVolumePoints, name: nameof(NumVolumePoints));
                NumPanningPoints      = s.Serialize <byte>(NumPanningPoints, name: nameof(NumPanningPoints));
                VolumeSustainPoint    = s.Serialize <byte>(VolumeSustainPoint, name: nameof(VolumeSustainPoint));
                VolumeLoopStartPoint  = s.Serialize <byte>(VolumeLoopStartPoint, name: nameof(VolumeLoopStartPoint));
                VolumeLoopEndPoint    = s.Serialize <byte>(VolumeLoopEndPoint, name: nameof(VolumeLoopEndPoint));
                PanningSustainPoint   = s.Serialize <byte>(PanningSustainPoint, name: nameof(PanningSustainPoint));
                PanningLoopStartPoint = s.Serialize <byte>(PanningLoopStartPoint, name: nameof(PanningLoopStartPoint));
                PanningLoopEndPoint   = s.Serialize <byte>(PanningLoopEndPoint, name: nameof(PanningLoopEndPoint));
                VolumeType            = s.Serialize <byte>(VolumeType, name: nameof(VolumeType));
                PanningType           = s.Serialize <byte>(PanningType, name: nameof(PanningType));
                VibratoType           = s.Serialize <byte>(VibratoType, name: nameof(VibratoType));
                VibratoSweep          = s.Serialize <byte>(VibratoSweep, name: nameof(VibratoSweep));
                VibratoDepth          = s.Serialize <byte>(VibratoDepth, name: nameof(VibratoDepth));
                VibratoRate           = s.Serialize <byte>(VibratoRate, name: nameof(VibratoRate));
                VolumeFadeout         = s.Serialize <ushort>(VolumeFadeout, name: nameof(VolumeFadeout));
                Reserved = s.SerializeArray <byte>(Reserved, 2, name: nameof(Reserved));

                Samples = s.SerializeObjectArray <XM_Sample>(Samples, NumSamples, name: nameof(Samples));
            }
        }
Пример #3
0
        public override void SerializeBlock(SerializerObject s)
        {
            if (DependencyTable.DependenciesCount > 0)
            {
                if (Vignettes == null)
                {
                    Vignettes = new GBC_Vignette[DependencyTable.DependenciesCount];
                }

                for (int i = 0; i < Vignettes.Length; i++)
                {
                    Vignettes[i] = s.DoAt(DependencyTable.GetPointer(i), () => s.SerializeObject <GBC_Vignette>(Vignettes[i], name: $"{nameof(Vignettes)}[{i}]"));
                }
            }
            else
            {
                // Serialize data
                Width      = s.Serialize <byte>(Width, name: nameof(Width));
                Height     = s.Serialize <byte>(Height, name: nameof(Height));
                UnkData    = s.SerializeArray <byte>(UnkData, 14, name: nameof(UnkData));
                Palette    = s.SerializeObjectArray <RGBA5551Color>(Palette, 4 * 8, name: nameof(Palette));
                TileSet    = s.SerializeArray <byte>(TileSet, Width * Height * 0x10, name: nameof(TileSet));
                PalIndices = s.SerializeArray <byte>(PalIndices, Width * Height, name: nameof(PalIndices));
            }
        }
Пример #4
0
        public override void SerializeBlock(SerializerObject s)
        {
            if (s.GameSettings.GBA_IsMilan)
            {
                Milan_Header = s.SerializeArray <byte>(Milan_Header, 4, name: nameof(Milan_Header));
            }

            if (s.GameSettings.EngineVersion >= EngineVersion.GBA_SplinterCell)
            {
                MatrixOffsets = s.SerializeArray <ushort>(MatrixOffsets, FrameCount, name: nameof(MatrixOffsets));
                s.Align(4);
                if (Matrices == null)
                {
                    Matrices = new GBA_AffineMatrix[FrameCount][];
                }

                for (int i = 0; i < Matrices.Length; i++)
                {
                    ushort offset = MatrixOffsets[i];
                    uint   count  = (uint)Math.Min((BlockSize - offset) / 8, 32);
                    s.DoAt(Offset + offset, () => {
                        Matrices[i] = s.SerializeObjectArray <GBA_AffineMatrix>(Matrices[i], count, name: $"{nameof(Matrices)}[{i}]");
                    });
                }
                s.Goto(Offset + BlockSize);
            }
            else
            {
                if (Matrices == null)
                {
                    Matrices = new GBA_AffineMatrix[1][];
                }
                Matrices[0] = s.SerializeObjectArray <GBA_AffineMatrix>(Matrices[0], BlockSize / 8, name: $"{nameof(Matrices)}[{0}]");
            }
        }
Пример #5
0
        public override void SerializeBlock(SerializerObject s)
        {
            // Serialize data
            Height            = s.Serialize <byte>(Height, name: nameof(Height));
            Width             = s.Serialize <byte>(Width, name: nameof(Width));
            UnkData0          = s.SerializeArray <byte>(UnkData0, 4, name: nameof(UnkData0));
            PaletteCount      = s.Serialize <byte>(PaletteCount, name: nameof(PaletteCount));
            PaletteBlockCount = s.Serialize <byte>(PaletteBlockCount, name: nameof(PaletteBlockCount));
            PaletteOffset     = s.Serialize <uint>(PaletteOffset, name: nameof(PaletteOffset));
            TileDataOffset    = s.Serialize <uint>(TileDataOffset, name: nameof(TileDataOffset));

            var basePtr = s.CurrentPointer;

            s.Goto(basePtr + TileDataOffset);
            TileSet    = s.SerializeArray <byte>(TileSet, Width * Height * 0x10, name: nameof(TileSet));
            PalIndices = s.SerializeArray <byte>(PalIndices, Width * Height, name: nameof(PalIndices));

            s.Goto(basePtr + PaletteOffset);
            if (Palette == null)
            {
                Palette = new RGBA5551Color[PaletteBlockCount][];
            }
            for (int i = 0; i < PaletteBlockCount; i++)
            {
                Palette[i] = s.SerializeObjectArray <RGBA5551Color>(Palette[i], PaletteCount * 4, name: $"{nameof(Palette)}[{i}]");
            }
        }
Пример #6
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            // Serialize header
            EventsPointer = s.SerializePointer(EventsPointer, name: nameof(EventsPointer));
            EventCount    = s.Serialize <byte>(EventCount, name: nameof(EventCount));
            s.SerializeArray <byte>(new byte[3], 3, name: "Padding");
            EventLinksPointer = s.SerializePointer(EventLinksPointer, name: nameof(EventLinksPointer));
            EventLinkCount    = s.Serialize <byte>(EventLinkCount, name: nameof(EventLinkCount));
            s.SerializeArray <byte>(new byte[3], 3, name: "Padding");

            if (EventCount != EventLinkCount)
            {
                Debug.LogError("Event counts don't match");
            }

            s.DoAt(EventsPointer, (() =>
            {
                // Serialize every event
                Events = s.SerializeObjectArray <R1_EventData>(Events, EventCount, name: nameof(Events));
            }));

            s.DoAt(EventLinksPointer, (() =>
            {
                // Serialize the event linking table
                EventLinkingTable = s.SerializeArray <byte>(EventLinkingTable, EventLinkCount, name: nameof(EventLinkingTable));
            }));
        }
Пример #7
0
        public override void SerializeImpl(SerializerObject s)
        {
            PointersPointer = s.SerializePointer <GBAIsometric_LevelDataLayerDataPointers>(PointersPointer, resolve: true, name: nameof(PointersPointer));
            StructType      = s.Serialize <MapLayerType>(StructType, name: nameof(StructType));
            Width           = s.Serialize <ushort>(Width, name: nameof(Width));
            Height          = s.Serialize <ushort>(Height, name: nameof(Height));
            Ushort_0A       = s.Serialize <ushort>(Ushort_0A, name: nameof(Ushort_0A));
            MapDataPointer  = s.SerializePointer(MapDataPointer, name: nameof(MapDataPointer));
            Pointer_20      = s.SerializePointer(Pointer_20, name: nameof(Pointer_20));

            if (StructType == MapLayerType.Map)
            {
                Palette       = s.SerializeObjectArray <ARGB1555Color>(Palette, 256, name: nameof(Palette));
                RemainingData = s.SerializeArray <byte>(RemainingData, 44, name: nameof(RemainingData));
            }

            // TODO: Remove try/catch
            try
            {
                s.DoAt(MapDataPointer, () =>
                {
                    s.DoEncoded(new RHREncoder(), () =>
                    {
                        MapData = s.SerializeArray <ushort>(MapData, Width * Height, name: nameof(MapData));
                    });
                });
            }
            catch (Exception ex)
            {
                Debug.LogWarning($"Failed to decompress {MapDataPointer}: {ex.Message}\n{ex.InnerException?.StackTrace}");
            }
        }
Пример #8
0
        public override void SerializeBlock(SerializerObject s)
        {
            if (s.GameSettings.EngineVersion <= EngineVersion.GBA_BatmanVengeance)
            {
                Is8bpp = s.Serialize <bool>(Is8bpp, name: nameof(Is8bpp));

                if (s.GameSettings.GBA_IsMilan)
                {
                    CompressionType = s.Serialize <Milan_CompressionType>(CompressionType, name: nameof(CompressionType));
                }
                else
                {
                    IsCompressed    = s.Serialize <bool>(IsCompressed, name: nameof(IsCompressed));
                    CompressionType = IsCompressed ? Milan_CompressionType.LZSS : Milan_CompressionType.None;
                }

                if (Is8bpp)
                {
                    TileSet8bppSize = s.Serialize <ushort>(TileSet8bppSize, name: nameof(TileSet8bppSize));
                }
                else
                {
                    TileSet4bppSize = s.Serialize <ushort>(TileSet4bppSize, name: nameof(TileSet4bppSize));
                }
            }
            else
            {
                TileSet4bppSize             = s.Serialize <ushort>(TileSet4bppSize, name: nameof(TileSet4bppSize));
                TileSet8bppSize             = s.Serialize <ushort>(TileSet8bppSize, name: nameof(TileSet8bppSize));
                IsCompressed                = s.Serialize <bool>(IsCompressed, name: nameof(IsCompressed));
                AnimatedTileKitManagerIndex = s.Serialize <byte>(AnimatedTileKitManagerIndex, name: nameof(AnimatedTileKitManagerIndex)); // Can be 0xFF which means this block doesn't exist
                PaletteCount                = s.Serialize <byte>(PaletteCount, name: nameof(PaletteCount));
                Byte_07        = s.Serialize <byte>(Byte_07, name: nameof(Byte_07));
                PaletteIndices = s.SerializeArray <byte>(PaletteIndices, PaletteCount, name: nameof(PaletteIndices));

                CompressionType = IsCompressed && s.GameSettings.EngineVersion != EngineVersion.GBA_R3_NGage ? Milan_CompressionType.LZSS : Milan_CompressionType.None;
            }

            // Serialize tilemap data
            switch (CompressionType)
            {
            case Milan_CompressionType.None:
            default:
                TileSet4bpp = s.SerializeArray <byte>(TileSet4bpp, TileSet4bppSize * 0x20, name: nameof(TileSet4bpp));
                TileSet8bpp = s.SerializeArray <byte>(TileSet8bpp, TileSet8bppSize * 0x40, name: nameof(TileSet8bpp));
                break;

            case Milan_CompressionType.RL:
                throw new NotImplementedException();

            case Milan_CompressionType.LZSS:
                s.DoEncoded(new GBA_LZSSEncoder(), () => {
                    TileSet4bpp = s.SerializeArray <byte>(TileSet4bpp, TileSet4bppSize * 0x20, name: nameof(TileSet4bpp));
                    TileSet8bpp = s.SerializeArray <byte>(TileSet8bpp, TileSet8bppSize * 0x40, name: nameof(TileSet8bpp));
                });
                s.Align();
                break;
            }
        }
Пример #9
0
        public override void SerializeImpl(SerializerObject s)
        {
            bool determineTileSize = false;

            if (Count == 0)
            {
                Headers = s.SerializeObjectArray <Header>(Headers, 2, name: nameof(Headers));

                if (Headers[0].TileOffset % 4 != 0 || Headers[0].ExtraBytes >= 4 || (Headers[0].TileOffset / 4) < 2)
                {
                    return;                                                                                                 // Invalid
                }
                Count             = (uint)(Headers[0].TileOffset / 4) - 1;
                determineTileSize = true;
                s.Goto(Offset);
            }
            Headers = s.SerializeObjectArray <Header>(Headers, Count + 1, name: nameof(Headers));
            if (TileData == null)
            {
                TileData = new byte[Count][];
                for (int i = 0; i < Count; i++)
                {
                    s.DoAt(Offset + Headers[i].TileOffset, () => {
                        int length = (Headers[i + 1].TileOffset - Headers[i].TileOffset - Headers[i].ExtraBytes);

                        if (determineTileSize && i == 0)
                        {
                            if (Math.Sqrt(length * 2) % 1 == 0)
                            {
                                int val = Mathf.RoundToInt(Mathf.Sqrt(length * 2));
                                if ((val != 0) && ((val & (val - 1)) == 0))
                                {
                                    TileSize = (uint)val;
                                }
                            }
                        }

                        if (length != TileSize * TileSize / 2)
                        {
                            s.DoEncoded(new LZSSEncoder((uint)length, hasHeader: false), () => {
                                TileData[i] = s.SerializeArray <byte>(TileData[i], s.CurrentLength, name: $"{nameof(TileData)}[{i}]");
                            });
                        }
                        else
                        {
                            TileData[i] = s.SerializeArray <byte>(TileData[i], length, name: $"{nameof(TileData)}[{i}]");
                        }
                        if (determineTileSize && i == 0)
                        {
                            int len = TileData[i].Length;
                            if (Math.Sqrt(len * 2) % 1 == 0)
                            {
                                TileSize = (uint)Mathf.RoundToInt(Mathf.Sqrt(len * 2));
                            }
                        }
                    });
                }
            }
        }
Пример #10
0
 public override void SerializeImpl(SerializerObject s)
 {
     TileSet_4bpp = s.SerializeArray <byte>(TileSet_4bpp, TileSetCount_4bpp * 0x20, name: nameof(TileSet_4bpp));
     TileSet_8bpp = s.SerializeArray <byte>(TileSet_8bpp, (TileSetCount_Total - TileSetCount_4bpp) * 0x40, name: nameof(TileSet_8bpp));
     TileSet_4bpp_ConvertIndexTable = s.SerializeArray <ushort>(TileSet_4bpp_ConvertIndexTable, TileSetCount_4bpp, name: nameof(TileSet_4bpp_ConvertIndexTable));
     s.Align();
     TileSet_4bpp_ConvertDatas = s.SerializeObjectArray <ConvertData>(TileSet_4bpp_ConvertDatas, TileSet_4bpp_ConvertIndexTable.Max() + 1, name: nameof(TileSet_4bpp_ConvertDatas));
 }
Пример #11
0
 public override void SerializeImpl(SerializerObject s)
 {
     Type = s.Serialize <byte>(Type, name: nameof(Type));
     if (Type == 0)
     {
         Bytes = s.SerializeArray <byte>(Bytes, GetLength() - 1, name: nameof(Bytes));
     }
     else
     {
         Shorts = s.SerializeArray <short>(Shorts, GetLength() - 1, name: nameof(Shorts));
     }
 }
Пример #12
0
        public override void SerializeImpl(SerializerObject s)
        {
            GraphicsDataPointer        = s.SerializePointer <GBAIsometric_RHR_GraphicsData>(GraphicsDataPointer, resolve: true, name: nameof(GraphicsDataPointer));
            PaletteIndexTablePointer   = s.SerializePointer <GBAIsometric_RHR_PaletteIndexTable>(PaletteIndexTablePointer, resolve: true, onPreSerialize: pit => pit.Length = GraphicsDataPointer.Value.CompressionLookupBufferLength, name: nameof(PaletteIndexTablePointer));
            CombinedTileDataPointer    = s.SerializePointer(CombinedTileDataPointer, name: nameof(CombinedTileDataPointer));
            CombinedTileOffsetsPointer = s.SerializePointer(CombinedTileOffsetsPointer, name: nameof(CombinedTileOffsetsPointer));
            for (int i = 0; i < 4; i++)
            {
                AssembleData[i] = s.SerializeObject <GBAIsometric_RHR_TileAssemble>(AssembleData[i], onPreSerialize: ad => ad.TileCompression = (GBAIsometric_RHR_TileAssemble.Compression)i, name: $"{nameof(AssembleData)}[{i}]");
            }
            PalettesPointer = s.SerializePointer(PalettesPointer, name: nameof(PalettesPointer));

            // Todo: Read these in a less hacky way
            s.DoAt(CombinedTileDataPointer, () => {
                CombinedTileData = s.SerializeArray <ushort>(CombinedTileData, (CombinedTileOffsetsPointer - CombinedTileDataPointer) / 2, name: nameof(CombinedTileData));
            });
            s.DoAt(CombinedTileOffsetsPointer, () => {
                if (CombinedTileDataPointer == CombinedTileOffsetsPointer)
                {
                    CombinedTileOffsets = new ushort[0];
                }
                else
                {
                    uint length = 0;
                    s.DoAt(CombinedTileOffsetsPointer, () => {
                        ushort CombinedTileOffsetsLengthHack = 0;
                        while (CombinedTileOffsetsLengthHack < CombinedTileData.Length)
                        {
                            CombinedTileOffsetsLengthHack = s.Serialize <ushort>(CombinedTileOffsetsLengthHack, name: nameof(CombinedTileOffsetsLengthHack));
                        }
                        length = (uint)((s.CurrentPointer - CombinedTileOffsetsPointer) / 2);
                    });
                    CombinedTileOffsets = s.SerializeArray <ushort>(CombinedTileOffsets, length, name: nameof(CombinedTileOffsets));
                }
            });

            s.DoAt(PalettesPointer, () =>
            {
                if (Palettes == null)
                {
                    Palettes = new RGBA5551Color[PaletteIndexTablePointer.Value.GetMaxPaletteIndex() + 1][];
                }

                for (int i = 0; i < Palettes.Length; i++)
                {
                    Palettes[i] = s.SerializeObjectArray <RGBA5551Color>(Palettes[i], 16, name: $"{nameof(Palettes)}[i]");
                }
            });

            s.DoEncoded(new RHR_SpriteEncoder(false, GraphicsDataPointer.Value.CompressionLookupBuffer, GraphicsDataPointer.Value.CompressedDataPointer), () => {
                byte[] fullSheet = s.SerializeArray <byte>(default, s.CurrentLength, name: nameof(fullSheet));
Пример #13
0
        public override void SerializeBlock(SerializerObject s)
        {
            Flags = s.Serialize <byte>(Flags, name: nameof(Flags));

            if (!s.GameSettings.GBA_IsMilan)
            {
                Byte_01             = s.Serialize <byte>(Byte_01, name: nameof(Byte_01));
                AffineMatricesIndex = s.Serialize <byte>((byte)AffineMatricesIndex, name: nameof(AffineMatricesIndex));
                Byte_03             = s.Serialize <byte>(Byte_03, name: nameof(Byte_03));
                FrameCount          = (byte)BitHelpers.ExtractBits(Byte_03, 6, 0);

                LayersPerFrame = s.SerializeArray <byte>(LayersPerFrame, FrameCount, name: nameof(LayersPerFrame));

                s.Align();

                if (Layers == null)
                {
                    Layers = new GBA_AnimationChannel[FrameCount][];
                }

                for (int i = 0; i < FrameCount; i++)
                {
                    Layers[i] = s.SerializeObjectArray <GBA_AnimationChannel>(Layers[i], LayersPerFrame[i], name: $"{nameof(Layers)}[{i}]");
                }
            }
            else
            {
                FrameCount          = s.Serialize <byte>(FrameCount, name: nameof(FrameCount));
                Milan_Ushort_02     = s.Serialize <ushort>(Milan_Ushort_02, name: nameof(Milan_Ushort_02));
                AffineMatricesIndex = s.Serialize <ushort>(AffineMatricesIndex, name: nameof(AffineMatricesIndex));
                Milan_Int_06        = s.Serialize <int>(Milan_Int_06, name: nameof(Milan_Int_06));

                var offsetBase = s.CurrentPointer;

                Milan_LayerOffsets = s.SerializeArray <ushort>(Milan_LayerOffsets, FrameCount + 1, name: nameof(Milan_LayerOffsets)); // +1 since last offset is the end

                if (Layers == null)
                {
                    Layers = new GBA_AnimationChannel[FrameCount][];
                }

                for (int i = 0; i < FrameCount; i++)
                {
                    Layers[i] = s.DoAt(offsetBase + Milan_LayerOffsets[i], () => s.SerializeObjectArray <GBA_AnimationChannel>(Layers[i], (Milan_LayerOffsets[i + 1] - Milan_LayerOffsets[i]) / 6, name: $"{nameof(Layers)}[{i}]"));
                }

                s.Goto(offsetBase + Milan_LayerOffsets.LastOrDefault());
            }
        }
Пример #14
0
 /// <summary>
 /// Handles the data serialization
 /// </summary>
 /// <param name="s">The serializer object</param>
 public override void SerializeImpl(SerializerObject s)
 {
     EntryPoint      = s.SerializeArray <byte>(EntryPoint, 4, name: nameof(EntryPoint));
     NintendoLogo    = s.SerializeArray <byte>(NintendoLogo, 156, name: nameof(NintendoLogo));
     GameTitle       = s.SerializeString(GameTitle, 12, Encoding.ASCII, name: nameof(GameTitle));
     GameCode        = s.SerializeString(GameCode, 4, Encoding.ASCII, name: nameof(GameCode));
     MakerCode       = s.SerializeString(MakerCode, 2, Encoding.ASCII, name: nameof(MakerCode));
     FixedValue      = s.Serialize <byte>(FixedValue, name: nameof(FixedValue));
     MainUnitCode    = s.Serialize <byte>(MainUnitCode, name: nameof(MainUnitCode));
     DeviceType      = s.Serialize <byte>(DeviceType, name: nameof(DeviceType));
     Reserved1       = s.SerializeArray <byte>(Reserved1, 7, name: nameof(Reserved1));
     SoftwareVersion = s.Serialize <byte>(SoftwareVersion, name: nameof(SoftwareVersion));
     ComplementCheck = s.Serialize <byte>(ComplementCheck, name: nameof(ComplementCheck));
     Reserved2       = s.SerializeArray <byte>(Reserved2, 2, name: nameof(Reserved2));
 }
Пример #15
0
        public void DecryptSaveFiles(GameSettings settings)
        {
            using (var context = new Context(settings))
            {
                foreach (var save in Directory.GetFiles(settings.GameDirectory, "*.sav", SearchOption.TopDirectoryOnly).Select(Path.GetFileName))
                {
                    LinearSerializedFile f = new LinearSerializedFile(context)
                    {
                        filePath = save
                    };
                    context.AddFile(f);
                    SerializerObject s        = context.Deserializer;
                    byte[]           saveData = null;
                    s.DoAt(f.StartPointer, () => {
                        s.DoEncoded(new PC_R1_SaveEncoder(), () => {
                            saveData = s.SerializeArray <byte>(saveData, s.CurrentLength, name: "SaveData");
                            Util.ByteArrayToFile(context.BasePath + save + ".dec", saveData);
                        });
                    });

                    /*LinearSerializedFile f2 = new LinearSerializedFile(context) {
                     *  filePath = save + ".recompressed"
                     * };
                     * context.AddFile(f2);
                     * s = context.Serializer;
                     * s.DoAt(f2.StartPointer, () => {
                     *  s.DoEncoded(new R1PCSaveEncoder(), () => {
                     *      saveData = s.SerializeArray<byte>(saveData, saveData.Length, name: "SaveData");
                     *  });
                     * });*/
                }
            }
        }
Пример #16
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            NumberOfLanguages = s.Serialize <byte>(NumberOfLanguages, name: nameof(NumberOfLanguages));
            LanguageUtilized  = s.Serialize <byte>(LanguageUtilized, name: nameof(LanguageUtilized));
            KeyboardType      = s.Serialize <KeyboardTypes>(KeyboardType, name: nameof(KeyboardType));

            // Most versions have 3 languages, but sometimes the NumberOfLanguages is set to 1 because only 1 is available. Other versions may have up to 5.
            var numLangNames = Mathf.Clamp(NumberOfLanguages, 3, 5);

            if (s.GameSettings.EngineVersion == EngineVersion.R1_PS1_Edu && (s.GameSettings.EduVolume.StartsWith("IT") || s.GameSettings.EduVolume.StartsWith("CS")))
            {
                numLangNames = 5;
            }

            if (s.GameSettings.EngineVersion == EngineVersion.R1_PC_Edu && (s.GameSettings.EduVolume.StartsWith("HN") || s.GameSettings.EduVolume.StartsWith("IS") || s.GameSettings.EduVolume.StartsWith("NL")))
            {
                numLangNames = 5;
            }

            LanguageNames = s.SerializeStringArray(LanguageNames, numLangNames, 11, name: nameof(LanguageNames));

            var align = 3 + LanguageNames.Length * 11 + 8;

            if (align % 4 != 0)
            {
                s.SerializeArray <byte>(new byte[align % 4], 4 - (align % 4), name: "Align");
            }

            TextDefineCount = s.Serialize <uint>(TextDefineCount, name: nameof(TextDefineCount));
            Unk1            = s.Serialize <ushort>(Unk1, name: nameof(Unk1));
            Unk2            = s.Serialize <ushort>(Unk2, name: nameof(Unk2));

            TextDefine = s.SerializeObjectArray <R1_PC_LocFileString>(TextDefine, TextDefineCount, name: nameof(TextDefine));
        }
Пример #17
0
        public override void SerializeBlock(SerializerObject s)
        {
            Data = s.SerializeArray <byte>(Data, BlockSize, name: nameof(Data));

            // Serialize sub-blocks
            if (SubBlocks == null)
            {
                SubBlocks = new GBC_DummyBlock[DependencyTable.DependenciesCount];
            }

            // Get all root pointers
            var rootBlock    = ((GBC_BaseManager)s.GameSettings.GetGameManager).GetLevelList(s.Context);
            var rootTable    = rootBlock.DependencyTable;
            var rootPointers = Enumerable.Range(0, rootTable.Dependencies.Length).Select(x => rootTable.GetPointer(x)).ToArray();

            for (int i = 0; i < DependencyTable.Dependencies.Length; i++)
            {
                var p = DependencyTable.GetPointer(i);

                if (rootPointers.Contains(p) && Offset != rootBlock.Offset)
                {
                    continue;
                }

                SubBlocks[i] = s.DoAt(p, () => s.SerializeObject <GBC_DummyBlock>(SubBlocks[i], name: $"{nameof(SubBlocks)}[{i}]"));
            }
        }
Пример #18
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            // Serialize data

            ImageDataPointer   = s.SerializePointer(ImageDataPointer, name: nameof(ImageDataPointer));
            Unk1               = s.SerializeArray <byte>(Unk1, 4, name: nameof(Unk1));
            ImageValuesPointer = s.SerializePointer(ImageValuesPointer, name: nameof(ImageValuesPointer));
            Unk2               = s.SerializeArray <byte>(Unk2, 4, name: nameof(Unk2));
            PalettesPointer    = s.SerializePointer(PalettesPointer, name: nameof(PalettesPointer));
            Unk3               = s.SerializeArray <byte>(Unk3, 4, name: nameof(Unk3));
            FrameCount         = s.Serialize <byte>(FrameCount, name: nameof(FrameCount));
            Unk4               = s.SerializeArray <byte>(Unk4, 3, name: nameof(Unk4));

            // Serialize data from pointers

            s.DoAt(ImageValuesPointer, () => ImageValues = s.SerializeArray <ushort>(default, Width * Height, name: nameof(ImageValues)));
        public override void SerializeImpl(SerializerObject s)
        {
            TileSetPointer    = s.SerializePointer <GBAIsometric_RHR_TileSet>(TileSetPointer, resolve: true, name: nameof(TileSetPointer));
            StructType        = s.Serialize <MapLayerType>(StructType, name: nameof(StructType));
            Width             = s.Serialize <ushort>(Width, name: nameof(Width));
            Height            = s.Serialize <ushort>(Height, name: nameof(Height));
            Ushort_0A         = s.Serialize <ushort>(Ushort_0A, name: nameof(Ushort_0A));
            MapDataPointer    = s.SerializePointer(MapDataPointer, name: nameof(MapDataPointer));
            MapPalettePointer = s.SerializePointer(MapPalettePointer, name: nameof(MapPalettePointer));
            MapPalette        = s.DoAt(MapPalettePointer, () => s.SerializeObjectArray <RGBA5551Color>(MapPalette, 256, name: nameof(MapPalette)));

            s.DoAt(MapDataPointer, () =>
            {
                s.DoEncoded(new RHREncoder(), () => MapData = s.SerializeArray <ushort>(MapData, Width * Height, name: nameof(MapData)));
            });

            // Debug tilemaps
            //ushort[] fullMap = CreateFullMap(MapData);
            //string logString = $"{Offset}: Max Tilemap Value - {fullMap.Max()}";
            //UnityEngine.Debug.Log(logString);
            //s.Log(logString);
            //byte[] result = new byte[fullMap.Length * sizeof(ushort)];
            //Buffer.BlockCopy(fullMap, 0, result, 0, result.Length);
            //Util.ByteArrayToFile(s.Context.BasePath + "full_tilemap/" + Offset.StringAbsoluteOffset + ".bin", result);
        }
Пример #20
0
        public override void SerializeImpl(SerializerObject s)
        {
            if (SerializeValues)
            {
                Index               = s.Serialize <uint>(Index, name: nameof(Index));
                AnimationsPointer   = s.SerializePointer(AnimationsPointer, name: nameof(AnimationsPointer));
                FrameOffsetsPointer = s.SerializePointer(FrameOffsetsPointer, name: nameof(FrameOffsetsPointer));
                PaletteIndex        = s.Serialize <uint>(PaletteIndex, name: nameof(PaletteIndex));
                Uint_10             = s.Serialize <uint>(Uint_10, name: nameof(Uint_10));
                Short_14            = s.Serialize <short>(Short_14, name: nameof(Short_14));
                Short_16            = s.Serialize <short>(Short_16, name: nameof(Short_16));
                Short_18            = s.Serialize <short>(Short_18, name: nameof(Short_18));
                Short_1A            = s.Serialize <short>(Short_1A, name: nameof(Short_1A));
                Short_1C            = s.Serialize <short>(Short_1C, name: nameof(Short_1C));
                Bytes_1E            = s.SerializeArray <byte>(Bytes_1E, 10, name: nameof(Bytes_1E));
            }

            s.DoAt(AnimationsPointer, () =>
            {
                if (Animations == null)
                {
                    // Since there is no count we read until we get to an invalid animation
                    var anims = new List <GBAVV_Mode7_Animation>();

                    var currentFrameIndex = 0;
                    var index             = 0;

                    while (true)
                    {
                        var anim = s.SerializeObject <GBAVV_Mode7_Animation>(default, name: $"{nameof(Animations)}[{index}]");
Пример #21
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            // Get offsets
            var offsetTableOffset = s.GameSettings.EngineVersion != EngineVersion.R1Jaguar_Proto ? Offset + 0x1208 : new R1Jaguar_Proto_Manager().GetDataPointer(s.Context, R1Jaguar_Proto_References.test_offlist);
            var eventTableOffset  = s.GameSettings.EngineVersion != EngineVersion.R1Jaguar_Proto ? Offset + 0x1608 : new R1Jaguar_Proto_Manager().GetDataPointer(s.Context, R1Jaguar_Proto_References.test_event);

            MapEvents = s.SerializeObject <R1Jaguar_MapEvents>(MapEvents, name: nameof(MapEvents));

            // Serialize next data block, skipping the padding
            s.DoAt(offsetTableOffset, () => EventOffsetTable = s.SerializeArray <ushort>(EventOffsetTable, MapEvents.EventIndexMap.Max(), name: nameof(EventOffsetTable)));

            if (EventData == null)
            {
                EventData = new R1Jaguar_EventInstance[EventOffsetTable.Length][];
            }

            // Serialize the events based on the offsets
            for (int i = 0; i < EventData.Length; i++)
            {
                s.DoAt(eventTableOffset + EventOffsetTable[i], () =>
                {
                    if (EventData[i] == null)
                    {
                        var temp = new List <R1Jaguar_EventInstance>();

                        var index = 0;
                        while (temp.LastOrDefault()?.Unk_00 != 0)
                        {
                            temp.Add(s.SerializeObject <R1Jaguar_EventInstance>(default, name: $"{nameof(EventData)}[{i}][{index}]"));
Пример #22
0
        public override void SerializeBlock(SerializerObject s)
        {
            UShort_00            = s.Serialize <ushort>(UShort_00, name: nameof(UShort_00));
            PatternOffsetsOffset = s.Serialize <ushort>(PatternOffsetsOffset, name: nameof(PatternOffsetsOffset));
            Byte_04      = s.Serialize <byte>(Byte_04, name: nameof(Byte_04));
            PatternCount = s.Serialize <byte>(PatternCount, name: nameof(PatternCount));
            UInt_06      = s.Serialize <uint>(UInt_06, name: nameof(UInt_06));

            s.DoAt(BlockStartPointer + PatternOffsetsOffset, () => {
                PatternOffsets = s.SerializeArray <ushort>(PatternOffsets, PatternCount, name: nameof(PatternOffsets));
            });
            if (Patterns == null)
            {
                Patterns = new Pattern[PatternCount];
            }
            for (int i = 0; i < PatternCount; i++)
            {
                Patterns[i] = s.DoAt(BlockStartPointer + PatternOffsets[i], () => {
                    return(s.SerializeObject <Pattern>(Patterns[i], name: $"{nameof(Patterns)}[{i}]"));
                });
            }
            if (Patterns.Length > 0)
            {
                s.Goto(Patterns[Patterns.Length - 1].Offset + Patterns[Patterns.Length - 1].Size);
            }
        }
Пример #23
0
        /// <summary>
        /// Creates a relocated 0.bin file, that is searchable with file offsets in big endian, prefixed with "DD".
        /// e.g.: the bytes 010F1E02 (a pointer to 0x01) become DD000001.
        /// </summary>
        /// <param name="s"></param>
        public void CreateRelocatedFile(SerializerObject s)
        {
            byte[] data = s.SerializeArray <byte>(null, s.CurrentLength, name: "fullfile");
            uint   addr = 0x021E0F00;

            for (int j = 0; j < data.Length; j++)
            {
                if (data[j] == 0x02)
                {
                    int  off = j - 3;
                    uint ptr = BitConverter.ToUInt32(data, off);
                    if (ptr >= addr && ptr < addr + data.Length)
                    {
                        ptr = (ptr - addr) + 0xDD000000;
                        byte[] newData = BitConverter.GetBytes(ptr);
                        for (int y = 0; y < 4; y++)
                        {
                            data[off + 3 - y] = newData[y];
                        }
                        j += 3;
                    }
                }
            }
            Util.ByteArrayToFile(s.Context.BasePath + "relocated.bin", data);
        }
Пример #24
0
        }                                                     // References to some of the states in the normal state array

        public override void SerializeImpl(SerializerObject s)
        {
            UnknownStatesPointer    = s.SerializeObject <SNES_Pointer>(UnknownStatesPointer, onPreSerialize: x => x.MemoryBankOverride = 4, name: nameof(UnknownStatesPointer));
            ImageDescriptorsPointer = s.SerializeObject <SNES_Pointer>(ImageDescriptorsPointer, onPreSerialize: x => x.MemoryBankOverride = 4, name: nameof(ImageDescriptorsPointer));

            Ushort_04 = s.Serialize <ushort>(Ushort_04, name: nameof(Ushort_04));

            XPosition = s.Serialize <short>(XPosition, name: nameof(XPosition));
            YPosition = s.Serialize <short>(YPosition, name: nameof(YPosition));

            Bytes_0A = s.SerializeArray <byte>(Bytes_0A, 6, name: nameof(Bytes_0A));

            StatesPointer = s.SerializeObject <SNES_Pointer>(StatesPointer, onPreSerialize: x => x.MemoryBankOverride = 4, name: nameof(StatesPointer));

            if (!s.FullSerialize)
            {
                return;
            }

            // Serialize data from pointers
            States           = s.DoAt(StatesPointer.GetPointer(), () => s.SerializeObjectArray <SNES_Proto_State>(States, 5 * 0x15, name: nameof(States)));
            ImageDescriptors = s.DoAt(ImageDescriptorsPointer.GetPointer(), () => s.SerializeObjectArray <SNES_Proto_ImageDescriptor>(ImageDescriptors, States.Max(state => state.Animation?.Layers.Max(layer => layer.ImageIndex + 1) ?? 0), name: nameof(ImageDescriptors)));

            UnknownStatesPointers = s.DoAt(UnknownStatesPointer.GetPointer(), () => s.SerializeObjectArray <SNES_Pointer>(UnknownStatesPointers, 16, onPreSerialize: x => x.MemoryBankOverride = 4, name: nameof(UnknownStatesPointers)));

            if (UnknownStates == null)
            {
                UnknownStates = new SNES_Proto_State[UnknownStatesPointers.Length];
            }

            for (int i = 0; i < UnknownStates.Length; i++)
            {
                UnknownStates[i] = s.DoAt(UnknownStatesPointers[i].GetPointer(), () => s.SerializeObject <SNES_Proto_State>(UnknownStates[i], name: $"{nameof(UnknownStates)}[{i}]"));
            }
        }
Пример #25
0
        public void SerializeLevelData(SerializerObject s)
        {
            if (s.GameSettings.EngineVersion == EngineVersion.R1_GBA)
            {
                s.DoAt(MapDataPointer, () => {
                    if ((CompressionFlags & 1) == 1)
                    {
                        s.DoEncoded(new GBA_LZSSEncoder(), () => {
                            MapData = s.SerializeObject <MapData>(MapData, name: nameof(MapData));
                        });
                    }
                    else
                    {
                        MapData = s.SerializeObject <MapData>(MapData, name: nameof(MapData));
                    }
                });
                s.DoAt(TilePaletteIndicesPointer, () => {
                    if ((CompressionFlags & 2) == 2)
                    {
                        s.DoEncoded(new GBA_LZSSEncoder(), () => TilePaletteIndices = s.SerializeArray <byte>(TilePaletteIndices, s.CurrentLength, name: nameof(TilePaletteIndices)));
                    }
                    else
                    {
                        uint numTileBlocks = (TilePaletteIndicesPointer.AbsoluteOffset - TileBlockIndicesPointer.AbsoluteOffset) / 2;
                        TilePaletteIndices = s.SerializeArray <byte>(TilePaletteIndices, numTileBlocks, name: nameof(TilePaletteIndices));
                    }
                });

                s.DoAt(TileBlockIndicesPointer, () => TileBlockIndices = s.SerializeArray <ushort>(TileBlockIndices, TilePaletteIndices.Length, name: nameof(TileBlockIndices)));
                s.DoAt(TilePalettePointer, () => TilePalettes          = s.SerializeObjectArray <RGBA5551Color>(TilePalettes, 10 * 16, name: nameof(TilePalettes)));

                ushort maxBlockIndex = TileBlockIndices.Max();
                s.DoAt(TileDataPointer, () => TileData = s.SerializeArray <byte>(TileData, 0x20 * ((uint)maxBlockIndex + 1), name: nameof(TileData)));
            }
            else if (s.GameSettings.EngineVersion == EngineVersion.R1_DSi)
            {
                s.DoAt(MapDataPointer, () => s.DoEncoded(new GBA_LZSSEncoder(), () => MapData = s.SerializeObject <MapData>(MapData, name: nameof(MapData))));
                s.DoAt(TileDataPointer, () => {
                    s.DoEncoded(new GBA_LZSSEncoder(), () => TileData = s.SerializeArray <byte>(TileData, s.CurrentLength, name: nameof(TileData)));
                });
                s.DoAt(TilePalettePointer, () => TilePalettes = s.SerializeObjectArray <RGBA5551Color>(TilePalettes, 256, name: nameof(TilePalettes)));
                s.DoAt(TileBlockIndicesPointer, () => {
                    uint maxTileInd  = MapData.Tiles.Max(t => t.TileMapY);
                    TileBlockIndices = s.SerializeArray <ushort>(TileBlockIndices, (maxTileInd + 1) * 4, name: nameof(TileBlockIndices));
                });
            }
        }
        public override void SerializeImpl(SerializerObject s)
        {
            Width   = s.Serialize <ushort>(Width, name: nameof(Width));
            Height  = s.Serialize <ushort>(Height, name: nameof(Height));
            Uint_04 = s.Serialize <uint>(Uint_04, name: nameof(Uint_04));

            if ((Uint_04 & 0x4000) == 0x4000)
            {
                MapData = s.SerializeArray <ushort>(MapData, Width * Height, name: nameof(MapData));
            }
            else
            {
                MapData = s.SerializeArray <byte>(MapData?.Select(x => (byte)x).ToArray(), Width * Height, name: nameof(MapData)).Select(x => (ushort)x).ToArray();
            }

            //s.Log($"Max index: {MapData.Max()}");
        }
        public override void SerializeImpl(SerializerObject s)
        {
            PaletteIndicesPointer              = s.SerializePointer(PaletteIndicesPointer, name: nameof(PaletteIndicesPointer));
            SecondaryPaletteIndicesPointer     = s.SerializePointer(SecondaryPaletteIndicesPointer, name: nameof(SecondaryPaletteIndicesPointer));
            SecondaryPaletteTileIndicesPointer = s.SerializePointer(SecondaryPaletteTileIndicesPointer, name: nameof(SecondaryPaletteTileIndicesPointer));

            s.DoAt(PaletteIndicesPointer, () => {
                PaletteIndices = s.SerializeArray <byte>(PaletteIndices, Length, name: nameof(PaletteIndices));
            });
            s.DoAt(SecondaryPaletteIndicesPointer, () => {
                long length             = SecondaryPaletteTileIndicesPointer - SecondaryPaletteIndicesPointer; // hack
                SecondaryPaletteIndices = s.SerializeArray <byte>(SecondaryPaletteIndices, length, name: nameof(SecondaryPaletteIndices));
            });
            s.DoAt(SecondaryPaletteTileIndicesPointer, () => {
                SecondaryTileIndices = s.SerializeArray <ushort>(SecondaryTileIndices, SecondaryPaletteIndices.Length, name: nameof(SecondaryTileIndices));
            });
        }
Пример #28
0
 public override void SerializeImpl(SerializerObject s)
 {
     XPosition = s.Serialize <short>(XPosition, name: nameof(XPosition));
     YPosition = s.Serialize <short>(YPosition, name: nameof(YPosition));
     Byte2     = s.Serialize <byte>(Byte2, name: nameof(Byte2));
     Count     = s.Serialize <byte>(Count, name: nameof(Count));
     Unknown   = s.SerializeArray <short>(Unknown, Count, name: nameof(Unknown));
 }
Пример #29
0
        public override void SerializeImpl(SerializerObject s)
        {
            SampleOffset = s.SerializePointer(SampleOffset, name: nameof(SampleOffset));
            Length       = s.Serialize <uint>(Length, name: nameof(Length));

            s.DoAt(SampleOffset, () => {
                Sample = s.SerializeArray <byte>(Sample, Length, name: nameof(Sample));
            });
        }
Пример #30
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            // Get info
            var pointerTable = s.GameSettings.EngineVersion != EngineVersion.R1Jaguar_Proto ? PointerTables.JaguarR1_PointerTable(s.GameSettings.EngineVersion, this.Offset.file) : null;
            var manager      = (R1Jaguar_Manager)s.GameSettings.GetGameManager;
            var levels       = manager.GetNumLevels;

            // Serialize the references for the prototype
            if (s.GameSettings.EngineVersion == EngineVersion.R1Jaguar_Proto)
            {
                s.DoAt(new Pointer(0x8BB6A8, Offset.file), () =>
                {
                    References = s.SerializeObjectArray <R1Jaguar_ReferenceEntry>(References, 1676, onPreSerialize: (x => x.StringBase = new Pointer(0x8C0538, Offset.file)), name: nameof(References));

                    // Unknown initial 4 bytes, part of the string table
                    UnkReferenceValue = s.Serialize <uint>(UnkReferenceValue, name: nameof(UnkReferenceValue));
                });
            }

            // Serialize event definition data
            if (s.GameSettings.EngineVersion == EngineVersion.R1Jaguar)
            {
                if (!s.Context.FileExists("RAM_EventDefinitions"))
                {
                    // Copied to 0x001f9000 in memory. All pointers to 0x001Fxxxx likely point to an entry in this table
                    s.DoAt(pointerTable[JaguarR1_Pointer.EventDefinitions], () =>
                    {
                        byte[] EventDefsDataBytes = s.SerializeArray <byte>(null, manager.EventCount * 0x28,
                                                                            name: nameof(EventDefsDataBytes));
                        var file = new MemoryMappedByteArrayFile("RAM_EventDefinitions", EventDefsDataBytes, s.Context,
                                                                 0x001f9000)
                        {
                            Endianness = BinaryFile.Endian.Big
                        };
                        s.Context.AddFile(file);
                        s.DoAt(file.StartPointer,
                               () => EventDefinitions = s.SerializeObjectArray <R1Jaguar_EventDefinition>(EventDefinitions,
                                                                                                          manager.EventCount, name: nameof(EventDefinitions)));
                    });
                }
            }
            else
            {
                var offset = s.GameSettings.EngineVersion == EngineVersion.R1Jaguar_Proto ? GetProtoDataPointer(R1Jaguar_Proto_References.MS_rayman) : pointerTable[JaguarR1_Pointer.EventDefinitions];

                // Pointers all point to the ROM, not RAM
                s.DoAt(offset, () => EventDefinitions = s.SerializeObjectArray <R1Jaguar_EventDefinition>(EventDefinitions,
                                                                                                          manager.EventCount, name: nameof(EventDefinitions)));
            }

            if (AdditionalEventDefinitions == null)
            {
                if (s.GameSettings.EngineVersion != EngineVersion.R1Jaguar_Proto)
                {
                    AdditionalEventDefinitions = manager.AdditionalEventDefinitionPointers.Select(p =>
                    {
                        return(s.DoAt(new Pointer(p, pointerTable[JaguarR1_Pointer.EventDefinitions].file), () => s.SerializeObject <R1Jaguar_EventDefinition>(default, name: nameof(AdditionalEventDefinitions))));