Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KV1BinaryNodeType.WideString #95

Open
Ellome opened this issue Mar 6, 2024 · 4 comments
Open

KV1BinaryNodeType.WideString #95

Ellome opened this issue Mar 6, 2024 · 4 comments

Comments

@Ellome
Copy link

Ellome commented Mar 6, 2024

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;
@xPaw
Copy link
Member

xPaw commented Mar 6, 2024

Can you create a pull request (with some tests)?

@Ellome
Copy link
Author

Ellome commented Mar 6, 2024

Yes, but since I only found out what .NET is yesterday, this will not be quick xD.
By the way, with these same messages from the lobby, there was another moment akin to a magic header, specific to the game, so I'll get both sorted out at once.

@yaakov-h
Copy link
Member

yaakov-h commented Mar 7, 2024

We have the existing C++ code quoted here: #34

A magic header for game-specific data probably doesn't belong in this lib? It's hard for me to judge without seeing it though.

@Ellome
Copy link
Author

Ellome commented Mar 7, 2024

We have the existing C++ code quoted here: #34

A magic header for game-specific data probably doesn't belong in this lib? It's hard for me to judge without seeing it though.

Though there was none in lib. If you can make pull request or rewrite it, you will surely do it faster.
Please tell then whether will you implement it, so i wont.

L4D series prepend int32be version to every lobbychat message, not sure about other games, and thats why NetHookAnalyzer2 didnt show them as KeyValues correctly and also its KV lib didnt support AlternateEnd \x0b, so i updated its code and used this lib for these messages to be shown convinient way as a tree.

Since i am not that familiar neither with git, nor c# it will be better if you will make commit for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants