private List <BiowareModel> readTerrainModels() { BinaryReader file = headerFile.openReader(); int numSectors, reference; long startOfList; //Seek to the reference to the terrain chunk list and get it file.BaseStream.Seek(headerFile.dataOffset + headerFile.structs[TOP_LEVEL_STRUCT_INDEX].fields[TERRAIN_CHUNK_LIST_INDEX].index, SeekOrigin.Begin); reference = file.ReadInt32(); //Seek to the list file.BaseStream.Seek(headerFile.dataOffset + reference, SeekOrigin.Begin); //Get the lenght of the list numSectors = file.ReadInt32(); //Make a list for the terrain meshes List <BiowareModel> terrainModels = new List <BiowareModel>(numSectors); int currentSectorFileIndex, currentSectorID = 0; uint currentSectorModelID = 1; GFF currentSectorFile; TerrainMesh currentTerrainMesh; startOfList = file.BaseStream.Position; for (int i = 0; i < numSectors; i++) { //Seek to the next struct in the list and get the model id and sector id file.BaseStream.Seek(startOfList + (i * terrainChunkStruct.structSize), SeekOrigin.Begin); //THIS IS UNSAFE ACCESS TO STRUCT FIELDS!!!!! currentSectorModelID = file.ReadUInt32(); currentSectorID = file.ReadInt32(); //Get the index of the next sector file currentSectorFileIndex = diskFile.indexOf(String.Format("sector{0:0000}.tmsh", currentSectorID)); //If its not there something is wrong if (currentSectorFileIndex < 0) { Console.WriteLine("Could not find file \"sector00" + i + ".tmsh\" :("); } //Otherwise read it in else { currentSectorFile = new GFF(diskFile.path, diskFile.resourceOffsets[currentSectorFileIndex]); currentTerrainMesh = new TerrainMesh(currentSectorFile); terrainModels.Add(currentTerrainMesh.toModel(currentSectorModelID)); } } return(terrainModels); }
public Level(String filePath) { // Initialize the erf (lvl) file in memory diskFile = new ERF(filePath); //find the index of the header file in the erf int headerIndex = diskFile.indexOf("header.gff"); if (headerIndex < 0) { throw new Exception("Could not find the header file in " + filePath + "! Please make sure it is a level file."); } //Initialize the header file headerFile = new GFF(filePath, diskFile.resourceOffsets[headerIndex]); baseModels = new Dictionary <String, Model>(); lightmapModels = new List <ModelInstance>(); layoutName = "WHAT"; //Set up the struct definitions (for sanity!) setStructDefinitions(); readObjects(); }
public Level(String filePath) { // Initialize the erf (lvl) file in memory diskFile = new ERF(filePath); //find the index of the header file in the erf int headerIndex = diskFile.indexOf("header.gff"); if (headerIndex < 0) { throw new Exception("Could not find the header file in "+filePath+"! Please make sure it is a level file."); } //Initialize the header file headerFile = new GFF(filePath, diskFile.resourceOffsets[headerIndex]); baseModels = new Dictionary<String, Model>(); lightmapModels = new List<ModelInstance>(); layoutName = "WHAT"; //Set up the struct definitions (for sanity!) setStructDefinitions(); readObjects(); }