alliedmodders / sourcemod

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

IsMapValid() uses partial search #1389

Open dragokas opened 4 years ago

dragokas commented 4 years ago

Help us help you

Environment

Description

When you check is map valid with IsMapValid() function, it also returns true when partial-string matched. Is it by intention?

Problematic Code (or Steps to Reproduce)

#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    RegConsoleCmd("sm_test",        CmdCheckMap);
}

public Action CmdCheckMap(int client, int args)
{
    char map[64];
    char displayName[PLATFORM_MAX_PATH];

    map = "de_swamp";
    //GetCmdArg(1, map, sizeof(map));

    PrintToServer("Checking map: %s", map);
    PrintToServer("Map valid? %b", IsMapValid(map));

    if (FindMap(map, displayName, sizeof(displayName)) == FindMap_NotFound)
    {
        PrintToServer("Map was not found: %s", map);
        return Plugin_Handled;
    }

    GetMapDisplayName(displayName, displayName, sizeof(displayName));
    PrintToServer("Map display name: %s", displayName);

    return Plugin_Handled;
}

Logs

Checking map: de_swamp
Map valid? 1
Map display name: styleguide_swamp01

Actually, there is no de_swamp.bsp in Left 4 Dead 2. Instead, there is maps/styleguide_swamp01.bsp

dragokas commented 4 years ago

Even, "sm_map" lies. She is reporting about success, but ForceChangeLevel() is failed.

sm_map 1
[SM] Changing map to c14m1_junkyard...
L 11/28/2020 - 18:15:47: [basecommands.smx] "Console<0><Console><Console>" changed map to "1"
L 11/28/2020 - 18:15:50: [SM] Changed map to "1"
CModelLoader::Map_IsValid:  No such map 'maps/1.bsp'
changelevel failed: 1 not found
asherkin commented 4 years ago

This is intentional, and was done to match the behaviour of changelevel - but from your test there it looks like L4D2 might not actually be a version with that behaviour (or there are other restrictions in play).

351 has some background info here, I think it is likely that CHalfLife2::IsMapValid needs changing to check == Found rather than != NotFound, but it'll need testing across at least L4D2, TF2, CS:GO, and SDK2013 by the sound of it.

Mart-User commented 4 years ago

In L4D2 the !map command fails also when the fullname of the map is not specified.

Example: c1m1_hotel

If I type !map c1m1 in the chat, it says "changing to c1m1_hotel" but doesn't changes, and if I try to use the command again, it stops working (even with the full name).

To make it work again, I always have to restart the server. (changing the map doesn't fix)

dragokas commented 3 years ago

For me, even more strange things are happening. When I enter something like "sm_map 1" and passed to the final safe room, the round looks like ends (i see the statistics), but after 5 sec, map still doesn't end, statistics is disappeared and I got frozen player on the old map.