quake pak files in php - classPak

Introduction

classPak is a PHP class for creating dynamic PAK files for the Quake I and II engines. Get classPak (download, view) and read below to see how to use it.

Synopsis

add_file (realpath, pakpath)
Add the physical file specified by realpath to the pak file as pakpath. Returns TRUE if successful, FALSE otherwise (eg, too long a pakpath). Adding more than one file with the same pakpath will result in undefined behaviour.

add_directory (realpath, pakpath [, match])
A helper function that recurses through the directory realpath and adds every file found to the pak file under pakpath. The optional match parameter is a regular expression specifying the pattern of files to include. If not specified, all files will be included. Returns TRUE on success, FALSE on failure (eg bad dir).

remove_file_by_path (realpath)
Removes the file realpath from the pak file by matching its real path. You cannot remove whole directories using this function.

remove_file_by_pakpath (pakpath)
Removes the file pakpath from the pak file by matching its pak path. You cannot remove whole directories using this function.

generate_pak (optimize)
Generate the pak file. Returns a binary string containing the entire pak file data if successful. If optimize is TRUE, the data will be optimized to remove duplicate file data (see pakoptimz). This may make the pak file smaller at the expense of being incompatible with some pak editors.

save_pak (path, optimize)
A helper function that generates and writes the .pak to path. See above for details about optimize.

Example:

<?php
    
require_once ('classPak.php');

    
$packfile = new classPak();
    
$packfile->add_file ('./data/map1.bsp''maps/map1.bsp');
    
$packfile->add_directory ('./data/textures/map1''textures/map1');

    
$pakdata $packfile->generate_pak (TRUE);
    
header ('Content-type: application/octet-stream');
    
header ('Content-disposition: attachment; filename="pak9.pak"');
    print 
$pakdata;
?>

Example Implementation

See the source for the details.

Select the files you want in your customised pak:

Crosshair 1

Crosshair 2

Textures