Hi guys,
I'm trying to get a bsp loader/render (with collision detection) to work, and as bsp comes often in pak-files I've started with the creation of a little PAK-loader.
When I load the file, and read-in the directories, I write them for debug reason at the time being to a logfil and this is what I get...
/// Session started at: 25/07/2008 19:45:49
-> Data cutted out to shorten the list....
[19:45:50]sound/world/amb8.wav av v l 1� �-����
[19:45:50]sound/world/amb7.wav av v l 1� �-����
[19:45:50]pics/a_blaster.pcx v av v l 1� �-����
[19:45:50]pics/a_bullets.pcx v av v l 1� �-����
[19:45:50]pics/a_cells.pcx x v av v l 1� �-����
[19:45:50]pics/a_grenades.pcx av v l 1� �-����
[19:45:50]pics/a_rockets.pcx av v l 1� �-����
[19:45:50]pics/a_shells.pcx av v l 1� �-����
[19:45:50]pics/a_slugs.pcx av v l 1� �-����
[19:45:50]pics/anum_0.pcx av v l 1� �-����
[19:45:50]pics/anum_1.pcx av v l 1� �-����
[19:45:50]pics/anum_2.pcx av v l 1� �-����
[19:45:50]pics/anum_3.pcx av v l 1� �-����
[19:45:50]pics/anum_4.pcx av v l 1� �-����
[19:45:50]pics/anum_5.pcx av v l 1� �-����
[19:45:50]pics/anum_6.pcx av v l 1� �-����
[19:45:50]pics/anum_7.pcx av v l 1� �-����
[19:45:50]pics/anum_8.pcx av v l 1� �-����
[19:45:50]pics/anum_9.pcx av v l 1� �-����
[19:45:50]pics/anum_minus.pcx av v l 1� �-����
[19:45:50]pics/i_bodyarmor.pcx av v l 1� �-����
[19:45:50]pics/i_combatarmor.pcx v v l 1� �-����
[19:45:50]pics/i_health.pcx .pcx v v l 1� �-����
[19:45:50]pics/i_jacketarmor.pcx v v l 1� �-����
[19:45:50]pics/i_pack.pcx or.pcx v v l 1� �-����
[19:45:50]pics/i_powerscreen.pcx v v l 1� �-����
[19:45:50]pics/i_powershield.pcx v v l 1� �-����
[19:45:50]pics/num_0.pcx eld.pcx v v l 1� �-����
[19:45:50]pics/num_1.pcx eld.pcx v v l 1� �-����
[19:45:50]pics/num_2.pcx eld.pcx v v l 1� �-����
[19:45:50]pics/num_3.pcx eld.pcx v v l 1� �-����
[19:45:50]pics/num_4.pcx eld.pcx v v l 1� �-����
[19:45:50]pics/num_5.pcx eld.pcx v v l 1� �-����
[19:45:50]pics/num_6.pcx eld.pcx v v l 1� �-����
[19:45:50]pics/num_7.pcx eld.pcx v v l 1� �-����
[19:45:50]pics/num_8.pcx eld.pcx v v l 1� �-����
[19:45:50]pics/num_9.pcx eld.pcx v v l 1� �-����
[19:45:50]pics/num_minus.pcx pcx v v l 1� �-����
[19:45:50]pics/w_bfg.pcx pcx pcx v v l 1� �-����
[19:45:50]pics/w_blaster.pcx pcx v v l 1� �-����
[19:45:50]pics/w_chaingun.pcx cx v v l 1� �-����
[19:45:50]pics/w_glauncher.pcx x v v l 1� �-����
[19:45:50]pics/w_hgrenade.pcx x v v l 1� �-����
[19:45:50]pics/w_hyperblaster.pcx v l 1� �-����
[19:45:50]pics/w_machinegun.pcx x v l 1� �-����
[19:45:50]pics/w_railgun.pcx cx x v l 1� �-����
[19:45:50]pics/w_rlauncher.pcx x v l 1� �-����
[19:45:50]pics/w_shotgun.pcx x x v l 1� �-����
[19:45:50]pics/w_sshotgun.pcx x v l 1� �-����
[19:45:50]pics/net.pcx un.pcx x v l 1� �-����
[19:45:50]pics/m_main_plaque.pcx v l 1� �-����
[19:45:50]pics/m_main_options.pcx v l 1� �-����
[19:45:50]pics/m_main_multiplayer.pcx 1� �-����
[19:45:50]pics/m_main_video.pcx r.pcx 1� �-����
[19:45:50]pics/m_main_quit.pcx r.pcx 1� �-����
[19:45:50]pics/m_main_game.pcx r.pcx 1� �-����
[19:45:50]pics/help.pcx me.pcx r.pcx 1� �-����
[19:45:50]pics/m_main_quit_sel.pcx cx 1� �-����
[19:45:50]pics/m_main_multiplayer_sel.pcx 1� �-����
[19:45:50]pics/m_main_options_sel.pcx pcx 1� �-����
[19:45:50]pics/m_main_game_sel.pcx cx pcx 1� �-����
[19:45:50]pics/m_main_video_sel.pcx x pcx 1� �-����
[19:45:50]pics/conback.pcx _sel.pcx x pcx 1� �-����
[19:45:50]models/items/ammo/rockets/medium/skin.pcx �-����
[19:45:50]models/items/ammo/grenades/medium/skin.pcx �-����
[19:45:50]models/items/ammo/bullets/medium/skin.pcx �-����
[19:45:50]models/items/armor/shard/skin.pcx kin.pcx �-����
[19:45:50]models/items/armor/new folder/skin.pcx cx �-����
[19:45:50]models/items/armor/body/skin.pcx n.pcx cx �-����
[19:45:50]models/items/armor/combat/skin.pcx pcx cx �-����
[19:45:50]models/items/armor/jacket/skin.pcx pcx cx �-����
The used loading code
namespace BspProcessor
{
[Serializable]
public class PAKFileConstants
{
public const uint PAKMagic = (0x50) | (0x41 << 8) | (0x43 << 16) | (0x4B << 24); //PACK
public const int sizeFileName = 56;
}
[Serializable]
public class PAKDirectoryEntry
{
private string fileName; //
private int offset; // offset into file (bytes)
private int length; // length of lump(bytes)
#region Constructors
public PAKDirectoryEntry(String name, int o, int l)
{
fileName = name;
offset = o;
length = l;
}
#endregion
#region Properties
public string Name { get { return fileName; } }
public int Offset { get { return offset; } }
public int Length { get { return length; } }
#endregion
}
public class PAKReader
{
public uint magic;
private int dirOffset;
private int dirLength;
private PAKDirectoryEntry[] PAKDirectories;
#region Constructor
public PAKReader()
{
magic = 0;
dirOffset = 0;
dirLength = 0;
PAKDirectories = null;
}
#endregion
public static PAKReader LoadFromFile(string assetName)
{
try
{
return LoadFromStream(
new BinaryReader(
File.Open(
assetName,
FileMode.Open,
FileAccess.Read),
Encoding.UTF8));
}
catch
{
return null;
}
}
public static PAKReader LoadFromStream(BinaryReader fileReader)
{
PAKReader tempreader = new PAKReader();
long filestart = fileReader.BaseStream.Position;
tempreader.magic = fileReader.ReadUInt32();
// if signature isn't "PACK", no valid PAK-file then
if (tempreader.magic != PAKFileConstants.PAKMagic)
return null;
tempreader.dirOffset = fileReader.ReadInt32();
tempreader.dirLength = fileReader.ReadInt32();
int dirCount = tempreader.dirLength / 64;
tempreader.PAKDirectories = new PAKDirectoryEntry[dirCount];
fileReader.BaseStream.Position = filestart;
fileReader.BaseStream.Seek(tempreader.dirOffset, SeekOrigin.Current);
//Read in all of the directories
for (int i = 0; i < dirCount; i++)
{
string fileName = new string(fileReader.ReadChars(56));
fileName = fileName.Replace("\0", " ");
fileName = fileName.Trim();
int position = fileReader.ReadInt32();
int length = fileReader.ReadInt32();
tempreader.PAKDirectories[i] = new PAKDirectoryEntry(fileName, position, length);
}
return tempreader;
}
The Quake2 format for pak file is given as:
Header:
Magic 4bytes of char, equals 'PACK'
Directory Offset 4bytes, single integer
Directory Length 4bytes, single integer
Directory section (size 64 bytes):
File name 56 bytes of char
File position 4bytes , singel integer
File length 4bytes, single integer
Does anyone have a clue, what may be causing it?

greetz
Mikeske