Dota2Patcher
 
Загрузка...
Поиск...
Не найдено
Config.h
См. документацию.
1#pragma once
2#include <iostream>
3#include <fstream>
4#include <shlobj.h>
5#include <nlohmann/json.hpp>
6
8public:
9 static inline std::unordered_map<string, int> config_entries = {
10 { "camera_distance", 1200 },
11 { "fog_enabled", 0 },
12 { "fow_client_nofiltering", 0 },
13 { "set_rendering_enabled", 0 },
14 { "allow_rc_update", 0 },
15 { "visible_by_enemy", 0 },
16 { "illusions_detection", 0 },
17 { "cl_weather", 0 },
18 { "river_vial", 0},
19 };
20
21 static void ask_for_settings() {
22 config_entries["camera_distance"] = ask_for_int("[~] Enter camera distance [default is 1200]: ", 1200, 1500);
23 config_entries["fog_enabled"] = ask_for_bool("[~] Disable fog? [y/n or 1/0]: ");
24 config_entries["fow_client_nofiltering"] = ask_for_bool("[~] Remove FoG anti-aliasing? (fow_client_nofiltering) [y/n or 1/0]: ");
25 config_entries["set_rendering_enabled"] = ask_for_bool("[~] Show hidden particles? [y/n or 1/0]: ");
26 config_entries["allow_rc_update"] = ask_for_bool("[~] Check for BETA update? [y/n or 1/0]: ");
27 cout << "[HACKS]\n";
28 config_entries["visible_by_enemy"] = ask_for_bool("[~] Visible By Enemy [y/n or 1/0]: ");
29 config_entries["illusions_detection"] = ask_for_bool("[~] Illusions Detection [y/n or 1/0]: ");
30 // Weather
31 cout <<
32 "[WEATHER]\n"
33 "Default: 1\n"
34 "Snow: 2\n"
35 "Rain: 3\n"
36 "Moonbeam: 4\n"
37 "Pestilence: 5\n"
38 "Harvest: 6\n"
39 "Sirocco: 7\n"
40 "Spring: 8\n"
41 "Ash: 9\n"
42 "Aurora: 10\n";
43
44 std::cin.ignore(10, '\n');
45 config_entries["cl_weather"] = ask_for_int("[~] Enter Weather number: ", 1, 10) - 1;
46
47
48 // River Vial
49 cout <<
50 "[RIVER TYPE]\n"
51 "Default: 1\n"
52 "Oil: 2\n"
53 "Dry: 3\n"
54 "Slime: 4\n"
55 "Chrome: 5\n"
56 "Electric: 6\n"
57 "Potion: 7\n"
58 "Blood: 8\n";
59
60 //std::cin.ignore(10, '\n');
61 config_entries["river_vial"] = ask_for_int("[~] Enter River type: ", 1, 8) - 1;
62
64 }
65
66 static void show_settings() {
67 cout
68 << "[~] Current settings:\n"
69 << "[~] Camera distance: " << config_entries["camera_distance"] << "\n"
70 << "[~] Fog disabled: " << std::boolalpha << (bool)config_entries["fog_enabled"] << "\n"
71 << "[~] Remove FoG anti-aliasing: " << std::boolalpha << (bool)config_entries["fow_client_nofiltering"] << "\n"
72 << "[~] Show hidden particles: " << std::boolalpha << (bool)config_entries["set_rendering_enabled"] << "\n"
73 << "[~] Check for BETA update: " << std::boolalpha << (bool)config_entries["allow_rc_update"] << "\n"
74 << "[HACKS]\n"
75 << "[~] Visible By Enemy: " << std::boolalpha << (bool)config_entries["visible_by_enemy"] << "\n"
76 << "[~] Illusions Detection: " << std::boolalpha << (bool)config_entries["illusions_detection"] << "\n"
77 << "[~] Weather: " << int_to_weather((DOTA_WEATHER)config_entries["cl_weather"]) << "\n"
78 << "[~] River type: " << int_to_river((DOTA_RIVER)config_entries["river_vial"]) << "\n"
79 ;
80 }
81
82 static void load_settings() {
83 if (auto path = app_data_path())
84 config_patch = *path + "\\Dota2Patcher.json";
85 else {
86 LOG::CRITICAL("Failed to get AppData path");
87 return;
88 }
89
90 std::ifstream file(config_patch);
91 if (!file.is_open()) {
92 LOG::ERR("Config file not found! Creating a new one.");
94 return;
95 }
96
97 try {
98 file >> config_file;
99
100 for (auto& [key, value] : config_entries) {
101 if (config_file.contains(key))
102 config_entries[key] = config_file[key].get<int>();
103 else {
104 LOG::ERR("Config missing key '{}'. Requesting user input.", key);
106 }
107 }
108 }
109 catch (const std::exception& e) {
110 LOG::ERR("Error parsing config file: {}", e.what());
112 }
113 }
114
115 static void save_settings() {
116 config_file = nlohmann::json::object();
117
118 for (const auto& [key, value] : config_entries) {
119 config_file[key] = value;
120 }
121
122 std::ofstream out_file(config_patch);
123 if (!out_file) {
124 LOG::ERR("Failed to open config file for writing: {}", config_patch);
125 return;
126 }
127
128 out_file << config_file.dump(4);
129 out_file.close();
130 }
131
132private:
133 static inline nlohmann::json config_file;
134 static inline string config_patch;
135
136 static string int_to_weather(DOTA_WEATHER weather) {
137 switch (weather) {
138 case DOTA_WEATHER::WEATHER_DEFAULT: return "Default";
139 case DOTA_WEATHER::WEATHER_SNOW: return "Snow";
140 case DOTA_WEATHER::WEATHER_RAIN: return "Rain";
141 case DOTA_WEATHER::WEATHER_MOONBEAM: return "Moonbeam";
142 case DOTA_WEATHER::WEATHER_PESTILENCE: return "Pestilence";
143 case DOTA_WEATHER::WEATHER_HARVEST: return "Harvest";
144 case DOTA_WEATHER::WEATHER_SIROCCO: return "Sirocco";
145 case DOTA_WEATHER::WEATHER_SPRING: return "Spring";
146 case DOTA_WEATHER::WEATHER_ASH: return "Ash";
147 case DOTA_WEATHER::WEATHER_AURORA: return "Aurora";
148 default: return "Default";
149 }
150 }
151
152 static string int_to_river(DOTA_RIVER river) {
153 switch (river) {
154 case DOTA_RIVER::RIVER_DEFAULT: return "Default";
155 case DOTA_RIVER::RIVER_OIL: return "Oil";
156 case DOTA_RIVER::RIVER_DRY: return "Dry";
157 case DOTA_RIVER::RIVER_SLIME: return "Slime";
158 case DOTA_RIVER::RIVER_CHROME: return "Chrome";
159 case DOTA_RIVER::RIVER_ELECTRIC: return "Electric";
160 case DOTA_RIVER::RIVER_POTION: return "Potion";
161 case DOTA_RIVER::RIVER_BLOOD: return "Blood";
162 default: return "Default";
163 }
164 }
165
166 static optional <string> app_data_path() {
167 PWSTR path = nullptr;
168 if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &path))) {
169 char charPath[MAX_PATH];
170 wcstombs(charPath, path, MAX_PATH);
171 CoTaskMemFree(path);
172 return string(charPath);
173 }
174
175 return nullopt;
176 }
177
178 static int ask_for_int(const string& prompt, const optional<int> min_value = nullopt, const optional<int> max_value = nullopt) {
179 int value;
180 while (true) {
181 cout << prompt;
182 string input;
183 std::getline(std::cin, input);
184
185 try {
186 value = std::stoi(input);
187
188 if (!min_value.has_value() || !max_value.has_value())
189 break;
190
191 if (value < min_value.value() || value > max_value.value()) {
192 LOG::ERR("Input must be between {} and {}", std::to_string(min_value.value()), std::to_string(max_value.value()));
193 continue;
194 }
195
196 break;
197 }
198 catch (...) {
199 LOG::ERR("Invalid input!\n");
200 }
201 }
202 return value;
203 }
204
205 static bool ask_for_bool(const string& prompt) {
206 bool value;
207 while (true) {
208 cout << prompt;
209 string input;
210 std::cin >> input;
211
212 if (input == "y" || input == "1") {
213 value = true;
214 break;
215 }
216 else if (input == "n" || input == "0") {
217 value = false;
218 break;
219 }
220 else {
221 LOG::ERR("Invalid input!\n");
222 }
223 }
224 return value;
225 }
226};
DOTA_WEATHER
Definition Enums.h:41
DOTA_RIVER
Definition Enums.h:54
Definition Config.h:7
static void ask_for_settings()
Definition Config.h:21
static void show_settings()
Definition Config.h:66
static std::unordered_map< string, int > config_entries
Definition Config.h:9
static void save_settings()
Definition Config.h:115
static void load_settings()
Definition Config.h:82