/// <summary> /// Initialize the <see cref="Package"/> by reading from the given filename. /// </summary> /// <param name="state">The <see cref="State"/> this <see cref="Package"/> is to exist within.</param> /// <param name="fileName">The name of the file to open that contains the <see cref="Package"/>.</param> /// <param name="stream">The <see cref="Stream"/> to read from.</param> public Package(State state, string fileName, Stream stream) : this(state, fileName, new BinaryReader(stream)) { }
/// <summary> /// Initialize the <see cref="Package"/> by reading from the given filename. /// </summary> /// <param name="state">The <see cref="State"/> this <see cref="Package"/> is to exist within.</param> /// <param name="fileName">The name of the file to open that contains the <see cref="Package"/>.</param> /// <param name="reader">The <see cref="BinaryReader"/> to read from.</param> public Package(State state, string fileName, BinaryReader reader) { if (state == null) throw new ArgumentNullException("state"); if (reader == null) throw new ArgumentNullException("reader"); if (reader.ReadInt32() != Magic) throw new Exception("Unreal package magic test failed."); Reader = reader; FileName = fileName; Export = new Unreal.Export(this, -1); Export.Name = Path.GetFileNameWithoutExtension(fileName); Export.LoadedObject = this; StateValue = state; FileVersion = reader.ReadUInt16(); LicenseMode = reader.ReadUInt16(); Flags = (PackageFlag)reader.ReadUInt32(); var nameCount = reader.ReadInt32(); var nameOffset = reader.ReadUInt32(); var exportCount = reader.ReadInt32(); var exportOffset = reader.ReadUInt32(); var importCount = reader.ReadInt32(); var importOffset = reader.ReadUInt32(); if (FileVersion >= 68) Guid = new Guid(reader.ReadBytes(16)); Imports = new ImportList(importCount); for (var index = 0; index < importCount; index++) Imports.Add(new Import(this, index)); Exports = new ExportList(exportCount); for (var index = 0; index < exportCount; index++) Exports.Add(new Export(this, index)); Names = new NameList(nameCount); reader.BaseStream.Position = nameOffset; for (var index = 0; index < nameCount; index++) Names.Add(new Name(this, reader)); reader.BaseStream.Position = exportOffset; for (var index = 0; index < exportCount; index++) Exports[index].Load(reader); reader.BaseStream.Position = importOffset; for (var index = 0; index < importCount; index++) Imports[index].Load(reader); FilteredExports = new ExportList(exportCount); foreach (var export in Exports) { /*if(export.ObjectClassReference != null && export.ObjectClassReference.Name.EndsWith("Property")) { if(((((Alexandria.Engines.Unreal.Core.Property)export.Object).PropertyFlags) & Alexandria.Engines.Unreal.Core.PropertyFlag.Test) != 0) FilteredExports.Add(export); }*/ if (export.ObjectClassReference == null || !export.ObjectClassReference.Name.EndsWith("Property")) FilteredExports.Add(export); } Game = DetermineGame(FileVersion, LicenseMode, IsEncrypted); }
/// <summary> /// Initialize the <see cref="Package"/> by reading from the given filename. /// </summary> /// <param name="state">The <see cref="State"/> this <see cref="Package"/> is to exist within.</param> /// <param name="fileName">The name of the file to open that contains the <see cref="Package"/>.</param> public Package(State state, string fileName) : this(state, fileName, File.OpenRead(fileName)) { }