summaryrefslogtreecommitdiff
path: root/mm/2s2h/Rando/ExcludedChecks.cpp
blob: c359a9f1f1402710e795c9b7c893ee67f212be1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "Rando.h"
#include "2s2h/Rando/StaticData/StaticData.h"
#include <libultraship/libultraship.h>
#include <libultraship/bridge/consolevariablebridge.h>

namespace Rando {

std::vector<RandoCheckId> GetExcludedChecksFromConfig() {
    auto allConfig = Ship::Context::GetRawInstance()->GetConfig()->GetNestedJson();
    std::vector<RandoCheckId> excludedChecks;

    if (allConfig.find("CVars") != allConfig.end() && allConfig["CVars"].is_object() &&
        allConfig["CVars"].find("gRando") != allConfig["CVars"].end() && allConfig["CVars"]["gRando"].is_object() &&
        allConfig["CVars"]["gRando"].find("ExcludedChecks") != allConfig["CVars"]["gRando"].end()) {

        if (allConfig["CVars"]["gRando"]["ExcludedChecks"].is_array()) {
            auto excludedChecksStrings = allConfig["CVars"]["gRando"]["ExcludedChecks"].get<std::vector<std::string>>();
            for (auto& checkName : excludedChecksStrings) {
                auto randoCheckId = Rando::StaticData::GetCheckIdFromName(checkName.c_str());
                if (randoCheckId > RC_UNKNOWN && randoCheckId < RC_MAX) {
                    excludedChecks.push_back(randoCheckId);
                }
            }
        } else if (allConfig["CVars"]["gRando"]["ExcludedChecks"].is_string()) {
            CVarClear("gRando.ExcludedChecks");
            Ship::Context::GetRawInstance()->GetWindow()->GetGui()->SaveConsoleVariablesNextFrame();
        }
    }

    std::sort(excludedChecks.begin(), excludedChecks.end());
    return excludedChecks;
}

void SetExcludedChecksInConfig(std::vector<RandoCheckId>& excludedChecks) {
    auto excludedChecksJson = nlohmann::json::array();

    for (auto& randoCheckId : excludedChecks) {
        if (randoCheckId > RC_UNKNOWN && randoCheckId < RC_MAX) {
            excludedChecksJson.push_back(Rando::StaticData::Checks[randoCheckId].name);
        }
    }

    Ship::Context::GetRawInstance()->GetConfig()->SetBlock("CVars.gRando.ExcludedChecks", excludedChecksJson);
    Ship::Context::GetRawInstance()->GetConfig()->Save();
}

} // namespace Rando