Ejemplo n.º 1
0
 def toString(self):
     ret = ""
     ret += "%s Lump #%d (%s):\n" % (misc.indent(1), self.lumpID, "to be implemented")
     ret += "%s File offset (byte): %d\n" % (misc.indent(2), self.fileofs)
     ret += "%s Length (bytes): %d\n" % (misc.indent(2), self.filelen)
     ret += "%s Version: %d\n" % (misc.indent(2), self.version)
     ret += "%s FourCC: " % (misc.indent(2),)
     for i in range(4):
         ret += "%d " % (self.fourCC[i],)
     if self.lumpID < constants.getHeaderLumps()-1:
         ret += "\n"
     return ret
Ejemplo n.º 2
0
 def toString(self, printLumps=False):
     ret = ""
     ret += "BSP Header:\n"
     if self.isValid():
         valid = "valid"
     else:
         valid = "invalid"
     ret += "%s Ident: %d (%s)\n" % (misc.indent(1), self.ident, valid)
     ret += "%s Version: %d\n" % (misc.indent(1), self.version)
     ret += "%s Map Revision: %d\n" % (misc.indent(1), self.mapRevision)
     if printLumps:
         for i in range(constants.getHeaderLumps()):
             ret += self.lumps[i].toString()
     return ret
Ejemplo n.º 3
0
import struct
from bspinlib import classes, constants

intsize = constants.getIntSize()
headerLumps = constants.getHeaderLumps()

#  references:  https://developer.valvesoftware.com/wiki/Source_BSP_File_Format
#               https://developer.valvesoftware.com/wiki/Lump_file_format

def readHeader(binfile):
    header = classes.BSPHeader()
    header.ident = struct.unpack("i", binfile.read(intsize))[0]
    header.version = struct.unpack("i", binfile.read(intsize))[0]
    for i in range(headerLumps):
        newlump = readLump_t(binfile)
        newlump.lumpID = i
        header.lumps.append(newlump)
    header.mapRevision = struct.unpack("i", binfile.read(intsize))[0]
    return header

def readLump_t(binfile):
    lumpt = classes.Lump_t()
    lumpt.fileofs = struct.unpack("i", binfile.read(intsize))[0]
    lumpt.filelen = struct.unpack("i", binfile.read(intsize))[0]
    lumpt.version = struct.unpack("i", binfile.read(intsize))[0]
    lumpt.fourCC.extend(struct.unpack("BBBB", binfile.read(4)))
    return lumpt

def loadLumpData(binfile, bspobject, id):
    lump_t = bspobject.header.lumps[int(id)]
    offset = lump_t.fileofs
Ejemplo n.º 4
0
from bspinlib import fileIO, cli_parse, classes, constants
from bspinlib import lump_extract

commandline = cli_parse.parsecli()

bspobject = classes.BSPFile(commandline.filename)

file = open(bspobject.name,"rb")
bspobject.header = fileIO.readHeader(file)
file.close()

print(bspobject.header.toString(commandline.lump_info))

if commandline.extract_all:
    ids = list(map(str, range(constants.getHeaderLumps())))
    lump_extract.lump_load(bspobject, ids)
    for lid in ids:
        print("Extracting lump #%d ..." % (int(lid)))
        lump_extract.lump_extract(bspobject, lid)
        print("Done.")
    print("Done extracting all")
elif commandline.extract:
    print("Extracting lump #%d ..." % (int(commandline.extract)))
    lump_extract.lump_extract(bspobject, commandline.extract)
    print("Done.")
Ejemplo n.º 5
0
 def insertLump_t(self, lumpt):
     self.lumps.append(lumpt)
     if len(self.lumps) > constants.getHeaderLumps():
         return False
     return True