alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
985 stars 423 forks source link

KvGetString represented as int #1824

Closed sheo9000 closed 2 years ago

sheo9000 commented 2 years ago

Environment

Description

If a KeyValue string consists of numeric characters only, and the value is big, it returns incorrect values. Source string:

"VDFresponse"
{
        "success" "1"
        "player_a0" "76561198034909367"
        "player_a1" "91662178184634525"
        "player_a2" "11562811565764339"
        "player_a3" "12192511247271115"
        "player_b0" "81926637784842249"
        "player_b1" "32519417278619213"
        "player_b2" "25262668645216893"
        "player_b3" "65792125846552674"
        "confogl" "zonemod"
        "first_map" "c10m1_caves"
        "last_map" "c10m4_mainstreet"
        "mmr_min" "-2000000000"
        "mmr_max" "2000000000"
        "game_state" "wait_readyup"
}

Problematic Code (or Steps to Reproduce)

        PrintToServer("%d", KvGetNum(kvGameInfo, "success", -1));

        char sBuffer[256];

        KvGetString(kvGameInfo, "confogl", sBuffer, sizeof(sBuffer), "default");
        PrintToServer(sBuffer);

        KvGetString(kvGameInfo, "player_a0", sBuffer, sizeof(sBuffer), "default");
        PrintToServer(sBuffer);

Output in server console

1
zonemod
2147483647

Instead of 76561198034909367 it returned 2147483647

Sikarii commented 2 years ago

SourceMod does not implement code on top of Valve's KeyValues, if you need something more reliable use SMCParser.

asherkin commented 2 years ago

This is the correct game behaviour, it makes the type decisions at parsing time.

If you're parsing the game's KV files, this is required behaviour. If you're parsing your own KV-like files, you should look into SourceMod's SMC parser.