Max Payne :: Zen Of Filestructure

File: /articles/filestructure.php
Updated: 20.08.2001 - 17:24 - @683

click here for a printable version

Version: 0.93

Content:

  1. Theory
  2. Using and configuring rasmaker
  3. MOD Making
  4. Using data-dir as a developer
  5. Closing words

Foreword

This article/tutorial goes through the basics of mpm filestructure and how you should work with it. We'll do a basic mpm where we add a level and use it in the game itself.

So let's start, shall we.

Theory

Alright, Max Payne uses a simple datastructure which is divided into directories. If you understand how PAK in quake works MPM is almost the same.

The directories goes like this:

  • data\
  • data\database\
  • data\database\levels
  • data\database\weapons
  • data\database\particles
And so on. You can see the whole structure when we extract the RAS-files later.

There are two ways to make Max Payne load your own files. Here's a bit from the documentation of Max-Fx:

Max Payne loads data files based on this priority list:

  • Individual files under the data\ folder
  • Files in the currently activated .mpm mod package
  • Files in the game shipping .ras packages
When you are developing a mod, you will need to have the files you plan to edit open as regular files under the data\ folder. Once you've finished your mod, you should package it with the RasMaker tool into something like "Sam's Weapon Factory.mpm" which will become available as a "Customized game" in the startup dialog.

Lets imagine that I have the game installed in c:\maxpayne -folder, my executable is of course c:\maxpayne\maxpayne.exe and so on.

So, if we make a folder called c:\maxpayne\data\database\levels\mylevels\ and insert a file called mylevel1.ldb in that folder, that specific level will be loaded by the game automatically (of course, in case you've edited levels.txt also, read more here). It won't even ask or say anything, because that specific data-folder is understood as basic data, same as the rest of the original files in data-folder.

The idea is quite simple. You'll understand it better when we'll actually do something. Don't worry if you don't understand this all yet. It will all be more clear at the end of this article. But first we need to make RASMaker work like we want it to work.

Using and configuring rasmaker

I think we should now do something practical, so let's extract those RAS-files, which holds Max Payne's -gamedata. I suppose you've installed all max-fx tools, so look up the rasmaker directory. If you are advanced in dos etc, you can skip the next few chapters where i just explain how one should use rasmaker in cmdline prompt.

When you've found rasmaker (probably something like c:\program files\max-fx tools\rasmaker\, open up the dos prompt by choosing Start -> Run and then type "command" in the dialog. In windows 2000 you should type just 'cmd'. Press return when ready. The DOS Prompt should now start. There are two ways we can set rasmaker.exe so that's easy to use. Basically we need a path to it so we can run it anywhere we want. For now, you have to always have the executable at the same dir when you want to use it. This is just to ease things up. The other option is, that you command rasmaker by using the full path every time, like c:\program files\max-fx tools\rasmaker\rasmaker.exe -a data mymod.mpm. As you can see, that isn't very healthy for your fingers. We can ease things up in two ways:

Copy the rasmaker-files to a directory which has a path. Now this is a bit tricky: type just path in your prompt and see what it outputs. You might see a lot of text, the idea is, that all those directories which are separated with a ; has a path. You need to copy your file in one of those paths, for instance c:\windows\ might be in the path, so just use windows explorer and copy all files (there should just be two) from the c:\program files\max-fx tools\rasmaker\ folder to the c:\windows -folder, and that's it. Or of course, any other dir is fine too.

The other way is:
Make a path of your own. So, you need to look where the rasmaker-files are. We'll add the rasmaker-dir to the path simply by commanding path c:\pathtorasmaker\;%path%. The problem is, that DOS is an ancient OS and supports only 8 characters long filenames. So you need to shorten directories to 6 first letters and end it with ~1. So for instance, if you have the files in c:\program files\max-fx tools\rasmaker\, you should command like this:

path c:\progra~1\max-fx~1\rasmaker;%path%

That's it, now you have rasmaker in your path, and you can command it from any folder. Try it out by cd:ing to the root for instance and typing "rasmaker". If it still doesn't work, you can try to put the rasmaker-files in folder c:\rasmaker and then making a path to it by commanding path c:\rasmaker;%path%.

Extracting Max Payne Data-files

So you have now rasmaker set up and all. CD to c:\maxpayne (or whatever your MP-folder is called, i'll just refer to c:\maxpayne) and type rasmaker -x x_data.ras. That extracts the file x_data.ras to current folder. Don't worry, it'll just put the data\ -subdir under your maxpayne-root, like c:\maxpayne\data. We need to extract all other ras-files too. So make a dir *.ras to see what other ras-files there are, and do the same operation to them.

Now when you have extracted all data which is in those RAS-files, you don't need the RAS-files anymore, but don't delete them! Rather make a dir under maxpayne called c:\maxpayne\ras-files for instance, and move them there. You don't need those any more, because all information is now loaded from that data -directory! Max-Fx documentation tells us why we don't want to have RAS-files there anymore:

After you have uncompressed the game data files, you should move all the .ras files away from the game root. Otherwise you will get a "duplicate entry" type error when loading the game. This is due to the way the game loads for example all *.txt files from the weapons folder. If you don't move the .ras packages away, the game will find for example two weapons called "beretta".

MOD Making

Configuring Levels.txt

You need to make an entry of your level in the levels.txt. The innards of levels.txt has simple blocks of information, each block represents one map. The syntax looks like this:

[map_name]
{
//commentation looks like this
map information
}

The easiest way is to copy an existing mapblock. So we need the original levels.txt. Go to folder c:\maxpayne\data\database\levels\ and copy the existing levels.txt to your mod-folder c:\mymod\data\database\levels\. Then edit the file you copied into your mod-structure and copy the first block. Change all variables in the copied textblock and set the correct filenames and folders to look the map for. In the "mapfolder" part you should set "mylevels" et cetera.

Here's an example, how a mapblock in levels.txt should look like (if used above definitions):


[mylevel]
{
	[Properties]
	LevelName		= "Testing Map";
	Directory 		= mylevels;
	Level 			= test.ldb;
	Gravity 		= ( 0, GRAVITY_VALUE , 0 );
	AmbientColor 	= ( 140, 135, 110 );
	DebrisProjectileCountInLevel = 400;
	DebrisProjectileCountPerRoom = 50;
	PlayerSkinName  = "max_payne"; 
	LoadingScreen	= "..\autosave\P0L0.jpg";
	WorldSphere 	= "intro";
	EnableAI		= FALSE;
	PlayerStartingPlace = "::StartRoom::Jumppoint_00";
	Fogging			= TRUE;
	FogColor		= ( 0, 0, 0 );
	FogStart		= 2000.0; // Level adjusts on the fly
	FogEnd			= 5000.0;
	StartupLevel	= false;
	ExitLevel		= false;
	AINodeCastHeight= 0.0; // zero uses room bounding box height

	[Difficulty]
	MaximumHealth	= 300%; // percent of player's maximum health
	MinimumHealth	= 0%; // percent of player's maximum health
	MinimumDeaths	= 0; // number of deaths in this level
	MaximumDeaths	= 100; // number of deaths in this level
	MinimumTime		= 0; // total level playtime in seconds
	MaximumTime		= 3600; // total level playtime in seconds
	HardcoreHealth	= 300%;  // difficulty scales up if the player has more health
	HardcoreDeaths	= 0;     // difficulty scales up if the player has died less often
	HardcoreTime	= 0;   // difficulty scales up if the player has played faster

	[Timedmode]
	PlayTime		= 60; // initial playtime in seconds
	EnemyTimeBonus	= TIMEBONUS; // number of additional seconds gained by killing an enemy
}

The most relevant parts are:


[mylevel]
{
	[Properties]
	LevelName		= "Testing Map";
	Directory 		= mylevels;
	Level 			= test.ldb;
	EnableAI		= FALSE;
	PlayerStartingPlace = "::StartRoom::Jumppoint_00";
}

Change the map name in the brackets (where reads 'mylevel') to your preference, don't use spaces. Remember this, because when you load this map in the console, you need to use that name you put between the brackets. The directory-part tells the dir-name to look under the levels\. In this case, it's mylevels\. So the path in the dir should be c:\mymod\data\database\levels\mylevels\. You should also change this dirname to your preference. LevelName -variable just defines the "long" name to your level.

PlayerStartingPlace defines the jumppoint where the game starts. The syntax goes like "::roomname::jumppointname". If you get messages of invalid starting places or something similar, you most probably have this line wrong in the levels.txt. Or then there's something wrong with the map.

Making the MPM

Remember the earlier part where i citated Max-Fx documentation? It went like this:

Max Payne loads data files based on this priority list:

  • Individual files under the data\ folder
  • Files in the currently activated .mpm mod package
  • Files in the game shipping .ras packages
When you are developing a mod, you will need to have the files you plan to edit open as regular files under the data\ folder. Once you've finished your mod, you should package it with the RasMaker tool into something like "Sam's Weapon Factory.mpm" which will become available as a "Customized game" in the startup dialog.

So there you have it. However, the doc doesn't explain the fact, that you should really just have a file-structure similar to the one which we uncompressed under c:\maxpayne\, but only with files we have made ourselves or edited. Now, let's go back to our mod-making and imagine that you have a level ready for distribution. It's called mylevel.dlb, and you want to distribute it as a .MPM -file.

First you need to make the empty filestructure like in c:\maxpayne\data. Just do a dir like c:\mymod and make the filestructure there. Here's how it should look:

  • c:\mymod
  • c:\mymod\data
  • c:\mymod\data\database
  • c:\mymod\data\database\levels
  • c:\mymod\data\database\levels\mylevels
You should always make an unique folder for your levels, we call it mylevels and it's the last dir in the filestructure i showed. Now copy your .dlb file in that mylevels-folder. You need to also have levels.txt in folder c:\mymod\data\database\levels\. When you are done with your editing, we're ready to compile our map. Start the dos prompt and go to c:\mymod\ directory and command

rasmaker -a data mymod.mpm

Now rasmaker will compile a mod called mymod.mpm and it has your map, and the edited levels.txt. Now, in case you haven't already, you need to rename that data -folder in c:\maxpayne to something else. Because if you have it there when you try the mod, the game will just use the levels.txt found in that folder, because it's the priority number Uno when loading game files. When you have renamed the data-folder, move the RAS-files back to c:\maxpayne because we still need the other gamefiles too.

Now when you've done this, move your .mpm to c:\maxpayne and start the game in developer-mode. Check that you don't have the -nodialog -option, because we need the first dialog to choose our mod from.

When you have chosen the mod from the upcoming dialog (it's there, at the bottom), start the game. And bring up the console (use F12) and type:

maxpayne_gamemode->gm_init(mylevel);

That initializes your map, next you have to switch to the game-mode:

x_modeswitch->s_modeswitch(game);

And that should finally load the level. The parameter in gm_init (which is in this example "mylevel") is now the one you put into those brackets in levels.txt.

Using data-dir as a developer

If you are developing a MOD/level, I suggest you don't compile it every time as a MPM, rather skip the process and copy the ldb with the appropriate levels.txt straight under the data\ -dir under maxpayne-root.

Of course you need to create it first, either by yourself or by just extracting all RAS-files. Remember to remove the RAS-files so you don't get multiple occasions of data-entities. This is the method I prefer. Reasons are:

  1. You save time when you don't have to do MPM every time
  2. You can later calculate the AI easily
  3. You can easily access all files, in realtime
  4. It's cool
  5. You can have maxpayne the game (hey that rhymed) open in window-mode with maxed, and just extract the ldb straight to the data-dir and just load the level again in the console, without even closing the game. Easy and effective
Compiling a MPM should be a special phase in making a mod. Perhaps a beta-release for testers, or other groupmembers. Or, of course, in the first public release. It's only needed if you want to have the mod easily playable for other people.

Closing Words

Now you've learned the way how MPM's and the rest filestructure works. If you didn't, read this text again. It's basically fairly simple, when you get it. There are still some issues in the use of MPM-files, and i'm working on them. I'll update this article/tutorial when i get more information.


--Mikael Kasurinen aka mixuk

note: if you want to comment this article, you can mail me.