-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
473 lines (388 loc) · 13.4 KB
/
Source.cpp
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
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
/*
DDLOADER 2
5TH GENERATION SUCCESSOR TO LOAD-R
-LOADS GAMES BY JSON FILES, NO MORE HARD CODING GAMES :)
(can you believe this all started as a patcher for friends?)
NOTES:
-This is a complete rewrite of the original LOAD-R (again)
-Why does CountFilesInDir() run twice? Should look up quirks of cpp
-std::vector<> solves everything.
-Maybe I should add all the funky colours and switcher back?
-Will do what DDLoader-Updater did (since I never released it), and can easily
add a way to update the games list without having to redownload the
entire program, since it can access my website or github on program boot!
-Yes, this will make it ping as a virus for 'phoning home', but I don't care /shrug
(what doesn't show as a virus nowadays?)
-and most importantly:
_____ __ __ __ __ _ ____ ____ ____ ___ ___ ___ ___ ___ _____
| || | | / ]| |/ ] | \ / || || \ | | | / \ | \ / ___/
| __|| | | / / | ' / | o ) o | | | | \ | _ _ || || ( \_
| |_ | | |/ / | \ | _/| | | | | D | | \_/ || O || D \__ |
| _] | : / \_ | \ | | | _ | | | | | | | || || / \ |
| | | \ || . | | | | | | | | | | | | || || \ |
|__| \__,_|\____||__|\_| |__| |__|__||____||_____| |___|___| \___/ |_____|\___| <3 me
*/
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
#include "UI.h"
#include "Game.h"
#include "Titlebar.h"
#include "Button.h"
#include "Mod.h"
#include "Game.h"
#include "json.hpp"
//disable warnings
#define _CRT_SECURE_NO_WARNINGS
using json = nlohmann::json;
class Tester
{
public:
sf::RectangleShape rect;
sf::Text text;
std::string name;
sf::Vector2f position;
sf::Font* font;
Tester(std::string names, sf::Font* font, bool recognised)
{
this->name = names;
this->font = font;
this->position = sf::Vector2f((rand() % 200) + 300, -20);
this->text.setString(name);
this->text.setFillColor(sf::Color::Black);
this->text.setCharacterSize(25);
this->text.setFont(*this->font);
this->text.setOrigin(this->text.getGlobalBounds().width/2,this->text.getGlobalBounds().height/2+5);
this->text.setPosition(position);
this->rect = sf::RectangleShape(sf::Vector2f(this->text.getGlobalBounds().width+10, this->text.getGlobalBounds().height+10));
this->rect.setFillColor(sf::Color(0,148,148));
this->rect.setOrigin(this->rect.getGlobalBounds().width/2,this->rect.getGlobalBounds().height/2);
this->rect.setPosition(position);
this->rect.setOutlineThickness(2);
this->rect.setOutlineColor(sf::Color(0,100,100));
if (recognised)
{
this->rect.setOutlineColor(sf::Color(0,240,240));
this->rect.setFillColor(sf::Color(0,214,214));
}
}
void Update()
{
this->position.y += 1;
this->rect.setPosition(this->position);
this->text.setPosition(this->position);
}
void Draw(sf::RenderWindow& window)
{
window.draw(this->rect);
window.draw(this->text);
}
void Log(std::string text)
{
std::ofstream file("log-ddloader.txt", std::ios_base::app);
if (file.is_open())
{
file << text << std::endl;
file.close();
std::cout << "[LOG]: " << text << std::endl;
}
else
{
std::cerr << "Error opening or creating log file!" << std::endl;
}
}
};
class Confetti
{
public:
sf::Vector2f position;
bool flip = false;
sf::RectangleShape rect;
sf::Color color;
sf::Texture* texture1;
sf::Texture* texture2;
int ticker = 0;
bool right;
int rightTicker;
float rotation = 0;
Confetti(sf::Vector2f position, sf::Texture* texture, sf::Texture* texture2, sf::Color color)
{
this->position = position;
this->color = sf::Color(rand()%255,rand()%255,rand()%255);
this->rect = sf::RectangleShape(sf::Vector2f(50,50));
this->rect.setFillColor(color);
this->rect.setPosition(this->position);
this->texture1 = texture;
this->texture2 = texture2;
this->rect.setTexture(this->texture1);
this->rect.setOrigin(this->rect.getGlobalBounds().width/2,this->rect.getGlobalBounds().height/2);
this->right = rand()%2;
this->rightTicker = 0;
}
void Update()
{
ticker++;
if (ticker > 100)
{
flip = !flip;
if (flip)
{
this->rect.setTexture(this->texture2);
}
else
{
this->rect.setTexture(this->texture1);
}
ticker = 0;
}
rightTicker++;
if (rightTicker>100)
{
right = !right;
rightTicker = 0;
}
if (right)
{
position.x += .1f;
rotation+=3;
}
else
{
position.x -= .1f;
rotation-=3;
}
this->position.y += 5;
this->rect.setPosition(this->position);
this->rect.setRotation(rotation);
}
void Draw(sf::RenderWindow& window)
{
window.draw(this->rect);
}
};
#pragma region METHODS
int CountFilesInDir(const std::string& path)
{
//counts ALL files, not just .json files
int count;
count = std::count_if(std::filesystem::directory_iterator(path), std::filesystem::directory_iterator(), static_cast<bool(*)(const std::filesystem::path&)>(std::filesystem::is_regular_file));
return count;
}
void Log(std::string text)
{
std::ofstream file("log-ddloader.txt", std::ios_base::app);
if (file.is_open())
{
file << text << std::endl;
file.close();
std::cout << "[LOG]: " << text << std::endl;
}
else
{
std::cerr << "Error opening or creating log file!" << std::endl;
}
}
void LoadGames(std::vector<Game>& games)
{
std::string path = "resources/games/";
std::string extension = ".json";
std::string pathImage = "resources/images/";
for (int i = 0; i < CountFilesInDir(path); i++)
{
std::string filename = "game" + std::to_string(i) + extension; // Assuming file names are like game0.json or game1.json
std::ifstream file;
file.open(path + filename); // Open the file
if (file.is_open())
{
json j;
file >> j;
std::string nameToUse = j["name"];
std::string descriptionToUse = j["description"];
std::string genreToUse = j["genre"];
std::string platformToUse = j["platform"];
std::string installLocation = j["installLocation"];
sf::Texture image;
std::string imagePath = pathImage + "game" + std::to_string(i) + ".png";
image.loadFromFile(imagePath);
std::string bepinexVersionToUse = j["bepinexVersion"];
Game game(nameToUse, descriptionToUse, genreToUse, platformToUse, installLocation, bepinexVersionToUse, image);
games.push_back(game);
file.close();
}
}
for (int i = 0; i < games.size(); i++)
{
Log("Loaded assets for " + games[i].name);
}
}
void WipeLog()
{
std::ofstream file("log-ddloader.txt", std::ios_base::trunc);
if (file.is_open())
{
file << "";
file.close();
}
else
{
std::cerr << "Error opening or creating log file!" << std::endl;
}
}
bool IsBepinexInstalled(std::string dir)
{
std::string path = dir + "/BepInEx";
if (std::filesystem::exists(path))
{
Log("Passed Bepinex Check!");
return true;
}
Log("BepInEx is not installed!");
return false;
}
#pragma endregion
const int width = 800;
const int height = 800;
sf::Font font;
sf::Text programTitle;
sf::RectangleShape programTitlebar;
sf::Vector2i mousePosition;
std::vector<Game> games;
bool locked = false;
bool isSettingsOpen = false;
std::vector<Tester> testers;
bool isSecretOpen = false;
int secretTicker = 0;
int names1Ticker = 0;
int names2Ticker = 0;
bool flip = true;
int count = 0;
std::vector<Confetti> confetti;
sf::Texture tex1;
sf::Texture tex2;
std::vector<std::string> recognised = { "CameraMan", "DHL Erzfeind", "latest_version", "Traube", "Wilde Pommes YT", "QuackAndCheese", "THANK YOU ALL SO MUCH <3", "FOR TESTING/BEING COOL/WHATEVER IT WAS!"};
std::vector<std::string> testersn = { "Azurii", "Bill", "Blammo", "Cookie", "Dimi", "DomPaul11", "Memepoleon", "nico", "Pixel Yoshi", "PlushEdits(Backup)", "Speedy612", "TarikGamer7" };
sf::Color color1 = sf::Color(217, 7, 24);
sf::Color color2 = sf::Color(15, 140, 65);
sf::Color color3 = sf::Color(43, 43, 128);
sf::Color color4 = sf::Color(230, 205, 18);
sf::RectangleShape shape1(sf::Vector2f(800,800));
int main()
{
shape1.setFillColor(sf::Color(0,0,0, 200));
shape1.setPosition(0,0);
sf::RenderWindow window(sf::VideoMode(width, height), "DDLOADER <3", sf::Style::None);
font.loadFromFile("resources/fonts/monospace.ttf");
sf::Image icon;
icon.loadFromFile("resources/images/icon.png");
window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr());
WipeLog();
LoadGames(games);
UI ui(games);
Titlebar titleBar(sf::Vector2f(400,20), sf::Vector2f(804,40), sf::Color(0,148,148));
srand(time(NULL));
tex1.loadFromFile("resources/images/confetti2.png");
tex2.loadFromFile("resources/images/confetti.png");
while (window.isOpen())
{
if (!window.hasFocus())
locked = true;
else
locked = false;
mousePosition = sf::Mouse::getPosition(window);
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color(0,116,116));
if (isSecretOpen)
{
count++;
if (count%2 == 0)
{
int choice = rand() % 4;
if (choice == 0)
confetti.push_back(Confetti(sf::Vector2f(rand() % 800, -20), &tex1, &tex2, color1));
else if (choice == 1)
confetti.push_back(Confetti(sf::Vector2f(rand() % 800, -20), &tex2, &tex1, color2));
else if (choice == 2)
confetti.push_back(Confetti(sf::Vector2f(rand() % 800, -20), &tex2, &tex2, color4));
else
confetti.push_back(Confetti(sf::Vector2f(rand() % 800, -20), &tex1, &tex1, color3));
}
if (count > 2400)
{
isSecretOpen = false;
count = 0;
confetti.clear();
testers.clear();
}
if (secretTicker > 0)
secretTicker--;
if (secretTicker == 0)
{
secretTicker = 40;
if (flip)
{
testers.push_back(Tester(recognised[names1Ticker], &font, true));
names1Ticker++;
if (names1Ticker> recognised.size()-1)
names1Ticker = 0;
flip = !flip;
}
else
{
testers.push_back(Tester(testersn[names2Ticker], &font, true));
names2Ticker++;
if (names2Ticker> testersn.size()-1)
names2Ticker = 0;
flip = !flip;
}
}
}
if (!isSettingsOpen)
{
ui.updateMain(mousePosition, window, locked, games);
ui.drawMain(window);
}
else
{
ui.updateSettings(mousePosition,window,locked,isSecretOpen);
ui.drawSettings(window);
}
if (isSecretOpen)
{
window.draw(shape1);
for (int i = 0; i < confetti.size(); i++)
{
confetti[i].Draw(window);
confetti[i].Update();
}
for (int i = 0; i < testers.size(); i++)
{
testers[i].Draw(window);
testers[i].Update();
}
}
for (int i = 0; i < testers.size(); i++)
{
if (testers[i].position.y > 820)
{
testers.erase(testers.begin() + i);
}
}
for (int i = 0; i < confetti.size(); i++)
{
if (confetti[i].position.y > 820)
{
confetti.erase(confetti.begin() + i);
}
}
titleBar.update(mousePosition, window, isSettingsOpen);
titleBar.draw(window);
window.setFramerateLimit(60);
window.display();
}
return 0;
}