コード例 #1
0
 protected override void Parse(ref BitStreamReader bsr)
 {
     Command   = (ShakeCommand)bsr.ReadByte();
     Amplitude = bsr.ReadFloat();
     Frequency = bsr.ReadFloat();
     Duration  = bsr.ReadFloat();
 }
コード例 #2
0
ファイル: Test.cs プロジェクト: FrogAC/CSE461_NetworkPhysics
    static void TestBitStream()
    {
        BitStreamWriter writer = new BitStreamWriter(2);
        BitStreamReader reader = new BitStreamReader();

        // Resize, basic int
        writer.WriteInt32(0x12345678);
        writer.WriteInt8(39);
        writer.WriteInt(2, 2);
        writer.WriteInt(87, 7);
        writer.WriteInt(33, 6);
        reader.SetBytes(writer.DumpBytes());
        Assert.IsTrue(reader.ReadInt32() == 0x12345678);
        Assert.IsTrue(reader.ReadInt8() == 39);
        Assert.IsTrue(reader.ReadInt(2) == 2);
        Assert.IsTrue(reader.ReadInt(7) == 87);
        Assert.IsTrue(reader.ReadInt(6) == 33);

        // Concatnat bits
        // 1, 0000010 11000011, 1
        // should be 00000101 10000110 00000011
        writer.WriteBool(true);
        writer.WriteInt16(707);
        writer.WriteBool(true);
        var data = writer.DumpBytes();

        Assert.IsTrue(data.Length == 3);
        Assert.IsTrue(data[0] == 0x05);
        Assert.IsTrue(data[1] == 0x86);
        Assert.IsTrue(data[2] == 0x03);
        reader.SetBytes(data);
        Assert.IsTrue(reader.ReadBool());
        Assert.IsTrue(reader.ReadInt16() == 707);
        Assert.IsTrue(reader.ReadBool());

        // float
        writer.WriteBool(false);
        writer.WriteFloat(12345.012345f);
        writer.WriteBool(true);
        reader.SetBytes(writer.DumpBytes());
        Assert.IsFalse(reader.ReadBool());
        Assert.IsTrue(reader.ReadFloat() == 12345.012345f);
        Assert.IsTrue(reader.ReadBool());

        // vector3, quaternion
        Vector3    vec = new Vector3(-0.51231f, 0.113123f, 1.1231123f);
        Quaternion q   = new Quaternion(-0.123f, 0.345f, 0.678f, -0.23f);

        q.Normalize();
        writer.WriteQuaternionRot(q);
        writer.WriteBool(false);
        writer.WriteVector3(Vector3.one);
        writer.WriteVector3(vec);
        reader.SetBytes(writer.DumpBytes());
        Assert.IsTrue(IsApprox(reader.ReadQuaternionRot(), q));
        Assert.IsFalse(reader.ReadBool());
        Assert.IsTrue(reader.ReadVector3() == Vector3.one);
        Assert.IsTrue(reader.ReadVector3() == vec);
    }
コード例 #3
0
        // src_main/common/netmessages.cpp  SVC_ServerInfo::WriteToBuffer
        protected override void Parse(ref BitStreamReader bsr)
        {
            NetworkProtocol = bsr.ReadUShort();
            ServerCount     = bsr.ReadUInt();
            IsHltv          = bsr.ReadBool();
            IsDedicated     = bsr.ReadBool();
            if (DemoInfo.IsLeft4Dead() && DemoInfo.Game >= SourceGame.L4D2_2147)
            {
                UnknownBit = bsr.ReadBool();
            }
            ClientCrc = bsr.ReadSInt();
            if (DemoInfo.NewDemoProtocol)             // unknown field, could be before ClientCrc
            {
                Unknown = bsr.ReadUInt();
            }
            MaxServerClasses = bsr.ReadUShort();
            if (NetworkProtocol == 24)
            {
                MapMD5 = bsr.ReadBytes(16);
            }
            else
            {
                MapCrc = bsr.ReadUInt();                 // network protocol < 18 according to p2 leak, but doesn't add up for l4d2 and p2
            }
            PlayerCount     = bsr.ReadByte();
            MaxClients      = bsr.ReadByte();
            TickInterval    = bsr.ReadFloat();
            Platform        = (char)bsr.ReadByte();
            GameDirBitIndex = bsr.AbsoluteBitIndex;
            GameDir         = bsr.ReadNullTerminatedString();
            MapName         = bsr.ReadNullTerminatedString();
            SkyName         = bsr.ReadNullTerminatedString();
            HostName        = bsr.ReadNullTerminatedString();
            if (DemoInfo.IsLeft4Dead() && DemoInfo.Game >= SourceGame.L4D2_2147)
            {
                MissionName  = bsr.ReadNullTerminatedString();
                MutationName = bsr.ReadNullTerminatedString();
            }
            if (NetworkProtocol == 24)
            {
                HasReplay = bsr.ReadBool();                 // protocol version >= 16
            }
            // there's a good change that the first SvcServerInfo parsed is parsed correctly
            // prevent the interval from being overwritten by subsequent, incorrectly detected, SvcServerInfo messages
            // TODO: check if changing tickrate mid game sends another SvcServerInfo
            if (!DemoInfo.HasParsedTickInterval)
            {
                DemoInfo.TickInterval          = TickInterval;
                DemoInfo.HasParsedTickInterval = true;
            }
            // this packet always(?) appears before the creation of any tables

            DemoRef.StringTablesManager.ClearCurrentTables();

            // init baselines here
            DemoRef.EntBaseLines = new EntityBaseLines(DemoRef, MaxServerClasses);
        }
コード例 #4
0
 protected override void Parse(ref BitStreamReader bsr)
 {
     Codec   = bsr.ReadNullTerminatedString();
     Quality = bsr.ReadByte();
     if (Quality == 255)
     {
         Unknown = bsr.ReadFloat();
     }
 }
コード例 #5
0
        protected override void Parse(ref BitStreamReader bsr)
        {
            PaintType = (PaintType)bsr.ReadByte();
            EHandle   = bsr.ReadEHandle();
            UnkHf1    = bsr.ReadFloat();
            UnkHf2    = bsr.ReadFloat();
            byte len = bsr.ReadByte();

            bsr.ReadVector3(out Center);
            if (bsr.BitsRemaining % 48 != 0)
            {
                throw new ParseException($"{GetType().Name} doesn't have the right number of bits left, " +
                                         $"expected a multiple of 48 but got {bsr.BitsRemaining}");
            }
            Positions = new Vector3[len];
            for (int i = 0; i < len; i++)
            {
                Positions[i] = Center + new Vector3(bsr.ReadSShort(), bsr.ReadSShort(), bsr.ReadSShort());
            }
        }
コード例 #6
0
 protected override void Parse(ref BitStreamReader bsr)
 {
     FileStamp       = bsr.ReadStringOfLength(8);
     DemoProtocol    = bsr.ReadUInt();
     NetworkProtocol = bsr.ReadUInt();
     ServerName      = bsr.ReadStringOfLength(260);
     ClientName      = bsr.ReadStringOfLength(260);
     MapName         = bsr.ReadStringOfLength(260);
     GameDirectory   = bsr.ReadStringOfLength(260);
     PlaybackTime    = bsr.ReadFloat();
     TickCount       = bsr.ReadSInt();
     FrameCount      = bsr.ReadSInt();
     SignOnLength    = bsr.ReadUInt();
 }
コード例 #7
0
        protected override void Parse(ref BitStreamReader bsr)
        {
            SendPropType = DemoInfo.SendPropTypes[(int)bsr.ReadUInt(5)];
            Name         = bsr.ReadNullTerminatedString();
            Flags        = (int)bsr.ReadUInt(DemoInfo.SendPropFlagBits);
            if (DemoInfo.NewDemoProtocol && !DemoInfo.IsLeft4Dead1())
            {
                Priority = bsr.ReadByte();
            }
            if (SendPropType == SendPropType.DataTable || DemoInfo.PropFlagChecker.HasFlag(Flags, PropFlag.Exclude))
            {
                ExcludeDtName = bsr.ReadNullTerminatedString();
            }
            else
            {
                switch (SendPropType)
                {
                case SendPropType.String:
                case SendPropType.Int:
                case SendPropType.Float:
                case SendPropType.Vector3:
                case SendPropType.Vector2:
                    LowValue  = bsr.ReadFloat();
                    HighValue = bsr.ReadFloat();
                    NumBits   = bsr.ReadUInt(DemoInfo.SendPropNumBitsToGetNumBits);
                    break;

                case SendPropType.Array:
                    NumElements = bsr.ReadUInt(10);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(SendPropType),
                                                          $"Invalid prop type: {SendPropType}");
                }
            }
        }
コード例 #8
0
 protected override void Parse(ref BitStreamReader bsr)
 {
     X        = bsr.ReadFloat();
     Y        = bsr.ReadFloat();
     R1       = bsr.ReadByte();
     G1       = bsr.ReadByte();
     B1       = bsr.ReadByte();
     A1       = bsr.ReadByte();
     R2       = bsr.ReadByte();
     G2       = bsr.ReadByte();
     B2       = bsr.ReadByte();
     A2       = bsr.ReadByte();
     Effect   = (HudMsgEffect)bsr.ReadByte();
     FadeIn   = bsr.ReadFloat();
     FadeOut  = bsr.ReadFloat();
     HoldTime = bsr.ReadFloat();
     FxTime   = bsr.ReadFloat();
     Message  = bsr.ReadNullTerminatedString();
 }
コード例 #9
0
 protected override void Parse(ref BitStreamReader bsr)
 {
     Unk = bsr.ReadFloat();
 }
コード例 #10
0
 protected override void Parse(ref BitStreamReader bsr)
 {
     F1 = bsr.ReadFloat();
     F2 = bsr.ReadFloat();
     F3 = bsr.ReadFloat();
 }
コード例 #11
0
        static void Main(string[] args)
        {
            if (!System.IO.File.Exists(fileName))
            {
                throw new System.IO.FileNotFoundException();
            }

            int record_count = 0;

            using (var wdb_stream = new BinaryReader(File.OpenRead(fileName)))
            {
                var signature = wdb_stream.ReadBytes(4);
                var build     = wdb_stream.ReadUInt32();
                var locale    = Encoding.UTF8.GetString(wdb_stream.ReadBytes(4).Reverse().ToArray());
                var unk_h1    = wdb_stream.ReadInt32();
                var unk_h2    = wdb_stream.ReadInt32();
                var version   = wdb_stream.ReadInt32();

                Console.WriteLine(fileName);
                Console.WriteLine("Locale: " + locale);
                Console.WriteLine("Build: " + build);

                using (var writer = File.CreateText(fileName + ".sql"))
                {
                    while (wdb_stream.BaseStream.Position != wdb_stream.BaseStream.Length)
                    {
                        var entry = wdb_stream.ReadInt32();
                        var size  = wdb_stream.ReadInt32();

                        if (entry == 0 && size == 0)
                        {
                            break;
                        }

                        ++record_count;

                        #region reader

                        var row_bytes = wdb_stream.ReadBytes(size);
                        var reader    = new BitStreamReader(row_bytes);

                        int titleLen      = (int)reader.ReadUInt32(11);
                        int titleAltLen   = (int)reader.ReadUInt32(11);
                        int cursorNameLen = (int)reader.ReadUInt32(6);

                        var racialLeader = reader.ReadBit() ? 1 : 0;

                        int[]    male_names_len  = new int[4];
                        int[]    female_name_len = new int[4];
                        string[] male_names      = new string[4];
                        string[] female_names    = new string[4];

                        for (int i2 = 0; i2 < 4; ++i2)
                        {
                            male_names_len[i2]  = (int)reader.ReadUInt32(11);
                            female_name_len[i2] = (int)reader.ReadUInt32(11);
                        }

                        for (int i2 = 0; i2 < 4; ++i2)
                        {
                            male_names[i2]   = reader.ReadEsqapedSqlString2(male_names_len[i2]);
                            female_names[i2] = reader.ReadEsqapedSqlString2(female_name_len[i2]);
                        }

                        var type_flags  = reader.ReadUInt32();
                        var type_flags2 = reader.ReadUInt32();

                        var type   = reader.ReadInt32();
                        var family = reader.ReadInt32();
                        var rank   = reader.ReadInt32();

                        var kill_kredit1 = reader.ReadInt32();
                        var kill_kredit2 = reader.ReadInt32();

                        var modelid1 = reader.ReadInt32();
                        var modelid2 = reader.ReadInt32();
                        var modelid3 = reader.ReadInt32();
                        var modelid4 = reader.ReadInt32();

                        var HealthModifier = reader.ReadFloat();
                        var ManaModifier   = reader.ReadFloat();

                        var quest_item_count = reader.ReadInt32();
                        var movement_id      = reader.ReadInt32();
                        var unk543           = reader.ReadInt32();    // unk EXP

                        var questFlag  = reader.ReadInt32();
                        var vignetteID = reader.ReadInt32();

                        var title    = reader.ReadEsqapedSqlString2(titleLen);
                        var titleAlt = reader.ReadEsqapedSqlString2(titleAltLen);

                        var cursorName = reader.ReadEsqapedSqlString2(cursorNameLen);

                        int[] QuestItem = new int[6];
                        for (int i = 0; i < quest_item_count; ++i)
                        {
                            QuestItem[i] = reader.ReadInt32();
                        }

                        if (reader.Buffer.Length != reader.Index)
                        {
                            Console.WriteLine(reader.Buffer.Length - reader.Index);
                        }

                        #endregion

                        #region SQL
                        writer.WriteLine("REPLACE INTO `creaturecache` VALUES (\'" + locale + "\', {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25}, {26}, {27}, {28}, {29}, {30}, {31}, {32}, {33}, {34}, {35}, {36}, {37}, {38}, {39}, {40}, {41}, {42}, {43}, {44}, {45}, {46}, {47});",
                                         entry,
                                         titleLen,
                                         titleAltLen,
                                         cursorNameLen,
                                         racialLeader,

                                         male_names_len[0], female_name_len[0],
                                         male_names_len[1], female_name_len[1],
                                         male_names_len[2], female_name_len[2],
                                         male_names_len[3], female_name_len[3],

                                         male_names[0],
                                         female_names[0],

                                         male_names[1],
                                         female_names[1],

                                         male_names[2],
                                         female_names[2],

                                         male_names[3],
                                         female_names[3],

                                         type_flags, type_flags2,
                                         type, family, rank,
                                         kill_kredit1, kill_kredit2,
                                         modelid1, modelid2, modelid3, modelid4,

                                         HealthModifier.ToString(CultureInfo.InvariantCulture),
                                         ManaModifier.ToString(CultureInfo.InvariantCulture),

                                         quest_item_count,
                                         movement_id,
                                         unk543,
                                         questFlag,
                                         vignetteID,

                                         title,
                                         titleAlt,
                                         cursorName,

                                         QuestItem[0],
                                         QuestItem[1],
                                         QuestItem[2],
                                         QuestItem[3],
                                         QuestItem[4],
                                         QuestItem[5]
                                         );
                        #endregion
                    }
                    writer.Flush();
                }
            }
            Console.WriteLine("Reading {0} records", record_count);
            Console.WriteLine("Done!");
            Console.ReadLine();
        }