Пример #1
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));
            }
        }
Пример #2
0
        public override void SerializeImpl(SerializerObject s)
        {
            if (s.GameSettings.EngineVersion == EngineVersion.GBAIsometric_RHR)
            {
                LocIndex = s.Serialize <int>(LocIndex, name: nameof(LocIndex));
            }
            else
            {
                LocIndex = s.Serialize <ushort>((ushort)LocIndex, name: nameof(LocIndex));
            }

            var locString = GetString();

            if (locString != null)
            {
                s.Log($"String: {locString}");
            }
        }
Пример #3
0
        public override void SerializeImpl(SerializerObject s)
        {
            TileSetIndices = s.SerializeObjectArray <GBAIsometric_Spyro_DataBlockIndex>(TileSetIndices, 4, name: nameof(TileSetIndices));
            MapIndex       = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(MapIndex, name: nameof(MapIndex));
            PaletteIndex   = s.SerializeObject <GBAIsometric_Spyro_DataBlockIndex>(PaletteIndex, name: nameof(PaletteIndex));

            if (TileSets == null)
            {
                TileSets = new byte[TileSetIndices.Length][];
            }

            for (int i = 0; i < TileSets.Length; i++)
            {
                TileSets[i] = TileSetIndices[i].DoAtBlock(size => s.SerializeArray <byte>(TileSets[i], size, name: $"{nameof(TileSets)}[{i}]"));
            }

            Map     = MapIndex.DoAtBlock(size => s.SerializeObject <GBAIsometric_Spyro_SpriteMap>(Map, name: nameof(Map)));
            Palette = PaletteIndex.DoAtBlock(size => s.SerializeObjectArray <RGBA5551Color>(Palette, 256, name: nameof(Palette)));

            s.Log($"Min: {Map.MapData.Where(x => x.TileMapY > 1).Min(x => x.TileMapY)}");
        }
Пример #4
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            if (s.GameSettings.GameModeSelection == GameModeSelection.MapperPC || s.GameSettings.EngineVersion == EngineVersion.R1_GBA || s.GameSettings.EngineVersion == EngineVersion.R1_DSi)
            {
                TileMapY      = s.Serialize <ushort>(TileMapY, name: nameof(TileMapY));
                TileMapX      = 0;
                CollisionType = (byte)s.Serialize <ushort>((ushort)CollisionType, name: nameof(CollisionType));
            }
            else if (s.GameSettings.EngineVersion == EngineVersion.R1_PC || s.GameSettings.EngineVersion == EngineVersion.R1_PC_Kit || s.GameSettings.EngineVersion == EngineVersion.R1_PC_Edu || s.GameSettings.EngineVersion == EngineVersion.R1_PS1_Edu || s.GameSettings.EngineVersion == EngineVersion.R1_PocketPC)
            {
                TileMapY            = s.Serialize <ushort>(TileMapY, name: nameof(TileMapY));
                TileMapX            = 0;
                CollisionType       = s.Serialize <byte>(CollisionType, name: nameof(CollisionType));
                PC_Unk1             = s.Serialize <byte>(PC_Unk1, name: nameof(PC_Unk1));
                PC_TransparencyMode = s.Serialize <R1_PC_MapTileTransparencyMode>(PC_TransparencyMode, name: nameof(PC_TransparencyMode));
                PC_Unk2             = s.Serialize <byte>(PC_Unk2, name: nameof(PC_Unk2));
            }
            else if (s.GameSettings.EngineVersion == EngineVersion.R1_PS1_JPDemoVol3 || s.GameSettings.EngineVersion == EngineVersion.R1_PS1_JPDemoVol6)
            {
                s.SerializeBitValues <int>(bitFunc =>
                {
                    TileMapX      = (ushort)bitFunc(TileMapX, 10, name: nameof(TileMapX));
                    TileMapY      = (ushort)bitFunc(TileMapY, 6, name: nameof(TileMapY));
                    CollisionType = (byte)bitFunc(CollisionType, 8, name: nameof(CollisionType));
                });
            }
            else if (s.GameSettings.EngineVersion == EngineVersion.R1_Saturn)
            {
                s.SerializeBitValues <ushort>(bitFunc =>
                {
                    TileMapX = (ushort)bitFunc(TileMapX, 4, name: nameof(TileMapX));
                    TileMapY = (ushort)bitFunc(TileMapY, 12, name: nameof(TileMapY));
                });

                CollisionType = s.Serialize <byte>(CollisionType, name: nameof(CollisionType));
                s.Serialize <byte>(0, name: "Padding");
            }
            else if (s.GameSettings.MajorEngineVersion == MajorEngineVersion.Rayman1_Jaguar)
            {
                s.SerializeBitValues <ushort>(bitFunc =>
                {
                    TileMapY      = (ushort)bitFunc(TileMapY, 12, name: nameof(TileMapY));
                    CollisionType = (byte)bitFunc(CollisionType, 4, name: nameof(CollisionType));
                });

                TileMapX = 0;
            }
            else if (s.GameSettings.MajorEngineVersion == MajorEngineVersion.SNES)
            {
                s.SerializeBitValues <ushort>(bitFunc =>
                {
                    TileMapY       = (ushort)bitFunc(TileMapY, 10, name: nameof(TileMapY));
                    HorizontalFlip = bitFunc(HorizontalFlip ? 1 : 0, 1, name: nameof(HorizontalFlip)) == 1;
                    VerticalFlip   = bitFunc(VerticalFlip ? 1 : 0, 1, name: nameof(VerticalFlip)) == 1;
                    CollisionType  = (byte)bitFunc(CollisionType, 4, name: nameof(CollisionType));
                });

                TileMapX = 0;
            }
            else if (s.GameSettings.MajorEngineVersion == MajorEngineVersion.GBA)
            {
                // TODO: Use SerializeBitValues

                if ((GBATileType == GBA_TileType.BGTile || GBATileType == GBA_TileType.FGTile) &&
                    s.GameSettings.EngineVersion != EngineVersion.GBA_SplinterCell_NGage &&
                    s.GameSettings.EngineVersion != EngineVersion.GBA_BatmanVengeance)
                {
                    int numBits = Is8Bpp ? 9 : 10;

                    if (s.GameSettings.EngineVersion <= EngineVersion.GBA_BatmanVengeance)
                    {
                        numBits = 8;
                    }/*else if(s.GameSettings.EngineVersion >= EngineVersion.GBA_StarWarsTrilogy) {
                      * numBits = Is8Bpp ? 9 : 10;
                      * } else if (s.GameSettings.EngineVersion >= EngineVersion.GBA_SplinterCell) {
                      * numBits = 9;
                      * if (GBATileType == GBA_TileType.FGTile) numBits = 10;
                      * }*/

                    ushort value = 0;

                    value = (ushort)BitHelpers.SetBits(value, TileMapY, numBits, 0);
                    //value = (ushort)BitHelpers.SetBits(value, VerticalFlip ? 1 : 0, 1, numBits);
                    value = (ushort)BitHelpers.SetBits(value, HorizontalFlip ? 1 : 0, 1, numBits);
                    value = (ushort)BitHelpers.SetBits(value, PaletteIndex, 4, 12);

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

                    TileMapY = (ushort)BitHelpers.ExtractBits(value, numBits, 0);
                    TileMapX = 0;
                    if (Is8Bpp)
                    {
                        IsFirstBlock = BitHelpers.ExtractBits(value, 1, 9) == 1;
                    }
                    HorizontalFlip = BitHelpers.ExtractBits(value, 1, 10) == 1;
                    VerticalFlip   = BitHelpers.ExtractBits(value, 1, 11) == 1;
                    PaletteIndex   = (byte)BitHelpers.ExtractBits(value, 4, 12);

                    s.Log($"{nameof(TileMapY)}: {TileMapY}");
                    s.Log($"{nameof(HorizontalFlip)}: {HorizontalFlip}");
                    s.Log($"{nameof(IsFirstBlock)}: {IsFirstBlock}");
                    s.Log($"{nameof(PaletteIndex)}: {PaletteIndex}");
                }
                else if (GBATileType == GBA_TileType.Mode7Tile)
                {
                    ushort value = 0;

                    value = (ushort)BitHelpers.SetBits(value, TileMapY, 9, 0);
                    //value = (ushort)BitHelpers.SetBits(value, VerticalFlip ? 1 : 0, 1, numBits);
                    value = (ushort)BitHelpers.SetBits(value, HorizontalFlip ? 1 : 0, 1, 9);

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

                    TileMapY       = (ushort)BitHelpers.ExtractBits(value, 9, 0);
                    TileMapX       = 0;
                    IsFirstBlock   = BitHelpers.ExtractBits(value, 1, 9) == 1;
                    HorizontalFlip = BitHelpers.ExtractBits(value, 1, 10) == 1;
                    VerticalFlip   = BitHelpers.ExtractBits(value, 1, 11) == 1;

                    s.Log($"{nameof(TileMapY)}: {TileMapY}");
                    s.Log($"{nameof(HorizontalFlip)}: {HorizontalFlip}");
                    s.Log($"{nameof(IsFirstBlock)}: {IsFirstBlock}");
                }
                else
                {
                    int numBits = Is8Bpp ? 14 : 11;

                    if (s.GameSettings.EngineVersion <= EngineVersion.GBA_BatmanVengeance)
                    {
                        numBits = 10;
                    }
                    else if (s.GameSettings.EngineVersion == EngineVersion.GBA_SplinterCell_NGage)
                    {
                        numBits = Is8Bpp ? 14 : 12;
                    }
                    else if (s.GameSettings.EngineVersion >= EngineVersion.GBA_SplinterCell)
                    {
                        numBits = Is8Bpp ? 14 : 12;
                    }

                    ushort value = 0;

                    value = (ushort)BitHelpers.SetBits(value, TileMapY, numBits, 0);
                    value = (ushort)BitHelpers.SetBits(value, HorizontalFlip ? 1 : 0, 1, numBits);
                    value = (ushort)BitHelpers.SetBits(value, PaletteIndex, 4, 12);

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

                    TileMapY = (ushort)BitHelpers.ExtractBits(value, numBits, 0);
                    if (s.GameSettings.EngineVersion == EngineVersion.GBA_SplinterCell_NGage && Is8Bpp)
                    {
                        TileMapY = (ushort)BitHelpers.ExtractBits(value, numBits - 1, 0);
                    }
                    TileMapX       = 0;
                    HorizontalFlip = BitHelpers.ExtractBits(value, 1, numBits) == 1;
                    if (s.GameSettings.EngineVersion == EngineVersion.GBA_BatmanVengeance)
                    {
                        VerticalFlip = BitHelpers.ExtractBits(value, 1, numBits + 1) == 1;
                    }
                    if (!Is8Bpp)
                    {
                        if (s.GameSettings.EngineVersion >= EngineVersion.GBA_SplinterCell)
                        {
                            PaletteIndex = (byte)BitHelpers.ExtractBits(value, 3, 13);
                        }
                        else
                        {
                            PaletteIndex = (byte)BitHelpers.ExtractBits(value, 4, 12);
                        }

                        if (s.GameSettings.EngineVersion == EngineVersion.GBA_SplinterCell)
                        {
                            PaletteIndex += 8;
                        }
                    }
                    else if (s.GameSettings.EngineVersion != EngineVersion.GBA_BatmanVengeance)
                    {
                        VerticalFlip = BitHelpers.ExtractBits(value, 1, numBits + 1) == 1;
                    }

                    s.Log($"{nameof(TileMapY)}: {TileMapY}");
                    s.Log($"{nameof(HorizontalFlip)}: {HorizontalFlip}");
                    s.Log($"{nameof(PaletteIndex)}: {PaletteIndex}");
                }
            }
            else if (s.GameSettings.EngineVersion == EngineVersion.R1_PS1 || s.GameSettings.EngineVersion == EngineVersion.R2_PS1)
            {
                s.SerializeBitValues <ushort>(bitFunc =>
                {
                    TileMapX      = (ushort)bitFunc(TileMapX, 4, name: nameof(TileMapX));
                    TileMapY      = (ushort)bitFunc(TileMapY, 6, name: nameof(TileMapY));
                    CollisionType = (byte)bitFunc(CollisionType, 6, name: nameof(CollisionType));
                });
            }
            else if (s.GameSettings.EngineVersion == EngineVersion.R1_PS1_JP)
            {
                s.SerializeBitValues <ushort>(bitFunc =>
                {
                    TileMapX      = (ushort)bitFunc(TileMapX, 9, name: nameof(TileMapX));
                    CollisionType = (byte)bitFunc(CollisionType, 7, name: nameof(CollisionType));
                });
            }
            else if (s.GameSettings.MajorEngineVersion == MajorEngineVersion.GBARRR)
            {
                if (GBARRRType == GBARRR_MapBlock.MapType.Collision)
                {
                    CollisionType = s.Serialize <byte>(CollisionType, name: nameof(CollisionType));
                }
                else if (GBARRRType == GBARRR_MapBlock.MapType.Tiles)
                {
                    TileMapY = s.Serialize <ushort>(TileMapY, name: nameof(TileMapY));
                }
                else if (GBARRRType == GBARRR_MapBlock.MapType.Foreground)
                {
                    s.SerializeBitValues <ushort>(bitFunc =>
                    {
                        TileMapY       = (ushort)bitFunc(TileMapY, 10, name: nameof(TileMapY));
                        HorizontalFlip = bitFunc(HorizontalFlip ? 1 : 0, 1, name: nameof(HorizontalFlip)) == 1;
                        VerticalFlip   = bitFunc(VerticalFlip ? 1 : 0, 1, name: nameof(VerticalFlip)) == 1;
                        PaletteIndex   = (byte)bitFunc(PaletteIndex, 4, name: nameof(PaletteIndex));
                        //Unk = (byte)bitFunc(Unk, 4, name: nameof(Unk));
                    });
                }
                else if (GBARRRType == GBARRR_MapBlock.MapType.Menu)
                {
                    s.SerializeBitValues <ushort>(bitFunc =>
                    {
                        TileMapY       = (ushort)bitFunc(TileMapY, 8, name: nameof(TileMapY));
                        GBARRR_MenuUnk = (byte)bitFunc(GBARRR_MenuUnk, 2, name: nameof(GBARRR_MenuUnk));
                        HorizontalFlip = bitFunc(HorizontalFlip ? 1 : 0, 1, name: nameof(HorizontalFlip)) == 1;
                        VerticalFlip   = bitFunc(VerticalFlip ? 1 : 0, 1, name: nameof(VerticalFlip)) == 1;
                        PaletteIndex   = (byte)bitFunc(PaletteIndex, 4, name: nameof(PaletteIndex));
                        //Unk = (byte)bitFunc(Unk, 4, name: nameof(Unk));
                    });
                }
                else if (GBARRRType == GBARRR_MapBlock.MapType.Mode7Tiles)
                {
                    TileMapY = s.Serialize <byte>((byte)TileMapY, name: nameof(TileMapY));
                }
            }
        }
Пример #5
0
        public override void SerializeImpl(SerializerObject s)
        {
            NumChannels           = s.Serialize <ushort>(NumChannels, name: nameof(NumChannels));
            NumRowsPerPattern     = s.Serialize <ushort>(NumRowsPerPattern, name: nameof(NumRowsPerPattern));
            NumPatternsPerChannel = s.Serialize <ushort>(NumPatternsPerChannel, name: nameof(NumPatternsPerChannel));
            UShort_06             = s.Serialize <ushort>(UShort_06, name: nameof(UShort_06));
            Volume               = s.Serialize <ushort>(Volume, name: nameof(Volume));
            UShort_0A            = s.Serialize <ushort>(UShort_0A, name: nameof(UShort_0A));
            SequenceDataPointer  = s.SerializePointer(SequenceDataPointer, name: nameof(SequenceDataPointer));
            InstrumentSetPointer = s.SerializePointer(InstrumentSetPointer, name: nameof(InstrumentSetPointer));
            SampleSetPointer     = s.SerializePointer(SampleSetPointer, name: nameof(SampleSetPointer));
            SampleRate           = s.Serialize <ushort>(SampleRate, name: nameof(SampleRate));
            UShort_1A            = s.Serialize <ushort>(UShort_1A, name: nameof(UShort_1A));
            UShort_1C            = s.Serialize <ushort>(UShort_1C, name: nameof(UShort_1C));
            UShort_1E            = s.Serialize <ushort>(UShort_1E, name: nameof(UShort_1E));
            PatternTablePointers = s.SerializePointerArray(PatternTablePointers, NumChannels, name: nameof(PatternTablePointers));
            Reserved             = s.SerializeArray <uint>(Reserved, NumChannels, name: nameof(Reserved));

            List <int> instruments = new List <int>();

            if (PatternTable == null)
            {
                int instrumentCount = 0;
                PatternTable = new GAX2_PatternHeader[PatternTablePointers.Length][];
                Patterns     = new GAX2_Pattern[PatternTablePointers.Length][];
                for (int i = 0; i < PatternTablePointers.Length; i++)
                {
                    s.DoAt(PatternTablePointers[i], () => {
                        PatternTable[i] = s.SerializeObjectArray <GAX2_PatternHeader>(PatternTable[i], NumPatternsPerChannel, name: $"{nameof(PatternTable)}[{i}]");
                        if (Patterns[i] == null)
                        {
                            Patterns[i] = new GAX2_Pattern[PatternTable[i].Length];
                            for (int j = 0; j < Patterns[i].Length; j++)
                            {
                                s.DoAt(SequenceDataPointer + PatternTable[i][j].SequenceOffset, () => {
                                    Patterns[i][j]  = s.SerializeObject <GAX2_Pattern>(Patterns[i][j], onPreSerialize: t => t.Duration = NumRowsPerPattern, name: $"{nameof(Patterns)}[{i}][{j}]");
                                    instrumentCount = Math.Max(instrumentCount, Patterns[i][j].Rows.Max(cmd => cmd.Command == GAX2_PatternRow.Cmd.Note ? cmd.Instrument + 1 : 0));
                                    instruments.AddRange(Patterns[i][j].Rows.Where(cmd => cmd.Command == GAX2_PatternRow.Cmd.Note).Select(cmd => (int)cmd.Instrument));
                                });
                            }
                        }
                    });
                }
                InstrumentIndices = instruments.Distinct().Where(i => i != 250).ToArray();
                s.Log("Instrument Count: " + InstrumentIndices.Length);
                Pointer endOffset = Patterns.Max(ta => ta.Max(t => t.EndOffset));
                s.DoAt(endOffset, () => {
                    Name           = s.Serialize <string>(Name, name: nameof(Name));
                    string[] parse = Name.Split('"');
                    ParsedName     = parse[1];
                    ParsedArtist   = parse[2].Substring(3, 0xF);
                    s.Log(ParsedName + " - " + ParsedArtist);
                });
                s.DoAt(InstrumentSetPointer, () => {
                    InstrumentSet = s.SerializePointerArray <GAX2_Instrument>(InstrumentSet, instrumentCount, resolve: true, name: nameof(InstrumentSet));
                });
                Samples = new GAX2_Sample[InstrumentIndices.Length];
                for (int i = 0; i < InstrumentIndices.Length; i++)
                {
                    int ind   = InstrumentIndices[i];
                    var instr = InstrumentSet[ind].Value;
                    if (instr != null)
                    {
                        s.DoAt(SampleSetPointer + (instr.Sample) * 8, () => {
                            Samples[i] = s.SerializeObject <GAX2_Sample>(Samples[i], name: $"{nameof(Samples)}[{i}]");
                        });
                    }
                }
            }
        }
Пример #6
0
        public override void SerializeImpl(SerializerObject s)
        {
            Attr0 = s.Serialize <ushort>(Attr0, name: nameof(Attr0));

            // Parse
            if ((Attr0 & BOX_FLAG) == 0x800)
            {
                ChannelType = Type.Unknown8;
            }
            if ((Attr0 & BOX_FLAG) == 0xC00)
            {
                ChannelType = Type.UnknownC;
            }
            if ((Attr0 & BOX_FLAG) == 0x1000)
            {
                ChannelType = Type.AttackBox;
            }
            if ((Attr0 & BOX_FLAG) == 0x1400)
            {
                ChannelType = Type.VulnerabilityBox;
            }

            if (ChannelType == Type.Sprite)
            {
                Attr1 = s.Serialize <ushort>(Attr1, name: nameof(Attr1));
                Attr2 = s.Serialize <ushort>(Attr2, name: nameof(Attr2));
                if (Attr0 == 0 && Attr1 == 0 && Attr2 == 0)
                {
                    ChannelType = Type.Null;
                    return;
                }
                // Attr0
                YPosition = (short)BitHelpers.ExtractBits(Attr0, 8, 0);

                /*if (s.GameSettings.Game == Game.GBA_Rayman3) {
                 *  if (YPosition >= 96) YPosition -= 256; // Hack. Since usually more of the top sprite is visible, this is more likely.
                 * } else {
                 *  if (YPosition >= 128) YPosition -= 256;
                 * }*/
                if (YPosition >= 128)
                {
                    YPosition -= 256;
                }
                TransformMode = (AffineObjectMode)BitHelpers.ExtractBits(Attr0, 2, 8);
                RenderMode    = (GfxMode)BitHelpers.ExtractBits(Attr0, 2, 10);
                //Controller.print(BitHelpers.ExtractBits(Attr0, 2, 10));
                Color       = (GBA_ColorMode)BitHelpers.ExtractBits(Attr0, 1, 13);
                SpriteShape = (Shape)BitHelpers.ExtractBits(Attr0, 2, 14);

                // Attr1
                XPosition = (short)BitHelpers.ExtractBits(Attr1, 9, 0);
                bool bit9 = false, bit10 = false, bit11 = false;
                if (XPosition >= 256)
                {
                    XPosition -= 512;
                }
                if (TransformMode == AffineObjectMode.Affine || TransformMode == AffineObjectMode.AffineDouble)
                {
                    AffineMatrixIndex = BitHelpers.ExtractBits(Attr1, 5, 9);
                }
                else
                {
                    bit9  = BitHelpers.ExtractBits(Attr1, 1, 9) == 1;
                    bit10 = BitHelpers.ExtractBits(Attr1, 1, 10) == 1;
                    bit11 = BitHelpers.ExtractBits(Attr1, 1, 11) == 1;
                    IsFlippedHorizontally = BitHelpers.ExtractBits(Attr1, 1, 12) == 1;
                    IsFlippedVertically   = BitHelpers.ExtractBits(Attr1, 1, 13) == 1;
                }
                SpriteSize = BitHelpers.ExtractBits(Attr1, 2, 14);

                if (s.GameSettings.EngineVersion == EngineVersion.GBA_Sabrina)
                {
                    ImageIndex   = (ushort)BitHelpers.ExtractBits(Attr2, 12, 0);
                    PaletteIndex = BitHelpers.ExtractBits(Attr2, 3, 12); // another flag at byte 0xF?
                }
                else if (s.GameSettings.EngineVersion == EngineVersion.GBA_BatmanRiseOfSinTzu)
                {
                    ImageIndex   = (ushort)BitHelpers.ExtractBits(Attr2, 15, 0);
                    PaletteIndex = BitHelpers.ExtractBits(Attr2, 1, 15); // another flag at byte 0xF?
                }
                else if (s.GameSettings.EngineVersion == EngineVersion.GBA_StarWarsTrilogy)
                {
                    ImageIndex   = (ushort)BitHelpers.ExtractBits(Attr2, 14, 0);
                    PaletteIndex = BitHelpers.ExtractBits(Attr2, 1, 14); // another flag at byte 0xF?
                }
                else if (s.GameSettings.EngineVersion >= EngineVersion.GBA_SplinterCell)
                {
                    ImageIndex   = (ushort)BitHelpers.ExtractBits(Attr2, 14, 0);
                    PaletteIndex = BitHelpers.ExtractBits(Attr2, 2, 14); // another flag at byte 0xF?
                }
                else if (s.GameSettings.GBA_IsMilan)
                {
                    ImageIndex = Attr2;
                }
                else
                {
                    ImageIndex   = (ushort)BitHelpers.ExtractBits(Attr2, 11, 0);
                    Priority     = BitHelpers.ExtractBits(Attr2, 1, 11);
                    PaletteIndex = BitHelpers.ExtractBits(Attr2, 3, 12); // another flag at byte 0xF?
                }
                bool paletteFlag = BitHelpers.ExtractBits(Attr2, 1, 15) == 1;

                s.Log($"{nameof(XPosition)}: {XPosition}");
                s.Log($"{nameof(YPosition)}: {YPosition}");
                s.Log($"{nameof(TransformMode)}: {TransformMode}");
                s.Log($"{nameof(RenderMode)}: {RenderMode}");
                s.Log($"{nameof(Color)}: {Color}");
                s.Log($"{nameof(SpriteShape)}: {SpriteShape}");
                s.Log($"{nameof(SpriteSize)}: {SpriteSize}");

                s.Log($"{nameof(ImageIndex)}: {ImageIndex}");
                s.Log($"{nameof(Priority)}: {Priority}");
                s.Log($"{nameof(PaletteIndex)}: {PaletteIndex}");
                s.Log($"{nameof(paletteFlag)}: {paletteFlag}");
                if (TransformMode == AffineObjectMode.Affine || TransformMode == AffineObjectMode.AffineDouble)
                {
                    s.Log($"{nameof(AffineMatrixIndex)}: {AffineMatrixIndex}");
                }
                else
                {
                    s.Log($"{nameof(IsFlippedHorizontally)}: {IsFlippedHorizontally}");
                    s.Log($"{nameof(IsFlippedVertically)}: {IsFlippedVertically}");
                }
                if (bit9)
                {
                    s.Log("BIT9");
                }
                if (bit10)
                {
                    s.Log("BIT10");
                }
                if (bit11)
                {
                    s.Log("BIT11");
                }

                // Calculate size
                XSize = 1;
                YSize = 1;
                switch (SpriteShape)
                {
                case Shape.Square:
                    XSize = 1 << SpriteSize;
                    YSize = XSize;
                    break;

                case Shape.Wide:
                    switch (SpriteSize)
                    {
                    case 0: XSize = 2; YSize = 1; break;

                    case 1: XSize = 4; YSize = 1; break;

                    case 2: XSize = 4; YSize = 2; break;

                    case 3: XSize = 8; YSize = 4; break;
                    }
                    break;

                case Shape.Tall:
                    switch (SpriteSize)
                    {
                    case 0: XSize = 1; YSize = 2; break;

                    case 1: XSize = 1; YSize = 4; break;

                    case 2: XSize = 2; YSize = 4; break;

                    case 3: XSize = 4; YSize = 8; break;
                    }
                    break;
                }
            }
            else if (ChannelType == Type.Unknown8)
            {
                Unknown8 = s.Serialize <int>(Unknown8, name: nameof(Unknown8));
            }
            else if (ChannelType == Type.UnknownC)
            {
                UnknownC = s.Serialize <int>(UnknownC, name: nameof(UnknownC));
            }
            else
            {
                s.Log($"{nameof(ChannelType)}: {ChannelType}");
                Box_MinY = s.Serialize <sbyte>(Box_MinY, name: nameof(Box_MinY));
                Box_MaxY = s.Serialize <sbyte>(Box_MaxY, name: nameof(Box_MaxY));
                Box_MinX = s.Serialize <sbyte>(Box_MinX, name: nameof(Box_MinX));
                Box_MaxX = s.Serialize <sbyte>(Box_MaxX, name: nameof(Box_MaxX));
            }
        }
        public override void SerializeImpl(SerializerObject s)
        {
            Attr0 = s.Serialize <ushort>(Attr0, name: nameof(Attr0));
            if (IsEndAttribute)
            {
                return;
            }

            // Parse
            Attr1 = s.Serialize <ushort>(Attr1, name: nameof(Attr1));
            Attr2 = s.Serialize <ushort>(Attr2, name: nameof(Attr2));

            // Attr0
            YPosition = (short)BitHelpers.ExtractBits(Attr0, 8, 0);
            if (YPosition >= 128)
            {
                YPosition -= 256;
            }


            TransformMode = (AffineObjectMode)BitHelpers.ExtractBits(Attr0, 2, 8);
            RenderMode    = (GfxMode)BitHelpers.ExtractBits(Attr0, 2, 10);
            Mosaic        = BitHelpers.ExtractBits(Attr0, 1, 12) == 1;
            Color         = (GBA_ColorMode)BitHelpers.ExtractBits(Attr0, 1, 13);
            SpriteShape   = (Shape)BitHelpers.ExtractBits(Attr0, 2, 14);

            // Attr1
            XPosition = (short)BitHelpers.ExtractBits(Attr1, 9, 0);
            bool bit9 = false, bit10 = false, bit11 = false;

            //if (XPosition >= 256) XPosition -= 512;
            if (XPosition >= 128)
            {
                XPosition -= 256;
            }
            if (TransformMode == AffineObjectMode.Affine || TransformMode == AffineObjectMode.AffineDouble)
            {
                AffineMatrixIndex = BitHelpers.ExtractBits(Attr1, 5, 9);
            }
            else
            {
                bit9  = BitHelpers.ExtractBits(Attr1, 1, 9) == 1;
                bit10 = BitHelpers.ExtractBits(Attr1, 1, 10) == 1;
                bit11 = BitHelpers.ExtractBits(Attr1, 1, 11) == 1;
                IsFlippedHorizontally = BitHelpers.ExtractBits(Attr1, 1, 12) == 1;
                IsFlippedVertically   = BitHelpers.ExtractBits(Attr1, 1, 13) == 1;
            }
            SpriteSize = BitHelpers.ExtractBits(Attr1, 2, 14);

            ImageIndex   = (short)BitHelpers.ExtractBits(Attr2, 10, 0);
            Priority     = BitHelpers.ExtractBits(Attr2, 2, 10);
            PaletteIndex = BitHelpers.ExtractBits(Attr2, 4, 12);

            s.Log($"{nameof(XPosition)}: {XPosition}");
            s.Log($"{nameof(YPosition)}: {YPosition}");
            s.Log($"{nameof(TransformMode)}: {TransformMode}");
            s.Log($"{nameof(RenderMode)}: {RenderMode}");
            s.Log($"{nameof(Color)}: {Color}");
            s.Log($"{nameof(Mosaic)}: {Mosaic}");
            s.Log($"{nameof(SpriteShape)}: {SpriteShape}");
            s.Log($"{nameof(SpriteSize)}: {SpriteSize}");

            s.Log($"{nameof(ImageIndex)}: {ImageIndex}");
            s.Log($"{nameof(Priority)}: {Priority}");
            s.Log($"{nameof(PaletteIndex)}: {PaletteIndex}");
            if (TransformMode == AffineObjectMode.Affine || TransformMode == AffineObjectMode.AffineDouble)
            {
                s.Log($"{nameof(AffineMatrixIndex)}: {AffineMatrixIndex}");
            }
            else
            {
                s.Log($"{nameof(IsFlippedHorizontally)}: {IsFlippedHorizontally}");
                s.Log($"{nameof(IsFlippedVertically)}: {IsFlippedVertically}");
            }
            if (bit9)
            {
                s.Log("BIT9");
            }
            if (bit10)
            {
                s.Log("BIT10");
            }
            if (bit11)
            {
                s.Log("BIT11");
            }

            // Calculate size
            XSize = 1;
            YSize = 1;
            switch (SpriteShape)
            {
            case Shape.Square:
                XSize = 1 << SpriteSize;
                YSize = XSize;
                break;

            case Shape.Wide:
                switch (SpriteSize)
                {
                case 0: XSize = 2; YSize = 1; break;

                case 1: XSize = 4; YSize = 1; break;

                case 2: XSize = 4; YSize = 2; break;

                case 3: XSize = 8; YSize = 4; break;
                }
                break;

            case Shape.Tall:
                switch (SpriteSize)
                {
                case 0: XSize = 1; YSize = 2; break;

                case 1: XSize = 1; YSize = 4; break;

                case 2: XSize = 2; YSize = 4; break;

                case 3: XSize = 4; YSize = 8; break;
                }
                break;
            }
        }
Пример #8
0
 public override void SerializeImpl(SerializerObject s)
 {
     Time = s.Serialize <uint>(Time, name: nameof(Time));
     s.Log($"Time: {GetDateTime}");
 }
Пример #9
0
 public override void SerializeImpl(SerializerObject s)
 {
     CentiSeconds = s.Serialize <int>(CentiSeconds, name: nameof(CentiSeconds));
     s.Log($"Time: {Time:g}");
 }