W:ET Source - Parsing script files


(Flippy) #1

Hi,

Ever since I started working on the very first version of ETScript, I had one final goal in mind: to have my application read and actually parse the script file the same way W:ET parses it in-game.

I had no hope of completing that goal until the source code was released. Now, I have plowed through the source looking for ways to parse the script files many times, but never getting remotely close.

I have decided to ask the help of experienced modders, maybe even devs?

Since I am using the .NET framework to program ETScript in, my goal is to ultimately create a DLL file that contains the exact parsing code you use in the source code to parse scripts. It should contain a function I can call to pass a script file, and it should then do it’s magic, after which it returns a list of errors (the strings you can see in game, for example when you have a missing brace or something…).

So, it may be possible that I have no clue what goes on inside the DLL. All I have to do is pass the script file to it, and it will return the list of errors just like the actual game.

For this to work of course, I need to find out exactly how you pass a script to your parse functions, and of course, what functions your actual parse functions are

The first stop I made is in the g_script.c file, specifically the void G_Script_ScriptLoad( void ) function.
By my limited knowledge of C(++?), I can see that it does some checks for the name of the script file, checks if it’s lms mode, and appends the .script extension to the file name. Then, the file is opened, and some stuff I don’t understand comes up, after which the file is closed again…:

// END Mad Doc - TDF
	// Arnout: make sure we terminate the script with a '\0' to prevent parser from choking
	//level.scriptEntity = G_Alloc( len );
	//trap_FS_Read( level.scriptEntity, len, f );
	level.scriptEntity = G_Alloc( len + 1 );
	trap_FS_Read( level.scriptEntity, len, f );
	*(level.scriptEntity + len) = '\0';

	// Gordon: and make sure ppl haven't put stuff with uppercase in the string table..
	G_Script_EventStringInit();

	// Gordon: discard all the comments NOW, so we dont deal with them inside scripts
	// Gordon: disabling for a sec, wanna check if i can get proper line numbers from error output
//	COM_Compress( level.scriptEntity );

	trap_FS_FCloseFile( f );

Where is the actual parsing done here? I can find dozens of “Parse_…” functions, but I cannot find any call to them in here…

Oh well… I hope someone can help me with this. Since my knowledge of C is very very basic I have no hope of ever figuring it out on my own. I think a tool like this would be a very nice addition to ETScript; you don’t even have to open the game anymore to find out you made a stupid typo somewhere, you can find that out right inside the editor!

Does anyone know if it is possible what I’m asking for? To compile the required functions into a DLL file which I can reference and use in my project?

Thanks!!!


(crapshoot) #2

G_Script_ScriptParse is what does the syntax checking as far as I know. The block you posted seems to just read the file into memory. You will see in the ScriptParse function where it references level.scriptEntity.

Relevant calls to the parse function are in G_CallSpawn(). The tricky part of this would most likely be that it relies on being able to reference entity properties (like scriptName), so either .map or bsp parsing would probably be part of the solution.

I guess the short answer to your question is, yes I think it is possible.


(Flippy) #3

[QUOTE=crapshoot;191313]G_Script_ScriptParse is what does the syntax checking as far as I know. The block you posted seems to just read the file into memory. You will see in the ScriptParse function where it references level.scriptEntity.

Relevant calls to the parse function are in G_CallSpawn(). The tricky part of this would most likely be that it relies on being able to reference entity properties (like scriptName), so either .map or bsp parsing would probably be part of the solution.

I guess the short answer to your question is, yes I think it is possible.[/QUOTE]

Thanks for your reply.

I see how the parse calls are made now, that makes a bit more sense, thanks.

Also, I realize that the entities in the bsp are a big part of the parsing, but that won’t be much of a problem: I can already parse the BSP file and extract all the entities along with their properties. I am actually already using that in ETScript.

I will take another look tomorrow and hope that I get a bit closer. :slight_smile:


(unf4z3d) #4

I had the same idea for my nickname genrator, but when i found out et just has a color table i just rewrote it in a javascript arr:tongue: XD