Exemplo n.º 1
0
        /// <summary>
        /// Writes the demo to the destination folder while performing modifications such as removing the scoreboard or fade to black, possibly converting messages to the current network protocol, as well as re-writing directory entries.
        /// </summary>
        /// <param name="_destinationPath">The destination folder.</param>
        protected override void WritingThread(object _destinationFileName)
        {
            firstFrameToWriteIndex = 0;

            try
            {
                /*
                 * Converted demos: pre-process the loading segment and get the frame index of the last
                 * svc_serverinfo message in the loading segment.
                 *
                 * This fixes several bugs:
                 *      1. long (for Half-Life) loading times, since the resources of several maps may be
                 *      loaded.
                 *
                 *      2. wrong map in resource list
                 *
                 *      3. random SendAudio CTD (indirectly)
                 */
                if (ConvertNetworkProtocol() && !IsBetaSteam())
                {
                    currentFrameIndex = 0;

                    // initialise parser
                    parser = new HalfLifeDemoParser(this);
                    parser.AddMessageHandler((Byte)HalfLifeDemoParser.MessageId.svc_serverinfo, PreWriteMessageServerInfo);
                    parser.Open();

                    try
                    {
                        parser.Seek(HeaderSizeInBytes);

                        while (true)
                        {
                            HalfLifeDemoParser.FrameHeader frameHeader = parser.ReadFrameHeader();

                            if (frameHeader.Type == 1)
                            {
                                break;
                            }

                            if (frameHeader.Type == 0)
                            {
                                HalfLifeDemoParser.GameDataFrameHeader gameDataFrameHeader = parser.ReadGameDataFrameHeader();
                                Byte[] frameData = parser.Reader.ReadBytes((Int32)gameDataFrameHeader.Length);
                                parser.ParseGameDataMessages(frameData);
                            }
                            else if (frameHeader.Type != 5)
                            {
                                parser.SkipFrame(frameHeader.Type);
                            }

                            currentFrameIndex++;
                        }
                    }
                    finally
                    {
                        parser.Close();
                    }
                }

                // demo writer
                HalfLifeDemoConverter demoConverter = new HalfLifeDemoConverter(this);
                HalfLifeDemoWriter    demoWriter    = new HalfLifeDemoWriter(this, (IHalfLifeDemoWriter)demoConverter, writeProgressWindowInterface, firstFrameToWriteIndex);

                demoWriter.ThreadWorker((String)_destinationFileName);
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (HalfLifeDemoWriter.AbortWritingException)
            {
                writeProgressWindowInterface.CloseWithResult(false);
                return;
            }
            catch (Exception ex)
            {
                writeProgressWindowInterface.Error("Error writing demo file \"" + fileFullPath + "\".", ex, false, null);
                writeProgressWindowInterface.CloseWithResult(false);
                return;
            }

            writeProgressWindowInterface.CloseWithResult(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Writes the demo to the destination folder while performing modifications such as removing the scoreboard or fade to black, possibly converting messages to the current network protocol, as well as re-writing directory entries.
        /// </summary>
        /// <param name="_destinationPath">The destination folder.</param>
        protected override void WritingThread(object _destinationFileName)
        {
            firstFrameToWriteIndex = 0;

            try
            {
                /*
                 * Converted demos: pre-process the loading segment and get the frame index of the last
                 * svc_serverinfo message in the loading segment.
                 *
                 * This fixes several bugs:
                 *      1. long (for Half-Life) loading times, since the resources of several maps may be
                 *      loaded.
                 *
                 *      2. wrong map in resource list
                 *
                 *      3. random SendAudio CTD (indirectly)
                 */
                if (ConvertNetworkProtocol() && !IsBetaSteam())
                {
                    currentFrameIndex = 0;

                    // initialise parser
                    parser = new HalfLifeDemoParser(this);
                    parser.AddMessageHandler((Byte)HalfLifeDemoParser.MessageId.svc_serverinfo, PreWriteMessageServerInfo);
                    parser.Open();

                    try
                    {
                        parser.Seek(HeaderSizeInBytes);

                        while (true)
                        {
                            HalfLifeDemoParser.FrameHeader frameHeader = parser.ReadFrameHeader();

                            if (frameHeader.Type == 1)
                            {
                                break;
                            }

                            if (frameHeader.Type == 0)
                            {
                                HalfLifeDemoParser.GameDataFrameHeader gameDataFrameHeader = parser.ReadGameDataFrameHeader();
                                Byte[] frameData = parser.Reader.ReadBytes((Int32)gameDataFrameHeader.Length);
                                parser.ParseGameDataMessages(frameData);
                            }
                            else if (frameHeader.Type != 5)
                            {
                                parser.SkipFrame(frameHeader.Type);
                            }

                            currentFrameIndex++;
                        }
                    }
                    finally
                    {
                        parser.Close();
                    }
                }

                // demo writer
                HalfLifeDemoConverter demoConverter = new HalfLifeDemoConverter(this);
                HalfLifeDemoWriter demoWriter = new HalfLifeDemoWriter(this, (IHalfLifeDemoWriter)demoConverter, writeProgressWindowInterface, firstFrameToWriteIndex);

                demoWriter.ThreadWorker((String)_destinationFileName);
            }
            catch (ThreadAbortException)
            {
                throw;
            }
            catch (HalfLifeDemoWriter.AbortWritingException)
            {
                writeProgressWindowInterface.CloseWithResult(false);
                return;
            }
            catch (Exception ex)
            {
                writeProgressWindowInterface.Error("Error writing demo file \"" + fileFullPath + "\".", ex, false, null);
                writeProgressWindowInterface.CloseWithResult(false);
                return;
            }

            writeProgressWindowInterface.CloseWithResult(true);
        }