-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
432 lines (353 loc) · 13.9 KB
/
Copy pathmain.cpp
File metadata and controls
432 lines (353 loc) · 13.9 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string>
#ifdef _WIN32
#include <direct.h>
#include <winsock2.h>
#include <windows.h>
#include <shlobj.h>
#endif /* _WIN32 */
#include <fstream>
#include <filesystem>
#include <json.hpp>
using namespace std;
using json = nlohmann::json;
#include "fastdl.h"
#include "commands.h"
#include "config.h"
#include "globs.h"
int forcedProfile = 0;
bool shouldExit = false;
bool shouldRestart = true;
bool shouldSwitchProfiles = false;
string gamePath;
bool verbose = false;
int defaultProfile = 1;
bool useProfileSelector = true;
bool quitFunc = false;
const char* defaultIp = "169.150.249.133";
const char* defaultFastDL = "https://wavespray.dathost.net/fastdl/teamfortress2/679d9656b8573d37aa848d60/";
const uint16_t defaultMainPortInt = 22912;
const uint16_t defaultSourceTVInt = 22913;
const int verMajor = 1;
const int verMinor = 2;
//char* appDataPath;
const char* configFile = "prefs.json";
const char* profFile = "profiles.json";
void clrScr()
{
#ifdef _WIN32
system( "cls" );
#else
system( "clear" );
#endif /* _WIN32 */
}
bool parse( const char* cmd, const char* args )
{
if ( strcmp( cmd, "cls" ) == 0 )
clrScr();
else if ( strcmp( cmd, "help" ) == 0 )
CgeInterface::help();
else if ( strcmp( cmd, "credits" ) == 0 )
CgeInterface::credits();
else if ( strcmp( cmd, "exit" ) == 0 || strcmp( cmd, "quit" ) == 0 )
shouldExit = true;
else if ( strcmp( cmd, "reset" ) == 0 || strcmp( cmd, "restart" ) == 0 )
shouldRestart = true;
else if ( strcmp( cmd, "info" ) == 0 )
CgeInterface::info();
else if ( strcmp( cmd, "fastdl" ) == 0 )
{
if ( CurrentProfile::fastDL == "" )
{
cerr << "The current profile has no fastdl set, so you cannot use this command." << endl;
return true;
}
FastDL::fastdl( args, false, false );
}
else if ( strcmp( cmd, "current-map" ) == 0 || strcmp( cmd, "map" ) == 0 )
{
if ( CurrentProfile::fastDL == "" )
{
cerr << "The current profile has no fastdl set, so you cannot use this command." << endl;
return true;
}
CgeInterface::pullCurrentMap();
}
else if ( strcmp( cmd, "view" ) == 0 )
{
if ( CurrentProfile::name != "cge7-193" )
{
cerr << "This command is only supported when using the \"cge7-193\" profile." << endl;
return true;
}
if ( CurrentProfile::fastDL == "" )
{
cerr << "The current profile has no fastdl set, so you cannot use this command." << endl;
return true;
}
if ( strcmp( args, "full" ) == 0 )
FastDL::fastdl_macro_view();
else if ( strcmp( args, "" ) == 0 || strcmp( args, " " ) == 0 || strcmp( args, "min" ) == 0 )
FastDL::fastdl_macro_view_min();
else
cerr << "fastdl -> macro (view) -> Invalid Syntax!" << endl;
}
else if ( strcmp( cmd, "scrape" ) == 0 )
{
if ( CurrentProfile::name != "cge7-193" )
{
cerr << "This command is only supported when using the \"cge7-193\" profile." << endl;
return true;
}
if ( CurrentProfile::fastDL == "" )
{
cerr << "The current profile has no fastdl set, so you cannot use this command." << endl;
return true;
}
if ( strcmp( args, "full" ) == 0 )
FastDL::fastdl_macro_scrape();
else if ( strcmp( args, "" ) == 0 || strcmp( args, " " ) == 0 || strcmp( args, "min" ) == 0 )
FastDL::fastdl_macro_scrape_min();
else
cerr << "fastdl -> macro (scrape) -> Invalid Syntax!" << endl;
}
else if ( strcmp( cmd, "gamepath" ) == 0 )
{
while( !filesystem::is_directory( gamePath ) )
{
cout << "Please input a valid path to your " << CurrentProfile::game << " Install folder (without quotes)" << endl << ">> ";
gamePath.clear();
getline( cin, gamePath );
}
ConfigInterface::UpdateConfStr( CurrentProfile::game, gamePath );
}
else if ( strcmp( cmd, "profile" ) == 0 )
{
if ( strcmp( args, "create" ) == 0 )
ProfileInterface::CreateProfile();
else if ( strcmp( args, "edit" ) == 0 )
ProfileInterface::EditProfile();
else if ( strcmp( args, "delete" ) == 0 )
ProfileInterface::DeleteProfile();
else if ( strcmp( args, "switch" ) == 0 )
{
if ( ProfileInterface::GetTotalProfiles() <= 1 )
{
cout << "You need multiple profiles to launch the profile selector." << endl;
return true;
}
shouldRestart = true;
shouldSwitchProfiles = true;
}
else if ( strcmp( args, "" ) == 0 || strcmp( args, " " ) == 0 || strcmp( args, "list" ) == 0 )
ProfileInterface::ListProfiles();
else
cerr << "profile -> Invalid Syntax!" << endl;
}
else if ( strcmp( cmd, "default" ) == 0 )
{
defaultProfile = CurrentProfile::id;
cout << "The default profile is now " << "[" << defaultProfile << "] " << ProfileInterface::GetConfStrNested( defaultProfile, "profileName" );
if ( ProfileInterface::GetConfStrNested( defaultProfile, "profileSeries" ) != "" && ProfileInterface::GetConfStrNested( defaultProfile, "profileSeries" ) != " " )
cout << " (" << ProfileInterface::GetConfStrNested( defaultProfile, "profileSeries" ) << ")";
cout << endl;
ConfigInterface::UpdateConfInt( "defaultprofile", defaultProfile );
}
else if ( strcmp( cmd, "selector" ) == 0 )
{
useProfileSelector = !useProfileSelector;
cout << ( useProfileSelector ? "The profile selector will now launch on startup if multiple profiles are present." : "The profile selector will no longer launch on startup." ) << endl;
ConfigInterface::UpdateConfBool( "profileselector", useProfileSelector );
}
else if ( strcmp( cmd, "verbose" ) == 0 )
{
verbose = !verbose;
cout << ( verbose ? "Verbose Logging is now enabled." : "Verbose Logging is now disabled." ) << endl;
ConfigInterface::UpdateConfBool( "verbose", verbose );
}
else
return false;
return true;
}
void multitool()
{
// cout << "The current configuration is \"" << currentConfig << "\"" << endl;
cout << "Type \"help\" for a list of valid commands." << endl;
while( !shouldExit && !shouldRestart )
{
cout << endl << ">> ";
string inputstream = "temp";
string second = "temp";
inputstream.clear();
second.clear();
getline( cin >> ws, inputstream );
string::size_type pos = inputstream.find( ' ', 0 );
if ( pos != string::npos )
{
second = inputstream.substr( pos+1 );
inputstream = inputstream.substr( 0, pos );
}
bool response = parse( inputstream.c_str(), second.c_str() );
if ( !response ) cerr << "Invalid command: \"" << inputstream.c_str() << "\"" << endl;
}
}
int main( int argc, char *argv[] )
{
// appDataPath = new char[ MAX_PATH ];
appPath = argv[ 0 ];
#ifdef _WIN32
appPath = appPath.substr( 0, appPath.find_last_of( "\\" ) ) + "\\";
#else
appPath = appPath.substr( 0, appPath.find_last_of( "/" ) ) + "/";
#endif /* _WIN32 */
bool resetSettings = false;
bool resetProfiles = false;
for ( int i = 1; i < argc; i++ )
{
if ( ( strcmp( argv[ i ], "-rs" ) == 0 ) || ( strcmp( argv[ i ], "--reset-settings" ) == 0 ) )
resetSettings = true;
if ( ( strcmp( argv[ i ], "-rp" ) == 0 ) || ( strcmp( argv[ i ], "--reset-profiles" ) == 0 ) )
resetProfiles = true;
if ( ( strcmp( argv[ i ], "-fp" ) == 0 ) || ( strcmp( argv[ i ], "--forced-profile" ) == 0 ) )
forcedProfile = atoi( argv[ ++i ] );
}
while ( shouldRestart )
{
shouldRestart = false;
cout << "Registering Configs...";
// PWSTR *tmp = new wchar_t*;
// SHGetKnownFolderPath( FOLDERID_RoamingAppData, 0, NULL, tmp );
// wcstombs( appDataPath, *tmp, sizeof( char ) * MAX_PATH );
// delete tmp;
bool validInstallPath = ConfigInterface::Init( resetSettings );
if ( !validInstallPath )
{
cout << " [ \033[31mFAILED\033[0m ]" << endl;
cout << "Prefrences file could not be found! A new one has been generated." << endl;
}
else
{
cout << " [ \033[34mDONE\033[0m ] " << endl;
}
verbose = ConfigInterface::GetConfBool( "verbose" );
defaultProfile = ConfigInterface::GetConfInt( "defaultprofile" );
useProfileSelector = ConfigInterface::GetConfBool( "profileselector" );
cout << "Registering Profiles...";
if ( !ProfileInterface::Init( resetProfiles ) )
{
cout << " [ \033[31mFAILED\033[0m ]" << endl;
if ( resetProfiles )
cout << "You have passed the reset-profiles switch." << endl << " Profiles have been reset to their defaults." << endl;
else
cout << "Profile configuration file could not be found! A new one has been generated." << endl;
cout << "Starting default profile..." << endl;
ProfileInterface::LoadProfile( 1 );
}
else
{
cout << " [ \033[34mDONE\033[0m ] " << endl;
if ( forcedProfile )
{
cout << "You have passed the forced-profile switch." << endl << " Profile #" << forcedProfile << " will now be loaded." << endl;
ProfileInterface::LoadProfile( forcedProfile );
forcedProfile = 0;
}
else if ( ProfileInterface::GetTotalProfiles() <= 1 )
{
cout << "Starting default profile..." << endl;
ProfileInterface::LoadProfile( 1 );
}
else
{
bool invalidSelection = true;
if ( !useProfileSelector && !shouldSwitchProfiles )
{
cout << "Starting default profile...";
if ( defaultProfile > 0 && defaultProfile <= ProfileInterface::GetTotalProfiles() )
{
cout << endl;
ProfileInterface::LoadProfile( defaultProfile );
invalidSelection = false;
}
else
{
cout << " [ \033[31mFAILED\033[0m ]" << endl;
cerr << "The Profile ID assigned as the default profile is malformed or does not exist." << endl;
defaultProfile = 1;
ConfigInterface::UpdateConfInt( "defaultprofile", defaultProfile );
}
}
cout << "Select a Profile" << endl << endl;
while ( invalidSelection )
{
for ( int i = 1; i <= ProfileInterface::GetTotalProfiles(); i++ )
{
cout << "[" << i << "] " << ProfileInterface::GetConfStrNested( i, "profileName" );
if ( ProfileInterface::GetConfStrNested( i, "profileSeries" ) != "" && ProfileInterface::GetConfStrNested( i, "profileSeries" ) != " " )
cout << " (" << ProfileInterface::GetConfStrNested( i, "profileSeries" ) << ")";
cout << endl;
}
cout << endl << ">> ";
string inputstream = "temp";
inputstream.clear();
getline( cin, inputstream );
int selection = atoi( inputstream.c_str() );
if ( selection > 0 && selection <= ProfileInterface::GetTotalProfiles() )
{
ProfileInterface::LoadProfile( selection );
invalidSelection = false;
}
else
{
cerr << "\033[31mInvalid selection!\033[0m Please only enter a number from 1 to " << ProfileInterface::GetTotalProfiles() << "." << endl;
clrScr();
}
}
}
}
cout << "Registering Filepath...";
if ( !validInstallPath )
{
cout << " [ \033[31mFAILED\033[0m ]" << endl;
while( !filesystem::is_directory( gamePath ) )
{
cout << "Please input a valid path to your " << CurrentProfile::game << " Install folder (without quotes)" << endl << ">> ";
gamePath.clear();
getline( cin, gamePath );
}
ConfigInterface::UpdateConfStr( CurrentProfile::game, gamePath );
}
else
{
gamePath = ConfigInterface::GetConfStr( CurrentProfile::game );
//cout << gamePath << endl;
if ( !filesystem::is_directory( gamePath ) )
{
cout << " [ \033[31mFAILED\033[0m ]" << endl;
while( !filesystem::is_directory( gamePath ) )
{
cout << "Please input a valid path to your " << CurrentProfile::game << " Install folder (without quotes)" << endl << ">> ";
gamePath.clear();
getline( cin, gamePath );
}
ConfigInterface::UpdateConfStr( CurrentProfile::game, gamePath );
}
else
{
cout << " [ \033[34mDONE\033[0m ] " << endl;
}
}
cout << "Starting multitool..." << endl;
//sleep( 500 );
clrScr();
cout << "Welcome to the \"cge7-193\" Multitool! v" << verMajor << "." << verMinor << endl;
cout << "DEDICATED TO INTERLOPER -- OCTOBER 24TH 2025" << endl;
cout << " (c) 2026 funniman.exe" << endl << endl;
multitool();
if ( shouldRestart ) clrScr();
}
cout << "\033[0m";
return 0;
}