Example #1
0
 /// <summary>
 /// This parses .hl3 files
 /// </summary>
 /// <param name="stateFile">The .hl3 file</param>
 /// <returns>Item1 is the size.Item2 are the entity ids which get FENTTABLE_REMOVED flag.</returns>
 public static Tuple <int, int[]> ParseEntityPatch(StateFileInfo stateFile)
 {
     using (var br = new BinaryReader(new MemoryStream(stateFile.Data)))
     {
         var entityIds = new List <int>();
         var size      = br.ReadInt32();
         for (var i = 0; i < size; i++)
         {
             entityIds.Add(br.ReadInt32());
             //This id gets the FENTTABLE_REMOVED flag
         }
         return(new Tuple <int, int[]>(size, entityIds.ToArray()));
     }
 }
Example #2
0
        /// <summary>
        /// Parses a .hl2 statefile which contains the client state
        /// </summary>
        /// <param name="stateFile"></param>
        /// <returns></returns>
        public static ClientState ParseClienState(StateFileInfo stateFile)
        {
            using (var br = new BinaryReader(new MemoryStream(stateFile.Data)))
            {
                ClientState cs = new ClientState();
                cs.IdString = br.ReadBytes(4);
                long savepos = br.BaseStream.Position;
                cs.Magicnumber = br.ReadUInt32();
                if (cs.Magicnumber == SECTION_MAGIC_NUMBER)
                {
                    cs.Baseclientsections.entitysize = br.ReadInt32();
                    cs.Baseclientsections.headersize = br.ReadInt32();
                    cs.Baseclientsections.decalsize  = br.ReadInt32();
                    cs.Baseclientsections.musicsize  = br.ReadInt32();
                    cs.Baseclientsections.symbolsize = br.ReadInt32();

                    cs.Baseclientsections.decalcount  = br.ReadInt32();
                    cs.Baseclientsections.musiccount  = br.ReadInt32();
                    cs.Baseclientsections.symbolcount = br.ReadInt32();
                }
                else
                {
                    br.BaseStream.Seek(savepos, SeekOrigin.Begin);
                    cs.Baseclientsectionsold.entitysize  = br.ReadInt32();
                    cs.Baseclientsectionsold.headersize  = br.ReadInt32();
                    cs.Baseclientsectionsold.decalsize   = br.ReadInt32();
                    cs.Baseclientsectionsold.symbolsize  = br.ReadInt32();
                    cs.Baseclientsectionsold.decalcount  = br.ReadInt32();
                    cs.Baseclientsectionsold.symbolcount = br.ReadInt32();

                    cs.Baseclientsections.entitysize = cs.Baseclientsectionsold.entitysize;
                    cs.Baseclientsections.headersize = cs.Baseclientsectionsold.headersize;
                    cs.Baseclientsections.decalsize  = cs.Baseclientsectionsold.decalsize;
                    cs.Baseclientsections.symbolsize = cs.Baseclientsectionsold.symbolsize;

                    cs.Baseclientsections.decalcount  = cs.Baseclientsectionsold.decalcount;
                    cs.Baseclientsections.symbolcount = cs.Baseclientsectionsold.symbolcount;
                }

                byte[] pszTokenList = br.ReadBytes(cs.Baseclientsections.SumBytes());


                return(cs);
            }
        }
Example #3
0
        /// <summary>
        /// A Method to Parser .hl1 files
        /// </summary>
        /// <param name="stateFile">A .hl1 statefile</param>
        /// <returns></returns>
        public static StateFileInfo ParseStateFile(StateFileInfo stateFile)
        {
            //if (stateFile.Data.Length < 16)
            return(stateFile);

            using (var br = new BinaryReader(new MemoryStream(stateFile.Data)))
            {
                var si = new SaveFileSectionsInfo_t();
                if (!UnexpectedEof(br, 20))
                {
                    return(stateFile);
                }
                stateFile.MagicWord  = br.ReadString(4);
                stateFile.Version    = br.ReadByte();
                si.nBytesSymbols     = Math.Abs(br.ReadInt32());
                si.nSymbols          = Math.Abs(br.ReadInt32());
                si.nBytesDataHeaders = Math.Abs(br.ReadInt32());
                si.nBytesData        = Math.Abs(br.ReadInt32());
                if (!UnexpectedEof(br, si.nSymbols + si.nBytesDataHeaders + si.nBytesData))
                {
                    return(stateFile);
                }
                stateFile.pSymbols     = br.ReadBytes(si.nSymbols);
                stateFile.pDataHeaders = br.ReadBytes(si.nBytesDataHeaders);
                stateFile.pData        = br.ReadBytes(si.nBytesData);



                var NumberOfFields = 8;
                for (var i = 0; i < NumberOfFields; i++)
                {
                    var size  = br.ReadInt16();
                    var index = br.ReadInt16();
                    var data  = br.ReadBytes(size);
                }
            }
            return(stateFile);
        }
Example #4
0
        public static SaveFile ParseSaveFile(string file)
        {
            var result = new SaveFile();

            using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read))
                using (var br = new BinaryReader(fs))
                {
                    result.FileName    = Path.GetFileName(file);
                    result.Files       = new List <StateFileInfo>();
                    result.IDString    = (Encoding.ASCII.GetString(br.ReadBytes(sizeof(int))));
                    result.SaveVersion = br.ReadInt32();
                    result.TokenTableFileTableOffset = br.ReadInt32();
                    result.TokenCount     = br.ReadInt32();
                    result.TokenTableSize = br.ReadInt32();
                    br.BaseStream.Seek(result.TokenTableSize + result.TokenTableFileTableOffset, SeekOrigin.Current);
                    var endoffile = false;
                    var check     = br.ReadBytes(4);
                    br.BaseStream.Seek(-4, SeekOrigin.Current);
                    if (check.Any(b => b == 0))
                    {
                        var filenum = br.ReadInt32();
                    }
                    while (!endoffile && result.SaveVersion <= 116)
                    {
                        if (UnexpectedEof(br, 260))
                        {
                            var tempvalv = new StateFileInfo
                            {
                                Data     = new byte[0],
                                FileName = Encoding.ASCII.GetString(br.ReadBytes(260)).TrimEnd('\0').Replace("\0", "")
                                           //BUG: bunch of \0 in string
                            };
                            if (UnexpectedEof(br, 8))
                            {
                                var filelength = br.ReadInt32();
                                tempvalv.MagicWord = Encoding.ASCII.GetString(br.ReadBytes(4))
                                                     .Trim('\0')
                                                     .Replace("\0", string.Empty);
                                br.BaseStream.Seek(-4, SeekOrigin.Current);
                                if (UnexpectedEof(br, 8) && filelength > 0)
                                {
                                    tempvalv.Data = br.ReadBytes(filelength);
                                }
                                else
                                {
                                    endoffile = true;
                                }
                            }
                            else
                            {
                                endoffile = true;
                            }
                            result.Files.Add(tempvalv);
                        }
                        else
                        {
                            endoffile = true;
                        }
                    }
                    for (var i = 0; i < result.Files.Count; i++)
                    {
                        result.Files[i] = ParseStateFile(result.Files[i]);
                    }
                    result.Map = (result.Files.Last().FileName);
                    return(result);
                }
        }