View Single Post
Author Message
DarthMan
Veteran Member
Join Date: Aug 2011
Old 01-27-2019 , 14:40   [ H3LP ] Parsing BSP File
Reply With Quote #1

Hello. I am trying to parse a bsp file to get the keys and values of each entity, but ti doesn't seem to work well. No text is parsed.

PHP Code:
stock int strtok(const char[] szTextchar[] szLeft, const int iLeftLenchar[] szRight, const int iRightLen, const char[] szToken, const int iTrimSpaces 0// from max_utils.inc
{
    
int iPosLen 0;
    
    
iPosLen StrContains(szTextszToken);
    
    if(!
iPosLen)
        return 
0;
    
    
SplitString(szTextszTokenszLeftiLeftLen);
    
    
strcopy(szRightiRightLenszText[iPosLen strlen(szToken)]);
    
    if(
iTrimSpaces)
    {
        
TrimString(szLeft);
        
TrimString(szRight);
    }
    
    return 
strlen(szText);
}

void ParseEntities()
{
    
char szMapName[128], szMapPath[512], szFileLine[2048];
    
int iEntID START_ENTITY;
    
    
GetCurrentMap(szMapNamecharsmax(szMapName));
    
    
FormatEx(szMapPathcharsmax(szMapPath), "maps/%s.bsp"szMapName);
    
    
Handle hFile OpenFile(szMapPath"r");
    
    if(
hFile == INVALID_HANDLE)
    {
        
LogError("Error parsing map '%s'!"szMapName);
        
        return;
    }
    
    while(!
IsEndOfFile(hFile) && ReadFileLine(hFileszFileLinecharsmax(szFileLine)))
    {
        if(
strlen(szFileLine) == 0)
            continue;
        
        if(
StrContains(szFileLine"\"classname\"") != -1)
        {
            if(
StrContains(szFileLine"\"hammerid\"") != -1// on Fortress Forever hammerid doesn't exist
                
continue;
            
            while(!
IsEndOfFile(hFile) && ReadFileLine(hFileszFileLinecharsmax(szFileLine)))
            {
                if(
strlen(szFileLine) == 0)
                    continue;
                
                if(
szFileLine[0] != '"' && szFileLine[0] != '{' && szFileLine[0] != '}')
                    break;
                
                if(
iEntID == START_ENTITY)
                    
PrintToServer(szFileLine);
                
                if(!
IsArrayValid(g_aEntVars[iEntID]))
                    
g_aEntVars[iEntID] = CreateArray(g_iArrayLeng_iArraySize);
                
                
char szLeft[128], szRight[128], szText[256];
                
strtok(szFileLineszLeftcharsmax(szLeft), szRightcharsmax(szRight), " ");
                
                
StripQuotes(szLeft);
                
StripQuotes(szRight);
                
                
FormatEx(szTextcharsmax(szText), "%s*%s"szLeftszRight);
                
                
PushArrayString(g_aEntVars[iEntID], szText);
                
                
// DEBUG
                
if(iEntID == START_ENTITY)
                    
PrintToServer(szText);
                
                if(
szFileLine[0] == '}')
                    
iEntID++;
            }
            
            break;
        }
    }
    
    
CloseHandle(hFile);


Last edited by DarthMan; 01-27-2019 at 14:53.
DarthMan is offline