Skip to content

KV1BinaryNodeType.WideString #95

@Ellome

Description

@Ellome

Was looking through steamapi msgs and found kv wstring type in lobby chat

In case one will need it, here is a short add for ValveKeyValue/Deserialization/KeyValues1/KV1BinaryReader.cs

replace

case KV1BinaryNodeType.WideString:
                    throw new NotSupportedException("Wide String is not supported, please create an issue saying where you found it: https://github.com/ValveResourceFormat/ValveKeyValue/issues");

with

case KV1BinaryNodeType.WideString:
    byte[] bytes = new byte[2];

    bytes = reader.ReadBytes(2);

    if (BitConverter.IsLittleEndian)
    {
        Array.Reverse(bytes, 0, 2);
    }

    int length = BitConverter.ToInt16(bytes, 0);

    List<byte> byteList = new List<byte>();

    for(int i = 0; i < length; i++)
    {
        bytes = reader.ReadBytes(2);
        
        byteList.AddRange(bytes);
    }

    string wstring_utf16 = Encoding.BigEndianUnicode.GetString(byteList.ToArray());
    //string wstring_utf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(wstring_utf16));

    value = new KVObjectValue<string>(wstring_utf16, KVValueType.WString);
    //value = new KVObjectValue<string>(wstring_utf8, KVValueType.WString);
    break;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions