Forum

COM_LoadPackFile

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

COM_LoadPackFile

Postby Stealth Kill » Sun Dec 14, 2008 2:05 pm

hi,

How can i use the function COM_LoadPackFile?
I made a Language menu

here is a small part

case 0:
COM_LoadPackFile ("PAKeng");
M_Menu_Main_f();
break;

case 1:
COM_LoadPackFile ("PAKdt");
M_Menu_Main_f();
break;

I removed my singleplayer.lmp from PAK0
and added it to PAKeng and PAKdt with different languages.

The Game starts with the language menu.
If I choose a language it should load the pak file and
go to main menu but
says singleplayer.lmp not found.

i think it doesn´t load the pak file but i don´t know why.
Stealth Kill
 
Posts: 83
Joined: Fri Dec 29, 2006 12:34 pm

Re: COM_LoadPackFile

Postby Baker » Sun Dec 14, 2008 10:18 pm

Stealth Kill wrote: case 0:
COM_LoadPackFile ("PAKeng");
M_Menu_Main_f();
break;

case 1:
COM_LoadPackFile ("PAKdt");
M_Menu_Main_f();
break;



With the code above, you aren't specifying a directory or a file extension so it isn't finding the file.

Code: Select all
//
// add any pak files in the format pak0.pak pak1.pak, ...
//
   for (i=0 ; ; i++)
   {
      sprintf (pakfile, "%s/pak%i.pak", dir, i);
      pak = COM_LoadPackFile (pakfile);


The sprintf above is printing the directory into the variable with the extension.
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Re: COM_LoadPackFile

Postby Baker » Mon Dec 15, 2008 2:14 am

Stealth Kill wrote: case 0:
COM_LoadPackFile ("PAKeng");
M_Menu_Main_f();
break;

case 1:
COM_LoadPackFile ("PAKdt");
M_Menu_Main_f();
break;


ADD: Try these instead COM_LoadPackFile(va("%s/pakeng.pak", dir)) and COM_LoadPackFile(va("%s/pakdt.pak", dir));

Should work, at least as far as properly getting the pak file acknowledged as a place to look for files.

However, it looks like you are doing the above in the menu. The .lmp files are read rather early. Unless you are doing a command line parameter to specify the language, you'd need to get the menu elements reloaded.
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby Stealth Kill » Mon Dec 15, 2008 2:30 pm

hmmm i don´t know how to reload the menu :(
Stealth Kill
 
Posts: 83
Joined: Fri Dec 29, 2006 12:34 pm

Postby Baker » Mon Dec 15, 2008 3:09 pm

Stealth Kill wrote:hmmm i don´t know how to reload the menu :(


Sometime later today (several hours from now), I'll help you add it as a command line parameter (i.e. "yourquake -english") which will at least get this initially working for you for testing.

From that point forward, I'll look and see what surprises lie in reloading the menu elements (if any).
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby Baker » Mon Dec 15, 2008 10:46 pm

The command line parameter method of solving your problem:

In the example, there are 2 pak files named menu-dt.pak and menu-eng.pak.

If "-lang_dt" is added to the command line as such:

c:\quake\quake.exe -lang_dt

It will load the menu-dt.pak, otherwise it will by default use the menu-eng.pak.


common.c wrote:/*
================
COM_AddGameDirectory

Sets com_gamedir, adds the directory to the head of the path,
then loads and adds pak1.pak pak2.pak ...
================
*/
void COM_AddGameDirectory (char *dir)
{
int i;
searchpath_t *search;
pack_t *pak;
char pakfile[MAX_OSPATH];

strcpy (com_gamedir, dir);

//
// add the directory to the search path
//
search = Hunk_Alloc (sizeof(searchpath_t));
strcpy (search->filename, dir);
search->next = com_searchpaths;
com_searchpaths = search;

//
// add any pak files in the format pak0.pak pak1.pak, ...
//
for (i=0 ; ; i++)
{
sprintf (pakfile, "%s/pak%i.pak", dir, i);
pak = COM_LoadPackFile (pakfile);
if (!pak)
break;
search = Hunk_Alloc (sizeof(searchpath_t));
search->pack = pak;
search->next = com_searchpaths;
com_searchpaths = search;
}

/* Begin modification */
if ((i = COM_CheckParm("-lang_dt"))) { // Check for command line param
// Load German Menu
sprintf (pakfile, "%s/menu-dt.pak", dir); // set filename
} else {
// None specified, load English
sprintf (pakfile, "%s/menu-eng.pak", dir); // set filename
}

pak = COM_LoadPackFile (pakfile); // Try to load it
if (pak) { // If successfully loaded, add to end of search paths
search = Hunk_Alloc (sizeof(searchpath_t));
search->pack = pak;
search->next = com_searchpaths;
com_searchpaths = search;
}

/* End modification */



//
// add the contents of the parms.txt file to the end of the command line
//

}


I didn't test this out but it should work as-is.
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am

Postby Stealth Kill » Tue Dec 23, 2008 12:50 pm

It works thanks :)

is it possible with a cvar too?

i tried this

Code: Select all
/* Begin modification */
if (i = (language.value == 1)) {
// Load German Menu
sprintf (pakfile, "%s/german.pak", dir); // set filename
} else {
// None specified, load English
sprintf (pakfile, "%s/english.pak", dir); // set filename


if i write this language "1" to my config.cfg
it stilll loads the english.pak.
Stealth Kill
 
Posts: 83
Joined: Fri Dec 29, 2006 12:34 pm

Postby Baker » Tue Dec 23, 2008 3:57 pm

Stealth Kill wrote:It works thanks :)

is it possible with a cvar too?


Not as easily in the way you want to do it. The pakfiles are read at startup. Then the graphics are loaded.

It would almost be easier to load both menus at startup and have both sets of menus available. Then you could use a cvar.
The night is young. How else can I annoy the world before sunsrise? 8) Inquisitive minds want to know ! And if they don't -- well like that ever has stopped me before ..
User avatar
Baker
 
Posts: 3666
Joined: Tue Mar 14, 2006 5:15 am


Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest