// class functions public void ParseScript() { this.commands = new List <ActionCommand>(); int offset = 0, length; while (offset < script.Length) { byte param1 = 0; if (script.Length - offset > 1) { param1 = script[offset + 1]; } length = ScriptEnums.GetActionCommandLength(script[offset], param1); commands.Add(new ActionCommand(Bits.GetBytes(script, offset, length), this.baseOffset + offset)); offset += length; } }
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); }