Пример #1
0
        private CLibFile[] ReadCLib30(BinaryReader reader)
        {
            Int32 seed = reader.ReadInt32();

            //NOTE(adm244): assuming asset files are stored sequentially
            Int32 filesCount = reader.ReadInt32();

            CLibFile[] files = new CLibFile[filesCount];
            for (int i = 0; i < files.Length; ++i)
            {
                files[i]          = new CLibFile();
                files[i].Filename = reader.ReadCString();
            }

            Int32 assetsCount = reader.ReadInt32();

            for (int i = 0; i < assetsCount; ++i)
            {
                CLibAsset asset = new CLibAsset();

                asset.Filename = reader.ReadCString();
                byte index = reader.ReadByte();
                asset.Offset = reader.ReadInt64();
                asset.Size   = reader.ReadInt64();

                if (index >= files.Length)
                {
                    throw new InvalidDataException("CLib file index is incorrect!");
                }

                files[index].Assets.Add(asset);
            }

            return(files);
        }
Пример #2
0
        private CLibFile[] ReadCLib21(BinaryReader reader)
        {
            Int32      seed    = reader.ReadInt32() + EncryptionSeedSalt;
            AGSEncoder encoder = new AGSEncoder(seed);

            //NOTE(adm244): assuming asset files are stored sequentially
            Int32 filesCount = encoder.ReadInt32(reader);

            CLibFile[] files = new CLibFile[filesCount];
            for (int i = 0; i < files.Length; ++i)
            {
                files[i] = new CLibFile();
            }

            for (int i = 0; i < files.Length; ++i)
            {
                files[i].Filename = encoder.ReadString(reader);
            }

            Int32 assetsCount = encoder.ReadInt32(reader);

            AGSCLibAsset[] assets = new AGSCLibAsset[assetsCount];
            for (int i = 0; i < assets.Length; ++i)
            {
                assets[i] = new AGSCLibAsset();
            }

            for (int i = 0; i < assetsCount; ++i)
            {
                assets[i].Filename = encoder.ReadString(reader);
            }

            for (int i = 0; i < assetsCount; ++i)
            {
                assets[i].Offset = encoder.ReadInt32(reader);
            }

            for (int i = 0; i < assetsCount; ++i)
            {
                assets[i].Size = encoder.ReadInt32(reader);
            }

            for (int i = 0; i < assetsCount; ++i)
            {
                assets[i].AssetFileIndex = encoder.ReadInt8(reader);
            }

            return(BuildAssetsLists(assets, ref files));
        }
Пример #3
0
        private CLibFile[] ReadCLib(BinaryReader reader)
        {
            CLibFile[] files = new CLibFile[0];

            byte version = reader.ReadByte();

            //TODO(adm244): legacy\community engine supports only these, add support for other versions
            if ((version != 6) && (version != 10) &&
                (version != 11) && (version != 15) &&
                (version != 20) && (version != 21) &&
                (version != 30))
            {
                throw new NotImplementedException("CLib version is not supported!");
            }

            if (version >= 10) // multi-file
            {
                byte index = reader.ReadByte();
                if (index != 0)
                {
                    throw new InvalidDataException("CLib file index is not 0!\nAre you trying to read a wrong CLib file?");
                }

                if (version >= 30)
                {
                    files = ReadCLib30(reader);
                }
                else if (version >= 21)
                {
                    files = ReadCLib21(reader);
                }
                else
                {
                    files = ReadCLibPre21(reader, version);
                }
            }
            else
            {
                files = ReadCLibPre10(reader, version);
            }

            return(files);
        }
Пример #4
0
        private CLibFile[] ReadCLibPre10(BinaryReader reader, int version)
        {
            CLibFile[] files = new CLibFile[1];
            files[0]          = new CLibFile();
            files[0].Filename = RootFilename;

            byte salt     = reader.ReadByte();
            byte reserved = reader.ReadByte();

            Int16 assetsCount = reader.ReadInt16();

            AGSCLibAsset[] assets = new AGSCLibAsset[assetsCount];

            //TODO(adm244): figure out how it's used in pre 6, ignored for now
            byte[] password = reader.ReadBytes(13);

            for (int i = 0; i < assets.Length; ++i)
            {
                assets[i] = new AGSCLibAsset();

                string filename = reader.ReadFixedCString(13);
                assets[i].Filename = AGSEncryption.DecryptSalt(filename, salt);
            }

            for (int i = 0; i < assetsCount; ++i)
            {
                assets[i].Size = reader.ReadInt32();
            }

            //TODO(adm244): read "flags and ratio", skipping for now
            reader.BaseStream.Seek(assetsCount * sizeof(Int16), SeekOrigin.Current);

            assets[0].Offset = reader.BaseStream.Position;
            for (int i = 1; i < assets.Length; ++i)
            {
                assets[i].Offset = assets[i - 1].Offset + assets[i - 1].Size;
            }

            return(BuildAssetsLists(assets, ref files));
        }
Пример #5
0
        //private CLibFile[] ReadCLib20(BinaryReader reader)
        //{
        //  //NOTE(adm244): assuming asset files are stored sequentially
        //  Int32 filesCount = reader.ReadInt32();
        //  CLibFile[] files = new CLibFile[filesCount];
        //  for (int i = 0; i < files.Length; ++i)
        //    files[i].Filename = reader.ReadCString(50);
        //
        //  Int32 assetsCount = reader.ReadInt32();
        //  AGSCLibAsset[] assets = new AGSCLibAsset[assetsCount];
        //
        //  for (int i = 0; i < assets.Length; ++i)
        //  {
        //    Int16 length = reader.ReadInt16();
        //    length /= 5;
        //
        //    byte[] jibzler = reader.ReadBytes(length);
        //    assets[i].Filename = AGSEncryption.DecryptJibzle(jibzler);
        //  }
        //
        //  for (int i = 0; i < assets.Length; ++i)
        //    assets[i].Offset = reader.ReadInt32();
        //
        //  for (int i = 0; i < assets.Length; ++i)
        //    assets[i].Size = reader.ReadInt32();
        //
        //  for (int i = 0; i < assets.Length; ++i)
        //    assets[i].AssetFileIndex = reader.ReadByte();
        //
        //  return BuildAssetsLists(assets, ref files);
        //}

        private CLibFile[] ReadCLibPre21(BinaryReader reader, int version)
        {
            Int32 filesCount = reader.ReadInt32();

            CLibFile[] files = new CLibFile[filesCount];
            for (int i = 0; i < files.Length; ++i)
            {
                files[i] = new CLibFile();
                if (version == 20)
                {
                    files[i].Filename = reader.ReadCString(50);
                }
                else
                {
                    files[i].Filename = reader.ReadFixedCString(20);
                }
            }

            Int32 asset_count = reader.ReadInt32();

            AGSCLibAsset[] assets = new AGSCLibAsset[asset_count];

            for (int i = 0; i < assets.Length; ++i)
            {
                assets[i] = new AGSCLibAsset();

                if (version == 20)
                {
                    Int16 length = reader.ReadInt16();
                    length /= 5;

                    byte[] jibzler = reader.ReadBytes(length);
                    assets[i].Filename = AGSEncryption.DecryptJibzle(jibzler);
                }
                else if (version >= 11)
                {
                    byte[] jibzler = reader.ReadBytes(25);
                    assets[i].Filename = AGSEncryption.DecryptJibzle(jibzler);
                }
                else
                {
                    assets[i].Filename = reader.ReadFixedCString(25);
                }
            }

            for (int i = 0; i < assets.Length; ++i)
            {
                assets[i].Offset = reader.ReadInt32();
            }

            for (int i = 0; i < assets.Length; ++i)
            {
                assets[i].Size = reader.ReadInt32();
            }

            for (int i = 0; i < assets.Length; ++i)
            {
                assets[i].AssetFileIndex = reader.ReadByte();
            }

            return(BuildAssetsLists(assets, ref files));
        }
Пример #6
0
 private AssetsManager()
 {
     RootFilename = string.Empty;
     RootFolder   = string.Empty;
     Files        = new CLibFile[0];
 }