Ejemplo n.º 1
0
        /// <summary>
        /// Opens an MEPackage from a stream. The stream position should be at the start of the expected MEPackage data.
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public static MEPackage OpenMEPackage(Stream stream, string debugSourcePath = null)
        {
            if (!initialized)
            {
                MEConstructorDelegate       = MEPackage.Initialize();
                MEConstructorStreamDelegate = MEPackage.InitializeStream();
                initialized = true;
            }
            ushort version;
            ushort licenseVersion;

            long originPoint = stream.Position;

            stream.Seek(4, SeekOrigin.Current);
            version         = stream.ReadUInt16();
            licenseVersion  = stream.ReadUInt16();
            stream.Position = originPoint;

            if (version == 684 && licenseVersion == 194 ||
                version == 512 && licenseVersion == 130 ||
                version == 491 && licenseVersion == 1008)
            {
                var package = MEConstructorStreamDelegate(stream, Mod.MEGame.Unknown);
                package.FileSourceForDebugging = debugSourcePath;
                return(package);
            }
            else
            {
                throw new FormatException("Not an ME1, ME2 or ME3 package file.");
            }
        }
Ejemplo n.º 2
0
        public static MEPackage OpenMEPackage(string pathToFile)
        {
            if (!initialized)
            {
                MEConstructorDelegate       = MEPackage.Initialize();
                MEConstructorStreamDelegate = MEPackage.InitializeStream();
                initialized = true;
            }
            pathToFile = Path.GetFullPath(pathToFile); //STANDARDIZE INPUT
            ushort version;
            ushort licenseVersion;

            using (FileStream fs = new FileStream(pathToFile, FileMode.Open, FileAccess.Read))
            {
                fs.Seek(4, SeekOrigin.Begin);
                version        = fs.ReadUInt16();
                licenseVersion = fs.ReadUInt16();
            }


            if (version == 684 && licenseVersion == 194 ||
                version == 512 && licenseVersion == 130 ||
                version == 491 && licenseVersion == 1008)
            {
                return(MEConstructorDelegate(pathToFile, Mod.MEGame.Unknown));
            }
            else
            {
                throw new FormatException("Not an ME1, ME2 or ME3 package file.");
            }
        }
Ejemplo n.º 3
0
 public static void Initialize()
 {
     if (!initialized)
     {
         MEConstructorDelegate       = MEPackage.Initialize();
         MEConstructorStreamDelegate = MEPackage.InitializeStream();
         initialized = true;
     }
 }