Esempio n. 1
0
        private void Init(Stream memstream, string grpFilePath)
        {
            int numFilesInGrp;

            Engine.Printf("bGrpArchive::Init: Loading " + grpFilePath);
#if UNITY_STANDALONE || UNITY_EDITOR
            if (memstream != null)
            {
                grpFile = new BinaryReader(memstream);
            }
            else
            {
                grpFile = new BinaryReader(new MemoryStream(Engine.filesystem.ReadContentFile(grpFilePath)));
            }
            if (grpFile == null)
            {
                throw new Exception("bGrpArchive::Init Failed to load " + grpFilePath);
            }
#else
            grpFile = new BinaryReader(new MemoryStream(_defaultGrpFile.bytes));
#endif

            grpFile.BaseStream.Position = 0;
            grpBuffer = new BinaryReader(new MemoryStream(grpFile.ReadBytes((int)grpFile.BaseStream.Length)));

            // Dispose of the HD binary reader since its now loaded into memory.
            grpFile.Dispose();

            // Check the file header to ensure its a valid grp file.
            Engine.Printf("...Checking Integrity");
            string header = new string(grpBuffer.ReadChars(12));
            if (header != GRPIDEN)
            {
                throw new Exception("bGrpArchive::Init Invalid Archive");
            }

            numFilesInGrp = grpBuffer.ReadInt32();
            Engine.Printf("..." + numFilesInGrp + " files");

            int offset = KENGRP_HEADERSIZE + (KENGRP_LUMPSIZE * numFilesInGrp);

            if (lumps == null)
            {
                lumps = new List <bGrpLump>();
            }
            lumps.Clear();
            for (int i = 0; i < numFilesInGrp; i++)
            {
                bGrpLump newlump = new bGrpLump();
                newlump.lumpName   = new string(grpBuffer.ReadChars(12)).ToLower().Trim('\0');
                newlump.lumpSize   = grpBuffer.ReadInt32();
                newlump.lumpOffset = offset;

                lumps.Add(newlump);

                offset += lumps[i].lumpSize;
            }
        }
Esempio n. 2
0
        private void WriteLump(BinaryWriter grpwriter, bGrpLump lump)
        {
            for (int i = 0; i < 12; i++)
            {
                if (i >= lump.lumpName.Length)
                {
                    grpwriter.Write((byte)0);
                }
                else
                {
                    grpwriter.Write(lump.lumpName[i]);
                }
            }

            grpwriter.Write(lump.lumpSize);
        }