Example #1
0
        public override void SerializeImpl(SerializerObject s)
        {
            LevelDataPointer = s.SerializePointer <GBAIsometric_RHR_LevelData>(LevelDataPointer, resolve: SerializeData, name: nameof(LevelDataPointer));

            MurfyStampScore1 = s.Serialize <ushort>(MurfyStampScore1, name: nameof(MurfyStampScore1));
            MurfyStampScore2 = s.Serialize <ushort>(MurfyStampScore2, name: nameof(MurfyStampScore2));
            MurfyStampScore3 = s.Serialize <ushort>(MurfyStampScore3, name: nameof(MurfyStampScore3));

            Short_0A          = s.Serialize <short>(Short_0A, name: nameof(Short_0A));
            Short_0C          = s.Serialize <ushort>(Short_0C, name: nameof(Short_0C));
            Short_0E          = s.Serialize <ushort>(Short_0E, name: nameof(Short_0E));
            Short_10          = s.Serialize <ushort>(Short_10, name: nameof(Short_10));
            Short_12          = s.Serialize <short>(Short_12, name: nameof(Short_12));
            Short_14          = s.Serialize <short>(Short_14, name: nameof(Short_14));
            PaletteShiftIndex = s.Serialize <byte>(PaletteShiftIndex, name: nameof(PaletteShiftIndex));
            Byte_17           = s.Serialize <byte>(Byte_17, name: nameof(Byte_17));

            Int_18 = s.Serialize <int>(Int_18, name: nameof(Int_18));
            Int_1C = s.Serialize <int>(Int_1C, name: nameof(Int_1C));

            Flags   = s.Serialize <LevelFlags>(Flags, name: nameof(Flags));
            Byte_21 = s.Serialize <byte>(Byte_21, name: nameof(Byte_21));
            Byte_22 = s.Serialize <byte>(Byte_22, name: nameof(Byte_22));
            Byte_23 = s.Serialize <byte>(Byte_23, name: nameof(Byte_23));

            MapPointer = s.SerializePointer(MapPointer, resolve: SerializeData, name: nameof(MapPointer));
        }
        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);
        }
Example #3
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));
            }));
        }
        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}]");
Example #5
0
        public override void SerializeImpl(SerializerObject s)
        {
            Name       = s.SerializeString(Name, 32, name: nameof(Name));
            Attributes = s.Serialize <ushort>(Attributes, name: nameof(Attributes));
            Version    = s.Serialize <ushort>(Version, name: nameof(Version));

            CreationTime     = s.SerializeObject <Palm_DateTime>(CreationTime, name: nameof(CreationTime));
            ModificationTime = s.SerializeObject <Palm_DateTime>(ModificationTime, name: nameof(ModificationTime));
            BackupTime       = s.SerializeObject <Palm_DateTime>(BackupTime, name: nameof(BackupTime));

            ModificationNumber  = s.Serialize <uint>(ModificationNumber, name: nameof(ModificationNumber));
            AppInfoAreaPointer  = s.SerializePointer(AppInfoAreaPointer, name: nameof(AppInfoAreaPointer));
            SortInfoAreaPointer = s.SerializePointer(SortInfoAreaPointer, name: nameof(SortInfoAreaPointer));

            DataBaseType = s.SerializeString(DataBaseType, 4, name: nameof(DataBaseType));
            CreatorID    = s.SerializeString(CreatorID, 4, name: nameof(CreatorID));
            UniqueID     = s.Serialize <uint>(UniqueID, name: nameof(UniqueID));

            NextRecordListID = s.Serialize <uint>(NextRecordListID, name: nameof(NextRecordListID));
            RecordsCount     = s.Serialize <ushort>(RecordsCount, name: nameof(RecordsCount));

            Records = s.SerializeObjectArray <Palm_DatabaseRecord>(Records, RecordsCount, onPreSerialize: x => x.Type = Type, name: nameof(Records));

            // Set the length of every record
            for (int i = 0; i < RecordsCount; i++)
            {
                Records[i].Length = (i == RecordsCount - 1 ? s.CurrentLength : Records[i + 1].DataPointer.FileOffset) - Records[i].DataPointer.FileOffset;
            }

            // TODO: Serialize sort info
        }
Example #6
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}");
            }
        }
Example #7
0
        public override void SerializeImpl(SerializerObject s)
        {
            PalettePointer = s.SerializePointer(PalettePointer, name: nameof(PalettePointer));
            TileSetPointer = s.SerializePointer(TileSetPointer, name: nameof(TileSetPointer));

            Palette = s.DoAt(PalettePointer, () => s.SerializeObject <GBAVV_WorldMap_Palette>(Palette, name: nameof(Palette)));
            TileSet = s.DoAt(TileSetPointer, () => s.SerializeObject <GBAVV_Map2D_TileSet>(TileSet, name: nameof(TileSet)));
        }
Example #8
0
 public override void SerializeImpl(SerializerObject s)
 {
     LinkedObjectsPointer  = s.SerializePointer(LinkedObjectsPointer, name: nameof(LinkedObjectsPointer));
     TriggerObjectsPointer = s.SerializePointer(TriggerObjectsPointer, name: nameof(TriggerObjectsPointer));
     LinkedObjectsCount    = s.Serialize <ushort>(LinkedObjectsCount, name: nameof(LinkedObjectsCount));
     TriggerObjectsCount   = s.Serialize <ushort>(TriggerObjectsCount, name: nameof(TriggerObjectsCount));
     Flags_0             = s.Serialize <GendoorFlags>(Flags_0, name: nameof(Flags_0));
     Flags_1             = s.Serialize <GendoorFlags>(Flags_1, name: nameof(Flags_1));
     RuntimeHasTriggered = s.Serialize <byte>(RuntimeHasTriggered, name: nameof(RuntimeHasTriggered));
     s.Serialize <byte>(default, name: "Padding"); // Not referenced by the code
Example #9
0
 /// <summary>
 /// Handles the data serialization
 /// </summary>
 /// <param name="s">The serializer object</param>
 public override void SerializeImpl(SerializerObject s)
 {
     if (s.GameSettings.EngineVersion == EngineVersion.R1_GBA)
     {
         // Serialize values
         TileDataPointer           = s.SerializePointer(TileDataPointer, name: nameof(TileDataPointer));
         MapDataPointer            = s.SerializePointer(MapDataPointer, name: nameof(MapDataPointer));
         TilePaletteIndicesPointer = s.SerializePointer(TilePaletteIndicesPointer, name: nameof(TilePaletteIndicesPointer));
         TileBlockIndicesPointer   = s.SerializePointer(TileBlockIndicesPointer, name: nameof(TileBlockIndicesPointer));
         TilePalettePointer        = s.SerializePointer(TilePalettePointer, name: nameof(TilePalettePointer));
         Unk_10                  = s.Serialize <byte>(Unk_10, name: nameof(Unk_10));
         Unk_11                  = s.Serialize <byte>(Unk_11, name: nameof(Unk_11));
         BackgroundIndex         = s.Serialize <byte>(BackgroundIndex, name: nameof(BackgroundIndex));
         ParallaxBackgroundIndex = s.Serialize <byte>(ParallaxBackgroundIndex, name: nameof(ParallaxBackgroundIndex));
         CompressionFlags        = s.Serialize <uint>(CompressionFlags, name: nameof(CompressionFlags));
     }
     else if (s.GameSettings.EngineVersion == EngineVersion.R1_DSi)
     {
         // Serialize values
         UnkDword_DSi_00         = s.Serialize <uint>(UnkDword_DSi_00, name: nameof(UnkDword_DSi_00));
         TileDataPointer         = s.SerializePointer(TileDataPointer, name: nameof(TileDataPointer));
         UnkDword_DSi_08         = s.Serialize <uint>(UnkDword_DSi_08, name: nameof(UnkDword_DSi_08));
         MapDataPointer          = s.SerializePointer(MapDataPointer, name: nameof(MapDataPointer));
         UnkDword_DSi_10         = s.Serialize <uint>(UnkDword_DSi_10, name: nameof(UnkDword_DSi_10));
         TileBlockIndicesPointer = s.SerializePointer(TileBlockIndicesPointer, name: nameof(TileBlockIndicesPointer));
         TilePalettePointer      = s.SerializePointer(TilePalettePointer, name: nameof(TilePalettePointer));
         UnkDword_DSi_1C         = s.Serialize <uint>(UnkDword_DSi_1C, name: nameof(UnkDword_DSi_1C));
     }
 }
Example #10
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));
Example #11
0
 public override void SerializeImpl(SerializerObject s)
 {
     Byte_01    = s.Serialize <byte>(Byte_01, name: nameof(Byte_01));
     Sample     = s.Serialize <byte>(Sample, name: nameof(Sample));
     UShort_02  = s.Serialize <ushort>(UShort_02, name: nameof(UShort_02));
     UInt_04    = s.Serialize <uint>(UInt_04, name: nameof(UInt_04));
     UInt_08    = s.Serialize <uint>(UInt_08, name: nameof(UInt_08));
     Pointer_0C = s.SerializePointer <GAX2_InstrumentVolumeEnvelope>(Pointer_0C, resolve: true, name: nameof(Pointer_0C));
     UInt_10    = s.Serialize <uint>(UInt_10, name: nameof(UInt_10));
     Pointer_14 = s.SerializePointer <GAX2_InstrumentConfig2>(Pointer_14, resolve: true, name: nameof(Pointer_14));
     Pitch1     = s.Serialize <sbyte>(Pitch1, name: nameof(Pitch1));
     Pitch2     = s.Serialize <sbyte>(Pitch2, name: nameof(Pitch2));
     Short_1A   = s.Serialize <short>(Short_1A, name: nameof(Short_1A));
 }
        public override void SerializeImpl(SerializerObject s)
        {
            MapTilesPointer = s.SerializePointer(MapTilesPointer, name: nameof(MapTilesPointer));
            TileMapPointer  = s.SerializePointer(TileMapPointer, name: nameof(TileMapPointer));
            LayerPrio       = s.Serialize <uint>(LayerPrio, name: nameof(LayerPrio));
            ScrollX         = s.Serialize <uint>(ScrollX, name: nameof(ScrollX));
            ScrollY         = s.Serialize <uint>(ScrollY, name: nameof(ScrollY));
            Uint_14         = s.Serialize <uint>(Uint_14, name: nameof(Uint_14));
            Uint_18         = s.Serialize <uint>(Uint_18, name: nameof(Uint_18));

            TileMap = s.DoAt(TileMapPointer, () => s.SerializeObject <GBAVV_Isometric_MapLayer>(TileMap, x => x.IsWorldMap = true, name: nameof(TileMap)));
            var mapTilesLength = TileMap.TileMapRows.SelectMany(x => x.Commands).Select(x => x.Params?.Max() ?? x.Param).Max() + 1;

            MapTiles = s.DoAt(MapTilesPointer, () => s.SerializeObjectArray <MapTile>(MapTiles, mapTilesLength * 4, x => x.GBAVV_IsWorldMap8bpp = Is8bpp, name: nameof(MapTiles)));
        }
 public override void SerializeImpl(SerializerObject s)
 {
     AnimGroupsPointer = s.SerializePointer(AnimGroupsPointer, name: nameof(AnimGroupsPointer));
     TileSetIndex      = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(TileSetIndex, name: nameof(TileSetIndex));
     AnimBlockIndex    = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(AnimBlockIndex, name: nameof(AnimBlockIndex));
     FrameImagesIndex  = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(FrameImagesIndex, name: nameof(FrameImagesIndex));
     s.Serialize <ushort>(default, name: "Padding");
Example #14
0
        public override void SerializeImpl(SerializerObject s)
        {
            AnimSetsPointer = s.SerializePointer(AnimSetsPointer, name: nameof(AnimSetsPointer));
            TileSetPointer  = s.SerializePointer(TileSetPointer, name: nameof(TileSetPointer));
            PalettesPointer = s.SerializePointer(PalettesPointer, name: nameof(PalettesPointer));
            AnimSetsCount   = s.Serialize <ushort>(AnimSetsCount, name: nameof(AnimSetsCount));
            PalettesCount   = s.Serialize <ushort>(PalettesCount, name: nameof(PalettesCount));

            AnimSets = s.DoAt(AnimSetsPointer, () => s.SerializeObjectArray <GBAVV_Map2D_AnimSet>(AnimSets, AnimSetsCount, name: nameof(AnimSets)));

            var tileSetLength = AnimSets.SelectMany(x => x.AnimationFrames).Select(x =>
                                                                                   x.TileOffset + (x.TileShapes.Select(t => (GBAVV_Map2D_AnimSet.TileShapes[t.ShapeIndex].x * GBAVV_Map2D_AnimSet.TileShapes[t.ShapeIndex].y) / 2).Sum())).Max();

            TileSet  = s.DoAt(TileSetPointer, () => s.SerializeArray <byte>(TileSet, tileSetLength, name: nameof(TileSet)));
            Palettes = s.DoAt(PalettesPointer, () => s.SerializeObjectArray <GBAVV_Map2D_ObjPal>(Palettes, PalettesCount, name: nameof(Palettes)));
        }
Example #15
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)
 {
     ID           = s.Serialize <uint>(ID, name: nameof(ID));
     Pointer_04   = s.SerializePointer(Pointer_04, name: nameof(Pointer_04));
     MapIndex     = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(MapIndex, name: nameof(MapIndex));
     TileSetIndex = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(TileSetIndex, name: nameof(TileSetIndex));
     PaletteIndex = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(PaletteIndex, name: nameof(PaletteIndex));
     s.Serialize <ushort>(default, name: "Padding");
        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));
            });
        }
Example #18
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));
            });
        }
Example #19
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            // Hack to get length
            Pointer smpOff1 = null;

            s.DoAt(Offset, () => {
                smpOff1 = s.SerializePointer(smpOff1, anchor: BaseOffset, name: nameof(smpOff1));
            });
            Samples = s.SerializePointerArray <MusyX_Sample>(Samples, (smpOff1 - Offset) / 4, anchor: BaseOffset, resolve: true, name: nameof(Samples));
        }
        public override void SerializeImpl(SerializerObject s)
        {
            ObjectsCount            = s.Serialize <ushort>(ObjectsCount, name: nameof(ObjectsCount));
            ObjGroupsCount          = s.Serialize <ushort>(ObjGroupsCount, name: nameof(ObjGroupsCount));
            ObjGroupsPointer        = s.SerializePointer(ObjGroupsPointer, name: nameof(ObjGroupsPointer));
            ObjParamsOffsetsPointer = s.SerializePointer(ObjParamsOffsetsPointer, name: nameof(ObjParamsOffsetsPointer));
            ObjParamsPointer        = s.SerializePointer(ObjParamsPointer, name: nameof(ObjParamsPointer));
            Pointer_10 = s.SerializePointer(Pointer_10, name: nameof(Pointer_10));

            if (ObjGroupsCount == 0)
            {
                Objects = s.DoAt(ObjGroupsPointer, () => s.SerializeObjectArray <GBAVV_Map2D_Object>(Objects, ObjectsCount, name: nameof(Objects)));
            }
            else
            {
                ObjGroups = s.DoAt(ObjGroupsPointer, () => s.SerializeObjectArray <GBAVV_Map2D_ObjGroups>(ObjGroups, ObjGroupsCount, name: nameof(ObjGroups)));
            }

            ObjParamsOffsets = s.DoAt(ObjParamsOffsetsPointer, () => s.SerializeArray <ushort>(ObjParamsOffsets, GetObjects.Max(x => x.ObjParamsIndex) + 1, name: nameof(ObjParamsOffsets)));

            s.DoAt(ObjParamsPointer, () =>
            {
                if (ObjParams == null)
                {
                    ObjParams = new byte[ObjParamsOffsets.Length][];
                }

                for (int i = 0; i < ObjParams.Length; i++)
                {
                    var length = i < ObjParams.Length - 1 ? ObjParamsOffsets[i + 1] - ObjParamsOffsets[i] : ObjParamsOffsetsPointer - (ObjParamsPointer + ObjParamsOffsets[i]);

                    // Make sure the length is reasonable (only really used for the last entry)
                    if (length < 0 || length > 64)
                    {
                        length = 8; // Default to 8

                        Debug.LogWarning($"Obj params length is invalid for entry {i}/{ObjParams.Length - 1}");
                    }

                    ObjParams[i] = s.SerializeArray <byte>(ObjParams[i], length, name: $"{nameof(ObjParams)}[{i}]");
                }
            });
        }
Example #21
0
        public override void SerializeImpl(SerializerObject s)
        {
            AnimationsPointer    = s.SerializePointer(AnimationsPointer, name: nameof(AnimationsPointer));
            FramePointersPointer = s.SerializePointer(FramePointersPointer, name: nameof(FramePointersPointer));
            Ushort_08            = s.Serialize <ushort>(Ushort_08, name: nameof(Ushort_08));
            AnimationsCount      = s.Serialize <ushort>(AnimationsCount, name: nameof(AnimationsCount));

            Animations    = s.DoAt(AnimationsPointer, () => s.SerializeObjectArray <GBAVV_Map2D_Animation>(Animations, AnimationsCount, name: nameof(Animations)));
            FramePointers = s.DoAt(FramePointersPointer, () => s.SerializePointerArray(FramePointers, Animations.SelectMany(x => x.FrameTable).Max() + 1, name: nameof(FramePointers)));

            if (AnimationFrames == null)
            {
                AnimationFrames = new GBAVV_Map2D_AnimationFrame[FramePointers.Length];
            }

            for (int i = 0; i < AnimationFrames.Length; i++)
            {
                AnimationFrames[i] = s.DoAt(FramePointers[i], () => s.SerializeObject <GBAVV_Map2D_AnimationFrame>(AnimationFrames[i], name: $"{nameof(AnimationFrames)}[{i}]"));
            }
        }
Example #22
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            InstrumentTable = s.SerializePointer <MusyX_InstrumentTable>(InstrumentTable, anchor: Offset, name: nameof(InstrumentTable));
            Unknown2List1   = s.SerializePointer <MusyX_UnknownTable>(Unknown2List1, anchor: Offset, resolve: true, name: nameof(Unknown2List1));
            Unknown2List2   = s.SerializePointer <MusyX_UnknownTable>(Unknown2List2, anchor: Offset, resolve: true, name: nameof(Unknown2List2));
            Unknown2List3   = s.SerializePointer <MusyX_UnknownTable>(Unknown2List3, anchor: Offset, resolve: true, name: nameof(Unknown2List3));
            UInt_10         = s.Serialize <uint>(UInt_10, name: nameof(UInt_10));
            UInt_14         = s.Serialize <uint>(UInt_14, name: nameof(UInt_14));
            SongTable       = s.SerializePointer <MusyX_SongTable>(SongTable, anchor: Offset, name: nameof(SongTable));
            SampleTable     = s.SerializePointer <MusyX_SampleTable>(SampleTable, anchor: Offset, name: nameof(SampleTable));


            // Read instrument table
            InstrumentTable.Resolve(s, onPreSerialize: st => {
                st.BaseOffset = Offset;
                st.EndOffset  = Unknown2List1.pointer;
            });

            // Read song table
            SongTable.Resolve(s, onPreSerialize: st => {
                st.BaseOffset = Offset;
                st.EndOffset  = SampleTable.pointer;
            });

            // Read sample table
            SampleTable.Resolve(s, onPreSerialize: st => {
                st.BaseOffset = Offset;
                //st.EndOffset = SampleTable.pointer;
            });
        }
        public override void SerializeImpl(SerializerObject s)
        {
            Width              = s.Serialize <int>(Width, name: nameof(Width));
            Height             = s.Serialize <int>(Height, name: nameof(Height));
            XPos               = s.SerializeObject <FixedPointInt>(XPos, onPreSerialize: fpi => fpi.PointPosition = 12, name: nameof(XPos));
            YPos               = s.SerializeObject <FixedPointInt>(YPos, onPreSerialize: fpi => fpi.PointPosition = 12, name: nameof(YPos));
            FramesPointer      = s.SerializePointer(FramesPointer, name: nameof(FramesPointer));
            FramesCountPointer = s.Serialize <uint>(FramesCountPointer, name: nameof(FramesCountPointer));

            if (s.DoAt(s.CurrentPointer, () => s.Serialize <int>(PaletteIndex, name: "PaletteValue")) >= 0x10)
            {
                PalettePointer = s.SerializePointer(PalettePointer, name: nameof(PalettePointer));
            }
            else
            {
                PaletteIndex = s.Serialize <int>(PaletteIndex, name: nameof(PaletteIndex));
            }

            IsFlipped = s.Serialize <bool>(IsFlipped, name: nameof(IsFlipped));
            s.SerializeArray <byte>(new byte[3], 3, name: "Padding");

            SerializeData(s);
        }
Example #24
0
        public override void SerializeImpl(SerializerObject s)
        {
            if (s.GameSettings.EngineVersion == EngineVersion.R1_PC_Edu || s.GameSettings.EngineVersion == EngineVersion.R1_PS1_Edu || s.GameSettings.EngineVersion == EngineVersion.R1_PC_Kit)
            {
                Unk1       = s.Serialize <uint>(Unk1, name: nameof(Unk1));
                XPosition  = s.Serialize <short>(XPosition, name: nameof(XPosition));
                YPosition  = s.Serialize <short>(YPosition, name: nameof(YPosition));
                UpIndex    = s.Serialize <byte>(UpIndex, name: nameof(UpIndex));
                DownIndex  = s.Serialize <byte>(DownIndex, name: nameof(DownIndex));
                LeftIndex  = s.Serialize <byte>(LeftIndex, name: nameof(LeftIndex));
                RightIndex = s.Serialize <byte>(RightIndex, name: nameof(RightIndex));
                Unk2       = s.SerializeArray <byte>(Unk2, 8, name: nameof(Unk2));
                LevelName  = s.Serialize <ushort>(LevelName, name: nameof(LevelName));

                string specialPath = null;
                var    m           = (R1_PCBaseManager)s.GameSettings.GetGameManager;

                if (m is R1_Kit_Manager kit)
                {
                    specialPath = kit.GetSpecialArchiveFilePath("USA");
                }
                else if (m is R1_PCEdu_Manager edu)
                {
                    specialPath = edu.GetSpecialArchiveFilePath(s.GameSettings.EduVolume);
                }

                if (specialPath != null)
                {
                    s.Log($"Name: {m.LoadArchiveFile<R1_PC_LocFile>(s.Context, specialPath, R1_PCBaseManager.R1_PC_ArchiveFileName.TEXT)?.TextDefine.ElementAtOrDefault(LevelName)?.Value ?? "(out of bounds)"}");
                }

                LoadingVig = s.SerializeString(LoadingVig, 9, name: nameof(LoadingVig));
                MapEntries = s.SerializeObjectArray(MapEntries, 46, name: nameof(MapEntries));
            }
            else
            {
                XPosition   = s.Serialize <short>(XPosition, name: nameof(XPosition));
                YPosition   = s.Serialize <short>(YPosition, name: nameof(YPosition));
                UpIndex     = s.Serialize <byte>(UpIndex, name: nameof(UpIndex));
                DownIndex   = s.Serialize <byte>(DownIndex, name: nameof(DownIndex));
                LeftIndex   = s.Serialize <byte>(LeftIndex, name: nameof(LeftIndex));
                RightIndex  = s.Serialize <byte>(RightIndex, name: nameof(RightIndex));
                RuntimeData = s.Serialize <ushort>(RuntimeData, name: nameof(RuntimeData));
                World       = s.Serialize <R1_World>(World, name: nameof(World));
                Level       = s.Serialize <byte>(Level, name: nameof(Level));
                Uint_0C     = s.Serialize <uint>(Uint_0C, name: nameof(Uint_0C));
                Pointer_10  = s.SerializePointer(Pointer_10, allowInvalid: true, name: nameof(Pointer_10));
            }
        }
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            // Serialize pointers
            LayersPointer      = s.SerializePointer(LayersPointer, name: nameof(LayersPointer));
            FramesPointer      = s.SerializePointer(FramesPointer, name: nameof(FramesPointer));
            UnkAnimDataPointer = s.SerializePointer(UnkAnimDataPointer, name: nameof(UnkAnimDataPointer)); // ^points to 8 bytes

            // Serialize values
            LayersPerFrame   = s.Serialize <ushort>(LayersPerFrame, name: nameof(LayersPerFrame));
            FrameCount       = s.Serialize <byte>(FrameCount, name: nameof(FrameCount));
            UnkAnimDataCount = s.Serialize <byte>(UnkAnimDataCount, name: nameof(UnkAnimDataCount));

            // Serialize layers
            s.DoAt(LayersPointer, () =>
            {
                // Serialize the layer pointers
                LayerPointers = s.SerializePointerArray(LayerPointers, FrameCount, name: nameof(LayerPointers));

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

                // Serialize the layers for each frame
                for (int i = 0; i < Layers.Length; i++)
                {
                    Layers[i] = s.SerializeObjectArray <R1_AnimationLayer>(Layers[i], LayersPerFrame, name: $"{nameof(Layers)} [{i}]");
                }
            });

            // Serialize frames
            s.DoAt(FramesPointer, () => Frames = s.SerializeObjectArray <R1_AnimationFrame>(Frames, FrameCount, name: nameof(Frames)));

            // Serialize unknown animation data
            s.DoAt(UnkAnimDataPointer, () => UnkAnimData = s.SerializeObjectArray <R1_R2UnknownAnimData>(UnkAnimData, UnkAnimDataCount, name: nameof(UnkAnimData)));
        }
Example #26
0
        public override void SerializeImpl(SerializerObject s)
        {
            if (ETA == null)
            {
                ETA = new R1_EventState[Lengths.Length][];
            }

            for (int i = 0; i < ETA.Length; i++)
            {
                s.DoAt(s.SerializePointer(ETA[i]?.FirstOrDefault()?.Offset, name: $"EtatPointers[{i}]"), () =>
                {
                    ETA[i] = s.SerializeObjectArray <R1_EventState>(ETA[i], Lengths[i], name: $"{nameof(ETA)}[{i}]");
                });
            }
        }
Example #27
0
        public override void SerializeImpl(SerializerObject s)
        {
            StringCount           = s.Serialize <uint>(StringCount, name: nameof(StringCount));
            StringPointersPointer = s.SerializePointer(StringPointersPointer, name: nameof(StringPointersPointer));

            Pointers = s.DoAt(StringPointersPointer, () => s.SerializePointerArray(Pointers, StringCount, name: nameof(Pointers)));

            if (Strings == null)
            {
                Strings = new string[Pointers.Length];
            }

            for (int i = 0; i < Strings.Length; i++)
            {
                Strings[i] = s.DoAt(Pointers[i], () => s.SerializeString(Strings[i], encoding: Encoding.GetEncoding(1252), name: $"{nameof(Strings)}[{i}]"));
            }
        }
Example #28
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            // Hack to get length of instrument table & instrument bytes
            Pointer instrOff1 = null;

            s.DoAt(Offset, () => {
                instrOff1 = s.SerializePointer(instrOff1, anchor: BaseOffset, name: nameof(instrOff1));
            });
            Instruments = s.SerializePointerArray(Instruments, (instrOff1 - Offset) / 4, anchor: BaseOffset, name: nameof(Instruments));
            if (InstrumentBytes == null)
            {
                InstrumentBytes = new byte[Instruments.Length][];
                for (int i = 0; i < Instruments.Length; i++)
                {
                    Pointer nextOff = (i < Instruments.Length - 1) ? Instruments[i + 1] : EndOffset;
                    s.DoAt(Instruments[i], () => {
                        InstrumentBytes[i] = s.SerializeArray <byte>(InstrumentBytes[i], nextOff - Instruments[i], name: $"{nameof(InstrumentBytes)}[{i}]");
                    });
                }
            }
        }
Example #29
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            Unk1 = s.Serialize <int>(Unk1, name: nameof(Unk1));
            Unk2 = s.Serialize <int>(Unk2, name: nameof(Unk2));

            LoadedEventsPointer = s.SerializePointer(LoadedEventsPointer, name: nameof(LoadedEventsPointer));

            AlwaysEventsPointer        = s.SerializePointer(AlwaysEventsPointer, name: nameof(AlwaysEventsPointer));
            FixImageDescriptorsPointer = s.SerializePointer(FixImageDescriptorsPointer, name: nameof(FixImageDescriptorsPointer));

            Unk3 = s.SerializeArray <byte>(Unk3, 30, name: nameof(Unk3));

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

            AlwaysEventsCount      = s.Serialize <ushort>(AlwaysEventsCount, name: nameof(AlwaysEventsCount));
            NormalEventCount       = s.Serialize <ushort>(NormalEventCount, name: nameof(NormalEventCount));
            AlwaysEventSlotsCount  = s.Serialize <ushort>(AlwaysEventSlotsCount, name: nameof(AlwaysEventSlotsCount));
            UShort_3A              = s.Serialize <ushort>(UShort_3A, name: nameof(UShort_3A));
            NumFixImageDescriptors = s.Serialize <ushort>(NumFixImageDescriptors, name: nameof(NumFixImageDescriptors));
            UShort_3E              = s.Serialize <ushort>(UShort_3E, name: nameof(UShort_3E));
            UShort_40              = s.Serialize <ushort>(UShort_40, name: nameof(UShort_40));
            UShort_42              = s.Serialize <ushort>(UShort_42, name: nameof(UShort_42));
            UShort_44              = s.Serialize <ushort>(UShort_44, name: nameof(UShort_44));
            UShort_46              = s.Serialize <ushort>(UShort_46, name: nameof(UShort_46));
            DevPointer_48          = s.Serialize <uint>(DevPointer_48, name: nameof(DevPointer_48));

            ZDCDataPointer   = s.SerializePointer(ZDCDataPointer, name: nameof(ZDCDataPointer));
            ZDCArray1Pointer = s.SerializePointer(ZDCArray1Pointer, name: nameof(ZDCArray1Pointer));
            ZDCArray2Pointer = s.SerializePointer(ZDCArray2Pointer, name: nameof(ZDCArray2Pointer));
            ZDCArray3Pointer = s.SerializePointer(ZDCArray3Pointer, name: nameof(ZDCArray3Pointer));

            EventLinkTable = s.SerializeArray <ushort>(EventLinkTable, LoadedEventCount, name: nameof(EventLinkTable));

            s.DoAt(FixImageDescriptorsPointer, () => FixImageDescriptors = s.SerializeObjectArray <R1_ImageDescriptor>(FixImageDescriptors, NumFixImageDescriptors, name: nameof(FixImageDescriptors)));

            s.DoAt(LoadedEventsPointer, () => Events       = s.SerializeObjectArray <R1_R2EventData>(Events, LoadedEventCount, name: nameof(Events)));
            s.DoAt(AlwaysEventsPointer, () => AlwaysEvents = s.SerializeObjectArray <R1_R2EventData>(AlwaysEvents, AlwaysEventsCount, name: nameof(AlwaysEvents)));

            s.DoAt(ZDCDataPointer, () => ZDC = s.SerializeObjectArray <R1_ZDCData>(ZDC, 237, name: nameof(ZDC)));
            s.DoAt(ZDCArray1Pointer, () => ZDCTriggerFlags = s.SerializeArray <ZDC_TriggerFlags>(ZDCTriggerFlags, 237, name: nameof(ZDCTriggerFlags)));
            s.DoAt(ZDCArray2Pointer, () => ZDCArray2       = s.SerializeArray <ushort>(ZDCArray2, 474, name: nameof(ZDCArray2)));
            s.DoAt(ZDCArray3Pointer, () => ZDCArray3       = s.SerializeObjectArray <R1_R2ZDCUnkData>(ZDCArray3, 16, name: nameof(ZDCArray3)));
        }
Example #30
0
        public override void SerializeImpl(SerializerObject s)
        {
            Height              = s.Serialize <byte>(Height, name: nameof(Height));
            Width               = s.Serialize <byte>(Width, name: nameof(Width));
            PivotX              = s.Serialize <byte>(PivotX, name: nameof(PivotX));
            PivotY              = s.Serialize <byte>(PivotY, name: nameof(PivotY));
            Byte_04             = s.Serialize <byte>(Byte_04, name: nameof(Byte_04));
            AnimationCount      = s.Serialize <byte>(AnimationCount, name: nameof(AnimationCount));
            Bytes_06            = s.SerializeArray <byte>(Bytes_06, 2, name: nameof(Bytes_06));
            Flags               = s.Serialize <byte>(Flags, name: nameof(Flags));
            Bytes_09            = s.SerializeArray <byte>(Bytes_09, 7, name: nameof(Bytes_09));
            PalettePointer      = s.SerializePointer(PalettePointer, name: nameof(PalettePointer));
            AnimationsPointer   = s.SerializePointer(AnimationsPointer, name: nameof(AnimationsPointer));
            FramesPointer       = s.SerializePointer(FramesPointer, name: nameof(FramesPointer));
            PatternsPointer     = s.SerializePointer(PatternsPointer, name: nameof(PatternsPointer));
            TileIndicesPointer  = s.SerializePointer(TileIndicesPointer, name: nameof(TileIndicesPointer));
            GraphicsDataPointer = s.SerializePointer <GBAIsometric_RHR_GraphicsData>(GraphicsDataPointer, resolve: true, name: nameof(GraphicsDataPointer));
            Bytes_28            = s.SerializeArray <byte>(Bytes_28, 8, name: nameof(Bytes_28));
            NamePointer         = s.SerializePointer(NamePointer, name: nameof(NamePointer));

            Palette = s.DoAt(PalettePointer, () => s.SerializeObjectArray <RGBA5551Color>(Palette, Is8Bit ? 256 : 16, name: nameof(Palette)));
            Name    = s.DoAt(NamePointer, () => s.SerializeString(Name, name: nameof(Name)));

            Animations = s.DoAt(AnimationsPointer, () => s.SerializeObjectArray <GBAIsometric_RHR_Animation>(Animations, AnimationCount, name: nameof(Animations)));
            Frames     = s.DoAt(FramesPointer, () => s.SerializeObjectArray <GBAIsometric_RHR_AnimFrame>(Frames, Animations?.Max(a => a.StartFrameIndex + a.FrameCount) ?? 0, name: nameof(Frames)));
            if (Patterns == null)
            {
                Patterns = new Dictionary <int, GBAIsometric_RHR_AnimPattern[]>();
                foreach (var frame in Frames)
                {
                    if (frame.PatternIndex == 0xFFFF)
                    {
                        continue;
                    }
                    if (!Patterns.ContainsKey(frame.PatternIndex))
                    {
                        var key = frame.PatternIndex;
                        List <GBAIsometric_RHR_AnimPattern> tempList = new List <GBAIsometric_RHR_AnimPattern>();
                        s.DoAt(PatternsPointer + 2 * key, () => {
                            GBAIsometric_RHR_AnimPattern curUnk = null;
                            while (curUnk == null || !curUnk.IsLastPattern)
                            {
                                curUnk = s.SerializeObject <GBAIsometric_RHR_AnimPattern>(default, name: $"Patterns[{key}][{tempList.Count}]");