Пример #1
0
 public override void SerializeImpl(SerializerObject s)
 {
     DirectoryIdentifierLength = s.Serialize <byte>(DirectoryIdentifierLength, name: nameof(DirectoryIdentifierLength));
     if (DirectoryIdentifierLength == 0)
     {
         return;
     }
     ExtendedAttributeRecordLength = s.Serialize <byte>(ExtendedAttributeRecordLength, name: nameof(ExtendedAttributeRecordLength));
     ExtentLBA            = s.Serialize <uint>(ExtentLBA, name: nameof(ExtentLBA));
     ParentDirectoryIndex = s.Serialize <ushort>(ParentDirectoryIndex, name: nameof(ParentDirectoryIndex));
     DirectoryIdentifier  = s.SerializeString(DirectoryIdentifier, length: DirectoryIdentifierLength, name: nameof(DirectoryIdentifier));
     if (DirectoryIdentifierLength % 2 != 0)
     {
         Padding = s.Serialize <byte>(Padding, name: nameof(Padding));
     }
 }
Пример #2
0
        public override void SerializeImpl(SerializerObject s)
        {
            var manager = ((GBA_Milan_Manager)s.GameSettings.GetGameManager);

            Pointers = s.SerializePointerArray(Pointers, manager.Milan_LocTableLength * manager.Milan_LocTableLangCount, 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}]"));
            }
        }
Пример #3
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}]"));
            }
        }
Пример #4
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}]");
Пример #5
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            SampleLength       = s.Serialize <uint>(SampleLength, name: nameof(SampleLength));
            SampleLoopStart    = s.Serialize <uint>(SampleLoopStart, name: nameof(SampleLoopStart));
            SampleLoopLength   = s.Serialize <uint>(SampleLoopLength, name: nameof(SampleLoopLength));
            Volume             = s.Serialize <byte>(Volume, name: nameof(Volume));
            FineTune           = s.Serialize <sbyte>(FineTune, name: nameof(FineTune));
            Type               = s.Serialize <byte>(Type, name: nameof(Type));
            Panning            = s.Serialize <byte>(Panning, name: nameof(Panning));
            RelativeNoteNumber = s.Serialize <sbyte>(RelativeNoteNumber, name: nameof(RelativeNoteNumber));
            DataType           = s.Serialize <byte>(DataType, name: nameof(DataType));
            SampleName         = s.SerializeString(SampleName, 22, Encoding.ASCII, name: nameof(SampleName));

            if (BitHelpers.ExtractBits(Type, 1, 4) == 1)
            {
                SampleData16 = s.SerializeArray <short>(SampleData16, SampleLength / 2, name: nameof(SampleData16));
            }
            else
            {
                SampleData8 = s.SerializeArray <sbyte>(SampleData8, SampleLength, name: nameof(SampleData8));
            }
        }
Пример #6
0
        public override void SerializeImpl(SerializerObject s)
        {
            Length = s.Serialize <byte>(Length, name: nameof(Length));
            if (Length == 0)
            {
                return;
            }
            ExtendedAttributeRecord = s.Serialize <byte>(ExtendedAttributeRecord, name: nameof(ExtendedAttributeRecord));

            ExtentLBA      = s.Serialize <uint>(ExtentLBA, name: nameof(ExtentLBA));
            BigEndianValue = s.SerializeArray <byte>(BigEndianValue, 4, name: nameof(BigEndianValue));

            ExtentSize     = s.Serialize <uint>(ExtentSize, name: nameof(ExtentSize));
            BigEndianValue = s.SerializeArray <byte>(BigEndianValue, 4, name: nameof(BigEndianValue));

            RecordingDateTime      = s.SerializeArray <byte>(RecordingDateTime, 7, name: nameof(RecordingDateTime));
            FileFlags              = s.Serialize <RecordFileFlags>(FileFlags, name: nameof(FileFlags));
            InterleaveFileUnitSize = s.Serialize <byte>(InterleaveFileUnitSize, name: nameof(InterleaveFileUnitSize));
            InterleaveFileGapSize  = s.Serialize <byte>(InterleaveFileGapSize, name: nameof(InterleaveFileGapSize));

            VolumeSequenceNumber = s.Serialize <ushort>(VolumeSequenceNumber, name: nameof(VolumeSequenceNumber));
            BigEndianValue       = s.SerializeArray <byte>(BigEndianValue, 2, name: nameof(BigEndianValue));

            FileIdentifierLength = s.Serialize <byte>(FileIdentifierLength, name: nameof(FileIdentifierLength));
            FileIdentifier       = s.SerializeString(FileIdentifier, length: FileIdentifierLength, name: nameof(FileIdentifier));

            if (s.CurrentPointer - Offset < Length && FileIdentifierLength % 2 != 0)
            {
                Padding = s.Serialize <byte>(Padding, name: nameof(Padding));
            }
            if (s.CurrentPointer - Offset < Length)
            {
                SystemUse = s.SerializeArray <byte>(SystemUse, Length - (s.CurrentPointer - Offset), name: nameof(SystemUse));
            }

            s.Goto(Offset + Length);
        }
Пример #7
0
        public override void SerializeImpl(SerializerObject s)
        {
            NamePointer           = s.SerializePointer(NamePointer, name: nameof(NamePointer));
            MapWidth              = s.Serialize <ushort>(MapWidth, name: nameof(MapWidth));
            MapHeight             = s.Serialize <ushort>(MapHeight, name: nameof(MapHeight));
            TileSetCount_Total    = s.Serialize <ushort>(TileSetCount_Total, name: nameof(TileSetCount_Total));
            TileSetCount_4bpp     = s.Serialize <ushort>(TileSetCount_4bpp, name: nameof(TileSetCount_4bpp));
            TileSetPointer        = s.SerializePointer(TileSetPointer, name: nameof(TileSetPointer));
            MapTilesPointer       = s.SerializePointer(MapTilesPointer, name: nameof(MapTilesPointer));
            MapLayerPointers      = s.SerializePointerArray(MapLayerPointers, 4, name: nameof(MapLayerPointers));
            TilePalettePointer    = s.SerializePointer(TilePalettePointer, name: nameof(TilePalettePointer));
            CollisionWidth        = s.Serialize <ushort>(CollisionWidth, name: nameof(CollisionWidth));
            CollisionHeight       = s.Serialize <ushort>(CollisionHeight, name: nameof(CollisionHeight));
            CollisionMapPointer   = s.SerializePointer(CollisionMapPointer, name: nameof(CollisionMapPointer));
            CollisionTilesPointer = s.SerializePointer(CollisionTilesPointer, name: nameof(CollisionTilesPointer));
            CollisionTypePointers = s.SerializePointer(CollisionTypePointers, name: nameof(CollisionTypePointers));
            Pointer_38            = s.SerializePointer(Pointer_38, name: nameof(Pointer_38));
            Pointer_3C            = s.SerializePointer(Pointer_3C, name: nameof(Pointer_3C));
            Pointer_40            = s.SerializePointer(Pointer_40, name: nameof(Pointer_40));
            Pointer_44            = s.SerializePointer(Pointer_44, name: nameof(Pointer_44));
            Pointer_48            = s.SerializePointer(Pointer_48, name: nameof(Pointer_48));
            Pointer_4C            = s.SerializePointer(Pointer_4C, name: nameof(Pointer_4C));
            XPosition             = s.SerializeObject <FixedPointInt>(XPosition, name: nameof(XPosition));
            YPosition             = s.SerializeObject <FixedPointInt>(YPosition, name: nameof(YPosition));

            Name = s.DoAt(NamePointer, () => s.SerializeString(Name, name: nameof(Name)));

            if (!SerializeData)
            {
                return;
            }

            TileSet = s.DoAt(TileSetPointer, () => s.SerializeObject <GBAVV_Isometric_TileSet>(TileSet, x =>
            {
                x.TileSetCount_Total = TileSetCount_Total;
                x.TileSetCount_4bpp  = TileSetCount_4bpp;
            }, name: nameof(TileSet)));

            if (MapLayers == null)
            {
                MapLayers = new GBAVV_Isometric_MapLayer[MapLayerPointers.Length];
            }

            for (int i = 0; i < MapLayers.Length; i++)
            {
                MapLayers[i] = s.DoAt(MapLayerPointers[i], () => s.SerializeObject <GBAVV_Isometric_MapLayer>(MapLayers[i], name: $"{nameof(MapLayers)}[{i}]"));
            }

            var mapTilesLength = MapLayers.SelectMany(x => x.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.Is8Bpp = true, name: nameof(MapTiles)));
            TilePalette = s.DoAt(TilePalettePointer, () => s.SerializeObjectArray <RGBA5551Color>(TilePalette, 256, name: nameof(TilePalette)));

            CollisionMap   = s.DoAt(CollisionMapPointer, () => s.SerializeArray <ushort>(CollisionMap, CollisionWidth * CollisionHeight, name: nameof(CollisionMap)));
            CollisionTiles = s.DoAt(CollisionTilesPointer, () => s.SerializeObjectArray <GBAVV_Isometric_CollisionTile>(CollisionTiles, CollisionMap.Max() + 1, name: nameof(CollisionTiles)));
            CollisionTypes = s.DoAt(CollisionTypePointers, () => s.SerializeObjectArray <GBAVV_Isometric_CollisionType>(CollisionTypes, CollisionTiles.Max(x => x.TypeIndex) + 1, name: nameof(CollisionTypes)));

            s.DoAt(Pointer_4C, () =>
            {
                if (Pointer_4C_Structs == null)
                {
                    var objects = new List <GBAVV_Isometric_UnkStruct_0>();
                    var index   = 0;

                    while (true)
                    {
                        var obj = s.SerializeObject <GBAVV_Isometric_UnkStruct_0>(default, name: $"{nameof(Pointer_4C_Structs)}[{index++}]");
Пример #8
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            // Get the pointer table
            var pointerTable = PointerTables.R1_DSi_PointerTable(s.GameSettings.GameModeSelection, this.Offset.file);

            s.DoAt(pointerTable[R1_DSi_Pointer.WorldLevelOffsetTable],
                   () => WorldLevelOffsetTable = s.SerializeArray <byte>(WorldLevelOffsetTable, 8, name: nameof(WorldLevelOffsetTable)));

            // Get the global level index
            var levelIndex = WorldLevelOffsetTable[s.GameSettings.World] + (s.GameSettings.Level - 1);

            DES_Ray = s.DoAt(pointerTable[R1_DSi_Pointer.DES_Ray], () => s.SerializeObject <R1_GBA_EventGraphicsData>(DES_Ray, name: nameof(DES_Ray)));
            ETA_Ray = s.DoAt(pointerTable.TryGetItem(R1_DSi_Pointer.ETA_Ray), () => s.SerializeObject <R1_GBA_ETA>(ETA_Ray, x => x.Lengths = new byte[] { 66, 12, 34, 53, 14, 14, 1, 2 }, name: nameof(ETA_Ray)));

            DES_RayLittle = s.DoAt(pointerTable[R1_DSi_Pointer.DES_RayLittle], () => s.SerializeObject <R1_GBA_EventGraphicsData>(DES_RayLittle, name: nameof(DES_RayLittle)));

            DES_Clock = s.DoAt(pointerTable[R1_DSi_Pointer.DES_Clock], () => s.SerializeObject <R1_GBA_EventGraphicsData>(DES_Clock, name: nameof(DES_Clock)));
            ETA_Clock = s.DoAt(pointerTable.TryGetItem(R1_DSi_Pointer.ETA_Clock), () => s.SerializeObject <R1_GBA_ETA>(ETA_Clock, x => x.Lengths = new byte[] { 3 }, name: nameof(ETA_Clock)));

            DES_Div = s.DoAt(pointerTable[R1_DSi_Pointer.DES_Div], () => s.SerializeObject <R1_GBA_EventGraphicsData>(DES_Div, name: nameof(DES_Div)));
            ETA_Div = s.DoAt(pointerTable.TryGetItem(R1_DSi_Pointer.ETA_Div), () => s.SerializeObject <R1_GBA_ETA>(ETA_Div, x => x.Lengths = new byte[] { 1, 1, 1, 1, 1, 1, 2, 2, 12, 12, 4 }, name: nameof(ETA_Div)));

            DES_Map = s.DoAt(pointerTable[R1_DSi_Pointer.DES_Map], () => s.SerializeObject <R1_GBA_EventGraphicsData>(DES_Map, name: nameof(DES_Map)));
            ETA_Map = s.DoAt(pointerTable.TryGetItem(R1_DSi_Pointer.ETA_Map), () => s.SerializeObject <R1_GBA_ETA>(ETA_Map, x => x.Lengths = new byte[] { 64, 1, 19, 1, 1, 69, 3 }, name: nameof(ETA_Map)));

            // Serialize data from the ROM
            if (s.GameSettings.R1_World != R1_World.Menu)
            {
                s.DoAt((s.GameSettings.R1_World == R1_World.Jungle ? pointerTable[R1_DSi_Pointer.JungleMaps] : pointerTable[R1_DSi_Pointer.LevelMaps]) + (levelIndex * 32),
                       () => LevelMapData = s.SerializeObject <R1_GBA_LevelMapData>(LevelMapData, name: nameof(LevelMapData)));
            }

            s.DoAt(pointerTable[R1_DSi_Pointer.BackgroundVignette],
                   () => BackgroundVignettes = s.SerializeObjectArray <R1_GBA_BackgroundVignette>(BackgroundVignettes, 48, name: nameof(BackgroundVignettes)));

            WorldMapVignette = s.SerializeObject <R1_GBA_WorldMapVignette>(WorldMapVignette, name: nameof(WorldMapVignette));

            // Serialize the level event data
            if (s.GameSettings.R1_World != R1_World.Menu)
            {
                LevelEventData = new R1_GBA_LevelEventData();
                LevelEventData.SerializeData(s, pointerTable[R1_DSi_Pointer.EventGraphicsPointers], pointerTable[R1_DSi_Pointer.EventDataPointers], pointerTable[R1_DSi_Pointer.EventGraphicsGroupCountTablePointers], pointerTable[R1_DSi_Pointer.LevelEventGraphicsGroupCounts]);
            }

            s.DoAt(pointerTable[R1_DSi_Pointer.SpecialPalettes], () => Palettes = s.SerializeObjectArray <R1_DSi_PaletteReference>(Palettes, 10, name: nameof(Palettes)));

            // Serialize strings
            s.DoAt(pointerTable[R1_DSi_Pointer.StringPointers], () =>
            {
                StringPointerTable = s.SerializePointerArray(StringPointerTable, 5 * 394, name: nameof(StringPointerTable));

                if (Strings == null)
                {
                    Strings = new string[5][];
                }

                var enc = new Encoding[]
                {
                    // Spanish
                    Encoding.GetEncoding(1252),
                    // English
                    Encoding.GetEncoding(437),
                    // French
                    Encoding.GetEncoding(1252),
                    // Italian
                    Encoding.GetEncoding(1252),
                    // German
                    Encoding.GetEncoding(437),
                };

                for (int i = 0; i < Strings.Length; i++)
                {
                    if (Strings[i] == null)
                    {
                        Strings[i] = new string[394];
                    }

                    for (int j = 0; j < Strings[i].Length; j++)
                    {
                        s.DoAt(StringPointerTable[i * 394 + j], () => Strings[i][j] = s.SerializeString(Strings[i][j], encoding: enc[i], name: $"{nameof(Strings)}[{i}][{j}]"));
                    }
                }
            });

            // Serialize tables
            s.DoAt(pointerTable[R1_DSi_Pointer.TypeZDC], () => TypeZDC       = s.SerializeObjectArray <R1_ZDCEntry>(TypeZDC, 262, name: nameof(TypeZDC)));
            s.DoAt(pointerTable[R1_DSi_Pointer.ZdcData], () => ZdcData       = s.SerializeObjectArray <R1_ZDCData>(ZdcData, 200, name: nameof(ZdcData)));
            s.DoAt(pointerTable[R1_DSi_Pointer.EventFlags], () => EventFlags = s.SerializeArray <R1_EventFlags>(EventFlags, 262, name: nameof(EventFlags)));

            if (s.GameSettings.R1_World != R1_World.Menu)
            {
                WorldVignetteIndicesPointers = s.DoAt(pointerTable[R1_DSi_Pointer.WorldVignetteIndices], () => s.SerializePointerArray(WorldVignetteIndicesPointers, 7, name: nameof(WorldVignetteIndicesPointers)));
                WorldVignetteIndices         = s.DoAt(WorldVignetteIndicesPointers[s.GameSettings.World], () => s.SerializeArray <byte>(WorldVignetteIndices, 8, name: nameof(WorldVignetteIndices))); // The max size is 8

                // Get the background indices
                s.DoAt(pointerTable[R1_DSi_Pointer.LevelMapsBGIndices] + (levelIndex * 32), () =>
                {
                    LevelMapData.Unk_10                  = s.Serialize <byte>(LevelMapData.Unk_10, name: nameof(LevelMapData.Unk_10));
                    LevelMapData.Unk_11                  = s.Serialize <byte>(LevelMapData.Unk_11, name: nameof(LevelMapData.Unk_11));
                    LevelMapData.BackgroundIndex         = s.Serialize <byte>(LevelMapData.BackgroundIndex, name: nameof(LevelMapData.BackgroundIndex));
                    LevelMapData.ParallaxBackgroundIndex = s.Serialize <byte>(LevelMapData.ParallaxBackgroundIndex, name: nameof(LevelMapData.ParallaxBackgroundIndex));
                });
            }

            WorldInfos = s.DoAt(pointerTable[R1_DSi_Pointer.WorldInfo], () => s.SerializeObjectArray <R1_WorldMapInfo>(WorldInfos, 24, name: nameof(WorldInfos)));
        }
        public override void SerializeImpl(SerializerObject s)
        {
            StringOffsets = s.SerializeArray <uint>(StringOffsets, Count * LanguageCount, name: nameof(StringOffsets));

            if (Strings == null)
            {
                Strings = Enumerable.Range(0, LanguageCount).Select(x => new string[Count]).ToArray();
            }

            for (int i = 0; i < Count; i++)
            {
                for (int j = 0; j < LanguageCount; j++)
                {
                    if (StringOffsets[i] != 0)
                    {
                        Strings[j][i] = s.DoAt(Offset + StringOffsets[i * LanguageCount + j] + 3, () => s.SerializeString(Strings[j][i], encoding: Encoding.GetEncoding(1252), name: $"{nameof(Strings)}[{j}][{i}]"));
                    }
                }
            }
        }