Пример #1
0
        /// <summary>
        /// Builds this script's command collection from the buffer data.
        /// </summary>
        public void ParseScript()
        {
            this.Commands = new List <ActionCommand>();
            int offset = 0, length;

            while (offset < Buffer.Length)
            {
                byte param1 = 0;
                if (Buffer.Length - offset > 1)
                {
                    param1 = Buffer[offset + 1];
                }
                length = ScriptEnums.GetActionCommandLength(Buffer[offset], param1);
                Commands.Add(new ActionCommand(Bits.GetBytes(Buffer, offset, length), this.BaseOffset + offset));
                offset += length;
            }
        }
Пример #2
0
        private int GetCommandLength(byte[] script, int offset)
        {
            byte opcode = script[offset];
            byte param1;

            if (script.Length - offset > 1)
            {
                param1 = script[offset + 1];
            }
            else
            {
                param1 = 0;
            }
            int length = ScriptEnums.GetEventCommandLength(opcode, param1);

            // Handles special case
            if (opcode <= 0x2F && (param1 == 0xF0 || param1 == 0xF1) && length == 3)
            {
                if (Bits.GetBit(script[offset + 2], 7))
                {
                    length += script[offset + 2] & 0x3F; // Max value of 63 0x3F
                }
                else
                {
                    length += script[offset + 2] & 0x7F; // Max value of 127 0x7F
                }
            }
            else if (opcode <= 0x2F && param1 < 0xF0)
            {
                for (int i = 0; i < length - 2;)
                {
                    opcode = script[offset + 2 + i];
                    if (script.Length - (offset + i + 2) > 1)
                    {
                        param1 = script[offset + 2 + 1 + i];
                    }
                    else
                    {
                        param1 = 0;
                    }
                    i += ScriptEnums.GetActionCommandLength(opcode, param1);
                }
            }
            return(length);
        }