コード例 #1
0
        public Texture(Package package, int exportId, byte[] data, bool fixDim = true)
        {
            properties = new TexProperty(package, data);
            if (data.Length == properties.propertyEndOffset)
            {
                return;
            }

            packagePath = package.packageFile.Name;
            packageName = Path.GetFileNameWithoutExtension(package.packageFile.Name).ToUpper();
            if (GameData.gameType == MeType.ME1_TYPE && package.compressed)
            {
                string basePkg = package.resolvePackagePath(package.exportsTable[exportId].linkId).Split('.')[0].ToUpper();
                if (basePkg != "")
                {
                    packageName = basePkg;
                }
            }

            textureData = new MemoryStream(data, properties.propertyEndOffset, data.Length - properties.propertyEndOffset);
            if (GameData.gameType != MeType.ME3_TYPE)
            {
                textureData.Skip(12);    // 12 zeros
                textureData.SkipInt32(); // position in the package
            }

            mipMapsList = new List <MipMap>();
            int numMipMaps = textureData.ReadInt32();

            for (int l = 0; l < numMipMaps; l++)
            {
                MipMap mipmap = new MipMap();
                mipmap.storageType      = (StorageTypes)textureData.ReadInt32();
                mipmap.uncompressedSize = textureData.ReadInt32();
                mipmap.compressedSize   = textureData.ReadInt32();
                mipmap.dataOffset       = textureData.ReadUInt32();
                if (mipmap.storageType == StorageTypes.pccUnc)
                {
                    mipmap.internalOffset = (uint)textureData.Position;
                    textureData.Skip(mipmap.uncompressedSize);
                }
                if (mipmap.storageType == StorageTypes.pccLZO ||
                    mipmap.storageType == StorageTypes.pccZlib)
                {
                    mipmap.internalOffset = (uint)textureData.Position;
                    textureData.Skip(mipmap.compressedSize);
                }

                mipmap.width  = textureData.ReadInt32();
                mipmap.height = textureData.ReadInt32();

                if (fixDim)
                {
                    if (mipmap.width == 4 && mipMapsList.Exists(mip => mip.width == mipmap.width))
                    {
                        mipmap.width = mipMapsList.Last().width / 2;
                    }
                    if (mipmap.height == 4 && mipMapsList.Exists(mip => mip.height == mipmap.height))
                    {
                        mipmap.height = mipMapsList.Last().height / 2;
                    }

                    if (mipmap.width == 0)
                    {
                        mipmap.width = 1;
                    }
                    if (mipmap.height == 0)
                    {
                        mipmap.height = 1;
                    }
                }

                mipMapsList.Add(mipmap);
            }

            restOfData = textureData.ReadToBuffer(textureData.Length - textureData.Position);
        }
コード例 #2
0
        public Texture(Package package, int exportId, byte[] data, bool fixDim = true)
        {
            properties = new TexProperty(package, data);
            if (data.Length == properties.propertyEndOffset)
            {
                return;
            }

            textureData = new MemoryStream(data, properties.propertyEndOffset, data.Length - properties.propertyEndOffset);
            if (GameData.gameType != MeType.ME3_TYPE)
            {
                textureData.Skip(12);    // 12 zeros
                textureData.SkipInt32(); // position in the package
            }

            mipMapsList = new List <MipMap>();
            int numMipMaps = textureData.ReadInt32();

            for (int l = 0; l < numMipMaps; l++)
            {
                MipMap mipmap = new MipMap();
                mipmap.storageType      = (StorageTypes)textureData.ReadInt32();
                mipmap.uncompressedSize = textureData.ReadInt32();
                mipmap.compressedSize   = textureData.ReadInt32();
                mipmap.dataOffset       = textureData.ReadUInt32();
                if (mipmap.storageType == StorageTypes.pccUnc)
                {
                    mipmap.internalOffset = (uint)textureData.Position;
                    textureData.Skip(mipmap.uncompressedSize);
                }
                if (mipmap.storageType == StorageTypes.pccLZO ||
                    mipmap.storageType == StorageTypes.pccZlib)
                {
                    mipmap.internalOffset = (uint)textureData.Position;
                    textureData.Skip(mipmap.compressedSize);
                }

                mipmap.width  = textureData.ReadInt32();
                mipmap.height = textureData.ReadInt32();

                if (fixDim)
                {
                    if (mipmap.width == 4 && mipMapsList.Exists(mip => mip.width == mipmap.width))
                    {
                        mipmap.width = mipMapsList.Last().width / 2;
                    }
                    if (mipmap.height == 4 && mipMapsList.Exists(mip => mip.height == mipmap.height))
                    {
                        mipmap.height = mipMapsList.Last().height / 2;
                    }

                    if (mipmap.width == 0)
                    {
                        mipmap.width = 1;
                    }
                    if (mipmap.height == 0)
                    {
                        mipmap.height = 1;
                    }
                }

                mipMapsList.Add(mipmap);
            }

            restOfData = textureData.ReadToBuffer(textureData.Length - textureData.Position);

            packagePath = package.packagePath;
            packageName = Path.GetFileNameWithoutExtension(packagePath).ToUpper();
            if (GameData.gameType == MeType.ME1_TYPE)
            {
                string baseName = package.resolvePackagePath(package.exportsTable[exportId].linkId).Split('.')[0].ToUpper();
                if (mipMapsList.Exists(s => s.storageType == StorageTypes.extLZO) ||
                    mipMapsList.Exists(s => s.storageType == StorageTypes.extZlib) ||
                    mipMapsList.Exists(s => s.storageType == StorageTypes.extUnc))
                {
                    basePackageName = baseName;
                    if (basePackageName == "")
                    {
                        throw new Exception("");
                    }
                    slave = true;
                }
                else
                {
                    if (baseName != "" && !properties.exists("NeverStream") &&
                        GameData.packageFiles.Exists(s => Path.GetFileNameWithoutExtension(s).Equals(baseName, StringComparison.OrdinalIgnoreCase)))
                    {
                        basePackageName = baseName;
                        weakSlave       = true;
                    }
                }
            }
        }