/// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            var isEncryptedAndChecksum = s.GameSettings.EngineVersion != EngineVersion.R1_PS1_Edu;

            LevelDefineChecksum = s.DoChecksum(new Checksum8Calculator(false), () =>
            {
                s.DoXOR((byte)(isEncryptedAndChecksum ? 0x57 : 0), () =>
                {
                    LevelDefine_0 = s.SerializeArray <byte>(LevelDefine_0, 6, name: nameof(LevelDefine_0));
                    MusicTrack    = s.Serialize <byte>(MusicTrack, name: nameof(MusicTrack));
                    BG_0          = s.Serialize <byte>(BG_0, name: nameof(BG_0));
                    BG_1          = s.Serialize <byte>(BG_1, name: nameof(BG_1));
                    BG_2          = s.Serialize <byte>(BG_2, name: nameof(BG_2));
                    LevelDefine_1 = s.SerializeArray <byte>(LevelDefine_1, 3, name: nameof(LevelDefine_1));
                    RayEvts       = s.Serialize <R1_RayEvtsFlags>(RayEvts, name: nameof(RayEvts));
                    UnkByte       = s.Serialize <byte>(UnkByte, name: nameof(UnkByte));
                });
            }, ChecksumPlacement.Before, calculateChecksum: isEncryptedAndChecksum, name: nameof(LevelDefineChecksum));

            BackgroundDefineNormalChecksum = s.DoChecksum(new Checksum8Calculator(false), () =>
            {
                s.DoXOR((byte)(isEncryptedAndChecksum ? 0xA5 : 0), () => BackgroundDefineNormal = s.SerializeObjectArray <R1_BackgroundLayerPosition>(BackgroundDefineNormal, 6, name: nameof(BackgroundDefineNormal)));
            }, ChecksumPlacement.Before, calculateChecksum: isEncryptedAndChecksum, name: nameof(BackgroundDefineNormalChecksum));

            BackgroundDefineDiffChecksum = s.DoChecksum(new Checksum8Calculator(false), () =>
            {
                s.DoXOR((byte)(isEncryptedAndChecksum ? 0xA5 : 0), () => BackgroundDefineDiff = s.SerializeObjectArray <R1_BackgroundLayerPosition>(BackgroundDefineDiff, 6, name: nameof(BackgroundDefineDiff)));
            }, ChecksumPlacement.Before, calculateChecksum: isEncryptedAndChecksum, name: nameof(BackgroundDefineDiffChecksum));
        }
Beispiel #2
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));
        }
Beispiel #3
0
        /// <summary>
        /// Serializes the data
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            // Serialize PC Header
            base.SerializeImpl(s);

            // Serialize world data
            BG1 = s.Serialize <ushort>(BG1, name: nameof(BG1));
            BG2 = s.Serialize <ushort>(BG2, name: nameof(BG2));
            Plan0NumPcxCount  = s.Serialize <byte>(Plan0NumPcxCount, name: nameof(Plan0NumPcxCount));
            VideoBiosCheckSum = s.Serialize <byte>(VideoBiosCheckSum, name: nameof(VideoBiosCheckSum));
            BiosCheckSum      = s.Serialize <byte>(BiosCheckSum, name: nameof(BiosCheckSum));

            if (s.GameSettings.EngineVersion == EngineVersion.R1_PC || s.GameSettings.EngineVersion == EngineVersion.R1_PocketPC)
            {
                s.DoXOR(0x15, () => Plan0NumPcx = s.SerializeArray <byte>(Plan0NumPcx, Plan0NumPcxCount, name: nameof(Plan0NumPcx)));
            }
            else
            {
                s.DoXOR(0x19, () => Plan0NumPcxFiles = s.SerializeStringArray(Plan0NumPcxFiles, Plan0NumPcxCount, 8, name: nameof(Plan0NumPcxFiles)));
            }

            // Serialize the DES
            DesItemCount = s.Serialize <ushort>(DesItemCount, name: nameof(DesItemCount));

            DesItems = s.SerializeObjectArray <R1_PC_DES>(DesItems, DesItemCount, onPreSerialize: data => data.FileType = R1_PC_DES.Type.World, name: nameof(DesItems));

            // Serialize the ETA
            Eta = s.SerializeArraySize <R1_PC_ETA, byte>(Eta, name: nameof(Eta));
            Eta = s.SerializeObjectArray <R1_PC_ETA>(Eta, Eta.Length, name: nameof(Eta));

            // Kit and EDU have more data...
            if (s.GameSettings.EngineVersion == EngineVersion.R1_PC_Kit || s.GameSettings.EngineVersion == EngineVersion.R1_PC_Edu)
            {
                // Serialize world defines
                WorldDefineChecksum = s.DoChecksum(new Checksum8Calculator(false), () =>
                {
                    s.DoXOR(0x71, () => WorldDefine = s.SerializeObject <R1_PC_WorldDefine>(WorldDefine, name: nameof(WorldDefine)));
                }, ChecksumPlacement.Before, name: nameof(WorldDefineChecksum));

                // Serialize file tables
                if (s.GameSettings.EngineVersion == EngineVersion.R1_PC_Kit)
                {
                    DESFileNames = s.SerializeStringArray(DESFileNames, 100, 13, name: nameof(DESFileNames));
                    ETAFileNames = s.SerializeStringArray(ETAFileNames, 60, 13, name: nameof(ETAFileNames));
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            // NOTE: This block is only parsed by the game if the rough textures should be used. Otherwise it skips to the texture block pointer.

            // Serialize the rough textures count
            RoughTexturesCount = s.Serialize <uint>(RoughTexturesCount, name: nameof(RoughTexturesCount));

            // Serialize the length of the third unknown value
            Unknown3Count = s.Serialize <uint>(Unknown3Count, name: nameof(Unknown3Count));

            RoughTexturesChecksum = s.DoChecksum(new Checksum8Calculator(false), () =>
            {
                s.DoXOR(0x7D, () =>
                {
                    // Create the collection of rough textures if necessary
                    if (RoughTextures == null)
                    {
                        RoughTextures = new byte[RoughTexturesCount][];
                    }

                    // Serialize each rough texture
                    for (int i = 0; i < RoughTexturesCount; i++)
                    {
                        RoughTextures[i] = s.SerializeArray <byte>(RoughTextures[i], Settings.CellSize * Settings.CellSize, name:
                                                                   $"{nameof(RoughTextures)}[{i}]");
                    }
                });
            }, ChecksumPlacement.After, name: nameof(RoughTexturesChecksum));

            // Read the offset table for the rough textures
            RoughTexturesOffsetTable = s.SerializeArray <uint>(RoughTexturesOffsetTable, 1200, name: nameof(RoughTexturesOffsetTable));

            Unknown3Checksum = s.DoChecksum(new Checksum8Calculator(false), () =>
            {
                // Serialize the items for the third unknown value
                s.DoXOR(0xF3, () => Unknown3 = s.SerializeArray <byte>(Unknown3, Unknown3Count, name: nameof(Unknown3)));
            }, ChecksumPlacement.After, name: nameof(Unknown3Checksum));

            // Read the offset table for the third unknown value
            Unknown3OffsetTable = s.SerializeArray <uint>(Unknown3OffsetTable, 1200, name: nameof(Unknown3OffsetTable));
        }
Beispiel #5
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            ProfileDefineChecksum = s.DoChecksum(new Checksum8Calculator(false), () =>
            {
                s.DoXOR(0x96, () =>
                {
                    LevelName        = s.SerializeString(LevelName, 25, name: nameof(LevelName));
                    LevelAuthor      = s.SerializeString(LevelAuthor, 25, name: nameof(LevelAuthor));
                    LevelDescription = s.SerializeString(LevelDescription, 240, name: nameof(LevelDescription));

                    Power_Fist        = s.Serialize <bool>(Power_Fist, name: nameof(Power_Fist));
                    Power_Hang        = s.Serialize <bool>(Power_Hang, name: nameof(Power_Hang));
                    Power_Run         = s.Serialize <bool>(Power_Run, name: nameof(Power_Run));
                    Power_Seed        = s.Serialize <bool>(Power_Seed, name: nameof(Power_Seed));
                    Power_Helico      = s.Serialize <bool>(Power_Helico, name: nameof(Power_Helico));
                    Power_SuperHelico = s.Serialize <bool>(Power_SuperHelico, name: nameof(Power_SuperHelico));
                });
            }, ChecksumPlacement.Before, name: nameof(ProfileDefineChecksum));
        }
Beispiel #6
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            if (FileType == Type.World)
            {
                RequiresBackgroundClearing = s.Serialize <bool>(RequiresBackgroundClearing, name: nameof(RequiresBackgroundClearing));
            }
            else
            {
                RequiresBackgroundClearing = true;
            }

            if (FileType == Type.AllFix)
            {
                Allfix_Unk1        = s.Serialize <uint>(Allfix_Unk1, name: nameof(Allfix_Unk1));
                RaymanExeSize      = s.Serialize <uint>(RaymanExeSize, name: nameof(RaymanExeSize));
                RaymanExeCheckSum1 = s.Serialize <uint>(RaymanExeCheckSum1, name: nameof(RaymanExeCheckSum1));
            }

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

            var isChecksumBefore = FileType == Type.World && (s.GameSettings.EngineVersion == EngineVersion.R1_PC_Kit || s.GameSettings.EngineVersion == EngineVersion.R1_PC_Edu);
            var hasChecksum      = !(!isChecksumBefore && FileType == Type.BigRay);

            ImageDataChecksum = s.DoChecksum(new Checksum8Calculator(false), () =>
            {
                s.DoXOR(0x8F, () =>
                {
                    ImageData = s.SerializeArray <byte>(ImageData, ImageDataLength, name: nameof(ImageData));
                });
            }, isChecksumBefore ? ChecksumPlacement.Before : ChecksumPlacement.After, calculateChecksum: hasChecksum, name: nameof(ImageDataChecksum));

            if (FileType == Type.AllFix)
            {
                RaymanExeCheckSum2 = s.Serialize <uint>(RaymanExeCheckSum2, name: nameof(RaymanExeCheckSum2));
            }

            ImageDescriptorCount     = s.Serialize <ushort>(ImageDescriptorCount, name: nameof(ImageDescriptorCount));
            ImageDescriptors         = s.SerializeObjectArray <R1_ImageDescriptor>(ImageDescriptors, ImageDescriptorCount, name: nameof(ImageDescriptors));
            AnimationDescriptorCount = s.Serialize <byte>(AnimationDescriptorCount, name: nameof(AnimationDescriptorCount));
            AnimationDescriptors     = s.SerializeObjectArray <R1_PC_AnimationDescriptor>(AnimationDescriptors, AnimationDescriptorCount, name: nameof(AnimationDescriptors));
        }
Beispiel #7
0
        /// <summary>
        /// Handles the data serialization
        /// </summary>
        /// <param name="s">The serializer object</param>
        public override void SerializeImpl(SerializerObject s)
        {
            EventBlockChecksum = s.DoChecksum(new Checksum8Calculator(false), () =>
            {
                // Set the xor key to use for the event block
                s.DoXOR((byte)(s.GameSettings.EngineVersion == EngineVersion.R1_PC || s.GameSettings.EngineVersion == EngineVersion.R1_PocketPC ? 0 : 0x91), () =>
                {
                    // Serialize the event count
                    EventCount = s.Serialize <ushort>(EventCount, name: nameof(EventCount));

                    // Serialize the event linking table
                    EventLinkingTable = s.SerializeArray <ushort>(EventLinkingTable, EventCount, name: nameof(EventLinkingTable));

                    // Serialize the events
                    Events = s.SerializeObjectArray <R1_EventData>(Events, EventCount, name: nameof(Events));

                    // Serialize the event commands
                    EventCommands = s.SerializeObjectArray <R1_PC_EventCommand>(EventCommands, EventCount, name: nameof(EventCommands));
                });
            }, ChecksumPlacement.Before, calculateChecksum: s.GameSettings.EngineVersion == EngineVersion.R1_PC_Kit || s.GameSettings.EngineVersion == EngineVersion.R1_PC_Edu, name: nameof(EventBlockChecksum));
        }
        /// <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_PC || s.GameSettings.EngineVersion == EngineVersion.R1_PocketPC)
            {
                FileOffset = s.Serialize <uint>(FileOffset, name: nameof(FileOffset));
                FileSize   = s.Serialize <uint>(FileSize, name: nameof(FileSize));
                XORKey     = s.Serialize <byte>(XORKey, name: nameof(XORKey));
                Checksum   = s.Serialize <byte>(Checksum, name: nameof(Checksum));

                s.SerializeArray <byte>(new byte[2], 2, name: "Padding");
            }
            else
            {
                XORKey     = s.Serialize <byte>(XORKey, name: nameof(XORKey));
                Checksum   = s.Serialize <byte>(Checksum, name: nameof(Checksum));
                FileOffset = s.Serialize <uint>(FileOffset, name: nameof(FileOffset));
                FileSize   = s.Serialize <uint>(FileSize, name: nameof(FileSize));

                s.DoXOR(XORKey, () => FileName = s.SerializeString(FileName, 9, name: nameof(FileName)));
            }
        }