public static SRFile Create(string dataFile, string objectListFile, Game game, ExportOptions options, int childIndex = -1) { SRFile srFile; try { if (game == Game.Gex) { GexFile gexFile = new GexFile(dataFile, options); if (gexFile.Asset == Asset.Unit && childIndex >= 0) { srFile = gexFile.Objects[childIndex]; } else { srFile = gexFile; } } else if (game == Game.SR1) { srFile = new SR1File(dataFile, options); } else if (game == Game.SR2) { srFile = new SR2File(dataFile, options); } else if (game == Game.Defiance) { srFile = new DefianceFile(dataFile, objectListFile, options); } else if (game == Game.TRL) { srFile = new TRLFile(dataFile, objectListFile, options); } else { srFile = null; } } catch (Exception) { srFile = null; } return(srFile); }
protected override void ReadUnitData(BinaryReader reader, ExportOptions options) { bool validVersion = false; if (options.ForcedPlatform != Platform.None) { _platform = options.ForcedPlatform; } if (!validVersion) { reader.BaseStream.Position = _dataStart + 0x08; _version = reader.ReadUInt32(); if (_version == RETAIL_VERSION) { validVersion = true; } } if (!validVersion) { throw new Exception("Wrong version number for level x"); } // Object Names reader.BaseStream.Position = _dataStart + 0x3C; _objectNameStart = reader.ReadUInt32(); reader.BaseStream.Position = _objectNameStart; List <string> objectNames = new List <string>(); List <SRFile> objectList = new List <SRFile>(); while (true) { UInt32 objectAddress = reader.ReadUInt32(); if (objectAddress == _objectNameStart) { break; } long oldPos = reader.BaseStream.Position; reader.BaseStream.Position = objectAddress + 0x00000024; reader.BaseStream.Position = reader.ReadUInt32(); string objectName = new string(reader.ReadChars(8)); objectName = Utility.CleanObjectName(objectName); reader.BaseStream.Position = objectAddress; GexFile gexObject = new GexFile(objectName, options, reader); objectNames.Add(objectName); objectList.Add(gexObject); reader.BaseStream.Position = oldPos; } _objectNames = objectNames.ToArray(); _objects = objectList.ToArray(); // Intros reader.BaseStream.Position = _dataStart + 0x7C; _introCount = reader.ReadUInt32(); _introStart = reader.ReadUInt32(); _intros = new Intro[_introCount]; for (int i = 0; i < _introCount; i++) { reader.BaseStream.Position = _introStart + 0x34 * i; UInt32 objectStart = reader.ReadUInt32(); if (objectStart == 0) { _intros[i].name = "Intro(0)-" + _intros[i].uniqueID; _intros[i].fileName = ""; } else { reader.BaseStream.Position = objectStart + 0x00000024; reader.BaseStream.Position = reader.ReadUInt32(); String introName = new String(reader.ReadChars(8)); _intros[i].name = Utility.CleanObjectName(introName) + "-" + _intros[i].uniqueID; _intros[i].fileName = Utility.CleanObjectName(introName); } } // Unit name. No names in Gex :( //reader.BaseStream.Position = _dataStart + 0x98; //reader.BaseStream.Position = reader.ReadUInt32(); //String strModelName = new String(reader.ReadChars(8)); //_name = Utility.CleanName(strModelName); // Texture type if (options.ForcedPlatform == CDC.Platform.None) { _platform = Platform.PSX; } // Model data reader.BaseStream.Position = _dataStart; _modelCount = 1; _modelStart = _dataStart; _models = new GexModel[_modelCount]; reader.BaseStream.Position = _modelStart; UInt32 m_uModelData = reader.ReadUInt32(); // Material data Console.WriteLine("Debug: reading area model 0"); _models[0] = GexUnitModel.Load(reader, _dataStart, m_uModelData, _name, _platform, _version, _tPages, options); }