Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <exception>
- #include <cstdio>
- #include <windows.h>
- #include <ShellApi.h>
- #include <vector>
- #include <sstream>
- using namespace std;
- bool Decrypt();
- bool Read();
- bool CSVExport();
- bool IsDecryptorHere();
- bool isFileHere(const char* path);
- //Data Structure
- struct trip
- {
- string sourceCity;
- string sourceCompany;
- string destinationCity;
- string destinationCompany;
- string cargo ;
- string gainedXP;
- string income;
- string fines;
- string distance;
- string damage;
- string truck;
- string typeContract;
- };
- //Global variables
- vector<trip> tripList; //List of saved trips
- /*
- Main. Calls more specific functions and checks for correct execution.
- If execution fails, it will try to call again the function, for a maximum of 3 tries.
- */
- int main()
- {
- //Number of tries made to call a function - Counter
- int nRetries = 0;
- //Boolean checking result of function execution - true = success / false = failure
- bool success = false;
- do
- {
- try
- {
- //Counter update
- nRetries++;
- //Calls function that returns either true or false
- success = Decrypt(); //Decrypt will execute SII Decrypt and create a .txt file. It returns true if everything went right or false if something failed.
- if(success == false)
- cout << "Error. Retrying." << endl;
- }
- catch(exception& e) //In case of an exception it will terminate the process
- {
- terminate();
- }
- }
- while(nRetries < 3 && success == false);
- //If it didn't work after 3 times the program will exit - Should never be triggered
- if(success == false)
- {
- cout << "Too many errors. The program will now terminate. Press enter to continue..." << endl;
- getchar();
- return 0;
- }
- //if it worked resets counter and status
- else
- {
- nRetries = 0;
- success = false;
- do
- {
- try
- {
- //Counter update
- nRetries++;
- //Calls function that returns either true or false
- success = Read(); //Read will read the .txt file created in Decrypt function and format all the data.
- if(success == false)
- cout << "Error. Retrying." << endl;
- }
- catch(exception& e) //In case of an exception it will terminate the process - Should never be triggered
- {
- terminate();
- }
- }
- while(nRetries < 3 && success == false);
- //If it didn't work after 3 times the program will exit
- if(success == false)
- {
- cout << "Too many errors. The program will now terminate. Press enter to continue..." << endl;
- getchar();
- return 0;
- }
- //if it worked resets counter and status
- else
- {
- nRetries = 0;
- success = false;
- do
- {
- try
- {
- //Counter update
- nRetries++;
- //Calls function that returns either true or false
- success = CSVExport(); //CSVExport will create a .csv excel file with all the data obtained in Read().
- if(success == false)
- cout << "Error. Retrying." << endl;
- }
- catch(exception& e) //In case of an exception it will terminate the process - Should never be triggered
- {
- terminate();
- }
- }
- while(nRetries < 3 && success == false);
- //If it didn't work after 3 times the program will exit
- if(success == false)
- {
- cout << "Too many errors. The program will now terminate. Press enter to continue..." << endl;
- getchar();
- return 0;
- }
- //Program executed correctly so no point in leaving it open. :P
- else
- {
- cout << "Thanks for using this tool. Press enter to continue..." << endl;
- getchar();
- return 0;
- }
- }
- }
- }
- /*
- Decrypt. Cheks for SII_Decrypt.exe. Asks user for game.sii directory. Checks input and decrypts file to game.txt.
- In case of errors function terminates back to main.
- */
- bool Decrypt()
- {
- string path = "";
- cout << endl << "---- Step 1 of 3: Decrypt save data ----" << endl;
- cout << "Trying to find SII_Decrypt.exe..." << endl;
- //Checks if SII_Decrypt.exe is available
- bool fileFound = IsDecryptorHere();
- if(fileFound == false)
- {
- //If not returns an error end exits Decrypt() function
- cout << "Error: SII_Decrypt.exe not found." << endl << endl;
- return false;
- }
- else
- {
- //Else asks for game.sii path
- cout << "SII_Decrypt.exe found." << endl << endl;
- do
- {
- cout << "Input required. Please write game.sii directory. Refer to readme.txt about how to get it." << endl << "Your input: ";
- getline(cin,path);
- }
- while(path.empty());
- path = path + "\\game.sii";
- cout << endl << "Checking input..." << endl;
- fileFound = isFileHere(path.c_str()); //Checks if game.sii is there
- if(fileFound == false)
- {
- //If not returns an error end exits Decrypt() function
- cout << "Error: game.sii not found." << endl << endl;
- return false;
- }
- else
- {
- cout << "game.sii found." << endl << endl;
- cout << "Decrypting... please wait until the other console closes itself, and then press enter." << endl;
- string variables = "\"" + path + "\" game.txt";
- ShellExecute(NULL, "open", "SII_Decrypt.exe", variables.c_str(), NULL, SW_SHOWDEFAULT);
- getchar();
- fileFound = isFileHere("game.txt"); //Checks if game.txt exists and therefore if the decrypt process worked fine
- if(fileFound == false)
- {
- //If not returns an error end exits Decrypt() function
- cout << "Error: Something went wrong with decryption." << endl << endl;
- return false;
- }
- else
- {
- cout << "File decrypted. Step completed. Press enter to continue." << endl << endl;
- getchar();
- return true;
- }
- }
- }
- }
- /*
- Reads, formats and stores all the data.
- */
- bool Read()
- {
- cout << endl << "---- Step 2 of 3: Read and format data ----" << endl;
- string deliverylog = "";
- ifstream game;
- string temp = "";
- int line1 = 0;
- bool found = false;
- //Open File
- game.open("game.txt");
- while(getline(game, temp))
- {
- line1++;
- //Find ID
- if(temp.find("delivery_log:", 0) != string::npos )
- {
- deliverylog = temp;
- cout << "Delivery Log ID found: " << deliverylog << " - Line " << line1 << "." << endl;
- found = true;
- break;
- }
- }
- game.close();
- if(found == false) //Error while finding id. It's not possible to get this error (I think).
- {
- cout << "Error. Could not find Delivery Log ID. This should't be possible so it's probably a bug. Please retry. If it doesn't work, send me an email." << endl;
- return false;
- }
- else //Formatting ID and saving array
- {
- //Since the found string is like delivery_log: _nameless.24f.4266.54d0 we have to get the string from the second _ so the program cuts the string twice
- size_t position = deliverylog.find("_");
- deliverylog = deliverylog.substr(position+1);
- position = deliverylog.find("_");
- deliverylog = deliverylog.substr(position);
- cout << "Formatted ID is: " << deliverylog << endl;
- found = false; //Check
- string parameter = "delivery_log : " + deliverylog;
- //Now the list of the jobs is needed so we must obtain the array from the file. Since it's variable it will be saved in a string vector
- vector<string> jobsIDS;
- string formatted = "";
- int line2 = 0;
- game.open("game.txt");
- while(getline(game, temp))
- {
- line2++;
- //Find array
- if(temp.find(parameter, 0) != string::npos && line2 > line1)
- {
- cout << "Array Found." << endl;
- getline(game, temp); //version, no need so skip
- getline(game, temp); //entries, more useful
- if(temp == "entries: 0")
- {
- cout << "No trips found." << endl;
- break;
- }
- else
- {
- while(getline(game, temp))
- {
- if(temp.find("entries[", 0) != string::npos)
- {
- position = temp.find("_");
- formatted = temp.substr(position); //String is like entries[0]: _nameless.24f.4150.fa80 so the program cuts the whole thing from _ to the end of the line
- cout << "Found: " << formatted << " - Saving!"<< endl;
- jobsIDS.push_back(formatted); //Save array entry inside vector
- found = true; //Check
- }
- }
- break;
- }
- }
- }
- game.close();
- if(found == false)
- {
- return false;
- }
- bool done = false; //Checks if a job's data is saved
- //After obtaining job ids we have to record their data. as always, it's variable so vector it is!
- game.open("game.txt");
- string sourceCity, sourceCompany, destinationCity, destinationCompany, cargo, XP, income, km, damage, fines, truck, type;
- while(getline(game, temp) && jobsIDS.size() > 0)
- {
- if(temp.find("delivery_log_entry : " + jobsIDS.at(0), 0) != string::npos)
- {
- //After finding the log entry just select things that are needed
- getline(game, temp); // params: 23, useless, so skip
- while(getline(game, temp))
- {
- if(temp.find("params[1]", 0) != string::npos) //Source data
- {
- position = temp.find("\"");
- formatted = temp.substr(position+1); //String is like params[1]: "company.volatile.exomar.roma" so the program cuts from p to " inculded
- //Remove company
- position = formatted.find(".");
- formatted = formatted.substr(position+1);
- position = formatted.find("\"");
- formatted = formatted.substr(0,position); //Remove final "
- //remove second entry
- position = formatted.find(".");
- formatted = formatted.substr(position+1);
- sourceCompany = formatted; //Save company
- //remove third entry
- position = formatted.find(".");
- formatted = formatted.substr(position+1);
- //Uppercase first letter
- formatted[0] = toupper(formatted[0]);
- sourceCity = formatted; //Save city
- cout << "Src. comp.: " << sourceCompany << " - Src. city: " << sourceCity << endl;
- }
- if(temp.find("params[2]", 0) != string::npos) //Destination data
- {
- position = temp.find("\"");
- formatted = temp.substr(position+1); //String is like params[1]: "company.volatile.exomar.roma" so the program cuts the whole thing from p to "
- //Remove company
- position = formatted.find(".");
- formatted = formatted.substr(position+1);
- position = formatted.find("\"");
- formatted = formatted.substr(0,position); //Remove final "
- //remove second entry
- position = formatted.find(".");
- formatted = formatted.substr(position+1);
- destinationCompany = formatted; //Save company
- //remove third entry
- position = formatted.find(".");
- formatted = formatted.substr(position+1);
- //Uppercase first letter
- formatted[0] = toupper(formatted[0]);
- destinationCity = formatted; //Save city
- cout << "Dest. comp.: " << destinationCompany << " - Dest. city: " << destinationCity << endl;
- }
- if(temp.find("params[3]", 0) != string::npos) //Cargo
- {
- position = temp.find("\"");
- formatted = temp.substr(position+1);
- //Remove cargo
- position = formatted.find(".");
- formatted = formatted.substr(position+1);
- position = formatted.find("\"");
- formatted = formatted.substr(0,position); //Remove final "
- cargo = formatted;
- cout << "Cargo: " << cargo << endl;
- }
- if(temp.find("params[4]", 0) != string::npos) //XP
- {
- position = temp.find(": ");
- formatted = temp.substr(position+1);
- XP = formatted;
- cout << "XP: " << XP << endl;
- }
- if(temp.find("params[5]", 0) != string::npos) //Income
- {
- position = temp.find(": ");
- formatted = temp.substr(position+1);
- income = formatted;
- cout << "Income: " << income << endl;
- }
- if(temp.find("params[6]", 0) != string::npos) //Distance
- {
- position = temp.find(": ");
- formatted = temp.substr(position+1);
- km = formatted;
- cout << "Distance: " << km << endl;
- }
- if(temp.find("params[7]", 0) != string::npos) //Cargo damage
- {
- position = temp.find("\"");
- formatted = temp.substr(position+1);
- position = formatted.find("\"");
- formatted = formatted.substr(0,position); //Remove final "
- //Damage formatting
- float temp1 = stof(formatted); //converts string to float 0.061
- temp1 = temp1 * 100; //6.1
- ostringstream convert;
- convert << temp1;
- formatted = convert.str(); //Puts back into string
- damage = formatted + "%"; //Final formatting
- cout << "Cargo damage: " << damage << endl;
- }
- if(temp.find("params[14]", 0) != string::npos) //Fines
- {
- position = temp.find(": ");
- formatted = temp.substr(position+1);
- fines = formatted;
- cout << "Total fines: " << fines << endl;
- }
- if(temp.find("params[16]", 0) != string::npos) //Truck
- {
- position = temp.find("\"");
- formatted = temp.substr(position+1, temp.length()-1); //String is like params[1]: "vehicle.iveco.strails" so the program cuts the whole thing from v to s
- //Remove vehicle
- position = formatted.find(".");
- formatted = formatted.substr(position+1);
- position = formatted.find("\"");
- formatted = formatted.substr(0,position); //Remove final "
- truck = formatted;
- cout << "truck: " << truck << endl;
- }
- if(temp.find("params[18]", 0) != string::npos) //Cargo Type
- {
- position = temp.find(": ");
- formatted = temp.substr(position+1);
- if(formatted == " quick")
- {
- formatted = "Quick Job";
- }
- if(formatted == " compn")
- {
- formatted = "Freight Market";
- }
- if(formatted == " on_compn")
- {
- formatted = "External Contract (World of Trucks)";
- }
- if(formatted == " freerm")
- {
- formatted = "Free Roam";
- sourceCompany = "Free Roam";
- sourceCity = "Free Roam";
- destinationCity = "Free Roam";
- destinationCompany = "Free Roam";
- damage = "0%"; //Bugged better set it to 0%
- truck = "Free Roam";
- }
- type = formatted;
- cout << "Cargo Type: " << type << endl;
- //Other ways crashed so yay
- trip temporary = (trip)
- {
- sourceCity, sourceCompany, destinationCity, destinationCompany, cargo, XP, income, fines, km, damage, truck, type
- };
- tripList.push_back(temporary);
- done = true;
- }
- if(done == true) //Checks if it's done with a job
- {
- break;
- }
- }
- jobsIDS.erase(jobsIDS.begin());
- done = false;
- }
- }
- game.close();
- }
- return true;
- }
- /*
- The data is written in a .csv file
- */
- bool CSVExport()
- {
- cout << endl << "---- Step 3 of 3: Export data to CSV ----" << endl;
- ofstream csv;
- csv.open("Trips.csv");
- cout << "Writing data..." << endl;
- csv << "Source City; Source Company; Destination City; Destination Company; Cargo; Cargo Damage; Gained XP; Income; Fines; Distance; Truck; Cargo Type;\n";
- csv << "\n";
- while(tripList.size() > 0)
- {
- csv << tripList.at(0).sourceCity << ";" << tripList.at(0).sourceCompany << ";" << tripList.at(0).destinationCity << ";" << tripList.at(0).destinationCompany << ";" << tripList.at(0).cargo << ";" << tripList.at(0).damage << ";" << tripList.at(0).gainedXP << ";" << tripList.at(0).income << ";" << tripList.at(0).fines << ";" << tripList.at(0).distance << ";" << tripList.at(0).truck << ";" << tripList.at(0).typeContract << ";\n";
- tripList.erase(tripList.begin());
- }
- cout << "Done." << endl;
- csv.close();
- return true;
- }
- /*
- Checks if SII_Decrypt.exe is in this program's folder
- */
- bool IsDecryptorHere()
- {
- ifstream decryptor("SII_Decrypt.exe");
- return decryptor.good();
- }
- /*
- Checks if file exists
- */
- bool isFileHere(const char* path)
- {
- ifstream file(path);
- return file.good();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement