Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
axstin
GitHub Repository: axstin/rbxfpsunlocker
Path: blob/master/Source/fflags.hpp
259 views
1
#pragma once
2
3
#include <filesystem>
4
#include <fstream>
5
#include <sstream>
6
#include "nlohmann.hpp"
7
8
using target_fps_t = std::optional<nlohmann::json::number_integer_t>;
9
using alt_enter_t = std::optional<bool>;
10
11
struct RobloxFFlags
12
{
13
const std::filesystem::path settings_file_path;
14
nlohmann::json object;
15
bool target_fps_mod = false;
16
bool alt_enter_mod = false;
17
18
RobloxFFlags(const std::filesystem::path &version_folder) : settings_file_path(version_folder / "ClientSettings" / "ClientAppSettings.json")
19
{
20
read_disk();
21
}
22
23
void read_disk()
24
{
25
object = {};
26
std::ifstream file(settings_file_path);
27
28
if (file.is_open())
29
{
30
nlohmann::json result = nlohmann::json::parse(file, nullptr, false);
31
if (!result.is_discarded())
32
{
33
object = std::move(result);
34
}
35
}
36
}
37
38
bool write_disk()
39
{
40
std::error_code ec{};
41
std::filesystem::create_directory(settings_file_path.parent_path(), ec);
42
43
std::ofstream file(settings_file_path);
44
if (!file.is_open()) return false;
45
46
file << object.dump(4);
47
return true;
48
}
49
50
template <typename T>
51
std::optional<T> read_json_opt(const char *key) const
52
{
53
if (object.contains(key))
54
{
55
if (auto ptr = object[key].template get_ptr<const T*>())
56
{
57
return *ptr;
58
}
59
}
60
61
return {};
62
}
63
64
template <typename T>
65
bool update_flag(const char *key, std::optional<T> new_value)
66
{
67
auto flag = read_json_opt<T>(key);
68
if (flag != new_value)
69
{
70
if (new_value) object[key] = *new_value;
71
else object.erase(key);
72
return true;
73
}
74
return false;
75
}
76
77
target_fps_t target_fps() const
78
{
79
return read_json_opt<nlohmann::json::number_integer_t>("DFIntTaskSchedulerTargetFps");
80
}
81
82
RobloxFFlags &set_target_fps(target_fps_t cap_opt)
83
{
84
if (cap_opt) *cap_opt = *cap_opt == 0 ? 5588562 : *cap_opt;
85
if (update_flag("DFIntTaskSchedulerTargetFps", cap_opt)) target_fps_mod = true;
86
return *this;
87
}
88
89
alt_enter_t alt_enter() const
90
{
91
return read_json_opt<bool>("FFlagHandleAltEnterFullscreenManually");
92
}
93
94
RobloxFFlags &set_alt_enter_flag(alt_enter_t alt_enter_opt)
95
{
96
if (update_flag("FFlagHandleAltEnterFullscreenManually", alt_enter_opt)) alt_enter_mod = true;
97
return *this;
98
}
99
100
bool apply(bool prompt);
101
};
102