Esempio n. 1
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_quotation_marks.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_backslash_not_special.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
Esempio n. 3
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_backslash_not_special.vdf"))
     {
         data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream);
     }
 }
Esempio n. 4
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.unquoted_document.vdf"))
     {
         data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream);
     }
 }
Esempio n. 5
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.type_guessing.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
Esempio n. 6
0
        string PerformNewLineTest(string value, bool hasEscapeSequences)
        {
            KVObject convertedKv;
            var      kv      = new KVObject("newLineTestCase", value);
            var      options = new KVSerializerOptions {
                HasEscapeSequences = hasEscapeSequences
            };

            string text;

            using (var ms = new MemoryStream())
            {
                var serializer = KVSerializer.Create(KVSerializationFormat.KeyValues1Text);

                serializer.Serialize(ms, kv, options);

                ms.Seek(0, SeekOrigin.Begin);

                text = Encoding.ASCII.GetString(ms.GetBuffer(), 0, (int)ms.Length);

                convertedKv = serializer.Deserialize(ms, options);
            }

            Assert.That((string)convertedKv.Value, Is.EqualTo(value));

            return(text);
        }
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_backslash_not_special.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
Esempio n. 8
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.unquoted_document.vdf"))
     {
         data = KVSerializer.Deserialize(stream);
     }
 }
Esempio n. 9
0
 public void SetUp()
 {
     using (var stream = TestDataHelper.OpenResource("Text.escaped_quotation_marks.vdf"))
     {
         data = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream);
     }
 }
Esempio n. 10
0
        public object ConvertingObjectWithChildren(Type type)
        {
            var kv = new KVObject(
                "aaa",
                new[] { new KVObject("bbb", "ccc") });

            return(Convert.ChangeType(kv.Value, type));
        }
        public void SetUp()
        {
            var options = new KVSerializerOptions {
                FileLoader = new StubIncludedFileLoader()
            };

            using var stream = TestDataHelper.OpenResource("Text.kv_with_include.vdf");
            data             = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream, options);
        }
        public void SetUp()
        {
            var options = new KVSerializerOptions {
                HasEscapeSequences = true
            };

            using var stream = TestDataHelper.OpenResource("Text.escaped_whitespace.vdf");
            data             = KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Deserialize(stream, options);
        }
Esempio n. 13
0
        public void ConvertingObjectWithChildrenIsNotSupported(Type type)
        {
            var kv = new KVObject(
                "aaa",
                new[] { new KVObject("bbb", "ccc") });

            Assert.That(
                () => Convert.ChangeType(kv.Value, type),
                Throws.Exception.TypeOf <NotSupportedException>());
        }
Esempio n. 14
0
        public byte[] ToValveMaterial()
        {
            var root = new KVObject("Layer0", new List <KVObject>());

            root.Add(new KVObject("shader", ShaderName));

            foreach (var(key, value) in IntParams)
            {
                root.Add(new KVObject(key, value));
            }

            foreach (var(key, value) in FloatParams)
            {
                root.Add(new KVObject(key, value));
            }

            foreach (var(key, value) in VectorParams)
            {
                root.Add(new KVObject(key, $"[{value.X} {value.Y} {value.Z} {value.W}]"));
            }

            foreach (var(key, value) in TextureParams)
            {
                root.Add(new KVObject(key, value));
            }

            foreach (var(key, value) in IntAttributes)
            {
                root.Add(new KVObject(key, value));
            }

            foreach (var(key, value) in FloatAttributes)
            {
                root.Add(new KVObject(key, value));
            }

            foreach (var(key, value) in FloatAttributes)
            {
                root.Add(new KVObject(key, value));
            }

            foreach (var(key, value) in VectorAttributes)
            {
                root.Add(new KVObject(key, $"[{value.X} {value.Y} {value.Z} {value.W}]"));
            }

            foreach (var(key, value) in StringAttributes)
            {
                root.Add(new KVObject(key, value ?? string.Empty));
            }

            using var ms = new MemoryStream();
            KVSerializer.Create(KVSerializationFormat.KeyValues1Text).Serialize(ms, root);
            return(ms.ToArray());
        }
        public void SetUp()
        {
            var options = new KVSerializerOptions {
                HasEscapeSequences = true
            };

            using (var stream = TestDataHelper.OpenResource("Text.escaped_whitespace.vdf"))
            {
                data = KVSerializer.Deserialize(stream, options);
            }
        }
 public void SetUp()
 {
     data = new KVObject(
         "test data",
         new[]
         {
             new KVObject("foo", "bar"),
             new KVObject("bar", "baz"),
             new KVObject("baz", "-"),
         });
 }
 public void SetUp()
 {
     data = new KVObject(
         "test data",
         new[]
     {
         new KVObject("foo", "bar"),
         new KVObject("bar", "baz"),
         new KVObject("baz", "-"),
     });
 }
Esempio n. 18
0
        public void SetUp()
        {
            var options = new KVSerializerOptions {
                FileLoader = new StubIncludedFileLoader()
            };

            using (var stream = TestDataHelper.OpenResource("Text.kv_with_base.vdf"))
            {
                data = KVSerializer.Deserialize(stream, options);
            }
        }
Esempio n. 19
0
        public void LobbySendHTML(ulong lobbyId, string text)
        {
            var kv = new KVObject("Game::ChatReportMatchmakingStatus", new[]
            {
                new KVObject("run", "all"),
                new KVObject("xuid", Client.SteamID.ConvertToUInt64()),
                new KVObject("error", text),
                new KVObject("status", text),
            });

            LobbySendKeyValues(lobbyId, kv);
        }
Esempio n. 20
0
        private KVObject ParseBinaryKV3(BinaryReader reader, KVObject parent, bool inArray = false)
        {
            string name = null;

            if (!inArray)
            {
                var stringID = reader.ReadInt32();
                name = (stringID == -1) ? string.Empty : stringArray[stringID];
            }

            var(datatype, flagInfo) = ReadType(reader);

            return(ReadBinaryValue(name, datatype, flagInfo, reader, parent));
        }
Esempio n. 21
0
 public static string GetInstallPathForApp(int appId)
 {
     foreach (var libraryFolder in libraryFolders)
     {
         try {
             KVObject manifest   = parseKVFile($@"{libraryFolder}\steamapps\appmanifest_{appId}.acf");
             string   installDir = fixSlashes(manifest["installdir"].ToString());
             return($@"{libraryFolder}\steamapps\common\{installDir}");
         } catch (FileNotFoundException) {
             continue;
         }
     }
     throw new KeyNotFoundException();
 }
Esempio n. 22
0
        public void LobbySendChatMsg(ulong lobbyId, string message)
        {
            var kv = new KVObject("SysSession::Command", new[]
            {
                new KVObject("Game::Chat", new[]
                {
                    new KVObject("run", "all"),
                    new KVObject("xuid", Client.SteamID.ConvertToUInt64()),
                    new KVObject("name", Friends.GetPersonaName()),
                    new KVObject("chat", message),
                }),
            });

            LobbySendKeyValues(lobbyId, kv);
        }
 static void Merge(KVObject from, KVObject into)
 {
     foreach (var child in from)
     {
         var matchingChild = into.Children.FirstOrDefault(c => c.Name == child.Name);
         if (matchingChild == null && into.Value.ValueType == KVValueType.Collection)
         {
             into.Add(child);
         }
         else
         {
             Merge(from: child, into: matchingChild);
         }
     }
 }
Esempio n. 24
0
        public void WriteObject(KVObject data)
        {
            if (data.Value.ValueType == KVValueType.Collection)
            {
                WriteStartObject(data.Name);

                var children = data.Children;
                foreach (var item in children)
                {
                    WriteObject(item);
                }

                WriteEndObject();
            }
            else
            {
                WriteKeyValuePair(data.Name, data.Value);
            }
        }
Esempio n. 25
0
        public void LobbySendKeyValues(ulong lobbyId, KVObject kv)
        {
            var request = new ClientMsgProtobuf <CMsgClientMMSSendLobbyChatMsg>(EMsg.ClientMMSSendLobbyChatMsg);

            request.ProtoHeader.routing_appid  = 730;
            request.Header.Proto.routing_appid = 730;
            request.Body.app_id          = 730;
            request.Body.steam_id_lobby  = lobbyId;
            request.Body.steam_id_target = 0;

            var stream = new MemoryStream();

            stream.Write(new byte[] { 0x00, 0x00, 0x35, 0x7F }, 0, 4); // csgo version in big endian. TODO: Automatically fetch version from gc message
            KVSerializer.Create(KVSerializationFormat.KeyValues2Binary).Serialize(stream, kv);
            request.Body.lobby_message = stream.ToArray();

            //Console.WriteLine(ByteArrayToString(request.Body.lobby_message));
            Client.Send(request);
        }
Esempio n. 26
0
        KVObject MakeObject(KVPartialState state)
        {
            if (state.Discard)
            {
                return(null);
            }

            KVObject @object;

            if (state.Value != null)
            {
                @object = new KVObject(state.Key, state.Value);
            }
            else
            {
                @object = new KVObject(state.Key, state.Items);
            }

            return(@object);
        }
Esempio n. 27
0
        public void CreatesTextDocument()
        {
            var kv = new KVObject(
                "test data",
                new[]
            {
                new KVObject(
                    "0",
                    new[]
                {
                    new KVObject("description", "Dota 2 is a complex game where you get sworn at\nin Russian all the time."),
                    new KVObject("developer", "Valve Software"),
                    new KVObject("name", "Dota 2")
                }),
                new KVObject(
                    "1",
                    new[]
                {
                    new KVObject("description", "Known as \"America's #1 war-themed hat simulator\", this game lets you wear stupid items while killing people."),
                    new KVObject("developer", "Valve Software"),
                    new KVObject("name", "Team Fortress 2")
                })
            });

            string text;

            using (var ms = new MemoryStream())
            {
                KVSerializer.Serialize(ms, kv);

                ms.Seek(0, SeekOrigin.Begin);
                using (var reader = new StreamReader(ms))
                {
                    text = reader.ReadToEnd();
                }
            }

            var expected = TestDataHelper.ReadTextResource("Text.serialization_expected.vdf");

            Assert.That(text, Is.EqualTo(expected));
        }
        public void SerializesToBinaryStructure()
        {
            var first = new KVObject("FirstObject", new[]
            {
                new KVObject("firstkey", "firstvalue")
            });

            var second = new KVObject("SecondObject", new[]
            {
                new KVObject("secondkey", "secondvalue")
            });

            var expectedData = new byte[]
            {
                0x00, // object: FirstObject
                0x46, 0x69, 0x72, 0x73, 0x74, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00,
                0x01, // string: firstkey = firstvalue
                0x66, 0x69, 0x72, 0x73, 0x74, 0x6b, 0x65, 0x79, 0x00,
                0x66, 0x69, 0x72, 0x73, 0x74, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x00,
                0x08, // end object
                0x08, // end document

                0x00, // object: SecondObject
                0x53, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x4f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x00,
                0x01, // string: secondkey = secondvalue
                0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x6b, 0x65, 0x79, 0x00,
                0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x00,
                0x08, // end object
                0x08, // end document
            };

            using (var stream = new MemoryStream())
            {
                KVSerializer.Create(KVSerializationFormat.KeyValues1Binary).Serialize(stream, first);
                KVSerializer.Create(KVSerializationFormat.KeyValues1Binary).Serialize(stream, second);
                Assert.That(stream.ToArray(), Is.EqualTo(expectedData));
            }
        }
Esempio n. 29
0
        public void LobbySendOnRemoved(ulong lobbyId)
        {
            var kv1 = new KVObject("SysSession::OnPlayerRemoved", new[]
            {
                new KVObject("xuid", Client.SteamID.ConvertToUInt64()),
            });

            LobbySendKeyValues(lobbyId, kv1);

            var kv2 = new KVObject("SysSession::OnUpdate", new[]
            {
                new KVObject("update", new[]
                {
                    new KVObject("game", new[]
                    {
                        new KVObject("ark", 0),
                        new KVObject("apr", 0),
                        new KVObject("loc", "UA"),
                    }),
                }),
            });

            LobbySendKeyValues(lobbyId, kv2);
        }
Esempio n. 30
0
 public void ByteFailure(string value)
 {
     var kv = new KVObject("aaa", value);
     Assert.That(() => (byte)kv.Value, Throws.Exception.TypeOf<FormatException>().Or.TypeOf<OverflowException>());
 }
 public void SetUp()
 {
     data = new KVObject("foo", "bar");
 }
 public void AddItemForMerging(KVObject item) => includedObjectsToMerge.Add(item);
 public void AddItemForAppending(KVObject item) => includedObjectsToAppend.Add(item);
Esempio n. 34
0
 public void CharFailure(string value)
 {
     var kv = new KVObject("aaa", value);
     Assert.That(() => (char)kv.Value, Throws.Exception.TypeOf<FormatException>());
 }
Esempio n. 35
0
 public void UInt64Success(string value, ulong expected)
 {
     var kv = new KVObject("aaa", value);
     Assert.That((ulong)kv.Value, Is.EqualTo(expected));
 }
Esempio n. 36
0
 public void CharSuccess(string value)
 {
     var kv = new KVObject("aaa", value);
     Assert.That((char)kv.Value, Is.EqualTo(value[0]));
 }
Esempio n. 37
0
 public void ByteSuccess(string value, byte expected)
 {
     var kv = new KVObject("aaa", value);
     Assert.That((byte)kv.Value, Is.EqualTo(expected));
 }
Esempio n. 38
0
        public void ConvertingObjectWithChildrenIsNotSupported(Type type)
        {
            var kv = new KVObject(
                "aaa",
                new[] { new KVObject("bbb", "ccc") });

            Assert.That(
                () => Convert.ChangeType(kv.Value, type),
                Throws.Exception.TypeOf<NotSupportedException>());
        }
 public void AddItem(KVObject item) => CurrentObject.Items.Add(item);
Esempio n. 40
0
 public void BooleanSuccess(string value, bool expected)
 {
     var kv = new KVObject("aaa", value);
     Assert.That((bool)kv.Value, Is.EqualTo(expected));
 }
Esempio n. 41
0
        public object ConvertingObjectWithChildren(Type type)
        {
            var kv = new KVObject(
                "aaa",
                new[] { new KVObject("bbb", "ccc") });

            return Convert.ChangeType(kv.Value, type);
        }
Esempio n. 42
0
 public void UInt16Success(string value, ushort expected)
 {
     var kv = new KVObject("aaa", value);
     Assert.That((ushort)kv.Value, Is.EqualTo(expected));
 }
Esempio n. 43
0
 public void Int32Success(string value, int expected)
 {
     var kv = new KVObject("aaa", value);
     Assert.That((int)kv.Value, Is.EqualTo(expected));
 }