コード例 #1
0
        //public FileStream s2 = File.Create(@"d:\Old\Temp\3DS Files\MK7\Mobi\CourseSelectRace\video.bin");
        //bool startedframe = false;
        //int framesize = 0;
        //long framestartpos = 0;

        public uint ReadEp(byte[] packet, ref uint pos, uint psize)
        {
            if (pos == psize) return 0x101;
            if (pos > psize)
            {
                Desynchronize();
                return 0x43;
            }
            //long curpos = packet.Position;
            //packet.Position += pos;
            byte tmp = packet[pos];//(byte)packet.ReadByte();
            //packet.Position -= 1;
            if (tmp == 0)
            {
                pos++;
                uint EpPadding;
                if (VariablePacketSize) EpPadding = 0;
                else
                {
                    EpPadding = PacketSize - pos;
                    pos = PacketSize;
                }
                //if (!VariablePacketSize) pos = PacketSize;
                return 0x101;
            }

            int NrStreamIdxBits = 1;
            MoLiveInBitStream bs = new MoLiveInBitStream() { Value = 0, Stream = packet, Pos = pos, Remaining = 0 };
            while (bs.Pop(1) == 0) NrStreamIdxBits++;
            int StreamIdx = (int)bs.Pop(NrStreamIdxBits);

            bool EndFrame = bs.Pop(1) == 1;

            if (EndFrame)
            {
                int FrameTypeNrBits = 1;
                while (bs.Pop(1) == 0) FrameTypeNrBits++;
                int FrameType = (int)bs.Pop(FrameTypeNrBits);
                int v23 = 28;
                bool v35 = (int)bs.Pop(1) == 1;
                while (bs.Pop(1) == 0) v23 += 2;
                long v24 = (long)bs.Pop(v23);
                int v26 = (int)(v24 >> 32);
                int v25 = (int)v24;
                if (v35)
                {
                    v25 = (int)-v24;
                    v26 = -((~((v24 <= 0) ? 1 : 0)) + (int)(v24 >> 32));
                }
            }
            int EPSize = (int)bs.Pop(0xD) + 1;
            pos = bs.Pos;//(uint)bs.Stream.Position - (uint)curpos;

            if (pos + EPSize > psize)
            {
                Desynchronize();
                return 0x43;
            }
            byte[] epdata = new byte[EPSize];
            Array.Copy(packet, pos, epdata, 0, EPSize);
            if(Streams.ContainsKey(StreamIdx))
                Streams[StreamIdx].AddData(epdata);
            /*if (StreamIdx == videostreamid)
            {
                if (!startedframe)
                {
                    //s2.WriteByte((byte)(EPSize & 0xFF));
                    //s2.WriteByte((byte)((EPSize >> 8) & 0xFF));
                    framestartpos = s2.Position;
                    s2.WriteByte(0);
                    s2.WriteByte(0);
                    framesize = 0;
                    startedframe = true;
                }
                framesize += EPSize;
                s2.Write(epdata, 0, epdata.Length);
            }*/
            pos += (uint)EPSize;

            if (EndFrame)// && StreamIdx == videostreamid)
            {
                if (Streams.ContainsKey(StreamIdx))
                {
                    Streams[StreamIdx].AddData(new byte[2]);
                    if (OnCompleteFrameReceived != null)
                    {
                        OnCompleteFrameReceived(Streams[StreamIdx].Chunk, Streams[StreamIdx].GetData());
                    }
                    Streams[StreamIdx].ClearData();
                }
                /*if (startedframe)
                {
                    startedframe = false;
                    long curpos = s2.Position;
                    s2.Position = framestartpos;
                    s2.WriteByte((byte)(framesize & 0xFF));
                    s2.WriteByte((byte)((framesize >> 8) & 0xFF));
                    s2.Position = curpos;
                }*/
            }

            if (pos < psize) return 0;
            return 0x101;
        }
コード例 #2
0
        //public FileStream s2 = File.Create(@"d:\Old\Temp\3DS Files\MK7\Mobi\CourseSelectRace\video.bin");
        //bool startedframe = false;
        //int framesize = 0;
        //long framestartpos = 0;

        public uint ReadEp(byte[] packet, ref uint pos, uint psize)
        {
            if (pos == psize)
            {
                return(0x101);
            }
            if (pos > psize)
            {
                Desynchronize();
                return(0x43);
            }
            //long curpos = packet.Position;
            //packet.Position += pos;
            byte tmp = packet[pos];//(byte)packet.ReadByte();

            //packet.Position -= 1;
            if (tmp == 0)
            {
                pos++;
                uint EpPadding;
                if (VariablePacketSize)
                {
                    EpPadding = 0;
                }
                else
                {
                    EpPadding = PacketSize - pos;
                    pos       = PacketSize;
                }
                //if (!VariablePacketSize) pos = PacketSize;
                return(0x101);
            }

            int NrStreamIdxBits  = 1;
            MoLiveInBitStream bs = new MoLiveInBitStream()
            {
                Value = 0, Stream = packet, Pos = pos, Remaining = 0
            };

            while (bs.Pop(1) == 0)
            {
                NrStreamIdxBits++;
            }
            int StreamIdx = (int)bs.Pop(NrStreamIdxBits);

            bool EndFrame = bs.Pop(1) == 1;

            if (EndFrame)
            {
                int FrameTypeNrBits = 1;
                while (bs.Pop(1) == 0)
                {
                    FrameTypeNrBits++;
                }
                int  FrameType = (int)bs.Pop(FrameTypeNrBits);
                int  v23       = 28;
                bool v35       = (int)bs.Pop(1) == 1;
                while (bs.Pop(1) == 0)
                {
                    v23 += 2;
                }
                long v24 = (long)bs.Pop(v23);
                int  v26 = (int)(v24 >> 32);
                int  v25 = (int)v24;
                if (v35)
                {
                    v25 = (int)-v24;
                    v26 = -((~((v24 <= 0) ? 1 : 0)) + (int)(v24 >> 32));
                }
            }
            int EPSize = (int)bs.Pop(0xD) + 1;

            pos = bs.Pos;//(uint)bs.Stream.Position - (uint)curpos;

            if (pos + EPSize > psize)
            {
                Desynchronize();
                return(0x43);
            }
            byte[] epdata = new byte[EPSize];
            Array.Copy(packet, pos, epdata, 0, EPSize);
            if (Streams.ContainsKey(StreamIdx))
            {
                Streams[StreamIdx].AddData(epdata);
            }

            /*if (StreamIdx == videostreamid)
             * {
             *  if (!startedframe)
             *  {
             *      //s2.WriteByte((byte)(EPSize & 0xFF));
             *      //s2.WriteByte((byte)((EPSize >> 8) & 0xFF));
             *      framestartpos = s2.Position;
             *      s2.WriteByte(0);
             *      s2.WriteByte(0);
             *      framesize = 0;
             *      startedframe = true;
             *  }
             *  framesize += EPSize;
             *  s2.Write(epdata, 0, epdata.Length);
             * }*/
            pos += (uint)EPSize;

            if (EndFrame)// && StreamIdx == videostreamid)
            {
                if (Streams.ContainsKey(StreamIdx))
                {
                    Streams[StreamIdx].AddData(new byte[2]);
                    if (OnCompleteFrameReceived != null)
                    {
                        OnCompleteFrameReceived(Streams[StreamIdx].Chunk, Streams[StreamIdx].GetData());
                    }
                    Streams[StreamIdx].ClearData();
                }

                /*if (startedframe)
                 * {
                 *  startedframe = false;
                 *  long curpos = s2.Position;
                 *  s2.Position = framestartpos;
                 *  s2.WriteByte((byte)(framesize & 0xFF));
                 *  s2.WriteByte((byte)((framesize >> 8) & 0xFF));
                 *  s2.Position = curpos;
                 * }*/
            }

            if (pos < psize)
            {
                return(0);
            }
            return(0x101);
        }