Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // GDAuto.cpp : Source definition of class GDAuto.
- //
- #include "GDAuto.h"
- #include <string>
- #include <sstream>
- #include <array>
- using namespace std;
- #pragma region GEOMETRY DASH AUTO
- GDAuto::GDAuto(const int key_toggle, string _filename)
- : KEY_TOGGLE(key_toggle),
- jump('j'),
- wait('w'),
- sep('-')
- {
- this->started = false;
- this->filename = _filename;
- //Command detection
- GetCommand();
- }
- GDAuto::~GDAuto()
- {
- cout<<"Writer class has been destroyed."<<endl;
- }
- void GDAuto::WriteFromInput()
- {
- bool action = false; //true = ha saltato
- bool write_start = false; //true = inizia a scrivere
- int val = 0;
- string sequence;
- cout<<"WriteFromInput setup finished. Waiting for left click to start writing."<<endl;
- while (true)
- if (GetAsyncKeyState(VK_LBUTTON)) break;
- cout<<"WriteFromInput started. Entering the loop..."<<endl;
- while (true)
- {
- //Se premi il tasto definito, interrompe il ciclo
- if (GetAsyncKeyState(KEY_TOGGLE)) break;
- //Questo è il main loop dove legge i tasti e scrive
- /* BACKUP
- if (action)
- {
- if (GetAsyncKeyState(VK_LBUTTON))
- {
- //sequence << jump << val << sep; vecchia versione con stringstream
- sequence += jump + NumberToString<int>(val) + sep;
- action = true;
- val = 0;
- }
- else
- {
- if (!GetAsyncKeyState(VK_LBUTTON))
- {
- //sequence << wait << val << sep; vecchia versione con stringstream
- sequence += wait + NumberToString<int>(val) + sep;
- action = false;
- val = 0;
- }
- }
- }
- */
- if (action)
- {
- if (!GetAsyncKeyState(VK_LBUTTON))
- {
- sequence += jump + NumberToString<int>(val) + sep;
- action = false;
- val = 0;
- }
- }
- else
- {
- if (GetAsyncKeyState(VK_LBUTTON))
- {
- sequence += wait + NumberToString<int>(val) + sep;
- action = true;
- val = 0;
- }
- }
- val++;
- //Pausa il thread per 1ms, così ogni ciclata corrisponde ad 1 ms.
- Sleep(1);
- }
- this->GDFile.open(this->filename);
- if (this->GDFile.is_open()) {
- //Scrivi tutto su file
- this->GDFile << sequence;
- } else cout<<"Unable to open file"<<endl;
- cout<<"Finished."<<endl;
- cout<<"The string that I wrote is:"<<endl;
- cout<<sequence<<endl;
- this->GDFile.close();
- this->started = false;
- }
- void GDAuto::GetCommand()
- {
- //List of commands:
- //help -> Show a list of all commands avaiable
- //rec -> Setup program to record mouse activity
- //exit -> Just quits the program
- bool first_time = true;
- string cmd = "";
- while (true)
- {
- if (first_time) {
- cout<<"Welcome to Geometry Dash Auto.\nPlease write a command (help for a list of commands)"<<endl;
- cin>>cmd;
- } else {
- cout<<"\nPlease insert a command."<<endl;
- cin>>cmd;
- }
- if (cmd=="help")
- {
- cout<<"\nCOMMAND LIST:"<<endl;
- cout<<"help -> Show a list of all commands avaiable;"<<endl;
- cout<<"rec -> Setup program to record mouse activity;"<<endl;
- cout<<"read -> Setup program to read files;"<<endl;
- cout<<"delete -> Delete GDWriter's file if it exists;"<<endl;
- cout<<"exit -> Just quits the program;"<<endl;
- }
- else if (cmd=="rec")
- {
- cout<<"rec command called. Writer is waiting for the toggle key ("<<KEY_TOGGLE<<")."<<endl;
- while (true) {
- if (GetAsyncKeyState(KEY_TOGGLE)) {
- this->started = true;
- Sleep(200);
- break;
- }
- }
- while (started) this->WriteFromInput();
- }
- else if (cmd=="read")
- {
- this->ReadFromFile();
- }
- else if (cmd=="delete")
- {
- if (remove(this->filename.c_str())!=0)
- cout<<"GDWriter's file ("<<filename<<") has been deleted."<<endl;
- else {
- //cout<<"I had some problems deleting GDWriter's file ("<<this->filename<<")."<<endl;
- //cout<<"Maybe filename has not been initialized."<<endl;
- }
- }
- else if (cmd=="exit")
- {
- break;
- }
- else
- {
- cout<<"This command is invalid."<<endl;
- }
- cmd = "";
- first_time = false;
- }
- cout<<"Killing program process..."<<endl;
- }
- void GDAuto::ReadFromFile()
- {
- wchar_t* buffer = GetFileName("Open a valid file");
- ifstream gd_file_read (buffer);
- string commands;
- if (gd_file_read.is_open())
- {
- getline(gd_file_read,commands);
- gd_file_read.close();
- } else {cout<<"Unable to open file."<<endl; return;}
- vector<string> list_cmd = split(commands, sep);
- int time = 0;
- //mouse_event(MOUSEEVENTF_LEFTDOWN,NULL,NULL,NULL,NULL);
- //mouse_event(MOUSEEVENTF_LEFTUP,NULL,NULL,NULL,NULL);
- cout<<"File loaded. Reader is waiting for the toggle key ("<<this->KEY_TOGGLE<<")."<<endl;
- while (!GetAsyncKeyState(KEY_TOGGLE)) continue;
- cout<<"Toggle on. Waiting for click to begin reading."<<endl;
- while (!GetAsyncKeyState(VK_LBUTTON)) continue;
- cout<<"Reading..."<<endl;
- for (int i=0; i<list_cmd.size(); i++)
- {
- //if (GetAsyncKeyState(KEY_TOGGLE)) break;
- if (list_cmd[i][0]==jump)
- {
- time = StringToNumber<int>(list_cmd[i].substr(1,list_cmd[i].length()-1));
- mouse_event(MOUSEEVENTF_LEFTDOWN,NULL,NULL,NULL,NULL);
- Sleep(time);
- mouse_event(MOUSEEVENTF_LEFTUP,NULL,NULL,NULL,NULL);
- }
- else if (list_cmd[i][0]==wait)
- {
- time = StringToNumber<int>(list_cmd[i].substr(1,list_cmd[i].length()-1));
- Sleep(time);
- }
- time = 0;
- }
- cout<<"Reading finished."<<endl;
- }
- wchar_t* GDAuto::GetFileName(const string &prompt)
- {
- const int BUFSIZE = 1024;
- char buffer[BUFSIZE] = {0};
- wchar_t* wBuffer = new wchar_t[BUFSIZE];
- MultiByteToWideChar(CP_ACP, 0, buffer, -1, wBuffer, BUFSIZE);
- wchar_t* wPrompt = new wchar_t[BUFSIZE];
- MultiByteToWideChar(CP_ACP, 0, prompt.c_str(), -1, wPrompt, BUFSIZE);
- OPENFILENAME ofns = {0};
- ofns.lStructSize = sizeof(ofns);
- ofns.lpstrFile = wBuffer;
- ofns.nMaxFile = BUFSIZE;
- ofns.lpstrTitle = wPrompt;
- GetOpenFileName(&ofns);
- return wBuffer;
- }
- #pragma endregion
Add Comment
Please, Sign In to add comment