Example #1
0
        public static void Close()
        {
            if (Playing)
            {
                return;
            }

            btnClose.Enabled = btnPlay.Enabled = btnStop.Enabled = false;
            if (m_GZIn != null)
            {
                m_GZIn.Close();
            }
            m_GZIn       = null;
            tbPos.Value  = tbPos.Minimum;
            lblPlay.Text = "";
            m_RPVInfo    = null;
            m_Elapsed    = m_CurLength = TimeSpan.Zero;
            UpdateTimeText();
        }
Example #2
0
        public static void Open( string filename )
        {
            if ( Playing )
                return;

            btnPlay.Enabled = btnStop.Enabled = false;
            if ( m_GZIn != null )
                m_GZIn.Close();
            try
            {
                m_GZIn = new GZBlockIn( filename );//new BinaryReader( new FileStream( filename, FileMode.Open, FileAccess.Read, FileShare.Read ) );

                m_Version = m_GZIn.Raw.ReadByte();

                if ( m_Version > PlayerVersion )
                {
                    m_GZIn.Close();
                    m_GZIn = null;
                    MessageBox.Show( Engine.MainWindow, Language.GetString( LocString.WrongVer ), "Version Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Stop );
                    return;
                }

                m_GZIn.IsCompressed = m_Version > 1;

                byte[] filehash = m_GZIn.Raw.ReadBytes( 16 );
                DateTime created = DateTime.FromFileTime( m_GZIn.Raw.ReadInt64() );
                TimeSpan len = TimeSpan.FromMilliseconds( m_GZIn.Raw.ReadInt32() );

                string player = m_GZIn.Compressed.ReadString();
                string shard = m_GZIn.Compressed.ReadString();
                System.Net.IPAddress ip = System.Net.IPAddress.Any;
                try
                {
                    if ( m_Version > 1 )
                        ip = new System.Net.IPAddress( (long)m_GZIn.Compressed.ReadUInt32() );
                }
                catch
                {
                }

                m_StartPos = (int)m_GZIn.Position;

                long rawPos = m_GZIn.RawStream.Position;
                m_GZIn.RawStream.Seek( 1+16, SeekOrigin.Begin );
                using ( MD5 md5 = MD5.Create() )
                {
                    byte[] check = md5.ComputeHash( m_GZIn.RawStream );
                    for(int i=0;i<check.Length;i++)
                    {
                        if ( check[i] != filehash[i] )
                        {
                            m_GZIn.Close();
                            m_GZIn = null;
                            MessageBox.Show( Engine.MainWindow, Language.GetString( LocString.VideoCorrupt ), "Damaged File", MessageBoxButtons.OK, MessageBoxIcon.Error );
                            return;
                        }
                    }
                }
                m_GZIn.RawStream.Seek( rawPos, SeekOrigin.Begin );

                m_CurLength = len;
                m_Elapsed = TimeSpan.Zero;

                UpdateTimeText();

                m_RPVInfo = lblPlay.Text = String.Format( "File: {0}\nLength: {1} ({2})\nDate: {3}\nRecorded by \"{4}\" on \"{5}\" ({6})\n", Path.GetFileName( filename ), Utility.FormatTime( (int)len.TotalSeconds ), Utility.FormatSize( m_GZIn.RawStream.Length ), created.ToString( "M-dd-yy @ h:mmtt" ), player, shard, ip );
                btnClose.Enabled = btnPlay.Enabled = btnStop.Enabled = true;
                tbPos.Maximum = (int)len.TotalSeconds;
                tbPos.Minimum = 0;
            }
            catch ( Exception e )
            {
                if ( e is FileNotFoundException )
                {
                    MessageBox.Show( Engine.MainWindow, e.Message, "File not found.", MessageBoxButtons.OK, MessageBoxIcon.Error );
                }
                else
                {
                    Engine.LogCrash( e );
                    MessageBox.Show( Engine.MainWindow, Language.GetString( LocString.ReadError ), "Read Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
                }
                m_GZIn.Close();
                m_GZIn = null;
                return;
            }
        }
Example #3
0
        public static void Close()
        {
            if ( Playing )
                return;

            btnClose.Enabled = btnPlay.Enabled = btnStop.Enabled = false;
            if ( m_GZIn != null )
                m_GZIn.Close();
            m_GZIn = null;
            tbPos.Value = tbPos.Minimum;
            lblPlay.Text = "";
            m_RPVInfo = null;
            m_Elapsed = m_CurLength = TimeSpan.Zero;
            UpdateTimeText();
        }
Example #4
0
        private void LoadRPV( string filename )
        {
            m_FileName = filename;

            GZBlockIn gzin = new GZBlockIn( filename );//new BinaryReader( new FileStream( filename, FileMode.Open, FileAccess.Read, FileShare.Read ) );
            byte ver;

            try
            {
                ver = gzin.Raw.ReadByte();

                if ( ver > PlayerVersion )
                {
                    gzin.Close();
                    gzin = null;
                    MessageBox.Show( this, "This file is not compatible with this version of RPVEditor.  Make sure you have the latest Razor version.", "Version Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Stop );
                    return;
                }

                gzin.IsCompressed = ver > 1;

                byte[] filehash = gzin.Raw.ReadBytes( 16 );
                m_Date = DateTime.FromFileTime( gzin.Raw.ReadInt64() );
                TimeSpan len = TimeSpan.FromMilliseconds( gzin.Raw.ReadInt32() );

                m_PlayerName = gzin.Compressed.ReadString();
                World.ShardName = gzin.Compressed.ReadString();
                try
                {
                    if ( ver > 1 )
                        m_IP = new System.Net.IPAddress( (long)gzin.Compressed.ReadUInt32() );
                    else
                        m_IP = System.Net.IPAddress.Any;
                }
                catch
                {
                }

                int m_StartPos = (int)gzin.Position;

                long rawPos = gzin.RawStream.Position;
                gzin.RawStream.Seek( 1+16, SeekOrigin.Begin );
                using ( MD5 md5 = MD5.Create() )
                {
                    byte[] check = md5.ComputeHash( gzin.RawStream );
                    for(int i=0;i<check.Length;i++)
                    {
                        if ( check[i] != filehash[i] )
                        {
                            gzin.Close();
                            gzin = null;
                            MessageBox.Show( this, "This video file is corrupt.\nIt may be incomplete, or it may have been tampered with.\nThe file cannot be played.", "Damaged File", MessageBoxButtons.OK, MessageBoxIcon.Error );
                            return;
                        }
                    }
                }
                gzin.RawStream.Seek( rawPos, SeekOrigin.Begin );

                rpvInfo.Text = String.Format( "File: {0}\nLength: {1} ({2})\nDate: {3}\nRecorded by \"{4}\" on \"{5}\" ({6})\n", Path.GetFileName( m_FileName ), Utility.FormatTime( (int)len.TotalSeconds ), Utility.FormatSize( gzin.RawStream.Length ), m_Date.ToString( "M-dd-yy @ h:mmtt" ), m_PlayerName, World.ShardName, m_IP );
            }
            catch ( Exception ex )
            {
                MessageBox.Show( this, "There was a problem reading the file.  It may be damaged or incomplete.\n" + ex.Message, "Read Error", MessageBoxButtons.OK, MessageBoxIcon.Error );
                gzin.Close();
                gzin = null;
                return;
            }

            int end = gzin.Compressed.ReadInt32();
            end += (int)gzin.Position;

            World.AddMobile( World.Player = new PlayerData( gzin.Compressed, ver ) );
            while ( gzin.Position < end )
            {
                byte type = gzin.Compressed.ReadByte();
                if ( type == 1 )
                    World.AddMobile( new Mobile( gzin.Compressed, ver ) );
                else if ( type == 0 )
                    World.AddItem( new Item( gzin.Compressed, ver ) );
            }

            foreach ( Mobile m in World.Mobiles.Values )
                m.AfterLoad();

            foreach ( Item i in World.Items.Values )
                i.AfterLoad();

            byte[] buff = new byte[32767];
            int curTime = 0;
            int lastTime = 0;
            while ( !gzin.EndOfFile )
            {
                lastTime = curTime;
                curTime += gzin.Compressed.ReadInt32();

                gzin.Compressed.Read( buff, 0, 1 );
                if ( buff[0] == 0xFF )
                    break;

                int len;
                int idx = 1;
                if ( PacketInfo.IsDyn( buff[0] ) )
                {
                    gzin.Compressed.Read( buff, 1, 2 );
                    idx += 2;
                }
                len = PacketInfo.GetLength( buff );

                gzin.Compressed.Read( buff, idx, len-idx );

                Packet p = new Packet();
                p.Time = curTime;
                p.Data = new byte[len];
                Array.Copy( buff, p.Data, len );

                m_Packets.Add( p );
            }

            gzin.Close();
            gzin = null;

            lastTime = curTime - lastTime;
            if ( lastTime <= 500 )
            {
                lastTime = 500;
                curTime += lastTime;
            }
            begPos.Maximum = endPos.Maximum = curTime;
            endPos.Value = curTime;
            begPos.Value = 0;

            evtList.BeginUpdate();
            for(int i=0;i<m_Packets.Count;i++)
            {
                Packet p = (Packet)m_Packets[i];
                if ( p.IsDisplayed )
                {
                    p.ListIdx = evtList.Items.Count;
                    evtList.Items.Add( p );
                }

            }
            UpdateBeg();
            UpdateEnd();
            evtList.EndUpdate();

            NeedSave = false;
        }
Example #5
0
        public static void Open(string filename)
        {
            if (Playing)
            {
                return;
            }

            btnPlay.Enabled = btnStop.Enabled = false;
            if (m_GZIn != null)
            {
                m_GZIn.Close();
            }
            try
            {
                m_GZIn = new GZBlockIn(filename);                  //new BinaryReader( new FileStream( filename, FileMode.Open, FileAccess.Read, FileShare.Read ) );

                m_Version = m_GZIn.Raw.ReadByte();

                if (m_Version > PlayerVersion)
                {
                    m_GZIn.Close();
                    m_GZIn = null;
                    MessageBox.Show(Engine.MainWindow, Language.GetString(LocString.WrongVer), "Version Mismatch", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return;
                }

                m_GZIn.IsCompressed = m_Version > 1;

                byte[]   filehash = m_GZIn.Raw.ReadBytes(16);
                DateTime created  = DateTime.FromFileTime(m_GZIn.Raw.ReadInt64());
                TimeSpan len      = TimeSpan.FromMilliseconds(m_GZIn.Raw.ReadInt32());

                string player           = m_GZIn.Compressed.ReadString();
                string shard            = m_GZIn.Compressed.ReadString();
                System.Net.IPAddress ip = System.Net.IPAddress.Any;
                try
                {
                    if (m_Version > 1)
                    {
                        ip = new System.Net.IPAddress((long)m_GZIn.Compressed.ReadUInt32());
                    }
                }
                catch
                {
                }

                m_StartPos = (int)m_GZIn.Position;

                long rawPos = m_GZIn.RawStream.Position;
                m_GZIn.RawStream.Seek(1 + 16, SeekOrigin.Begin);
                using (MD5 md5 = MD5.Create())
                {
                    byte[] check = md5.ComputeHash(m_GZIn.RawStream);
                    for (int i = 0; i < check.Length; i++)
                    {
                        if (check[i] != filehash[i])
                        {
                            m_GZIn.Close();
                            m_GZIn = null;
                            MessageBox.Show(Engine.MainWindow, Language.GetString(LocString.VideoCorrupt), "Damaged File", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }
                m_GZIn.RawStream.Seek(rawPos, SeekOrigin.Begin);

                m_CurLength = len;
                m_Elapsed   = TimeSpan.Zero;

                UpdateTimeText();

                m_RPVInfo        = lblPlay.Text = String.Format("File: {0}\nLength: {1} ({2})\nDate: {3}\nRecorded by \"{4}\" on \"{5}\" ({6})\n", Path.GetFileName(filename), Utility.FormatTime((int)len.TotalSeconds), Utility.FormatSize(m_GZIn.RawStream.Length), created.ToString("M-dd-yy @ h:mmtt"), player, shard, ip);
                btnClose.Enabled = btnPlay.Enabled = btnStop.Enabled = true;
                tbPos.Maximum    = (int)len.TotalSeconds;
                tbPos.Minimum    = 0;
            }
            catch (Exception e)
            {
                if (e is FileNotFoundException)
                {
                    MessageBox.Show(Engine.MainWindow, e.Message, "File not found.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    Engine.LogCrash(e);
                    MessageBox.Show(Engine.MainWindow, Language.GetString(LocString.ReadError), "Read Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                m_GZIn.Close();
                m_GZIn = null;
                return;
            }
        }