Raised This Month: $12 Target: $400
 3% 

[ H3LP ] Parsing BSP File


Post New Thread Reply   
 
Thread Tools Display Modes
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
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-27-2019 , 15:16   Re: [ H3LP ] Parsing BSP File
Reply With Quote #2

The OnLevelInit provides the extracted entity lump for the current map, you can load it as KeyValues.
__________________
asherkin is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 01-27-2019 , 15:21   Re: [ H3LP ] Parsing BSP File
Reply With Quote #3

Quote:
Originally Posted by asherkin View Post
The OnLevelInit provides the extracted entity lump for the current map, you can load it as KeyValues.
PHP Code:
Action OnLevelInit(const char[] szMapNamechar szMapEntities[2097152])
{
    
// ?

How would I do that exactly?
Is szMapEntities the char that holds the keys and values for each entity?

Last edited by DarthMan; 01-27-2019 at 15:21.
DarthMan is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-27-2019 , 15:29   Re: [ H3LP ] Parsing BSP File
Reply With Quote #4

Quote:
Originally Posted by DarthMan View Post
Is szMapEntities the char that holds the keys and values for each entity?
Yes.

https://sm.alliedmods.net/new-api/ke...portFromString
__________________
asherkin is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 01-27-2019 , 15:38   Re: [ H3LP ] Parsing BSP File
Reply With Quote #5

Quote:
Originally Posted by asherkin View Post
I did that for a test, and it doesn't seem to work.

PHP Code:
public Action OnLevelInit(const char[] szMapNamechar szMapEntities[2097152])
{
    if(!
StrEqual(szMapName"ff_xpress_b1"true))
        return 
Plugin_Continue;
    
    
char szMapPath[160];
    
    
FormatEx(szMapPathcharsmax(szMapPath), "%s-dump.txt"szMapName);
    
    
Handle hFile OpenFile(szMapPath"w");
    
    
WriteFileString(hFileszMapEntitiesfalse);
    
    
CloseHandle(hFile);
    
    return 
Plugin_Continue;

It's like the forward isn't called and I have #include <sdkhooks>
And I made it to only dump if the map is ff_xpress_b1.

Last edited by DarthMan; 01-27-2019 at 15:39.
DarthMan is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 01-27-2019 , 16:14   Re: [ H3LP ] Parsing BSP File
Reply With Quote #6

Quote:
Originally Posted by asherkin View Post
Apparently berni said somewhere in the forum that it doesn't work (OnLevelInit forward), and that was sometimes in 2011.
Perhaps it just doesn't work on Fortress Forever and maybe other source games.
Seems to work fine on TF2 from what I read (forum posts from 2014).

Can the forward be fixed?

Read here too: https://forums.alliedmods.net/showpo...postcount=2660

Edit: I got it to work with #pragma dynamic 2097152

Last edited by DarthMan; 01-27-2019 at 16:43. Reason: Solved
DarthMan is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:42.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode