public CrossParse(GoldSourceDemoInfoHlsooe gsdi, Parseresult pr, SourceDemoInfo sdi, GoldSourceDemoInfo gd)
 {
     this.HlsooeDemoInfo = gsdi;
     this.Res            = pr;
     this.Sdi            = sdi;
     this.GsDemoInfo     = gd;
 }
Beispiel #2
0
 public CrossParseResult(GoldSourceDemoInfoHlsooe gsdi, Parseresult pr, SourceDemoInfo sdi, GoldSourceDemoInfo gd, L4D2BranchDemoInfo lbi)
 {
     HlsooeDemoInfo = gsdi;
     Type           = pr;
     Sdi            = sdi;
     GsDemoInfo     = gd;
     L4D2BranchInfo = lbi;
 }
        public static GoldSourceDemoInfoHlsooe ParseDemoHlsooe(string s) //Add error out
        {
            var gDemo = new GoldSourceDemoInfoHlsooe
            {
                Header           = new Hlsooe.DemoHeader(),
                ParsingErrors    = new List <string>(),
                DirectoryEntries = new List <Hlsooe.DemoDirectoryEntry>()
            };

            using (var br = new BinaryReader(new FileStream(s, FileMode.Open)))
            {
                var mw = Encoding.ASCII.GetString(br.ReadBytes(8)).Trim('\0').Replace("\0", string.Empty);
                if (mw == "HLDEMO")
                {
                    gDemo.Header.DemoProtocol    = br.ReadInt32();
                    gDemo.Header.Netprotocol     = br.ReadInt32();
                    gDemo.Header.MapName         = Encoding.ASCII.GetString(br.ReadBytes(260)).Trim('\0').Replace("\0", string.Empty);
                    gDemo.Header.GameDirectory   = Encoding.ASCII.GetString(br.ReadBytes(260)).Trim('\0').Replace("\0", string.Empty);
                    gDemo.Header.DirectoryOffset = br.ReadInt32();
                    //Header Parsed... now we read the directory entries
                    br.BaseStream.Seek(gDemo.Header.DirectoryOffset, SeekOrigin.Begin);
                    var entryCount = br.ReadInt32();
                    for (var i = 0; i < entryCount; i++)
                    {
                        var tempvar = new Hlsooe.DemoDirectoryEntry
                        {
                            Type         = br.ReadInt32(),
                            PlaybackTime = br.ReadSingle(),
                            FrameCount   = br.ReadInt32(),
                            Offset       = br.ReadInt32(),
                            Filelength   = br.ReadInt32(),
                            Frames       = new Dictionary <Hlsooe.DemoFrame, Hlsooe.IFrame>()
                        };
                        gDemo.DirectoryEntries.Add(tempvar);
                    }
                    //Demo directory entries parsed... now we parse the frames.
                    foreach (var entry in gDemo.DirectoryEntries)
                    {
                        br.BaseStream.Seek(entry.Offset, SeekOrigin.Begin);
                        var nextSectionRead = false;
                        for (var i = 0; i < entry.FrameCount; i++)
                        {
                            if (!nextSectionRead)
                            {
                                var brpos            = br.BaseStream.Position;
                                var bpleft           = br.BaseStream.Length - brpos;
                                var currentDemoFrame = new Hlsooe.DemoFrame
                                {
                                    Type = (Hlsooe.DemoFrameType)br.ReadSByte(),
                                    Time = br.ReadSingle(),
                                    Tick = br.ReadInt32()
                                };
                                switch (currentDemoFrame.Type)
                                {
                                case Hlsooe.DemoFrameType.StartupPacket:
                                    var g = new Hlsooe.StartupPacketFrame
                                    {
                                        Flags                        = br.ReadInt32(),
                                        ViewOrigins                  = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        ViewAngles                   = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        LocalViewAngles              = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        ViewOrigin2                  = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        IncomingSequence             = br.ReadInt32(),
                                        IncomingAcknowledged         = br.ReadInt32(),
                                        IncomingReliableAcknowledged = br.ReadInt32(),
                                        IncomingReliableSequence     = br.ReadInt32(),
                                        OutgoingSequence             = br.ReadInt32(),
                                        ReliableSequence             = br.ReadInt32(),
                                        LastReliableSequence         = br.ReadInt32()
                                    };
                                    entry.Frames.Add(currentDemoFrame, g);
                                    break;

                                case Hlsooe.DemoFrameType.NetworkPacket:
                                    var b = new Hlsooe.NetMsgFrame
                                    {
                                        Flags           = br.ReadInt32(),
                                        ViewOrigins     = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        ViewAngles      = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        LocalViewAngles =
                                            new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        ViewOrigin2                  = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        IncomingSequence             = br.ReadInt32(),
                                        IncomingAcknowledged         = br.ReadInt32(),
                                        IncomingReliableAcknowledged = br.ReadInt32(),
                                        IncomingReliableSequence     = br.ReadInt32(),
                                        OutgoingSequence             = br.ReadInt32(),
                                        ReliableSequence             = br.ReadInt32(),
                                        LastReliableSequence         = br.ReadInt32()
                                    };
                                    entry.Frames.Add(currentDemoFrame, b);
                                    break;

                                case Hlsooe.DemoFrameType.Jumptime:
                                    //No extra stuff
                                    entry.Frames.Add(currentDemoFrame, new Hlsooe.JumpTimeFrame());
                                    break;

                                case Hlsooe.DemoFrameType.ConsoleCommand:
                                    var a             = new Hlsooe.ConsoleCommandFrame();
                                    var commandlength = br.ReadInt32();
                                    a.Command = new string(br.ReadChars(commandlength)).Trim('\0');
                                    entry.Frames.Add(currentDemoFrame, a);
                                    break;

                                case Hlsooe.DemoFrameType.Usercmd:
                                    var c = new Hlsooe.UserCmdFrame
                                    {
                                        OutgoingSequence = br.ReadInt32(),
                                        Slot             = br.ReadInt32()
                                    };
                                    var usercmdlength = br.ReadInt32();
                                    c.Data = Encoding.ASCII.GetString(br.ReadBytes(usercmdlength)).Trim('\0').Replace("\0", string.Empty);
                                    entry.Frames.Add(currentDemoFrame, c);
                                    break;

                                case Hlsooe.DemoFrameType.Stringtables:     //TODO: This is horribly broken. Do something.
                                    var e = new Hlsooe.StringTablesFrame();
                                    var stringtablelength = br.ReadInt32();
                                    var edata             =
                                        Encoding.ASCII.GetString(br.ReadBytes(stringtablelength))
                                        .Trim('\0')
                                        .Replace("\0", string.Empty)
                                        .Split('?');
                                    e.Data = edata[0];
                                    entry.Frames.Add(currentDemoFrame, e);
                                    break;

                                case Hlsooe.DemoFrameType.NetworkDataTable:
                                    var d = new Hlsooe.NetworkDataTableFrame();
                                    var networktablelength = br.ReadInt32();
                                    d.Data = new string(br.ReadChars(networktablelength)).Trim('\0');     //TODO: Somehow read u8[]
                                    entry.Frames.Add(currentDemoFrame, d);
                                    break;

                                case Hlsooe.DemoFrameType.NextSection:
                                    nextSectionRead = true;
                                    entry.Frames.Add(currentDemoFrame, new Hlsooe.NextSectionFrame());
                                    break;

                                default:
                                    Main.Log($"Error: Frame type: + {currentDemoFrame.Type} at parsing.");
                                    var err = new Hlsooe.ErrorFrame()
                                    {
                                        Flags                        = br.ReadInt32(),
                                        ViewOrigins                  = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        ViewAngles                   = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        LocalViewAngles              = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        ViewOrigin2                  = new Point3D(br.ReadDouble(), br.ReadDouble(), br.ReadDouble()),
                                        IncomingSequence             = br.ReadInt32(),
                                        IncomingAcknowledged         = br.ReadInt32(),
                                        IncomingReliableAcknowledged = br.ReadInt32(),
                                        IncomingReliableSequence     = br.ReadInt32(),
                                        OutgoingSequence             = br.ReadInt32(),
                                        ReliableSequence             = br.ReadInt32(),
                                        LastReliableSequence         = br.ReadInt32()
                                    };
                                    entry.Frames.Add(currentDemoFrame, err);
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    gDemo.ParsingErrors.Add("Non goldsource demo file");
                    br.Close();
                }
            }
            return(gDemo);
        }