1
1
#include < pch.h>
2
2
#include " Settings.h"
3
3
4
- #include < cheat-base/render/gui-util.h>
5
- #include < cheat-base/render/renderer.h>
6
4
#include < cheat-base/cheat/CheatManagerBase.h>
5
+ #include < cheat-base/render/renderer.h>
6
+ #include < cheat-base/render/gui-util.h>
7
+ #include < misc/cpp/imgui_stdlib.h>
8
+ #include < cheat-base/util.h>
9
+
10
+ #include " shlwapi.h"
11
+ #pragma comment(lib, "shlwapi.lib")
7
12
8
- namespace cheat ::feature
13
+ namespace cheat ::feature
9
14
{
10
- Settings::Settings () : Feature(),
15
+ Settings::Settings () : Feature(),
11
16
NF (f_MenuKey, " Show Cheat Menu Key" , " General" , Hotkey(VK_F1)),
12
17
NF(f_HotkeysEnabled, " Hotkeys Enabled" , " General" , true ),
13
18
NF(f_FontSize, " Font size" , " General" , 16 .0f ),
14
19
NF(f_ShowStyleEditor, " Show Style Editor" , " General" , false ),
15
20
16
21
NF(f_StatusMove, " Move Status Window" , " General::StatusWindow" , true ),
17
22
NF(f_StatusShow, " Show Status Window" , " General::StatusWindow" , true ),
18
-
19
- NF(f_InfoMove, " Move Info Window" , " General::InfoWindow" , true ),
20
- NF(f_InfoShow, " Show Info Window" , " General::InfoWindow" , true ),
21
-
23
+
24
+ NF(f_InfoMove, " Move Info Window" , " General::InfoWindow" , true ),
25
+ NF(f_InfoShow, " Show Info Window" , " General::InfoWindow" , true ),
26
+
22
27
NF(f_FpsMove, " Move FPS Indicator" , " General::FPS" , false ),
23
28
NF(f_FpsShow, " Show FPS Indicator" , " General::FPS" , true ),
24
29
25
- NF(f_NotificationsShow, " Show Notifications" , " General::Notify" , true ),
30
+ NF(f_NotificationsShow, " Show Notifications" , " General::Notify" , true ),
26
31
NF(f_NotificationsDelay, " Notifications Delay" , " General::Notify" , 500 ),
27
-
28
- NF(f_FileLogging, " File Logging" , " General::Logging" , false ),
32
+
33
+ NF(f_FileLogging, " File Logging" , " General::Logging" , false ),
29
34
NF(f_ConsoleLogging, " Console Logging" , " General::Logging" , true ),
30
35
31
36
NF(f_FastExitEnable, " Fast Exit" , " General::FastExit" , false ),
32
- NF(f_HotkeyExit, " Hotkeys" , " General::FastExit" , Hotkey(VK_F12))
33
-
34
- {
37
+ NF(f_HotkeyExit, " Hotkeys" , " General::FastExit" , Hotkey(VK_F12)),
38
+ NFS(f_DefaultTheme, " Theme" , " General::Colors" , " Default" ),
39
+ themesDir(util::GetCurrentPath() / "themes")
40
+
41
+ {
35
42
renderer::SetGlobalFontSize (static_cast <float >(f_FontSize));
36
43
f_HotkeyExit.value ().PressedEvent += MY_METHOD_HANDLER (Settings::OnExitKeyPressed);
37
- }
44
+ if (!std::filesystem::exists (themesDir))
45
+ std::filesystem::create_directory (themesDir);
38
46
39
- const FeatureGUIInfo& Settings::GetGUIInfo () const
40
- {
41
- static const FeatureGUIInfo info{ " " , " Settings" , false };
42
- return info;
43
- }
47
+ }
48
+
49
+ bool inited = false ;
50
+ void Settings::Init () {
51
+ if (this ->f_DefaultTheme .value () != " Default" && !inited)
52
+ {
53
+ LOG_INFO (" Loading theme: %s" , themesDir / (f_DefaultTheme.value () + " .json" ).c_str ());
54
+ if (!std::filesystem::exists (themesDir / (f_DefaultTheme.value () + " .json" )))
55
+ f_DefaultTheme = " Default" ;
56
+ else Colors_Import (f_DefaultTheme.value ());
57
+ inited = true ;
58
+ }
59
+ }
60
+
61
+ const FeatureGUIInfo& Settings::GetGUIInfo () const
62
+ {
63
+ static const FeatureGUIInfo info{ " " , " Settings" , false };
64
+ return info;
65
+ }
66
+
67
+ void Settings::Colors_Export (std::string name)
68
+ {
69
+ ImGuiStyle& style = ImGui::GetStyle ();
70
+ auto colors = style.Colors ;
71
+
72
+ nlohmann::json json;
73
+ for (int i = 0 ; i < ImGuiCol_COUNT; i++)
74
+ json[ImGui::GetStyleColorName ((ImGuiCol)i)] = { colors[i].x , colors[i].y , colors[i].z , colors[i].w };
75
+ std::ofstream file (themesDir / (name + " .json" ));
76
+ file << std::setw (4 ) << json << std::endl;
77
+ }
78
+
79
+ void Settings::Colors_Import (std::string name)
80
+ {
81
+ ImGuiStyle& style = ImGui::GetStyle ();
82
+ auto colors = style.Colors ;
83
+ nlohmann::json json;
84
+ std::ifstream file (themesDir / (name + " .json" ));
85
+ file >> json;
86
+ for (int i = 0 ; i < ImGuiCol_COUNT; i++)
87
+ {
88
+ auto color = json[ImGui::GetStyleColorName ((ImGuiCol)i)];
89
+ colors[i].x = color[0 ];
90
+ colors[i].y = color[1 ];
91
+ colors[i].z = color[2 ];
92
+ colors[i].w = color[3 ];
93
+ }
94
+ }
44
95
45
96
void Settings::DrawMain ()
46
97
{
@@ -103,15 +154,15 @@ namespace cheat::feature
103
154
ImGui::BeginGroupPanel (" Show Notifications" );
104
155
{
105
156
ConfigWidget (f_NotificationsShow, " Notifications on the bottom-right corner of the window will be displayed." );
106
- ConfigWidget (f_NotificationsDelay, 1 ,1 , 10000 , " Delay in milliseconds between notifications." );
157
+ ConfigWidget (f_NotificationsDelay, 1 , 1 , 10000 , " Delay in milliseconds between notifications." );
107
158
}
108
159
ImGui::EndGroupPanel ();
109
160
110
161
ImGui::BeginGroupPanel (" Fast Exit" );
111
162
{
112
163
ConfigWidget (" Enabled" ,
113
164
f_FastExitEnable,
114
- " Enable Fast Exit.\n "
165
+ " Enable Fast Exit.\n "
115
166
);
116
167
if (!f_FastExitEnable)
117
168
ImGui::BeginDisabled ();
@@ -123,13 +174,36 @@ namespace cheat::feature
123
174
ImGui::EndDisabled ();
124
175
}
125
176
ImGui::EndGroupPanel ();
177
+
178
+ ImGui::BeginGroupPanel (" Colors" );
179
+ {
180
+ static std::string nameBuffer_;
181
+ ImGui::InputText (" Name" , &nameBuffer_);
182
+ if (std::filesystem::exists (themesDir / (nameBuffer_ + " .json" )))
183
+ {
184
+ if (this ->f_DefaultTheme .value () != nameBuffer_)
185
+ if (ImGui::Button (" Set as default" ))
186
+ f_DefaultTheme = nameBuffer_;
187
+ if (ImGui::Button (" Load" ))
188
+ {
189
+ Colors_Import (nameBuffer_);
190
+ }
191
+ }
192
+ else
193
+ {
194
+ ImGui::Text (" Theme does not exist." );
195
+ }
196
+ if (ImGui::Button (" Save" ))
197
+ Colors_Export (nameBuffer_);
198
+ }
199
+ ImGui::EndGroupPanel ();
126
200
}
127
201
128
- Settings& Settings::GetInstance ()
129
- {
130
- static Settings instance;
131
- return instance;
132
- }
202
+ Settings& Settings::GetInstance ()
203
+ {
204
+ static Settings instance;
205
+ return instance;
206
+ }
133
207
134
208
void Settings::OnExitKeyPressed ()
135
209
{
@@ -139,4 +213,3 @@ namespace cheat::feature
139
213
ExitProcess (0 );
140
214
}
141
215
}
142
-
0 commit comments