Jump to content

Halloween SALE 35% OFF ends in:

Thank you for support!

[Code] C++ Code to Filter BetterQuesting's QuestProgress.json File


NTaterY

Recommended Posts

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...

image.png.36667477d994cbfbec2acd532e8e4803.png

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!

image.png.93b423d1d2d90d730f8a33e38e9f8bb2.png

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;
}

 

Link to comment
Share on other sites

  • 6 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site you agree to the following Terms of Use, Guidelines and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.