Ejemplo n.º 1
0
Archivo: HIO2.cs Proyecto: magcius/mchi
        private void ProcessTags(ByteBuffer tagBuffer)
        {
            while (true)
            {
                if (tagBuffer.Data.Length < 0x08)
                {
                    // Not enough data...
                    return;
                }

                string           tagMagic  = Encoding.ASCII.GetString(tagBuffer.Data, 0x00, 0x04);
                IJHITagProcessor processor = tagDispatch[tagMagic];

                int tagSize = JHI.SwapBytes(BitConverter.ToInt32(tagBuffer.Data, 0x04));
                if (tagBuffer.Data.Length < 0x08 + tagSize)
                {
                    // Not enough data...
                    return;
                }

                // Tag is done!
                JHITag tag = new JHITag();
                tag.Magic = tagMagic;
                tag.Data  = tagBuffer.Data.AsSpan(0x08, tagSize).ToArray();
                tagBuffer.DoneReading(0x08 + tagSize);

                processor.ProcessTag(tag);
            }
        }
Ejemplo n.º 2
0
        public int ReadS16()
        {
            int offset = this.offset;

            this.offset += 0x02;
            return(JHI.SwapBytes(BitConverter.ToInt16(this.data, offset)));
        }
Ejemplo n.º 3
0
        public uint ReadU32()
        {
            int offset = this.offset;

            this.offset += 0x04;
            return(JHI.SwapBytes(BitConverter.ToUInt32(this.data, offset)));
        }
Ejemplo n.º 4
0
        public float ReadF32()
        {
            int offset = this.offset;

            this.offset += 0x04;
            return(BitConverter.ToSingle(JHI.SwapBytes(this.data.AsSpan(offset, 4).ToArray()), 0));
        }
Ejemplo n.º 5
0
Archivo: HIO2.cs Proyecto: magcius/mchi
 public void WriteToDolphin(JHITag tag)
 {
     byte[] data       = new byte[0x08 + tag.Data.Length];
     byte[] magicBytes = Encoding.ASCII.GetBytes(tag.Magic);
     Array.Copy(magicBytes, 0x00, data, 0x00, 0x04);
     byte[] lengthBytes = BitConverter.GetBytes(JHI.SwapBytes(tag.Data.Length));
     Array.Copy(lengthBytes, 0x00, data, 0x04, 0x04);
     Array.Copy(tag.Data, 0x00, data, 0x08, tag.Data.Length);
     WriteToDolphin(data);
 }
Ejemplo n.º 6
0
Archivo: HIO2.cs Proyecto: magcius/mchi
        private int WriteMessage(int dstOffs, byte[] src, int srcOffs, int size)
        {
            hio2.WriteBytes(dstOffs + 0x00, Encoding.ASCII.GetBytes(MAGIC_CODE));
            hio2.WriteBytes(dstOffs + 0x04, BitConverter.GetBytes(JHI.SwapBytes((ushort)size)));
            hio2.WriteBytes(dstOffs + 0x06, src, srcOffs, size);
            int fullSize         = GetFullMessageSize(size);
            int numZeroesToWrite = fullSize - (0x06 + size);

            byte[] zeroes = new byte[numZeroesToWrite];
            hio2.WriteBytes(dstOffs + 0x06 + size, zeroes);
            return(fullSize);
        }
Ejemplo n.º 7
0
Archivo: HIO2.cs Proyecto: magcius/mchi
        private void ProcessChunks(ByteBuffer outBuffer, byte[] data)
        {
            int offs = 0;

            while (offs < data.Length)
            {
                Debug.Assert(JHI.StrEq(data, offs + 0x00, JHIMccBuf.MAGIC_CODE));

                int chunkSize = JHI.SwapBytes(BitConverter.ToInt16(data, offs + 0x04));
                offs += 0x06;

                outBuffer.Write(data, offs, chunkSize);
                offs += chunkSize;

                // Align to 0x20.
                offs = (offs + 0x1F) & ~0x1F;
            }
        }
Ejemplo n.º 8
0
Archivo: HIO2.cs Proyecto: magcius/mchi
        public byte[] ReadData()
        {
            SyncPointsFromHIO2();

            if (this.pointW == this.pointR)
            {
                // Empty, nothing to read.
                return(null);
            }

            int size = this.pointW - this.pointR;

            if (size < 0)
            {
                size += this.bufDataSize;
            }

            byte[] data      = new byte[size];
            int    data_offs = 0x00;

            // Check for wraparound -- where the new WP is less than our RP.
            // In this case, we need to split the read into two.
            if (this.pointW < this.pointR)
            {
                // First, read from pointW until end of buffer.
                int size1 = this.bufDataSize - this.pointR;
                hio2.ReadBytes(ref data, data_offs, this.baseOffset + DATA_OFFSET + this.pointR, size1);
                data_offs += size1;
                size      -= size1;

                // Reset pointR back to the start to prepare for the next read.
                this.pointR = 0;
            }

            hio2.ReadBytes(ref data, data_offs, this.baseOffset + DATA_OFFSET + this.pointR, size);

            Debug.Assert(JHI.StrEq(data, 0, MAGIC_CODE));

            // Update our read point to match.
            this.pointR = this.pointW;
            SyncReadPointToHIO2();

            return(data);
        }
Ejemplo n.º 9
0
        private void ProcessUpdateNode(MemoryInputStream stream, JORNode node)
        {
            Debug.WriteLine("<- ORef ProcessUpdate CMD {0}", JHI.HexDump(stream.data));

            while (stream.HasData())
            {
                JORMessageCommand command = (JORMessageCommand)stream.ReadU32();

                Debug.WriteLine("<- ORef ProcessUpdate {0}", command);

                if (command == JORMessageCommand.UpdateControl)
                {
                    uint updateMode = stream.ReadU32();
                    uint id         = stream.ReadU32();
                    var  control    = node.FindControlByID(id, 0);

                    if (control == null)
                    {
                        // No clue about this control; can't parse.
                        return;
                    }

                    if (control is JORControlCheckBox)
                    {
                        // Checkboxes can have multiple controls with the same ID.
                        uint subID = stream.ReadU32();
                        control = node.FindControlByID(id, subID);

                        if (control == null)
                        {
                            // Shouldn't happen, but just in case...
                            return;
                        }
                    }

                    control.Update(updateMode, stream);
                }
            }
        }
Ejemplo n.º 10
0
Archivo: HIO2.cs Proyecto: magcius/mchi
 public int ReadU32(int buf_idx)
 {
     return(JHI.SwapBytes(this.accessor.ReadInt32(buf_idx)));
 }
Ejemplo n.º 11
0
Archivo: HIO2.cs Proyecto: magcius/mchi
 public void WriteU32(int buf_idx, int v)
 {
     WriteBytes(buf_idx, BitConverter.GetBytes(JHI.SwapBytes(v)));
 }
Ejemplo n.º 12
0
Archivo: HIO2.cs Proyecto: magcius/mchi
 public bool IsConnected()
 {
     return(JHI.StrEq(ReadBytes(0x00, 0x04), 0x00, JHIMccBuf.MAGIC_CODE));
 }
Ejemplo n.º 13
0
 public void Write(float x)
 {
     Write(JHI.SwapBytes(BitConverter.GetBytes(x)));
 }
Ejemplo n.º 14
0
 public void Write(ushort x)
 {
     Write(BitConverter.GetBytes(JHI.SwapBytes(x)));
 }
Ejemplo n.º 15
0
Archivo: HIO2.cs Proyecto: magcius/mchi
 public bool HasDisconnectCode()
 {
     return(JHI.StrEq(ReadBytes(0x04, 0x04), 0x00, DISCONNECT_CODE));
 }
Ejemplo n.º 16
0
Archivo: HIO2.cs Proyecto: magcius/mchi
 public bool IsReady()
 {
     return(JHI.StrEq(hio2.ReadBytes(MAGIC_OFFSET, 4), 0, MAGIC_CODE));
 }
Ejemplo n.º 17
0
Archivo: HIO2.cs Proyecto: magcius/mchi
 public string Dump()
 {
     return(String.Format("JHITag {0}  {1}", this.Magic, JHI.HexDump(this.Data)));
 }