Fixed bug with LOOP function

This commit is contained in:
Spacehuhn 2023-06-28 00:01:25 +02:00
parent 8db0a6e881
commit 92c4089d6d
3 changed files with 40 additions and 32 deletions

View File

@ -19,7 +19,7 @@ namespace attack {
void start(const char* path) {
// If script doesn't exist, don't do anything
if (!msc::exists(path)) return;
// Set attack color
led::setColor(preferences::getAttackColor());
@ -41,25 +41,26 @@ namespace attack {
uint32_t cur_pos = 0;
int repeats = 0;
// For LOOP_START and LOOP_END
// For LOOP_BEGIN and LOOP_END
uint32_t start_pos = 0;
int loops = 0;
while (true) {
debug("Reading line...");
debugF("Reading line...");
if (!msc::getInLine()) cur_pos = msc::getPosition();
len = msc::readLine(buffer, READ_BUFFER);
debugln(len);
//debugln(std::string(buffer, len-1).c_str());
// Reached end of file
if (len == 0) {
debugln("Reached end of file");
debuglnF("Reached end of file");
if (msc::openNextFile()) continue;
else break;
}
debug("Parsing...");
debugln(len);
debugln(std::string(buffer, len-1).c_str());
debugF("Parsing...");
duckparser::parse(buffer, len);
// For REPEAT/REPLAY
@ -76,7 +77,7 @@ namespace attack {
if (!msc::getInLine()) prev_pos = cur_pos;
// For LOOP_START/LOOP_STOP
// For LOOP_BEGIN/LOOP_END
if (duckparser::loopBegin()) {
start_pos = msc::getPosition();
loops = duckparser::getLoops();
@ -91,10 +92,9 @@ namespace attack {
msc::open(path.c_str());
}
debugln("OK");
debuglnF("OK");
}
debugln("Attack finished");
debuglnF("Attack finished");
}
void start() {

View File

@ -161,12 +161,16 @@ namespace duckparser {
if (offset > time) return;
else time -= offset;
sleep_start_time = millis();
unsigned long sleep_end_time = sleep_start_time + time;
if (time < 50) {
delay(time);
} else {
sleep_start_time = millis();
unsigned long sleep_end_time = sleep_start_time + time;
while (millis() < sleep_end_time) {
delay(1);
tasks::update();
while (millis() < sleep_end_time) {
delay(1);
tasks::update();
}
}
}
@ -190,20 +194,21 @@ namespace duckparser {
bool ignore_delay;
while (n) {
ignore_delay = false;
loop_begin = false;
loop_end = false;
word_list* wl = n->words;
word_node* cmd = wl->first;
// String of the entire line excluding the command keyword (i.e. "STRING ")
const char* line_str = cmd->str + cmd->len + 1;
size_t line_str_len = n->len - cmd->len - 1;
bool has_line_str = cmd->next;
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];
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
if (in_ml_comment) {
// Check for the end of the comment block
@ -277,7 +282,7 @@ namespace duckparser {
type(line_str, line_str_len);
}
if(line_end) {
if (line_end) {
keyboard::pressKey(KEY_ENTER);
release();
}

View File

@ -65,9 +65,9 @@ namespace duckparser {
// comparison incorrect or string checked until the end and templ_str not checked until the end
if (!res || ((a == str_len - 1) &&
(templ_str[b + 1] != ',') &&
(templ_str[b + 1] != '/') &&
(templ_str[b + 1] != '\0'))) {
(templ_str[b + 1] != ',') &&
(templ_str[b + 1] != '/') &&
(templ_str[b + 1] != '\0'))) {
// fast forward to next comma
while (b < key_len && templ_str[b] != ',') b++;
res = 1;
@ -81,8 +81,8 @@ namespace duckparser {
// comparison correct AND string checked until the end AND templ_str checked until the end
if (res && (a == str_len) &&
((templ_str[b] == ',') ||
(templ_str[b] == '/') ||
(templ_str[b] == '\0'))) return COMPARE_EQUAL; // res_i
(templ_str[b] == '/') ||
(templ_str[b] == '\0'))) return COMPARE_EQUAL; // res_i
return COMPARE_UNEQUAL;
}
@ -295,19 +295,22 @@ namespace duckparser {
// in_quotes = (curr == '"' && !escaped) ? !in_quotes : in_quotes;
// 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) {
size_t llen = stri - ls; // length of line
// for every line, parse_words and add to list
//if (llen > 0) {
if (llen > 0) {
n = line_node_create(&str[ls], llen);
n->words = parse_words(&str[ls], llen);
line_list_push(l, n);
//}
}
if (delimiter) ++stri;