示例#1
0
        public void BinaryDeserialize(BinaryReader br)
        {
            CustomMeta_MinLevelIntVersion = 0;
            CustomMeta_UserID             = -1;
            CustomMeta_LevelID            = -1;
            CustomMeta_Timestamp          = DateTimeOffset.MinValue;

            byte[] id = new byte[1];
            while (br.Read(id, 0, 1) > 0)
            {
                switch (id[0])
                {
                case SERIALIZE_ID_SCHEMA:
                    var schema = br.ReadByte();
                    if (schema != SCHEMA_VERSION)                             // currently only schema 1
                    {
                        throw new Exception($"schema not supported ({schema} <> {SCHEMA_VERSION})");
                    }
                    break;

                case SERIALIZE_ID_CANNON:
                    BlueprintCannons.Add(CannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_VOIDWALL:
                    BlueprintVoidWalls.Add(VoidWallBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_VOIDCIRCLE:
                    BlueprintVoidCircles.Add(VoidCircleBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_GLASSBLOCK:
                    BlueprintGlassBlocks.Add(GlassBlockBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_BLACKHOLE:
                    BlueprintBlackHoles.Add(BlackHoleBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_PORTAL:
                    BlueprintPortals.Add(PortalBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_LASERCANNON:
                    BlueprintLaserCannons.Add(LaserCannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_MIRRORBLOCK:
                    BlueprintMirrorBlocks.Add(MirrorBlockBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_MIRRORCIRCLE:
                    BlueprintMirrorCircles.Add(MirrorCircleBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_BACKGROUNDTEXT:
                    BlueprintBackgroundText.Add(BackgroundTextBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_MINIGUN:
                    BlueprintMinigun.Add(MinigunBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_SHIELDPROJECTOR:
                    BlueprintShieldProjector.Add(ShieldProjectorBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_RELAY:
                    BlueprintRelayCannon.Add(RelayCannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_TRISHOT:
                    BlueprintTrishotCannon.Add(TrishotCannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_META:
                    Name        = br.ReadString();
                    FullName    = br.ReadString();
                    UniqueID    = new Guid(br.ReadBytes(16));
                    KIType      = br.ReadByte();
                    WrapMode    = br.ReadByte();
                    LevelWidth  = br.ReadSingle();
                    LevelHeight = br.ReadSingle();
                    LevelViewX  = br.ReadSingle();
                    LevelViewY  = br.ReadSingle();
                    break;

                case SERIALIZE_ID_META_CUSTOM:
                    CustomMusic = br.ReadInt32();
                    CustomMeta_MinLevelIntVersion = br.ReadUInt64();
                    CustomMeta_UserID             = br.ReadInt32();
                    CustomMeta_Timestamp          = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(br.ReadInt64());
                    CustomMeta_LevelID            = br.ReadInt64();
                    break;

                case SERIALIZE_ID_EOF:
                    if (br.ReadByte() != 0xB1)
                    {
                        throw new Exception("Missing footer byte 1");
                    }
                    if (br.ReadByte() != 0x6B)
                    {
                        throw new Exception("Missing footer byte 2");
                    }
                    if (br.ReadByte() != 0x00)
                    {
                        throw new Exception("Missing footer byte 3");
                    }
                    if (br.ReadByte() != 0xB5)
                    {
                        throw new Exception("Missing footer byte 4");
                    }

                    return;

                default:
                    throw new Exception("Unknown binary ID:" + id[0]);
                }
            }

            throw new Exception("Unexpected binary file end");
        }
示例#2
0
        public void BinaryDeserialize(BinaryReader br)
        {
            byte[] id = new byte[1];
            while (br.Read(id, 0, 1) > 0)
            {
                switch (id[0])
                {
                case SERIALIZE_ID_CANNON:
                    BlueprintCannons.Add(CannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_VOIDWALL:
                    BlueprintVoidWalls.Add(VoidWallBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_VOIDCIRCLE:
                    BlueprintVoidCircles.Add(VoidCircleBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_GLASSBLOCK:
                    BlueprintGlassBlocks.Add(GlassBlockBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_BLACKHOLE:
                    BlueprintBlackHoles.Add(BlackHoleBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_PORTAL:
                    BlueprintPortals.Add(PortalBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_LASERCANNON:
                    BlueprintLaserCannons.Add(LaserCannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_MIRRORBLOCK:
                    BlueprintMirrorBlocks.Add(MirrorBlockBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_MIRRORCIRCLE:
                    BlueprintMirrorCircles.Add(MirrorCircleBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_BACKGROUNDTEXT:
                    BlueprintBackgroundText.Add(BackgroundTextBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_MINIGUN:
                    BlueprintMinigun.Add(MinigunBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_SHIELDPROJECTOR:
                    BlueprintShieldProjector.Add(ShieldProjectorBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_RELAY:
                    BlueprintRelayCannon.Add(RelayCannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_TRISHOT:
                    BlueprintTrishotCannon.Add(TrishotCannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_META:
                    Name        = br.ReadString();
                    FullName    = br.ReadString();
                    UniqueID    = new Guid(br.ReadBytes(16));
                    KIType      = br.ReadByte();
                    WrapMode    = br.ReadByte();
                    LevelWidth  = br.ReadSingle();
                    LevelHeight = br.ReadSingle();
                    LevelViewX  = br.ReadSingle();
                    LevelViewY  = br.ReadSingle();
                    break;

                case SERIALIZE_ID_EOF:
                    if (br.ReadByte() != 0xB1)
                    {
                        throw new Exception("Missing footer byte 1");
                    }
                    if (br.ReadByte() != 0x6B)
                    {
                        throw new Exception("Missing footer byte 2");
                    }
                    if (br.ReadByte() != 0x00)
                    {
                        throw new Exception("Missing footer byte 3");
                    }
                    if (br.ReadByte() != 0xB5)
                    {
                        throw new Exception("Missing footer byte 4");
                    }

                    return;

                default:
                    throw new Exception("Unknown binary ID:" + id[0]);
                }
            }

            throw new Exception("Unexpected binary file end");
        }
示例#3
0
        public void BinaryDeserialize(BinaryReader br)
        {
            CustomMeta_MinLevelIntVersion = 0;
            CustomMeta_UserID             = -1;
            CustomMeta_LevelID            = -1;
            CustomMeta_Timestamp          = DateTimeOffset.MinValue;

            byte schema = 0;

            var eof = false;

            byte[] id = new byte[1];
            while (br.Read(id, 0, 1) > 0)
            {
                switch (id[0])
                {
                case SERIALIZE_ID_SCHEMA:
                    schema = br.ReadByte();
                    if (schema > SCHEMA_VERSION)
                    {
                        throw new Exception($"schema not supported ({schema} > {SCHEMA_VERSION})");
                    }
                    break;

                case SERIALIZE_ID_CANNON:
                    BlueprintCannons.Add(CannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_VOIDWALL:
                    BlueprintVoidWalls.Add(VoidWallBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_VOIDCIRCLE:
                    BlueprintVoidCircles.Add(VoidCircleBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_GLASSBLOCK:
                    BlueprintGlassBlocks.Add(GlassBlockBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_BLACKHOLE:
                    BlueprintBlackHoles.Add(BlackHoleBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_PORTAL:
                    BlueprintPortals.Add(PortalBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_LASERCANNON:
                    BlueprintLaserCannons.Add(LaserCannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_MIRRORBLOCK:
                    BlueprintMirrorBlocks.Add(MirrorBlockBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_MIRRORCIRCLE:
                    BlueprintMirrorCircles.Add(MirrorCircleBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_BACKGROUNDTEXT:
                    BlueprintBackgroundText.Add(BackgroundTextBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_MINIGUN:
                    BlueprintMinigun.Add(MinigunBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_SHIELDPROJECTOR:
                    BlueprintShieldProjector.Add(ShieldProjectorBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_RELAY:
                    BlueprintRelayCannon.Add(RelayCannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_TRISHOT:
                    BlueprintTrishotCannon.Add(TrishotCannonBlueprint.Deserialize(br));
                    break;

                case SERIALIZE_ID_META:
                    Name        = br.ReadString();
                    FullName    = br.ReadString();
                    UniqueID    = new Guid(br.ReadBytes(16));
                    KIType      = br.ReadByte();
                    WrapMode    = br.ReadByte();
                    LevelWidth  = br.ReadSingle();
                    LevelHeight = br.ReadSingle();
                    LevelViewX  = br.ReadSingle();
                    LevelViewY  = br.ReadSingle();
                    break;

                case SERIALIZE_ID_META_CUSTOM:
                    CustomMusic = br.ReadInt32();
                    CustomMeta_MinLevelIntVersion = br.ReadUInt64();
                    CustomMeta_UserID             = br.ReadInt32();
                    CustomMeta_Timestamp          = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(br.ReadInt64());
                    CustomMeta_LevelID            = br.ReadInt64();
                    break;

                case SERIALIZE_ID_EOF:
                    if (br.ReadByte() != 0xB1)
                    {
                        throw new Exception("Missing footer byte 1");
                    }
                    if (br.ReadByte() != 0x6B)
                    {
                        throw new Exception("Missing footer byte 2");
                    }
                    if (br.ReadByte() != 0x00)
                    {
                        throw new Exception("Missing footer byte 3");
                    }
                    if (br.ReadByte() != 0xB5)
                    {
                        throw new Exception("Missing footer byte 4");
                    }

                    eof = true;
                    break;

                default:
                    throw new Exception("Unknown binary ID:" + id[0]);
                }
                if (eof)
                {
                    break;
                }
            }

            if (!eof)
            {
                throw new Exception("Unexpected binary file end");
            }

            if (schema == 0)
            {
                // no schema
            }
            else if (schema == 1)
            {
                if (CustomMeta_LevelID > 0)
                {
                    // Fix wrong LevelID Serialization in schema-1 :/

                    var uid = ByteMath.SplitGuid(UniqueID);

                    var a = uid.Item1;
                    var b = uid.Item2;
                    var c = uid.Item3;
                    var d = uid.Item4;
                    var e = uid.Item5;

                    e = Convert.ToUInt64($"{e:X}", 10);

                    UniqueID = ByteMath.JoinGuid(a, b, c, d, e);
                }
            }
        }