   Unsure what to do with data obtained from .BSP
  I'm trying to write a half life bsp loader, for learning some about binary file formats. I've read alot of articles that I've found on flipcode and through google about the bsp file structure. The bsp file contains a header, which tells which version it is but I'm having troubles knowing how much data to read at the start to get this header. I've seen a few different approchesstruct stQ3Header{   char bspID[4];   int version;};stQ3Header Header;fread(&Header, 1, sizeof(stQ3Header), fp);When i try reading some at the beginning(9 bytes, 5 chars at 1 byte each and 1 int at 4 bytes) I just get random charachters like these: ?c Ok  |   0# ? ??  ?? D 4 ?L ?  ? ? x}  ?? ?V ?K ?? ?? HD ?#  ?  ?0 ?. (This is from 100 bytes)I'm guessing I'm supposed extract the bsp header somehow from data like this. The problem right now is that i don't know how to extract any useful data from the bytes I'm reading. So I'm looking for some help with what to do with this.I use visual studio 2005 and .net.Help greatly appreciated.   
  I know nothing about hal-life's bsp format, but from the struc you're showing, you should be trying to read 8 bytes and not 9.char bspID[4] is 4 chars, valid from bspID[0] through bspID[3].If the header's supposed to be at the begining of the file, then the C code you posted (or C++, Win32, whatever equivalent you prefer) should do the trick. Otherwise get some more doc about the bsp file format.silly detail: make sure fp is valid (at least fp != NULL) I happen to make some stupid mistakes myself.JA   ;Quote:Original post by JustMe1984fread(&Header, 1, sizeof(stQ3Header), fp);You have a slip here.fread(&Header, sizeof(stQ3Header), 1, fp);That would be better!;  One other thing you might want to do is disable alignment, like this:#pragma pack(1)    // Trun alignment offstruct stQ3Header{   char bspID[4];   int version;};#pragma pack()    // Turn it back onThat's because sizeof takes struct alignment into consideration (See my post here). In this case, the struct might not be aligned (because it's size is a multiple of 4), but you should do this for any struct that you read from a file.   ;Quote:Original post by JustMe1984When i try reading some at the beginning(9 bytes, 5 chars at 1 byte each and 1 int at 4 bytes) I just get random charachters like these:You "get" them how? That's considerably more than the 8 bytes you should be reading. You can't printf() the char[] buffer as a string if that's what you're doing - it's not a string, it's 4 chars, not null terminated. You'd have to print them out as characters ("%c").   ;  Halflife is a modified Quake 1 engine, but the bsp format is pretty identical with Quake (Quake bsp version = 29 and H/L bsp version is 30, plus halflife bsp file don't have textures binded into bsp file as quake).   ;  I wrote this very late yesterday, and I did a few important mistakes, it should have said I'm using visual basic, and I only use the c++ code for reference. Anyways, I tried reading only the first 8 bytes as suggested, but this also just gives me random charachters: "   ?c ". Here is the code i use for loading.   FS = New FileStream("C:\BSP\co_crossfire.bsp", FileMode.Open, FileAccess.Read)   BR = New BinaryReader(FS)   MapData = BR.ReadBytes(8)   MapString = System.Text.ASCIIEncoding.ASCII.GetChars(MapData)   File.WriteAllText("C:\BSP\map.txt", MapString)If I read the whole file and convert it, there is alot of readable text at the bottom, but most of it is just random charachters like before.Thanks for all the replies.   