Repository navigation
Expand file tree
/
Copy pathconfig.cpp
More file actions
127 lines (97 loc) · 4.52 KB
/
Copy pathconfig.cpp
File metadata and controls
127 lines (97 loc) · 4.52 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "globals.h"
static int ClampVibrance(int value) {
if (value < 0) return 0;
if (value > 100) return 100;
return value;
}
void RefreshColorSettingsFromUI() {
char val[32];
GetWindowTextA(hEditGVibrance, val, 32);
gameVibrance = ClampVibrance(atoi(val));
sprintf(val, "%d", gameVibrance);
SetWindowTextA(hEditGVibrance, val);
GetWindowTextA(hEditNVibrance, val, 32);
normalVibrance = ClampVibrance(atoi(val));
sprintf(val, "%d", normalVibrance);
SetWindowTextA(hEditNVibrance, val);
}
// ---- Persist current UI state to config.ini ----
void SaveConfig() {
char buf[64];
int monIdx = SendMessage(hComboMon, CB_GETCURSEL, 0, 0);
sprintf(buf, "%d", monIdx);
WritePrivateProfileStringA("Settings", "Monitor", buf, configFile);
int res1Idx = SendMessage(hComboResGame, CB_GETCURSEL, 0, 0);
SendMessage(hComboResGame, CB_GETLBTEXT, res1Idx, (LPARAM)buf);
WritePrivateProfileStringA("Settings", "Resolution1", buf, configFile);
strncpy(g_savedRes1, buf, sizeof(g_savedRes1) - 1);
int res2Idx = SendMessage(hComboResNormal, CB_GETCURSEL, 0, 0);
SendMessage(hComboResNormal, CB_GETLBTEXT, res2Idx, (LPARAM)buf);
WritePrivateProfileStringA("Settings", "Resolution2", buf, configFile);
strncpy(g_savedRes2, buf, sizeof(g_savedRes2) - 1);
sprintf(buf, "%d", gameHotkey);
WritePrivateProfileStringA("Settings", "Hotkey1", buf, configFile);
sprintf(buf, "%d", normalHotkey);
WritePrivateProfileStringA("Settings", "Hotkey2", buf, configFile);
sprintf(buf, "%d", colorHotkey1);
WritePrivateProfileStringA("Settings", "ColorHotkey1", buf, configFile);
sprintf(buf, "%d", colorHotkey2);
WritePrivateProfileStringA("Settings", "ColorHotkey2", buf, configFile);
// Read colors from Edit controls
RefreshColorSettingsFromUI();
sprintf(buf, "%d", gameVibrance);
WritePrivateProfileStringA("Color2", "Vibrance", buf, configFile);
sprintf(buf, "%d", normalVibrance);
WritePrivateProfileStringA("Color1", "Vibrance", buf, configFile);
DebugLog("Config saved to %s", configFile);
}
// ---- Helper: restore a saved resolution string into a combo box ----
static void RestoreComboSelection(HWND hCombo, const char* saved) {
if (!saved || !saved[0]) return;
int count = SendMessage(hCombo, CB_GETCOUNT, 0, 0);
for (int i = 0; i < count; i++) {
char item[64];
SendMessage(hCombo, CB_GETLBTEXT, i, (LPARAM)item);
if (strcmp(item, saved) == 0) {
SendMessage(hCombo, CB_SETCURSEL, i, 0);
return;
}
}
}
// ---- Load config.ini and apply to UI controls ----
void LoadConfig() {
char buf[64];
DebugLog("Loading config from %s", configFile);
// Monitor
GetPrivateProfileStringA("Settings", "Monitor", "0", buf, sizeof(buf), configFile);
int monIdx = atoi(buf);
if (monIdx >= 0 && monIdx < SendMessage(hComboMon, CB_GETCOUNT, 0, 0))
SendMessage(hComboMon, CB_SETCURSEL, monIdx, 0);
// Resolution presets
GetPrivateProfileStringA("Settings", "Resolution1", "", buf, sizeof(buf), configFile);
strncpy(g_savedRes1, buf, sizeof(g_savedRes1) - 1);
RestoreComboSelection(hComboResGame, buf);
GetPrivateProfileStringA("Settings", "Resolution2", "", buf, sizeof(buf), configFile);
strncpy(g_savedRes2, buf, sizeof(g_savedRes2) - 1);
RestoreComboSelection(hComboResNormal, buf);
// Hotkeys
GetPrivateProfileStringA("Settings", "Hotkey1", "118", buf, sizeof(buf), configFile);
gameHotkey = atoi(buf);
SendMessage(hHotkeyGame, HKM_SETHOTKEY, MAKEWORD(gameHotkey, 0), 0);
GetPrivateProfileStringA("Settings", "Hotkey2", "119", buf, sizeof(buf), configFile);
normalHotkey = atoi(buf);
SendMessage(hHotkeyNormal, HKM_SETHOTKEY, MAKEWORD(normalHotkey, 0), 0);
GetPrivateProfileStringA("Settings", "ColorHotkey1", "122", buf, sizeof(buf), configFile);
colorHotkey1 = atoi(buf);
SendMessage(hHotkeyColor1, HKM_SETHOTKEY, MAKEWORD(colorHotkey1, 0), 0);
GetPrivateProfileStringA("Settings", "ColorHotkey2", "123", buf, sizeof(buf), configFile);
colorHotkey2 = atoi(buf);
SendMessage(hHotkeyColor2, HKM_SETHOTKEY, MAKEWORD(colorHotkey2, 0), 0);
// Color controls
char val[32];
GetPrivateProfileStringA("Color2", "Vibrance", "50", val, 32, configFile);
SetWindowTextA(hEditGVibrance, val); gameVibrance = atoi(val);
GetPrivateProfileStringA("Color1", "Vibrance", "50", val, 32, configFile);
SetWindowTextA(hEditNVibrance, val); normalVibrance = atoi(val);
DebugLog("Config loaded");
}