Example #1
0
        public void SerializeData(SerializerObject s, Pointer eventGraphicsPointers, Pointer eventDataPointers, Pointer eventGraphicsGroupCountTablePointers, Pointer levelEventGraphicsGroupCounts)
        {
            // Get the global level index
            var levelIndex = ((R1_GBA_Manager)s.Context.Settings.GetGameManager).LoadData(s.Context).WorldLevelOffsetTable[s.GameSettings.World] + (s.GameSettings.Level - 1);

            // Serialize data
            s.DoAt(eventGraphicsPointers + (uint)(4 * levelIndex),
                   () => EventGraphicsPointer = s.SerializePointer(EventGraphicsPointer, name: nameof(EventGraphicsPointer)));
            s.DoAt(eventDataPointers + (uint)(4 * levelIndex),
                   () => EventDataPointer = s.SerializePointer(EventDataPointer, name: nameof(EventDataPointer)));
            s.DoAt(eventGraphicsGroupCountTablePointers + (uint)(4 * levelIndex),
                   () => GraphicsGroupCountTablePointer = s.SerializePointer(GraphicsGroupCountTablePointer, name: nameof(GraphicsGroupCountTablePointer)));
            s.DoAt(levelEventGraphicsGroupCounts + (uint)(4 * levelIndex),
                   () => GraphicsGroupCount = s.Serialize <uint>(GraphicsGroupCount, name: nameof(GraphicsGroupCount)));


            // Parse data from pointers
            s.DoAt(GraphicsGroupCountTablePointer, () => GraphicsGroupCountTable = s.SerializeArray <byte>(GraphicsGroupCountTable, GraphicsGroupCount, name: nameof(GraphicsGroupCountTable)));
            s.DoAt(EventGraphicsPointer, () => GraphicDataPointers = s.SerializePointerArray(GraphicDataPointers, GraphicsGroupCount, name: nameof(GraphicDataPointers)));

            if (GraphicData == null)
            {
                GraphicData = new R1_GBA_EventGraphicsData[GraphicsGroupCount];
            }

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

            s.DoAt(EventDataPointer, () => EventDataPointers = s.SerializePointerArray(EventDataPointers, GraphicsGroupCount, name: nameof(EventDataPointers)));

            if (EventData == null)
            {
                EventData = new R1_GBA_EventData[GraphicsGroupCount][];
            }

            for (int i = 0; i < EventData.Length; i++)
            {
                if (EventDataPointers[i] != null)
                {
                    s.DoAt(EventDataPointers[i], () => EventData[i] = s.SerializeObjectArray <R1_GBA_EventData>(EventData[i], GraphicsGroupCountTable[i], name: $"{nameof(EventData)}[{i}]"));
                }
                else
                {
                    EventData[i] = new R1_GBA_EventData[0];
                }
            }
        }
Example #2
0
        public override void SerializeImpl(SerializerObject s)
        {
            MapLayersPointers    = s.SerializePointerArray(MapLayersPointers, 4, name: nameof(MapLayersPointers));
            CollisionDataPointer = s.SerializePointer(CollisionDataPointer, name: nameof(CollisionDataPointer));
            LayersBlockPointer   = s.SerializePointer(LayersBlockPointer, name: nameof(LayersBlockPointer));
            HasDataBlockHeader   = s.Serialize <bool>(HasDataBlockHeader, name: nameof(HasDataBlockHeader));
            s.SerializeArray <byte>(new byte[3], 3, name: "Padding");
            ObjDataPointer         = s.SerializePointer(ObjDataPointer, name: nameof(ObjDataPointer));
            ObjDataUnkTablePointer = s.SerializePointer(ObjDataUnkTablePointer, name: nameof(ObjDataUnkTablePointer));
            s.SerializeArray <byte>(new byte[12], 12, name: "Padding"); // Always 0, but still part of the same struct

            if (MapLayers == null)
            {
                MapLayers = new GBAVV_Map2D_MapLayer[MapLayersPointers.Length];
            }

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

            CollisionLayer = s.DoAt(CollisionDataPointer, () => s.SerializeObject <GBAVV_Map2D_MapLayer>(CollisionLayer, name: nameof(CollisionLayer)));

            LayersBlock = s.DoAt(LayersBlockPointer, () => s.SerializeObject <GBAVV_Map2D_LayersBlock>(LayersBlock, x =>
            {
                x.HasHeader = HasDataBlockHeader;
                x.MapData   = this;
            }, name: nameof(LayersBlock)));

            ObjData         = s.DoAt(ObjDataPointer, () => s.SerializeObject <GBAVV_Map2D_ObjData>(ObjData, name: nameof(ObjData)));
            ObjDataUnkTable = s.DoAt(ObjDataUnkTablePointer, () => s.SerializeObject <GBAVV_Map2D_ObjDataUnkTable>(ObjDataUnkTable, name: nameof(ObjDataUnkTable)));
        }
Example #3
0
        public override void SerializeImpl(SerializerObject s)
        {
            MapsCount           = s.Serialize <uint>(MapsCount, name: nameof(MapsCount));
            MapsPointer         = s.SerializePointer(MapsPointer, name: nameof(MapsPointer));
            BonusMapPointer     = s.SerializePointer(BonusMapPointer, name: nameof(BonusMapPointer));
            ChallengeMapPointer = s.SerializePointer(ChallengeMapPointer, name: nameof(ChallengeMapPointer));

            MapsPointers = s.DoAt(MapsPointer, () => s.SerializePointerArray(MapsPointers, MapsCount, name: nameof(MapsPointers)));

            if (Maps == null)
            {
                Maps = new GBAVV_MapInfo[MapsCount];
            }

            for (int i = 0; i < Maps.Length; i++)
            {
                if (SerializeAll || (LevInfo?.MapIndex == i && LevInfo?.MapType == GBAVV_BaseManager.LevInfo.Type.Normal))
                {
                    Maps[i] = s.DoAt(MapsPointers[i], () => s.SerializeObject <GBAVV_MapInfo>(Maps[i], name: $"{nameof(Maps)}[{i}]"));
                }
            }

            if (SerializeAll || LevInfo?.MapType == GBAVV_BaseManager.LevInfo.Type.Bonus)
            {
                BonusMap = s.DoAt(BonusMapPointer, () => s.SerializeObject <GBAVV_MapInfo>(BonusMap, name: nameof(BonusMap)));
            }

            if (SerializeAll || LevInfo?.MapType == GBAVV_BaseManager.LevInfo.Type.Challenge)
            {
                ChallengeMap = s.DoAt(ChallengeMapPointer, () => s.SerializeObject <GBAVV_MapInfo>(ChallengeMap, name: nameof(ChallengeMap)));
            }
        }
Example #4
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            TextureBlockChecksum = s.DoChecksum(new Checksum8Calculator(false), () =>
            {
                s.DoXOR((byte)(s.GameSettings.EngineVersion == EngineVersion.R1_PC || s.GameSettings.EngineVersion == EngineVersion.R1_PocketPC ? 0 : 0xFF), () =>
                {
                    // Read the offset table for the textures, based from the start of the tile texture arrays
                    TexturesOffsetTable = s.SerializePointerArray(TexturesOffsetTable, 1200, s.CurrentPointer + 1200 * 4 + 3 * 4, name: nameof(TexturesOffsetTable));

                    // Read the textures count
                    TexturesCount = s.Serialize <uint>(TexturesCount, name: nameof(TexturesCount));
                    NonTransparentTexturesCount = s.Serialize <uint>(NonTransparentTexturesCount, name: nameof(NonTransparentTexturesCount));
                    TexturesDataTableCount      = s.Serialize <uint>(TexturesDataTableCount, name: nameof(TexturesDataTableCount));
                });

                TexturesChecksum = s.DoChecksum(new Checksum8Calculator(), () =>
                {
                    // Serialize the textures
                    NonTransparentTextures = s.SerializeObjectArray <R1_PC_TileTexture>(NonTransparentTextures, NonTransparentTexturesCount, name: nameof(NonTransparentTextures));
                    TransparentTextures    = s.SerializeObjectArray <R1_PC_TransparentTileTexture>(TransparentTextures, TexturesCount - NonTransparentTexturesCount, name: nameof(TransparentTextures));

                    // Serialize the fourth unknown value
                    Unknown4 = s.SerializeArray <byte>(Unknown4, 32, name: nameof(Unknown4));
                }, ChecksumPlacement.After, calculateChecksum: s.GameSettings.EngineVersion == EngineVersion.R1_PC || s.GameSettings.EngineVersion == EngineVersion.R1_PocketPC, name: nameof(TexturesChecksum));
            }, ChecksumPlacement.Before, calculateChecksum: s.GameSettings.EngineVersion == EngineVersion.R1_PC_Kit || s.GameSettings.EngineVersion == EngineVersion.R1_PC_Edu, name: nameof(TextureBlockChecksum));
        }
Example #5
0
        /// <summary>
        /// Serializes the data
        /// </summary>
        /// <param name="serializer">The serializer</param>
        public override void SerializeImpl(SerializerObject s)
        {
            Pointer BaseAddress = s.CurrentPointer;

            PointerCount = s.Serialize <uint>(PointerCount, name: nameof(PointerCount));

            // Serialize the block pointers. These aren't memory pointers but file pointers, so subtract the base address
            BlockPointers = s.SerializePointerArray(BlockPointers, PointerCount, anchor: BaseAddress, name: nameof(BlockPointers));
            FileSize      = s.Serialize <uint>(FileSize, name: nameof(FileSize));
        }
Example #6
0
        //public GBAIsometric_Spyro_SpriteMap Index3Map { get; set; } // TODO: What is this?

        public override void SerializeImpl(SerializerObject s)
        {
            MapLayerPointers = s.SerializePointerArray(MapLayerPointers, 4, name: nameof(MapLayerPointers));

            if (Is2D)
            {
                if (s.GameSettings.EngineVersion == EngineVersion.GBAIsometric_Spyro2)
                {
                    Collision2DIndex = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(Collision2DIndex, x => x.HasPadding = true, name: nameof(Collision2DIndex));
                }

                TilePaletteIndex = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(TilePaletteIndex, x => x.HasPadding = true, name: nameof(TilePaletteIndex));

                if (s.GameSettings.EngineVersion == EngineVersion.GBAIsometric_Spyro3)
                {
                    Collision2DIndex = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(Collision2DIndex, x => x.HasPadding = true, name: nameof(Collision2DIndex));
                }

                ObjPaletteIndex = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(ObjPaletteIndex, x => x.HasPadding = true, name: nameof(ObjPaletteIndex));

                if (s.GameSettings.EngineVersion == EngineVersion.GBAIsometric_Spyro3)
                {
                    ID = s.Serialize <uint>(ID, name: nameof(ID));
                }
            }
            else
            {
                TilePaletteIndex = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(TilePaletteIndex, x => x.HasPadding = true, name: nameof(TilePaletteIndex));
                Collision3DIndex = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(Collision3DIndex, x => x.HasPadding = true, name: nameof(Collision3DIndex));
                ObjPaletteIndex  = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(ObjPaletteIndex, x => x.HasPadding = true, name: nameof(ObjPaletteIndex));
                Index3           = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(Index3, x => x.HasPadding = true, name: nameof(Index3));
                ID = s.Serialize <uint>(ID, name: nameof(ID));
            }

            if (SerializeDataForID == ID || ForceSerializeAll)
            {
                if (MapLayers == null)
                {
                    MapLayers = new GBAIsometric_Spyro_MapLayer[MapLayerPointers.Length];
                }

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

                TilePalette = TilePaletteIndex.DoAtBlock(size => s.SerializeObjectArray <RGBA5551Color>(TilePalette, 256, name: nameof(TilePalette)));
                ObjPalette  = ObjPaletteIndex.DoAtBlock(size => s.SerializeObjectArray <RGBA5551Color>(ObjPalette, 256, name: nameof(ObjPalette)));
                Collision3D = Collision3DIndex?.DoAtBlock(size => s.SerializeObject <GBAIsometric_Spyro_Collision3DMapData>(Collision3D, name: nameof(Collision3D)));
                Collision2D = Collision2DIndex?.DoAtBlock(size => s.SerializeObject <GBAIsometric_Spyro_Collision2DMapData>(Collision2D, name: nameof(Collision2D)));
                //Index3Map = Index3?.DoAtBlock(size => s.SerializeObject<GBAIsometric_Spyro_SpriteMap>(Index3Map, name: nameof(Index3Map)));
            }
        }
Example #7
0
        public override void SerializeImpl(SerializerObject s)
        {
            Pointers = s.SerializePointerArray(Pointers, 12, name: nameof(Pointers));

            if (LocStrings == null)
            {
                LocStrings = new GBA_LocStringTable[Pointers.Length];
            }

            for (int i = 0; i < LocStrings.Length; i++)
            {
                LocStrings[i] = s.DoAt(Pointers[i], () => s.SerializeObject <GBA_LocStringTable>(LocStrings[i], name: $"{nameof(LocStrings)}[{i}]"));
            }
        }
Example #8
0
        public override void SerializeImpl(SerializerObject s)
        {
            StringPointers = s.SerializePointerArray(StringPointers, ((GBAVV_BaseManager)s.GameSettings.GetGameManager).LocTableCount, name: nameof(StringPointers));

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

            for (int i = 0; i < Strings.Length; i++)
            {
                Strings[i] = s.DoAt(StringPointers[i], () => s.SerializeString(Strings[i], name: $"{nameof(Strings)}[{i}]"));
            }
        }
        public override void SerializeImpl(SerializerObject s)
        {
            Pointers = s.SerializePointerArray(Pointers, s.GameSettings.EngineVersion == EngineVersion.GBA_R3 ? 10 : 6, name: nameof(Pointers));

            if (StringGroups == null)
            {
                StringGroups = new GBA_LocStringGroupTable[Pointers.Length];
            }

            for (int i = 0; i < StringGroups.Length; i++)
            {
                StringGroups[i] = s.DoAt(Pointers[i], () => s.SerializeObject <GBA_LocStringGroupTable>(StringGroups[i], name:  $"{nameof(StringGroups)}[{i}]"));
            }
        }
Example #10
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            NumDescriptors = s.Serialize <uint>(NumDescriptors, name: nameof(NumDescriptors));
            NumPages       = s.Serialize <uint>(NumPages, name: nameof(NumPages));
            Width          = s.Serialize <uint>(Width, name: nameof(Width));
            Height         = s.Serialize <uint>(Height, name: nameof(Height));
            BitDepth       = s.Serialize <uint>(BitDepth, name: nameof(BitDepth)); // can be 4, 8 or 16
            NumPalettes    = s.Serialize <uint>(NumPalettes, name: nameof(NumPalettes));
            Unk1           = s.Serialize <uint>(Unk1, name: nameof(Unk1));

            // Initialize array sizes
            if (PagePointers == null)
            {
                PagePointers = new Pointer[NumPages];
            }
            if (TexturePages == null)
            {
                TexturePages = new byte[NumPages][];
            }
            if (Palettes == null)
            {
                Palettes = new ObjectArray <RGBA5551Color> [NumPalettes];
            }
            if (Descriptors == null)
            {
                Descriptors = new R1_PS1Edu_TEXDescriptor[NumDescriptors];
            }

            PagePointers = s.SerializePointerArray(PagePointers, PagePointers.Length, anchor: Offset, name: nameof(PagePointers));
            Palettes     = s.SerializeObjectArray(Palettes, Palettes.Length, onPreSerialize: a => a.Length = PaletteLength, name: nameof(Palettes));
            Descriptors  = s.SerializeObjectArray(Descriptors, Descriptors.Length, name: nameof(Descriptors));

            for (int i = 0; i < TexturePages.Length; i++)
            {
                s.DoAt(PagePointers[i], () => {
                    TexturePages[i] = s.SerializeArray <byte>(TexturePages[i], PageLength, name: $"{nameof(TexturePages)}[{i}]");
                });
            }
        }
        public override void SerializeImpl(SerializerObject s)
        {
            TilePalettePointer = s.SerializePointer(TilePalettePointer, name: nameof(TilePalettePointer));
            MapLayerPointers   = s.SerializePointerArray(MapLayerPointers, 4, name: nameof(MapLayerPointers));
            Pointer_14         = s.SerializePointer(Pointer_14, name: nameof(Pointer_14));
            ObjDataPointer     = s.SerializePointer(ObjDataPointer, name: nameof(ObjDataPointer));
            TileSetsPointer    = s.SerializePointer(TileSetsPointer, name: nameof(TileSetsPointer));

            TilePalette = s.DoAt(TilePalettePointer, () => s.SerializeObjectArray <RGBA5551Color>(TilePalette, 256, name: nameof(TilePalette)));

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

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

            ObjData  = s.DoAt(ObjDataPointer, () => s.SerializeObject <GBAVV_Map2D_ObjData>(ObjData, name: nameof(ObjData)));
            TileSets = s.DoAt(TileSetsPointer, () => s.SerializeObject <GBAVV_WorldMap_TileSets>(TileSets, name: nameof(TileSets)));
        }