@@ -51,52 +51,17 @@ void Utils::Install()
5151
5252void Utils::LoadConfig (Config& config)
5353{
54- string input;
5554 ifstream file (" Settings.cfg" );
5655
5756 if (!file.is_open ())
5857 {
59- do
60- {
61- cout << " Enter bhop boolean value (1/0) -> " ;
62- getline (cin, input);
63- istringstream iss (input);
64- if (!(iss >> config.bhop ) || (config.bhop != 0 && config.bhop != 1 ))
65- {
66- config.bhop = -1 ;
67- cout << " Invalid input! Please enter 1 or 0." << endl << endl;
68- }
69- }
70- while (config.bhop != 0 && config.bhop != 1 );
71-
72- do
73- {
74- cout << " Enter rapid-fire boolean value (1/0) -> " ;
75- getline (cin, input);
76- istringstream iss (input);
77- if (!(iss >> config.rapidFire ) || (config.rapidFire != 0 && config.rapidFire != 1 ))
78- {
79- config.rapidFire = -1 ;
80- cout << " Invalid input! Please enter 1 or 0." << endl << endl;
81- }
82- }
83- while (config.rapidFire != 0 && config.rapidFire != 1 );
84-
85- do
86- {
87- cout << " Enter sensitivity integer value (1-8) -> " ;
88- getline (cin, input);
89- istringstream iss (input);
90- if (!(iss >> config.sensitivity ) || config.sensitivity < 1 || config.sensitivity > 8 )
91- {
92- config.sensitivity = -1 ;
93- cout << " Invalid input! Please enter an integer between 1 and 8." << endl << endl;
94- }
95- }
96- while (config.sensitivity < 1 || config.sensitivity > 8 );
58+ config.bhop = GetValidatedIntInput (" Enter bhop boolean value (1/0) -> " , 0 , 1 );
59+ config.rapidFire = GetValidatedIntInput (" Enter rapid-fire boolean value (1/0) -> " , 0 , 1 );
60+ config.sensitivity = GetValidatedIntInput (" Enter sensitivity integer value (1-8) -> " , 1 , 8 );
61+ config.confirmationKey = GetValidatedKeyInput (" Enter recoil control confirmation key (0/VK_CODE) -> " );
9762
9863 ofstream out (" Settings.cfg" );
99- out << config.bhop << endl << config.rapidFire << endl << config.sensitivity ;
64+ out << config.bhop << endl << config.rapidFire << endl << config.sensitivity << endl << hex << config. confirmationKey ;
10065 out.close ();
10166
10267 cout << " Configuration successfully saved!" << endl;
@@ -106,6 +71,7 @@ void Utils::LoadConfig(Config& config)
10671 file >> config.bhop ;
10772 file >> config.rapidFire ;
10873 file >> config.sensitivity ;
74+ file >> hex >> config.confirmationKey ;
10975 file.close ();
11076
11177 if (!ValidateConfig (config))
@@ -119,9 +85,64 @@ void Utils::LoadConfig(Config& config)
11985 }
12086}
12187
88+ int Utils::GetValidatedIntInput (const string& prompt, int min, int max)
89+ {
90+ string input;
91+ int value = -1 ;
92+
93+ do
94+ {
95+ cout << prompt;
96+ getline (cin, input);
97+ istringstream iss (input);
98+
99+ if (!(iss >> value) || value < min || value > max)
100+ {
101+ value = -1 ;
102+
103+ if (min == 0 && max == 1 )
104+ {
105+ cout << " Invalid input! Please enter 0 or 1." << endl << endl;
106+ }
107+ else
108+ {
109+ cout << " Invalid input! Please enter an integer between " << min << " and " << max << " ." << endl << endl;
110+ }
111+ }
112+ } while (value == -1 );
113+
114+ return value;
115+ }
116+
117+ int Utils::GetValidatedKeyInput (const string& prompt)
118+ {
119+ string input;
120+ int value = -1 ;
121+
122+ do
123+ {
124+ cout << prompt;
125+ getline (cin, input);
126+ istringstream iss (input);
127+
128+ if (!(iss >> hex >> value) || (value != 0 && (value < 0x01 || value > 0xFE )))
129+ {
130+ value = -1 ;
131+ cout << " Invalid input! Please enter 0 or VK_CODE." << endl << endl;
132+ }
133+ } while (value == -1 );
134+
135+ return value;
136+ }
137+
122138bool Utils::ValidateConfig (Config& config)
123139{
124- return ((config.bhop == 0 || config.bhop == 1 ) && (config.rapidFire == 0 || config.rapidFire == 1 ) && (config.sensitivity >= 1 && config.sensitivity <= 8 )) ? true : false ;
140+ bool validBhop = (config.bhop == 0 || config.bhop == 1 );
141+ bool validRapidFire = (config.rapidFire == 0 || config.rapidFire == 1 );
142+ bool validSensitivity = (config.sensitivity >= 1 && config.sensitivity <= 8 );
143+ bool validConfirmationKey = (config.confirmationKey == 0 || (config.confirmationKey >= 0x01 && config.confirmationKey <= 0xFE ));
144+
145+ return validBhop && validRapidFire && validSensitivity && validConfirmationKey;
125146}
126147
127148void Utils::PrintAscii (const string& asciiArt)
0 commit comments