Fixed bug with LOOP function
This commit is contained in:
parent
8db0a6e881
commit
92c4089d6d
|
@ -19,7 +19,7 @@ namespace attack {
|
||||||
void start(const char* path) {
|
void start(const char* path) {
|
||||||
// If script doesn't exist, don't do anything
|
// If script doesn't exist, don't do anything
|
||||||
if (!msc::exists(path)) return;
|
if (!msc::exists(path)) return;
|
||||||
|
|
||||||
// Set attack color
|
// Set attack color
|
||||||
led::setColor(preferences::getAttackColor());
|
led::setColor(preferences::getAttackColor());
|
||||||
|
|
||||||
|
@ -41,25 +41,26 @@ namespace attack {
|
||||||
uint32_t cur_pos = 0;
|
uint32_t cur_pos = 0;
|
||||||
int repeats = 0;
|
int repeats = 0;
|
||||||
|
|
||||||
// For LOOP_START and LOOP_END
|
// For LOOP_BEGIN and LOOP_END
|
||||||
uint32_t start_pos = 0;
|
uint32_t start_pos = 0;
|
||||||
int loops = 0;
|
int loops = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
debug("Reading line...");
|
debugF("Reading line...");
|
||||||
if (!msc::getInLine()) cur_pos = msc::getPosition();
|
if (!msc::getInLine()) cur_pos = msc::getPosition();
|
||||||
len = msc::readLine(buffer, READ_BUFFER);
|
len = msc::readLine(buffer, READ_BUFFER);
|
||||||
debugln(len);
|
|
||||||
//debugln(std::string(buffer, len-1).c_str());
|
|
||||||
|
|
||||||
// Reached end of file
|
// Reached end of file
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
debugln("Reached end of file");
|
debuglnF("Reached end of file");
|
||||||
if (msc::openNextFile()) continue;
|
if (msc::openNextFile()) continue;
|
||||||
else break;
|
else break;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug("Parsing...");
|
debugln(len);
|
||||||
|
debugln(std::string(buffer, len-1).c_str());
|
||||||
|
|
||||||
|
debugF("Parsing...");
|
||||||
duckparser::parse(buffer, len);
|
duckparser::parse(buffer, len);
|
||||||
|
|
||||||
// For REPEAT/REPLAY
|
// For REPEAT/REPLAY
|
||||||
|
@ -76,7 +77,7 @@ namespace attack {
|
||||||
|
|
||||||
if (!msc::getInLine()) prev_pos = cur_pos;
|
if (!msc::getInLine()) prev_pos = cur_pos;
|
||||||
|
|
||||||
// For LOOP_START/LOOP_STOP
|
// For LOOP_BEGIN/LOOP_END
|
||||||
if (duckparser::loopBegin()) {
|
if (duckparser::loopBegin()) {
|
||||||
start_pos = msc::getPosition();
|
start_pos = msc::getPosition();
|
||||||
loops = duckparser::getLoops();
|
loops = duckparser::getLoops();
|
||||||
|
@ -91,10 +92,9 @@ namespace attack {
|
||||||
msc::open(path.c_str());
|
msc::open(path.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
debugln("OK");
|
debuglnF("OK");
|
||||||
}
|
}
|
||||||
|
debuglnF("Attack finished");
|
||||||
debugln("Attack finished");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void start() {
|
void start() {
|
||||||
|
|
|
@ -161,12 +161,16 @@ namespace duckparser {
|
||||||
if (offset > time) return;
|
if (offset > time) return;
|
||||||
else time -= offset;
|
else time -= offset;
|
||||||
|
|
||||||
sleep_start_time = millis();
|
if (time < 50) {
|
||||||
unsigned long sleep_end_time = sleep_start_time + time;
|
delay(time);
|
||||||
|
} else {
|
||||||
|
sleep_start_time = millis();
|
||||||
|
unsigned long sleep_end_time = sleep_start_time + time;
|
||||||
|
|
||||||
while (millis() < sleep_end_time) {
|
while (millis() < sleep_end_time) {
|
||||||
delay(1);
|
delay(1);
|
||||||
tasks::update();
|
tasks::update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,20 +194,21 @@ namespace duckparser {
|
||||||
bool ignore_delay;
|
bool ignore_delay;
|
||||||
|
|
||||||
while (n) {
|
while (n) {
|
||||||
ignore_delay = false;
|
|
||||||
loop_begin = false;
|
|
||||||
loop_end = false;
|
|
||||||
|
|
||||||
word_list* wl = n->words;
|
word_list* wl = n->words;
|
||||||
word_node* cmd = wl->first;
|
word_node* cmd = wl->first;
|
||||||
|
|
||||||
// String of the entire line excluding the command keyword (i.e. "STRING ")
|
// String of the entire line excluding the command keyword (i.e. "STRING ")
|
||||||
const char* line_str = cmd->str + cmd->len + 1;
|
bool has_line_str = cmd->next;
|
||||||
size_t line_str_len = n->len - cmd->len - 1;
|
const char* line_str = has_line_str ? (cmd->str + cmd->len + 1) : nullptr;
|
||||||
|
size_t line_str_len = has_line_str ? (n->len - cmd->len - 1) : 0;
|
||||||
|
|
||||||
char last_char = n->str[n->len];
|
char last_char = n->str[n->len];
|
||||||
bool line_end = last_char == '\r' || last_char == '\n';
|
bool line_end = last_char == '\r' || last_char == '\n';
|
||||||
|
|
||||||
|
ignore_delay = false;
|
||||||
|
loop_begin = false;
|
||||||
|
loop_end = false;
|
||||||
|
|
||||||
// Check if we're in a multi line comment
|
// Check if we're in a multi line comment
|
||||||
if (in_ml_comment) {
|
if (in_ml_comment) {
|
||||||
// Check for the end of the comment block
|
// Check for the end of the comment block
|
||||||
|
@ -277,7 +282,7 @@ namespace duckparser {
|
||||||
type(line_str, line_str_len);
|
type(line_str, line_str_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(line_end) {
|
if (line_end) {
|
||||||
keyboard::pressKey(KEY_ENTER);
|
keyboard::pressKey(KEY_ENTER);
|
||||||
release();
|
release();
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,9 +65,9 @@ namespace duckparser {
|
||||||
|
|
||||||
// comparison incorrect or string checked until the end and templ_str not checked until the end
|
// comparison incorrect or string checked until the end and templ_str not checked until the end
|
||||||
if (!res || ((a == str_len - 1) &&
|
if (!res || ((a == str_len - 1) &&
|
||||||
(templ_str[b + 1] != ',') &&
|
(templ_str[b + 1] != ',') &&
|
||||||
(templ_str[b + 1] != '/') &&
|
(templ_str[b + 1] != '/') &&
|
||||||
(templ_str[b + 1] != '\0'))) {
|
(templ_str[b + 1] != '\0'))) {
|
||||||
// fast forward to next comma
|
// fast forward to next comma
|
||||||
while (b < key_len && templ_str[b] != ',') b++;
|
while (b < key_len && templ_str[b] != ',') b++;
|
||||||
res = 1;
|
res = 1;
|
||||||
|
@ -81,8 +81,8 @@ namespace duckparser {
|
||||||
// comparison correct AND string checked until the end AND templ_str checked until the end
|
// comparison correct AND string checked until the end AND templ_str checked until the end
|
||||||
if (res && (a == str_len) &&
|
if (res && (a == str_len) &&
|
||||||
((templ_str[b] == ',') ||
|
((templ_str[b] == ',') ||
|
||||||
(templ_str[b] == '/') ||
|
(templ_str[b] == '/') ||
|
||||||
(templ_str[b] == '\0'))) return COMPARE_EQUAL; // res_i
|
(templ_str[b] == '\0'))) return COMPARE_EQUAL; // res_i
|
||||||
|
|
||||||
return COMPARE_UNEQUAL;
|
return COMPARE_UNEQUAL;
|
||||||
}
|
}
|
||||||
|
@ -295,19 +295,22 @@ namespace duckparser {
|
||||||
// in_quotes = (curr == '"' && !escaped) ? !in_quotes : in_quotes;
|
// in_quotes = (curr == '"' && !escaped) ? !in_quotes : in_quotes;
|
||||||
// delimiter = !in_quotes && !escaped && curr == ';' && next == ';';
|
// delimiter = !in_quotes && !escaped && curr == ';' && next == ';';
|
||||||
|
|
||||||
linebreak = !in_quotes && (curr == '\r' || curr == '\n');
|
linebreak = /*!in_quotes && */ (curr == '\r' || curr == '\n');
|
||||||
|
|
||||||
endofline = stri == len || curr == '\0';
|
// skip \n after \r (windows linebreak)
|
||||||
|
if (/*!in_quotes && */ (curr == '\r') && (next == '\n')) ++stri;
|
||||||
|
|
||||||
|
endofline = (stri == len) || (curr == '\0');
|
||||||
|
|
||||||
if (linebreak || endofline || delimiter) {
|
if (linebreak || endofline || delimiter) {
|
||||||
size_t llen = stri - ls; // length of line
|
size_t llen = stri - ls; // length of line
|
||||||
|
|
||||||
// for every line, parse_words and add to list
|
// for every line, parse_words and add to list
|
||||||
//if (llen > 0) {
|
if (llen > 0) {
|
||||||
n = line_node_create(&str[ls], llen);
|
n = line_node_create(&str[ls], llen);
|
||||||
n->words = parse_words(&str[ls], llen);
|
n->words = parse_words(&str[ls], llen);
|
||||||
line_list_push(l, n);
|
line_list_push(l, n);
|
||||||
//}
|
}
|
||||||
|
|
||||||
if (delimiter) ++stri;
|
if (delimiter) ++stri;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue