NTaterY Posted July 13, 2021 Share Posted July 13, 2021 After the recent server wipe, my friend group decided that we would try to continue playing on our own server using the world download. Something that I took notice of was a particularly large QuestProgress.json file... After seeing this, I decided to filter the file to extract the data associated just with me and my friends. To do this, I wrote some jank C++ code available below. We were a group of five players, and after running the code, the file size is much, much smaller! Feel free to use the code if you want to filter your quest data out of the same file. #include <fstream> #include <iostream> #include <string> #include <vector> using namespace std; const vector<string> UUIDs = {""}; // INSERT UUIDs here const int num_players = UUIDs.size(); bool matchesUUID(string uuid) { for (int i = 0; i < num_players; i++) { if(!uuid.compare(UUIDs[i])) return 1; } return 0; } int main() { ifstream input("QuestProgress.json"); ofstream output("QuestProgressNew.json"); string buffer[20]; string line; for (int i = 0; i < 2; i++) { getline(input, line); output << line << endl; } getline(input, line); while(line.find("}") == string::npos) { output << line << endl; getline(input, line); output << line << endl; getline(input, line); output << line; bool hasMatch = 0; if (line.find("}") == string::npos) { int number = 0; getline(input, line); while (line.find('}') == string::npos) { buffer[0] = line; getline(input, line); buffer[1] = line; getline(input, line); string uuid = line.substr(line.rfind(":") + 3, 36); if (matchesUUID(uuid)) { if (hasMatch == 0) output << endl; else output << "," << endl; hasMatch = 1; buffer[0] = buffer[0].substr(0, buffer[0].find("\"")) + "\"" + to_string(number) + buffer[0].substr(buffer[0].find(":"), buffer[0].length() - buffer[0].find(":")); number++; output << buffer[0] << endl << buffer[1] << endl << line << endl; getline(input, line); output << line << endl; getline(input, line); if (line.find(",") == string::npos) output << line; else output << line.substr(0, line.find(",")); } else { getline(input, line); getline(input, line); } getline(input, line); } output << endl; if (hasMatch) { output << line << endl; } else { output << "}," << endl; } } else { output << endl; } getline(input, line); output << line << endl; getline(input, line); bool task = 1; while(task) { output << line << endl; int number = 0; bool flag = 0; hasMatch = 0; getline(input, line); if (line.find('}') == string::npos) { flag = 1; output << line; } while (line.find('}') == string::npos) { string uuid = line.substr(line.rfind(":") + 3, 36); if (matchesUUID(uuid)) { if (hasMatch == 0) output << endl; else output << "," << endl; hasMatch = 1; line = line.substr(0, line.find("\"")) + "\"" + to_string(number) + line.substr(line.find(":"), line.length() - line.find(":")); number++; if (line.find(",") == string::npos) output << line; else output << line.substr(0, line.find(",")); } getline(input, line); } output << endl; if (flag && !hasMatch) { output << "}," << endl; } else { output << line << endl; } hasMatch = 0; getline(input, line); if (line.find('{') != string::npos) { output << line; if (line.find('}') == string::npos) { number = 0; int index = 1; int level = 1; getline(input, line); while (line.find('}') == string::npos) { buffer[0] = line; level = 1; while (level > 0) { getline(input, line); buffer[index] = line; index++; if (line.find('}') != string::npos) level--; if (line.find('{') != string::npos) level++; } string uuid; for (int i = 0; i < index; i++) { if (buffer[i].find("uuid") != string::npos) { uuid = buffer[i]; break; } } if (uuid.find(":") != string::npos) uuid = uuid.substr(uuid.find_last_of(':') + 3, 36); if (matchesUUID(uuid)) { if (hasMatch == 0) output << endl; else output << "," << endl; hasMatch = 1; buffer[0] = buffer[0].substr(0, buffer[0].find("\"")) + "\"" + to_string(number) + buffer[0].substr(buffer[0].find(":"), buffer[0].length() - buffer[0].find(":")); number++; for (int i = 0; i < index - 1; i++) { output << buffer[i] << endl; } line = buffer[index - 1]; if (line.find(",") == string::npos) output << line; else output << line.substr(0, line.find(",")); } getline(input, line); index = 1; } output << endl; if (hasMatch) { output << line << endl; } else { output << "}," << endl; } } else { output << endl; } getline(input, line); output << line << endl; getline(input, line); output << line << endl; } else { output << line << endl; getline(input, line); output << line << endl; } getline(input, line); if (line.find(",") != string::npos) { output << line << endl; getline(input, line); continue; } task = 0; } output << line << endl; for (int i = 0; i < 2; i++) { getline(input, line); output << line << endl; } getline(input, line); } output << line << endl; getline(input, line); output << line; }  Nikkinz and MiniTermi77 2 Quote Link to comment Share on other sites More sharing options...
Nikkinz Posted July 13, 2021 Share Posted July 13, 2021 Awesome! MiniTermi77 1 Quote Link to comment Share on other sites More sharing options...
MiniTermi77 Posted July 13, 2021 Share Posted July 13, 2021 I like that type of players that try to program Java or C++, they make their world more personal ^^ Nikkinz 1 Quote Link to comment Share on other sites More sharing options...
jozy19 Posted January 27, 2022 Share Posted January 27, 2022 Gawd looking at this code reminded me how much I hate C++ lol. pointers suck Quote Link to comment Share on other sites More sharing options...
MiniTermi77 Posted January 27, 2022 Share Posted January 27, 2022 1 hour ago, jozy19 said: Gawd looking at this code reminded me how much I hate C++ lol. pointers suck Is different Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.